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