^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Topstar Laptop ACPI Extras driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2009 Herton Ronaldo Krzesinski <herton@mandriva.com.br>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2018 Guillaume Douézan-Grard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Implementation inspired by existing x86 platform drivers, in special
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * asus/eepc/fujitsu-laptop, thanks to their authors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/input/sparse-keymap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define TOPSTAR_LAPTOP_CLASS "topstar"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct topstar_laptop {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct acpi_device *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct platform_device *platform;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct led_classdev led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * LED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static enum led_brightness topstar_led_get(struct led_classdev *led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return led->brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static int topstar_led_set(struct led_classdev *led,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) enum led_brightness state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct topstar_laptop *topstar = container_of(led,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct topstar_laptop, led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct acpi_object_list params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) union acpi_object in_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) unsigned long long int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) params.count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) params.pointer = &in_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) in_obj.type = ACPI_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) in_obj.integer.value = 0x83;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * Topstar ACPI returns 0x30001 when the LED is ON and 0x30000 when it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * is OFF.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) status = acpi_evaluate_integer(topstar->device->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) "GETX", ¶ms, &ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * FNCX(0x83) toggles the LED (more precisely, it is supposed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * act as an hardware switch and disconnect the WLAN adapter but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * it seems to be faulty on some models like the Topstar U931
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * Notebook).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if ((ret == 0x30001 && state == LED_OFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) || (ret == 0x30000 && state != LED_OFF)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) status = acpi_execute_simple_method(topstar->device->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) "FNCX", 0x83);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static int topstar_led_init(struct topstar_laptop *topstar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) topstar->led = (struct led_classdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .default_trigger = "rfkill0",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .brightness_get = topstar_led_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .brightness_set_blocking = topstar_led_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .name = TOPSTAR_LAPTOP_CLASS "::wlan",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return led_classdev_register(&topstar->platform->dev, &topstar->led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static void topstar_led_exit(struct topstar_laptop *topstar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) led_classdev_unregister(&topstar->led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * Input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static const struct key_entry topstar_keymap[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) { KE_KEY, 0x80, { KEY_BRIGHTNESSUP } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) { KE_KEY, 0x81, { KEY_BRIGHTNESSDOWN } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) { KE_KEY, 0x83, { KEY_VOLUMEUP } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) { KE_KEY, 0x84, { KEY_VOLUMEDOWN } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) { KE_KEY, 0x85, { KEY_MUTE } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) { KE_KEY, 0x86, { KEY_SWITCHVIDEOMODE } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) { KE_KEY, 0x87, { KEY_F13 } }, /* touchpad enable/disable key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) { KE_KEY, 0x88, { KEY_WLAN } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) { KE_KEY, 0x8a, { KEY_WWW } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) { KE_KEY, 0x8b, { KEY_MAIL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) { KE_KEY, 0x8c, { KEY_MEDIA } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* Known non hotkey events don't handled or that we don't care yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) { KE_IGNORE, 0x82, }, /* backlight event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) { KE_IGNORE, 0x8e, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) { KE_IGNORE, 0x8f, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) { KE_IGNORE, 0x90, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * 'G key' generate two event codes, convert to only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * one event/key code for now, consider replacing by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * a switch (3G switch - SW_3G?)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) { KE_KEY, 0x96, { KEY_F14 } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) { KE_KEY, 0x97, { KEY_F14 } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) { KE_END, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static void topstar_input_notify(struct topstar_laptop *topstar, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (!sparse_keymap_report_event(topstar->input, event, 1, true))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) pr_info("unknown event = 0x%02x\n", event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static int topstar_input_init(struct topstar_laptop *topstar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) input = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (!input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) input->name = "Topstar Laptop extra buttons";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) input->phys = TOPSTAR_LAPTOP_CLASS "/input0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) input->id.bustype = BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) input->dev.parent = &topstar->platform->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) err = sparse_keymap_setup(input, topstar_keymap, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) pr_err("Unable to setup input device keymap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) goto err_free_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) err = input_register_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) pr_err("Unable to register input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) goto err_free_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) topstar->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) err_free_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) input_free_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static void topstar_input_exit(struct topstar_laptop *topstar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) input_unregister_device(topstar->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * Platform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static struct platform_driver topstar_platform_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) .name = TOPSTAR_LAPTOP_CLASS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static int topstar_platform_init(struct topstar_laptop *topstar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) topstar->platform = platform_device_alloc(TOPSTAR_LAPTOP_CLASS, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (!topstar->platform)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) platform_set_drvdata(topstar->platform, topstar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) err = platform_device_add(topstar->platform);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) goto err_device_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) err_device_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) platform_device_put(topstar->platform);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static void topstar_platform_exit(struct topstar_laptop *topstar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) platform_device_unregister(topstar->platform);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static int topstar_acpi_fncx_switch(struct acpi_device *device, bool state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) u64 arg = state ? 0x86 : 0x87;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) status = acpi_execute_simple_method(device->handle, "FNCX", arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) pr_err("Unable to switch FNCX notifications\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static void topstar_acpi_notify(struct acpi_device *device, u32 event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct topstar_laptop *topstar = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static bool dup_evnt[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) bool *dup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* 0x83 and 0x84 key events comes duplicated... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (event == 0x83 || event == 0x84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) dup = &dup_evnt[event - 0x83];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (*dup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) *dup = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) *dup = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) topstar_input_notify(topstar, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static int topstar_acpi_init(struct topstar_laptop *topstar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return topstar_acpi_fncx_switch(topstar->device, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static void topstar_acpi_exit(struct topstar_laptop *topstar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) topstar_acpi_fncx_switch(topstar->device, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * Enable software-based WLAN LED control on systems with defective
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * hardware switch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static bool led_workaround;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static int dmi_led_workaround(const struct dmi_system_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) led_workaround = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static const struct dmi_system_id topstar_dmi_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) .callback = dmi_led_workaround,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) .ident = "Topstar U931/RVP7",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) DMI_MATCH(DMI_BOARD_NAME, "U931"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) DMI_MATCH(DMI_BOARD_VERSION, "RVP7"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static int topstar_acpi_add(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct topstar_laptop *topstar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) dmi_check_system(topstar_dmi_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) topstar = kzalloc(sizeof(struct topstar_laptop), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (!topstar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) strcpy(acpi_device_name(device), "Topstar TPSACPI");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) strcpy(acpi_device_class(device), TOPSTAR_LAPTOP_CLASS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) device->driver_data = topstar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) topstar->device = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) err = topstar_acpi_init(topstar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) err = topstar_platform_init(topstar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) goto err_acpi_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) err = topstar_input_init(topstar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) goto err_platform_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (led_workaround) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) err = topstar_led_init(topstar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) goto err_input_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) err_input_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) topstar_input_exit(topstar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) err_platform_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) topstar_platform_exit(topstar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) err_acpi_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) topstar_acpi_exit(topstar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) kfree(topstar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) static int topstar_acpi_remove(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct topstar_laptop *topstar = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (led_workaround)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) topstar_led_exit(topstar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) topstar_input_exit(topstar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) topstar_platform_exit(topstar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) topstar_acpi_exit(topstar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) kfree(topstar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static const struct acpi_device_id topstar_device_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) { "TPS0001", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) { "TPSACPI01", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) { "", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) MODULE_DEVICE_TABLE(acpi, topstar_device_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static struct acpi_driver topstar_acpi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) .name = "Topstar laptop ACPI driver",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) .class = TOPSTAR_LAPTOP_CLASS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) .ids = topstar_device_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) .ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) .add = topstar_acpi_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) .remove = topstar_acpi_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) .notify = topstar_acpi_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static int __init topstar_laptop_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) ret = platform_driver_register(&topstar_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) ret = acpi_bus_register_driver(&topstar_acpi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) goto err_driver_unreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) pr_info("ACPI extras driver loaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) err_driver_unreg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) platform_driver_unregister(&topstar_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static void __exit topstar_laptop_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) acpi_bus_unregister_driver(&topstar_acpi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) platform_driver_unregister(&topstar_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) module_init(topstar_laptop_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) module_exit(topstar_laptop_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) MODULE_AUTHOR("Herton Ronaldo Krzesinski");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) MODULE_AUTHOR("Guillaume Douézan-Grard");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) MODULE_DESCRIPTION("Topstar Laptop ACPI Extras driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) MODULE_LICENSE("GPL");