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