^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Panasonic HotKey and LCD brightness control driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * (C) 2004 Hiroshi Miura <miura@da-cha.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (C) 2004 NTT DATA Intellilink Co. http://www.intellilink.co.jp/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * (C) YOKOTA Hiroshi <yokota (at) netlab. is. tsukuba. ac. jp>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * (C) 2004 David Bronaugh <dbronaugh>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * (C) 2006-2008 Harald Welte <laforge@gnumonks.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * derived from toshiba_acpi.c, Copyright (C) 2002-2004 John Belmonte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *---------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * ChangeLog:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Sep.23, 2008 Harald Welte <laforge@gnumonks.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * -v0.95 rename driver from drivers/acpi/pcc_acpi.c to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * drivers/misc/panasonic-laptop.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Jul.04, 2008 Harald Welte <laforge@gnumonks.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * -v0.94 replace /proc interface with device attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * support {set,get}keycode on th input device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Jun.27, 2008 Harald Welte <laforge@gnumonks.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * -v0.92 merge with 2.6.26-rc6 input API changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * remove broken <= 2.6.15 kernel support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * resolve all compiler warnings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * various coding style fixes (checkpatch.pl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * add support for backlight api
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * major code restructuring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * Dac.28, 2007 Harald Welte <laforge@gnumonks.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * -v0.91 merge with 2.6.24-rc6 ACPI changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Nov.04, 2006 Hiroshi Miura <miura@da-cha.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * -v0.9 remove warning about section reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * remove acpi_os_free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * add /proc/acpi/pcc/brightness interface for HAL access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * merge dbronaugh's enhancement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * Aug.17, 2004 David Bronaugh (dbronaugh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * - Added screen brightness setting interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * Thanks to FreeBSD crew (acpi_panasonic.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * for the ideas I needed to accomplish it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * May.29, 2006 Hiroshi Miura <miura@da-cha.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * -v0.8.4 follow to change keyinput structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * thanks Fabian Yamaguchi <fabs@cs.tu-berlin.de>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * Jacob Bower <jacob.bower@ic.ac.uk> and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * Hiroshi Yokota for providing solutions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * Oct.02, 2004 Hiroshi Miura <miura@da-cha.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * -v0.8.2 merge code of YOKOTA Hiroshi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * <yokota@netlab.is.tsukuba.ac.jp>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * Add sticky key mode interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * Refactoring acpi_pcc_generate_keyinput().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * Sep.15, 2004 Hiroshi Miura <miura@da-cha.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * -v0.8 Generate key input event on input subsystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * This is based on yet another driver written by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * Ryuta Nakanishi.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * Sep.10, 2004 Hiroshi Miura <miura@da-cha.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * -v0.7 Change proc interface functions using seq_file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * facility as same as other ACPI drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * Aug.28, 2004 Hiroshi Miura <miura@da-cha.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * -v0.6.4 Fix a silly error with status checking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * Aug.25, 2004 Hiroshi Miura <miura@da-cha.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * -v0.6.3 replace read_acpi_int by standard function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * acpi_evaluate_integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * some clean up and make smart copyright notice.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * fix return value of pcc_acpi_get_key()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * fix checking return value of acpi_bus_register_driver()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * Aug.22, 2004 David Bronaugh <dbronaugh@linuxboxen.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * -v0.6.2 Add check on ACPI data (num_sifr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * Coding style cleanups, better error messages/handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * Fixed an off-by-one error in memory allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * Aug.21, 2004 David Bronaugh <dbronaugh@linuxboxen.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * -v0.6.1 Fix a silly error with status checking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * Aug.20, 2004 David Bronaugh <dbronaugh@linuxboxen.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * - v0.6 Correct brightness controls to reflect reality
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * based on information gleaned by Hiroshi Miura
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * and discussions with Hiroshi Miura
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * Aug.10, 2004 Hiroshi Miura <miura@da-cha.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * - v0.5 support LCD brightness control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * based on the disclosed information by MEI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * Jul.25, 2004 Hiroshi Miura <miura@da-cha.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * - v0.4 first post version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * add function to retrive SIFR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * Jul.24, 2004 Hiroshi Miura <miura@da-cha.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * - v0.3 get proper status of hotkey
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * Jul.22, 2004 Hiroshi Miura <miura@da-cha.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * - v0.2 add HotKey handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * Jul.17, 2004 Hiroshi Miura <miura@da-cha.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * - v0.1 start from toshiba_acpi driver written by John Belmonte
^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) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #include <linux/backlight.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #include <linux/input/sparse-keymap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #ifndef ACPI_HOTKEY_COMPONENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define ACPI_HOTKEY_COMPONENT 0x10000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define _COMPONENT ACPI_HOTKEY_COMPONENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) MODULE_AUTHOR("Hiroshi Miura, David Bronaugh and Harald Welte");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) MODULE_DESCRIPTION("ACPI HotKey driver for Panasonic Let's Note laptops");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #define LOGPREFIX "pcc_acpi: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* Define ACPI PATHs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /* Lets note hotkeys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #define METHOD_HKEY_QUERY "HINF"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #define METHOD_HKEY_SQTY "SQTY"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define METHOD_HKEY_SINF "SINF"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #define METHOD_HKEY_SSET "SSET"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #define HKEY_NOTIFY 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #define ACPI_PCC_DRIVER_NAME "Panasonic Laptop Support"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #define ACPI_PCC_DEVICE_NAME "Hotkey"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #define ACPI_PCC_CLASS "pcc"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #define ACPI_PCC_INPUT_PHYS "panasonic/hkey0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /* LCD_TYPEs: 0 = Normal, 1 = Semi-transparent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) ENV_STATEs: Normal temp=0x01, High temp=0x81, N/A=0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) enum SINF_BITS { SINF_NUM_BATTERIES = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) SINF_LCD_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) SINF_AC_MAX_BRIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) SINF_AC_MIN_BRIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) SINF_AC_CUR_BRIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) SINF_DC_MAX_BRIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) SINF_DC_MIN_BRIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) SINF_DC_CUR_BRIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) SINF_MUTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) SINF_RESERVED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) SINF_ENV_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) SINF_STICKY_KEY = 0x80,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* R1 handles SINF_AC_CUR_BRIGHT as SINF_CUR_BRIGHT, doesn't know AC state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static int acpi_pcc_hotkey_add(struct acpi_device *device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int acpi_pcc_hotkey_remove(struct acpi_device *device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static void acpi_pcc_hotkey_notify(struct acpi_device *device, u32 event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static const struct acpi_device_id pcc_device_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) { "MAT0012", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) { "MAT0013", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) { "MAT0018", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) { "MAT0019", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) { "", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) MODULE_DEVICE_TABLE(acpi, pcc_device_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int acpi_pcc_hotkey_resume(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static SIMPLE_DEV_PM_OPS(acpi_pcc_hotkey_pm, NULL, acpi_pcc_hotkey_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static struct acpi_driver acpi_pcc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .name = ACPI_PCC_DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .class = ACPI_PCC_CLASS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) .ids = pcc_device_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) .ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) .add = acpi_pcc_hotkey_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) .remove = acpi_pcc_hotkey_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) .notify = acpi_pcc_hotkey_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) .drv.pm = &acpi_pcc_hotkey_pm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static const struct key_entry panasonic_keymap[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) { KE_KEY, 0, { KEY_RESERVED } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) { KE_KEY, 1, { KEY_BRIGHTNESSDOWN } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) { KE_KEY, 2, { KEY_BRIGHTNESSUP } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) { KE_KEY, 3, { KEY_DISPLAYTOGGLE } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) { KE_KEY, 4, { KEY_MUTE } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) { KE_KEY, 5, { KEY_VOLUMEDOWN } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) { KE_KEY, 6, { KEY_VOLUMEUP } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) { KE_KEY, 7, { KEY_SLEEP } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) { KE_KEY, 8, { KEY_PROG1 } }, /* Change CPU boost */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) { KE_KEY, 9, { KEY_BATTERY } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) { KE_KEY, 10, { KEY_SUSPEND } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) { KE_END, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct pcc_acpi {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) acpi_handle handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) unsigned long num_sifr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int sticky_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) u32 *sinf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct acpi_device *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct backlight_device *backlight;
^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) /* method access functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static int acpi_pcc_write_sset(struct pcc_acpi *pcc, int func, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) union acpi_object in_objs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) { .integer.type = ACPI_TYPE_INTEGER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) .integer.value = func, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) { .integer.type = ACPI_TYPE_INTEGER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) .integer.value = val, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct acpi_object_list params = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .count = ARRAY_SIZE(in_objs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .pointer = in_objs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) status = acpi_evaluate_object(pcc->handle, METHOD_HKEY_SSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) ¶ms, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return (status == AE_OK) ? 0 : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static inline int acpi_pcc_get_sqty(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) unsigned long long s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) status = acpi_evaluate_integer(device->handle, METHOD_HKEY_SQTY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) NULL, &s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (ACPI_SUCCESS(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) "evaluation error HKEY.SQTY\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return -EINVAL;
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int acpi_pcc_retrieve_biosdata(struct pcc_acpi *pcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) union acpi_object *hkey = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) status = acpi_evaluate_object(pcc->handle, METHOD_HKEY_SINF, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) "evaluation error HKEY.SINF\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) hkey = buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (!hkey || (hkey->type != ACPI_TYPE_PACKAGE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid HKEY.SINF\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) status = AE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (pcc->num_sifr < hkey->package.count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) "SQTY reports bad SINF length\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) status = AE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) for (i = 0; i < hkey->package.count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) union acpi_object *element = &(hkey->package.elements[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (likely(element->type == ACPI_TYPE_INTEGER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) pcc->sinf[i] = element->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) "Invalid HKEY.SINF data\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) pcc->sinf[hkey->package.count] = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) kfree(buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return status == AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /* backlight API interface functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /* This driver currently treats AC and DC brightness identical,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * since we don't need to invent an interface to the core ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * logic to receive events in case a power supply is plugged in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * or removed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static int bl_get(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct pcc_acpi *pcc = bl_get_data(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (!acpi_pcc_retrieve_biosdata(pcc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return pcc->sinf[SINF_AC_CUR_BRIGHT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static int bl_set_status(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) struct pcc_acpi *pcc = bl_get_data(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) int bright = bd->props.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (!acpi_pcc_retrieve_biosdata(pcc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (bright < pcc->sinf[SINF_AC_MIN_BRIGHT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) bright = pcc->sinf[SINF_AC_MIN_BRIGHT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (bright < pcc->sinf[SINF_DC_MIN_BRIGHT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) bright = pcc->sinf[SINF_DC_MIN_BRIGHT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (bright < pcc->sinf[SINF_AC_MIN_BRIGHT] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) bright > pcc->sinf[SINF_AC_MAX_BRIGHT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) rc = acpi_pcc_write_sset(pcc, SINF_AC_CUR_BRIGHT, bright);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, bright);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static const struct backlight_ops pcc_backlight_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) .get_brightness = bl_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) .update_status = bl_set_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /* sysfs user interface functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static ssize_t show_numbatt(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) struct acpi_device *acpi = to_acpi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct pcc_acpi *pcc = acpi_driver_data(acpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (!acpi_pcc_retrieve_biosdata(pcc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_NUM_BATTERIES]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) static ssize_t show_lcdtype(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) struct acpi_device *acpi = to_acpi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct pcc_acpi *pcc = acpi_driver_data(acpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (!acpi_pcc_retrieve_biosdata(pcc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_LCD_TYPE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static ssize_t show_mute(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct acpi_device *acpi = to_acpi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct pcc_acpi *pcc = acpi_driver_data(acpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (!acpi_pcc_retrieve_biosdata(pcc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_MUTE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static ssize_t show_sticky(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) struct acpi_device *acpi = to_acpi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) struct pcc_acpi *pcc = acpi_driver_data(acpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (!acpi_pcc_retrieve_biosdata(pcc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_STICKY_KEY]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static ssize_t set_sticky(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct acpi_device *acpi = to_acpi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) struct pcc_acpi *pcc = acpi_driver_data(acpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (count && sscanf(buf, "%i", &val) == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) (val == 0 || val == 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) pcc->sticky_mode = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static DEVICE_ATTR(numbatt, S_IRUGO, show_numbatt, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static DEVICE_ATTR(lcdtype, S_IRUGO, show_lcdtype, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static DEVICE_ATTR(mute, S_IRUGO, show_mute, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static DEVICE_ATTR(sticky_key, S_IRUGO | S_IWUSR, show_sticky, set_sticky);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static struct attribute *pcc_sysfs_entries[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) &dev_attr_numbatt.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) &dev_attr_lcdtype.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) &dev_attr_mute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) &dev_attr_sticky_key.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static const struct attribute_group pcc_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) .name = NULL, /* put in device directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) .attrs = pcc_sysfs_entries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /* hotkey input device driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static int sleep_keydown_seen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) static void acpi_pcc_generate_keyinput(struct pcc_acpi *pcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) struct input_dev *hotk_input_dev = pcc->input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) unsigned long long result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) rc = acpi_evaluate_integer(pcc->handle, METHOD_HKEY_QUERY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) NULL, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (ACPI_FAILURE(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) "error getting hotkey status\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /* hack: some firmware sends no key down for sleep / hibernate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if ((result & 0xf) == 0x7 || (result & 0xf) == 0xa) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) if (result & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) sleep_keydown_seen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (!sleep_keydown_seen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) sparse_keymap_report_event(hotk_input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) result & 0xf, 0x80, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (!sparse_keymap_report_event(hotk_input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) result & 0xf, result & 0x80, false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) "Unknown hotkey event: %d\n", result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static void acpi_pcc_hotkey_notify(struct acpi_device *device, u32 event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) struct pcc_acpi *pcc = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) case HKEY_NOTIFY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) acpi_pcc_generate_keyinput(pcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) /* nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static int acpi_pcc_init_input(struct pcc_acpi *pcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if (!input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) input_dev->name = ACPI_PCC_DRIVER_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) input_dev->phys = ACPI_PCC_INPUT_PHYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) input_dev->id.bustype = BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) input_dev->id.vendor = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) input_dev->id.product = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) input_dev->id.version = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) error = sparse_keymap_setup(input_dev, panasonic_keymap, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) "Unable to setup input device keymap\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) goto err_free_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) error = input_register_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) "Unable to register input device\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) goto err_free_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) pcc->input_dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) err_free_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) /* kernel module interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) static int acpi_pcc_hotkey_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) struct pcc_acpi *pcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) pcc = acpi_driver_data(to_acpi_device(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) if (!pcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Sticky mode restore: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) pcc->sticky_mode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) return acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, pcc->sticky_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static int acpi_pcc_hotkey_add(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct backlight_properties props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) struct pcc_acpi *pcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) int num_sifr, result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) if (!device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) num_sifr = acpi_pcc_get_sqty(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) if (num_sifr < 0 || num_sifr > 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "num_sifr out of range"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) pcc = kzalloc(sizeof(struct pcc_acpi), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) if (!pcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) "Couldn't allocate mem for pcc"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) pcc->sinf = kcalloc(num_sifr + 1, sizeof(u32), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (!pcc->sinf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) result = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) goto out_hotkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) pcc->device = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) pcc->handle = device->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) pcc->num_sifr = num_sifr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) device->driver_data = pcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) strcpy(acpi_device_name(device), ACPI_PCC_DEVICE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) strcpy(acpi_device_class(device), ACPI_PCC_CLASS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) result = acpi_pcc_init_input(pcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) "Error installing keyinput handler\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) goto out_sinf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) if (!acpi_pcc_retrieve_biosdata(pcc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) "Couldn't retrieve BIOS data\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) goto out_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /* initialize backlight */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) memset(&props, 0, sizeof(struct backlight_properties));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) props.type = BACKLIGHT_PLATFORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) props.max_brightness = pcc->sinf[SINF_AC_MAX_BRIGHT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) pcc->backlight = backlight_device_register("panasonic", NULL, pcc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) &pcc_backlight_ops, &props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (IS_ERR(pcc->backlight)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) result = PTR_ERR(pcc->backlight);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) goto out_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /* read the initial brightness setting from the hardware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) pcc->backlight->props.brightness = pcc->sinf[SINF_AC_CUR_BRIGHT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) /* read the initial sticky key mode from the hardware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) pcc->sticky_mode = pcc->sinf[SINF_STICKY_KEY];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) /* add sysfs attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) result = sysfs_create_group(&device->dev.kobj, &pcc_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) goto out_backlight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) out_backlight:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) backlight_device_unregister(pcc->backlight);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) out_input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) input_unregister_device(pcc->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) out_sinf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) kfree(pcc->sinf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) out_hotkey:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) kfree(pcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) static int acpi_pcc_hotkey_remove(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) struct pcc_acpi *pcc = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) if (!device || !pcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) sysfs_remove_group(&device->dev.kobj, &pcc_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) backlight_device_unregister(pcc->backlight);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) input_unregister_device(pcc->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) kfree(pcc->sinf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) kfree(pcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) module_acpi_driver(acpi_pcc_driver);