blob: a5e1aa3d8c72556a6c446ed9b24c56e3aa011d5b [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},
Matthew Garrettae42f232010-07-15 14:23:42 -0400132 {KE_KEY, 0x102, KEY_ZOOMOUT},
133 {KE_KEY, 0x103, KEY_ZOOMIN},
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500134 {KE_KEY, 0x13b, KEY_COFFEE},
135 {KE_KEY, 0x13c, KEY_BATTERY},
136 {KE_KEY, 0x13d, KEY_SLEEP},
137 {KE_KEY, 0x13e, KEY_SUSPEND},
138 {KE_KEY, 0x13f, KEY_SWITCHVIDEOMODE},
139 {KE_KEY, 0x140, KEY_BRIGHTNESSDOWN},
140 {KE_KEY, 0x141, KEY_BRIGHTNESSUP},
141 {KE_KEY, 0x142, KEY_WLAN},
142 {KE_KEY, 0x143, KEY_PROG1},
143 {KE_KEY, 0xb05, KEY_PROG2},
144 {KE_KEY, 0xb06, KEY_WWW},
145 {KE_KEY, 0xb07, KEY_MAIL},
146 {KE_KEY, 0xb30, KEY_STOP},
147 {KE_KEY, 0xb31, KEY_PREVIOUSSONG},
148 {KE_KEY, 0xb32, KEY_NEXTSONG},
149 {KE_KEY, 0xb33, KEY_PLAYPAUSE},
150 {KE_KEY, 0xb5a, KEY_MEDIA},
151 {KE_END, 0, 0},
152};
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154/* utility
155 */
156
Len Brown4be44fc2005-08-05 00:44:28 -0400157static __inline__ void _set_bit(u32 * word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 *word = (*word & ~mask) | (mask * value);
160}
161
162/* acpi interface wrappers
163 */
164
Len Brown4be44fc2005-08-05 00:44:28 -0400165static int is_valid_acpi_path(const char *methodName)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
167 acpi_handle handle;
168 acpi_status status;
169
Len Brown4be44fc2005-08-05 00:44:28 -0400170 status = acpi_get_handle(NULL, (char *)methodName, &handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 return !ACPI_FAILURE(status);
172}
173
Len Brown4be44fc2005-08-05 00:44:28 -0400174static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
176 struct acpi_object_list params;
177 union acpi_object in_objs[1];
178 acpi_status status;
179
Ahmed S. Darwishb2b79102007-02-06 16:14:43 -0800180 params.count = ARRAY_SIZE(in_objs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 params.pointer = in_objs;
182 in_objs[0].type = ACPI_TYPE_INTEGER;
183 in_objs[0].integer.value = val;
184
Len Brown4be44fc2005-08-05 00:44:28 -0400185 status = acpi_evaluate_object(NULL, (char *)methodName, &params, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 return (status == AE_OK);
187}
188
189#if 0
Len Brown4be44fc2005-08-05 00:44:28 -0400190static int read_acpi_int(const char *methodName, int *pVal)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
192 struct acpi_buffer results;
193 union acpi_object out_objs[1];
194 acpi_status status;
195
196 results.length = sizeof(out_objs);
197 results.pointer = out_objs;
198
Len Brown4be44fc2005-08-05 00:44:28 -0400199 status = acpi_evaluate_object(0, (char *)methodName, 0, &results);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 *pVal = out_objs[0].integer.value;
201
202 return (status == AE_OK) && (out_objs[0].type == ACPI_TYPE_INTEGER);
203}
204#endif
205
Len Brown4be44fc2005-08-05 00:44:28 -0400206static const char *method_hci /*= 0*/ ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208/* Perform a raw HCI call. Here we don't care about input or output buffer
209 * format.
210 */
Len Brown4be44fc2005-08-05 00:44:28 -0400211static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
213 struct acpi_object_list params;
214 union acpi_object in_objs[HCI_WORDS];
215 struct acpi_buffer results;
Len Brown4be44fc2005-08-05 00:44:28 -0400216 union acpi_object out_objs[HCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 acpi_status status;
218 int i;
219
220 params.count = HCI_WORDS;
221 params.pointer = in_objs;
222 for (i = 0; i < HCI_WORDS; ++i) {
223 in_objs[i].type = ACPI_TYPE_INTEGER;
224 in_objs[i].integer.value = in[i];
225 }
226
227 results.length = sizeof(out_objs);
228 results.pointer = out_objs;
229
Len Brown4be44fc2005-08-05 00:44:28 -0400230 status = acpi_evaluate_object(NULL, (char *)method_hci, &params,
231 &results);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
233 for (i = 0; i < out_objs->package.count; ++i) {
234 out[i] = out_objs->package.elements[i].integer.value;
235 }
236 }
237
238 return status;
239}
240
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400241/* common hci tasks (get or set one or two value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 *
243 * In addition to the ACPI status, the HCI system returns a result which
244 * may be useful (such as "not supported").
245 */
246
Len Brown4be44fc2005-08-05 00:44:28 -0400247static acpi_status hci_write1(u32 reg, u32 in1, u32 * result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
249 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
250 u32 out[HCI_WORDS];
251 acpi_status status = hci_raw(in, out);
252 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
253 return status;
254}
255
Len Brown4be44fc2005-08-05 00:44:28 -0400256static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
258 u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
259 u32 out[HCI_WORDS];
260 acpi_status status = hci_raw(in, out);
261 *out1 = out[2];
262 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
263 return status;
264}
265
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400266static acpi_status hci_write2(u32 reg, u32 in1, u32 in2, u32 *result)
267{
268 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
269 u32 out[HCI_WORDS];
270 acpi_status status = hci_raw(in, out);
271 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
272 return status;
273}
274
275static acpi_status hci_read2(u32 reg, u32 *out1, u32 *out2, u32 *result)
276{
277 u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
278 u32 out[HCI_WORDS];
279 acpi_status status = hci_raw(in, out);
280 *out1 = out[2];
281 *out2 = out[3];
282 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
283 return status;
284}
285
286struct toshiba_acpi_dev {
287 struct platform_device *p_dev;
Johannes Berg19d337d2009-06-02 13:01:37 +0200288 struct rfkill *bt_rfk;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500289 struct input_dev *hotkey_dev;
290 acpi_handle handle;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400291
292 const char *bt_name;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400293
294 struct mutex mutex;
295};
296
297static struct toshiba_acpi_dev toshiba_acpi = {
298 .bt_name = "Toshiba Bluetooth",
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400299};
300
301/* Bluetooth rfkill handlers */
302
303static u32 hci_get_bt_present(bool *present)
304{
305 u32 hci_result;
306 u32 value, value2;
307
308 value = 0;
309 value2 = 0;
310 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
311 if (hci_result == HCI_SUCCESS)
312 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
313
314 return hci_result;
315}
316
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400317static u32 hci_get_radio_state(bool *radio_state)
318{
319 u32 hci_result;
320 u32 value, value2;
321
322 value = 0;
323 value2 = 0x0001;
324 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
325
326 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
327 return hci_result;
328}
329
Johannes Berg19d337d2009-06-02 13:01:37 +0200330static int bt_rfkill_set_block(void *data, bool blocked)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400331{
Johannes Berg19d337d2009-06-02 13:01:37 +0200332 struct toshiba_acpi_dev *dev = data;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400333 u32 result1, result2;
334 u32 value;
Johannes Berg19d337d2009-06-02 13:01:37 +0200335 int err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400336 bool radio_state;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400337
Johannes Berg19d337d2009-06-02 13:01:37 +0200338 value = (blocked == false);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400339
340 mutex_lock(&dev->mutex);
Johannes Berg19d337d2009-06-02 13:01:37 +0200341 if (hci_get_radio_state(&radio_state) != HCI_SUCCESS) {
342 err = -EBUSY;
343 goto out;
344 }
345
346 if (!radio_state) {
347 err = 0;
348 goto out;
349 }
350
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400351 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
352 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400353
354 if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS)
Johannes Berg19d337d2009-06-02 13:01:37 +0200355 err = -EBUSY;
356 else
357 err = 0;
358 out:
359 mutex_unlock(&dev->mutex);
360 return err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400361}
362
Johannes Berg19d337d2009-06-02 13:01:37 +0200363static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400364{
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400365 bool new_rfk_state;
366 bool value;
367 u32 hci_result;
Johannes Berg19d337d2009-06-02 13:01:37 +0200368 struct toshiba_acpi_dev *dev = data;
369
370 mutex_lock(&dev->mutex);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400371
372 hci_result = hci_get_radio_state(&value);
Johannes Berg19d337d2009-06-02 13:01:37 +0200373 if (hci_result != HCI_SUCCESS) {
374 /* Can't do anything useful */
375 mutex_unlock(&dev->mutex);
Jiri Slaby82e77842009-08-06 15:57:51 -0700376 return;
Johannes Berg19d337d2009-06-02 13:01:37 +0200377 }
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400378
379 new_rfk_state = value;
380
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400381 mutex_unlock(&dev->mutex);
382
Johannes Berg19d337d2009-06-02 13:01:37 +0200383 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
384 bt_rfkill_set_block(data, true);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400385}
386
Johannes Berg19d337d2009-06-02 13:01:37 +0200387static const struct rfkill_ops toshiba_rfk_ops = {
388 .set_block = bt_rfkill_set_block,
389 .poll = bt_rfkill_poll,
390};
391
Len Brown4be44fc2005-08-05 00:44:28 -0400392static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
Holger Machtc9263552006-10-20 14:30:29 -0700393static struct backlight_device *toshiba_backlight_device;
Len Brown4be44fc2005-08-05 00:44:28 -0400394static int force_fan;
395static int last_key_event;
396static int key_event_valid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Holger Machtc9263552006-10-20 14:30:29 -0700398static int get_lcd(struct backlight_device *bd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
400 u32 hci_result;
401 u32 value;
402
403 hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result);
404 if (hci_result == HCI_SUCCESS) {
Holger Machtc9263552006-10-20 14:30:29 -0700405 return (value >> HCI_LCD_BRIGHTNESS_SHIFT);
406 } else
407 return -EFAULT;
408}
409
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800410static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -0700411{
412 int value = get_lcd(NULL);
413
414 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800415 seq_printf(m, "brightness: %d\n", value);
416 seq_printf(m, "brightness_levels: %d\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400417 HCI_LCD_BRIGHTNESS_LEVELS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 } else {
419 printk(MY_ERR "Error reading LCD brightness\n");
420 }
421
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800422 return 0;
423}
424
425static int lcd_proc_open(struct inode *inode, struct file *file)
426{
427 return single_open(file, lcd_proc_show, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428}
429
Holger Machtc9263552006-10-20 14:30:29 -0700430static int set_lcd(int value)
431{
432 u32 hci_result;
433
434 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
435 hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result);
436 if (hci_result != HCI_SUCCESS)
437 return -EFAULT;
438
439 return 0;
440}
441
442static int set_lcd_status(struct backlight_device *bd)
443{
Richard Purdie599a52d2007-02-10 23:07:48 +0000444 return set_lcd(bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -0700445}
446
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800447static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
448 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800450 char cmd[42];
451 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 int value;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800453 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800455 len = min(count, sizeof(cmd) - 1);
456 if (copy_from_user(cmd, buf, len))
457 return -EFAULT;
458 cmd[len] = '\0';
459
460 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800461 value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) {
Holger Machtc9263552006-10-20 14:30:29 -0700462 ret = set_lcd(value);
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800463 if (ret == 0)
464 ret = count;
465 } else {
Holger Machtc9263552006-10-20 14:30:29 -0700466 ret = -EINVAL;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800467 }
Holger Machtc9263552006-10-20 14:30:29 -0700468 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469}
470
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800471static const struct file_operations lcd_proc_fops = {
472 .owner = THIS_MODULE,
473 .open = lcd_proc_open,
474 .read = seq_read,
475 .llseek = seq_lseek,
476 .release = single_release,
477 .write = lcd_proc_write,
478};
479
480static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
482 u32 hci_result;
483 u32 value;
484
485 hci_read1(HCI_VIDEO_OUT, &value, &hci_result);
486 if (hci_result == HCI_SUCCESS) {
487 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
488 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400489 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800490 seq_printf(m, "lcd_out: %d\n", is_lcd);
491 seq_printf(m, "crt_out: %d\n", is_crt);
492 seq_printf(m, "tv_out: %d\n", is_tv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 } else {
494 printk(MY_ERR "Error reading video out status\n");
495 }
496
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800497 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498}
499
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800500static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800502 return single_open(file, video_proc_show, NULL);
503}
504
505static ssize_t video_proc_write(struct file *file, const char __user *buf,
506 size_t count, loff_t *pos)
507{
508 char *cmd, *buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 int value;
510 int remain = count;
511 int lcd_out = -1;
512 int crt_out = -1;
513 int tv_out = -1;
514 u32 hci_result;
Al Virob4482a42007-10-14 19:35:40 +0100515 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800517 cmd = kmalloc(count + 1, GFP_KERNEL);
518 if (!cmd)
519 return -ENOMEM;
520 if (copy_from_user(cmd, buf, count)) {
521 kfree(cmd);
522 return -EFAULT;
523 }
524 cmd[count] = '\0';
525
526 buffer = cmd;
527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 /* scan expression. Multiple expressions may be delimited with ;
529 *
530 * NOTE: to keep scanning simple, invalid fields are ignored
531 */
532 while (remain) {
533 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
534 lcd_out = value & 1;
535 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
536 crt_out = value & 1;
537 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
538 tv_out = value & 1;
539 /* advance to one character past the next ; */
540 do {
541 ++buffer;
542 --remain;
543 }
Len Brown4be44fc2005-08-05 00:44:28 -0400544 while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 }
546
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800547 kfree(cmd);
548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 hci_read1(HCI_VIDEO_OUT, &video_out, &hci_result);
550 if (hci_result == HCI_SUCCESS) {
Harvey Harrison9e113e02008-09-22 14:37:29 -0700551 unsigned int new_video_out = video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (lcd_out != -1)
553 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
554 if (crt_out != -1)
555 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
556 if (tv_out != -1)
557 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
558 /* To avoid unnecessary video disruption, only write the new
559 * video setting if something changed. */
560 if (new_video_out != video_out)
561 write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
562 } else {
563 return -EFAULT;
564 }
565
566 return count;
567}
568
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800569static const struct file_operations video_proc_fops = {
570 .owner = THIS_MODULE,
571 .open = video_proc_open,
572 .read = seq_read,
573 .llseek = seq_lseek,
574 .release = single_release,
575 .write = video_proc_write,
576};
577
578static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
580 u32 hci_result;
581 u32 value;
582
583 hci_read1(HCI_FAN, &value, &hci_result);
584 if (hci_result == HCI_SUCCESS) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800585 seq_printf(m, "running: %d\n", (value > 0));
586 seq_printf(m, "force_on: %d\n", force_fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 } else {
588 printk(MY_ERR "Error reading fan status\n");
589 }
590
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800591 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592}
593
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800594static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800596 return single_open(file, fan_proc_show, NULL);
597}
598
599static ssize_t fan_proc_write(struct file *file, const char __user *buf,
600 size_t count, loff_t *pos)
601{
602 char cmd[42];
603 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 int value;
605 u32 hci_result;
606
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800607 len = min(count, sizeof(cmd) - 1);
608 if (copy_from_user(cmd, buf, len))
609 return -EFAULT;
610 cmd[len] = '\0';
611
612 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
Len Brown4be44fc2005-08-05 00:44:28 -0400613 value >= 0 && value <= 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 hci_write1(HCI_FAN, value, &hci_result);
615 if (hci_result != HCI_SUCCESS)
616 return -EFAULT;
617 else
618 force_fan = value;
619 } else {
620 return -EINVAL;
621 }
622
623 return count;
624}
625
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800626static const struct file_operations fan_proc_fops = {
627 .owner = THIS_MODULE,
628 .open = fan_proc_open,
629 .read = seq_read,
630 .llseek = seq_lseek,
631 .release = single_release,
632 .write = fan_proc_write,
633};
634
635static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636{
637 u32 hci_result;
638 u32 value;
639
640 if (!key_event_valid) {
641 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
642 if (hci_result == HCI_SUCCESS) {
643 key_event_valid = 1;
644 last_key_event = value;
645 } else if (hci_result == HCI_EMPTY) {
646 /* better luck next time */
647 } else if (hci_result == HCI_NOT_SUPPORTED) {
648 /* This is a workaround for an unresolved issue on
649 * some machines where system events sporadically
650 * become disabled. */
651 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
652 printk(MY_NOTICE "Re-enabled hotkeys\n");
653 } else {
654 printk(MY_ERR "Error reading hotkey status\n");
655 goto end;
656 }
657 }
658
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800659 seq_printf(m, "hotkey_ready: %d\n", key_event_valid);
660 seq_printf(m, "hotkey: 0x%04x\n", last_key_event);
661end:
662 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663}
664
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800665static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800667 return single_open(file, keys_proc_show, NULL);
668}
669
670static ssize_t keys_proc_write(struct file *file, const char __user *buf,
671 size_t count, loff_t *pos)
672{
673 char cmd[42];
674 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 int value;
676
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800677 len = min(count, sizeof(cmd) - 1);
678 if (copy_from_user(cmd, buf, len))
679 return -EFAULT;
680 cmd[len] = '\0';
681
682 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 key_event_valid = 0;
684 } else {
685 return -EINVAL;
686 }
687
688 return count;
689}
690
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800691static const struct file_operations keys_proc_fops = {
692 .owner = THIS_MODULE,
693 .open = keys_proc_open,
694 .read = seq_read,
695 .llseek = seq_lseek,
696 .release = single_release,
697 .write = keys_proc_write,
698};
699
700static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800702 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
703 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
704 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705}
706
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800707static int version_proc_open(struct inode *inode, struct file *file)
708{
709 return single_open(file, version_proc_show, PDE(inode)->data);
710}
711
712static const struct file_operations version_proc_fops = {
713 .owner = THIS_MODULE,
714 .open = version_proc_open,
715 .read = seq_read,
716 .llseek = seq_lseek,
717 .release = single_release,
718};
719
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720/* proc and module init
721 */
722
723#define PROC_TOSHIBA "toshiba"
724
Len Brown4be44fc2005-08-05 00:44:28 -0400725static acpi_status __init add_device(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800727 proc_create("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, &lcd_proc_fops);
728 proc_create("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, &video_proc_fops);
729 proc_create("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, &fan_proc_fops);
730 proc_create("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, &keys_proc_fops);
731 proc_create("version", S_IRUGO, toshiba_proc_dir, &version_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 return AE_OK;
734}
735
Randy Dunlapb1d93de2007-06-16 10:16:02 -0700736static acpi_status remove_device(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800738 remove_proc_entry("lcd", toshiba_proc_dir);
739 remove_proc_entry("video", toshiba_proc_dir);
740 remove_proc_entry("fan", toshiba_proc_dir);
741 remove_proc_entry("keys", toshiba_proc_dir);
742 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 return AE_OK;
744}
745
Richard Purdie599a52d2007-02-10 23:07:48 +0000746static struct backlight_ops toshiba_backlight_data = {
Holger Machtc9263552006-10-20 14:30:29 -0700747 .get_brightness = get_lcd,
748 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -0700749};
750
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800751static struct key_entry *toshiba_acpi_get_entry_by_scancode(unsigned int code)
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500752{
753 struct key_entry *key;
754
755 for (key = toshiba_acpi_keymap; key->type != KE_END; key++)
756 if (code == key->code)
757 return key;
758
759 return NULL;
760}
761
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800762static struct key_entry *toshiba_acpi_get_entry_by_keycode(unsigned int code)
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500763{
764 struct key_entry *key;
765
766 for (key = toshiba_acpi_keymap; key->type != KE_END; key++)
767 if (code == key->keycode && key->type == KE_KEY)
768 return key;
769
770 return NULL;
771}
772
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800773static int toshiba_acpi_getkeycode(struct input_dev *dev,
774 unsigned int scancode, unsigned int *keycode)
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500775{
776 struct key_entry *key = toshiba_acpi_get_entry_by_scancode(scancode);
777
778 if (key && key->type == KE_KEY) {
779 *keycode = key->keycode;
780 return 0;
781 }
782
783 return -EINVAL;
784}
785
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800786static int toshiba_acpi_setkeycode(struct input_dev *dev,
787 unsigned int scancode, unsigned int keycode)
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500788{
789 struct key_entry *key;
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800790 unsigned int old_keycode;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500791
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;
Frans Popb4663012010-03-01 09:50:46 -0500817 /* act on key press; ignore key release */
818 if (value & 0x80)
819 continue;
820
821 key = toshiba_acpi_get_entry_by_scancode
822 (value);
823 if (!key) {
824 printk(MY_INFO "Unknown key %x\n",
825 value);
826 continue;
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500827 }
Frans Popb4663012010-03-01 09:50:46 -0500828 input_report_key(toshiba_acpi.hotkey_dev,
829 key->keycode, 1);
830 input_sync(toshiba_acpi.hotkey_dev);
831 input_report_key(toshiba_acpi.hotkey_dev,
832 key->keycode, 0);
833 input_sync(toshiba_acpi.hotkey_dev);
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500834 } else if (hci_result == HCI_NOT_SUPPORTED) {
835 /* This is a workaround for an unresolved issue on
836 * some machines where system events sporadically
837 * become disabled. */
838 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
839 printk(MY_NOTICE "Re-enabled hotkeys\n");
840 }
841 } while (hci_result != HCI_EMPTY);
842}
843
844static int toshiba_acpi_setup_keyboard(char *device)
845{
846 acpi_status status;
847 acpi_handle handle;
848 int result;
849 const struct key_entry *key;
850
851 status = acpi_get_handle(NULL, device, &handle);
852 if (ACPI_FAILURE(status)) {
853 printk(MY_INFO "Unable to get notification device\n");
854 return -ENODEV;
855 }
856
857 toshiba_acpi.handle = handle;
858
859 status = acpi_evaluate_object(handle, "ENAB", NULL, NULL);
860 if (ACPI_FAILURE(status)) {
861 printk(MY_INFO "Unable to enable hotkeys\n");
862 return -ENODEV;
863 }
864
865 status = acpi_install_notify_handler(handle, ACPI_DEVICE_NOTIFY,
866 toshiba_acpi_notify, NULL);
867 if (ACPI_FAILURE(status)) {
868 printk(MY_INFO "Unable to install hotkey notification\n");
869 return -ENODEV;
870 }
871
872 toshiba_acpi.hotkey_dev = input_allocate_device();
873 if (!toshiba_acpi.hotkey_dev) {
874 printk(MY_INFO "Unable to register input device\n");
875 return -ENOMEM;
876 }
877
878 toshiba_acpi.hotkey_dev->name = "Toshiba input device";
879 toshiba_acpi.hotkey_dev->phys = device;
880 toshiba_acpi.hotkey_dev->id.bustype = BUS_HOST;
881 toshiba_acpi.hotkey_dev->getkeycode = toshiba_acpi_getkeycode;
882 toshiba_acpi.hotkey_dev->setkeycode = toshiba_acpi_setkeycode;
883
884 for (key = toshiba_acpi_keymap; key->type != KE_END; key++) {
885 set_bit(EV_KEY, toshiba_acpi.hotkey_dev->evbit);
886 set_bit(key->keycode, toshiba_acpi.hotkey_dev->keybit);
887 }
888
889 result = input_register_device(toshiba_acpi.hotkey_dev);
890 if (result) {
891 printk(MY_INFO "Unable to register input device\n");
892 return result;
893 }
894
895 return 0;
896}
897
Sam Ravnborgb2b77b22007-06-01 00:47:12 -0700898static void toshiba_acpi_exit(void)
Holger Machtc9263552006-10-20 14:30:29 -0700899{
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500900 if (toshiba_acpi.hotkey_dev)
901 input_unregister_device(toshiba_acpi.hotkey_dev);
902
Johannes Berg19d337d2009-06-02 13:01:37 +0200903 if (toshiba_acpi.bt_rfk) {
904 rfkill_unregister(toshiba_acpi.bt_rfk);
905 rfkill_destroy(toshiba_acpi.bt_rfk);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400906 }
907
Holger Machtc9263552006-10-20 14:30:29 -0700908 if (toshiba_backlight_device)
909 backlight_device_unregister(toshiba_backlight_device);
910
911 remove_device();
912
913 if (toshiba_proc_dir)
914 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
915
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500916 acpi_remove_notify_handler(toshiba_acpi.handle, ACPI_DEVICE_NOTIFY,
917 toshiba_acpi_notify);
918
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400919 platform_device_unregister(toshiba_acpi.p_dev);
920
Holger Machtc9263552006-10-20 14:30:29 -0700921 return;
922}
923
Len Brown4be44fc2005-08-05 00:44:28 -0400924static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925{
926 acpi_status status = AE_OK;
927 u32 hci_result;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400928 bool bt_present;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400929 int ret = 0;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500930 struct backlight_properties props;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
932 if (acpi_disabled)
933 return -ENODEV;
Luming Yufb9802f2005-03-18 18:03:45 -0500934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 /* simple device detection: look for HCI method */
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500936 if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD)) {
937 method_hci = TOSH_INTERFACE_1 GHCI_METHOD;
938 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1))
939 printk(MY_INFO "Unable to activate hotkeys\n");
940 } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD)) {
941 method_hci = TOSH_INTERFACE_2 GHCI_METHOD;
942 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2))
943 printk(MY_INFO "Unable to activate hotkeys\n");
944 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 return -ENODEV;
946
947 printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400948 TOSHIBA_ACPI_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 printk(MY_INFO " HCI method: %s\n", method_hci);
950
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400951 mutex_init(&toshiba_acpi.mutex);
952
953 toshiba_acpi.p_dev = platform_device_register_simple("toshiba_acpi",
954 -1, NULL, 0);
955 if (IS_ERR(toshiba_acpi.p_dev)) {
956 ret = PTR_ERR(toshiba_acpi.p_dev);
957 printk(MY_ERR "unable to register platform device\n");
958 toshiba_acpi.p_dev = NULL;
959 toshiba_acpi_exit();
960 return ret;
961 }
962
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 force_fan = 0;
964 key_event_valid = 0;
965
966 /* enable event fifo */
967 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
968
969 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
970 if (!toshiba_proc_dir) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400971 toshiba_acpi_exit();
972 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 status = add_device();
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400975 if (ACPI_FAILURE(status)) {
976 toshiba_acpi_exit();
977 return -ENODEV;
978 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 }
980
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500981 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400982 toshiba_backlight_device = backlight_device_register("toshiba",
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500983 &toshiba_acpi.p_dev->dev,
984 NULL,
985 &toshiba_backlight_data,
986 &props);
Holger Machtc9263552006-10-20 14:30:29 -0700987 if (IS_ERR(toshiba_backlight_device)) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400988 ret = PTR_ERR(toshiba_backlight_device);
Andrey Borzenkov12993422007-11-14 16:58:28 -0800989
Holger Machtc9263552006-10-20 14:30:29 -0700990 printk(KERN_ERR "Could not register toshiba backlight device\n");
991 toshiba_backlight_device = NULL;
992 toshiba_acpi_exit();
Andrey Borzenkov12993422007-11-14 16:58:28 -0800993 return ret;
Holger Machtc9263552006-10-20 14:30:29 -0700994 }
995
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400996 /* Register rfkill switch for Bluetooth */
997 if (hci_get_bt_present(&bt_present) == HCI_SUCCESS && bt_present) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200998 toshiba_acpi.bt_rfk = rfkill_alloc(toshiba_acpi.bt_name,
999 &toshiba_acpi.p_dev->dev,
1000 RFKILL_TYPE_BLUETOOTH,
1001 &toshiba_rfk_ops,
1002 &toshiba_acpi);
1003 if (!toshiba_acpi.bt_rfk) {
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001004 printk(MY_ERR "unable to allocate rfkill device\n");
1005 toshiba_acpi_exit();
1006 return -ENOMEM;
1007 }
1008
Johannes Berg19d337d2009-06-02 13:01:37 +02001009 ret = rfkill_register(toshiba_acpi.bt_rfk);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001010 if (ret) {
1011 printk(MY_ERR "unable to register rfkill device\n");
Johannes Berg19d337d2009-06-02 13:01:37 +02001012 rfkill_destroy(toshiba_acpi.bt_rfk);
Frederik Deweerdt38aefbc2008-12-15 13:54:19 -08001013 toshiba_acpi_exit();
1014 return ret;
1015 }
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001016 }
1017
1018 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019}
1020
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021module_init(toshiba_acpi_init);
1022module_exit(toshiba_acpi_exit);