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