core.h 3.2 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 15 16 17
#include <linux/pinctrl/pinconf.h>

struct pinctrl_gpio_range;

18 19 20 21 22 23 24 25 26 27 28 29 30
/**
 * 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
31
 * @p: result of pinctrl_get() for this device
32
 * @device_root: debugfs root for this device
33 34 35 36 37 38
 */
struct pinctrl_dev {
	struct list_head node;
	struct pinctrl_desc *desc;
	struct radix_tree_root pin_desc_tree;
	struct list_head gpio_ranges;
39
	struct device *dev;
40 41
	struct module *owner;
	void *driver_data;
42
	struct pinctrl *p;
43 44 45
#ifdef CONFIG_DEBUG_FS
	struct dentry *device_root;
#endif
46 47 48 49 50 51
};

/**
 * struct pinctrl - per-device pin control state holder
 * @node: global list node
 * @dev: the device using this pin control handle
52
 * @state: the state name passed to pinctrl_get()
53 54
 * @usecount: the number of active users of this pin controller setting, used
 *	to keep track of nested use cases
55
 * @settings: a list of settings for this device/state
56 57 58 59
 */
struct pinctrl {
	struct list_head node;
	struct device *dev;
60
	const char *state;
61
	unsigned usecount;
62 63 64 65 66 67 68 69 70 71 72 73
	struct list_head settings;
};

/**
 * struct pinctrl_setting - an individual mux setting
 * @node: list node for struct pinctrl's @settings field
 * @pctldev: pin control device handling to be programmed
 * @group_selector: the group selector to program
 * @func_selector: the function selector to program
 */
struct pinctrl_setting {
	struct list_head node;
74
	struct pinctrl_dev *pctldev;
75 76
	unsigned group_selector;
	unsigned func_selector;
77 78 79 80 81 82 83
};

/**
 * 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
84
 * @dynamic_name: if the name of this pin was dynamically allocated
85
 * @owner: the device holding this pin or NULL of no device has claimed it
86 87 88
 */
struct pin_desc {
	struct pinctrl_dev *pctldev;
89
	const char *name;
90
	bool dynamic_name;
91 92
	/* These fields only added when supporting pinmux drivers */
#ifdef CONFIG_PINMUX
93
	const char *owner;
94 95 96
#endif
};

97
struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
98
int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
99 100
int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
			       const char *pin_group);
101 102 103 104 105 106

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

extern struct mutex pinctrl_mutex;