Skip to contentSkip to conversation

platform/chrome: Add Wilco EC keyboard backlight LEDs support

PATCH In review Nick Crews 3 participants 4 messages Apr 9, 2019 – Jun 3, 2019

Subsystems (2)
lore
Share & tools
lore

Nick Crews

author
#0 lore raw

PATCH v6 1/1 platform/chrome: Add Wilco EC keyboard backlight LEDs support

The EC is in charge of controlling the keyboard backlight on the Wilco platform. We expose a standard LED class device at /sys/class/leds/chromeos::kbd_backlight. This driver is modeled after the standard Chrome OS keyboard backlight driver at drivers/platform/chrome/cros_kbd_led_backlight.c

Some Wilco devices do not support a keyboard backlight. This is checked via wilco_ec_keyboard_leds_exist() in the core driver, and a platform_device will only be registered by the core if a backlight is supported.

After an EC reset the backlight could be in a non-PWM mode. Earlier in the boot sequence the BIOS should send a command to the EC to set the brightness, so things **should** be set up, but we double check in probe() as we query the initial brightness. If not set up, then set the brightness to 0.

Since the EC will never change the backlight level of its own accord, we don't need to implement a brightness_get() method.

v6 changes:
-Remove bogus extra de-referencing in send_kbbl_msg() -Actually return error if mailbox() fails in send_kbbl_msg() -Use SET_STATE, not GET_STATE sub-command in set_brightness()

v4 changes:
-Call keyboard_led_set_brightness() directly within
initialize_brightness(), instead of calling the library function.

v3 changes:
-Since this behaves the same as the standard Chrome OS keyboard
backlight, rename the led device to "chromeos::kbd_backlight"
-Move wilco_ec_keyboard_backlight_exists() into core module, so
that the core does not depend upon the keyboard backlight driver.
-This required moving some code into wilco-ec.h -Refactor out some common code in set_brightness() and
initialize_brightness()

v2 changes:
-Remove and fix uses of led vs LED in kconfig
-Assume BIOS initializes brightness, but double check in probe() -Remove get_brightness() callback, as EC never changes brightness
by itself.
-Use a __packed struct as message instead of opaque array -Add exported wilco_ec_keyboard_leds_exist() so the core driver
now only creates a platform _device if relevant
-Fix use of keyboard_led_set_brightness() since it can sleep

---
 drivers/platform/chrome/wilco_ec/Kconfig      |   9 +
 drivers/platform/chrome/wilco_ec/Makefile     |   2 +
 drivers/platform/chrome/wilco_ec/core.c       |  58 ++++++
 .../chrome/wilco_ec/kbd_led_backlight.c       | 166 ++++++++++++++++++
 include/linux/platform_data/wilco-ec.h        |  38 ++++
 5 files changed, 273 insertions(+)
 create mode 100644 drivers/platform/chrome/wilco_ec/kbd_led_backlight.c
drivers/platform/chrome/wilco_ec/Kconfig +9 -0
index e09e4cebe9b4..d8cf4a60d1b5 100644
@@ -18,3 +18,12 @@ config WILCO_EC_DEBUGFS
 	  manipulation and allow for testing arbitrary commands.  This
 	  interface is intended for debug only and will not be present
 	  on production devices.
+
+config WILCO_EC_KBD_BACKLIGHT
+	tristate "Enable keyboard backlight control"
+	depends on WILCO_EC
+	help
+	  If you say Y here, you get support to set the keyboard backlight
+	  brightness. This happens via a standard LED driver that uses the
+	  Wilco EC mailbox interface. A standard LED class device will
+	  appear under /sys/class/leds/chromeos::kbd_backlight
drivers/platform/chrome/wilco_ec/Makefile +2 -0
index 063e7fb4ea17..8436539813cd 100644
@@ -4,3 +4,5 @@ wilco_ec-objs				:= core.o mailbox.o
 obj-$(CONFIG_WILCO_EC)			+= wilco_ec.o
 wilco_ec_debugfs-objs			:= debugfs.o
 obj-$(CONFIG_WILCO_EC_DEBUGFS)		+= wilco_ec_debugfs.o
+wilco_kbd_backlight-objs		:= kbd_led_backlight.o
+obj-$(CONFIG_WILCO_EC_KBD_BACKLIGHT)	+= wilco_kbd_backlight.o
drivers/platform/chrome/wilco_ec/core.c +58 -0

