aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform
diff options
context:
space:
mode:
authorSeth Forshee <seth.forshee@canonical.com>2011-09-20 17:55:49 -0400
committerMatthew Garrett <mjg@redhat.com>2011-10-24 10:52:36 -0400
commit135740de77641b4180c8a1f19abcfcd5e4351b15 (patch)
treeb8c1421f005dbaa8f95079c53eeb30cd18becf36 /drivers/platform
parentf689c875c13c9d62b3c4de09cd5dad66549f700d (diff)
toshiba_acpi: Convert to use acpi_driver
Changes toshiba_acpi to register an acpi driver and eliminates the platform device it was using. Also eliminates most global variables, moving them into toshiba_acpi_dev, along with some other miscellaneous fixes and cleanup. Signed-off-by: Azael Avalos <coproscefalo@gmail.com> Signed-off-by: Seth Forshee <seth.forshee@canonical.com> Signed-off-by: Matthew Garrett <mjg@redhat.com>
Diffstat (limited to 'drivers/platform')
-rw-r--r--drivers/platform/x86/toshiba_acpi.c506
1 files changed, 261 insertions, 245 deletions
diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index cb009b2629ee..d74c97cde0f1 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -47,7 +47,6 @@
47#include <linux/proc_fs.h> 47#include <linux/proc_fs.h>
48#include <linux/seq_file.h> 48#include <linux/seq_file.h>
49#include <linux/backlight.h> 49#include <linux/backlight.h>
50#include <linux/platform_device.h>
51#include <linux/rfkill.h> 50#include <linux/rfkill.h>
52#include <linux/input.h> 51#include <linux/input.h>
53#include <linux/input/sparse-keymap.h> 52#include <linux/input/sparse-keymap.h>
@@ -111,6 +110,22 @@ MODULE_LICENSE("GPL");
111#define HCI_WIRELESS_BT_ATTACH 0x40 110#define HCI_WIRELESS_BT_ATTACH 0x40
112#define HCI_WIRELESS_BT_POWER 0x80 111#define HCI_WIRELESS_BT_POWER 0x80
113 112
113struct toshiba_acpi_dev {
114 struct acpi_device *acpi_dev;
115 const char *method_hci;
116 struct rfkill *bt_rfk;
117 struct input_dev *hotkey_dev;
118 struct backlight_device *backlight_dev;
119 struct led_classdev led_dev;
120 int illumination_installed;
121 int force_fan;
122 int last_key_event;
123 int key_event_valid;
124 acpi_handle handle;
125
126 struct mutex mutex;
127};
128
114static const struct acpi_device_id toshiba_device_ids[] = { 129static const struct acpi_device_id toshiba_device_ids[] = {
115 {"TOS6200", 0}, 130 {"TOS6200", 0},
116 {"TOS6208", 0}, 131 {"TOS6208", 0},
@@ -119,7 +134,7 @@ static const struct acpi_device_id toshiba_device_ids[] = {
119}; 134};
120MODULE_DEVICE_TABLE(acpi, toshiba_device_ids); 135MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
121 136
122static const struct key_entry toshiba_acpi_keymap[] __initconst = { 137static const struct key_entry toshiba_acpi_keymap[] __devinitconst = {
123 { KE_KEY, 0x101, { KEY_MUTE } }, 138 { KE_KEY, 0x101, { KEY_MUTE } },
124 { KE_KEY, 0x102, { KEY_ZOOMOUT } }, 139 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
125 { KE_KEY, 0x103, { KEY_ZOOMIN } }, 140 { KE_KEY, 0x103, { KEY_ZOOMIN } },
@@ -179,29 +194,11 @@ static int write_acpi_int(const char *methodName, int val)
179 return (status == AE_OK); 194 return (status == AE_OK);
180} 195}
181 196
182#if 0
183static int read_acpi_int(const char *methodName, int *pVal)
184{
185 struct acpi_buffer results;
186 union acpi_object out_objs[1];
187 acpi_status status;
188
189 results.length = sizeof(out_objs);
190 results.pointer = out_objs;
191
192 status = acpi_evaluate_object(0, (char *)methodName, 0, &results);
193 *pVal = out_objs[0].integer.value;
194
195 return (status == AE_OK) && (out_objs[0].type == ACPI_TYPE_INTEGER);
196}
197#endif
198
199static const char *method_hci /*= 0*/ ;
200
201/* Perform a raw HCI call. Here we don't care about input or output buffer 197/* Perform a raw HCI call. Here we don't care about input or output buffer
202 * format. 198 * format.
203 */ 199 */
204static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS]) 200static acpi_status hci_raw(struct toshiba_acpi_dev *dev,
201 const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
205{ 202{
206 struct acpi_object_list params; 203 struct acpi_object_list params;
207 union acpi_object in_objs[HCI_WORDS]; 204 union acpi_object in_objs[HCI_WORDS];
@@ -220,7 +217,7 @@ static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
220 results.length = sizeof(out_objs); 217 results.length = sizeof(out_objs);
221 results.pointer = out_objs; 218 results.pointer = out_objs;
222 219
223 status = acpi_evaluate_object(NULL, (char *)method_hci, &params, 220 status = acpi_evaluate_object(NULL, (char *)dev->method_hci, &params,
224 &results); 221 &results);
225 if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) { 222 if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
226 for (i = 0; i < out_objs->package.count; ++i) { 223 for (i = 0; i < out_objs->package.count; ++i) {
@@ -237,85 +234,79 @@ static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
237 * may be useful (such as "not supported"). 234 * may be useful (such as "not supported").
238 */ 235 */
239 236
240static acpi_status hci_write1(u32 reg, u32 in1, u32 * result) 237static acpi_status hci_write1(struct toshiba_acpi_dev *dev, u32 reg,
238 u32 in1, u32 *result)
241{ 239{
242 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 }; 240 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
243 u32 out[HCI_WORDS]; 241 u32 out[HCI_WORDS];
244 acpi_status status = hci_raw(in, out); 242 acpi_status status = hci_raw(dev, in, out);
245 *result = (status == AE_OK) ? out[0] : HCI_FAILURE; 243 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
246 return status; 244 return status;
247} 245}
248 246
249static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result) 247static acpi_status hci_read1(struct toshiba_acpi_dev *dev, u32 reg,
248 u32 *out1, u32 *result)
250{ 249{
251 u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 }; 250 u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
252 u32 out[HCI_WORDS]; 251 u32 out[HCI_WORDS];
253 acpi_status status = hci_raw(in, out); 252 acpi_status status = hci_raw(dev, in, out);
254 *out1 = out[2]; 253 *out1 = out[2];
255 *result = (status == AE_OK) ? out[0] : HCI_FAILURE; 254 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
256 return status; 255 return status;
257} 256}
258 257
259static acpi_status hci_write2(u32 reg, u32 in1, u32 in2, u32 *result) 258static acpi_status hci_write2(struct toshiba_acpi_dev *dev, u32 reg,
259 u32 in1, u32 in2, u32 *result)
260{ 260{
261 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 }; 261 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
262 u32 out[HCI_WORDS]; 262 u32 out[HCI_WORDS];
263 acpi_status status = hci_raw(in, out); 263 acpi_status status = hci_raw(dev, in, out);
264 *result = (status == AE_OK) ? out[0] : HCI_FAILURE; 264 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
265 return status; 265 return status;
266} 266}
267 267
268static acpi_status hci_read2(u32 reg, u32 *out1, u32 *out2, u32 *result) 268static acpi_status hci_read2(struct toshiba_acpi_dev *dev, u32 reg,
269 u32 *out1, u32 *out2, u32 *result)
269{ 270{
270 u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 }; 271 u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
271 u32 out[HCI_WORDS]; 272 u32 out[HCI_WORDS];
272 acpi_status status = hci_raw(in, out); 273 acpi_status status = hci_raw(dev, in, out);
273 *out1 = out[2]; 274 *out1 = out[2];
274 *out2 = out[3]; 275 *out2 = out[3];
275 *result = (status == AE_OK) ? out[0] : HCI_FAILURE; 276 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
276 return status; 277 return status;
277} 278}
278 279
279struct toshiba_acpi_dev {
280 struct platform_device *p_dev;
281 struct rfkill *bt_rfk;
282 struct input_dev *hotkey_dev;
283 int illumination_installed;
284 acpi_handle handle;
285
286 const char *bt_name;
287
288 struct mutex mutex;
289};
290
291/* Illumination support */ 280/* Illumination support */
292static int toshiba_illumination_available(void) 281static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
293{ 282{
294 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 }; 283 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
295 u32 out[HCI_WORDS]; 284 u32 out[HCI_WORDS];
296 acpi_status status; 285 acpi_status status;
297 286
298 in[0] = 0xf100; 287 in[0] = 0xf100;
299 status = hci_raw(in, out); 288 status = hci_raw(dev, in, out);
300 if (ACPI_FAILURE(status)) { 289 if (ACPI_FAILURE(status)) {
301 pr_info("Illumination device not available\n"); 290 pr_info("Illumination device not available\n");
302 return 0; 291 return 0;
303 } 292 }
304 in[0] = 0xf400; 293 in[0] = 0xf400;
305 status = hci_raw(in, out); 294 status = hci_raw(dev, in, out);
306 return 1; 295 return 1;
307} 296}
308 297
309static void toshiba_illumination_set(struct led_classdev *cdev, 298static void toshiba_illumination_set(struct led_classdev *cdev,
310 enum led_brightness brightness) 299 enum led_brightness brightness)
311{ 300{
301 struct toshiba_acpi_dev *dev = container_of(cdev,
302 struct toshiba_acpi_dev, led_dev);
312 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 }; 303 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
313 u32 out[HCI_WORDS]; 304 u32 out[HCI_WORDS];
314 acpi_status status; 305 acpi_status status;
315 306
316 /* First request : initialize communication. */ 307 /* First request : initialize communication. */
317 in[0] = 0xf100; 308 in[0] = 0xf100;
318 status = hci_raw(in, out); 309 status = hci_raw(dev, in, out);
319 if (ACPI_FAILURE(status)) { 310 if (ACPI_FAILURE(status)) {
320 pr_info("Illumination device not available\n"); 311 pr_info("Illumination device not available\n");
321 return; 312 return;
@@ -326,7 +317,7 @@ static void toshiba_illumination_set(struct led_classdev *cdev,
326 in[0] = 0xf400; 317 in[0] = 0xf400;
327 in[1] = 0x14e; 318 in[1] = 0x14e;
328 in[2] = 1; 319 in[2] = 1;
329 status = hci_raw(in, out); 320 status = hci_raw(dev, in, out);
330 if (ACPI_FAILURE(status)) { 321 if (ACPI_FAILURE(status)) {
331 pr_info("ACPI call for illumination failed\n"); 322 pr_info("ACPI call for illumination failed\n");
332 return; 323 return;
@@ -336,7 +327,7 @@ static void toshiba_illumination_set(struct led_classdev *cdev,
336 in[0] = 0xf400; 327 in[0] = 0xf400;
337 in[1] = 0x14e; 328 in[1] = 0x14e;
338 in[2] = 0; 329 in[2] = 0;
339 status = hci_raw(in, out); 330 status = hci_raw(dev, in, out);
340 if (ACPI_FAILURE(status)) { 331 if (ACPI_FAILURE(status)) {
341 pr_info("ACPI call for illumination failed.\n"); 332 pr_info("ACPI call for illumination failed.\n");
342 return; 333 return;
@@ -347,11 +338,13 @@ static void toshiba_illumination_set(struct led_classdev *cdev,
347 in[0] = 0xf200; 338 in[0] = 0xf200;
348 in[1] = 0; 339 in[1] = 0;
349 in[2] = 0; 340 in[2] = 0;
350 hci_raw(in, out); 341 hci_raw(dev, in, out);
351} 342}
352 343
353static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev) 344static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
354{ 345{
346 struct toshiba_acpi_dev *dev = container_of(cdev,
347 struct toshiba_acpi_dev, led_dev);
355 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 }; 348 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
356 u32 out[HCI_WORDS]; 349 u32 out[HCI_WORDS];
357 acpi_status status; 350 acpi_status status;
@@ -359,7 +352,7 @@ static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
359 352
360 /* First request : initialize communication. */ 353 /* First request : initialize communication. */
361 in[0] = 0xf100; 354 in[0] = 0xf100;
362 status = hci_raw(in, out); 355 status = hci_raw(dev, in, out);
363 if (ACPI_FAILURE(status)) { 356 if (ACPI_FAILURE(status)) {
364 pr_info("Illumination device not available\n"); 357 pr_info("Illumination device not available\n");
365 return LED_OFF; 358 return LED_OFF;
@@ -368,7 +361,7 @@ static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
368 /* Check the illumination */ 361 /* Check the illumination */
369 in[0] = 0xf300; 362 in[0] = 0xf300;
370 in[1] = 0x14e; 363 in[1] = 0x14e;
371 status = hci_raw(in, out); 364 status = hci_raw(dev, in, out);
372 if (ACPI_FAILURE(status)) { 365 if (ACPI_FAILURE(status)) {
373 pr_info("ACPI call for illumination failed.\n"); 366 pr_info("ACPI call for illumination failed.\n");
374 return LED_OFF; 367 return LED_OFF;
@@ -380,46 +373,35 @@ static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
380 in[0] = 0xf200; 373 in[0] = 0xf200;
381 in[1] = 0; 374 in[1] = 0;
382 in[2] = 0; 375 in[2] = 0;
383 hci_raw(in, out); 376 hci_raw(dev, in, out);
384 377
385 return result; 378 return result;
386} 379}
387 380
388static struct led_classdev toshiba_led = {
389 .name = "toshiba::illumination",
390 .max_brightness = 1,
391 .brightness_set = toshiba_illumination_set,
392 .brightness_get = toshiba_illumination_get,
393};
394
395static struct toshiba_acpi_dev toshiba_acpi = {
396 .bt_name = "Toshiba Bluetooth",
397};
398
399/* Bluetooth rfkill handlers */ 381/* Bluetooth rfkill handlers */
400 382
401static u32 hci_get_bt_present(bool *present) 383static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
402{ 384{
403 u32 hci_result; 385 u32 hci_result;
404 u32 value, value2; 386 u32 value, value2;
405 387
406 value = 0; 388 value = 0;
407 value2 = 0; 389 value2 = 0;
408 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result); 390 hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result);
409 if (hci_result == HCI_SUCCESS) 391 if (hci_result == HCI_SUCCESS)
410 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false; 392 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
411 393
412 return hci_result; 394 return hci_result;
413} 395}
414 396
415static u32 hci_get_radio_state(bool *radio_state) 397static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state)
416{ 398{
417 u32 hci_result; 399 u32 hci_result;
418 u32 value, value2; 400 u32 value, value2;
419 401
420 value = 0; 402 value = 0;
421 value2 = 0x0001; 403 value2 = 0x0001;
422 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result); 404 hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result);
423 405
424 *radio_state = value & HCI_WIRELESS_KILL_SWITCH; 406 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
425 return hci_result; 407 return hci_result;
@@ -436,7 +418,7 @@ static int bt_rfkill_set_block(void *data, bool blocked)
436 value = (blocked == false); 418 value = (blocked == false);
437 419
438 mutex_lock(&dev->mutex); 420 mutex_lock(&dev->mutex);
439 if (hci_get_radio_state(&radio_state) != HCI_SUCCESS) { 421 if (hci_get_radio_state(dev, &radio_state) != HCI_SUCCESS) {
440 err = -EBUSY; 422 err = -EBUSY;
441 goto out; 423 goto out;
442 } 424 }
@@ -446,8 +428,8 @@ static int bt_rfkill_set_block(void *data, bool blocked)
446 goto out; 428 goto out;
447 } 429 }
448 430
449 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1); 431 hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
450 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2); 432 hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
451 433
452 if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS) 434 if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS)
453 err = -EBUSY; 435 err = -EBUSY;
@@ -467,7 +449,7 @@ static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
467 449
468 mutex_lock(&dev->mutex); 450 mutex_lock(&dev->mutex);
469 451
470 hci_result = hci_get_radio_state(&value); 452 hci_result = hci_get_radio_state(dev, &value);
471 if (hci_result != HCI_SUCCESS) { 453 if (hci_result != HCI_SUCCESS) {
472 /* Can't do anything useful */ 454 /* Can't do anything useful */
473 mutex_unlock(&dev->mutex); 455 mutex_unlock(&dev->mutex);
@@ -488,17 +470,14 @@ static const struct rfkill_ops toshiba_rfk_ops = {
488}; 470};
489 471
490static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ; 472static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
491static struct backlight_device *toshiba_backlight_device;
492static int force_fan;
493static int last_key_event;
494static int key_event_valid;
495 473
496static int get_lcd(struct backlight_device *bd) 474static int get_lcd(struct backlight_device *bd)
497{ 475{
476 struct toshiba_acpi_dev *dev = bl_get_data(bd);
498 u32 hci_result; 477 u32 hci_result;
499 u32 value; 478 u32 value;
500 479
501 hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result); 480 hci_read1(dev, HCI_LCD_BRIGHTNESS, &value, &hci_result);
502 if (hci_result == HCI_SUCCESS) { 481 if (hci_result == HCI_SUCCESS) {
503 return (value >> HCI_LCD_BRIGHTNESS_SHIFT); 482 return (value >> HCI_LCD_BRIGHTNESS_SHIFT);
504 } else 483 } else
@@ -507,8 +486,13 @@ static int get_lcd(struct backlight_device *bd)
507 486
508static int lcd_proc_show(struct seq_file *m, void *v) 487static int lcd_proc_show(struct seq_file *m, void *v)
509{ 488{
510 int value = get_lcd(NULL); 489 struct toshiba_acpi_dev *dev = m->private;
490 int value;
491
492 if (!dev->backlight_dev)
493 return -ENODEV;
511 494
495 value = get_lcd(dev->backlight_dev);
512 if (value >= 0) { 496 if (value >= 0) {
513 seq_printf(m, "brightness: %d\n", value); 497 seq_printf(m, "brightness: %d\n", value);
514 seq_printf(m, "brightness_levels: %d\n", 498 seq_printf(m, "brightness_levels: %d\n",
@@ -522,15 +506,15 @@ static int lcd_proc_show(struct seq_file *m, void *v)
522 506
523static int lcd_proc_open(struct inode *inode, struct file *file) 507static int lcd_proc_open(struct inode *inode, struct file *file)
524{ 508{
525 return single_open(file, lcd_proc_show, NULL); 509 return single_open(file, lcd_proc_show, PDE(inode)->data);
526} 510}
527 511
528static int set_lcd(int value) 512static int set_lcd(struct toshiba_acpi_dev *dev, int value)
529{ 513{
530 u32 hci_result; 514 u32 hci_result;
531 515
532 value = value << HCI_LCD_BRIGHTNESS_SHIFT; 516 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
533 hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result); 517 hci_write1(dev, HCI_LCD_BRIGHTNESS, value, &hci_result);
534 if (hci_result != HCI_SUCCESS) 518 if (hci_result != HCI_SUCCESS)
535 return -EFAULT; 519 return -EFAULT;
536 520
@@ -539,12 +523,14 @@ static int set_lcd(int value)
539 523
540static int set_lcd_status(struct backlight_device *bd) 524static int set_lcd_status(struct backlight_device *bd)
541{ 525{
542 return set_lcd(bd->props.brightness); 526 struct toshiba_acpi_dev *dev = bl_get_data(bd);
527 return set_lcd(dev, bd->props.brightness);
543} 528}
544 529
545static ssize_t lcd_proc_write(struct file *file, const char __user *buf, 530static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
546 size_t count, loff_t *pos) 531 size_t count, loff_t *pos)
547{ 532{
533 struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
548 char cmd[42]; 534 char cmd[42];
549 size_t len; 535 size_t len;
550 int value; 536 int value;
@@ -557,7 +543,7 @@ static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
557 543
558 if (sscanf(cmd, " brightness : %i", &value) == 1 && 544 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
559 value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) { 545 value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) {
560 ret = set_lcd(value); 546 ret = set_lcd(dev, value);
561 if (ret == 0) 547 if (ret == 0)
562 ret = count; 548 ret = count;
563 } else { 549 } else {
@@ -577,10 +563,11 @@ static const struct file_operations lcd_proc_fops = {
577 563
578static int video_proc_show(struct seq_file *m, void *v) 564static int video_proc_show(struct seq_file *m, void *v)
579{ 565{
566 struct toshiba_acpi_dev *dev = m->private;
580 u32 hci_result; 567 u32 hci_result;
581 u32 value; 568 u32 value;
582 569
583 hci_read1(HCI_VIDEO_OUT, &value, &hci_result); 570 hci_read1(dev, HCI_VIDEO_OUT, &value, &hci_result);
584 if (hci_result == HCI_SUCCESS) { 571 if (hci_result == HCI_SUCCESS) {
585 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0; 572 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
586 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0; 573 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
@@ -597,12 +584,13 @@ static int video_proc_show(struct seq_file *m, void *v)
597 584
598static int video_proc_open(struct inode *inode, struct file *file) 585static int video_proc_open(struct inode *inode, struct file *file)
599{ 586{
600 return single_open(file, video_proc_show, NULL); 587 return single_open(file, video_proc_show, PDE(inode)->data);
601} 588}
602 589
603static ssize_t video_proc_write(struct file *file, const char __user *buf, 590static ssize_t video_proc_write(struct file *file, const char __user *buf,
604 size_t count, loff_t *pos) 591 size_t count, loff_t *pos)
605{ 592{
593 struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
606 char *cmd, *buffer; 594 char *cmd, *buffer;
607 int value; 595 int value;
608 int remain = count; 596 int remain = count;
@@ -644,7 +632,7 @@ static ssize_t video_proc_write(struct file *file, const char __user *buf,
644 632
645 kfree(cmd); 633 kfree(cmd);
646 634
647 hci_read1(HCI_VIDEO_OUT, &video_out, &hci_result); 635 hci_read1(dev, HCI_VIDEO_OUT, &video_out, &hci_result);
648 if (hci_result == HCI_SUCCESS) { 636 if (hci_result == HCI_SUCCESS) {
649 unsigned int new_video_out = video_out; 637 unsigned int new_video_out = video_out;
650 if (lcd_out != -1) 638 if (lcd_out != -1)
@@ -675,13 +663,14 @@ static const struct file_operations video_proc_fops = {
675 663
676static int fan_proc_show(struct seq_file *m, void *v) 664static int fan_proc_show(struct seq_file *m, void *v)
677{ 665{
666 struct toshiba_acpi_dev *dev = m->private;
678 u32 hci_result; 667 u32 hci_result;
679 u32 value; 668 u32 value;
680 669
681 hci_read1(HCI_FAN, &value, &hci_result); 670 hci_read1(dev, HCI_FAN, &value, &hci_result);
682 if (hci_result == HCI_SUCCESS) { 671 if (hci_result == HCI_SUCCESS) {
683 seq_printf(m, "running: %d\n", (value > 0)); 672 seq_printf(m, "running: %d\n", (value > 0));
684 seq_printf(m, "force_on: %d\n", force_fan); 673 seq_printf(m, "force_on: %d\n", dev->force_fan);
685 } else { 674 } else {
686 pr_err("Error reading fan status\n"); 675 pr_err("Error reading fan status\n");
687 } 676 }
@@ -691,12 +680,13 @@ static int fan_proc_show(struct seq_file *m, void *v)
691 680
692static int fan_proc_open(struct inode *inode, struct file *file) 681static int fan_proc_open(struct inode *inode, struct file *file)
693{ 682{
694 return single_open(file, fan_proc_show, NULL); 683 return single_open(file, fan_proc_show, PDE(inode)->data);
695} 684}
696 685
697static ssize_t fan_proc_write(struct file *file, const char __user *buf, 686static ssize_t fan_proc_write(struct file *file, const char __user *buf,
698 size_t count, loff_t *pos) 687 size_t count, loff_t *pos)
699{ 688{
689 struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
700 char cmd[42]; 690 char cmd[42];
701 size_t len; 691 size_t len;
702 int value; 692 int value;
@@ -709,11 +699,11 @@ static ssize_t fan_proc_write(struct file *file, const char __user *buf,
709 699
710 if (sscanf(cmd, " force_on : %i", &value) == 1 && 700 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
711 value >= 0 && value <= 1) { 701 value >= 0 && value <= 1) {
712 hci_write1(HCI_FAN, value, &hci_result); 702 hci_write1(dev, HCI_FAN, value, &hci_result);
713 if (hci_result != HCI_SUCCESS) 703 if (hci_result != HCI_SUCCESS)
714 return -EFAULT; 704 return -EFAULT;
715 else 705 else
716 force_fan = value; 706 dev->force_fan = value;
717 } else { 707 } else {
718 return -EINVAL; 708 return -EINVAL;
719 } 709 }
@@ -732,21 +722,22 @@ static const struct file_operations fan_proc_fops = {
732 722
733static int keys_proc_show(struct seq_file *m, void *v) 723static int keys_proc_show(struct seq_file *m, void *v)
734{ 724{
725 struct toshiba_acpi_dev *dev = m->private;
735 u32 hci_result; 726 u32 hci_result;
736 u32 value; 727 u32 value;
737 728
738 if (!key_event_valid) { 729 if (!dev->key_event_valid) {
739 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result); 730 hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result);
740 if (hci_result == HCI_SUCCESS) { 731 if (hci_result == HCI_SUCCESS) {
741 key_event_valid = 1; 732 dev->key_event_valid = 1;
742 last_key_event = value; 733 dev->last_key_event = value;
743 } else if (hci_result == HCI_EMPTY) { 734 } else if (hci_result == HCI_EMPTY) {
744 /* better luck next time */ 735 /* better luck next time */
745 } else if (hci_result == HCI_NOT_SUPPORTED) { 736 } else if (hci_result == HCI_NOT_SUPPORTED) {
746 /* This is a workaround for an unresolved issue on 737 /* This is a workaround for an unresolved issue on
747 * some machines where system events sporadically 738 * some machines where system events sporadically
748 * become disabled. */ 739 * become disabled. */
749 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result); 740 hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
750 pr_notice("Re-enabled hotkeys\n"); 741 pr_notice("Re-enabled hotkeys\n");
751 } else { 742 } else {
752 pr_err("Error reading hotkey status\n"); 743 pr_err("Error reading hotkey status\n");
@@ -754,20 +745,21 @@ static int keys_proc_show(struct seq_file *m, void *v)
754 } 745 }
755 } 746 }
756 747
757 seq_printf(m, "hotkey_ready: %d\n", key_event_valid); 748 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
758 seq_printf(m, "hotkey: 0x%04x\n", last_key_event); 749 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
759end: 750end:
760 return 0; 751 return 0;
761} 752}
762 753
763static int keys_proc_open(struct inode *inode, struct file *file) 754static int keys_proc_open(struct inode *inode, struct file *file)
764{ 755{
765 return single_open(file, keys_proc_show, NULL); 756 return single_open(file, keys_proc_show, PDE(inode)->data);
766} 757}
767 758
768static ssize_t keys_proc_write(struct file *file, const char __user *buf, 759static ssize_t keys_proc_write(struct file *file, const char __user *buf,
769 size_t count, loff_t *pos) 760 size_t count, loff_t *pos)
770{ 761{
762 struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
771 char cmd[42]; 763 char cmd[42];
772 size_t len; 764 size_t len;
773 int value; 765 int value;
@@ -778,7 +770,7 @@ static ssize_t keys_proc_write(struct file *file, const char __user *buf,
778 cmd[len] = '\0'; 770 cmd[len] = '\0';
779 771
780 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) { 772 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
781 key_event_valid = 0; 773 dev->key_event_valid = 0;
782 } else { 774 } else {
783 return -EINVAL; 775 return -EINVAL;
784 } 776 }
@@ -820,13 +812,19 @@ static const struct file_operations version_proc_fops = {
820 812
821#define PROC_TOSHIBA "toshiba" 813#define PROC_TOSHIBA "toshiba"
822 814
823static void __init create_toshiba_proc_entries(void) 815static void __devinit
816create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
824{ 817{
825 proc_create("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, &lcd_proc_fops); 818 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
826 proc_create("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, &video_proc_fops); 819 &lcd_proc_fops, dev);
827 proc_create("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, &fan_proc_fops); 820 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
828 proc_create("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, &keys_proc_fops); 821 &video_proc_fops, dev);
829 proc_create("version", S_IRUGO, toshiba_proc_dir, &version_proc_fops); 822 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
823 &fan_proc_fops, dev);
824 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
825 &keys_proc_fops, dev);
826 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
827 &version_proc_fops, dev);
830} 828}
831 829
832static void remove_toshiba_proc_entries(void) 830static void remove_toshiba_proc_entries(void)
@@ -843,224 +841,242 @@ static const struct backlight_ops toshiba_backlight_data = {
843 .update_status = set_lcd_status, 841 .update_status = set_lcd_status,
844}; 842};
845 843
846static void toshiba_acpi_notify(acpi_handle handle, u32 event, void *context) 844static int __devinit toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev,
847{ 845 char *device_path)
848 u32 hci_result, value;
849
850 if (event != 0x80)
851 return;
852 do {
853 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
854 if (hci_result == HCI_SUCCESS) {
855 if (value == 0x100)
856 continue;
857 /* act on key press; ignore key release */
858 if (value & 0x80)
859 continue;
860
861 if (!sparse_keymap_report_event(toshiba_acpi.hotkey_dev,
862 value, 1, true)) {
863 pr_info("Unknown key %x\n",
864 value);
865 }
866 } else if (hci_result == HCI_NOT_SUPPORTED) {
867 /* This is a workaround for an unresolved issue on
868 * some machines where system events sporadically
869 * become disabled. */
870 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
871 pr_notice("Re-enabled hotkeys\n");
872 }
873 } while (hci_result != HCI_EMPTY);
874}
875
876static int __init toshiba_acpi_setup_keyboard(char *device)
877{ 846{
878 acpi_status status; 847 acpi_status status;
879 int error; 848 int error;
880 849
881 status = acpi_get_handle(NULL, device, &toshiba_acpi.handle); 850 status = acpi_get_handle(NULL, device_path, &dev->handle);
882 if (ACPI_FAILURE(status)) { 851 if (ACPI_FAILURE(status)) {
883 pr_info("Unable to get notification device\n"); 852 pr_info("Unable to get notification device\n");
884 return -ENODEV; 853 return -ENODEV;
885 } 854 }
886 855
887 toshiba_acpi.hotkey_dev = input_allocate_device(); 856 dev->hotkey_dev = input_allocate_device();
888 if (!toshiba_acpi.hotkey_dev) { 857 if (!dev->hotkey_dev) {
889 pr_info("Unable to register input device\n"); 858 pr_info("Unable to register input device\n");
890 return -ENOMEM; 859 return -ENOMEM;
891 } 860 }
892 861
893 toshiba_acpi.hotkey_dev->name = "Toshiba input device"; 862 dev->hotkey_dev->name = "Toshiba input device";
894 toshiba_acpi.hotkey_dev->phys = device; 863 dev->hotkey_dev->phys = device_path;
895 toshiba_acpi.hotkey_dev->id.bustype = BUS_HOST; 864 dev->hotkey_dev->id.bustype = BUS_HOST;
896 865
897 error = sparse_keymap_setup(toshiba_acpi.hotkey_dev, 866 error = sparse_keymap_setup(dev->hotkey_dev, toshiba_acpi_keymap, NULL);
898 toshiba_acpi_keymap, NULL);
899 if (error) 867 if (error)
900 goto err_free_dev; 868 goto err_free_dev;
901 869
902 status = acpi_install_notify_handler(toshiba_acpi.handle, 870 status = acpi_evaluate_object(dev->handle, "ENAB", NULL, NULL);
903 ACPI_DEVICE_NOTIFY, toshiba_acpi_notify, NULL);
904 if (ACPI_FAILURE(status)) {
905 pr_info("Unable to install hotkey notification\n");
906 error = -ENODEV;
907 goto err_free_keymap;
908 }
909
910 status = acpi_evaluate_object(toshiba_acpi.handle, "ENAB", NULL, NULL);
911 if (ACPI_FAILURE(status)) { 871 if (ACPI_FAILURE(status)) {
912 pr_info("Unable to enable hotkeys\n"); 872 pr_info("Unable to enable hotkeys\n");
913 error = -ENODEV; 873 error = -ENODEV;
914 goto err_remove_notify; 874 goto err_free_keymap;
915 } 875 }
916 876
917 error = input_register_device(toshiba_acpi.hotkey_dev); 877 error = input_register_device(dev->hotkey_dev);
918 if (error) { 878 if (error) {
919 pr_info("Unable to register input device\n"); 879 pr_info("Unable to register input device\n");
920 goto err_remove_notify; 880 goto err_free_keymap;
921 } 881 }
922 882
923 return 0; 883 return 0;
924 884
925 err_remove_notify:
926 acpi_remove_notify_handler(toshiba_acpi.handle,
927 ACPI_DEVICE_NOTIFY, toshiba_acpi_notify);
928 err_free_keymap: 885 err_free_keymap:
929 sparse_keymap_free(toshiba_acpi.hotkey_dev); 886 sparse_keymap_free(dev->hotkey_dev);
930 err_free_dev: 887 err_free_dev:
931 input_free_device(toshiba_acpi.hotkey_dev); 888 input_free_device(dev->hotkey_dev);
932 toshiba_acpi.hotkey_dev = NULL; 889 dev->hotkey_dev = NULL;
933 return error; 890 return error;
934} 891}
935 892
936static void toshiba_acpi_exit(void) 893static int toshiba_acpi_remove(struct acpi_device *acpi_dev, int type)
937{ 894{
938 if (toshiba_acpi.hotkey_dev) { 895 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
939 acpi_remove_notify_handler(toshiba_acpi.handle,
940 ACPI_DEVICE_NOTIFY, toshiba_acpi_notify);
941 sparse_keymap_free(toshiba_acpi.hotkey_dev);
942 input_unregister_device(toshiba_acpi.hotkey_dev);
943 }
944 896
945 if (toshiba_acpi.bt_rfk) { 897 remove_toshiba_proc_entries();
946 rfkill_unregister(toshiba_acpi.bt_rfk);
947 rfkill_destroy(toshiba_acpi.bt_rfk);
948 }
949 898
950 if (toshiba_backlight_device) 899 if (dev->hotkey_dev) {
951 backlight_device_unregister(toshiba_backlight_device); 900 input_unregister_device(dev->hotkey_dev);
901 sparse_keymap_free(dev->hotkey_dev);
902 }
952 903
953 remove_toshiba_proc_entries(); 904 if (dev->bt_rfk) {
905 rfkill_unregister(dev->bt_rfk);
906 rfkill_destroy(dev->bt_rfk);
907 }
954 908
955 if (toshiba_proc_dir) 909 if (dev->backlight_dev)
956 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); 910 backlight_device_unregister(dev->backlight_dev);
957 911
958 if (toshiba_acpi.illumination_installed) 912 if (dev->illumination_installed)
959 led_classdev_unregister(&toshiba_led); 913 led_classdev_unregister(&dev->led_dev);
960 914
961 platform_device_unregister(toshiba_acpi.p_dev); 915 kfree(dev);
962 916
963 return; 917 return 0;
964} 918}
965 919
966static int __init toshiba_acpi_init(void) 920static int __devinit toshiba_acpi_add(struct acpi_device *acpi_dev)
967{ 921{
922 struct toshiba_acpi_dev *dev;
968 u32 hci_result; 923 u32 hci_result;
969 bool bt_present; 924 bool bt_present;
970 int ret = 0; 925 int ret = 0;
971 struct backlight_properties props; 926 struct backlight_properties props;
972 927
973 if (acpi_disabled) 928 pr_info("Toshiba Laptop ACPI Extras version %s\n",
974 return -ENODEV; 929 TOSHIBA_ACPI_VERSION);
930
931 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
932 if (!dev)
933 return -ENOMEM;
934 dev->acpi_dev = acpi_dev;
935 acpi_dev->driver_data = dev;
975 936
976 /* simple device detection: look for HCI method */ 937 /* simple device detection: look for HCI method */
977 if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD)) { 938 if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD)) {
978 method_hci = TOSH_INTERFACE_1 GHCI_METHOD; 939 dev->method_hci = TOSH_INTERFACE_1 GHCI_METHOD;
979 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1)) 940 if (toshiba_acpi_setup_keyboard(dev, TOSH_INTERFACE_1))
980 pr_info("Unable to activate hotkeys\n"); 941 pr_info("Unable to activate hotkeys\n");
981 } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD)) { 942 } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD)) {
982 method_hci = TOSH_INTERFACE_2 GHCI_METHOD; 943 dev->method_hci = TOSH_INTERFACE_2 GHCI_METHOD;
983 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2)) 944 if (toshiba_acpi_setup_keyboard(dev, TOSH_INTERFACE_2))
984 pr_info("Unable to activate hotkeys\n"); 945 pr_info("Unable to activate hotkeys\n");
985 } else 946 } else {
986 return -ENODEV; 947 ret = -ENODEV;
987 948 goto error;
988 pr_info("Toshiba Laptop ACPI Extras version %s\n",
989 TOSHIBA_ACPI_VERSION);
990 pr_info(" HCI method: %s\n", method_hci);
991
992 mutex_init(&toshiba_acpi.mutex);
993
994 toshiba_acpi.p_dev = platform_device_register_simple("toshiba_acpi",
995 -1, NULL, 0);
996 if (IS_ERR(toshiba_acpi.p_dev)) {
997 ret = PTR_ERR(toshiba_acpi.p_dev);
998 pr_err("unable to register platform device\n");
999 toshiba_acpi.p_dev = NULL;
1000 toshiba_acpi_exit();
1001 return ret;
1002 } 949 }
1003 950
1004 force_fan = 0; 951 pr_info("HCI method: %s\n", dev->method_hci);
1005 key_event_valid = 0; 952
953 mutex_init(&dev->mutex);
1006 954
1007 /* enable event fifo */ 955 /* enable event fifo */
1008 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result); 956 hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
1009 957
1010 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir); 958 create_toshiba_proc_entries(dev);
1011 if (!toshiba_proc_dir) {
1012 toshiba_acpi_exit();
1013 return -ENODEV;
1014 } else {
1015 create_toshiba_proc_entries();
1016 }
1017 959
1018 props.type = BACKLIGHT_PLATFORM; 960 props.type = BACKLIGHT_PLATFORM;
1019 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1; 961 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
1020 toshiba_backlight_device = backlight_device_register("toshiba", 962 dev->backlight_dev = backlight_device_register("toshiba",
1021 &toshiba_acpi.p_dev->dev, 963 &acpi_dev->dev,
1022 NULL, 964 dev,
1023 &toshiba_backlight_data, 965 &toshiba_backlight_data,
1024 &props); 966 &props);
1025 if (IS_ERR(toshiba_backlight_device)) { 967 if (IS_ERR(dev->backlight_dev)) {
1026 ret = PTR_ERR(toshiba_backlight_device); 968 ret = PTR_ERR(dev->backlight_dev);
1027 969
1028 pr_err("Could not register toshiba backlight device\n"); 970 pr_err("Could not register toshiba backlight device\n");
1029 toshiba_backlight_device = NULL; 971 dev->backlight_dev = NULL;
1030 toshiba_acpi_exit(); 972 goto error;
1031 return ret;
1032 } 973 }
1033 974
1034 /* Register rfkill switch for Bluetooth */ 975 /* Register rfkill switch for Bluetooth */
1035 if (hci_get_bt_present(&bt_present) == HCI_SUCCESS && bt_present) { 976 if (hci_get_bt_present(dev, &bt_present) == HCI_SUCCESS && bt_present) {
1036 toshiba_acpi.bt_rfk = rfkill_alloc(toshiba_acpi.bt_name, 977 dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
1037 &toshiba_acpi.p_dev->dev, 978 &acpi_dev->dev,
1038 RFKILL_TYPE_BLUETOOTH, 979 RFKILL_TYPE_BLUETOOTH,
1039 &toshiba_rfk_ops, 980 &toshiba_rfk_ops,
1040 &toshiba_acpi); 981 dev);
1041 if (!toshiba_acpi.bt_rfk) { 982 if (!dev->bt_rfk) {
1042 pr_err("unable to allocate rfkill device\n"); 983 pr_err("unable to allocate rfkill device\n");
1043 toshiba_acpi_exit(); 984 ret = -ENOMEM;
1044 return -ENOMEM; 985 goto error;
1045 } 986 }
1046 987
1047 ret = rfkill_register(toshiba_acpi.bt_rfk); 988 ret = rfkill_register(dev->bt_rfk);
1048 if (ret) { 989 if (ret) {
1049 pr_err("unable to register rfkill device\n"); 990 pr_err("unable to register rfkill device\n");
1050 rfkill_destroy(toshiba_acpi.bt_rfk); 991 rfkill_destroy(dev->bt_rfk);
1051 toshiba_acpi_exit(); 992 goto error;
1052 return ret;
1053 } 993 }
1054 } 994 }
1055 995
1056 toshiba_acpi.illumination_installed = 0; 996 if (toshiba_illumination_available(dev)) {
1057 if (toshiba_illumination_available()) { 997 dev->led_dev.name = "toshiba::illumination";
1058 if (!led_classdev_register(&(toshiba_acpi.p_dev->dev), 998 dev->led_dev.max_brightness = 1;
1059 &toshiba_led)) 999 dev->led_dev.brightness_set = toshiba_illumination_set;
1060 toshiba_acpi.illumination_installed = 1; 1000 dev->led_dev.brightness_get = toshiba_illumination_get;
1001 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
1002 dev->illumination_installed = 1;
1061 } 1003 }
1062 1004
1063 return 0; 1005 return 0;
1006
1007error:
1008 toshiba_acpi_remove(acpi_dev, 0);
1009 return ret;
1010}
1011
1012static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
1013{
1014 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
1015 u32 hci_result, value;
1016
1017 if (event != 0x80)
1018 return;
1019 do {
1020 hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result);
1021 if (hci_result == HCI_SUCCESS) {
1022 if (value == 0x100)
1023 continue;
1024 /* act on key press; ignore key release */
1025 if (value & 0x80)
1026 continue;
1027
1028 if (!sparse_keymap_report_event(dev->hotkey_dev,
1029 value, 1, true)) {
1030 pr_info("Unknown key %x\n",
1031 value);
1032 }
1033 } else if (hci_result == HCI_NOT_SUPPORTED) {
1034 /* This is a workaround for an unresolved issue on
1035 * some machines where system events sporadically
1036 * become disabled. */
1037 hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
1038 pr_notice("Re-enabled hotkeys\n");
1039 }
1040 } while (hci_result != HCI_EMPTY);
1041}
1042
1043
1044static struct acpi_driver toshiba_acpi_driver = {
1045 .name = "Toshiba ACPI driver",
1046 .owner = THIS_MODULE,
1047 .ids = toshiba_device_ids,
1048 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1049 .ops = {
1050 .add = toshiba_acpi_add,
1051 .remove = toshiba_acpi_remove,
1052 .notify = toshiba_acpi_notify,
1053 },
1054};
1055
1056static int __init toshiba_acpi_init(void)
1057{
1058 int ret;
1059
1060 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
1061 if (!toshiba_proc_dir) {
1062 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
1063 return -ENODEV;
1064 }
1065
1066 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
1067 if (ret) {
1068 pr_err("Failed to register ACPI driver: %d\n", ret);
1069 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
1070 }
1071
1072 return ret;
1073}
1074
1075static void __exit toshiba_acpi_exit(void)
1076{
1077 acpi_bus_unregister_driver(&toshiba_acpi_driver);
1078 if (toshiba_proc_dir)
1079 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
1064} 1080}
1065 1081
1066module_init(toshiba_acpi_init); 1082module_init(toshiba_acpi_init);