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 |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | * |
| 21 | * |
| 22 | * The devolpment page for this driver is located at |
| 23 | * http://memebeam.org/toys/ToshibaAcpiDriver. |
| 24 | * |
| 25 | * Credits: |
| 26 | * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse |
| 27 | * engineering the Windows drivers |
| 28 | * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5 |
| 29 | * Rob Miller - TV out and hotkeys help |
| 30 | * |
| 31 | * |
| 32 | * TODO |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | #define TOSHIBA_ACPI_VERSION "0.18" |
| 37 | #define PROC_INTERFACE_VERSION 1 |
| 38 | |
| 39 | #include <linux/kernel.h> |
| 40 | #include <linux/module.h> |
| 41 | #include <linux/init.h> |
| 42 | #include <linux/types.h> |
| 43 | #include <linux/proc_fs.h> |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 44 | #include <linux/backlight.h> |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <asm/uaccess.h> |
| 47 | |
| 48 | #include <acpi/acpi_drivers.h> |
| 49 | |
| 50 | MODULE_AUTHOR("John Belmonte"); |
| 51 | MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver"); |
| 52 | MODULE_LICENSE("GPL"); |
| 53 | |
| 54 | #define MY_LOGPREFIX "toshiba_acpi: " |
| 55 | #define MY_ERR KERN_ERR MY_LOGPREFIX |
| 56 | #define MY_NOTICE KERN_NOTICE MY_LOGPREFIX |
| 57 | #define MY_INFO KERN_INFO MY_LOGPREFIX |
| 58 | |
| 59 | /* Toshiba ACPI method paths */ |
| 60 | #define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM" |
| 61 | #define METHOD_HCI_1 "\\_SB_.VALD.GHCI" |
| 62 | #define METHOD_HCI_2 "\\_SB_.VALZ.GHCI" |
| 63 | #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX" |
| 64 | |
| 65 | /* Toshiba HCI interface definitions |
| 66 | * |
| 67 | * HCI is Toshiba's "Hardware Control Interface" which is supposed to |
| 68 | * be uniform across all their models. Ideally we would just call |
| 69 | * dedicated ACPI methods instead of using this primitive interface. |
| 70 | * However the ACPI methods seem to be incomplete in some areas (for |
| 71 | * example they allow setting, but not reading, the LCD brightness value), |
| 72 | * so this is still useful. |
| 73 | */ |
| 74 | |
| 75 | #define HCI_WORDS 6 |
| 76 | |
| 77 | /* operations */ |
| 78 | #define HCI_SET 0xff00 |
| 79 | #define HCI_GET 0xfe00 |
| 80 | |
| 81 | /* return codes */ |
| 82 | #define HCI_SUCCESS 0x0000 |
| 83 | #define HCI_FAILURE 0x1000 |
| 84 | #define HCI_NOT_SUPPORTED 0x8000 |
| 85 | #define HCI_EMPTY 0x8c00 |
| 86 | |
| 87 | /* registers */ |
| 88 | #define HCI_FAN 0x0004 |
| 89 | #define HCI_SYSTEM_EVENT 0x0016 |
| 90 | #define HCI_VIDEO_OUT 0x001c |
| 91 | #define HCI_HOTKEY_EVENT 0x001e |
| 92 | #define HCI_LCD_BRIGHTNESS 0x002a |
| 93 | |
| 94 | /* field definitions */ |
| 95 | #define HCI_LCD_BRIGHTNESS_BITS 3 |
| 96 | #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS) |
| 97 | #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS) |
| 98 | #define HCI_VIDEO_OUT_LCD 0x1 |
| 99 | #define HCI_VIDEO_OUT_CRT 0x2 |
| 100 | #define HCI_VIDEO_OUT_TV 0x4 |
| 101 | |
| 102 | /* utility |
| 103 | */ |
| 104 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 105 | static __inline__ void _set_bit(u32 * word, u32 mask, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
| 107 | *word = (*word & ~mask) | (mask * value); |
| 108 | } |
| 109 | |
| 110 | /* acpi interface wrappers |
| 111 | */ |
| 112 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | static int is_valid_acpi_path(const char *methodName) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
| 115 | acpi_handle handle; |
| 116 | acpi_status status; |
| 117 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 118 | status = acpi_get_handle(NULL, (char *)methodName, &handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | return !ACPI_FAILURE(status); |
| 120 | } |
| 121 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 122 | static int write_acpi_int(const char *methodName, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | struct acpi_object_list params; |
| 125 | union acpi_object in_objs[1]; |
| 126 | acpi_status status; |
| 127 | |
Ahmed S. Darwish | b2b7910 | 2007-02-06 16:14:43 -0800 | [diff] [blame] | 128 | params.count = ARRAY_SIZE(in_objs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | params.pointer = in_objs; |
| 130 | in_objs[0].type = ACPI_TYPE_INTEGER; |
| 131 | in_objs[0].integer.value = val; |
| 132 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | status = acpi_evaluate_object(NULL, (char *)methodName, ¶ms, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | return (status == AE_OK); |
| 135 | } |
| 136 | |
| 137 | #if 0 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | static int read_acpi_int(const char *methodName, int *pVal) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | { |
| 140 | struct acpi_buffer results; |
| 141 | union acpi_object out_objs[1]; |
| 142 | acpi_status status; |
| 143 | |
| 144 | results.length = sizeof(out_objs); |
| 145 | results.pointer = out_objs; |
| 146 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | status = acpi_evaluate_object(0, (char *)methodName, 0, &results); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | *pVal = out_objs[0].integer.value; |
| 149 | |
| 150 | return (status == AE_OK) && (out_objs[0].type == ACPI_TYPE_INTEGER); |
| 151 | } |
| 152 | #endif |
| 153 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 154 | static const char *method_hci /*= 0*/ ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | /* Perform a raw HCI call. Here we don't care about input or output buffer |
| 157 | * format. |
| 158 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 159 | 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] | 160 | { |
| 161 | struct acpi_object_list params; |
| 162 | union acpi_object in_objs[HCI_WORDS]; |
| 163 | struct acpi_buffer results; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | union acpi_object out_objs[HCI_WORDS + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | acpi_status status; |
| 166 | int i; |
| 167 | |
| 168 | params.count = HCI_WORDS; |
| 169 | params.pointer = in_objs; |
| 170 | for (i = 0; i < HCI_WORDS; ++i) { |
| 171 | in_objs[i].type = ACPI_TYPE_INTEGER; |
| 172 | in_objs[i].integer.value = in[i]; |
| 173 | } |
| 174 | |
| 175 | results.length = sizeof(out_objs); |
| 176 | results.pointer = out_objs; |
| 177 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 178 | status = acpi_evaluate_object(NULL, (char *)method_hci, ¶ms, |
| 179 | &results); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) { |
| 181 | for (i = 0; i < out_objs->package.count; ++i) { |
| 182 | out[i] = out_objs->package.elements[i].integer.value; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | return status; |
| 187 | } |
| 188 | |
| 189 | /* common hci tasks (get or set one value) |
| 190 | * |
| 191 | * In addition to the ACPI status, the HCI system returns a result which |
| 192 | * may be useful (such as "not supported"). |
| 193 | */ |
| 194 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | static acpi_status hci_write1(u32 reg, u32 in1, u32 * result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 }; |
| 198 | u32 out[HCI_WORDS]; |
| 199 | acpi_status status = hci_raw(in, out); |
| 200 | *result = (status == AE_OK) ? out[0] : HCI_FAILURE; |
| 201 | return status; |
| 202 | } |
| 203 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { |
| 206 | u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 }; |
| 207 | u32 out[HCI_WORDS]; |
| 208 | acpi_status status = hci_raw(in, out); |
| 209 | *out1 = out[2]; |
| 210 | *result = (status == AE_OK) ? out[0] : HCI_FAILURE; |
| 211 | return status; |
| 212 | } |
| 213 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 214 | static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ; |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 215 | static struct backlight_device *toshiba_backlight_device; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | static int force_fan; |
| 217 | static int last_key_event; |
| 218 | static int key_event_valid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | typedef struct _ProcItem { |
| 221 | const char *name; |
| 222 | char *(*read_func) (char *); |
| 223 | unsigned long (*write_func) (const char *, unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } ProcItem; |
| 225 | |
| 226 | /* proc file handlers |
| 227 | */ |
| 228 | |
| 229 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 230 | dispatch_read(char *page, char **start, off_t off, int count, int *eof, |
| 231 | ProcItem * item) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 233 | char *p = page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | int len; |
| 235 | |
| 236 | if (off == 0) |
| 237 | p = item->read_func(p); |
| 238 | |
| 239 | /* ISSUE: I don't understand this code */ |
| 240 | len = (p - page); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 241 | if (len <= off + count) |
| 242 | *eof = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | *start = page + off; |
| 244 | len -= off; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 245 | if (len > count) |
| 246 | len = count; |
| 247 | if (len < 0) |
| 248 | len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | return len; |
| 250 | } |
| 251 | |
| 252 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | dispatch_write(struct file *file, const char __user * buffer, |
| 254 | unsigned long count, ProcItem * item) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
| 256 | int result; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 257 | char *tmp_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | /* Arg buffer points to userspace memory, which can't be accessed |
| 260 | * directly. Since we're making a copy, zero-terminate the |
| 261 | * destination so that sscanf can be used on it safely. |
| 262 | */ |
| 263 | tmp_buffer = kmalloc(count + 1, GFP_KERNEL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 264 | if (!tmp_buffer) |
Panagiotis Issaris | f422415 | 2005-03-30 22:15:36 -0500 | [diff] [blame] | 265 | return -ENOMEM; |
| 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | if (copy_from_user(tmp_buffer, buffer, count)) { |
| 268 | result = -EFAULT; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 269 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | tmp_buffer[count] = 0; |
| 271 | result = item->write_func(tmp_buffer, count); |
| 272 | } |
| 273 | kfree(tmp_buffer); |
| 274 | return result; |
| 275 | } |
| 276 | |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 277 | static int get_lcd(struct backlight_device *bd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
| 279 | u32 hci_result; |
| 280 | u32 value; |
| 281 | |
| 282 | hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result); |
| 283 | if (hci_result == HCI_SUCCESS) { |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 284 | return (value >> HCI_LCD_BRIGHTNESS_SHIFT); |
| 285 | } else |
| 286 | return -EFAULT; |
| 287 | } |
| 288 | |
| 289 | static char *read_lcd(char *p) |
| 290 | { |
| 291 | int value = get_lcd(NULL); |
| 292 | |
| 293 | if (value >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | p += sprintf(p, "brightness: %d\n", value); |
| 295 | p += sprintf(p, "brightness_levels: %d\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 296 | HCI_LCD_BRIGHTNESS_LEVELS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } else { |
| 298 | printk(MY_ERR "Error reading LCD brightness\n"); |
| 299 | } |
| 300 | |
| 301 | return p; |
| 302 | } |
| 303 | |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 304 | static int set_lcd(int value) |
| 305 | { |
| 306 | u32 hci_result; |
| 307 | |
| 308 | value = value << HCI_LCD_BRIGHTNESS_SHIFT; |
| 309 | hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result); |
| 310 | if (hci_result != HCI_SUCCESS) |
| 311 | return -EFAULT; |
| 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static int set_lcd_status(struct backlight_device *bd) |
| 317 | { |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 318 | return set_lcd(bd->props.brightness); |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 321 | static unsigned long write_lcd(const char *buffer, unsigned long count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
| 323 | int value; |
Matthijs van Otterdijk | c8af57e | 2007-01-05 16:37:03 -0800 | [diff] [blame] | 324 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | if (sscanf(buffer, " brightness : %i", &value) == 1 && |
Matthijs van Otterdijk | c8af57e | 2007-01-05 16:37:03 -0800 | [diff] [blame] | 327 | value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) { |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 328 | ret = set_lcd(value); |
Matthijs van Otterdijk | c8af57e | 2007-01-05 16:37:03 -0800 | [diff] [blame] | 329 | if (ret == 0) |
| 330 | ret = count; |
| 331 | } else { |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 332 | ret = -EINVAL; |
Matthijs van Otterdijk | c8af57e | 2007-01-05 16:37:03 -0800 | [diff] [blame] | 333 | } |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 334 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 337 | static char *read_video(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
| 339 | u32 hci_result; |
| 340 | u32 value; |
| 341 | |
| 342 | hci_read1(HCI_VIDEO_OUT, &value, &hci_result); |
| 343 | if (hci_result == HCI_SUCCESS) { |
| 344 | int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0; |
| 345 | int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 346 | int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | p += sprintf(p, "lcd_out: %d\n", is_lcd); |
| 348 | p += sprintf(p, "crt_out: %d\n", is_crt); |
| 349 | p += sprintf(p, "tv_out: %d\n", is_tv); |
| 350 | } else { |
| 351 | printk(MY_ERR "Error reading video out status\n"); |
| 352 | } |
| 353 | |
| 354 | return p; |
| 355 | } |
| 356 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 357 | static unsigned long write_video(const char *buffer, unsigned long count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | { |
| 359 | int value; |
| 360 | int remain = count; |
| 361 | int lcd_out = -1; |
| 362 | int crt_out = -1; |
| 363 | int tv_out = -1; |
| 364 | u32 hci_result; |
| 365 | int video_out; |
| 366 | |
| 367 | /* scan expression. Multiple expressions may be delimited with ; |
| 368 | * |
| 369 | * NOTE: to keep scanning simple, invalid fields are ignored |
| 370 | */ |
| 371 | while (remain) { |
| 372 | if (sscanf(buffer, " lcd_out : %i", &value) == 1) |
| 373 | lcd_out = value & 1; |
| 374 | else if (sscanf(buffer, " crt_out : %i", &value) == 1) |
| 375 | crt_out = value & 1; |
| 376 | else if (sscanf(buffer, " tv_out : %i", &value) == 1) |
| 377 | tv_out = value & 1; |
| 378 | /* advance to one character past the next ; */ |
| 379 | do { |
| 380 | ++buffer; |
| 381 | --remain; |
| 382 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 383 | while (remain && *(buffer - 1) != ';'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | hci_read1(HCI_VIDEO_OUT, &video_out, &hci_result); |
| 387 | if (hci_result == HCI_SUCCESS) { |
| 388 | int new_video_out = video_out; |
| 389 | if (lcd_out != -1) |
| 390 | _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out); |
| 391 | if (crt_out != -1) |
| 392 | _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out); |
| 393 | if (tv_out != -1) |
| 394 | _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out); |
| 395 | /* To avoid unnecessary video disruption, only write the new |
| 396 | * video setting if something changed. */ |
| 397 | if (new_video_out != video_out) |
| 398 | write_acpi_int(METHOD_VIDEO_OUT, new_video_out); |
| 399 | } else { |
| 400 | return -EFAULT; |
| 401 | } |
| 402 | |
| 403 | return count; |
| 404 | } |
| 405 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | static char *read_fan(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | { |
| 408 | u32 hci_result; |
| 409 | u32 value; |
| 410 | |
| 411 | hci_read1(HCI_FAN, &value, &hci_result); |
| 412 | if (hci_result == HCI_SUCCESS) { |
| 413 | p += sprintf(p, "running: %d\n", (value > 0)); |
| 414 | p += sprintf(p, "force_on: %d\n", force_fan); |
| 415 | } else { |
| 416 | printk(MY_ERR "Error reading fan status\n"); |
| 417 | } |
| 418 | |
| 419 | return p; |
| 420 | } |
| 421 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 422 | static unsigned long write_fan(const char *buffer, unsigned long count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | { |
| 424 | int value; |
| 425 | u32 hci_result; |
| 426 | |
| 427 | if (sscanf(buffer, " force_on : %i", &value) == 1 && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 428 | value >= 0 && value <= 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | hci_write1(HCI_FAN, value, &hci_result); |
| 430 | if (hci_result != HCI_SUCCESS) |
| 431 | return -EFAULT; |
| 432 | else |
| 433 | force_fan = value; |
| 434 | } else { |
| 435 | return -EINVAL; |
| 436 | } |
| 437 | |
| 438 | return count; |
| 439 | } |
| 440 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 441 | static char *read_keys(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
| 443 | u32 hci_result; |
| 444 | u32 value; |
| 445 | |
| 446 | if (!key_event_valid) { |
| 447 | hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result); |
| 448 | if (hci_result == HCI_SUCCESS) { |
| 449 | key_event_valid = 1; |
| 450 | last_key_event = value; |
| 451 | } else if (hci_result == HCI_EMPTY) { |
| 452 | /* better luck next time */ |
| 453 | } else if (hci_result == HCI_NOT_SUPPORTED) { |
| 454 | /* This is a workaround for an unresolved issue on |
| 455 | * some machines where system events sporadically |
| 456 | * become disabled. */ |
| 457 | hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result); |
| 458 | printk(MY_NOTICE "Re-enabled hotkeys\n"); |
| 459 | } else { |
| 460 | printk(MY_ERR "Error reading hotkey status\n"); |
| 461 | goto end; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | p += sprintf(p, "hotkey_ready: %d\n", key_event_valid); |
| 466 | p += sprintf(p, "hotkey: 0x%04x\n", last_key_event); |
| 467 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 468 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | return p; |
| 470 | } |
| 471 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 472 | static unsigned long write_keys(const char *buffer, unsigned long count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | { |
| 474 | int value; |
| 475 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 476 | if (sscanf(buffer, " hotkey_ready : %i", &value) == 1 && value == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | key_event_valid = 0; |
| 478 | } else { |
| 479 | return -EINVAL; |
| 480 | } |
| 481 | |
| 482 | return count; |
| 483 | } |
| 484 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 485 | static char *read_version(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | { |
| 487 | p += sprintf(p, "driver: %s\n", TOSHIBA_ACPI_VERSION); |
| 488 | p += sprintf(p, "proc_interface: %d\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 489 | PROC_INTERFACE_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | return p; |
| 491 | } |
| 492 | |
| 493 | /* proc and module init |
| 494 | */ |
| 495 | |
| 496 | #define PROC_TOSHIBA "toshiba" |
| 497 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 498 | static ProcItem proc_items[] = { |
| 499 | {"lcd", read_lcd, write_lcd}, |
| 500 | {"video", read_video, write_video}, |
| 501 | {"fan", read_fan, write_fan}, |
| 502 | {"keys", read_keys, write_keys}, |
| 503 | {"version", read_version, NULL}, |
| 504 | {NULL} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | }; |
| 506 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 507 | static acpi_status __init add_device(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 509 | struct proc_dir_entry *proc; |
| 510 | ProcItem *item; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 512 | for (item = proc_items; item->name; ++item) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | proc = create_proc_read_entry(item->name, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | S_IFREG | S_IRUGO | S_IWUSR, |
| 515 | toshiba_proc_dir, |
| 516 | (read_proc_t *) dispatch_read, |
| 517 | item); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | if (proc) |
| 519 | proc->owner = THIS_MODULE; |
| 520 | if (proc && item->write_func) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 521 | proc->write_proc = (write_proc_t *) dispatch_write; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | return AE_OK; |
| 525 | } |
| 526 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 527 | static acpi_status __exit remove_device(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 529 | ProcItem *item; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
| 531 | for (item = proc_items; item->name; ++item) |
| 532 | remove_proc_entry(item->name, toshiba_proc_dir); |
| 533 | return AE_OK; |
| 534 | } |
| 535 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 536 | static struct backlight_ops toshiba_backlight_data = { |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 537 | .get_brightness = get_lcd, |
| 538 | .update_status = set_lcd_status, |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 539 | }; |
| 540 | |
| 541 | static void __exit toshiba_acpi_exit(void) |
| 542 | { |
| 543 | if (toshiba_backlight_device) |
| 544 | backlight_device_unregister(toshiba_backlight_device); |
| 545 | |
| 546 | remove_device(); |
| 547 | |
| 548 | if (toshiba_proc_dir) |
| 549 | remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); |
| 550 | |
| 551 | return; |
| 552 | } |
| 553 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 554 | static int __init toshiba_acpi_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | { |
| 556 | acpi_status status = AE_OK; |
| 557 | u32 hci_result; |
| 558 | |
| 559 | if (acpi_disabled) |
| 560 | return -ENODEV; |
Luming Yu | fb9802f | 2005-03-18 18:03:45 -0500 | [diff] [blame] | 561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | /* simple device detection: look for HCI method */ |
| 563 | if (is_valid_acpi_path(METHOD_HCI_1)) |
| 564 | method_hci = METHOD_HCI_1; |
| 565 | else if (is_valid_acpi_path(METHOD_HCI_2)) |
| 566 | method_hci = METHOD_HCI_2; |
| 567 | else |
| 568 | return -ENODEV; |
| 569 | |
| 570 | printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 571 | TOSHIBA_ACPI_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | printk(MY_INFO " HCI method: %s\n", method_hci); |
| 573 | |
| 574 | force_fan = 0; |
| 575 | key_event_valid = 0; |
| 576 | |
| 577 | /* enable event fifo */ |
| 578 | hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result); |
| 579 | |
| 580 | toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir); |
| 581 | if (!toshiba_proc_dir) { |
| 582 | status = AE_ERROR; |
| 583 | } else { |
| 584 | toshiba_proc_dir->owner = THIS_MODULE; |
| 585 | status = add_device(); |
| 586 | if (ACPI_FAILURE(status)) |
| 587 | remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); |
| 588 | } |
| 589 | |
Yu Luming | 519ab5f | 2006-12-19 12:56:15 -0800 | [diff] [blame] | 590 | toshiba_backlight_device = backlight_device_register("toshiba",NULL, |
| 591 | NULL, |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 592 | &toshiba_backlight_data); |
| 593 | if (IS_ERR(toshiba_backlight_device)) { |
| 594 | printk(KERN_ERR "Could not register toshiba backlight device\n"); |
| 595 | toshiba_backlight_device = NULL; |
| 596 | toshiba_acpi_exit(); |
| 597 | } |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 598 | toshiba_backlight_device->props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1; |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | return (ACPI_SUCCESS(status)) ? 0 : -ENODEV; |
| 601 | } |
| 602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | module_init(toshiba_acpi_init); |
| 604 | module_exit(toshiba_acpi_exit); |