fujitsu-laptop.c 31.8 KB
Newer Older
1 2 3
/*-*-linux-c-*-*/

/*
J
Jonathan Woithe 已提交
4
  Copyright (C) 2007,2008 Jonathan Woithe <jwoithe@just42.net>
J
Jonathan Woithe 已提交
5
  Copyright (C) 2008 Peter Gruber <nokos@gmx.net>
6
  Copyright (C) 2008 Tony Vroon <tony@linx.net>
7 8 9 10
  Based on earlier work:
    Copyright (C) 2003 Shane Spencer <shane@bogomip.com>
    Adrian Yee <brewt-fujitsu@brewt.org>

J
Jonathan Woithe 已提交
11 12
  Templated from msi-laptop.c and thinkpad_acpi.c which is copyright
  by its respective authors.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  02110-1301, USA.
 */

/*
 * fujitsu-laptop.c - Fujitsu laptop support, providing access to additional
 * features made available on a range of Fujitsu laptops including the
 * P2xxx/P5xxx/S6xxx/S7xxx series.
 *
 * This driver exports a few files in /sys/devices/platform/fujitsu-laptop/;
 * others may be added at a later date.
 *
 *   lcd_level - Screen brightness: contains a single integer in the
 *   range 0..7. (rw)
 *
 * In addition to these platform device attributes the driver
 * registers itself in the Linux backlight control subsystem and is
 * available to userspace under /sys/class/backlight/fujitsu-laptop/.
 *
J
Jonathan Woithe 已提交
45 46 47
 * Hotkeys present on certain Fujitsu laptops (eg: the S6xxx series) are
 * also supported by this driver.
 *
48 49 50
 * This driver has been tested on a Fujitsu Lifebook S6410, S7020 and
 * P8010.  It should work on most P-series and S-series Lifebooks, but
 * YMMV.
J
Jonathan Woithe 已提交
51 52 53 54 55 56
 *
 * The module parameter use_alt_lcd_levels switches between different ACPI
 * brightness controls which are used by different Fujitsu laptops.  In most
 * cases the correct method is automatically detected. "use_alt_lcd_levels=1"
 * is applicable for a Fujitsu Lifebook S6410 if autodetection fails.
 *
57 58
 */

59 60
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

61 62 63 64 65 66
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/acpi.h>
#include <linux/dmi.h>
#include <linux/backlight.h>
J
Jonathan Woithe 已提交
67 68 69
#include <linux/input.h>
#include <linux/kfifo.h>
#include <linux/video_output.h>
70
#include <linux/platform_device.h>
71
#include <linux/slab.h>
72
#if defined(CONFIG_LEDS_CLASS) || defined(CONFIG_LEDS_CLASS_MODULE)
73 74
#include <linux/leds.h>
#endif
75

76
#define FUJITSU_DRIVER_VERSION "0.6.0"
77 78 79 80 81

#define FUJITSU_LCD_N_LEVELS 8

#define ACPI_FUJITSU_CLASS              "fujitsu"
#define ACPI_FUJITSU_HID                "FUJ02B1"
J
Jonathan Woithe 已提交
82
#define ACPI_FUJITSU_DRIVER_NAME	"Fujitsu laptop FUJ02B1 ACPI brightness driver"
83
#define ACPI_FUJITSU_DEVICE_NAME        "Fujitsu FUJ02B1"
J
Jonathan Woithe 已提交
84 85 86 87 88 89 90 91 92
#define ACPI_FUJITSU_HOTKEY_HID 	"FUJ02E3"
#define ACPI_FUJITSU_HOTKEY_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver"
#define ACPI_FUJITSU_HOTKEY_DEVICE_NAME "Fujitsu FUJ02E3"

#define ACPI_FUJITSU_NOTIFY_CODE1     0x80

#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS     0x86
#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS     0x87

93 94 95 96 97 98 99 100 101
/* FUNC interface - command values */
#define FUNC_RFKILL	0x1000
#define FUNC_LEDS	0x1001
#define FUNC_BUTTONS	0x1002
#define FUNC_BACKLIGHT  0x1004

/* FUNC interface - responses */
#define UNSUPPORTED_CMD 0x80000000

102
#if defined(CONFIG_LEDS_CLASS) || defined(CONFIG_LEDS_CLASS_MODULE)
103 104 105 106 107 108 109 110
/* FUNC interface - LED control */
#define FUNC_LED_OFF	0x1
#define FUNC_LED_ON	0x30001
#define KEYBOARD_LAMPS	0x100
#define LOGOLAMP_POWERON 0x2000
#define LOGOLAMP_ALWAYS  0x4000
#endif

J
Jonathan Woithe 已提交
111
/* Hotkey details */
112 113 114 115
#define KEY1_CODE	0x410	/* codes for the keys in the GIRB register */
#define KEY2_CODE	0x411
#define KEY3_CODE	0x412
#define KEY4_CODE	0x413
J
Jonathan Woithe 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144

#define MAX_HOTKEY_RINGBUFFER_SIZE 100
#define RINGBUFFERSIZE 40

/* Debugging */
#define FUJLAPTOP_LOG	   ACPI_FUJITSU_HID ": "
#define FUJLAPTOP_ERR	   KERN_ERR FUJLAPTOP_LOG
#define FUJLAPTOP_NOTICE   KERN_NOTICE FUJLAPTOP_LOG
#define FUJLAPTOP_INFO	   KERN_INFO FUJLAPTOP_LOG
#define FUJLAPTOP_DEBUG    KERN_DEBUG FUJLAPTOP_LOG

#define FUJLAPTOP_DBG_ALL	  0xffff
#define FUJLAPTOP_DBG_ERROR	  0x0001
#define FUJLAPTOP_DBG_WARN	  0x0002
#define FUJLAPTOP_DBG_INFO	  0x0004
#define FUJLAPTOP_DBG_TRACE	  0x0008

