Merge tag 'u-boot-imx-20190719' of https://gitlab.denx.de/u-boot/custodians/u-boot-imx
[platform/kernel/u-boot.git] / include / asm-generic / gpio.h
index de91e57..37f71e5 100644 (file)
@@ -1,12 +1,16 @@
+/* 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;
+
 /*
  * 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;
 }
@@ -207,6 +211,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
  *
  * Refer to functions above for description. These function largely copy
@@ -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);
 };
 
 /**
@@ -322,6 +336,35 @@ struct gpio_dev_priv {
 const char *gpio_get_bank_info(struct udevice *dev, int *offset_count);
 
 /**
+ * dm_gpio_lookup_name() - Look up a named GPIO and return its description
+ *
+ * The name of a GPIO is typically its bank name followed by a number from 0.
+ * For example A0 is the first GPIO in bank A. Each bank is a separate driver
+ * model device.
+ *
+ * @name:      Name to look up
+ * @desc:      Returns description, on success
+ * @return 0 if OK, -ve on error
+ */
+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
+ * @return:    Returns gpio_desc for gpio
+ */
+struct gpio_desc *gpio_hog_lookup_name(const char *name);
+
+/**
+ * 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
  *
  * This is used to convert a named GPIO into a device, offset and GPIO
@@ -347,6 +390,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
  *
  * @gpio_num_array:    array of gpios to claim, terminated by -1
@@ -421,6 +476,18 @@ int gpio_request_list_by_name(struct udevice *dev, const char *list_name,
                              int flags);
 
 /**
+ * dm_gpio_request() - manually request a GPIO
+ *
+ * Note: This function should only be used for testing / debugging. Instead.
+ * use gpio_request_by_name() to pull GPIOs from the device tree.
+ *
+ * @desc:      GPIO description of GPIO to request (see dm_gpio_lookup_name())
+ * @label:     Label to attach to the GPIO while claimed
+ * @return 0 if OK, -ve on error
+ */
+int dm_gpio_request(struct gpio_desc *desc, const char *label);
+
+/**
  * gpio_get_list_count() - Returns the number of GPIOs in a list
  *
  * Counts the GPIOs in a list. See gpio_request_by_name() for additional
@@ -439,9 +506,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
@@ -449,12 +515,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
+ * @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
+ * @desc:      GPIO descriotor 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
  *
  * This frees a single GPIOs previously returned from gpio_request_by_name().
@@ -499,9 +580,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
@@ -540,6 +653,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_ */