gpio: remove the open_drain API and ops
authorPatrick Delaunay <patrick.delaunay@st.com>
Mon, 13 Jan 2020 10:35:00 +0000 (11:35 +0100)
committerTom Rini <trini@konsulko.com>
Fri, 17 Apr 2020 03:06:54 +0000 (23:06 -0400)
This patch removes the ops get_open_drain/set_open_drain
and the API dm_gpio_get_open_drain/dm_gpio_set_open_drain.

The ops only provided in one driver (mpc8xxx gpio) and the
associated API is never called in boards.

This patch prepare a more generic set/get_dir_flags ops,
including the open drain property.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
arch/sandbox/include/asm/gpio.h
drivers/gpio/gpio-uclass.c
drivers/gpio/mpc8xxx_gpio.c
drivers/gpio/sandbox.c
include/asm-generic/gpio.h
test/dm/gpio.c

index de8ac37f4262dcdf16958b877462422e29b22dfa..cfb803bb3bb563fa9d4cdeb164dc2604cb840311 100644 (file)
@@ -42,26 +42,6 @@ int sandbox_gpio_get_value(struct udevice *dev, unsigned int offset);
  */
 int sandbox_gpio_set_value(struct udevice *dev, unsigned int offset, int value);
 
  */
 int sandbox_gpio_set_value(struct udevice *dev, unsigned int offset, int value);
 
-/**
- * Set or reset the simulated open drain mode of a GPIO (used only in sandbox
- * test code)
- *
- * @param gp   GPIO number
- * @param value        value to set (0 for enabled open drain mode, non-zero for
- *             disabled)
- * @return -1 on error, 0 if ok
- */
-int sandbox_gpio_set_open_drain(struct udevice *dev, unsigned offset, int value);
-
-/**
- * Return the state of the simulated open drain mode of a GPIO (used only in
- * sandbox test code)
- *
- * @param gp   GPIO number
- * @return -1 on error, 0 if GPIO is input, >0 if output
- */
-int sandbox_gpio_get_open_drain(struct udevice *dev, unsigned offset);
-
 /**
  * Return the simulated direction of a GPIO (used only in sandbox test code)
  *
 /**
  * Return the simulated direction of a GPIO (used only in sandbox test code)
  *
index 0a22441d38a4eeb99818b45ba80dbc2430809386..2515df4e7c7dfa21fbd4f9552e028a0a89a2e8ba 100644 (file)
@@ -491,38 +491,6 @@ int dm_gpio_set_value(const struct gpio_desc *desc, int value)
        return 0;
 }
 
        return 0;
 }
 
-int dm_gpio_get_open_drain(struct gpio_desc *desc)
-{
-       struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
-       int ret;
-
-       ret = check_reserved(desc, "get_open_drain");
-       if (ret)
-               return ret;
-
-       if (ops->set_open_drain)
-               return ops->get_open_drain(desc->dev, desc->offset);
-       else
-               return -ENOSYS;
-}
-
-int dm_gpio_set_open_drain(struct gpio_desc *desc, int value)
-{
-       struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
-       int ret;
-
-       ret = check_reserved(desc, "set_open_drain");
-       if (ret)
-               return ret;
-
-       if (ops->set_open_drain)
-               ret = ops->set_open_drain(desc->dev, desc->offset, value);
-       else
-               return 0; /* feature not supported -> ignore setting */
-
-       return ret;
-}
-
 int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
 {
        struct udevice *dev = desc->dev;
 int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
 {
        struct udevice *dev = desc->dev;
@@ -1053,10 +1021,6 @@ static int gpio_post_bind(struct udevice *dev)
                        ops->get_value += gd->reloc_off;
                if (ops->set_value)
                        ops->set_value += gd->reloc_off;
                        ops->get_value += gd->reloc_off;
                if (ops->set_value)
                        ops->set_value += gd->reloc_off;
-               if (ops->get_open_drain)
-                       ops->get_open_drain += gd->reloc_off;
-               if (ops->set_open_drain)
-                       ops->set_open_drain += gd->reloc_off;
                if (ops->get_function)
                        ops->get_function += gd->reloc_off;
                if (ops->xlate)
                if (ops->get_function)
                        ops->get_function += gd->reloc_off;
                if (ops->xlate)
index 4b385b8b395b6526bafb88b8cc1a259681a805f7..1dfd22522c7d5d4cba1b647ac76b8231af35b115 100644 (file)
@@ -133,26 +133,6 @@ static int mpc8xxx_gpio_get_value(struct udevice *dev, uint gpio)
        return !!mpc8xxx_gpio_get_val(data->base, gpio_mask(gpio));
 }
 
        return !!mpc8xxx_gpio_get_val(data->base, gpio_mask(gpio));
 }
 