#define dbg_printk(a_dbg_level, format, arg...) \
	do { if (dbg_level & a_dbg_level) \
		printk(FUJLAPTOP_DEBUG "%s: " format, __func__ , ## arg); \
	} while (0)
#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
#define vdbg_printk(a_dbg_level, format, arg...) \
	dbg_printk(a_dbg_level, format, ## arg)
#else
#define vdbg_printk(a_dbg_level, format, arg...)
#endif

/* Device controlling the backlight and associated keys */
145 146
struct fujitsu_t {
	acpi_handle acpi_handle;
J
Jonathan Woithe 已提交
147 148 149
	struct acpi_device *dev;
	struct input_dev *input;
	char phys[32];
150 151
	struct backlight_device *bl_device;
	struct platform_device *pf_device;
152
	int keycode1, keycode2, keycode3, keycode4;
153

J
Jonathan Woithe 已提交
154
	unsigned int max_brightness;
155 156 157 158 159
	unsigned int brightness_changed;
	unsigned int brightness_level;
};

static struct fujitsu_t *fujitsu;
J
Jonathan Woithe 已提交
160 161 162 163 164 165 166 167 168 169
static int use_alt_lcd_levels = -1;
static int disable_brightness_adjust = -1;

/* Device used to access other hotkeys on the laptop */
struct fujitsu_hotkey_t {
	acpi_handle acpi_handle;
	struct acpi_device *dev;
	struct input_dev *input;
	char phys[32];
	struct platform_device *pf_device;
170
	struct kfifo fifo;
J
Jonathan Woithe 已提交
171
	spinlock_t fifo_lock;
172
	int rfkill_supported;
173 174 175
	int rfkill_state;
	int logolamp_registered;
	int kblamps_registered;
J
Jonathan Woithe 已提交
176
};
177

J
Jonathan Woithe 已提交
178 179
static struct fujitsu_hotkey_t *fujitsu_hotkey;

180
static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event);
J
Jonathan Woithe 已提交
181

182
#if defined(CONFIG_LEDS_CLASS) || defined(CONFIG_LEDS_CLASS_MODULE)
183 184 185 186
static enum led_brightness logolamp_get(struct led_classdev *cdev);
static void logolamp_set(struct led_classdev *cdev,
			       enum led_brightness brightness);

187
static struct led_classdev logolamp_led = {
188 189 190 191 192 193 194 195 196
 .name = "fujitsu::logolamp",
 .brightness_get = logolamp_get,
 .brightness_set = logolamp_set
};

static enum led_brightness kblamps_get(struct led_classdev *cdev);
static void kblamps_set(struct led_classdev *cdev,
			       enum led_brightness brightness);

197
static struct led_classdev kblamps_led = {
198 199 200 201 202 203
 .name = "fujitsu::kblamps",
 .brightness_get = kblamps_get,
 .brightness_set = kblamps_set
};
#endif

J
Jonathan Woithe 已提交
204 205 206 207
#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
static u32 dbg_level = 0x03;
#endif

208
static void acpi_fujitsu_notify(struct acpi_device *device, u32 event);
J
Jonathan Woithe 已提交
209

210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
/* Fujitsu ACPI interface function */

static int call_fext_func(int cmd, int arg0, int arg1, int arg2)
{
	acpi_status status = AE_OK;
	union acpi_object params[4] = {
	{ .type = ACPI_TYPE_INTEGER },
	{ .type = ACPI_TYPE_INTEGER },
	{ .type = ACPI_TYPE_INTEGER },
	{ .type = ACPI_TYPE_INTEGER }
	};
	struct acpi_object_list arg_list = { 4, &params[0] };
	struct acpi_buffer output;
	union acpi_object out_obj;
	acpi_handle handle = NULL;

	status = acpi_get_handle(fujitsu_hotkey->acpi_handle, "FUNC", &handle);
	if (ACPI_FAILURE(status)) {
		vdbg_printk(FUJLAPTOP_DBG_ERROR,
				"FUNC interface is not present\n");
		return -ENODEV;
	}

	params[0].integer.value = cmd;
	params[1].integer.value = arg0;
	params[2].integer.value = arg1;
	params[3].integer.value = arg2;

	output.length = sizeof(out_obj);
	output.pointer = &out_obj;

	status = acpi_evaluate_object(handle, NULL, &arg_list, &output);
	if (ACPI_FAILURE(status)) {
		vdbg_printk(FUJLAPTOP_DBG_WARN,
			"FUNC 0x%x (args 0x%x, 0x%x, 0x%x) call failed\n",
				cmd, arg0, arg1, arg2);
		return -ENODEV;
	}

	if (out_obj.type != ACPI_TYPE_INTEGER) {
		vdbg_printk(FUJLAPTOP_DBG_WARN,
			"FUNC 0x%x (args 0x%x, 0x%x, 0x%x) did not "
			"return an integer\n",
			cmd, arg0, arg1, arg2);
		return -ENODEV;
	}

	vdbg_printk(FUJLAPTOP_DBG_TRACE,
		"FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n",
			cmd, arg0, arg1, arg2, (int)out_obj.integer.value);
	return out_obj.integer.value;
}

263
#if defined(CONFIG_LEDS_CLASS) || defined(CONFIG_LEDS_CLASS_MODULE)
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
/* LED class callbacks */

static void logolamp_set(struct led_classdev *cdev,
			       enum led_brightness brightness)
{
	if (brightness >= LED_FULL) {
		call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_ON);
		call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, FUNC_LED_ON);
	} else if (brightness >= LED_HALF) {
		call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_ON);
		call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, FUNC_LED_OFF);
	} else {
		call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_OFF);
	}
}

static void kblamps_set(struct led_classdev *cdev,
			       enum led_brightness brightness)
{
	if (brightness >= LED_FULL)
		call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_ON);
	else
		call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_OFF);
}

static enum led_brightness logolamp_get(struct led_classdev *cdev)
{
	enum led_brightness brightness = LED_OFF;
	int poweron, always;

