History log of /linux-master/drivers/platform/x86/ideapad-laptop.c
Revision Date Author Comments
# f492f5f3 09-Mar-2024 Gergo Koteles <soyer@irl.hu>

platform/x86: ideapad-laptop: map Fn + R key to KEY_REFRESH_RATE_TOGGLE

Newer Lenovo Yogas and Legions with 60Hz/90Hz displays send a wmi event
when Fn + R is pressed. This is intended for use to switch between the
two refresh rates.

The Fn + R key was incorrectly assigned to KEY_DISPLAYTOGGLE because it
is used to toggle the display on and off.

Map Fn + R key to the KEY_REFRESH_RATE_TOGGLE event code.

Signed-off-by: Gergo Koteles <soyer@irl.hu>
Link: https://lore.kernel.org/r/8fd36f0f016dde700396d8afaba1979d5dbc30a1.1710065750.git.soyer@irl.hu
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>


# c5211eac 10-Feb-2024 Gergo Koteles <soyer@irl.hu>

platform/x86: ideapad-laptop: support Fn+R dual-function key

According to the manual, Fn+R adjusts the display refresh rate.
Map Fn+R to KEY_DISPLAYTOGGLE.

Signed-off-by: Gergo Koteles <soyer@irl.hu>
Link: https://lore.kernel.org/r/0cdbc0e6eb65e160384ae0ed152e7de3ded1d9d5.1707604991.git.soyer@irl.hu
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>


# 7a3c36ee 14-Nov-2023 Stuart Hayhurst <stuart.a.hayhurst@gmail.com>

platform/x86: ideapad-laptop: Set max_brightness before using it

max_brightness is used in ideapad_kbd_bl_brightness_get() before it's set,
causing ideapad_kbd_bl_brightness_get() to return -EINVAL sometimes.

Fixes: ecaa1867b524 ("platform/x86: ideapad-laptop: Add support for keyboard backlights using KBLC ACPI symbol")
Signed-off-by: Stuart Hayhurst <stuart.a.hayhurst@gmail.com>
Cc: stable@vger.kernel.org
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20231114114055.6220-2-stuart.a.hayhurst@gmail.com
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>


# ecaa1867 27-Aug-2023 Stuart Hayhurst <stuart.a.hayhurst@gmail.com>

platform/x86: ideapad-laptop: Add support for keyboard backlights using KBLC ACPI symbol

Newer Lenovo laptops seem to use the KBLC symbol to control the backlight
Add support for handling the keyboard backlight on these devices

Signed-off-by: Stuart Hayhurst <stuart.a.hayhurst@gmail.com>
Link: https://lore.kernel.org/r/20230827161940.485200-1-stuart.a.hayhurst@gmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# a260f7d7 19-Aug-2023 André Apitzsch <git@apitzsch.eu>

platform/x86: ideapad-laptop: Add support for new hotkeys found on ThinkBook 14s Yoga ITL

The Lenovo Thinkbook 14s Yoga ITL has 4 new symbols/shortcuts on their
F9-F11 and PrtSc keys:

F9: Has a symbol of a head with a headset, the manual says "Service key"
F10: Has a symbol of a telephone horn which has been picked up from the
receiver, the manual says: "Answer incoming calls"
F11: Has a symbol of a telephone horn which is resting on the receiver,
the manual says: "Reject incoming calls"
PrtSc: Has a symbol of a siccor and a dashed ellipse, the manual says:
"Open the Windows 'Snipping' Tool app"

This commit adds support for these 4 new hkey events.

Signed-off-by: André Apitzsch <git@apitzsch.eu>
Link: https://lore.kernel.org/r/20230819-lenovo_keys-v1-1-9d34eac88e0a@apitzsch.eu
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 0de0ab9a 28-Mar-2023 Andrew Kallmeyer <kallmeyeras@gmail.com>

platform/x86: Move ideapad ACPI helpers to a new header

These functions will be used by a driver written by Gergo Koteles to
detect the tablet mode switch in Lenovo Yoga laptops. These changes were
discussed in review of that patch.

This is the minimal set of functions needed in that driver, there are
several more small functions left in the ACPI Helpers section in
ideapad-laptop.c. The only change is the functions are now marked inline
as requested in the review comments.

Signed-off-by: Andrew Kallmeyer <kallmeyeras@gmail.com>
Link: https://lore.kernel.org/r/20221004214332.35934-1-soyer@irl.hu/
Tested-by: André Apitzsch <git@apitzsch.eu>
Link: https://lore.kernel.org/r/20230329014559.44494-2-kallmeyeras@gmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# d21c474c 02-Mar-2023 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

platform/x86: ideapad-laptop: Convert to platform remove callback returning void

The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is (mostly) ignored
and this typically results in resource leaks. To improve here there is a
quest to make the remove callback return void. In the first step of this
quest all drivers are converted to .remove_new() which already returns
void.

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20230302144732.1903781-15-u.kleine-koenig@pengutronix.de
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# e3271a59 30-Mar-2023 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Stop sending KEY_TOUCHPAD_TOGGLE

