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