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