	poweron = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
	if (poweron == FUNC_LED_ON) {
		brightness = LED_HALF;
		always = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
		if (always == FUNC_LED_ON)
			brightness = LED_FULL;
	}
	return brightness;
}

static enum led_brightness kblamps_get(struct led_classdev *cdev)
{
	enum led_brightness brightness = LED_OFF;

	if (call_fext_func(FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
		brightness = LED_FULL;

	return brightness;
}
#endif

J
Jonathan Woithe 已提交
315
/* Hardware access for LCD brightness control */
316 317 318 319 320 321

static int set_lcd_level(int level)
{
	acpi_status status = AE_OK;
	acpi_handle handle = NULL;

J
Jonathan Woithe 已提交
322 323 324 325
	vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n",
		    level);

	if (level < 0 || level >= fujitsu->max_brightness)
326 327 328 329
		return -EINVAL;

	status = acpi_get_handle(fujitsu->acpi_handle, "SBLL", &handle);
	if (ACPI_FAILURE(status)) {
J
Jonathan Woithe 已提交
330 331 332 333 334
		vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n");
		return -ENODEV;
	}


335
	status = acpi_execute_simple_method(handle, NULL, level);
J
Jonathan Woithe 已提交
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
	if (ACPI_FAILURE(status))
		return -ENODEV;

	return 0;
}

static int set_lcd_level_alt(int level)
{
	acpi_status status = AE_OK;
	acpi_handle handle = NULL;

	vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n",
		    level);

	if (level < 0 || level >= fujitsu->max_brightness)
		return -EINVAL;

	status = acpi_get_handle(fujitsu->acpi_handle, "SBL2", &handle);
	if (ACPI_FAILURE(status)) {
		vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n");
356 357 358
		return -ENODEV;
	}

359
	status = acpi_execute_simple_method(handle, NULL, level);
360 361 362 363 364 365 366 367
	if (ACPI_FAILURE(status))
		return -ENODEV;

	return 0;
}

static int get_lcd_level(void)
{
368
	unsigned long long state = 0;
369 370
	acpi_status status = AE_OK;

J
Jonathan Woithe 已提交
371 372
	vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");

373 374
	status =
	    acpi_evaluate_integer(fujitsu->acpi_handle, "GBLL", NULL, &state);
375 376
	if (ACPI_FAILURE(status))
		return 0;
377

J
Jonathan Woithe 已提交
378 379 380 381 382 383 384 385 386 387 388 389
	fujitsu->brightness_level = state & 0x0fffffff;

	if (state & 0x80000000)
		fujitsu->brightness_changed = 1;
	else
		fujitsu->brightness_changed = 0;

	return fujitsu->brightness_level;
}

static int get_max_brightness(void)
{
390
	unsigned long long state = 0;
J
Jonathan Woithe 已提交
391 392 393 394 395 396
	acpi_status status = AE_OK;

	vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");

	status =
	    acpi_evaluate_integer(fujitsu->acpi_handle, "RBLL", NULL, &state);
397 398
	if (ACPI_FAILURE(status))
		return -1;
J
Jonathan Woithe 已提交
399 400 401 402 403 404

	fujitsu->max_brightness = state;

	return fujitsu->max_brightness;
}

405 406 407 408
/* Backlight device stuff */

static int bl_get_brightness(struct backlight_device *b)
{
409
	return get_lcd_level();
410 411 412 413
}

static int bl_update_status(struct backlight_device *b)
{
414 415 416 417 418 419 420 421 422 423
	int ret;
	if (b->props.power == 4)
		ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x3);
	else
		ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x0);
	if (ret != 0)
		vdbg_printk(FUJLAPTOP_DBG_ERROR,
			"Unable to adjust backlight power, error code %i\n",
			ret);

J
Jonathan Woithe 已提交
424
	if (use_alt_lcd_levels)
425
		ret = set_lcd_level_alt(b->props.brightness);
J
Jonathan Woithe 已提交
426
	else
427 428 429 430 431 432
		ret = set_lcd_level(b->props.brightness);
	if (ret != 0)
		vdbg_printk(FUJLAPTOP_DBG_ERROR,
			"Unable to adjust LCD brightness, error code %i\n",
			ret);
	return ret;
433 434
}

L
Lionel Debroux 已提交
435
static const struct backlight_ops fujitsubl_ops = {
436 437 438 439
	.get_brightness = bl_get_brightness,
	.update_status = bl_update_status,
};

J
Jonathan Woithe 已提交
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
/* Platform LCD brightness device */

static ssize_t
show_max_brightness(struct device *dev,
		    struct device_attribute *attr, char *buf)
{

	int ret;

	ret = get_max_brightness();
	if (ret < 0)
		return ret;

	return sprintf(buf, "%i\n", ret);
}

static ssize_t
show_brightness_changed(struct device *dev,
			struct device_attribute *attr, char *buf)
{

	int ret;

	ret = fujitsu->brightness_changed;
	if (ret < 0)
		return ret;

	return sprintf(buf, "%i\n", ret);
}
469 470 471 472 473 474 475

static ssize_t show_lcd_level(struct device *dev,
			      struct device_attribute *attr, char *buf)
{

	int ret;

476
	ret = get_lcd_level();
477 478 479 480 481 482 483 484 485 486 487 488 489 490
	if (ret < 0)
		return ret;

	return sprintf(buf, "%i\n", ret);
}

static ssize_t store_lcd_level(struct device *dev,
			       struct device_attribute *attr, const char *buf,
			       size_t count)
{

	int level, ret;

	if (sscanf(buf, "%i", &level) != 1
J
Jonathan Woithe 已提交
491
	    || (level < 0 || level >= fujitsu->max_brightness))
492 493
		return -EINVAL;

J
Jonathan Woithe 已提交
494 495 496 497 498 499 500
	if (use_alt_lcd_levels)
		ret = set_lcd_level_alt(level);
	else
		ret = set_lcd_level(level);
	if (ret < 0)
		return ret;

501
	ret = get_lcd_level();
502 503 504 505 506 507
	if (ret < 0)
		return ret;

	return count;
}

