Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * toshiba_acpi.c - Toshiba Laptop ACPI Extras |
| 3 | * |
| 4 | * |
| 5 | * Copyright (C) 2002-2004 John Belmonte |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 6 | * Copyright (C) 2008 Philip Langdale |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | * |
| 23 | * The devolpment page for this driver is located at |
| 24 | * http://memebeam.org/toys/ToshibaAcpiDriver. |
| 25 | * |
| 26 | * Credits: |
| 27 | * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse |
| 28 | * engineering the Windows drivers |
| 29 | * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5 |
| 30 | * Rob Miller - TV out and hotkeys help |
| 31 | * |
| 32 | * |
| 33 | * TODO |
| 34 | * |
| 35 | */ |
| 36 | |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 37 | #define TOSHIBA_ACPI_VERSION "0.19" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #define PROC_INTERFACE_VERSION 1 |
| 39 | |
| 40 | #include <linux/kernel.h> |
| 41 | #include <linux/module.h> |
| 42 | #include <linux/init.h> |
| 43 | #include <linux/types.h> |
| 44 | #include <linux/proc_fs.h> |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 45 | #include <linux/seq_file.h> |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 46 | #include <linux/backlight.h> |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 47 | #include <linux/platform_device.h> |
| 48 | #include <linux/rfkill.h> |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 49 | #include <linux/input.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame^] | 50 | #include <linux/slab.h> |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <asm/uaccess.h> |
| 53 | |
| 54 | #include <acpi/acpi_drivers.h> |
| 55 | |
| 56 | MODULE_AUTHOR("John Belmonte"); |
| 57 | MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver"); |
| 58 | MODULE_LICENSE("GPL"); |
| 59 | |
| 60 | #define MY_LOGPREFIX "toshiba_acpi: " |
| 61 | #define MY_ERR KERN_ERR MY_LOGPREFIX |
| 62 | #define MY_NOTICE KERN_NOTICE MY_LOGPREFIX |
| 63 | #define MY_INFO KERN_INFO MY_LOGPREFIX |
| 64 | |
| 65 | /* Toshiba ACPI method paths */ |
| 66 | #define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM" |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 67 | #define TOSH_INTERFACE_1 "\\_SB_.VALD" |
| 68 | #define TOSH_INTERFACE_2 "\\_SB_.VALZ" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX" |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 70 | #define GHCI_METHOD ".GHCI" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | /* Toshiba HCI interface definitions |
| 73 | * |
| 74 | * HCI is Toshiba's "Hardware Control Interface" which is supposed to |
| 75 | * be uniform across all their models. Ideally we would just call |
| 76 | * dedicated ACPI methods instead of using this primitive interface. |
| 77 | * However the ACPI methods seem to be incomplete in some areas (for |
| 78 | * example they allow setting, but not reading, the LCD brightness value), |
| 79 | * so this is still useful. |
| 80 | */ |
| 81 | |
| 82 | #define HCI_WORDS 6 |
| 83 | |
| 84 | /* operations */ |
| 85 | #define HCI_SET 0xff00 |
| 86 | #define HCI_GET 0xfe00 |
| 87 | |
| 88 | /* return codes */ |
| 89 | #define HCI_SUCCESS 0x0000 |
| 90 | #define HCI_FAILURE 0x1000 |
| 91 | #define HCI_NOT_SUPPORTED 0x8000 |
| 92 | #define HCI_EMPTY 0x8c00 |
| 93 | |
| 94 | /* registers */ |
| 95 | #define HCI_FAN 0x0004 |
| 96 | #define HCI_SYSTEM_EVENT 0x0016 |
| 97 | #define HCI_VIDEO_OUT 0x001c |
| 98 | #define HCI_HOTKEY_EVENT 0x001e |
| 99 | #define HCI_LCD_BRIGHTNESS 0x002a |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 100 | #define HCI_WIRELESS 0x0056 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | /* field definitions */ |
| 103 | #define HCI_LCD_BRIGHTNESS_BITS 3 |
| 104 | #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS) |
| 105 | #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS) |
| 106 | #define HCI_VIDEO_OUT_LCD 0x1 |
| 107 | #define HCI_VIDEO_OUT_CRT 0x2 |
| 108 | #define HCI_VIDEO_OUT_TV 0x4 |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 109 | #define HCI_WIRELESS_KILL_SWITCH 0x01 |
| 110 | #define HCI_WIRELESS_BT_PRESENT 0x0f |
| 111 | #define HCI_WIRELESS_BT_ATTACH 0x40 |
| 112 | #define HCI_WIRELESS_BT_POWER 0x80 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
arvidjaar@mail.ru | 4db42c5 | 2008-03-04 15:06:34 -0800 | [diff] [blame] | 114 | static const struct acpi_device_id toshiba_device_ids[] = { |
| 115 | {"TOS6200", 0}, |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 116 | {"TOS6208", 0}, |
arvidjaar@mail.ru | 4db42c5 | 2008-03-04 15:06:34 -0800 | [diff] [blame] | 117 | {"TOS1900", 0}, |
| 118 | {"", 0}, |
| 119 | }; |
| 120 | MODULE_DEVICE_TABLE(acpi, toshiba_device_ids); |
| 121 | |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 122 | struct key_entry { |
| 123 | char type; |
| 124 | u16 code; |
| 125 | u16 keycode; |
| 126 | }; |
| 127 | |
| 128 | enum {KE_KEY, KE_END}; |
| 129 | |
| 130 | static struct key_entry toshiba_acpi_keymap[] = { |
| 131 | {KE_KEY, 0x101, KEY_MUTE}, |
| 132 | {KE_KEY, 0x13b, KEY_COFFEE}, |
| 133 | {KE_KEY, 0x13c, KEY_BATTERY}, |
| 134 | {KE_KEY, 0x13d, KEY_SLEEP}, |
| 135 | {KE_KEY, 0x13e, KEY_SUSPEND}, |
| 136 | {KE_KEY, 0x13f, KEY_SWITCHVIDEOMODE}, |
| 137 | {KE_KEY, 0x140, KEY_BRIGHTNESSDOWN}, |
| 138 | {KE_KEY, 0x141, KEY_BRIGHTNESSUP}, |
| 139 | {KE_KEY, 0x142, KEY_WLAN}, |
| 140 | {KE_KEY, 0x143, KEY_PROG1}, |
| 141 | {KE_KEY, 0xb05, KEY_PROG2}, |
| 142 | {KE_KEY, 0xb06, KEY_WWW}, |
| 143 | {KE_KEY, 0xb07, KEY_MAIL}, |
| 144 | {KE_KEY, 0xb30, KEY_STOP}, |
| 145 | {KE_KEY, 0xb31, KEY_PREVIOUSSONG}, |
| 146 | {KE_KEY, 0xb32, KEY_NEXTSONG}, |
| 147 | {KE_KEY, 0xb33, KEY_PLAYPAUSE}, |
| 148 | {KE_KEY, 0xb5a, KEY_MEDIA}, |
| 149 | {KE_END, 0, 0}, |
| 150 | }; |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* utility |
| 153 | */ |
| 154 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 155 | static __inline__ void _set_bit(u32 * word, u32 mask, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
| 157 | *word = (*word & ~mask) | (mask * value); |
| 158 | } |
| 159 | |
| 160 | /* acpi interface wrappers |
| 161 | */ |
| 162 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | static int is_valid_acpi_path(const char *methodName) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
| 165 | acpi_handle handle; |
| 166 | acpi_status status; |
| 167 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 168 | status = acpi_get_handle(NULL, (char *)methodName, &handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | return !ACPI_FAILURE(status); |
| 170 | } |
| 171 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | static int write_acpi_int(const char *methodName, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
| 174 | struct acpi_object_list params; |
| 175 | union acpi_object in_objs[1]; |
| 176 | acpi_status status; |
| 177 | |
Ahmed S. Darwish | b2b7910 | 2007-02-06 16:14:43 -0800 | [diff] [blame] | 178 | params.count = ARRAY_SIZE(in_objs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | params.pointer = in_objs; |
| 180 | in_objs[0].type = ACPI_TYPE_INTEGER; |
| 181 | in_objs[0].integer.value = val; |
| 182 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 183 | status = acpi_evaluate_object(NULL, (char *)methodName, ¶ms, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | return (status == AE_OK); |
| 185 | } |
| 186 | |
| 187 | #if 0 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 188 | static int read_acpi_int(const char *methodName, int *pVal) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
| 190 | struct acpi_buffer results; |
| 191 | union acpi_object out_objs[1]; |
| 192 | acpi_status status; |
| 193 | |
| 194 | results.length = sizeof(out_objs); |
| 195 | results.pointer = out_objs; |
| 196 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 197 | status = acpi_evaluate_object(0, (char *)methodName, 0, &results); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | *pVal = out_objs[0].integer.value; |
| 199 | |
| 200 | return (status == AE_OK) && (out_objs[0].type == ACPI_TYPE_INTEGER); |
| 201 | } |
| 202 | #endif |
| 203 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | static const char *method_hci /*= 0*/ ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | /* Perform a raw HCI call. Here we don't care about input or output buffer |
| 207 | * format. |
| 208 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | { |
| 211 | struct acpi_object_list params; |
| 212 | union acpi_object in_objs[HCI_WORDS]; |
| 213 | struct acpi_buffer results; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 214 | union acpi_object out_objs[HCI_WORDS + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | acpi_status status; |
| 216 | int i; |
| 217 | |
| 218 | params.count = HCI_WORDS; |
| 219 | params.pointer = in_objs; |
| 220 | for (i = 0; i < HCI_WORDS; ++i) { |
| 221 | in_objs[i].type = ACPI_TYPE_INTEGER; |
| 222 | in_objs[i].integer.value = in[i]; |
| 223 | } |
| 224 | |
| 225 | results.length = sizeof(out_objs); |
| 226 | results.pointer = out_objs; |
| 227 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 228 | status = acpi_evaluate_object(NULL, (char *)method_hci, ¶ms, |
| 229 | &results); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) { |
| 231 | for (i = 0; i < out_objs->package.count; ++i) { |
| 232 | out[i] = out_objs->package.elements[i].integer.value; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | return status; |
| 237 | } |
| 238 | |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 239 | /* common hci tasks (get or set one or two value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | * |
| 241 | * In addition to the ACPI status, the HCI system returns a result which |
| 242 | * may be useful (such as "not supported"). |
| 243 | */ |
| 244 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 245 | static acpi_status hci_write1(u32 reg, u32 in1, u32 * result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
| 247 | u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 }; |
| 248 | u32 out[HCI_WORDS]; |
| 249 | acpi_status status = hci_raw(in, out); |
| 250 | *result = (status == AE_OK) ? out[0] : HCI_FAILURE; |
| 251 | return status; |
| 252 | } |
| 253 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 254 | static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
| 256 | u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 }; |
| 257 | u32 out[HCI_WORDS]; |
| 258 | acpi_status status = hci_raw(in, out); |
| 259 | *out1 = out[2]; |
| 260 | *result = (status == AE_OK) ? out[0] : HCI_FAILURE; |
| 261 | return status; |
| 262 | } |
| 263 | |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 264 | static acpi_status hci_write2(u32 reg, u32 in1, u32 in2, u32 *result) |
| 265 | { |
| 266 | u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 }; |
| 267 | u32 out[HCI_WORDS]; |
| 268 | acpi_status status = hci_raw(in, out); |
| 269 | *result = (status == AE_OK) ? out[0] : HCI_FAILURE; |
| 270 | return status; |
| 271 | } |
| 272 | |
| 273 | static acpi_status hci_read2(u32 reg, u32 *out1, u32 *out2, u32 *result) |
| 274 | { |
| 275 | u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 }; |
| 276 | u32 out[HCI_WORDS]; |
| 277 | acpi_status status = hci_raw(in, out); |
| 278 | *out1 = out[2]; |
| 279 | *out2 = out[3]; |
| 280 | *result = (status == AE_OK) ? out[0] : HCI_FAILURE; |
| 281 | return status; |
| 282 | } |
| 283 | |
| 284 | struct toshiba_acpi_dev { |
| 285 | struct platform_device *p_dev; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 286 | struct rfkill *bt_rfk; |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 287 | struct input_dev *hotkey_dev; |
| 288 | acpi_handle handle; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 289 | |
| 290 | const char *bt_name; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 291 | |
| 292 | struct mutex mutex; |
| 293 | }; |
| 294 | |
| 295 | static struct toshiba_acpi_dev toshiba_acpi = { |
| 296 | .bt_name = "Toshiba Bluetooth", |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 297 | }; |
| 298 | |
| 299 | /* Bluetooth rfkill handlers */ |
| 300 | |
| 301 | static u32 hci_get_bt_present(bool *present) |
| 302 | { |
| 303 | u32 hci_result; |
| 304 | u32 value, value2; |
| 305 | |
| 306 | value = 0; |
| 307 | value2 = 0; |
| 308 | hci_read2(HCI_WIRELESS, &value, &value2, &hci_result); |
| 309 | if (hci_result == HCI_SUCCESS) |
| 310 | *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false; |
| 311 | |
| 312 | return hci_result; |
| 313 | } |
| 314 | |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 315 | static u32 hci_get_radio_state(bool *radio_state) |
| 316 | { |
| 317 | u32 hci_result; |
| 318 | u32 value, value2; |
| 319 | |
| 320 | value = 0; |
| 321 | value2 = 0x0001; |
| 322 | hci_read2(HCI_WIRELESS, &value, &value2, &hci_result); |
| 323 | |
| 324 | *radio_state = value & HCI_WIRELESS_KILL_SWITCH; |
| 325 | return hci_result; |
| 326 | } |
| 327 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 328 | static int bt_rfkill_set_block(void *data, bool blocked) |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 329 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 330 | struct toshiba_acpi_dev *dev = data; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 331 | u32 result1, result2; |
| 332 | u32 value; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 333 | int err; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 334 | bool radio_state; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 335 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 336 | value = (blocked == false); |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 337 | |
| 338 | mutex_lock(&dev->mutex); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 339 | if (hci_get_radio_state(&radio_state) != HCI_SUCCESS) { |
| 340 | err = -EBUSY; |
| 341 | goto out; |
| 342 | } |
| 343 | |
| 344 | if (!radio_state) { |
| 345 | err = 0; |
| 346 | goto out; |
| 347 | } |
| 348 | |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 349 | hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1); |
| 350 | hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2); |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 351 | |
| 352 | if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 353 | err = -EBUSY; |
| 354 | else |
| 355 | err = 0; |
| 356 | out: |
| 357 | mutex_unlock(&dev->mutex); |
| 358 | return err; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 359 | } |
| 360 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 361 | static void bt_rfkill_poll(struct rfkill *rfkill, void *data) |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 362 | { |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 363 | bool new_rfk_state; |
| 364 | bool value; |
| 365 | u32 hci_result; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 366 | struct toshiba_acpi_dev *dev = data; |
| 367 | |
| 368 | mutex_lock(&dev->mutex); |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 369 | |
| 370 | hci_result = hci_get_radio_state(&value); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 371 | if (hci_result != HCI_SUCCESS) { |
| 372 | /* Can't do anything useful */ |
| 373 | mutex_unlock(&dev->mutex); |
Jiri Slaby | 82e7784 | 2009-08-06 15:57:51 -0700 | [diff] [blame] | 374 | return; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 375 | } |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 376 | |
| 377 | new_rfk_state = value; |
| 378 | |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 379 | mutex_unlock(&dev->mutex); |
| 380 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 381 | if (rfkill_set_hw_state(rfkill, !new_rfk_state)) |
| 382 | bt_rfkill_set_block(data, true); |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 383 | } |
| 384 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 385 | static const struct rfkill_ops toshiba_rfk_ops = { |
| 386 | .set_block = bt_rfkill_set_block, |
| 387 | .poll = bt_rfkill_poll, |
| 388 | }; |
| 389 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 390 | static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ; |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 391 | static struct backlight_device *toshiba_backlight_device; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 392 | static int force_fan; |
| 393 | static int last_key_event; |
| 394 | static int key_event_valid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 396 | static int get_lcd(struct backlight_device *bd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { |
| 398 | u32 hci_result; |
| 399 | u32 value; |
| 400 | |
| 401 | hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result); |
| 402 | if (hci_result == HCI_SUCCESS) { |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 403 | return (value >> HCI_LCD_BRIGHTNESS_SHIFT); |
| 404 | } else |
| 405 | return -EFAULT; |
| 406 | } |
| 407 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 408 | static int lcd_proc_show(struct seq_file *m, void *v) |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 409 | { |
| 410 | int value = get_lcd(NULL); |
| 411 | |
| 412 | if (value >= 0) { |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 413 | seq_printf(m, "brightness: %d\n", value); |
| 414 | seq_printf(m, "brightness_levels: %d\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 415 | HCI_LCD_BRIGHTNESS_LEVELS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } else { |
| 417 | printk(MY_ERR "Error reading LCD brightness\n"); |
| 418 | } |
| 419 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | static int lcd_proc_open(struct inode *inode, struct file *file) |
| 424 | { |
| 425 | return single_open(file, lcd_proc_show, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 428 | static int set_lcd(int value) |
| 429 | { |
| 430 | u32 hci_result; |
| 431 | |
| 432 | value = value << HCI_LCD_BRIGHTNESS_SHIFT; |
| 433 | hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result); |
| 434 | if (hci_result != HCI_SUCCESS) |
| 435 | return -EFAULT; |
| 436 | |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | static int set_lcd_status(struct backlight_device *bd) |
| 441 | { |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 442 | return set_lcd(bd->props.brightness); |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 445 | static ssize_t lcd_proc_write(struct file *file, const char __user *buf, |
| 446 | size_t count, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | { |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 448 | char cmd[42]; |
| 449 | size_t len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | int value; |
Matthijs van Otterdijk | c8af57e | 2007-01-05 16:37:03 -0800 | [diff] [blame] | 451 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 453 | len = min(count, sizeof(cmd) - 1); |
| 454 | if (copy_from_user(cmd, buf, len)) |
| 455 | return -EFAULT; |
| 456 | cmd[len] = '\0'; |
| 457 | |
| 458 | if (sscanf(cmd, " brightness : %i", &value) == 1 && |
Matthijs van Otterdijk | c8af57e | 2007-01-05 16:37:03 -0800 | [diff] [blame] | 459 | value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) { |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 460 | ret = set_lcd(value); |
Matthijs van Otterdijk | c8af57e | 2007-01-05 16:37:03 -0800 | [diff] [blame] | 461 | if (ret == 0) |
| 462 | ret = count; |
| 463 | } else { |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 464 | ret = -EINVAL; |
Matthijs van Otterdijk | c8af57e | 2007-01-05 16:37:03 -0800 | [diff] [blame] | 465 | } |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 466 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 469 | static const struct file_operations lcd_proc_fops = { |
| 470 | .owner = THIS_MODULE, |
| 471 | .open = lcd_proc_open, |
| 472 | .read = seq_read, |
| 473 | .llseek = seq_lseek, |
| 474 | .release = single_release, |
| 475 | .write = lcd_proc_write, |
| 476 | }; |
| 477 | |
| 478 | static int video_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
| 480 | u32 hci_result; |
| 481 | u32 value; |
| 482 | |
| 483 | hci_read1(HCI_VIDEO_OUT, &value, &hci_result); |
| 484 | if (hci_result == HCI_SUCCESS) { |
| 485 | int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0; |
| 486 | int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 487 | int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0; |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 488 | seq_printf(m, "lcd_out: %d\n", is_lcd); |
| 489 | seq_printf(m, "crt_out: %d\n", is_crt); |
| 490 | seq_printf(m, "tv_out: %d\n", is_tv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } else { |
| 492 | printk(MY_ERR "Error reading video out status\n"); |
| 493 | } |
| 494 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 495 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 498 | static int video_proc_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | { |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 500 | return single_open(file, video_proc_show, NULL); |
| 501 | } |
| 502 | |
| 503 | static ssize_t video_proc_write(struct file *file, const char __user *buf, |
| 504 | size_t count, loff_t *pos) |
| 505 | { |
| 506 | char *cmd, *buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | int value; |
| 508 | int remain = count; |
| 509 | int lcd_out = -1; |
| 510 | int crt_out = -1; |
| 511 | int tv_out = -1; |
| 512 | u32 hci_result; |
Al Viro | b4482a4 | 2007-10-14 19:35:40 +0100 | [diff] [blame] | 513 | u32 video_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 515 | cmd = kmalloc(count + 1, GFP_KERNEL); |
| 516 | if (!cmd) |
| 517 | return -ENOMEM; |
| 518 | if (copy_from_user(cmd, buf, count)) { |
| 519 | kfree(cmd); |
| 520 | return -EFAULT; |
| 521 | } |
| 522 | cmd[count] = '\0'; |
| 523 | |
| 524 | buffer = cmd; |
| 525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | /* scan expression. Multiple expressions may be delimited with ; |
| 527 | * |
| 528 | * NOTE: to keep scanning simple, invalid fields are ignored |
| 529 | */ |
| 530 | while (remain) { |
| 531 | if (sscanf(buffer, " lcd_out : %i", &value) == 1) |
| 532 | lcd_out = value & 1; |
| 533 | else if (sscanf(buffer, " crt_out : %i", &value) == 1) |
| 534 | crt_out = value & 1; |
| 535 | else if (sscanf(buffer, " tv_out : %i", &value) == 1) |
| 536 | tv_out = value & 1; |
| 537 | /* advance to one character past the next ; */ |
| 538 | do { |
| 539 | ++buffer; |
| 540 | --remain; |
| 541 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 542 | while (remain && *(buffer - 1) != ';'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 545 | kfree(cmd); |
| 546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | hci_read1(HCI_VIDEO_OUT, &video_out, &hci_result); |
| 548 | if (hci_result == HCI_SUCCESS) { |
Harvey Harrison | 9e113e0 | 2008-09-22 14:37:29 -0700 | [diff] [blame] | 549 | unsigned int new_video_out = video_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | if (lcd_out != -1) |
| 551 | _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out); |
| 552 | if (crt_out != -1) |
| 553 | _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out); |
| 554 | if (tv_out != -1) |
| 555 | _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out); |
| 556 | /* To avoid unnecessary video disruption, only write the new |
| 557 | * video setting if something changed. */ |
| 558 | if (new_video_out != video_out) |
| 559 | write_acpi_int(METHOD_VIDEO_OUT, new_video_out); |
| 560 | } else { |
| 561 | return -EFAULT; |
| 562 | } |
| 563 | |
| 564 | return count; |
| 565 | } |
| 566 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 567 | static const struct file_operations video_proc_fops = { |
| 568 | .owner = THIS_MODULE, |
| 569 | .open = video_proc_open, |
| 570 | .read = seq_read, |
| 571 | .llseek = seq_lseek, |
| 572 | .release = single_release, |
| 573 | .write = video_proc_write, |
| 574 | }; |
| 575 | |
| 576 | static int fan_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | { |
| 578 | u32 hci_result; |
| 579 | u32 value; |
| 580 | |
| 581 | hci_read1(HCI_FAN, &value, &hci_result); |
| 582 | if (hci_result == HCI_SUCCESS) { |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 583 | seq_printf(m, "running: %d\n", (value > 0)); |
| 584 | seq_printf(m, "force_on: %d\n", force_fan); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | } else { |
| 586 | printk(MY_ERR "Error reading fan status\n"); |
| 587 | } |
| 588 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 589 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 592 | static int fan_proc_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | { |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 594 | return single_open(file, fan_proc_show, NULL); |
| 595 | } |
| 596 | |
| 597 | static ssize_t fan_proc_write(struct file *file, const char __user *buf, |
| 598 | size_t count, loff_t *pos) |
| 599 | { |
| 600 | char cmd[42]; |
| 601 | size_t len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | int value; |
| 603 | u32 hci_result; |
| 604 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 605 | len = min(count, sizeof(cmd) - 1); |
| 606 | if (copy_from_user(cmd, buf, len)) |
| 607 | return -EFAULT; |
| 608 | cmd[len] = '\0'; |
| 609 | |
| 610 | if (sscanf(cmd, " force_on : %i", &value) == 1 && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 611 | value >= 0 && value <= 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | hci_write1(HCI_FAN, value, &hci_result); |
| 613 | if (hci_result != HCI_SUCCESS) |
| 614 | return -EFAULT; |
| 615 | else |
| 616 | force_fan = value; |
| 617 | } else { |
| 618 | return -EINVAL; |
| 619 | } |
| 620 | |
| 621 | return count; |
| 622 | } |
| 623 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 624 | static const struct file_operations fan_proc_fops = { |
| 625 | .owner = THIS_MODULE, |
| 626 | .open = fan_proc_open, |
| 627 | .read = seq_read, |
| 628 | .llseek = seq_lseek, |
| 629 | .release = single_release, |
| 630 | .write = fan_proc_write, |
| 631 | }; |
| 632 | |
| 633 | static int keys_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
| 635 | u32 hci_result; |
| 636 | u32 value; |
| 637 | |
| 638 | if (!key_event_valid) { |
| 639 | hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result); |
| 640 | if (hci_result == HCI_SUCCESS) { |
| 641 | key_event_valid = 1; |
| 642 | last_key_event = value; |
| 643 | } else if (hci_result == HCI_EMPTY) { |
| 644 | /* better luck next time */ |
| 645 | } else if (hci_result == HCI_NOT_SUPPORTED) { |
| 646 | /* This is a workaround for an unresolved issue on |
| 647 | * some machines where system events sporadically |
| 648 | * become disabled. */ |
| 649 | hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result); |
| 650 | printk(MY_NOTICE "Re-enabled hotkeys\n"); |
| 651 | } else { |
| 652 | printk(MY_ERR "Error reading hotkey status\n"); |
| 653 | goto end; |
| 654 | } |
| 655 | } |
| 656 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 657 | seq_printf(m, "hotkey_ready: %d\n", key_event_valid); |
| 658 | seq_printf(m, "hotkey: 0x%04x\n", last_key_event); |
| 659 | end: |
| 660 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 663 | static int keys_proc_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | { |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 665 | return single_open(file, keys_proc_show, NULL); |
| 666 | } |
| 667 | |
| 668 | static ssize_t keys_proc_write(struct file *file, const char __user *buf, |
| 669 | size_t count, loff_t *pos) |
| 670 | { |
| 671 | char cmd[42]; |
| 672 | size_t len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | int value; |
| 674 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 675 | len = min(count, sizeof(cmd) - 1); |
| 676 | if (copy_from_user(cmd, buf, len)) |
| 677 | return -EFAULT; |
| 678 | cmd[len] = '\0'; |
| 679 | |
| 680 | if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | key_event_valid = 0; |
| 682 | } else { |
| 683 | return -EINVAL; |
| 684 | } |
| 685 | |
| 686 | return count; |
| 687 | } |
| 688 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 689 | static const struct file_operations keys_proc_fops = { |
| 690 | .owner = THIS_MODULE, |
| 691 | .open = keys_proc_open, |
| 692 | .read = seq_read, |
| 693 | .llseek = seq_lseek, |
| 694 | .release = single_release, |
| 695 | .write = keys_proc_write, |
| 696 | }; |
| 697 | |
| 698 | static int version_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | { |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 700 | seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION); |
| 701 | seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION); |
| 702 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 705 | static int version_proc_open(struct inode *inode, struct file *file) |
| 706 | { |
| 707 | return single_open(file, version_proc_show, PDE(inode)->data); |
| 708 | } |
| 709 | |
| 710 | static const struct file_operations version_proc_fops = { |
| 711 | .owner = THIS_MODULE, |
| 712 | .open = version_proc_open, |
| 713 | .read = seq_read, |
| 714 | .llseek = seq_lseek, |
| 715 | .release = single_release, |
| 716 | }; |
| 717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | /* proc and module init |
| 719 | */ |
| 720 | |
| 721 | #define PROC_TOSHIBA "toshiba" |
| 722 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 723 | static acpi_status __init add_device(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | { |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 725 | proc_create("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, &lcd_proc_fops); |
| 726 | proc_create("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, &video_proc_fops); |
| 727 | proc_create("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, &fan_proc_fops); |
| 728 | proc_create("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, &keys_proc_fops); |
| 729 | proc_create("version", S_IRUGO, toshiba_proc_dir, &version_proc_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
| 731 | return AE_OK; |
| 732 | } |
| 733 | |
Randy Dunlap | b1d93de | 2007-06-16 10:16:02 -0700 | [diff] [blame] | 734 | static acpi_status remove_device(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | { |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 736 | remove_proc_entry("lcd", toshiba_proc_dir); |
| 737 | remove_proc_entry("video", toshiba_proc_dir); |
| 738 | remove_proc_entry("fan", toshiba_proc_dir); |
| 739 | remove_proc_entry("keys", toshiba_proc_dir); |
| 740 | remove_proc_entry("version", toshiba_proc_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | return AE_OK; |
| 742 | } |
| 743 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 744 | static struct backlight_ops toshiba_backlight_data = { |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 745 | .get_brightness = get_lcd, |
| 746 | .update_status = set_lcd_status, |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 747 | }; |
| 748 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 749 | static struct key_entry *toshiba_acpi_get_entry_by_scancode(unsigned int code) |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 750 | { |
| 751 | struct key_entry *key; |
| 752 | |
| 753 | for (key = toshiba_acpi_keymap; key->type != KE_END; key++) |
| 754 | if (code == key->code) |
| 755 | return key; |
| 756 | |
| 757 | return NULL; |
| 758 | } |
| 759 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 760 | static struct key_entry *toshiba_acpi_get_entry_by_keycode(unsigned int code) |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 761 | { |
| 762 | struct key_entry *key; |
| 763 | |
| 764 | for (key = toshiba_acpi_keymap; key->type != KE_END; key++) |
| 765 | if (code == key->keycode && key->type == KE_KEY) |
| 766 | return key; |
| 767 | |
| 768 | return NULL; |
| 769 | } |
| 770 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 771 | static int toshiba_acpi_getkeycode(struct input_dev *dev, |
| 772 | unsigned int scancode, unsigned int *keycode) |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 773 | { |
| 774 | struct key_entry *key = toshiba_acpi_get_entry_by_scancode(scancode); |
| 775 | |
| 776 | if (key && key->type == KE_KEY) { |
| 777 | *keycode = key->keycode; |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | return -EINVAL; |
| 782 | } |
| 783 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 784 | static int toshiba_acpi_setkeycode(struct input_dev *dev, |
| 785 | unsigned int scancode, unsigned int keycode) |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 786 | { |
| 787 | struct key_entry *key; |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 788 | unsigned int old_keycode; |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 789 | |
| 790 | key = toshiba_acpi_get_entry_by_scancode(scancode); |
| 791 | if (key && key->type == KE_KEY) { |
| 792 | old_keycode = key->keycode; |
| 793 | key->keycode = keycode; |
| 794 | set_bit(keycode, dev->keybit); |
| 795 | if (!toshiba_acpi_get_entry_by_keycode(old_keycode)) |
| 796 | clear_bit(old_keycode, dev->keybit); |
| 797 | return 0; |
| 798 | } |
| 799 | |
| 800 | return -EINVAL; |
| 801 | } |
| 802 | |
| 803 | static void toshiba_acpi_notify(acpi_handle handle, u32 event, void *context) |
| 804 | { |
| 805 | u32 hci_result, value; |
| 806 | struct key_entry *key; |
| 807 | |
| 808 | if (event != 0x80) |
| 809 | return; |
| 810 | do { |
| 811 | hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result); |
| 812 | if (hci_result == HCI_SUCCESS) { |
| 813 | if (value == 0x100) |
| 814 | continue; |
Frans Pop | b466301 | 2010-03-01 09:50:46 -0500 | [diff] [blame] | 815 | /* act on key press; ignore key release */ |
| 816 | if (value & 0x80) |
| 817 | continue; |
| 818 | |
| 819 | key = toshiba_acpi_get_entry_by_scancode |
| 820 | (value); |
| 821 | if (!key) { |
| 822 | printk(MY_INFO "Unknown key %x\n", |
| 823 | value); |
| 824 | continue; |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 825 | } |
Frans Pop | b466301 | 2010-03-01 09:50:46 -0500 | [diff] [blame] | 826 | input_report_key(toshiba_acpi.hotkey_dev, |
| 827 | key->keycode, 1); |
| 828 | input_sync(toshiba_acpi.hotkey_dev); |
| 829 | input_report_key(toshiba_acpi.hotkey_dev, |
| 830 | key->keycode, 0); |
| 831 | input_sync(toshiba_acpi.hotkey_dev); |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 832 | } else if (hci_result == HCI_NOT_SUPPORTED) { |
| 833 | /* This is a workaround for an unresolved issue on |
| 834 | * some machines where system events sporadically |
| 835 | * become disabled. */ |
| 836 | hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result); |
| 837 | printk(MY_NOTICE "Re-enabled hotkeys\n"); |
| 838 | } |
| 839 | } while (hci_result != HCI_EMPTY); |
| 840 | } |
| 841 | |
| 842 | static int toshiba_acpi_setup_keyboard(char *device) |
| 843 | { |
| 844 | acpi_status status; |
| 845 | acpi_handle handle; |
| 846 | int result; |
| 847 | const struct key_entry *key; |
| 848 | |
| 849 | status = acpi_get_handle(NULL, device, &handle); |
| 850 | if (ACPI_FAILURE(status)) { |
| 851 | printk(MY_INFO "Unable to get notification device\n"); |
| 852 | return -ENODEV; |
| 853 | } |
| 854 | |
| 855 | toshiba_acpi.handle = handle; |
| 856 | |
| 857 | status = acpi_evaluate_object(handle, "ENAB", NULL, NULL); |
| 858 | if (ACPI_FAILURE(status)) { |
| 859 | printk(MY_INFO "Unable to enable hotkeys\n"); |
| 860 | return -ENODEV; |
| 861 | } |
| 862 | |
| 863 | status = acpi_install_notify_handler(handle, ACPI_DEVICE_NOTIFY, |
| 864 | toshiba_acpi_notify, NULL); |
| 865 | if (ACPI_FAILURE(status)) { |
| 866 | printk(MY_INFO "Unable to install hotkey notification\n"); |
| 867 | return -ENODEV; |
| 868 | } |
| 869 | |
| 870 | toshiba_acpi.hotkey_dev = input_allocate_device(); |
| 871 | if (!toshiba_acpi.hotkey_dev) { |
| 872 | printk(MY_INFO "Unable to register input device\n"); |
| 873 | return -ENOMEM; |
| 874 | } |
| 875 | |
| 876 | toshiba_acpi.hotkey_dev->name = "Toshiba input device"; |
| 877 | toshiba_acpi.hotkey_dev->phys = device; |
| 878 | toshiba_acpi.hotkey_dev->id.bustype = BUS_HOST; |
| 879 | toshiba_acpi.hotkey_dev->getkeycode = toshiba_acpi_getkeycode; |
| 880 | toshiba_acpi.hotkey_dev->setkeycode = toshiba_acpi_setkeycode; |
| 881 | |
| 882 | for (key = toshiba_acpi_keymap; key->type != KE_END; key++) { |
| 883 | set_bit(EV_KEY, toshiba_acpi.hotkey_dev->evbit); |
| 884 | set_bit(key->keycode, toshiba_acpi.hotkey_dev->keybit); |
| 885 | } |
| 886 | |
| 887 | result = input_register_device(toshiba_acpi.hotkey_dev); |
| 888 | if (result) { |
| 889 | printk(MY_INFO "Unable to register input device\n"); |
| 890 | return result; |
| 891 | } |
| 892 | |
| 893 | return 0; |
| 894 | } |
| 895 | |
Sam Ravnborg | b2b77b2 | 2007-06-01 00:47:12 -0700 | [diff] [blame] | 896 | static void toshiba_acpi_exit(void) |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 897 | { |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 898 | if (toshiba_acpi.hotkey_dev) |
| 899 | input_unregister_device(toshiba_acpi.hotkey_dev); |
| 900 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 901 | if (toshiba_acpi.bt_rfk) { |
| 902 | rfkill_unregister(toshiba_acpi.bt_rfk); |
| 903 | rfkill_destroy(toshiba_acpi.bt_rfk); |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 904 | } |
| 905 | |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 906 | if (toshiba_backlight_device) |
| 907 | backlight_device_unregister(toshiba_backlight_device); |
| 908 | |
| 909 | remove_device(); |
| 910 | |
| 911 | if (toshiba_proc_dir) |
| 912 | remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); |
| 913 | |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 914 | acpi_remove_notify_handler(toshiba_acpi.handle, ACPI_DEVICE_NOTIFY, |
| 915 | toshiba_acpi_notify); |
| 916 | |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 917 | platform_device_unregister(toshiba_acpi.p_dev); |
| 918 | |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 919 | return; |
| 920 | } |
| 921 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 922 | static int __init toshiba_acpi_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | { |
| 924 | acpi_status status = AE_OK; |
| 925 | u32 hci_result; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 926 | bool bt_present; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 927 | int ret = 0; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 928 | struct backlight_properties props; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
| 930 | if (acpi_disabled) |
| 931 | return -ENODEV; |
Luming Yu | fb9802f | 2005-03-18 18:03:45 -0500 | [diff] [blame] | 932 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | /* simple device detection: look for HCI method */ |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 934 | if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD)) { |
| 935 | method_hci = TOSH_INTERFACE_1 GHCI_METHOD; |
| 936 | if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1)) |
| 937 | printk(MY_INFO "Unable to activate hotkeys\n"); |
| 938 | } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD)) { |
| 939 | method_hci = TOSH_INTERFACE_2 GHCI_METHOD; |
| 940 | if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2)) |
| 941 | printk(MY_INFO "Unable to activate hotkeys\n"); |
| 942 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | return -ENODEV; |
| 944 | |
| 945 | printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 946 | TOSHIBA_ACPI_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | printk(MY_INFO " HCI method: %s\n", method_hci); |
| 948 | |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 949 | mutex_init(&toshiba_acpi.mutex); |
| 950 | |
| 951 | toshiba_acpi.p_dev = platform_device_register_simple("toshiba_acpi", |
| 952 | -1, NULL, 0); |
| 953 | if (IS_ERR(toshiba_acpi.p_dev)) { |
| 954 | ret = PTR_ERR(toshiba_acpi.p_dev); |
| 955 | printk(MY_ERR "unable to register platform device\n"); |
| 956 | toshiba_acpi.p_dev = NULL; |
| 957 | toshiba_acpi_exit(); |
| 958 | return ret; |
| 959 | } |
| 960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | force_fan = 0; |
| 962 | key_event_valid = 0; |
| 963 | |
| 964 | /* enable event fifo */ |
| 965 | hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result); |
| 966 | |
| 967 | toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir); |
| 968 | if (!toshiba_proc_dir) { |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 969 | toshiba_acpi_exit(); |
| 970 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | status = add_device(); |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 973 | if (ACPI_FAILURE(status)) { |
| 974 | toshiba_acpi_exit(); |
| 975 | return -ENODEV; |
| 976 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 979 | props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 980 | toshiba_backlight_device = backlight_device_register("toshiba", |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 981 | &toshiba_acpi.p_dev->dev, |
| 982 | NULL, |
| 983 | &toshiba_backlight_data, |
| 984 | &props); |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 985 | if (IS_ERR(toshiba_backlight_device)) { |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 986 | ret = PTR_ERR(toshiba_backlight_device); |
Andrey Borzenkov | 1299342 | 2007-11-14 16:58:28 -0800 | [diff] [blame] | 987 | |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 988 | printk(KERN_ERR "Could not register toshiba backlight device\n"); |
| 989 | toshiba_backlight_device = NULL; |
| 990 | toshiba_acpi_exit(); |
Andrey Borzenkov | 1299342 | 2007-11-14 16:58:28 -0800 | [diff] [blame] | 991 | return ret; |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 992 | } |
| 993 | |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 994 | /* Register rfkill switch for Bluetooth */ |
| 995 | if (hci_get_bt_present(&bt_present) == HCI_SUCCESS && bt_present) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 996 | toshiba_acpi.bt_rfk = rfkill_alloc(toshiba_acpi.bt_name, |
| 997 | &toshiba_acpi.p_dev->dev, |
| 998 | RFKILL_TYPE_BLUETOOTH, |
| 999 | &toshiba_rfk_ops, |
| 1000 | &toshiba_acpi); |
| 1001 | if (!toshiba_acpi.bt_rfk) { |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1002 | printk(MY_ERR "unable to allocate rfkill device\n"); |
| 1003 | toshiba_acpi_exit(); |
| 1004 | return -ENOMEM; |
| 1005 | } |
| 1006 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1007 | ret = rfkill_register(toshiba_acpi.bt_rfk); |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1008 | if (ret) { |
| 1009 | printk(MY_ERR "unable to register rfkill device\n"); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1010 | rfkill_destroy(toshiba_acpi.bt_rfk); |
Frederik Deweerdt | 38aefbc | 2008-12-15 13:54:19 -0800 | [diff] [blame] | 1011 | toshiba_acpi_exit(); |
| 1012 | return ret; |
| 1013 | } |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | module_init(toshiba_acpi_init); |
| 1020 | module_exit(toshiba_acpi_exit); |