History log of /linux-master/drivers/platform/x86/huawei-wmi.c
Revision Date Author Comments
# 2cee4d0c 14-Jan-2024 Heiner Kallweit <hkallweit1@gmail.com>

platform/x86: remove obsolete calls to ledtrig_audio_get

Since 64f67b5240db ("leds: trigger: audio: Add an activate callback to
ensure the initial brightness is set") the audio triggers have an
activate callback which sets the LED brightness as soon as the
(default) trigger is bound to the LED device. So we can remove the
call to ledtrig_audio_get.

Positive side effect: There's no code dependency to ledtrig-audio any
longer, what allows to remove some Kconfig dependencies.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/daef7331-dcb4-4b3a-802e-656629486b4c@gmail.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>


# c2173375 22-Jul-2023 Konstantin Shelekhin <k.shelekhin@ftml.net>

platform/x86: huawei-wmi: Silence ambient light sensor

Currently huawei-wmi causes a lot of spam in dmesg on my
Huawei MateBook X Pro 2022:

...
[36409.328463] input input9: Unknown key pressed, code: 0x02c1
[36411.335104] input input9: Unknown key pressed, code: 0x02c1
[36412.338674] input input9: Unknown key pressed, code: 0x02c1
[36414.848564] input input9: Unknown key pressed, code: 0x02c1
[36416.858706] input input9: Unknown key pressed, code: 0x02c1
...

Fix that by ignoring events generated by ambient light sensor.

This issue was reported on GitHub and resolved with the following merge
request:

https://github.com/aymanbagabas/Huawei-WMI/pull/70

I've contacted the mainter of this repo and he gave me the "go ahead" to
send this patch to the maling list.

Signed-off-by: Konstantin Shelekhin <k.shelekhin@ftml.net>
Link: https://lore.kernel.org/r/20230722155922.173856-1-k.shelekhin@ftml.net
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


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

platform/x86: huawei-wmi: 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-14-u.kleine-koenig@pengutronix.de
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# e57d58ee 05-Oct-2022 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: huawei-wmi: remove unnecessary member

The `huawei_wmi::idev` array is not actually used by the driver,
so remove it. The piece of code that - I believe - was supposed
to fill the array is flawed, it did not actually set any of the
values inside the array. This was most likely masked by the fact
that the input devices are devm managed and that the only function
that needs a reference to the input devices is
`huawei_wmi_input_notify()`, however, that does not access the
appropriate input device via the `huawei_wmi` object.

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


# 0b9a1dcd 05-Oct-2022 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: huawei-wmi: fix return value calculation

Previously, `huawei_wmi_input_setup()` returned the result of
logical or-ing the return values of two functions that return negative
errno-style error codes and one that returns `acpi_status`. If this
returned value was non-zero, then it was propagated from the platform
driver's probe function. That function should return a negative
errno-style error code, so the result of the logical or that
`huawei_wmi_input_setup()` returned was not appropriate.

Fix that by checking each function separately and returning the
error code unmodified.

Fixes: 1ac9abeb2e5b ("platform/x86: huawei-wmi: Move to platform driver")
Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20221005150032.173198-2-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# d6fef932 05-Oct-2022 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: huawei-wmi: do not hard-code sizes

Use `sizeof()` and `ARRAY_SIZE()` instead of
hard-coding buffer sizes and indices.

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


# 878a82c2 27-Sep-2022 Armin Wolf <W_Armin@gmx.de>

ACPI: battery: Pass battery hook pointer to hook callbacks

Right now, is impossible for battery hook callbacks
to access instance-specific data, forcing most drivers
to provide some sort of global state. This however is
difficult for drivers which can be instantiated multiple
times and/or are hotplug-capable.

Pass a pointer to the battery hook to those callbacks
for usage with container_of().

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/20220927204521.601887-2-W_Armin@gmx.de
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 8d05fc03 30-Sep-2022 Barnabás Pőcze <pobrn@protonmail.com>

platform/x86: use PLATFORM_DEVID_NONE instead of -1

Use the `PLATFORM_DEVID_NONE` constant instead of
hard-coding -1 when creating a platform device.

No functional changes are intended.

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


# c91a5b1c 02-Mar-2022 Jia-Ju Bai <baijiaju1990@gmail.com>

platform/x86: huawei-wmi: check the return value of device_create_file()

The function device_create_file() in huawei_wmi_battery_add() can fail,
so its return value should be checked.

Fixes: 355a070b09ab ("platform/x86: huawei-wmi: Add battery charging thresholds")
Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Link: https://lore.kernel.org/r/20220303022421.313-1-baijiaju1990@gmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 16c6c057 20-Oct-2019 Ayman Bagabas <ayman.bagabas@gmail.com>

platform/x86: huawei-wmi: Remove unnecessary battery mutex

battery_lock mutex is never used and not needed.

Fixes: 355a070b09ab ("platform/x86: huawei-wmi: Add battery charging thresholds")
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 39c0a629 20-Oct-2019 Ayman Bagabas <ayman.bagabas@gmail.com>

platform/x86: huawei-wmi: No need to check for battery name

No need to check for battery name, we already check if the WMI function is
available in huawei_wmi_battery_setup.

Fixes: 355a070b09ab ("platform/x86: huawei-wmi: Add battery charging thresholds")
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 7c675486 20-Oct-2019 Ayman Bagabas <ayman.bagabas@gmail.com>

platform/x86: huawei-wmi: Stricter battery thresholds set

Check if battery thresholds are within 0 and 100.

Fixes: 355a070b09ab ("platform/x86: huawei-wmi: Add battery charging thresholds")
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 2a43c9fc 14-Oct-2019 Dan Carpenter <dan.carpenter@oracle.com>

platform/x86: huawei-wmi: Fix a precision vs width printf bug

This was supposed to be precision "%.*s" instead of width "%*s". It's
possible that this results in printing beyond the end of the string.

Fixes: a970b95345ab ("platform/x86: huawei-wmi: Add debugfs support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 3c27f179 10-Oct-2019 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

platform/x86: huawei-wmi: Avoid use of global variable when possible

There is no need to access global variable directly when we may derive it
through other means.

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


# c7a94976 10-Oct-2019 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

platform/x86: huawei-wmi: No need to keep pointer to platform device

There is no need to keep a pointer to the platform device. Currently there are
no users of it directly, and if there will be in the future we may restore it
from pointer to the struct device.

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


# 8c7d9ec8 10-Oct-2019 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

platform/x86: huawei-wmi: Don't leak memory on the exit

We have to clean memory resources allocated during init.

Fixes: 7532afb35012 ("platform/x86: huawei-wmi: Move to platform driver")
Cc: Ayman Bagabas <ayman.bagabas@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 9bfc14cb 09-Oct-2019 kbuild test robot <lkp@intel.com>

platform/x86: huawei-wmi: huawei_wmi can be static

Fixes: 7532afb35012 ("platform/x86: huawei-wmi: Move to platform driver")
Signed-off-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 94930d01 23-Sep-2019 Ayman Bagabas <ayman.bagabas@gmail.com>

platform/x86: huawei-wmi: Add debugfs support

Add a debugfs interface that can be used to call the WMI management
interface function if available.

Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 32e59d11 23-Sep-2019 Ayman Bagabas <ayman.bagabas@gmail.com>

platform/x86: huawei-wmi: Add fn-lock support

Huawei Matebook laptops uses Fn key and toggle to access F1-F12 keys.
Along with that, there is this feature called fn-lock that inverts the
behavior of this Fn key and the F1-F12 row.

Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 355a070b 23-Sep-2019 Ayman Bagabas <ayman.bagabas@gmail.com>

platform/x86: huawei-wmi: Add battery charging thresholds

Control battery charge thresholds through the battery API and driver's
attributes.

Setting battery charging thresholds can introduce a race condition with
MACH-WX9 where two or more threads are trying to read/write values
from/to EC memory.

Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 090ddd77 23-Sep-2019 Ayman Bagabas <ayman.bagabas@gmail.com>

platform/x86: huawei-wmi: Implement huawei wmi management

Huawei Matebook laptops come with a WMI management interface that can
control various aspects of the device. This interface is also found on
the old Matebook X released in 2017.

Use that to control the mic mute LED.

Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 8a480c10 23-Sep-2019 Ayman Bagabas <ayman.bagabas@gmail.com>

platform/x86: huawei-wmi: Add quirks and module parameters

Introduce quirks and module parameters. 3 quirks are added:
1. Fixes reporting brightness keys twice since it's already handled by
acpi-video.
2. Some models need a short delay when setting battery thresholds to
prevent a race condition when two processes read/write. (will be used later)
3. Matebook X (2017) handles micmute led through the "legacy" interface
which is not currently implemented. Use ACPI EC method to control
this led. (will be used later)

2 module parameters are added to enable this short delay and/or report
brightness keys through this driver.

Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 1ac9abeb 23-Sep-2019 Ayman Bagabas <ayman.bagabas@gmail.com>

platform/x86: huawei-wmi: Move to platform driver

Move from WMI driver to platform driver. This move is necessary since
the driver is no longer a hotkeys driver only. Platform driver makes it
easier for users to access sysfs attributes under (i.e.
/sys/devices/platform/huawei-wmi) compared to wmi driver.

Use WMI device UID, AMW0 has a UID of HWMI. WMI0 is the device name
and doesn't have a UID so keep it as it is.

Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 440c4983 27-May-2019 Mattias Jacobsson <2pi@mok.nu>

platform/x86: wmi: add context argument to the probe function

The struct wmi_device_id has a context pointer field, forward this
pointer as an argument to the probe function in struct wmi_driver.

Update existing users of the same probe function to accept this new
context argument.

Signed-off-by: Mattias Jacobsson <2pi@mok.nu>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 44423592 19-Feb-2019 Mattias Jacobsson <2pi@mok.nu>

platform/x86: huawei-wmi: use MODULE_DEVICE_TABLE() instead of MODULE_ALIAS()

WMI drivers can if they have specified an array of struct wmi_device_id
use the MODULE_DEVICE_TABLE() macro to automatically generate the
appropriate MODULE_ALIAS() output. Thus avoiding to keep both the array
of struct wmi_device_id and the MODULE_ALIAS() declaration(s) in sync.

Change driver to use MODULE_DEVICE_TABLE() instead of MODULE_ALIAS().

Signed-off-by: Mattias Jacobsson <2pi@mok.nu>
Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>


# bf4fb28c 12-Dec-2018 Ayman Bagabas <ayman.bagabas@gmail.com>

platform/x86: add support for Huawei WMI hotkeys

This driver adds support for missing hotkeys on some Huawei laptops.
Laptops such as the Matebook X have non functioning hotkeys. Whereas
newer laptops such as the Matebook X Pro come with working hotkeys out
of the box.

Old laptops, such as the Matebook X, report hotkey events through ACPI
device "\WMI0". However, new laptops, such as the Matebook X Pro, does
not have this WMI device.

All the hotkeys on the Matebook X Pro work fine without this patch
except (micmute, wlan, and huawei key). These keys and the brightness
keys report events to "\AMW0" ACPI device. One problem is that
brightness keys on the Matebook X Pro work without this patch. This
results in reporting two brightness key press events one is captured
by ACPI and another by this driver.

A solution would be to check if such event came from the "\AMW0" WMI
driver then skip reporting event. Another solution would be to leave
this to user-space to handle. Which can be achieved by using "hwdb"
tables and remap those keys to "unknown". This solution seems more
natural to me because it leaves the decision to user-space.

Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>