mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 08:14:15 +08:00
ab78029ecc
This makes the device core auto-grab the pinctrl handle and set the "default" (PINCTRL_STATE_DEFAULT) state for every device that is present in the device model right before probe. This will account for the lion's share of embedded silicon devcies. A modification of the semantics for pinctrl_get() is also done: previously if the pinctrl handle for a certain device was already taken, the pinctrl core would return an error. Now, since the core may have already default-grabbed the handle and set its state to "default", if the handle was already taken, this will be disregarded and the located, previously instanitated handle will be returned to the caller. This way all code in drivers explicitly requesting their pinctrl handlers will still be functional, and drivers that want to explicitly retrieve and switch their handles can still do that. But if the desired functionality is just boilerplate of this type in the probe() function: struct pinctrl *p; p = devm_pinctrl_get_select_default(&dev); if (IS_ERR(p)) { if (PTR_ERR(p) == -EPROBE_DEFER) return -EPROBE_DEFER; dev_warn(&dev, "no pinctrl handle\n"); } The discussion began with the addition of such boilerplate to the omap4 keypad driver: http://marc.info/?l=linux-input&m=135091157719300&w=2 A previous approach using notifiers was discussed: http://marc.info/?l=linux-kernel&m=135263661110528&w=2 This failed because it could not handle deferred probes. This patch alone does not solve the entire dilemma faced: whether code should be distributed into the drivers or if it should be centralized to e.g. a PM domain. But it solves the immediate issue of the addition of boilerplate to a lot of drivers that just want to grab the default state. As mentioned, they can later explicitly retrieve the handle and set different states, and this could as well be done by e.g. PM domains as it is only related to a certain struct device * pointer. ChangeLog v4->v5 (Stephen): - Simplified the devicecore grab code. - Deleted a piece of documentation recommending that pins be mapped to a device rather than hogged. ChangeLog v3->v4 (Linus): - Drop overzealous NULL checks. - Move kref initialization to pinctrl_create(). - Seeking Tested-by from Stephen Warren so we do not disturb the Tegra platform. - Seeking ACK on this from Greg (and others who like it) so I can merge it through the pinctrl subsystem. ChangeLog v2->v3 (Linus): - Abstain from using IS_ERR_OR_NULL() in the driver core, Russell recently sent a patch to remove it. Handle the NULL case explicitly even though it's a bogus case. - Make sure we handle probe deferral correctly in the device core file. devm_kfree() the container on error so we don't waste memory for devices without pinctrl handles. - Introduce reference counting into the pinctrl core using <linux/kref.h> so that we don't release pinctrl handles that have been obtained for two or more places. ChangeLog v1->v2 (Linus): - Only store a pointer in the device struct, and only allocate this if it's really used by the device. Cc: Felipe Balbi <balbi@ti.com> Cc: Benoit Cousson <b-cousson@ti.com> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com> Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Cc: Mitch Bradley <wmb@firmworks.com> Cc: Ulf Hansson <ulf.hansson@linaro.org> Cc: Rafael J. Wysocki <rjw@sisk.pl> Cc: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Cc: Rickard Andersson <rickard.andersson@stericsson.com> Cc: Russell King <linux@arm.linux.org.uk> Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> [swarren: fixed and simplified error-handling in pinctrl_bind_pins(), to correctly handle deferred probe. Removed admonition from docs not to use pinctrl hogs for devices] Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
179 lines
5.7 KiB
C
179 lines
5.7 KiB
C
/*
|
|
* 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
|
|
*/
|
|
|
|
#include <linux/kref.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/radix-tree.h>
|
|
#include <linux/pinctrl/pinconf.h>
|
|
#include <linux/pinctrl/machine.h>
|
|
|
|
struct pinctrl_gpio_range;
|
|
|
|
/**
|
|
* 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
|
|
* @p: result of pinctrl_get() for this device
|
|
* @hog_default: default state for pins hogged by this device
|
|
* @hog_sleep: sleep state for pins hogged by 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;
|
|
struct list_head gpio_ranges;
|
|
struct device *dev;
|
|
struct module *owner;
|
|
void *driver_data;
|
|
struct pinctrl *p;
|
|
struct pinctrl_state *hog_default;
|
|
struct pinctrl_state *hog_sleep;
|
|
#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
|
|
* @dt_maps: the mapping table chunks dynamically parsed from device tree for
|
|
* this device, if any
|
|
* @users: reference count
|
|
*/
|
|
struct pinctrl {
|
|
struct list_head node;
|
|
struct device *dev;
|
|
struct list_head states;
|
|
struct pinctrl_state *state;
|
|
struct list_head dt_maps;
|
|
struct kref users;
|
|
};
|
|
|
|
/**
|
|
* 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 or config setting
|
|
* @node: list node for struct pinctrl_settings's @settings field
|
|
* @type: the type of setting
|
|
* @pctldev: pin control device handling to be programmed. Not used for
|
|
* PIN_MAP_TYPE_DUMMY_STATE.
|
|
* @dev_name: the name of the device using this state
|
|
* @data: Data specific to the setting type
|
|
*/
|
|
struct pinctrl_setting {
|
|
struct list_head node;
|
|
enum pinctrl_map_type type;
|
|
struct pinctrl_dev *pctldev;
|
|
const char *dev_name;
|
|
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
|
|
* @mux_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.
|
|
* @mux_owner: The name of device that called pinctrl_get().
|
|
* @mux_setting: The most recent selected mux setting for this pin, if any.
|
|
* @gpio_owner: If pinctrl_request_gpio() was called for this pin, this is
|
|
* the name of the GPIO that "owns" this pin.
|
|
*/
|
|
struct pin_desc {
|
|
struct pinctrl_dev *pctldev;
|
|
const char *name;
|
|
bool dynamic_name;
|
|
/* These fields only added when supporting pinmux drivers */
|
|
#ifdef CONFIG_PINMUX
|
|
unsigned mux_usecount;
|
|
const char *mux_owner;
|
|
const struct pinctrl_setting_mux *mux_setting;
|
|
const char *gpio_owner;
|
|
#endif
|
|
};
|
|
|
|
struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
|
|
int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
|
|
const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin);
|
|
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);
|
|
}
|
|
|
|
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);
|
|
|
|
extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev);
|
|
extern int pinctrl_force_default(struct pinctrl_dev *pctldev);
|
|
|
|
extern struct mutex pinctrl_mutex;
|
|
extern struct list_head pinctrldev_list;
|