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