Commit Graph

17 Commits

Author SHA1 Message Date
Ayman Bagabas
16c6c05717 platform/x86: huawei-wmi: Remove unnecessary battery mutex
battery_lock mutex is never used and not needed.

Fixes: 355a070b09 ("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>
2019-10-21 12:17:30 +03:00
Ayman Bagabas
39c0a6295e 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: 355a070b09 ("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>
2019-10-21 12:17:30 +03:00
Ayman Bagabas
7c675486b9 platform/x86: huawei-wmi: Stricter battery thresholds set
Check if battery thresholds are within 0 and 100.

Fixes: 355a070b09 ("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>
2019-10-21 12:17:30 +03:00
Dan Carpenter
2a43c9fc87 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>
2019-10-15 10:55:11 +03:00
Andy Shevchenko
3c27f179d5 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>
2019-10-15 10:55:11 +03:00
Andy Shevchenko
c7a949766f 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>
2019-10-15 10:55:11 +03:00
Andy Shevchenko
8c7d9ec8a4 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>
2019-10-15 10:55:10 +03:00
kbuild test robot
9bfc14cb6a 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>
2019-10-15 10:55:10 +03:00
Ayman Bagabas
94930d0133 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>
2019-10-15 10:55:09 +03:00
Ayman Bagabas
32e59d119d 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>
2019-10-15 10:55:09 +03:00
Ayman Bagabas
355a070b09 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>
2019-10-15 10:55:08 +03:00
Ayman Bagabas
090ddd770b 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>
2019-10-15 10:55:08 +03:00
Ayman Bagabas
8a480c108f 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>
2019-10-15 10:55:08 +03:00
Ayman Bagabas
1ac9abeb2e 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>
2019-10-15 10:55:08 +03:00
Mattias Jacobsson
440c4983de 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>
2019-06-17 15:22:47 +03:00
Mattias Jacobsson
44423592ce 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>
2019-03-07 08:46:29 -08:00
Ayman Bagabas
bf4fb28c6e 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>
2018-12-13 09:23:27 +01:00