pinctrl: enhance mapping table to support pin config operations
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / pinctrl / core.h
index 177a3310547f31ceb8a9cd1191cb55f7f253469d..1cae3723bbed22bf9461b04a5b52d778b4a40a18 100644 (file)
@@ -9,6 +9,8 @@
  * License terms: GNU General Public License (GPL) version 2
  */
 
+#include <linux/mutex.h>
+#include <linux/radix-tree.h>
 #include <linux/pinctrl/pinconf.h>
 
 struct pinctrl_gpio_range;
@@ -20,61 +22,131 @@ struct pinctrl_gpio_range;
  *     controller
  * @pin_desc_tree: each pin descriptor for this pin controller is stored in
  *     this radix tree
- * @pin_desc_tree_lock: lock for the descriptor tree
  * @gpio_ranges: a list of GPIO ranges that is handled by this pin controller,
  *     ranges are added to this list at runtime
- * @gpio_ranges_lock: lock for the GPIO ranges list
  * @dev: the device entry for this pin controller
  * @owner: module providing the pin controller, used for refcounting
  * @driver_data: driver data for drivers registering to the pin controller
  *     subsystem
- * @pinmux_hogs_lock: lock for the pinmux hog list
- * @pinmux_hogs: list of pinmux maps hogged by this device
+ * @p: result of pinctrl_get() for this device
+ * @device_root: debugfs root for this device
  */
 struct pinctrl_dev {
        struct list_head node;
        struct pinctrl_desc *desc;
        struct radix_tree_root pin_desc_tree;
-       spinlock_t pin_desc_tree_lock;
        struct list_head gpio_ranges;
-       struct mutex gpio_ranges_lock;
        struct device *dev;
        struct module *owner;
        void *driver_data;
-#ifdef CONFIG_PINMUX
-       struct mutex pinmux_hogs_lock;
-       struct list_head pinmux_hogs;
+       struct pinctrl *p;
+#ifdef CONFIG_DEBUG_FS
+       struct dentry *device_root;
 #endif
 };
 
+/**
+ * struct pinctrl - per-device pin control state holder
+ * @node: global list node
+ * @dev: the device using this pin control handle
+ * @states: a list of states for this device
+ * @state: the current state
+ */
+struct pinctrl {
+       struct list_head node;
+       struct device *dev;
+       struct list_head states;
+       struct pinctrl_state *state;
+};
+
+/**
+ * struct pinctrl_state - a pinctrl state for a device
+ * @node: list not for struct pinctrl's @states field
+ * @name: the name of this state
+ * @settings: a list of settings for this state
+ */
+struct pinctrl_state {
+       struct list_head node;
+       const char *name;
+       struct list_head settings;
+};
+
+/**
+ * struct pinctrl_setting_mux - setting data for MAP_TYPE_MUX_GROUP
+ * @group: the group selector to program
+ * @func: the function selector to program
+ */
+struct pinctrl_setting_mux {
+       unsigned group;
+       unsigned func;
+};
+
+/**
+ * struct pinctrl_setting_configs - setting data for MAP_TYPE_CONFIGS_*
+ * @group_or_pin: the group selector or pin ID to program
+ * @configs: a pointer to an array of config parameters/values to program into
+ *     hardware. Each individual pin controller defines the format and meaning
+ *     of config parameters.
+ * @num_configs: the number of entries in array @configs
+ */
+struct pinctrl_setting_configs {
+       unsigned group_or_pin;
+       unsigned long *configs;
+       unsigned num_configs;
+};
+
+/**
+ * struct pinctrl_setting - an individual mux setting
+ * @node: list node for struct pinctrl_settings's @settings field
+ * @type: the type of setting
+ * @pctldev: pin control device handling to be programmed
+ * @data: Data specific to the setting type
+ */
+struct pinctrl_setting {
+       struct list_head node;
+       enum pinctrl_map_type type;
+       struct pinctrl_dev *pctldev;
+       union {
+               struct pinctrl_setting_mux mux;
+               struct pinctrl_setting_configs configs;
+       } data;
+};
+
 /**
  * struct pin_desc - pin descriptor for each physical pin in the arch
  * @pctldev: corresponding pin control device
  * @name: a name for the pin, e.g. the name of the pin/pad/finger on a
  *     datasheet or such
  * @dynamic_name: if the name of this pin was dynamically allocated
- * @lock: a lock to protect the descriptor structure
- * @mux_requested: whether the pin is already requested by pinmux or not
- * @mux_function: a named muxing function for the pin that will be passed to
- *     subdrivers and shown in debugfs etc
+ * @usecount: If zero, the pin is not claimed, and @owner should be NULL.
+ *     If non-zero, this pin is claimed by @owner. This field is an integer
+ *     rather than a boolean, since pinctrl_get() might process multiple
+ *     mapping table entries that refer to, and hence claim, the same group
+ *     or pin, and each of these will increment the @usecount.
+ * @owner: The name of the entity owning the pin. Typically, this is the name
+ *     of the device that called pinctrl_get(). Alternatively, it may be the
+ *     name of the GPIO passed to pinctrl_request_gpio().
  */
 struct pin_desc {
        struct pinctrl_dev *pctldev;
        const char *name;
        bool dynamic_name;
-       spinlock_t lock;
        /* These fields only added when supporting pinmux drivers */
 #ifdef CONFIG_PINMUX
-       const char *mux_function;
+       unsigned usecount;
+       const char *owner;
 #endif
 };
 
-struct pinctrl_dev *get_pinctrl_dev_from_dev(struct device *dev,
-                                            const char *dev_name);
-struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev, unsigned int pin);
+struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
 int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
-int pinctrl_get_device_gpio_range(unsigned gpio,
-                                 struct pinctrl_dev **outdev,
-                                 struct pinctrl_gpio_range **outrange);
 int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
                               const char *pin_group);
+
+static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev,
+                                           unsigned int pin)
+{
+       return radix_tree_lookup(&pctldev->pin_desc_tree, pin);
+}
+
+extern struct mutex pinctrl_mutex;