| 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> |
| Michał Kępień | 819cdda | 2018-02-20 06:24:54 +0100 | [diff] [blame] | 56 | #include <linux/bitops.h> |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 57 | #include <linux/dmi.h> |
| 58 | #include <linux/backlight.h> |
| Michael Karcher | e8549e2 | 2015-01-18 20:28:46 +0100 | [diff] [blame] | 59 | #include <linux/fb.h> |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 60 | #include <linux/input.h> |
| Michał Kępień | f225267 | 2017-03-20 10:32:19 +0100 | [diff] [blame] | 61 | #include <linux/input/sparse-keymap.h> |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 62 | #include <linux/kfifo.h> |
| Michał Kępień | d89bcc8 | 2017-04-07 15:07:08 +0200 | [diff] [blame] | 63 | #include <linux/leds.h> |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 64 | #include <linux/platform_device.h> |
| Hans de Goede | 413226f | 2015-06-16 16:28:03 +0200 | [diff] [blame] | 65 | #include <acpi/video.h> |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 66 | |
| Michał Kępień | 819cdda | 2018-02-20 06:24:54 +0100 | [diff] [blame] | 67 | #define FUJITSU_DRIVER_VERSION "0.6.0" |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 68 | |
| Michał Kępień | 819cdda | 2018-02-20 06:24:54 +0100 | [diff] [blame] | 69 | #define FUJITSU_LCD_N_LEVELS 8 |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 70 | |
| Alan Jenkins | 9fc5cf6 | 2017-02-08 14:46:24 +0100 | [diff] [blame] | 71 | #define ACPI_FUJITSU_CLASS "fujitsu" |
| 72 | #define ACPI_FUJITSU_BL_HID "FUJ02B1" |
| 73 | #define ACPI_FUJITSU_BL_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver" |
| 74 | #define ACPI_FUJITSU_BL_DEVICE_NAME "Fujitsu FUJ02B1" |
| Alan Jenkins | 6942eab | 2017-02-08 14:46:25 +0100 | [diff] [blame] | 75 | #define ACPI_FUJITSU_LAPTOP_HID "FUJ02E3" |
| 76 | #define ACPI_FUJITSU_LAPTOP_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver" |
| 77 | #define ACPI_FUJITSU_LAPTOP_DEVICE_NAME "Fujitsu FUJ02E3" |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 78 | |
| Michał Kępień | 819cdda | 2018-02-20 06:24:54 +0100 | [diff] [blame] | 79 | #define ACPI_FUJITSU_NOTIFY_CODE 0x80 |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 80 | |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 81 | /* FUNC interface - command values */ |
| Michał Kępień | 819cdda | 2018-02-20 06:24:54 +0100 | [diff] [blame] | 82 | #define FUNC_FLAGS BIT(12) |
| 83 | #define FUNC_LEDS (BIT(12) | BIT(0)) |
| 84 | #define FUNC_BUTTONS (BIT(12) | BIT(1)) |
| 85 | #define FUNC_BACKLIGHT (BIT(12) | BIT(2)) |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 86 | |
| 87 | /* FUNC interface - responses */ |
| Michał Kępień | 502ab00 | 2018-03-10 21:43:53 +0100 | [diff] [blame] | 88 | #define UNSUPPORTED_CMD 0x80000000 |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 89 | |
| Alan Jenkins | d3dd448 | 2017-02-08 14:46:28 +0100 | [diff] [blame] | 90 | /* FUNC interface - status flags */ |
| Michał Kępień | 819cdda | 2018-02-20 06:24:54 +0100 | [diff] [blame] | 91 | #define FLAG_RFKILL BIT(5) |
| 92 | #define FLAG_LID BIT(8) |
| 93 | #define FLAG_DOCK BIT(9) |
| Alan Jenkins | d3dd448 | 2017-02-08 14:46:28 +0100 | [diff] [blame] | 94 | |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 95 | /* FUNC interface - LED control */ |
| Michał Kępień | 819cdda | 2018-02-20 06:24:54 +0100 | [diff] [blame] | 96 | #define FUNC_LED_OFF BIT(0) |
| 97 | #define FUNC_LED_ON (BIT(0) | BIT(16) | BIT(17)) |
| 98 | #define LOGOLAMP_POWERON BIT(13) |
| 99 | #define LOGOLAMP_ALWAYS BIT(14) |
| 100 | #define KEYBOARD_LAMPS BIT(8) |
| 101 | #define RADIO_LED_ON BIT(5) |
| 102 | #define ECO_LED BIT(16) |
| 103 | #define ECO_LED_ON BIT(19) |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 104 | |
| Michał Kępień | 2f60efa | 2018-02-20 06:24:53 +0100 | [diff] [blame] | 105 | /* FUNC interface - backlight power control */ |
| Michał Kępień | 819cdda | 2018-02-20 06:24:54 +0100 | [diff] [blame] | 106 | #define BACKLIGHT_PARAM_POWER BIT(2) |
| 107 | #define BACKLIGHT_OFF (BIT(0) | BIT(1)) |
| 108 | #define BACKLIGHT_ON 0 |
| Michał Kępień | 2f60efa | 2018-02-20 06:24:53 +0100 | [diff] [blame] | 109 | |
| Michał Kępień | 819cdda | 2018-02-20 06:24:54 +0100 | [diff] [blame] | 110 | /* Scancodes read from the GIRB register */ |
| 111 | #define KEY1_CODE 0x410 |
| 112 | #define KEY2_CODE 0x411 |
| 113 | #define KEY3_CODE 0x412 |
| 114 | #define KEY4_CODE 0x413 |
| 115 | #define KEY5_CODE 0x420 |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 116 | |
| Michał Kępień | 819cdda | 2018-02-20 06:24:54 +0100 | [diff] [blame] | 117 | /* Hotkey ringbuffer limits */ |
| 118 | #define MAX_HOTKEY_RINGBUFFER_SIZE 100 |
| 119 | #define RINGBUFFERSIZE 40 |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 120 | |
| Michał Kępień | 6cb1192 | 2018-02-11 22:07:24 +0100 | [diff] [blame] | 121 | /* Module parameters */ |
| 122 | static int use_alt_lcd_levels = -1; |
| 123 | static bool disable_brightness_adjust; |
| 124 | |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 125 | /* Device controlling the backlight and associated keys */ |
| Alan Jenkins | 9fc5cf6 | 2017-02-08 14:46:24 +0100 | [diff] [blame] | 126 | struct fujitsu_bl { |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 127 | struct input_dev *input; |
| 128 | char phys[32]; |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 129 | struct backlight_device *bl_device; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 130 | unsigned int max_brightness; |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 131 | unsigned int brightness_level; |
| 132 | }; |
| 133 | |
| Alan Jenkins | 9fc5cf6 | 2017-02-08 14:46:24 +0100 | [diff] [blame] | 134 | static struct fujitsu_bl *fujitsu_bl; |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 135 | |
| Alan Jenkins | 6942eab | 2017-02-08 14:46:25 +0100 | [diff] [blame] | 136 | /* Device used to access hotkeys and other features on the laptop */ |
| 137 | struct fujitsu_laptop { |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 138 | struct input_dev *input; |
| 139 | char phys[32]; |
| 140 | struct platform_device *pf_device; |
| Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 141 | struct kfifo fifo; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 142 | spinlock_t fifo_lock; |
| Alan Jenkins | 8ef27bd | 2017-02-08 14:46:27 +0100 | [diff] [blame] | 143 | int flags_supported; |
| 144 | int flags_state; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 145 | }; |
| 146 | |
| Michał Kępień | ca0d9ea | 2017-05-19 09:44:45 +0200 | [diff] [blame] | 147 | static struct acpi_device *fext; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 148 | |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 149 | /* Fujitsu ACPI interface function */ |
| 150 | |
| Michał Kępień | 84631e0 | 2017-05-19 09:44:46 +0200 | [diff] [blame] | 151 | static int call_fext_func(struct acpi_device *device, |
| 152 | int func, int op, int feature, int state) |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 153 | { |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 154 | union acpi_object params[4] = { |
| Michał Kępień | f68e492 | 2017-04-03 11:38:59 +0200 | [diff] [blame] | 155 | { .integer.type = ACPI_TYPE_INTEGER, .integer.value = func }, |
| 156 | { .integer.type = ACPI_TYPE_INTEGER, .integer.value = op }, |
| 157 | { .integer.type = ACPI_TYPE_INTEGER, .integer.value = feature }, |
| 158 | { .integer.type = ACPI_TYPE_INTEGER, .integer.value = state } |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 159 | }; |
| Michał Kępień | b106641 | 2017-04-03 11:38:57 +0200 | [diff] [blame] | 160 | struct acpi_object_list arg_list = { 4, params }; |
| Zhang Rui | 29c29a9 | 2013-09-03 08:32:12 +0800 | [diff] [blame] | 161 | unsigned long long value; |
| Michał Kępień | b106641 | 2017-04-03 11:38:57 +0200 | [diff] [blame] | 162 | acpi_status status; |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 163 | |
| Michał Kępień | 84631e0 | 2017-05-19 09:44:46 +0200 | [diff] [blame] | 164 | status = acpi_evaluate_integer(device->handle, "FUNC", &arg_list, |
| 165 | &value); |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 166 | if (ACPI_FAILURE(status)) { |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 167 | acpi_handle_err(device->handle, "Failed to evaluate FUNC\n"); |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 168 | return -ENODEV; |
| 169 | } |
| 170 | |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 171 | acpi_handle_debug(device->handle, |
| 172 | "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n", |
| 173 | func, op, feature, state, (int)value); |
| Zhang Rui | 29c29a9 | 2013-09-03 08:32:12 +0800 | [diff] [blame] | 174 | return value; |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 177 | /* Hardware access for LCD brightness control */ |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 178 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 179 | static int set_lcd_level(struct acpi_device *device, int level) |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 180 | { |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 181 | struct fujitsu_bl *priv = acpi_driver_data(device); |
| Michał Kępień | a8779c3 | 2017-04-05 08:49:03 +0200 | [diff] [blame] | 182 | acpi_status status; |
| Michał Kępień | e32c50b | 2017-04-05 08:49:02 +0200 | [diff] [blame] | 183 | char *method; |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 184 | |
| Michał Kępień | e32c50b | 2017-04-05 08:49:02 +0200 | [diff] [blame] | 185 | switch (use_alt_lcd_levels) { |
| Michał Kępień | e06e483 | 2017-04-05 08:49:05 +0200 | [diff] [blame] | 186 | case -1: |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 187 | if (acpi_has_method(device->handle, "SBL2")) |
| Michał Kępień | e06e483 | 2017-04-05 08:49:05 +0200 | [diff] [blame] | 188 | method = "SBL2"; |
| 189 | else |
| 190 | method = "SBLL"; |
| 191 | break; |
| Michał Kępień | e32c50b | 2017-04-05 08:49:02 +0200 | [diff] [blame] | 192 | case 1: |
| 193 | method = "SBL2"; |
| 194 | break; |
| 195 | default: |
| 196 | method = "SBLL"; |
| 197 | break; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 198 | } |
| 199 | |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 200 | acpi_handle_debug(device->handle, "set lcd level via %s [%d]\n", method, |
| 201 | level); |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 202 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 203 | if (level < 0 || level >= priv->max_brightness) |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 204 | return -EINVAL; |
| 205 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 206 | status = acpi_execute_simple_method(device->handle, method, level); |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 207 | if (ACPI_FAILURE(status)) { |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 208 | acpi_handle_err(device->handle, "Failed to evaluate %s\n", |
| 209 | method); |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 210 | return -ENODEV; |
| 211 | } |
| 212 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 213 | priv->brightness_level = level; |
| Michał Kępień | bd079a2 | 2017-04-05 08:49:04 +0200 | [diff] [blame] | 214 | |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 215 | return 0; |
| 216 | } |
| 217 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 218 | static int get_lcd_level(struct acpi_device *device) |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 219 | { |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 220 | struct fujitsu_bl *priv = acpi_driver_data(device); |
| Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 221 | unsigned long long state = 0; |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 222 | acpi_status status = AE_OK; |
| 223 | |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 224 | acpi_handle_debug(device->handle, "get lcd level via GBLL\n"); |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 225 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 226 | status = acpi_evaluate_integer(device->handle, "GBLL", NULL, &state); |
| Jonathan Woithe | 3b1c37c | 2009-12-23 09:19:42 +1030 | [diff] [blame] | 227 | if (ACPI_FAILURE(status)) |
| 228 | return 0; |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 229 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 230 | priv->brightness_level = state & 0x0fffffff; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 231 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 232 | return priv->brightness_level; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 233 | } |
| 234 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 235 | static int get_max_brightness(struct acpi_device *device) |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 236 | { |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 237 | struct fujitsu_bl *priv = acpi_driver_data(device); |
| Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 238 | unsigned long long state = 0; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 239 | acpi_status status = AE_OK; |
| 240 | |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 241 | acpi_handle_debug(device->handle, "get max lcd level via RBLL\n"); |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 242 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 243 | status = acpi_evaluate_integer(device->handle, "RBLL", NULL, &state); |
| Jonathan Woithe | 3b1c37c | 2009-12-23 09:19:42 +1030 | [diff] [blame] | 244 | if (ACPI_FAILURE(status)) |
| 245 | return -1; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 246 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 247 | priv->max_brightness = state; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 248 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 249 | return priv->max_brightness; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 250 | } |
| 251 | |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 252 | /* Backlight device stuff */ |
| 253 | |
| 254 | static int bl_get_brightness(struct backlight_device *b) |
| 255 | { |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 256 | struct acpi_device *device = bl_get_data(b); |
| 257 | |
| 258 | return b->props.power == FB_BLANK_POWERDOWN ? 0 : get_lcd_level(device); |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | static int bl_update_status(struct backlight_device *b) |
| 262 | { |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 263 | struct acpi_device *device = bl_get_data(b); |
| 264 | |
| Ville Syrjälä | cd6bf77 | 2017-09-18 23:00:59 +0300 | [diff] [blame] | 265 | if (fext) { |
| 266 | if (b->props.power == FB_BLANK_POWERDOWN) |
| Michał Kępień | 2f60efa | 2018-02-20 06:24:53 +0100 | [diff] [blame] | 267 | call_fext_func(fext, FUNC_BACKLIGHT, 0x1, |
| 268 | BACKLIGHT_PARAM_POWER, BACKLIGHT_OFF); |
| Ville Syrjälä | cd6bf77 | 2017-09-18 23:00:59 +0300 | [diff] [blame] | 269 | else |
| Michał Kępień | 2f60efa | 2018-02-20 06:24:53 +0100 | [diff] [blame] | 270 | call_fext_func(fext, FUNC_BACKLIGHT, 0x1, |
| 271 | BACKLIGHT_PARAM_POWER, BACKLIGHT_ON); |
| Ville Syrjälä | cd6bf77 | 2017-09-18 23:00:59 +0300 | [diff] [blame] | 272 | } |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 273 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 274 | return set_lcd_level(device, b->props.brightness); |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 275 | } |
| 276 | |
| Alan Jenkins | 9fc5cf6 | 2017-02-08 14:46:24 +0100 | [diff] [blame] | 277 | static const struct backlight_ops fujitsu_bl_ops = { |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 278 | .get_brightness = bl_get_brightness, |
| 279 | .update_status = bl_update_status, |
| 280 | }; |
| 281 | |
| Michał Kępień | b0c4b9c | 2017-03-14 11:26:28 +0100 | [diff] [blame] | 282 | static ssize_t lid_show(struct device *dev, struct device_attribute *attr, |
| 283 | char *buf) |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 284 | { |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 285 | struct fujitsu_laptop *priv = dev_get_drvdata(dev); |
| 286 | |
| 287 | if (!(priv->flags_supported & FLAG_LID)) |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 288 | return sprintf(buf, "unknown\n"); |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 289 | if (priv->flags_state & FLAG_LID) |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 290 | return sprintf(buf, "open\n"); |
| 291 | else |
| 292 | return sprintf(buf, "closed\n"); |
| 293 | } |
| 294 | |
| Michał Kępień | b0c4b9c | 2017-03-14 11:26:28 +0100 | [diff] [blame] | 295 | static ssize_t dock_show(struct device *dev, struct device_attribute *attr, |
| 296 | char *buf) |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 297 | { |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 298 | struct fujitsu_laptop *priv = dev_get_drvdata(dev); |
| 299 | |
| 300 | if (!(priv->flags_supported & FLAG_DOCK)) |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 301 | return sprintf(buf, "unknown\n"); |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 302 | if (priv->flags_state & FLAG_DOCK) |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 303 | return sprintf(buf, "docked\n"); |
| 304 | else |
| 305 | return sprintf(buf, "undocked\n"); |
| 306 | } |
| 307 | |
| Michał Kępień | b0c4b9c | 2017-03-14 11:26:28 +0100 | [diff] [blame] | 308 | static ssize_t radios_show(struct device *dev, struct device_attribute *attr, |
| 309 | char *buf) |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 310 | { |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 311 | struct fujitsu_laptop *priv = dev_get_drvdata(dev); |
| 312 | |
| 313 | if (!(priv->flags_supported & FLAG_RFKILL)) |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 314 | return sprintf(buf, "unknown\n"); |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 315 | if (priv->flags_state & FLAG_RFKILL) |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 316 | return sprintf(buf, "on\n"); |
| 317 | else |
| 318 | return sprintf(buf, "killed\n"); |
| 319 | } |
| 320 | |
| Michał Kępień | b0c4b9c | 2017-03-14 11:26:28 +0100 | [diff] [blame] | 321 | static DEVICE_ATTR_RO(lid); |
| 322 | static DEVICE_ATTR_RO(dock); |
| 323 | static DEVICE_ATTR_RO(radios); |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 324 | |
| Alan Jenkins | 1650602 | 2017-02-08 14:46:26 +0100 | [diff] [blame] | 325 | static struct attribute *fujitsu_pf_attributes[] = { |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 326 | &dev_attr_lid.attr, |
| 327 | &dev_attr_dock.attr, |
| 328 | &dev_attr_radios.attr, |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 329 | NULL |
| 330 | }; |
| 331 | |
| Arvind Yadav | ee56ff7 | 2017-07-11 16:18:14 +0530 | [diff] [blame] | 332 | static const struct attribute_group fujitsu_pf_attribute_group = { |
| Alan Jenkins | 1650602 | 2017-02-08 14:46:26 +0100 | [diff] [blame] | 333 | .attrs = fujitsu_pf_attributes |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 334 | }; |
| 335 | |
| Alan Jenkins | 1650602 | 2017-02-08 14:46:26 +0100 | [diff] [blame] | 336 | static struct platform_driver fujitsu_pf_driver = { |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 337 | .driver = { |
| 338 | .name = "fujitsu-laptop", |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 339 | } |
| 340 | }; |
| 341 | |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 342 | /* ACPI device for LCD brightness control */ |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 343 | |
| Michał Kępień | f225267 | 2017-03-20 10:32:19 +0100 | [diff] [blame] | 344 | static const struct key_entry keymap_backlight[] = { |
| 345 | { KE_KEY, true, { KEY_BRIGHTNESSUP } }, |
| 346 | { KE_KEY, false, { KEY_BRIGHTNESSDOWN } }, |
| 347 | { KE_END, 0 } |
| 348 | }; |
| 349 | |
| Michał Kępień | 7d134e4 | 2017-03-20 10:32:17 +0100 | [diff] [blame] | 350 | static int acpi_fujitsu_bl_input_setup(struct acpi_device *device) |
| 351 | { |
| Michał Kępień | 7ec3b54 | 2017-05-19 09:44:41 +0200 | [diff] [blame] | 352 | struct fujitsu_bl *priv = acpi_driver_data(device); |
| Michał Kępień | f225267 | 2017-03-20 10:32:19 +0100 | [diff] [blame] | 353 | int ret; |
| Michał Kępień | 7d134e4 | 2017-03-20 10:32:17 +0100 | [diff] [blame] | 354 | |
| Michał Kępień | 7ec3b54 | 2017-05-19 09:44:41 +0200 | [diff] [blame] | 355 | priv->input = devm_input_allocate_device(&device->dev); |
| 356 | if (!priv->input) |
| Michał Kępień | 7d134e4 | 2017-03-20 10:32:17 +0100 | [diff] [blame] | 357 | return -ENOMEM; |
| 358 | |
| Michał Kępień | 7ec3b54 | 2017-05-19 09:44:41 +0200 | [diff] [blame] | 359 | snprintf(priv->phys, sizeof(priv->phys), "%s/video/input0", |
| 360 | acpi_device_hid(device)); |
| Michał Kępień | 7d134e4 | 2017-03-20 10:32:17 +0100 | [diff] [blame] | 361 | |
| Michał Kępień | 7ec3b54 | 2017-05-19 09:44:41 +0200 | [diff] [blame] | 362 | priv->input->name = acpi_device_name(device); |
| 363 | priv->input->phys = priv->phys; |
| 364 | priv->input->id.bustype = BUS_HOST; |
| 365 | priv->input->id.product = 0x06; |
| Michał Kępień | f225267 | 2017-03-20 10:32:19 +0100 | [diff] [blame] | 366 | |
| Michał Kępień | 7ec3b54 | 2017-05-19 09:44:41 +0200 | [diff] [blame] | 367 | ret = sparse_keymap_setup(priv->input, keymap_backlight, NULL); |
| Michał Kępień | f225267 | 2017-03-20 10:32:19 +0100 | [diff] [blame] | 368 | if (ret) |
| 369 | return ret; |
| Michał Kępień | 7d134e4 | 2017-03-20 10:32:17 +0100 | [diff] [blame] | 370 | |
| Michał Kępień | 7ec3b54 | 2017-05-19 09:44:41 +0200 | [diff] [blame] | 371 | return input_register_device(priv->input); |
| Michał Kępień | 7d134e4 | 2017-03-20 10:32:17 +0100 | [diff] [blame] | 372 | } |
| 373 | |
| Michał Kępień | a1aabd5 | 2017-04-05 08:49:01 +0200 | [diff] [blame] | 374 | static int fujitsu_backlight_register(struct acpi_device *device) |
| Michał Kępień | b8d69c1 | 2017-03-10 11:50:33 +0100 | [diff] [blame] | 375 | { |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 376 | struct fujitsu_bl *priv = acpi_driver_data(device); |
| Michał Kępień | a1aabd5 | 2017-04-05 08:49:01 +0200 | [diff] [blame] | 377 | const struct backlight_properties props = { |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 378 | .brightness = priv->brightness_level, |
| 379 | .max_brightness = priv->max_brightness - 1, |
| Michał Kępień | b8d69c1 | 2017-03-10 11:50:33 +0100 | [diff] [blame] | 380 | .type = BACKLIGHT_PLATFORM |
| 381 | }; |
| 382 | struct backlight_device *bd; |
| 383 | |
| Michał Kępień | a1aabd5 | 2017-04-05 08:49:01 +0200 | [diff] [blame] | 384 | bd = devm_backlight_device_register(&device->dev, "fujitsu-laptop", |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 385 | &device->dev, device, |
| Michał Kępień | a1aabd5 | 2017-04-05 08:49:01 +0200 | [diff] [blame] | 386 | &fujitsu_bl_ops, &props); |
| Michał Kępień | b8d69c1 | 2017-03-10 11:50:33 +0100 | [diff] [blame] | 387 | if (IS_ERR(bd)) |
| 388 | return PTR_ERR(bd); |
| 389 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 390 | priv->bl_device = bd; |
| Michał Kępień | b8d69c1 | 2017-03-10 11:50:33 +0100 | [diff] [blame] | 391 | |
| 392 | return 0; |
| 393 | } |
| 394 | |
| Alan Jenkins | 9fc5cf6 | 2017-02-08 14:46:24 +0100 | [diff] [blame] | 395 | static int acpi_fujitsu_bl_add(struct acpi_device *device) |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 396 | { |
| Michał Kępień | 679374e | 2017-05-19 09:44:42 +0200 | [diff] [blame] | 397 | struct fujitsu_bl *priv; |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 398 | int ret; |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 399 | |
| Michał Kępień | 07acf62 | 2017-04-05 08:49:00 +0200 | [diff] [blame] | 400 | if (acpi_video_get_backlight_type() != acpi_backlight_vendor) |
| 401 | return -ENODEV; |
| 402 | |
| Michał Kępień | 679374e | 2017-05-19 09:44:42 +0200 | [diff] [blame] | 403 | priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL); |
| 404 | if (!priv) |
| 405 | return -ENOMEM; |
| 406 | |
| 407 | fujitsu_bl = priv; |
| Michał Kępień | d6a298a | 2017-06-16 06:40:54 +0200 | [diff] [blame] | 408 | strcpy(acpi_device_name(device), ACPI_FUJITSU_BL_DEVICE_NAME); |
| 409 | strcpy(acpi_device_class(device), ACPI_FUJITSU_CLASS); |
| Michał Kępień | 679374e | 2017-05-19 09:44:42 +0200 | [diff] [blame] | 410 | device->driver_data = priv; |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 411 | |
| Michał Kępień | 1c19462 | 2017-06-16 06:40:56 +0200 | [diff] [blame] | 412 | pr_info("ACPI: %s [%s]\n", |
| 413 | acpi_device_name(device), acpi_device_bid(device)); |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 414 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 415 | if (get_max_brightness(device) <= 0) |
| 416 | priv->max_brightness = FUJITSU_LCD_N_LEVELS; |
| 417 | get_lcd_level(device); |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 418 | |
| Michał Kępień | a7a1ccbe | 2018-02-11 22:07:22 +0100 | [diff] [blame] | 419 | ret = acpi_fujitsu_bl_input_setup(device); |
| 420 | if (ret) |
| 421 | return ret; |
| 422 | |
| Michał Kępień | 7f83d41 | 2018-02-11 22:07:23 +0100 | [diff] [blame] | 423 | return fujitsu_backlight_register(device); |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 424 | } |
| 425 | |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 426 | /* Brightness notify */ |
| 427 | |
| Alan Jenkins | 9fc5cf6 | 2017-02-08 14:46:24 +0100 | [diff] [blame] | 428 | static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event) |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 429 | { |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 430 | struct fujitsu_bl *priv = acpi_driver_data(device); |
| Michał Kępień | f225267 | 2017-03-20 10:32:19 +0100 | [diff] [blame] | 431 | int oldb, newb; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 432 | |
| Michał Kępień | 819cdda | 2018-02-20 06:24:54 +0100 | [diff] [blame] | 433 | if (event != ACPI_FUJITSU_NOTIFY_CODE) { |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 434 | acpi_handle_info(device->handle, "unsupported event [0x%x]\n", |
| 435 | event); |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 436 | sparse_keymap_report_event(priv->input, -1, 1, true); |
| Michał Kępień | 5efc800 | 2017-03-01 07:42:53 +0100 | [diff] [blame] | 437 | return; |
| 438 | } |
| 439 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 440 | oldb = priv->brightness_level; |
| 441 | get_lcd_level(device); |
| 442 | newb = priv->brightness_level; |
| Michał Kępień | 5efc800 | 2017-03-01 07:42:53 +0100 | [diff] [blame] | 443 | |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 444 | acpi_handle_debug(device->handle, |
| 445 | "brightness button event [%i -> %i]\n", oldb, newb); |
| Michał Kępień | 5efc800 | 2017-03-01 07:42:53 +0100 | [diff] [blame] | 446 | |
| Michał Kępień | d2aa3ae | 2017-03-01 07:42:54 +0100 | [diff] [blame] | 447 | if (oldb == newb) |
| 448 | return; |
| 449 | |
| Michał Kępień | b4bb0cf | 2017-04-05 08:49:06 +0200 | [diff] [blame] | 450 | if (!disable_brightness_adjust) |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 451 | set_lcd_level(device, newb); |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 452 | |
| Michał Kępień | f2db7c6 | 2017-05-19 09:44:43 +0200 | [diff] [blame] | 453 | sparse_keymap_report_event(priv->input, oldb < newb, 1, true); |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /* ACPI device for hotkey handling */ |
| 457 | |
| Michał Kępień | 527483a | 2017-03-20 10:32:22 +0100 | [diff] [blame] | 458 | static const struct key_entry keymap_default[] = { |
| 459 | { KE_KEY, KEY1_CODE, { KEY_PROG1 } }, |
| 460 | { KE_KEY, KEY2_CODE, { KEY_PROG2 } }, |
| 461 | { KE_KEY, KEY3_CODE, { KEY_PROG3 } }, |
| 462 | { KE_KEY, KEY4_CODE, { KEY_PROG4 } }, |
| 463 | { KE_KEY, KEY5_CODE, { KEY_RFKILL } }, |
| Jan-Marek Glogowski | 797195a | 2018-02-12 13:08:51 +0100 | [diff] [blame^] | 464 | { KE_KEY, BIT(5), { KEY_RFKILL } }, |
| Michał Kępień | 527483a | 2017-03-20 10:32:22 +0100 | [diff] [blame] | 465 | { KE_KEY, BIT(26), { KEY_TOUCHPAD_TOGGLE } }, |
| Jan-Marek Glogowski | 797195a | 2018-02-12 13:08:51 +0100 | [diff] [blame^] | 466 | { KE_KEY, BIT(29), { KEY_MICMUTE } }, |
| Michał Kępień | 527483a | 2017-03-20 10:32:22 +0100 | [diff] [blame] | 467 | { KE_END, 0 } |
| 468 | }; |
| 469 | |
| Michał Kępień | f8c94ec | 2017-03-20 10:32:23 +0100 | [diff] [blame] | 470 | static const struct key_entry keymap_s64x0[] = { |
| 471 | { KE_KEY, KEY1_CODE, { KEY_SCREENLOCK } }, /* "Lock" */ |
| 472 | { KE_KEY, KEY2_CODE, { KEY_HELP } }, /* "Mobility Center */ |
| 473 | { KE_KEY, KEY3_CODE, { KEY_PROG3 } }, |
| 474 | { KE_KEY, KEY4_CODE, { KEY_PROG4 } }, |
| 475 | { KE_END, 0 } |
| 476 | }; |
| 477 | |
| 478 | static const struct key_entry keymap_p8010[] = { |
| 479 | { KE_KEY, KEY1_CODE, { KEY_HELP } }, /* "Support" */ |
| 480 | { KE_KEY, KEY2_CODE, { KEY_PROG2 } }, |
| 481 | { KE_KEY, KEY3_CODE, { KEY_SWITCHVIDEOMODE } }, /* "Presentation" */ |
| 482 | { KE_KEY, KEY4_CODE, { KEY_WWW } }, /* "WWW" */ |
| 483 | { KE_END, 0 } |
| 484 | }; |
| 485 | |
| Michał Kępień | 527483a | 2017-03-20 10:32:22 +0100 | [diff] [blame] | 486 | static const struct key_entry *keymap = keymap_default; |
| 487 | |
| Michał Kępień | f8c94ec | 2017-03-20 10:32:23 +0100 | [diff] [blame] | 488 | static int fujitsu_laptop_dmi_keymap_override(const struct dmi_system_id *id) |
| 489 | { |
| 490 | pr_info("Identified laptop model '%s'\n", id->ident); |
| 491 | keymap = id->driver_data; |
| 492 | return 1; |
| 493 | } |
| 494 | |
| 495 | static const struct dmi_system_id fujitsu_laptop_dmi_table[] = { |
| 496 | { |
| 497 | .callback = fujitsu_laptop_dmi_keymap_override, |
| 498 | .ident = "Fujitsu Siemens S6410", |
| 499 | .matches = { |
| 500 | DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), |
| 501 | DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"), |
| 502 | }, |
| 503 | .driver_data = (void *)keymap_s64x0 |
| 504 | }, |
| 505 | { |
| 506 | .callback = fujitsu_laptop_dmi_keymap_override, |
| 507 | .ident = "Fujitsu Siemens S6420", |
| 508 | .matches = { |
| 509 | DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), |
| 510 | DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"), |
| 511 | }, |
| 512 | .driver_data = (void *)keymap_s64x0 |
| 513 | }, |
| 514 | { |
| 515 | .callback = fujitsu_laptop_dmi_keymap_override, |
| 516 | .ident = "Fujitsu LifeBook P8010", |
| 517 | .matches = { |
| 518 | DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"), |
| 519 | DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"), |
| 520 | }, |
| 521 | .driver_data = (void *)keymap_p8010 |
| 522 | }, |
| 523 | {} |
| 524 | }; |
| 525 | |
| Michał Kępień | 11182db | 2017-03-20 10:32:20 +0100 | [diff] [blame] | 526 | static int acpi_fujitsu_laptop_input_setup(struct acpi_device *device) |
| 527 | { |
| Michał Kępień | 7ec3b54 | 2017-05-19 09:44:41 +0200 | [diff] [blame] | 528 | struct fujitsu_laptop *priv = acpi_driver_data(device); |
| Michał Kępień | 527483a | 2017-03-20 10:32:22 +0100 | [diff] [blame] | 529 | int ret; |
| Michał Kępień | 11182db | 2017-03-20 10:32:20 +0100 | [diff] [blame] | 530 | |
| Michał Kępień | 7ec3b54 | 2017-05-19 09:44:41 +0200 | [diff] [blame] | 531 | priv->input = devm_input_allocate_device(&device->dev); |
| 532 | if (!priv->input) |
| Michał Kępień | 11182db | 2017-03-20 10:32:20 +0100 | [diff] [blame] | 533 | return -ENOMEM; |
| 534 | |
| Michał Kępień | c1f51f1 | 2017-06-16 06:40:55 +0200 | [diff] [blame] | 535 | snprintf(priv->phys, sizeof(priv->phys), "%s/input0", |
| Michał Kępień | 7ec3b54 | 2017-05-19 09:44:41 +0200 | [diff] [blame] | 536 | acpi_device_hid(device)); |
| Michał Kępień | 11182db | 2017-03-20 10:32:20 +0100 | [diff] [blame] | 537 | |
| Michał Kępień | 7ec3b54 | 2017-05-19 09:44:41 +0200 | [diff] [blame] | 538 | priv->input->name = acpi_device_name(device); |
| 539 | priv->input->phys = priv->phys; |
| 540 | priv->input->id.bustype = BUS_HOST; |
| Michał Kępień | 11182db | 2017-03-20 10:32:20 +0100 | [diff] [blame] | 541 | |
| Michał Kępień | f8c94ec | 2017-03-20 10:32:23 +0100 | [diff] [blame] | 542 | dmi_check_system(fujitsu_laptop_dmi_table); |
| Michał Kępień | 7ec3b54 | 2017-05-19 09:44:41 +0200 | [diff] [blame] | 543 | ret = sparse_keymap_setup(priv->input, keymap, NULL); |
| Michał Kępień | 527483a | 2017-03-20 10:32:22 +0100 | [diff] [blame] | 544 | if (ret) |
| 545 | return ret; |
| Michał Kępień | 11182db | 2017-03-20 10:32:20 +0100 | [diff] [blame] | 546 | |
| Michał Kępień | 7ec3b54 | 2017-05-19 09:44:41 +0200 | [diff] [blame] | 547 | return input_register_device(priv->input); |
| Michał Kępień | 11182db | 2017-03-20 10:32:20 +0100 | [diff] [blame] | 548 | } |
| 549 | |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 550 | static int fujitsu_laptop_platform_add(struct acpi_device *device) |
| Michał Kępień | d811b51 | 2017-03-14 11:26:29 +0100 | [diff] [blame] | 551 | { |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 552 | struct fujitsu_laptop *priv = acpi_driver_data(device); |
| Michał Kępień | d811b51 | 2017-03-14 11:26:29 +0100 | [diff] [blame] | 553 | int ret; |
| 554 | |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 555 | priv->pf_device = platform_device_alloc("fujitsu-laptop", -1); |
| 556 | if (!priv->pf_device) |
| Michał Kępień | d811b51 | 2017-03-14 11:26:29 +0100 | [diff] [blame] | 557 | return -ENOMEM; |
| 558 | |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 559 | platform_set_drvdata(priv->pf_device, priv); |
| 560 | |
| 561 | ret = platform_device_add(priv->pf_device); |
| Michał Kępień | d811b51 | 2017-03-14 11:26:29 +0100 | [diff] [blame] | 562 | if (ret) |
| 563 | goto err_put_platform_device; |
| 564 | |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 565 | ret = sysfs_create_group(&priv->pf_device->dev.kobj, |
| Michał Kępień | d811b51 | 2017-03-14 11:26:29 +0100 | [diff] [blame] | 566 | &fujitsu_pf_attribute_group); |
| 567 | if (ret) |
| 568 | goto err_del_platform_device; |
| 569 | |
| 570 | return 0; |
| 571 | |
| 572 | err_del_platform_device: |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 573 | platform_device_del(priv->pf_device); |
| Michał Kępień | d811b51 | 2017-03-14 11:26:29 +0100 | [diff] [blame] | 574 | err_put_platform_device: |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 575 | platform_device_put(priv->pf_device); |
| Michał Kępień | d811b51 | 2017-03-14 11:26:29 +0100 | [diff] [blame] | 576 | |
| 577 | return ret; |
| 578 | } |
| 579 | |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 580 | static void fujitsu_laptop_platform_remove(struct acpi_device *device) |
| Michał Kępień | d811b51 | 2017-03-14 11:26:29 +0100 | [diff] [blame] | 581 | { |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 582 | struct fujitsu_laptop *priv = acpi_driver_data(device); |
| 583 | |
| 584 | sysfs_remove_group(&priv->pf_device->dev.kobj, |
| Michał Kępień | d811b51 | 2017-03-14 11:26:29 +0100 | [diff] [blame] | 585 | &fujitsu_pf_attribute_group); |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 586 | platform_device_unregister(priv->pf_device); |
| Michał Kępień | d811b51 | 2017-03-14 11:26:29 +0100 | [diff] [blame] | 587 | } |
| 588 | |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 589 | static int logolamp_set(struct led_classdev *cdev, |
| 590 | enum led_brightness brightness) |
| 591 | { |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 592 | struct acpi_device *device = to_acpi_device(cdev->dev->parent); |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 593 | int poweron = FUNC_LED_ON, always = FUNC_LED_ON; |
| 594 | int ret; |
| 595 | |
| 596 | if (brightness < LED_HALF) |
| 597 | poweron = FUNC_LED_OFF; |
| 598 | |
| 599 | if (brightness < LED_FULL) |
| 600 | always = FUNC_LED_OFF; |
| 601 | |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 602 | ret = call_fext_func(device, FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron); |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 603 | if (ret < 0) |
| 604 | return ret; |
| 605 | |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 606 | return call_fext_func(device, FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always); |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | static enum led_brightness logolamp_get(struct led_classdev *cdev) |
| 610 | { |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 611 | struct acpi_device *device = to_acpi_device(cdev->dev->parent); |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 612 | int ret; |
| 613 | |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 614 | ret = call_fext_func(device, FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0); |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 615 | if (ret == FUNC_LED_ON) |
| 616 | return LED_FULL; |
| 617 | |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 618 | ret = call_fext_func(device, FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0); |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 619 | if (ret == FUNC_LED_ON) |
| 620 | return LED_HALF; |
| 621 | |
| 622 | return LED_OFF; |
| 623 | } |
| 624 | |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 625 | static int kblamps_set(struct led_classdev *cdev, |
| 626 | enum led_brightness brightness) |
| 627 | { |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 628 | struct acpi_device *device = to_acpi_device(cdev->dev->parent); |
| 629 | |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 630 | if (brightness >= LED_FULL) |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 631 | return call_fext_func(device, FUNC_LEDS, 0x1, KEYBOARD_LAMPS, |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 632 | FUNC_LED_ON); |
| 633 | else |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 634 | return call_fext_func(device, FUNC_LEDS, 0x1, KEYBOARD_LAMPS, |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 635 | FUNC_LED_OFF); |
| 636 | } |
| 637 | |
| 638 | static enum led_brightness kblamps_get(struct led_classdev *cdev) |
| 639 | { |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 640 | struct acpi_device *device = to_acpi_device(cdev->dev->parent); |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 641 | enum led_brightness brightness = LED_OFF; |
| 642 | |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 643 | if (call_fext_func(device, |
| Michał Kępień | 84631e0 | 2017-05-19 09:44:46 +0200 | [diff] [blame] | 644 | FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON) |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 645 | brightness = LED_FULL; |
| 646 | |
| 647 | return brightness; |
| 648 | } |
| 649 | |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 650 | static int radio_led_set(struct led_classdev *cdev, |
| 651 | enum led_brightness brightness) |
| 652 | { |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 653 | struct acpi_device *device = to_acpi_device(cdev->dev->parent); |
| 654 | |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 655 | if (brightness >= LED_FULL) |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 656 | return call_fext_func(device, FUNC_FLAGS, 0x5, RADIO_LED_ON, |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 657 | RADIO_LED_ON); |
| 658 | else |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 659 | return call_fext_func(device, FUNC_FLAGS, 0x5, RADIO_LED_ON, |
| Michał Kępień | 84631e0 | 2017-05-19 09:44:46 +0200 | [diff] [blame] | 660 | 0x0); |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | static enum led_brightness radio_led_get(struct led_classdev *cdev) |
| 664 | { |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 665 | struct acpi_device *device = to_acpi_device(cdev->dev->parent); |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 666 | enum led_brightness brightness = LED_OFF; |
| 667 | |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 668 | if (call_fext_func(device, FUNC_FLAGS, 0x4, 0x0, 0x0) & RADIO_LED_ON) |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 669 | brightness = LED_FULL; |
| 670 | |
| 671 | return brightness; |
| 672 | } |
| 673 | |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 674 | static int eco_led_set(struct led_classdev *cdev, |
| 675 | enum led_brightness brightness) |
| 676 | { |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 677 | struct acpi_device *device = to_acpi_device(cdev->dev->parent); |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 678 | int curr; |
| 679 | |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 680 | curr = call_fext_func(device, FUNC_LEDS, 0x2, ECO_LED, 0x0); |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 681 | if (brightness >= LED_FULL) |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 682 | return call_fext_func(device, FUNC_LEDS, 0x1, ECO_LED, |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 683 | curr | ECO_LED_ON); |
| 684 | else |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 685 | return call_fext_func(device, FUNC_LEDS, 0x1, ECO_LED, |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 686 | curr & ~ECO_LED_ON); |
| 687 | } |
| 688 | |
| 689 | static enum led_brightness eco_led_get(struct led_classdev *cdev) |
| 690 | { |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 691 | struct acpi_device *device = to_acpi_device(cdev->dev->parent); |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 692 | enum led_brightness brightness = LED_OFF; |
| 693 | |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 694 | if (call_fext_func(device, FUNC_LEDS, 0x2, ECO_LED, 0x0) & ECO_LED_ON) |
| Michał Kępień | e33ca45 | 2017-04-07 15:07:10 +0200 | [diff] [blame] | 695 | brightness = LED_FULL; |
| 696 | |
| 697 | return brightness; |
| 698 | } |
| 699 | |
| Michał Kępień | 81f6821 | 2017-04-07 15:07:11 +0200 | [diff] [blame] | 700 | static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device) |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 701 | { |
| Michał Kępień | c7b3e98 | 2017-10-25 06:29:46 +0200 | [diff] [blame] | 702 | struct fujitsu_laptop *priv = acpi_driver_data(device); |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 703 | struct led_classdev *led; |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 704 | int ret; |
| Michał Kępień | 7adb7b1 | 2017-04-07 15:07:09 +0200 | [diff] [blame] | 705 | |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 706 | if (call_fext_func(device, |
| Michał Kępień | 84631e0 | 2017-05-19 09:44:46 +0200 | [diff] [blame] | 707 | FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) { |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 708 | led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL); |
| Gustavo A. R. Silva | b77a537 | 2017-07-06 17:19:02 -0500 | [diff] [blame] | 709 | if (!led) |
| 710 | return -ENOMEM; |
| 711 | |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 712 | led->name = "fujitsu::logolamp"; |
| 713 | led->brightness_set_blocking = logolamp_set; |
| 714 | led->brightness_get = logolamp_get; |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 715 | ret = devm_led_classdev_register(&device->dev, led); |
| 716 | if (ret) |
| 717 | return ret; |
| Michał Kępień | 7adb7b1 | 2017-04-07 15:07:09 +0200 | [diff] [blame] | 718 | } |
| 719 | |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 720 | if ((call_fext_func(device, |
| Michał Kępień | 84631e0 | 2017-05-19 09:44:46 +0200 | [diff] [blame] | 721 | FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) && |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 722 | (call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) { |
| 723 | led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL); |
| Gustavo A. R. Silva | b77a537 | 2017-07-06 17:19:02 -0500 | [diff] [blame] | 724 | if (!led) |
| 725 | return -ENOMEM; |
| 726 | |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 727 | led->name = "fujitsu::kblamps"; |
| 728 | led->brightness_set_blocking = kblamps_set; |
| 729 | led->brightness_get = kblamps_get; |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 730 | ret = devm_led_classdev_register(&device->dev, led); |
| 731 | if (ret) |
| 732 | return ret; |
| Michał Kępień | 7adb7b1 | 2017-04-07 15:07:09 +0200 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | /* |
| Michał Kępień | c7b3e98 | 2017-10-25 06:29:46 +0200 | [diff] [blame] | 736 | * Some Fujitsu laptops have a radio toggle button in place of a slide |
| 737 | * switch and all such machines appear to also have an RF LED. Based on |
| 738 | * comparing DSDT tables of four Fujitsu Lifebook models (E744, E751, |
| 739 | * S7110, S8420; the first one has a radio toggle button, the other |
| 740 | * three have slide switches), bit 17 of flags_supported (the value |
| 741 | * returned by method S000 of ACPI device FUJ02E3) seems to indicate |
| 742 | * whether given model has a radio toggle button. |
| Michał Kępień | 7adb7b1 | 2017-04-07 15:07:09 +0200 | [diff] [blame] | 743 | */ |
| Michał Kępień | c7b3e98 | 2017-10-25 06:29:46 +0200 | [diff] [blame] | 744 | if (priv->flags_supported & BIT(17)) { |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 745 | led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL); |
| Gustavo A. R. Silva | b77a537 | 2017-07-06 17:19:02 -0500 | [diff] [blame] | 746 | if (!led) |
| 747 | return -ENOMEM; |
| 748 | |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 749 | led->name = "fujitsu::radio_led"; |
| 750 | led->brightness_set_blocking = radio_led_set; |
| 751 | led->brightness_get = radio_led_get; |
| 752 | led->default_trigger = "rfkill-any"; |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 753 | ret = devm_led_classdev_register(&device->dev, led); |
| 754 | if (ret) |
| 755 | return ret; |
| Michał Kępień | 7adb7b1 | 2017-04-07 15:07:09 +0200 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | /* Support for eco led is not always signaled in bit corresponding |
| 759 | * to the bit used to control the led. According to the DSDT table, |
| 760 | * bit 14 seems to indicate presence of said led as well. |
| 761 | * Confirm by testing the status. |
| 762 | */ |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 763 | if ((call_fext_func(device, FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) && |
| 764 | (call_fext_func(device, |
| Michał Kępień | 84631e0 | 2017-05-19 09:44:46 +0200 | [diff] [blame] | 765 | FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) { |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 766 | led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL); |
| Gustavo A. R. Silva | b77a537 | 2017-07-06 17:19:02 -0500 | [diff] [blame] | 767 | if (!led) |
| 768 | return -ENOMEM; |
| 769 | |
| Michał Kępień | a823f8e | 2017-05-19 09:44:47 +0200 | [diff] [blame] | 770 | led->name = "fujitsu::eco_led"; |
| 771 | led->brightness_set_blocking = eco_led_set; |
| 772 | led->brightness_get = eco_led_get; |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 773 | ret = devm_led_classdev_register(&device->dev, led); |
| 774 | if (ret) |
| 775 | return ret; |
| Michał Kępień | 7adb7b1 | 2017-04-07 15:07:09 +0200 | [diff] [blame] | 776 | } |
| 777 | |
| Michał Kępień | 30943e1 | 2017-04-07 15:07:12 +0200 | [diff] [blame] | 778 | return 0; |
| Michał Kępień | 7adb7b1 | 2017-04-07 15:07:09 +0200 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | static int acpi_fujitsu_laptop_add(struct acpi_device *device) |
| 782 | { |
| Michał Kępień | a4b176e | 2017-05-19 09:44:44 +0200 | [diff] [blame] | 783 | struct fujitsu_laptop *priv; |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 784 | int ret, i = 0; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 785 | |
| Michał Kępień | a4b176e | 2017-05-19 09:44:44 +0200 | [diff] [blame] | 786 | priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL); |
| 787 | if (!priv) |
| 788 | return -ENOMEM; |
| 789 | |
| Michał Kępień | ca0d9ea | 2017-05-19 09:44:45 +0200 | [diff] [blame] | 790 | WARN_ONCE(fext, "More than one FUJ02E3 ACPI device was found. Driver may not work as intended."); |
| 791 | fext = device; |
| 792 | |
| Michał Kępień | d6a298a | 2017-06-16 06:40:54 +0200 | [diff] [blame] | 793 | strcpy(acpi_device_name(device), ACPI_FUJITSU_LAPTOP_DEVICE_NAME); |
| 794 | strcpy(acpi_device_class(device), ACPI_FUJITSU_CLASS); |
| Michał Kępień | a4b176e | 2017-05-19 09:44:44 +0200 | [diff] [blame] | 795 | device->driver_data = priv; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 796 | |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 797 | /* kfifo */ |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 798 | spin_lock_init(&priv->fifo_lock); |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 799 | ret = kfifo_alloc(&priv->fifo, RINGBUFFERSIZE * sizeof(int), |
| 800 | GFP_KERNEL); |
| Michał Kępień | 7f83d41 | 2018-02-11 22:07:23 +0100 | [diff] [blame] | 801 | if (ret) |
| 802 | return ret; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 803 | |
| Michał Kępień | 1c19462 | 2017-06-16 06:40:56 +0200 | [diff] [blame] | 804 | pr_info("ACPI: %s [%s]\n", |
| 805 | acpi_device_name(device), acpi_device_bid(device)); |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 806 | |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 807 | while (call_fext_func(device, FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0 && |
| 808 | i++ < MAX_HOTKEY_RINGBUFFER_SIZE) |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 809 | ; /* No action, result is discarded */ |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 810 | acpi_handle_debug(device->handle, "Discarded %i ringbuffer entries\n", |
| 811 | i); |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 812 | |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 813 | priv->flags_supported = call_fext_func(device, FUNC_FLAGS, 0x0, 0x0, |
| 814 | 0x0); |
| Tony Vroon | 4898c2b | 2009-02-02 11:11:10 +0000 | [diff] [blame] | 815 | |
| 816 | /* Make sure our bitmask of supported functions is cleared if the |
| 817 | RFKILL function block is not implemented, like on the S7020. */ |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 818 | if (priv->flags_supported == UNSUPPORTED_CMD) |
| 819 | priv->flags_supported = 0; |
| Tony Vroon | 4898c2b | 2009-02-02 11:11:10 +0000 | [diff] [blame] | 820 | |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 821 | if (priv->flags_supported) |
| 822 | priv->flags_state = call_fext_func(device, FUNC_FLAGS, 0x4, 0x0, |
| 823 | 0x0); |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 824 | |
| 825 | /* Suspect this is a keymap of the application panel, print it */ |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 826 | acpi_handle_info(device->handle, "BTNI: [0x%x]\n", |
| 827 | call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0)); |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 828 | |
| Michał Kępień | 1877e26 | 2017-03-10 11:50:34 +0100 | [diff] [blame] | 829 | /* Sync backlight power status */ |
| Michał Kępień | 679374e | 2017-05-19 09:44:42 +0200 | [diff] [blame] | 830 | if (fujitsu_bl && fujitsu_bl->bl_device && |
| Michał Kępień | aea3137 | 2017-03-10 11:50:35 +0100 | [diff] [blame] | 831 | acpi_video_get_backlight_type() == acpi_backlight_vendor) { |
| Michał Kępień | 2f60efa | 2018-02-20 06:24:53 +0100 | [diff] [blame] | 832 | if (call_fext_func(fext, FUNC_BACKLIGHT, 0x2, |
| 833 | BACKLIGHT_PARAM_POWER, 0x0) == BACKLIGHT_OFF) |
| Michał Kępień | 1877e26 | 2017-03-10 11:50:34 +0100 | [diff] [blame] | 834 | fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN; |
| 835 | else |
| 836 | fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK; |
| 837 | } |
| 838 | |
| Michał Kępień | a7a1ccbe | 2018-02-11 22:07:22 +0100 | [diff] [blame] | 839 | ret = acpi_fujitsu_laptop_input_setup(device); |
| 840 | if (ret) |
| 841 | goto err_free_fifo; |
| 842 | |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 843 | ret = acpi_fujitsu_laptop_leds_register(device); |
| 844 | if (ret) |
| Michał Kępień | d1c7073 | 2017-04-07 15:07:13 +0200 | [diff] [blame] | 845 | goto err_free_fifo; |
| 846 | |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 847 | ret = fujitsu_laptop_platform_add(device); |
| 848 | if (ret) |
| Michał Kępień | f66735f | 2017-03-20 10:32:21 +0100 | [diff] [blame] | 849 | goto err_free_fifo; |
| Michał Kępień | c33f4c0 | 2017-03-14 11:26:30 +0100 | [diff] [blame] | 850 | |
| Michał Kępień | 7adb7b1 | 2017-04-07 15:07:09 +0200 | [diff] [blame] | 851 | return 0; |
| Michał Kępień | 4f62568 | 2016-04-12 22:06:34 +0930 | [diff] [blame] | 852 | |
| Bjorn Helgaas | b4ec027 | 2009-04-07 15:37:22 +0000 | [diff] [blame] | 853 | err_free_fifo: |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 854 | kfifo_free(&priv->fifo); |
| Michał Kępień | 7f83d41 | 2018-02-11 22:07:23 +0100 | [diff] [blame] | 855 | |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 856 | return ret; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 857 | } |
| 858 | |
| Alan Jenkins | 6942eab | 2017-02-08 14:46:25 +0100 | [diff] [blame] | 859 | static int acpi_fujitsu_laptop_remove(struct acpi_device *device) |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 860 | { |
| Michał Kępień | 7ec3b54 | 2017-05-19 09:44:41 +0200 | [diff] [blame] | 861 | struct fujitsu_laptop *priv = acpi_driver_data(device); |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 862 | |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 863 | fujitsu_laptop_platform_remove(device); |
| Michał Kępień | c33f4c0 | 2017-03-14 11:26:30 +0100 | [diff] [blame] | 864 | |
| Michał Kępień | 7ec3b54 | 2017-05-19 09:44:41 +0200 | [diff] [blame] | 865 | kfifo_free(&priv->fifo); |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 866 | |
| 867 | return 0; |
| 868 | } |
| 869 | |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 870 | static void acpi_fujitsu_laptop_press(struct acpi_device *device, int scancode) |
| Michał Kępień | 2451d19 | 2017-01-11 09:59:31 +0100 | [diff] [blame] | 871 | { |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 872 | struct fujitsu_laptop *priv = acpi_driver_data(device); |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 873 | int ret; |
| Michał Kępień | 2451d19 | 2017-01-11 09:59:31 +0100 | [diff] [blame] | 874 | |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 875 | ret = kfifo_in_locked(&priv->fifo, (unsigned char *)&scancode, |
| 876 | sizeof(scancode), &priv->fifo_lock); |
| 877 | if (ret != sizeof(scancode)) { |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 878 | dev_info(&priv->input->dev, "Could not push scancode [0x%x]\n", |
| 879 | scancode); |
| Michał Kępień | a28c7e9 | 2017-01-11 09:59:33 +0100 | [diff] [blame] | 880 | return; |
| Michał Kępień | 2451d19 | 2017-01-11 09:59:31 +0100 | [diff] [blame] | 881 | } |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 882 | sparse_keymap_report_event(priv->input, scancode, 1, false); |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 883 | dev_dbg(&priv->input->dev, "Push scancode into ringbuffer [0x%x]\n", |
| 884 | scancode); |
| Michał Kępień | 2451d19 | 2017-01-11 09:59:31 +0100 | [diff] [blame] | 885 | } |
| 886 | |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 887 | static void acpi_fujitsu_laptop_release(struct acpi_device *device) |
| Michał Kępień | 2451d19 | 2017-01-11 09:59:31 +0100 | [diff] [blame] | 888 | { |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 889 | struct fujitsu_laptop *priv = acpi_driver_data(device); |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 890 | int scancode, ret; |
| Michał Kępień | 2451d19 | 2017-01-11 09:59:31 +0100 | [diff] [blame] | 891 | |
| Michał Kępień | 29544f0 | 2017-01-11 09:59:32 +0100 | [diff] [blame] | 892 | while (true) { |
| Michał Kępień | 14966e0 | 2018-02-11 22:07:21 +0100 | [diff] [blame] | 893 | ret = kfifo_out_locked(&priv->fifo, (unsigned char *)&scancode, |
| 894 | sizeof(scancode), &priv->fifo_lock); |
| 895 | if (ret != sizeof(scancode)) |
| Michał Kępień | 29544f0 | 2017-01-11 09:59:32 +0100 | [diff] [blame] | 896 | return; |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 897 | sparse_keymap_report_event(priv->input, scancode, 0, false); |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 898 | dev_dbg(&priv->input->dev, |
| 899 | "Pop scancode from ringbuffer [0x%x]\n", scancode); |
| Michał Kępień | 2451d19 | 2017-01-11 09:59:31 +0100 | [diff] [blame] | 900 | } |
| 901 | } |
| 902 | |
| Alan Jenkins | 6942eab | 2017-02-08 14:46:25 +0100 | [diff] [blame] | 903 | static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event) |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 904 | { |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 905 | struct fujitsu_laptop *priv = acpi_driver_data(device); |
| Jan-Marek Glogowski | 797195a | 2018-02-12 13:08:51 +0100 | [diff] [blame^] | 906 | int scancode, i = 0, ret; |
| Michał Kępień | 527483a | 2017-03-20 10:32:22 +0100 | [diff] [blame] | 907 | unsigned int irb; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 908 | |
| Michał Kępień | 819cdda | 2018-02-20 06:24:54 +0100 | [diff] [blame] | 909 | if (event != ACPI_FUJITSU_NOTIFY_CODE) { |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 910 | acpi_handle_info(device->handle, "Unsupported event [0x%x]\n", |
| 911 | event); |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 912 | sparse_keymap_report_event(priv->input, -1, 1, true); |
| Michał Kępień | eb357cb | 2017-01-11 09:59:30 +0100 | [diff] [blame] | 913 | return; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 914 | } |
| Michał Kępień | eb357cb | 2017-01-11 09:59:30 +0100 | [diff] [blame] | 915 | |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 916 | if (priv->flags_supported) |
| 917 | priv->flags_state = call_fext_func(device, FUNC_FLAGS, 0x4, 0x0, |
| 918 | 0x0); |
| Michał Kępień | eb357cb | 2017-01-11 09:59:30 +0100 | [diff] [blame] | 919 | |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 920 | while ((irb = call_fext_func(device, |
| Michał Kępień | 84631e0 | 2017-05-19 09:44:46 +0200 | [diff] [blame] | 921 | FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0 && |
| Michał Kępień | 527483a | 2017-03-20 10:32:22 +0100 | [diff] [blame] | 922 | i++ < MAX_HOTKEY_RINGBUFFER_SIZE) { |
| 923 | scancode = irb & 0x4ff; |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 924 | if (sparse_keymap_entry_from_scancode(priv->input, scancode)) |
| 925 | acpi_fujitsu_laptop_press(device, scancode); |
| Michał Kępień | 527483a | 2017-03-20 10:32:22 +0100 | [diff] [blame] | 926 | else if (scancode == 0) |
| Michał Kępień | d659d11 | 2017-05-19 09:44:48 +0200 | [diff] [blame] | 927 | acpi_fujitsu_laptop_release(device); |
| Michał Kępień | 527483a | 2017-03-20 10:32:22 +0100 | [diff] [blame] | 928 | else |
| Michał Kępień | eee77da1 | 2017-06-16 06:40:58 +0200 | [diff] [blame] | 929 | acpi_handle_info(device->handle, |
| 930 | "Unknown GIRB result [%x]\n", irb); |
| Michał Kępień | eb357cb | 2017-01-11 09:59:30 +0100 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | /* On some models (first seen on the Skylake-based Lifebook |
| 934 | * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is |
| Alan Jenkins | 8ef27bd | 2017-02-08 14:46:27 +0100 | [diff] [blame] | 935 | * handled in software; its state is queried using FUNC_FLAGS |
| Michał Kępień | eb357cb | 2017-01-11 09:59:30 +0100 | [diff] [blame] | 936 | */ |
| Jan-Marek Glogowski | 797195a | 2018-02-12 13:08:51 +0100 | [diff] [blame^] | 937 | if (priv->flags_supported & (BIT(5) | BIT(26) | BIT(29))) { |
| 938 | ret = call_fext_func(device, FUNC_FLAGS, 0x1, 0x0, 0x0); |
| 939 | if (ret & BIT(5)) |
| 940 | sparse_keymap_report_event(priv->input, |
| 941 | BIT(5), 1, true); |
| 942 | if (ret & BIT(26)) |
| 943 | sparse_keymap_report_event(priv->input, |
| 944 | BIT(26), 1, true); |
| 945 | if (ret & BIT(29)) |
| 946 | sparse_keymap_report_event(priv->input, |
| 947 | BIT(29), 1, true); |
| 948 | } |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | /* Initialization */ |
| 952 | |
| Alan Jenkins | 9fc5cf6 | 2017-02-08 14:46:24 +0100 | [diff] [blame] | 953 | static const struct acpi_device_id fujitsu_bl_device_ids[] = { |
| 954 | {ACPI_FUJITSU_BL_HID, 0}, |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 955 | {"", 0}, |
| 956 | }; |
| 957 | |
| Alan Jenkins | 9fc5cf6 | 2017-02-08 14:46:24 +0100 | [diff] [blame] | 958 | static struct acpi_driver acpi_fujitsu_bl_driver = { |
| 959 | .name = ACPI_FUJITSU_BL_DRIVER_NAME, |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 960 | .class = ACPI_FUJITSU_CLASS, |
| Alan Jenkins | 9fc5cf6 | 2017-02-08 14:46:24 +0100 | [diff] [blame] | 961 | .ids = fujitsu_bl_device_ids, |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 962 | .ops = { |
| Alan Jenkins | 9fc5cf6 | 2017-02-08 14:46:24 +0100 | [diff] [blame] | 963 | .add = acpi_fujitsu_bl_add, |
| Alan Jenkins | 9fc5cf6 | 2017-02-08 14:46:24 +0100 | [diff] [blame] | 964 | .notify = acpi_fujitsu_bl_notify, |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 965 | }, |
| 966 | }; |
| 967 | |
| Alan Jenkins | 6942eab | 2017-02-08 14:46:25 +0100 | [diff] [blame] | 968 | static const struct acpi_device_id fujitsu_laptop_device_ids[] = { |
| 969 | {ACPI_FUJITSU_LAPTOP_HID, 0}, |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 970 | {"", 0}, |
| 971 | }; |
| 972 | |
| Alan Jenkins | 6942eab | 2017-02-08 14:46:25 +0100 | [diff] [blame] | 973 | static struct acpi_driver acpi_fujitsu_laptop_driver = { |
| 974 | .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME, |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 975 | .class = ACPI_FUJITSU_CLASS, |
| Alan Jenkins | 6942eab | 2017-02-08 14:46:25 +0100 | [diff] [blame] | 976 | .ids = fujitsu_laptop_device_ids, |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 977 | .ops = { |
| Alan Jenkins | 6942eab | 2017-02-08 14:46:25 +0100 | [diff] [blame] | 978 | .add = acpi_fujitsu_laptop_add, |
| 979 | .remove = acpi_fujitsu_laptop_remove, |
| 980 | .notify = acpi_fujitsu_laptop_notify, |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 981 | }, |
| 982 | }; |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 983 | |
| Zhang Rui | 4990141 | 2014-09-09 00:21:59 +0200 | [diff] [blame] | 984 | static const struct acpi_device_id fujitsu_ids[] __used = { |
| Alan Jenkins | 9fc5cf6 | 2017-02-08 14:46:24 +0100 | [diff] [blame] | 985 | {ACPI_FUJITSU_BL_HID, 0}, |
| Alan Jenkins | 6942eab | 2017-02-08 14:46:25 +0100 | [diff] [blame] | 986 | {ACPI_FUJITSU_LAPTOP_HID, 0}, |
| Zhang Rui | 4990141 | 2014-09-09 00:21:59 +0200 | [diff] [blame] | 987 | {"", 0} |
| 988 | }; |
| 989 | MODULE_DEVICE_TABLE(acpi, fujitsu_ids); |
| 990 | |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 991 | static int __init fujitsu_init(void) |
| 992 | { |
| Michał Kępień | b8d69c1 | 2017-03-10 11:50:33 +0100 | [diff] [blame] | 993 | int ret; |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 994 | |
| Alan Jenkins | c1d1e8a | 2017-02-08 14:46:30 +0100 | [diff] [blame] | 995 | ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver); |
| 996 | if (ret) |
| Michał Kępień | 679374e | 2017-05-19 09:44:42 +0200 | [diff] [blame] | 997 | return ret; |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 998 | |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 999 | /* Register platform stuff */ |
| 1000 | |
| Alan Jenkins | 1650602 | 2017-02-08 14:46:26 +0100 | [diff] [blame] | 1001 | ret = platform_driver_register(&fujitsu_pf_driver); |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1002 | if (ret) |
| Michał Kępień | c33f4c0 | 2017-03-14 11:26:30 +0100 | [diff] [blame] | 1003 | goto err_unregister_acpi; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1004 | |
| Alan Jenkins | 6942eab | 2017-02-08 14:46:25 +0100 | [diff] [blame] | 1005 | /* Register laptop driver */ |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1006 | |
| Alan Jenkins | c1d1e8a | 2017-02-08 14:46:30 +0100 | [diff] [blame] | 1007 | ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver); |
| 1008 | if (ret) |
| Michał Kępień | a4b176e | 2017-05-19 09:44:44 +0200 | [diff] [blame] | 1009 | goto err_unregister_platform_driver; |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1010 | |
| Joe Perches | 77bad7c | 2011-03-29 15:21:39 -0700 | [diff] [blame] | 1011 | pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n"); |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1012 | |
| 1013 | return 0; |
| 1014 | |
| Michał Kępień | c2cddd4 | 2017-03-10 11:50:36 +0100 | [diff] [blame] | 1015 | err_unregister_platform_driver: |
| Alan Jenkins | 1650602 | 2017-02-08 14:46:26 +0100 | [diff] [blame] | 1016 | platform_driver_unregister(&fujitsu_pf_driver); |
| Michał Kępień | c2cddd4 | 2017-03-10 11:50:36 +0100 | [diff] [blame] | 1017 | err_unregister_acpi: |
| Alan Jenkins | 9fc5cf6 | 2017-02-08 14:46:24 +0100 | [diff] [blame] | 1018 | acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver); |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1019 | |
| 1020 | return ret; |
| 1021 | } |
| 1022 | |
| 1023 | static void __exit fujitsu_cleanup(void) |
| 1024 | { |
| Alan Jenkins | 6942eab | 2017-02-08 14:46:25 +0100 | [diff] [blame] | 1025 | acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver); |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 1026 | |
| Alan Jenkins | 1650602 | 2017-02-08 14:46:26 +0100 | [diff] [blame] | 1027 | platform_driver_unregister(&fujitsu_pf_driver); |
| Bartlomiej Zolnierkiewicz | 72afeea | 2009-07-31 18:16:02 +0930 | [diff] [blame] | 1028 | |
| Alan Jenkins | 9fc5cf6 | 2017-02-08 14:46:24 +0100 | [diff] [blame] | 1029 | acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver); |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1030 | |
| Joe Perches | 77bad7c | 2011-03-29 15:21:39 -0700 | [diff] [blame] | 1031 | pr_info("driver unloaded\n"); |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | module_init(fujitsu_init); |
| 1035 | module_exit(fujitsu_cleanup); |
| 1036 | |
| Michał Kępień | e06e483 | 2017-04-05 08:49:05 +0200 | [diff] [blame] | 1037 | module_param(use_alt_lcd_levels, int, 0644); |
| 1038 | MODULE_PARM_DESC(use_alt_lcd_levels, "Interface used for setting LCD brightness level (-1 = auto, 0 = force SBLL, 1 = force SBL2)"); |
| Michał Kępień | b4bb0cf | 2017-04-05 08:49:06 +0200 | [diff] [blame] | 1039 | module_param(disable_brightness_adjust, bool, 0644); |
| 1040 | MODULE_PARM_DESC(disable_brightness_adjust, "Disable LCD brightness adjustment"); |
| Jonathan Woithe | 20b9373 | 2008-06-11 10:14:56 +0930 | [diff] [blame] | 1041 | |
| Tony Vroon | 3a40708 | 2008-12-31 18:19:59 +0000 | [diff] [blame] | 1042 | MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon"); |
| Jonathan Woithe | d048253 | 2007-08-29 15:58:19 +0930 | [diff] [blame] | 1043 | MODULE_DESCRIPTION("Fujitsu laptop extras support"); |
| 1044 | MODULE_VERSION(FUJITSU_DRIVER_VERSION); |
| 1045 | MODULE_LICENSE("GPL"); |