blob: 26c211724acf7cb2374f46a7ddfcdeabe6e3a1d0 [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>
Holger Machtc9263552006-10-20 14:30:29 -070050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <asm/uaccess.h>
52
53#include <acpi/acpi_drivers.h>
54
55MODULE_AUTHOR("John Belmonte");
56MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
57MODULE_LICENSE("GPL");
58
59#define MY_LOGPREFIX "toshiba_acpi: "
60#define MY_ERR KERN_ERR MY_LOGPREFIX
61#define MY_NOTICE KERN_NOTICE MY_LOGPREFIX
62#define MY_INFO KERN_INFO MY_LOGPREFIX
63
64/* Toshiba ACPI method paths */
65#define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM"
Matthew Garrett6335e4d2010-02-25 15:20:54 -050066#define TOSH_INTERFACE_1 "\\_SB_.VALD"
67#define TOSH_INTERFACE_2 "\\_SB_.VALZ"
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
Matthew Garrett6335e4d2010-02-25 15:20:54 -050069#define GHCI_METHOD ".GHCI"
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71/* Toshiba HCI interface definitions
72 *
73 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
74 * be uniform across all their models. Ideally we would just call
75 * dedicated ACPI methods instead of using this primitive interface.
76 * However the ACPI methods seem to be incomplete in some areas (for
77 * example they allow setting, but not reading, the LCD brightness value),
78 * so this is still useful.
79 */
80
81#define HCI_WORDS 6
82
83/* operations */
84#define HCI_SET 0xff00
85#define HCI_GET 0xfe00
86
87/* return codes */
88#define HCI_SUCCESS 0x0000
89#define HCI_FAILURE 0x1000
90#define HCI_NOT_SUPPORTED 0x8000
91#define HCI_EMPTY 0x8c00
92
93/* registers */
94#define HCI_FAN 0x0004
95#define HCI_SYSTEM_EVENT 0x0016
96#define HCI_VIDEO_OUT 0x001c
97#define HCI_HOTKEY_EVENT 0x001e
98#define HCI_LCD_BRIGHTNESS 0x002a
philipl@overt.orgc41a40c2008-08-30 11:57:39 -040099#define HCI_WIRELESS 0x0056
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101/* field definitions */
102#define HCI_LCD_BRIGHTNESS_BITS 3
103#define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
104#define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
105#define HCI_VIDEO_OUT_LCD 0x1
106#define HCI_VIDEO_OUT_CRT 0x2
107#define HCI_VIDEO_OUT_TV 0x4
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400108#define HCI_WIRELESS_KILL_SWITCH 0x01
109#define HCI_WIRELESS_BT_PRESENT 0x0f
110#define HCI_WIRELESS_BT_ATTACH 0x40
111#define HCI_WIRELESS_BT_POWER 0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800113static const struct acpi_device_id toshiba_device_ids[] = {
114 {"TOS6200", 0},
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400115 {"TOS6208", 0},
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800116 {"TOS1900", 0},
117 {"", 0},
118};
119MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
120
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500121struct key_entry {
122 char type;
123 u16 code;
124 u16 keycode;
125};
126
127enum {KE_KEY, KE_END};
128
129static struct key_entry toshiba_acpi_keymap[] = {
130 {KE_KEY, 0x101, KEY_MUTE},
131 {KE_KEY, 0x13b, KEY_COFFEE},
132 {KE_KEY, 0x13c, KEY_BATTERY},
133 {KE_KEY, 0x13d, KEY_SLEEP},
134 {KE_KEY, 0x13e, KEY_SUSPEND},
135 {KE_KEY, 0x13f, KEY_SWITCHVIDEOMODE},
136 {KE_KEY, 0x140, KEY_BRIGHTNESSDOWN},
137 {KE_KEY, 0x141, KEY_BRIGHTNESSUP},
138 {KE_KEY, 0x142, KEY_WLAN},
139 {KE_KEY, 0x143, KEY_PROG1},
140 {KE_KEY, 0xb05, KEY_PROG2},
141 {KE_KEY, 0xb06, KEY_WWW},
142 {KE_KEY, 0xb07, KEY_MAIL},
143 {KE_KEY, 0xb30, KEY_STOP},
144 {KE_KEY, 0xb31, KEY_PREVIOUSSONG},
145 {KE_KEY, 0xb32, KEY_NEXTSONG},
146 {KE_KEY, 0xb33, KEY_PLAYPAUSE},
147 {KE_KEY, 0xb5a, KEY_MEDIA},
148 {KE_END, 0, 0},
149};
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151/* utility
152 */
153
Len Brown4be44fc2005-08-05 00:44:28 -0400154static __inline__ void _set_bit(u32 * word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
156 *word = (*word & ~mask) | (mask * value);
157}
158
159/* acpi interface wrappers
160 */
161
Len Brown4be44fc2005-08-05 00:44:28 -0400162static int is_valid_acpi_path(const char *methodName)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
164 acpi_handle handle;
165 acpi_status status;
166
Len Brown4be44fc2005-08-05 00:44:28 -0400167 status = acpi_get_handle(NULL, (char *)methodName, &handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return !ACPI_FAILURE(status);
169}
170
Len Brown4be44fc2005-08-05 00:44:28 -0400171static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
173 struct acpi_object_list params;
174 union acpi_object in_objs[1];
175 acpi_status status;
176
Ahmed S. Darwishb2b79102007-02-06 16:14:43 -0800177 params.count = ARRAY_SIZE(in_objs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 params.pointer = in_objs;
179 in_objs[0].type = ACPI_TYPE_INTEGER;
180 in_objs[0].integer.value = val;
181
Len Brown4be44fc2005-08-05 00:44:28 -0400182 status = acpi_evaluate_object(NULL, (char *)methodName, &params, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 return (status == AE_OK);
184}
185
186#if 0
Len Brown4be44fc2005-08-05 00:44:28 -0400187static int read_acpi_int(const char *methodName, int *pVal)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
189 struct acpi_buffer results;
190 union acpi_object out_objs[1];
191 acpi_status status;
192
193 results.length = sizeof(out_objs);
194 results.pointer = out_objs;
195
Len Brown4be44fc2005-08-05 00:44:28 -0400196 status = acpi_evaluate_object(0, (char *)methodName, 0, &results);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 *pVal = out_objs[0].integer.value;
198
199 return (status == AE_OK) && (out_objs[0].type == ACPI_TYPE_INTEGER);
200}
201#endif
202
Len Brown4be44fc2005-08-05 00:44:28 -0400203static const char *method_hci /*= 0*/ ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205/* Perform a raw HCI call. Here we don't care about input or output buffer
206 * format.
207 */
Len Brown4be44fc2005-08-05 00:44:28 -0400208static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
210 struct acpi_object_list params;
211 union acpi_object in_objs[HCI_WORDS];
212 struct acpi_buffer results;
Len Brown4be44fc2005-08-05 00:44:28 -0400213 union acpi_object out_objs[HCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 acpi_status status;
215 int i;
216
217 params.count = HCI_WORDS;
218 params.pointer = in_objs;
219 for (i = 0; i < HCI_WORDS; ++i) {
220 in_objs[i].type = ACPI_TYPE_INTEGER;
221 in_objs[i].integer.value = in[i];
222 }
223
224 results.length = sizeof(out_objs);
225 results.pointer = out_objs;
226
Len Brown4be44fc2005-08-05 00:44:28 -0400227 status = acpi_evaluate_object(NULL, (char *)method_hci, &params,
228 &results);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
230 for (i = 0; i < out_objs->package.count; ++i) {
231 out[i] = out_objs->package.elements[i].integer.value;
232 }
233 }
234
235 return status;
236}
237
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400238/* common hci tasks (get or set one or two value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 *
240 * In addition to the ACPI status, the HCI system returns a result which
241 * may be useful (such as "not supported").
242 */
243
Len Brown4be44fc2005-08-05 00:44:28 -0400244static acpi_status hci_write1(u32 reg, u32 in1, u32 * result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
246 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
247 u32 out[HCI_WORDS];
248 acpi_status status = hci_raw(in, out);
249 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
250 return status;
251}
252
Len Brown4be44fc2005-08-05 00:44:28 -0400253static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
256 u32 out[HCI_WORDS];
257 acpi_status status = hci_raw(in, out);
258 *out1 = out[2];
259 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
260 return status;
261}
262
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400263static acpi_status hci_write2(u32 reg, u32 in1, u32 in2, u32 *result)
264{
265 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
266 u32 out[HCI_WORDS];
267 acpi_status status = hci_raw(in, out);
268 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
269 return status;
270}
271
272static acpi_status hci_read2(u32 reg, u32 *out1, u32 *out2, u32 *result)
273{
274 u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
275 u32 out[HCI_WORDS];
276 acpi_status status = hci_raw(in, out);
277 *out1 = out[2];
278 *out2 = out[3];
279 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
280 return status;
281}
282
283struct toshiba_acpi_dev {
284 struct platform_device *p_dev;
Johannes Berg19d337d2009-06-02 13:01:37 +0200285 struct rfkill *bt_rfk;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500286 struct input_dev *hotkey_dev;
287 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
294static struct toshiba_acpi_dev toshiba_acpi = {
295 .bt_name = "Toshiba Bluetooth",
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400296};
297
298/* Bluetooth rfkill handlers */
299
300static u32 hci_get_bt_present(bool *present)
301{
302 u32 hci_result;
303 u32 value, value2;
304
305 value = 0;
306 value2 = 0;
307 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
308 if (hci_result == HCI_SUCCESS)
309 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
310
311 return hci_result;
312}
313
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400314static u32 hci_get_radio_state(bool *radio_state)
315{
316 u32 hci_result;
317 u32 value, value2;
318
319 value = 0;
320 value2 = 0x0001;
321 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
322
323 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
324 return hci_result;
325}
326
Johannes Berg19d337d2009-06-02 13:01:37 +0200327static int bt_rfkill_set_block(void *data, bool blocked)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400328{
Johannes Berg19d337d2009-06-02 13:01:37 +0200329 struct toshiba_acpi_dev *dev = data;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400330 u32 result1, result2;
331 u32 value;
Johannes Berg19d337d2009-06-02 13:01:37 +0200332 int err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400333 bool radio_state;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400334
Johannes Berg19d337d2009-06-02 13:01:37 +0200335 value = (blocked == false);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400336
337 mutex_lock(&dev->mutex);
Johannes Berg19d337d2009-06-02 13:01:37 +0200338 if (hci_get_radio_state(&radio_state) != HCI_SUCCESS) {
339 err = -EBUSY;
340 goto out;
341 }
342
343 if (!radio_state) {
344 err = 0;
345 goto out;
346 }
347
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400348 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
349 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400350
351 if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS)
Johannes Berg19d337d2009-06-02 13:01:37 +0200352 err = -EBUSY;
353 else
354 err = 0;
355 out:
356 mutex_unlock(&dev->mutex);
357 return err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400358}
359
Johannes Berg19d337d2009-06-02 13:01:37 +0200360static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400361{
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400362 bool new_rfk_state;
363 bool value;
364 u32 hci_result;
Johannes Berg19d337d2009-06-02 13:01:37 +0200365 struct toshiba_acpi_dev *dev = data;
366
367 mutex_lock(&dev->mutex);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400368
369 hci_result = hci_get_radio_state(&value);
Johannes Berg19d337d2009-06-02 13:01:37 +0200370 if (hci_result != HCI_SUCCESS) {
371 /* Can't do anything useful */
372 mutex_unlock(&dev->mutex);
Jiri Slaby82e77842009-08-06 15:57:51 -0700373 return;
Johannes Berg19d337d2009-06-02 13:01:37 +0200374 }
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400375
376 new_rfk_state = value;
377
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400378 mutex_unlock(&dev->mutex);
379
Johannes Berg19d337d2009-06-02 13:01:37 +0200380 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
381 bt_rfkill_set_block(data, true);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400382}
383
Johannes Berg19d337d2009-06-02 13:01:37 +0200384static const struct rfkill_ops toshiba_rfk_ops = {
385 .set_block = bt_rfkill_set_block,
386 .poll = bt_rfkill_poll,
387};
388
Len Brown4be44fc2005-08-05 00:44:28 -0400389static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
Holger Machtc9263552006-10-20 14:30:29 -0700390static struct backlight_device *toshiba_backlight_device;
Len Brown4be44fc2005-08-05 00:44:28 -0400391static int force_fan;
392static int last_key_event;
393static int key_event_valid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Holger Machtc9263552006-10-20 14:30:29 -0700395static int get_lcd(struct backlight_device *bd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
397 u32 hci_result;
398 u32 value;
399
400 hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result);
401 if (hci_result == HCI_SUCCESS) {
Holger Machtc9263552006-10-20 14:30:29 -0700402 return (value >> HCI_LCD_BRIGHTNESS_SHIFT);
403 } else
404 return -EFAULT;
405}
406
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800407static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -0700408{
409 int value = get_lcd(NULL);
410
411 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800412 seq_printf(m, "brightness: %d\n", value);
413 seq_printf(m, "brightness_levels: %d\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400414 HCI_LCD_BRIGHTNESS_LEVELS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 } else {
416 printk(MY_ERR "Error reading LCD brightness\n");
417 }
418
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800419 return 0;
420}
421
422static int lcd_proc_open(struct inode *inode, struct file *file)
423{
424 return single_open(file, lcd_proc_show, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
426
Holger Machtc9263552006-10-20 14:30:29 -0700427static int set_lcd(int value)
428{
429 u32 hci_result;
430
431 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
432 hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result);
433 if (hci_result != HCI_SUCCESS)
434 return -EFAULT;
435
436 return 0;
437}
438
439static int set_lcd_status(struct backlight_device *bd)
440{
Richard Purdie599a52d2007-02-10 23:07:48 +0000441 return set_lcd(bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -0700442}
443
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800444static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
445 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800447 char cmd[42];
448 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 int value;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800450 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800452 len = min(count, sizeof(cmd) - 1);
453 if (copy_from_user(cmd, buf, len))
454 return -EFAULT;
455 cmd[len] = '\0';
456
457 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800458 value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) {
Holger Machtc9263552006-10-20 14:30:29 -0700459 ret = set_lcd(value);
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800460 if (ret == 0)
461 ret = count;
462 } else {
Holger Machtc9263552006-10-20 14:30:29 -0700463 ret = -EINVAL;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800464 }
Holger Machtc9263552006-10-20 14:30:29 -0700465 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466}
467
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800468static const struct file_operations lcd_proc_fops = {
469 .owner = THIS_MODULE,
470 .open = lcd_proc_open,
471 .read = seq_read,
472 .llseek = seq_lseek,
473 .release = single_release,
474 .write = lcd_proc_write,
475};
476
477static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
479 u32 hci_result;
480 u32 value;
481
482 hci_read1(HCI_VIDEO_OUT, &value, &hci_result);
483 if (hci_result == HCI_SUCCESS) {
484 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
485 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400486 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800487 seq_printf(m, "lcd_out: %d\n", is_lcd);
488 seq_printf(m, "crt_out: %d\n", is_crt);
489 seq_printf(m, "tv_out: %d\n", is_tv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 } else {
491 printk(MY_ERR "Error reading video out status\n");
492 }
493
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800494 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495}
496
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800497static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800499 return single_open(file, video_proc_show, NULL);
500}
501
502static ssize_t video_proc_write(struct file *file, const char __user *buf,
503 size_t count, loff_t *pos)
504{
505 char *cmd, *buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 int value;
507 int remain = count;
508 int lcd_out = -1;
509 int crt_out = -1;
510 int tv_out = -1;
511 u32 hci_result;
Al Virob4482a42007-10-14 19:35:40 +0100512 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800514 cmd = kmalloc(count + 1, GFP_KERNEL);
515 if (!cmd)
516 return -ENOMEM;
517 if (copy_from_user(cmd, buf, count)) {
518 kfree(cmd);
519 return -EFAULT;
520 }
521 cmd[count] = '\0';
522
523 buffer = cmd;
524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 /* scan expression. Multiple expressions may be delimited with ;
526 *
527 * NOTE: to keep scanning simple, invalid fields are ignored
528 */
529 while (remain) {
530 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
531 lcd_out = value & 1;
532 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
533 crt_out = value & 1;
534 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
535 tv_out = value & 1;
536 /* advance to one character past the next ; */
537 do {
538 ++buffer;
539 --remain;
540 }
Len Brown4be44fc2005-08-05 00:44:28 -0400541 while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 }
543
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800544 kfree(cmd);
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 hci_read1(HCI_VIDEO_OUT, &video_out, &hci_result);
547 if (hci_result == HCI_SUCCESS) {
Harvey Harrison9e113e02008-09-22 14:37:29 -0700548 unsigned int new_video_out = video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 if (lcd_out != -1)
550 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
551 if (crt_out != -1)
552 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
553 if (tv_out != -1)
554 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
555 /* To avoid unnecessary video disruption, only write the new
556 * video setting if something changed. */
557 if (new_video_out != video_out)
558 write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
559 } else {
560 return -EFAULT;
561 }
562
563 return count;
564}
565
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800566static const struct file_operations video_proc_fops = {
567 .owner = THIS_MODULE,
568 .open = video_proc_open,
569 .read = seq_read,
570 .llseek = seq_lseek,
571 .release = single_release,
572 .write = video_proc_write,
573};
574
575static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
577 u32 hci_result;
578 u32 value;
579
580 hci_read1(HCI_FAN, &value, &hci_result);
581 if (hci_result == HCI_SUCCESS) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800582 seq_printf(m, "running: %d\n", (value > 0));
583 seq_printf(m, "force_on: %d\n", force_fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 } else {
585 printk(MY_ERR "Error reading fan status\n");
586 }
587
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800588 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589}
590
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800591static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800593 return single_open(file, fan_proc_show, NULL);
594}
595
596static ssize_t fan_proc_write(struct file *file, const char __user *buf,
597 size_t count, loff_t *pos)
598{
599 char cmd[42];
600 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 int value;
602 u32 hci_result;
603
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800604 len = min(count, sizeof(cmd) - 1);
605 if (copy_from_user(cmd, buf, len))
606 return -EFAULT;
607 cmd[len] = '\0';
608
609 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
Len Brown4be44fc2005-08-05 00:44:28 -0400610 value >= 0 && value <= 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 hci_write1(HCI_FAN, value, &hci_result);
612 if (hci_result != HCI_SUCCESS)
613 return -EFAULT;
614 else
615 force_fan = value;
616 } else {
617 return -EINVAL;
618 }
619
620 return count;
621}
622
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800623static const struct file_operations fan_proc_fops = {
624 .owner = THIS_MODULE,
625 .open = fan_proc_open,
626 .read = seq_read,
627 .llseek = seq_lseek,
628 .release = single_release,
629 .write = fan_proc_write,
630};
631
632static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
634 u32 hci_result;
635 u32 value;
636
637 if (!key_event_valid) {
638 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
639 if (hci_result == HCI_SUCCESS) {
640 key_event_valid = 1;
641 last_key_event = value;
642 } else if (hci_result == HCI_EMPTY) {
643 /* better luck next time */
644 } else if (hci_result == HCI_NOT_SUPPORTED) {
645 /* This is a workaround for an unresolved issue on
646 * some machines where system events sporadically
647 * become disabled. */
648 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
649 printk(MY_NOTICE "Re-enabled hotkeys\n");
650 } else {
651 printk(MY_ERR "Error reading hotkey status\n");
652 goto end;
653 }
654 }
655
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800656 seq_printf(m, "hotkey_ready: %d\n", key_event_valid);
657 seq_printf(m, "hotkey: 0x%04x\n", last_key_event);
658end:
659 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660}
661
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800662static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800664 return single_open(file, keys_proc_show, NULL);
665}
666
667static ssize_t keys_proc_write(struct file *file, const char __user *buf,
668 size_t count, loff_t *pos)
669{
670 char cmd[42];
671 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 int value;
673
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800674 len = min(count, sizeof(cmd) - 1);
675 if (copy_from_user(cmd, buf, len))
676 return -EFAULT;
677 cmd[len] = '\0';
678
679 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 key_event_valid = 0;
681 } else {
682 return -EINVAL;
683 }
684
685 return count;
686}
687
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800688static const struct file_operations keys_proc_fops = {
689 .owner = THIS_MODULE,
690 .open = keys_proc_open,
691 .read = seq_read,
692 .llseek = seq_lseek,
693 .release = single_release,
694 .write = keys_proc_write,
695};
696
697static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800699 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
700 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
701 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702}
703
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800704static int version_proc_open(struct inode *inode, struct file *file)
705{
706 return single_open(file, version_proc_show, PDE(inode)->data);
707}
708
709static const struct file_operations version_proc_fops = {
710 .owner = THIS_MODULE,
711 .open = version_proc_open,
712 .read = seq_read,
713 .llseek = seq_lseek,
714 .release = single_release,
715};
716
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717/* proc and module init
718 */
719
720#define PROC_TOSHIBA "toshiba"
721
Len Brown4be44fc2005-08-05 00:44:28 -0400722static acpi_status __init add_device(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800724 proc_create("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, &lcd_proc_fops);
725 proc_create("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, &video_proc_fops);
726 proc_create("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, &fan_proc_fops);
727 proc_create("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, &keys_proc_fops);
728 proc_create("version", S_IRUGO, toshiba_proc_dir, &version_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 return AE_OK;
731}
732
Randy Dunlapb1d93de2007-06-16 10:16:02 -0700733static acpi_status remove_device(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800735 remove_proc_entry("lcd", toshiba_proc_dir);
736 remove_proc_entry("video", toshiba_proc_dir);
737 remove_proc_entry("fan", toshiba_proc_dir);
738 remove_proc_entry("keys", toshiba_proc_dir);
739 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 return AE_OK;
741}
742
Richard Purdie599a52d2007-02-10 23:07:48 +0000743static struct backlight_ops toshiba_backlight_data = {
Holger Machtc9263552006-10-20 14:30:29 -0700744 .get_brightness = get_lcd,
745 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -0700746};
747
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500748static struct key_entry *toshiba_acpi_get_entry_by_scancode(int code)
749{
750 struct key_entry *key;
751
752 for (key = toshiba_acpi_keymap; key->type != KE_END; key++)
753 if (code == key->code)
754 return key;
755
756 return NULL;
757}
758
759static struct key_entry *toshiba_acpi_get_entry_by_keycode(int code)
760{
761 struct key_entry *key;
762
763 for (key = toshiba_acpi_keymap; key->type != KE_END; key++)
764 if (code == key->keycode && key->type == KE_KEY)
765 return key;
766
767 return NULL;
768}
769
770static int toshiba_acpi_getkeycode(struct input_dev *dev, int scancode,
771 int *keycode)
772{
773 struct key_entry *key = toshiba_acpi_get_entry_by_scancode(scancode);
774
775 if (key && key->type == KE_KEY) {
776 *keycode = key->keycode;
777 return 0;
778 }
779
780 return -EINVAL;
781}
782
783static int toshiba_acpi_setkeycode(struct input_dev *dev, int scancode,
784 int keycode)
785{
786 struct key_entry *key;
787 int old_keycode;
788
789 if (keycode < 0 || keycode > KEY_MAX)
790 return -EINVAL;
791
792 key = toshiba_acpi_get_entry_by_scancode(scancode);
793 if (key && key->type == KE_KEY) {
794 old_keycode = key->keycode;
795 key->keycode = keycode;
796 set_bit(keycode, dev->keybit);
797 if (!toshiba_acpi_get_entry_by_keycode(old_keycode))
798 clear_bit(old_keycode, dev->keybit);
799 return 0;
800 }
801
802 return -EINVAL;
803}
804
805static void toshiba_acpi_notify(acpi_handle handle, u32 event, void *context)
806{
807 u32 hci_result, value;
808 struct key_entry *key;
809
810 if (event != 0x80)
811 return;
812 do {
813 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
814 if (hci_result == HCI_SUCCESS) {
815 if (value == 0x100)
816 continue;
817 else if (value & 0x80) {
818 key = toshiba_acpi_get_entry_by_scancode
819 (value & ~0x80);
820 if (!key) {
821 printk(MY_INFO "Unknown key %x\n",
822 value & ~0x80);
823 continue;
824 }
825 input_report_key(toshiba_acpi.hotkey_dev,
826 key->keycode, 1);
827 input_sync(toshiba_acpi.hotkey_dev);
828 input_report_key(toshiba_acpi.hotkey_dev,
829 key->keycode, 0);
830 input_sync(toshiba_acpi.hotkey_dev);
831 }
832 } 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
929 if (acpi_disabled)
930 return -ENODEV;
Luming Yufb9802f2005-03-18 18:03:45 -0500931
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 /* simple device detection: look for HCI method */
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500933 if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD)) {
934 method_hci = TOSH_INTERFACE_1 GHCI_METHOD;
935 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1))
936 printk(MY_INFO "Unable to activate hotkeys\n");
937 } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD)) {
938 method_hci = TOSH_INTERFACE_2 GHCI_METHOD;
939 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2))
940 printk(MY_INFO "Unable to activate hotkeys\n");
941 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 return -ENODEV;
943
944 printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400945 TOSHIBA_ACPI_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 printk(MY_INFO " HCI method: %s\n", method_hci);
947
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400948 mutex_init(&toshiba_acpi.mutex);
949
950 toshiba_acpi.p_dev = platform_device_register_simple("toshiba_acpi",
951 -1, NULL, 0);
952 if (IS_ERR(toshiba_acpi.p_dev)) {
953 ret = PTR_ERR(toshiba_acpi.p_dev);
954 printk(MY_ERR "unable to register platform device\n");
955 toshiba_acpi.p_dev = NULL;
956 toshiba_acpi_exit();
957 return ret;
958 }
959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 force_fan = 0;
961 key_event_valid = 0;
962
963 /* enable event fifo */
964 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
965
966 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
967 if (!toshiba_proc_dir) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400968 toshiba_acpi_exit();
969 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 status = add_device();
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400972 if (ACPI_FAILURE(status)) {
973 toshiba_acpi_exit();
974 return -ENODEV;
975 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 }
977
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400978 toshiba_backlight_device = backlight_device_register("toshiba",
979 &toshiba_acpi.p_dev->dev,
Yu Luming519ab5f2006-12-19 12:56:15 -0800980 NULL,
Holger Machtc9263552006-10-20 14:30:29 -0700981 &toshiba_backlight_data);
982 if (IS_ERR(toshiba_backlight_device)) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400983 ret = PTR_ERR(toshiba_backlight_device);
Andrey Borzenkov12993422007-11-14 16:58:28 -0800984
Holger Machtc9263552006-10-20 14:30:29 -0700985 printk(KERN_ERR "Could not register toshiba backlight device\n");
986 toshiba_backlight_device = NULL;
987 toshiba_acpi_exit();
Andrey Borzenkov12993422007-11-14 16:58:28 -0800988 return ret;
Holger Machtc9263552006-10-20 14:30:29 -0700989 }
Richard Purdie599a52d2007-02-10 23:07:48 +0000990 toshiba_backlight_device->props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
Holger Machtc9263552006-10-20 14:30:29 -0700991
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400992 /* Register rfkill switch for Bluetooth */
993 if (hci_get_bt_present(&bt_present) == HCI_SUCCESS && bt_present) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200994 toshiba_acpi.bt_rfk = rfkill_alloc(toshiba_acpi.bt_name,
995 &toshiba_acpi.p_dev->dev,
996 RFKILL_TYPE_BLUETOOTH,
997 &toshiba_rfk_ops,
998 &toshiba_acpi);
999 if (!toshiba_acpi.bt_rfk) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001000 printk(MY_ERR "unable to allocate rfkill device\n");
1001 toshiba_acpi_exit();
1002 return -ENOMEM;
1003 }
1004
Johannes Berg19d337d2009-06-02 13:01:37 +02001005 ret = rfkill_register(toshiba_acpi.bt_rfk);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001006 if (ret) {
1007 printk(MY_ERR "unable to register rfkill device\n");
Johannes Berg19d337d2009-06-02 13:01:37 +02001008 rfkill_destroy(toshiba_acpi.bt_rfk);
Frederik Deweerdt38aefbc2008-12-15 13:54:19 -08001009 toshiba_acpi_exit();
1010 return ret;
1011 }
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001012 }
1013
1014 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015}
1016
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017module_init(toshiba_acpi_init);
1018module_exit(toshiba_acpi_exit);