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