]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * toshiba_acpi.c - Toshiba Laptop ACPI Extras | |
3 | * | |
4 | * | |
5 | * Copyright (C) 2002-2004 John Belmonte | |
c41a40c5 | 6 | * Copyright (C) 2008 Philip Langdale |
6c3f6e6c | 7 | * Copyright (C) 2010 Pierre Ducroquet |
548c4306 | 8 | * Copyright (C) 2014 Azael Avalos |
1da177e4 LT |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 | * | |
24 | * | |
25 | * The devolpment page for this driver is located at | |
26 | * http://memebeam.org/toys/ToshibaAcpiDriver. | |
27 | * | |
28 | * Credits: | |
29 | * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse | |
30 | * engineering the Windows drivers | |
31 | * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5 | |
32 | * Rob Miller - TV out and hotkeys help | |
33 | * | |
34 | * | |
35 | * TODO | |
36 | * | |
37 | */ | |
38 | ||
7e33460d JP |
39 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
40 | ||
548c4306 | 41 | #define TOSHIBA_ACPI_VERSION "0.20" |
1da177e4 LT |
42 | #define PROC_INTERFACE_VERSION 1 |
43 | ||
44 | #include <linux/kernel.h> | |
45 | #include <linux/module.h> | |
46 | #include <linux/init.h> | |
47 | #include <linux/types.h> | |
48 | #include <linux/proc_fs.h> | |
936c8bcd | 49 | #include <linux/seq_file.h> |
c9263557 | 50 | #include <linux/backlight.h> |
c41a40c5 | 51 | #include <linux/rfkill.h> |
6335e4d5 | 52 | #include <linux/input.h> |
384a7cd9 | 53 | #include <linux/input/sparse-keymap.h> |
6c3f6e6c | 54 | #include <linux/leds.h> |
5a0e3ad6 | 55 | #include <linux/slab.h> |
29cd293f SF |
56 | #include <linux/workqueue.h> |
57 | #include <linux/i8042.h> | |
8b48463f | 58 | #include <linux/acpi.h> |
fe808bfb | 59 | #include <linux/dmi.h> |
1da177e4 LT |
60 | #include <asm/uaccess.h> |
61 | ||
1da177e4 LT |
62 | MODULE_AUTHOR("John Belmonte"); |
63 | MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver"); | |
64 | MODULE_LICENSE("GPL"); | |
65 | ||
f11f999e SF |
66 | #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100" |
67 | ||
29cd293f SF |
68 | /* Scan code for Fn key on TOS1900 models */ |
69 | #define TOS1900_FN_SCAN 0x6e | |
70 | ||
1da177e4 | 71 | /* Toshiba ACPI method paths */ |
1da177e4 LT |
72 | #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX" |
73 | ||
258c5903 AA |
74 | /* The Toshiba configuration interface is composed of the HCI and the SCI, |
75 | * which are defined as follows: | |
1da177e4 LT |
76 | * |
77 | * HCI is Toshiba's "Hardware Control Interface" which is supposed to | |
78 | * be uniform across all their models. Ideally we would just call | |
79 | * dedicated ACPI methods instead of using this primitive interface. | |
80 | * However the ACPI methods seem to be incomplete in some areas (for | |
81 | * example they allow setting, but not reading, the LCD brightness value), | |
82 | * so this is still useful. | |
ea6b31f4 | 83 | * |
84a6273f AA |
84 | * SCI stands for "System Configuration Interface" which aim is to |
85 | * conceal differences in hardware between different models. | |
1da177e4 LT |
86 | */ |
87 | ||
258c5903 | 88 | #define TCI_WORDS 6 |
1da177e4 LT |
89 | |
90 | /* operations */ | |
91 | #define HCI_SET 0xff00 | |
92 | #define HCI_GET 0xfe00 | |
84a6273f AA |
93 | #define SCI_OPEN 0xf100 |
94 | #define SCI_CLOSE 0xf200 | |
95 | #define SCI_GET 0xf300 | |
96 | #define SCI_SET 0xf400 | |
1da177e4 LT |
97 | |
98 | /* return codes */ | |
1864bbc2 AA |
99 | #define TOS_SUCCESS 0x0000 |
100 | #define TOS_OPEN_CLOSE_OK 0x0044 | |
101 | #define TOS_FAILURE 0x1000 | |
102 | #define TOS_NOT_SUPPORTED 0x8000 | |
103 | #define TOS_ALREADY_OPEN 0x8100 | |
104 | #define TOS_NOT_OPENED 0x8200 | |
105 | #define TOS_INPUT_DATA_ERROR 0x8300 | |
106 | #define TOS_WRITE_PROTECTED 0x8400 | |
107 | #define TOS_NOT_PRESENT 0x8600 | |
108 | #define TOS_FIFO_EMPTY 0x8c00 | |
109 | #define TOS_DATA_NOT_AVAILABLE 0x8d20 | |
110 | #define TOS_NOT_INITIALIZED 0x8d50 | |
1da177e4 LT |
111 | |
112 | /* registers */ | |
113 | #define HCI_FAN 0x0004 | |
121b7b0d | 114 | #define HCI_TR_BACKLIGHT 0x0005 |
1da177e4 LT |
115 | #define HCI_SYSTEM_EVENT 0x0016 |
116 | #define HCI_VIDEO_OUT 0x001c | |
117 | #define HCI_HOTKEY_EVENT 0x001e | |
118 | #define HCI_LCD_BRIGHTNESS 0x002a | |
c41a40c5 | 119 | #define HCI_WIRELESS 0x0056 |
5a2813e9 | 120 | #define HCI_ACCELEROMETER 0x006d |
360f0f39 | 121 | #define HCI_KBD_ILLUMINATION 0x0095 |
def6c4e2 | 122 | #define HCI_ECO_MODE 0x0097 |
5a2813e9 | 123 | #define HCI_ACCELEROMETER2 0x00a6 |
fdb79081 | 124 | #define SCI_ILLUMINATION 0x014e |
360f0f39 | 125 | #define SCI_KBD_ILLUM_STATUS 0x015c |
9d8658ac | 126 | #define SCI_TOUCHPAD 0x050e |
1da177e4 LT |
127 | |
128 | /* field definitions */ | |
5a2813e9 | 129 | #define HCI_ACCEL_MASK 0x7fff |
29cd293f SF |
130 | #define HCI_HOTKEY_DISABLE 0x0b |
131 | #define HCI_HOTKEY_ENABLE 0x09 | |
1da177e4 LT |
132 | #define HCI_LCD_BRIGHTNESS_BITS 3 |
133 | #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS) | |
134 | #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS) | |
360f0f39 | 135 | #define HCI_MISC_SHIFT 0x10 |
1da177e4 LT |
136 | #define HCI_VIDEO_OUT_LCD 0x1 |
137 | #define HCI_VIDEO_OUT_CRT 0x2 | |
138 | #define HCI_VIDEO_OUT_TV 0x4 | |
c41a40c5 | 139 | #define HCI_WIRELESS_KILL_SWITCH 0x01 |
140 | #define HCI_WIRELESS_BT_PRESENT 0x0f | |
141 | #define HCI_WIRELESS_BT_ATTACH 0x40 | |
142 | #define HCI_WIRELESS_BT_POWER 0x80 | |
93f8c16d | 143 | #define SCI_KBD_MODE_MASK 0x1f |
360f0f39 AA |
144 | #define SCI_KBD_MODE_FNZ 0x1 |
145 | #define SCI_KBD_MODE_AUTO 0x2 | |
93f8c16d AA |
146 | #define SCI_KBD_MODE_ON 0x8 |
147 | #define SCI_KBD_MODE_OFF 0x10 | |
148 | #define SCI_KBD_TIME_MAX 0x3c001a | |
1da177e4 | 149 | |
135740de SF |
150 | struct toshiba_acpi_dev { |
151 | struct acpi_device *acpi_dev; | |
152 | const char *method_hci; | |
153 | struct rfkill *bt_rfk; | |
154 | struct input_dev *hotkey_dev; | |
29cd293f | 155 | struct work_struct hotkey_work; |
135740de SF |
156 | struct backlight_device *backlight_dev; |
157 | struct led_classdev led_dev; | |
360f0f39 | 158 | struct led_classdev kbd_led; |
def6c4e2 | 159 | struct led_classdev eco_led; |
36d03f93 | 160 | |
135740de SF |
161 | int force_fan; |
162 | int last_key_event; | |
163 | int key_event_valid; | |
93f8c16d | 164 | int kbd_type; |
360f0f39 AA |
165 | int kbd_mode; |
166 | int kbd_time; | |
135740de | 167 | |
592b746c DC |
168 | unsigned int illumination_supported:1; |
169 | unsigned int video_supported:1; | |
170 | unsigned int fan_supported:1; | |
171 | unsigned int system_event_supported:1; | |
29cd293f SF |
172 | unsigned int ntfy_supported:1; |
173 | unsigned int info_supported:1; | |
121b7b0d | 174 | unsigned int tr_backlight_supported:1; |
360f0f39 AA |
175 | unsigned int kbd_illum_supported:1; |
176 | unsigned int kbd_led_registered:1; | |
9d8658ac | 177 | unsigned int touchpad_supported:1; |
def6c4e2 | 178 | unsigned int eco_supported:1; |
5a2813e9 | 179 | unsigned int accelerometer_supported:1; |
360f0f39 | 180 | unsigned int sysfs_created:1; |
36d03f93 | 181 | |
135740de SF |
182 | struct mutex mutex; |
183 | }; | |
184 | ||
29cd293f SF |
185 | static struct toshiba_acpi_dev *toshiba_acpi; |
186 | ||
4db42c51 | 187 | static const struct acpi_device_id toshiba_device_ids[] = { |
188 | {"TOS6200", 0}, | |
c41a40c5 | 189 | {"TOS6208", 0}, |
4db42c51 | 190 | {"TOS1900", 0}, |
191 | {"", 0}, | |
192 | }; | |
193 | MODULE_DEVICE_TABLE(acpi, toshiba_device_ids); | |
194 | ||
b859f159 | 195 | static const struct key_entry toshiba_acpi_keymap[] = { |
fec278a1 | 196 | { KE_KEY, 0x9e, { KEY_RFKILL } }, |
384a7cd9 DT |
197 | { KE_KEY, 0x101, { KEY_MUTE } }, |
198 | { KE_KEY, 0x102, { KEY_ZOOMOUT } }, | |
199 | { KE_KEY, 0x103, { KEY_ZOOMIN } }, | |
408a5d13 | 200 | { KE_KEY, 0x10f, { KEY_TAB } }, |
af502837 AA |
201 | { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } }, |
202 | { KE_KEY, 0x139, { KEY_ZOOMRESET } }, | |
384a7cd9 DT |
203 | { KE_KEY, 0x13b, { KEY_COFFEE } }, |
204 | { KE_KEY, 0x13c, { KEY_BATTERY } }, | |
205 | { KE_KEY, 0x13d, { KEY_SLEEP } }, | |
206 | { KE_KEY, 0x13e, { KEY_SUSPEND } }, | |
207 | { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } }, | |
208 | { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } }, | |
209 | { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } }, | |
210 | { KE_KEY, 0x142, { KEY_WLAN } }, | |
af502837 | 211 | { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } }, |
a49010f5 | 212 | { KE_KEY, 0x17f, { KEY_FN } }, |
384a7cd9 DT |
213 | { KE_KEY, 0xb05, { KEY_PROG2 } }, |
214 | { KE_KEY, 0xb06, { KEY_WWW } }, | |
215 | { KE_KEY, 0xb07, { KEY_MAIL } }, | |
216 | { KE_KEY, 0xb30, { KEY_STOP } }, | |
217 | { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } }, | |
218 | { KE_KEY, 0xb32, { KEY_NEXTSONG } }, | |
219 | { KE_KEY, 0xb33, { KEY_PLAYPAUSE } }, | |
220 | { KE_KEY, 0xb5a, { KEY_MEDIA } }, | |
408a5d13 AA |
221 | { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */ |
222 | { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */ | |
223 | { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */ | |
224 | { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */ | |
225 | { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */ | |
384a7cd9 | 226 | { KE_END, 0 }, |
6335e4d5 MG |
227 | }; |
228 | ||
fe808bfb TI |
229 | /* alternative keymap */ |
230 | static const struct dmi_system_id toshiba_alt_keymap_dmi[] = { | |
231 | { | |
232 | .matches = { | |
233 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), | |
234 | DMI_MATCH(DMI_PRODUCT_NAME, "Satellite M840"), | |
235 | }, | |
236 | }, | |
e6efad7f AA |
237 | { |
238 | .matches = { | |
239 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), | |
240 | DMI_MATCH(DMI_PRODUCT_NAME, "Qosmio X75-A"), | |
241 | }, | |
242 | }, | |
fe808bfb TI |
243 | {} |
244 | }; | |
245 | ||
246 | static const struct key_entry toshiba_acpi_alt_keymap[] = { | |
247 | { KE_KEY, 0x157, { KEY_MUTE } }, | |
248 | { KE_KEY, 0x102, { KEY_ZOOMOUT } }, | |
249 | { KE_KEY, 0x103, { KEY_ZOOMIN } }, | |
e6efad7f | 250 | { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } }, |
fe808bfb TI |
251 | { KE_KEY, 0x139, { KEY_ZOOMRESET } }, |
252 | { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } }, | |
253 | { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } }, | |
254 | { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } }, | |
255 | { KE_KEY, 0x158, { KEY_WLAN } }, | |
256 | { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } }, | |
257 | { KE_END, 0 }, | |
258 | }; | |
259 | ||
1da177e4 LT |
260 | /* utility |
261 | */ | |
262 | ||
4be44fcd | 263 | static __inline__ void _set_bit(u32 * word, u32 mask, int value) |
1da177e4 LT |
264 | { |
265 | *word = (*word & ~mask) | (mask * value); | |
266 | } | |
267 | ||
268 | /* acpi interface wrappers | |
269 | */ | |
270 | ||
4be44fcd | 271 | static int write_acpi_int(const char *methodName, int val) |
1da177e4 | 272 | { |
1da177e4 LT |
273 | acpi_status status; |
274 | ||
619400da | 275 | status = acpi_execute_simple_method(NULL, (char *)methodName, val); |
32bcd5cb | 276 | return (status == AE_OK) ? 0 : -EIO; |
1da177e4 LT |
277 | } |
278 | ||
258c5903 AA |
279 | /* Perform a raw configuration call. Here we don't care about input or output |
280 | * buffer format. | |
1da177e4 | 281 | */ |
258c5903 AA |
282 | static acpi_status tci_raw(struct toshiba_acpi_dev *dev, |
283 | const u32 in[TCI_WORDS], u32 out[TCI_WORDS]) | |
1da177e4 LT |
284 | { |
285 | struct acpi_object_list params; | |
258c5903 | 286 | union acpi_object in_objs[TCI_WORDS]; |
1da177e4 | 287 | struct acpi_buffer results; |
258c5903 | 288 | union acpi_object out_objs[TCI_WORDS + 1]; |
1da177e4 LT |
289 | acpi_status status; |
290 | int i; | |
291 | ||
258c5903 | 292 | params.count = TCI_WORDS; |
1da177e4 | 293 | params.pointer = in_objs; |
258c5903 | 294 | for (i = 0; i < TCI_WORDS; ++i) { |
1da177e4 LT |
295 | in_objs[i].type = ACPI_TYPE_INTEGER; |
296 | in_objs[i].integer.value = in[i]; | |
297 | } | |
298 | ||
299 | results.length = sizeof(out_objs); | |
300 | results.pointer = out_objs; | |
301 | ||
6e02cc7e SF |
302 | status = acpi_evaluate_object(dev->acpi_dev->handle, |
303 | (char *)dev->method_hci, ¶ms, | |
4be44fcd | 304 | &results); |
258c5903 | 305 | if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) { |
1da177e4 LT |
306 | for (i = 0; i < out_objs->package.count; ++i) { |
307 | out[i] = out_objs->package.elements[i].integer.value; | |
308 | } | |
309 | } | |
310 | ||
311 | return status; | |
312 | } | |
313 | ||
c41a40c5 | 314 | /* common hci tasks (get or set one or two value) |
1da177e4 LT |
315 | * |
316 | * In addition to the ACPI status, the HCI system returns a result which | |
317 | * may be useful (such as "not supported"). | |
318 | */ | |
319 | ||
135740de SF |
320 | static acpi_status hci_write1(struct toshiba_acpi_dev *dev, u32 reg, |
321 | u32 in1, u32 *result) | |
1da177e4 | 322 | { |
258c5903 AA |
323 | u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 }; |
324 | u32 out[TCI_WORDS]; | |
325 | acpi_status status = tci_raw(dev, in, out); | |
1864bbc2 | 326 | *result = (status == AE_OK) ? out[0] : TOS_FAILURE; |
1da177e4 LT |
327 | return status; |
328 | } | |
329 | ||
135740de SF |
330 | static acpi_status hci_read1(struct toshiba_acpi_dev *dev, u32 reg, |
331 | u32 *out1, u32 *result) | |
1da177e4 | 332 | { |
258c5903 AA |
333 | u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 }; |
334 | u32 out[TCI_WORDS]; | |
335 | acpi_status status = tci_raw(dev, in, out); | |
1da177e4 | 336 | *out1 = out[2]; |
1864bbc2 | 337 | *result = (status == AE_OK) ? out[0] : TOS_FAILURE; |
1da177e4 LT |
338 | return status; |
339 | } | |
340 | ||
135740de SF |
341 | static acpi_status hci_write2(struct toshiba_acpi_dev *dev, u32 reg, |
342 | u32 in1, u32 in2, u32 *result) | |
c41a40c5 | 343 | { |
258c5903 AA |
344 | u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 }; |
345 | u32 out[TCI_WORDS]; | |
346 | acpi_status status = tci_raw(dev, in, out); | |
1864bbc2 | 347 | *result = (status == AE_OK) ? out[0] : TOS_FAILURE; |
c41a40c5 | 348 | return status; |
349 | } | |
350 | ||
135740de SF |
351 | static acpi_status hci_read2(struct toshiba_acpi_dev *dev, u32 reg, |
352 | u32 *out1, u32 *out2, u32 *result) | |
c41a40c5 | 353 | { |
258c5903 AA |
354 | u32 in[TCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 }; |
355 | u32 out[TCI_WORDS]; | |
356 | acpi_status status = tci_raw(dev, in, out); | |
c41a40c5 | 357 | *out1 = out[2]; |
358 | *out2 = out[3]; | |
1864bbc2 | 359 | *result = (status == AE_OK) ? out[0] : TOS_FAILURE; |
c41a40c5 | 360 | return status; |
361 | } | |
362 | ||
84a6273f AA |
363 | /* common sci tasks |
364 | */ | |
365 | ||
366 | static int sci_open(struct toshiba_acpi_dev *dev) | |
367 | { | |
258c5903 AA |
368 | u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 }; |
369 | u32 out[TCI_WORDS]; | |
84a6273f AA |
370 | acpi_status status; |
371 | ||
258c5903 | 372 | status = tci_raw(dev, in, out); |
1864bbc2 | 373 | if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { |
84a6273f AA |
374 | pr_err("ACPI call to open SCI failed\n"); |
375 | return 0; | |
376 | } | |
377 | ||
1864bbc2 | 378 | if (out[0] == TOS_OPEN_CLOSE_OK) { |
84a6273f | 379 | return 1; |
1864bbc2 | 380 | } else if (out[0] == TOS_ALREADY_OPEN) { |
84a6273f AA |
381 | pr_info("Toshiba SCI already opened\n"); |
382 | return 1; | |
1864bbc2 | 383 | } else if (out[0] == TOS_NOT_PRESENT) { |
84a6273f AA |
384 | pr_info("Toshiba SCI is not present\n"); |
385 | } | |
386 | ||
387 | return 0; | |
388 | } | |
389 | ||
390 | static void sci_close(struct toshiba_acpi_dev *dev) | |
391 | { | |
258c5903 AA |
392 | u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 }; |
393 | u32 out[TCI_WORDS]; | |
84a6273f AA |
394 | acpi_status status; |
395 | ||
258c5903 | 396 | status = tci_raw(dev, in, out); |
1864bbc2 | 397 | if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { |
84a6273f AA |
398 | pr_err("ACPI call to close SCI failed\n"); |
399 | return; | |
400 | } | |
401 | ||
1864bbc2 | 402 | if (out[0] == TOS_OPEN_CLOSE_OK) |
84a6273f | 403 | return; |
1864bbc2 | 404 | else if (out[0] == TOS_NOT_OPENED) |
84a6273f | 405 | pr_info("Toshiba SCI not opened\n"); |
1864bbc2 | 406 | else if (out[0] == TOS_NOT_PRESENT) |
84a6273f AA |
407 | pr_info("Toshiba SCI is not present\n"); |
408 | } | |
409 | ||
410 | static acpi_status sci_read(struct toshiba_acpi_dev *dev, u32 reg, | |
411 | u32 *out1, u32 *result) | |
412 | { | |
258c5903 AA |
413 | u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 }; |
414 | u32 out[TCI_WORDS]; | |
415 | acpi_status status = tci_raw(dev, in, out); | |
84a6273f | 416 | *out1 = out[2]; |
1864bbc2 | 417 | *result = (ACPI_SUCCESS(status)) ? out[0] : TOS_FAILURE; |
84a6273f AA |
418 | return status; |
419 | } | |
420 | ||
421 | static acpi_status sci_write(struct toshiba_acpi_dev *dev, u32 reg, | |
422 | u32 in1, u32 *result) | |
423 | { | |
258c5903 AA |
424 | u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 }; |
425 | u32 out[TCI_WORDS]; | |
426 | acpi_status status = tci_raw(dev, in, out); | |
1864bbc2 | 427 | *result = (ACPI_SUCCESS(status)) ? out[0] : TOS_FAILURE; |
84a6273f AA |
428 | return status; |
429 | } | |
430 | ||
6c3f6e6c | 431 | /* Illumination support */ |
135740de | 432 | static int toshiba_illumination_available(struct toshiba_acpi_dev *dev) |
6c3f6e6c | 433 | { |
258c5903 AA |
434 | u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 }; |
435 | u32 out[TCI_WORDS]; | |
6c3f6e6c PD |
436 | acpi_status status; |
437 | ||
fdb79081 AA |
438 | if (!sci_open(dev)) |
439 | return 0; | |
440 | ||
258c5903 | 441 | status = tci_raw(dev, in, out); |
fdb79081 | 442 | sci_close(dev); |
1864bbc2 | 443 | if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { |
fdb79081 AA |
444 | pr_err("ACPI call to query Illumination support failed\n"); |
445 | return 0; | |
1864bbc2 | 446 | } else if (out[0] == TOS_NOT_SUPPORTED) { |
7e33460d | 447 | pr_info("Illumination device not available\n"); |
6c3f6e6c PD |
448 | return 0; |
449 | } | |
fdb79081 | 450 | |
6c3f6e6c PD |
451 | return 1; |
452 | } | |
453 | ||
454 | static void toshiba_illumination_set(struct led_classdev *cdev, | |
455 | enum led_brightness brightness) | |
456 | { | |
135740de SF |
457 | struct toshiba_acpi_dev *dev = container_of(cdev, |
458 | struct toshiba_acpi_dev, led_dev); | |
fdb79081 | 459 | u32 state, result; |
6c3f6e6c PD |
460 | acpi_status status; |
461 | ||
462 | /* First request : initialize communication. */ | |
fdb79081 | 463 | if (!sci_open(dev)) |
6c3f6e6c | 464 | return; |
6c3f6e6c | 465 | |
fdb79081 AA |
466 | /* Switch the illumination on/off */ |
467 | state = brightness ? 1 : 0; | |
468 | status = sci_write(dev, SCI_ILLUMINATION, state, &result); | |
469 | sci_close(dev); | |
470 | if (ACPI_FAILURE(status)) { | |
471 | pr_err("ACPI call for illumination failed\n"); | |
472 | return; | |
1864bbc2 | 473 | } else if (result == TOS_NOT_SUPPORTED) { |
fdb79081 AA |
474 | pr_info("Illumination not supported\n"); |
475 | return; | |
6c3f6e6c | 476 | } |
6c3f6e6c PD |
477 | } |
478 | ||
479 | static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev) | |
480 | { | |
135740de SF |
481 | struct toshiba_acpi_dev *dev = container_of(cdev, |
482 | struct toshiba_acpi_dev, led_dev); | |
fdb79081 | 483 | u32 state, result; |
6c3f6e6c | 484 | acpi_status status; |
6c3f6e6c PD |
485 | |
486 | /*Â First request : initialize communication. */ | |
fdb79081 | 487 | if (!sci_open(dev)) |
6c3f6e6c | 488 | return LED_OFF; |
6c3f6e6c PD |
489 | |
490 | /* Check the illumination */ | |
fdb79081 AA |
491 | status = sci_read(dev, SCI_ILLUMINATION, &state, &result); |
492 | sci_close(dev); | |
1864bbc2 | 493 | if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { |
fdb79081 AA |
494 | pr_err("ACPI call for illumination failed\n"); |
495 | return LED_OFF; | |
1864bbc2 | 496 | } else if (result == TOS_NOT_SUPPORTED) { |
fdb79081 | 497 | pr_info("Illumination not supported\n"); |
6c3f6e6c PD |
498 | return LED_OFF; |
499 | } | |
500 | ||
fdb79081 | 501 | return state ? LED_FULL : LED_OFF; |
6c3f6e6c | 502 | } |
ea6b31f4 | 503 | |
360f0f39 | 504 | /* KBD Illumination */ |
93f8c16d AA |
505 | static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev) |
506 | { | |
258c5903 AA |
507 | u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 }; |
508 | u32 out[TCI_WORDS]; | |
93f8c16d AA |
509 | acpi_status status; |
510 | ||
511 | if (!sci_open(dev)) | |
512 | return 0; | |
513 | ||
258c5903 | 514 | status = tci_raw(dev, in, out); |
93f8c16d | 515 | sci_close(dev); |
1864bbc2 | 516 | if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { |
93f8c16d AA |
517 | pr_err("ACPI call to query kbd illumination support failed\n"); |
518 | return 0; | |
1864bbc2 | 519 | } else if (out[0] == TOS_NOT_SUPPORTED) { |
93f8c16d AA |
520 | pr_info("Keyboard illumination not available\n"); |
521 | return 0; | |
522 | } | |
523 | ||
524 | /* Check for keyboard backlight timeout max value, | |
525 | * previous kbd backlight implementation set this to | |
526 | * 0x3c0003, and now the new implementation set this | |
527 | * to 0x3c001a, use this to distinguish between them | |
528 | */ | |
529 | if (out[3] == SCI_KBD_TIME_MAX) | |
530 | dev->kbd_type = 2; | |
531 | else | |
532 | dev->kbd_type = 1; | |
533 | /* Get the current keyboard backlight mode */ | |
534 | dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK; | |
535 | /* Get the current time (1-60 seconds) */ | |
536 | dev->kbd_time = out[2] >> HCI_MISC_SHIFT; | |
537 | ||
538 | return 1; | |
539 | } | |
540 | ||
360f0f39 AA |
541 | static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time) |
542 | { | |
543 | u32 result; | |
544 | acpi_status status; | |
545 | ||
546 | if (!sci_open(dev)) | |
547 | return -EIO; | |
548 | ||
549 | status = sci_write(dev, SCI_KBD_ILLUM_STATUS, time, &result); | |
550 | sci_close(dev); | |
1864bbc2 | 551 | if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { |
360f0f39 AA |
552 | pr_err("ACPI call to set KBD backlight status failed\n"); |
553 | return -EIO; | |
1864bbc2 | 554 | } else if (result == TOS_NOT_SUPPORTED) { |
360f0f39 AA |
555 | pr_info("Keyboard backlight status not supported\n"); |
556 | return -ENODEV; | |
557 | } | |
558 | ||
559 | return 0; | |
560 | } | |
561 | ||
562 | static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time) | |
563 | { | |
564 | u32 result; | |
565 | acpi_status status; | |
566 | ||
567 | if (!sci_open(dev)) | |
568 | return -EIO; | |
569 | ||
570 | status = sci_read(dev, SCI_KBD_ILLUM_STATUS, time, &result); | |
571 | sci_close(dev); | |
1864bbc2 | 572 | if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { |
360f0f39 AA |
573 | pr_err("ACPI call to get KBD backlight status failed\n"); |
574 | return -EIO; | |
1864bbc2 | 575 | } else if (result == TOS_NOT_SUPPORTED) { |
360f0f39 AA |
576 | pr_info("Keyboard backlight status not supported\n"); |
577 | return -ENODEV; | |
578 | } | |
579 | ||
580 | return 0; | |
581 | } | |
582 | ||
583 | static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev) | |
584 | { | |
585 | struct toshiba_acpi_dev *dev = container_of(cdev, | |
586 | struct toshiba_acpi_dev, kbd_led); | |
587 | u32 state, result; | |
588 | acpi_status status; | |
589 | ||
590 | /* Check the keyboard backlight state */ | |
591 | status = hci_read1(dev, HCI_KBD_ILLUMINATION, &state, &result); | |
1864bbc2 | 592 | if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { |
360f0f39 AA |
593 | pr_err("ACPI call to get the keyboard backlight failed\n"); |
594 | return LED_OFF; | |
1864bbc2 | 595 | } else if (result == TOS_NOT_SUPPORTED) { |
360f0f39 AA |
596 | pr_info("Keyboard backlight not supported\n"); |
597 | return LED_OFF; | |
598 | } | |
599 | ||
600 | return state ? LED_FULL : LED_OFF; | |
601 | } | |
602 | ||
603 | static void toshiba_kbd_backlight_set(struct led_classdev *cdev, | |
604 | enum led_brightness brightness) | |
605 | { | |
606 | struct toshiba_acpi_dev *dev = container_of(cdev, | |
607 | struct toshiba_acpi_dev, kbd_led); | |
608 | u32 state, result; | |
609 | acpi_status status; | |
610 | ||
611 | /* Set the keyboard backlight state */ | |
612 | state = brightness ? 1 : 0; | |
613 | status = hci_write1(dev, HCI_KBD_ILLUMINATION, state, &result); | |
1864bbc2 | 614 | if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { |
360f0f39 AA |
615 | pr_err("ACPI call to set KBD Illumination mode failed\n"); |
616 | return; | |
1864bbc2 | 617 | } else if (result == TOS_NOT_SUPPORTED) { |
360f0f39 AA |
618 | pr_info("Keyboard backlight not supported\n"); |
619 | return; | |
620 | } | |
621 | } | |
ea6b31f4 | 622 | |
9d8658ac AA |
623 | /* TouchPad support */ |
624 | static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state) | |
625 | { | |
626 | u32 result; | |
627 | acpi_status status; | |
628 | ||
629 | if (!sci_open(dev)) | |
630 | return -EIO; | |
631 | ||
632 | status = sci_write(dev, SCI_TOUCHPAD, state, &result); | |
633 | sci_close(dev); | |
634 | if (ACPI_FAILURE(status)) { | |
635 | pr_err("ACPI call to set the touchpad failed\n"); | |
636 | return -EIO; | |
1864bbc2 | 637 | } else if (result == TOS_NOT_SUPPORTED) { |
9d8658ac AA |
638 | return -ENODEV; |
639 | } | |
640 | ||
641 | return 0; | |
642 | } | |
643 | ||
644 | static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state) | |
645 | { | |
646 | u32 result; | |
647 | acpi_status status; | |
648 | ||
649 | if (!sci_open(dev)) | |
650 | return -EIO; | |
651 | ||
652 | status = sci_read(dev, SCI_TOUCHPAD, state, &result); | |
653 | sci_close(dev); | |
654 | if (ACPI_FAILURE(status)) { | |
655 | pr_err("ACPI call to query the touchpad failed\n"); | |
656 | return -EIO; | |
1864bbc2 | 657 | } else if (result == TOS_NOT_SUPPORTED) { |
9d8658ac AA |
658 | return -ENODEV; |
659 | } | |
660 | ||
661 | return 0; | |
662 | } | |
6c3f6e6c | 663 | |
def6c4e2 AA |
664 | /* Eco Mode support */ |
665 | static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev) | |
666 | { | |
667 | acpi_status status; | |
258c5903 AA |
668 | u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 }; |
669 | u32 out[TCI_WORDS]; | |
def6c4e2 | 670 | |
258c5903 | 671 | status = tci_raw(dev, in, out); |
1864bbc2 | 672 | if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { |
def6c4e2 AA |
673 | pr_info("ACPI call to get ECO led failed\n"); |
674 | return 0; | |
675 | } | |
676 | ||
677 | return 1; | |
678 | } | |
679 | ||
680 | static enum led_brightness toshiba_eco_mode_get_status(struct led_classdev *cdev) | |
681 | { | |
682 | struct toshiba_acpi_dev *dev = container_of(cdev, | |
683 | struct toshiba_acpi_dev, eco_led); | |
258c5903 AA |
684 | u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 }; |
685 | u32 out[TCI_WORDS]; | |
def6c4e2 AA |
686 | acpi_status status; |
687 | ||
258c5903 | 688 | status = tci_raw(dev, in, out); |
1864bbc2 | 689 | if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { |
def6c4e2 AA |
690 | pr_err("ACPI call to get ECO led failed\n"); |
691 | return LED_OFF; | |
692 | } | |
693 | ||
694 | return out[2] ? LED_FULL : LED_OFF; | |
695 | } | |
696 | ||
697 | static void toshiba_eco_mode_set_status(struct led_classdev *cdev, | |
698 | enum led_brightness brightness) | |
699 | { | |
700 | struct toshiba_acpi_dev *dev = container_of(cdev, | |
701 | struct toshiba_acpi_dev, eco_led); | |
258c5903 AA |
702 | u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 }; |
703 | u32 out[TCI_WORDS]; | |
def6c4e2 AA |
704 | acpi_status status; |
705 | ||
706 | /* Switch the Eco Mode led on/off */ | |
707 | in[2] = (brightness) ? 1 : 0; | |
258c5903 | 708 | status = tci_raw(dev, in, out); |
1864bbc2 | 709 | if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { |
def6c4e2 AA |
710 | pr_err("ACPI call to set ECO led failed\n"); |
711 | return; | |
712 | } | |
713 | } | |
ea6b31f4 | 714 | |
5a2813e9 AA |
715 | /* Accelerometer support */ |
716 | static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev) | |
717 | { | |
258c5903 AA |
718 | u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 }; |
719 | u32 out[TCI_WORDS]; | |
5a2813e9 AA |
720 | acpi_status status; |
721 | ||
722 | /* Check if the accelerometer call exists, | |
723 | * this call also serves as initialization | |
724 | */ | |
258c5903 | 725 | status = tci_raw(dev, in, out); |
1864bbc2 | 726 | if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { |
5a2813e9 AA |
727 | pr_err("ACPI call to query the accelerometer failed\n"); |
728 | return -EIO; | |
1864bbc2 AA |
729 | } else if (out[0] == TOS_DATA_NOT_AVAILABLE || |
730 | out[0] == TOS_NOT_INITIALIZED) { | |
5a2813e9 AA |
731 | pr_err("Accelerometer not initialized\n"); |
732 | return -EIO; | |
1864bbc2 | 733 | } else if (out[0] == TOS_NOT_SUPPORTED) { |
5a2813e9 AA |
734 | pr_info("Accelerometer not supported\n"); |
735 | return -ENODEV; | |
736 | } | |
737 | ||
738 | return 0; | |
739 | } | |
740 | ||
741 | static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev, | |
742 | u32 *xy, u32 *z) | |
743 | { | |
258c5903 AA |
744 | u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 }; |
745 | u32 out[TCI_WORDS]; | |
5a2813e9 AA |
746 | acpi_status status; |
747 | ||
748 | /* Check the Accelerometer status */ | |
258c5903 | 749 | status = tci_raw(dev, in, out); |
1864bbc2 | 750 | if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { |
5a2813e9 AA |
751 | pr_err("ACPI call to query the accelerometer failed\n"); |
752 | return -EIO; | |
753 | } | |
754 | ||
755 | *xy = out[2]; | |
756 | *z = out[4]; | |
757 | ||
758 | return 0; | |
759 | } | |
def6c4e2 | 760 | |
c41a40c5 | 761 | /* Bluetooth rfkill handlers */ |
762 | ||
135740de | 763 | static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present) |
c41a40c5 | 764 | { |
765 | u32 hci_result; | |
766 | u32 value, value2; | |
767 | ||
768 | value = 0; | |
769 | value2 = 0; | |
135740de | 770 | hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result); |
1864bbc2 | 771 | if (hci_result == TOS_SUCCESS) |
c41a40c5 | 772 | *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false; |
773 | ||
774 | return hci_result; | |
775 | } | |
776 | ||
135740de | 777 | static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state) |
c41a40c5 | 778 | { |
779 | u32 hci_result; | |
780 | u32 value, value2; | |
781 | ||
782 | value = 0; | |
783 | value2 = 0x0001; | |
135740de | 784 | hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result); |
c41a40c5 | 785 | |
786 | *radio_state = value & HCI_WIRELESS_KILL_SWITCH; | |
787 | return hci_result; | |
788 | } | |
789 | ||
19d337df | 790 | static int bt_rfkill_set_block(void *data, bool blocked) |
c41a40c5 | 791 | { |
19d337df | 792 | struct toshiba_acpi_dev *dev = data; |
c41a40c5 | 793 | u32 result1, result2; |
794 | u32 value; | |
19d337df | 795 | int err; |
c41a40c5 | 796 | bool radio_state; |
c41a40c5 | 797 | |
19d337df | 798 | value = (blocked == false); |
c41a40c5 | 799 | |
19d337df | 800 | mutex_lock(&dev->mutex); |
1864bbc2 | 801 | if (hci_get_radio_state(dev, &radio_state) != TOS_SUCCESS) { |
32bcd5cb | 802 | err = -EIO; |
19d337df JB |
803 | goto out; |
804 | } | |
c41a40c5 | 805 | |
19d337df JB |
806 | if (!radio_state) { |
807 | err = 0; | |
808 | goto out; | |
c41a40c5 | 809 | } |
810 | ||
135740de SF |
811 | hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1); |
812 | hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2); | |
c41a40c5 | 813 | |
1864bbc2 | 814 | if (result1 != TOS_SUCCESS || result2 != TOS_SUCCESS) |
32bcd5cb | 815 | err = -EIO; |
19d337df JB |
816 | else |
817 | err = 0; | |
818 | out: | |
819 | mutex_unlock(&dev->mutex); | |
820 | return err; | |
c41a40c5 | 821 | } |
822 | ||
19d337df | 823 | static void bt_rfkill_poll(struct rfkill *rfkill, void *data) |
c41a40c5 | 824 | { |
c41a40c5 | 825 | bool new_rfk_state; |
826 | bool value; | |
827 | u32 hci_result; | |
19d337df JB |
828 | struct toshiba_acpi_dev *dev = data; |
829 | ||
830 | mutex_lock(&dev->mutex); | |
c41a40c5 | 831 | |
135740de | 832 | hci_result = hci_get_radio_state(dev, &value); |
1864bbc2 | 833 | if (hci_result != TOS_SUCCESS) { |
19d337df JB |
834 | /* Can't do anything useful */ |
835 | mutex_unlock(&dev->mutex); | |
82e7784f | 836 | return; |
19d337df | 837 | } |
c41a40c5 | 838 | |
839 | new_rfk_state = value; | |
840 | ||
c41a40c5 | 841 | mutex_unlock(&dev->mutex); |
842 | ||
19d337df JB |
843 | if (rfkill_set_hw_state(rfkill, !new_rfk_state)) |
844 | bt_rfkill_set_block(data, true); | |
c41a40c5 | 845 | } |
846 | ||
19d337df JB |
847 | static const struct rfkill_ops toshiba_rfk_ops = { |
848 | .set_block = bt_rfkill_set_block, | |
849 | .poll = bt_rfkill_poll, | |
850 | }; | |
851 | ||
121b7b0d AI |
852 | static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled) |
853 | { | |
854 | u32 hci_result; | |
855 | u32 status; | |
856 | ||
857 | hci_read1(dev, HCI_TR_BACKLIGHT, &status, &hci_result); | |
858 | *enabled = !status; | |
1864bbc2 | 859 | return hci_result == TOS_SUCCESS ? 0 : -EIO; |
121b7b0d AI |
860 | } |
861 | ||
862 | static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable) | |
863 | { | |
864 | u32 hci_result; | |
865 | u32 value = !enable; | |
866 | ||
867 | hci_write1(dev, HCI_TR_BACKLIGHT, value, &hci_result); | |
1864bbc2 | 868 | return hci_result == TOS_SUCCESS ? 0 : -EIO; |
121b7b0d AI |
869 | } |
870 | ||
4be44fcd | 871 | static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ; |
1da177e4 | 872 | |
62cce752 | 873 | static int __get_lcd_brightness(struct toshiba_acpi_dev *dev) |
1da177e4 LT |
874 | { |
875 | u32 hci_result; | |
876 | u32 value; | |
121b7b0d AI |
877 | int brightness = 0; |
878 | ||
879 | if (dev->tr_backlight_supported) { | |
880 | bool enabled; | |
881 | int ret = get_tr_backlight_status(dev, &enabled); | |
882 | if (ret) | |
883 | return ret; | |
884 | if (enabled) | |
885 | return 0; | |
886 | brightness++; | |
887 | } | |
1da177e4 | 888 | |
135740de | 889 | hci_read1(dev, HCI_LCD_BRIGHTNESS, &value, &hci_result); |
1864bbc2 | 890 | if (hci_result == TOS_SUCCESS) |
121b7b0d | 891 | return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT); |
32bcd5cb SF |
892 | |
893 | return -EIO; | |
c9263557 HM |
894 | } |
895 | ||
62cce752 SF |
896 | static int get_lcd_brightness(struct backlight_device *bd) |
897 | { | |
898 | struct toshiba_acpi_dev *dev = bl_get_data(bd); | |
899 | return __get_lcd_brightness(dev); | |
900 | } | |
901 | ||
936c8bcd | 902 | static int lcd_proc_show(struct seq_file *m, void *v) |
c9263557 | 903 | { |
135740de SF |
904 | struct toshiba_acpi_dev *dev = m->private; |
905 | int value; | |
121b7b0d | 906 | int levels; |
135740de SF |
907 | |
908 | if (!dev->backlight_dev) | |
909 | return -ENODEV; | |
c9263557 | 910 | |
121b7b0d | 911 | levels = dev->backlight_dev->props.max_brightness + 1; |
62cce752 | 912 | value = get_lcd_brightness(dev->backlight_dev); |
c9263557 | 913 | if (value >= 0) { |
936c8bcd | 914 | seq_printf(m, "brightness: %d\n", value); |
121b7b0d | 915 | seq_printf(m, "brightness_levels: %d\n", levels); |
32bcd5cb | 916 | return 0; |
1da177e4 LT |
917 | } |
918 | ||
32bcd5cb SF |
919 | pr_err("Error reading LCD brightness\n"); |
920 | return -EIO; | |
936c8bcd AD |
921 | } |
922 | ||
923 | static int lcd_proc_open(struct inode *inode, struct file *file) | |
924 | { | |
d9dda78b | 925 | return single_open(file, lcd_proc_show, PDE_DATA(inode)); |
1da177e4 LT |
926 | } |
927 | ||
62cce752 | 928 | static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value) |
c9263557 | 929 | { |
258c5903 AA |
930 | u32 in[TCI_WORDS] = { HCI_SET, HCI_LCD_BRIGHTNESS, 0, 0, 0, 0 }; |
931 | u32 out[TCI_WORDS]; | |
f6aac652 | 932 | acpi_status status; |
c9263557 | 933 | |
121b7b0d AI |
934 | if (dev->tr_backlight_supported) { |
935 | bool enable = !value; | |
936 | int ret = set_tr_backlight_status(dev, enable); | |
937 | if (ret) | |
938 | return ret; | |
939 | if (value) | |
940 | value--; | |
941 | } | |
942 | ||
f6aac652 | 943 | in[2] = value << HCI_LCD_BRIGHTNESS_SHIFT; |
258c5903 | 944 | status = tci_raw(dev, in, out); |
1864bbc2 | 945 | if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { |
f6aac652 AA |
946 | pr_err("ACPI call to set brightness failed"); |
947 | return -EIO; | |
948 | } | |
949 | /* Extra check for "incomplete" backlight method, where the AML code | |
1864bbc2 | 950 | * doesn't check for HCI_SET or HCI_GET and returns TOS_SUCCESS, |
f6aac652 AA |
951 | * the actual brightness, and in some cases the max brightness. |
952 | */ | |
953 | if (out[2] > 0 || out[3] == 0xE000) | |
954 | return -ENODEV; | |
955 | ||
1864bbc2 | 956 | return out[0] == TOS_SUCCESS ? 0 : -EIO; |
c9263557 HM |
957 | } |
958 | ||
959 | static int set_lcd_status(struct backlight_device *bd) | |
960 | { | |
135740de | 961 | struct toshiba_acpi_dev *dev = bl_get_data(bd); |
62cce752 | 962 | return set_lcd_brightness(dev, bd->props.brightness); |
c9263557 HM |
963 | } |
964 | ||
936c8bcd AD |
965 | static ssize_t lcd_proc_write(struct file *file, const char __user *buf, |
966 | size_t count, loff_t *pos) | |
1da177e4 | 967 | { |
d9dda78b | 968 | struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); |
936c8bcd AD |
969 | char cmd[42]; |
970 | size_t len; | |
1da177e4 | 971 | int value; |
c8af57eb | 972 | int ret; |
121b7b0d | 973 | int levels = dev->backlight_dev->props.max_brightness + 1; |
1da177e4 | 974 | |
936c8bcd AD |
975 | len = min(count, sizeof(cmd) - 1); |
976 | if (copy_from_user(cmd, buf, len)) | |
977 | return -EFAULT; | |
978 | cmd[len] = '\0'; | |
979 | ||
980 | if (sscanf(cmd, " brightness : %i", &value) == 1 && | |
121b7b0d | 981 | value >= 0 && value < levels) { |
62cce752 | 982 | ret = set_lcd_brightness(dev, value); |
c8af57eb MO |
983 | if (ret == 0) |
984 | ret = count; | |
985 | } else { | |
c9263557 | 986 | ret = -EINVAL; |
c8af57eb | 987 | } |
c9263557 | 988 | return ret; |
1da177e4 LT |
989 | } |
990 | ||
936c8bcd AD |
991 | static const struct file_operations lcd_proc_fops = { |
992 | .owner = THIS_MODULE, | |
993 | .open = lcd_proc_open, | |
994 | .read = seq_read, | |
995 | .llseek = seq_lseek, | |
996 | .release = single_release, | |
997 | .write = lcd_proc_write, | |
998 | }; | |
999 | ||
36d03f93 SF |
1000 | static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status) |
1001 | { | |
1002 | u32 hci_result; | |
1003 | ||
1004 | hci_read1(dev, HCI_VIDEO_OUT, status, &hci_result); | |
1864bbc2 | 1005 | return hci_result == TOS_SUCCESS ? 0 : -EIO; |
36d03f93 SF |
1006 | } |
1007 | ||
936c8bcd | 1008 | static int video_proc_show(struct seq_file *m, void *v) |
1da177e4 | 1009 | { |
135740de | 1010 | struct toshiba_acpi_dev *dev = m->private; |
1da177e4 | 1011 | u32 value; |
36d03f93 | 1012 | int ret; |
1da177e4 | 1013 | |
36d03f93 SF |
1014 | ret = get_video_status(dev, &value); |
1015 | if (!ret) { | |
1da177e4 LT |
1016 | int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0; |
1017 | int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0; | |
4be44fcd | 1018 | int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0; |
936c8bcd AD |
1019 | seq_printf(m, "lcd_out: %d\n", is_lcd); |
1020 | seq_printf(m, "crt_out: %d\n", is_crt); | |
1021 | seq_printf(m, "tv_out: %d\n", is_tv); | |
1da177e4 LT |
1022 | } |
1023 | ||
36d03f93 | 1024 | return ret; |
1da177e4 LT |
1025 | } |
1026 | ||
936c8bcd | 1027 | static int video_proc_open(struct inode *inode, struct file *file) |
1da177e4 | 1028 | { |
d9dda78b | 1029 | return single_open(file, video_proc_show, PDE_DATA(inode)); |
936c8bcd AD |
1030 | } |
1031 | ||
1032 | static ssize_t video_proc_write(struct file *file, const char __user *buf, | |
1033 | size_t count, loff_t *pos) | |
1034 | { | |
d9dda78b | 1035 | struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); |
936c8bcd | 1036 | char *cmd, *buffer; |
36d03f93 | 1037 | int ret; |
1da177e4 LT |
1038 | int value; |
1039 | int remain = count; | |
1040 | int lcd_out = -1; | |
1041 | int crt_out = -1; | |
1042 | int tv_out = -1; | |
b4482a4b | 1043 | u32 video_out; |
1da177e4 | 1044 | |
936c8bcd AD |
1045 | cmd = kmalloc(count + 1, GFP_KERNEL); |
1046 | if (!cmd) | |
1047 | return -ENOMEM; | |
1048 | if (copy_from_user(cmd, buf, count)) { | |
1049 | kfree(cmd); | |
1050 | return -EFAULT; | |
1051 | } | |
1052 | cmd[count] = '\0'; | |
1053 | ||
1054 | buffer = cmd; | |
1055 | ||
1da177e4 LT |
1056 | /* scan expression. Multiple expressions may be delimited with ; |
1057 | * | |
1058 | * NOTE: to keep scanning simple, invalid fields are ignored | |
1059 | */ | |
1060 | while (remain) { | |
1061 | if (sscanf(buffer, " lcd_out : %i", &value) == 1) | |
1062 | lcd_out = value & 1; | |
1063 | else if (sscanf(buffer, " crt_out : %i", &value) == 1) | |
1064 | crt_out = value & 1; | |
1065 | else if (sscanf(buffer, " tv_out : %i", &value) == 1) | |
1066 | tv_out = value & 1; | |
1067 | /* advance to one character past the next ; */ | |
1068 | do { | |
1069 | ++buffer; | |
1070 | --remain; | |
1071 | } | |
4be44fcd | 1072 | while (remain && *(buffer - 1) != ';'); |
1da177e4 LT |
1073 | } |
1074 | ||
936c8bcd AD |
1075 | kfree(cmd); |
1076 | ||
36d03f93 SF |
1077 | ret = get_video_status(dev, &video_out); |
1078 | if (!ret) { | |
9e113e00 | 1079 | unsigned int new_video_out = video_out; |
1da177e4 LT |
1080 | if (lcd_out != -1) |
1081 | _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out); | |
1082 | if (crt_out != -1) | |
1083 | _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out); | |
1084 | if (tv_out != -1) | |
1085 | _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out); | |
1086 | /* To avoid unnecessary video disruption, only write the new | |
1087 | * video setting if something changed. */ | |
1088 | if (new_video_out != video_out) | |
32bcd5cb | 1089 | ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out); |
1da177e4 LT |
1090 | } |
1091 | ||
32bcd5cb | 1092 | return ret ? ret : count; |
1da177e4 LT |
1093 | } |
1094 | ||
936c8bcd AD |
1095 | static const struct file_operations video_proc_fops = { |
1096 | .owner = THIS_MODULE, | |
1097 | .open = video_proc_open, | |
1098 | .read = seq_read, | |
1099 | .llseek = seq_lseek, | |
1100 | .release = single_release, | |
1101 | .write = video_proc_write, | |
1102 | }; | |
1103 | ||
36d03f93 SF |
1104 | static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status) |
1105 | { | |
1106 | u32 hci_result; | |
1107 | ||
1108 | hci_read1(dev, HCI_FAN, status, &hci_result); | |
1864bbc2 | 1109 | return hci_result == TOS_SUCCESS ? 0 : -EIO; |
36d03f93 SF |
1110 | } |
1111 | ||
936c8bcd | 1112 | static int fan_proc_show(struct seq_file *m, void *v) |
1da177e4 | 1113 | { |
135740de | 1114 | struct toshiba_acpi_dev *dev = m->private; |
36d03f93 | 1115 | int ret; |
1da177e4 LT |
1116 | u32 value; |
1117 | ||
36d03f93 SF |
1118 | ret = get_fan_status(dev, &value); |
1119 | if (!ret) { | |
936c8bcd | 1120 | seq_printf(m, "running: %d\n", (value > 0)); |
135740de | 1121 | seq_printf(m, "force_on: %d\n", dev->force_fan); |
1da177e4 LT |
1122 | } |
1123 | ||
36d03f93 | 1124 | return ret; |
936c8bcd AD |
1125 | } |
1126 | ||
1127 | static int fan_proc_open(struct inode *inode, struct file *file) | |
1128 | { | |
d9dda78b | 1129 | return single_open(file, fan_proc_show, PDE_DATA(inode)); |
1da177e4 LT |
1130 | } |
1131 | ||
936c8bcd AD |
1132 | static ssize_t fan_proc_write(struct file *file, const char __user *buf, |
1133 | size_t count, loff_t *pos) | |
1da177e4 | 1134 | { |
d9dda78b | 1135 | struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); |
936c8bcd AD |
1136 | char cmd[42]; |
1137 | size_t len; | |
1da177e4 LT |
1138 | int value; |
1139 | u32 hci_result; | |
1140 | ||
936c8bcd AD |
1141 | len = min(count, sizeof(cmd) - 1); |
1142 | if (copy_from_user(cmd, buf, len)) | |
1143 | return -EFAULT; | |
1144 | cmd[len] = '\0'; | |
1145 | ||
1146 | if (sscanf(cmd, " force_on : %i", &value) == 1 && | |
4be44fcd | 1147 | value >= 0 && value <= 1) { |
135740de | 1148 | hci_write1(dev, HCI_FAN, value, &hci_result); |
1864bbc2 | 1149 | if (hci_result != TOS_SUCCESS) |
32bcd5cb | 1150 | return -EIO; |
1da177e4 | 1151 | else |
135740de | 1152 | dev->force_fan = value; |
1da177e4 LT |
1153 | } else { |
1154 | return -EINVAL; | |
1155 | } | |
1156 | ||
1157 | return count; | |
1158 | } | |
1159 | ||
936c8bcd AD |
1160 | static const struct file_operations fan_proc_fops = { |
1161 | .owner = THIS_MODULE, | |
1162 | .open = fan_proc_open, | |
1163 | .read = seq_read, | |
1164 | .llseek = seq_lseek, | |
1165 | .release = single_release, | |
1166 | .write = fan_proc_write, | |
1167 | }; | |
1168 | ||
1169 | static int keys_proc_show(struct seq_file *m, void *v) | |
1da177e4 | 1170 | { |
135740de | 1171 | struct toshiba_acpi_dev *dev = m->private; |
1da177e4 LT |
1172 | u32 hci_result; |
1173 | u32 value; | |
1174 | ||
11948b93 | 1175 | if (!dev->key_event_valid && dev->system_event_supported) { |
135740de | 1176 | hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result); |
1864bbc2 | 1177 | if (hci_result == TOS_SUCCESS) { |
135740de SF |
1178 | dev->key_event_valid = 1; |
1179 | dev->last_key_event = value; | |
1864bbc2 | 1180 | } else if (hci_result == TOS_FIFO_EMPTY) { |
1da177e4 | 1181 | /* better luck next time */ |
1864bbc2 | 1182 | } else if (hci_result == TOS_NOT_SUPPORTED) { |
1da177e4 LT |
1183 | /* This is a workaround for an unresolved issue on |
1184 | * some machines where system events sporadically | |
1185 | * become disabled. */ | |
135740de | 1186 | hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result); |
7e33460d | 1187 | pr_notice("Re-enabled hotkeys\n"); |
1da177e4 | 1188 | } else { |
7e33460d | 1189 | pr_err("Error reading hotkey status\n"); |
32bcd5cb | 1190 | return -EIO; |
1da177e4 LT |
1191 | } |
1192 | } | |
1193 | ||
135740de SF |
1194 | seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid); |
1195 | seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event); | |
936c8bcd AD |
1196 | return 0; |
1197 | } | |
1da177e4 | 1198 | |
936c8bcd AD |
1199 | static int keys_proc_open(struct inode *inode, struct file *file) |
1200 | { | |
d9dda78b | 1201 | return single_open(file, keys_proc_show, PDE_DATA(inode)); |
1da177e4 LT |
1202 | } |
1203 | ||
936c8bcd AD |
1204 | static ssize_t keys_proc_write(struct file *file, const char __user *buf, |
1205 | size_t count, loff_t *pos) | |
1da177e4 | 1206 | { |
d9dda78b | 1207 | struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); |
936c8bcd AD |
1208 | char cmd[42]; |
1209 | size_t len; | |
1da177e4 LT |
1210 | int value; |
1211 | ||
936c8bcd AD |
1212 | len = min(count, sizeof(cmd) - 1); |
1213 | if (copy_from_user(cmd, buf, len)) | |
1214 | return -EFAULT; | |
1215 | cmd[len] = '\0'; | |
1216 | ||
1217 | if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) { | |
135740de | 1218 | dev->key_event_valid = 0; |
1da177e4 LT |
1219 | } else { |
1220 | return -EINVAL; | |
1221 | } | |
1222 | ||
1223 | return count; | |
1224 | } | |
1225 | ||
936c8bcd AD |
1226 | static const struct file_operations keys_proc_fops = { |
1227 | .owner = THIS_MODULE, | |
1228 | .open = keys_proc_open, | |
1229 | .read = seq_read, | |
1230 | .llseek = seq_lseek, | |
1231 | .release = single_release, | |
1232 | .write = keys_proc_write, | |
1233 | }; | |
1234 | ||
1235 | static int version_proc_show(struct seq_file *m, void *v) | |
1da177e4 | 1236 | { |
936c8bcd AD |
1237 | seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION); |
1238 | seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION); | |
1239 | return 0; | |
1da177e4 LT |
1240 | } |
1241 | ||
936c8bcd AD |
1242 | static int version_proc_open(struct inode *inode, struct file *file) |
1243 | { | |
d9dda78b | 1244 | return single_open(file, version_proc_show, PDE_DATA(inode)); |
936c8bcd AD |
1245 | } |
1246 | ||
1247 | static const struct file_operations version_proc_fops = { | |
1248 | .owner = THIS_MODULE, | |
1249 | .open = version_proc_open, | |
1250 | .read = seq_read, | |
1251 | .llseek = seq_lseek, | |
1252 | .release = single_release, | |
1253 | }; | |
1254 | ||
1da177e4 LT |
1255 | /* proc and module init |
1256 | */ | |
1257 | ||
1258 | #define PROC_TOSHIBA "toshiba" | |
1259 | ||
b859f159 | 1260 | static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev) |
1da177e4 | 1261 | { |
36d03f93 SF |
1262 | if (dev->backlight_dev) |
1263 | proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, | |
1264 | &lcd_proc_fops, dev); | |
1265 | if (dev->video_supported) | |
1266 | proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, | |
1267 | &video_proc_fops, dev); | |
1268 | if (dev->fan_supported) | |
1269 | proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, | |
1270 | &fan_proc_fops, dev); | |
1271 | if (dev->hotkey_dev) | |
1272 | proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, | |
1273 | &keys_proc_fops, dev); | |
135740de SF |
1274 | proc_create_data("version", S_IRUGO, toshiba_proc_dir, |
1275 | &version_proc_fops, dev); | |
1da177e4 LT |
1276 | } |
1277 | ||
36d03f93 | 1278 | static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev) |
1da177e4 | 1279 | { |
36d03f93 SF |
1280 | if (dev->backlight_dev) |
1281 | remove_proc_entry("lcd", toshiba_proc_dir); | |
1282 | if (dev->video_supported) | |
1283 | remove_proc_entry("video", toshiba_proc_dir); | |
1284 | if (dev->fan_supported) | |
1285 | remove_proc_entry("fan", toshiba_proc_dir); | |
1286 | if (dev->hotkey_dev) | |
1287 | remove_proc_entry("keys", toshiba_proc_dir); | |
936c8bcd | 1288 | remove_proc_entry("version", toshiba_proc_dir); |
1da177e4 LT |
1289 | } |
1290 | ||
acc2472e | 1291 | static const struct backlight_ops toshiba_backlight_data = { |
121b7b0d | 1292 | .options = BL_CORE_SUSPENDRESUME, |
62cce752 SF |
1293 | .get_brightness = get_lcd_brightness, |
1294 | .update_status = set_lcd_status, | |
c9263557 | 1295 | }; |
ea6b31f4 | 1296 | |
360f0f39 AA |
1297 | /* |
1298 | * Sysfs files | |
1299 | */ | |
93f8c16d AA |
1300 | static ssize_t toshiba_kbd_bl_mode_store(struct device *dev, |
1301 | struct device_attribute *attr, | |
1302 | const char *buf, size_t count); | |
1303 | static ssize_t toshiba_kbd_bl_mode_show(struct device *dev, | |
1304 | struct device_attribute *attr, | |
1305 | char *buf); | |
1306 | static ssize_t toshiba_kbd_type_show(struct device *dev, | |
1307 | struct device_attribute *attr, | |
1308 | char *buf); | |
1309 | static ssize_t toshiba_available_kbd_modes_show(struct device *dev, | |
1310 | struct device_attribute *attr, | |
1311 | char *buf); | |
1312 | static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev, | |
1313 | struct device_attribute *attr, | |
1314 | const char *buf, size_t count); | |
1315 | static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev, | |
1316 | struct device_attribute *attr, | |
1317 | char *buf); | |
1318 | static ssize_t toshiba_touchpad_store(struct device *dev, | |
1319 | struct device_attribute *attr, | |
1320 | const char *buf, size_t count); | |
1321 | static ssize_t toshiba_touchpad_show(struct device *dev, | |
1322 | struct device_attribute *attr, | |
1323 | char *buf); | |
1324 | static ssize_t toshiba_position_show(struct device *dev, | |
1325 | struct device_attribute *attr, | |
1326 | char *buf); | |
1327 | ||
1328 | static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR, | |
1329 | toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store); | |
1330 | static DEVICE_ATTR(kbd_type, S_IRUGO, toshiba_kbd_type_show, NULL); | |
1331 | static DEVICE_ATTR(available_kbd_modes, S_IRUGO, | |
1332 | toshiba_available_kbd_modes_show, NULL); | |
1333 | static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR, | |
1334 | toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store); | |
1335 | static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR, | |
1336 | toshiba_touchpad_show, toshiba_touchpad_store); | |
1337 | static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL); | |
1338 | ||
1339 | static struct attribute *toshiba_attributes[] = { | |
1340 | &dev_attr_kbd_backlight_mode.attr, | |
1341 | &dev_attr_kbd_type.attr, | |
1342 | &dev_attr_available_kbd_modes.attr, | |
1343 | &dev_attr_kbd_backlight_timeout.attr, | |
1344 | &dev_attr_touchpad.attr, | |
1345 | &dev_attr_position.attr, | |
1346 | NULL, | |
1347 | }; | |
1348 | ||
1349 | static umode_t toshiba_sysfs_is_visible(struct kobject *, | |
1350 | struct attribute *, int); | |
1351 | ||
1352 | static struct attribute_group toshiba_attr_group = { | |
1353 | .is_visible = toshiba_sysfs_is_visible, | |
1354 | .attrs = toshiba_attributes, | |
1355 | }; | |
360f0f39 AA |
1356 | |
1357 | static ssize_t toshiba_kbd_bl_mode_store(struct device *dev, | |
1358 | struct device_attribute *attr, | |
1359 | const char *buf, size_t count) | |
1360 | { | |
1361 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
aeaac098 DC |
1362 | int mode; |
1363 | int time; | |
1364 | int ret; | |
1365 | ||
360f0f39 | 1366 | |
aeaac098 DC |
1367 | ret = kstrtoint(buf, 0, &mode); |
1368 | if (ret) | |
1369 | return ret; | |
93f8c16d AA |
1370 | |
1371 | /* Check for supported modes depending on keyboard backlight type */ | |
1372 | if (toshiba->kbd_type == 1) { | |
1373 | /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */ | |
1374 | if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO) | |
1375 | return -EINVAL; | |
1376 | } else if (toshiba->kbd_type == 2) { | |
1377 | /* Type 2 doesn't support SCI_KBD_MODE_FNZ */ | |
1378 | if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON && | |
1379 | mode != SCI_KBD_MODE_OFF) | |
1380 | return -EINVAL; | |
1381 | } | |
360f0f39 AA |
1382 | |
1383 | /* Set the Keyboard Backlight Mode where: | |
360f0f39 AA |
1384 | * Auto - KBD backlight turns off automatically in given time |
1385 | * FN-Z - KBD backlight "toggles" when hotkey pressed | |
93f8c16d AA |
1386 | * ON - KBD backlight is always on |
1387 | * OFF - KBD backlight is always off | |
360f0f39 | 1388 | */ |
93f8c16d AA |
1389 | |
1390 | /* Only make a change if the actual mode has changed */ | |
aeaac098 | 1391 | if (toshiba->kbd_mode != mode) { |
93f8c16d | 1392 | /* Shift the time to "base time" (0x3c0000 == 60 seconds) */ |
360f0f39 | 1393 | time = toshiba->kbd_time << HCI_MISC_SHIFT; |
93f8c16d AA |
1394 | |
1395 | /* OR the "base time" to the actual method format */ | |
1396 | if (toshiba->kbd_type == 1) { | |
1397 | /* Type 1 requires the current mode */ | |
1398 | time |= toshiba->kbd_mode; | |
1399 | } else if (toshiba->kbd_type == 2) { | |
1400 | /* Type 2 requires the desired mode */ | |
1401 | time |= mode; | |
1402 | } | |
1403 | ||
aeaac098 DC |
1404 | ret = toshiba_kbd_illum_status_set(toshiba, time); |
1405 | if (ret) | |
1406 | return ret; | |
93f8c16d AA |
1407 | |
1408 | /* Update sysfs entries on successful mode change*/ | |
1409 | ret = sysfs_update_group(&toshiba->acpi_dev->dev.kobj, | |
1410 | &toshiba_attr_group); | |
1411 | if (ret) | |
1412 | return ret; | |
1413 | ||
360f0f39 AA |
1414 | toshiba->kbd_mode = mode; |
1415 | } | |
1416 | ||
1417 | return count; | |
1418 | } | |
1419 | ||
1420 | static ssize_t toshiba_kbd_bl_mode_show(struct device *dev, | |
1421 | struct device_attribute *attr, | |
1422 | char *buf) | |
1423 | { | |
1424 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1425 | u32 time; | |
1426 | ||
1427 | if (toshiba_kbd_illum_status_get(toshiba, &time) < 0) | |
1428 | return -EIO; | |
1429 | ||
93f8c16d AA |
1430 | return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK); |
1431 | } | |
1432 | ||
1433 | static ssize_t toshiba_kbd_type_show(struct device *dev, | |
1434 | struct device_attribute *attr, | |
1435 | char *buf) | |
1436 | { | |
1437 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1438 | ||
1439 | return sprintf(buf, "%d\n", toshiba->kbd_type); | |
1440 | } | |
1441 | ||
1442 | static ssize_t toshiba_available_kbd_modes_show(struct device *dev, | |
1443 | struct device_attribute *attr, | |
1444 | char *buf) | |
1445 | { | |
1446 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1447 | ||
1448 | if (toshiba->kbd_type == 1) | |
1449 | return sprintf(buf, "%x %x\n", | |
1450 | SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO); | |
1451 | ||
1452 | return sprintf(buf, "%x %x %x\n", | |
1453 | SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF); | |
360f0f39 AA |
1454 | } |
1455 | ||
1456 | static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev, | |
1457 | struct device_attribute *attr, | |
1458 | const char *buf, size_t count) | |
1459 | { | |
1460 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1461 | int time = -1; | |
1462 | ||
1463 | if (sscanf(buf, "%i", &time) != 1 && (time < 0 || time > 60)) | |
1464 | return -EINVAL; | |
1465 | ||
1466 | /* Set the Keyboard Backlight Timeout: 0-60 seconds */ | |
1467 | if (time != -1 && toshiba->kbd_time != time) { | |
1468 | time = time << HCI_MISC_SHIFT; | |
1469 | time = (toshiba->kbd_mode == SCI_KBD_MODE_AUTO) ? | |
1470 | time + 1 : time + 2; | |
1471 | if (toshiba_kbd_illum_status_set(toshiba, time) < 0) | |
1472 | return -EIO; | |
1473 | toshiba->kbd_time = time >> HCI_MISC_SHIFT; | |
1474 | } | |
1475 | ||
1476 | return count; | |
1477 | } | |
1478 | ||
1479 | static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev, | |
1480 | struct device_attribute *attr, | |
1481 | char *buf) | |
1482 | { | |
1483 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1484 | u32 time; | |
1485 | ||
1486 | if (toshiba_kbd_illum_status_get(toshiba, &time) < 0) | |
1487 | return -EIO; | |
1488 | ||
1489 | return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT); | |
1490 | } | |
ea6b31f4 | 1491 | |
9d8658ac AA |
1492 | static ssize_t toshiba_touchpad_store(struct device *dev, |
1493 | struct device_attribute *attr, | |
1494 | const char *buf, size_t count) | |
1495 | { | |
1496 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1497 | int state; | |
c8a41669 | 1498 | int ret; |
9d8658ac AA |
1499 | |
1500 | /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */ | |
c8a41669 AA |
1501 | ret = kstrtoint(buf, 0, &state); |
1502 | if (ret) | |
1503 | return ret; | |
1504 | if (state != 0 && state != 1) | |
1505 | return -EINVAL; | |
1506 | ||
1507 | ret = toshiba_touchpad_set(toshiba, state); | |
1508 | if (ret) | |
1509 | return ret; | |
9d8658ac AA |
1510 | |
1511 | return count; | |
1512 | } | |
1513 | ||
1514 | static ssize_t toshiba_touchpad_show(struct device *dev, | |
1515 | struct device_attribute *attr, char *buf) | |
1516 | { | |
1517 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1518 | u32 state; | |
1519 | int ret; | |
1520 | ||
1521 | ret = toshiba_touchpad_get(toshiba, &state); | |
1522 | if (ret < 0) | |
1523 | return ret; | |
1524 | ||
1525 | return sprintf(buf, "%i\n", state); | |
1526 | } | |
ea6b31f4 | 1527 | |
5a2813e9 AA |
1528 | static ssize_t toshiba_position_show(struct device *dev, |
1529 | struct device_attribute *attr, char *buf) | |
1530 | { | |
1531 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1532 | u32 xyval, zval, tmp; | |
1533 | u16 x, y, z; | |
1534 | int ret; | |
1535 | ||
1536 | xyval = zval = 0; | |
1537 | ret = toshiba_accelerometer_get(toshiba, &xyval, &zval); | |
1538 | if (ret < 0) | |
1539 | return ret; | |
1540 | ||
1541 | x = xyval & HCI_ACCEL_MASK; | |
1542 | tmp = xyval >> HCI_MISC_SHIFT; | |
1543 | y = tmp & HCI_ACCEL_MASK; | |
1544 | z = zval & HCI_ACCEL_MASK; | |
1545 | ||
1546 | return sprintf(buf, "%d %d %d\n", x, y, z); | |
1547 | } | |
360f0f39 | 1548 | |
360f0f39 AA |
1549 | static umode_t toshiba_sysfs_is_visible(struct kobject *kobj, |
1550 | struct attribute *attr, int idx) | |
1551 | { | |
1552 | struct device *dev = container_of(kobj, struct device, kobj); | |
1553 | struct toshiba_acpi_dev *drv = dev_get_drvdata(dev); | |
1554 | bool exists = true; | |
1555 | ||
1556 | if (attr == &dev_attr_kbd_backlight_mode.attr) | |
1557 | exists = (drv->kbd_illum_supported) ? true : false; | |
1558 | else if (attr == &dev_attr_kbd_backlight_timeout.attr) | |
1559 | exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false; | |
9d8658ac AA |
1560 | else if (attr == &dev_attr_touchpad.attr) |
1561 | exists = (drv->touchpad_supported) ? true : false; | |
5a2813e9 AA |
1562 | else if (attr == &dev_attr_position.attr) |
1563 | exists = (drv->accelerometer_supported) ? true : false; | |
360f0f39 AA |
1564 | |
1565 | return exists ? attr->mode : 0; | |
1566 | } | |
1567 | ||
29cd293f SF |
1568 | static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str, |
1569 | struct serio *port) | |
1570 | { | |
1571 | if (str & 0x20) | |
1572 | return false; | |
1573 | ||
1574 | if (unlikely(data == 0xe0)) | |
1575 | return false; | |
1576 | ||
1577 | if ((data & 0x7f) == TOS1900_FN_SCAN) { | |
1578 | schedule_work(&toshiba_acpi->hotkey_work); | |
1579 | return true; | |
1580 | } | |
1581 | ||
1582 | return false; | |
1583 | } | |
1584 | ||
1585 | static void toshiba_acpi_hotkey_work(struct work_struct *work) | |
1586 | { | |
1587 | acpi_handle ec_handle = ec_get_handle(); | |
1588 | acpi_status status; | |
1589 | ||
1590 | if (!ec_handle) | |
1591 | return; | |
1592 | ||
1593 | status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL); | |
1594 | if (ACPI_FAILURE(status)) | |
1595 | pr_err("ACPI NTFY method execution failed\n"); | |
1596 | } | |
1597 | ||
1598 | /* | |
1599 | * Returns hotkey scancode, or < 0 on failure. | |
1600 | */ | |
1601 | static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev) | |
1602 | { | |
74facaf7 | 1603 | unsigned long long value; |
29cd293f SF |
1604 | acpi_status status; |
1605 | ||
74facaf7 ZR |
1606 | status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO", |
1607 | NULL, &value); | |
1608 | if (ACPI_FAILURE(status)) { | |
29cd293f SF |
1609 | pr_err("ACPI INFO method execution failed\n"); |
1610 | return -EIO; | |
1611 | } | |
1612 | ||
74facaf7 | 1613 | return value; |
29cd293f SF |
1614 | } |
1615 | ||
1616 | static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev, | |
1617 | int scancode) | |
1618 | { | |
1619 | if (scancode == 0x100) | |
1620 | return; | |
1621 | ||
1622 | /* act on key press; ignore key release */ | |
1623 | if (scancode & 0x80) | |
1624 | return; | |
1625 | ||
1626 | if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true)) | |
1627 | pr_info("Unknown key %x\n", scancode); | |
1628 | } | |
1629 | ||
b859f159 | 1630 | static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) |
6335e4d5 MG |
1631 | { |
1632 | acpi_status status; | |
e2e19606 | 1633 | acpi_handle ec_handle; |
384a7cd9 | 1634 | int error; |
29cd293f | 1635 | u32 hci_result; |
fe808bfb | 1636 | const struct key_entry *keymap = toshiba_acpi_keymap; |
6335e4d5 | 1637 | |
135740de | 1638 | dev->hotkey_dev = input_allocate_device(); |
b222cca6 | 1639 | if (!dev->hotkey_dev) |
6335e4d5 | 1640 | return -ENOMEM; |
6335e4d5 | 1641 | |
135740de | 1642 | dev->hotkey_dev->name = "Toshiba input device"; |
6e02cc7e | 1643 | dev->hotkey_dev->phys = "toshiba_acpi/input0"; |
135740de | 1644 | dev->hotkey_dev->id.bustype = BUS_HOST; |
6335e4d5 | 1645 | |
fe808bfb TI |
1646 | if (dmi_check_system(toshiba_alt_keymap_dmi)) |
1647 | keymap = toshiba_acpi_alt_keymap; | |
1648 | error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL); | |
384a7cd9 DT |
1649 | if (error) |
1650 | goto err_free_dev; | |
1651 | ||
29cd293f SF |
1652 | /* |
1653 | * For some machines the SCI responsible for providing hotkey | |
1654 | * notification doesn't fire. We can trigger the notification | |
1655 | * whenever the Fn key is pressed using the NTFY method, if | |
1656 | * supported, so if it's present set up an i8042 key filter | |
1657 | * for this purpose. | |
1658 | */ | |
1659 | status = AE_ERROR; | |
1660 | ec_handle = ec_get_handle(); | |
e2e19606 | 1661 | if (ec_handle && acpi_has_method(ec_handle, "NTFY")) { |
29cd293f SF |
1662 | INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work); |
1663 | ||
1664 | error = i8042_install_filter(toshiba_acpi_i8042_filter); | |
1665 | if (error) { | |
1666 | pr_err("Error installing key filter\n"); | |
1667 | goto err_free_keymap; | |
1668 | } | |
1669 | ||
1670 | dev->ntfy_supported = 1; | |
1671 | } | |
1672 | ||
1673 | /* | |
1674 | * Determine hotkey query interface. Prefer using the INFO | |
1675 | * method when it is available. | |
1676 | */ | |
e2e19606 | 1677 | if (acpi_has_method(dev->acpi_dev->handle, "INFO")) |
29cd293f | 1678 | dev->info_supported = 1; |
e2e19606 | 1679 | else { |
29cd293f | 1680 | hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result); |
1864bbc2 | 1681 | if (hci_result == TOS_SUCCESS) |
29cd293f SF |
1682 | dev->system_event_supported = 1; |
1683 | } | |
1684 | ||
1685 | if (!dev->info_supported && !dev->system_event_supported) { | |
1686 | pr_warn("No hotkey query interface found\n"); | |
1687 | goto err_remove_filter; | |
1688 | } | |
1689 | ||
6e02cc7e | 1690 | status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB", NULL, NULL); |
384a7cd9 | 1691 | if (ACPI_FAILURE(status)) { |
7e33460d | 1692 | pr_info("Unable to enable hotkeys\n"); |
384a7cd9 | 1693 | error = -ENODEV; |
29cd293f | 1694 | goto err_remove_filter; |
6335e4d5 MG |
1695 | } |
1696 | ||
135740de | 1697 | error = input_register_device(dev->hotkey_dev); |
384a7cd9 | 1698 | if (error) { |
7e33460d | 1699 | pr_info("Unable to register input device\n"); |
29cd293f | 1700 | goto err_remove_filter; |
6335e4d5 MG |
1701 | } |
1702 | ||
29cd293f | 1703 | hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &hci_result); |
6335e4d5 | 1704 | return 0; |
384a7cd9 | 1705 | |
29cd293f SF |
1706 | err_remove_filter: |
1707 | if (dev->ntfy_supported) | |
1708 | i8042_remove_filter(toshiba_acpi_i8042_filter); | |
384a7cd9 | 1709 | err_free_keymap: |
135740de | 1710 | sparse_keymap_free(dev->hotkey_dev); |
384a7cd9 | 1711 | err_free_dev: |
135740de SF |
1712 | input_free_device(dev->hotkey_dev); |
1713 | dev->hotkey_dev = NULL; | |
384a7cd9 | 1714 | return error; |
6335e4d5 MG |
1715 | } |
1716 | ||
b859f159 | 1717 | static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev) |
62cce752 SF |
1718 | { |
1719 | struct backlight_properties props; | |
1720 | int brightness; | |
1721 | int ret; | |
121b7b0d | 1722 | bool enabled; |
62cce752 SF |
1723 | |
1724 | /* | |
1725 | * Some machines don't support the backlight methods at all, and | |
1726 | * others support it read-only. Either of these is pretty useless, | |
1727 | * so only register the backlight device if the backlight method | |
1728 | * supports both reads and writes. | |
1729 | */ | |
1730 | brightness = __get_lcd_brightness(dev); | |
1731 | if (brightness < 0) | |
1732 | return 0; | |
1733 | ret = set_lcd_brightness(dev, brightness); | |
1734 | if (ret) { | |
1735 | pr_debug("Backlight method is read-only, disabling backlight support\n"); | |
1736 | return 0; | |
1737 | } | |
1738 | ||
121b7b0d AI |
1739 | /* Determine whether or not BIOS supports transflective backlight */ |
1740 | ret = get_tr_backlight_status(dev, &enabled); | |
1741 | dev->tr_backlight_supported = !ret; | |
1742 | ||
53039f22 | 1743 | memset(&props, 0, sizeof(props)); |
62cce752 SF |
1744 | props.type = BACKLIGHT_PLATFORM; |
1745 | props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1; | |
62cce752 | 1746 | |
121b7b0d AI |
1747 | /* adding an extra level and having 0 change to transflective mode */ |
1748 | if (dev->tr_backlight_supported) | |
1749 | props.max_brightness++; | |
1750 | ||
62cce752 SF |
1751 | dev->backlight_dev = backlight_device_register("toshiba", |
1752 | &dev->acpi_dev->dev, | |
1753 | dev, | |
1754 | &toshiba_backlight_data, | |
1755 | &props); | |
1756 | if (IS_ERR(dev->backlight_dev)) { | |
1757 | ret = PTR_ERR(dev->backlight_dev); | |
1758 | pr_err("Could not register toshiba backlight device\n"); | |
1759 | dev->backlight_dev = NULL; | |
1760 | return ret; | |
1761 | } | |
1762 | ||
1763 | dev->backlight_dev->props.brightness = brightness; | |
1764 | return 0; | |
1765 | } | |
1766 | ||
51fac838 | 1767 | static int toshiba_acpi_remove(struct acpi_device *acpi_dev) |
c9263557 | 1768 | { |
135740de | 1769 | struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); |
6335e4d5 | 1770 | |
36d03f93 | 1771 | remove_toshiba_proc_entries(dev); |
ea6b31f4 | 1772 | |
360f0f39 AA |
1773 | if (dev->sysfs_created) |
1774 | sysfs_remove_group(&dev->acpi_dev->dev.kobj, | |
1775 | &toshiba_attr_group); | |
c41a40c5 | 1776 | |
29cd293f SF |
1777 | if (dev->ntfy_supported) { |
1778 | i8042_remove_filter(toshiba_acpi_i8042_filter); | |
1779 | cancel_work_sync(&dev->hotkey_work); | |
1780 | } | |
1781 | ||
135740de SF |
1782 | if (dev->hotkey_dev) { |
1783 | input_unregister_device(dev->hotkey_dev); | |
1784 | sparse_keymap_free(dev->hotkey_dev); | |
1785 | } | |
c9263557 | 1786 | |
135740de SF |
1787 | if (dev->bt_rfk) { |
1788 | rfkill_unregister(dev->bt_rfk); | |
1789 | rfkill_destroy(dev->bt_rfk); | |
1790 | } | |
c9263557 | 1791 | |
135740de SF |
1792 | if (dev->backlight_dev) |
1793 | backlight_device_unregister(dev->backlight_dev); | |
c9263557 | 1794 | |
36d03f93 | 1795 | if (dev->illumination_supported) |
135740de | 1796 | led_classdev_unregister(&dev->led_dev); |
ea6b31f4 | 1797 | |
360f0f39 AA |
1798 | if (dev->kbd_led_registered) |
1799 | led_classdev_unregister(&dev->kbd_led); | |
ea6b31f4 | 1800 | |
def6c4e2 AA |
1801 | if (dev->eco_supported) |
1802 | led_classdev_unregister(&dev->eco_led); | |
6c3f6e6c | 1803 | |
29cd293f SF |
1804 | if (toshiba_acpi) |
1805 | toshiba_acpi = NULL; | |
1806 | ||
135740de | 1807 | kfree(dev); |
c41a40c5 | 1808 | |
135740de | 1809 | return 0; |
c9263557 HM |
1810 | } |
1811 | ||
b859f159 | 1812 | static const char *find_hci_method(acpi_handle handle) |
a540d6b5 | 1813 | { |
e2e19606 | 1814 | if (acpi_has_method(handle, "GHCI")) |
a540d6b5 SF |
1815 | return "GHCI"; |
1816 | ||
e2e19606 | 1817 | if (acpi_has_method(handle, "SPFC")) |
a540d6b5 SF |
1818 | return "SPFC"; |
1819 | ||
1820 | return NULL; | |
1821 | } | |
1822 | ||
b859f159 | 1823 | static int toshiba_acpi_add(struct acpi_device *acpi_dev) |
1da177e4 | 1824 | { |
135740de | 1825 | struct toshiba_acpi_dev *dev; |
a540d6b5 | 1826 | const char *hci_method; |
36d03f93 | 1827 | u32 dummy; |
c41a40c5 | 1828 | bool bt_present; |
c41a40c5 | 1829 | int ret = 0; |
1da177e4 | 1830 | |
29cd293f SF |
1831 | if (toshiba_acpi) |
1832 | return -EBUSY; | |
1833 | ||
135740de SF |
1834 | pr_info("Toshiba Laptop ACPI Extras version %s\n", |
1835 | TOSHIBA_ACPI_VERSION); | |
1836 | ||
a540d6b5 SF |
1837 | hci_method = find_hci_method(acpi_dev->handle); |
1838 | if (!hci_method) { | |
1839 | pr_err("HCI interface not found\n"); | |
6e02cc7e | 1840 | return -ENODEV; |
a540d6b5 | 1841 | } |
6e02cc7e | 1842 | |
135740de SF |
1843 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
1844 | if (!dev) | |
1845 | return -ENOMEM; | |
1846 | dev->acpi_dev = acpi_dev; | |
a540d6b5 | 1847 | dev->method_hci = hci_method; |
135740de | 1848 | acpi_dev->driver_data = dev; |
360f0f39 | 1849 | dev_set_drvdata(&acpi_dev->dev, dev); |
fb9802fa | 1850 | |
6e02cc7e SF |
1851 | if (toshiba_acpi_setup_keyboard(dev)) |
1852 | pr_info("Unable to activate hotkeys\n"); | |
135740de SF |
1853 | |
1854 | mutex_init(&dev->mutex); | |
1da177e4 | 1855 | |
62cce752 SF |
1856 | ret = toshiba_acpi_setup_backlight(dev); |
1857 | if (ret) | |
135740de | 1858 | goto error; |
1da177e4 | 1859 | |
c41a40c5 | 1860 | /* Register rfkill switch for Bluetooth */ |
1864bbc2 | 1861 | if (hci_get_bt_present(dev, &bt_present) == TOS_SUCCESS && bt_present) { |
135740de SF |
1862 | dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth", |
1863 | &acpi_dev->dev, | |
1864 | RFKILL_TYPE_BLUETOOTH, | |
1865 | &toshiba_rfk_ops, | |
1866 | dev); | |
1867 | if (!dev->bt_rfk) { | |
7e33460d | 1868 | pr_err("unable to allocate rfkill device\n"); |
135740de SF |
1869 | ret = -ENOMEM; |
1870 | goto error; | |
c41a40c5 | 1871 | } |
1872 | ||
135740de | 1873 | ret = rfkill_register(dev->bt_rfk); |
c41a40c5 | 1874 | if (ret) { |
7e33460d | 1875 | pr_err("unable to register rfkill device\n"); |
135740de SF |
1876 | rfkill_destroy(dev->bt_rfk); |
1877 | goto error; | |
38aefbc5 | 1878 | } |
c41a40c5 | 1879 | } |
1880 | ||
135740de SF |
1881 | if (toshiba_illumination_available(dev)) { |
1882 | dev->led_dev.name = "toshiba::illumination"; | |
1883 | dev->led_dev.max_brightness = 1; | |
1884 | dev->led_dev.brightness_set = toshiba_illumination_set; | |
1885 | dev->led_dev.brightness_get = toshiba_illumination_get; | |
1886 | if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev)) | |
36d03f93 | 1887 | dev->illumination_supported = 1; |
6c3f6e6c | 1888 | } |
ea6b31f4 | 1889 | |
def6c4e2 AA |
1890 | if (toshiba_eco_mode_available(dev)) { |
1891 | dev->eco_led.name = "toshiba::eco_mode"; | |
1892 | dev->eco_led.max_brightness = 1; | |
1893 | dev->eco_led.brightness_set = toshiba_eco_mode_set_status; | |
1894 | dev->eco_led.brightness_get = toshiba_eco_mode_get_status; | |
1895 | if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led)) | |
1896 | dev->eco_supported = 1; | |
1897 | } | |
ea6b31f4 | 1898 | |
93f8c16d | 1899 | dev->kbd_illum_supported = toshiba_kbd_illum_available(dev); |
360f0f39 AA |
1900 | /* |
1901 | * Only register the LED if KBD illumination is supported | |
1902 | * and the keyboard backlight operation mode is set to FN-Z | |
1903 | */ | |
1904 | if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) { | |
1905 | dev->kbd_led.name = "toshiba::kbd_backlight"; | |
1906 | dev->kbd_led.max_brightness = 1; | |
1907 | dev->kbd_led.brightness_set = toshiba_kbd_backlight_set; | |
1908 | dev->kbd_led.brightness_get = toshiba_kbd_backlight_get; | |
1909 | if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led)) | |
1910 | dev->kbd_led_registered = 1; | |
1911 | } | |
ea6b31f4 | 1912 | |
9d8658ac AA |
1913 | ret = toshiba_touchpad_get(dev, &dummy); |
1914 | dev->touchpad_supported = !ret; | |
ea6b31f4 | 1915 | |
5a2813e9 AA |
1916 | ret = toshiba_accelerometer_supported(dev); |
1917 | dev->accelerometer_supported = !ret; | |
6c3f6e6c | 1918 | |
36d03f93 SF |
1919 | /* Determine whether or not BIOS supports fan and video interfaces */ |
1920 | ||
1921 | ret = get_video_status(dev, &dummy); | |
1922 | dev->video_supported = !ret; | |
1923 | ||
1924 | ret = get_fan_status(dev, &dummy); | |
1925 | dev->fan_supported = !ret; | |
1926 | ||
360f0f39 AA |
1927 | ret = sysfs_create_group(&dev->acpi_dev->dev.kobj, |
1928 | &toshiba_attr_group); | |
1929 | if (ret) { | |
1930 | dev->sysfs_created = 0; | |
1931 | goto error; | |
1932 | } | |
1933 | dev->sysfs_created = !ret; | |
1934 | ||
36d03f93 SF |
1935 | create_toshiba_proc_entries(dev); |
1936 | ||
29cd293f SF |
1937 | toshiba_acpi = dev; |
1938 | ||
c41a40c5 | 1939 | return 0; |
135740de SF |
1940 | |
1941 | error: | |
51fac838 | 1942 | toshiba_acpi_remove(acpi_dev); |
135740de SF |
1943 | return ret; |
1944 | } | |
1945 | ||
1946 | static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event) | |
1947 | { | |
1948 | struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); | |
1949 | u32 hci_result, value; | |
11948b93 | 1950 | int retries = 3; |
29cd293f | 1951 | int scancode; |
135740de | 1952 | |
29cd293f | 1953 | if (event != 0x80) |
135740de | 1954 | return; |
11948b93 | 1955 | |
29cd293f SF |
1956 | if (dev->info_supported) { |
1957 | scancode = toshiba_acpi_query_hotkey(dev); | |
1958 | if (scancode < 0) | |
1959 | pr_err("Failed to query hotkey event\n"); | |
1960 | else if (scancode != 0) | |
1961 | toshiba_acpi_report_hotkey(dev, scancode); | |
1962 | } else if (dev->system_event_supported) { | |
1963 | do { | |
1964 | hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result); | |
1965 | switch (hci_result) { | |
1864bbc2 | 1966 | case TOS_SUCCESS: |
29cd293f SF |
1967 | toshiba_acpi_report_hotkey(dev, (int)value); |
1968 | break; | |
1864bbc2 | 1969 | case TOS_NOT_SUPPORTED: |
29cd293f SF |
1970 | /* |
1971 | * This is a workaround for an unresolved | |
1972 | * issue on some machines where system events | |
1973 | * sporadically become disabled. | |
1974 | */ | |
1975 | hci_write1(dev, HCI_SYSTEM_EVENT, 1, | |
1976 | &hci_result); | |
1977 | pr_notice("Re-enabled hotkeys\n"); | |
1978 | /* fall through */ | |
1979 | default: | |
1980 | retries--; | |
1981 | break; | |
135740de | 1982 | } |
1864bbc2 | 1983 | } while (retries && hci_result != TOS_FIFO_EMPTY); |
29cd293f | 1984 | } |
135740de SF |
1985 | } |
1986 | ||
3567a4e2 | 1987 | #ifdef CONFIG_PM_SLEEP |
43d2fd3b | 1988 | static int toshiba_acpi_suspend(struct device *device) |
29cd293f | 1989 | { |
43d2fd3b | 1990 | struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device)); |
29cd293f SF |
1991 | u32 result; |
1992 | ||
1993 | if (dev->hotkey_dev) | |
1994 | hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE, &result); | |
1995 | ||
1996 | return 0; | |
1997 | } | |
1998 | ||
43d2fd3b | 1999 | static int toshiba_acpi_resume(struct device *device) |
29cd293f | 2000 | { |
43d2fd3b | 2001 | struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device)); |
29cd293f | 2002 | u32 result; |
e7fdb762 BT |
2003 | acpi_status status; |
2004 | ||
2005 | if (dev->hotkey_dev) { | |
2006 | status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB", | |
2007 | NULL, NULL); | |
2008 | if (ACPI_FAILURE(status)) | |
2009 | pr_info("Unable to re-enable hotkeys\n"); | |
29cd293f | 2010 | |
29cd293f | 2011 | hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &result); |
e7fdb762 | 2012 | } |
29cd293f SF |
2013 | |
2014 | return 0; | |
2015 | } | |
3567a4e2 | 2016 | #endif |
135740de | 2017 | |
43d2fd3b RW |
2018 | static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm, |
2019 | toshiba_acpi_suspend, toshiba_acpi_resume); | |
2020 | ||
135740de SF |
2021 | static struct acpi_driver toshiba_acpi_driver = { |
2022 | .name = "Toshiba ACPI driver", | |
2023 | .owner = THIS_MODULE, | |
2024 | .ids = toshiba_device_ids, | |
2025 | .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, | |
2026 | .ops = { | |
2027 | .add = toshiba_acpi_add, | |
2028 | .remove = toshiba_acpi_remove, | |
2029 | .notify = toshiba_acpi_notify, | |
2030 | }, | |
43d2fd3b | 2031 | .drv.pm = &toshiba_acpi_pm, |
135740de SF |
2032 | }; |
2033 | ||
2034 | static int __init toshiba_acpi_init(void) | |
2035 | { | |
2036 | int ret; | |
2037 | ||
f11f999e SF |
2038 | /* |
2039 | * Machines with this WMI guid aren't supported due to bugs in | |
2040 | * their AML. This check relies on wmi initializing before | |
2041 | * toshiba_acpi to guarantee guids have been identified. | |
2042 | */ | |
2043 | if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) | |
2044 | return -ENODEV; | |
2045 | ||
135740de SF |
2046 | toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir); |
2047 | if (!toshiba_proc_dir) { | |
2048 | pr_err("Unable to create proc dir " PROC_TOSHIBA "\n"); | |
2049 | return -ENODEV; | |
2050 | } | |
2051 | ||
2052 | ret = acpi_bus_register_driver(&toshiba_acpi_driver); | |
2053 | if (ret) { | |
2054 | pr_err("Failed to register ACPI driver: %d\n", ret); | |
2055 | remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); | |
2056 | } | |
2057 | ||
2058 | return ret; | |
2059 | } | |
2060 | ||
2061 | static void __exit toshiba_acpi_exit(void) | |
2062 | { | |
2063 | acpi_bus_unregister_driver(&toshiba_acpi_driver); | |
2064 | if (toshiba_proc_dir) | |
2065 | remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); | |
1da177e4 LT |
2066 | } |
2067 | ||
2068 | module_init(toshiba_acpi_init); | |
2069 | module_exit(toshiba_acpi_exit); |