Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * asus_acpi.c - Asus Laptop ACPI Extras |
| 3 | * |
| 4 | * |
Karol Kozimor | a170a53 | 2006-06-30 19:03:00 -0400 | [diff] [blame] | 5 | * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 development page for this driver is located at |
| 23 | * http://sourceforge.net/projects/acpi4asus/ |
| 24 | * |
| 25 | * Credits: |
| 26 | * Pontus Fuchs - Helper functions, cleanup |
| 27 | * Johann Wiesner - Small compile fixes |
| 28 | * John Belmonte - ACPI code for Toshiba laptop was a good starting point. |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 29 | * �ic Burghard - LED display support for W1N |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/init.h> |
| 37 | #include <linux/types.h> |
| 38 | #include <linux/proc_fs.h> |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 39 | #include <linux/seq_file.h> |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 40 | #include <linux/backlight.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <acpi/acpi_drivers.h> |
| 42 | #include <acpi/acpi_bus.h> |
| 43 | #include <asm/uaccess.h> |
| 44 | |
Karol Kozimor | a170a53 | 2006-06-30 19:03:00 -0400 | [diff] [blame] | 45 | #define ASUS_ACPI_VERSION "0.30" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 47 | #define PROC_ASUS "asus" /* The directory */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define PROC_MLED "mled" |
| 49 | #define PROC_WLED "wled" |
| 50 | #define PROC_TLED "tled" |
Karol Kozimor | e067aaa | 2006-06-30 19:07:00 -0400 | [diff] [blame] | 51 | #define PROC_BT "bluetooth" |
Karol Kozimor | 42cb891 | 2006-06-30 19:04:00 -0400 | [diff] [blame] | 52 | #define PROC_LEDD "ledd" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #define PROC_INFO "info" |
| 54 | #define PROC_LCD "lcd" |
| 55 | #define PROC_BRN "brn" |
| 56 | #define PROC_DISP "disp" |
| 57 | |
| 58 | #define ACPI_HOTK_NAME "Asus Laptop ACPI Extras Driver" |
| 59 | #define ACPI_HOTK_CLASS "hotkey" |
| 60 | #define ACPI_HOTK_DEVICE_NAME "Hotkey" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | * Some events we use, same for all Asus |
| 64 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 65 | #define BR_UP 0x10 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #define BR_DOWN 0x20 |
| 67 | |
| 68 | /* |
| 69 | * Flags for hotk status |
| 70 | */ |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 71 | #define MLED_ON 0x01 /* Mail LED */ |
| 72 | #define WLED_ON 0x02 /* Wireless LED */ |
| 73 | #define TLED_ON 0x04 /* Touchpad LED */ |
| 74 | #define BT_ON 0x08 /* Internal Bluetooth */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | MODULE_AUTHOR("Julien Lerouge, Karol Kozimor"); |
| 77 | MODULE_DESCRIPTION(ACPI_HOTK_NAME); |
| 78 | MODULE_LICENSE("GPL"); |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | static uid_t asus_uid; |
| 81 | static gid_t asus_gid; |
| 82 | module_param(asus_uid, uint, 0); |
Niels de Vos | 61a2d07 | 2008-07-31 00:07:23 -0700 | [diff] [blame] | 83 | MODULE_PARM_DESC(asus_uid, "UID for entries in /proc/acpi/asus"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | module_param(asus_gid, uint, 0); |
Niels de Vos | 61a2d07 | 2008-07-31 00:07:23 -0700 | [diff] [blame] | 85 | MODULE_PARM_DESC(asus_gid, "GID for entries in /proc/acpi/asus"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 87 | /* For each model, all features implemented, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | * those marked with R are relative to HOTK, A for absolute */ |
| 89 | struct model_data { |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 90 | char *name; /* name of the laptop________________A */ |
| 91 | char *mt_mled; /* method to handle mled_____________R */ |
| 92 | char *mled_status; /* node to handle mled reading_______A */ |
| 93 | char *mt_wled; /* method to handle wled_____________R */ |
| 94 | char *wled_status; /* node to handle wled reading_______A */ |
| 95 | char *mt_tled; /* method to handle tled_____________R */ |
| 96 | char *tled_status; /* node to handle tled reading_______A */ |
| 97 | char *mt_ledd; /* method to handle LED display______R */ |
| 98 | char *mt_bt_switch; /* method to switch Bluetooth on/off_R */ |
| 99 | char *bt_status; /* no model currently supports this__? */ |
| 100 | char *mt_lcd_switch; /* method to turn LCD on/off_________A */ |
| 101 | char *lcd_status; /* node to read LCD panel state______A */ |
| 102 | char *brightness_up; /* method to set brightness up_______A */ |
| 103 | char *brightness_down; /* method to set brightness down ____A */ |
| 104 | char *brightness_set; /* method to set absolute brightness_R */ |
| 105 | char *brightness_get; /* method to get absolute brightness_R */ |
| 106 | char *brightness_status;/* node to get brightness____________A */ |
| 107 | char *display_set; /* method to set video output________R */ |
| 108 | char *display_get; /* method to get video output________R */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | /* |
| 112 | * This is the main structure, we can use it to store anything interesting |
| 113 | * about the hotk device |
| 114 | */ |
| 115 | struct asus_hotk { |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 116 | struct acpi_device *device; /* the device we are in */ |
| 117 | acpi_handle handle; /* the handle of the hotk device */ |
| 118 | char status; /* status of the hotk, for LEDs */ |
| 119 | u32 ledd_status; /* status of the LED display */ |
| 120 | struct model_data *methods; /* methods available on the laptop */ |
| 121 | u8 brightness; /* brightness level */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | enum { |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 123 | A1x = 0, /* A1340D, A1300F */ |
| 124 | A2x, /* A2500H */ |
| 125 | A4G, /* A4700G */ |
| 126 | D1x, /* D1 */ |
| 127 | L2D, /* L2000D */ |
| 128 | L3C, /* L3800C */ |
| 129 | L3D, /* L3400D */ |
| 130 | L3H, /* L3H, L2000E, L5D */ |
| 131 | L4R, /* L4500R */ |
| 132 | L5x, /* L5800C */ |
| 133 | L8L, /* L8400L */ |
| 134 | M1A, /* M1300A */ |
| 135 | M2E, /* M2400E, L4400L */ |
| 136 | M6N, /* M6800N, W3400N */ |
| 137 | M6R, /* M6700R, A3000G */ |
| 138 | P30, /* Samsung P30 */ |
| 139 | S1x, /* S1300A, but also L1400B and M2400A (L84F) */ |
| 140 | S2x, /* S200 (J1 reported), Victor MP-XP7210 */ |
| 141 | W1N, /* W1000N */ |
| 142 | W5A, /* W5A */ |
| 143 | W3V, /* W3030V */ |
| 144 | xxN, /* M2400N, M3700N, M5200N, M6800N, |
| 145 | S1300N, S5200N*/ |
| 146 | A4S, /* Z81sp */ |
| 147 | F3Sa, /* (Centrino) */ |
Corentin Chary | 1021e21 | 2009-01-20 16:17:41 +0100 | [diff] [blame] | 148 | R1F, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | END_MODEL |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 150 | } model; /* Models currently supported */ |
| 151 | u16 event_count[128]; /* Count for each event TODO make this better */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | /* Here we go */ |
| 155 | #define A1x_PREFIX "\\_SB.PCI0.ISA.EC0." |
| 156 | #define L3C_PREFIX "\\_SB.PCI0.PX40.ECD0." |
| 157 | #define M1A_PREFIX "\\_SB.PCI0.PX40.EC0." |
| 158 | #define P30_PREFIX "\\_SB.PCI0.LPCB.EC0." |
| 159 | #define S1x_PREFIX "\\_SB.PCI0.PX40." |
| 160 | #define S2x_PREFIX A1x_PREFIX |
| 161 | #define xxN_PREFIX "\\_SB.PCI0.SBRG.EC0." |
| 162 | |
| 163 | static struct model_data model_conf[END_MODEL] = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | * TODO I have seen a SWBX and AIBX method on some models, like L1400B, |
| 166 | * it seems to be a kind of switch, but what for ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | */ |
| 168 | |
| 169 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | .name = "A1x", |
| 171 | .mt_mled = "MLED", |
| 172 | .mled_status = "\\MAIL", |
| 173 | .mt_lcd_switch = A1x_PREFIX "_Q10", |
| 174 | .lcd_status = "\\BKLI", |
| 175 | .brightness_up = A1x_PREFIX "_Q0E", |
| 176 | .brightness_down = A1x_PREFIX "_Q0F"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | .name = "A2x", |
| 180 | .mt_mled = "MLED", |
| 181 | .mt_wled = "WLED", |
| 182 | .wled_status = "\\SG66", |
| 183 | .mt_lcd_switch = "\\Q10", |
| 184 | .lcd_status = "\\BAOF", |
| 185 | .brightness_set = "SPLV", |
| 186 | .brightness_get = "GPLV", |
| 187 | .display_set = "SDSP", |
| 188 | .display_get = "\\INFB"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | { |
Karol Kozimor | f78c589 | 2006-06-30 19:06:00 -0400 | [diff] [blame] | 191 | .name = "A4G", |
| 192 | .mt_mled = "MLED", |
| 193 | /* WLED present, but not controlled by ACPI */ |
| 194 | .mt_lcd_switch = xxN_PREFIX "_Q10", |
| 195 | .brightness_set = "SPLV", |
| 196 | .brightness_get = "GPLV", |
| 197 | .display_set = "SDSP", |
| 198 | .display_get = "\\ADVG"}, |
| 199 | |
| 200 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | .name = "D1x", |
| 202 | .mt_mled = "MLED", |
| 203 | .mt_lcd_switch = "\\Q0D", |
| 204 | .lcd_status = "\\GP11", |
| 205 | .brightness_up = "\\Q0C", |
| 206 | .brightness_down = "\\Q0B", |
| 207 | .brightness_status = "\\BLVL", |
| 208 | .display_set = "SDSP", |
| 209 | .display_get = "\\INFB"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 212 | .name = "L2D", |
| 213 | .mt_mled = "MLED", |
| 214 | .mled_status = "\\SGP6", |
| 215 | .mt_wled = "WLED", |
| 216 | .wled_status = "\\RCP3", |
| 217 | .mt_lcd_switch = "\\Q10", |
| 218 | .lcd_status = "\\SGP0", |
| 219 | .brightness_up = "\\Q0E", |
| 220 | .brightness_down = "\\Q0F", |
| 221 | .display_set = "SDSP", |
| 222 | .display_get = "\\INFB"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 225 | .name = "L3C", |
| 226 | .mt_mled = "MLED", |
| 227 | .mt_wled = "WLED", |
| 228 | .mt_lcd_switch = L3C_PREFIX "_Q10", |
| 229 | .lcd_status = "\\GL32", |
| 230 | .brightness_set = "SPLV", |
| 231 | .brightness_get = "GPLV", |
| 232 | .display_set = "SDSP", |
| 233 | .display_get = "\\_SB.PCI0.PCI1.VGAC.NMAP"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
| 235 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 236 | .name = "L3D", |
| 237 | .mt_mled = "MLED", |
| 238 | .mled_status = "\\MALD", |
| 239 | .mt_wled = "WLED", |
| 240 | .mt_lcd_switch = "\\Q10", |
| 241 | .lcd_status = "\\BKLG", |
| 242 | .brightness_set = "SPLV", |
| 243 | .brightness_get = "GPLV", |
| 244 | .display_set = "SDSP", |
| 245 | .display_get = "\\INFB"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | .name = "L3H", |
| 249 | .mt_mled = "MLED", |
| 250 | .mt_wled = "WLED", |
| 251 | .mt_lcd_switch = "EHK", |
| 252 | .lcd_status = "\\_SB.PCI0.PM.PBC", |
| 253 | .brightness_set = "SPLV", |
| 254 | .brightness_get = "GPLV", |
| 255 | .display_set = "SDSP", |
| 256 | .display_get = "\\INFB"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
| 258 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 259 | .name = "L4R", |
| 260 | .mt_mled = "MLED", |
| 261 | .mt_wled = "WLED", |
| 262 | .wled_status = "\\_SB.PCI0.SBRG.SG13", |
| 263 | .mt_lcd_switch = xxN_PREFIX "_Q10", |
| 264 | .lcd_status = "\\_SB.PCI0.SBSM.SEO4", |
| 265 | .brightness_set = "SPLV", |
| 266 | .brightness_get = "GPLV", |
| 267 | .display_set = "SDSP", |
| 268 | .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
| 270 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | .name = "L5x", |
| 272 | .mt_mled = "MLED", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | /* WLED present, but not controlled by ACPI */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | .mt_tled = "TLED", |
| 275 | .mt_lcd_switch = "\\Q0D", |
| 276 | .lcd_status = "\\BAOF", |
| 277 | .brightness_set = "SPLV", |
| 278 | .brightness_get = "GPLV", |
| 279 | .display_set = "SDSP", |
| 280 | .display_get = "\\INFB"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
| 282 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 283 | .name = "L8L" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | /* No features, but at least support the hotkeys */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 285 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
| 287 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 288 | .name = "M1A", |
| 289 | .mt_mled = "MLED", |
| 290 | .mt_lcd_switch = M1A_PREFIX "Q10", |
| 291 | .lcd_status = "\\PNOF", |
| 292 | .brightness_up = M1A_PREFIX "Q0E", |
| 293 | .brightness_down = M1A_PREFIX "Q0F", |
| 294 | .brightness_status = "\\BRIT", |
| 295 | .display_set = "SDSP", |
| 296 | .display_get = "\\INFB"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
| 298 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | .name = "M2E", |
| 300 | .mt_mled = "MLED", |
| 301 | .mt_wled = "WLED", |
| 302 | .mt_lcd_switch = "\\Q10", |
| 303 | .lcd_status = "\\GP06", |
| 304 | .brightness_set = "SPLV", |
| 305 | .brightness_get = "GPLV", |
| 306 | .display_set = "SDSP", |
| 307 | .display_get = "\\INFB"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 310 | .name = "M6N", |
| 311 | .mt_mled = "MLED", |
| 312 | .mt_wled = "WLED", |
| 313 | .wled_status = "\\_SB.PCI0.SBRG.SG13", |
| 314 | .mt_lcd_switch = xxN_PREFIX "_Q10", |
| 315 | .lcd_status = "\\_SB.BKLT", |
| 316 | .brightness_set = "SPLV", |
| 317 | .brightness_get = "GPLV", |
| 318 | .display_set = "SDSP", |
Karol Kozimor | 9becf5b | 2006-06-30 19:15:00 -0400 | [diff] [blame] | 319 | .display_get = "\\SSTE"}, |
| 320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | .name = "M6R", |
| 323 | .mt_mled = "MLED", |
| 324 | .mt_wled = "WLED", |
| 325 | .mt_lcd_switch = xxN_PREFIX "_Q10", |
| 326 | .lcd_status = "\\_SB.PCI0.SBSM.SEO4", |
| 327 | .brightness_set = "SPLV", |
| 328 | .brightness_get = "GPLV", |
| 329 | .display_set = "SDSP", |
Karol Kozimor | 9becf5b | 2006-06-30 19:15:00 -0400 | [diff] [blame] | 330 | .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
| 332 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | .name = "P30", |
| 334 | .mt_wled = "WLED", |
| 335 | .mt_lcd_switch = P30_PREFIX "_Q0E", |
| 336 | .lcd_status = "\\BKLT", |
| 337 | .brightness_up = P30_PREFIX "_Q68", |
| 338 | .brightness_down = P30_PREFIX "_Q69", |
| 339 | .brightness_get = "GPLV", |
| 340 | .display_set = "SDSP", |
| 341 | .display_get = "\\DNXT"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 344 | .name = "S1x", |
| 345 | .mt_mled = "MLED", |
| 346 | .mled_status = "\\EMLE", |
| 347 | .mt_wled = "WLED", |
| 348 | .mt_lcd_switch = S1x_PREFIX "Q10", |
| 349 | .lcd_status = "\\PNOF", |
| 350 | .brightness_set = "SPLV", |
| 351 | .brightness_get = "GPLV"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
| 353 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 354 | .name = "S2x", |
| 355 | .mt_mled = "MLED", |
| 356 | .mled_status = "\\MAIL", |
| 357 | .mt_lcd_switch = S2x_PREFIX "_Q10", |
| 358 | .lcd_status = "\\BKLI", |
| 359 | .brightness_up = S2x_PREFIX "_Q0B", |
| 360 | .brightness_down = S2x_PREFIX "_Q0A"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | { |
Karol Kozimor | 42cb891 | 2006-06-30 19:04:00 -0400 | [diff] [blame] | 363 | .name = "W1N", |
| 364 | .mt_mled = "MLED", |
| 365 | .mt_wled = "WLED", |
| 366 | .mt_ledd = "SLCM", |
| 367 | .mt_lcd_switch = xxN_PREFIX "_Q10", |
| 368 | .lcd_status = "\\BKLT", |
| 369 | .brightness_set = "SPLV", |
| 370 | .brightness_get = "GPLV", |
| 371 | .display_set = "SDSP", |
| 372 | .display_get = "\\ADVG"}, |
| 373 | |
| 374 | { |
Karol Kozimor | e067aaa | 2006-06-30 19:07:00 -0400 | [diff] [blame] | 375 | .name = "W5A", |
| 376 | .mt_bt_switch = "BLED", |
| 377 | .mt_wled = "WLED", |
| 378 | .mt_lcd_switch = xxN_PREFIX "_Q10", |
| 379 | .brightness_set = "SPLV", |
| 380 | .brightness_get = "GPLV", |
| 381 | .display_set = "SDSP", |
| 382 | .display_get = "\\ADVG"}, |
| 383 | |
| 384 | { |
Marek W | 288f3ad | 2006-08-14 22:37:20 -0700 | [diff] [blame] | 385 | .name = "W3V", |
| 386 | .mt_mled = "MLED", |
| 387 | .mt_wled = "WLED", |
| 388 | .mt_lcd_switch = xxN_PREFIX "_Q10", |
| 389 | .lcd_status = "\\BKLT", |
| 390 | .brightness_set = "SPLV", |
| 391 | .brightness_get = "GPLV", |
| 392 | .display_set = "SDSP", |
| 393 | .display_get = "\\INFB"}, |
| 394 | |
| 395 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 396 | .name = "xxN", |
| 397 | .mt_mled = "MLED", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | /* WLED present, but not controlled by ACPI */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 399 | .mt_lcd_switch = xxN_PREFIX "_Q10", |
| 400 | .lcd_status = "\\BKLT", |
| 401 | .brightness_set = "SPLV", |
| 402 | .brightness_get = "GPLV", |
| 403 | .display_set = "SDSP", |
Matthew C Campbell | 1c0f057 | 2007-02-05 16:09:09 -0800 | [diff] [blame] | 404 | .display_get = "\\ADVG"}, |
| 405 | |
| 406 | { |
| 407 | .name = "A4S", |
| 408 | .brightness_set = "SPLV", |
| 409 | .brightness_get = "GPLV", |
| 410 | .mt_bt_switch = "BLED", |
| 411 | .mt_wled = "WLED" |
Luca Tettamanti | 31e0729 | 2008-02-04 23:31:18 -0800 | [diff] [blame] | 412 | }, |
| 413 | |
| 414 | { |
| 415 | .name = "F3Sa", |
| 416 | .mt_bt_switch = "BLED", |
| 417 | .mt_wled = "WLED", |
| 418 | .mt_mled = "MLED", |
| 419 | .brightness_get = "GPLV", |
| 420 | .brightness_set = "SPLV", |
| 421 | .mt_lcd_switch = "\\_SB.PCI0.SBRG.EC0._Q10", |
| 422 | .lcd_status = "\\_SB.PCI0.SBRG.EC0.RPIN", |
| 423 | .display_get = "\\ADVG", |
| 424 | .display_set = "SDSP", |
| 425 | }, |
Corentin Chary | 1021e21 | 2009-01-20 16:17:41 +0100 | [diff] [blame] | 426 | { |
| 427 | .name = "R1F", |
| 428 | .mt_bt_switch = "BLED", |
| 429 | .mt_mled = "MLED", |
| 430 | .mt_wled = "WLED", |
| 431 | .mt_lcd_switch = "\\Q10", |
| 432 | .lcd_status = "\\GP06", |
| 433 | .brightness_set = "SPLV", |
| 434 | .brightness_get = "GPLV", |
| 435 | .display_set = "SDSP", |
| 436 | .display_get = "\\INFB" |
| 437 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | }; |
| 439 | |
| 440 | /* procdir we use */ |
| 441 | static struct proc_dir_entry *asus_proc_dir; |
| 442 | |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 443 | static struct backlight_device *asus_backlight_device; |
| 444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | /* |
| 446 | * This header is made available to allow proper configuration given model, |
| 447 | * revision number , ... this info cannot go in struct asus_hotk because it is |
| 448 | * available before the hotk |
| 449 | */ |
| 450 | static struct acpi_table_header *asus_info; |
| 451 | |
| 452 | /* The actual device the driver binds to */ |
| 453 | static struct asus_hotk *hotk; |
| 454 | |
| 455 | /* |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 456 | * The hotkey driver and autoloading declaration |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | */ |
| 458 | static int asus_hotk_add(struct acpi_device *device); |
| 459 | static int asus_hotk_remove(struct acpi_device *device, int type); |
Bjorn Helgaas | 352fa20 | 2009-04-30 09:35:58 -0600 | [diff] [blame] | 460 | static void asus_hotk_notify(struct acpi_device *device, u32 event); |
| 461 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 462 | static const struct acpi_device_id asus_device_ids[] = { |
| 463 | {"ATK0100", 0}, |
| 464 | {"", 0}, |
| 465 | }; |
| 466 | MODULE_DEVICE_TABLE(acpi, asus_device_ids); |
| 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | static struct acpi_driver asus_hotk_driver = { |
Len Brown | c2b6705b | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 469 | .name = "asus_acpi", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 470 | .class = ACPI_HOTK_CLASS, |
Alan Jenkins | db7c554 | 2009-12-03 07:44:50 +0000 | [diff] [blame] | 471 | .owner = THIS_MODULE, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 472 | .ids = asus_device_ids, |
Bjorn Helgaas | 352fa20 | 2009-04-30 09:35:58 -0600 | [diff] [blame] | 473 | .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 474 | .ops = { |
| 475 | .add = asus_hotk_add, |
| 476 | .remove = asus_hotk_remove, |
Bjorn Helgaas | 352fa20 | 2009-04-30 09:35:58 -0600 | [diff] [blame] | 477 | .notify = asus_hotk_notify, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 478 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | }; |
| 480 | |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 481 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | * This function evaluates an ACPI method, given an int as parameter, the |
| 483 | * method is searched within the scope of the handle, can be NULL. The output |
| 484 | * of the method is written is output, which can also be NULL |
| 485 | * |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 486 | * returns 1 if write is successful, 0 else. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | */ |
| 488 | static int write_acpi_int(acpi_handle handle, const char *method, int val, |
| 489 | struct acpi_buffer *output) |
| 490 | { |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 491 | struct acpi_object_list params; /* list of input parameters (int) */ |
| 492 | union acpi_object in_obj; /* the only param we use */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | acpi_status status; |
| 494 | |
| 495 | params.count = 1; |
| 496 | params.pointer = &in_obj; |
| 497 | in_obj.type = ACPI_TYPE_INTEGER; |
| 498 | in_obj.integer.value = val; |
| 499 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 500 | status = acpi_evaluate_object(handle, (char *)method, ¶ms, output); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | return (status == AE_OK); |
| 502 | } |
| 503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | static int read_acpi_int(acpi_handle handle, const char *method, int *val) |
| 505 | { |
| 506 | struct acpi_buffer output; |
| 507 | union acpi_object out_obj; |
| 508 | acpi_status status; |
| 509 | |
| 510 | output.length = sizeof(out_obj); |
| 511 | output.pointer = &out_obj; |
| 512 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 513 | status = acpi_evaluate_object(handle, (char *)method, NULL, &output); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | *val = out_obj.integer.value; |
| 515 | return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER); |
| 516 | } |
| 517 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 518 | static int asus_info_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | int temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 522 | seq_printf(m, ACPI_HOTK_NAME " " ASUS_ACPI_VERSION "\n"); |
| 523 | seq_printf(m, "Model reference : %s\n", hotk->methods->name); |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 524 | /* |
| 525 | * The SFUN method probably allows the original driver to get the list |
| 526 | * of features supported by a given model. For now, 0x0100 or 0x0800 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card. |
| 528 | * The significance of others is yet to be found. |
| 529 | */ |
| 530 | if (read_acpi_int(hotk->handle, "SFUN", &temp)) |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 531 | seq_printf(m, "SFUN value : 0x%04x\n", temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | /* |
| 533 | * Another value for userspace: the ASYM method returns 0x02 for |
| 534 | * battery low and 0x04 for battery critical, its readings tend to be |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 535 | * more accurate than those provided by _BST. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | * Note: since not all the laptops provide this method, errors are |
| 537 | * silently ignored. |
| 538 | */ |
| 539 | if (read_acpi_int(hotk->handle, "ASYM", &temp)) |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 540 | seq_printf(m, "ASYM value : 0x%04x\n", temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | if (asus_info) { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 542 | seq_printf(m, "DSDT length : %d\n", asus_info->length); |
| 543 | seq_printf(m, "DSDT checksum : %d\n", asus_info->checksum); |
| 544 | seq_printf(m, "DSDT revision : %d\n", asus_info->revision); |
| 545 | seq_printf(m, "OEM id : %.*s\n", ACPI_OEM_ID_SIZE, asus_info->oem_id); |
| 546 | seq_printf(m, "OEM table id : %.*s\n", ACPI_OEM_TABLE_ID_SIZE, asus_info->oem_table_id); |
| 547 | seq_printf(m, "OEM revision : 0x%x\n", asus_info->oem_revision); |
| 548 | seq_printf(m, "ASL comp vendor id : %.*s\n", ACPI_NAME_SIZE, asus_info->asl_compiler_id); |
| 549 | seq_printf(m, "ASL comp revision : 0x%x\n", asus_info->asl_compiler_revision); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | } |
| 551 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 552 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 555 | static int asus_info_proc_open(struct inode *inode, struct file *file) |
| 556 | { |
| 557 | return single_open(file, asus_info_proc_show, NULL); |
| 558 | } |
| 559 | |
| 560 | static const struct file_operations asus_info_proc_fops = { |
| 561 | .owner = THIS_MODULE, |
| 562 | .open = asus_info_proc_open, |
| 563 | .read = seq_read, |
| 564 | .llseek = seq_lseek, |
| 565 | .release = single_release, |
| 566 | }; |
| 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | /* |
| 569 | * /proc handlers |
| 570 | * We write our info in page, we begin at offset off and cannot write more |
| 571 | * than count bytes. We set eof to 1 if we handle those 2 values. We return the |
| 572 | * number of bytes written in page |
| 573 | */ |
| 574 | |
| 575 | /* Generic LED functions */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 576 | static int read_led(const char *ledname, int ledmask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | { |
| 578 | if (ledname) { |
| 579 | int led_status; |
| 580 | |
| 581 | if (read_acpi_int(NULL, ledname, &led_status)) |
| 582 | return led_status; |
| 583 | else |
| 584 | printk(KERN_WARNING "Asus ACPI: Error reading LED " |
| 585 | "status\n"); |
| 586 | } |
| 587 | return (hotk->status & ledmask) ? 1 : 0; |
| 588 | } |
| 589 | |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 590 | static int parse_arg(const char __user *buf, unsigned long count, int *val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
| 592 | char s[32]; |
| 593 | if (!count) |
| 594 | return 0; |
| 595 | if (count > 31) |
| 596 | return -EINVAL; |
| 597 | if (copy_from_user(s, buf, count)) |
| 598 | return -EFAULT; |
| 599 | s[count] = 0; |
| 600 | if (sscanf(s, "%i", val) != 1) |
| 601 | return -EINVAL; |
| 602 | return count; |
| 603 | } |
| 604 | |
| 605 | /* FIXME: kill extraneous args so it can be called independently */ |
| 606 | static int |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 607 | write_led(const char __user *buffer, unsigned long count, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 608 | char *ledname, int ledmask, int invert) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | { |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 610 | int rv, value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | int led_out = 0; |
| 612 | |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 613 | rv = parse_arg(buffer, count, &value); |
| 614 | if (rv > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | led_out = value ? 1 : 0; |
| 616 | |
| 617 | hotk->status = |
| 618 | (led_out) ? (hotk->status | ledmask) : (hotk->status & ~ledmask); |
| 619 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 620 | if (invert) /* invert target value */ |
Julia Lawall | abc5a87 | 2008-03-04 15:00:13 -0800 | [diff] [blame] | 621 | led_out = !led_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
| 623 | if (!write_acpi_int(hotk->handle, ledname, led_out, NULL)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 624 | printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n", |
| 625 | ledname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 627 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | /* |
| 631 | * Proc handlers for MLED |
| 632 | */ |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 633 | static int mled_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 635 | seq_printf(m, "%d\n", read_led(hotk->methods->mled_status, MLED_ON)); |
| 636 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 639 | static int mled_proc_open(struct inode *inode, struct file *file) |
| 640 | { |
| 641 | return single_open(file, mled_proc_show, NULL); |
| 642 | } |
| 643 | |
| 644 | static ssize_t mled_proc_write(struct file *file, const char __user *buffer, |
| 645 | size_t count, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | { |
| 647 | return write_led(buffer, count, hotk->methods->mt_mled, MLED_ON, 1); |
| 648 | } |
| 649 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 650 | static const struct file_operations mled_proc_fops = { |
| 651 | .owner = THIS_MODULE, |
| 652 | .open = mled_proc_open, |
| 653 | .read = seq_read, |
| 654 | .llseek = seq_lseek, |
| 655 | .release = single_release, |
| 656 | .write = mled_proc_write, |
| 657 | }; |
| 658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | /* |
Karol Kozimor | 42cb891 | 2006-06-30 19:04:00 -0400 | [diff] [blame] | 660 | * Proc handlers for LED display |
| 661 | */ |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 662 | static int ledd_proc_show(struct seq_file *m, void *v) |
Karol Kozimor | 42cb891 | 2006-06-30 19:04:00 -0400 | [diff] [blame] | 663 | { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 664 | seq_printf(m, "0x%08x\n", hotk->ledd_status); |
| 665 | return 0; |
Karol Kozimor | 42cb891 | 2006-06-30 19:04:00 -0400 | [diff] [blame] | 666 | } |
| 667 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 668 | static int ledd_proc_open(struct inode *inode, struct file *file) |
| 669 | { |
| 670 | return single_open(file, ledd_proc_show, NULL); |
| 671 | } |
| 672 | |
| 673 | static ssize_t ledd_proc_write(struct file *file, const char __user *buffer, |
| 674 | size_t count, loff_t *pos) |
Karol Kozimor | 42cb891 | 2006-06-30 19:04:00 -0400 | [diff] [blame] | 675 | { |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 676 | int rv, value; |
Karol Kozimor | 42cb891 | 2006-06-30 19:04:00 -0400 | [diff] [blame] | 677 | |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 678 | rv = parse_arg(buffer, count, &value); |
| 679 | if (rv > 0) { |
Karol Kozimor | 42cb891 | 2006-06-30 19:04:00 -0400 | [diff] [blame] | 680 | if (!write_acpi_int |
| 681 | (hotk->handle, hotk->methods->mt_ledd, value, NULL)) |
| 682 | printk(KERN_WARNING |
| 683 | "Asus ACPI: LED display write failed\n"); |
| 684 | else |
| 685 | hotk->ledd_status = (u32) value; |
Alexey Dobriyan | 6df0570 | 2006-10-10 14:20:36 -0700 | [diff] [blame] | 686 | } |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 687 | return rv; |
Karol Kozimor | 42cb891 | 2006-06-30 19:04:00 -0400 | [diff] [blame] | 688 | } |
| 689 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 690 | static const struct file_operations ledd_proc_fops = { |
| 691 | .owner = THIS_MODULE, |
| 692 | .open = ledd_proc_open, |
| 693 | .read = seq_read, |
| 694 | .llseek = seq_lseek, |
| 695 | .release = single_release, |
| 696 | .write = ledd_proc_write, |
| 697 | }; |
| 698 | |
Karol Kozimor | 42cb891 | 2006-06-30 19:04:00 -0400 | [diff] [blame] | 699 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | * Proc handlers for WLED |
| 701 | */ |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 702 | static int wled_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 704 | seq_printf(m, "%d\n", read_led(hotk->methods->wled_status, WLED_ON)); |
| 705 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 708 | static int wled_proc_open(struct inode *inode, struct file *file) |
| 709 | { |
| 710 | return single_open(file, wled_proc_show, NULL); |
| 711 | } |
| 712 | |
| 713 | static ssize_t wled_proc_write(struct file *file, const char __user *buffer, |
| 714 | size_t count, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | { |
| 716 | return write_led(buffer, count, hotk->methods->mt_wled, WLED_ON, 0); |
| 717 | } |
| 718 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 719 | static const struct file_operations wled_proc_fops = { |
| 720 | .owner = THIS_MODULE, |
| 721 | .open = wled_proc_open, |
| 722 | .read = seq_read, |
| 723 | .llseek = seq_lseek, |
| 724 | .release = single_release, |
| 725 | .write = wled_proc_write, |
| 726 | }; |
| 727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | /* |
Karol Kozimor | e067aaa | 2006-06-30 19:07:00 -0400 | [diff] [blame] | 729 | * Proc handlers for Bluetooth |
| 730 | */ |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 731 | static int bluetooth_proc_show(struct seq_file *m, void *v) |
Karol Kozimor | e067aaa | 2006-06-30 19:07:00 -0400 | [diff] [blame] | 732 | { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 733 | seq_printf(m, "%d\n", read_led(hotk->methods->bt_status, BT_ON)); |
| 734 | return 0; |
Karol Kozimor | e067aaa | 2006-06-30 19:07:00 -0400 | [diff] [blame] | 735 | } |
| 736 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 737 | static int bluetooth_proc_open(struct inode *inode, struct file *file) |
| 738 | { |
| 739 | return single_open(file, bluetooth_proc_show, NULL); |
| 740 | } |
| 741 | |
| 742 | static ssize_t bluetooth_proc_write(struct file *file, |
| 743 | const char __user *buffer, size_t count, loff_t *pos) |
Karol Kozimor | e067aaa | 2006-06-30 19:07:00 -0400 | [diff] [blame] | 744 | { |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 745 | /* Note: mt_bt_switch controls both internal Bluetooth adapter's |
Karol Kozimor | e067aaa | 2006-06-30 19:07:00 -0400 | [diff] [blame] | 746 | presence and its LED */ |
| 747 | return write_led(buffer, count, hotk->methods->mt_bt_switch, BT_ON, 0); |
| 748 | } |
| 749 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 750 | static const struct file_operations bluetooth_proc_fops = { |
| 751 | .owner = THIS_MODULE, |
| 752 | .open = bluetooth_proc_open, |
| 753 | .read = seq_read, |
| 754 | .llseek = seq_lseek, |
| 755 | .release = single_release, |
| 756 | .write = bluetooth_proc_write, |
| 757 | }; |
| 758 | |
Karol Kozimor | e067aaa | 2006-06-30 19:07:00 -0400 | [diff] [blame] | 759 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | * Proc handlers for TLED |
| 761 | */ |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 762 | static int tled_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 764 | seq_printf(m, "%d\n", read_led(hotk->methods->tled_status, TLED_ON)); |
| 765 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 768 | static int tled_proc_open(struct inode *inode, struct file *file) |
| 769 | { |
| 770 | return single_open(file, tled_proc_show, NULL); |
| 771 | } |
| 772 | |
| 773 | static ssize_t tled_proc_write(struct file *file, const char __user *buffer, |
| 774 | size_t count, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | { |
| 776 | return write_led(buffer, count, hotk->methods->mt_tled, TLED_ON, 0); |
| 777 | } |
| 778 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 779 | static const struct file_operations tled_proc_fops = { |
| 780 | .owner = THIS_MODULE, |
| 781 | .open = tled_proc_open, |
| 782 | .read = seq_read, |
| 783 | .llseek = seq_lseek, |
| 784 | .release = single_release, |
| 785 | .write = tled_proc_write, |
| 786 | }; |
| 787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | static int get_lcd_state(void) |
| 789 | { |
| 790 | int lcd = 0; |
| 791 | |
Luca Tettamanti | 31e0729 | 2008-02-04 23:31:18 -0800 | [diff] [blame] | 792 | if (hotk->model == L3H) { |
| 793 | /* L3H and the like have to be handled differently */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | acpi_status status = 0; |
| 795 | struct acpi_object_list input; |
| 796 | union acpi_object mt_params[2]; |
| 797 | struct acpi_buffer output; |
| 798 | union acpi_object out_obj; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 799 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | input.count = 2; |
| 801 | input.pointer = mt_params; |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 802 | /* Note: the following values are partly guessed up, but |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | otherwise they seem to work */ |
| 804 | mt_params[0].type = ACPI_TYPE_INTEGER; |
| 805 | mt_params[0].integer.value = 0x02; |
| 806 | mt_params[1].type = ACPI_TYPE_INTEGER; |
| 807 | mt_params[1].integer.value = 0x02; |
| 808 | |
| 809 | output.length = sizeof(out_obj); |
| 810 | output.pointer = &out_obj; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 811 | |
| 812 | status = |
| 813 | acpi_evaluate_object(NULL, hotk->methods->lcd_status, |
| 814 | &input, &output); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | if (status != AE_OK) |
| 816 | return -1; |
| 817 | if (out_obj.type == ACPI_TYPE_INTEGER) |
| 818 | /* That's what the AML code does */ |
| 819 | lcd = out_obj.integer.value >> 8; |
Luca Tettamanti | 31e0729 | 2008-02-04 23:31:18 -0800 | [diff] [blame] | 820 | } else if (hotk->model == F3Sa) { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 821 | unsigned long long tmp; |
Luca Tettamanti | 31e0729 | 2008-02-04 23:31:18 -0800 | [diff] [blame] | 822 | union acpi_object param; |
| 823 | struct acpi_object_list input; |
| 824 | acpi_status status; |
| 825 | |
| 826 | /* Read pin 11 */ |
| 827 | param.type = ACPI_TYPE_INTEGER; |
| 828 | param.integer.value = 0x11; |
| 829 | input.count = 1; |
| 830 | input.pointer = ¶m; |
| 831 | |
| 832 | status = acpi_evaluate_integer(NULL, hotk->methods->lcd_status, |
| 833 | &input, &tmp); |
| 834 | if (status != AE_OK) |
| 835 | return -1; |
| 836 | |
| 837 | lcd = tmp; |
| 838 | } else { |
| 839 | /* We don't have to check anything if we are here */ |
| 840 | if (!read_acpi_int(NULL, hotk->methods->lcd_status, &lcd)) |
| 841 | printk(KERN_WARNING |
| 842 | "Asus ACPI: Error reading LCD status\n"); |
| 843 | |
| 844 | if (hotk->model == L2D) |
| 845 | lcd = ~lcd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | return (lcd & 1); |
| 849 | } |
| 850 | |
| 851 | static int set_lcd_state(int value) |
| 852 | { |
| 853 | int lcd = 0; |
| 854 | acpi_status status = 0; |
| 855 | |
| 856 | lcd = value ? 1 : 0; |
| 857 | if (lcd != get_lcd_state()) { |
| 858 | /* switch */ |
| 859 | if (hotk->model != L3H) { |
| 860 | status = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 861 | acpi_evaluate_object(NULL, |
| 862 | hotk->methods->mt_lcd_switch, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | NULL, NULL); |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 864 | } else { |
| 865 | /* L3H and the like must be handled differently */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 866 | if (!write_acpi_int |
| 867 | (hotk->handle, hotk->methods->mt_lcd_switch, 0x07, |
| 868 | NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | status = AE_ERROR; |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 870 | /* L3H's AML executes EHK (0x07) upon Fn+F7 keypress, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | the exact behaviour is simulated here */ |
| 872 | } |
| 873 | if (ACPI_FAILURE(status)) |
| 874 | printk(KERN_WARNING "Asus ACPI: Error switching LCD\n"); |
| 875 | } |
| 876 | return 0; |
| 877 | |
| 878 | } |
| 879 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 880 | static int lcd_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 882 | seq_printf(m, "%d\n", get_lcd_state()); |
| 883 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 886 | static int lcd_proc_open(struct inode *inode, struct file *file) |
| 887 | { |
| 888 | return single_open(file, lcd_proc_show, NULL); |
| 889 | } |
| 890 | |
| 891 | static ssize_t lcd_proc_write(struct file *file, const char __user *buffer, |
| 892 | size_t count, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | { |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 894 | int rv, value; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 895 | |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 896 | rv = parse_arg(buffer, count, &value); |
| 897 | if (rv > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | set_lcd_state(value); |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 899 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 902 | static const struct file_operations lcd_proc_fops = { |
| 903 | .owner = THIS_MODULE, |
| 904 | .open = lcd_proc_open, |
| 905 | .read = seq_read, |
| 906 | .llseek = seq_lseek, |
| 907 | .release = single_release, |
| 908 | .write = lcd_proc_write, |
| 909 | }; |
| 910 | |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 911 | static int read_brightness(struct backlight_device *bd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | { |
| 913 | int value; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 914 | |
| 915 | if (hotk->methods->brightness_get) { /* SPLV/GPLV laptop */ |
| 916 | if (!read_acpi_int(hotk->handle, hotk->methods->brightness_get, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | &value)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 918 | printk(KERN_WARNING |
| 919 | "Asus ACPI: Error reading brightness\n"); |
| 920 | } else if (hotk->methods->brightness_status) { /* For D1 for example */ |
| 921 | if (!read_acpi_int(NULL, hotk->methods->brightness_status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | &value)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 923 | printk(KERN_WARNING |
| 924 | "Asus ACPI: Error reading brightness\n"); |
| 925 | } else /* No GPLV method */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | value = hotk->brightness; |
| 927 | return value; |
| 928 | } |
| 929 | |
| 930 | /* |
| 931 | * Change the brightness level |
| 932 | */ |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 933 | static int set_brightness(int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | { |
| 935 | acpi_status status = 0; |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 936 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | |
| 938 | /* SPLV laptop */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 939 | if (hotk->methods->brightness_set) { |
| 940 | if (!write_acpi_int(hotk->handle, hotk->methods->brightness_set, |
Julia Lawall | 2e0ee69 | 2010-08-05 22:24:12 +0200 | [diff] [blame] | 941 | value, NULL)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 942 | printk(KERN_WARNING |
| 943 | "Asus ACPI: Error changing brightness\n"); |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 944 | ret = -EIO; |
Julia Lawall | 2e0ee69 | 2010-08-05 22:24:12 +0200 | [diff] [blame] | 945 | } |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 946 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | /* No SPLV method if we are here, act as appropriate */ |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 950 | value -= read_brightness(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | while (value != 0) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 952 | status = acpi_evaluate_object(NULL, (value > 0) ? |
| 953 | hotk->methods->brightness_up : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | hotk->methods->brightness_down, |
| 955 | NULL, NULL); |
| 956 | (value > 0) ? value-- : value++; |
Julia Lawall | 2e0ee69 | 2010-08-05 22:24:12 +0200 | [diff] [blame] | 957 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 958 | printk(KERN_WARNING |
| 959 | "Asus ACPI: Error changing brightness\n"); |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 960 | ret = -EIO; |
Julia Lawall | 2e0ee69 | 2010-08-05 22:24:12 +0200 | [diff] [blame] | 961 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | } |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 963 | out: |
| 964 | return ret; |
| 965 | } |
| 966 | |
| 967 | static int set_brightness_status(struct backlight_device *bd) |
| 968 | { |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 969 | return set_brightness(bd->props.brightness); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 972 | static int brn_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 974 | seq_printf(m, "%d\n", read_brightness(NULL)); |
| 975 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | } |
| 977 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 978 | static int brn_proc_open(struct inode *inode, struct file *file) |
| 979 | { |
| 980 | return single_open(file, brn_proc_show, NULL); |
| 981 | } |
| 982 | |
| 983 | static ssize_t brn_proc_write(struct file *file, const char __user *buffer, |
| 984 | size_t count, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | { |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 986 | int rv, value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 988 | rv = parse_arg(buffer, count, &value); |
| 989 | if (rv > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | value = (0 < value) ? ((15 < value) ? 15 : value) : 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 991 | /* 0 <= value <= 15 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | set_brightness(value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | } |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 994 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 997 | static const struct file_operations brn_proc_fops = { |
| 998 | .owner = THIS_MODULE, |
| 999 | .open = brn_proc_open, |
| 1000 | .read = seq_read, |
| 1001 | .llseek = seq_lseek, |
| 1002 | .release = single_release, |
| 1003 | .write = brn_proc_write, |
| 1004 | }; |
| 1005 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | static void set_display(int value) |
| 1007 | { |
| 1008 | /* no sanity check needed for now */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1009 | if (!write_acpi_int(hotk->handle, hotk->methods->display_set, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | value, NULL)) |
| 1011 | printk(KERN_WARNING "Asus ACPI: Error setting display\n"); |
| 1012 | return; |
| 1013 | } |
| 1014 | |
| 1015 | /* |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 1016 | * Now, *this* one could be more user-friendly, but so far, no-one has |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | * complained. The significance of bits is the same as in proc_write_disp() |
| 1018 | */ |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1019 | static int disp_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | { |
| 1021 | int value = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | if (!read_acpi_int(hotk->handle, hotk->methods->display_get, &value)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1024 | printk(KERN_WARNING |
| 1025 | "Asus ACPI: Error reading display status\n"); |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 1026 | value &= 0x07; /* needed for some models, shouldn't hurt others */ |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1027 | seq_printf(m, "%d\n", value); |
| 1028 | return 0; |
| 1029 | } |
| 1030 | |
| 1031 | static int disp_proc_open(struct inode *inode, struct file *file) |
| 1032 | { |
| 1033 | return single_open(file, disp_proc_show, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | /* |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 1037 | * Experimental support for display switching. As of now: 1 should activate |
| 1038 | * the LCD output, 2 should do for CRT, and 4 for TV-Out. Any combination |
| 1039 | * (bitwise) of these will suffice. I never actually tested 3 displays hooked |
| 1040 | * up simultaneously, so be warned. See the acpi4asus README for more info. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | */ |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1042 | static ssize_t disp_proc_write(struct file *file, const char __user *buffer, |
| 1043 | size_t count, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | { |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 1045 | int rv, value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 1047 | rv = parse_arg(buffer, count, &value); |
| 1048 | if (rv > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | set_display(value); |
Darren Jenkins | 6311f0d | 2006-10-10 14:20:35 -0700 | [diff] [blame] | 1050 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1053 | static const struct file_operations disp_proc_fops = { |
| 1054 | .owner = THIS_MODULE, |
| 1055 | .open = disp_proc_open, |
| 1056 | .read = seq_read, |
| 1057 | .llseek = seq_lseek, |
| 1058 | .release = single_release, |
| 1059 | .write = disp_proc_write, |
| 1060 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | |
| 1062 | static int |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1063 | asus_proc_add(char *name, const struct file_operations *proc_fops, mode_t mode, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1064 | struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1066 | struct proc_dir_entry *proc; |
| 1067 | |
| 1068 | proc = proc_create_data(name, mode, acpi_device_dir(device), |
| 1069 | proc_fops, acpi_driver_data(device)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1070 | if (!proc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | printk(KERN_WARNING " Unable to create %s fs entry\n", name); |
| 1072 | return -1; |
| 1073 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | proc->uid = asus_uid; |
| 1075 | proc->gid = asus_gid; |
| 1076 | return 0; |
| 1077 | } |
| 1078 | |
Bjorn Helgaas | 200739c | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 1079 | static int asus_hotk_add_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | { |
| 1081 | struct proc_dir_entry *proc; |
| 1082 | mode_t mode; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1083 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | /* |
| 1085 | * If parameter uid or gid is not changed, keep the default setting for |
| 1086 | * our proc entries (-rw-rw-rw-) else, it means we care about security, |
| 1087 | * and then set to -rw-rw---- |
| 1088 | */ |
| 1089 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1090 | if ((asus_uid == 0) && (asus_gid == 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | mode = S_IFREG | S_IRUGO | S_IWUGO; |
| 1092 | } else { |
| 1093 | mode = S_IFREG | S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP; |
Karol Kozimor | aea19aa | 2006-01-03 23:05:00 -0500 | [diff] [blame] | 1094 | printk(KERN_WARNING " asus_uid and asus_gid parameters are " |
| 1095 | "deprecated, use chown and chmod instead!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | acpi_device_dir(device) = asus_proc_dir; |
| 1099 | if (!acpi_device_dir(device)) |
| 1100 | return -ENODEV; |
| 1101 | |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1102 | proc = proc_create(PROC_INFO, mode, acpi_device_dir(device), |
| 1103 | &asus_info_proc_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | if (proc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | proc->uid = asus_uid; |
| 1106 | proc->gid = asus_gid; |
| 1107 | } else { |
| 1108 | printk(KERN_WARNING " Unable to create " PROC_INFO |
| 1109 | " fs entry\n"); |
| 1110 | } |
| 1111 | |
| 1112 | if (hotk->methods->mt_wled) { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1113 | asus_proc_add(PROC_WLED, &wled_proc_fops, mode, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
Karol Kozimor | 42cb891 | 2006-06-30 19:04:00 -0400 | [diff] [blame] | 1116 | if (hotk->methods->mt_ledd) { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1117 | asus_proc_add(PROC_LEDD, &ledd_proc_fops, mode, device); |
Karol Kozimor | 42cb891 | 2006-06-30 19:04:00 -0400 | [diff] [blame] | 1118 | } |
| 1119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | if (hotk->methods->mt_mled) { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1121 | asus_proc_add(PROC_MLED, &mled_proc_fops, mode, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | if (hotk->methods->mt_tled) { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1125 | asus_proc_add(PROC_TLED, &tled_proc_fops, mode, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Karol Kozimor | e067aaa | 2006-06-30 19:07:00 -0400 | [diff] [blame] | 1128 | if (hotk->methods->mt_bt_switch) { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1129 | asus_proc_add(PROC_BT, &bluetooth_proc_fops, mode, device); |
Karol Kozimor | e067aaa | 2006-06-30 19:07:00 -0400 | [diff] [blame] | 1130 | } |
| 1131 | |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 1132 | /* |
| 1133 | * We need both read node and write method as LCD switch is also |
| 1134 | * accessible from the keyboard |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | */ |
| 1136 | if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1137 | asus_proc_add(PROC_LCD, &lcd_proc_fops, mode, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | if ((hotk->methods->brightness_up && hotk->methods->brightness_down) || |
| 1141 | (hotk->methods->brightness_get && hotk->methods->brightness_set)) { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1142 | asus_proc_add(PROC_BRN, &brn_proc_fops, mode, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | if (hotk->methods->display_set) { |
Alexey Dobriyan | ff93be5 | 2009-12-21 16:20:01 -0800 | [diff] [blame] | 1146 | asus_proc_add(PROC_DISP, &disp_proc_fops, mode, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | return 0; |
| 1150 | } |
| 1151 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1152 | static int asus_hotk_remove_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1154 | if (acpi_device_dir(device)) { |
| 1155 | remove_proc_entry(PROC_INFO, acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | if (hotk->methods->mt_wled) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1157 | remove_proc_entry(PROC_WLED, acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | if (hotk->methods->mt_mled) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1159 | remove_proc_entry(PROC_MLED, acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | if (hotk->methods->mt_tled) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1161 | remove_proc_entry(PROC_TLED, acpi_device_dir(device)); |
Karol Kozimor | 42cb891 | 2006-06-30 19:04:00 -0400 | [diff] [blame] | 1162 | if (hotk->methods->mt_ledd) |
| 1163 | remove_proc_entry(PROC_LEDD, acpi_device_dir(device)); |
Karol Kozimor | e067aaa | 2006-06-30 19:07:00 -0400 | [diff] [blame] | 1164 | if (hotk->methods->mt_bt_switch) |
| 1165 | remove_proc_entry(PROC_BT, acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) |
| 1167 | remove_proc_entry(PROC_LCD, acpi_device_dir(device)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1168 | if ((hotk->methods->brightness_up |
| 1169 | && hotk->methods->brightness_down) |
| 1170 | || (hotk->methods->brightness_get |
| 1171 | && hotk->methods->brightness_set)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | remove_proc_entry(PROC_BRN, acpi_device_dir(device)); |
| 1173 | if (hotk->methods->display_set) |
| 1174 | remove_proc_entry(PROC_DISP, acpi_device_dir(device)); |
| 1175 | } |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
Bjorn Helgaas | 352fa20 | 2009-04-30 09:35:58 -0600 | [diff] [blame] | 1179 | static void asus_hotk_notify(struct acpi_device *device, u32 event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1181 | /* TODO Find a better way to handle events count. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | if (!hotk) |
| 1183 | return; |
| 1184 | |
Bjorn Helgaas | 352fa20 | 2009-04-30 09:35:58 -0600 | [diff] [blame] | 1185 | /* |
| 1186 | * The BIOS *should* be sending us device events, but apparently |
| 1187 | * Asus uses system events instead, so just ignore any device |
| 1188 | * events we get. |
| 1189 | */ |
| 1190 | if (event > ACPI_MAX_SYS_NOTIFY) |
| 1191 | return; |
| 1192 | |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 1193 | if ((event & ~((u32) BR_UP)) < 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | hotk->brightness = (event & ~((u32) BR_UP)); |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 1195 | else if ((event & ~((u32) BR_DOWN)) < 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | hotk->brightness = (event & ~((u32) BR_DOWN)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | |
Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 1198 | acpi_bus_generate_proc_event(hotk->device, event, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | hotk->event_count[event % 128]++); |
| 1200 | |
| 1201 | return; |
| 1202 | } |
| 1203 | |
| 1204 | /* |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1205 | * Match the model string to the list of supported models. Return END_MODEL if |
| 1206 | * no match or model is NULL. |
| 1207 | */ |
| 1208 | static int asus_model_match(char *model) |
| 1209 | { |
| 1210 | if (model == NULL) |
| 1211 | return END_MODEL; |
| 1212 | |
| 1213 | if (strncmp(model, "L3D", 3) == 0) |
| 1214 | return L3D; |
| 1215 | else if (strncmp(model, "L2E", 3) == 0 || |
| 1216 | strncmp(model, "L3H", 3) == 0 || strncmp(model, "L5D", 3) == 0) |
| 1217 | return L3H; |
| 1218 | else if (strncmp(model, "L3", 2) == 0 || strncmp(model, "L2B", 3) == 0) |
| 1219 | return L3C; |
| 1220 | else if (strncmp(model, "L8L", 3) == 0) |
| 1221 | return L8L; |
| 1222 | else if (strncmp(model, "L4R", 3) == 0) |
| 1223 | return L4R; |
| 1224 | else if (strncmp(model, "M6N", 3) == 0 || strncmp(model, "W3N", 3) == 0) |
| 1225 | return M6N; |
| 1226 | else if (strncmp(model, "M6R", 3) == 0 || strncmp(model, "A3G", 3) == 0) |
| 1227 | return M6R; |
| 1228 | else if (strncmp(model, "M2N", 3) == 0 || |
| 1229 | strncmp(model, "M3N", 3) == 0 || |
| 1230 | strncmp(model, "M5N", 3) == 0 || |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1231 | strncmp(model, "S1N", 3) == 0 || |
Roel Kluin | 6268f50 | 2010-03-01 13:26:22 -0500 | [diff] [blame] | 1232 | strncmp(model, "S5N", 3) == 0) |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1233 | return xxN; |
| 1234 | else if (strncmp(model, "M1", 2) == 0) |
| 1235 | return M1A; |
| 1236 | else if (strncmp(model, "M2", 2) == 0 || strncmp(model, "L4E", 3) == 0) |
| 1237 | return M2E; |
| 1238 | else if (strncmp(model, "L2", 2) == 0) |
| 1239 | return L2D; |
| 1240 | else if (strncmp(model, "L8", 2) == 0) |
| 1241 | return S1x; |
| 1242 | else if (strncmp(model, "D1", 2) == 0) |
| 1243 | return D1x; |
| 1244 | else if (strncmp(model, "A1", 2) == 0) |
| 1245 | return A1x; |
| 1246 | else if (strncmp(model, "A2", 2) == 0) |
| 1247 | return A2x; |
| 1248 | else if (strncmp(model, "J1", 2) == 0) |
| 1249 | return S2x; |
| 1250 | else if (strncmp(model, "L5", 2) == 0) |
| 1251 | return L5x; |
| 1252 | else if (strncmp(model, "A4G", 3) == 0) |
| 1253 | return A4G; |
| 1254 | else if (strncmp(model, "W1N", 3) == 0) |
| 1255 | return W1N; |
Marek W | 288f3ad | 2006-08-14 22:37:20 -0700 | [diff] [blame] | 1256 | else if (strncmp(model, "W3V", 3) == 0) |
| 1257 | return W3V; |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1258 | else if (strncmp(model, "W5A", 3) == 0) |
| 1259 | return W5A; |
Corentin Chary | 1021e21 | 2009-01-20 16:17:41 +0100 | [diff] [blame] | 1260 | else if (strncmp(model, "R1F", 3) == 0) |
| 1261 | return R1F; |
Matthew C Campbell | 1c0f057 | 2007-02-05 16:09:09 -0800 | [diff] [blame] | 1262 | else if (strncmp(model, "A4S", 3) == 0) |
| 1263 | return A4S; |
Luca Tettamanti | 31e0729 | 2008-02-04 23:31:18 -0800 | [diff] [blame] | 1264 | else if (strncmp(model, "F3Sa", 4) == 0) |
| 1265 | return F3Sa; |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1266 | else |
| 1267 | return END_MODEL; |
| 1268 | } |
| 1269 | |
| 1270 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | * This function is used to initialize the hotk with right values. In this |
| 1272 | * method, we can make all the detection we want, and modify the hotk struct |
| 1273 | */ |
Bjorn Helgaas | 200739c | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 1274 | static int asus_hotk_get_info(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | { |
| 1276 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | union acpi_object *model = NULL; |
| 1278 | int bsts_result; |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1279 | char *string = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | acpi_status status; |
| 1281 | |
| 1282 | /* |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 1283 | * Get DSDT headers early enough to allow for differentiating between |
| 1284 | * models, but late enough to allow acpi_bus_register_driver() to fail |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | * before doing anything ACPI-specific. Should we encounter a machine, |
| 1286 | * which needs special handling (i.e. its hotkey device has a different |
| 1287 | * HID), this bit will be moved. A global variable asus_info contains |
| 1288 | * the DSDT header. |
| 1289 | */ |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 1290 | status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | if (ACPI_FAILURE(status)) |
| 1292 | printk(KERN_WARNING " Couldn't get the DSDT table header\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | |
| 1294 | /* We have to write 0 on init this far for all ASUS models */ |
| 1295 | if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) { |
| 1296 | printk(KERN_ERR " Hotkey initialization failed\n"); |
| 1297 | return -ENODEV; |
| 1298 | } |
| 1299 | |
| 1300 | /* This needs to be called for some laptops to init properly */ |
| 1301 | if (!read_acpi_int(hotk->handle, "BSTS", &bsts_result)) |
| 1302 | printk(KERN_WARNING " Error calling BSTS\n"); |
| 1303 | else if (bsts_result) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1304 | printk(KERN_NOTICE " BSTS called, 0x%02x returned\n", |
| 1305 | bsts_result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | |
Karol Kozimor | b697b53 | 2005-12-22 12:42:00 -0500 | [diff] [blame] | 1307 | /* |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1308 | * Try to match the object returned by INIT to the specific model. |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 1309 | * Handle every possible object (or the lack of thereof) the DSDT |
| 1310 | * writers might throw at us. When in trouble, we pass NULL to |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1311 | * asus_model_match() and try something completely different. |
Karol Kozimor | b697b53 | 2005-12-22 12:42:00 -0500 | [diff] [blame] | 1312 | */ |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1313 | if (buffer.pointer) { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1314 | model = buffer.pointer; |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1315 | switch (model->type) { |
| 1316 | case ACPI_TYPE_STRING: |
| 1317 | string = model->string.pointer; |
| 1318 | break; |
| 1319 | case ACPI_TYPE_BUFFER: |
| 1320 | string = model->buffer.pointer; |
| 1321 | break; |
| 1322 | default: |
| 1323 | kfree(model); |
Jesper Juhl | de47b69 | 2007-07-29 00:45:59 +0200 | [diff] [blame] | 1324 | model = NULL; |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1325 | break; |
| 1326 | } |
| 1327 | } |
| 1328 | hotk->model = asus_model_match(string); |
| 1329 | if (hotk->model == END_MODEL) { /* match failed */ |
| 1330 | if (asus_info && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) { |
| 1332 | hotk->model = P30; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1333 | printk(KERN_NOTICE |
| 1334 | " Samsung P30 detected, supported\n"); |
Axel Lin | 3bf460f | 2010-07-20 15:19:42 -0700 | [diff] [blame] | 1335 | hotk->methods = &model_conf[hotk->model]; |
| 1336 | kfree(model); |
| 1337 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | } else { |
| 1339 | hotk->model = M2E; |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1340 | printk(KERN_NOTICE " unsupported model %s, trying " |
| 1341 | "default values\n", string); |
| 1342 | printk(KERN_NOTICE |
| 1343 | " send /proc/acpi/dsdt to the developers\n"); |
Zhang Rui | 7745384 | 2008-10-17 01:42:41 -0400 | [diff] [blame] | 1344 | kfree(model); |
| 1345 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | hotk->methods = &model_conf[hotk->model]; |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1349 | printk(KERN_NOTICE " %s model detected, supported\n", string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | |
| 1351 | /* Sort of per-model blacklist */ |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1352 | if (strncmp(string, "L2B", 3) == 0) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1353 | hotk->methods->lcd_status = NULL; |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 1354 | /* L2B is similar enough to L3C to use its settings, with this only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | exception */ |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1356 | else if (strncmp(string, "A3G", 3) == 0) |
Karol Kozimor | ed2cb07 | 2006-06-30 19:03:00 -0400 | [diff] [blame] | 1357 | hotk->methods->lcd_status = "\\BLFG"; |
| 1358 | /* A3G is like M6R */ |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1359 | else if (strncmp(string, "S5N", 3) == 0 || |
| 1360 | strncmp(string, "M5N", 3) == 0 || |
| 1361 | strncmp(string, "W3N", 3) == 0) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1362 | hotk->methods->mt_mled = NULL; |
Karol Kozimor | c067a78 | 2006-06-30 19:05:00 -0400 | [diff] [blame] | 1363 | /* S5N, M5N and W3N have no MLED */ |
Karol Kozimor | ffab0d9 | 2006-06-30 19:11:00 -0400 | [diff] [blame] | 1364 | else if (strncmp(string, "L5D", 3) == 0) |
Karol Kozimor | ebccb84 | 2006-06-30 19:08:00 -0400 | [diff] [blame] | 1365 | hotk->methods->mt_wled = NULL; |
| 1366 | /* L5D's WLED is not controlled by ACPI */ |
Karol Kozimor | 96d1142 | 2006-06-30 19:13:00 -0400 | [diff] [blame] | 1367 | else if (strncmp(string, "M2N", 3) == 0 || |
Marek W | 288f3ad | 2006-08-14 22:37:20 -0700 | [diff] [blame] | 1368 | strncmp(string, "W3V", 3) == 0 || |
Karol Kozimor | 96d1142 | 2006-06-30 19:13:00 -0400 | [diff] [blame] | 1369 | strncmp(string, "S1N", 3) == 0) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1370 | hotk->methods->mt_wled = "WLED"; |
Marek W | 288f3ad | 2006-08-14 22:37:20 -0700 | [diff] [blame] | 1371 | /* M2N, S1N and W3V have a usable WLED */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | else if (asus_info) { |
| 1373 | if (strncmp(asus_info->oem_table_id, "L1", 2) == 0) |
| 1374 | hotk->methods->mled_status = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1375 | /* S1300A reports L84F, but L1400B too, account for that */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | } |
| 1377 | |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 1378 | kfree(model); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | |
Axel Lin | d47bb5b | 2010-07-20 15:19:41 -0700 | [diff] [blame] | 1380 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | } |
| 1382 | |
Bjorn Helgaas | 200739c | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 1383 | static int asus_hotk_check(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | { |
| 1385 | int result = 0; |
| 1386 | |
| 1387 | result = acpi_bus_get_status(hotk->device); |
| 1388 | if (result) |
| 1389 | return result; |
| 1390 | |
| 1391 | if (hotk->device->status.present) { |
| 1392 | result = asus_hotk_get_info(); |
| 1393 | } else { |
| 1394 | printk(KERN_ERR " Hotkey device not present, aborting\n"); |
| 1395 | return -EINVAL; |
| 1396 | } |
| 1397 | |
| 1398 | return result; |
| 1399 | } |
| 1400 | |
Bjorn Helgaas | 578b333 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 1401 | static int asus_hotk_found; |
| 1402 | |
Bjorn Helgaas | 200739c | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 1403 | static int asus_hotk_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | { |
| 1405 | acpi_status status = AE_OK; |
| 1406 | int result; |
| 1407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n", |
| 1409 | ASUS_ACPI_VERSION); |
| 1410 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 1411 | hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | if (!hotk) |
| 1413 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | |
| 1415 | hotk->handle = device->handle; |
| 1416 | strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME); |
| 1417 | strcpy(acpi_device_class(device), ACPI_HOTK_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 1418 | device->driver_data = hotk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | hotk->device = device; |
| 1420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | result = asus_hotk_check(); |
| 1422 | if (result) |
| 1423 | goto end; |
| 1424 | |
| 1425 | result = asus_hotk_add_fs(device); |
| 1426 | if (result) |
| 1427 | goto end; |
| 1428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | /* For laptops without GPLV: init the hotk->brightness value */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1430 | if ((!hotk->methods->brightness_get) |
| 1431 | && (!hotk->methods->brightness_status) |
Karol Kozimor | a170a53 | 2006-06-30 19:03:00 -0400 | [diff] [blame] | 1432 | && (hotk->methods->brightness_up && hotk->methods->brightness_down)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1433 | status = |
| 1434 | acpi_evaluate_object(NULL, hotk->methods->brightness_down, |
| 1435 | NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | if (ACPI_FAILURE(status)) |
| 1437 | printk(KERN_WARNING " Error changing brightness\n"); |
| 1438 | else { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1439 | status = |
| 1440 | acpi_evaluate_object(NULL, |
| 1441 | hotk->methods->brightness_up, |
| 1442 | NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | if (ACPI_FAILURE(status)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1444 | printk(KERN_WARNING " Strange, error changing" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | " brightness\n"); |
| 1446 | } |
| 1447 | } |
| 1448 | |
Bjorn Helgaas | 578b333 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 1449 | asus_hotk_found = 1; |
| 1450 | |
Karol Kozimor | 42cb891 | 2006-06-30 19:04:00 -0400 | [diff] [blame] | 1451 | /* LED display is off by default */ |
| 1452 | hotk->ledd_status = 0xFFF; |
| 1453 | |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 1454 | end: |
| 1455 | if (result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | kfree(hotk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | |
| 1458 | return result; |
| 1459 | } |
| 1460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | static int asus_hotk_remove(struct acpi_device *device, int type) |
| 1462 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | asus_hotk_remove_fs(device); |
| 1464 | |
| 1465 | kfree(hotk); |
| 1466 | |
| 1467 | return 0; |
| 1468 | } |
| 1469 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 1470 | static struct backlight_ops asus_backlight_data = { |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 1471 | .get_brightness = read_brightness, |
| 1472 | .update_status = set_brightness_status, |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1473 | }; |
| 1474 | |
Sam Ravnborg | b2b77b2 | 2007-06-01 00:47:12 -0700 | [diff] [blame] | 1475 | static void asus_acpi_exit(void) |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1476 | { |
| 1477 | if (asus_backlight_device) |
| 1478 | backlight_device_unregister(asus_backlight_device); |
| 1479 | |
| 1480 | acpi_bus_unregister_driver(&asus_hotk_driver); |
| 1481 | remove_proc_entry(PROC_ASUS, acpi_root_dir); |
| 1482 | |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1483 | return; |
| 1484 | } |
| 1485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | static int __init asus_acpi_init(void) |
| 1487 | { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 1488 | struct backlight_properties props; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | int result; |
| 1490 | |
Alan Jenkins | 5a4a9f6 | 2009-12-03 07:44:49 +0000 | [diff] [blame] | 1491 | result = acpi_bus_register_driver(&asus_hotk_driver); |
| 1492 | if (result < 0) |
| 1493 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir); |
| 1496 | if (!asus_proc_dir) { |
| 1497 | printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n"); |
Alan Jenkins | 5a4a9f6 | 2009-12-03 07:44:49 +0000 | [diff] [blame] | 1498 | acpi_bus_unregister_driver(&asus_hotk_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | return -ENODEV; |
| 1500 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | |
Bjorn Helgaas | 578b333 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 1502 | /* |
| 1503 | * This is a bit of a kludge. We only want this module loaded |
| 1504 | * for ASUS systems, but there's currently no way to probe the |
| 1505 | * ACPI namespace for ASUS HIDs. So we just return failure if |
| 1506 | * we didn't find one, which will cause the module to be |
| 1507 | * unloaded. |
| 1508 | */ |
| 1509 | if (!asus_hotk_found) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | acpi_bus_unregister_driver(&asus_hotk_driver); |
| 1511 | remove_proc_entry(PROC_ASUS, acpi_root_dir); |
Maxime Austruy | 5ebffd7 | 2007-07-01 12:06:38 -0700 | [diff] [blame] | 1512 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 1515 | memset(&props, 0, sizeof(struct backlight_properties)); |
| 1516 | props.max_brightness = 15; |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 1517 | asus_backlight_device = backlight_device_register("asus", NULL, NULL, |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 1518 | &asus_backlight_data, |
| 1519 | &props); |
Mike Dahlgren | c6c38ba | 2008-10-17 14:35:14 -0400 | [diff] [blame] | 1520 | if (IS_ERR(asus_backlight_device)) { |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1521 | printk(KERN_ERR "Could not register asus backlight device\n"); |
| 1522 | asus_backlight_device = NULL; |
| 1523 | asus_acpi_exit(); |
Maxime Austruy | 5ebffd7 | 2007-07-01 12:06:38 -0700 | [diff] [blame] | 1524 | return -ENODEV; |
Holger Macht | 2039a6e | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | return 0; |
| 1528 | } |
| 1529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | module_init(asus_acpi_init); |
| 1531 | module_exit(asus_acpi_exit); |