blob: 63f42a22e10240a32d58c6f4bd1ce7ddc87428b6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * toshiba_acpi.c - Toshiba Laptop ACPI Extras
3 *
4 *
5 * Copyright (C) 2002-2004 John Belmonte
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04006 * Copyright (C) 2008 Philip Langdale
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +02007 * Copyright (C) 2010 Pierre Ducroquet
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 *
24 * The devolpment page for this driver is located at
25 * http://memebeam.org/toys/ToshibaAcpiDriver.
26 *
27 * Credits:
28 * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
29 * engineering the Windows drivers
30 * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
31 * Rob Miller - TV out and hotkeys help
32 *
33 *
34 * TODO
35 *
36 */
37
philipl@overt.orgc41a40c2008-08-30 11:57:39 -040038#define TOSHIBA_ACPI_VERSION "0.19"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define PROC_INTERFACE_VERSION 1
40
41#include <linux/kernel.h>
42#include <linux/module.h>
43#include <linux/init.h>
44#include <linux/types.h>
45#include <linux/proc_fs.h>
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -080046#include <linux/seq_file.h>
Holger Machtc9263552006-10-20 14:30:29 -070047#include <linux/backlight.h>
philipl@overt.orgc41a40c2008-08-30 11:57:39 -040048#include <linux/platform_device.h>
49#include <linux/rfkill.h>
Matthew Garrett6335e4d2010-02-25 15:20:54 -050050#include <linux/input.h>
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -070051#include <linux/input/sparse-keymap.h>
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +020052#include <linux/leds.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090053#include <linux/slab.h>
Holger Machtc9263552006-10-20 14:30:29 -070054
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <asm/uaccess.h>
56
57#include <acpi/acpi_drivers.h>
58
59MODULE_AUTHOR("John Belmonte");
60MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
61MODULE_LICENSE("GPL");
62
63#define MY_LOGPREFIX "toshiba_acpi: "
64#define MY_ERR KERN_ERR MY_LOGPREFIX
65#define MY_NOTICE KERN_NOTICE MY_LOGPREFIX
66#define MY_INFO KERN_INFO MY_LOGPREFIX
67
68/* Toshiba ACPI method paths */
69#define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM"
Matthew Garrett6335e4d2010-02-25 15:20:54 -050070#define TOSH_INTERFACE_1 "\\_SB_.VALD"
71#define TOSH_INTERFACE_2 "\\_SB_.VALZ"
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
Matthew Garrett6335e4d2010-02-25 15:20:54 -050073#define GHCI_METHOD ".GHCI"
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75/* Toshiba HCI interface definitions
76 *
77 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
78 * be uniform across all their models. Ideally we would just call
79 * dedicated ACPI methods instead of using this primitive interface.
80 * However the ACPI methods seem to be incomplete in some areas (for
81 * example they allow setting, but not reading, the LCD brightness value),
82 * so this is still useful.
83 */
84
85#define HCI_WORDS 6
86
87/* operations */
88#define HCI_SET 0xff00
89#define HCI_GET 0xfe00
90
91/* return codes */
92#define HCI_SUCCESS 0x0000
93#define HCI_FAILURE 0x1000
94#define HCI_NOT_SUPPORTED 0x8000
95#define HCI_EMPTY 0x8c00
96
97/* registers */
98#define HCI_FAN 0x0004
99#define HCI_SYSTEM_EVENT 0x0016
100#define HCI_VIDEO_OUT 0x001c
101#define HCI_HOTKEY_EVENT 0x001e
102#define HCI_LCD_BRIGHTNESS 0x002a
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400103#define HCI_WIRELESS 0x0056
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105/* field definitions */
106#define HCI_LCD_BRIGHTNESS_BITS 3
107#define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
108#define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
109#define HCI_VIDEO_OUT_LCD 0x1
110#define HCI_VIDEO_OUT_CRT 0x2
111#define HCI_VIDEO_OUT_TV 0x4
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400112#define HCI_WIRELESS_KILL_SWITCH 0x01
113#define HCI_WIRELESS_BT_PRESENT 0x0f
114#define HCI_WIRELESS_BT_ATTACH 0x40
115#define HCI_WIRELESS_BT_POWER 0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800117static const struct acpi_device_id toshiba_device_ids[] = {
118 {"TOS6200", 0},
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400119 {"TOS6208", 0},
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800120 {"TOS1900", 0},
121 {"", 0},
122};
123MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
124
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700125static const struct key_entry toshiba_acpi_keymap[] __initconst = {
126 { KE_KEY, 0x101, { KEY_MUTE } },
127 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
128 { KE_KEY, 0x103, { KEY_ZOOMIN } },
129 { KE_KEY, 0x13b, { KEY_COFFEE } },
130 { KE_KEY, 0x13c, { KEY_BATTERY } },
131 { KE_KEY, 0x13d, { KEY_SLEEP } },
132 { KE_KEY, 0x13e, { KEY_SUSPEND } },
133 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
134 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
135 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
136 { KE_KEY, 0x142, { KEY_WLAN } },
137 { KE_KEY, 0x143, { KEY_PROG1 } },
Jon Dowlanda49010f2010-10-27 00:24:59 +0100138 { KE_KEY, 0x17f, { KEY_FN } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700139 { KE_KEY, 0xb05, { KEY_PROG2 } },
140 { KE_KEY, 0xb06, { KEY_WWW } },
141 { KE_KEY, 0xb07, { KEY_MAIL } },
142 { KE_KEY, 0xb30, { KEY_STOP } },
143 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
144 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
145 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
146 { KE_KEY, 0xb5a, { KEY_MEDIA } },
147 { KE_END, 0 },
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500148};
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150/* utility
151 */
152
Len Brown4be44fc2005-08-05 00:44:28 -0400153static __inline__ void _set_bit(u32 * word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
155 *word = (*word & ~mask) | (mask * value);
156}
157
158/* acpi interface wrappers
159 */
160
Len Brown4be44fc2005-08-05 00:44:28 -0400161static int is_valid_acpi_path(const char *methodName)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
163 acpi_handle handle;
164 acpi_status status;
165
Len Brown4be44fc2005-08-05 00:44:28 -0400166 status = acpi_get_handle(NULL, (char *)methodName, &handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 return !ACPI_FAILURE(status);
168}
169
Len Brown4be44fc2005-08-05 00:44:28 -0400170static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
172 struct acpi_object_list params;
173 union acpi_object in_objs[1];
174 acpi_status status;
175
Ahmed S. Darwishb2b79102007-02-06 16:14:43 -0800176 params.count = ARRAY_SIZE(in_objs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 params.pointer = in_objs;
178 in_objs[0].type = ACPI_TYPE_INTEGER;
179 in_objs[0].integer.value = val;
180
Len Brown4be44fc2005-08-05 00:44:28 -0400181 status = acpi_evaluate_object(NULL, (char *)methodName, &params, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 return (status == AE_OK);
183}
184
185#if 0
Len Brown4be44fc2005-08-05 00:44:28 -0400186static int read_acpi_int(const char *methodName, int *pVal)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
188 struct acpi_buffer results;
189 union acpi_object out_objs[1];
190 acpi_status status;
191
192 results.length = sizeof(out_objs);
193 results.pointer = out_objs;
194
Len Brown4be44fc2005-08-05 00:44:28 -0400195 status = acpi_evaluate_object(0, (char *)methodName, 0, &results);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 *pVal = out_objs[0].integer.value;
197
198 return (status == AE_OK) && (out_objs[0].type == ACPI_TYPE_INTEGER);
199}
200#endif
201
Len Brown4be44fc2005-08-05 00:44:28 -0400202static const char *method_hci /*= 0*/ ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204/* Perform a raw HCI call. Here we don't care about input or output buffer
205 * format.
206 */
Len Brown4be44fc2005-08-05 00:44:28 -0400207static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
209 struct acpi_object_list params;
210 union acpi_object in_objs[HCI_WORDS];
211 struct acpi_buffer results;
Len Brown4be44fc2005-08-05 00:44:28 -0400212 union acpi_object out_objs[HCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 acpi_status status;
214 int i;
215
216 params.count = HCI_WORDS;
217 params.pointer = in_objs;
218 for (i = 0; i < HCI_WORDS; ++i) {
219 in_objs[i].type = ACPI_TYPE_INTEGER;
220 in_objs[i].integer.value = in[i];
221 }
222
223 results.length = sizeof(out_objs);
224 results.pointer = out_objs;
225
Len Brown4be44fc2005-08-05 00:44:28 -0400226 status = acpi_evaluate_object(NULL, (char *)method_hci, &params,
227 &results);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
229 for (i = 0; i < out_objs->package.count; ++i) {
230 out[i] = out_objs->package.elements[i].integer.value;
231 }
232 }
233
234 return status;
235}
236
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400237/* common hci tasks (get or set one or two value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 *
239 * In addition to the ACPI status, the HCI system returns a result which
240 * may be useful (such as "not supported").
241 */
242
Len Brown4be44fc2005-08-05 00:44:28 -0400243static acpi_status hci_write1(u32 reg, u32 in1, u32 * result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
246 u32 out[HCI_WORDS];
247 acpi_status status = hci_raw(in, out);
248 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
249 return status;
250}
251
Len Brown4be44fc2005-08-05 00:44:28 -0400252static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
254 u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
255 u32 out[HCI_WORDS];
256 acpi_status status = hci_raw(in, out);
257 *out1 = out[2];
258 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
259 return status;
260}
261
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400262static acpi_status hci_write2(u32 reg, u32 in1, u32 in2, u32 *result)
263{
264 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
265 u32 out[HCI_WORDS];
266 acpi_status status = hci_raw(in, out);
267 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
268 return status;
269}
270
271static acpi_status hci_read2(u32 reg, u32 *out1, u32 *out2, u32 *result)
272{
273 u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
274 u32 out[HCI_WORDS];
275 acpi_status status = hci_raw(in, out);
276 *out1 = out[2];
277 *out2 = out[3];
278 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
279 return status;
280}
281
282struct toshiba_acpi_dev {
283 struct platform_device *p_dev;
Johannes Berg19d337d2009-06-02 13:01:37 +0200284 struct rfkill *bt_rfk;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500285 struct input_dev *hotkey_dev;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200286 int illumination_installed;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500287 acpi_handle handle;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400288
289 const char *bt_name;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400290
291 struct mutex mutex;
292};
293
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200294/* Illumination support */
295static int toshiba_illumination_available(void)
296{
297 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
298 u32 out[HCI_WORDS];
299 acpi_status status;
300
301 in[0] = 0xf100;
302 status = hci_raw(in, out);
303 if (ACPI_FAILURE(status)) {
304 printk(MY_INFO "Illumination device not available\n");
305 return 0;
306 }
307 in[0] = 0xf400;
308 status = hci_raw(in, out);
309 return 1;
310}
311
312static void toshiba_illumination_set(struct led_classdev *cdev,
313 enum led_brightness brightness)
314{
315 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
316 u32 out[HCI_WORDS];
317 acpi_status status;
318
319 /* First request : initialize communication. */
320 in[0] = 0xf100;
321 status = hci_raw(in, out);
322 if (ACPI_FAILURE(status)) {
323 printk(MY_INFO "Illumination device not available\n");
324 return;
325 }
326
327 if (brightness) {
328 /* Switch the illumination on */
329 in[0] = 0xf400;
330 in[1] = 0x14e;
331 in[2] = 1;
332 status = hci_raw(in, out);
333 if (ACPI_FAILURE(status)) {
334 printk(MY_INFO "ACPI call for illumination failed.\n");
335 return;
336 }
337 } else {
338 /* Switch the illumination off */
339 in[0] = 0xf400;
340 in[1] = 0x14e;
341 in[2] = 0;
342 status = hci_raw(in, out);
343 if (ACPI_FAILURE(status)) {
344 printk(MY_INFO "ACPI call for illumination failed.\n");
345 return;
346 }
347 }
348
349 /* Last request : close communication. */
350 in[0] = 0xf200;
351 in[1] = 0;
352 in[2] = 0;
353 hci_raw(in, out);
354}
355
356static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
357{
358 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
359 u32 out[HCI_WORDS];
360 acpi_status status;
361 enum led_brightness result;
362
363 /* First request : initialize communication. */
364 in[0] = 0xf100;
365 status = hci_raw(in, out);
366 if (ACPI_FAILURE(status)) {
367 printk(MY_INFO "Illumination device not available\n");
368 return LED_OFF;
369 }
370
371 /* Check the illumination */
372 in[0] = 0xf300;
373 in[1] = 0x14e;
374 status = hci_raw(in, out);
375 if (ACPI_FAILURE(status)) {
376 printk(MY_INFO "ACPI call for illumination failed.\n");
377 return LED_OFF;
378 }
379
380 result = out[2] ? LED_FULL : LED_OFF;
381
382 /* Last request : close communication. */
383 in[0] = 0xf200;
384 in[1] = 0;
385 in[2] = 0;
386 hci_raw(in, out);
387
388 return result;
389}
390
391static struct led_classdev toshiba_led = {
392 .name = "toshiba::illumination",
393 .max_brightness = 1,
394 .brightness_set = toshiba_illumination_set,
395 .brightness_get = toshiba_illumination_get,
396};
397
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400398static struct toshiba_acpi_dev toshiba_acpi = {
399 .bt_name = "Toshiba Bluetooth",
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400400};
401
402/* Bluetooth rfkill handlers */
403
404static u32 hci_get_bt_present(bool *present)
405{
406 u32 hci_result;
407 u32 value, value2;
408
409 value = 0;
410 value2 = 0;
411 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
412 if (hci_result == HCI_SUCCESS)
413 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
414
415 return hci_result;
416}
417
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400418static u32 hci_get_radio_state(bool *radio_state)
419{
420 u32 hci_result;
421 u32 value, value2;
422
423 value = 0;
424 value2 = 0x0001;
425 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
426
427 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
428 return hci_result;
429}
430
Johannes Berg19d337d2009-06-02 13:01:37 +0200431static int bt_rfkill_set_block(void *data, bool blocked)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400432{
Johannes Berg19d337d2009-06-02 13:01:37 +0200433 struct toshiba_acpi_dev *dev = data;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400434 u32 result1, result2;
435 u32 value;
Johannes Berg19d337d2009-06-02 13:01:37 +0200436 int err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400437 bool radio_state;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400438
Johannes Berg19d337d2009-06-02 13:01:37 +0200439 value = (blocked == false);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400440
441 mutex_lock(&dev->mutex);
Johannes Berg19d337d2009-06-02 13:01:37 +0200442 if (hci_get_radio_state(&radio_state) != HCI_SUCCESS) {
443 err = -EBUSY;
444 goto out;
445 }
446
447 if (!radio_state) {
448 err = 0;
449 goto out;
450 }
451
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400452 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
453 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400454
455 if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS)
Johannes Berg19d337d2009-06-02 13:01:37 +0200456 err = -EBUSY;
457 else
458 err = 0;
459 out:
460 mutex_unlock(&dev->mutex);
461 return err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400462}
463
Johannes Berg19d337d2009-06-02 13:01:37 +0200464static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400465{
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400466 bool new_rfk_state;
467 bool value;
468 u32 hci_result;
Johannes Berg19d337d2009-06-02 13:01:37 +0200469 struct toshiba_acpi_dev *dev = data;
470
471 mutex_lock(&dev->mutex);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400472
473 hci_result = hci_get_radio_state(&value);
Johannes Berg19d337d2009-06-02 13:01:37 +0200474 if (hci_result != HCI_SUCCESS) {
475 /* Can't do anything useful */
476 mutex_unlock(&dev->mutex);
Jiri Slaby82e77842009-08-06 15:57:51 -0700477 return;
Johannes Berg19d337d2009-06-02 13:01:37 +0200478 }
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400479
480 new_rfk_state = value;
481
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400482 mutex_unlock(&dev->mutex);
483
Johannes Berg19d337d2009-06-02 13:01:37 +0200484 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
485 bt_rfkill_set_block(data, true);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400486}
487
Johannes Berg19d337d2009-06-02 13:01:37 +0200488static const struct rfkill_ops toshiba_rfk_ops = {
489 .set_block = bt_rfkill_set_block,
490 .poll = bt_rfkill_poll,
491};
492
Len Brown4be44fc2005-08-05 00:44:28 -0400493static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
Holger Machtc9263552006-10-20 14:30:29 -0700494static struct backlight_device *toshiba_backlight_device;
Len Brown4be44fc2005-08-05 00:44:28 -0400495static int force_fan;
496static int last_key_event;
497static int key_event_valid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Holger Machtc9263552006-10-20 14:30:29 -0700499static int get_lcd(struct backlight_device *bd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
501 u32 hci_result;
502 u32 value;
503
504 hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result);
505 if (hci_result == HCI_SUCCESS) {
Holger Machtc9263552006-10-20 14:30:29 -0700506 return (value >> HCI_LCD_BRIGHTNESS_SHIFT);
507 } else
508 return -EFAULT;
509}
510
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800511static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -0700512{
513 int value = get_lcd(NULL);
514
515 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800516 seq_printf(m, "brightness: %d\n", value);
517 seq_printf(m, "brightness_levels: %d\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400518 HCI_LCD_BRIGHTNESS_LEVELS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 } else {
520 printk(MY_ERR "Error reading LCD brightness\n");
521 }
522
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800523 return 0;
524}
525
526static int lcd_proc_open(struct inode *inode, struct file *file)
527{
528 return single_open(file, lcd_proc_show, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529}
530
Holger Machtc9263552006-10-20 14:30:29 -0700531static int set_lcd(int value)
532{
533 u32 hci_result;
534
535 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
536 hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result);
537 if (hci_result != HCI_SUCCESS)
538 return -EFAULT;
539
540 return 0;
541}
542
543static int set_lcd_status(struct backlight_device *bd)
544{
Richard Purdie599a52d2007-02-10 23:07:48 +0000545 return set_lcd(bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -0700546}
547
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800548static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
549 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800551 char cmd[42];
552 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 int value;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800554 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800556 len = min(count, sizeof(cmd) - 1);
557 if (copy_from_user(cmd, buf, len))
558 return -EFAULT;
559 cmd[len] = '\0';
560
561 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800562 value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) {
Holger Machtc9263552006-10-20 14:30:29 -0700563 ret = set_lcd(value);
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800564 if (ret == 0)
565 ret = count;
566 } else {
Holger Machtc9263552006-10-20 14:30:29 -0700567 ret = -EINVAL;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800568 }
Holger Machtc9263552006-10-20 14:30:29 -0700569 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570}
571
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800572static const struct file_operations lcd_proc_fops = {
573 .owner = THIS_MODULE,
574 .open = lcd_proc_open,
575 .read = seq_read,
576 .llseek = seq_lseek,
577 .release = single_release,
578 .write = lcd_proc_write,
579};
580
581static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
583 u32 hci_result;
584 u32 value;
585
586 hci_read1(HCI_VIDEO_OUT, &value, &hci_result);
587 if (hci_result == HCI_SUCCESS) {
588 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
589 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400590 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800591 seq_printf(m, "lcd_out: %d\n", is_lcd);
592 seq_printf(m, "crt_out: %d\n", is_crt);
593 seq_printf(m, "tv_out: %d\n", is_tv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 } else {
595 printk(MY_ERR "Error reading video out status\n");
596 }
597
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800598 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
600
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800601static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800603 return single_open(file, video_proc_show, NULL);
604}
605
606static ssize_t video_proc_write(struct file *file, const char __user *buf,
607 size_t count, loff_t *pos)
608{
609 char *cmd, *buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 int value;
611 int remain = count;
612 int lcd_out = -1;
613 int crt_out = -1;
614 int tv_out = -1;
615 u32 hci_result;
Al Virob4482a42007-10-14 19:35:40 +0100616 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800618 cmd = kmalloc(count + 1, GFP_KERNEL);
619 if (!cmd)
620 return -ENOMEM;
621 if (copy_from_user(cmd, buf, count)) {
622 kfree(cmd);
623 return -EFAULT;
624 }
625 cmd[count] = '\0';
626
627 buffer = cmd;
628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 /* scan expression. Multiple expressions may be delimited with ;
630 *
631 * NOTE: to keep scanning simple, invalid fields are ignored
632 */
633 while (remain) {
634 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
635 lcd_out = value & 1;
636 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
637 crt_out = value & 1;
638 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
639 tv_out = value & 1;
640 /* advance to one character past the next ; */
641 do {
642 ++buffer;
643 --remain;
644 }
Len Brown4be44fc2005-08-05 00:44:28 -0400645 while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 }
647
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800648 kfree(cmd);
649
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 hci_read1(HCI_VIDEO_OUT, &video_out, &hci_result);
651 if (hci_result == HCI_SUCCESS) {
Harvey Harrison9e113e02008-09-22 14:37:29 -0700652 unsigned int new_video_out = video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 if (lcd_out != -1)
654 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
655 if (crt_out != -1)
656 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
657 if (tv_out != -1)
658 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
659 /* To avoid unnecessary video disruption, only write the new
660 * video setting if something changed. */
661 if (new_video_out != video_out)
662 write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
663 } else {
664 return -EFAULT;
665 }
666
667 return count;
668}
669
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800670static const struct file_operations video_proc_fops = {
671 .owner = THIS_MODULE,
672 .open = video_proc_open,
673 .read = seq_read,
674 .llseek = seq_lseek,
675 .release = single_release,
676 .write = video_proc_write,
677};
678
679static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680{
681 u32 hci_result;
682 u32 value;
683
684 hci_read1(HCI_FAN, &value, &hci_result);
685 if (hci_result == HCI_SUCCESS) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800686 seq_printf(m, "running: %d\n", (value > 0));
687 seq_printf(m, "force_on: %d\n", force_fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 } else {
689 printk(MY_ERR "Error reading fan status\n");
690 }
691
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800692 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693}
694
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800695static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800697 return single_open(file, fan_proc_show, NULL);
698}
699
700static ssize_t fan_proc_write(struct file *file, const char __user *buf,
701 size_t count, loff_t *pos)
702{
703 char cmd[42];
704 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 int value;
706 u32 hci_result;
707
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800708 len = min(count, sizeof(cmd) - 1);
709 if (copy_from_user(cmd, buf, len))
710 return -EFAULT;
711 cmd[len] = '\0';
712
713 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
Len Brown4be44fc2005-08-05 00:44:28 -0400714 value >= 0 && value <= 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 hci_write1(HCI_FAN, value, &hci_result);
716 if (hci_result != HCI_SUCCESS)
717 return -EFAULT;
718 else
719 force_fan = value;
720 } else {
721 return -EINVAL;
722 }
723
724 return count;
725}
726
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800727static const struct file_operations fan_proc_fops = {
728 .owner = THIS_MODULE,
729 .open = fan_proc_open,
730 .read = seq_read,
731 .llseek = seq_lseek,
732 .release = single_release,
733 .write = fan_proc_write,
734};
735
736static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737{
738 u32 hci_result;
739 u32 value;
740
741 if (!key_event_valid) {
742 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
743 if (hci_result == HCI_SUCCESS) {
744 key_event_valid = 1;
745 last_key_event = value;
746 } else if (hci_result == HCI_EMPTY) {
747 /* better luck next time */
748 } else if (hci_result == HCI_NOT_SUPPORTED) {
749 /* This is a workaround for an unresolved issue on
750 * some machines where system events sporadically
751 * become disabled. */
752 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
753 printk(MY_NOTICE "Re-enabled hotkeys\n");
754 } else {
755 printk(MY_ERR "Error reading hotkey status\n");
756 goto end;
757 }
758 }
759
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800760 seq_printf(m, "hotkey_ready: %d\n", key_event_valid);
761 seq_printf(m, "hotkey: 0x%04x\n", last_key_event);
762end:
763 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764}
765
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800766static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800768 return single_open(file, keys_proc_show, NULL);
769}
770
771static ssize_t keys_proc_write(struct file *file, const char __user *buf,
772 size_t count, loff_t *pos)
773{
774 char cmd[42];
775 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 int value;
777
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800778 len = min(count, sizeof(cmd) - 1);
779 if (copy_from_user(cmd, buf, len))
780 return -EFAULT;
781 cmd[len] = '\0';
782
783 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 key_event_valid = 0;
785 } else {
786 return -EINVAL;
787 }
788
789 return count;
790}
791
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800792static const struct file_operations keys_proc_fops = {
793 .owner = THIS_MODULE,
794 .open = keys_proc_open,
795 .read = seq_read,
796 .llseek = seq_lseek,
797 .release = single_release,
798 .write = keys_proc_write,
799};
800
801static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800803 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
804 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
805 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806}
807
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800808static int version_proc_open(struct inode *inode, struct file *file)
809{
810 return single_open(file, version_proc_show, PDE(inode)->data);
811}
812
813static const struct file_operations version_proc_fops = {
814 .owner = THIS_MODULE,
815 .open = version_proc_open,
816 .read = seq_read,
817 .llseek = seq_lseek,
818 .release = single_release,
819};
820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821/* proc and module init
822 */
823
824#define PROC_TOSHIBA "toshiba"
825
Axel Linf8ef3ae2010-07-20 15:19:51 -0700826static void __init create_toshiba_proc_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800828 proc_create("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, &lcd_proc_fops);
829 proc_create("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, &video_proc_fops);
830 proc_create("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, &fan_proc_fops);
831 proc_create("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, &keys_proc_fops);
832 proc_create("version", S_IRUGO, toshiba_proc_dir, &version_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833}
834
Axel Linf8ef3ae2010-07-20 15:19:51 -0700835static void remove_toshiba_proc_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800837 remove_proc_entry("lcd", toshiba_proc_dir);
838 remove_proc_entry("video", toshiba_proc_dir);
839 remove_proc_entry("fan", toshiba_proc_dir);
840 remove_proc_entry("keys", toshiba_proc_dir);
841 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842}
843
Lionel Debrouxacc24722010-11-16 14:14:02 +0100844static const struct backlight_ops toshiba_backlight_data = {
Holger Machtc9263552006-10-20 14:30:29 -0700845 .get_brightness = get_lcd,
846 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -0700847};
848
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500849static void toshiba_acpi_notify(acpi_handle handle, u32 event, void *context)
850{
851 u32 hci_result, value;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500852
853 if (event != 0x80)
854 return;
855 do {
856 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
857 if (hci_result == HCI_SUCCESS) {
858 if (value == 0x100)
859 continue;
Frans Popb4663012010-03-01 09:50:46 -0500860 /* act on key press; ignore key release */
861 if (value & 0x80)
862 continue;
863
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700864 if (!sparse_keymap_report_event(toshiba_acpi.hotkey_dev,
865 value, 1, true)) {
Frans Popb4663012010-03-01 09:50:46 -0500866 printk(MY_INFO "Unknown key %x\n",
867 value);
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500868 }
869 } else if (hci_result == HCI_NOT_SUPPORTED) {
870 /* This is a workaround for an unresolved issue on
871 * some machines where system events sporadically
872 * become disabled. */
873 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
874 printk(MY_NOTICE "Re-enabled hotkeys\n");
875 }
876 } while (hci_result != HCI_EMPTY);
877}
878
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700879static int __init toshiba_acpi_setup_keyboard(char *device)
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500880{
881 acpi_status status;
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700882 int error;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500883
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700884 status = acpi_get_handle(NULL, device, &toshiba_acpi.handle);
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500885 if (ACPI_FAILURE(status)) {
886 printk(MY_INFO "Unable to get notification device\n");
887 return -ENODEV;
888 }
889
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500890 toshiba_acpi.hotkey_dev = input_allocate_device();
891 if (!toshiba_acpi.hotkey_dev) {
892 printk(MY_INFO "Unable to register input device\n");
893 return -ENOMEM;
894 }
895
896 toshiba_acpi.hotkey_dev->name = "Toshiba input device";
897 toshiba_acpi.hotkey_dev->phys = device;
898 toshiba_acpi.hotkey_dev->id.bustype = BUS_HOST;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500899
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700900 error = sparse_keymap_setup(toshiba_acpi.hotkey_dev,
901 toshiba_acpi_keymap, NULL);
902 if (error)
903 goto err_free_dev;
904
905 status = acpi_install_notify_handler(toshiba_acpi.handle,
906 ACPI_DEVICE_NOTIFY, toshiba_acpi_notify, NULL);
907 if (ACPI_FAILURE(status)) {
908 printk(MY_INFO "Unable to install hotkey notification\n");
909 error = -ENODEV;
910 goto err_free_keymap;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500911 }
912
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700913 status = acpi_evaluate_object(toshiba_acpi.handle, "ENAB", NULL, NULL);
914 if (ACPI_FAILURE(status)) {
915 printk(MY_INFO "Unable to enable hotkeys\n");
916 error = -ENODEV;
917 goto err_remove_notify;
918 }
919
920 error = input_register_device(toshiba_acpi.hotkey_dev);
921 if (error) {
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500922 printk(MY_INFO "Unable to register input device\n");
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700923 goto err_remove_notify;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500924 }
925
926 return 0;
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700927
928 err_remove_notify:
929 acpi_remove_notify_handler(toshiba_acpi.handle,
930 ACPI_DEVICE_NOTIFY, toshiba_acpi_notify);
931 err_free_keymap:
932 sparse_keymap_free(toshiba_acpi.hotkey_dev);
933 err_free_dev:
934 input_free_device(toshiba_acpi.hotkey_dev);
935 toshiba_acpi.hotkey_dev = NULL;
936 return error;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500937}
938
Sam Ravnborgb2b77b22007-06-01 00:47:12 -0700939static void toshiba_acpi_exit(void)
Holger Machtc9263552006-10-20 14:30:29 -0700940{
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700941 if (toshiba_acpi.hotkey_dev) {
942 acpi_remove_notify_handler(toshiba_acpi.handle,
943 ACPI_DEVICE_NOTIFY, toshiba_acpi_notify);
944 sparse_keymap_free(toshiba_acpi.hotkey_dev);
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500945 input_unregister_device(toshiba_acpi.hotkey_dev);
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700946 }
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500947
Johannes Berg19d337d2009-06-02 13:01:37 +0200948 if (toshiba_acpi.bt_rfk) {
949 rfkill_unregister(toshiba_acpi.bt_rfk);
950 rfkill_destroy(toshiba_acpi.bt_rfk);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400951 }
952
Holger Machtc9263552006-10-20 14:30:29 -0700953 if (toshiba_backlight_device)
954 backlight_device_unregister(toshiba_backlight_device);
955
Axel Linf8ef3ae2010-07-20 15:19:51 -0700956 remove_toshiba_proc_entries();
Holger Machtc9263552006-10-20 14:30:29 -0700957
958 if (toshiba_proc_dir)
959 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
960
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200961 if (toshiba_acpi.illumination_installed)
962 led_classdev_unregister(&toshiba_led);
963
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400964 platform_device_unregister(toshiba_acpi.p_dev);
965
Holger Machtc9263552006-10-20 14:30:29 -0700966 return;
967}
968
Len Brown4be44fc2005-08-05 00:44:28 -0400969static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 u32 hci_result;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400972 bool bt_present;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400973 int ret = 0;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500974 struct backlight_properties props;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
976 if (acpi_disabled)
977 return -ENODEV;
Luming Yufb9802f2005-03-18 18:03:45 -0500978
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 /* simple device detection: look for HCI method */
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500980 if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD)) {
981 method_hci = TOSH_INTERFACE_1 GHCI_METHOD;
982 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1))
983 printk(MY_INFO "Unable to activate hotkeys\n");
984 } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD)) {
985 method_hci = TOSH_INTERFACE_2 GHCI_METHOD;
986 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2))
987 printk(MY_INFO "Unable to activate hotkeys\n");
988 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 return -ENODEV;
990
991 printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400992 TOSHIBA_ACPI_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 printk(MY_INFO " HCI method: %s\n", method_hci);
994
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400995 mutex_init(&toshiba_acpi.mutex);
996
997 toshiba_acpi.p_dev = platform_device_register_simple("toshiba_acpi",
998 -1, NULL, 0);
999 if (IS_ERR(toshiba_acpi.p_dev)) {
1000 ret = PTR_ERR(toshiba_acpi.p_dev);
1001 printk(MY_ERR "unable to register platform device\n");
1002 toshiba_acpi.p_dev = NULL;
1003 toshiba_acpi_exit();
1004 return ret;
1005 }
1006
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 force_fan = 0;
1008 key_event_valid = 0;
1009
1010 /* enable event fifo */
1011 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
1012
1013 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
1014 if (!toshiba_proc_dir) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001015 toshiba_acpi_exit();
1016 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 } else {
Axel Linf8ef3ae2010-07-20 15:19:51 -07001018 create_toshiba_proc_entries();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 }
1020
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001021 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001022 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001023 toshiba_backlight_device = backlight_device_register("toshiba",
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001024 &toshiba_acpi.p_dev->dev,
1025 NULL,
1026 &toshiba_backlight_data,
1027 &props);
Holger Machtc9263552006-10-20 14:30:29 -07001028 if (IS_ERR(toshiba_backlight_device)) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001029 ret = PTR_ERR(toshiba_backlight_device);
Andrey Borzenkov12993422007-11-14 16:58:28 -08001030
Holger Machtc9263552006-10-20 14:30:29 -07001031 printk(KERN_ERR "Could not register toshiba backlight device\n");
1032 toshiba_backlight_device = NULL;
1033 toshiba_acpi_exit();
Andrey Borzenkov12993422007-11-14 16:58:28 -08001034 return ret;
Holger Machtc9263552006-10-20 14:30:29 -07001035 }
1036
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001037 /* Register rfkill switch for Bluetooth */
1038 if (hci_get_bt_present(&bt_present) == HCI_SUCCESS && bt_present) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001039 toshiba_acpi.bt_rfk = rfkill_alloc(toshiba_acpi.bt_name,
1040 &toshiba_acpi.p_dev->dev,
1041 RFKILL_TYPE_BLUETOOTH,
1042 &toshiba_rfk_ops,
1043 &toshiba_acpi);
1044 if (!toshiba_acpi.bt_rfk) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001045 printk(MY_ERR "unable to allocate rfkill device\n");
1046 toshiba_acpi_exit();
1047 return -ENOMEM;
1048 }
1049
Johannes Berg19d337d2009-06-02 13:01:37 +02001050 ret = rfkill_register(toshiba_acpi.bt_rfk);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001051 if (ret) {
1052 printk(MY_ERR "unable to register rfkill device\n");
Johannes Berg19d337d2009-06-02 13:01:37 +02001053 rfkill_destroy(toshiba_acpi.bt_rfk);
Frederik Deweerdt38aefbc2008-12-15 13:54:19 -08001054 toshiba_acpi_exit();
1055 return ret;
1056 }
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001057 }
1058
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +02001059 toshiba_acpi.illumination_installed = 0;
1060 if (toshiba_illumination_available()) {
1061 if (!led_classdev_register(&(toshiba_acpi.p_dev->dev),
1062 &toshiba_led))
1063 toshiba_acpi.illumination_installed = 1;
1064 }
1065
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001066 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067}
1068
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069module_init(toshiba_acpi_init);
1070module_exit(toshiba_acpi_exit);