2019-05-31 08:09:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2008-09-23 15:46:57 +00:00
|
|
|
/*
|
|
|
|
* Panasonic HotKey and LCD brightness control driver
|
|
|
|
* (C) 2004 Hiroshi Miura <miura@da-cha.org>
|
|
|
|
* (C) 2004 NTT DATA Intellilink Co. http://www.intellilink.co.jp/
|
|
|
|
* (C) YOKOTA Hiroshi <yokota (at) netlab. is. tsukuba. ac. jp>
|
|
|
|
* (C) 2004 David Bronaugh <dbronaugh>
|
|
|
|
* (C) 2006-2008 Harald Welte <laforge@gnumonks.org>
|
|
|
|
*
|
|
|
|
* derived from toshiba_acpi.c, Copyright (C) 2002-2004 John Belmonte
|
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* ChangeLog:
|
2020-08-21 18:14:25 +00:00
|
|
|
* Aug.18, 2020 Kenneth Chan <kenneth.t.chan@gmail.com>
|
2020-08-21 18:14:33 +00:00
|
|
|
* -v0.98 add platform devices for firmware brightness registers
|
2020-08-21 18:14:32 +00:00
|
|
|
* add support for battery charging threshold (eco mode)
|
2020-08-21 18:14:31 +00:00
|
|
|
* resolve hotkey double trigger
|
2020-08-21 18:14:30 +00:00
|
|
|
* add write support to mute
|
2020-08-21 18:14:29 +00:00
|
|
|
* fix sticky_key init bug
|
2020-08-21 18:14:28 +00:00
|
|
|
* fix naming of platform files for consistency with other
|
|
|
|
* modules
|
2020-08-21 18:14:27 +00:00
|
|
|
* split MODULE_AUTHOR() by one author per macro call
|
2020-08-21 18:14:26 +00:00
|
|
|
* replace ACPI prints with pr_*() macros
|
2020-08-21 18:14:25 +00:00
|
|
|
* -v0.97 add support for cdpower hardware switch
|
|
|
|
* -v0.96 merge Lucina's enhancement
|
|
|
|
* Jan.13, 2009 Martin Lucina <mato@kotelna.sk>
|
|
|
|
* - add support for optical driver power in
|
|
|
|
* Y and W series
|
|
|
|
*
|
2008-09-23 15:46:57 +00:00
|
|
|
* Sep.23, 2008 Harald Welte <laforge@gnumonks.org>
|
|
|
|
* -v0.95 rename driver from drivers/acpi/pcc_acpi.c to
|
|
|
|
* drivers/misc/panasonic-laptop.c
|
|
|
|
*
|
|
|
|
* Jul.04, 2008 Harald Welte <laforge@gnumonks.org>
|
|
|
|
* -v0.94 replace /proc interface with device attributes
|
|
|
|
* support {set,get}keycode on th input device
|
|
|
|
*
|
|
|
|
* Jun.27, 2008 Harald Welte <laforge@gnumonks.org>
|
|
|
|
* -v0.92 merge with 2.6.26-rc6 input API changes
|
|
|
|
* remove broken <= 2.6.15 kernel support
|
|
|
|
* resolve all compiler warnings
|
|
|
|
* various coding style fixes (checkpatch.pl)
|
|
|
|
* add support for backlight api
|
|
|
|
* major code restructuring
|
|
|
|
*
|
|
|
|
* Dac.28, 2007 Harald Welte <laforge@gnumonks.org>
|
|
|
|
* -v0.91 merge with 2.6.24-rc6 ACPI changes
|
|
|
|
*
|
|
|
|
* Nov.04, 2006 Hiroshi Miura <miura@da-cha.org>
|
|
|
|
* -v0.9 remove warning about section reference.
|
|
|
|
* remove acpi_os_free
|
|
|
|
* add /proc/acpi/pcc/brightness interface for HAL access
|
|
|
|
* merge dbronaugh's enhancement
|
|
|
|
* Aug.17, 2004 David Bronaugh (dbronaugh)
|
|
|
|
* - Added screen brightness setting interface
|
|
|
|
* Thanks to FreeBSD crew (acpi_panasonic.c)
|
|
|
|
* for the ideas I needed to accomplish it
|
|
|
|
*
|
|
|
|
* May.29, 2006 Hiroshi Miura <miura@da-cha.org>
|
|
|
|
* -v0.8.4 follow to change keyinput structure
|
|
|
|
* thanks Fabian Yamaguchi <fabs@cs.tu-berlin.de>,
|
|
|
|
* Jacob Bower <jacob.bower@ic.ac.uk> and
|
|
|
|
* Hiroshi Yokota for providing solutions.
|
|
|
|
*
|
|
|
|
* Oct.02, 2004 Hiroshi Miura <miura@da-cha.org>
|
|
|
|
* -v0.8.2 merge code of YOKOTA Hiroshi
|
|
|
|
* <yokota@netlab.is.tsukuba.ac.jp>.
|
|
|
|
* Add sticky key mode interface.
|
|
|
|
* Refactoring acpi_pcc_generate_keyinput().
|
|
|
|
*
|
|
|
|
* Sep.15, 2004 Hiroshi Miura <miura@da-cha.org>
|
|
|
|
* -v0.8 Generate key input event on input subsystem.
|
|
|
|
* This is based on yet another driver written by
|
|
|
|
* Ryuta Nakanishi.
|
|
|
|
*
|
|
|
|
* Sep.10, 2004 Hiroshi Miura <miura@da-cha.org>
|
|
|
|
* -v0.7 Change proc interface functions using seq_file
|
|
|
|
* facility as same as other ACPI drivers.
|
|
|
|
*
|
|
|
|
* Aug.28, 2004 Hiroshi Miura <miura@da-cha.org>
|
|
|
|
* -v0.6.4 Fix a silly error with status checking
|
|
|
|
*
|
|
|
|
* Aug.25, 2004 Hiroshi Miura <miura@da-cha.org>
|
|
|
|
* -v0.6.3 replace read_acpi_int by standard function
|
|
|
|
* acpi_evaluate_integer
|
|
|
|
* some clean up and make smart copyright notice.
|
|
|
|
* fix return value of pcc_acpi_get_key()
|
|
|
|
* fix checking return value of acpi_bus_register_driver()
|
|
|
|
*
|
|
|
|
* Aug.22, 2004 David Bronaugh <dbronaugh@linuxboxen.org>
|
|
|
|
* -v0.6.2 Add check on ACPI data (num_sifr)
|
|
|
|
* Coding style cleanups, better error messages/handling
|
|
|
|
* Fixed an off-by-one error in memory allocation
|
|
|
|
*
|
|
|
|
* Aug.21, 2004 David Bronaugh <dbronaugh@linuxboxen.org>
|
|
|
|
* -v0.6.1 Fix a silly error with status checking
|
|
|
|
*
|
|
|
|
* Aug.20, 2004 David Bronaugh <dbronaugh@linuxboxen.org>
|
|
|
|
* - v0.6 Correct brightness controls to reflect reality
|
|
|
|
* based on information gleaned by Hiroshi Miura
|
|
|
|
* and discussions with Hiroshi Miura
|
|
|
|
*
|
|
|
|
* Aug.10, 2004 Hiroshi Miura <miura@da-cha.org>
|
|
|
|
* - v0.5 support LCD brightness control
|
|
|
|
* based on the disclosed information by MEI.
|
|
|
|
*
|
|
|
|
* Jul.25, 2004 Hiroshi Miura <miura@da-cha.org>
|
|
|
|
* - v0.4 first post version
|
|
|
|
* add function to retrive SIFR
|
|
|
|
*
|
|
|
|
* Jul.24, 2004 Hiroshi Miura <miura@da-cha.org>
|
|
|
|
* - v0.3 get proper status of hotkey
|
|
|
|
*
|
|
|
|
* Jul.22, 2004 Hiroshi Miura <miura@da-cha.org>
|
|
|
|
* - v0.2 add HotKey handler
|
|
|
|
*
|
|
|
|
* Jul.17, 2004 Hiroshi Miura <miura@da-cha.org>
|
|
|
|
* - v0.1 start from toshiba_acpi driver written by John Belmonte
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/backlight.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/uaccess.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2013-12-03 00:49:16 +00:00
|
|
|
#include <linux/acpi.h>
|
2008-09-23 15:46:57 +00:00
|
|
|
#include <linux/input.h>
|
2010-08-05 05:30:02 +00:00
|
|
|
#include <linux/input/sparse-keymap.h>
|
2020-08-21 18:14:25 +00:00
|
|
|
#include <linux/platform_device.h>
|
2008-09-23 15:46:57 +00:00
|
|
|
|
2020-08-21 18:14:33 +00:00
|
|
|
|
2020-08-21 18:14:27 +00:00
|
|
|
MODULE_AUTHOR("Hiroshi Miura <miura@da-cha.org>");
|
|
|
|
MODULE_AUTHOR("David Bronaugh <dbronaugh@linuxboxen.org>");
|
|
|
|
MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
|
|
|
|
MODULE_AUTHOR("Martin Lucina <mato@kotelna.sk>");
|
|
|
|
MODULE_AUTHOR("Kenneth Chan <kenneth.t.chan@gmail.com>");
|
2008-09-23 15:46:57 +00:00
|
|
|
MODULE_DESCRIPTION("ACPI HotKey driver for Panasonic Let's Note laptops");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
#define LOGPREFIX "pcc_acpi: "
|
|
|
|
|
|
|
|
/* Define ACPI PATHs */
|
|
|
|
/* Lets note hotkeys */
|
|
|
|
#define METHOD_HKEY_QUERY "HINF"
|
|
|
|
#define METHOD_HKEY_SQTY "SQTY"
|
|
|
|
#define METHOD_HKEY_SINF "SINF"
|
|
|
|
#define METHOD_HKEY_SSET "SSET"
|
2020-08-21 18:14:32 +00:00
|
|
|
#define METHOD_ECWR "\\_SB.ECWR"
|
|
|
|
#define HKEY_NOTIFY 0x80
|
|
|
|
#define ECO_MODE_OFF 0x00
|
|
|
|
#define ECO_MODE_ON 0x80
|
2008-09-23 15:46:57 +00:00
|
|
|
|
|
|
|
#define ACPI_PCC_DRIVER_NAME "Panasonic Laptop Support"
|
|
|
|
#define ACPI_PCC_DEVICE_NAME "Hotkey"
|
|
|
|
#define ACPI_PCC_CLASS "pcc"
|
|
|
|
|
|
|
|
#define ACPI_PCC_INPUT_PHYS "panasonic/hkey0"
|
|
|
|
|
|
|
|
/* LCD_TYPEs: 0 = Normal, 1 = Semi-transparent
|
2020-08-21 18:14:32 +00:00
|
|
|
ECO_MODEs: 0x03 = off, 0x83 = on
|
2008-09-23 15:46:57 +00:00
|
|
|
*/
|
|
|
|
enum SINF_BITS { SINF_NUM_BATTERIES = 0,
|
|
|
|
SINF_LCD_TYPE,
|
|
|
|
SINF_AC_MAX_BRIGHT,
|
|
|
|
SINF_AC_MIN_BRIGHT,
|
|
|
|
SINF_AC_CUR_BRIGHT,
|
|
|
|
SINF_DC_MAX_BRIGHT,
|
|
|
|
SINF_DC_MIN_BRIGHT,
|
|
|
|
SINF_DC_CUR_BRIGHT,
|
|
|
|
SINF_MUTE,
|
|
|
|
SINF_RESERVED,
|
2020-08-21 18:14:32 +00:00
|
|
|
SINF_ECO_MODE = 0x0A,
|
2020-08-21 18:14:33 +00:00
|
|
|
SINF_CUR_BRIGHT = 0x0D,
|
2008-09-23 15:46:57 +00:00
|
|
|
SINF_STICKY_KEY = 0x80,
|
|
|
|
};
|
|
|
|
/* R1 handles SINF_AC_CUR_BRIGHT as SINF_CUR_BRIGHT, doesn't know AC state */
|
|
|
|
|
|
|
|
static int acpi_pcc_hotkey_add(struct acpi_device *device);
|
2013-01-23 23:24:48 +00:00
|
|
|
static int acpi_pcc_hotkey_remove(struct acpi_device *device);
|
2009-04-07 15:37:27 +00:00
|
|
|
static void acpi_pcc_hotkey_notify(struct acpi_device *device, u32 event);
|
2008-09-23 15:46:57 +00:00
|
|
|
|
|
|
|
static const struct acpi_device_id pcc_device_ids[] = {
|
|
|
|
{ "MAT0012", 0},
|
|
|
|
{ "MAT0013", 0},
|
|
|
|
{ "MAT0018", 0},
|
|
|
|
{ "MAT0019", 0},
|
|
|
|
{ "", 0},
|
|
|
|
};
|
2009-01-14 05:59:50 +00:00
|
|
|
MODULE_DEVICE_TABLE(acpi, pcc_device_ids);
|
2008-09-23 15:46:57 +00:00
|
|
|
|
2012-08-09 21:00:13 +00:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2012-06-27 21:27:40 +00:00
|
|
|
static int acpi_pcc_hotkey_resume(struct device *dev);
|
2012-08-09 21:00:13 +00:00
|
|
|
#endif
|
2012-06-27 21:27:40 +00:00
|
|
|
static SIMPLE_DEV_PM_OPS(acpi_pcc_hotkey_pm, NULL, acpi_pcc_hotkey_resume);
|
|
|
|
|
2008-09-23 15:46:57 +00:00
|
|
|
static struct acpi_driver acpi_pcc_driver = {
|
|
|
|
.name = ACPI_PCC_DRIVER_NAME,
|
|
|
|
.class = ACPI_PCC_CLASS,
|
|
|
|
.ids = pcc_device_ids,
|
|
|
|
.ops = {
|
|
|
|
.add = acpi_pcc_hotkey_add,
|
|
|
|
.remove = acpi_pcc_hotkey_remove,
|
2009-04-07 15:37:27 +00:00
|
|
|
.notify = acpi_pcc_hotkey_notify,
|
2008-09-23 15:46:57 +00:00
|
|
|
},
|
2012-06-27 21:27:40 +00:00
|
|
|
.drv.pm = &acpi_pcc_hotkey_pm,
|
2008-09-23 15:46:57 +00:00
|
|
|
};
|
|
|
|
|
2010-08-05 05:30:02 +00:00
|
|
|
static const struct key_entry panasonic_keymap[] = {
|
|
|
|
{ KE_KEY, 0, { KEY_RESERVED } },
|
|
|
|
{ KE_KEY, 1, { KEY_BRIGHTNESSDOWN } },
|
|
|
|
{ KE_KEY, 2, { KEY_BRIGHTNESSUP } },
|
|
|
|
{ KE_KEY, 3, { KEY_DISPLAYTOGGLE } },
|
|
|
|
{ KE_KEY, 4, { KEY_MUTE } },
|
|
|
|
{ KE_KEY, 5, { KEY_VOLUMEDOWN } },
|
|
|
|
{ KE_KEY, 6, { KEY_VOLUMEUP } },
|
|
|
|
{ KE_KEY, 7, { KEY_SLEEP } },
|
|
|
|
{ KE_KEY, 8, { KEY_PROG1 } }, /* Change CPU boost */
|
|
|
|
{ KE_KEY, 9, { KEY_BATTERY } },
|
|
|
|
{ KE_KEY, 10, { KEY_SUSPEND } },
|
|
|
|
{ KE_END, 0 }
|
2008-09-23 15:46:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pcc_acpi {
|
|
|
|
acpi_handle handle;
|
|
|
|
unsigned long num_sifr;
|
2020-08-21 18:14:29 +00:00
|
|
|
int sticky_key;
|
2020-08-21 18:14:32 +00:00
|
|
|
int eco_mode;
|
2020-08-21 18:14:30 +00:00
|
|
|
int mute;
|
2020-08-21 18:14:33 +00:00
|
|
|
int ac_brightness;
|
|
|
|
int dc_brightness;
|
|
|
|
int current_brightness;
|
2010-08-05 05:30:02 +00:00
|
|
|
u32 *sinf;
|
2008-09-23 15:46:57 +00:00
|
|
|
struct acpi_device *device;
|
|
|
|
struct input_dev *input_dev;
|
|
|
|
struct backlight_device *backlight;
|
2020-08-21 18:14:25 +00:00
|
|
|
struct platform_device *platform;
|
2008-09-23 15:46:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* method access functions */
|
|
|
|
static int acpi_pcc_write_sset(struct pcc_acpi *pcc, int func, int val)
|
|
|
|
{
|
|
|
|
union acpi_object in_objs[] = {
|
|
|
|
{ .integer.type = ACPI_TYPE_INTEGER,
|
|
|
|
.integer.value = func, },
|
|
|
|
{ .integer.type = ACPI_TYPE_INTEGER,
|
|
|
|
.integer.value = val, },
|
|
|
|
};
|
|
|
|
struct acpi_object_list params = {
|
|
|
|
.count = ARRAY_SIZE(in_objs),
|
|
|
|
.pointer = in_objs,
|
|
|
|
};
|
|
|
|
acpi_status status = AE_OK;
|
|
|
|
|
|
|
|
status = acpi_evaluate_object(pcc->handle, METHOD_HKEY_SSET,
|
|
|
|
¶ms, NULL);
|
|
|
|
|
2010-07-07 00:21:48 +00:00
|
|
|
return (status == AE_OK) ? 0 : -EIO;
|
2008-09-23 15:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int acpi_pcc_get_sqty(struct acpi_device *device)
|
|
|
|
{
|
2008-10-11 06:30:14 +00:00
|
|
|
unsigned long long s;
|
2008-09-23 15:46:57 +00:00
|
|
|
acpi_status status;
|
|
|
|
|
|
|
|
status = acpi_evaluate_integer(device->handle, METHOD_HKEY_SQTY,
|
|
|
|
NULL, &s);
|
|
|
|
if (ACPI_SUCCESS(status))
|
|
|
|
return s;
|
|
|
|
else {
|
2020-08-21 18:14:26 +00:00
|
|
|
pr_err("evaluation error HKEY.SQTY\n");
|
2008-09-23 15:46:57 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-21 09:50:47 +00:00
|
|
|
static int acpi_pcc_retrieve_biosdata(struct pcc_acpi *pcc)
|
2008-09-23 15:46:57 +00:00
|
|
|
{
|
|
|
|
acpi_status status;
|
|
|
|
struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
|
|
|
|
union acpi_object *hkey = NULL;
|
|
|
|
int i;
|
|
|
|
|
2009-03-05 19:15:44 +00:00
|
|
|
status = acpi_evaluate_object(pcc->handle, METHOD_HKEY_SINF, NULL,
|
2008-09-23 15:46:57 +00:00
|
|
|
&buffer);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
2020-08-21 18:14:26 +00:00
|
|
|
pr_err("evaluation error HKEY.SINF\n");
|
2008-09-23 15:46:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
hkey = buffer.pointer;
|
|
|
|
if (!hkey || (hkey->type != ACPI_TYPE_PACKAGE)) {
|
2020-08-21 18:14:26 +00:00
|
|
|
pr_err("Invalid HKEY.SINF\n");
|
2010-10-21 09:48:47 +00:00
|
|
|
status = AE_ERROR;
|
2008-09-23 15:46:57 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pcc->num_sifr < hkey->package.count) {
|
2020-08-21 18:14:26 +00:00
|
|
|
pr_err("SQTY reports bad SINF length\n");
|
2008-09-23 15:46:57 +00:00
|
|
|
status = AE_ERROR;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < hkey->package.count; i++) {
|
|
|
|
union acpi_object *element = &(hkey->package.elements[i]);
|
|
|
|
if (likely(element->type == ACPI_TYPE_INTEGER)) {
|
2010-10-21 09:50:47 +00:00
|
|
|
pcc->sinf[i] = element->integer.value;
|
2008-09-23 15:46:57 +00:00
|
|
|
} else
|
2020-08-21 18:14:26 +00:00
|
|
|
pr_err("Invalid HKEY.SINF data\n");
|
2008-09-23 15:46:57 +00:00
|
|
|
}
|
2010-10-21 09:50:47 +00:00
|
|
|
pcc->sinf[hkey->package.count] = -1;
|
2008-09-23 15:46:57 +00:00
|
|
|
|
|
|
|
end:
|
|
|
|
kfree(buffer.pointer);
|
|
|
|
return status == AE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* backlight API interface functions */
|
|
|
|
|
|
|
|
/* This driver currently treats AC and DC brightness identical,
|
|
|
|
* since we don't need to invent an interface to the core ACPI
|
|
|
|
* logic to receive events in case a power supply is plugged in
|
|
|
|
* or removed */
|
|
|
|
|
|
|
|
static int bl_get(struct backlight_device *bd)
|
|
|
|
{
|
|
|
|
struct pcc_acpi *pcc = bl_get_data(bd);
|
|
|
|
|
2010-10-21 09:50:47 +00:00
|
|
|
if (!acpi_pcc_retrieve_biosdata(pcc))
|
2008-09-23 15:46:57 +00:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return pcc->sinf[SINF_AC_CUR_BRIGHT];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bl_set_status(struct backlight_device *bd)
|
|
|
|
{
|
|
|
|
struct pcc_acpi *pcc = bl_get_data(bd);
|
|
|
|
int bright = bd->props.brightness;
|
|
|
|
int rc;
|
|
|
|
|
2010-10-21 09:50:47 +00:00
|
|
|
if (!acpi_pcc_retrieve_biosdata(pcc))
|
2008-09-23 15:46:57 +00:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
if (bright < pcc->sinf[SINF_AC_MIN_BRIGHT])
|
|
|
|
bright = pcc->sinf[SINF_AC_MIN_BRIGHT];
|
|
|
|
|
|
|
|
if (bright < pcc->sinf[SINF_DC_MIN_BRIGHT])
|
|
|
|
bright = pcc->sinf[SINF_DC_MIN_BRIGHT];
|
|
|
|
|
|
|
|
if (bright < pcc->sinf[SINF_AC_MIN_BRIGHT] ||
|
|
|
|
bright > pcc->sinf[SINF_AC_MAX_BRIGHT])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
rc = acpi_pcc_write_sset(pcc, SINF_AC_CUR_BRIGHT, bright);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
return acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, bright);
|
|
|
|
}
|
|
|
|
|
2010-02-26 12:20:10 +00:00
|
|
|
static const struct backlight_ops pcc_backlight_ops = {
|
2008-09-23 15:46:57 +00:00
|
|
|
.get_brightness = bl_get,
|
|
|
|
.update_status = bl_set_status,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-08-21 18:14:25 +00:00
|
|
|
/* returns ACPI_SUCCESS if methods to control optical drive are present */
|
|
|
|
|
|
|
|
static acpi_status check_optd_present(void)
|
|
|
|
{
|
|
|
|
acpi_status status = AE_OK;
|
|
|
|
acpi_handle handle;
|
|
|
|
|
|
|
|
status = acpi_get_handle(NULL, "\\_SB.STAT", &handle);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
goto out;
|
|
|
|
status = acpi_get_handle(NULL, "\\_SB.FBAY", &handle);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
goto out;
|
|
|
|
status = acpi_get_handle(NULL, "\\_SB.CDDI", &handle);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get optical driver power state */
|
|
|
|
|
|
|
|
static int get_optd_power_state(void)
|
|
|
|
{
|
|
|
|
acpi_status status;
|
|
|
|
unsigned long long state;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
status = acpi_evaluate_integer(NULL, "\\_SB.STAT", NULL, &state);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
pr_err("evaluation error _SB.STAT\n");
|
|
|
|
result = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
switch (state) {
|
|
|
|
case 0: /* power off */
|
|
|
|
result = 0;
|
|
|
|
break;
|
|
|
|
case 0x0f: /* power on */
|
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = -EIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set optical drive power state */
|
|
|
|
|
|
|
|
static int set_optd_power_state(int new_state)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
acpi_status status;
|
|
|
|
|
|
|
|
result = get_optd_power_state();
|
|
|
|
if (result < 0)
|
|
|
|
goto out;
|
|
|
|
if (new_state == result)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
switch (new_state) {
|
|
|
|
case 0: /* power off */
|
|
|
|
/* Call CDDR instead, since they both call the same method
|
|
|
|
* while CDDI takes 1 arg and we are not quite sure what it is.
|
|
|
|
*/
|
|
|
|
status = acpi_evaluate_object(NULL, "\\_SB.CDDR", NULL, NULL);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
pr_err("evaluation error _SB.CDDR\n");
|
|
|
|
result = -EIO;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: /* power on */
|
|
|
|
status = acpi_evaluate_object(NULL, "\\_SB.FBAY", NULL, NULL);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
pr_err("evaluation error _SB.FBAY\n");
|
|
|
|
result = -EIO;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-23 15:46:57 +00:00
|
|
|
/* sysfs user interface functions */
|
|
|
|
|
2020-08-21 18:14:28 +00:00
|
|
|
static ssize_t numbatt_show(struct device *dev, struct device_attribute *attr,
|
2008-09-23 15:46:57 +00:00
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct acpi_device *acpi = to_acpi_device(dev);
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(acpi);
|
|
|
|
|
2010-10-21 09:50:47 +00:00
|
|
|
if (!acpi_pcc_retrieve_biosdata(pcc))
|
2008-09-23 15:46:57 +00:00
|
|
|
return -EIO;
|
|
|
|
|
2021-10-15 06:50:40 +00:00
|
|
|
return sysfs_emit(buf, "%u\n", pcc->sinf[SINF_NUM_BATTERIES]);
|
2008-09-23 15:46:57 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 18:14:28 +00:00
|
|
|
static ssize_t lcdtype_show(struct device *dev, struct device_attribute *attr,
|
2008-09-23 15:46:57 +00:00
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct acpi_device *acpi = to_acpi_device(dev);
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(acpi);
|
|
|
|
|
2010-10-21 09:50:47 +00:00
|
|
|
if (!acpi_pcc_retrieve_biosdata(pcc))
|
2008-09-23 15:46:57 +00:00
|
|
|
return -EIO;
|
|
|
|
|
2021-10-15 06:50:40 +00:00
|
|
|
return sysfs_emit(buf, "%u\n", pcc->sinf[SINF_LCD_TYPE]);
|
2008-09-23 15:46:57 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 18:14:28 +00:00
|
|
|
static ssize_t mute_show(struct device *dev, struct device_attribute *attr,
|
2008-09-23 15:46:57 +00:00
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct acpi_device *acpi = to_acpi_device(dev);
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(acpi);
|
|
|
|
|
2010-10-21 09:50:47 +00:00
|
|
|
if (!acpi_pcc_retrieve_biosdata(pcc))
|
2008-09-23 15:46:57 +00:00
|
|
|
return -EIO;
|
|
|
|
|
2021-10-15 06:50:40 +00:00
|
|
|
return sysfs_emit(buf, "%u\n", pcc->sinf[SINF_MUTE]);
|
2008-09-23 15:46:57 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 18:14:30 +00:00
|
|
|
static ssize_t mute_store(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct acpi_device *acpi = to_acpi_device(dev);
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(acpi);
|
|
|
|
int err, val;
|
|
|
|
|
|
|
|
err = kstrtoint(buf, 0, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
if (val == 0 || val == 1) {
|
|
|
|
acpi_pcc_write_sset(pcc, SINF_MUTE, val);
|
|
|
|
pcc->mute = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2020-08-21 18:14:28 +00:00
|
|
|
static ssize_t sticky_key_show(struct device *dev, struct device_attribute *attr,
|
2008-09-23 15:46:57 +00:00
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct acpi_device *acpi = to_acpi_device(dev);
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(acpi);
|
|
|
|
|
2010-10-21 09:50:47 +00:00
|
|
|
if (!acpi_pcc_retrieve_biosdata(pcc))
|
2008-09-23 15:46:57 +00:00
|
|
|
return -EIO;
|
|
|
|
|
2021-10-15 06:50:40 +00:00
|
|
|
return sysfs_emit(buf, "%u\n", pcc->sticky_key);
|
2008-09-23 15:46:57 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 18:14:28 +00:00
|
|
|
static ssize_t sticky_key_store(struct device *dev, struct device_attribute *attr,
|
2008-09-23 15:46:57 +00:00
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct acpi_device *acpi = to_acpi_device(dev);
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(acpi);
|
2020-08-21 18:14:29 +00:00
|
|
|
int err, val;
|
2008-09-23 15:46:57 +00:00
|
|
|
|
2020-08-21 18:14:29 +00:00
|
|
|
err = kstrtoint(buf, 0, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
if (val == 0 || val == 1) {
|
2008-09-23 15:46:57 +00:00
|
|
|
acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, val);
|
2020-08-21 18:14:29 +00:00
|
|
|
pcc->sticky_key = val;
|
2008-09-23 15:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2020-08-21 18:14:32 +00:00
|
|
|
static ssize_t eco_mode_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct acpi_device *acpi = to_acpi_device(dev);
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(acpi);
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (!acpi_pcc_retrieve_biosdata(pcc))
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
switch (pcc->sinf[SINF_ECO_MODE]) {
|
|
|
|
case (ECO_MODE_OFF + 3):
|
|
|
|
result = 0;
|
|
|
|
break;
|
|
|
|
case (ECO_MODE_ON + 3):
|
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = -EIO;
|
|
|
|
break;
|
|
|
|
}
|
2021-10-15 06:50:40 +00:00
|
|
|
return sysfs_emit(buf, "%u\n", result);
|
2020-08-21 18:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t eco_mode_store(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct acpi_device *acpi = to_acpi_device(dev);
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(acpi);
|
|
|
|
int err, state;
|
|
|
|
|
|
|
|
union acpi_object param[2];
|
|
|
|
struct acpi_object_list input;
|
|
|
|
acpi_status status;
|
|
|
|
|
|
|
|
param[0].type = ACPI_TYPE_INTEGER;
|
|
|
|
param[0].integer.value = 0x15;
|
|
|
|
param[1].type = ACPI_TYPE_INTEGER;
|
|
|
|
input.count = 2;
|
|
|
|
input.pointer = param;
|
|
|
|
|
|
|
|
err = kstrtoint(buf, 0, &state);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case 0:
|
|
|
|
param[1].integer.value = ECO_MODE_OFF;
|
|
|
|
pcc->sinf[SINF_ECO_MODE] = 0;
|
|
|
|
pcc->eco_mode = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
param[1].integer.value = ECO_MODE_ON;
|
|
|
|
pcc->sinf[SINF_ECO_MODE] = 1;
|
|
|
|
pcc->eco_mode = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* nothing to do */
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = acpi_evaluate_object(NULL, METHOD_ECWR,
|
|
|
|
&input, NULL);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
pr_err("%s evaluation failed\n", METHOD_ECWR);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2020-08-21 18:14:33 +00:00
|
|
|
static ssize_t ac_brightness_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct acpi_device *acpi = to_acpi_device(dev);
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(acpi);
|
|
|
|
|
|
|
|
if (!acpi_pcc_retrieve_biosdata(pcc))
|
|
|
|
return -EIO;
|
|
|
|
|
2021-10-15 06:50:40 +00:00
|
|
|
return sysfs_emit(buf, "%u\n", pcc->sinf[SINF_AC_CUR_BRIGHT]);
|
2020-08-21 18:14:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ac_brightness_store(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct acpi_device *acpi = to_acpi_device(dev);
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(acpi);
|
|
|
|
int err, val;
|
|
|
|
|
|
|
|
err = kstrtoint(buf, 0, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
if (val >= 0 && val <= 255) {
|
|
|
|
acpi_pcc_write_sset(pcc, SINF_AC_CUR_BRIGHT, val);
|
|
|
|
pcc->ac_brightness = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dc_brightness_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct acpi_device *acpi = to_acpi_device(dev);
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(acpi);
|
|
|
|
|
|
|
|
if (!acpi_pcc_retrieve_biosdata(pcc))
|
|
|
|
return -EIO;
|
|
|
|
|
2021-10-15 06:50:40 +00:00
|
|
|
return sysfs_emit(buf, "%u\n", pcc->sinf[SINF_DC_CUR_BRIGHT]);
|
2020-08-21 18:14:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dc_brightness_store(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct acpi_device *acpi = to_acpi_device(dev);
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(acpi);
|
|
|
|
int err, val;
|
|
|
|
|
|
|
|
err = kstrtoint(buf, 0, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
if (val >= 0 && val <= 255) {
|
|
|
|
acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, val);
|
|
|
|
pcc->dc_brightness = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t current_brightness_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct acpi_device *acpi = to_acpi_device(dev);
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(acpi);
|
|
|
|
|
|
|
|
if (!acpi_pcc_retrieve_biosdata(pcc))
|
|
|
|
return -EIO;
|
|
|
|
|
2021-10-15 06:50:40 +00:00
|
|
|
return sysfs_emit(buf, "%u\n", pcc->sinf[SINF_CUR_BRIGHT]);
|
2020-08-21 18:14:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t current_brightness_store(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct acpi_device *acpi = to_acpi_device(dev);
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(acpi);
|
|
|
|
int err, val;
|
|
|
|
|
|
|
|
err = kstrtoint(buf, 0, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (val >= 0 && val <= 255) {
|
|
|
|
err = acpi_pcc_write_sset(pcc, SINF_CUR_BRIGHT, val);
|
|
|
|
pcc->current_brightness = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2020-08-21 18:14:25 +00:00
|
|
|
static ssize_t cdpower_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
2021-10-15 06:50:40 +00:00
|
|
|
return sysfs_emit(buf, "%d\n", get_optd_power_state());
|
2020-08-21 18:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t cdpower_store(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
int err, val;
|
|
|
|
|
|
|
|
err = kstrtoint(buf, 10, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
set_optd_power_state(val);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2020-08-21 18:14:28 +00:00
|
|
|
static DEVICE_ATTR_RO(numbatt);
|
|
|
|
static DEVICE_ATTR_RO(lcdtype);
|
2020-08-21 18:14:30 +00:00
|
|
|
static DEVICE_ATTR_RW(mute);
|
2020-08-21 18:14:28 +00:00
|
|
|
static DEVICE_ATTR_RW(sticky_key);
|
2020-08-21 18:14:32 +00:00
|
|
|
static DEVICE_ATTR_RW(eco_mode);
|
2020-08-21 18:14:33 +00:00
|
|
|
static DEVICE_ATTR_RW(ac_brightness);
|
|
|
|
static DEVICE_ATTR_RW(dc_brightness);
|
|
|
|
static DEVICE_ATTR_RW(current_brightness);
|
2020-08-21 18:14:25 +00:00
|
|
|
static DEVICE_ATTR_RW(cdpower);
|
2008-09-23 15:46:57 +00:00
|
|
|
|
|
|
|
static struct attribute *pcc_sysfs_entries[] = {
|
|
|
|
&dev_attr_numbatt.attr,
|
|
|
|
&dev_attr_lcdtype.attr,
|
|
|
|
&dev_attr_mute.attr,
|
|
|
|
&dev_attr_sticky_key.attr,
|
2020-08-21 18:14:32 +00:00
|
|
|
&dev_attr_eco_mode.attr,
|
2020-08-21 18:14:33 +00:00
|
|
|
&dev_attr_ac_brightness.attr,
|
|
|
|
&dev_attr_dc_brightness.attr,
|
|
|
|
&dev_attr_current_brightness.attr,
|
2020-08-21 18:14:25 +00:00
|
|
|
&dev_attr_cdpower.attr,
|
2008-09-23 15:46:57 +00:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2017-07-11 10:48:18 +00:00
|
|
|
static const struct attribute_group pcc_attr_group = {
|
2008-09-23 15:46:57 +00:00
|
|
|
.name = NULL, /* put in device directory */
|
|
|
|
.attrs = pcc_sysfs_entries,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* hotkey input device driver */
|
|
|
|
|
Fix sleep / suspend keys for Toughbook CF-51
Hi all,
my panasonic cf-51 does no longer react to the suspend and hibernate
keys. I cannot tell when this started since I no longer use the machine
on a daily basis, but I suspect it started when userspace switched from
using /proc/acpi/event to the input layer, wich was quite some time ago ;-)
Today I investigated the issue and found that the firmware simply does
not generate any event on "key down" for those keys, but only on "key up".
The attached patch works around the problem.
Best regards,
Stefan
--
Stefan Seyfried
Linux Consultant & Developer -- GPG Key: 0x731B665B
B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
>From 7c96fee748cfd3e64732a7ac142f5dea07d7379f Mon Sep 17 00:00:00 2001
From: Stefan Seyfried <seife+kernel@b1-systems.com>
Date: Sun, 2 Mar 2014 17:50:01 +0100
Subject: [PATCH] panasonic-laptop: fix sleep keys on CF-51
At least on my CF-51, both sleep and hibernate keys do not
generate "key down" events, only "key up". Because of this,
the input layer does ignore both keys. The work around is
to generate a key down event before the key up. To avoid
double events on non-broken firmware, this is only done if
no key down is ever seen for those keys.
Signed-off-by: Stefan Seyfried <seife+kernel@b1-systems.com>
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
2014-03-02 17:01:19 +00:00
|
|
|
static int sleep_keydown_seen;
|
2008-09-23 15:46:57 +00:00
|
|
|
static void acpi_pcc_generate_keyinput(struct pcc_acpi *pcc)
|
|
|
|
{
|
|
|
|
struct input_dev *hotk_input_dev = pcc->input_dev;
|
|
|
|
int rc;
|
2008-10-11 06:30:14 +00:00
|
|
|
unsigned long long result;
|
2008-09-23 15:46:57 +00:00
|
|
|
|
|
|
|
rc = acpi_evaluate_integer(pcc->handle, METHOD_HKEY_QUERY,
|
|
|
|
NULL, &result);
|
2016-09-19 01:33:51 +00:00
|
|
|
if (ACPI_FAILURE(rc)) {
|
2020-08-21 18:14:26 +00:00
|
|
|
pr_err("error getting hotkey status\n");
|
2008-09-23 15:46:57 +00:00
|
|
|
return;
|
|
|
|
}
|
Fix sleep / suspend keys for Toughbook CF-51
Hi all,
my panasonic cf-51 does no longer react to the suspend and hibernate
keys. I cannot tell when this started since I no longer use the machine
on a daily basis, but I suspect it started when userspace switched from
using /proc/acpi/event to the input layer, wich was quite some time ago ;-)
Today I investigated the issue and found that the firmware simply does
not generate any event on "key down" for those keys, but only on "key up".
The attached patch works around the problem.
Best regards,
Stefan
--
Stefan Seyfried
Linux Consultant & Developer -- GPG Key: 0x731B665B
B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
>From 7c96fee748cfd3e64732a7ac142f5dea07d7379f Mon Sep 17 00:00:00 2001
From: Stefan Seyfried <seife+kernel@b1-systems.com>
Date: Sun, 2 Mar 2014 17:50:01 +0100
Subject: [PATCH] panasonic-laptop: fix sleep keys on CF-51
At least on my CF-51, both sleep and hibernate keys do not
generate "key down" events, only "key up". Because of this,
the input layer does ignore both keys. The work around is
to generate a key down event before the key up. To avoid
double events on non-broken firmware, this is only done if
no key down is ever seen for those keys.
Signed-off-by: Stefan Seyfried <seife+kernel@b1-systems.com>
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
2014-03-02 17:01:19 +00:00
|
|
|
|
|
|
|
/* hack: some firmware sends no key down for sleep / hibernate */
|
|
|
|
if ((result & 0xf) == 0x7 || (result & 0xf) == 0xa) {
|
|
|
|
if (result & 0x80)
|
|
|
|
sleep_keydown_seen = 1;
|
|
|
|
if (!sleep_keydown_seen)
|
|
|
|
sparse_keymap_report_event(hotk_input_dev,
|
|
|
|
result & 0xf, 0x80, false);
|
|
|
|
}
|
|
|
|
|
2020-08-21 18:14:31 +00:00
|
|
|
if ((result & 0xf) == 0x7 || (result & 0xf) == 0x9 || (result & 0xf) == 0xa) {
|
|
|
|
if (!sparse_keymap_report_event(hotk_input_dev,
|
|
|
|
result & 0xf, result & 0x80, false))
|
|
|
|
pr_err("Unknown hotkey event: 0x%04llx\n", result);
|
|
|
|
}
|
2008-09-23 15:46:57 +00:00
|
|
|
}
|
|
|
|
|
2009-04-07 15:37:27 +00:00
|
|
|
static void acpi_pcc_hotkey_notify(struct acpi_device *device, u32 event)
|
2008-09-23 15:46:57 +00:00
|
|
|
{
|
2009-04-07 15:37:27 +00:00
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(device);
|
2008-09-23 15:46:57 +00:00
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case HKEY_NOTIFY:
|
|
|
|
acpi_pcc_generate_keyinput(pcc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* nothing to do */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-21 18:14:25 +00:00
|
|
|
static void pcc_optd_notify(acpi_handle handle, u32 event, void *data)
|
|
|
|
{
|
|
|
|
if (event != ACPI_NOTIFY_EJECT_REQUEST)
|
|
|
|
return;
|
|
|
|
|
|
|
|
set_optd_power_state(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcc_register_optd_notifier(struct pcc_acpi *pcc, char *node)
|
|
|
|
{
|
|
|
|
acpi_status status;
|
|
|
|
acpi_handle handle;
|
|
|
|
|
|
|
|
status = acpi_get_handle(NULL, node, &handle);
|
|
|
|
|
|
|
|
if (ACPI_SUCCESS(status)) {
|
|
|
|
status = acpi_install_notify_handler(handle,
|
|
|
|
ACPI_SYSTEM_NOTIFY,
|
|
|
|
pcc_optd_notify, pcc);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
pr_err("Failed to register notify on %s\n", node);
|
|
|
|
} else
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pcc_unregister_optd_notifier(struct pcc_acpi *pcc, char *node)
|
|
|
|
{
|
|
|
|
acpi_status status = AE_OK;
|
|
|
|
acpi_handle handle;
|
|
|
|
|
|
|
|
status = acpi_get_handle(NULL, node, &handle);
|
|
|
|
|
|
|
|
if (ACPI_SUCCESS(status)) {
|
|
|
|
status = acpi_remove_notify_handler(handle,
|
|
|
|
ACPI_SYSTEM_NOTIFY,
|
|
|
|
pcc_optd_notify);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
pr_err("Error removing optd notify handler %s\n",
|
|
|
|
node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-23 15:46:57 +00:00
|
|
|
static int acpi_pcc_init_input(struct pcc_acpi *pcc)
|
|
|
|
{
|
2010-08-05 05:30:02 +00:00
|
|
|
struct input_dev *input_dev;
|
|
|
|
int error;
|
2008-09-23 15:46:57 +00:00
|
|
|
|
2010-08-05 05:30:02 +00:00
|
|
|
input_dev = input_allocate_device();
|
2013-10-23 19:14:52 +00:00
|
|
|
if (!input_dev)
|
2008-09-23 15:46:57 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-08-05 05:30:02 +00:00
|
|
|
input_dev->name = ACPI_PCC_DRIVER_NAME;
|
|
|
|
input_dev->phys = ACPI_PCC_INPUT_PHYS;
|
|
|
|
input_dev->id.bustype = BUS_HOST;
|
|
|
|
input_dev->id.vendor = 0x0001;
|
|
|
|
input_dev->id.product = 0x0001;
|
|
|
|
input_dev->id.version = 0x0100;
|
2008-09-23 15:46:57 +00:00
|
|
|
|
2010-08-05 05:30:02 +00:00
|
|
|
error = sparse_keymap_setup(input_dev, panasonic_keymap, NULL);
|
|
|
|
if (error) {
|
2020-08-21 18:14:26 +00:00
|
|
|
pr_err("Unable to setup input device keymap\n");
|
2010-08-05 05:30:02 +00:00
|
|
|
goto err_free_dev;
|
|
|
|
}
|
2008-09-23 15:46:57 +00:00
|
|
|
|
2010-08-05 05:30:02 +00:00
|
|
|
error = input_register_device(input_dev);
|
|
|
|
if (error) {
|
2020-08-21 18:14:26 +00:00
|
|
|
pr_err("Unable to register input device\n");
|
2017-03-09 12:11:47 +00:00
|
|
|
goto err_free_dev;
|
2010-08-05 05:30:02 +00:00
|
|
|
}
|
2008-09-23 15:46:57 +00:00
|
|
|
|
2010-08-05 05:30:02 +00:00
|
|
|
pcc->input_dev = input_dev;
|
|
|
|
return 0;
|
2008-09-23 15:46:57 +00:00
|
|
|
|
2010-08-05 05:30:02 +00:00
|
|
|
err_free_dev:
|
|
|
|
input_free_device(input_dev);
|
|
|
|
return error;
|
|
|
|
}
|
2008-09-23 15:46:57 +00:00
|
|
|
|
|
|
|
/* kernel module interface */
|
|
|
|
|
2012-08-09 21:00:13 +00:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2012-06-27 21:27:40 +00:00
|
|
|
static int acpi_pcc_hotkey_resume(struct device *dev)
|
2008-09-23 15:46:57 +00:00
|
|
|
{
|
2012-06-27 21:27:40 +00:00
|
|
|
struct pcc_acpi *pcc;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return -EINVAL;
|
2008-09-23 15:46:57 +00:00
|
|
|
|
2012-06-27 21:27:40 +00:00
|
|
|
pcc = acpi_driver_data(to_acpi_device(dev));
|
|
|
|
if (!pcc)
|
2008-09-23 15:46:57 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2020-08-21 18:14:30 +00:00
|
|
|
acpi_pcc_write_sset(pcc, SINF_MUTE, pcc->mute);
|
2020-08-21 18:14:32 +00:00
|
|
|
acpi_pcc_write_sset(pcc, SINF_ECO_MODE, pcc->eco_mode);
|
2020-08-21 18:14:29 +00:00
|
|
|
acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, pcc->sticky_key);
|
2020-08-21 18:14:33 +00:00
|
|
|
acpi_pcc_write_sset(pcc, SINF_AC_CUR_BRIGHT, pcc->ac_brightness);
|
|
|
|
acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, pcc->dc_brightness);
|
|
|
|
acpi_pcc_write_sset(pcc, SINF_CUR_BRIGHT, pcc->current_brightness);
|
2020-08-21 18:14:29 +00:00
|
|
|
|
|
|
|
return 0;
|
2008-09-23 15:46:57 +00:00
|
|
|
}
|
2012-08-09 21:00:13 +00:00
|
|
|
#endif
|
2008-09-23 15:46:57 +00:00
|
|
|
|
|
|
|
static int acpi_pcc_hotkey_add(struct acpi_device *device)
|
|
|
|
{
|
2010-02-17 21:39:44 +00:00
|
|
|
struct backlight_properties props;
|
2008-09-23 15:46:57 +00:00
|
|
|
struct pcc_acpi *pcc;
|
|
|
|
int num_sifr, result;
|
|
|
|
|
|
|
|
if (!device)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
num_sifr = acpi_pcc_get_sqty(device);
|
|
|
|
|
2011-12-29 04:49:06 +00:00
|
|
|
if (num_sifr < 0 || num_sifr > 255) {
|
2020-08-21 18:14:26 +00:00
|
|
|
pr_err("num_sifr out of range");
|
2008-09-23 15:46:57 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
pcc = kzalloc(sizeof(struct pcc_acpi), GFP_KERNEL);
|
|
|
|
if (!pcc) {
|
2020-08-21 18:14:26 +00:00
|
|
|
pr_err("Couldn't allocate mem for pcc");
|
2008-09-23 15:46:57 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 21:03:40 +00:00
|
|
|
pcc->sinf = kcalloc(num_sifr + 1, sizeof(u32), GFP_KERNEL);
|
2008-09-23 15:46:57 +00:00
|
|
|
if (!pcc->sinf) {
|
|
|
|
result = -ENOMEM;
|
|
|
|
goto out_hotkey;
|
|
|
|
}
|
|
|
|
|
|
|
|
pcc->device = device;
|
|
|
|
pcc->handle = device->handle;
|
|
|
|
pcc->num_sifr = num_sifr;
|
2008-10-11 06:30:14 +00:00
|
|
|
device->driver_data = pcc;
|
2008-09-23 15:46:57 +00:00
|
|
|
strcpy(acpi_device_name(device), ACPI_PCC_DEVICE_NAME);
|
|
|
|
strcpy(acpi_device_class(device), ACPI_PCC_CLASS);
|
|
|
|
|
|
|
|
result = acpi_pcc_init_input(pcc);
|
|
|
|
if (result) {
|
2020-08-21 18:14:26 +00:00
|
|
|
pr_err("Error installing keyinput handler\n");
|
2010-08-05 05:30:02 +00:00
|
|
|
goto out_sinf;
|
2008-09-23 15:46:57 +00:00
|
|
|
}
|
|
|
|
|
2010-10-21 09:50:47 +00:00
|
|
|
if (!acpi_pcc_retrieve_biosdata(pcc)) {
|
2010-10-21 09:48:47 +00:00
|
|
|
result = -EIO;
|
2020-08-21 18:14:26 +00:00
|
|
|
pr_err("Couldn't retrieve BIOS data\n");
|
2010-02-17 21:39:44 +00:00
|
|
|
goto out_input;
|
2008-09-23 15:46:57 +00:00
|
|
|
}
|
2010-02-17 21:39:44 +00:00
|
|
|
/* initialize backlight */
|
|
|
|
memset(&props, 0, sizeof(struct backlight_properties));
|
2011-03-22 23:30:21 +00:00
|
|
|
props.type = BACKLIGHT_PLATFORM;
|
2010-02-17 21:39:44 +00:00
|
|
|
props.max_brightness = pcc->sinf[SINF_AC_MAX_BRIGHT];
|
|
|
|
pcc->backlight = backlight_device_register("panasonic", NULL, pcc,
|
|
|
|
&pcc_backlight_ops, &props);
|
2010-02-26 12:20:10 +00:00
|
|
|
if (IS_ERR(pcc->backlight)) {
|
|
|
|
result = PTR_ERR(pcc->backlight);
|
2010-08-05 05:30:02 +00:00
|
|
|
goto out_input;
|
2010-02-26 12:20:10 +00:00
|
|
|
}
|
2008-09-23 15:46:57 +00:00
|
|
|
|
|
|
|
/* read the initial brightness setting from the hardware */
|
|
|
|
pcc->backlight->props.brightness = pcc->sinf[SINF_AC_CUR_BRIGHT];
|
|
|
|
|
2020-08-21 18:14:29 +00:00
|
|
|
/* Reset initial sticky key mode since the hardware register state is not consistent */
|
|
|
|
acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, 0);
|
|
|
|
pcc->sticky_key = 0;
|
2008-09-23 15:46:57 +00:00
|
|
|
|
2020-08-21 18:14:32 +00:00
|
|
|
pcc->eco_mode = pcc->sinf[SINF_ECO_MODE];
|
2020-08-21 18:14:30 +00:00
|
|
|
pcc->mute = pcc->sinf[SINF_MUTE];
|
2020-08-21 18:14:33 +00:00
|
|
|
pcc->ac_brightness = pcc->sinf[SINF_AC_CUR_BRIGHT];
|
|
|
|
pcc->dc_brightness = pcc->sinf[SINF_DC_CUR_BRIGHT];
|
2021-03-26 19:20:22 +00:00
|
|
|
pcc->current_brightness = pcc->sinf[SINF_CUR_BRIGHT];
|
2020-08-21 18:14:30 +00:00
|
|
|
|
2008-09-23 15:46:57 +00:00
|
|
|
/* add sysfs attributes */
|
|
|
|
result = sysfs_create_group(&device->dev.kobj, &pcc_attr_group);
|
|
|
|
if (result)
|
|
|
|
goto out_backlight;
|
|
|
|
|
2020-08-21 18:14:25 +00:00
|
|
|
/* optical drive initialization */
|
|
|
|
if (ACPI_SUCCESS(check_optd_present())) {
|
|
|
|
pcc->platform = platform_device_register_simple("panasonic",
|
|
|
|
-1, NULL, 0);
|
|
|
|
if (IS_ERR(pcc->platform)) {
|
|
|
|
result = PTR_ERR(pcc->platform);
|
|
|
|
goto out_backlight;
|
|
|
|
}
|
|
|
|
result = device_create_file(&pcc->platform->dev,
|
|
|
|
&dev_attr_cdpower);
|
|
|
|
pcc_register_optd_notifier(pcc, "\\_SB.PCI0.EHCI.ERHB.OPTD");
|
|
|
|
if (result)
|
|
|
|
goto out_platform;
|
|
|
|
} else {
|
|
|
|
pcc->platform = NULL;
|
|
|
|
}
|
|
|
|
|
2008-09-23 15:46:57 +00:00
|
|
|
return 0;
|
|
|
|
|
2020-08-21 18:14:25 +00:00
|
|
|
out_platform:
|
|
|
|
platform_device_unregister(pcc->platform);
|
2008-09-23 15:46:57 +00:00
|
|
|
out_backlight:
|
|
|
|
backlight_device_unregister(pcc->backlight);
|
2010-08-05 05:30:02 +00:00
|
|
|
out_input:
|
2017-03-09 12:11:47 +00:00
|
|
|
input_unregister_device(pcc->input_dev);
|
2010-02-17 21:39:44 +00:00
|
|
|
out_sinf:
|
|
|
|
kfree(pcc->sinf);
|
2008-09-23 15:46:57 +00:00
|
|
|
out_hotkey:
|
|
|
|
kfree(pcc);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-01-23 23:24:48 +00:00
|
|
|
static int acpi_pcc_hotkey_remove(struct acpi_device *device)
|
2008-09-23 15:46:57 +00:00
|
|
|
{
|
|
|
|
struct pcc_acpi *pcc = acpi_driver_data(device);
|
|
|
|
|
|
|
|
if (!device || !pcc)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2020-08-21 18:14:25 +00:00
|
|
|
if (pcc->platform) {
|
|
|
|
device_remove_file(&pcc->platform->dev, &dev_attr_cdpower);
|
|
|
|
platform_device_unregister(pcc->platform);
|
|
|
|
}
|
|
|
|
pcc_unregister_optd_notifier(pcc, "\\_SB.PCI0.EHCI.ERHB.OPTD");
|
|
|
|
|
2008-09-23 15:46:57 +00:00
|
|
|
sysfs_remove_group(&device->dev.kobj, &pcc_attr_group);
|
|
|
|
|
|
|
|
backlight_device_unregister(pcc->backlight);
|
|
|
|
|
2017-03-09 12:11:47 +00:00
|
|
|
input_unregister_device(pcc->input_dev);
|
2008-09-23 15:46:57 +00:00
|
|
|
|
|
|
|
kfree(pcc->sinf);
|
|
|
|
kfree(pcc);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-28 11:48:41 +00:00
|
|
|
module_acpi_driver(acpi_pcc_driver);
|