Skip to content

Commit

Permalink
platform/x86: panasonic-laptop: Fix sticky key init bug
Browse files Browse the repository at this point in the history
The return value of the sticky key on some models (e.g. CF-W5) do not
reflect its state. How to retrieve its state from firmware is unknown.
The safest bet is to reset it at module init and store its state in
pcc struct.

Signed-off-by: Kenneth Chan <kenneth.t.chan@gmail.com>
Link: https://lore.kernel.org/r/20200821181433.17653-6-kenneth.t.chan@gmail.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  • Loading branch information
Kenneth Chan authored and Hans de Goede committed Nov 10, 2020
1 parent 80373ad commit 0085635
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions drivers/platform/x86/panasonic-laptop.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* ChangeLog:
* Aug.18, 2020 Kenneth Chan <kenneth.t.chan@gmail.com>
* fix sticky_key init bug
* fix naming of platform files for consistency with other
* modules
* split MODULE_AUTHOR() by one author per macro call
Expand Down Expand Up @@ -218,7 +219,7 @@ static const struct key_entry panasonic_keymap[] = {
struct pcc_acpi {
acpi_handle handle;
unsigned long num_sifr;
int sticky_mode;
int sticky_key;
u32 *sinf;
struct acpi_device *device;
struct input_dev *input_dev;
Expand Down Expand Up @@ -491,20 +492,22 @@ static ssize_t sticky_key_show(struct device *dev, struct device_attribute *attr
if (!acpi_pcc_retrieve_biosdata(pcc))
return -EIO;

return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_STICKY_KEY]);
return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sticky_key);
}

static ssize_t sticky_key_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 val;
int err, val;

if (count && sscanf(buf, "%i", &val) == 1 &&
(val == 0 || val == 1)) {
err = kstrtoint(buf, 0, &val);
if (err)
return err;
if (val == 0 || val == 1) {
acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, val);
pcc->sticky_mode = val;
pcc->sticky_key = val;
}

return count;
Expand Down Expand Up @@ -687,7 +690,9 @@ static int acpi_pcc_hotkey_resume(struct device *dev)
if (!pcc)
return -EINVAL;

return acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, pcc->sticky_mode);
acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, pcc->sticky_key);

return 0;
}
#endif

Expand Down Expand Up @@ -751,8 +756,9 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
/* read the initial brightness setting from the hardware */
pcc->backlight->props.brightness = pcc->sinf[SINF_AC_CUR_BRIGHT];

/* read the initial sticky key mode from the hardware */
pcc->sticky_mode = pcc->sinf[SINF_STICKY_KEY];
/* 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;

/* add sysfs attributes */
result = sysfs_create_group(&device->dev.kobj, &pcc_attr_group);
Expand Down

0 comments on commit 0085635

Please sign in to comment.