508 509 510
static ssize_t
ignore_store(struct device *dev,
	     struct device_attribute *attr, const char *buf, size_t count)
J
Jonathan Woithe 已提交
511
{
512 513
	return count;
}
J
Jonathan Woithe 已提交
514

515 516 517 518
static ssize_t
show_lid_state(struct device *dev,
			struct device_attribute *attr, char *buf)
{
519
	if (!(fujitsu_hotkey->rfkill_supported & 0x100))
520 521 522 523 524 525
		return sprintf(buf, "unknown\n");
	if (fujitsu_hotkey->rfkill_state & 0x100)
		return sprintf(buf, "open\n");
	else
		return sprintf(buf, "closed\n");
}
J
Jonathan Woithe 已提交
526

527 528 529 530
static ssize_t
show_dock_state(struct device *dev,
			struct device_attribute *attr, char *buf)
{
531
	if (!(fujitsu_hotkey->rfkill_supported & 0x200))
532 533 534 535 536
		return sprintf(buf, "unknown\n");
	if (fujitsu_hotkey->rfkill_state & 0x200)
		return sprintf(buf, "docked\n");
	else
		return sprintf(buf, "undocked\n");
J
Jonathan Woithe 已提交
537 538 539
}

static ssize_t
540 541
show_radios_state(struct device *dev,
			struct device_attribute *attr, char *buf)
J
Jonathan Woithe 已提交
542
{
543
	if (!(fujitsu_hotkey->rfkill_supported & 0x20))
544 545 546 547 548
		return sprintf(buf, "unknown\n");
	if (fujitsu_hotkey->rfkill_state & 0x20)
		return sprintf(buf, "on\n");
	else
		return sprintf(buf, "killed\n");
J
Jonathan Woithe 已提交
549 550 551 552 553
}

static DEVICE_ATTR(max_brightness, 0444, show_max_brightness, ignore_store);
static DEVICE_ATTR(brightness_changed, 0444, show_brightness_changed,
		   ignore_store);
554
static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
555 556 557
static DEVICE_ATTR(lid, 0444, show_lid_state, ignore_store);
static DEVICE_ATTR(dock, 0444, show_dock_state, ignore_store);
static DEVICE_ATTR(radios, 0444, show_radios_state, ignore_store);
558 559

static struct attribute *fujitsupf_attributes[] = {
J
Jonathan Woithe 已提交
560 561
	&dev_attr_brightness_changed.attr,
	&dev_attr_max_brightness.attr,
562
	&dev_attr_lcd_level.attr,
563 564 565
	&dev_attr_lid.attr,
	&dev_attr_dock.attr,
	&dev_attr_radios.attr,
566 567 568 569 570 571 572 573 574 575 576 577 578 579
	NULL
};

static struct attribute_group fujitsupf_attribute_group = {
	.attrs = fujitsupf_attributes
};

static struct platform_driver fujitsupf_driver = {
	.driver = {
		   .name = "fujitsu-laptop",
		   .owner = THIS_MODULE,
		   }
};

580
static void dmi_check_cb_common(const struct dmi_system_id *id)
J
Jonathan Woithe 已提交
581 582
{
	acpi_handle handle;
583
	pr_info("Identified laptop model '%s'\n", id->ident);
J
Jonathan Woithe 已提交
584
	if (use_alt_lcd_levels == -1) {
585 586 587 588 589 590 591
		if (ACPI_SUCCESS(acpi_get_handle(NULL,
				"\\_SB.PCI0.LPCB.FJEX.SBL2", &handle)))
			use_alt_lcd_levels = 1;
		else
			use_alt_lcd_levels = 0;
		vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detected usealt as "
			"%i\n", use_alt_lcd_levels);
J
Jonathan Woithe 已提交
592
	}
593 594 595 596 597 598 599
}

static int dmi_check_cb_s6410(const struct dmi_system_id *id)
{
	dmi_check_cb_common(id);
	fujitsu->keycode1 = KEY_SCREENLOCK;	/* "Lock" */
	fujitsu->keycode2 = KEY_HELP;	/* "Mobility Center" */
600
	return 1;
601 602
}

603 604 605 606 607
static int dmi_check_cb_s6420(const struct dmi_system_id *id)
{
	dmi_check_cb_common(id);
	fujitsu->keycode1 = KEY_SCREENLOCK;	/* "Lock" */
	fujitsu->keycode2 = KEY_HELP;	/* "Mobility Center" */
608
	return 1;
609 610
}

611 612 613 614 615 616
static int dmi_check_cb_p8010(const struct dmi_system_id *id)
{
	dmi_check_cb_common(id);
	fujitsu->keycode1 = KEY_HELP;	/* "Support" */
	fujitsu->keycode3 = KEY_SWITCHVIDEOMODE;	/* "Presentation" */
	fujitsu->keycode4 = KEY_WWW;	/* "Internet" */
617
	return 1;
J
Jonathan Woithe 已提交
618 619
}

620
static struct dmi_system_id fujitsu_dmi_table[] = {
J
Jonathan Woithe 已提交
621
	{
622
	 .ident = "Fujitsu Siemens S6410",
J
Jonathan Woithe 已提交
623 624 625 626 627
	 .matches = {
		     DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
		     DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
		     },
	 .callback = dmi_check_cb_s6410},
628 629 630 631 632 633 634
	{
	 .ident = "Fujitsu Siemens S6420",
	 .matches = {
		     DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
		     DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
		     },
	 .callback = dmi_check_cb_s6420},
635
	{
636
	 .ident = "Fujitsu LifeBook P8010",
637 638 639
	 .matches = {
		     DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
		     DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
640 641
		     },
	 .callback = dmi_check_cb_p8010},
J
Jonathan Woithe 已提交
642 643 644 645
	{}
};

