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