blob: 06f304f46e0229427e039180abb6731bceb403bd [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 } },
138 { KE_KEY, 0xb05, { KEY_PROG2 } },
139 { KE_KEY, 0xb06, { KEY_WWW } },
140 { KE_KEY, 0xb07, { KEY_MAIL } },
141 { KE_KEY, 0xb30, { KEY_STOP } },
142 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
143 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
144 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
145 { KE_KEY, 0xb5a, { KEY_MEDIA } },
146 { KE_END, 0 },
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500147};
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149/* utility
150 */
151
Len Brown4be44fc2005-08-05 00:44:28 -0400152static __inline__ void _set_bit(u32 * word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
154 *word = (*word & ~mask) | (mask * value);
155}
156
157/* acpi interface wrappers
158 */
159
Len Brown4be44fc2005-08-05 00:44:28 -0400160static int is_valid_acpi_path(const char *methodName)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161{
162 acpi_handle handle;
163 acpi_status status;
164
Len Brown4be44fc2005-08-05 00:44:28 -0400165 status = acpi_get_handle(NULL, (char *)methodName, &handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 return !ACPI_FAILURE(status);
167}
168
Len Brown4be44fc2005-08-05 00:44:28 -0400169static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170{
171 struct acpi_object_list params;
172 union acpi_object in_objs[1];
173 acpi_status status;
174
Ahmed S. Darwishb2b79102007-02-06 16:14:43 -0800175 params.count = ARRAY_SIZE(in_objs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 params.pointer = in_objs;
177 in_objs[0].type = ACPI_TYPE_INTEGER;
178 in_objs[0].integer.value = val;
179
Len Brown4be44fc2005-08-05 00:44:28 -0400180 status = acpi_evaluate_object(NULL, (char *)methodName, &params, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 return (status == AE_OK);
182}
183
184#if 0
Len Brown4be44fc2005-08-05 00:44:28 -0400185static int read_acpi_int(const char *methodName, int *pVal)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
187 struct acpi_buffer results;
188 union acpi_object out_objs[1];
189 acpi_status status;
190
191 results.length = sizeof(out_objs);
192 results.pointer = out_objs;
193
Len Brown4be44fc2005-08-05 00:44:28 -0400194 status = acpi_evaluate_object(0, (char *)methodName, 0, &results);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 *pVal = out_objs[0].integer.value;
196
197 return (status == AE_OK) && (out_objs[0].type == ACPI_TYPE_INTEGER);
198}
199#endif
200
Len Brown4be44fc2005-08-05 00:44:28 -0400201static const char *method_hci /*= 0*/ ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203/* Perform a raw HCI call. Here we don't care about input or output buffer
204 * format.
205 */
Len Brown4be44fc2005-08-05 00:44:28 -0400206static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
208 struct acpi_object_list params;
209 union acpi_object in_objs[HCI_WORDS];
210 struct acpi_buffer results;
Len Brown4be44fc2005-08-05 00:44:28 -0400211 union acpi_object out_objs[HCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 acpi_status status;
213 int i;
214
215 params.count = HCI_WORDS;
216 params.pointer = in_objs;
217 for (i = 0; i < HCI_WORDS; ++i) {
218 in_objs[i].type = ACPI_TYPE_INTEGER;
219 in_objs[i].integer.value = in[i];
220 }
221
222 results.length = sizeof(out_objs);
223 results.pointer = out_objs;
224
Len Brown4be44fc2005-08-05 00:44:28 -0400225 status = acpi_evaluate_object(NULL, (char *)method_hci, &params,
226 &results);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
228 for (i = 0; i < out_objs->package.count; ++i) {
229 out[i] = out_objs->package.elements[i].integer.value;
230 }
231 }
232
233 return status;
234}
235
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400236/* common hci tasks (get or set one or two value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 *
238 * In addition to the ACPI status, the HCI system returns a result which
239 * may be useful (such as "not supported").
240 */
241
Len Brown4be44fc2005-08-05 00:44:28 -0400242static acpi_status hci_write1(u32 reg, u32 in1, u32 * result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
244 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
245 u32 out[HCI_WORDS];
246 acpi_status status = hci_raw(in, out);
247 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
248 return status;
249}
250
Len Brown4be44fc2005-08-05 00:44:28 -0400251static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
253 u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
254 u32 out[HCI_WORDS];
255 acpi_status status = hci_raw(in, out);
256 *out1 = out[2];
257 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
258 return status;
259}
260
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400261static acpi_status hci_write2(u32 reg, u32 in1, u32 in2, u32 *result)
262{
263 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
264 u32 out[HCI_WORDS];
265 acpi_status status = hci_raw(in, out);
266 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
267 return status;
268}
269
270static acpi_status hci_read2(u32 reg, u32 *out1, u32 *out2, u32 *result)
271{
272 u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
273 u32 out[HCI_WORDS];
274 acpi_status status = hci_raw(in, out);
275 *out1 = out[2];
276 *out2 = out[3];
277 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
278 return status;
279}
280
281struct toshiba_acpi_dev {
282 struct platform_device *p_dev;
Johannes Berg19d337d2009-06-02 13:01:37 +0200283 struct rfkill *bt_rfk;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500284 struct input_dev *hotkey_dev;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200285 int illumination_installed;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500286 acpi_handle handle;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400287
288 const char *bt_name;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400289
290 struct mutex mutex;
291};
292
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200293/* Illumination support */
294static int toshiba_illumination_available(void)
295{
296 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
297 u32 out[HCI_WORDS];
298 acpi_status status;
299
300 in[0] = 0xf100;
301 status = hci_raw(in, out);
302 if (ACPI_FAILURE(status)) {
303 printk(MY_INFO "Illumination device not available\n");
304 return 0;
305 }
306 in[0] = 0xf400;
307 status = hci_raw(in, out);
308 return 1;
309}
310
311static void toshiba_illumination_set(struct led_classdev *cdev,
312 enum led_brightness brightness)
313{
314 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
315 u32 out[HCI_WORDS];
316 acpi_status status;
317
318 /* First request : initialize communication. */
319 in[0] = 0xf100;
320 status = hci_raw(in, out);
321 if (ACPI_FAILURE(status)) {
322 printk(MY_INFO "Illumination device not available\n");
323 return;
324 }
325
326 if (brightness) {
327 /* Switch the illumination on */
328 in[0] = 0xf400;
329 in[1] = 0x14e;
330 in[2] = 1;
331 status = hci_raw(in, out);
332 if (ACPI_FAILURE(status)) {
333 printk(MY_INFO "ACPI call for illumination failed.\n");
334 return;
335 }
336 } else {
337 /* Switch the illumination off */
338 in[0] = 0xf400;
339 in[1] = 0x14e;
340 in[2] = 0;
341 status = hci_raw(in, out);
342 if (ACPI_FAILURE(status)) {
343 printk(MY_INFO "ACPI call for illumination failed.\n");
344 return;
345 }
346 }
347
348 /* Last request : close communication. */
349 in[0] = 0xf200;
350 in[1] = 0;
351 in[2] = 0;
352 hci_raw(in, out);
353}
354
355static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
356{
357 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
358 u32 out[HCI_WORDS];
359 acpi_status status;
360 enum led_brightness result;
361
362 /* First request : initialize communication. */
363 in[0] = 0xf100;
364 status = hci_raw(in, out);
365 if (ACPI_FAILURE(status)) {
366 printk(MY_INFO "Illumination device not available\n");
367 return LED_OFF;
368 }
369
370 /* Check the illumination */
371 in[0] = 0xf300;
372 in[1] = 0x14e;
373 status = hci_raw(in, out);
374 if (ACPI_FAILURE(status)) {
375 printk(MY_INFO "ACPI call for illumination failed.\n");
376 return LED_OFF;
377 }
378
379 result = out[2] ? LED_FULL : LED_OFF;
380
381 /* Last request : close communication. */
382 in[0] = 0xf200;
383 in[1] = 0;
384 in[2] = 0;
385 hci_raw(in, out);
386
387 return result;
388}
389
390static struct led_classdev toshiba_led = {
391 .name = "toshiba::illumination",
392 .max_brightness = 1,
393 .brightness_set = toshiba_illumination_set,
394 .brightness_get = toshiba_illumination_get,
395};
396
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400397static struct toshiba_acpi_dev toshiba_acpi = {
398 .bt_name = "Toshiba Bluetooth",
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400399};
400
401/* Bluetooth rfkill handlers */
402
403static u32 hci_get_bt_present(bool *present)
404{
405 u32 hci_result;
406 u32 value, value2;
407
408 value = 0;
409 value2 = 0;
410 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
411 if (hci_result == HCI_SUCCESS)
412 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
413
414 return hci_result;
415}
416
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400417static u32 hci_get_radio_state(bool *radio_state)
418{
419 u32 hci_result;
420 u32 value, value2;
421
422 value = 0;
423 value2 = 0x0001;
424 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
425
426 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
427 return hci_result;
428}
429
Johannes Berg19d337d2009-06-02 13:01:37 +0200430static int bt_rfkill_set_block(void *data, bool blocked)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400431{
Johannes Berg19d337d2009-06-02 13:01:37 +0200432 struct toshiba_acpi_dev *dev = data;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400433 u32 result1, result2;
434 u32 value;
Johannes Berg19d337d2009-06-02 13:01:37 +0200435 int err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400436 bool radio_state;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400437
Johannes Berg19d337d2009-06-02 13:01:37 +0200438 value = (blocked == false);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400439
440 mutex_lock(&dev->mutex);
Johannes Berg19d337d2009-06-02 13:01:37 +0200441 if (hci_get_radio_state(&radio_state) != HCI_SUCCESS) {
442 err = -EBUSY;
443 goto out;
444 }
445
446 if (!radio_state) {
447 err = 0;
448 goto out;
449 }
450
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400451 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
452 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400453
454 if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS)
Johannes Berg19d337d2009-06-02 13:01:37 +0200455 err = -EBUSY;
456 else
457 err = 0;
458 out:
459 mutex_unlock(&dev->mutex);
460 return err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400461}
462
Johannes Berg19d337d2009-06-02 13:01:37 +0200463static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400464{
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400465 bool new_rfk_state;
466 bool value;
467 u32 hci_result;
Johannes Berg19d337d2009-06-02 13:01:37 +0200468 struct toshiba_acpi_dev *dev = data;
469
470 mutex_lock(&dev->mutex);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400471
472 hci_result = hci_get_radio_state(&value);
Johannes Berg19d337d2009-06-02 13:01:37 +0200473 if (hci_result != HCI_SUCCESS) {
474 /* Can't do anything useful */
475 mutex_unlock(&dev->mutex);
Jiri Slaby82e77842009-08-06 15:57:51 -0700476 return;
Johannes Berg19d337d2009-06-02 13:01:37 +0200477 }
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400478
479 new_rfk_state = value;
480
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400481 mutex_unlock(&dev->mutex);
482
Johannes Berg19d337d2009-06-02 13:01:37 +0200483 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
484 bt_rfkill_set_block(data, true);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400485}
486
Johannes Berg19d337d2009-06-02 13:01:37 +0200487static const struct rfkill_ops toshiba_rfk_ops = {
488 .set_block = bt_rfkill_set_block,
489 .poll = bt_rfkill_poll,
490};
491
Len Brown4be44fc2005-08-05 00:44:28 -0400492static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
Holger Machtc9263552006-10-20 14:30:29 -0700493static struct backlight_device *toshiba_backlight_device;
Len Brown4be44fc2005-08-05 00:44:28 -0400494static int force_fan;
495static int last_key_event;
496static int key_event_valid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Holger Machtc9263552006-10-20 14:30:29 -0700498static int get_lcd(struct backlight_device *bd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
500 u32 hci_result;
501 u32 value;
502
503 hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result);
504 if (hci_result == HCI_SUCCESS) {
Holger Machtc9263552006-10-20 14:30:29 -0700505 return (value >> HCI_LCD_BRIGHTNESS_SHIFT);
506 } else
507 return -EFAULT;
508}
509
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800510static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -0700511{
512 int value = get_lcd(NULL);
513
514 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800515 seq_printf(m, "brightness: %d\n", value);
516 seq_printf(m, "brightness_levels: %d\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400517 HCI_LCD_BRIGHTNESS_LEVELS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 } else {
519 printk(MY_ERR "Error reading LCD brightness\n");
520 }
521
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800522 return 0;
523}
524
525static int lcd_proc_open(struct inode *inode, struct file *file)
526{
527 return single_open(file, lcd_proc_show, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528}
529
Holger Machtc9263552006-10-20 14:30:29 -0700530static int set_lcd(int value)
531{
532 u32 hci_result;
533
534 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
535 hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result);
536 if (hci_result != HCI_SUCCESS)
537 return -EFAULT;
538
539 return 0;
540}
541
542static int set_lcd_status(struct backlight_device *bd)
543{
Richard Purdie599a52d2007-02-10 23:07:48 +0000544 return set_lcd(bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -0700545}
546
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800547static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
548 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800550 char cmd[42];
551 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 int value;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800553 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800555 len = min(count, sizeof(cmd) - 1);
556 if (copy_from_user(cmd, buf, len))
557 return -EFAULT;
558 cmd[len] = '\0';
559
560 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800561 value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) {
Holger Machtc9263552006-10-20 14:30:29 -0700562 ret = set_lcd(value);
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800563 if (ret == 0)
564 ret = count;
565 } else {
Holger Machtc9263552006-10-20 14:30:29 -0700566 ret = -EINVAL;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800567 }
Holger Machtc9263552006-10-20 14:30:29 -0700568 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569}
570
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800571static const struct file_operations lcd_proc_fops = {
572 .owner = THIS_MODULE,
573 .open = lcd_proc_open,
574 .read = seq_read,
575 .llseek = seq_lseek,
576 .release = single_release,
577 .write = lcd_proc_write,
578};
579
580static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
582 u32 hci_result;
583 u32 value;
584
585 hci_read1(HCI_VIDEO_OUT, &value, &hci_result);
586 if (hci_result == HCI_SUCCESS) {
587 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
588 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400589 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800590 seq_printf(m, "lcd_out: %d\n", is_lcd);
591 seq_printf(m, "crt_out: %d\n", is_crt);
592 seq_printf(m, "tv_out: %d\n", is_tv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 } else {
594 printk(MY_ERR "Error reading video out status\n");
595 }
596
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800597 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598}
599
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800600static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800602 return single_open(file, video_proc_show, NULL);
603}
604
605static ssize_t video_proc_write(struct file *file, const char __user *buf,
606 size_t count, loff_t *pos)
607{
608 char *cmd, *buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 int value;
610 int remain = count;
611 int lcd_out = -1;
612 int crt_out = -1;
613 int tv_out = -1;
614 u32 hci_result;
Al Virob4482a42007-10-14 19:35:40 +0100615 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800617 cmd = kmalloc(count + 1, GFP_KERNEL);
618 if (!cmd)
619 return -ENOMEM;
620 if (copy_from_user(cmd, buf, count)) {
621 kfree(cmd);
622 return -EFAULT;
623 }
624 cmd[count] = '\0';
625
626 buffer = cmd;
627
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 /* scan expression. Multiple expressions may be delimited with ;
629 *
630 * NOTE: to keep scanning simple, invalid fields are ignored
631 */
632 while (remain) {
633 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
634 lcd_out = value & 1;
635 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
636 crt_out = value & 1;
637 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
638 tv_out = value & 1;
639 /* advance to one character past the next ; */
640 do {
641 ++buffer;
642 --remain;
643 }
Len Brown4be44fc2005-08-05 00:44:28 -0400644 while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 }
646
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800647 kfree(cmd);
648
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 hci_read1(HCI_VIDEO_OUT, &video_out, &hci_result);
650 if (hci_result == HCI_SUCCESS) {
Harvey Harrison9e113e02008-09-22 14:37:29 -0700651 unsigned int new_video_out = video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 if (lcd_out != -1)
653 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
654 if (crt_out != -1)
655 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
656 if (tv_out != -1)
657 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
658 /* To avoid unnecessary video disruption, only write the new
659 * video setting if something changed. */
660 if (new_video_out != video_out)
661 write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
662 } else {
663 return -EFAULT;
664 }
665
666 return count;
667}
668
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800669static const struct file_operations video_proc_fops = {
670 .owner = THIS_MODULE,
671 .open = video_proc_open,
672 .read = seq_read,
673 .llseek = seq_lseek,
674 .release = single_release,
675 .write = video_proc_write,
676};
677
678static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679{
680 u32 hci_result;
681 u32 value;
682
683 hci_read1(HCI_FAN, &value, &hci_result);
684 if (hci_result == HCI_SUCCESS) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800685 seq_printf(m, "running: %d\n", (value > 0));
686 seq_printf(m, "force_on: %d\n", force_fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 } else {
688 printk(MY_ERR "Error reading fan status\n");
689 }
690
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800691 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692}
693
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800694static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800696 return single_open(file, fan_proc_show, NULL);
697}
698
699static ssize_t fan_proc_write(struct file *file, const char __user *buf,
700 size_t count, loff_t *pos)
701{
702 char cmd[42];
703 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 int value;
705 u32 hci_result;
706
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800707 len = min(count, sizeof(cmd) - 1);
708 if (copy_from_user(cmd, buf, len))
709 return -EFAULT;
710 cmd[len] = '\0';
711
712 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
Len Brown4be44fc2005-08-05 00:44:28 -0400713 value >= 0 && value <= 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 hci_write1(HCI_FAN, value, &hci_result);
715 if (hci_result != HCI_SUCCESS)
716 return -EFAULT;
717 else
718 force_fan = value;
719 } else {
720 return -EINVAL;
721 }
722
723 return count;
724}
725
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800726static const struct file_operations fan_proc_fops = {
727 .owner = THIS_MODULE,
728 .open = fan_proc_open,
729 .read = seq_read,
730 .llseek = seq_lseek,
731 .release = single_release,
732 .write = fan_proc_write,
733};
734
735static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
737 u32 hci_result;
738 u32 value;
739
740 if (!key_event_valid) {
741 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
742 if (hci_result == HCI_SUCCESS) {
743 key_event_valid = 1;
744 last_key_event = value;
745 } else if (hci_result == HCI_EMPTY) {
746 /* better luck next time */
747 } else if (hci_result == HCI_NOT_SUPPORTED) {
748 /* This is a workaround for an unresolved issue on
749 * some machines where system events sporadically
750 * become disabled. */
751 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
752 printk(MY_NOTICE "Re-enabled hotkeys\n");
753 } else {
754 printk(MY_ERR "Error reading hotkey status\n");
755 goto end;
756 }
757 }
758
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800759 seq_printf(m, "hotkey_ready: %d\n", key_event_valid);
760 seq_printf(m, "hotkey: 0x%04x\n", last_key_event);
761end:
762 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763}
764
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800765static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800767 return single_open(file, keys_proc_show, NULL);
768}
769
770static ssize_t keys_proc_write(struct file *file, const char __user *buf,
771 size_t count, loff_t *pos)
772{
773 char cmd[42];
774 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 int value;
776
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800777 len = min(count, sizeof(cmd) - 1);
778 if (copy_from_user(cmd, buf, len))
779 return -EFAULT;
780 cmd[len] = '\0';
781
782 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 key_event_valid = 0;
784 } else {
785 return -EINVAL;
786 }
787
788 return count;
789}
790
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800791static const struct file_operations keys_proc_fops = {
792 .owner = THIS_MODULE,
793 .open = keys_proc_open,
794 .read = seq_read,
795 .llseek = seq_lseek,
796 .release = single_release,
797 .write = keys_proc_write,
798};
799
800static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800802 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
803 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
804 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805}
806
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800807static int version_proc_open(struct inode *inode, struct file *file)
808{
809 return single_open(file, version_proc_show, PDE(inode)->data);
810}
811
812static const struct file_operations version_proc_fops = {
813 .owner = THIS_MODULE,
814 .open = version_proc_open,
815 .read = seq_read,
816 .llseek = seq_lseek,
817 .release = single_release,
818};
819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820/* proc and module init
821 */
822
823#define PROC_TOSHIBA "toshiba"
824
Axel Linf8ef3ae2010-07-20 15:19:51 -0700825static void __init create_toshiba_proc_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800827 proc_create("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, &lcd_proc_fops);
828 proc_create("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, &video_proc_fops);
829 proc_create("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, &fan_proc_fops);
830 proc_create("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, &keys_proc_fops);
831 proc_create("version", S_IRUGO, toshiba_proc_dir, &version_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832}
833
Axel Linf8ef3ae2010-07-20 15:19:51 -0700834static void remove_toshiba_proc_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800836 remove_proc_entry("lcd", toshiba_proc_dir);
837 remove_proc_entry("video", toshiba_proc_dir);
838 remove_proc_entry("fan", toshiba_proc_dir);
839 remove_proc_entry("keys", toshiba_proc_dir);
840 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841}
842
Richard Purdie599a52d2007-02-10 23:07:48 +0000843static struct backlight_ops toshiba_backlight_data = {
Holger Machtc9263552006-10-20 14:30:29 -0700844 .get_brightness = get_lcd,
845 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -0700846};
847
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500848static void toshiba_acpi_notify(acpi_handle handle, u32 event, void *context)
849{
850 u32 hci_result, value;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500851
852 if (event != 0x80)
853 return;
854 do {
855 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
856 if (hci_result == HCI_SUCCESS) {
857 if (value == 0x100)
858 continue;
Frans Popb4663012010-03-01 09:50:46 -0500859 /* act on key press; ignore key release */
860 if (value & 0x80)
861 continue;
862
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700863 if (!sparse_keymap_report_event(toshiba_acpi.hotkey_dev,
864 value, 1, true)) {
Frans Popb4663012010-03-01 09:50:46 -0500865 printk(MY_INFO "Unknown key %x\n",
866 value);
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500867 }
868 } else if (hci_result == HCI_NOT_SUPPORTED) {
869 /* This is a workaround for an unresolved issue on
870 * some machines where system events sporadically
871 * become disabled. */
872 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
873 printk(MY_NOTICE "Re-enabled hotkeys\n");
874 }
875 } while (hci_result != HCI_EMPTY);
876}
877
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700878static int __init toshiba_acpi_setup_keyboard(char *device)
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500879{
880 acpi_status status;
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700881 int error;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500882
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700883 status = acpi_get_handle(NULL, device, &toshiba_acpi.handle);
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500884 if (ACPI_FAILURE(status)) {
885 printk(MY_INFO "Unable to get notification device\n");
886 return -ENODEV;
887 }
888
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500889 toshiba_acpi.hotkey_dev = input_allocate_device();
890 if (!toshiba_acpi.hotkey_dev) {
891 printk(MY_INFO "Unable to register input device\n");
892 return -ENOMEM;
893 }
894
895 toshiba_acpi.hotkey_dev->name = "Toshiba input device";
896 toshiba_acpi.hotkey_dev->phys = device;
897 toshiba_acpi.hotkey_dev->id.bustype = BUS_HOST;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500898
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700899 error = sparse_keymap_setup(toshiba_acpi.hotkey_dev,
900 toshiba_acpi_keymap, NULL);
901 if (error)
902 goto err_free_dev;
903
904 status = acpi_install_notify_handler(toshiba_acpi.handle,
905 ACPI_DEVICE_NOTIFY, toshiba_acpi_notify, NULL);
906 if (ACPI_FAILURE(status)) {
907 printk(MY_INFO "Unable to install hotkey notification\n");
908 error = -ENODEV;
909 goto err_free_keymap;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500910 }
911
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700912 status = acpi_evaluate_object(toshiba_acpi.handle, "ENAB", NULL, NULL);
913 if (ACPI_FAILURE(status)) {
914 printk(MY_INFO "Unable to enable hotkeys\n");
915 error = -ENODEV;
916 goto err_remove_notify;
917 }
918
919 error = input_register_device(toshiba_acpi.hotkey_dev);
920 if (error) {
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500921 printk(MY_INFO "Unable to register input device\n");
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700922 goto err_remove_notify;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500923 }
924
925 return 0;
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700926
927 err_remove_notify:
928 acpi_remove_notify_handler(toshiba_acpi.handle,
929 ACPI_DEVICE_NOTIFY, toshiba_acpi_notify);
930 err_free_keymap:
931 sparse_keymap_free(toshiba_acpi.hotkey_dev);
932 err_free_dev:
933 input_free_device(toshiba_acpi.hotkey_dev);
934 toshiba_acpi.hotkey_dev = NULL;
935 return error;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500936}
937
Sam Ravnborgb2b77b22007-06-01 00:47:12 -0700938static void toshiba_acpi_exit(void)
Holger Machtc9263552006-10-20 14:30:29 -0700939{
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700940 if (toshiba_acpi.hotkey_dev) {
941 acpi_remove_notify_handler(toshiba_acpi.handle,
942 ACPI_DEVICE_NOTIFY, toshiba_acpi_notify);
943 sparse_keymap_free(toshiba_acpi.hotkey_dev);
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500944 input_unregister_device(toshiba_acpi.hotkey_dev);
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700945 }
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500946
Johannes Berg19d337d2009-06-02 13:01:37 +0200947 if (toshiba_acpi.bt_rfk) {
948 rfkill_unregister(toshiba_acpi.bt_rfk);
949 rfkill_destroy(toshiba_acpi.bt_rfk);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400950 }
951
Holger Machtc9263552006-10-20 14:30:29 -0700952 if (toshiba_backlight_device)
953 backlight_device_unregister(toshiba_backlight_device);
954
Axel Linf8ef3ae2010-07-20 15:19:51 -0700955 remove_toshiba_proc_entries();
Holger Machtc9263552006-10-20 14:30:29 -0700956
957 if (toshiba_proc_dir)
958 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
959
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200960 if (toshiba_acpi.illumination_installed)
961 led_classdev_unregister(&toshiba_led);
962
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400963 platform_device_unregister(toshiba_acpi.p_dev);
964
Holger Machtc9263552006-10-20 14:30:29 -0700965 return;
966}
967
Len Brown4be44fc2005-08-05 00:44:28 -0400968static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 u32 hci_result;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400971 bool bt_present;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400972 int ret = 0;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500973 struct backlight_properties props;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
975 if (acpi_disabled)
976 return -ENODEV;
Luming Yufb9802f2005-03-18 18:03:45 -0500977
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 /* simple device detection: look for HCI method */
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500979 if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD)) {
980 method_hci = TOSH_INTERFACE_1 GHCI_METHOD;
981 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1))
982 printk(MY_INFO "Unable to activate hotkeys\n");
983 } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD)) {
984 method_hci = TOSH_INTERFACE_2 GHCI_METHOD;
985 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2))
986 printk(MY_INFO "Unable to activate hotkeys\n");
987 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 return -ENODEV;
989
990 printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400991 TOSHIBA_ACPI_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 printk(MY_INFO " HCI method: %s\n", method_hci);
993
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400994 mutex_init(&toshiba_acpi.mutex);
995
996 toshiba_acpi.p_dev = platform_device_register_simple("toshiba_acpi",
997 -1, NULL, 0);
998 if (IS_ERR(toshiba_acpi.p_dev)) {
999 ret = PTR_ERR(toshiba_acpi.p_dev);
1000 printk(MY_ERR "unable to register platform device\n");
1001 toshiba_acpi.p_dev = NULL;
1002 toshiba_acpi_exit();
1003 return ret;
1004 }
1005
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 force_fan = 0;
1007 key_event_valid = 0;
1008
1009 /* enable event fifo */
1010 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
1011
1012 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
1013 if (!toshiba_proc_dir) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001014 toshiba_acpi_exit();
1015 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 } else {
Axel Linf8ef3ae2010-07-20 15:19:51 -07001017 create_toshiba_proc_entries();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 }
1019
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001020 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001021 toshiba_backlight_device = backlight_device_register("toshiba",
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001022 &toshiba_acpi.p_dev->dev,
1023 NULL,
1024 &toshiba_backlight_data,
1025 &props);
Holger Machtc9263552006-10-20 14:30:29 -07001026 if (IS_ERR(toshiba_backlight_device)) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001027 ret = PTR_ERR(toshiba_backlight_device);
Andrey Borzenkov12993422007-11-14 16:58:28 -08001028
Holger Machtc9263552006-10-20 14:30:29 -07001029 printk(KERN_ERR "Could not register toshiba backlight device\n");
1030 toshiba_backlight_device = NULL;
1031 toshiba_acpi_exit();
Andrey Borzenkov12993422007-11-14 16:58:28 -08001032 return ret;
Holger Machtc9263552006-10-20 14:30:29 -07001033 }
1034
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001035 /* Register rfkill switch for Bluetooth */
1036 if (hci_get_bt_present(&bt_present) == HCI_SUCCESS && bt_present) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001037 toshiba_acpi.bt_rfk = rfkill_alloc(toshiba_acpi.bt_name,
1038 &toshiba_acpi.p_dev->dev,
1039 RFKILL_TYPE_BLUETOOTH,
1040 &toshiba_rfk_ops,
1041 &toshiba_acpi);
1042 if (!toshiba_acpi.bt_rfk) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001043 printk(MY_ERR "unable to allocate rfkill device\n");
1044 toshiba_acpi_exit();
1045 return -ENOMEM;
1046 }
1047
Johannes Berg19d337d2009-06-02 13:01:37 +02001048 ret = rfkill_register(toshiba_acpi.bt_rfk);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001049 if (ret) {
1050 printk(MY_ERR "unable to register rfkill device\n");
Johannes Berg19d337d2009-06-02 13:01:37 +02001051 rfkill_destroy(toshiba_acpi.bt_rfk);
Frederik Deweerdt38aefbc2008-12-15 13:54:19 -08001052 toshiba_acpi_exit();
1053 return ret;
1054 }
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001055 }
1056
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +02001057 toshiba_acpi.illumination_installed = 0;
1058 if (toshiba_illumination_available()) {
1059 if (!led_classdev_register(&(toshiba_acpi.p_dev->dev),
1060 &toshiba_led))
1061 toshiba_acpi.illumination_installed = 1;
1062 }
1063
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001064 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065}
1066
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067module_init(toshiba_acpi_init);
1068module_exit(toshiba_acpi_exit);