/* ACPI device for LCD brightness control */
646

647
static int acpi_fujitsu_add(struct acpi_device *device)
648
{
J
Jonathan Woithe 已提交
649
	acpi_handle handle;
650 651
	int result = 0;
	int state = 0;
J
Jonathan Woithe 已提交
652 653
	struct input_dev *input;
	int error;
654 655 656 657 658 659 660

	if (!device)
		return -EINVAL;

	fujitsu->acpi_handle = device->handle;
	sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_DEVICE_NAME);
	sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
661
	device->driver_data = fujitsu;
662

J
Jonathan Woithe 已提交
663 664 665
	fujitsu->input = input = input_allocate_device();
	if (!input) {
		error = -ENOMEM;
666
		goto err_stop;
J
Jonathan Woithe 已提交
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
	}

	snprintf(fujitsu->phys, sizeof(fujitsu->phys),
		 "%s/video/input0", acpi_device_hid(device));

	input->name = acpi_device_name(device);
	input->phys = fujitsu->phys;
	input->id.bustype = BUS_HOST;
	input->id.product = 0x06;
	input->dev.parent = &device->dev;
	input->evbit[0] = BIT(EV_KEY);
	set_bit(KEY_BRIGHTNESSUP, input->keybit);
	set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
	set_bit(KEY_UNKNOWN, input->keybit);

	error = input_register_device(input);
	if (error)
		goto err_free_input_dev;

686
	result = acpi_bus_update_power(fujitsu->acpi_handle, &state);
687
	if (result) {
688
		pr_err("Error reading power state\n");
689
		goto err_unregister_input_dev;
690 691
	}

692
	pr_info("ACPI: %s [%s] (%s)\n",
693 694 695
	       acpi_device_name(device), acpi_device_bid(device),
	       !device->power.state ? "on" : "off");

J
Jonathan Woithe 已提交
696 697 698 699 700 701 702 703
	fujitsu->dev = device;

	if (ACPI_SUCCESS
	    (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) {
		vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
		if (ACPI_FAILURE
		    (acpi_evaluate_object
		     (device->handle, METHOD_NAME__INI, NULL, NULL)))
704
			pr_err("_INI Method failed\n");
J
Jonathan Woithe 已提交
705 706 707 708 709 710
	}

	/* do config (detect defaults) */
	use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
	disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
	vdbg_printk(FUJLAPTOP_DBG_INFO,
711 712
		    "config: [alt interface: %d], [adjust disable: %d]\n",
		    use_alt_lcd_levels, disable_brightness_adjust);
J
Jonathan Woithe 已提交
713 714 715

	if (get_max_brightness() <= 0)
		fujitsu->max_brightness = FUJITSU_LCD_N_LEVELS;
716
	get_lcd_level();
J
Jonathan Woithe 已提交
717 718 719

	return result;

720 721
err_unregister_input_dev:
	input_unregister_device(input);
722
	input = NULL;
J
Jonathan Woithe 已提交
723 724 725
err_free_input_dev:
	input_free_device(input);
err_stop:
726 727 728
	return result;
}

729
static int acpi_fujitsu_remove(struct acpi_device *device)
730
{
731 732
	struct fujitsu_t *fujitsu = acpi_driver_data(device);
	struct input_dev *input = fujitsu->input;
733

734
	input_unregister_device(input);
J
Jonathan Woithe 已提交
735

A
Al Viro 已提交
736
	fujitsu->acpi_handle = NULL;
737 738 739 740

	return 0;
}

J
Jonathan Woithe 已提交
741 742
/* Brightness notify */

743
static void acpi_fujitsu_notify(struct acpi_device *device, u32 event)
J
Jonathan Woithe 已提交
744 745 746 747 748 749 750 751 752 753 754
{
	struct input_dev *input;
	int keycode;
	int oldb, newb;

	input = fujitsu->input;

	switch (event) {
	case ACPI_FUJITSU_NOTIFY_CODE1:
		keycode = 0;
		oldb = fujitsu->brightness_level;
755
		get_lcd_level();
J
Jonathan Woithe 已提交
756 757 758 759 760 761
		newb = fujitsu->brightness_level;

		vdbg_printk(FUJLAPTOP_DBG_TRACE,
			    "brightness button event [%i -> %i (%i)]\n",
			    oldb, newb, fujitsu->brightness_changed);

762
		if (oldb < newb) {
J
Jonathan Woithe 已提交
763 764 765 766 767 768
			if (disable_brightness_adjust != 1) {
				if (use_alt_lcd_levels)
					set_lcd_level_alt(newb);
				else
					set_lcd_level(newb);
			}
769
			keycode = KEY_BRIGHTNESSUP;
J
Jonathan Woithe 已提交
770 771 772 773 774 775 776
		} else if (oldb > newb) {
			if (disable_brightness_adjust != 1) {
				if (use_alt_lcd_levels)
					set_lcd_level_alt(newb);
				else
					set_lcd_level(newb);
			}
777
			keycode = KEY_BRIGHTNESSDOWN;
J
Jonathan Woithe 已提交
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
		}
		break;
	default:
		keycode = KEY_UNKNOWN;
		vdbg_printk(FUJLAPTOP_DBG_WARN,
			    "unsupported event [0x%x]\n", event);
		break;
	}

	if (keycode != 0) {
		input_report_key(input, keycode, 1);
		input_sync(input);
		input_report_key(input, keycode, 0);
		input_sync(input);
	}
}

/* ACPI device for hotkey handling */

