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