gpio: remove the open_drain API and ops
[oweals/u-boot.git] / include / asm-generic / gpio.h
index b073b391380c3fc616577b978906fedc66886f94..4d5348d8c8ec723ecca2e7319532d59b03f7cf22 100644 (file)
@@ -1,12 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
 /*
  * Copyright (c) 2011 The Chromium OS Authors.
  * Copyright (c) 2011, NVIDIA Corp. All rights reserved.
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #ifndef _ASM_GENERIC_GPIO_H_
 #define _ASM_GENERIC_GPIO_H_
 
+#include <dm/ofnode.h>
+
 struct ofnode_phandle_args;
 
 /*
@@ -115,11 +117,10 @@ struct udevice;
 struct gpio_desc {
        struct udevice *dev;    /* Device, NULL for invalid GPIO */
        unsigned long flags;
-#define GPIOD_REQUESTED                (1 << 0)        /* Requested/claimed */
-#define GPIOD_IS_OUT           (1 << 1)        /* GPIO is an output */
-#define GPIOD_IS_IN            (1 << 2)        /* GPIO is an input */
-#define GPIOD_ACTIVE_LOW       (1 << 3)        /* value has active low */
-#define GPIOD_IS_OUT_ACTIVE    (1 << 4)        /* set output active */
+#define GPIOD_IS_OUT           BIT(1)  /* GPIO is an output */
+#define GPIOD_IS_IN            BIT(2)  /* GPIO is an input */
+#define GPIOD_ACTIVE_LOW       BIT(3)  /* value has active low */
+#define GPIOD_IS_OUT_ACTIVE    BIT(4)  /* set output active */
 
        uint offset;            /* GPIO offset within the device */
        /*
@@ -213,7 +214,6 @@ struct fdtdec_phandle_args;
  *
  * This routine sets the offset field to args[0] and the flags field to
  * GPIOD_ACTIVE_LOW if the GPIO_ACTIVE_LOW flag is present in args[1].
- *
  */
 int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
                          struct ofnode_phandle_args *args);
@@ -247,14 +247,12 @@ int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
  */
 struct dm_gpio_ops {
        int (*request)(struct udevice *dev, unsigned offset, const char *label);
-       int (*free)(struct udevice *dev, unsigned offset);
+       int (*rfree)(struct udevice *dev, unsigned int offset);
        int (*direction_input)(struct udevice *dev, unsigned offset);
        int (*direction_output)(struct udevice *dev, unsigned offset,
                                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
         *
@@ -347,6 +345,23 @@ const char *gpio_get_bank_info(struct udevice *dev, int *offset_count);
  */
 int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc);
 
+/**
+ * gpio_hog_lookup_name() - Look up a named GPIO and return the gpio descr.
+ *
+ * @name:      Name to look up
+ * @desc:      Returns GPIO description, on success, else NULL
+ * @return:    Returns 0 if OK, else -ENODEV
+ */
+int gpio_hog_lookup_name(const char *name, struct gpio_desc **desc);
+
+/**
+ * gpio_hog_probe_all() - probe all gpio devices with
+ * gpio-hog subnodes.
+ *
+ * @return:    Returns return value from device_probe()
+ */
+int gpio_hog_probe_all(void);
+
 /**
  * gpio_lookup_name - Look up a GPIO name and return its details
  *
@@ -489,9 +504,8 @@ int gpio_get_list_count(struct udevice *dev, const char *list_name);
  * This is a version of gpio_request_list_by_name() that does not use a
  * device. Avoid it unless the caller is not yet using driver model
  */
-int gpio_request_by_name_nodev(const void *blob, int node,
-                              const char *list_name,
-                              int index, struct gpio_desc *desc, int flags);
+int gpio_request_by_name_nodev(ofnode node, const char *list_name, int index,
+                              struct gpio_desc *desc, int flags);
 
 /**
  * gpio_request_list_by_name_nodev() - request GPIOs without a device
@@ -499,11 +513,27 @@ int gpio_request_by_name_nodev(const void *blob, int node,
  * This is a version of gpio_request_list_by_name() that does not use a
  * device. Avoid it unless the caller is not yet using driver model
  */
-int gpio_request_list_by_name_nodev(const void *blob, int node,
-                                   const char *list_name,
+int gpio_request_list_by_name_nodev(ofnode node, const char *list_name,
                                    struct gpio_desc *desc_list, int max_count,
                                    int flags);
 
+/**
+ * gpio_dev_request_index() - request single GPIO from gpio device
+ *
+ * @dev:       GPIO device
+ * @nodename:  Name of node for which gpio gets requested, used
+ *             for the gpio label name
+ * @list_name: Name of GPIO list (e.g. "board-id-gpios")
+ * @index:     Index number of the GPIO in that list use request (0=first)
+ * @flags:     GPIOD_* flags
+ * @dtflags:   GPIO flags read from DT defined see GPIOD_*
+ * @desc:      returns GPIO descriptor filled from this function
+ * @return:    return value from gpio_request_tail()
+ */
+int gpio_dev_request_index(struct udevice *dev, const char *nodename,
+                          char *list_name, int index, int flags,
+                          int dtflags, struct gpio_desc *desc);
+
 /**
  * dm_gpio_free() - Free a single GPIO
  *
@@ -553,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);
 
-/**
- * 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
  *