static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
{
	acpi_handle handle;
	int result = 0;
	int state = 0;
	struct input_dev *input;
	int error;
	int i;

	if (!device)
		return -EINVAL;

	fujitsu_hotkey->acpi_handle = device->handle;
	sprintf(acpi_device_name(device), "%s",
		ACPI_FUJITSU_HOTKEY_DEVICE_NAME);
	sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
813
	device->driver_data = fujitsu_hotkey;
J
Jonathan Woithe 已提交
814 815 816

	/* kfifo */
	spin_lock_init(&fujitsu_hotkey->fifo_lock);
817
	error = kfifo_alloc(&fujitsu_hotkey->fifo, RINGBUFFERSIZE * sizeof(int),
S
Stefani Seibold 已提交
818
			GFP_KERNEL);
819
	if (error) {
820
		pr_err("kfifo_alloc failed\n");
J
Jonathan Woithe 已提交
821 822 823 824 825 826
		goto err_stop;
	}

	fujitsu_hotkey->input = input = input_allocate_device();
	if (!input) {
		error = -ENOMEM;
827
		goto err_free_fifo;
J
Jonathan Woithe 已提交
828 829 830 831 832 833 834 835 836 837
	}

	snprintf(fujitsu_hotkey->phys, sizeof(fujitsu_hotkey->phys),
		 "%s/video/input0", acpi_device_hid(device));

	input->name = acpi_device_name(device);
	input->phys = fujitsu_hotkey->phys;
	input->id.bustype = BUS_HOST;
	input->id.product = 0x06;
	input->dev.parent = &device->dev;
838 839

	set_bit(EV_KEY, input->evbit);
840 841 842 843
	set_bit(fujitsu->keycode1, input->keybit);
	set_bit(fujitsu->keycode2, input->keybit);
	set_bit(fujitsu->keycode3, input->keybit);
	set_bit(fujitsu->keycode4, input->keybit);
J
Jonathan Woithe 已提交
844 845 846 847 848 849
	set_bit(KEY_UNKNOWN, input->keybit);

	error = input_register_device(input);
	if (error)
		goto err_free_input_dev;

850
	result = acpi_bus_update_power(fujitsu_hotkey->acpi_handle, &state);
J
Jonathan Woithe 已提交
851
	if (result) {
852
		pr_err("Error reading power state\n");
853
		goto err_unregister_input_dev;
J
Jonathan Woithe 已提交
854 855
	}

856 857 858
	pr_info("ACPI: %s [%s] (%s)\n",
		acpi_device_name(device), acpi_device_bid(device),
		!device->power.state ? "on" : "off");
J
Jonathan Woithe 已提交
859 860 861 862 863 864 865 866 867

	fujitsu_hotkey->dev = device;

	if (ACPI_SUCCESS
	    (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) {
		vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
		if (ACPI_FAILURE
		    (acpi_evaluate_object
		     (device->handle, METHOD_NAME__INI, NULL, NULL)))
868
			pr_err("_INI Method failed\n");
J
Jonathan Woithe 已提交
869 870
	}

871 872 873 874
	i = 0;
	while (call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
		&& (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
		; /* No action, result is discarded */
J
Jonathan Woithe 已提交
875 876
	vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);

877 878 879 880 881 882 883 884 885 886 887
	fujitsu_hotkey->rfkill_supported =
		call_fext_func(FUNC_RFKILL, 0x0, 0x0, 0x0);

	/* Make sure our bitmask of supported functions is cleared if the
	   RFKILL function block is not implemented, like on the S7020. */
	if (fujitsu_hotkey->rfkill_supported == UNSUPPORTED_CMD)
		fujitsu_hotkey->rfkill_supported = 0;

	if (fujitsu_hotkey->rfkill_supported)
		fujitsu_hotkey->rfkill_state =
			call_fext_func(FUNC_RFKILL, 0x4, 0x0, 0x0);
888 889

	/* Suspect this is a keymap of the application panel, print it */
890
	pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0));
891

892
#if defined(CONFIG_LEDS_CLASS) || defined(CONFIG_LEDS_CLASS_MODULE)
893 894 895 896 897 898
	if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
		result = led_classdev_register(&fujitsu->pf_device->dev,
						&logolamp_led);
		if (result == 0) {
			fujitsu_hotkey->logolamp_registered = 1;
		} else {
899 900
			pr_err("Could not register LED handler for logo lamp, error %i\n",
			       result);
901 902 903 904 905 906 907 908 909 910
		}
	}

	if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
	   (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
		result = led_classdev_register(&fujitsu->pf_device->dev,
						&kblamps_led);
		if (result == 0) {
			fujitsu_hotkey->kblamps_registered = 1;
		} else {
911 912
			pr_err("Could not register LED handler for keyboard lamps, error %i\n",
			       result);
913 914
		}
	}
915
#endif
916

J
Jonathan Woithe 已提交
917 918
	return result;

919 920
err_unregister_input_dev:
	input_unregister_device(input);
921
	input = NULL;
J
Jonathan Woithe 已提交
922 923
err_free_input_dev:
	input_free_device(input);
924
err_free_fifo:
925
	kfifo_free(&fujitsu_hotkey->fifo);
J
Jonathan Woithe 已提交
926 927 928 929
err_stop:
	return result;
}

930
static int acpi_fujitsu_hotkey_remove(struct acpi_device *device)
J
Jonathan Woithe 已提交
931
{
932 933
	struct fujitsu_hotkey_t *fujitsu_hotkey = acpi_driver_data(device);
	struct input_dev *input = fujitsu_hotkey->input;
J
Jonathan Woithe 已提交
934

935
#if defined(CONFIG_LEDS_CLASS) || defined(CONFIG_LEDS_CLASS_MODULE)
936 937
	if (fujitsu_hotkey->logolamp_registered)
		led_classdev_unregister(&logolamp_led);
J
Jonathan Woithe 已提交
938

939 940 941
	if (fujitsu_hotkey->kblamps_registered)
		led_classdev_unregister(&kblamps_led);
#endif
J
Jonathan Woithe 已提交
942

943
	input_unregister_device(input);
J
Jonathan Woithe 已提交
944

945
	kfifo_free(&fujitsu_hotkey->fifo);
J
Jonathan Woithe 已提交
946

947 948
	fujitsu_hotkey->acpi_handle = NULL;

J
Jonathan Woithe 已提交
949 950 951
	return 0;
}

