[U-Boot] [PATCH 2/2] dm: gpio: mxc: implement xlate function

Peng Fan van.freenix at gmail.com
Tue Mar 15 06:48:57 CET 2016


To i.MX controller, we use such as "<&gpio1 3 GPIO_ACTIVE_LOW>" for
a device to refer a gpio pin in device tree. So need to implement
xlate function, to correctly handle gpio flags and offset.

Signed-off-by: Peng Fan <van.freenix at gmail.com>
Cc: Simon Glass <sjg at chromium.org>
Cc: Stefano Babic <sbabic at denx.de>
Cc: Fabio Estevam <fabio.estevam at nxp.com>
---
 drivers/gpio/mxc_gpio.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c
index b6ae3fc..15449d7 100644
--- a/drivers/gpio/mxc_gpio.c
+++ b/drivers/gpio/mxc_gpio.c
@@ -10,10 +10,12 @@
 #include <common.h>
 #include <errno.h>
 #include <dm.h>
+#include <fdtdec.h>
 #include <malloc.h>
 #include <asm/arch/imx-regs.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
+#include <dt-bindings/gpio/gpio.h>
 
 enum mxc_gpio_direction {
 	MXC_GPIO_DIRECTION_IN,
@@ -263,12 +265,22 @@ static int mxc_gpio_get_function(struct udevice *dev, unsigned offset)
 		return GPIOF_INPUT;
 }
 
+static int mxc_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
+			  struct fdtdec_phandle_args *args)
+{
+	desc->offset = args->args[0];
+	desc->flags = args->args[1] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0;
+
+	return 0;
+}
+
 static const struct dm_gpio_ops gpio_mxc_ops = {
 	.direction_input	= mxc_gpio_direction_input,
 	.direction_output	= mxc_gpio_direction_output,
 	.get_value		= mxc_gpio_get_value,
 	.set_value		= mxc_gpio_set_value,
 	.get_function		= mxc_gpio_get_function,
+	.xlate			= mxc_gpio_xlate,
 };
 
 static int mxc_gpio_probe(struct udevice *dev)
-- 
2.6.2



More information about the U-Boot mailing list