blob: 37aa1479855136c10f2384edc814da5eda6dc6c9 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 *
23 * The devolpment page for this driver is located at
24 * http://memebeam.org/toys/ToshibaAcpiDriver.
25 *
26 * Credits:
27 * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
28 * engineering the Windows drivers
29 * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
30 * Rob Miller - TV out and hotkeys help
31 *
32 *
33 * TODO
34 *
35 */
36
philipl@overt.orgc41a40c2008-08-30 11:57:39 -040037#define TOSHIBA_ACPI_VERSION "0.19"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define PROC_INTERFACE_VERSION 1
39
40#include <linux/kernel.h>
41#include <linux/module.h>
42#include <linux/init.h>
43#include <linux/types.h>
44#include <linux/proc_fs.h>
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -080045#include <linux/seq_file.h>
Holger Machtc9263552006-10-20 14:30:29 -070046#include <linux/backlight.h>
philipl@overt.orgc41a40c2008-08-30 11:57:39 -040047#include <linux/platform_device.h>
48#include <linux/rfkill.h>
Matthew Garrett6335e4d2010-02-25 15:20:54 -050049#include <linux/input.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090050#include <linux/slab.h>
Holger Machtc9263552006-10-20 14:30:29 -070051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <asm/uaccess.h>
53
54#include <acpi/acpi_drivers.h>
55
56MODULE_AUTHOR("John Belmonte");
57MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
58MODULE_LICENSE("GPL");
59
60#define MY_LOGPREFIX "toshiba_acpi: "
61#define MY_ERR KERN_ERR MY_LOGPREFIX
62#define MY_NOTICE KERN_NOTICE MY_LOGPREFIX
63#define MY_INFO KERN_INFO MY_LOGPREFIX
64
65/* Toshiba ACPI method paths */
66#define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM"
Matthew Garrett6335e4d2010-02-25 15:20:54 -050067#define TOSH_INTERFACE_1 "\\_SB_.VALD"
68#define TOSH_INTERFACE_2 "\\_SB_.VALZ"
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
Matthew Garrett6335e4d2010-02-25 15:20:54 -050070#define GHCI_METHOD ".GHCI"
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72/* Toshiba HCI interface definitions
73 *
74 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
75 * be uniform across all their models. Ideally we would just call
76 * dedicated ACPI methods instead of using this primitive interface.
77 * However the ACPI methods seem to be incomplete in some areas (for
78 * example they allow setting, but not reading, the LCD brightness value),
79 * so this is still useful.
80 */
81
82#define HCI_WORDS 6
83
84/* operations */
85#define HCI_SET 0xff00
86#define HCI_GET 0xfe00
87
88/* return codes */
89#define HCI_SUCCESS 0x0000
90#define HCI_FAILURE 0x1000
91#define HCI_NOT_SUPPORTED 0x8000
92#define HCI_EMPTY 0x8c00
93
94/* registers */
95#define HCI_FAN 0x0004
96#define HCI_SYSTEM_EVENT 0x0016
97#define HCI_VIDEO_OUT 0x001c
98#define HCI_HOTKEY_EVENT 0x001e
99#define HCI_LCD_BRIGHTNESS 0x002a
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400100#define HCI_WIRELESS 0x0056
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102/* field definitions */
103#define HCI_LCD_BRIGHTNESS_BITS 3
104#define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
105#define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
106#define HCI_VIDEO_OUT_LCD 0x1
107#define HCI_VIDEO_OUT_CRT 0x2
108#define HCI_VIDEO_OUT_TV 0x4
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400109#define HCI_WIRELESS_KILL_SWITCH 0x01
110#define HCI_WIRELESS_BT_PRESENT 0x0f
111#define HCI_WIRELESS_BT_ATTACH 0x40
112#define HCI_WIRELESS_BT_POWER 0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800114static const struct acpi_device_id toshiba_device_ids[] = {
115 {"TOS6200", 0},
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400116 {"TOS6208", 0},
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800117 {"TOS1900", 0},
118 {"", 0},
119};
120MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
121
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500122struct key_entry {
123 char type;
124 u16 code;
125 u16 keycode;
126};
127
128enum {KE_KEY, KE_END};
129
130static struct key_entry toshiba_acpi_keymap[] = {
131 {KE_KEY, 0x101, KEY_MUTE},
132 {KE_KEY, 0x13b, KEY_COFFEE},
133 {KE_KEY, 0x13c, KEY_BATTERY},
134 {KE_KEY, 0x13d, KEY_SLEEP},
135 {KE_KEY, 0x13e, KEY_SUSPEND},
136 {KE_KEY, 0x13f, KEY_SWITCHVIDEOMODE},
137 {KE_KEY, 0x140, KEY_BRIGHTNESSDOWN},
138 {KE_KEY, 0x141, KEY_BRIGHTNESSUP},
139 {KE_KEY, 0x142, KEY_WLAN},
140 {KE_KEY, 0x143, KEY_PROG1},
141 {KE_KEY, 0xb05, KEY_PROG2},
142 {KE_KEY, 0xb06, KEY_WWW},
143 {KE_KEY, 0xb07, KEY_MAIL},
144 {KE_KEY, 0xb30, KEY_STOP},
145 {KE_KEY, 0xb31, KEY_PREVIOUSSONG},
146 {KE_KEY, 0xb32, KEY_NEXTSONG},
147 {KE_KEY, 0xb33, KEY_PLAYPAUSE},
148 {KE_KEY, 0xb5a, KEY_MEDIA},
149 {KE_END, 0, 0},
150};
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152/* utility
153 */
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155static __inline__ void _set_bit(u32 * word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
157 *word = (*word & ~mask) | (mask * value);
158}
159
160/* acpi interface wrappers
161 */
162
Len Brown4be44fc2005-08-05 00:44:28 -0400163static int is_valid_acpi_path(const char *methodName)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
165 acpi_handle handle;
166 acpi_status status;
167
Len Brown4be44fc2005-08-05 00:44:28 -0400168 status = acpi_get_handle(NULL, (char *)methodName, &handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 return !ACPI_FAILURE(status);
170}
171
Len Brown4be44fc2005-08-05 00:44:28 -0400172static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 struct acpi_object_list params;
175 union acpi_object in_objs[1];
176 acpi_status status;
177
Ahmed S. Darwishb2b79102007-02-06 16:14:43 -0800178 params.count = ARRAY_SIZE(in_objs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 params.pointer = in_objs;
180 in_objs[0].type = ACPI_TYPE_INTEGER;
181 in_objs[0].integer.value = val;
182
Len Brown4be44fc2005-08-05 00:44:28 -0400183 status = acpi_evaluate_object(NULL, (char *)methodName, &params, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 return (status == AE_OK);
185}
186
187#if 0
Len Brown4be44fc2005-08-05 00:44:28 -0400188static int read_acpi_int(const char *methodName, int *pVal)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
190 struct acpi_buffer results;
191 union acpi_object out_objs[1];
192 acpi_status status;
193
194 results.length = sizeof(out_objs);
195 results.pointer = out_objs;
196
Len Brown4be44fc2005-08-05 00:44:28 -0400197 status = acpi_evaluate_object(0, (char *)methodName, 0, &results);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 *pVal = out_objs[0].integer.value;
199
200 return (status == AE_OK) && (out_objs[0].type == ACPI_TYPE_INTEGER);
201}
202#endif
203
Len Brown4be44fc2005-08-05 00:44:28 -0400204static const char *method_hci /*= 0*/ ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206/* Perform a raw HCI call. Here we don't care about input or output buffer
207 * format.
208 */
Len Brown4be44fc2005-08-05 00:44:28 -0400209static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
211 struct acpi_object_list params;
212 union acpi_object in_objs[HCI_WORDS];
213 struct acpi_buffer results;
Len Brown4be44fc2005-08-05 00:44:28 -0400214 union acpi_object out_objs[HCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 acpi_status status;
216 int i;
217
218 params.count = HCI_WORDS;
219 params.pointer = in_objs;
220 for (i = 0; i < HCI_WORDS; ++i) {
221 in_objs[i].type = ACPI_TYPE_INTEGER;
222 in_objs[i].integer.value = in[i];
223 }
224
225 results.length = sizeof(out_objs);
226 results.pointer = out_objs;
227
Len Brown4be44fc2005-08-05 00:44:28 -0400228 status = acpi_evaluate_object(NULL, (char *)method_hci, &params,
229 &results);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
231 for (i = 0; i < out_objs->package.count; ++i) {
232 out[i] = out_objs->package.elements[i].integer.value;
233 }
234 }
235
236 return status;
237}
238
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400239/* common hci tasks (get or set one or two value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 *
241 * In addition to the ACPI status, the HCI system returns a result which
242 * may be useful (such as "not supported").
243 */
244
Len Brown4be44fc2005-08-05 00:44:28 -0400245static acpi_status hci_write1(u32 reg, u32 in1, u32 * result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
247 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
248 u32 out[HCI_WORDS];
249 acpi_status status = hci_raw(in, out);
250 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
251 return status;
252}
253
Len Brown4be44fc2005-08-05 00:44:28 -0400254static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
256 u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
257 u32 out[HCI_WORDS];
258 acpi_status status = hci_raw(in, out);
259 *out1 = out[2];
260 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
261 return status;
262}
263
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400264static acpi_status hci_write2(u32 reg, u32 in1, u32 in2, u32 *result)
265{
266 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
267 u32 out[HCI_WORDS];
268 acpi_status status = hci_raw(in, out);
269 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
270 return status;
271}
272
273static acpi_status hci_read2(u32 reg, u32 *out1, u32 *out2, u32 *result)
274{
275 u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
276 u32 out[HCI_WORDS];
277 acpi_status status = hci_raw(in, out);
278 *out1 = out[2];
279 *out2 = out[3];
280 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
281 return status;
282}
283
284struct toshiba_acpi_dev {
285 struct platform_device *p_dev;
Johannes Berg19d337d2009-06-02 13:01:37 +0200286 struct rfkill *bt_rfk;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500287 struct input_dev *hotkey_dev;
288 acpi_handle handle;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400289
290 const char *bt_name;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400291
292 struct mutex mutex;
293};
294
295static struct toshiba_acpi_dev toshiba_acpi = {
296 .bt_name = "Toshiba Bluetooth",
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400297};
298
299/* Bluetooth rfkill handlers */
300
301static u32 hci_get_bt_present(bool *present)
302{
303 u32 hci_result;
304 u32 value, value2;
305
306 value = 0;
307 value2 = 0;
308 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
309 if (hci_result == HCI_SUCCESS)
310 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
311
312 return hci_result;
313}
314
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400315static u32 hci_get_radio_state(bool *radio_state)
316{
317 u32 hci_result;
318 u32 value, value2;
319
320 value = 0;
321 value2 = 0x0001;
322 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
323
324 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
325 return hci_result;
326}
327
Johannes Berg19d337d2009-06-02 13:01:37 +0200328static int bt_rfkill_set_block(void *data, bool blocked)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400329{
Johannes Berg19d337d2009-06-02 13:01:37 +0200330 struct toshiba_acpi_dev *dev = data;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400331 u32 result1, result2;
332 u32 value;
Johannes Berg19d337d2009-06-02 13:01:37 +0200333 int err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400334 bool radio_state;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400335
Johannes Berg19d337d2009-06-02 13:01:37 +0200336 value = (blocked == false);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400337
338 mutex_lock(&dev->mutex);
Johannes Berg19d337d2009-06-02 13:01:37 +0200339 if (hci_get_radio_state(&radio_state) != HCI_SUCCESS) {
340 err = -EBUSY;
341 goto out;
342 }
343
344 if (!radio_state) {
345 err = 0;
346 goto out;
347 }
348
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400349 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
350 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400351
352 if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS)
Johannes Berg19d337d2009-06-02 13:01:37 +0200353 err = -EBUSY;
354 else
355 err = 0;
356 out:
357 mutex_unlock(&dev->mutex);
358 return err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400359}
360
Johannes Berg19d337d2009-06-02 13:01:37 +0200361static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400362{
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400363 bool new_rfk_state;
364 bool value;
365 u32 hci_result;
Johannes Berg19d337d2009-06-02 13:01:37 +0200366 struct toshiba_acpi_dev *dev = data;
367
368 mutex_lock(&dev->mutex);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400369
370 hci_result = hci_get_radio_state(&value);
Johannes Berg19d337d2009-06-02 13:01:37 +0200371 if (hci_result != HCI_SUCCESS) {
372 /* Can't do anything useful */
373 mutex_unlock(&dev->mutex);
Jiri Slaby82e77842009-08-06 15:57:51 -0700374 return;
Johannes Berg19d337d2009-06-02 13:01:37 +0200375 }
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400376
377 new_rfk_state = value;
378
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400379 mutex_unlock(&dev->mutex);
380
Johannes Berg19d337d2009-06-02 13:01:37 +0200381 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
382 bt_rfkill_set_block(data, true);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400383}
384
Johannes Berg19d337d2009-06-02 13:01:37 +0200385static const struct rfkill_ops toshiba_rfk_ops = {
386 .set_block = bt_rfkill_set_block,
387 .poll = bt_rfkill_poll,
388};
389
Len Brown4be44fc2005-08-05 00:44:28 -0400390static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
Holger Machtc9263552006-10-20 14:30:29 -0700391static struct backlight_device *toshiba_backlight_device;
Len Brown4be44fc2005-08-05 00:44:28 -0400392static int force_fan;
393static int last_key_event;
394static int key_event_valid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Holger Machtc9263552006-10-20 14:30:29 -0700396static int get_lcd(struct backlight_device *bd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
398 u32 hci_result;
399 u32 value;
400
401 hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result);
402 if (hci_result == HCI_SUCCESS) {
Holger Machtc9263552006-10-20 14:30:29 -0700403 return (value >> HCI_LCD_BRIGHTNESS_SHIFT);
404 } else
405 return -EFAULT;
406}
407
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800408static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -0700409{
410 int value = get_lcd(NULL);
411
412 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800413 seq_printf(m, "brightness: %d\n", value);
414 seq_printf(m, "brightness_levels: %d\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400415 HCI_LCD_BRIGHTNESS_LEVELS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 } else {
417 printk(MY_ERR "Error reading LCD brightness\n");
418 }
419
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800420 return 0;
421}
422
423static int lcd_proc_open(struct inode *inode, struct file *file)
424{
425 return single_open(file, lcd_proc_show, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426}
427
Holger Machtc9263552006-10-20 14:30:29 -0700428static int set_lcd(int value)
429{
430 u32 hci_result;
431
432 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
433 hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result);
434 if (hci_result != HCI_SUCCESS)
435 return -EFAULT;
436
437 return 0;
438}
439
440static int set_lcd_status(struct backlight_device *bd)
441{
Richard Purdie599a52d2007-02-10 23:07:48 +0000442 return set_lcd(bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -0700443}
444
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800445static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
446 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800448 char cmd[42];
449 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 int value;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800451 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800453 len = min(count, sizeof(cmd) - 1);
454 if (copy_from_user(cmd, buf, len))
455 return -EFAULT;
456 cmd[len] = '\0';
457
458 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800459 value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) {
Holger Machtc9263552006-10-20 14:30:29 -0700460 ret = set_lcd(value);
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800461 if (ret == 0)
462 ret = count;
463 } else {
Holger Machtc9263552006-10-20 14:30:29 -0700464 ret = -EINVAL;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800465 }
Holger Machtc9263552006-10-20 14:30:29 -0700466 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467}
468
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800469static const struct file_operations lcd_proc_fops = {
470 .owner = THIS_MODULE,
471 .open = lcd_proc_open,
472 .read = seq_read,
473 .llseek = seq_lseek,
474 .release = single_release,
475 .write = lcd_proc_write,
476};
477
478static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
480 u32 hci_result;
481 u32 value;
482
483 hci_read1(HCI_VIDEO_OUT, &value, &hci_result);
484 if (hci_result == HCI_SUCCESS) {
485 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
486 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400487 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800488 seq_printf(m, "lcd_out: %d\n", is_lcd);
489 seq_printf(m, "crt_out: %d\n", is_crt);
490 seq_printf(m, "tv_out: %d\n", is_tv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 } else {
492 printk(MY_ERR "Error reading video out status\n");
493 }
494
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800495 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496}
497
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800498static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800500 return single_open(file, video_proc_show, NULL);
501}
502
503static ssize_t video_proc_write(struct file *file, const char __user *buf,
504 size_t count, loff_t *pos)
505{
506 char *cmd, *buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 int value;
508 int remain = count;
509 int lcd_out = -1;
510 int crt_out = -1;
511 int tv_out = -1;
512 u32 hci_result;
Al Virob4482a42007-10-14 19:35:40 +0100513 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800515 cmd = kmalloc(count + 1, GFP_KERNEL);
516 if (!cmd)
517 return -ENOMEM;
518 if (copy_from_user(cmd, buf, count)) {
519 kfree(cmd);
520 return -EFAULT;
521 }
522 cmd[count] = '\0';
523
524 buffer = cmd;
525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 /* scan expression. Multiple expressions may be delimited with ;
527 *
528 * NOTE: to keep scanning simple, invalid fields are ignored
529 */
530 while (remain) {
531 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
532 lcd_out = value & 1;
533 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
534 crt_out = value & 1;
535 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
536 tv_out = value & 1;
537 /* advance to one character past the next ; */
538 do {
539 ++buffer;
540 --remain;
541 }
Len Brown4be44fc2005-08-05 00:44:28 -0400542 while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 }
544
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800545 kfree(cmd);
546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 hci_read1(HCI_VIDEO_OUT, &video_out, &hci_result);
548 if (hci_result == HCI_SUCCESS) {
Harvey Harrison9e113e02008-09-22 14:37:29 -0700549 unsigned int new_video_out = video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 if (lcd_out != -1)
551 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
552 if (crt_out != -1)
553 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
554 if (tv_out != -1)
555 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
556 /* To avoid unnecessary video disruption, only write the new
557 * video setting if something changed. */
558 if (new_video_out != video_out)
559 write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
560 } else {
561 return -EFAULT;
562 }
563
564 return count;
565}
566
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800567static const struct file_operations video_proc_fops = {
568 .owner = THIS_MODULE,
569 .open = video_proc_open,
570 .read = seq_read,
571 .llseek = seq_lseek,
572 .release = single_release,
573 .write = video_proc_write,
574};
575
576static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577{
578 u32 hci_result;
579 u32 value;
580
581 hci_read1(HCI_FAN, &value, &hci_result);
582 if (hci_result == HCI_SUCCESS) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800583 seq_printf(m, "running: %d\n", (value > 0));
584 seq_printf(m, "force_on: %d\n", force_fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 } else {
586 printk(MY_ERR "Error reading fan status\n");
587 }
588
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800589 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
591
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800592static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800594 return single_open(file, fan_proc_show, NULL);
595}
596
597static ssize_t fan_proc_write(struct file *file, const char __user *buf,
598 size_t count, loff_t *pos)
599{
600 char cmd[42];
601 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 int value;
603 u32 hci_result;
604
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800605 len = min(count, sizeof(cmd) - 1);
606 if (copy_from_user(cmd, buf, len))
607 return -EFAULT;
608 cmd[len] = '\0';
609
610 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
Len Brown4be44fc2005-08-05 00:44:28 -0400611 value >= 0 && value <= 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 hci_write1(HCI_FAN, value, &hci_result);
613 if (hci_result != HCI_SUCCESS)
614 return -EFAULT;
615 else
616 force_fan = value;
617 } else {
618 return -EINVAL;
619 }
620
621 return count;
622}
623
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800624static const struct file_operations fan_proc_fops = {
625 .owner = THIS_MODULE,
626 .open = fan_proc_open,
627 .read = seq_read,
628 .llseek = seq_lseek,
629 .release = single_release,
630 .write = fan_proc_write,
631};
632
633static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634{
635 u32 hci_result;
636 u32 value;
637
638 if (!key_event_valid) {
639 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
640 if (hci_result == HCI_SUCCESS) {
641 key_event_valid = 1;
642 last_key_event = value;
643 } else if (hci_result == HCI_EMPTY) {
644 /* better luck next time */
645 } else if (hci_result == HCI_NOT_SUPPORTED) {
646 /* This is a workaround for an unresolved issue on
647 * some machines where system events sporadically
648 * become disabled. */
649 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
650 printk(MY_NOTICE "Re-enabled hotkeys\n");
651 } else {
652 printk(MY_ERR "Error reading hotkey status\n");
653 goto end;
654 }
655 }
656
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800657 seq_printf(m, "hotkey_ready: %d\n", key_event_valid);
658 seq_printf(m, "hotkey: 0x%04x\n", last_key_event);
659end:
660 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661}
662
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800663static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800665 return single_open(file, keys_proc_show, NULL);
666}
667
668static ssize_t keys_proc_write(struct file *file, const char __user *buf,
669 size_t count, loff_t *pos)
670{
671 char cmd[42];
672 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 int value;
674
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800675 len = min(count, sizeof(cmd) - 1);
676 if (copy_from_user(cmd, buf, len))
677 return -EFAULT;
678 cmd[len] = '\0';
679
680 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 key_event_valid = 0;
682 } else {
683 return -EINVAL;
684 }
685
686 return count;
687}
688
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800689static const struct file_operations keys_proc_fops = {
690 .owner = THIS_MODULE,
691 .open = keys_proc_open,
692 .read = seq_read,
693 .llseek = seq_lseek,
694 .release = single_release,
695 .write = keys_proc_write,
696};
697
698static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800700 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
701 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
702 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703}
704
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800705static int version_proc_open(struct inode *inode, struct file *file)
706{
707 return single_open(file, version_proc_show, PDE(inode)->data);
708}
709
710static const struct file_operations version_proc_fops = {
711 .owner = THIS_MODULE,
712 .open = version_proc_open,
713 .read = seq_read,
714 .llseek = seq_lseek,
715 .release = single_release,
716};
717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718/* proc and module init
719 */
720
721#define PROC_TOSHIBA "toshiba"
722
Len Brown4be44fc2005-08-05 00:44:28 -0400723static acpi_status __init add_device(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800725 proc_create("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, &lcd_proc_fops);
726 proc_create("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, &video_proc_fops);
727 proc_create("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, &fan_proc_fops);
728 proc_create("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, &keys_proc_fops);
729 proc_create("version", S_IRUGO, toshiba_proc_dir, &version_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731 return AE_OK;
732}
733
Randy Dunlapb1d93de2007-06-16 10:16:02 -0700734static acpi_status remove_device(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800736 remove_proc_entry("lcd", toshiba_proc_dir);
737 remove_proc_entry("video", toshiba_proc_dir);
738 remove_proc_entry("fan", toshiba_proc_dir);
739 remove_proc_entry("keys", toshiba_proc_dir);
740 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 return AE_OK;
742}
743
Richard Purdie599a52d2007-02-10 23:07:48 +0000744static struct backlight_ops toshiba_backlight_data = {
Holger Machtc9263552006-10-20 14:30:29 -0700745 .get_brightness = get_lcd,
746 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -0700747};
748
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800749static struct key_entry *toshiba_acpi_get_entry_by_scancode(unsigned int code)
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500750{
751 struct key_entry *key;
752
753 for (key = toshiba_acpi_keymap; key->type != KE_END; key++)
754 if (code == key->code)
755 return key;
756
757 return NULL;
758}
759
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800760static struct key_entry *toshiba_acpi_get_entry_by_keycode(unsigned int code)
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500761{
762 struct key_entry *key;
763
764 for (key = toshiba_acpi_keymap; key->type != KE_END; key++)
765 if (code == key->keycode && key->type == KE_KEY)
766 return key;
767
768 return NULL;
769}
770
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800771static int toshiba_acpi_getkeycode(struct input_dev *dev,
772 unsigned int scancode, unsigned int *keycode)
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500773{
774 struct key_entry *key = toshiba_acpi_get_entry_by_scancode(scancode);
775
776 if (key && key->type == KE_KEY) {
777 *keycode = key->keycode;
778 return 0;
779 }
780
781 return -EINVAL;
782}
783
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800784static int toshiba_acpi_setkeycode(struct input_dev *dev,
785 unsigned int scancode, unsigned int keycode)
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500786{
787 struct key_entry *key;
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800788 unsigned int old_keycode;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500789
790 key = toshiba_acpi_get_entry_by_scancode(scancode);
791 if (key && key->type == KE_KEY) {
792 old_keycode = key->keycode;
793 key->keycode = keycode;
794 set_bit(keycode, dev->keybit);
795 if (!toshiba_acpi_get_entry_by_keycode(old_keycode))
796 clear_bit(old_keycode, dev->keybit);
797 return 0;
798 }
799
800 return -EINVAL;
801}
802
803static void toshiba_acpi_notify(acpi_handle handle, u32 event, void *context)
804{
805 u32 hci_result, value;
806 struct key_entry *key;
807
808 if (event != 0x80)
809 return;
810 do {
811 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
812 if (hci_result == HCI_SUCCESS) {
813 if (value == 0x100)
814 continue;
Frans Popb4663012010-03-01 09:50:46 -0500815 /* act on key press; ignore key release */
816 if (value & 0x80)
817 continue;
818
819 key = toshiba_acpi_get_entry_by_scancode
820 (value);
821 if (!key) {
822 printk(MY_INFO "Unknown key %x\n",
823 value);
824 continue;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500825 }
Frans Popb4663012010-03-01 09:50:46 -0500826 input_report_key(toshiba_acpi.hotkey_dev,
827 key->keycode, 1);
828 input_sync(toshiba_acpi.hotkey_dev);
829 input_report_key(toshiba_acpi.hotkey_dev,
830 key->keycode, 0);
831 input_sync(toshiba_acpi.hotkey_dev);
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500832 } else if (hci_result == HCI_NOT_SUPPORTED) {
833 /* This is a workaround for an unresolved issue on
834 * some machines where system events sporadically
835 * become disabled. */
836 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
837 printk(MY_NOTICE "Re-enabled hotkeys\n");
838 }
839 } while (hci_result != HCI_EMPTY);
840}
841
842static int toshiba_acpi_setup_keyboard(char *device)
843{
844 acpi_status status;
845 acpi_handle handle;
846 int result;
847 const struct key_entry *key;
848
849 status = acpi_get_handle(NULL, device, &handle);
850 if (ACPI_FAILURE(status)) {
851 printk(MY_INFO "Unable to get notification device\n");
852 return -ENODEV;
853 }
854
855 toshiba_acpi.handle = handle;
856
857 status = acpi_evaluate_object(handle, "ENAB", NULL, NULL);
858 if (ACPI_FAILURE(status)) {
859 printk(MY_INFO "Unable to enable hotkeys\n");
860 return -ENODEV;
861 }
862
863 status = acpi_install_notify_handler(handle, ACPI_DEVICE_NOTIFY,
864 toshiba_acpi_notify, NULL);
865 if (ACPI_FAILURE(status)) {
866 printk(MY_INFO "Unable to install hotkey notification\n");
867 return -ENODEV;
868 }
869
870 toshiba_acpi.hotkey_dev = input_allocate_device();
871 if (!toshiba_acpi.hotkey_dev) {
872 printk(MY_INFO "Unable to register input device\n");
873 return -ENOMEM;
874 }
875
876 toshiba_acpi.hotkey_dev->name = "Toshiba input device";
877 toshiba_acpi.hotkey_dev->phys = device;
878 toshiba_acpi.hotkey_dev->id.bustype = BUS_HOST;
879 toshiba_acpi.hotkey_dev->getkeycode = toshiba_acpi_getkeycode;
880 toshiba_acpi.hotkey_dev->setkeycode = toshiba_acpi_setkeycode;
881
882 for (key = toshiba_acpi_keymap; key->type != KE_END; key++) {
883 set_bit(EV_KEY, toshiba_acpi.hotkey_dev->evbit);
884 set_bit(key->keycode, toshiba_acpi.hotkey_dev->keybit);
885 }
886
887 result = input_register_device(toshiba_acpi.hotkey_dev);
888 if (result) {
889 printk(MY_INFO "Unable to register input device\n");
890 return result;
891 }
892
893 return 0;
894}
895
Sam Ravnborgb2b77b22007-06-01 00:47:12 -0700896static void toshiba_acpi_exit(void)
Holger Machtc9263552006-10-20 14:30:29 -0700897{
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500898 if (toshiba_acpi.hotkey_dev)
899 input_unregister_device(toshiba_acpi.hotkey_dev);
900
Johannes Berg19d337d2009-06-02 13:01:37 +0200901 if (toshiba_acpi.bt_rfk) {
902 rfkill_unregister(toshiba_acpi.bt_rfk);
903 rfkill_destroy(toshiba_acpi.bt_rfk);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400904 }
905
Holger Machtc9263552006-10-20 14:30:29 -0700906 if (toshiba_backlight_device)
907 backlight_device_unregister(toshiba_backlight_device);
908
909 remove_device();
910
911 if (toshiba_proc_dir)
912 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
913
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500914 acpi_remove_notify_handler(toshiba_acpi.handle, ACPI_DEVICE_NOTIFY,
915 toshiba_acpi_notify);
916
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400917 platform_device_unregister(toshiba_acpi.p_dev);
918
Holger Machtc9263552006-10-20 14:30:29 -0700919 return;
920}
921
Len Brown4be44fc2005-08-05 00:44:28 -0400922static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923{
924 acpi_status status = AE_OK;
925 u32 hci_result;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400926 bool bt_present;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400927 int ret = 0;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500928 struct backlight_properties props;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
930 if (acpi_disabled)
931 return -ENODEV;
Luming Yufb9802f2005-03-18 18:03:45 -0500932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 /* simple device detection: look for HCI method */
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500934 if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD)) {
935 method_hci = TOSH_INTERFACE_1 GHCI_METHOD;
936 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1))
937 printk(MY_INFO "Unable to activate hotkeys\n");
938 } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD)) {
939 method_hci = TOSH_INTERFACE_2 GHCI_METHOD;
940 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2))
941 printk(MY_INFO "Unable to activate hotkeys\n");
942 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 return -ENODEV;
944
945 printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400946 TOSHIBA_ACPI_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 printk(MY_INFO " HCI method: %s\n", method_hci);
948
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400949 mutex_init(&toshiba_acpi.mutex);
950
951 toshiba_acpi.p_dev = platform_device_register_simple("toshiba_acpi",
952 -1, NULL, 0);
953 if (IS_ERR(toshiba_acpi.p_dev)) {
954 ret = PTR_ERR(toshiba_acpi.p_dev);
955 printk(MY_ERR "unable to register platform device\n");
956 toshiba_acpi.p_dev = NULL;
957 toshiba_acpi_exit();
958 return ret;
959 }
960
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 force_fan = 0;
962 key_event_valid = 0;
963
964 /* enable event fifo */
965 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
966
967 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
968 if (!toshiba_proc_dir) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400969 toshiba_acpi_exit();
970 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 status = add_device();
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400973 if (ACPI_FAILURE(status)) {
974 toshiba_acpi_exit();
975 return -ENODEV;
976 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 }
978
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500979 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400980 toshiba_backlight_device = backlight_device_register("toshiba",
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500981 &toshiba_acpi.p_dev->dev,
982 NULL,
983 &toshiba_backlight_data,
984 &props);
Holger Machtc9263552006-10-20 14:30:29 -0700985 if (IS_ERR(toshiba_backlight_device)) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400986 ret = PTR_ERR(toshiba_backlight_device);
Andrey Borzenkov12993422007-11-14 16:58:28 -0800987
Holger Machtc9263552006-10-20 14:30:29 -0700988 printk(KERN_ERR "Could not register toshiba backlight device\n");
989 toshiba_backlight_device = NULL;
990 toshiba_acpi_exit();
Andrey Borzenkov12993422007-11-14 16:58:28 -0800991 return ret;
Holger Machtc9263552006-10-20 14:30:29 -0700992 }
993
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400994 /* Register rfkill switch for Bluetooth */
995 if (hci_get_bt_present(&bt_present) == HCI_SUCCESS && bt_present) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200996 toshiba_acpi.bt_rfk = rfkill_alloc(toshiba_acpi.bt_name,
997 &toshiba_acpi.p_dev->dev,
998 RFKILL_TYPE_BLUETOOTH,
999 &toshiba_rfk_ops,
1000 &toshiba_acpi);
1001 if (!toshiba_acpi.bt_rfk) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001002 printk(MY_ERR "unable to allocate rfkill device\n");
1003 toshiba_acpi_exit();
1004 return -ENOMEM;
1005 }
1006
Johannes Berg19d337d2009-06-02 13:01:37 +02001007 ret = rfkill_register(toshiba_acpi.bt_rfk);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001008 if (ret) {
1009 printk(MY_ERR "unable to register rfkill device\n");
Johannes Berg19d337d2009-06-02 13:01:37 +02001010 rfkill_destroy(toshiba_acpi.bt_rfk);
Frederik Deweerdt38aefbc2008-12-15 13:54:19 -08001011 toshiba_acpi_exit();
1012 return ret;
1013 }
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001014 }
1015
1016 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017}
1018
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019module_init(toshiba_acpi_init);
1020module_exit(toshiba_acpi_exit);