[PATCH 2/3] dm: button: add support for linux_code in button-gpio.c driver
Dzmitry Sankouski
dsankouski at gmail.com
Wed Jan 11 11:19:30 CET 2023
Linux event code may be used in input devices, using buttons.
Signed-off-by: Dzmitry Sankouski <dsankouski at gmail.com>
---
drivers/button/button-gpio.c | 20 ++++++++++++++++++++
drivers/button/button-uclass.c | 10 ++++++++++
include/button.h | 16 ++++++++++++++++
3 files changed, 46 insertions(+)
diff --git a/drivers/button/button-gpio.c b/drivers/button/button-gpio.c
index dbb000622c..e6eff5c1da 100644
--- a/drivers/button/button-gpio.c
+++ b/drivers/button/button-gpio.c
@@ -13,6 +13,7 @@
struct button_gpio_priv {
struct gpio_desc gpio;
+ u32 linux_code;
};
static enum button_state_t button_gpio_get_state(struct udevice *dev)
@@ -29,10 +30,22 @@ static enum button_state_t button_gpio_get_state(struct udevice *dev)
return ret ? BUTTON_ON : BUTTON_OFF;
}
+static u32 button_gpio_get_code(struct udevice *dev)
+{
+ struct button_gpio_priv *priv = dev_get_priv(dev);
+ u32 code = priv->linux_code;
+
+ if (!code)
+ return 0;
+
+ return code;
+}
+
static int button_gpio_probe(struct udevice *dev)
{
struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
struct button_gpio_priv *priv = dev_get_priv(dev);
+ u32 linux_code;
int ret;
/* Ignore the top-level button node */
@@ -43,6 +56,12 @@ static int button_gpio_probe(struct udevice *dev)
if (ret)
return ret;
+ linux_code = dev_read_u32_default(dev, "linux,code", -ENODATA);
+ debug("linux code value: %d, ret: %d", linux_code, ret);
+ if (ret)
+ return ret;
+ priv->linux_code = linux_code;
+
return 0;
}
@@ -92,6 +111,7 @@ static int button_gpio_bind(struct udevice *parent)
static const struct button_ops button_gpio_ops = {
.get_state = button_gpio_get_state,
+ .get_code = button_gpio_get_code,
};
static const struct udevice_id button_gpio_ids[] = {
diff --git a/drivers/button/button-uclass.c b/drivers/button/button-uclass.c
index e33ed7d01d..6d0c6f69c5 100644
--- a/drivers/button/button-uclass.c
+++ b/drivers/button/button-uclass.c
@@ -38,6 +38,16 @@ enum button_state_t button_get_state(struct udevice *dev)
return ops->get_state(dev);
}
+u32 button_get_code(struct udevice *dev)
+{
+ struct button_ops *ops = button_get_ops(dev);
+
+ if (!ops->get_code)
+ return -ENOSYS;
+
+ return ops->get_code(dev);
+}
+
UCLASS_DRIVER(button) = {
.id = UCLASS_BUTTON,
.name = "button",
diff --git a/include/button.h b/include/button.h
index 96e6b1901f..27af4a6a1a 100644
--- a/include/button.h
+++ b/include/button.h
@@ -37,6 +37,14 @@ struct button_ops {
* @return button state button_state_t, or -ve on error
*/
enum button_state_t (*get_state)(struct udevice *dev);
+
+ /**
+ * get_code() - get linux event code of a button
+ *
+ * @dev: button device to change
+ * @return button code, or -ve on error
+ */
+ u32 (*get_code)(struct udevice *dev);
};
#define button_get_ops(dev) ((struct button_ops *)(dev)->driver->ops)
@@ -58,4 +66,12 @@ int button_get_by_label(const char *label, struct udevice **devp);
*/
enum button_state_t button_get_state(struct udevice *dev);
+/**
+ * button_get_code() - get linux event code of a button
+ *
+ * @dev: button device to change
+ * @return button code, or -ve on error
+ */
+u32 button_get_code(struct udevice *dev);
+
#endif
--
2.30.2
More information about the U-Boot
mailing list