Commit ca53c5f1 authored by Linus Walleij's avatar Linus Walleij

pinctrl: conjure names for unnamed pins

If pins with blank names are registered, we assign them names on-the-fly
on the form "PINn" where n is the pin number for that pin on the specific
controller.
Acked-by: default avatarStephen Warren <swarren@nvidia.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 23750196
...@@ -158,6 +158,8 @@ static void pinctrl_free_pindescs(struct pinctrl_dev *pctldev, ...@@ -158,6 +158,8 @@ static void pinctrl_free_pindescs(struct pinctrl_dev *pctldev,
if (pindesc != NULL) { if (pindesc != NULL) {
radix_tree_delete(&pctldev->pin_desc_tree, radix_tree_delete(&pctldev->pin_desc_tree,
pins[i].number); pins[i].number);
if (pindesc->dynamic_name)
kfree(pindesc->name);
} }
kfree(pindesc); kfree(pindesc);
} }
...@@ -186,13 +188,20 @@ static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev, ...@@ -186,13 +188,20 @@ static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev,
pindesc->pctldev = pctldev; pindesc->pctldev = pctldev;
/* Copy basic pin info */ /* Copy basic pin info */
pindesc->name = name; if (pindesc->name) {
pindesc->name = name;
} else {
pindesc->name = kasprintf(GFP_KERNEL, "PIN%u", number);
if (pindesc->name == NULL)
return -ENOMEM;
pindesc->dynamic_name = true;
}
spin_lock(&pctldev->pin_desc_tree_lock); spin_lock(&pctldev->pin_desc_tree_lock);
radix_tree_insert(&pctldev->pin_desc_tree, number, pindesc); radix_tree_insert(&pctldev->pin_desc_tree, number, pindesc);
spin_unlock(&pctldev->pin_desc_tree_lock); spin_unlock(&pctldev->pin_desc_tree_lock);
pr_debug("registered pin %d (%s) on %s\n", pr_debug("registered pin %d (%s) on %s\n",
number, name ? name : "(unnamed)", pctldev->desc->name); number, pindesc->name, pctldev->desc->name);
return 0; return 0;
} }
......
...@@ -52,6 +52,7 @@ struct pinctrl_dev { ...@@ -52,6 +52,7 @@ struct pinctrl_dev {
* @pctldev: corresponding pin control device * @pctldev: corresponding pin control device
* @name: a name for the pin, e.g. the name of the pin/pad/finger on a * @name: a name for the pin, e.g. the name of the pin/pad/finger on a
* datasheet or such * datasheet or such
* @dynamic_name: if the name of this pin was dynamically allocated
* @lock: a lock to protect the descriptor structure * @lock: a lock to protect the descriptor structure
* @mux_requested: whether the pin is already requested by pinmux or not * @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 * @mux_function: a named muxing function for the pin that will be passed to
...@@ -60,6 +61,7 @@ struct pinctrl_dev { ...@@ -60,6 +61,7 @@ struct pinctrl_dev {
struct pin_desc { struct pin_desc {
struct pinctrl_dev *pctldev; struct pinctrl_dev *pctldev;
const char *name; const char *name;
bool dynamic_name;
spinlock_t lock; spinlock_t lock;
/* These fields only added when supporting pinmux drivers */ /* These fields only added when supporting pinmux drivers */
#ifdef CONFIG_PINMUX #ifdef CONFIG_PINMUX
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment