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