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