Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 1 | /* |
| 2 | * ACPI driver for Topstar notebooks (hotkeys support only) |
| 3 | * |
| 4 | * Copyright (c) 2009 Herton Ronaldo Krzesinski <herton@mandriva.com.br> |
| 5 | * |
| 6 | * Implementation inspired by existing x86 platform drivers, in special |
| 7 | * asus/eepc/fujitsu-laptop, thanks to their authors |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 20 | #include <linux/acpi.h> |
| 21 | #include <linux/input.h> |
Dmitry Torokhov | 97490f1 | 2010-08-04 22:29:57 -0700 | [diff] [blame] | 22 | #include <linux/input/sparse-keymap.h> |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 23 | |
| 24 | #define ACPI_TOPSTAR_CLASS "topstar" |
| 25 | |
| 26 | struct topstar_hkey { |
| 27 | struct input_dev *inputdev; |
| 28 | }; |
| 29 | |
Dmitry Torokhov | 97490f1 | 2010-08-04 22:29:57 -0700 | [diff] [blame] | 30 | static const struct key_entry topstar_keymap[] = { |
| 31 | { KE_KEY, 0x80, { KEY_BRIGHTNESSUP } }, |
| 32 | { KE_KEY, 0x81, { KEY_BRIGHTNESSDOWN } }, |
| 33 | { KE_KEY, 0x83, { KEY_VOLUMEUP } }, |
| 34 | { KE_KEY, 0x84, { KEY_VOLUMEDOWN } }, |
| 35 | { KE_KEY, 0x85, { KEY_MUTE } }, |
| 36 | { KE_KEY, 0x86, { KEY_SWITCHVIDEOMODE } }, |
| 37 | { KE_KEY, 0x87, { KEY_F13 } }, /* touchpad enable/disable key */ |
| 38 | { KE_KEY, 0x88, { KEY_WLAN } }, |
| 39 | { KE_KEY, 0x8a, { KEY_WWW } }, |
| 40 | { KE_KEY, 0x8b, { KEY_MAIL } }, |
| 41 | { KE_KEY, 0x8c, { KEY_MEDIA } }, |
| 42 | |
| 43 | /* Known non hotkey events don't handled or that we don't care yet */ |
Manuel Lauss | bd03808 | 2011-09-26 15:04:54 +0200 | [diff] [blame] | 44 | { KE_IGNORE, 0x82, }, /* backlight event */ |
Dmitry Torokhov | 97490f1 | 2010-08-04 22:29:57 -0700 | [diff] [blame] | 45 | { KE_IGNORE, 0x8e, }, |
| 46 | { KE_IGNORE, 0x8f, }, |
| 47 | { KE_IGNORE, 0x90, }, |
| 48 | |
| 49 | /* |
| 50 | * 'G key' generate two event codes, convert to only |
| 51 | * one event/key code for now, consider replacing by |
| 52 | * a switch (3G switch - SW_3G?) |
| 53 | */ |
| 54 | { KE_KEY, 0x96, { KEY_F14 } }, |
| 55 | { KE_KEY, 0x97, { KEY_F14 } }, |
| 56 | |
| 57 | { KE_END, 0 } |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 58 | }; |
| 59 | |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 60 | static void acpi_topstar_notify(struct acpi_device *device, u32 event) |
| 61 | { |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 62 | static bool dup_evnt[2]; |
| 63 | bool *dup; |
| 64 | struct topstar_hkey *hkey = acpi_driver_data(device); |
| 65 | |
| 66 | /* 0x83 and 0x84 key events comes duplicated... */ |
| 67 | if (event == 0x83 || event == 0x84) { |
| 68 | dup = &dup_evnt[event - 0x83]; |
| 69 | if (*dup) { |
| 70 | *dup = false; |
| 71 | return; |
| 72 | } |
| 73 | *dup = true; |
| 74 | } |
| 75 | |
Dmitry Torokhov | 97490f1 | 2010-08-04 22:29:57 -0700 | [diff] [blame] | 76 | if (!sparse_keymap_report_event(hkey->inputdev, event, 1, true)) |
| 77 | pr_info("unknown event = 0x%02x\n", event); |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static int acpi_topstar_fncx_switch(struct acpi_device *device, bool state) |
| 81 | { |
| 82 | acpi_status status; |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 83 | |
Zhang Rui | a7f6451 | 2013-09-03 08:31:55 +0800 | [diff] [blame] | 84 | status = acpi_execute_simple_method(device->handle, "FNCX", |
| 85 | state ? 0x86 : 0x87); |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 86 | if (ACPI_FAILURE(status)) { |
| 87 | pr_err("Unable to switch FNCX notifications\n"); |
| 88 | return -ENODEV; |
| 89 | } |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 94 | static int acpi_topstar_init_hkey(struct topstar_hkey *hkey) |
| 95 | { |
Dmitry Torokhov | 97490f1 | 2010-08-04 22:29:57 -0700 | [diff] [blame] | 96 | struct input_dev *input; |
| 97 | int error; |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 98 | |
Dmitry Torokhov | 97490f1 | 2010-08-04 22:29:57 -0700 | [diff] [blame] | 99 | input = input_allocate_device(); |
Joe Perches | b222cca | 2013-10-23 12:14:52 -0700 | [diff] [blame] | 100 | if (!input) |
Dmitry Torokhov | 97490f1 | 2010-08-04 22:29:57 -0700 | [diff] [blame] | 101 | return -ENOMEM; |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 102 | |
Dmitry Torokhov | 97490f1 | 2010-08-04 22:29:57 -0700 | [diff] [blame] | 103 | input->name = "Topstar Laptop extra buttons"; |
| 104 | input->phys = "topstar/input0"; |
| 105 | input->id.bustype = BUS_HOST; |
| 106 | |
| 107 | error = sparse_keymap_setup(input, topstar_keymap, NULL); |
| 108 | if (error) { |
| 109 | pr_err("Unable to setup input device keymap\n"); |
| 110 | goto err_free_dev; |
| 111 | } |
| 112 | |
| 113 | error = input_register_device(input); |
| 114 | if (error) { |
| 115 | pr_err("Unable to register input device\n"); |
Michał Kępień | 3f2e1a3 | 2017-03-09 13:11:48 +0100 | [diff] [blame] | 116 | goto err_free_dev; |
Dmitry Torokhov | 97490f1 | 2010-08-04 22:29:57 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | hkey->inputdev = input; |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 120 | return 0; |
Dmitry Torokhov | 97490f1 | 2010-08-04 22:29:57 -0700 | [diff] [blame] | 121 | |
Dmitry Torokhov | 97490f1 | 2010-08-04 22:29:57 -0700 | [diff] [blame] | 122 | err_free_dev: |
| 123 | input_free_device(input); |
| 124 | return error; |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | static int acpi_topstar_add(struct acpi_device *device) |
| 128 | { |
| 129 | struct topstar_hkey *tps_hkey; |
| 130 | |
| 131 | tps_hkey = kzalloc(sizeof(struct topstar_hkey), GFP_KERNEL); |
| 132 | if (!tps_hkey) |
| 133 | return -ENOMEM; |
| 134 | |
| 135 | strcpy(acpi_device_name(device), "Topstar TPSACPI"); |
| 136 | strcpy(acpi_device_class(device), ACPI_TOPSTAR_CLASS); |
| 137 | |
| 138 | if (acpi_topstar_fncx_switch(device, true)) |
| 139 | goto add_err; |
| 140 | |
| 141 | if (acpi_topstar_init_hkey(tps_hkey)) |
| 142 | goto add_err; |
| 143 | |
| 144 | device->driver_data = tps_hkey; |
| 145 | return 0; |
| 146 | |
| 147 | add_err: |
| 148 | kfree(tps_hkey); |
| 149 | return -ENODEV; |
| 150 | } |
| 151 | |
Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 152 | static int acpi_topstar_remove(struct acpi_device *device) |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 153 | { |
| 154 | struct topstar_hkey *tps_hkey = acpi_driver_data(device); |
| 155 | |
| 156 | acpi_topstar_fncx_switch(device, false); |
| 157 | |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 158 | input_unregister_device(tps_hkey->inputdev); |
| 159 | kfree(tps_hkey); |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | static const struct acpi_device_id topstar_device_ids[] = { |
| 165 | { "TPSACPI01", 0 }, |
| 166 | { "", 0 }, |
| 167 | }; |
| 168 | MODULE_DEVICE_TABLE(acpi, topstar_device_ids); |
| 169 | |
| 170 | static struct acpi_driver acpi_topstar_driver = { |
| 171 | .name = "Topstar laptop ACPI driver", |
| 172 | .class = ACPI_TOPSTAR_CLASS, |
| 173 | .ids = topstar_device_ids, |
| 174 | .ops = { |
| 175 | .add = acpi_topstar_add, |
| 176 | .remove = acpi_topstar_remove, |
| 177 | .notify = acpi_topstar_notify, |
| 178 | }, |
| 179 | }; |
Mika Westerberg | 1516559 | 2012-09-07 10:31:47 +0300 | [diff] [blame] | 180 | module_acpi_driver(acpi_topstar_driver); |
Herton Ronaldo Krzesinski | 9caeb53 | 2009-09-14 21:11:21 -0300 | [diff] [blame] | 181 | |
| 182 | MODULE_AUTHOR("Herton Ronaldo Krzesinski"); |
| 183 | MODULE_DESCRIPTION("Topstar Laptop ACPI Extras driver"); |
| 184 | MODULE_LICENSE("GPL"); |