952
static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event)
J
Jonathan Woithe 已提交
953 954 955 956 957 958 959 960
{
	struct input_dev *input;
	int keycode, keycode_r;
	unsigned int irb = 1;
	int i, status;

	input = fujitsu_hotkey->input;

961 962 963
	if (fujitsu_hotkey->rfkill_supported)
		fujitsu_hotkey->rfkill_state =
			call_fext_func(FUNC_RFKILL, 0x4, 0x0, 0x0);
J
Jonathan Woithe 已提交
964 965 966 967

	switch (event) {
	case ACPI_FUJITSU_NOTIFY_CODE1:
		i = 0;
968 969 970
		while ((irb =
			call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0
				&& (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) {
J
Jonathan Woithe 已提交
971
			switch (irb & 0x4ff) {
972 973
			case KEY1_CODE:
				keycode = fujitsu->keycode1;
J
Jonathan Woithe 已提交
974
				break;
975 976
			case KEY2_CODE:
				keycode = fujitsu->keycode2;
J
Jonathan Woithe 已提交
977
				break;
978 979
			case KEY3_CODE:
				keycode = fujitsu->keycode3;
J
Jonathan Woithe 已提交
980
				break;
981 982
			case KEY4_CODE:
				keycode = fujitsu->keycode4;
J
Jonathan Woithe 已提交
983 984 985 986 987 988
				break;
			case 0:
				keycode = 0;
				break;
			default:
				vdbg_printk(FUJLAPTOP_DBG_WARN,
989
					    "Unknown GIRB result [%x]\n", irb);
J
Jonathan Woithe 已提交
990 991 992 993 994 995 996
				keycode = -1;
				break;
			}
			if (keycode > 0) {
				vdbg_printk(FUJLAPTOP_DBG_TRACE,
					"Push keycode into ringbuffer [%d]\n",
					keycode);
997
				status = kfifo_in_locked(&fujitsu_hotkey->fifo,
998
						   (unsigned char *)&keycode,
S
Stefani Seibold 已提交
999 1000
						   sizeof(keycode),
						   &fujitsu_hotkey->fifo_lock);
J
Jonathan Woithe 已提交
1001 1002
				if (status != sizeof(keycode)) {
					vdbg_printk(FUJLAPTOP_DBG_WARN,
1003 1004
					    "Could not push keycode [0x%x]\n",
					    keycode);
J
Jonathan Woithe 已提交
1005 1006 1007 1008 1009 1010
				} else {
					input_report_key(input, keycode, 1);
					input_sync(input);
				}
			} else if (keycode == 0) {
				while ((status =
1011
					kfifo_out_locked(
S
Stefani Seibold 已提交
1012 1013 1014 1015 1016
					 &fujitsu_hotkey->fifo,
					 (unsigned char *) &keycode_r,
					 sizeof(keycode_r),
					 &fujitsu_hotkey->fifo_lock))
					 == sizeof(keycode_r)) {
J
Jonathan Woithe 已提交
1017 1018 1019
					input_report_key(input, keycode_r, 0);
					input_sync(input);
					vdbg_printk(FUJLAPTOP_DBG_TRACE,
1020 1021
					  "Pop keycode from ringbuffer [%d]\n",
					  keycode_r);
J
Jonathan Woithe 已提交
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
				}
			}
		}

		break;
	default:
		keycode = KEY_UNKNOWN;
		vdbg_printk(FUJLAPTOP_DBG_WARN,
			    "Unsupported event [0x%x]\n", event);
		input_report_key(input, keycode, 1);
		input_sync(input);
		input_report_key(input, keycode, 0);
		input_sync(input);
		break;
	}
}

/* Initialization */

1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052
static const struct acpi_device_id fujitsu_device_ids[] = {
	{ACPI_FUJITSU_HID, 0},
	{"", 0},
};

static struct acpi_driver acpi_fujitsu_driver = {
	.name = ACPI_FUJITSU_DRIVER_NAME,
	.class = ACPI_FUJITSU_CLASS,
	.ids = fujitsu_device_ids,
	.ops = {
		.add = acpi_fujitsu_add,
		.remove = acpi_fujitsu_remove,
1053
		.notify = acpi_fujitsu_notify,
1054 1055 1056
		},
};

J
Jonathan Woithe 已提交
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
static const struct acpi_device_id fujitsu_hotkey_device_ids[] = {
	{ACPI_FUJITSU_HOTKEY_HID, 0},
	{"", 0},
};

static struct acpi_driver acpi_fujitsu_hotkey_driver = {
	.name = ACPI_FUJITSU_HOTKEY_DRIVER_NAME,
	.class = ACPI_FUJITSU_CLASS,
	.ids = fujitsu_hotkey_device_ids,
	.ops = {
		.add = acpi_fujitsu_hotkey_add,
		.remove = acpi_fujitsu_hotkey_remove,
1069
		.notify = acpi_fujitsu_hotkey_notify,
J
Jonathan Woithe 已提交
1070 1071
		},
};
1072 1073 1074

static int __init fujitsu_init(void)
{
J
Jonathan Woithe 已提交
1075
	int ret, result, max_brightness;
1076 1077 1078 1079

	if (acpi_disabled)
		return -ENODEV;

J
Julia Lawall 已提交
1080
	fujitsu = kzalloc(sizeof(struct fujitsu_t), GFP_KERNEL);
1081 1082
	if (!fujitsu)
		return -ENOMEM;
1083 1084 1085 1086 1087
	fujitsu->keycode1 = KEY_PROG1;
	fujitsu->keycode2 = KEY_PROG2;
	fujitsu->keycode3 = KEY_PROG3;
	fujitsu->keycode4 = KEY_PROG4;
	dmi_check_system(fujitsu_dmi_table);
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112

	result = acpi_bus_register_driver(&acpi_fujitsu_driver);
	if (result < 0) {
		ret = -ENODEV;
		goto fail_acpi;
	}

	/* Register platform stuff */

	fujitsu->pf_device = platform_device_alloc("fujitsu-laptop", -1);
	if (!fujitsu->pf_device) {
		ret = -ENOMEM;
		goto fail_platform_driver;
	}

	ret = platform_device_add(fujitsu->pf_device);
	if (ret)
		goto fail_platform_device1;

	ret =
	    sysfs_create_group(&fujitsu->pf_device->dev.kobj,
			       &fujitsupf_attribute_group);
	if (ret)
		goto fail_platform_device2;

J
Jonathan Woithe 已提交
1113 1114
	/* Register backlight stuff */

1115
	if (!acpi_video_backlight_support()) {
1116 1117 1118 1119
		struct backlight_properties props;

		memset(&props, 0, sizeof(struct backlight_properties));
		max_brightness = fujitsu->max_brightness;
M
Matthew Garrett 已提交
1120
		props.type = BACKLIGHT_PLATFORM;
1121 1122 1123 1124 1125
		props.max_brightness = max_brightness - 1;
		fujitsu->bl_device = backlight_device_register("fujitsu-laptop",
							       NULL, NULL,
							       &fujitsubl_ops,
							       &props);
1126 1127 1128 1129 1130
		if (IS_ERR(fujitsu->bl_device)) {
			ret = PTR_ERR(fujitsu->bl_device);
			fujitsu->bl_device = NULL;
			goto fail_sysfs_group;
		}
1131 1132
		fujitsu->bl_device->props.brightness = fujitsu->brightness_level;
	}
J
Jonathan Woithe 已提交
1133 1134 1135 1136 1137 1138 1139

	ret = platform_driver_register(&fujitsupf_driver);
	if (ret)
		goto fail_backlight;

	/* Register hotkey driver */

J
Julia Lawall 已提交
1140
	fujitsu_hotkey = kzalloc(sizeof(struct fujitsu_hotkey_t), GFP_KERNEL);
J
Jonathan Woithe 已提交
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
	if (!fujitsu_hotkey) {
		ret = -ENOMEM;
		goto fail_hotkey;
	}

	result = acpi_bus_register_driver(&acpi_fujitsu_hotkey_driver);
	if (result < 0) {
		ret = -ENODEV;
		goto fail_hotkey1;
	}

1152 1153 1154 1155 1156 1157 1158 1159 1160
	/* Sync backlight power status (needs FUJ02E3 device, hence deferred) */

	if (!acpi_video_backlight_support()) {
		if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
			fujitsu->bl_device->props.power = 4;
		else
			fujitsu->bl_device->props.power = 0;
	}

1161
	pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
1162 1163 1164

	return 0;

J
Jonathan Woithe 已提交
1165 1166 1167
fail_hotkey1:
	kfree(fujitsu_hotkey);
fail_hotkey:
1168
	platform_driver_unregister(&fujitsupf_driver);
J
Jonathan Woithe 已提交
1169
fail_backlight:
1170 1171
	if (fujitsu->bl_device)
		backlight_device_unregister(fujitsu->bl_device);
1172 1173 1174
fail_sysfs_group:
	sysfs_remove_group(&fujitsu->pf_device->dev.kobj,
			   &fujitsupf_attribute_group);
J
Jonathan Woithe 已提交
1175 1176 1177 1178 1179 1180 1181
fail_platform_device2:
	platform_device_del(fujitsu->pf_device);
fail_platform_device1:
	platform_device_put(fujitsu->pf_device);
fail_platform_driver:
	acpi_bus_unregister_driver(&acpi_fujitsu_driver);
fail_acpi:
1182 1183 1184 1185 1186 1187 1188
	kfree(fujitsu);

	return ret;
}

static void __exit fujitsu_cleanup(void)
{
1189
	acpi_bus_unregister_driver(&acpi_fujitsu_hotkey_driver);
1190

1191
	kfree(fujitsu_hotkey);
1192

1193
	platform_driver_unregister(&fujitsupf_driver);
1194

1195 1196
	if (fujitsu->bl_device)
		backlight_device_unregister(fujitsu->bl_device);
1197

1198 1199
	sysfs_remove_group(&fujitsu->pf_device->dev.kobj,
			   &fujitsupf_attribute_group);
1200

1201
	platform_device_unregister(fujitsu->pf_device);
1202

1203
	acpi_bus_unregister_driver(&acpi_fujitsu_driver);
J
Jonathan Woithe 已提交
1204

1205
	kfree(fujitsu);
J
Jonathan Woithe 已提交
1206

1207
	pr_info("driver unloaded\n");
1208 1209 1210 1211 1212
}

module_init(fujitsu_init);
module_exit(fujitsu_cleanup);

J
Jonathan Woithe 已提交
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222
module_param(use_alt_lcd_levels, uint, 0644);
MODULE_PARM_DESC(use_alt_lcd_levels,
		 "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
module_param(disable_brightness_adjust, uint, 0644);
MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
module_param_named(debug, dbg_level, uint, 0644);
MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
#endif

1223
MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
1224 1225 1226
MODULE_DESCRIPTION("Fujitsu laptop extras support");
MODULE_VERSION(FUJITSU_DRIVER_VERSION);
MODULE_LICENSE("GPL");
1227

1228
MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*");
1229
MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1E6:*:cvrS6420:*");
1230
MODULE_ALIAS("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*");
J
Jonathan Woithe 已提交
1231

1232
static struct pnp_device_id pnp_ids[] __used = {
1233 1234 1235 1236
	{.id = "FUJ02bf"},
	{.id = "FUJ02B1"},
	{.id = "FUJ02E3"},
	{.id = ""}
1237
};
1238

1239
MODULE_DEVICE_TABLE(pnp, pnp_ids);