[U-Boot] [PATCH 3/3] dm: gpio: Implement open drain for MPC85XX GPIO

Mario Six mario.six at gdsys.cc
Tue Apr 26 16:08:28 CEST 2016


Signed-off-by: Mario Six <mario.six at gdsys.cc>
---
 drivers/gpio/mpc85xx_gpio.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/drivers/gpio/mpc85xx_gpio.c b/drivers/gpio/mpc85xx_gpio.c
index 2289eb7..6e920e6 100644
--- a/drivers/gpio/mpc85xx_gpio.c
+++ b/drivers/gpio/mpc85xx_gpio.c
@@ -66,6 +66,25 @@ mpc85xx_gpio_set_high(struct ccsr_gpio *base, unsigned int gpios)
 	setbits_be32(&base->gpdir, gpios);
 }
 
+static inline int
+mpc85xx_gpio_open_drain_val(struct ccsr_gpio *base, unsigned int mask)
+{
+	/* Read the requested values */
+	return in_be32(&base->gpodr) & mask;
+}
+
+static inline void
+mpc85xx_gpio_open_drain_on(struct ccsr_gpio *base, unsigned int gpios)
+{
+	setbits_be32(&base->gpodr, gpios);
+}
+
+static inline void
+mpc85xx_gpio_open_drain_off(struct ccsr_gpio *base, unsigned int gpios)
+{
+	clrbits_be32(&base->gpodr, gpios);
+}
+
 static int mpc85xx_gpio_direction_input(struct udevice *dev, unsigned int gpio)
 {
 	struct mpc85xx_gpio_data *data = dev_get_priv(dev);
@@ -75,6 +94,26 @@ static int mpc85xx_gpio_direction_input(struct udevice *dev, unsigned int gpio)
 }
 
 static int
+mpc85xx_gpio_get_open_drain(struct udevice *dev, unsigned gpio)
+{
+	struct mpc85xx_gpio_data *data = dev_get_priv(dev);
+
+	return !!mpc85xx_gpio_open_drain_val(data->base, 1U << (31 - gpio));
+}
+
+static int
+mpc85xx_gpio_set_open_drain(struct udevice *dev, unsigned gpio, int value)
+{
+	struct mpc85xx_gpio_data *data = dev_get_priv(dev);
+
+	if (value)
+		mpc85xx_gpio_open_drain_on(data->base, 1U << (31 - gpio));
+	else
+		mpc85xx_gpio_open_drain_off(data->base, 1U << (31 - gpio));
+	return 0;
+}
+
+static int
 mpc85xx_gpio_set_value(struct udevice *dev, unsigned gpio, int value)
 {
 	struct mpc85xx_gpio_data *data = dev_get_priv(dev);
@@ -163,6 +202,8 @@ static const struct dm_gpio_ops gpio_mpc85xx_ops = {
 	.direction_output	= mpc85xx_gpio_direction_output,
 	.get_value		= mpc85xx_gpio_get_value,
 	.set_value		= mpc85xx_gpio_set_value,
+	.get_open_drain		= mpc85xx_gpio_get_open_drain,
+	.set_open_drain		= mpc85xx_gpio_set_open_drain,
 	.get_function		= mpc85xx_gpio_get_function,
 };
 
-- 
2.7.0.GIT



More information about the U-Boot mailing list