Commit 5829f8a897e4 ("platform/x86: ideapad-laptop: Send
KEY_TOUCHPAD_TOGGLE on some models") made ideapad-laptop send
KEY_TOUCHPAD_TOGGLE when we receive an ACPI notify with VPC event bit 5 set
and the touchpad-state has not been changed by the EC itself already.

This was done under the assumption that this would be good to do to make
the touchpad-toggle hotkey work on newer models where the EC does not
toggle the touchpad on/off itself (because it is not routed through
the PS/2 controller, but uses I2C).

But it turns out that at least some models, e.g. the Yoga 7-15ITL5 the EC
triggers an ACPI notify with VPC event bit 5 set on resume, which would
now cause a spurious KEY_TOUCHPAD_TOGGLE on resume to which the desktop
environment responds by disabling the touchpad in software, breaking
the touchpad (until manually re-enabled) on resume.

It was never confirmed that sending KEY_TOUCHPAD_TOGGLE actually improves
things on new models and at least some new models like the Yoga 7-15ITL5
don't have a touchpad on/off toggle hotkey at all, while still sending
ACPI notify events with VPC event bit 5 set.

So it seems best to revert the change to send KEY_TOUCHPAD_TOGGLE when
receiving an ACPI notify events with VPC event bit 5 and the touchpad
state as reported by the EC has not changed.

Note this is not a full revert the code to cache the last EC touchpad
state is kept to avoid sending spurious KEY_TOUCHPAD_ON / _OFF events
on resume.

Fixes: 5829f8a897e4 ("platform/x86: ideapad-laptop: Send KEY_TOUCHPAD_TOGGLE on some models")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217234
Cc: stable@vger.kernel.org
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20230330194644.64628-1-hdegoede@redhat.com


# f4b7f8fe 15-Dec-2022 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Add Legion 5 15ARH05 DMI id to set_fn_lock_led_list[]

The Lenovo Legion 5 15ARH05 needs ideapad-laptop to call SALS_FNLOCK_ON /
SALS_FNLOCK_OFF on Fn-lock state change to get the LED in the Fn key to
correctly reflect the Fn-lock state.

Add a DMI match for the Legion 5 15ARH05 to the set_fn_lock_led_list[]
table for this.

Fixes: 81a5603a0f50 ("platform/x86: ideapad-laptop: Fix interrupt storm on fn-lock toggle on some Yoga laptops")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20221215154357.123876-1-hdegoede@redhat.com


# 301e0d76 16-Nov-2022 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Make touchpad_ctrl_via_ec a module option

Remove the ACPI-HID + DMI-id deny-lists for touchpad_ctrl_via_ec and
instead make it a module option which defaults to false.

The touchpad sysfs attribute allowing directly writing VPCCMD_W_TOUCHPAD
from userspace has been leading to a lot of bug-reports / patches adding
both ACPI HID + dmi-id based deny-lists for it which then need to be
expanded all the time going forward leading to a high maintenance load.

At the same time the touchpad sysfs attribute is not a standard Linux
userspace API. So it is not used in standard desktop-enviroments, instead
it is only used in the following 2 rare circumstances:

1. Ideapad specific control-panel like applets
2. Custom scripts written by users

For 1. these applets need to already deal with the touchpad sysfs attr
sometimes not being there because of the existing deny lists so hiding
it be default should not cause an issue; and most desktop environments
already have a touchpad-disable option in their native control-panel,
so having an ideapad specific toggle for this is not necessary.

For 2. since these users are already customizing their systems they
can add the module option if they want to keep using the touchpad
sysfs attribute.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Maxim Mikityanskiy <maxtram95@gmail.com>
Link: https://lore.kernel.org/r/20221117110244.67811-7-hdegoede@redhat.com


# a10ba160 16-Nov-2022 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Stop writing VPCCMD_W_TOUCHPAD at probe time

Commit d69cd7eea93e ("platform/x86: ideapad-laptop: Disable touchpad_switch
for ELAN0634") from Janary 2021 added a flag hiding the touchpad sysfs-attr
and disabling ideapad_sync_touchpad_state() because some devices
"do not use EC to switch touchpad".

At the same time this added a write(VPCCMD_W_TOUCHPAD, 1) call at probe
time on these same devices. This seems to be copied from the rfkill code
which does something similar when hw rfkill support is disabled.

But for the rfkill code this is known to be necessary on some models,
where as for the touchpad control no motivation is given for doing this
and prior to this patch there were no reports of needing to do this.

So this seems unnecessary; and it is best to avoid poking the hardware
unnecessary to avoid unwanted side effects, so remove this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Maxim Mikityanskiy <maxtram95@gmail.com>
Link: https://lore.kernel.org/r/20221117110244.67811-6-hdegoede@redhat.com


# 5829f8a8 16-Nov-2022 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Send KEY_TOUCHPAD_TOGGLE on some models

On recent Ideapad models the EC does not control the touchpad at all,
so instead of sending KEY_TOUCHPAD_ON/ _OFF on touchpad toggle hotkey
events, ideapad-laptop should send KEY_TOUCHPAD_TOGGLE and let userspace
handle the toggling.

Check for this by checking if the value read from VPCCMD_R_TOUCHPAD
actually changes when receiving a touchpad-toggle hotkey event; and
if it does not change send KEY_TOUCHPAD_TOGGLE to userspace to let
userspace enable/disable the touchpad in software.

Note this also drops the priv->features.touchpad_ctrl_via_ec check from
ideapad_sync_touchpad_state() so that KEY_TOUCHPAD_TOGGLE will be send
on laptops where this is not set too. This can be safely dropped now
because the i8042_command(I8042_CMD_AUX_ENABLE/_DISABLE) call is now
guarded by its own feature flag.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Maxim Mikityanskiy <maxtram95@gmail.com>
Link: https://lore.kernel.org/r/20221117110244.67811-5-hdegoede@redhat.com


# c69e7d84 16-Nov-2022 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Only toggle ps2 aux port on/off on select models

Recently there have been multiple patches to disable the ideapad-laptop's
touchpad control code, because it is causing issues on various laptops:

Commit d69cd7eea93e ("platform/x86: ideapad-laptop: Disable touchpad_switch for ELAN0634")
Commit a231224a601c ("platform/x86: ideapad-laptop: Disable touchpad_switch")

The turning on/off of the ps2 aux port was added specifically for
the IdeaPad Z570, where the EC does toggle the touchpad on/off LED and
toggles the value returned by reading VPCCMD_R_TOUCHPAD, but it does not
actually turn on/off the touchpad.

The ideapad-laptop code really should not be messing with the i8042
controller on all devices just for this special case.

Add a new ctrl_ps2_aux_port flag set based on a DMI based allow-list
for devices which need this workaround, populating it with just
the Ideapad Z570 for now.

This also adds a module parameter so that this behavior can easily
be enabled on other models which may need it.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Maxim Mikityanskiy <maxtram95@gmail.com>
Link: https://lore.kernel.org/r/20221117110244.67811-4-hdegoede@redhat.com


# f4dd8c44 16-Nov-2022 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Do not send KEY_TOUCHPAD* events on probe / resume

The sending of KEY_TOUCHPAD* events is causing spurious touchpad OSD
showing on resume.

Disable the sending of events on probe / resume to fix this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Maxim Mikityanskiy <maxtram95@gmail.com>
Link: https://lore.kernel.org/r/20221117110244.67811-3-hdegoede@redhat.com


# 289a5989 16-Nov-2022 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Refactor ideapad_sync_touchpad_state()

Add an error exit for read_ec_data() failing instead of putting the main
body in an if (success) block.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Maxim Mikityanskiy <maxtram95@gmail.com>
Link: https://lore.kernel.org/r/20221117110244.67811-2-hdegoede@redhat.com


# f32e0241 15-Nov-2022 Philipp Jungkamp <p.jungkamp@gmx.net>

platform/x86: ideapad-laptop: support for more special keys in WMI

The event data of the WMI event 0xD0, which is assumed to be the
fn_lock, is used to indicate several special keys on newer Yoga 7/9
laptops.

The notify_id 0xD0 is non-unique in the DSDT of the Yoga 9 14IAP7, this
causes wmi_get_event_data() to report wrong values.
Port the ideapad-laptop WMI code to the wmi bus infrastructure which
does not suffer from the shortcomings of wmi_get_event_data().

Signed-off-by: Philipp Jungkamp <p.jungkamp@gmx.net>
Link: https://lore.kernel.org/r/20221116110647.3438-1-p.jungkamp@gmx.net
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# be5dd7d8 29-Oct-2022 Eray Orçunus <erayorcunus@gmail.com>

platform/x86: ideapad-laptop: Add new _CFG bit numbers for future use

Later IdeaPads report various things in last 8 bits of _CFG, at least
5 of them represent supported on-screen-displays. Add those bit numbers
to the enum, and use CFG_OSD_ as prefix of their names. Also expose
the values of these bits to debugfs, since they can be useful.

Signed-off-by: Eray Orçunus <erayorcunus@gmail.com>
Acked-by: Ike Panhc <ike.pan@canonical.com>
Link: https://lore.kernel.org/r/20221029120311.11152-5-erayorcunus@gmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 58318828 29-Oct-2022 Eray Orçunus <erayorcunus@gmail.com>

platform/x86: ideapad-laptop: Revert "check for touchpad support in _CFG"

Last 8 bit of _CFG started being used in later IdeaPads, thus 30th bit
doesn't always show whether device supports touchpad or touchpad switch.
Remove checking bit 30 of _CFG, so older IdeaPads like S10-3 can switch
touchpad again via touchpad attribute.

This reverts commit b3ed1b7fe378 ("platform/x86: ideapad-laptop: check for
touchpad support in _CFG").

Signed-off-by: Eray Orçunus <erayorcunus@gmail.com>
Acked-by: Ike Panhc <ike.pan@canonical.com>
Link: https://lore.kernel.org/r/20221029120311.11152-2-erayorcunus@gmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# b44fd994 15-Nov-2022 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Add module parameters to match DMI quirk tables

Add module parameters to allow setting the hw_rfkill_switch and
set_fn_lock_led feature flags for testing these on laptops which are not
on the DMI-id based allow lists for these 2 flags.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20221115193400.376159-1-hdegoede@redhat.com


# 81a5603a 11-Nov-2022 Arnav Rawat <arnavr3@illinois.edu>

platform/x86: ideapad-laptop: Fix interrupt storm on fn-lock toggle on some Yoga laptops

Commit 3ae86d2d4704 ("platform/x86: ideapad-laptop: Fix Legion 5 Fn lock
LED") uses the WMI event-id for the fn-lock event on some Legion 5 laptops
to manually toggle the fn-lock LED because the EC does not do it itself.
However, the same WMI ID is also sent on some Yoga laptops. Here, setting
the fn-lock state is not valid behavior, and causes the EC to spam
interrupts until the laptop is rebooted.

Add a set_fn_lock_led_list[] DMI-id list and only enable the workaround to
manually set the LED on models on this list.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=212671
Cc: Meng Dong <whenov@gmail.com>
Signed-off-by: Arnav Rawat <arnavr3@illinois.edu>
Link: https://lore.kernel.org/r/12093851.O9o76ZdvQC@fedora
[hdegoede@redhat.com: Check DMI-id list only once and store the result]
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# a231224a 18-Oct-2022 Manyi Li <limanyi@uniontech.com>

platform/x86: ideapad-laptop: Disable touchpad_switch

Ideapads for "Lenovo Yoga 3 Pro 1370" and "ZhaoYang K4e-IML" do not
use EC to switch touchpad.

Reading VPCCMD_R_TOUCHPAD will return zero thus touchpad may be blocked
unexpectedly.

Signed-off-by: Manyi Li <limanyi@uniontech.com>
Link: https://lore.kernel.org/r/20221018095323.14591-1-limanyi@uniontech.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 7dbd3af5 27-Jun-2022 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Add Ideapad 5 15ITL05 to ideapad_dytc_v4_allow_table[]

The Ideapad 5 15ITL05 uses DYTC version 4 for platform-profile
control. This has been tested successfully with the ideapad-laptop
DYTC version 5 code; Add the Ideapad 5 15ITL05 to the
ideapad_dytc_v4_allow_table[].

Fixes: 599482c58ebd ("platform/x86: ideapad-laptop: Add platform support for Ideapad 5 Pro 16ACH6-82L5")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=213297
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20220627130850.313537-1-hdegoede@redhat.com


# 1ccd5906 23-Jun-2022 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Add allow_v4_dytc module parameter

Add an allow_v4_dytc module parameter to allow users to easily test if
DYTC version 4 platform-profiles work on their laptop.

Fixes: 599482c58ebd ("platform/x86: ideapad-laptop: Add platform support for Ideapad 5 Pro 16ACH6-82L5")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=213297
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20220623115914.103001-1-hdegoede@redhat.com


# 8853e8ce 27-Jun-2022 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Add Ideapad 5 15ITL05 to ideapad_dytc_v4_allow_table[]

The Ideapad 5 15ITL05 uses DYTC version 4 for platform-profile
control. This has been tested successfully with the ideapad-laptop
DYTC version 5 code; Add the Ideapad 5 15ITL05 to the
ideapad_dytc_v4_allow_table[].

Fixes: 599482c58ebd ("platform/x86: ideapad-laptop: Add platform support for Ideapad 5 Pro 16ACH6-82L5")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=213297
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20220627130850.313537-1-hdegoede@redhat.com


# a27a1e35 23-Jun-2022 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Add allow_v4_dytc module parameter

Add an allow_v4_dytc module parameter to allow users to easily test if
DYTC version 4 platform-profiles work on their laptop.

Fixes: 599482c58ebd ("platform/x86: ideapad-laptop: Add platform support for Ideapad 5 Pro 16ACH6-82L5")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=213297
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20220623115914.103001-1-hdegoede@redhat.com


# 043449e7 13-Oct-2021 Rafael J. Wysocki <rafael.j.wysocki@intel.com>

platform: x86: ideapad-laptop: Use ACPI_COMPANION() directly

The ACPI_HANDLE() macro is a wrapper arond the ACPI_COMPANION()
macro and the ACPI handle produced by the former comes from the
ACPI device object produced by the latter, so it is way more
straightforward to evaluate the latter directly instead of passing
the handle produced by the former to acpi_bus_get_device().

Modify ideapad_acpi_add() accordingly (no intentional functional
impact).

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/8000884.T7Z3S40VBb@kreacher
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 599482c5 25-Sep-2021 Kelly Anderson <kelly@xilka.com>

platform/x86: ideapad-laptop: Add platform support for Ideapad 5 Pro 16ACH6-82L5

Adding support specifically for Ideapad 5 Pro 16ACH6-82L5 by adding a
allow list that can validate notebooks for which dytc_version
is less than 5, and seem to work fine at dytc_version 4. This code has
been tested to work properly on the specified system.

Signed-off-by: Kelly Anderson <kelly@xilka.com>
Link: https://lore.kernel.org/r/11840239.O9o76ZdvQC@comer.internal
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 3ae86d2d 17-Aug-2021 Meng Dong <whenov@gmail.com>

platform/x86: ideapad-laptop: Fix Legion 5 Fn lock LED

This patch fixes the bug 212671.
Althrough the Fn lock (Fn + Esc) works on Legion 5 (R7000P), its LED
light does not change with the state. This modification sets the Fn lock
state to its current value on receiving the wmi event
8FC0DE0C-B4E4-43FD-B0F3-8871711C1294 to update the LED state.

Signed-off-by: Meng Dong <whenov@gmail.com>
Link: https://lore.kernel.org/r/20210817171203.12855-1-whenov@gmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# ab66724a 23-May-2021 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Ignore VPC event bit 10

VPC event bit 10 gets set on a Yoga 300-11IBR when the EC believes that the
device has changed between laptop/tent/stand/tablet mode.

The EC relies on getting angle info from 2 accelerometers through a special
windows service calling a DSM on the DUAL250E ACPI-device. Linux does not
do this, making the laptop/tent/stand/tablet mode info unreliable.

Ignore VPC event bit 10 to avoid the warnings triggered by the default case
in ideapad_acpi_notify().

Note that the plan for Linux is to have iio-sensor-proxy read the 2
accelerometers and have it provide info about which mode 360° hinges
2-in-1s to the rest of userspace:
https://gitlab.freedesktop.org/hadess/iio-sensor-proxy/-/issues/216

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20210523172331.177834-1-hdegoede@redhat.com


# b09aaa3f 07-May-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: fix method name typo

"smbc" should be "sbmc". `eval_smbc()` incorrectly called
the SMBC ACPI method instead of SBMC. This resulted in
partial loss of functionality. Rectify that by calling
the correct ACPI method (SBMC), and also rename
methods and constants.

BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=212985
Fixes: 0b765671cb80 ("platform/x86: ideapad-laptop: group and separate (un)related constants into enums")
Fixes: ff36b0d953dc ("platform/x86: ideapad-laptop: rework and create new ACPI helpers")
Cc: stable@vger.kernel.org # 5.12
Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210507235333.286505-1-pobrn@protonmail.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# ff67dbd5 27-Apr-2021 Qiu Wenbo <qiuwenbo@kylinos.com.cn>

platform/x86: ideapad-laptop: fix a NULL pointer dereference

The third parameter of dytc_cql_command should not be NULL since it will
be dereferenced immediately.

Fixes: ff36b0d953dc4 ("platform/x86: ideapad-laptop: rework and create new ACPI helpers")
Signed-off-by: Qiu Wenbo <qiuwenbo@kylinos.com.cn>
Acked-by: Ike Panhc <ike.pan@canonical.com>
Link: https://lore.kernel.org/r/20210428050636.8003-1-qiuwenbo@kylinos.com.cn
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 6b49dea4 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: add "always on USB charging" control support

Certain models have a so-called "always on USB charging" feature,
which enables USB charging even when the computer is turned off
or suspended, and which may be controlled/queried using the
SALS/HALS ACPI methods. Expose this functionality via a new device
attribute (usb_charging). Tested on: Lenovo YOGA 520-14IKB 80X8

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-28-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 503325f8 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: add keyboard backlight control support

On certain models it is possible to control/query the
keyboard backlight via the SALS/HALS ACPI methods. Add
support for that, and register an LED class device to expose
this functionality. Tested on: Lenovo YOGA 520-14IKB 80X8

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-27-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# c6795746 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: send notification about touchpad state change to sysfs

Consumers can determine if the value of an attribute changed much more
easily if changes are broadcast using sysfs_notify(), so utilize it.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-26-pobrn@protonmail.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 65c7713a 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: fix checkpatch warnings, more consistent style

Fix all checkpatch warnings. Reorder variable definitions from
longest to shortest. Add more whitespaces for better readability.
Rename variables named `ret` to `err` where appropriate. Reorder
sysfs attributes show/store callbacks and the `ideapad_attributes`
array in lexicographic order. And other minor formatting changes.
No significant functional changes are intended.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-25-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 921f70ff 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

Revert "platform/x86: ideapad-laptop: Switch touchpad attribute to be RO"

The touchpad can be enabled/disabled via this attribute on a Lenovo
Yoga 520-14IKB. Allow writing as it provides legitimate functionality.

This reverts commit 7f363145992cebf4ea760447f1cfdf6f81459683.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-24-pobrn@protonmail.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 18227424 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: change 'cfg' debugfs file format

Minor formatting changes. Use seq_puts() where possible.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-23-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 7553390d 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: change 'status' debugfs file format

Remove conservation mode reporting since it is already reported via
the appropriate device attribute, and its state can be deduced from
the value of GBMD. Add the return value of the GBMD and HALS ACPI
methods to the output. Use seq_puts() where possible.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-22-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# b3ed1b7f 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: check for touchpad support in _CFG

Bit 30 of _CFG is set if the device has a touchpad, check that
in is_visible() for the touchpad attribute. Show 'touchpad', if
supported, in the list of capabilities in the 'cfg' debugfs file.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-21-pobrn@protonmail.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 392cbf0a 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: check for Fn-lock support in HALS

Bit 9 in the return value of the HALS ACPI method is set if
Fn-lock is supported. Change ideapad_check_features() to check it.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-20-pobrn@protonmail.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 1c59de4a 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: rework is_visible() logic

Store the supported features in the driver private
data, and modify the is_visible() callback to use it,
and create ideapad_check_features() to populate it.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-19-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# ff36b0d9 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: rework and create new ACPI helpers

Create dedicated helper functions for accessing the main ACPI methods:
GBMD, SMBC, HALS, SALS; and utilize them. Use `unsigned long` consistently
in every ACPI helper wherever possible. Change names to better express
purpose. Do not assign values to output parameters in case of failure.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-18-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 0b765671 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: group and separate (un)related constants into enums

Group and rename constants depending on which ACPI interface
they pertain to, and rename CFG_X constants to CFG_CAP_X.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-17-pobrn@protonmail.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 00641c08 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: misc. device attribute changes

Do not handle zero length buffer separately. Use kstrtouint() instead
of sscanf(). Use kstrtobool() in store_ideapad_cam(). These
introduce minor ABI changes, but it is expected that no users rely
on the previous behavior. Thus the change is deemed justifed.
Additionally, use `!!` to convert to `int` and use the "%d" format
specifier in sysfs_emit() for boolean-like attributes.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-16-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# c81f2410 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: always propagate error codes from device attributes' show() callback

Consumers can differentiate an error from a successful read much more
easily if the read() call fails with an appropriate errno instead of
returning a magic string like "-1". This introduces an ABI change, but
not many users are expected to be relying on the previous behavior,
and this change makes this module conforming to the standard behavior
that sysfs attribute show/store callbacks return an appropriate
errno in case of failure. Thus the ABI breakage is deemed justified.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-15-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 7be193e3 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: convert ACPI helpers to return -EIO in case of failure

ACPI helpers returned -1 in case of failure. Convert these
functions to return appropriate error codes, and convert
their users to propagate these error codes accordingly.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-14-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 654324c4 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: use dev_{err,warn} or appropriate variant to display log messages

Having the device name in the log message makes it easier to determine
in the context of which device the message was printed, so utilize the
appropriate variants of dev_{err,warn,...} when printing log messages.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-12-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 40e0447d 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: use msecs_to_jiffies() helper instead of hand-crafted formula

The current code used a hand-crafted formula to convert milliseconds to
jiffies, replace it with the msecs_to_jiffies() function. Furthermore,
use a while loop instead of for loop for shorter lines and simplicity.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-11-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 0c4915b6 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: use for_each_set_bit() helper to simplify event processing

The current code used the combination of a for loop + test_bit,
which can be simplified using for_each_set_bit(), so utilize that.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-10-pobrn@protonmail.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 708086b2 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: use kobj_to_dev()

Use kobj_to_dev() instead of open-coding the container_of() macro.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-9-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 8782d8d7 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: use device_{add,remove}_group

Use device_{add,remove}_group instead of sysfs_{add,remove}_group.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-8-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# d6b50889 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: use sysfs_emit()

sysfs_emit() has been introduced to make it less ambiguous
which function is preferred when writing to the output
buffer in a device attribute's show() callback. Convert the
ideapad-laptop module to utilize this new helper function.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-7-pobrn@protonmail.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# caa315b8 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: add missing call to submodule destructor

ideapad_dytc_profile_exit() is not called in ideapad_acpi_add()
in the error path. Add the missing call.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-6-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 7d38f034 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: sort includes lexicographically

Managing includes is easier when they are
sorted, so sort them lexicographically.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-5-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 803be832 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: use appropriately typed variable to store the return value of ACPI methods

Use a variable with type `acpi_status` to store the return value of
ACPI methods instead of a plain `int`. And use ACPI_{SUCCESS,FAILURE}
macros where possible instead of direct comparison.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-4-pobrn@protonmail.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# e1a39a44 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: remove unnecessary NULL checks

The checks that are removed test pointers which should not
be NULL. If they are NULL, that indicates a bug in
a different part of the kernel. Instead of silently
bailing out, let it fail loudly.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-3-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# a14b3c83 03-Feb-2021 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: ideapad-laptop: remove unnecessary dev_set_drvdata() call

The driver core already sets the driver specific data on
bind failure or removal. Thus the call is unnecessary.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-2-pobrn@protonmail.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# eabe5339 05-Jan-2021 Jiaxun Yang <jiaxun.yang@flygoat.com>

platform/x86: ideapad-laptop: DYTC Platform profile support

Add support to ideapad-laptop for Lenovo platforms that have DYTC
version 5 support or newer to use the platform profile feature.

Mostly based on Mark Pearson <markpearson@lenovo.com>'s thinkpad-acpi
work but massaged to fit ideapad driver.

Note that different from ThinkPads, IdeaPads's Thermal Hotkey won't
trigger profile switch itself, we'll leave it for userspace programs.

Tested on Lenovo Yoga-14S ARE Chinese Edition.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20210105131447.38036-3-jiaxun.yang@flygoat.com
[hdegoede@redhat.com s/QUIET/LOW_POWER/]
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# d69cd7ee 07-Jan-2021 Jiaxun Yang <jiaxun.yang@flygoat.com>

platform/x86: ideapad-laptop: Disable touchpad_switch for ELAN0634

Newer ideapads (e.g.: Yoga 14s, 720S 14) come with ELAN0634 touchpad do not
use EC to switch touchpad.

Reading VPCCMD_R_TOUCHPAD will return zero thus touchpad may be blocked
unexpectedly.
Writing VPCCMD_W_TOUCHPAD may cause a spurious key press.

Add has_touchpad_switch to workaround these machines.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: stable@vger.kernel.org # 5.4+
--
v2: Specify touchpad to ELAN0634
v3: Stupid missing ! in v2
v4: Correct acpi_dev_present usage (Hans)
Link: https://lore.kernel.org/r/20210107144438.12605-1-jiaxun.yang@flygoat.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# f419e594 07-Jan-2021 Jiaxun Yang <jiaxun.yang@flygoat.com>

platform/x86: ideapad-laptop: Disable touchpad_switch for ELAN0634

Newer ideapads (e.g.: Yoga 14s, 720S 14) come with ELAN0634 touchpad do not
use EC to switch touchpad.

Reading VPCCMD_R_TOUCHPAD will return zero thus touchpad may be blocked
unexpectedly.
Writing VPCCMD_W_TOUCHPAD may cause a spurious key press.

Add has_touchpad_switch to workaround these machines.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: stable@vger.kernel.org # 5.4+
--
v2: Specify touchpad to ELAN0634
v3: Stupid missing ! in v2
v4: Correct acpi_dev_present usage (Hans)
Link: https://lore.kernel.org/r/20210107144438.12605-1-jiaxun.yang@flygoat.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 17f1bf38 12-Jun-2019 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

platform/x86: ideapad-laptop: no need to check return value of debugfs_create functions

When calling debugfs functions, there is no need to ever check the
return value. The function can work or not, but the code logic should
never do something different based on this.

Cc: Ike Panhc <ike.pan@canonical.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Andy Shevchenko <andy@infradead.org>
Cc: platform-driver-x86@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 16216333 19-May-2019 Thomas Gleixner <tglx@linutronix.de>

treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 1

Based on 2 normalized pattern(s):

this program is free software you can redistribute it and or modify
it under the terms of the gnu general public license as published by
the free software foundation either version 2 of the license or at
your option any later version this program is distributed in the
hope that it will be useful but without any warranty without even
the implied warranty of merchantability or fitness for a particular
purpose see the gnu general public license for more details you
should have received a copy of the gnu general public license along
with this program if not write to the free software foundation inc
51 franklin street fifth floor boston ma 02110 1301 usa

this program is free software you can redistribute it and or modify
it under the terms of the gnu general public license as published by
the free software foundation either version 2 of the license or at
your option [no]_[pad]_[ctrl] any later version this program is
distributed in the hope that it will be useful but without any
warranty without even the implied warranty of merchantability or
fitness for a particular purpose see the gnu general public license
for more details you should have received a copy of the gnu general
public license along with this program if not write to the free
software foundation inc 51 franklin street fifth floor boston ma
02110 1301 usa

extracted by the scancode license scanner the SPDX license identifier

GPL-2.0-or-later

has been chosen to replace the boilerplate/reference in 176 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Jilayne Lovejoy <opensource@jilayne.com>
Reviewed-by: Steve Winslow <swinslow@gmail.com>
Reviewed-by: Allison Randal <allison@lohutok.net>
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190519154040.652910950@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 5105e78e 29-Apr-2019 Hans de Goede <hdegoede@redhat.com>

platform/x86: ideapad-laptop: Remove no_hw_rfkill_list

When the ideapad-laptop driver was first written it was written for laptops
which had a hardware rfkill switch. So when the first ideapad laptops
showed up without a hw rfkill switch and it turned out that in this case
the ideapad firmware interface would always report the wifi being hardware-
blocked, a DMI id list of models which lack a hw rfkill switch was started
(by yours truly). Things were done this way to avoid regressing existing
models with a hw rfkill switch. In hindsight this was a mistake.

Lenovo releases a lot of ideapad models every year and even the latest
models still use the "VPC2004" ACPI interface the ideapad-laptop driver
binds to. Having a hw rfkill switch is quite rare on modern hardware, so
all these new models need to be added to the no_hw_rfkill_list, leading
to a never ending game of whack a mole.

Worse the failure mode when not present on the list, is very bad. In this
case the ideapad-laptop driver will report the wifi as being hw-blocked,
at which points NetworkManager does not even try to use it and the user
ends up with non working wifi.

This leads to various Linux fora on the internet being filled with
wifi not working on ideapad laptops stories, which does not make Linux
look good.

The failure mode when we flip the default to assuming that a hw rfkill
switch is not present OTOH is quite benign. When we properly report the
wifi as being hw-blocked on ideapads which do have the hw-switch; and it
is in the wifi-off position, then at least when using NetworkManager +
GNOME3 the user will get a "wifi disabled in hardware" message when trying
to connect to the wifi from the UI. If OTOH we assume there is no hardware
rfkill switch, then the user will get an empty list for the list of
available networks. Although the empty list vs the "wifi disabled in
hardware" message is a regression, it is a very minor regression and it
can easily be fixed on a model by model basis by filling the new
hw_rfkill_list this commit introduces.

Therefor this commit removes the ever growing no_hw_rfkill_list, flipping
the default to assuming there is no hw rfkill switch and adding a new
hw_rfkill_list. Thereby fixing the wifi not working on all the current
ideapad and yoga models which are not on the list yet and also fixing it
for all future ideapad and yoga models using the "VPC2004" ACPI interface.

Note once this patch has been accepted upstream. I plan to write a blog
post asking for users of ideapads and yoga's with a hw rfkill switch to
step forward, so that we can populate the new hw_rfkill_list with the few
older yoga and ideapad models which actually have a hw rfkill switch.

BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1703338
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 34f0b6e6 06-Mar-2019 Felix Eckhofer <felix@eckhofer.com>

platform/x86: ideapad-laptop: Add S130-14IGM to no_hw_rfkill list

Lenovo Ideapad S130-14IGM does not have a hardware radio switch.
Add it to no_hw_rfkill to enable wireless connections.

Signed-off-by: Felix Eckhofer <felix@eckhofer.com>
Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>


# faf96501 05-Mar-2019 Kai-Heng Feng <kai.heng.feng@canonical.com>

platform/x86: ideapad-laptop: Add Ideapad 530S-14ARR to no_hw_rfkill list

This platform doesn't have hardware switch for rfkill, so add it to
no_hw_rfkill list to prevent wireless gets hard-blocked.

BugLink: https://bugs.launchpad.net/bugs/1818204
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 67133c6d 24-Feb-2019 Hugo Trovao <htrovao@gmail.com>

platform/x86: ideapad-laptop: Add Yoga C930 to no_hw_rfkill_list

Lenovo Yoga C930 does not have a physical hw radio switch which
makes ideapad_laptop to incorrectly disable radio while it should
be working fine. Adding it to the no_hw_rfkill_list makes
wireless available again without having to unload the module.

Signed-off-by: Hugo Trovao <htrovao@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# b7531859 09-Feb-2019 Mark Levedahl <mlevedahl@gmail.com>

platform/x86: ideapad-laptop: Add Y530-I5ICH-1060 to no_hw_rfkill list

Commit 0252894f53fc2693672308 added the Legion Y530 to the no_hw_rfkill
list, but missed a Y530 variant using the nvidia 1060 graphics card.
I have had to blacklist ideapad-laptop as a result to get Wi-Fi working.

dmidecode info:

Handle 0x0001, DMI type 1, 27 bytes
System Information
Manufacturer: LENOVO
Product Name: 81LB
Version: Lenovo Legion Y530-15ICH-1060
Serial Number: <snip>
UUID: <snip>
Wake-up Type: Power Switch
SKU Number: LENOVO_MT_81LB_BU_idea_FM_Legion Y530-15ICH-1060
Family: Legion Y530-15ICH-1060

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>


# 4d9b2864 19-Jan-2019 Yang Fan <nullptr.cpp@gmail.com>

platform/x86: ideapad-laptop: Fix no_hw_rfkill_list for Lenovo RESCUER R720-15IKBN

Commit ae7c8cba3221 ("platform/x86: ideapad-laptop: add lenovo RESCUER
R720-15IKBN to no_hw_rfkill_list") added
DMI_MATCH(DMI_BOARD_NAME, "80WW")
for Lenovo RESCUER R720-15IKBN.

But DMI_BOARD_NAME does not match 80WW on Lenovo RESCUER R720-15IKBN,
thus cause Wireless LAN still be hard blocked.

On Lenovo RESCUER R720-15IKBN:
~$ cat /sys/class/dmi/id/sys_vendor
LENOVO
~$ cat /sys/class/dmi/id/board_name
Provence-5R3
~$ cat /sys/class/dmi/id/product_name
80WW
~$ cat /sys/class/dmi/id/product_version
Lenovo R720-15IKBN

So on Lenovo RESCUER R720-15IKBN:
DMI_SYS_VENDOR should match "LENOVO",
DMI_BOARD_NAME should match "Provence-5R3",
DMI_PRODUCT_NAME should match "80WW",
DMI_PRODUCT_VERSION should match "Lenovo R720-15IKBN".

Fix it, and in according with other entries in no_hw_rfkill_list,
use DMI_PRODUCT_VERSION instead of DMI_BOARD_NAME.

Fixes: ae7c8cba3221 ("platform/x86: ideapad-laptop: add lenovo RESCUER R720-15IKBN to no_hw_rfkill_list")
Signed-off-by: Yang Fan <nullptr.cpp@gmail.com>
Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>


# 0bbbe97f 18-Jan-2019 Anthony Wong <anthony.wong@ubuntu.com>

platform/x86: ideapad: Add ideapad 330-15ICH to no_hw_rfkill

Lenovo ideapad 330-15ICH does not have hardware radio switch
but driver wrongly reports all radios as hard-blocked, add
it to no_hw_rfkill to fix it.

BugLink: https://bugs.launchpad.net/bugs/1811815
Signed-off-by: Anthony Wong <anthony.wong@ubuntu.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 91a75360 14-Nov-2018 Loic WEI YU NENG <loic.wyn@gmail.com>

platform/x86: ideapad-laptop: Add Yoga 2 13 to no_hw_rfkill list

Some Lenovo IdeaPad models lack a physical rfkill switch.
On Lenovo models Yoga 2 13, ideapad-laptop would wrongly report all
radios as blocked by hardware which caused wireless network connections
to fail.

Add these models without an rfkill switch to the no_hw_rfkill list.

Signed-off-by: Loic WEI YU NENG <loic.wyn@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 0252894f 26-Oct-2018 Misha Komarovskiy <zombah@gmail.com>

platform/x86: ideapad: Add Y530-15ICH to no_hw_rfkill

Lenovo Legion Y530-15ICH is another model without
hardware radio switch. Add it to no_hw_rfkill to
enable wireless.

Signed-off-by: Misha Komarovskiy <zombah@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 31e56f23 04-Sep-2018 Zhang Xianwei <zhang.xianwei8@zte.com.cn>

platform/x86: ideapad-laptop: Use __func__ instead of read_ec_cmd in pr_err

Refer to the commit f1395edbcec8 ("platform/x86: ideapad-laptop: Use
__func__ instead of write_ec_cmd in pr_err"), prefer using '"%s...",
__func__' to using 'read_ec_cmd' in read_ec_data.

Signed-off-by: Zhang Xianwei <zhang.xianwei8@zte.com.cn>
Acked-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 56c9bba1 14-Aug-2018 Ike Panhc <ike.pan@canonical.com>

platform/x86: ideapad: Add Y520-15IKBM and Y720-15IKBM to no_hw_rfkill

Lenovo Y520-15IKBM and Y720-15IKBM are another Lenovo models
without physical radio switch and ideapad-laptop reports it
is hard blocked. Add them into no_hw_rfkill to unlock wireless.

BugLink: https://bugs.launchpad.net/bugs/1723612
Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 58e73aa1 22-Jun-2018 Takashi Iwai <tiwai@suse.de>

platform/x86: ideapad-laptop: Apply no_hw_rfkill to Y20-15IKBM, too

The commit 5d9f40b56630 ("platform/x86: ideapad-laptop: Add
Y520-15IKBN to no_hw_rfkill") added the entry for Y20-15IKBN, and it
turned out that another variant, Y20-15IKBM, also requires the
no_hw_rfkill.

Trim the last letter from the string so that it matches to both
Y20-15IKBN and Y20-15IKBM models.

Bugzilla: https://bugzilla.opensuse.org/show_bug.cgi?id=1098626
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>


# 1262516e 28-May-2018 dylanchu <chdy.uuid@gmail.com>

platform/x86: ideapad-laptop: Add E42-80 to no_hw_rfkill

Lenovo Zhaoyang E42-80 is another Lenovo model without a hw rfkill switch,
resulting in wifi always reported as hard blocked.

Add the model to the list of models without rfkill switch.

Signed-off-by: dylanchu <chdy.uuid@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 40760717 13-May-2018 Oleg Keri <ezhi99@gmail.com>

platform/x86: ideapad-laptop: Add fn-lock setting

Some of latest Lenovo ideapad laptops do not have UEFI/BIOS setting for
switching fn-lock mode. This commit adds related acpi calls to ideapad
platform driver. However setting is available via sysfs.

Signed-off-by: Oleg Keri <ezhi99@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 7caf0c1e 14-May-2018 Takashi Iwai <tiwai@suse.de>

platform/x86: ideapad-laptop: Add MIIX 720-12IKB to no_hw_rfkill

Yet another Lenovo model to be added to the no_hw_rfkill blacklist:
ideapad MIIX 720-12IKB. Otherwise it's always hard-blocked.

Reported-by: Robin Roevens <robin.roevens1@pandora.be>
Bugzilla: https://bugzilla.opensuse.org/show_bug.cgi?id=1093035
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# ed5b9ba7 11-Feb-2018 Aaron Ma <aaron.ma@canonical.com>

platform/x86: ideapad-laptop: Increase timeout to wait for EC answer

Lenovo E41-20 needs more time than 100ms to read VPC,
the funtion keys always failed responding.
Increase timeout to get the value from VPC, then
the funtion keys like mic mute key work well.

Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 334c4efd 22-Jan-2018 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

platform/x86: ideapad-laptop: Re-use DEFINE_SHOW_ATTRIBUTE() macro

...instead of open coding file operations followed by custom ->open()
callbacks per each attribute.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 28d71ae9 07-Jan-2018 Olle Liljenzin <olle@liljenzin.se>

platform/x86: ideapad-laptop: Add Y720-15IKB to no_hw_rfkill

Lenovo Legion Y720-15IKB is another Lenovo model without a
hw rfkill switch, resulting in wifi always reported as hard
blocked.

Add the model to the list of models without rfkill switch.

Signed-off-by: Olle Liljenzin <olle@liljenzin.se>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# ae7c8cba 02-Dec-2017 Jiaxun Yang <jiaxun.yang@flygoat.com>

platform/x86: ideapad-laptop: add lenovo RESCUER R720-15IKBN to no_hw_rfkill_list

This model does not have a hardware rfkill switch, add it to the
no_hw_rfkill_list to prevent the radio always being blocked.

Reported-by: Roger Jargoyhen <rjargoyhen@gmail.com>
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>


# f1395edb 02-Dec-2017 Jiaxun Yang <jiaxun.yang@flygoat.com>

platform/x86: ideapad-laptop: Use __func__ instead of write_ec_cmd in pr_err

Address the following checkpatch warning by using __func__ instead:
WARNING: Prefer using '"%s...", __func__' to using 'write_ec_cmd',
this function's name, in a string

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>


# ba3a3387 02-Dec-2017 Jiaxun Yang <jiaxun.yang@flygoat.com>

platform/x86: ideapad-laptop: Remove unnecessary else

Address the following checkpatch warning by removing unnecessary else
blocks:
WARNING: else is not generally useful after a break or return

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>


# b231669c 24-Oct-2017 Philipp Hug <philipp@hug.cx>

platform/x86: ideapad-laptop: Add Lenovo Yoga 920-13IKB to no_hw_rfkill dmi list

The Lenovo Yoga 920-13IKB does not have a hw rfkill switch, and trying
to read the hw rfkill switch through the ideapad module causes it to
always report as blocked.

This commit adds the Lenovo Yoga 920-13IKB to the no_hw_rfkill dmi list,
fixing the WiFI breakage.

Signed-off-by: Philipp Hug <philipp@hug.cx>
Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>


# ade50296 14-Aug-2017 Hao Wei Tee <angelsl@in04.sg>

platform/x86: ideapad-laptop: Expose conservation mode switch

This exposes the battery conservation mode present on some (?) IdeaPads.
The mode is set by calling ACPI method SBMC with argument 3 (on) or
5 (off). Status is reported in bit 5 of the return value of ACPI method
GBMD.

Signed-off-by: Hao Wei Tee <angelsl@in04.sg>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 5e8f42aa 04-Jul-2017 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

platform/x86: ideapad-laptop: Fix indentation in DMI table

There are couple of places where 8 spaces are used instead of tabs.
Replace former by latter. No functional change intended.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 710c059c 04-Jul-2017 Yang Jiaxun <yjx@flygoat.com>

platform/x86: ideapad-laptop: Add several models to no_hw_rfkill

Some Lenovo ideapad models do not have hardware rfkill switches, but
trying to read the rfkill switches through the ideapad-laptop module.
It caused to always reported blocking breaking wifi.

Fix it by adding those models to no_hw_rfkill_list.

Signed-off-by: Yang Jiaxun <yjx@flygoat.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 0df4b805 01-Jul-2017 Sven Eckelmann <sven@narfation.org>

platform/x86: ideapad-laptop: Add IdeaPad V510-15IKB to no_hw_rfkill

Like other Lenovo models the IdeaPad V510-15IKB does not have an hw
rfkill switch. This results in hard-blocked radios after boot, resulting
in always blocked radios rendering them unusable.

Add the IdeaPad V510-15IKB to the no_hw_rfkill DMI list and allows using
the built-in radios.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# b2f2fe20 18-Jun-2017 Olle Liljenzin <olle@liljenzin.se>

platform/x86: ideapad-laptop: Add Y720-15IKBN to no_hw_rfkill

Lenovo Legion Y720-15IKBN is yet another Lenovo model that does not
have an hw rfkill switch, resulting in wifi always reported as hard
blocked.

Add the model to the list of models without rfkill switch.

Signed-off-by: Olle Liljenzin <olle@liljenzin.se>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 5d9f40b5 18-Jun-2017 Olle Liljenzin <olle@liljenzin.se>

platform/x86: ideapad-laptop: Add Y520-15IKBN to no_hw_rfkill

Lenovo Legion Y520-15IKBN is yet another Lenovo model that does not
have an hw rfkill switch, resulting in wifi always reported as hard
blocked.

Add the model to the list of models without rfkill switch.

Signed-off-by: Olle Liljenzin <olle@liljenzin.se>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 3d59dfcd 09-Jun-2017 Bhumika Goyal <bhumirks@gmail.com>

platform/x86: ideapad-laptop: constify rfkill_ops structure

Add const to rfkill_ops structure as it is only passed as an argument
to the functions rfkill_alloc. This argument is of type const,
so annotate the structure with const.

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 3cfd956b 22-May-2017 Hao Wei Tee <angelsl@angelsl.xyz>

platform/x86: ideapad-laptop: Squelch ACPI event 1

Don't simply throw this to userspace via the sparse_keymap (which does not
have a mapping for scancode 1), as this causes KEY_UNKNOWN to be emitted,
which is a nuisance and of no use at all (it is not the right way to expose
this ACPI event to userspace, anyway, and the original intention of the commit
which added this (cfee5d63767b2e7997c1f36420d008abbe61565c) was only to suppress
an unhandled event log message).

Signed-off-by: Hao Wei Tee <angelsl@angelsl.xyz>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 46936fd6 22-May-2017 Arnd Bergmann <arnd@arndb.de>

platform/x86: ideapad-laptop: hide unused 'touchpad_store'

A readonly sysfs property must not have a 'store' function:

drivers/platform/x86/ideapad-laptop.c:438:16: error: 'touchpad_store' defined but not used [-Werror=unused-function]

We can either comment it out or remove the function entirely,
without a good reason one or or another I picked the second option.

Fixes: 7f363145992c ("platform/x86: ideapad-laptop: Switch touchpad attribute to be RO")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 7f363145 07-May-2017 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

platform/x86: ideapad-laptop: Switch touchpad attribute to be RO

For now let's restrict touchpad attribute to be read only.
We might revisit this in the future though.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 36ac0d43 17-Feb-2017 Ritesh Raj Sarraf <rrs@debian.org>

platform/x86: ideapad-laptop: Add sysfs interface for touchpad state

Lenovo Yoga (many variants: Yoga, Yoga2 Pro, Yoga2 13, Yoga3 Pro, Yoga 3
14, etc) has multiple modles that are a hybrid laptop, working in laptop
mode as well as tablet mode.

Currently, there is no easy interface to determine the touchpad status,
which in case of the Yoga family of machines, can also be useful to
assume tablet mode status.

Note: The ideapad-laptop driver does not provide a SW_TABLET_MODE either.

For a detailed discussion on why we want either of the interfaces,
please see:
https://bugs.launchpad.net/onboard/+bug/1366421/comments/43

This patch adds a sysfs interface for read/write access under:
/sys/bus/platform/devices/VPC2004\:00/touchpad_mode

Signed-off-by: Ritesh Raj Sarraf <rrs@debian.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# ccc7179f 21-Feb-2017 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

platform/x86: ideapad-laptop: Add IdeaPad V310-15ISK to no_hw_rfkill

Like other Lenovo models the IdeaPad V310-15ISK does not have an hw
rfkill switch. This results in hard-blocked radios after boot, resulting
in always blocked radios rendering them unusable.

Add the IdeaPad V310-15ISK to the no_hw_rfkill DMI list and allows using
the built-in radios.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# c973d4b5 09-Mar-2017 Michał Kępień <kernel@kempniu.pl>

platform/x86: ideapad-laptop: remove sparse_keymap_free() calls

As sparse_keymap_setup() now uses a managed memory allocation for the
keymap copy it creates, the latter is freed automatically. Remove all
calls to sparse_keymap_free().

Signed-off-by: Michał Kępień <kernel@kempniu.pl>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 1f3bc53d 21-Feb-2017 Sven Rebhan <sven.rebhan@gmail.com>

platform/x86: ideapad-laptop: Add IdeaPad 310-15IKB to no_hw_rfkill

Like other Lenovo models the IdeaPad 310-15IKB does not have an hw rfkill
switch. This results in hard-blocked radios after boot, resulting in
always blocked radios rendering them unusable.

Add the IdeaPad 310-15IKB to the no_hw_rfkill DMI list and allows using
the built-in radios.

Signed-off-by: Sven Rebhan <Sven.Rebhan@googlemail.com>
[andy: massaged commit message]
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# cfee5d63 22-Jan-2017 Zach Ploskey <zach@ploskey.com>

platform/x86: ideapad-laptop: handle ACPI event 1

On Ideapad laptops, ACPI event 1 is currently not handled. Many models
log "ideapad_laptop: Unknown event: 1" every 20 seconds or so while
running on battery power. Some convertible laptops receive this event
when switching in and out of tablet mode.

This adds and additional case for event 1 in ideapad_acpi_notify to call
ideapad_input_report(priv, vpc_bit), so that the event is reported to
userspace and we avoid unnecessary logging.

Fixes bug #107481 (https://bugzilla.kernel.org/show_bug.cgi?id=107481)
Fixes bug #65751 (https://bugzilla.kernel.org/show_bug.cgi?id=65751)

Signed-off-by: Zach Ploskey <zach@ploskey.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# e2970468 06-Dec-2016 velemas <velemas@gmail.com>

platform/x86: ideapad-laptop: Add Y700 15-ACZ to no_hw_rfkill DMI list

Like other Y700 models Lenovo Y700 15-ACZ does not have a physical rfkill switch.
ideapad-laptop wrongly reports all radios as blocked by hardware which causes
wireless network connections to fail.

Add this model without an rfkill switch to the no_hw_rfkill list.

Signed-off-by: Artiom Vaskov <velemas@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 446647d4 19-Oct-2016 Mika Westerberg <mika.westerberg@linux.intel.com>

ideapad-laptop: Add another DMI entry for Yoga 900

This particular laptop has its motherboard replaced and after that, even
with the latest BIOS, some DMI identification strings have become
"INVALID". This includes DMI_PRODUCT_VERSION which results Wifi being
blocked.

It seems that DMI_BOARD_NAME is still valid so use that as an
alternative for Lenovo Yoga 900.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 40c30bbf 11-Oct-2016 Brian Masney <masneyb@onstation.org>

platform/x86: ideapad-laptop: Add Lenovo Yoga 910-13IKB to no_hw_rfkill dmi list

The Lenovo Yoga 910-13IKB does not have a hw rfkill switch, and trying
to read the hw rfkill switch through the ideapad module causes it to
always report as blocked.

This commit adds the Lenovo Yoga 910-13IKB to the no_hw_rfkill dmi list,
fixing the WiFI breakage.

Signed-off-by: Brian Masney <masneyb@onstation.org>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 48f67d62 05-Jun-2016 Alex Hung <alex.hung@canonical.com>

ideapad_laptop: Add an event for mic mute hotkey

Newer ideapads support a new mic hotkey implemented via an ACPI
interface. This patch converts the mic mute event to a keycode
KEY_MICMUTE.

Signed-off-by: Alex Hung <alex.hung@canonical.com>
Acked-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 2d98e0b9 09-May-2016 Arnd Bergmann <arnd@arndb.de>

ideapad-laptop: add a new WMI string for ESC key

My patch to the ideapad-laptop driver to get the ESC key working on the
Yoga 1170 (Yoga 3) failed to do the same for the following model, the
Lenovo Yoga 700.

Denis Gordienko managed to get it working by adding another GUID for the
new WMI interface. I have adapted his patch to normal coding style
and simplified it a bit for inclusion, but this patch is currently
untested.

Link: https://forums.lenovo.com/t5/Lenovo-Yoga-Series-Notebooks/YOGA-3-14-How-to-reclaim-my-Esc-key-and-permanently-disable/m-p/3317499
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Tested-by: Denis Gordienko <denis.gordienko.mail@gmail.com>
[dvhart: Whitespace cleanup, static const char *const array declaration]
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 4db9675d 26-Feb-2016 John Dahlstrom <jodarom@SDF.ORG>

ideapad-laptop: Add ideapad Y700 (15) to the no_hw_rfkill DMI list

Some Lenovo ideapad models lack a physical rfkill switch.
On Lenovo models ideapad Y700 Touch-15ISK and ideapad Y700-15ISK,
ideapad-laptop would wrongly report all radios as blocked by
hardware which caused wireless network connections to fail.

Add these models without an rfkill switch to the no_hw_rfkill list.

Signed-off-by: John Dahlstrom <jodarom@sdf.org>
Cc: <stable@vger.kernel.org> # 3.17.x-: 4fa9dab: ideapad_laptop: Lenovo G50-30 fix rfkill reports wireless blocked
Cc: <stable@vger.kernel.org>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 6b31de3e 24-Jan-2016 Josh Boyer <jwboyer@fedoraproject.org>

ideapad-laptop: Add Lenovo Yoga 700 to no_hw_rfkill dmi list

Like the Yoga 900 models the Lenovo Yoga 700 does not have a
hw rfkill switch, and trying to read the hw rfkill switch through the
ideapad module causes it to always reported blocking breaking wifi.

This commit adds the Lenovo Yoga 700 to the no_hw_rfkill dmi list, fixing
the wifi breakage.

BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1295272
Tested-by: <dinyar.rabady+spam@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Josh Boyer <jwboyer@fedoraproject.org>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# edde316a 09-Dec-2015 Josh Boyer <jwboyer@fedoraproject.org>

ideapad-laptop: Add Lenovo ideapad Y700-17ISK to no_hw_rfkill dmi list

One of the newest ideapad models also lacks a physical hw rfkill switch,
and trying to read the hw rfkill switch through the ideapad module
causes it to always reported blocking breaking wifi.

Fix it by adding this model to the DMI list.

BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1286293
Cc: stable@vger.kernel.org
Signed-off-by: Josh Boyer <jwboyer@fedoraproject.org>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# f71c882d 09-Nov-2015 Hans de Goede <hdegoede@redhat.com>

ideapad-laptop: Add Lenovo Yoga 900 to no_hw_rfkill dmi list

Like some of the other Yoga models the Lenovo Yoga 900 does not have a
hw rfkill switch, and trying to read the hw rfkill switch through the
ideapad module causes it to always reported blocking breaking wifi.

This commit adds the Lenovo Yoga 900 to the no_hw_rfkill dmi list, fixing
the wifi breakage.

BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1275490
Cc: stable@vger.kernel.org
Reported-and-tested-by: Kevin Fenzi <kevin@scrye.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# c789fffc 06-Nov-2015 Arnd Bergmann <arnd@arndb.de>

ideapad-laptop: include Yoga 3 1170 in add rfkill whitelist

This changes the entry to the whitelist of machines that do not have
a physical rfkill switch. Unfortunately, the Yoga 3 generation seems
to use upper-case letters for the YOGA 3 Pro-1370, while it uses normal
capitalization for its Yoga 3 1170 and 1470 siblings.

In order to catch all variants of the Yoga 3, I'm changing both
the entry for the 1470 (using "Yoga" as the name) and the entry for
the Pro 1370 (using all-caps "YOGA") to not match the exact model number
but only the generation. This way, the 1170 and 1470 models share one
entry, but if the firmware changes from one format to the other, it will
still work.

The second entry for Yoga 2 Pro that was recently added for some
reason ended up not being added in alphanumeric order, and I'm
moving the Yoga 3 1470 entry down while making the change, so they
are sorted more logically.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 74caab99 06-Nov-2015 Arnd Bergmann <arnd@arndb.de>

ideapad-laptop: add support for Yoga 3 ESC key

The ideapad-laptop handles most special keys on various Lenovo Laptops
including the Yoga line. Unfortunately, the Yoga 3 11/13/14 models have
one important exception, which is the Fn-ESC combination.

On other Lenovo Laptops, this is FnLock, which switches the function keys
between the primary (Mute, Vol down, Vol up, ...) and the secondary (F1,
F2, F3, ...) behavior. On the new machines, FnLock is only available
through BIOS setup (possibly through a yet-to-be-implemented feature
in this driver) but not through Fn-ESC, but instead the ESC key itself
switched between ESC and a "Paper Display" app for Windows.

Unfortunately, that means that you can never have both ESC *and* the
function keys working at the same time without needing to press Fn on
one of them.
As pointed out in the official Lenovo Forum by dozens of users, this
makes the machine rather useless for any serious work [1].

I have now studied the ACPI DSDT one more time and found the event
that is generated for the ESC key. Unlike all other key events on this
machine, it is actually a WMI, while the other ones are read from the
embedded controller.

I am now installing a WMI notifier that uses the event number from the
WMI subsystem as the scancode. The only event number generated here is
'128', and that fits in nicely with the two existing ranges of scancodes
used by the EC: 0-15 for the 16-bit VPCCMD_R_VPC register, 16-17 for
the VPCCMD_R_NOVO register and 64-67 for VPCCMD_R_SPECIAL_BUTTONS.

The only sane way to handle this button (in absence of the Windows Paper
Display driver) seems to be to have it emit KEY_ESC, so that is what
I use as the default. Should any user ever want to overwrite the default,
they can install their own keymap.

To ensure that we can still build the driver without adding a CONFIG_WMI
dependency, all new code is enclosed in #ifdef.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

[1] https://forums.lenovo.com/t5/Lenovo-Yoga-Series-Notebooks/YOGA-3-14-How-to-reclaim-my-Esc-key-and-permanently-disable/td-p/2070816
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 6d212b8a 18-Jul-2015 Sebastian Krzyszkowiak <dos@dosowisko.net>

ideapad-laptop: add alternative representation for Yoga 2 to DMI table

There is at least one (mine) Yoga 2 Pro in existence that has incorrect
product version stored in DMI (reading as "INVALID"), causing it to not be
recognized as Yoga 2 by ideapad-laptop module, which in turn causes
non-existent hardware rfkills to be always reported as blocked.

This change adds a second check by board name, which is "Yoga2".
Looks like it also happens to be "INVALID" on some other Yoga 2 machines
where product version is correct instead, so the original check is left
intact to catch both cases.

Signed-off-by: Sebastian Krzyszkowiak <dos@dosowisko.net>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# fa92a31b 10-Aug-2015 Hans de Goede <hdegoede@redhat.com>

ideapad-laptop: Add Lenovo Yoga 3 14 to no_hw_rfkill dmi list

Like some of the other Yoga models the Lenovo Yoga 3 14 does not have a
hw rfkill switch, and trying to read the hw rfkill switch through the
ideapad module causes it to always reported blocking breaking wifi.

This commit adds the Lenovo Yoga 3 14 to the no_hw_rfkill dmi list, fixing
the wifi breakage.

BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1239050
Cc: stable@vger.kernel.org
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 26bff5f0 16-Jun-2015 Hans de Goede <hdegoede@redhat.com>

ideapad-laptop: Port to new backlight interface selection API

Port the backlight selection logic to the new backlight interface
selection API.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 4b200b46 13-Jun-2015 Arnd Bergmann <arnd@arndb.de>

ideapad: fix software rfkill setting

This fixes a several year old regression that I found while trying
to get the Yoga 3 11 to work. The ideapad_rfk_set function is meant
to send a command to the embedded controller through ACPI, but
as of c1f73658ed, it sends the index of the rfkill device instead
of the command, and ignores the opcode field.

This changes it back to the original behavior, which indeed
flips the rfkill state as seen in the debugfs interface.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: c1f73658ed ("ideapad: pass ideapad_priv as argument (part 2)")
Cc: stable@vger.kernel.org # v2.6.38+
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 4fa9dabc 18-Jan-2015 Dmitry Tunin <hanipouspilot@gmail.com>

ideapad_laptop: Lenovo G50-30 fix rfkill reports wireless blocked

Lenovo G30-50 does not have a hardware wireless switch and wireless
is always blocked.

BugLink: https://bugs.launchpad.net/bugs/1397021
Signed-off-by: Dmitry Tunin <hanipouspilot@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Philippe Coval <philippe.coval@open.eurogiciel.org>
[dvhart@linux.intel.com: Reordered dmi id per Phillippe's later version]
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 9b071a43 02-May-2015 Philippe Coval <philippe.coval@open.eurogiciel.org>

ideapad_laptop: Add Lenovo G40-30 to devices without radio switch

Lenovo G40-30 does not provide any physical radio switch to user.
Therefore disable the rfkill switch identically to the Yoga 2 approach.
(Note for later, models ids are sorted alphabetically).

Benefit is to make wireless available again without unloading module.

It was tested successfully on 4.1.0-rc1 base with this model:
(LENOVO_MT_80FY_BU_idea_FM_Lenovo G40-30).

BugLink: https://bugs.launchpad.net/ideapad-laptop/+bug/1450946
Cc: platform-driver-x86@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Philippe Coval <rzr@gna.org>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 00981810 24-Nov-2014 Markus Elfring <elfring@users.sourceforge.net>

platform: x86: Deletion of checks before backlight_device_unregister()

The backlight_device_unregister() function tests whether its argument is NULL
and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
For msi-wmi.c:
Acked-by: Anisse Astier <anisse@astier.eu>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 725c7f61 26-Oct-2014 Stephan Mueller <smueller@chronox.de>

quirk for Lenovo Yoga 3: no rfkill switch

The Yoga 3 does not contain any physical rfkill switch. Therefore
disable the rfkill switch identically to the Yoga 2 approach.

Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 3493f414 20-Oct-2014 Wolfram Sang <wsa@kernel.org>

platform: x86: drop owner assignment from platform_drivers

A platform_driver does not need to set an owner, it will be populated by the
driver core.

Signed-off-by: Wolfram Sang <wsa@the-dreams.de>


# b3d94d70 28-Aug-2014 Mathias Krause <minipli@googlemail.com>

ideapad-laptop: Constify DMI table for real!

This is a follow-up patch to commit 49458e83082d ("ideapad-laptop:
Constify DMI table and other r/o variables") to do what its commit
message says. The actual commit differs from the patch posted at
https://www.mail-archive.com/platform-driver-x86@vger.kernel.org/msg05340.html
significantly, probably due to a bad merge conflict resolution. Fix up
the mess and constify the DMI table for real and fix the bogus
double-const of ideapad_rfk_data[].

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
Cc: Matthew Garrett <matthew.garrett@nebula.com>
Cc: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 3b264d27 24-Aug-2014 Hans de Goede <hdegoede@redhat.com>

Revert "ideapad-laptop: Disable touchpad interface on Yoga models"

I've received a bug report from a user that the touchpad control part
of the ideapad-laptop ACPI interface does work for him on his
"Lenovo Yoga 2 13", and that this patch causes a regression for him.

Since it did not work for me when I had a "Lenovo Yoga 2 11" in my own
hands (loaned from a friend). It seems that this is a bit of hit and miss.

Since the result of having a false positive here is worse, then the minor
annoyance of a false touchpad disabled messages being shown after suspend /
resume on models (or is it firmware versions?) where the interface does not
work, simply revert the patch.

This reverts commit f79a901331a823ae370584b15cd39dd110b95a0a.

Reported-by: GOESSEL Guillaume <g_goessel@outlook.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>


# 49458e83 16-Jul-2014 Mathias Krause <minipli@googlemail.com>

ideapad-laptop: Constify DMI table and other r/o variables

Constify the rfkill_blacklist[] DMI table, the ideapad_rfk_data[] table
and the ideapad_attribute_group attribute group. There's no need to have
them writeable during runtime.

Signed-off-by: Mathias Krause <minipli@googlemail.com>
Cc: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>


# f79a9013 17-Jul-2014 Hans de Goede <hdegoede@redhat.com>

ideapad-laptop: Disable touchpad interface on Yoga models

Yoga models don't offer touchpad ctrl through the ideapad interface, causing
ideapad_sync_touchpad_state to send wrong touchpad enable/disable events.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>


# ce363c2b 23-Jun-2014 Hans de Goede <hdegoede@redhat.com>

ideapad-laptop: Change Lenovo Yoga 2 series rfkill handling

It seems that the same problems which lead to adding an rfkill blacklist and
putting the Lenovo Yoga 2 11 on it are also present on the Lenovo Yoga 2 13
and Lenovo Yoga 2 Pro too:
https://bugzilla.redhat.com/show_bug.cgi?id=1021036
https://forums.lenovo.com/t5/Linux-Discussion/Yoga-2-13-not-Pro-Linux-Warning/m-p/1517612

Testing has shown that the firmware rfkill settings are persistent over
reboots. So blacklisting the driver is not good enough, if the wifi is blocked
at the firmware level the wifi needs to be explictly unblocked through the
ideapad-laptop interface.

And at least on the Lenovo Yoga 2 13 the VPCCMD_RF register which on devices
with hardware kill switch reports the hardware switch state, needs to be
explictly set to 1 (radio enabled / not blocked).

So this patch does 3 things to get proper rfkill handling on these models:

1) Instead of blacklisting the rfkill functionality, which means that people
with a firmware blocked wifi get stuck in that situation, ignore the value
reported by the not present hardware rfkill switch, as this is what is causing
ideapad-laptop to wrongly report all radios as hardware blocks. But do register
the rfkill interfaces so that the user can soft [un]block them.

2) On models without a hardware rfkill switch, explictly set VPCCMD_RF to 1

3) Drop the " 11" postfix from the dmi match string, as the entire Yoga 2
series is affected.

Yoga 2 11:
Reported-and-tested-by: Vincent Gerris <vgerris@gmail.com>

Yoga 2 13:
Tested-by: madls05 <http://ubuntuforums.org/showthread.php?t=2215044>

Yoga 2 Pro:
Reported-and-tested-by: Peter F. Patel-Schneider <pfpschneider@gmail.com>

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>


# b3facd7b 09-Jun-2014 Himangi Saraogi <himangi774@gmail.com>

ideapad_laptop: Introduce the use of the managed version of kzalloc

This patch moves data allocated using kzalloc to managed data allocated
using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
functions. The label sysfs_failed is removed as it is no longer
required. Also, linux/device.h is added to make sure the devm_*()
routine declarations are unambiguously available.

The following Coccinelle semantic patch was used for making the change:

@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kfree(e);
...+>
}

@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
<...
- kfree(e);
...>
}

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>


# 85093f79 13-May-2014 Hans de Goede <hdegoede@redhat.com>

ideapad-laptop: Blacklist rfkill control on the Lenovo Yoga 2 11

The Lenovo Yoga 2 11 always reports everything as blocked, causing userspace
to not even try to use the wlan / bluetooth even though they work fine.

Note this patch also removes the "else priv->rfk[i] = NULL;" bit of the
rfkill initialization, it is not necessary as the priv struct is allocated
with kzalloc.

Reported-and-tested-by: Vincent Gerris <vgerris@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>


# 8b48463f 02-Dec-2013 Lv Zheng <lv.zheng@intel.com>

ACPI: Clean up inclusions of ACPI header files

Replace direct inclusions of <acpi/acpi.h>, <acpi/acpi_bus.h> and
<acpi/acpi_drivers.h>, which are incorrect, with <linux/acpi.h>
inclusions and remove some inclusions of those files that aren't
necessary.

First of all, <acpi/acpi.h>, <acpi/acpi_bus.h> and <acpi/acpi_drivers.h>
should not be included directly from any files that are built for
CONFIG_ACPI unset, because that generally leads to build warnings about
undefined symbols in !CONFIG_ACPI builds. For CONFIG_ACPI set,
<linux/acpi.h> includes those files and for CONFIG_ACPI unset it
provides stub ACPI symbols to be used in that case.

Second, there are ordering dependencies between those files that always
have to be met. Namely, it is required that <acpi/acpi_bus.h> be included
prior to <acpi/acpi_drivers.h> so that the acpi_pci_root declarations the
latter depends on are always there. And <acpi/acpi.h> which provides
basic ACPICA type declarations should always be included prior to any other
ACPI headers in CONFIG_ACPI builds. That also is taken care of including
<linux/acpi.h> as appropriate.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Matthew Garrett <mjg59@srcf.ucam.org>
Cc: Tony Luck <tony.luck@intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com> (drivers/pci stuff)
Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> (Xen stuff)
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# b222cca6 23-Oct-2013 Joe Perches <joe@perches.com>

platform:x86: Remove OOM message after input_allocate_device

Emitting an OOM message isn't necessary after input_allocate_device
as there's a generic OOM and a dump_stack already done.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>


# b5c37b79 25-Sep-2013 Zhang Rui <rui.zhang@intel.com>

ideapad_laptop: convert ideapad device/driver to platform bus

This patch does two things,
1. enumerate the ideapad device node to platform bus.
2. convert the current driver from ACPI bus to platform bus.

Note, with this patch, the platform device node created by ACPI,
with the name VPC2004:00, is used as the parent device of
the input, backlight, rfkill sysfs class device.
Plus the ideapad_platform private sysfs attributes,
i.e. camera_power and fan_mode, are also moved to the new
platform device node.

The previous platform device node "ideapad" is removed.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
CC: Matthew Garrett <matthew.garrett@nebula.com>
CC: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 331e0ea2 25-Sep-2013 Zhang Rui <rui.zhang@intel.com>

ideapad_laptop: remove ideapad_handle and ideapad_priv

The current code use ideapad_handle and ideapad_priv to store
some information for the ideapad device.
But as they are global/static variables, the driver will be broken
if there are more than one ideapad ACPI device node on a platform.
Although this does not happen for now and may not happen in the future,
but still, this is a software bug.

Remove these two variables in this patch.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
CC: Matthew Garrett <matthew.garrett@nebula.com>
CC: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 75a11f11 25-Sep-2013 Zhang Rui <rui.zhang@intel.com>

ideapad_laptop: convert internal function calls to use ideapad_private as parameter

As struct ideapad_private has all the information needed for any operations,
convert ideapad_register_rfkill()/ideapad_unregister_rfkill() and
ideapad_sync_touchpad_state() to use struct ideapad_private as the parameter,
to be consistent with the others.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
CC: Matthew Garrett <matthew.garrett@nebula.com>
CC: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 469f6434 25-Sep-2013 Zhang Rui <rui.zhang@intel.com>

ideapad_laptop: introduce struct acpi_device pointer to ideapad_private structure

Introduce struct acpi_device pointer to ideapad_private structure.
At the same time, replace all adevice with adev to be short and consistent.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
CC: Matthew Garrett <matthew.garrett@nebula.com>
CC: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 11fa8da5 25-Sep-2013 Zhang Rui <rui.zhang@intel.com>

ideapad_laptop: introduce #ifdef CONFIG_PM_SLEEP for PM specific code

ideapad_acpi_resume() and ideapad_pm is meaningful
only if CONFIG_PM_SLEEP is set.
Thus introduce #ifdef for this piece of code.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
CC: Matthew Garrett <matthew.garrett@nebula.com>
CC: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# a1ec56ed 19-Mar-2013 Maxim Mikityanskiy <maxtram95@gmail.com>

Add support for fan button on Ideapad Z580

The patch adds support for fan control button on Ideapad Z580. This is
the same button as on Z570, but it raises different bit in
VPCCMD_R_SPECIAL_BUTTONS. Also add message to dmesg when unknown button
press detected, it will help adding support for new special buttons.

Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>
Tested-by: Ivan Vojtko <nekroman.sk@gmail.com>
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>


# 51fac838 23-Jan-2013 Rafael J. Wysocki <rafael.j.wysocki@intel.com>

ACPI: Remove useless type argument of driver .remove() operation

The second argument of ACPI driver .remove() operation is only used
by the ACPI processor driver and the value passed to that driver
through it is always available from the given struct acpi_device
object's removal_type field. For this reason, the second ACPI driver
.remove() argument is in fact useless, so drop it.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Jiang Liu <jiang.liu@huawei.com>
Acked-by: Toshi Kani <toshi.kani@hp.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>


# b859f159 21-Dec-2012 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Drivers: platform: x86: remove __dev* attributes.

CONFIG_HOTPLUG is going away as an option. As a result, the __dev*
markings need to be removed.

This change removes the use of __devinit, __devexit_p, __devinitdata,
__devinitconst, and __devexit from these drivers.

Based on patches originally written by Bill Pemberton, but redone by me
in order to handle some of the coding style issues better, by hand.

Cc: Bill Pemberton <wfp5p@virginia.edu>
Cc: Joey Lee <jlee@novell.com>
Cc: Matthew Garrett <mjg@redhat.com>
Cc: Peter Feuerer <peter@piie.net>
Cc: Corentin Chary <corentin.chary@gmail.com>
Cc: Cezary Jackiewicz <cezary.jackiewicz@gmail.com>
Cc: Robert Gerlach <khnz@gmx.de>
Cc: Ike Panhc <ike.pan@canonical.com>
Cc: Henrique de Moraes Holschuh <ibm-acpi@hmh.eng.br>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 26953f78 07-Sep-2012 Mika Westerberg <mika.westerberg@linux.intel.com>

ideapad: convert to module_acpi_driver()

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Len Brown <len.brown@intel.com>


# 0c7bbeb9 06-Jul-2012 Maxim Mikityanskiy <maxtram95@gmail.com>

ideapad: add Lenovo IdeaPad Z570 support (part 3)

The patch adds support for Lenovo IdeaPad Z570 laptop. It makes all special
keys working, adds possibility to control fan like Windows does, controls
Touchpad Disabled LED, toggles touchpad state via keyboard controller and
corrects touchpad behavior on resume from suspend. It is new, modified
version of patch. Now it does not depend on psmouse and does not need patching
of input subsystem.

Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>

This is the part 3 for fan control

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 07a4a4fc 06-Jul-2012 Maxim Mikityanskiy <maxtram95@gmail.com>

ideapad: add Lenovo IdeaPad Z570 support (part 2)

The patch adds support for Lenovo IdeaPad Z570 laptop. It makes all special
keys working, adds possibility to control fan like Windows does, controls
Touchpad Disabled LED, toggles touchpad state via keyboard controller and
corrects touchpad behavior on resume from suspend. It is new, modified
version of patch. Now it does not depend on psmouse and does not need patching
of input subsystem.

Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>

This is part 2 for touchpad toggle

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 296f9fe0 06-Jul-2012 Maxim Mikityanskiy <maxtram95@gmail.com>

ideapad: add Lenovo IdeaPad Z570 support (part 1)

The patch adds support for Lenovo IdeaPad Z570 laptop. It makes all special
keys working, adds possibility to control fan like Windows does, controls
Touchpad Disabled LED, toggles touchpad state via keyboard controller and
corrects touchpad behavior on resume from suspend. It is new, modified
version of patch. Now it does not depend on psmouse and does not need patching
of input subsystem.

Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>

This is part 1 for special button handling.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 57f9616b 12-Jun-2012 Dan Carpenter <dan.carpenter@oracle.com>

ideapad: uninitialized data in ideapad_acpi_add()

We only initialize the high bits of "cfg". It probably doesn't cause
a problem given that this is platform specific code and doesn't have to
worry about endianness etc. But it's sort of messy.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 20a769c1 03-May-2012 Ike Panhc <ike.pan@canonical.com>

ideapad: generate valid key event only

Otherwise will generate KEY_UNKNOWN on un-listed vpc event,
which means nothing and is hard for user to report the detail
of the event.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# a5c3892f 03-May-2012 Ike Panhc <ike.pan@canonical.com>

ideapad: remove unused define and fix a typo

After review the current ideapad-laptop, found an unused define and
a typo.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 587a1f16 23-Jul-2011 Al Viro <viro@zeniv.linux.org.uk>

switch ->is_visible() to returning umode_t

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>


# 349d594b 05-Sep-2011 Ike Panhc <ike.pan@canonical.com>

ideapad: remove sysfs node for cfg

Replaced by the one in debugfs.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 773e3206 05-Sep-2011 Ike Panhc <ike.pan@canonical.com>

ideapad: add debugfs support

Add two nodes in debugfs which shows cfg value and its meaning,
and status info read from VPC2004.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# f43d9ec0 05-Sep-2011 Ike Panhc <ike.pan@canonical.com>

ideapad: add event for Novo key

Novo key is the Lenovo define key on every ideapads, which has two
definition. Long press and short click. Driver will report
KEY_PROG1 on short click and KEY_PROG2 when long press.

On pre-install OS for ideapads there are application waiting for
the event and there is no such application for Linux yet, so I
think to report KEY_PROG is fine in anyway.

Also change the scancode from hex to decimal because they are
related to vpc bit in notify function which is in decimal.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 923de84a 05-Sep-2011 Ike Panhc <ike.pan@canonical.com>

ideapad: change parameter of ideapad_sync_rfk_state

This could save us a local variable.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 2be1dc21 05-Sep-2011 Ike Panhc <ike.pan@canonical.com>

ideapad: define vpc commands

Better then write hex number everywhere.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# d4afc775 23-Oct-2011 Rene Bollford <xsecute@googlemail.com>

[PATCH] ideapad: Check if acpi already handle backlight power to avoid a page fault

This patch avoid a page fault in the ideapad-laptop extras when
turning the backlight power on or off.

Signed-off-by: Rene Bolldorf <xsecute@googlemail.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 7451a55a 27-Jul-2011 Axel Lin <axel.lin@gmail.com>

platform-drivers-x86: ideapad-laptop: add missing ideapad_input_exit in ideapad_acpi_add error path

In the case of ideapad_backlight_init() failure,
we need to free the resources allocated by ideapad_input_init().

Aslo drop __devexit annotation for ideapad_input_exit() because
we also call it in ideapad_acpi_add() error path.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# a4ecbb8a 30-Jun-2011 Ike Panhc <ike.pan@canonical.com>

ideapad: add backlight driver

When acpi_backlight=vendor in cmdline or no backlight support in acpi video
device, ideapad-laptop will register backlight device and control brightness
and backlight power via the command in VPC2004.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# a84511f7 30-Jun-2011 Ike Panhc <ike.pan@canonical.com>

ideapad: let camera_power node invisiable if no camera

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 3371f481 30-Jun-2011 Ike Panhc <ike.pan@canonical.com>

ideapad: define cfg bits and create sysfs node for cfg

Create /sys/devices/platform/ideapad/cfg for showing cfg value.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 9ab23989 29-Mar-2011 Joe Perches <joe@perches.com>

ideapad-laptop: Add pr_fmt

Add pr_fmt to prefix logging messages.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 21651365 23-Feb-2011 Ike Panhc <ike.pan@canonical.com>

ideapad: read brightness setting on brightness key notify

BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=25922

On ideapad Y530, the brightness key notify will be blocked if the last notify
is not responsed by getting the brightness value. Read value when we get the
notify shall fix the problem and will not have any difference on other ideapads.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 883ae799 23-Feb-2011 Ike Panhc <ike.pan@canonical.com>

ideapad: read brightness setting on brightness key notify

BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=25922

On ideapad Y530, the brightness key notify will be blocked if the last notify
is not responsed by getting the brightness value. Read value when we get the
notify shall fix the problem and will not have any difference on other ideapads.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# c1f73658 13-Dec-2010 Ike Panhc <ike.pan@canonical.com>

ideapad: pass ideapad_priv as argument (part 2)

Passing ideapad_priv as argument and try not to using too much global variable.
This is part 2 for rfkill.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 8693ae84 13-Dec-2010 Ike Panhc <ike.pan@canonical.com>

ideapad: pass ideapad_priv as argument (part 1)

Passing ideapad_priv as argument and try not to using too much global variable.
This is part 1 for platform driver and input device.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# a4b5a279 13-Dec-2010 Ike Panhc <ike.pan@canonical.com>

ideapad: add markups, unify comments and return result when init

1. Add markups on init and exit functions
2. Unify the comments in the same style
3. Return result when module initial

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# f63409ae 13-Dec-2010 Ike Panhc <ike.pan@canonical.com>

ideapad: add hotkey support

Hotkey enabled by this patch:
Fn+F3: Video mode switch
Fn+F5: software rfkill for wifi

For some ideapad when push Fn+F3, hardware generates Super-P keys, those key
will not be enabled by this patch.

Thanks for Dave Hansen report the problem. If CONFIG_INPUT_SPARSEKMAP is not
set, when building, you will have error message:

ERROR: "sparse_keymap_setup" [drivers/platform/x86/ideapad-laptop.ko] undefined!
ERROR: "sparse_keymap_free" [drivers/platform/x86/ideapad-laptop.ko] undefined!
ERROR: "sparse_keymap_report_event" [drivers/platform/x86/ideapad-laptop.ko] undefined!

To select INPUT_SPARSEKMAP solve this issue.

Ref: http://lkml.org/lkml/2010/12/2/340

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# c9f718d0 13-Dec-2010 Ike Panhc <ike.pan@canonical.com>

ideapad: let camera power control entry under platform driver

The entry was at /sys/devices/LNXSYSTM:00/../VPC2004:00/camera_power
move to /sys/devices/platform/ideapad/camera_power

Add document about usage of ideapad node in sysfs.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 98ee6919 13-Dec-2010 Ike Panhc <ike.pan@canonical.com>

ideapad: add platform driver for ideapad

Create /sys/devices/platform/ideapad for nodes of ideapad landing.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# bfa97b7d 01-Oct-2010 Ike Panhc <ike.pan@canonical.com>

ideapad: Add param: no_bt_rfkill

Add new module parameter that force module not to register bluetooth rfkill.

There is report that saying using this bluetooth rfkill to enable/disable
bluetooth will let bluetooth device initial failed when enable on Lenovo
ideapad S12. Fortunately there is another rfkill registered by bluetooth
driver for S12 and user can shutdown the bluetooth by either bluetooth driver
or HW RF switch.

For dual OS user, it may have some trouble that using Linux after turning off
bluetooth with another OS if we do not register bluetooth rfkill at all. So
we will force bluetooth enable when no_bt_rfkill=1.

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Tested-by: Mario 'BitKoenig' Holbe <Mario.Holbe@TU-Ilmenau.DE>
Signed-off-by: Matthew Garrett <mjg@redhat.com>


# 57ac3b05 01-Oct-2010 Ike Panhc <ike.pan@canonical.com>

ideapad: Change the driver name to ideapad-laptop

Since the platform drivers doing more for laptops than just using specific
ACPI device. It will be good to change the name from *_acpi to *-laptop.

Reference: http://lkml.org/lkml/2010/8/14/154

Signed-off-by: Ike Panhc <ike.pan@canonical.com>
Acked-by: Len Brown <len.brown@intel.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>