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