]>
Commit | Line | Data |
---|---|---|
d0482533 JW |
1 | /*-*-linux-c-*-*/ |
2 | ||
3 | /* | |
409a3e98 | 4 | Copyright (C) 2007,2008 Jonathan Woithe <jwoithe@just42.net> |
20b93734 | 5 | Copyright (C) 2008 Peter Gruber <nokos@gmx.net> |
3a407086 | 6 | Copyright (C) 2008 Tony Vroon <tony@linx.net> |
d0482533 JW |
7 | Based on earlier work: |
8 | Copyright (C) 2003 Shane Spencer <shane@bogomip.com> | |
9 | Adrian Yee <brewt-fujitsu@brewt.org> | |
10 | ||
20b93734 JW |
11 | Templated from msi-laptop.c and thinkpad_acpi.c which is copyright |
12 | by its respective authors. | |
d0482533 JW |
13 | |
14 | This program is free software; you can redistribute it and/or modify | |
15 | it under the terms of the GNU General Public License as published by | |
16 | the Free Software Foundation; either version 2 of the License, or | |
17 | (at your option) any later version. | |
18 | ||
19 | This program is distributed in the hope that it will be useful, but | |
20 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
22 | General Public License for more details. | |
23 | ||
24 | You should have received a copy of the GNU General Public License | |
25 | along with this program; if not, write to the Free Software | |
26 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
27 | 02110-1301, USA. | |
28 | */ | |
29 | ||
30 | /* | |
31 | * fujitsu-laptop.c - Fujitsu laptop support, providing access to additional | |
32 | * features made available on a range of Fujitsu laptops including the | |
33 | * P2xxx/P5xxx/S6xxx/S7xxx series. | |
34 | * | |
35 | * This driver exports a few files in /sys/devices/platform/fujitsu-laptop/; | |
36 | * others may be added at a later date. | |
37 | * | |
38 | * lcd_level - Screen brightness: contains a single integer in the | |
39 | * range 0..7. (rw) | |
40 | * | |
41 | * In addition to these platform device attributes the driver | |
42 | * registers itself in the Linux backlight control subsystem and is | |
43 | * available to userspace under /sys/class/backlight/fujitsu-laptop/. | |
44 | * | |
20b93734 JW |
45 | * Hotkeys present on certain Fujitsu laptops (eg: the S6xxx series) are |
46 | * also supported by this driver. | |
47 | * | |
0e6a66e9 JW |
48 | * This driver has been tested on a Fujitsu Lifebook S6410, S7020 and |
49 | * P8010. It should work on most P-series and S-series Lifebooks, but | |
50 | * YMMV. | |
20b93734 JW |
51 | * |
52 | * The module parameter use_alt_lcd_levels switches between different ACPI | |
53 | * brightness controls which are used by different Fujitsu laptops. In most | |
54 | * cases the correct method is automatically detected. "use_alt_lcd_levels=1" | |
55 | * is applicable for a Fujitsu Lifebook S6410 if autodetection fails. | |
56 | * | |
d0482533 JW |
57 | */ |
58 | ||
77bad7c8 JP |
59 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
60 | ||
d0482533 JW |
61 | #include <linux/module.h> |
62 | #include <linux/kernel.h> | |
63 | #include <linux/init.h> | |
64 | #include <linux/acpi.h> | |
65 | #include <linux/dmi.h> | |
66 | #include <linux/backlight.h> | |
e8549e2c | 67 | #include <linux/fb.h> |
20b93734 JW |
68 | #include <linux/input.h> |
69 | #include <linux/kfifo.h> | |
d0482533 | 70 | #include <linux/platform_device.h> |
5a0e3ad6 | 71 | #include <linux/slab.h> |
575b245d | 72 | #if IS_ENABLED(CONFIG_LEDS_CLASS) |
3a407086 TV |
73 | #include <linux/leds.h> |
74 | #endif | |
413226f7 | 75 | #include <acpi/video.h> |
d0482533 | 76 | |
84a6ce26 | 77 | #define FUJITSU_DRIVER_VERSION "0.6.0" |
d0482533 JW |
78 | |
79 | #define FUJITSU_LCD_N_LEVELS 8 | |
80 | ||
81 | #define ACPI_FUJITSU_CLASS "fujitsu" | |
82 | #define ACPI_FUJITSU_HID "FUJ02B1" | |
20b93734 | 83 | #define ACPI_FUJITSU_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver" |
d0482533 | 84 | #define ACPI_FUJITSU_DEVICE_NAME "Fujitsu FUJ02B1" |
20b93734 JW |
85 | #define ACPI_FUJITSU_HOTKEY_HID "FUJ02E3" |
86 | #define ACPI_FUJITSU_HOTKEY_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver" | |
87 | #define ACPI_FUJITSU_HOTKEY_DEVICE_NAME "Fujitsu FUJ02E3" | |
88 | ||
89 | #define ACPI_FUJITSU_NOTIFY_CODE1 0x80 | |
90 | ||
3a407086 TV |
91 | /* FUNC interface - command values */ |
92 | #define FUNC_RFKILL 0x1000 | |
93 | #define FUNC_LEDS 0x1001 | |
94 | #define FUNC_BUTTONS 0x1002 | |
95 | #define FUNC_BACKLIGHT 0x1004 | |
96 | ||
97 | /* FUNC interface - responses */ | |
98 | #define UNSUPPORTED_CMD 0x80000000 | |
99 | ||
575b245d | 100 | #if IS_ENABLED(CONFIG_LEDS_CLASS) |
3a407086 TV |
101 | /* FUNC interface - LED control */ |
102 | #define FUNC_LED_OFF 0x1 | |
103 | #define FUNC_LED_ON 0x30001 | |
104 | #define KEYBOARD_LAMPS 0x100 | |
105 | #define LOGOLAMP_POWERON 0x2000 | |
106 | #define LOGOLAMP_ALWAYS 0x4000 | |
4f62568c | 107 | #define RADIO_LED_ON 0x20 |
d6b88f64 MG |
108 | #define ECO_LED 0x10000 |
109 | #define ECO_LED_ON 0x80000 | |
3a407086 TV |
110 | #endif |
111 | ||
20b93734 | 112 | /* Hotkey details */ |
0e6a66e9 JW |
113 | #define KEY1_CODE 0x410 /* codes for the keys in the GIRB register */ |
114 | #define KEY2_CODE 0x411 | |
115 | #define KEY3_CODE 0x412 | |
116 | #define KEY4_CODE 0x413 | |
b5df36cf | 117 | #define KEY5_CODE 0x420 |
20b93734 JW |
118 | |
119 | #define MAX_HOTKEY_RINGBUFFER_SIZE 100 | |
120 | #define RINGBUFFERSIZE 40 | |
121 | ||
122 | /* Debugging */ | |
20b93734 JW |
123 | #define FUJLAPTOP_DBG_ERROR 0x0001 |
124 | #define FUJLAPTOP_DBG_WARN 0x0002 | |
125 | #define FUJLAPTOP_DBG_INFO 0x0004 | |
126 | #define FUJLAPTOP_DBG_TRACE 0x0008 | |
127 | ||
c4960cf0 JD |
128 | #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG |
129 | #define vdbg_printk(a_dbg_level, format, arg...) \ | |
20b93734 | 130 | do { if (dbg_level & a_dbg_level) \ |
98020a4a | 131 | printk(KERN_DEBUG pr_fmt("%s: " format), __func__, ## arg); \ |
20b93734 | 132 | } while (0) |
20b93734 | 133 | #else |
c4960cf0 JD |
134 | #define vdbg_printk(a_dbg_level, format, arg...) \ |
135 | do { } while (0) | |
20b93734 JW |
136 | #endif |
137 | ||
138 | /* Device controlling the backlight and associated keys */ | |
d0482533 JW |
139 | struct fujitsu_t { |
140 | acpi_handle acpi_handle; | |
20b93734 JW |
141 | struct acpi_device *dev; |
142 | struct input_dev *input; | |
143 | char phys[32]; | |
d0482533 JW |
144 | struct backlight_device *bl_device; |
145 | struct platform_device *pf_device; | |
b5df36cf | 146 | int keycode1, keycode2, keycode3, keycode4, keycode5; |
d0482533 | 147 | |
20b93734 | 148 | unsigned int max_brightness; |
d0482533 JW |
149 | unsigned int brightness_changed; |
150 | unsigned int brightness_level; | |
151 | }; | |
152 | ||
153 | static struct fujitsu_t *fujitsu; | |
20b93734 | 154 | static int use_alt_lcd_levels = -1; |
20b93734 JW |
155 | static int disable_brightness_adjust = -1; |
156 | ||
157 | /* Device used to access other hotkeys on the laptop */ | |
158 | struct fujitsu_hotkey_t { | |
159 | acpi_handle acpi_handle; | |
160 | struct acpi_device *dev; | |
161 | struct input_dev *input; | |
162 | char phys[32]; | |
163 | struct platform_device *pf_device; | |
45465487 | 164 | struct kfifo fifo; |
20b93734 | 165 | spinlock_t fifo_lock; |
4898c2b2 | 166 | int rfkill_supported; |
3a407086 TV |
167 | int rfkill_state; |
168 | int logolamp_registered; | |
169 | int kblamps_registered; | |
4f62568c | 170 | int radio_led_registered; |
d6b88f64 | 171 | int eco_led_registered; |
20b93734 | 172 | }; |
d0482533 | 173 | |
20b93734 JW |
174 | static struct fujitsu_hotkey_t *fujitsu_hotkey; |
175 | ||
b4ec0275 | 176 | static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event); |
20b93734 | 177 | |
575b245d | 178 | #if IS_ENABLED(CONFIG_LEDS_CLASS) |
3a407086 | 179 | static enum led_brightness logolamp_get(struct led_classdev *cdev); |
a608a9d5 | 180 | static int logolamp_set(struct led_classdev *cdev, |
3a407086 TV |
181 | enum led_brightness brightness); |
182 | ||
67af7111 | 183 | static struct led_classdev logolamp_led = { |
3a407086 TV |
184 | .name = "fujitsu::logolamp", |
185 | .brightness_get = logolamp_get, | |
a608a9d5 | 186 | .brightness_set_blocking = logolamp_set |
3a407086 TV |
187 | }; |
188 | ||
189 | static enum led_brightness kblamps_get(struct led_classdev *cdev); | |
a608a9d5 | 190 | static int kblamps_set(struct led_classdev *cdev, |
3a407086 TV |
191 | enum led_brightness brightness); |
192 | ||
67af7111 | 193 | static struct led_classdev kblamps_led = { |
3a407086 TV |
194 | .name = "fujitsu::kblamps", |
195 | .brightness_get = kblamps_get, | |
a608a9d5 | 196 | .brightness_set_blocking = kblamps_set |
3a407086 | 197 | }; |
4f62568c MK |
198 | |
199 | static enum led_brightness radio_led_get(struct led_classdev *cdev); | |
a608a9d5 | 200 | static int radio_led_set(struct led_classdev *cdev, |
4f62568c MK |
201 | enum led_brightness brightness); |
202 | ||
203 | static struct led_classdev radio_led = { | |
204 | .name = "fujitsu::radio_led", | |
5f25b005 | 205 | .default_trigger = "rfkill-any", |
4f62568c | 206 | .brightness_get = radio_led_get, |
a608a9d5 | 207 | .brightness_set_blocking = radio_led_set |
4f62568c | 208 | }; |
d6b88f64 MG |
209 | |
210 | static enum led_brightness eco_led_get(struct led_classdev *cdev); | |
a608a9d5 | 211 | static int eco_led_set(struct led_classdev *cdev, |
d6b88f64 MG |
212 | enum led_brightness brightness); |
213 | ||
214 | static struct led_classdev eco_led = { | |
215 | .name = "fujitsu::eco_led", | |
d6b88f64 | 216 | .brightness_get = eco_led_get, |
a608a9d5 | 217 | .brightness_set_blocking = eco_led_set |
d6b88f64 | 218 | }; |
3a407086 TV |
219 | #endif |
220 | ||
20b93734 JW |
221 | #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG |
222 | static u32 dbg_level = 0x03; | |
223 | #endif | |
224 | ||
700b6721 | 225 | static void acpi_fujitsu_notify(struct acpi_device *device, u32 event); |
20b93734 | 226 | |
3a407086 TV |
227 | /* Fujitsu ACPI interface function */ |
228 | ||
229 | static int call_fext_func(int cmd, int arg0, int arg1, int arg2) | |
230 | { | |
231 | acpi_status status = AE_OK; | |
232 | union acpi_object params[4] = { | |
233 | { .type = ACPI_TYPE_INTEGER }, | |
234 | { .type = ACPI_TYPE_INTEGER }, | |
235 | { .type = ACPI_TYPE_INTEGER }, | |
236 | { .type = ACPI_TYPE_INTEGER } | |
237 | }; | |
238 | struct acpi_object_list arg_list = { 4, ¶ms[0] }; | |
29c29a9b | 239 | unsigned long long value; |
3a407086 TV |
240 | acpi_handle handle = NULL; |
241 | ||
242 | status = acpi_get_handle(fujitsu_hotkey->acpi_handle, "FUNC", &handle); | |
243 | if (ACPI_FAILURE(status)) { | |
244 | vdbg_printk(FUJLAPTOP_DBG_ERROR, | |
245 | "FUNC interface is not present\n"); | |
246 | return -ENODEV; | |
247 | } | |
248 | ||
249 | params[0].integer.value = cmd; | |
250 | params[1].integer.value = arg0; | |
251 | params[2].integer.value = arg1; | |
252 | params[3].integer.value = arg2; | |
253 | ||
29c29a9b | 254 | status = acpi_evaluate_integer(handle, NULL, &arg_list, &value); |
3a407086 TV |
255 | if (ACPI_FAILURE(status)) { |
256 | vdbg_printk(FUJLAPTOP_DBG_WARN, | |
257 | "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) call failed\n", | |
258 | cmd, arg0, arg1, arg2); | |
259 | return -ENODEV; | |
260 | } | |
261 | ||
3a407086 TV |
262 | vdbg_printk(FUJLAPTOP_DBG_TRACE, |
263 | "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n", | |
29c29a9b ZR |
264 | cmd, arg0, arg1, arg2, (int)value); |
265 | return value; | |
3a407086 TV |
266 | } |
267 | ||
575b245d | 268 | #if IS_ENABLED(CONFIG_LEDS_CLASS) |
3a407086 TV |
269 | /* LED class callbacks */ |
270 | ||
a608a9d5 | 271 | static int logolamp_set(struct led_classdev *cdev, |
3a407086 TV |
272 | enum led_brightness brightness) |
273 | { | |
dcb50b35 MK |
274 | int poweron = FUNC_LED_ON, always = FUNC_LED_ON; |
275 | int ret; | |
276 | ||
277 | if (brightness < LED_HALF) | |
278 | poweron = FUNC_LED_OFF; | |
279 | ||
280 | if (brightness < LED_FULL) | |
281 | always = FUNC_LED_OFF; | |
282 | ||
283 | ret = call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron); | |
284 | if (ret < 0) | |
285 | return ret; | |
286 | ||
287 | return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always); | |
3a407086 TV |
288 | } |
289 | ||
a608a9d5 | 290 | static int kblamps_set(struct led_classdev *cdev, |
3a407086 TV |
291 | enum led_brightness brightness) |
292 | { | |
293 | if (brightness >= LED_FULL) | |
a608a9d5 | 294 | return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_ON); |
3a407086 | 295 | else |
a608a9d5 | 296 | return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_OFF); |
3a407086 TV |
297 | } |
298 | ||
a608a9d5 | 299 | static int radio_led_set(struct led_classdev *cdev, |
4f62568c MK |
300 | enum led_brightness brightness) |
301 | { | |
302 | if (brightness >= LED_FULL) | |
a608a9d5 | 303 | return call_fext_func(FUNC_RFKILL, 0x5, RADIO_LED_ON, RADIO_LED_ON); |
4f62568c | 304 | else |
a608a9d5 | 305 | return call_fext_func(FUNC_RFKILL, 0x5, RADIO_LED_ON, 0x0); |
4f62568c MK |
306 | } |
307 | ||
a608a9d5 | 308 | static int eco_led_set(struct led_classdev *cdev, |
d6b88f64 MG |
309 | enum led_brightness brightness) |
310 | { | |
311 | int curr; | |
312 | ||
313 | curr = call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0); | |
69678934 | 314 | if (brightness >= LED_FULL) |
a608a9d5 | 315 | return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr | ECO_LED_ON); |
d6b88f64 | 316 | else |
a608a9d5 | 317 | return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr & ~ECO_LED_ON); |
d6b88f64 MG |
318 | } |
319 | ||
3a407086 TV |
320 | static enum led_brightness logolamp_get(struct led_classdev *cdev) |
321 | { | |
5c461e8e MK |
322 | int ret; |
323 | ||
324 | ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0); | |
325 | if (ret == FUNC_LED_ON) | |
326 | return LED_FULL; | |
327 | ||
328 | ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0); | |
329 | if (ret == FUNC_LED_ON) | |
330 | return LED_HALF; | |
331 | ||
332 | return LED_OFF; | |
3a407086 TV |
333 | } |
334 | ||
335 | static enum led_brightness kblamps_get(struct led_classdev *cdev) | |
336 | { | |
337 | enum led_brightness brightness = LED_OFF; | |
338 | ||
339 | if (call_fext_func(FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON) | |
340 | brightness = LED_FULL; | |
341 | ||
342 | return brightness; | |
343 | } | |
4f62568c MK |
344 | |
345 | static enum led_brightness radio_led_get(struct led_classdev *cdev) | |
346 | { | |
347 | enum led_brightness brightness = LED_OFF; | |
348 | ||
349 | if (call_fext_func(FUNC_RFKILL, 0x4, 0x0, 0x0) & RADIO_LED_ON) | |
350 | brightness = LED_FULL; | |
351 | ||
352 | return brightness; | |
353 | } | |
d6b88f64 MG |
354 | |
355 | static enum led_brightness eco_led_get(struct led_classdev *cdev) | |
356 | { | |
357 | enum led_brightness brightness = LED_OFF; | |
358 | ||
359 | if (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) & ECO_LED_ON) | |
69678934 | 360 | brightness = LED_FULL; |
d6b88f64 MG |
361 | |
362 | return brightness; | |
363 | } | |
3a407086 TV |
364 | #endif |
365 | ||
20b93734 | 366 | /* Hardware access for LCD brightness control */ |
d0482533 JW |
367 | |
368 | static int set_lcd_level(int level) | |
369 | { | |
370 | acpi_status status = AE_OK; | |
d0482533 JW |
371 | acpi_handle handle = NULL; |
372 | ||
20b93734 JW |
373 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n", |
374 | level); | |
375 | ||
376 | if (level < 0 || level >= fujitsu->max_brightness) | |
d0482533 JW |
377 | return -EINVAL; |
378 | ||
d0482533 JW |
379 | status = acpi_get_handle(fujitsu->acpi_handle, "SBLL", &handle); |
380 | if (ACPI_FAILURE(status)) { | |
20b93734 JW |
381 | vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n"); |
382 | return -ENODEV; | |
383 | } | |
384 | ||
20b93734 | 385 | |
6c7fe47a | 386 | status = acpi_execute_simple_method(handle, NULL, level); |
20b93734 JW |
387 | if (ACPI_FAILURE(status)) |
388 | return -ENODEV; | |
389 | ||
390 | return 0; | |
391 | } | |
392 | ||
393 | static int set_lcd_level_alt(int level) | |
394 | { | |
395 | acpi_status status = AE_OK; | |
20b93734 JW |
396 | acpi_handle handle = NULL; |
397 | ||
398 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n", | |
399 | level); | |
400 | ||
401 | if (level < 0 || level >= fujitsu->max_brightness) | |
402 | return -EINVAL; | |
403 | ||
20b93734 JW |
404 | status = acpi_get_handle(fujitsu->acpi_handle, "SBL2", &handle); |
405 | if (ACPI_FAILURE(status)) { | |
406 | vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n"); | |
d0482533 JW |
407 | return -ENODEV; |
408 | } | |
409 | ||
6c7fe47a | 410 | status = acpi_execute_simple_method(handle, NULL, level); |
d0482533 JW |
411 | if (ACPI_FAILURE(status)) |
412 | return -ENODEV; | |
413 | ||
414 | return 0; | |
415 | } | |
416 | ||
417 | static int get_lcd_level(void) | |
418 | { | |
27663c58 | 419 | unsigned long long state = 0; |
d0482533 JW |
420 | acpi_status status = AE_OK; |
421 | ||
20b93734 JW |
422 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n"); |
423 | ||
d0482533 JW |
424 | status = |
425 | acpi_evaluate_integer(fujitsu->acpi_handle, "GBLL", NULL, &state); | |
3b1c37ca JW |
426 | if (ACPI_FAILURE(status)) |
427 | return 0; | |
d0482533 | 428 | |
20b93734 JW |
429 | fujitsu->brightness_level = state & 0x0fffffff; |
430 | ||
431 | if (state & 0x80000000) | |
432 | fujitsu->brightness_changed = 1; | |
433 | else | |
434 | fujitsu->brightness_changed = 0; | |
435 | ||
436 | return fujitsu->brightness_level; | |
437 | } | |
438 | ||
439 | static int get_max_brightness(void) | |
440 | { | |
27663c58 | 441 | unsigned long long state = 0; |
20b93734 JW |
442 | acpi_status status = AE_OK; |
443 | ||
444 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n"); | |
445 | ||
446 | status = | |
447 | acpi_evaluate_integer(fujitsu->acpi_handle, "RBLL", NULL, &state); | |
3b1c37ca JW |
448 | if (ACPI_FAILURE(status)) |
449 | return -1; | |
20b93734 JW |
450 | |
451 | fujitsu->max_brightness = state; | |
452 | ||
453 | return fujitsu->max_brightness; | |
454 | } | |
455 | ||
d0482533 JW |
456 | /* Backlight device stuff */ |
457 | ||
458 | static int bl_get_brightness(struct backlight_device *b) | |
459 | { | |
f87a1a5f | 460 | return get_lcd_level(); |
d0482533 JW |
461 | } |
462 | ||
463 | static int bl_update_status(struct backlight_device *b) | |
464 | { | |
3a407086 | 465 | int ret; |
e8549e2c | 466 | if (b->props.power == FB_BLANK_POWERDOWN) |
3a407086 TV |
467 | ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x3); |
468 | else | |
469 | ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x0); | |
470 | if (ret != 0) | |
471 | vdbg_printk(FUJLAPTOP_DBG_ERROR, | |
472 | "Unable to adjust backlight power, error code %i\n", | |
473 | ret); | |
474 | ||
20b93734 | 475 | if (use_alt_lcd_levels) |
3a407086 | 476 | ret = set_lcd_level_alt(b->props.brightness); |
20b93734 | 477 | else |
3a407086 TV |
478 | ret = set_lcd_level(b->props.brightness); |
479 | if (ret != 0) | |
480 | vdbg_printk(FUJLAPTOP_DBG_ERROR, | |
481 | "Unable to adjust LCD brightness, error code %i\n", | |
482 | ret); | |
483 | return ret; | |
d0482533 JW |
484 | } |
485 | ||
acc2472e | 486 | static const struct backlight_ops fujitsubl_ops = { |
d0482533 JW |
487 | .get_brightness = bl_get_brightness, |
488 | .update_status = bl_update_status, | |
489 | }; | |
490 | ||
20b93734 JW |
491 | /* Platform LCD brightness device */ |
492 | ||
493 | static ssize_t | |
494 | show_max_brightness(struct device *dev, | |
495 | struct device_attribute *attr, char *buf) | |
496 | { | |
497 | ||
498 | int ret; | |
499 | ||
500 | ret = get_max_brightness(); | |
501 | if (ret < 0) | |
502 | return ret; | |
503 | ||
504 | return sprintf(buf, "%i\n", ret); | |
505 | } | |
506 | ||
507 | static ssize_t | |
508 | show_brightness_changed(struct device *dev, | |
509 | struct device_attribute *attr, char *buf) | |
510 | { | |
511 | ||
512 | int ret; | |
513 | ||
514 | ret = fujitsu->brightness_changed; | |
515 | if (ret < 0) | |
516 | return ret; | |
517 | ||
518 | return sprintf(buf, "%i\n", ret); | |
519 | } | |
d0482533 JW |
520 | |
521 | static ssize_t show_lcd_level(struct device *dev, | |
522 | struct device_attribute *attr, char *buf) | |
523 | { | |
524 | ||
525 | int ret; | |
526 | ||
f87a1a5f | 527 | ret = get_lcd_level(); |
d0482533 JW |
528 | if (ret < 0) |
529 | return ret; | |
530 | ||
531 | return sprintf(buf, "%i\n", ret); | |
532 | } | |
533 | ||
534 | static ssize_t store_lcd_level(struct device *dev, | |
535 | struct device_attribute *attr, const char *buf, | |
536 | size_t count) | |
537 | { | |
538 | ||
539 | int level, ret; | |
540 | ||
541 | if (sscanf(buf, "%i", &level) != 1 | |
20b93734 | 542 | || (level < 0 || level >= fujitsu->max_brightness)) |
d0482533 JW |
543 | return -EINVAL; |
544 | ||
20b93734 JW |
545 | if (use_alt_lcd_levels) |
546 | ret = set_lcd_level_alt(level); | |
547 | else | |
548 | ret = set_lcd_level(level); | |
549 | if (ret < 0) | |
550 | return ret; | |
551 | ||
f87a1a5f | 552 | ret = get_lcd_level(); |
d0482533 JW |
553 | if (ret < 0) |
554 | return ret; | |
555 | ||
556 | return count; | |
557 | } | |
558 | ||
3a407086 TV |
559 | static ssize_t |
560 | ignore_store(struct device *dev, | |
561 | struct device_attribute *attr, const char *buf, size_t count) | |
20b93734 | 562 | { |
3a407086 TV |
563 | return count; |
564 | } | |
20b93734 | 565 | |
3a407086 TV |
566 | static ssize_t |
567 | show_lid_state(struct device *dev, | |
568 | struct device_attribute *attr, char *buf) | |
569 | { | |
4898c2b2 | 570 | if (!(fujitsu_hotkey->rfkill_supported & 0x100)) |
3a407086 TV |
571 | return sprintf(buf, "unknown\n"); |
572 | if (fujitsu_hotkey->rfkill_state & 0x100) | |
573 | return sprintf(buf, "open\n"); | |
574 | else | |
575 | return sprintf(buf, "closed\n"); | |
576 | } | |
20b93734 | 577 | |
3a407086 TV |
578 | static ssize_t |
579 | show_dock_state(struct device *dev, | |
580 | struct device_attribute *attr, char *buf) | |
581 | { | |
4898c2b2 | 582 | if (!(fujitsu_hotkey->rfkill_supported & 0x200)) |
3a407086 TV |
583 | return sprintf(buf, "unknown\n"); |
584 | if (fujitsu_hotkey->rfkill_state & 0x200) | |
585 | return sprintf(buf, "docked\n"); | |
586 | else | |
587 | return sprintf(buf, "undocked\n"); | |
20b93734 JW |
588 | } |
589 | ||
590 | static ssize_t | |
3a407086 TV |
591 | show_radios_state(struct device *dev, |
592 | struct device_attribute *attr, char *buf) | |
20b93734 | 593 | { |
4898c2b2 | 594 | if (!(fujitsu_hotkey->rfkill_supported & 0x20)) |
3a407086 TV |
595 | return sprintf(buf, "unknown\n"); |
596 | if (fujitsu_hotkey->rfkill_state & 0x20) | |
597 | return sprintf(buf, "on\n"); | |
598 | else | |
599 | return sprintf(buf, "killed\n"); | |
20b93734 JW |
600 | } |
601 | ||
602 | static DEVICE_ATTR(max_brightness, 0444, show_max_brightness, ignore_store); | |
603 | static DEVICE_ATTR(brightness_changed, 0444, show_brightness_changed, | |
604 | ignore_store); | |
d0482533 | 605 | static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level); |
3a407086 TV |
606 | static DEVICE_ATTR(lid, 0444, show_lid_state, ignore_store); |
607 | static DEVICE_ATTR(dock, 0444, show_dock_state, ignore_store); | |
608 | static DEVICE_ATTR(radios, 0444, show_radios_state, ignore_store); | |
d0482533 JW |
609 | |
610 | static struct attribute *fujitsupf_attributes[] = { | |
20b93734 JW |
611 | &dev_attr_brightness_changed.attr, |
612 | &dev_attr_max_brightness.attr, | |
d0482533 | 613 | &dev_attr_lcd_level.attr, |
3a407086 TV |
614 | &dev_attr_lid.attr, |
615 | &dev_attr_dock.attr, | |
616 | &dev_attr_radios.attr, | |
d0482533 JW |
617 | NULL |
618 | }; | |
619 | ||
620 | static struct attribute_group fujitsupf_attribute_group = { | |
621 | .attrs = fujitsupf_attributes | |
622 | }; | |
623 | ||
624 | static struct platform_driver fujitsupf_driver = { | |
625 | .driver = { | |
626 | .name = "fujitsu-laptop", | |
d0482533 JW |
627 | } |
628 | }; | |
629 | ||
fbe9b79f | 630 | static void __init dmi_check_cb_common(const struct dmi_system_id *id) |
20b93734 | 631 | { |
77bad7c8 | 632 | pr_info("Identified laptop model '%s'\n", id->ident); |
20b93734 | 633 | if (use_alt_lcd_levels == -1) { |
dd13b9a6 ZR |
634 | if (acpi_has_method(NULL, |
635 | "\\_SB.PCI0.LPCB.FJEX.SBL2")) | |
f87a1a5f TV |
636 | use_alt_lcd_levels = 1; |
637 | else | |
638 | use_alt_lcd_levels = 0; | |
639 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detected usealt as " | |
640 | "%i\n", use_alt_lcd_levels); | |
20b93734 | 641 | } |
0e6a66e9 JW |
642 | } |
643 | ||
fbe9b79f | 644 | static int __init dmi_check_cb_s6410(const struct dmi_system_id *id) |
0e6a66e9 JW |
645 | { |
646 | dmi_check_cb_common(id); | |
647 | fujitsu->keycode1 = KEY_SCREENLOCK; /* "Lock" */ | |
648 | fujitsu->keycode2 = KEY_HELP; /* "Mobility Center" */ | |
80183a4b | 649 | return 1; |
0e6a66e9 JW |
650 | } |
651 | ||
fbe9b79f | 652 | static int __init dmi_check_cb_s6420(const struct dmi_system_id *id) |
56960b54 TV |
653 | { |
654 | dmi_check_cb_common(id); | |
655 | fujitsu->keycode1 = KEY_SCREENLOCK; /* "Lock" */ | |
656 | fujitsu->keycode2 = KEY_HELP; /* "Mobility Center" */ | |
80183a4b | 657 | return 1; |
56960b54 TV |
658 | } |
659 | ||
fbe9b79f | 660 | static int __init dmi_check_cb_p8010(const struct dmi_system_id *id) |
0e6a66e9 JW |
661 | { |
662 | dmi_check_cb_common(id); | |
663 | fujitsu->keycode1 = KEY_HELP; /* "Support" */ | |
664 | fujitsu->keycode3 = KEY_SWITCHVIDEOMODE; /* "Presentation" */ | |
665 | fujitsu->keycode4 = KEY_WWW; /* "Internet" */ | |
80183a4b | 666 | return 1; |
20b93734 JW |
667 | } |
668 | ||
fbe9b79f | 669 | static const struct dmi_system_id fujitsu_dmi_table[] __initconst = { |
20b93734 | 670 | { |
0e6a66e9 | 671 | .ident = "Fujitsu Siemens S6410", |
20b93734 JW |
672 | .matches = { |
673 | DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), | |
674 | DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"), | |
675 | }, | |
676 | .callback = dmi_check_cb_s6410}, | |
56960b54 TV |
677 | { |
678 | .ident = "Fujitsu Siemens S6420", | |
679 | .matches = { | |
680 | DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), | |
681 | DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"), | |
682 | }, | |
683 | .callback = dmi_check_cb_s6420}, | |
d8196a93 | 684 | { |
0e6a66e9 | 685 | .ident = "Fujitsu LifeBook P8010", |
d8196a93 JW |
686 | .matches = { |
687 | DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"), | |
688 | DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"), | |
0e6a66e9 JW |
689 | }, |
690 | .callback = dmi_check_cb_p8010}, | |
20b93734 JW |
691 | {} |
692 | }; | |
693 | ||
694 | /* ACPI device for LCD brightness control */ | |
d0482533 | 695 | |
b6f03ae6 | 696 | static int acpi_fujitsu_add(struct acpi_device *device) |
d0482533 | 697 | { |
d0482533 | 698 | int state = 0; |
20b93734 JW |
699 | struct input_dev *input; |
700 | int error; | |
d0482533 JW |
701 | |
702 | if (!device) | |
703 | return -EINVAL; | |
704 | ||
705 | fujitsu->acpi_handle = device->handle; | |
706 | sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_DEVICE_NAME); | |
707 | sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS); | |
db89b4f0 | 708 | device->driver_data = fujitsu; |
d0482533 | 709 | |
20b93734 JW |
710 | fujitsu->input = input = input_allocate_device(); |
711 | if (!input) { | |
712 | error = -ENOMEM; | |
700b6721 | 713 | goto err_stop; |
20b93734 JW |
714 | } |
715 | ||
716 | snprintf(fujitsu->phys, sizeof(fujitsu->phys), | |
717 | "%s/video/input0", acpi_device_hid(device)); | |
718 | ||
719 | input->name = acpi_device_name(device); | |
720 | input->phys = fujitsu->phys; | |
721 | input->id.bustype = BUS_HOST; | |
722 | input->id.product = 0x06; | |
723 | input->dev.parent = &device->dev; | |
724 | input->evbit[0] = BIT(EV_KEY); | |
725 | set_bit(KEY_BRIGHTNESSUP, input->keybit); | |
726 | set_bit(KEY_BRIGHTNESSDOWN, input->keybit); | |
727 | set_bit(KEY_UNKNOWN, input->keybit); | |
728 | ||
729 | error = input_register_device(input); | |
730 | if (error) | |
731 | goto err_free_input_dev; | |
732 | ||
b30bb89f JL |
733 | error = acpi_bus_update_power(fujitsu->acpi_handle, &state); |
734 | if (error) { | |
77bad7c8 | 735 | pr_err("Error reading power state\n"); |
72afeeaf | 736 | goto err_unregister_input_dev; |
d0482533 JW |
737 | } |
738 | ||
77bad7c8 | 739 | pr_info("ACPI: %s [%s] (%s)\n", |
d0482533 JW |
740 | acpi_device_name(device), acpi_device_bid(device), |
741 | !device->power.state ? "on" : "off"); | |
742 | ||
20b93734 JW |
743 | fujitsu->dev = device; |
744 | ||
dd13b9a6 | 745 | if (acpi_has_method(device->handle, METHOD_NAME__INI)) { |
20b93734 JW |
746 | vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n"); |
747 | if (ACPI_FAILURE | |
748 | (acpi_evaluate_object | |
749 | (device->handle, METHOD_NAME__INI, NULL, NULL))) | |
77bad7c8 | 750 | pr_err("_INI Method failed\n"); |
20b93734 JW |
751 | } |
752 | ||
753 | /* do config (detect defaults) */ | |
20b93734 | 754 | use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0; |
20b93734 JW |
755 | disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0; |
756 | vdbg_printk(FUJLAPTOP_DBG_INFO, | |
f87a1a5f TV |
757 | "config: [alt interface: %d], [adjust disable: %d]\n", |
758 | use_alt_lcd_levels, disable_brightness_adjust); | |
20b93734 JW |
759 | |
760 | if (get_max_brightness() <= 0) | |
761 | fujitsu->max_brightness = FUJITSU_LCD_N_LEVELS; | |
f87a1a5f | 762 | get_lcd_level(); |
20b93734 | 763 | |
b30bb89f | 764 | return 0; |
20b93734 | 765 | |
72afeeaf BZ |
766 | err_unregister_input_dev: |
767 | input_unregister_device(input); | |
8e4e2efd | 768 | input = NULL; |
20b93734 JW |
769 | err_free_input_dev: |
770 | input_free_device(input); | |
20b93734 | 771 | err_stop: |
b30bb89f | 772 | return error; |
d0482533 JW |
773 | } |
774 | ||
51fac838 | 775 | static int acpi_fujitsu_remove(struct acpi_device *device) |
d0482533 | 776 | { |
72afeeaf BZ |
777 | struct fujitsu_t *fujitsu = acpi_driver_data(device); |
778 | struct input_dev *input = fujitsu->input; | |
d0482533 | 779 | |
72afeeaf | 780 | input_unregister_device(input); |
20b93734 | 781 | |
5cf83b9b | 782 | fujitsu->acpi_handle = NULL; |
d0482533 JW |
783 | |
784 | return 0; | |
785 | } | |
786 | ||
20b93734 JW |
787 | /* Brightness notify */ |
788 | ||
700b6721 | 789 | static void acpi_fujitsu_notify(struct acpi_device *device, u32 event) |
20b93734 JW |
790 | { |
791 | struct input_dev *input; | |
792 | int keycode; | |
793 | int oldb, newb; | |
794 | ||
795 | input = fujitsu->input; | |
796 | ||
797 | switch (event) { | |
798 | case ACPI_FUJITSU_NOTIFY_CODE1: | |
799 | keycode = 0; | |
800 | oldb = fujitsu->brightness_level; | |
f87a1a5f | 801 | get_lcd_level(); |
20b93734 JW |
802 | newb = fujitsu->brightness_level; |
803 | ||
804 | vdbg_printk(FUJLAPTOP_DBG_TRACE, | |
805 | "brightness button event [%i -> %i (%i)]\n", | |
806 | oldb, newb, fujitsu->brightness_changed); | |
807 | ||
f87a1a5f | 808 | if (oldb < newb) { |
20b93734 JW |
809 | if (disable_brightness_adjust != 1) { |
810 | if (use_alt_lcd_levels) | |
811 | set_lcd_level_alt(newb); | |
812 | else | |
813 | set_lcd_level(newb); | |
814 | } | |
f87a1a5f | 815 | keycode = KEY_BRIGHTNESSUP; |
20b93734 JW |
816 | } else if (oldb > newb) { |
817 | if (disable_brightness_adjust != 1) { | |
818 | if (use_alt_lcd_levels) | |
819 | set_lcd_level_alt(newb); | |
820 | else | |
821 | set_lcd_level(newb); | |
822 | } | |
f87a1a5f | 823 | keycode = KEY_BRIGHTNESSDOWN; |
20b93734 JW |
824 | } |
825 | break; | |
826 | default: | |
827 | keycode = KEY_UNKNOWN; | |
828 | vdbg_printk(FUJLAPTOP_DBG_WARN, | |
829 | "unsupported event [0x%x]\n", event); | |
830 | break; | |
831 | } | |
832 | ||
833 | if (keycode != 0) { | |
834 | input_report_key(input, keycode, 1); | |
835 | input_sync(input); | |
836 | input_report_key(input, keycode, 0); | |
837 | input_sync(input); | |
838 | } | |
20b93734 JW |
839 | } |
840 | ||
841 | /* ACPI device for hotkey handling */ | |
842 | ||
843 | static int acpi_fujitsu_hotkey_add(struct acpi_device *device) | |
844 | { | |
20b93734 JW |
845 | int result = 0; |
846 | int state = 0; | |
847 | struct input_dev *input; | |
848 | int error; | |
849 | int i; | |
850 | ||
851 | if (!device) | |
852 | return -EINVAL; | |
853 | ||
854 | fujitsu_hotkey->acpi_handle = device->handle; | |
855 | sprintf(acpi_device_name(device), "%s", | |
856 | ACPI_FUJITSU_HOTKEY_DEVICE_NAME); | |
857 | sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS); | |
db89b4f0 | 858 | device->driver_data = fujitsu_hotkey; |
20b93734 | 859 | |
20b93734 JW |
860 | /* kfifo */ |
861 | spin_lock_init(&fujitsu_hotkey->fifo_lock); | |
45465487 | 862 | error = kfifo_alloc(&fujitsu_hotkey->fifo, RINGBUFFERSIZE * sizeof(int), |
c1e13f25 | 863 | GFP_KERNEL); |
45465487 | 864 | if (error) { |
77bad7c8 | 865 | pr_err("kfifo_alloc failed\n"); |
20b93734 JW |
866 | goto err_stop; |
867 | } | |
868 | ||
869 | fujitsu_hotkey->input = input = input_allocate_device(); | |
870 | if (!input) { | |
871 | error = -ENOMEM; | |
b4ec0275 | 872 | goto err_free_fifo; |
20b93734 JW |
873 | } |
874 | ||
875 | snprintf(fujitsu_hotkey->phys, sizeof(fujitsu_hotkey->phys), | |
876 | "%s/video/input0", acpi_device_hid(device)); | |
877 | ||
878 | input->name = acpi_device_name(device); | |
879 | input->phys = fujitsu_hotkey->phys; | |
880 | input->id.bustype = BUS_HOST; | |
881 | input->id.product = 0x06; | |
882 | input->dev.parent = &device->dev; | |
3a407086 TV |
883 | |
884 | set_bit(EV_KEY, input->evbit); | |
0e6a66e9 JW |
885 | set_bit(fujitsu->keycode1, input->keybit); |
886 | set_bit(fujitsu->keycode2, input->keybit); | |
887 | set_bit(fujitsu->keycode3, input->keybit); | |
888 | set_bit(fujitsu->keycode4, input->keybit); | |
b5df36cf | 889 | set_bit(fujitsu->keycode5, input->keybit); |
1879e69f | 890 | set_bit(KEY_TOUCHPAD_TOGGLE, input->keybit); |
20b93734 JW |
891 | set_bit(KEY_UNKNOWN, input->keybit); |
892 | ||
893 | error = input_register_device(input); | |
894 | if (error) | |
895 | goto err_free_input_dev; | |
896 | ||
b30bb89f JL |
897 | error = acpi_bus_update_power(fujitsu_hotkey->acpi_handle, &state); |
898 | if (error) { | |
77bad7c8 | 899 | pr_err("Error reading power state\n"); |
72afeeaf | 900 | goto err_unregister_input_dev; |
20b93734 JW |
901 | } |
902 | ||
77bad7c8 JP |
903 | pr_info("ACPI: %s [%s] (%s)\n", |
904 | acpi_device_name(device), acpi_device_bid(device), | |
905 | !device->power.state ? "on" : "off"); | |
20b93734 JW |
906 | |
907 | fujitsu_hotkey->dev = device; | |
908 | ||
dd13b9a6 | 909 | if (acpi_has_method(device->handle, METHOD_NAME__INI)) { |
20b93734 JW |
910 | vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n"); |
911 | if (ACPI_FAILURE | |
912 | (acpi_evaluate_object | |
913 | (device->handle, METHOD_NAME__INI, NULL, NULL))) | |
77bad7c8 | 914 | pr_err("_INI Method failed\n"); |
20b93734 JW |
915 | } |
916 | ||
3a407086 TV |
917 | i = 0; |
918 | while (call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0 | |
919 | && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) | |
920 | ; /* No action, result is discarded */ | |
20b93734 JW |
921 | vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i); |
922 | ||
4898c2b2 TV |
923 | fujitsu_hotkey->rfkill_supported = |
924 | call_fext_func(FUNC_RFKILL, 0x0, 0x0, 0x0); | |
925 | ||
926 | /* Make sure our bitmask of supported functions is cleared if the | |
927 | RFKILL function block is not implemented, like on the S7020. */ | |
928 | if (fujitsu_hotkey->rfkill_supported == UNSUPPORTED_CMD) | |
929 | fujitsu_hotkey->rfkill_supported = 0; | |
930 | ||
931 | if (fujitsu_hotkey->rfkill_supported) | |
932 | fujitsu_hotkey->rfkill_state = | |
933 | call_fext_func(FUNC_RFKILL, 0x4, 0x0, 0x0); | |
3a407086 TV |
934 | |
935 | /* Suspect this is a keymap of the application panel, print it */ | |
77bad7c8 | 936 | pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0)); |
3a407086 | 937 | |
575b245d | 938 | #if IS_ENABLED(CONFIG_LEDS_CLASS) |
3a407086 TV |
939 | if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) { |
940 | result = led_classdev_register(&fujitsu->pf_device->dev, | |
941 | &logolamp_led); | |
942 | if (result == 0) { | |
943 | fujitsu_hotkey->logolamp_registered = 1; | |
944 | } else { | |
77bad7c8 JP |
945 | pr_err("Could not register LED handler for logo lamp, error %i\n", |
946 | result); | |
3a407086 TV |
947 | } |
948 | } | |
949 | ||
950 | if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) && | |
951 | (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) { | |
952 | result = led_classdev_register(&fujitsu->pf_device->dev, | |
953 | &kblamps_led); | |
954 | if (result == 0) { | |
955 | fujitsu_hotkey->kblamps_registered = 1; | |
956 | } else { | |
77bad7c8 JP |
957 | pr_err("Could not register LED handler for keyboard lamps, error %i\n", |
958 | result); | |
3a407086 TV |
959 | } |
960 | } | |
4f62568c MK |
961 | |
962 | /* | |
963 | * BTNI bit 24 seems to indicate the presence of a radio toggle | |
964 | * button in place of a slide switch, and all such machines appear | |
965 | * to also have an RF LED. Therefore use bit 24 as an indicator | |
966 | * that an RF LED is present. | |
967 | */ | |
968 | if (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) { | |
969 | result = led_classdev_register(&fujitsu->pf_device->dev, | |
970 | &radio_led); | |
971 | if (result == 0) { | |
972 | fujitsu_hotkey->radio_led_registered = 1; | |
973 | } else { | |
974 | pr_err("Could not register LED handler for radio LED, error %i\n", | |
975 | result); | |
976 | } | |
977 | } | |
d6b88f64 MG |
978 | |
979 | /* Support for eco led is not always signaled in bit corresponding | |
980 | * to the bit used to control the led. According to the DSDT table, | |
981 | * bit 14 seems to indicate presence of said led as well. | |
982 | * Confirm by testing the status. | |
983 | */ | |
984 | if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) && | |
985 | (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) { | |
986 | result = led_classdev_register(&fujitsu->pf_device->dev, | |
987 | &eco_led); | |
988 | if (result == 0) { | |
989 | fujitsu_hotkey->eco_led_registered = 1; | |
990 | } else { | |
991 | pr_err("Could not register LED handler for eco LED, error %i\n", | |
992 | result); | |
993 | } | |
994 | } | |
72afeeaf | 995 | #endif |
3a407086 | 996 | |
20b93734 JW |
997 | return result; |
998 | ||
72afeeaf BZ |
999 | err_unregister_input_dev: |
1000 | input_unregister_device(input); | |
8e4e2efd | 1001 | input = NULL; |
20b93734 JW |
1002 | err_free_input_dev: |
1003 | input_free_device(input); | |
b4ec0275 | 1004 | err_free_fifo: |
45465487 | 1005 | kfifo_free(&fujitsu_hotkey->fifo); |
20b93734 | 1006 | err_stop: |
b30bb89f | 1007 | return error; |
20b93734 JW |
1008 | } |
1009 | ||
51fac838 | 1010 | static int acpi_fujitsu_hotkey_remove(struct acpi_device *device) |
20b93734 | 1011 | { |
72afeeaf BZ |
1012 | struct fujitsu_hotkey_t *fujitsu_hotkey = acpi_driver_data(device); |
1013 | struct input_dev *input = fujitsu_hotkey->input; | |
20b93734 | 1014 | |
575b245d | 1015 | #if IS_ENABLED(CONFIG_LEDS_CLASS) |
72afeeaf BZ |
1016 | if (fujitsu_hotkey->logolamp_registered) |
1017 | led_classdev_unregister(&logolamp_led); | |
20b93734 | 1018 | |
72afeeaf BZ |
1019 | if (fujitsu_hotkey->kblamps_registered) |
1020 | led_classdev_unregister(&kblamps_led); | |
4f62568c MK |
1021 | |
1022 | if (fujitsu_hotkey->radio_led_registered) | |
1023 | led_classdev_unregister(&radio_led); | |
d6b88f64 MG |
1024 | |
1025 | if (fujitsu_hotkey->eco_led_registered) | |
1026 | led_classdev_unregister(&eco_led); | |
72afeeaf | 1027 | #endif |
20b93734 | 1028 | |
72afeeaf | 1029 | input_unregister_device(input); |
20b93734 | 1030 | |
45465487 | 1031 | kfifo_free(&fujitsu_hotkey->fifo); |
20b93734 | 1032 | |
72afeeaf BZ |
1033 | fujitsu_hotkey->acpi_handle = NULL; |
1034 | ||
20b93734 JW |
1035 | return 0; |
1036 | } | |
1037 | ||
b4ec0275 | 1038 | static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event) |
20b93734 JW |
1039 | { |
1040 | struct input_dev *input; | |
1041 | int keycode, keycode_r; | |
1042 | unsigned int irb = 1; | |
1043 | int i, status; | |
1044 | ||
1045 | input = fujitsu_hotkey->input; | |
1046 | ||
4898c2b2 TV |
1047 | if (fujitsu_hotkey->rfkill_supported) |
1048 | fujitsu_hotkey->rfkill_state = | |
1049 | call_fext_func(FUNC_RFKILL, 0x4, 0x0, 0x0); | |
20b93734 JW |
1050 | |
1051 | switch (event) { | |
1052 | case ACPI_FUJITSU_NOTIFY_CODE1: | |
1053 | i = 0; | |
3a407086 TV |
1054 | while ((irb = |
1055 | call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0 | |
1056 | && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) { | |
20b93734 | 1057 | switch (irb & 0x4ff) { |
0e6a66e9 JW |
1058 | case KEY1_CODE: |
1059 | keycode = fujitsu->keycode1; | |
20b93734 | 1060 | break; |
0e6a66e9 JW |
1061 | case KEY2_CODE: |
1062 | keycode = fujitsu->keycode2; | |
20b93734 | 1063 | break; |
0e6a66e9 JW |
1064 | case KEY3_CODE: |
1065 | keycode = fujitsu->keycode3; | |
20b93734 | 1066 | break; |
0e6a66e9 JW |
1067 | case KEY4_CODE: |
1068 | keycode = fujitsu->keycode4; | |
20b93734 | 1069 | break; |
b5df36cf MK |
1070 | case KEY5_CODE: |
1071 | keycode = fujitsu->keycode5; | |
1072 | break; | |
20b93734 JW |
1073 | case 0: |
1074 | keycode = 0; | |
1075 | break; | |
1076 | default: | |
1077 | vdbg_printk(FUJLAPTOP_DBG_WARN, | |
0e6a66e9 | 1078 | "Unknown GIRB result [%x]\n", irb); |
20b93734 JW |
1079 | keycode = -1; |
1080 | break; | |
1081 | } | |
1082 | if (keycode > 0) { | |
1083 | vdbg_printk(FUJLAPTOP_DBG_TRACE, | |
1084 | "Push keycode into ringbuffer [%d]\n", | |
1085 | keycode); | |
7acd72eb | 1086 | status = kfifo_in_locked(&fujitsu_hotkey->fifo, |
0e6a66e9 | 1087 | (unsigned char *)&keycode, |
c1e13f25 SS |
1088 | sizeof(keycode), |
1089 | &fujitsu_hotkey->fifo_lock); | |
20b93734 JW |
1090 | if (status != sizeof(keycode)) { |
1091 | vdbg_printk(FUJLAPTOP_DBG_WARN, | |
0e6a66e9 JW |
1092 | "Could not push keycode [0x%x]\n", |
1093 | keycode); | |
20b93734 JW |
1094 | } else { |
1095 | input_report_key(input, keycode, 1); | |
1096 | input_sync(input); | |
1097 | } | |
1098 | } else if (keycode == 0) { | |
1099 | while ((status = | |
7acd72eb | 1100 | kfifo_out_locked( |
c1e13f25 SS |
1101 | &fujitsu_hotkey->fifo, |
1102 | (unsigned char *) &keycode_r, | |
1103 | sizeof(keycode_r), | |
1104 | &fujitsu_hotkey->fifo_lock)) | |
1105 | == sizeof(keycode_r)) { | |
20b93734 JW |
1106 | input_report_key(input, keycode_r, 0); |
1107 | input_sync(input); | |
1108 | vdbg_printk(FUJLAPTOP_DBG_TRACE, | |
0e6a66e9 JW |
1109 | "Pop keycode from ringbuffer [%d]\n", |
1110 | keycode_r); | |
20b93734 JW |
1111 | } |
1112 | } | |
1113 | } | |
1114 | ||
1879e69f MK |
1115 | /* On some models (first seen on the Skylake-based Lifebook |
1116 | * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is | |
1117 | * handled in software; its state is queried using FUNC_RFKILL | |
1118 | */ | |
1119 | if ((fujitsu_hotkey->rfkill_supported & BIT(26)) && | |
1120 | (call_fext_func(FUNC_RFKILL, 0x1, 0x0, 0x0) & BIT(26))) { | |
1121 | keycode = KEY_TOUCHPAD_TOGGLE; | |
1122 | input_report_key(input, keycode, 1); | |
1123 | input_sync(input); | |
1124 | input_report_key(input, keycode, 0); | |
1125 | input_sync(input); | |
1126 | } | |
1127 | ||
20b93734 JW |
1128 | break; |
1129 | default: | |
1130 | keycode = KEY_UNKNOWN; | |
1131 | vdbg_printk(FUJLAPTOP_DBG_WARN, | |
1132 | "Unsupported event [0x%x]\n", event); | |
1133 | input_report_key(input, keycode, 1); | |
1134 | input_sync(input); | |
1135 | input_report_key(input, keycode, 0); | |
1136 | input_sync(input); | |
1137 | break; | |
1138 | } | |
20b93734 JW |
1139 | } |
1140 | ||
1141 | /* Initialization */ | |
1142 | ||
d0482533 JW |
1143 | static const struct acpi_device_id fujitsu_device_ids[] = { |
1144 | {ACPI_FUJITSU_HID, 0}, | |
1145 | {"", 0}, | |
1146 | }; | |
1147 | ||
1148 | static struct acpi_driver acpi_fujitsu_driver = { | |
1149 | .name = ACPI_FUJITSU_DRIVER_NAME, | |
1150 | .class = ACPI_FUJITSU_CLASS, | |
1151 | .ids = fujitsu_device_ids, | |
1152 | .ops = { | |
1153 | .add = acpi_fujitsu_add, | |
1154 | .remove = acpi_fujitsu_remove, | |
700b6721 | 1155 | .notify = acpi_fujitsu_notify, |
d0482533 JW |
1156 | }, |
1157 | }; | |
1158 | ||
20b93734 JW |
1159 | static const struct acpi_device_id fujitsu_hotkey_device_ids[] = { |
1160 | {ACPI_FUJITSU_HOTKEY_HID, 0}, | |
1161 | {"", 0}, | |
1162 | }; | |
1163 | ||
1164 | static struct acpi_driver acpi_fujitsu_hotkey_driver = { | |
1165 | .name = ACPI_FUJITSU_HOTKEY_DRIVER_NAME, | |
1166 | .class = ACPI_FUJITSU_CLASS, | |
1167 | .ids = fujitsu_hotkey_device_ids, | |
1168 | .ops = { | |
1169 | .add = acpi_fujitsu_hotkey_add, | |
1170 | .remove = acpi_fujitsu_hotkey_remove, | |
b4ec0275 | 1171 | .notify = acpi_fujitsu_hotkey_notify, |
20b93734 JW |
1172 | }, |
1173 | }; | |
d0482533 | 1174 | |
49901414 ZR |
1175 | static const struct acpi_device_id fujitsu_ids[] __used = { |
1176 | {ACPI_FUJITSU_HID, 0}, | |
1177 | {ACPI_FUJITSU_HOTKEY_HID, 0}, | |
1178 | {"", 0} | |
1179 | }; | |
1180 | MODULE_DEVICE_TABLE(acpi, fujitsu_ids); | |
1181 | ||
d0482533 JW |
1182 | static int __init fujitsu_init(void) |
1183 | { | |
20b93734 | 1184 | int ret, result, max_brightness; |
d0482533 JW |
1185 | |
1186 | if (acpi_disabled) | |
1187 | return -ENODEV; | |
1188 | ||
6c75dd0f | 1189 | fujitsu = kzalloc(sizeof(struct fujitsu_t), GFP_KERNEL); |
d0482533 JW |
1190 | if (!fujitsu) |
1191 | return -ENOMEM; | |
0e6a66e9 JW |
1192 | fujitsu->keycode1 = KEY_PROG1; |
1193 | fujitsu->keycode2 = KEY_PROG2; | |
1194 | fujitsu->keycode3 = KEY_PROG3; | |
1195 | fujitsu->keycode4 = KEY_PROG4; | |
b5df36cf | 1196 | fujitsu->keycode5 = KEY_RFKILL; |
0e6a66e9 | 1197 | dmi_check_system(fujitsu_dmi_table); |
d0482533 JW |
1198 | |
1199 | result = acpi_bus_register_driver(&acpi_fujitsu_driver); | |
1200 | if (result < 0) { | |
1201 | ret = -ENODEV; | |
1202 | goto fail_acpi; | |
1203 | } | |
1204 | ||
d0482533 JW |
1205 | /* Register platform stuff */ |
1206 | ||
1207 | fujitsu->pf_device = platform_device_alloc("fujitsu-laptop", -1); | |
1208 | if (!fujitsu->pf_device) { | |
1209 | ret = -ENOMEM; | |
1210 | goto fail_platform_driver; | |
1211 | } | |
1212 | ||
1213 | ret = platform_device_add(fujitsu->pf_device); | |
1214 | if (ret) | |
1215 | goto fail_platform_device1; | |
1216 | ||
1217 | ret = | |
1218 | sysfs_create_group(&fujitsu->pf_device->dev.kobj, | |
1219 | &fujitsupf_attribute_group); | |
1220 | if (ret) | |
1221 | goto fail_platform_device2; | |
1222 | ||
20b93734 JW |
1223 | /* Register backlight stuff */ |
1224 | ||
413226f7 | 1225 | if (acpi_video_get_backlight_type() == acpi_backlight_vendor) { |
a19a6ee6 MG |
1226 | struct backlight_properties props; |
1227 | ||
1228 | memset(&props, 0, sizeof(struct backlight_properties)); | |
1229 | max_brightness = fujitsu->max_brightness; | |
bb7ca747 | 1230 | props.type = BACKLIGHT_PLATFORM; |
a19a6ee6 MG |
1231 | props.max_brightness = max_brightness - 1; |
1232 | fujitsu->bl_device = backlight_device_register("fujitsu-laptop", | |
1233 | NULL, NULL, | |
1234 | &fujitsubl_ops, | |
1235 | &props); | |
72afeeaf BZ |
1236 | if (IS_ERR(fujitsu->bl_device)) { |
1237 | ret = PTR_ERR(fujitsu->bl_device); | |
1238 | fujitsu->bl_device = NULL; | |
1239 | goto fail_sysfs_group; | |
1240 | } | |
7d5c89a6 TR |
1241 | fujitsu->bl_device->props.brightness = fujitsu->brightness_level; |
1242 | } | |
20b93734 JW |
1243 | |
1244 | ret = platform_driver_register(&fujitsupf_driver); | |
1245 | if (ret) | |
1246 | goto fail_backlight; | |
1247 | ||
1248 | /* Register hotkey driver */ | |
1249 | ||
6c75dd0f | 1250 | fujitsu_hotkey = kzalloc(sizeof(struct fujitsu_hotkey_t), GFP_KERNEL); |
20b93734 JW |
1251 | if (!fujitsu_hotkey) { |
1252 | ret = -ENOMEM; | |
1253 | goto fail_hotkey; | |
1254 | } | |
20b93734 JW |
1255 | |
1256 | result = acpi_bus_register_driver(&acpi_fujitsu_hotkey_driver); | |
1257 | if (result < 0) { | |
1258 | ret = -ENODEV; | |
1259 | goto fail_hotkey1; | |
1260 | } | |
1261 | ||
3a407086 | 1262 | /* Sync backlight power status (needs FUJ02E3 device, hence deferred) */ |
413226f7 | 1263 | if (acpi_video_get_backlight_type() == acpi_backlight_vendor) { |
3a407086 | 1264 | if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3) |
e8549e2c | 1265 | fujitsu->bl_device->props.power = FB_BLANK_POWERDOWN; |
3a407086 | 1266 | else |
e8549e2c | 1267 | fujitsu->bl_device->props.power = FB_BLANK_UNBLANK; |
3a407086 TV |
1268 | } |
1269 | ||
77bad7c8 | 1270 | pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n"); |
d0482533 JW |
1271 | |
1272 | return 0; | |
1273 | ||
20b93734 | 1274 | fail_hotkey1: |
20b93734 | 1275 | kfree(fujitsu_hotkey); |
20b93734 | 1276 | fail_hotkey: |
d0482533 | 1277 | platform_driver_unregister(&fujitsupf_driver); |
20b93734 | 1278 | fail_backlight: |
00981810 | 1279 | backlight_device_unregister(fujitsu->bl_device); |
72afeeaf BZ |
1280 | fail_sysfs_group: |
1281 | sysfs_remove_group(&fujitsu->pf_device->dev.kobj, | |
1282 | &fujitsupf_attribute_group); | |
20b93734 | 1283 | fail_platform_device2: |
20b93734 | 1284 | platform_device_del(fujitsu->pf_device); |
20b93734 | 1285 | fail_platform_device1: |
20b93734 | 1286 | platform_device_put(fujitsu->pf_device); |
20b93734 | 1287 | fail_platform_driver: |
20b93734 | 1288 | acpi_bus_unregister_driver(&acpi_fujitsu_driver); |
20b93734 | 1289 | fail_acpi: |
d0482533 JW |
1290 | kfree(fujitsu); |
1291 | ||
1292 | return ret; | |
1293 | } | |
1294 | ||
1295 | static void __exit fujitsu_cleanup(void) | |
1296 | { | |
72afeeaf | 1297 | acpi_bus_unregister_driver(&acpi_fujitsu_hotkey_driver); |
3a407086 | 1298 | |
72afeeaf | 1299 | kfree(fujitsu_hotkey); |
3a407086 | 1300 | |
d0482533 | 1301 | platform_driver_unregister(&fujitsupf_driver); |
72afeeaf | 1302 | |
00981810 | 1303 | backlight_device_unregister(fujitsu->bl_device); |
d0482533 | 1304 | |
72afeeaf BZ |
1305 | sysfs_remove_group(&fujitsu->pf_device->dev.kobj, |
1306 | &fujitsupf_attribute_group); | |
d0482533 | 1307 | |
72afeeaf | 1308 | platform_device_unregister(fujitsu->pf_device); |
d0482533 | 1309 | |
72afeeaf | 1310 | acpi_bus_unregister_driver(&acpi_fujitsu_driver); |
20b93734 | 1311 | |
72afeeaf | 1312 | kfree(fujitsu); |
20b93734 | 1313 | |
77bad7c8 | 1314 | pr_info("driver unloaded\n"); |
d0482533 JW |
1315 | } |
1316 | ||
1317 | module_init(fujitsu_init); | |
1318 | module_exit(fujitsu_cleanup); | |
1319 | ||
20b93734 JW |
1320 | module_param(use_alt_lcd_levels, uint, 0644); |
1321 | MODULE_PARM_DESC(use_alt_lcd_levels, | |
1322 | "Use alternative interface for lcd_levels (needed for Lifebook s6410)."); | |
20b93734 JW |
1323 | module_param(disable_brightness_adjust, uint, 0644); |
1324 | MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment ."); | |
1325 | #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG | |
1326 | module_param_named(debug, dbg_level, uint, 0644); | |
1327 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); | |
1328 | #endif | |
1329 | ||
3a407086 | 1330 | MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon"); |
d0482533 JW |
1331 | MODULE_DESCRIPTION("Fujitsu laptop extras support"); |
1332 | MODULE_VERSION(FUJITSU_DRIVER_VERSION); | |
1333 | MODULE_LICENSE("GPL"); | |
a361a82c | 1334 | |
0e6a66e9 | 1335 | MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*"); |
3a407086 | 1336 | MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1E6:*:cvrS6420:*"); |
0e6a66e9 | 1337 | MODULE_ALIAS("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*"); |