core.h 5.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/*
 * Core private header for the pin control subsystem
 *
 * Copyright (C) 2011 ST-Ericsson SA
 * Written on behalf of Linaro for ST-Ericsson
 *
 * Author: Linus Walleij <linus.walleij@linaro.org>
 *
 * License terms: GNU General Public License (GPL) version 2
 */

12 13
#include <linux/mutex.h>
#include <linux/radix-tree.h>
14
#include <linux/pinctrl/pinconf.h>
15
#include <linux/pinctrl/machine.h>
16 17 18

struct pinctrl_gpio_range;

19 20 21 22 23 24 25 26 27 28 29 30 31
/**
 * struct pinctrl_dev - pin control class device
 * @node: node to include this pin controller in the global pin controller list
 * @desc: the pin controller descriptor supplied when initializing this pin
 *	controller
 * @pin_desc_tree: each pin descriptor for this pin controller is stored in
 *	this radix tree
 * @gpio_ranges: a list of GPIO ranges that is handled by this pin controller,
 *	ranges are added to this list at runtime
 * @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
32
 * @p: result of pinctrl_get() for this device
33 34
 * @hog_default: default state for pins hogged by this device
 * @hog_sleep: sleep state for pins hogged by this device
35
 * @device_root: debugfs root for this device
36 37 38 39 40 41
 */
struct pinctrl_dev {
	struct list_head node;
	struct pinctrl_desc *desc;
	struct radix_tree_root pin_desc_tree;
	struct list_head gpio_ranges;
42
	struct device *dev;
43 44
	struct module *owner;
	void *driver_data;
45
	struct pinctrl *p;
46 47
	struct pinctrl_state *hog_default;
	struct pinctrl_state *hog_sleep;
48 49 50
#ifdef CONFIG_DEBUG_FS
	struct dentry *device_root;
#endif
51 52 53 54 55 56
};

/**
 * struct pinctrl - per-device pin control state holder
 * @node: global list node
 * @dev: the device using this pin control handle
57 58
 * @states: a list of states for this device
 * @state: the current state
59 60
 * @dt_maps: the mapping table chunks dynamically parsed from device tree for
 *	this device, if any
61 62 63 64
 */
struct pinctrl {
	struct list_head node;
	struct device *dev;
65 66
	struct list_head states;
	struct pinctrl_state *state;
67
	struct list_head dt_maps;
68 69 70 71 72 73 74 75 76 77 78
};

/**
 * 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;
79 80 81
	struct list_head settings;
};

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
/**
 * 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;
};

106
/**
107
 * struct pinctrl_setting - an individual mux or config setting
108
 * @node: list node for struct pinctrl_settings's @settings field
109
 * @type: the type of setting
110 111
 * @pctldev: pin control device handling to be programmed. Not used for
 *   PIN_MAP_TYPE_DUMMY_STATE.
112
 * @dev_name: the name of the device using this state
113
 * @data: Data specific to the setting type
114 115 116
 */
struct pinctrl_setting {
	struct list_head node;
117
	enum pinctrl_map_type type;
118
	struct pinctrl_dev *pctldev;
119
	const char *dev_name;
120 121 122 123
	union {
		struct pinctrl_setting_mux mux;
		struct pinctrl_setting_configs configs;
	} data;
124 125 126 127 128 129 130
};

/**
 * 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
131
 * @dynamic_name: if the name of this pin was dynamically allocated
132
 * @mux_usecount: If zero, the pin is not claimed, and @owner should be NULL.
133 134 135 136
 *	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.
137
 * @mux_owner: The name of device that called pinctrl_get().
138
 * @mux_setting: The most recent selected mux setting for this pin, if any.
139 140
 * @gpio_owner: If pinctrl_request_gpio() was called for this pin, this is
 *	the name of the GPIO that "owns" this pin.
141 142 143
 */
struct pin_desc {
	struct pinctrl_dev *pctldev;
144
	const char *name;
145
	bool dynamic_name;
146 147
	/* These fields only added when supporting pinmux drivers */
#ifdef CONFIG_PINMUX
148 149
	unsigned mux_usecount;
	const char *mux_owner;
150
	const struct pinctrl_setting_mux *mux_setting;
151
	const char *gpio_owner;
152 153 154
#endif
};

155
struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
156
int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
157
const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin);
158 159
int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
			       const char *pin_group);
160 161 162 163 164 165

static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev,
					    unsigned int pin)
{
	return radix_tree_lookup(&pctldev->pin_desc_tree, pin);
}
166

167 168 169 170
int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps,
			 bool dup, bool locked);
void pinctrl_unregister_map(struct pinctrl_map const *map);

171 172 173
extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev);
extern int pinctrl_force_default(struct pinctrl_dev *pctldev);

174
extern struct mutex pinctrl_mutex;
175
extern struct list_head pinctrldev_list;