forked from luck/tmp_suning_uos_patched
pinctrl: refactor struct pinctrl handling in core.c vs pinmux.c
This change separates two aspects of struct pinctrl: a) The data representation of the parsed mapping table, into: 1) The top-level struct pinctrl object, a single entity returned by pinctrl_get(). 2) The parsed version of each mapping table entry, struct pinctrl_setting, of which there is one per mapping table entry. b) The code that handles this; the code for (1) above is in core.c, and the code to parse/execute each entry in (2) above is in pinmux.c, while the iteration over multiple settings is lifted to core.c. This will allow the following future changes: 1) pinctrl_get() API rework, so that struct pinctrl represents all states for the device, and the device can select between them without calling put()/get() again. 2) To support that, a struct pinctrl_state object will be inserted into the data model between the struct pinctrl and struct pinctrl_setting. 3) The mapping table will be extended to allow specification of pin config settings too. To support this, struct pinctrl_setting will be enhanced to store either mux settings or config settings, and functions will be added to pinconf.c to parse/execute pin configuration settings. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Dong Aisheng <dong.aisheng@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
parent
57b676f9c1
commit
7ecdb16fe6
|
@ -460,14 +460,15 @@ EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
|
||||||
|
|
||||||
static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)
|
static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)
|
||||||
{
|
{
|
||||||
struct pinctrl_dev *pctldev = NULL;
|
struct pinctrl_dev *pctldev;
|
||||||
const char *devname;
|
const char *devname;
|
||||||
struct pinctrl *p;
|
struct pinctrl *p;
|
||||||
unsigned num_maps = 0;
|
unsigned num_maps = 0;
|
||||||
int ret = -ENODEV;
|
int ret;
|
||||||
struct pinctrl_maps *maps_node;
|
struct pinctrl_maps *maps_node;
|
||||||
int i;
|
int i;
|
||||||
struct pinctrl_map const *map;
|
struct pinctrl_map const *map;
|
||||||
|
struct pinctrl_setting *setting;
|
||||||
|
|
||||||
/* We must have both a dev and state name */
|
/* We must have both a dev and state name */
|
||||||
if (WARN_ON(!dev || !name))
|
if (WARN_ON(!dev || !name))
|
||||||
|
@ -487,26 +488,12 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)
|
||||||
dev_err(dev, "failed to alloc struct pinctrl\n");
|
dev_err(dev, "failed to alloc struct pinctrl\n");
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
}
|
}
|
||||||
pinmux_init_pinctrl_handle(p);
|
p->dev = dev;
|
||||||
|
p->state = name;
|
||||||
|
INIT_LIST_HEAD(&p->settings);
|
||||||
|
|
||||||
/* Iterate over the pin control maps to locate the right ones */
|
/* Iterate over the pin control maps to locate the right ones */
|
||||||
for_each_maps(maps_node, i, map) {
|
for_each_maps(maps_node, i, map) {
|
||||||
/*
|
|
||||||
* First, try to find the pctldev given in the map
|
|
||||||
*/
|
|
||||||
pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name);
|
|
||||||
if (!pctldev) {
|
|
||||||
dev_err(dev, "unknown pinctrl device %s in map entry",
|
|
||||||
map->ctrl_dev_name);
|
|
||||||
pinmux_put(p);
|
|
||||||
kfree(p);
|
|
||||||
/* Eventually, this should trigger deferred probe */
|
|
||||||
return ERR_PTR(-ENODEV);
|
|
||||||
}
|
|
||||||
|
|
||||||
dev_dbg(dev, "in map, found pctldev %s to handle function %s",
|
|
||||||
dev_name(pctldev->dev), map->function);
|
|
||||||
|
|
||||||
/* Map must be for this device */
|
/* Map must be for this device */
|
||||||
if (strcmp(map->dev_name, devname))
|
if (strcmp(map->dev_name, devname))
|
||||||
continue;
|
continue;
|
||||||
|
@ -515,11 +502,36 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)
|
||||||
if (strcmp(map->name, name))
|
if (strcmp(map->name, name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ret = pinmux_apply_muxmap(pctldev, p, dev, devname, map);
|
/*
|
||||||
if (ret) {
|
* Try to find the pctldev given in the map
|
||||||
kfree(p);
|
*/
|
||||||
return ERR_PTR(ret);
|
pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name);
|
||||||
|
if (!pctldev) {
|
||||||
|
dev_err(dev, "unknown pinctrl device %s in map entry",
|
||||||
|
map->ctrl_dev_name);
|
||||||
|
/* Eventually, this should trigger deferred probe */
|
||||||
|
ret = -ENODEV;
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dev_dbg(dev, "in map, found pctldev %s to handle function %s",
|
||||||
|
dev_name(pctldev->dev), map->function);
|
||||||
|
|
||||||
|
setting = kzalloc(sizeof(*setting), GFP_KERNEL);
|
||||||
|
if (setting == NULL) {
|
||||||
|
dev_err(dev,
|
||||||
|
"failed to alloc struct pinctrl_setting\n");
|
||||||
|
ret = -ENOMEM;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
setting->pctldev = pctldev;
|
||||||
|
ret = pinmux_map_to_setting(map, setting);
|
||||||
|
if (ret < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
list_add_tail(&setting->node, &p->settings);
|
||||||
|
|
||||||
num_maps++;
|
num_maps++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,6 +553,14 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)
|
||||||
list_add_tail(&p->node, &pinctrl_list);
|
list_add_tail(&p->node, &pinctrl_list);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
|
||||||
|
error:
|
||||||
|
list_for_each_entry(setting, &p->settings, node)
|
||||||
|
pinmux_free_setting(setting);
|
||||||
|
|
||||||
|
kfree(p);
|
||||||
|
|
||||||
|
return ERR_PTR(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -564,13 +584,18 @@ EXPORT_SYMBOL_GPL(pinctrl_get);
|
||||||
|
|
||||||
static void pinctrl_put_locked(struct pinctrl *p)
|
static void pinctrl_put_locked(struct pinctrl *p)
|
||||||
{
|
{
|
||||||
|
struct pinctrl_setting *setting, *n;
|
||||||
|
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (p->usecount)
|
if (p->usecount)
|
||||||
pr_warn("releasing pin control handle with active users!\n");
|
pr_warn("releasing pin control handle with active users!\n");
|
||||||
/* Free the groups and all acquired pins */
|
list_for_each_entry_safe(setting, n, &p->settings, node) {
|
||||||
pinmux_put(p);
|
pinmux_free_setting(setting);
|
||||||
|
list_del(&setting->node);
|
||||||
|
kfree(setting);
|
||||||
|
}
|
||||||
|
|
||||||
/* Remove from list */
|
/* Remove from list */
|
||||||
list_del(&p->node);
|
list_del(&p->node);
|
||||||
|
@ -592,18 +617,24 @@ EXPORT_SYMBOL_GPL(pinctrl_put);
|
||||||
|
|
||||||
static int pinctrl_enable_locked(struct pinctrl *p)
|
static int pinctrl_enable_locked(struct pinctrl *p)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
struct pinctrl_setting *setting;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (p->usecount++ == 0) {
|
if (p->usecount++ == 0) {
|
||||||
ret = pinmux_enable(p);
|
list_for_each_entry(setting, &p->settings, node) {
|
||||||
if (ret)
|
ret = pinmux_enable_setting(setting);
|
||||||
p->usecount--;
|
if (ret < 0) {
|
||||||
|
/* FIXME: Difficult to return to prev state */
|
||||||
|
p->usecount--;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -622,11 +653,14 @@ EXPORT_SYMBOL_GPL(pinctrl_enable);
|
||||||
|
|
||||||
static void pinctrl_disable_locked(struct pinctrl *p)
|
static void pinctrl_disable_locked(struct pinctrl *p)
|
||||||
{
|
{
|
||||||
|
struct pinctrl_setting *setting;
|
||||||
|
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (--p->usecount == 0) {
|
if (--p->usecount == 0) {
|
||||||
pinmux_disable(p);
|
list_for_each_entry(setting, &p->settings, node)
|
||||||
|
pinmux_disable_setting(setting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -857,27 +891,20 @@ static int pinctrl_maps_show(struct seq_file *s, void *what)
|
||||||
static int pinctrl_show(struct seq_file *s, void *what)
|
static int pinctrl_show(struct seq_file *s, void *what)
|
||||||
{
|
{
|
||||||
struct pinctrl *p;
|
struct pinctrl *p;
|
||||||
|
struct pinctrl_setting *setting;
|
||||||
|
|
||||||
seq_puts(s, "Requested pin control handlers their pinmux maps:\n");
|
seq_puts(s, "Requested pin control handlers their pinmux maps:\n");
|
||||||
|
|
||||||
mutex_lock(&pinctrl_mutex);
|
mutex_lock(&pinctrl_mutex);
|
||||||
|
|
||||||
list_for_each_entry(p, &pinctrl_list, node) {
|
list_for_each_entry(p, &pinctrl_list, node) {
|
||||||
struct pinctrl_dev *pctldev = p->pctldev;
|
seq_printf(s, "device: %s state: %s users: %u\n",
|
||||||
|
dev_name(p->dev), p->state, p->usecount);
|
||||||
|
|
||||||
if (!pctldev) {
|
list_for_each_entry(setting, &p->settings, node) {
|
||||||
seq_puts(s, "NO PIN CONTROLLER DEVICE\n");
|
seq_printf(s, " ");
|
||||||
continue;
|
pinmux_dbg_show(s, setting);
|
||||||
}
|
}
|
||||||
|
|
||||||
seq_printf(s, "device: %s",
|
|
||||||
pinctrl_dev_get_name(p->pctldev));
|
|
||||||
|
|
||||||
pinmux_dbg_show(s, p);
|
|
||||||
|
|
||||||
seq_printf(s, " users: %u map-> %s\n",
|
|
||||||
p->usecount,
|
|
||||||
p->dev ? dev_name(p->dev) : "(system)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&pinctrl_mutex);
|
mutex_unlock(&pinctrl_mutex);
|
||||||
|
|
|
@ -49,22 +49,31 @@ struct pinctrl_dev {
|
||||||
* struct pinctrl - per-device pin control state holder
|
* struct pinctrl - per-device pin control state holder
|
||||||
* @node: global list node
|
* @node: global list node
|
||||||
* @dev: the device using this pin control handle
|
* @dev: the device using this pin control handle
|
||||||
|
* @state: the state name passed to pinctrl_get()
|
||||||
* @usecount: the number of active users of this pin controller setting, used
|
* @usecount: the number of active users of this pin controller setting, used
|
||||||
* to keep track of nested use cases
|
* to keep track of nested use cases
|
||||||
* @pctldev: pin control device handling this pin control handle
|
* @settings: a list of settings for this device/state
|
||||||
* @groups: the group selectors for the pinmux device and
|
|
||||||
* selector combination handling this pinmux, this is a list that
|
|
||||||
* will be traversed on all pinmux operations such as
|
|
||||||
* get/put/enable/disable
|
|
||||||
*/
|
*/
|
||||||
struct pinctrl {
|
struct pinctrl {
|
||||||
struct list_head node;
|
struct list_head node;
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
|
const char *state;
|
||||||
unsigned usecount;
|
unsigned usecount;
|
||||||
|
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;
|
||||||
struct pinctrl_dev *pctldev;
|
struct pinctrl_dev *pctldev;
|
||||||
#ifdef CONFIG_PINMUX
|
unsigned group_selector;
|
||||||
struct list_head groups;
|
unsigned func_selector;
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
*
|
*
|
||||||
* Author: Linus Walleij <linus.walleij@linaro.org>
|
* Author: Linus Walleij <linus.walleij@linaro.org>
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
|
||||||
|
*
|
||||||
* License terms: GNU General Public License (GPL) version 2
|
* License terms: GNU General Public License (GPL) version 2
|
||||||
*/
|
*/
|
||||||
#define pr_fmt(fmt) "pinmux core: " fmt
|
#define pr_fmt(fmt) "pinmux core: " fmt
|
||||||
|
@ -28,19 +30,6 @@
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "pinmux.h"
|
#include "pinmux.h"
|
||||||
|
|
||||||
/**
|
|
||||||
* struct pinmux_group - group list item for pinmux groups
|
|
||||||
* @node: pinmux group list node
|
|
||||||
* @func_selector: the function selector for the pinmux device handling
|
|
||||||
* this pinmux
|
|
||||||
* @group_selector: the group selector for this group
|
|
||||||
*/
|
|
||||||
struct pinmux_group {
|
|
||||||
struct list_head node;
|
|
||||||
unsigned func_selector;
|
|
||||||
unsigned group_selector;
|
|
||||||
};
|
|
||||||
|
|
||||||
int pinmux_check_ops(struct pinctrl_dev *pctldev)
|
int pinmux_check_ops(struct pinctrl_dev *pctldev)
|
||||||
{
|
{
|
||||||
const struct pinmux_ops *ops = pctldev->desc->pmxops;
|
const struct pinmux_ops *ops = pctldev->desc->pmxops;
|
||||||
|
@ -244,164 +233,8 @@ int pinmux_gpio_direction(struct pinctrl_dev *pctldev,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static int pinmux_func_name_to_selector(struct pinctrl_dev *pctldev,
|
||||||
* acquire_pins() - acquire all the pins for a certain function on a pinmux
|
const char *function)
|
||||||
* @pctldev: the device to take the pins on
|
|
||||||
* @owner: a representation of the owner of this pin; typically the device
|
|
||||||
* name that controls its mux function
|
|
||||||
* @group_selector: the group selector containing the pins to acquire
|
|
||||||
*/
|
|
||||||
static int acquire_pins(struct pinctrl_dev *pctldev,
|
|
||||||
const char *owner,
|
|
||||||
unsigned group_selector)
|
|
||||||
{
|
|
||||||
const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
|
|
||||||
const unsigned *pins;
|
|
||||||
unsigned num_pins;
|
|
||||||
int ret;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
ret = pctlops->get_group_pins(pctldev, group_selector,
|
|
||||||
&pins, &num_pins);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
dev_dbg(pctldev->dev, "requesting the %u pins from group %u\n",
|
|
||||||
num_pins, group_selector);
|
|
||||||
|
|
||||||
/* Try to allocate all pins in this group, one by one */
|
|
||||||
for (i = 0; i < num_pins; i++) {
|
|
||||||
ret = pin_request(pctldev, pins[i], owner, NULL);
|
|
||||||
if (ret) {
|
|
||||||
dev_err(pctldev->dev,
|
|
||||||
"could not get request pin %d on device %s - conflicting mux mappings?\n",
|
|
||||||
pins[i],
|
|
||||||
pinctrl_dev_get_name(pctldev));
|
|
||||||
/* On error release all taken pins */
|
|
||||||
i--; /* this pin just failed */
|
|
||||||
for (; i >= 0; i--)
|
|
||||||
pin_free(pctldev, pins[i], NULL);
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* release_pins() - release pins taken by earlier acquirement
|
|
||||||
* @pctldev: the device to free the pins on
|
|
||||||
* @group_selector: the group selector containing the pins to free
|
|
||||||
*/
|
|
||||||
static void release_pins(struct pinctrl_dev *pctldev,
|
|
||||||
unsigned group_selector)
|
|
||||||
{
|
|
||||||
const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
|
|
||||||
const unsigned *pins;
|
|
||||||
unsigned num_pins;
|
|
||||||
int ret;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
ret = pctlops->get_group_pins(pctldev, group_selector,
|
|
||||||
&pins, &num_pins);
|
|
||||||
if (ret) {
|
|
||||||
dev_err(pctldev->dev, "could not get pins to release for group selector %d\n",
|
|
||||||
group_selector);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (i = 0; i < num_pins; i++)
|
|
||||||
pin_free(pctldev, pins[i], NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* pinmux_check_pin_group() - check function and pin group combo
|
|
||||||
* @pctldev: device to check the pin group vs function for
|
|
||||||
* @func_selector: the function selector to check the pin group for, we have
|
|
||||||
* already looked this up in the calling function
|
|
||||||
* @pin_group: the pin group to match to the function
|
|
||||||
*
|
|
||||||
* This function will check that the pinmux driver can supply the
|
|
||||||
* selected pin group for a certain function, returns the group selector if
|
|
||||||
* the group and function selector will work fine together, else returns
|
|
||||||
* negative
|
|
||||||
*/
|
|
||||||
static int pinmux_check_pin_group(struct pinctrl_dev *pctldev,
|
|
||||||
unsigned func_selector,
|
|
||||||
const char *pin_group)
|
|
||||||
{
|
|
||||||
const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
|
|
||||||
const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If the driver does not support different pin groups for the
|
|
||||||
* functions, we only support group 0, and assume this exists.
|
|
||||||
*/
|
|
||||||
if (!pctlops || !pctlops->list_groups)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Passing NULL (no specific group) will select the first and
|
|
||||||
* hopefully only group of pins available for this function.
|
|
||||||
*/
|
|
||||||
if (!pin_group) {
|
|
||||||
char const * const *groups;
|
|
||||||
unsigned num_groups;
|
|
||||||
|
|
||||||
ret = pmxops->get_function_groups(pctldev, func_selector,
|
|
||||||
&groups, &num_groups);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
if (num_groups < 1)
|
|
||||||
return -EINVAL;
|
|
||||||
ret = pinctrl_get_group_selector(pctldev, groups[0]);
|
|
||||||
if (ret < 0) {
|
|
||||||
dev_err(pctldev->dev,
|
|
||||||
"function %s wants group %s but the pin controller does not seem to have that group\n",
|
|
||||||
pmxops->get_function_name(pctldev, func_selector),
|
|
||||||
groups[0]);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (num_groups > 1)
|
|
||||||
dev_dbg(pctldev->dev,
|
|
||||||
"function %s support more than one group, default-selecting first group %s (%d)\n",
|
|
||||||
pmxops->get_function_name(pctldev, func_selector),
|
|
||||||
groups[0],
|
|
||||||
ret);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
dev_dbg(pctldev->dev,
|
|
||||||
"check if we have pin group %s on controller %s\n",
|
|
||||||
pin_group, pinctrl_dev_get_name(pctldev));
|
|
||||||
|
|
||||||
ret = pinctrl_get_group_selector(pctldev, pin_group);
|
|
||||||
if (ret < 0) {
|
|
||||||
dev_dbg(pctldev->dev,
|
|
||||||
"%s does not support pin group %s with function %s\n",
|
|
||||||
pinctrl_dev_get_name(pctldev),
|
|
||||||
pin_group,
|
|
||||||
pmxops->get_function_name(pctldev, func_selector));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* pinmux_search_function() - check pin control driver for a certain function
|
|
||||||
* @pctldev: device to check for function and position
|
|
||||||
* @map: function map containing the function and position to look for
|
|
||||||
* @func_selector: returns the applicable function selector if found
|
|
||||||
* @group_selector: returns the applicable group selector if found
|
|
||||||
*
|
|
||||||
* This will search the pinmux driver for an applicable
|
|
||||||
* function with a specific pin group, returns 0 if these can be mapped
|
|
||||||
* negative otherwise
|
|
||||||
*/
|
|
||||||
static int pinmux_search_function(struct pinctrl_dev *pctldev,
|
|
||||||
struct pinctrl_map const *map,
|
|
||||||
unsigned *func_selector,
|
|
||||||
unsigned *group_selector)
|
|
||||||
{
|
{
|
||||||
const struct pinmux_ops *ops = pctldev->desc->pmxops;
|
const struct pinmux_ops *ops = pctldev->desc->pmxops;
|
||||||
unsigned selector = 0;
|
unsigned selector = 0;
|
||||||
|
@ -410,155 +243,128 @@ static int pinmux_search_function(struct pinctrl_dev *pctldev,
|
||||||
while (ops->list_functions(pctldev, selector) >= 0) {
|
while (ops->list_functions(pctldev, selector) >= 0) {
|
||||||
const char *fname = ops->get_function_name(pctldev,
|
const char *fname = ops->get_function_name(pctldev,
|
||||||
selector);
|
selector);
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!strcmp(map->function, fname)) {
|
if (!strcmp(function, fname))
|
||||||
/* Found the function, check pin group */
|
return selector;
|
||||||
ret = pinmux_check_pin_group(pctldev, selector,
|
|
||||||
map->group);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
/* This function and group selector can be used */
|
|
||||||
*func_selector = selector;
|
|
||||||
*group_selector = ret;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
selector++;
|
selector++;
|
||||||
}
|
}
|
||||||
|
|
||||||
pr_err("%s does not support function %s\n",
|
pr_err("%s does not support function %s\n",
|
||||||
pinctrl_dev_get_name(pctldev), map->function);
|
pinctrl_dev_get_name(pctldev), function);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
int pinmux_map_to_setting(struct pinctrl_map const *map,
|
||||||
* pinmux_enable_muxmap() - enable a map entry for a certain pinmux
|
struct pinctrl_setting *setting)
|
||||||
*/
|
|
||||||
static int pinmux_enable_muxmap(struct pinctrl_dev *pctldev,
|
|
||||||
struct pinctrl *p,
|
|
||||||
struct device *dev,
|
|
||||||
const char *devname,
|
|
||||||
struct pinctrl_map const *map)
|
|
||||||
{
|
{
|
||||||
unsigned func_selector;
|
struct pinctrl_dev *pctldev = setting->pctldev;
|
||||||
unsigned group_selector;
|
const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
|
||||||
struct pinmux_group *grp;
|
const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
|
||||||
|
char const * const *groups;
|
||||||
|
unsigned num_groups;
|
||||||
int ret;
|
int ret;
|
||||||
|
const char *group;
|
||||||
|
int i;
|
||||||
|
const unsigned *pins;
|
||||||
|
unsigned num_pins;
|
||||||
|
|
||||||
/*
|
setting->func_selector =
|
||||||
* Note that we're not locking the pinmux mutex here, because
|
pinmux_func_name_to_selector(pctldev, map->function);
|
||||||
* this is only called at pinmux initialization time when it
|
if (setting->func_selector < 0)
|
||||||
* has not been added to any list and thus is not reachable
|
return setting->func_selector;
|
||||||
* by anyone else.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (p->pctldev && p->pctldev != pctldev) {
|
ret = pmxops->get_function_groups(pctldev, setting->func_selector,
|
||||||
dev_err(pctldev->dev,
|
&groups, &num_groups);
|
||||||
"different pin control devices given for device %s, function %s\n",
|
|
||||||
devname, map->function);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
p->dev = dev;
|
|
||||||
p->pctldev = pctldev;
|
|
||||||
|
|
||||||
/* Now go into the driver and try to match a function and group */
|
|
||||||
ret = pinmux_search_function(pctldev, map, &func_selector,
|
|
||||||
&group_selector);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
if (!num_groups)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
/* Now add this group selector, we may have many of them */
|
if (map->group) {
|
||||||
grp = kmalloc(sizeof(*grp), GFP_KERNEL);
|
bool found = false;
|
||||||
if (!grp)
|
group = map->group;
|
||||||
return -ENOMEM;
|
for (i = 0; i < num_groups; i++) {
|
||||||
grp->func_selector = func_selector;
|
if (!strcmp(group, groups[i])) {
|
||||||
grp->group_selector = group_selector;
|
found = true;
|
||||||
ret = acquire_pins(pctldev, devname, group_selector);
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
return -EINVAL;
|
||||||
|
} else {
|
||||||
|
group = groups[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
setting->group_selector =
|
||||||
|
pinctrl_get_group_selector(pctldev, group);
|
||||||
|
if (setting->group_selector < 0)
|
||||||
|
return setting->group_selector;
|
||||||
|
|
||||||
|
ret = pctlops->get_group_pins(pctldev, setting->group_selector,
|
||||||
|
&pins, &num_pins);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
kfree(grp);
|
dev_err(pctldev->dev,
|
||||||
return ret;
|
"could not get pins for device %s group selector %d\n",
|
||||||
|
pinctrl_dev_get_name(pctldev), setting->group_selector);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Try to allocate all pins in this group, one by one */
|
||||||
|
for (i = 0; i < num_pins; i++) {
|
||||||
|
ret = pin_request(pctldev, pins[i], map->dev_name, NULL);
|
||||||
|
if (ret) {
|
||||||
|
dev_err(pctldev->dev,
|
||||||
|
"could not get request pin %d on device %s\n",
|
||||||
|
pins[i], pinctrl_dev_get_name(pctldev));
|
||||||
|
/* On error release all taken pins */
|
||||||
|
i--; /* this pin just failed */
|
||||||
|
for (; i >= 0; i--)
|
||||||
|
pin_free(pctldev, pins[i], NULL);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
list_add_tail(&grp->node, &p->groups);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void pinmux_free_setting(struct pinctrl_setting const *setting)
|
||||||
* pinmux_apply_muxmap() - apply a certain mux mapping entry
|
|
||||||
*/
|
|
||||||
int pinmux_apply_muxmap(struct pinctrl_dev *pctldev,
|
|
||||||
struct pinctrl *p,
|
|
||||||
struct device *dev,
|
|
||||||
const char *devname,
|
|
||||||
struct pinctrl_map const *map)
|
|
||||||
{
|
{
|
||||||
|
struct pinctrl_dev *pctldev = setting->pctldev;
|
||||||
|
const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
|
||||||
|
const unsigned *pins;
|
||||||
|
unsigned num_pins;
|
||||||
int ret;
|
int ret;
|
||||||
|
int i;
|
||||||
|
|
||||||
ret = pinmux_enable_muxmap(pctldev, p, dev,
|
ret = pctlops->get_group_pins(pctldev, setting->group_selector,
|
||||||
devname, map);
|
&pins, &num_pins);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pinmux_put(p);
|
dev_err(pctldev->dev,
|
||||||
return ret;
|
"could not get pins for device %s group selector %d\n",
|
||||||
|
pinctrl_dev_get_name(pctldev), setting->group_selector);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
for (i = 0; i < num_pins; i++)
|
||||||
|
pin_free(pctldev, pins[i], NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
int pinmux_enable_setting(struct pinctrl_setting const *setting)
|
||||||
* pinmux_put() - free up the pinmux portions of a pin controller handle
|
|
||||||
*/
|
|
||||||
void pinmux_put(struct pinctrl *p)
|
|
||||||
{
|
{
|
||||||
struct list_head *node, *tmp;
|
struct pinctrl_dev *pctldev = setting->pctldev;
|
||||||
|
|
||||||
list_for_each_safe(node, tmp, &p->groups) {
|
|
||||||
struct pinmux_group *grp =
|
|
||||||
list_entry(node, struct pinmux_group, node);
|
|
||||||
/* Release all pins taken by this group */
|
|
||||||
release_pins(p->pctldev, grp->group_selector);
|
|
||||||
list_del(node);
|
|
||||||
kfree(grp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* pinmux_enable() - enable the pinmux portion of a pin control handle
|
|
||||||
*/
|
|
||||||
int pinmux_enable(struct pinctrl *p)
|
|
||||||
{
|
|
||||||
struct pinctrl_dev *pctldev = p->pctldev;
|
|
||||||
const struct pinmux_ops *ops = pctldev->desc->pmxops;
|
const struct pinmux_ops *ops = pctldev->desc->pmxops;
|
||||||
struct pinmux_group *grp;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
list_for_each_entry(grp, &p->groups, node) {
|
return ops->enable(pctldev, setting->func_selector,
|
||||||
ret = ops->enable(pctldev, grp->func_selector,
|
setting->group_selector);
|
||||||
grp->group_selector);
|
|
||||||
if (ret)
|
|
||||||
/*
|
|
||||||
* TODO: call disable() on all groups we called
|
|
||||||
* enable() on to this point?
|
|
||||||
*/
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void pinmux_disable_setting(struct pinctrl_setting const *setting)
|
||||||
* pinmux_disable() - disable the pinmux portions of a pin control handle
|
|
||||||
*/
|
|
||||||
void pinmux_disable(struct pinctrl *p)
|
|
||||||
{
|
{
|
||||||
struct pinctrl_dev *pctldev = p->pctldev;
|
struct pinctrl_dev *pctldev = setting->pctldev;
|
||||||
const struct pinmux_ops *ops = pctldev->desc->pmxops;
|
const struct pinmux_ops *ops = pctldev->desc->pmxops;
|
||||||
struct pinmux_group *grp;
|
|
||||||
|
|
||||||
list_for_each_entry(grp, &p->groups, node) {
|
ops->disable(pctldev, setting->func_selector, setting->group_selector);
|
||||||
ops->disable(pctldev, grp->func_selector,
|
|
||||||
grp->group_selector);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_FS
|
#ifdef CONFIG_DEBUG_FS
|
||||||
|
@ -635,30 +441,18 @@ static int pinmux_pins_show(struct seq_file *s, void *what)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pinmux_dbg_show(struct seq_file *s, struct pinctrl *p)
|
void pinmux_dbg_show(struct seq_file *s, struct pinctrl_setting const *setting)
|
||||||
{
|
{
|
||||||
struct pinctrl_dev *pctldev = p->pctldev;
|
struct pinctrl_dev *pctldev = setting->pctldev;
|
||||||
const struct pinmux_ops *pmxops;
|
const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
|
||||||
const struct pinctrl_ops *pctlops;
|
const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
|
||||||
struct pinmux_group *grp;
|
|
||||||
const char *sep = "";
|
|
||||||
|
|
||||||
pmxops = pctldev->desc->pmxops;
|
seq_printf(s, "controller: %s group: %s (%u) function: %s (%u)\n",
|
||||||
pctlops = pctldev->desc->pctlops;
|
pinctrl_dev_get_name(pctldev),
|
||||||
|
pctlops->get_group_name(pctldev, setting->group_selector),
|
||||||
seq_printf(s, " groups: [");
|
setting->group_selector,
|
||||||
list_for_each_entry(grp, &p->groups, node) {
|
pmxops->get_function_name(pctldev, setting->func_selector),
|
||||||
seq_printf(s, "%s%s (%u)=%s (%u)",
|
setting->func_selector);
|
||||||
sep,
|
|
||||||
pctlops->get_group_name(pctldev,
|
|
||||||
grp->group_selector),
|
|
||||||
grp->group_selector,
|
|
||||||
pmxops->get_function_name(pctldev,
|
|
||||||
grp->func_selector),
|
|
||||||
grp->func_selector);
|
|
||||||
sep = ", ";
|
|
||||||
}
|
|
||||||
seq_printf(s, " ]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pinmux_functions_open(struct inode *inode, struct file *file)
|
static int pinmux_functions_open(struct inode *inode, struct file *file)
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#ifdef CONFIG_PINMUX
|
#ifdef CONFIG_PINMUX
|
||||||
|
|
||||||
int pinmux_check_ops(struct pinctrl_dev *pctldev);
|
int pinmux_check_ops(struct pinctrl_dev *pctldev);
|
||||||
|
|
||||||
int pinmux_request_gpio(struct pinctrl_dev *pctldev,
|
int pinmux_request_gpio(struct pinctrl_dev *pctldev,
|
||||||
struct pinctrl_gpio_range *range,
|
struct pinctrl_gpio_range *range,
|
||||||
unsigned pin, unsigned gpio);
|
unsigned pin, unsigned gpio);
|
||||||
|
@ -21,21 +22,16 @@ void pinmux_free_gpio(struct pinctrl_dev *pctldev, unsigned pin,
|
||||||
int pinmux_gpio_direction(struct pinctrl_dev *pctldev,
|
int pinmux_gpio_direction(struct pinctrl_dev *pctldev,
|
||||||
struct pinctrl_gpio_range *range,
|
struct pinctrl_gpio_range *range,
|
||||||
unsigned pin, bool input);
|
unsigned pin, bool input);
|
||||||
static inline void pinmux_init_pinctrl_handle(struct pinctrl *p)
|
|
||||||
{
|
int pinmux_map_to_setting(struct pinctrl_map const *map,
|
||||||
INIT_LIST_HEAD(&p->groups);
|
struct pinctrl_setting *setting);
|
||||||
}
|
void pinmux_free_setting(struct pinctrl_setting const *setting);
|
||||||
int pinmux_apply_muxmap(struct pinctrl_dev *pctldev,
|
int pinmux_enable_setting(struct pinctrl_setting const *setting);
|
||||||
struct pinctrl *p,
|
void pinmux_disable_setting(struct pinctrl_setting const *setting);
|
||||||
struct device *dev,
|
|
||||||
const char *devname,
|
void pinmux_dbg_show(struct seq_file *s, struct pinctrl_setting const *setting);
|
||||||
struct pinctrl_map const *map);
|
|
||||||
void pinmux_put(struct pinctrl *p);
|
|
||||||
int pinmux_enable(struct pinctrl *p);
|
|
||||||
void pinmux_disable(struct pinctrl *p);
|
|
||||||
void pinmux_init_device_debugfs(struct dentry *devroot,
|
void pinmux_init_device_debugfs(struct dentry *devroot,
|
||||||
struct pinctrl_dev *pctldev);
|
struct pinctrl_dev *pctldev);
|
||||||
void pinmux_dbg_show(struct seq_file *s, struct pinctrl *p);
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -64,28 +60,23 @@ static inline int pinmux_gpio_direction(struct pinctrl_dev *pctldev,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void pinmux_init_pinctrl_handle(struct pinctrl *p)
|
static inline int pinmux_map_to_setting(struct pinctrl_map const *map,
|
||||||
{
|
struct pinctrl_setting *setting)
|
||||||
}
|
|
||||||
|
|
||||||
static inline int pinmux_apply_muxmap(struct pinctrl_dev *pctldev,
|
|
||||||
struct pinctrl *p,
|
|
||||||
struct device *dev,
|
|
||||||
const char *devname,
|
|
||||||
struct pinctrl_map const *map)
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void pinmux_put(struct pinctrl *p)
|
static inline void pinmux_free_setting(struct pinctrl_setting const *setting)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int pinmux_enable(struct pinctrl *p)
|
static inline int pinmux_enable_setting(struct pinctrl_setting const *setting)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void pinmux_disable(struct pinctrl *p)
|
static inline void pinmux_disable_setting(
|
||||||
|
struct pinctrl_setting const *setting)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user