-static int mpc8xxx_gpio_get_open_drain(struct udevice *dev, uint gpio)
-{
-       struct mpc8xxx_gpio_data *data = dev_get_priv(dev);
-
-       return !!mpc8xxx_gpio_open_drain_val(data->base, gpio_mask(gpio));
-}
-
-static int mpc8xxx_gpio_set_open_drain(struct udevice *dev, uint gpio,
-                                      int value)
-{
-       struct mpc8xxx_gpio_data *data = dev_get_priv(dev);
-
-       if (value)
-               mpc8xxx_gpio_open_drain_on(data->base, gpio_mask(gpio));
-       else
-               mpc8xxx_gpio_open_drain_off(data->base, gpio_mask(gpio));
-
-       return 0;
-}
-
 static int mpc8xxx_gpio_get_function(struct udevice *dev, uint gpio)
 {
        struct mpc8xxx_gpio_data *data = dev_get_priv(dev);
 static int mpc8xxx_gpio_get_function(struct udevice *dev, uint gpio)
 {
        struct mpc8xxx_gpio_data *data = dev_get_priv(dev);
@@ -229,8 +209,6 @@ static const struct dm_gpio_ops gpio_mpc8xxx_ops = {
        .direction_output       = mpc8xxx_gpio_direction_output,
        .get_value              = mpc8xxx_gpio_get_value,
        .set_value              = mpc8xxx_gpio_set_value,
        .direction_output       = mpc8xxx_gpio_direction_output,
        .get_value              = mpc8xxx_gpio_get_value,
        .set_value              = mpc8xxx_gpio_set_value,
-       .get_open_drain         = mpc8xxx_gpio_get_open_drain,
-       .set_open_drain         = mpc8xxx_gpio_set_open_drain,
        .get_function           = mpc8xxx_gpio_get_function,
 };
 
        .get_function           = mpc8xxx_gpio_get_function,
 };
 
index 2ef5c67ad593c153b27b6a1d393b208bbb2331f0..91e8e0677ea8e1708dd8a14b4cc02f6730e05b55 100644 (file)
@@ -14,7 +14,6 @@
 /* Flags for each GPIO */
 #define GPIOF_OUTPUT   (1 << 0)        /* Currently set as an output */
 #define GPIOF_HIGH     (1 << 1)        /* Currently set high */
 /* Flags for each GPIO */
 #define GPIOF_OUTPUT   (1 << 0)        /* Currently set as an output */
 #define GPIOF_HIGH     (1 << 1)        /* Currently set high */
-#define GPIOF_ODR      (1 << 2)        /* Currently set to open drain mode */
 
 struct gpio_state {
        const char *label;      /* label given by requester */
 
 struct gpio_state {
        const char *label;      /* label given by requester */
@@ -70,16 +69,6 @@ int sandbox_gpio_set_value(struct udevice *dev, unsigned offset, int value)
        return set_gpio_flag(dev, offset, GPIOF_HIGH, value);
 }
 
        return set_gpio_flag(dev, offset, GPIOF_HIGH, value);
 }
 
-int sandbox_gpio_get_open_drain(struct udevice *dev, unsigned offset)
-{
-       return get_gpio_flag(dev, offset, GPIOF_ODR);
-}
-
-int sandbox_gpio_set_open_drain(struct udevice *dev, unsigned offset, int value)
-{
-       return set_gpio_flag(dev, offset, GPIOF_ODR, value);
-}
-
 int sandbox_gpio_get_direction(struct udevice *dev, unsigned offset)
 {
        return get_gpio_flag(dev, offset, GPIOF_OUTPUT);
 int sandbox_gpio_get_direction(struct udevice *dev, unsigned offset)
 {
        return get_gpio_flag(dev, offset, GPIOF_OUTPUT);
@@ -134,28 +123,6 @@ static int sb_gpio_set_value(struct udevice *dev, unsigned offset, int value)
        return sandbox_gpio_set_value(dev, offset, value);
 }
 
        return sandbox_gpio_set_value(dev, offset, value);
 }
 
-/* read GPIO ODR value of port 'offset' */
-static int sb_gpio_get_open_drain(struct udevice *dev, unsigned offset)
-{
-       debug("%s: offset:%u\n", __func__, offset);
-
-       return sandbox_gpio_get_open_drain(dev, offset);
-}
-
-/* write GPIO ODR value to port 'offset' */
-static int sb_gpio_set_open_drain(struct udevice *dev, unsigned offset, int value)
-{
-       debug("%s: offset:%u, value = %d\n", __func__, offset, value);
-
-       if (!sandbox_gpio_get_direction(dev, offset)) {
-               printf("sandbox_gpio: error: set_open_drain on input gpio %u\n",
-                      offset);
-               return -1;
-       }
-
-       return sandbox_gpio_set_open_drain(dev, offset, value);
-}
-
 static int sb_gpio_get_function(struct udevice *dev, unsigned offset)
 {
        if (get_gpio_flag(dev, offset, GPIOF_OUTPUT))
 static int sb_gpio_get_function(struct udevice *dev, unsigned offset)
 {
        if (get_gpio_flag(dev, offset, GPIOF_OUTPUT))
@@ -186,8 +153,6 @@ static const struct dm_gpio_ops gpio_sandbox_ops = {
        .direction_output       = sb_gpio_direction_output,
        .get_value              = sb_gpio_get_value,
        .set_value              = sb_gpio_set_value,
        .direction_output       = sb_gpio_direction_output,
        .get_value              = sb_gpio_get_value,
        .set_value              = sb_gpio_set_value,
-       .get_open_drain         = sb_gpio_get_open_drain,
-       .set_open_drain         = sb_gpio_set_open_drain,
        .get_function           = sb_gpio_get_function,
        .xlate                  = sb_gpio_xlate,
 };
        .get_function           = sb_gpio_get_function,
        .xlate                  = sb_gpio_xlate,
 };
index 4064efeb8d0658f937051bb87c28d9dc664e8874..4d5348d8c8ec723ecca2e7319532d59b03f7cf22 100644 (file)
@@ -253,8 +253,6 @@ struct dm_gpio_ops {
                                int value);
        int (*get_value)(struct udevice *dev, unsigned offset);
        int (*set_value)(struct udevice *dev, unsigned offset, int value);
                                int value);
        int (*get_value)(struct udevice *dev, unsigned offset);
        int (*set_value)(struct udevice *dev, unsigned offset, int value);
-       int (*get_open_drain)(struct udevice *dev, unsigned offset);
-       int (*set_open_drain)(struct udevice *dev, unsigned offset, int value);
        /**
         * get_function() Get the GPIO function
         *
        /**
         * get_function() Get the GPIO function
         *
@@ -585,38 +583,6 @@ int dm_gpio_get_value(const struct gpio_desc *desc);
 
 int dm_gpio_set_value(const struct gpio_desc *desc, int value);
 
 
 int dm_gpio_set_value(const struct gpio_desc *desc, int value);
 
-/**
- * dm_gpio_get_open_drain() - Check if open-drain-mode of a GPIO is active
- *
- * This checks if open-drain-mode for a GPIO is enabled or not. This method is
- * optional.
- *
- * @desc:      GPIO description containing device, offset and flags,
- *             previously returned by gpio_request_by_name()
- * @return Value of open drain mode for GPIO (0 for inactive, 1 for active) or
- *        -ve on error
- */
-int dm_gpio_get_open_drain(struct gpio_desc *desc);
-
-/**
- * dm_gpio_set_open_drain() - Switch open-drain-mode of a GPIO on or off
- *
- * This enables or disables open-drain mode for a GPIO. This method is
- * optional; if the driver does not support it, nothing happens when the method
- * is called.
- *
- * In open-drain mode, instead of actively driving the output (Push-pull
- * output), the GPIO's pin is connected to the collector (for a NPN transistor)
- * or the drain (for a MOSFET) of a transistor, respectively. The pin then
- * either forms an open circuit or a connection to ground, depending on the
- * state of the transistor.
- *
- * @desc:      GPIO description containing device, offset and flags,
- *             previously returned by gpio_request_by_name()
- * @return 0 if OK, -ve on error
- */
-int dm_gpio_set_open_drain(struct gpio_desc *desc, int value);
-
 /**
  * dm_gpio_set_dir() - Set the direction for a GPIO
  *
 /**
  * dm_gpio_set_dir() - Set the direction for a GPIO
  *
index 349123a657c2f0599ebb2f2f07e0d6761284af4d..2dfb9fd43065576d5853b3611342ac8949519cb8 100644 (file)
@@ -73,13 +73,6 @@ static int dm_test_gpio(struct unit_test_state *uts)
        ut_assertok(ops->set_value(dev, offset, 1));
        ut_asserteq(1, ops->get_value(dev, offset));
 
        ut_assertok(ops->set_value(dev, offset, 1));
        ut_asserteq(1, ops->get_value(dev, offset));
 
-       /* Make it an open drain output, and reset it */
-       ut_asserteq(0, sandbox_gpio_get_open_drain(dev, offset));
-       ut_assertok(ops->set_open_drain(dev, offset, 1));
-       ut_asserteq(1, sandbox_gpio_get_open_drain(dev, offset));
-       ut_assertok(ops->set_open_drain(dev, offset, 0));
-       ut_asserteq(0, sandbox_gpio_get_open_drain(dev, offset));
-
        /* Make it an input */
        ut_assertok(ops->direction_input(dev, offset));
        ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
        /* Make it an input */
        ut_assertok(ops->direction_input(dev, offset));
        ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));