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