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