Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1 | /*-*-linux-c-*-*/ |
| 2 | |
| 3 | /* |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 4 | Copyright (C) 2007,2008 Jonathan Woithe <jwoithe@physics.adelaide.edu.au> |
| 5 | Copyright (C) 2008 Peter Gruber <nokos@gmx.net> |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 6 | Copyright (C) 2008 Tony Vroon <tony@linx.net> |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 7 | Based on earlier work: |
| 8 | Copyright (C) 2003 Shane Spencer <shane@bogomip.com> |
| 9 | Adrian Yee <brewt-fujitsu@brewt.org> |
| 10 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 11 | Templated from msi-laptop.c and thinkpad_acpi.c which is copyright |
| 12 | by its respective authors. |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 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 | * |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 45 | * Hotkeys present on certain Fujitsu laptops (eg: the S6xxx series) are |
| 46 | * also supported by this driver. |
| 47 | * |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 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. |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 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 | * |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 57 | */ |
| 58 | |
| 59 | #include <linux/module.h> |
| 60 | #include <linux/kernel.h> |
| 61 | #include <linux/init.h> |
| 62 | #include <linux/acpi.h> |
| 63 | #include <linux/dmi.h> |
| 64 | #include <linux/backlight.h> |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 65 | #include <linux/input.h> |
| 66 | #include <linux/kfifo.h> |
| 67 | #include <linux/video_output.h> |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 68 | #include <linux/platform_device.h> |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 69 | #ifdef CONFIG_LEDS_CLASS |
| 70 | #include <linux/leds.h> |
| 71 | #endif |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 72 | |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 73 | #define FUJITSU_DRIVER_VERSION "0.5.0" |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 74 | |
| 75 | #define FUJITSU_LCD_N_LEVELS 8 |
| 76 | |
| 77 | #define ACPI_FUJITSU_CLASS "fujitsu" |
| 78 | #define ACPI_FUJITSU_HID "FUJ02B1" |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 79 | #define ACPI_FUJITSU_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver" |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 80 | #define ACPI_FUJITSU_DEVICE_NAME "Fujitsu FUJ02B1" |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 81 | #define ACPI_FUJITSU_HOTKEY_HID "FUJ02E3" |
| 82 | #define ACPI_FUJITSU_HOTKEY_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver" |
| 83 | #define ACPI_FUJITSU_HOTKEY_DEVICE_NAME "Fujitsu FUJ02E3" |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 84 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 85 | #define ACPI_FUJITSU_NOTIFY_CODE1 0x80 |
| 86 | |
| 87 | #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86 |
| 88 | #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87 |
| 89 | |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 90 | /* FUNC interface - command values */ |
| 91 | #define FUNC_RFKILL 0x1000 |
| 92 | #define FUNC_LEDS 0x1001 |
| 93 | #define FUNC_BUTTONS 0x1002 |
| 94 | #define FUNC_BACKLIGHT 0x1004 |
| 95 | |
| 96 | /* FUNC interface - responses */ |
| 97 | #define UNSUPPORTED_CMD 0x80000000 |
| 98 | |
| 99 | #ifdef CONFIG_LEDS_CLASS |
| 100 | /* FUNC interface - LED control */ |
| 101 | #define FUNC_LED_OFF 0x1 |
| 102 | #define FUNC_LED_ON 0x30001 |
| 103 | #define KEYBOARD_LAMPS 0x100 |
| 104 | #define LOGOLAMP_POWERON 0x2000 |
| 105 | #define LOGOLAMP_ALWAYS 0x4000 |
| 106 | #endif |
| 107 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 108 | /* Hotkey details */ |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 109 | #define KEY1_CODE 0x410 /* codes for the keys in the GIRB register */ |
| 110 | #define KEY2_CODE 0x411 |
| 111 | #define KEY3_CODE 0x412 |
| 112 | #define KEY4_CODE 0x413 |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 113 | |
| 114 | #define MAX_HOTKEY_RINGBUFFER_SIZE 100 |
| 115 | #define RINGBUFFERSIZE 40 |
| 116 | |
| 117 | /* Debugging */ |
| 118 | #define FUJLAPTOP_LOG ACPI_FUJITSU_HID ": " |
| 119 | #define FUJLAPTOP_ERR KERN_ERR FUJLAPTOP_LOG |
| 120 | #define FUJLAPTOP_NOTICE KERN_NOTICE FUJLAPTOP_LOG |
| 121 | #define FUJLAPTOP_INFO KERN_INFO FUJLAPTOP_LOG |
| 122 | #define FUJLAPTOP_DEBUG KERN_DEBUG FUJLAPTOP_LOG |
| 123 | |
| 124 | #define FUJLAPTOP_DBG_ALL 0xffff |
| 125 | #define FUJLAPTOP_DBG_ERROR 0x0001 |
| 126 | #define FUJLAPTOP_DBG_WARN 0x0002 |
| 127 | #define FUJLAPTOP_DBG_INFO 0x0004 |
| 128 | #define FUJLAPTOP_DBG_TRACE 0x0008 |
| 129 | |
| 130 | #define dbg_printk(a_dbg_level, format, arg...) \ |
| 131 | do { if (dbg_level & a_dbg_level) \ |
| 132 | printk(FUJLAPTOP_DEBUG "%s: " format, __func__ , ## arg); \ |
| 133 | } while (0) |
| 134 | #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG |
| 135 | #define vdbg_printk(a_dbg_level, format, arg...) \ |
| 136 | dbg_printk(a_dbg_level, format, ## arg) |
| 137 | #else |
| 138 | #define vdbg_printk(a_dbg_level, format, arg...) |
| 139 | #endif |
| 140 | |
| 141 | /* Device controlling the backlight and associated keys */ |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 142 | struct fujitsu_t { |
| 143 | acpi_handle acpi_handle; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 144 | struct acpi_device *dev; |
| 145 | struct input_dev *input; |
| 146 | char phys[32]; |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 147 | struct backlight_device *bl_device; |
| 148 | struct platform_device *pf_device; |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 149 | int keycode1, keycode2, keycode3, keycode4; |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 150 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 151 | unsigned int max_brightness; |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 152 | unsigned int brightness_changed; |
| 153 | unsigned int brightness_level; |
| 154 | }; |
| 155 | |
| 156 | static struct fujitsu_t *fujitsu; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 157 | static int use_alt_lcd_levels = -1; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 158 | static int disable_brightness_adjust = -1; |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 159 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 160 | /* Device used to access other hotkeys on the laptop */ |
| 161 | struct fujitsu_hotkey_t { |
| 162 | acpi_handle acpi_handle; |
| 163 | struct acpi_device *dev; |
| 164 | struct input_dev *input; |
| 165 | char phys[32]; |
| 166 | struct platform_device *pf_device; |
| 167 | struct kfifo *fifo; |
| 168 | spinlock_t fifo_lock; |
Tony Vroon | 4898c2b | 2009-02-02 11:11:10 +0000 | [diff] [blame] | 169 | int rfkill_supported; |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 170 | int rfkill_state; |
| 171 | int logolamp_registered; |
| 172 | int kblamps_registered; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | static struct fujitsu_hotkey_t *fujitsu_hotkey; |
| 176 | |
Bjorn Helgaas | b4ec027 | 2009-04-07 15:37:22 +0000 | [diff] [blame] | 177 | static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 178 | |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 179 | #ifdef CONFIG_LEDS_CLASS |
| 180 | static enum led_brightness logolamp_get(struct led_classdev *cdev); |
| 181 | static void logolamp_set(struct led_classdev *cdev, |
| 182 | enum led_brightness brightness); |
| 183 | |
| 184 | struct led_classdev logolamp_led = { |
| 185 | .name = "fujitsu::logolamp", |
| 186 | .brightness_get = logolamp_get, |
| 187 | .brightness_set = logolamp_set |
| 188 | }; |
| 189 | |
| 190 | static enum led_brightness kblamps_get(struct led_classdev *cdev); |
| 191 | static void kblamps_set(struct led_classdev *cdev, |
| 192 | enum led_brightness brightness); |
| 193 | |
| 194 | struct led_classdev kblamps_led = { |
| 195 | .name = "fujitsu::kblamps", |
| 196 | .brightness_get = kblamps_get, |
| 197 | .brightness_set = kblamps_set |
| 198 | }; |
| 199 | #endif |
| 200 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 201 | #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG |
| 202 | static u32 dbg_level = 0x03; |
| 203 | #endif |
| 204 | |
Bjorn Helgaas | 700b672 | 2009-04-07 15:37:16 +0000 | [diff] [blame] | 205 | static void acpi_fujitsu_notify(struct acpi_device *device, u32 event); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 206 | |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 207 | /* Fujitsu ACPI interface function */ |
| 208 | |
| 209 | static int call_fext_func(int cmd, int arg0, int arg1, int arg2) |
| 210 | { |
| 211 | acpi_status status = AE_OK; |
| 212 | union acpi_object params[4] = { |
| 213 | { .type = ACPI_TYPE_INTEGER }, |
| 214 | { .type = ACPI_TYPE_INTEGER }, |
| 215 | { .type = ACPI_TYPE_INTEGER }, |
| 216 | { .type = ACPI_TYPE_INTEGER } |
| 217 | }; |
| 218 | struct acpi_object_list arg_list = { 4, ¶ms[0] }; |
| 219 | struct acpi_buffer output; |
| 220 | union acpi_object out_obj; |
| 221 | acpi_handle handle = NULL; |
| 222 | |
| 223 | status = acpi_get_handle(fujitsu_hotkey->acpi_handle, "FUNC", &handle); |
| 224 | if (ACPI_FAILURE(status)) { |
| 225 | vdbg_printk(FUJLAPTOP_DBG_ERROR, |
| 226 | "FUNC interface is not present\n"); |
| 227 | return -ENODEV; |
| 228 | } |
| 229 | |
| 230 | params[0].integer.value = cmd; |
| 231 | params[1].integer.value = arg0; |
| 232 | params[2].integer.value = arg1; |
| 233 | params[3].integer.value = arg2; |
| 234 | |
| 235 | output.length = sizeof(out_obj); |
| 236 | output.pointer = &out_obj; |
| 237 | |
| 238 | status = acpi_evaluate_object(handle, NULL, &arg_list, &output); |
| 239 | if (ACPI_FAILURE(status)) { |
| 240 | vdbg_printk(FUJLAPTOP_DBG_WARN, |
| 241 | "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) call failed\n", |
| 242 | cmd, arg0, arg1, arg2); |
| 243 | return -ENODEV; |
| 244 | } |
| 245 | |
| 246 | if (out_obj.type != ACPI_TYPE_INTEGER) { |
| 247 | vdbg_printk(FUJLAPTOP_DBG_WARN, |
| 248 | "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) did not " |
| 249 | "return an integer\n", |
| 250 | cmd, arg0, arg1, arg2); |
| 251 | return -ENODEV; |
| 252 | } |
| 253 | |
| 254 | vdbg_printk(FUJLAPTOP_DBG_TRACE, |
| 255 | "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n", |
| 256 | cmd, arg0, arg1, arg2, (int)out_obj.integer.value); |
| 257 | return out_obj.integer.value; |
| 258 | } |
| 259 | |
| 260 | #ifdef CONFIG_LEDS_CLASS |
| 261 | /* LED class callbacks */ |
| 262 | |
| 263 | static void logolamp_set(struct led_classdev *cdev, |
| 264 | enum led_brightness brightness) |
| 265 | { |
| 266 | if (brightness >= LED_FULL) { |
| 267 | call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_ON); |
| 268 | call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, FUNC_LED_ON); |
| 269 | } else if (brightness >= LED_HALF) { |
| 270 | call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_ON); |
| 271 | call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, FUNC_LED_OFF); |
| 272 | } else { |
| 273 | call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_OFF); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | static void kblamps_set(struct led_classdev *cdev, |
| 278 | enum led_brightness brightness) |
| 279 | { |
| 280 | if (brightness >= LED_FULL) |
| 281 | call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_ON); |
| 282 | else |
| 283 | call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_OFF); |
| 284 | } |
| 285 | |
| 286 | static enum led_brightness logolamp_get(struct led_classdev *cdev) |
| 287 | { |
| 288 | enum led_brightness brightness = LED_OFF; |
| 289 | int poweron, always; |
| 290 | |
| 291 | poweron = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0); |
| 292 | if (poweron == FUNC_LED_ON) { |
| 293 | brightness = LED_HALF; |
| 294 | always = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0); |
| 295 | if (always == FUNC_LED_ON) |
| 296 | brightness = LED_FULL; |
| 297 | } |
| 298 | return brightness; |
| 299 | } |
| 300 | |
| 301 | static enum led_brightness kblamps_get(struct led_classdev *cdev) |
| 302 | { |
| 303 | enum led_brightness brightness = LED_OFF; |
| 304 | |
| 305 | if (call_fext_func(FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON) |
| 306 | brightness = LED_FULL; |
| 307 | |
| 308 | return brightness; |
| 309 | } |
| 310 | #endif |
| 311 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 312 | /* Hardware access for LCD brightness control */ |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 313 | |
| 314 | static int set_lcd_level(int level) |
| 315 | { |
| 316 | acpi_status status = AE_OK; |
| 317 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; |
| 318 | struct acpi_object_list arg_list = { 1, &arg0 }; |
| 319 | acpi_handle handle = NULL; |
| 320 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 321 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n", |
| 322 | level); |
| 323 | |
| 324 | if (level < 0 || level >= fujitsu->max_brightness) |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 325 | return -EINVAL; |
| 326 | |
| 327 | if (!fujitsu) |
| 328 | return -EINVAL; |
| 329 | |
| 330 | status = acpi_get_handle(fujitsu->acpi_handle, "SBLL", &handle); |
| 331 | if (ACPI_FAILURE(status)) { |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 332 | vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n"); |
| 333 | return -ENODEV; |
| 334 | } |
| 335 | |
| 336 | arg0.integer.value = level; |
| 337 | |
| 338 | status = acpi_evaluate_object(handle, NULL, &arg_list, NULL); |
| 339 | if (ACPI_FAILURE(status)) |
| 340 | return -ENODEV; |
| 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | static int set_lcd_level_alt(int level) |
| 346 | { |
| 347 | acpi_status status = AE_OK; |
| 348 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; |
| 349 | struct acpi_object_list arg_list = { 1, &arg0 }; |
| 350 | acpi_handle handle = NULL; |
| 351 | |
| 352 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n", |
| 353 | level); |
| 354 | |
| 355 | if (level < 0 || level >= fujitsu->max_brightness) |
| 356 | return -EINVAL; |
| 357 | |
| 358 | if (!fujitsu) |
| 359 | return -EINVAL; |
| 360 | |
| 361 | status = acpi_get_handle(fujitsu->acpi_handle, "SBL2", &handle); |
| 362 | if (ACPI_FAILURE(status)) { |
| 363 | vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n"); |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 364 | return -ENODEV; |
| 365 | } |
| 366 | |
| 367 | arg0.integer.value = level; |
| 368 | |
| 369 | status = acpi_evaluate_object(handle, NULL, &arg_list, NULL); |
| 370 | if (ACPI_FAILURE(status)) |
| 371 | return -ENODEV; |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | static int get_lcd_level(void) |
| 377 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 378 | unsigned long long state = 0; |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 379 | acpi_status status = AE_OK; |
| 380 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 381 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n"); |
| 382 | |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 383 | status = |
| 384 | acpi_evaluate_integer(fujitsu->acpi_handle, "GBLL", NULL, &state); |
| 385 | if (status < 0) |
| 386 | return status; |
| 387 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 388 | fujitsu->brightness_level = state & 0x0fffffff; |
| 389 | |
| 390 | if (state & 0x80000000) |
| 391 | fujitsu->brightness_changed = 1; |
| 392 | else |
| 393 | fujitsu->brightness_changed = 0; |
| 394 | |
| 395 | return fujitsu->brightness_level; |
| 396 | } |
| 397 | |
| 398 | static int get_max_brightness(void) |
| 399 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 400 | unsigned long long state = 0; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 401 | acpi_status status = AE_OK; |
| 402 | |
| 403 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n"); |
| 404 | |
| 405 | status = |
| 406 | acpi_evaluate_integer(fujitsu->acpi_handle, "RBLL", NULL, &state); |
| 407 | if (status < 0) |
| 408 | return status; |
| 409 | |
| 410 | fujitsu->max_brightness = state; |
| 411 | |
| 412 | return fujitsu->max_brightness; |
| 413 | } |
| 414 | |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 415 | /* Backlight device stuff */ |
| 416 | |
| 417 | static int bl_get_brightness(struct backlight_device *b) |
| 418 | { |
Tony Vroon | f87a1a5 | 2009-01-07 10:11:24 +0000 | [diff] [blame] | 419 | return get_lcd_level(); |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | static int bl_update_status(struct backlight_device *b) |
| 423 | { |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 424 | int ret; |
| 425 | if (b->props.power == 4) |
| 426 | ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x3); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 427 | else |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 428 | ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x0); |
| 429 | if (ret != 0) |
| 430 | vdbg_printk(FUJLAPTOP_DBG_ERROR, |
| 431 | "Unable to adjust backlight power, error code %i\n", |
| 432 | ret); |
| 433 | |
| 434 | if (use_alt_lcd_levels) |
| 435 | ret = set_lcd_level_alt(b->props.brightness); |
| 436 | else |
| 437 | ret = set_lcd_level(b->props.brightness); |
| 438 | if (ret != 0) |
| 439 | vdbg_printk(FUJLAPTOP_DBG_ERROR, |
| 440 | "Unable to adjust LCD brightness, error code %i\n", |
| 441 | ret); |
| 442 | return ret; |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | static struct backlight_ops fujitsubl_ops = { |
| 446 | .get_brightness = bl_get_brightness, |
| 447 | .update_status = bl_update_status, |
| 448 | }; |
| 449 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 450 | /* Platform LCD brightness device */ |
| 451 | |
| 452 | static ssize_t |
| 453 | show_max_brightness(struct device *dev, |
| 454 | struct device_attribute *attr, char *buf) |
| 455 | { |
| 456 | |
| 457 | int ret; |
| 458 | |
| 459 | ret = get_max_brightness(); |
| 460 | if (ret < 0) |
| 461 | return ret; |
| 462 | |
| 463 | return sprintf(buf, "%i\n", ret); |
| 464 | } |
| 465 | |
| 466 | static ssize_t |
| 467 | show_brightness_changed(struct device *dev, |
| 468 | struct device_attribute *attr, char *buf) |
| 469 | { |
| 470 | |
| 471 | int ret; |
| 472 | |
| 473 | ret = fujitsu->brightness_changed; |
| 474 | if (ret < 0) |
| 475 | return ret; |
| 476 | |
| 477 | return sprintf(buf, "%i\n", ret); |
| 478 | } |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 479 | |
| 480 | static ssize_t show_lcd_level(struct device *dev, |
| 481 | struct device_attribute *attr, char *buf) |
| 482 | { |
| 483 | |
| 484 | int ret; |
| 485 | |
Tony Vroon | f87a1a5 | 2009-01-07 10:11:24 +0000 | [diff] [blame] | 486 | ret = get_lcd_level(); |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 487 | if (ret < 0) |
| 488 | return ret; |
| 489 | |
| 490 | return sprintf(buf, "%i\n", ret); |
| 491 | } |
| 492 | |
| 493 | static ssize_t store_lcd_level(struct device *dev, |
| 494 | struct device_attribute *attr, const char *buf, |
| 495 | size_t count) |
| 496 | { |
| 497 | |
| 498 | int level, ret; |
| 499 | |
| 500 | if (sscanf(buf, "%i", &level) != 1 |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 501 | || (level < 0 || level >= fujitsu->max_brightness)) |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 502 | return -EINVAL; |
| 503 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 504 | if (use_alt_lcd_levels) |
| 505 | ret = set_lcd_level_alt(level); |
| 506 | else |
| 507 | ret = set_lcd_level(level); |
| 508 | if (ret < 0) |
| 509 | return ret; |
| 510 | |
Tony Vroon | f87a1a5 | 2009-01-07 10:11:24 +0000 | [diff] [blame] | 511 | ret = get_lcd_level(); |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 512 | if (ret < 0) |
| 513 | return ret; |
| 514 | |
| 515 | return count; |
| 516 | } |
| 517 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 518 | static ssize_t |
| 519 | ignore_store(struct device *dev, |
| 520 | struct device_attribute *attr, const char *buf, size_t count) |
| 521 | { |
| 522 | return count; |
| 523 | } |
| 524 | |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 525 | static ssize_t |
| 526 | show_lid_state(struct device *dev, |
| 527 | struct device_attribute *attr, char *buf) |
| 528 | { |
Tony Vroon | 4898c2b | 2009-02-02 11:11:10 +0000 | [diff] [blame] | 529 | if (!(fujitsu_hotkey->rfkill_supported & 0x100)) |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 530 | return sprintf(buf, "unknown\n"); |
| 531 | if (fujitsu_hotkey->rfkill_state & 0x100) |
| 532 | return sprintf(buf, "open\n"); |
| 533 | else |
| 534 | return sprintf(buf, "closed\n"); |
| 535 | } |
| 536 | |
| 537 | static ssize_t |
| 538 | show_dock_state(struct device *dev, |
| 539 | struct device_attribute *attr, char *buf) |
| 540 | { |
Tony Vroon | 4898c2b | 2009-02-02 11:11:10 +0000 | [diff] [blame] | 541 | if (!(fujitsu_hotkey->rfkill_supported & 0x200)) |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 542 | return sprintf(buf, "unknown\n"); |
| 543 | if (fujitsu_hotkey->rfkill_state & 0x200) |
| 544 | return sprintf(buf, "docked\n"); |
| 545 | else |
| 546 | return sprintf(buf, "undocked\n"); |
| 547 | } |
| 548 | |
| 549 | static ssize_t |
| 550 | show_radios_state(struct device *dev, |
| 551 | struct device_attribute *attr, char *buf) |
| 552 | { |
Tony Vroon | 4898c2b | 2009-02-02 11:11:10 +0000 | [diff] [blame] | 553 | if (!(fujitsu_hotkey->rfkill_supported & 0x20)) |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 554 | return sprintf(buf, "unknown\n"); |
| 555 | if (fujitsu_hotkey->rfkill_state & 0x20) |
| 556 | return sprintf(buf, "on\n"); |
| 557 | else |
| 558 | return sprintf(buf, "killed\n"); |
| 559 | } |
| 560 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 561 | static DEVICE_ATTR(max_brightness, 0444, show_max_brightness, ignore_store); |
| 562 | static DEVICE_ATTR(brightness_changed, 0444, show_brightness_changed, |
| 563 | ignore_store); |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 564 | static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level); |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 565 | static DEVICE_ATTR(lid, 0444, show_lid_state, ignore_store); |
| 566 | static DEVICE_ATTR(dock, 0444, show_dock_state, ignore_store); |
| 567 | static DEVICE_ATTR(radios, 0444, show_radios_state, ignore_store); |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 568 | |
| 569 | static struct attribute *fujitsupf_attributes[] = { |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 570 | &dev_attr_brightness_changed.attr, |
| 571 | &dev_attr_max_brightness.attr, |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 572 | &dev_attr_lcd_level.attr, |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 573 | &dev_attr_lid.attr, |
| 574 | &dev_attr_dock.attr, |
| 575 | &dev_attr_radios.attr, |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 576 | NULL |
| 577 | }; |
| 578 | |
| 579 | static struct attribute_group fujitsupf_attribute_group = { |
| 580 | .attrs = fujitsupf_attributes |
| 581 | }; |
| 582 | |
| 583 | static struct platform_driver fujitsupf_driver = { |
| 584 | .driver = { |
| 585 | .name = "fujitsu-laptop", |
| 586 | .owner = THIS_MODULE, |
| 587 | } |
| 588 | }; |
| 589 | |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 590 | static void dmi_check_cb_common(const struct dmi_system_id *id) |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 591 | { |
| 592 | acpi_handle handle; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 593 | printk(KERN_INFO "fujitsu-laptop: Identified laptop model '%s'.\n", |
| 594 | id->ident); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 595 | if (use_alt_lcd_levels == -1) { |
Tony Vroon | f87a1a5 | 2009-01-07 10:11:24 +0000 | [diff] [blame] | 596 | if (ACPI_SUCCESS(acpi_get_handle(NULL, |
| 597 | "\\_SB.PCI0.LPCB.FJEX.SBL2", &handle))) |
| 598 | use_alt_lcd_levels = 1; |
| 599 | else |
| 600 | use_alt_lcd_levels = 0; |
| 601 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detected usealt as " |
| 602 | "%i\n", use_alt_lcd_levels); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 603 | } |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | static int dmi_check_cb_s6410(const struct dmi_system_id *id) |
| 607 | { |
| 608 | dmi_check_cb_common(id); |
| 609 | fujitsu->keycode1 = KEY_SCREENLOCK; /* "Lock" */ |
| 610 | fujitsu->keycode2 = KEY_HELP; /* "Mobility Center" */ |
| 611 | return 0; |
| 612 | } |
| 613 | |
Tony Vroon | 56960b5 | 2008-11-09 04:20:05 +0000 | [diff] [blame] | 614 | static int dmi_check_cb_s6420(const struct dmi_system_id *id) |
| 615 | { |
| 616 | dmi_check_cb_common(id); |
| 617 | fujitsu->keycode1 = KEY_SCREENLOCK; /* "Lock" */ |
| 618 | fujitsu->keycode2 = KEY_HELP; /* "Mobility Center" */ |
| 619 | return 0; |
| 620 | } |
| 621 | |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 622 | static int dmi_check_cb_p8010(const struct dmi_system_id *id) |
| 623 | { |
| 624 | dmi_check_cb_common(id); |
| 625 | fujitsu->keycode1 = KEY_HELP; /* "Support" */ |
| 626 | fujitsu->keycode3 = KEY_SWITCHVIDEOMODE; /* "Presentation" */ |
| 627 | fujitsu->keycode4 = KEY_WWW; /* "Internet" */ |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 628 | return 0; |
| 629 | } |
| 630 | |
Randy Dunlap | afeb12b | 2008-10-29 14:13:20 -0700 | [diff] [blame] | 631 | static struct dmi_system_id fujitsu_dmi_table[] = { |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 632 | { |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 633 | .ident = "Fujitsu Siemens S6410", |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 634 | .matches = { |
| 635 | DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), |
| 636 | DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"), |
| 637 | }, |
| 638 | .callback = dmi_check_cb_s6410}, |
Jonathan Woithe | d8196a9 | 2008-08-29 11:06:21 +0930 | [diff] [blame] | 639 | { |
Tony Vroon | 56960b5 | 2008-11-09 04:20:05 +0000 | [diff] [blame] | 640 | .ident = "Fujitsu Siemens S6420", |
| 641 | .matches = { |
| 642 | DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), |
| 643 | DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"), |
| 644 | }, |
| 645 | .callback = dmi_check_cb_s6420}, |
| 646 | { |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 647 | .ident = "Fujitsu LifeBook P8010", |
Jonathan Woithe | d8196a9 | 2008-08-29 11:06:21 +0930 | [diff] [blame] | 648 | .matches = { |
| 649 | DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"), |
| 650 | DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"), |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 651 | }, |
| 652 | .callback = dmi_check_cb_p8010}, |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 653 | {} |
| 654 | }; |
| 655 | |
| 656 | /* ACPI device for LCD brightness control */ |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 657 | |
Adrian Bunk | b6f03ae | 2007-10-24 18:23:16 +0200 | [diff] [blame] | 658 | static int acpi_fujitsu_add(struct acpi_device *device) |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 659 | { |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 660 | acpi_handle handle; |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 661 | int result = 0; |
| 662 | int state = 0; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 663 | struct input_dev *input; |
| 664 | int error; |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 665 | |
| 666 | if (!device) |
| 667 | return -EINVAL; |
| 668 | |
| 669 | fujitsu->acpi_handle = device->handle; |
| 670 | sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_DEVICE_NAME); |
| 671 | sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 672 | device->driver_data = fujitsu; |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 673 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 674 | fujitsu->input = input = input_allocate_device(); |
| 675 | if (!input) { |
| 676 | error = -ENOMEM; |
Bjorn Helgaas | 700b672 | 2009-04-07 15:37:16 +0000 | [diff] [blame] | 677 | goto err_stop; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | snprintf(fujitsu->phys, sizeof(fujitsu->phys), |
| 681 | "%s/video/input0", acpi_device_hid(device)); |
| 682 | |
| 683 | input->name = acpi_device_name(device); |
| 684 | input->phys = fujitsu->phys; |
| 685 | input->id.bustype = BUS_HOST; |
| 686 | input->id.product = 0x06; |
| 687 | input->dev.parent = &device->dev; |
| 688 | input->evbit[0] = BIT(EV_KEY); |
| 689 | set_bit(KEY_BRIGHTNESSUP, input->keybit); |
| 690 | set_bit(KEY_BRIGHTNESSDOWN, input->keybit); |
| 691 | set_bit(KEY_UNKNOWN, input->keybit); |
| 692 | |
| 693 | error = input_register_device(input); |
| 694 | if (error) |
| 695 | goto err_free_input_dev; |
| 696 | |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 697 | result = acpi_bus_get_power(fujitsu->acpi_handle, &state); |
| 698 | if (result) { |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 699 | printk(KERN_ERR "Error reading power state\n"); |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 700 | goto end; |
| 701 | } |
| 702 | |
| 703 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", |
| 704 | acpi_device_name(device), acpi_device_bid(device), |
| 705 | !device->power.state ? "on" : "off"); |
| 706 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 707 | fujitsu->dev = device; |
| 708 | |
| 709 | if (ACPI_SUCCESS |
| 710 | (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) { |
| 711 | vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n"); |
| 712 | if (ACPI_FAILURE |
| 713 | (acpi_evaluate_object |
| 714 | (device->handle, METHOD_NAME__INI, NULL, NULL))) |
| 715 | printk(KERN_ERR "_INI Method failed\n"); |
| 716 | } |
| 717 | |
| 718 | /* do config (detect defaults) */ |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 719 | use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 720 | disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0; |
| 721 | vdbg_printk(FUJLAPTOP_DBG_INFO, |
Tony Vroon | f87a1a5 | 2009-01-07 10:11:24 +0000 | [diff] [blame] | 722 | "config: [alt interface: %d], [adjust disable: %d]\n", |
| 723 | use_alt_lcd_levels, disable_brightness_adjust); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 724 | |
| 725 | if (get_max_brightness() <= 0) |
| 726 | fujitsu->max_brightness = FUJITSU_LCD_N_LEVELS; |
Tony Vroon | f87a1a5 | 2009-01-07 10:11:24 +0000 | [diff] [blame] | 727 | get_lcd_level(); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 728 | |
| 729 | return result; |
| 730 | |
| 731 | end: |
| 732 | err_free_input_dev: |
| 733 | input_free_device(input); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 734 | err_stop: |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 735 | |
| 736 | return result; |
| 737 | } |
| 738 | |
Adrian Bunk | b6f03ae | 2007-10-24 18:23:16 +0200 | [diff] [blame] | 739 | static int acpi_fujitsu_remove(struct acpi_device *device, int type) |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 740 | { |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 741 | struct fujitsu_t *fujitsu = NULL; |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 742 | |
| 743 | if (!device || !acpi_driver_data(device)) |
| 744 | return -EINVAL; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 745 | |
| 746 | fujitsu = acpi_driver_data(device); |
| 747 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 748 | if (!device || !acpi_driver_data(device)) |
| 749 | return -EINVAL; |
| 750 | |
Al Viro | 5cf83b9 | 2008-03-29 03:07:48 +0000 | [diff] [blame] | 751 | fujitsu->acpi_handle = NULL; |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 752 | |
| 753 | return 0; |
| 754 | } |
| 755 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 756 | /* Brightness notify */ |
| 757 | |
Bjorn Helgaas | 700b672 | 2009-04-07 15:37:16 +0000 | [diff] [blame] | 758 | static void acpi_fujitsu_notify(struct acpi_device *device, u32 event) |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 759 | { |
| 760 | struct input_dev *input; |
| 761 | int keycode; |
| 762 | int oldb, newb; |
| 763 | |
| 764 | input = fujitsu->input; |
| 765 | |
| 766 | switch (event) { |
| 767 | case ACPI_FUJITSU_NOTIFY_CODE1: |
| 768 | keycode = 0; |
| 769 | oldb = fujitsu->brightness_level; |
Tony Vroon | f87a1a5 | 2009-01-07 10:11:24 +0000 | [diff] [blame] | 770 | get_lcd_level(); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 771 | newb = fujitsu->brightness_level; |
| 772 | |
| 773 | vdbg_printk(FUJLAPTOP_DBG_TRACE, |
| 774 | "brightness button event [%i -> %i (%i)]\n", |
| 775 | oldb, newb, fujitsu->brightness_changed); |
| 776 | |
Tony Vroon | f87a1a5 | 2009-01-07 10:11:24 +0000 | [diff] [blame] | 777 | if (oldb < newb) { |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 778 | if (disable_brightness_adjust != 1) { |
| 779 | if (use_alt_lcd_levels) |
| 780 | set_lcd_level_alt(newb); |
| 781 | else |
| 782 | set_lcd_level(newb); |
| 783 | } |
Tony Vroon | f87a1a5 | 2009-01-07 10:11:24 +0000 | [diff] [blame] | 784 | acpi_bus_generate_proc_event(fujitsu->dev, |
| 785 | ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS, 0); |
| 786 | keycode = KEY_BRIGHTNESSUP; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 787 | } else if (oldb > newb) { |
| 788 | if (disable_brightness_adjust != 1) { |
| 789 | if (use_alt_lcd_levels) |
| 790 | set_lcd_level_alt(newb); |
| 791 | else |
| 792 | set_lcd_level(newb); |
| 793 | } |
Tony Vroon | f87a1a5 | 2009-01-07 10:11:24 +0000 | [diff] [blame] | 794 | acpi_bus_generate_proc_event(fujitsu->dev, |
| 795 | ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS, 0); |
| 796 | keycode = KEY_BRIGHTNESSDOWN; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 797 | } |
| 798 | break; |
| 799 | default: |
| 800 | keycode = KEY_UNKNOWN; |
| 801 | vdbg_printk(FUJLAPTOP_DBG_WARN, |
| 802 | "unsupported event [0x%x]\n", event); |
| 803 | break; |
| 804 | } |
| 805 | |
| 806 | if (keycode != 0) { |
| 807 | input_report_key(input, keycode, 1); |
| 808 | input_sync(input); |
| 809 | input_report_key(input, keycode, 0); |
| 810 | input_sync(input); |
| 811 | } |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | /* ACPI device for hotkey handling */ |
| 815 | |
| 816 | static int acpi_fujitsu_hotkey_add(struct acpi_device *device) |
| 817 | { |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 818 | acpi_handle handle; |
| 819 | int result = 0; |
| 820 | int state = 0; |
| 821 | struct input_dev *input; |
| 822 | int error; |
| 823 | int i; |
| 824 | |
| 825 | if (!device) |
| 826 | return -EINVAL; |
| 827 | |
| 828 | fujitsu_hotkey->acpi_handle = device->handle; |
| 829 | sprintf(acpi_device_name(device), "%s", |
| 830 | ACPI_FUJITSU_HOTKEY_DEVICE_NAME); |
| 831 | sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 832 | device->driver_data = fujitsu_hotkey; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 833 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 834 | /* kfifo */ |
| 835 | spin_lock_init(&fujitsu_hotkey->fifo_lock); |
| 836 | fujitsu_hotkey->fifo = |
| 837 | kfifo_alloc(RINGBUFFERSIZE * sizeof(int), GFP_KERNEL, |
| 838 | &fujitsu_hotkey->fifo_lock); |
| 839 | if (IS_ERR(fujitsu_hotkey->fifo)) { |
| 840 | printk(KERN_ERR "kfifo_alloc failed\n"); |
| 841 | error = PTR_ERR(fujitsu_hotkey->fifo); |
| 842 | goto err_stop; |
| 843 | } |
| 844 | |
| 845 | fujitsu_hotkey->input = input = input_allocate_device(); |
| 846 | if (!input) { |
| 847 | error = -ENOMEM; |
Bjorn Helgaas | b4ec027 | 2009-04-07 15:37:22 +0000 | [diff] [blame] | 848 | goto err_free_fifo; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | snprintf(fujitsu_hotkey->phys, sizeof(fujitsu_hotkey->phys), |
| 852 | "%s/video/input0", acpi_device_hid(device)); |
| 853 | |
| 854 | input->name = acpi_device_name(device); |
| 855 | input->phys = fujitsu_hotkey->phys; |
| 856 | input->id.bustype = BUS_HOST; |
| 857 | input->id.product = 0x06; |
| 858 | input->dev.parent = &device->dev; |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 859 | |
| 860 | set_bit(EV_KEY, input->evbit); |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 861 | set_bit(fujitsu->keycode1, input->keybit); |
| 862 | set_bit(fujitsu->keycode2, input->keybit); |
| 863 | set_bit(fujitsu->keycode3, input->keybit); |
| 864 | set_bit(fujitsu->keycode4, input->keybit); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 865 | set_bit(KEY_UNKNOWN, input->keybit); |
| 866 | |
| 867 | error = input_register_device(input); |
| 868 | if (error) |
| 869 | goto err_free_input_dev; |
| 870 | |
| 871 | result = acpi_bus_get_power(fujitsu_hotkey->acpi_handle, &state); |
| 872 | if (result) { |
| 873 | printk(KERN_ERR "Error reading power state\n"); |
| 874 | goto end; |
| 875 | } |
| 876 | |
| 877 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", |
| 878 | acpi_device_name(device), acpi_device_bid(device), |
| 879 | !device->power.state ? "on" : "off"); |
| 880 | |
| 881 | fujitsu_hotkey->dev = device; |
| 882 | |
| 883 | if (ACPI_SUCCESS |
| 884 | (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) { |
| 885 | vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n"); |
| 886 | if (ACPI_FAILURE |
| 887 | (acpi_evaluate_object |
| 888 | (device->handle, METHOD_NAME__INI, NULL, NULL))) |
| 889 | printk(KERN_ERR "_INI Method failed\n"); |
| 890 | } |
| 891 | |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 892 | i = 0; |
| 893 | while (call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0 |
| 894 | && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) |
| 895 | ; /* No action, result is discarded */ |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 896 | vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i); |
| 897 | |
Tony Vroon | 4898c2b | 2009-02-02 11:11:10 +0000 | [diff] [blame] | 898 | fujitsu_hotkey->rfkill_supported = |
| 899 | call_fext_func(FUNC_RFKILL, 0x0, 0x0, 0x0); |
| 900 | |
| 901 | /* Make sure our bitmask of supported functions is cleared if the |
| 902 | RFKILL function block is not implemented, like on the S7020. */ |
| 903 | if (fujitsu_hotkey->rfkill_supported == UNSUPPORTED_CMD) |
| 904 | fujitsu_hotkey->rfkill_supported = 0; |
| 905 | |
| 906 | if (fujitsu_hotkey->rfkill_supported) |
| 907 | fujitsu_hotkey->rfkill_state = |
| 908 | call_fext_func(FUNC_RFKILL, 0x4, 0x0, 0x0); |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 909 | |
| 910 | /* Suspect this is a keymap of the application panel, print it */ |
| 911 | printk(KERN_INFO "fujitsu-laptop: BTNI: [0x%x]\n", |
| 912 | call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0)); |
| 913 | |
| 914 | #ifdef CONFIG_LEDS_CLASS |
| 915 | if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) { |
| 916 | result = led_classdev_register(&fujitsu->pf_device->dev, |
| 917 | &logolamp_led); |
| 918 | if (result == 0) { |
| 919 | fujitsu_hotkey->logolamp_registered = 1; |
| 920 | } else { |
| 921 | printk(KERN_ERR "fujitsu-laptop: Could not register " |
| 922 | "LED handler for logo lamp, error %i\n", result); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) && |
| 927 | (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) { |
| 928 | result = led_classdev_register(&fujitsu->pf_device->dev, |
| 929 | &kblamps_led); |
| 930 | if (result == 0) { |
| 931 | fujitsu_hotkey->kblamps_registered = 1; |
| 932 | } else { |
| 933 | printk(KERN_ERR "fujitsu-laptop: Could not register " |
| 934 | "LED handler for keyboard lamps, error %i\n", result); |
| 935 | } |
| 936 | } |
| 937 | #endif |
| 938 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 939 | return result; |
| 940 | |
| 941 | end: |
| 942 | err_free_input_dev: |
| 943 | input_free_device(input); |
Bjorn Helgaas | b4ec027 | 2009-04-07 15:37:22 +0000 | [diff] [blame] | 944 | err_free_fifo: |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 945 | kfifo_free(fujitsu_hotkey->fifo); |
| 946 | err_stop: |
| 947 | |
| 948 | return result; |
| 949 | } |
| 950 | |
| 951 | static int acpi_fujitsu_hotkey_remove(struct acpi_device *device, int type) |
| 952 | { |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 953 | struct fujitsu_hotkey_t *fujitsu_hotkey = NULL; |
| 954 | |
| 955 | if (!device || !acpi_driver_data(device)) |
| 956 | return -EINVAL; |
| 957 | |
| 958 | fujitsu_hotkey = acpi_driver_data(device); |
| 959 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 960 | fujitsu_hotkey->acpi_handle = NULL; |
| 961 | |
| 962 | kfifo_free(fujitsu_hotkey->fifo); |
| 963 | |
| 964 | return 0; |
| 965 | } |
| 966 | |
Bjorn Helgaas | b4ec027 | 2009-04-07 15:37:22 +0000 | [diff] [blame] | 967 | static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event) |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 968 | { |
| 969 | struct input_dev *input; |
| 970 | int keycode, keycode_r; |
| 971 | unsigned int irb = 1; |
| 972 | int i, status; |
| 973 | |
| 974 | input = fujitsu_hotkey->input; |
| 975 | |
Tony Vroon | 4898c2b | 2009-02-02 11:11:10 +0000 | [diff] [blame] | 976 | if (fujitsu_hotkey->rfkill_supported) |
| 977 | fujitsu_hotkey->rfkill_state = |
| 978 | call_fext_func(FUNC_RFKILL, 0x4, 0x0, 0x0); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 979 | |
| 980 | switch (event) { |
| 981 | case ACPI_FUJITSU_NOTIFY_CODE1: |
| 982 | i = 0; |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 983 | while ((irb = |
| 984 | call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0 |
| 985 | && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) { |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 986 | switch (irb & 0x4ff) { |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 987 | case KEY1_CODE: |
| 988 | keycode = fujitsu->keycode1; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 989 | break; |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 990 | case KEY2_CODE: |
| 991 | keycode = fujitsu->keycode2; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 992 | break; |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 993 | case KEY3_CODE: |
| 994 | keycode = fujitsu->keycode3; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 995 | break; |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 996 | case KEY4_CODE: |
| 997 | keycode = fujitsu->keycode4; |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 998 | break; |
| 999 | case 0: |
| 1000 | keycode = 0; |
| 1001 | break; |
| 1002 | default: |
| 1003 | vdbg_printk(FUJLAPTOP_DBG_WARN, |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 1004 | "Unknown GIRB result [%x]\n", irb); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1005 | keycode = -1; |
| 1006 | break; |
| 1007 | } |
| 1008 | if (keycode > 0) { |
| 1009 | vdbg_printk(FUJLAPTOP_DBG_TRACE, |
| 1010 | "Push keycode into ringbuffer [%d]\n", |
| 1011 | keycode); |
| 1012 | status = kfifo_put(fujitsu_hotkey->fifo, |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 1013 | (unsigned char *)&keycode, |
| 1014 | sizeof(keycode)); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1015 | if (status != sizeof(keycode)) { |
| 1016 | vdbg_printk(FUJLAPTOP_DBG_WARN, |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 1017 | "Could not push keycode [0x%x]\n", |
| 1018 | keycode); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1019 | } else { |
| 1020 | input_report_key(input, keycode, 1); |
| 1021 | input_sync(input); |
| 1022 | } |
| 1023 | } else if (keycode == 0) { |
| 1024 | while ((status = |
| 1025 | kfifo_get |
| 1026 | (fujitsu_hotkey->fifo, (unsigned char *) |
| 1027 | &keycode_r, |
| 1028 | sizeof |
| 1029 | (keycode_r))) == sizeof(keycode_r)) { |
| 1030 | input_report_key(input, keycode_r, 0); |
| 1031 | input_sync(input); |
| 1032 | vdbg_printk(FUJLAPTOP_DBG_TRACE, |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 1033 | "Pop keycode from ringbuffer [%d]\n", |
| 1034 | keycode_r); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | break; |
| 1040 | default: |
| 1041 | keycode = KEY_UNKNOWN; |
| 1042 | vdbg_printk(FUJLAPTOP_DBG_WARN, |
| 1043 | "Unsupported event [0x%x]\n", event); |
| 1044 | input_report_key(input, keycode, 1); |
| 1045 | input_sync(input); |
| 1046 | input_report_key(input, keycode, 0); |
| 1047 | input_sync(input); |
| 1048 | break; |
| 1049 | } |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | /* Initialization */ |
| 1053 | |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1054 | static const struct acpi_device_id fujitsu_device_ids[] = { |
| 1055 | {ACPI_FUJITSU_HID, 0}, |
| 1056 | {"", 0}, |
| 1057 | }; |
| 1058 | |
| 1059 | static struct acpi_driver acpi_fujitsu_driver = { |
| 1060 | .name = ACPI_FUJITSU_DRIVER_NAME, |
| 1061 | .class = ACPI_FUJITSU_CLASS, |
| 1062 | .ids = fujitsu_device_ids, |
| 1063 | .ops = { |
| 1064 | .add = acpi_fujitsu_add, |
| 1065 | .remove = acpi_fujitsu_remove, |
Bjorn Helgaas | 700b672 | 2009-04-07 15:37:16 +0000 | [diff] [blame] | 1066 | .notify = acpi_fujitsu_notify, |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1067 | }, |
| 1068 | }; |
| 1069 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1070 | static const struct acpi_device_id fujitsu_hotkey_device_ids[] = { |
| 1071 | {ACPI_FUJITSU_HOTKEY_HID, 0}, |
| 1072 | {"", 0}, |
| 1073 | }; |
| 1074 | |
| 1075 | static struct acpi_driver acpi_fujitsu_hotkey_driver = { |
| 1076 | .name = ACPI_FUJITSU_HOTKEY_DRIVER_NAME, |
| 1077 | .class = ACPI_FUJITSU_CLASS, |
| 1078 | .ids = fujitsu_hotkey_device_ids, |
| 1079 | .ops = { |
| 1080 | .add = acpi_fujitsu_hotkey_add, |
| 1081 | .remove = acpi_fujitsu_hotkey_remove, |
Bjorn Helgaas | b4ec027 | 2009-04-07 15:37:22 +0000 | [diff] [blame] | 1082 | .notify = acpi_fujitsu_hotkey_notify, |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1083 | }, |
| 1084 | }; |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1085 | |
| 1086 | static int __init fujitsu_init(void) |
| 1087 | { |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1088 | int ret, result, max_brightness; |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1089 | |
| 1090 | if (acpi_disabled) |
| 1091 | return -ENODEV; |
| 1092 | |
| 1093 | fujitsu = kmalloc(sizeof(struct fujitsu_t), GFP_KERNEL); |
| 1094 | if (!fujitsu) |
| 1095 | return -ENOMEM; |
| 1096 | memset(fujitsu, 0, sizeof(struct fujitsu_t)); |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 1097 | fujitsu->keycode1 = KEY_PROG1; |
| 1098 | fujitsu->keycode2 = KEY_PROG2; |
| 1099 | fujitsu->keycode3 = KEY_PROG3; |
| 1100 | fujitsu->keycode4 = KEY_PROG4; |
| 1101 | dmi_check_system(fujitsu_dmi_table); |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1102 | |
| 1103 | result = acpi_bus_register_driver(&acpi_fujitsu_driver); |
| 1104 | if (result < 0) { |
| 1105 | ret = -ENODEV; |
| 1106 | goto fail_acpi; |
| 1107 | } |
| 1108 | |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1109 | /* Register platform stuff */ |
| 1110 | |
| 1111 | fujitsu->pf_device = platform_device_alloc("fujitsu-laptop", -1); |
| 1112 | if (!fujitsu->pf_device) { |
| 1113 | ret = -ENOMEM; |
| 1114 | goto fail_platform_driver; |
| 1115 | } |
| 1116 | |
| 1117 | ret = platform_device_add(fujitsu->pf_device); |
| 1118 | if (ret) |
| 1119 | goto fail_platform_device1; |
| 1120 | |
| 1121 | ret = |
| 1122 | sysfs_create_group(&fujitsu->pf_device->dev.kobj, |
| 1123 | &fujitsupf_attribute_group); |
| 1124 | if (ret) |
| 1125 | goto fail_platform_device2; |
| 1126 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1127 | /* Register backlight stuff */ |
| 1128 | |
Thomas Renninger | 7d5c89a | 2008-08-01 17:38:00 +0200 | [diff] [blame] | 1129 | if (!acpi_video_backlight_support()) { |
| 1130 | fujitsu->bl_device = |
| 1131 | backlight_device_register("fujitsu-laptop", NULL, NULL, |
| 1132 | &fujitsubl_ops); |
| 1133 | if (IS_ERR(fujitsu->bl_device)) |
| 1134 | return PTR_ERR(fujitsu->bl_device); |
| 1135 | max_brightness = fujitsu->max_brightness; |
| 1136 | fujitsu->bl_device->props.max_brightness = max_brightness - 1; |
| 1137 | fujitsu->bl_device->props.brightness = fujitsu->brightness_level; |
| 1138 | } |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1139 | |
| 1140 | ret = platform_driver_register(&fujitsupf_driver); |
| 1141 | if (ret) |
| 1142 | goto fail_backlight; |
| 1143 | |
| 1144 | /* Register hotkey driver */ |
| 1145 | |
| 1146 | fujitsu_hotkey = kmalloc(sizeof(struct fujitsu_hotkey_t), GFP_KERNEL); |
| 1147 | if (!fujitsu_hotkey) { |
| 1148 | ret = -ENOMEM; |
| 1149 | goto fail_hotkey; |
| 1150 | } |
| 1151 | memset(fujitsu_hotkey, 0, sizeof(struct fujitsu_hotkey_t)); |
| 1152 | |
| 1153 | result = acpi_bus_register_driver(&acpi_fujitsu_hotkey_driver); |
| 1154 | if (result < 0) { |
| 1155 | ret = -ENODEV; |
| 1156 | goto fail_hotkey1; |
| 1157 | } |
| 1158 | |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 1159 | /* Sync backlight power status (needs FUJ02E3 device, hence deferred) */ |
| 1160 | |
| 1161 | if (!acpi_video_backlight_support()) { |
| 1162 | if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3) |
| 1163 | fujitsu->bl_device->props.power = 4; |
| 1164 | else |
| 1165 | fujitsu->bl_device->props.power = 0; |
| 1166 | } |
| 1167 | |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1168 | printk(KERN_INFO "fujitsu-laptop: driver " FUJITSU_DRIVER_VERSION |
| 1169 | " successfully loaded.\n"); |
| 1170 | |
| 1171 | return 0; |
| 1172 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1173 | fail_hotkey1: |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1174 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1175 | kfree(fujitsu_hotkey); |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1176 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1177 | fail_hotkey: |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1178 | |
| 1179 | platform_driver_unregister(&fujitsupf_driver); |
| 1180 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1181 | fail_backlight: |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1182 | |
Thomas Renninger | 7d5c89a | 2008-08-01 17:38:00 +0200 | [diff] [blame] | 1183 | if (fujitsu->bl_device) |
| 1184 | backlight_device_unregister(fujitsu->bl_device); |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1185 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1186 | fail_platform_device2: |
| 1187 | |
| 1188 | platform_device_del(fujitsu->pf_device); |
| 1189 | |
| 1190 | fail_platform_device1: |
| 1191 | |
| 1192 | platform_device_put(fujitsu->pf_device); |
| 1193 | |
| 1194 | fail_platform_driver: |
| 1195 | |
| 1196 | acpi_bus_unregister_driver(&acpi_fujitsu_driver); |
| 1197 | |
| 1198 | fail_acpi: |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1199 | |
| 1200 | kfree(fujitsu); |
| 1201 | |
| 1202 | return ret; |
| 1203 | } |
| 1204 | |
| 1205 | static void __exit fujitsu_cleanup(void) |
| 1206 | { |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 1207 | #ifdef CONFIG_LEDS_CLASS |
| 1208 | if (fujitsu_hotkey->logolamp_registered != 0) |
| 1209 | led_classdev_unregister(&logolamp_led); |
| 1210 | |
| 1211 | if (fujitsu_hotkey->kblamps_registered != 0) |
| 1212 | led_classdev_unregister(&kblamps_led); |
| 1213 | #endif |
| 1214 | |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1215 | sysfs_remove_group(&fujitsu->pf_device->dev.kobj, |
| 1216 | &fujitsupf_attribute_group); |
| 1217 | platform_device_unregister(fujitsu->pf_device); |
| 1218 | platform_driver_unregister(&fujitsupf_driver); |
Thomas Renninger | 7d5c89a | 2008-08-01 17:38:00 +0200 | [diff] [blame] | 1219 | if (fujitsu->bl_device) |
| 1220 | backlight_device_unregister(fujitsu->bl_device); |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1221 | |
| 1222 | acpi_bus_unregister_driver(&acpi_fujitsu_driver); |
| 1223 | |
| 1224 | kfree(fujitsu); |
| 1225 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1226 | acpi_bus_unregister_driver(&acpi_fujitsu_hotkey_driver); |
| 1227 | |
| 1228 | kfree(fujitsu_hotkey); |
| 1229 | |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1230 | printk(KERN_INFO "fujitsu-laptop: driver unloaded.\n"); |
| 1231 | } |
| 1232 | |
| 1233 | module_init(fujitsu_init); |
| 1234 | module_exit(fujitsu_cleanup); |
| 1235 | |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1236 | module_param(use_alt_lcd_levels, uint, 0644); |
| 1237 | MODULE_PARM_DESC(use_alt_lcd_levels, |
| 1238 | "Use alternative interface for lcd_levels (needed for Lifebook s6410)."); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1239 | module_param(disable_brightness_adjust, uint, 0644); |
| 1240 | MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment ."); |
| 1241 | #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG |
| 1242 | module_param_named(debug, dbg_level, uint, 0644); |
| 1243 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
| 1244 | #endif |
| 1245 | |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 1246 | MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon"); |
Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1247 | MODULE_DESCRIPTION("Fujitsu laptop extras support"); |
| 1248 | MODULE_VERSION(FUJITSU_DRIVER_VERSION); |
| 1249 | MODULE_LICENSE("GPL"); |
Dan Williams | a361a82 | 2008-06-05 22:46:08 -0700 | [diff] [blame] | 1250 | |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 1251 | MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*"); |
Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 1252 | MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1E6:*:cvrS6420:*"); |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 1253 | MODULE_ALIAS("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*"); |
Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1254 | |
Dan Williams | a361a82 | 2008-06-05 22:46:08 -0700 | [diff] [blame] | 1255 | static struct pnp_device_id pnp_ids[] = { |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 1256 | {.id = "FUJ02bf"}, |
| 1257 | {.id = "FUJ02B1"}, |
| 1258 | {.id = "FUJ02E3"}, |
| 1259 | {.id = ""} |
Dan Williams | a361a82 | 2008-06-05 22:46:08 -0700 | [diff] [blame] | 1260 | }; |
Jonathan Woithe | 0e6a66e | 2008-10-09 13:44:40 +0930 | [diff] [blame] | 1261 | |
Dan Williams | a361a82 | 2008-06-05 22:46:08 -0700 | [diff] [blame] | 1262 | MODULE_DEVICE_TABLE(pnp, pnp_ids); |