dm: button: add support for linux_code in button-gpio.c driver

Linux event code must be used in input devices, using buttons.

Signed-off-by: Dzmitry Sankouski <dsankouski@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
diff --git a/drivers/button/button-gpio.c b/drivers/button/button-gpio.c
index dbb0006..7b5b3af 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;
+	int linux_code;
 };
 
 static enum button_state_t button_gpio_get_state(struct udevice *dev)
@@ -29,6 +30,17 @@
 	return ret ? BUTTON_ON : BUTTON_OFF;
 }
 
+static int button_gpio_get_code(struct udevice *dev)
+{
+	struct button_gpio_priv *priv = dev_get_priv(dev);
+	int code = priv->linux_code;
+
+	if (!code)
+		return -ENODATA;
+
+	return code;
+}
+
 static int button_gpio_probe(struct udevice *dev)
 {
 	struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
@@ -43,7 +55,9 @@
 	if (ret)
 		return ret;
 
-	return 0;
+	ret = dev_read_u32(dev, "linux,code", &priv->linux_code);
+
+	return ret;
 }
 
 static int button_gpio_remove(struct udevice *dev)
@@ -92,6 +106,7 @@
 
 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 e33ed7d..032191d 100644
--- a/drivers/button/button-uclass.c
+++ b/drivers/button/button-uclass.c
@@ -38,6 +38,16 @@
 	return ops->get_state(dev);
 }
 
+int 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",