83 lines not on this page · raw message

drivers/platform/chrome/wilco_ec/kbd_led_backlight.c new file +166 -0

166 lines not on this page · raw message

include/linux/platform_data/wilco-ec.h +38 -0
index 1ff224793c99..c3965b7f397d 100644
@@ -32,6 +32,7 @@
  * @data_size: Size of the data buffer used for EC communication.
  * @debugfs_pdev: The child platform_device used by the debugfs sub-driver.
  * @rtc_pdev: The child platform_device used by the RTC sub-driver.
+ * @kbbl_pdev: The child pdev used by the keyboard backlight sub-driver.
  */
 struct wilco_ec_device {
 	struct device *dev;
@@ -43,6 +44,7 @@ struct wilco_ec_device {
 	size_t data_size;
 	struct platform_device *debugfs_pdev;
 	struct platform_device *rtc_pdev;
+	struct platform_device *kbbl_pdev;
 };
 
 /**
@@ -114,6 +116,42 @@ struct wilco_ec_message {
 	void *response_data;
 };
 
+/* Constants and structs useful for keyboard backlight (KBBL) control */
+
+#define WILCO_EC_COMMAND_KBBL		0x75
+#define WILCO_KBBL_MODE_FLAG_PWM	BIT(1)	/* Set brightness by percent. */
+
+/**
+ * enum kbbl_subcommand - What action does the EC perform?
+ * @WILCO_KBBL_SUBCMD_GET_FEATURES: Request available functionality from EC.
+ * @WILCO_KBBL_SUBCMD_GET_STATE: Request current mode and brightness from EC.
+ * @WILCO_KBBL_SUBCMD_SET_STATE: Write mode and brightness to EC.
+ */
+enum kbbl_subcommand {
+	WILCO_KBBL_SUBCMD_GET_FEATURES = 0x00,
+	WILCO_KBBL_SUBCMD_GET_STATE = 0x01,
+	WILCO_KBBL_SUBCMD_SET_STATE = 0x02,
+};
+
+/**
+ * struct wilco_ec_kbbl_msg - Message to/from EC for keyboard backlight control.
+ * @command: Always WILCO_EC_COMMAND_KBBL.
+ * @status: Set by EC to 0 on success, 0xFF on failure.
+ * @subcmd: One of enum kbbl_subcommand.
+ * @mode: Bit flags for used mode, we want to use WILCO_KBBL_MODE_FLAG_PWM.
+ * @percent: Brightness in 0-100. Only meaningful in PWM mode.
+ */
+struct wilco_ec_kbbl_msg {
+	u8 command;
+	u8 status;
+	u8 subcmd;
+	u8 reserved3;
+	u8 mode;
+	u8 reserved5to8[4];
+	u8 percent;
+	u8 reserved10to15[6];
+} __packed;
+
 /**
  * wilco_ec_mailbox() - Send request to the EC and receive the response.
  * @ec: Wilco EC device.
Signature · 1 line
2.20.1
#1 lore raw
Quoted 3 lines

The EC is in charge of controlling the keyboard backlight on the Wilco platform. We expose a standard LED class device at /sys/class/leds/chromeos::kbd_backlight. This driver is modeled

As discussed, please use platform::.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#2 lore raw

Hi Pavel,

Quoted 6 lines · Pavel Machek
Quoted 3 lines

The EC is in charge of controlling the keyboard backlight on the Wilco platform. We expose a standard LED class device at /sys/class/leds/chromeos::kbd_backlight. This driver is modeled

As discussed, please use platform::.

Last time I looked at this patch there were some work and discussion ongoing about led naming in led ML, did the discussion end? I'm not able to find if there is a final agreement.

Thanks,
Enric

Quoted 2 lines

Pavel

#3 lore raw

Hi!

Quoted 11 lines · Pavel Machek
Quoted 6 lines
Quoted 3 lines

The EC is in charge of controlling the keyboard backlight on the Wilco platform. We expose a standard LED class device at /sys/class/leds/chromeos::kbd_backlight. This driver is modeled

As discussed, please use platform::.

Last time I looked at this patch there were some work and discussion ongoing about led naming in led ML, did the discussion end? I'm not able to find if there is a final agreement.

Jacek is working on series to clean up naming, yes.

Under new naming system, it should be "/sys/class/leds/color:kbd_backlight", AFAICT. That is acceptable to me.

Best regards,

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html