diff options
| author | Yong Wang <yong.y.wang@linux.intel.com> | 2010-04-10 21:27:54 -0400 |
|---|---|---|
| committer | Matthew Garrett <mjg@redhat.com> | 2010-04-12 13:02:52 -0400 |
| commit | 3d7b165539d4174b0b8396bd52ee37ba21bd0dfb (patch) | |
| tree | ac3b04212849485cb8d4ef44dfd94b62e484fdcf | |
| parent | 45f2c6937ed6066c9a177c4d37f6bd76daa607c0 (diff) | |
eeepc-wmi: add backlight support
Add backlight support for WMI based Eee PC laptops.
Signed-off-by: Yong Wang <yong.y.wang@intel.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>
Reviewed-by: Corentin Chary <corentincj@iksaif.net>
| -rw-r--r-- | drivers/platform/x86/eeepc-wmi.c | 232 |
1 files changed, 197 insertions, 35 deletions
diff --git a/drivers/platform/x86/eeepc-wmi.c b/drivers/platform/x86/eeepc-wmi.c index 0c9596c97a0f..b227eb469f49 100644 --- a/drivers/platform/x86/eeepc-wmi.c +++ b/drivers/platform/x86/eeepc-wmi.c | |||
| @@ -32,6 +32,8 @@ | |||
| 32 | #include <linux/slab.h> | 32 | #include <linux/slab.h> |
| 33 | #include <linux/input.h> | 33 | #include <linux/input.h> |
| 34 | #include <linux/input/sparse-keymap.h> | 34 | #include <linux/input/sparse-keymap.h> |
| 35 | #include <linux/fb.h> | ||
| 36 | #include <linux/backlight.h> | ||
| 35 | #include <linux/platform_device.h> | 37 | #include <linux/platform_device.h> |
| 36 | #include <acpi/acpi_bus.h> | 38 | #include <acpi/acpi_bus.h> |
| 37 | #include <acpi/acpi_drivers.h> | 39 | #include <acpi/acpi_drivers.h> |
| @@ -43,14 +45,21 @@ MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver"); | |||
| 43 | MODULE_LICENSE("GPL"); | 45 | MODULE_LICENSE("GPL"); |
| 44 | 46 | ||
| 45 | #define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000" | 47 | #define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000" |
| 48 | #define EEEPC_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66" | ||
| 46 | 49 | ||
| 47 | MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID); | 50 | MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID); |
| 51 | MODULE_ALIAS("wmi:"EEEPC_WMI_MGMT_GUID); | ||
| 48 | 52 | ||
| 49 | #define NOTIFY_BRNUP_MIN 0x11 | 53 | #define NOTIFY_BRNUP_MIN 0x11 |
| 50 | #define NOTIFY_BRNUP_MAX 0x1f | 54 | #define NOTIFY_BRNUP_MAX 0x1f |
| 51 | #define NOTIFY_BRNDOWN_MIN 0x20 | 55 | #define NOTIFY_BRNDOWN_MIN 0x20 |
| 52 | #define NOTIFY_BRNDOWN_MAX 0x2e | 56 | #define NOTIFY_BRNDOWN_MAX 0x2e |
| 53 | 57 | ||
| 58 | #define EEEPC_WMI_METHODID_DEVS 0x53564544 | ||
| 59 | #define EEEPC_WMI_METHODID_DSTS 0x53544344 | ||
| 60 | |||
| 61 | #define EEEPC_WMI_DEVID_BACKLIGHT 0x00050012 | ||
| 62 | |||
| 54 | static const struct key_entry eeepc_wmi_keymap[] = { | 63 | static const struct key_entry eeepc_wmi_keymap[] = { |
| 55 | /* Sleep already handled via generic ACPI code */ | 64 | /* Sleep already handled via generic ACPI code */ |
| 56 | { KE_KEY, 0x5d, { KEY_WLAN } }, | 65 | { KE_KEY, 0x5d, { KEY_WLAN } }, |
| @@ -63,44 +72,18 @@ static const struct key_entry eeepc_wmi_keymap[] = { | |||
| 63 | { KE_END, 0}, | 72 | { KE_END, 0}, |
| 64 | }; | 73 | }; |
| 65 | 74 | ||
| 75 | struct bios_args { | ||
| 76 | u32 dev_id; | ||
| 77 | u32 ctrl_param; | ||
| 78 | }; | ||
| 79 | |||
| 66 | struct eeepc_wmi { | 80 | struct eeepc_wmi { |
| 67 | struct input_dev *inputdev; | 81 | struct input_dev *inputdev; |
| 82 | struct backlight_device *backlight_device; | ||
| 68 | }; | 83 | }; |
| 69 | 84 | ||
| 70 | static struct platform_device *platform_device; | 85 | static struct platform_device *platform_device; |
| 71 | 86 | ||
| 72 | static void eeepc_wmi_notify(u32 value, void *context) | ||
| 73 | { | ||
| 74 | struct eeepc_wmi *eeepc = context; | ||
| 75 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; | ||
| 76 | union acpi_object *obj; | ||
| 77 | acpi_status status; | ||
| 78 | int code; | ||
| 79 | |||
| 80 | status = wmi_get_event_data(value, &response); | ||
| 81 | if (status != AE_OK) { | ||
| 82 | pr_err("bad event status 0x%x\n", status); | ||
| 83 | return; | ||
| 84 | } | ||
| 85 | |||
| 86 | obj = (union acpi_object *)response.pointer; | ||
| 87 | |||
| 88 | if (obj && obj->type == ACPI_TYPE_INTEGER) { | ||
| 89 | code = obj->integer.value; | ||
| 90 | |||
| 91 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) | ||
| 92 | code = NOTIFY_BRNUP_MIN; | ||
| 93 | else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX) | ||
| 94 | code = NOTIFY_BRNDOWN_MIN; | ||
| 95 | |||
| 96 | if (!sparse_keymap_report_event(eeepc->inputdev, | ||
| 97 | code, 1, true)) | ||
| 98 | pr_info("Unknown key %x pressed\n", code); | ||
| 99 | } | ||
| 100 | |||
| 101 | kfree(obj); | ||
| 102 | } | ||
| 103 | |||
| 104 | static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc) | 87 | static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc) |
| 105 | { | 88 | { |
| 106 | int err; | 89 | int err; |
| @@ -141,6 +124,174 @@ static void eeepc_wmi_input_exit(struct eeepc_wmi *eeepc) | |||
| 141 | eeepc->inputdev = NULL; | 124 | eeepc->inputdev = NULL; |
| 142 | } | 125 | } |
| 143 | 126 | ||
| 127 | static acpi_status eeepc_wmi_get_devstate(u32 dev_id, u32 *ctrl_param) | ||
| 128 | { | ||
| 129 | struct acpi_buffer input = { (acpi_size)sizeof(u32), &dev_id }; | ||
| 130 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; | ||
| 131 | union acpi_object *obj; | ||
| 132 | acpi_status status; | ||
| 133 | u32 tmp; | ||
| 134 | |||
| 135 | status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, | ||
| 136 | 1, EEEPC_WMI_METHODID_DSTS, &input, &output); | ||
| 137 | |||
| 138 | if (ACPI_FAILURE(status)) | ||
| 139 | return status; | ||
| 140 | |||
| 141 | obj = (union acpi_object *)output.pointer; | ||
| 142 | if (obj && obj->type == ACPI_TYPE_INTEGER) | ||
| 143 | tmp = (u32)obj->integer.value; | ||
| 144 | else | ||
| 145 | tmp = 0; | ||
| 146 | |||
| 147 | if (ctrl_param) | ||
| 148 | *ctrl_param = tmp; | ||
| 149 | |||
| 150 | kfree(obj); | ||
| 151 | |||
| 152 | return status; | ||
| 153 | |||
| 154 | } | ||
| 155 | |||
| 156 | static acpi_status eeepc_wmi_set_devstate(u32 dev_id, u32 ctrl_param) | ||
| 157 | { | ||
| 158 | struct bios_args args = { | ||
| 159 | .dev_id = dev_id, | ||
| 160 | .ctrl_param = ctrl_param, | ||
| 161 | }; | ||
| 162 | struct acpi_buffer input = { (acpi_size)sizeof(args), &args }; | ||
| 163 | acpi_status status; | ||
| 164 | |||
| 165 | status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, | ||
| 166 | 1, EEEPC_WMI_METHODID_DEVS, &input, NULL); | ||
| 167 | |||
| 168 | return status; | ||
| 169 | } | ||
| 170 | |||
| 171 | static int read_brightness(struct backlight_device *bd) | ||
| 172 | { | ||
| 173 | static u32 ctrl_param; | ||
| 174 | acpi_status status; | ||
| 175 | |||
| 176 | status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_BACKLIGHT, &ctrl_param); | ||
| 177 | |||
| 178 | if (ACPI_FAILURE(status)) | ||
| 179 | return -1; | ||
| 180 | else | ||
| 181 | return ctrl_param & 0xFF; | ||
| 182 | } | ||
| 183 | |||
| 184 | static int update_bl_status(struct backlight_device *bd) | ||
| 185 | { | ||
| 186 | |||
| 187 | static u32 ctrl_param; | ||
| 188 | acpi_status status; | ||
| 189 | |||
| 190 | ctrl_param = bd->props.brightness; | ||
| 191 | |||
| 192 | status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BACKLIGHT, ctrl_param); | ||
| 193 | |||
| 194 | if (ACPI_FAILURE(status)) | ||
| 195 | return -1; | ||
| 196 | else | ||
| 197 | return 0; | ||
| 198 | } | ||
| 199 | |||
| 200 | static const struct backlight_ops eeepc_wmi_bl_ops = { | ||
| 201 | .get_brightness = read_brightness, | ||
| 202 | .update_status = update_bl_status, | ||
| 203 | }; | ||
| 204 | |||
| 205 | static int eeepc_wmi_backlight_notify(struct eeepc_wmi *eeepc, int code) | ||
| 206 | { | ||
| 207 | struct backlight_device *bd = eeepc->backlight_device; | ||
| 208 | int old = bd->props.brightness; | ||
| 209 | int new; | ||
| 210 | |||
| 211 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) | ||
| 212 | new = code - NOTIFY_BRNUP_MIN + 1; | ||
| 213 | else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX) | ||
| 214 | new = code - NOTIFY_BRNDOWN_MIN; | ||
| 215 | |||
| 216 | bd->props.brightness = new; | ||
| 217 | backlight_update_status(bd); | ||
| 218 | backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY); | ||
| 219 | |||
| 220 | return old; | ||
| 221 | } | ||
| 222 | |||
| 223 | static int eeepc_wmi_backlight_init(struct eeepc_wmi *eeepc) | ||
| 224 | { | ||
| 225 | struct backlight_device *bd; | ||
| 226 | struct backlight_properties props; | ||
| 227 | |||
| 228 | memset(&props, 0, sizeof(struct backlight_properties)); | ||
| 229 | props.max_brightness = 15; | ||
| 230 | bd = backlight_device_register(EEEPC_WMI_FILE, | ||
| 231 | &platform_device->dev, eeepc, | ||
| 232 | &eeepc_wmi_bl_ops, &props); | ||
| 233 | if (IS_ERR(bd)) { | ||
| 234 | pr_err("Could not register backlight device\n"); | ||
| 235 | return PTR_ERR(bd); | ||
| 236 | } | ||
| 237 | |||
| 238 | eeepc->backlight_device = bd; | ||
| 239 | |||
| 240 | bd->props.brightness = read_brightness(bd); | ||
| 241 | bd->props.power = FB_BLANK_UNBLANK; | ||
| 242 | backlight_update_status(bd); | ||
| 243 | |||
| 244 | return 0; | ||
| 245 | } | ||
| 246 | |||
| 247 | static void eeepc_wmi_backlight_exit(struct eeepc_wmi *eeepc) | ||
| 248 | { | ||
| 249 | if (eeepc->backlight_device) | ||
| 250 | backlight_device_unregister(eeepc->backlight_device); | ||
| 251 | |||
| 252 | eeepc->backlight_device = NULL; | ||
| 253 | } | ||
| 254 | |||
| 255 | static void eeepc_wmi_notify(u32 value, void *context) | ||
| 256 | { | ||
| 257 | struct eeepc_wmi *eeepc = context; | ||
| 258 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; | ||
| 259 | union acpi_object *obj; | ||
| 260 | acpi_status status; | ||
| 261 | int code; | ||
| 262 | int orig_code; | ||
| 263 | |||
| 264 | status = wmi_get_event_data(value, &response); | ||
| 265 | if (status != AE_OK) { | ||
| 266 | pr_err("bad event status 0x%x\n", status); | ||
| 267 | return; | ||
| 268 | } | ||
| 269 | |||
| 270 | obj = (union acpi_object *)response.pointer; | ||
| 271 | |||
| 272 | if (obj && obj->type == ACPI_TYPE_INTEGER) { | ||
| 273 | code = obj->integer.value; | ||
| 274 | orig_code = code; | ||
| 275 | |||
| 276 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) | ||
| 277 | code = NOTIFY_BRNUP_MIN; | ||
| 278 | else if (code >= NOTIFY_BRNDOWN_MIN && | ||
| 279 | code <= NOTIFY_BRNDOWN_MAX) | ||
| 280 | code = NOTIFY_BRNDOWN_MIN; | ||
| 281 | |||
| 282 | if (code == NOTIFY_BRNUP_MIN || code == NOTIFY_BRNDOWN_MIN) { | ||
| 283 | if (!acpi_video_backlight_support()) | ||
| 284 | eeepc_wmi_backlight_notify(eeepc, orig_code); | ||
| 285 | } | ||
| 286 | |||
| 287 | if (!sparse_keymap_report_event(eeepc->inputdev, | ||
| 288 | code, 1, true)) | ||
| 289 | pr_info("Unknown key %x pressed\n", code); | ||
| 290 | } | ||
| 291 | |||
| 292 | kfree(obj); | ||
| 293 | } | ||
| 294 | |||
| 144 | static int __devinit eeepc_wmi_platform_probe(struct platform_device *device) | 295 | static int __devinit eeepc_wmi_platform_probe(struct platform_device *device) |
| 145 | { | 296 | { |
| 146 | struct eeepc_wmi *eeepc; | 297 | struct eeepc_wmi *eeepc; |
| @@ -151,7 +302,14 @@ static int __devinit eeepc_wmi_platform_probe(struct platform_device *device) | |||
| 151 | 302 | ||
| 152 | err = eeepc_wmi_input_init(eeepc); | 303 | err = eeepc_wmi_input_init(eeepc); |
| 153 | if (err) | 304 | if (err) |
| 154 | return err; | 305 | goto error_input; |
| 306 | |||
| 307 | if (!acpi_video_backlight_support()) { | ||
| 308 | err = eeepc_wmi_backlight_init(eeepc); | ||
| 309 | if (err) | ||
| 310 | goto error_backlight; | ||
| 311 | } else | ||
| 312 | pr_info("Backlight controlled by ACPI video driver\n"); | ||
| 155 | 313 | ||
| 156 | status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID, | 314 | status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID, |
| 157 | eeepc_wmi_notify, eeepc); | 315 | eeepc_wmi_notify, eeepc); |
| @@ -165,8 +323,10 @@ static int __devinit eeepc_wmi_platform_probe(struct platform_device *device) | |||
| 165 | return 0; | 323 | return 0; |
| 166 | 324 | ||
| 167 | error_wmi: | 325 | error_wmi: |
| 326 | eeepc_wmi_backlight_exit(eeepc); | ||
| 327 | error_backlight: | ||
| 168 | eeepc_wmi_input_exit(eeepc); | 328 | eeepc_wmi_input_exit(eeepc); |
| 169 | 329 | error_input: | |
| 170 | return err; | 330 | return err; |
| 171 | } | 331 | } |
| 172 | 332 | ||
| @@ -176,6 +336,7 @@ static int __devexit eeepc_wmi_platform_remove(struct platform_device *device) | |||
| 176 | 336 | ||
| 177 | eeepc = platform_get_drvdata(device); | 337 | eeepc = platform_get_drvdata(device); |
| 178 | wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID); | 338 | wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID); |
| 339 | eeepc_wmi_backlight_exit(eeepc); | ||
| 179 | eeepc_wmi_input_exit(eeepc); | 340 | eeepc_wmi_input_exit(eeepc); |
| 180 | 341 | ||
| 181 | return 0; | 342 | return 0; |
| @@ -195,7 +356,8 @@ static int __init eeepc_wmi_init(void) | |||
| 195 | struct eeepc_wmi *eeepc; | 356 | struct eeepc_wmi *eeepc; |
| 196 | int err; | 357 | int err; |
| 197 | 358 | ||
| 198 | if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID)) { | 359 | if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID) || |
| 360 | !wmi_has_guid(EEEPC_WMI_MGMT_GUID)) { | ||
| 199 | pr_warning("No known WMI GUID found\n"); | 361 | pr_warning("No known WMI GUID found\n"); |
| 200 | return -ENODEV; | 362 | return -ENODEV; |
| 201 | } | 363 | } |
