]> git.sur5r.net Git - u-boot/blobdiff - include/asm-generic/gpio.h
log: Add control over log formatting
[u-boot] / include / asm-generic / gpio.h
index 0af599f86df5bee53efa1745a833d386df6665a6..bf230c15ba5f2b08d581c87d1a66b484267dcfb5 100644 (file)
@@ -7,6 +7,10 @@
 #ifndef _ASM_GENERIC_GPIO_H_
 #define _ASM_GENERIC_GPIO_H_
 
+#include <dm/ofnode.h>
+
+struct ofnode_phandle_args;
+
 /*
  * Generic GPIO API for U-Boot
  *
@@ -133,7 +137,7 @@ struct gpio_desc {
  *             previously returned by gpio_request_by_name()
  * @return true if valid, false if not
  */
-static inline bool dm_gpio_is_valid(struct gpio_desc *desc)
+static inline bool dm_gpio_is_valid(const struct gpio_desc *desc)
 {
        return desc->dev != NULL;
 }
@@ -206,6 +210,15 @@ int gpio_requestf(unsigned gpio, const char *fmt, ...)
 
 struct fdtdec_phandle_args;
 
+/**
+ * gpio_xlate_offs_flags() - implementation for common use of dm_gpio_ops.xlate
+ *
+ * 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);
+
 /**
  * struct struct dm_gpio_ops - Driver model GPIO operations
  *
@@ -241,6 +254,8 @@ 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 (*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
         *
@@ -258,12 +273,11 @@ struct dm_gpio_ops {
         *
         *   @desc->dev to @dev
         *   @desc->flags to 0
-        *   @desc->offset to the value of the first argument in args, if any,
-        *              otherwise -1 (which is invalid)
+        *   @desc->offset to 0
         *
-        * This method is optional so if the above defaults suit it can be
-        * omitted. Typical behaviour is to set up the GPIOD_ACTIVE_LOW flag
-        * in desc->flags.
+        * This method is optional and defaults to gpio_xlate_offs_flags,
+        * which will parse offset and the GPIO_ACTIVE_LOW flag in the first
+        * two arguments.
         *
         * Note that @dev is passed in as a parameter to follow driver model
         * uclass conventions, even though it is already available as
@@ -275,7 +289,7 @@ struct dm_gpio_ops {
         * @return 0 if OK, -ve on error
         */
        int (*xlate)(struct udevice *dev, struct gpio_desc *desc,
-                    struct fdtdec_phandle_args *args);
+                    struct ofnode_phandle_args *args);
 };
 
 /**
@@ -359,6 +373,18 @@ int gpio_lookup_name(const char *name, struct udevice **devp,
  */
 int gpio_get_values_as_int(const int *gpio_list);
 
+/**
+ * dm_gpio_get_values_as_int() - Turn the values of a list of GPIOs into an int
+ *
+ * This puts the value of the first GPIO into bit 0, the second into bit 1,
+ * etc. then returns the resulting integer.
+ *
+ * @desc_list: List of GPIOs to collect
+ * @count: Number of GPIOs
+ * @return resulting integer value, or -ve on error
+ */
+int dm_gpio_get_values_as_int(const struct gpio_desc *desc_list, int count);
+
 /**
  * gpio_claim_vector() - claim a number of GPIOs for input
  *
@@ -464,9 +490,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
@@ -474,8 +499,7 @@ 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);
 
@@ -524,9 +548,41 @@ int gpio_free_list_nodev(struct gpio_desc *desc, int count);
  *             previously returned by gpio_request_by_name()
  * @return GPIO value (0 for inactive, 1 for active) or -ve on error
  */
-int dm_gpio_get_value(struct gpio_desc *desc);
+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);
 
-int dm_gpio_set_value(struct gpio_desc *desc, int value);
+/**
+ * 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
@@ -565,6 +621,6 @@ int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags);
  *             previously returned by gpio_request_by_name()
  * @return GPIO number, or -ve if not found
  */
-int gpio_get_number(struct gpio_desc *desc);
+int gpio_get_number(const struct gpio_desc *desc);
 
 #endif /* _ASM_GENERIC_GPIO_H_ */