pinctrl: API change, config in mapping table
Subsystems (5)
cover pinctrl: API change, config in mapping table
These changes:
* Rework the pinctrl API as we discussed at Linaro Connect.
* Allow specifying pin config settings in the mapping table in addition to mux options, as we agreed upon at Linaro Connect.
* Various cleanups and refactorings aimed at supporting the changes above.
TODO in this patch set:
* Test build of non-Tegra platforms.
* Test build with pinmux/pinconf disabled.
... but I figure it was a good idea to send out for comments ASAP.
TODO in future patch sets:
* Implement device tree support in pinctrl core and a pinctrl driver.
* Remove pin config APIs from pinctrl now that the mapping table supports pin config?
I've tested this all on a couple Tegra boards, including hacking in a single pin config and dummy state mapping table entry. I've got patches for Tegra boards that use the explicit pin config APIs, and need to convert them to using the pin config mapping table entries for more complete testing.
(In the diffstat below, I /think/ the first 19 patches are a net negative in line-count, and only the last patch, which implements a new feature, adds a significant number of lines)
Stephen Warren (20):
pinctrl: pinctrl_register_mappings() shouldn't be __init
pinctrl: use list_add_tail instead of list_add
pinctrl: Store mapping table as a list of chunks
pinctrl: Record a pin owner, not mux function, when requesting pins
pinctrl: Re-order pinmux.[ch] to match each-other
pinctrl: Re-order pinconf.[ch] to match each-other
pinctrl: core.c/h cleanups
pinctrl: Assume map table entries can't have a NULL name field
pinctrl: Disallow map table entries with NULL dev_name field
pinctrl: Assume map table entries can't have a NULL ctrl_dev_name
field
pinctrl: Downgrade pinctrl_get warning when no maps are found
pinctrl: Use dev_*() instead of pr_*(), add some msgs, minor cleanups
pinctrl: Error if mapping table's control dev can't be found
pinctrl: Allocate sizeof(*p) instead of sizeof(struct foo)
pinctrl: Fix and simplify locking
pinctrl: Refactor struct pinctrl handling in core.c vs pinmux.c
pinctrl: Add usecount to pins for muxing
pinctrl: Fix pinconf_groups_show() to emit newline
pinctrl: API changes to support multiple states per device
pinctrl: Enhance mapping table to support pin config operations
Documentation/pinctrl.txt | 244 +++++++---- arch/arm/mach-u300/core.c | 28 +- drivers/pinctrl/core.c | 936 +++++++++++++++++++++---------------- drivers/pinctrl/core.h | 100 +++-- drivers/pinctrl/pinconf.c | 288 ++++++++++-- drivers/pinctrl/pinconf.h | 45 ++- drivers/pinctrl/pinmux.c | 578 ++++++++--------------- drivers/pinctrl/pinmux.h | 61 ++-- drivers/tty/serial/sirfsoc_uart.c | 12 +- include/linux/pinctrl/consumer.h | 55 ++- include/linux/pinctrl/machine.h | 131 ++++-- include/linux/pinctrl/pinctrl.h | 1 - 12 files changed, 1438 insertions(+), 1041 deletions(-)
Signature · 1 line
1.7.5.4
PATCH 1/20 pinctrl: pinctrl_register_mappings() shouldn't be __init
It may be common for pinctrl_register_mappings() to be used from __init context, but there's no reason that additional mappings shouldn't be added at a later point, e.g. if loading modules that add pin controllers and their mapping tables.
--- drivers/pinctrl/core.c | 15 +++++---------- 1 files changed, 5 insertions(+), 10 deletions(-)
drivers/pinctrl/core.c +5 -10
@@ -641,18 +641,13 @@ EXPORT_SYMBOL_GPL(pinctrl_disable);/** * pinctrl_register_mappings() - register a set of pin controller mappings -* @maps: the pincontrol mappings table to register, this should be marked with -* __initdata so it can be discarded after boot, this function will -* perform a shallow copy for the mapping entries. +* @maps: the pincontrol mappings table to register. This should probably be +* marked with __initdata so it can be discarded after boot. This +* function will perform a shallow copy for the mapping entries. * @num_maps: the number of maps in the mapping table -* -* Only call this once during initialization of your machine, the function is -* tagged as __init and won't be callable after init has completed. The map -* passed into this function will be owned by the pinmux core and cannot be -* freed. */ -int __init pinctrl_register_mappings (struct pinctrl_map const *maps, -unsigned num_maps) +int pinctrl_register_mappings (struct pinctrl_map const *maps, +unsigned num_maps) {void *tmp_maps;int i;
Signature · 1 line
1.7.5.4
Re: [PATCH 01/20] pinctrl: pinctrl_register_mappings() shouldn't be __init
Quoted 6 lines · Stephen Warren
It may be common for
pinctrl_register_mappings()to be used from__initcontext, but there's no reason that additional mappings shouldn't be added at a later point, e.g. if loading modules that add pin controllers and their mapping tables.Signed-off-by Stephen Warren <[email protected]>
OK applied.
Thanks,
Linus Walleij
PATCH 2/20 pinctrl: use list_add_tail instead of list_add
In reply to Stephen WarrenThis mostly makes debugfs files print things in the order that they were added or acquired, which just feels a little more consistent.
--- drivers/pinctrl/core.c | 8 ++++---- drivers/pinctrl/pinmux.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/pinctrl/core.c +4 -4
@@ -309,7 +309,7 @@ void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev, struct pinctrl_gpio_range *range) {mutex_lock (&pctldev->gpio_ranges_lock); -list_add (&range->node, &pctldev->gpio_ranges); +list_add_tail (&range->node, &pctldev->gpio_ranges);mutex_unlock (&pctldev->gpio_ranges_lock); }
@@ -569,7 +569,7 @@ struct pinctrl *pinctrl_get(struct device *dev, const char *name)/* Add the pinmux to the global list */ mutex_lock (&pinctrl_list_mutex); -list_add (&p->node, &pinctrl_list); +list_add_tail (&p->node, &pinctrl_list);mutex_unlock (&pinctrl_list_mutex);return p;
@@ -749,7 +749,7 @@ static int pinctrl_hog_map(struct pinctrl_dev *pctldev,dev_info (pctldev->dev,"hogged map %s, function %s\n" , map->name, map->function);mutex_lock (&pctldev->pinctrl_hogs_lock); -list_add (&hog->node, &pctldev->pinctrl_hogs); +list_add_tail (&hog->node, &pctldev->pinctrl_hogs);mutex_unlock (&pctldev->pinctrl_hogs_lock);return 0 ;
@@ -1197,7 +1197,7 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,pinctrl_init_device_debugfs (pctldev);mutex_lock (&pinctrldev_list_mutex); -list_add (&pctldev->node, &pinctrldev_list); +list_add_tail (&pctldev->node, &pinctrldev_list);mutex_unlock (&pinctrldev_list_mutex);pinctrl_hog_maps (pctldev);return pctldev;
drivers/pinctrl/pinmux.c +1 -1
@@ -480,7 +480,7 @@ static int pinmux_enable_muxmap(struct pinctrl_dev *pctldev,kfree (grp);return ret; } -list_add (&grp->node, &p->groups); +list_add_tail (&grp->node, &p->groups);return 0 ; }
Signature · 1 line
1.7.5.4
Re: [PATCH 02/20] pinctrl: use list_add_tail instead of list_add
Quoted 4 lines · Stephen Warren
This mostly makes debugfs files print things in the order that they were added or acquired, which just feels a little more consistent.
Signed-off-by Stephen Warren <[email protected]>
OK applied.
Thanks,
Linus Walleij
PATCH 3/20 pinctrl: Store mapping table as a list of chunks
In reply to Stephen WarrenInstead of storing a single array of mapping table entries, which requires realloc()ing that array each time it's extended and copying the new data, simply store a list of pointers to the individual chunks. This also removes the need to copy the mapping table at all; a pointer is maintained to the original table, this saving memory.
A macro for_each_maps() is introduced to hide the additional complexity of iterating over the map entries.
This change will also simplify removing chunks of entries from the mapping table. This isn't important right now, but will be in the future, when mapping table entries are dynamically added when parsing them from the device tree, and removed when drivers no longer need to interact with pinctrl.
---
v2: Fixed kzalloc size parameter in pinctrl_register_mappings(),
add pr_error on kzalloc() failure, keep pinctrl_get() docs with pinctrl_get() not pinctrl_get_locked(), make pinctrl_get_locked() static, use list_add_tail instead of list_add, continue to duplicate mapping table, don't remove __initdata from u300 mapping table.
--- drivers/pinctrl/core.c | 120 ++++++++++++++++++++++++++++++------------------ 1 files changed, 75 insertions(+), 45 deletions(-)
drivers/pinctrl/core.c +75 -45
@@ -7,6 +7,8 @@* * Author: Linus Walleij <[email protected]> * +* Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved. +* * License terms: GNU General Public License (GPL) version 2 */ #define pr_fmt (fmt) "pinctrl core: " fmt
@@ -31,6 +33,18 @@#include "pinconf.h" /** +* struct pinctrl_maps - a list item containing part of the mapping table +* @node: mapping table list node +* @maps: array of mapping table entries +* @num_maps: the number of entries in @maps +*/ +struct pinctrl_maps { +struct list_head node; +struct pinctrl_map const *maps; +unsigned num_maps; +}; + +/** * struct pinctrl_hog - a list item to stash control hogs * @node: pin control hog list node * @map: map entry responsible for this hogging
@@ -51,8 +65,14 @@ static DEFINE_MUTEX(pinctrl_list_mutex);static LIST_HEAD (pinctrl_list);/* Global pinctrl maps */ -static struct pinctrl_map *pinctrl_maps; -static unsigned pinctrl_maps_num; +static DEFINE_MUTEX (pinctrl_maps_mutex); +static LIST_HEAD (pinctrl_maps); + +#define for_each_maps (_maps_node_, _i_, _map_) \ + list_for_each_entry(_maps_node_, &pinctrl_maps, node) \ + for (_i_ = 0, _map_ = &_maps_node_->maps[_i_]; \ + _i_ < _maps_node_->num_maps; \ + i++, _map_ = &_maps_node_->maps[_i_])const char *pinctrl_dev_get_name (struct pinctrl_dev *pctldev) {
@@ -454,23 +474,17 @@ int pinctrl_gpio_direction_output(unsigned gpio) }EXPORT_SYMBOL_GPL (pinctrl_gpio_direction_output); -/** -* pinctrl_get() - retrieves the pin controller handle for a certain device -* @dev: the device to get the pin controller handle for -* @name: an optional specific control mapping name or NULL, the name is only -* needed if you want to have more than one mapping per device, or if you -* need an anonymous pin control (not tied to any specific device) -*/ -struct pinctrl *pinctrl_get (struct device *dev,const char *name) +static struct pinctrl *pinctrl_get_locked (struct device *dev,const char *name) { -struct pinctrl_map const *map =NULL ;struct pinctrl_dev *pctldev =NULL ;const char *devname =NULL ;struct pinctrl *p;bool found_map;unsigned num_maps =0 ;int ret = -ENODEV ; +struct pinctrl_maps *maps_node;int i; +struct pinctrl_map const *map;/* We must have dev or ID or both */ if (!dev && !name)
@@ -494,8 +508,7 @@ struct pinctrl *pinctrl_get(struct device *dev, const char *name)pinmux_init_pinctrl_handle (p);/* Iterate over the pin control maps to locate the right ones */ -for (i =0 ; i < pinctrl_maps_num; i++) { - map = &pinctrl_maps[i]; +for_each_maps (maps_node, i, map) { found_map = false;/*
@@ -515,7 +528,6 @@ struct pinctrl *pinctrl_get(struct device *dev, const char *name)pr_debug ("in map, found pctldev %s to handle function %s" ,dev_name (pctldev->dev), map->function); -/* * If we're looking for a specific named map, this must match, * else we loop and look for the next.
@@ -574,6 +586,24 @@ struct pinctrl *pinctrl_get(struct device *dev, const char *name)return p; } + +/** +* pinctrl_get() - retrieves the pin controller handle for a certain device +* @dev: the device to get the pin controller handle for +* @name: an optional specific control mapping name or NULL, the name is only +* needed if you want to have more than one mapping per device, or if you +* need an anonymous pin control (not tied to any specific device) +*/ +struct pinctrl *pinctrl_get (struct device *dev,const char *name) +{ +struct pinctrl *p; + +mutex_lock (&pinctrl_maps_mutex); + p =pinctrl_get_locked (dev, name); +mutex_unlock (&pinctrl_maps_mutex); + +return p; +}EXPORT_SYMBOL_GPL (pinctrl_get);/**
@@ -649,8 +679,8 @@ EXPORT_SYMBOL_GPL(pinctrl_disable);int pinctrl_register_mappings (struct pinctrl_map const *maps,unsigned num_maps) { -void *tmp_maps;int i; +struct pinctrl_maps *maps_node;pr_debug ("add %d pinmux maps\n" , num_maps);
@@ -684,31 +714,23 @@ int pinctrl_register_mappings(struct pinctrl_map const *maps, maps[i].function); } -/* -* Make a copy of the map array - string pointers will end up in the -* kernel const section anyway so these do not need to be deep copied. -*/ -if (!pinctrl_maps_num) { -/* On first call, just copy them */ - tmp_maps =kmemdup (maps, -sizeof (struct pinctrl_map ) * num_maps, -GFP_KERNEL ); -if (!tmp_maps) -return -ENOMEM ; - }else { -/* Subsequent calls, reallocate array to new size */ -size_t oldsize =sizeof (struct pinctrl_map ) * pinctrl_maps_num; -size_t newsize =sizeof (struct pinctrl_map ) * num_maps; + maps_node =kzalloc (sizeof (*maps_node),GFP_KERNEL ); +if (!maps_node) { +pr_err ("failed to alloc struct pinctrl_maps\n" ); +return -ENOMEM ; + } - tmp_maps =krealloc (pinctrl_maps, - oldsize + newsize,GFP_KERNEL ); -if (!tmp_maps) -return -ENOMEM ; -memcpy ((tmp_maps + oldsize), maps, newsize); + maps_node->num_maps = num_maps; + maps_node->maps =kmemdup (maps,sizeof (*maps) * num_maps,GFP_KERNEL ); +if (!maps_node->maps) { +kfree (maps_node); +return -ENOMEM ; } - pinctrl_maps = tmp_maps; - pinctrl_maps_num += num_maps; +mutex_lock (&pinctrl_maps_mutex); +list_add_tail (&maps_node->node, &pinctrl_maps); +mutex_unlock (&pinctrl_maps_mutex); +return 0 ; }
@@ -724,7 +746,7 @@ static int pinctrl_hog_map(struct pinctrl_dev *pctldev,if (!hog)return -ENOMEM ; - p =pinctrl_get (pctldev->dev, map->name); + p =pinctrl_get_locked (pctldev->dev, map->name);if (IS_ERR (p)) {kfree (hog); dev_err(pctldev->dev,
@@ -768,23 +790,28 @@ int pinctrl_hog_maps(struct pinctrl_dev *pctldev)struct device *dev = pctldev->dev;const char *devname =dev_name (dev);int ret; +struct pinctrl_maps *maps_node;int i; +struct pinctrl_map const *map;INIT_LIST_HEAD (&pctldev->pinctrl_hogs);mutex_init (&pctldev->pinctrl_hogs_lock); -for (i =0 ; i < pinctrl_maps_num; i++) { -struct pinctrl_map const *map = &pinctrl_maps[i]; - +mutex_lock (&pinctrl_maps_mutex); +for_each_maps (maps_node, i, map) {if (map->ctrl_dev_name && !strcmp (map->ctrl_dev_name, devname) && !strcmp (map->dev_name, devname)) {/* OK time to hog! */ ret =pinctrl_hog_map (pctldev, map); -if (ret) +if (ret) { +mutex_unlock (&pinctrl_maps_mutex);return ret; + } } } +mutex_unlock (&pinctrl_maps_mutex); +return 0 ; }
@@ -900,13 +927,14 @@ static int pinctrl_gpioranges_show(struct seq_file *s, void *what)static int pinctrl_maps_show (struct seq_file *s,void *what) { +struct pinctrl_maps *maps_node;int i; +struct pinctrl_map const *map;seq_puts (s,"Pinctrl maps:\n" ); -for (i =0 ; i < pinctrl_maps_num; i++) { -struct pinctrl_map const *map = &pinctrl_maps[i]; - +mutex_lock (&pinctrl_maps_mutex); +for_each_maps (maps_node, i, map) {seq_printf (s,"%s:\n" , map->name);if (map->dev_name) seq_printf(s, " device: %s\n",
@@ -919,6 +947,8 @@ static int pinctrl_maps_show(struct seq_file *s, void *what)seq_printf (s," group: %s\n" , map->group ? map->group :"(default)" ); } +mutex_unlock (&pinctrl_maps_mutex); +return 0 ; }
Signature · 1 line
1.7.5.4
Re: [PATCH 03/20] pinctrl: Store mapping table as a list of chunks
Quoted 15 lines · Stephen Warren
Instead of storing a single array of mapping table entries, which requires realloc()ing that array each time it's extended and copying the new data, simply store a list of pointers to the individual chunks. This also removes the need to copy the mapping table at all; a pointer is maintained to the original table, this saving memory.
A macro
for_each_maps()is introduced to hide the additional complexity of iterating over the map entries.This change will also simplify removing chunks of entries from the mapping table. This isn't important right now, but will be in the future, when mapping table entries are dynamically added when parsing them from the device tree, and removed when drivers no longer need to interact with pinctrl.
Quoted 7 lines
Signed-off-by Stephen Warren <[email protected]>---
v2: Fixed kzalloc size parameter inpinctrl_register_mappings(), addpr_erroronkzalloc()failure, keeppinctrl_get()docs withpinctrl_get()notpinctrl_get_locked(), makepinctrl_get_locked()static, uselist_add_tailinstead oflist_add, continue to duplicate mapping table, don't remove__initdatafrom u300 mapping table.
Brilliant, applied.
Also tested on U300 up to this point, everything works just fine.
Thanks,
Linus Walleij
PATCH 4/20 pinctrl: Record a pin owner, not mux function, when requesting pins
In reply to Stephen WarrenWhen pins are requested/acquired/got, some device becomes the owner of their mux setting. At this point, it isn't certain which mux function will be selected for the pin, since this may vary between each of the device's states in the pinctrl mapping table. As such, we should record the owning device, not what we think the initial mux setting will be, when requesting pins.
This doesn't make a lot of difference right now since pinctrl_get gets only one single device/state combination, but this will make a difference when pinctrl_get gets all states, and pinctrl_select_state can switch between states.
--- drivers/pinctrl/core.h | 2 +- drivers/pinctrl/pinmux.c | 71 ++++++++++++++++++++-------------------------- 2 files changed, 32 insertions(+), 41 deletions(-)
drivers/pinctrl/core.h +1 -1
@@ -94,7 +94,7 @@ struct pin_desc {spinlock_t lock;/* These fields only added when supporting pinmux drivers */ #ifdef CONFIG_PINMUX -const char *mux_function; +const char *owner;#endif };
drivers/pinctrl/pinmux.c +31 -40
190 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Re: [PATCH 04/20] pinctrl: Record a pin owner, not mux function, when requesting pins
Quoted 7 lines · Stephen Warren
When pins are requested/acquired/got, some device becomes the owner of their mux setting. At this point, it isn't certain which mux function will be selected for the pin, since this may vary between each of the device's states in the pinctrl mapping table. As such, we should record the owning device, not what we think the initial mux setting will be, when requesting pins.
Quoted 6 lines
This doesn't make a lot of difference right now since
pinctrl_getgets only one single device/state combination, but this will make a difference whenpinctrl_getgets all states, andpinctrl_select_statecan switch between states.Signed-off-by Stephen Warren <[email protected]>
Mostly a rename then, OK...
drivers/pinctrl/pinmux.c static int pin_request(struct pinctrl_dev *pctldev, · line 73
Quoted 9 lines
drivers/pinctrl/pinmux.c +0
-5@@ -66,19 +65,14 @@ static int pin_request(struct pinctrl_dev *pctldev, goto out; } - if (!function) { - dev_err(pctldev->dev, "no function name given\n"); - return -EINVAL; - } -
Why should it be allowed to have a NULL owner? There is a debug print involving it above but ... maybe this is over-cautious?
Yours,
Linus Walleij
RE: [PATCH 04/20] pinctrl: Record a pin owner, not mux function, when requesting pins
Linus Walleij wrote at Monday, February 20, 2012 2:15 PM:
Quoted 22 lines · Stephen Warren
Quoted 8 lines
When pins are requested/acquired/got, some device becomes the owner of their mux setting. At this point, it isn't certain which mux function will be selected for the pin, since this may vary between each of the device's states in the pinctrl mapping table. As such, we should record the owning device, not what we think the initial mux setting will be, when requesting pins.
Quoted 6 lines
This doesn't make a lot of difference right now since
pinctrl_getgets only one single device/state combination, but this will make a difference whenpinctrl_getgets all states, andpinctrl_select_statecan switch between states.Signed-off-by Stephen Warren <[email protected]>Mostly a rename then, OK...
Quoted 4 lines
drivers/pinctrl/pinmux.c +0
-0@@ -66,19 +65,14 @@ static int pin_request(struct pinctrl_dev *pctldev, goto out; }
Quoted 8 lines
drivers/pinctrl/pinmux.c static int pin_request(struct pinctrl_dev *pctldev, · line 73
Quoted 5 lines
drivers/pinctrl/pinmux.c +0
-5- if (!function) { - dev_err(pctldev->dev, "no function name given\n"); - return -EINVAL; - } -Why should it be allowed to have a NULL owner? There is a debug print involving it above but ... maybe this is over-cautious?
My reasoning was that this is an internal function, so this isn't a user- supplied parameter we need to be paranoid about checking, and the places that call this function internally "obviously" don't pass NULL owner. Well, I suppose one place relies on the fact we checked elsewhere that map->dev_name != NULL.
Still, I can see a defensive programming argument for keeping that check, although I suspect if we apply that argument we should probably check a lot more things too throughout the code?
Signature · 1 line
nvpublic
Re: [PATCH 04/20] pinctrl: Record a pin owner, not mux function, when requesting pins
Quoted 17 lines · Stephen Warren
Linus Walleij wrote at Monday, February 20, 2012 2:15 PM:
Quoted 9 lines
Quoted 6 lines
- if (!function) {
-dev_err(pctldev->dev, "no function name given\n");
- return-EINVAL;
- }
-Why should it be allowed to have a NULL owner? There is a debug print involving it above but ... maybe this is over-cautious?
My reasoning was that this is an internal function, so this isn't a user- supplied parameter we need to be paranoid about checking, and the places that call this function internally "obviously" don't pass NULL owner. Well, I suppose one place relies on the fact we checked elsewhere that
map->dev_name!= NULL.
Quoted 3 lines
Still, I can see a defensive programming argument for keeping that check, although I suspect if we apply that argument we should probably check a lot more things too throughout the code?
Bah whatever, no big deal.
Patch applied!
Thanks,
Linus Walleij
PATCH 5/20 pinctrl: Re-order pinmux.[ch] to match each-other
In reply to Stephen WarrenModify the two files so that the order of function prototypes in the header matches the order of implementations in the .c file.
--- drivers/pinctrl/pinmux.c | 56 +++++++++++++++++++++++----------------------- drivers/pinctrl/pinmux.h | 16 ++++++------ 2 files changed, 36 insertions(+), 36 deletions(-)
drivers/pinctrl/pinmux.c +28 -28
@@ -40,6 +40,34 @@ struct pinmux_group {unsigned group_selector; }; +int pinmux_check_ops (struct pinctrl_dev *pctldev) +{ +const struct pinmux_ops *ops = pctldev->desc->pmxops; +unsigned selector =0 ; + +/* Check that we implement required operations */ +if (!ops->list_functions || + !ops->get_function_name || + !ops->get_function_groups || + !ops->enable || + !ops->disable) +return -EINVAL ; + +/* Check that all functions registered have names */ +while (ops->list_functions (pctldev, selector) >=0 ) { +const char *fname = ops->get_function_name (pctldev, + selector); +if (!fname) { +pr_err ("pinmux ops has no name for function%u\n" , + selector); +return -EINVAL ; + } + selector++; + } + +return 0 ; +} +/** * pin_request() - request a single pin to be muxed in, typically for GPIO * @pin: the pin number in the global pin space
@@ -553,34 +581,6 @@ void pinmux_disable(struct pinctrl *p) } } -int pinmux_check_ops (struct pinctrl_dev *pctldev) -{ -const struct pinmux_ops *ops = pctldev->desc->pmxops; -unsigned selector =0 ; - -/* Check that we implement required operations */ -if (!ops->list_functions || - !ops->get_function_name || - !ops->get_function_groups || - !ops->enable || - !ops->disable) -return -EINVAL ; - -/* Check that all functions registered have names */ -while (ops->list_functions (pctldev, selector) >=0 ) { -const char *fname = ops->get_function_name (pctldev, - selector); -if (!fname) { -pr_err ("pinmux ops has no name for function%u\n" , - selector); -return -EINVAL ; - } - selector++; - } - -return 0 ; -} -#ifdef CONFIG_DEBUG_FS /* Called from pincontrol core */
drivers/pinctrl/pinmux.h +8 -8
@@ -13,8 +13,6 @@#ifdef CONFIG_PINMUX int pinmux_check_ops (struct pinctrl_dev *pctldev); -void pinmux_init_device_debugfs (struct dentry *devroot, -struct pinctrl_dev *pctldev);int pinmux_request_gpio (struct pinctrl_dev *pctldev,struct pinctrl_gpio_range *range,unsigned pin,unsigned gpio);
@@ -36,6 +34,8 @@ int pinmux_apply_muxmap(struct pinctrl_dev *pctldev,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, +struct pinctrl_dev *pctldev);void pinmux_dbg_show (struct seq_file *s,struct pinctrl *p);#else
@@ -45,11 +45,6 @@ static inline int pinmux_check_ops(struct pinctrl_dev *pctldev)return 0 ; } -static inline void pinmux_init_device_debugfs (struct dentry *devroot, -struct pinctrl_dev *pctldev) -{ -} -static inline int pinmux_request_gpio (struct pinctrl_dev *pctldev,struct pinctrl_gpio_range *range,unsigned pin,unsigned gpio)
@@ -95,7 +90,12 @@ static inline void pinmux_disable(struct pinctrl *p) { } -void pinmux_dbg_show (struct seq_file *s,struct pinctrl *p) +static inline void pinmux_init_device_debugfs (struct dentry *devroot, +struct pinctrl_dev *pctldev) +{ +} + +static inline void pinmux_dbg_show (struct seq_file *s,struct pinctrl *p) { }
Signature · 1 line
1.7.5.4
Re: [PATCH 05/20] pinctrl: Re-order pinmux.[ch] to match each-other
Quoted 4 lines · Stephen Warren
Modify the two files so that the order of function prototypes in the header matches the order of implementations in the .c file.
Signed-off-by Stephen Warren <[email protected]>
OK applied.
Thanks,
Linus Walleij
PATCH 6/20 pinctrl: Re-order pinconf.[ch] to match each-other
In reply to Stephen WarrenModify the two files so that the order of function prototypes in the header matches the order of implementations in the .c file.
Don't prototype a couple of internal functions.
--- drivers/pinctrl/pinconf.c | 31 +++++++++++++++---------------- drivers/pinctrl/pinconf.h | 5 +---- 2 files changed, 16 insertions(+), 20 deletions(-)
drivers/pinctrl/pinconf.c +15 -16
@@ -23,7 +23,20 @@#include "core.h" #include "pinconf.h" -int pin_config_get_for_pin (struct pinctrl_dev *pctldev,unsigned pin, +int pinconf_check_ops (struct pinctrl_dev *pctldev) +{ +const struct pinconf_ops *ops = pctldev->desc->confops; + +/* We must be able to read out pin status */ +if (!ops->pin_config_get && !ops->pin_config_group_get) +return -EINVAL ; +/* We have to be able to config the pins in SOME way */ +if (!ops->pin_config_set && !ops->pin_config_group_set) +return -EINVAL ; +return 0 ; +} + +static int pin_config_get_for_pin (struct pinctrl_dev *pctldev,unsigned pin,unsigned long *config) {const struct pinconf_ops *ops = pctldev->desc->confops;
@@ -63,7 +76,7 @@ int pin_config_get(const char *dev_name, const char *name, }EXPORT_SYMBOL (pin_config_get); -int pin_config_set_for_pin (struct pinctrl_dev *pctldev,unsigned pin, +static int pin_config_set_for_pin (struct pinctrl_dev *pctldev,unsigned pin,unsigned long config) {const struct pinconf_ops *ops = pctldev->desc->confops;
@@ -138,7 +151,6 @@ int pin_config_group_get(const char *dev_name, const char *pin_group, }EXPORT_SYMBOL (pin_config_group_get); -int pin_config_group_set (const char *dev_name,const char *pin_group,unsigned long config) {
@@ -205,19 +217,6 @@ int pin_config_group_set(const char *dev_name, const char *pin_group, }EXPORT_SYMBOL (pin_config_group_set); -int pinconf_check_ops (struct pinctrl_dev *pctldev) -{ -const struct pinconf_ops *ops = pctldev->desc->confops; - -/* We must be able to read out pin status */ -if (!ops->pin_config_get && !ops->pin_config_group_get) -return -EINVAL ; -/* We have to be able to config the pins in SOME way */ -if (!ops->pin_config_set && !ops->pin_config_group_set) -return -EINVAL ; -return 0 ; -} -#ifdef CONFIG_DEBUG_FS static void pinconf_dump_pin(struct pinctrl_dev *pctldev,
drivers/pinctrl/pinconf.h +1 -4
@@ -14,12 +14,9 @@#ifdef CONFIG_PINCONF int pinconf_check_ops (struct pinctrl_dev *pctldev); +void pinconf_init_device_debugfs (struct dentry *devroot,struct pinctrl_dev *pctldev); -int pin_config_get_for_pin (struct pinctrl_dev *pctldev,unsigned pin, -unsigned long *config); -int pin_config_set_for_pin (struct pinctrl_dev *pctldev,unsigned pin, -unsigned long config);#else
Signature · 1 line
1.7.5.4
Re: [PATCH 06/20] pinctrl: Re-order pinconf.[ch] to match each-other
Quoted 6 lines · Stephen Warren
Modify the two files so that the order of function prototypes in the header matches the order of implementations in the .c file.
Don't prototype a couple of internal functions.
Signed-off-by Stephen Warren <[email protected]>
OK applied.
Thanks,
Linus Walleij
PATCH 7/20 pinctrl: core.c/h cleanups
In reply to Stephen Warren* Make all functions internal to core.c static. Remove any of these from core.h.
* Add any missing EXPORT_SYMBOL_GPL().
--- drivers/pinctrl/core.c | 12 +++++++----- drivers/pinctrl/core.h | 3 --- 2 files changed, 7 insertions(+), 8 deletions(-)
drivers/pinctrl/core.c +7 -5
@@ -293,9 +293,9 @@ pinctrl_match_gpio_range(struct pinctrl_dev *pctldev, unsigned gpio)* the GPIO subsystem, return the device and the matching GPIO range. Returns * negative if the GPIO range could not be found in any device. */ -int pinctrl_get_device_gpio_range (unsigned gpio, -struct pinctrl_dev **outdev, -struct pinctrl_gpio_range **outrange) +static int pinctrl_get_device_gpio_range (unsigned gpio, +struct pinctrl_dev **outdev, +struct pinctrl_gpio_range **outrange) {struct pinctrl_dev *pctldev =NULL ;
@@ -332,6 +332,7 @@ void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,list_add_tail (&range->node, &pctldev->gpio_ranges);mutex_unlock (&pctldev->gpio_ranges_lock); } +EXPORT_SYMBOL_GPL (pinctrl_add_gpio_range);/** * pinctrl_remove_gpio_range() - remove a range of GPIOs fro a pin controller
@@ -345,6 +346,7 @@ void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,list_del (&range->node);mutex_unlock (&pctldev->gpio_ranges_lock); } +EXPORT_SYMBOL_GPL (pinctrl_remove_gpio_range);/** * pinctrl_get_group_selector() - returns the group selector for a group
@@ -785,7 +787,7 @@ static int pinctrl_hog_map(struct pinctrl_dev *pctldev,* map entries that need to be hogged, i.e. get+enabled until the system shuts * down. */ -int pinctrl_hog_maps (struct pinctrl_dev *pctldev) +static int pinctrl_hog_maps (struct pinctrl_dev *pctldev) {struct device *dev = pctldev->dev;const char *devname =dev_name (dev);
@@ -819,7 +821,7 @@ int pinctrl_hog_maps(struct pinctrl_dev *pctldev)* pinctrl_unhog_maps() - unhog specific map entries on controller device * @pctldev: the pin control device to unhog entries on */ -void pinctrl_unhog_maps (struct pinctrl_dev *pctldev) +static void pinctrl_unhog_maps (struct pinctrl_dev *pctldev) {struct list_head *node, *tmp;
drivers/pinctrl/core.h +0 -3
@@ -101,8 +101,5 @@ struct pin_desc {struct pinctrl_dev *get_pinctrl_dev_from_devname (const char *dev_name);struct pin_desc *pin_desc_get (struct pinctrl_dev *pctldev,unsigned int pin);int pin_get_from_name (struct pinctrl_dev *pctldev,const char *name); -int pinctrl_get_device_gpio_range (unsigned gpio, -struct pinctrl_dev **outdev, -struct pinctrl_gpio_range **outrange);int pinctrl_get_group_selector (struct pinctrl_dev *pctldev,const char *pin_group);
Signature · 1 line
1.7.5.4
Re: [PATCH 07/20] pinctrl: core.c/h cleanups
Quoted 5 lines · Stephen Warren
* Make all functions internal to
core.cstatic. Remove any of these fromcore.h.
* Add any missingEXPORT_SYMBOL_GPL().Signed-off-by Stephen Warren <[email protected]>
OK applied.
Thanks,
Linus Walleij
PATCH 8/20 pinctrl: Assume map table entries can't have a NULL name field
In reply to Stephen Warrenpinctrl_register_mappings() already requires that every mapping table entry have a non-NULL name field.
Logically, this makes sense too; drivers should always request a specific named state so they know what they're getting. Relying on getting the first mentioned state in the mapping table is error-prone, and a nasty special case to implement, given that a given the mapping table may define multiple states for a device.
Update a few places in the code and documentation that still allowed for NULL name fields.
--- Documentation/pinctrl.txt | 8 ++------ drivers/pinctrl/core.c | 25 ++++++++----------------- 2 files changed, 10 insertions(+), 23 deletions(-)
Documentation/pinctrl.txt +2 -6
@@ -934,7 +934,7 @@ foo_probe() /* Allocate a state holder named "state" etc */ struct pinctrl p; - p = pinctrl_get(&device, NULL); + p = pinctrl_get(&device, "default"); if IS_ERR(p) return PTR_ERR(p); pinctrl_enable(p);
@@ -948,10 +948,6 @@ foo_remove() pinctrl_put(state->p); } -If you want to grab a specific control mapping and not just the first one -found for this device you can specify a specific mapping name, for example in -the above example the second i2c0 setting: pinctrl_get(&device, "spi0-pos-B"); - This get/enable/disable/put sequence can just as well be handled by bus drivers if you don't want each and every driver to handle it and you know the arrangement on your bus.
@@ -1003,7 +999,7 @@ Since it may be common to request the core to hog a few always-applicable mux settings on the primary pin controller, there is a convenience macro for this: -PIN_MAP_PRIMARY_SYS_HOG("POWERMAP", "pinctrl-foo", "power_func") +PIN_MAP_SYS_HOG("POWERMAP", "pinctrl-foo", "power_func") This gives the exact same result as the above construction.
drivers/pinctrl/core.c +8 -17
@@ -488,8 +488,8 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)int i;struct pinctrl_map const *map; -/* We must have dev or ID or both */ -if (!dev && !name) +/* We must have a state name */ +if (WARN_ON (!name))return ERR_PTR (-EINVAL );if (dev)
@@ -530,23 +530,16 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)pr_debug ("in map, found pctldev %s to handle function %s" ,dev_name (pctldev->dev), map->function); -/* -* If we're looking for a specific named map, this must match, -* else we loop and look for the next. -*/ -if (name !=NULL ) { -if (map->name ==NULL ) -continue ; -if (strcmp (map->name, name)) -continue ; - } +/* State name must be the one we're looking for */ +if (strcmp (map->name, name)) +continue ;/* * This is for the case where no device name is given, we * already know that the function name matches from above * code. */ -if (!map->dev_name && (name !=NULL )) +if (!map->dev_name) found_map = true;/* If the mapping has a device set up it must match */
@@ -570,16 +563,14 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)/* We should have atleast one map, right */ if (!num_maps) {pr_err ("could not find any mux maps for device %s, ID %s\n" , - devname ? devname :"(anonymous)" , - name ? name :"(undefined)" ); + devname ? devname :"(anonymous)" , name);kfree (p);return ERR_PTR (-EINVAL ); }pr_debug ("found %u mux maps for device %s, UD %s\n" , num_maps, - devname ? devname :"(anonymous)" , - name ? name :"(undefined)" ); + devname ? devname :"(anonymous)" , name);/* Add the pinmux to the global list */ mutex_lock (&pinctrl_list_mutex);
Signature · 1 line
1.7.5.4
Re: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
Quoted 9 lines · Stephen Warren
pinctrl_register_mappings()already requires that every mapping table entry have a non-NULL name field.Logically, this makes sense too; drivers should always request a specific named state so they know what they're getting. Relying on getting the first mentioned state in the mapping table is error-prone, and a nasty special case to implement, given that a given the mapping table may define multiple states for a device.
Quoted 4 lines
Update a few places in the code and documentation that still allowed for NULL name fields.
Signed-off-by Stephen Warren <[email protected]>
This causes a regression on U300 and most certainly on the Sirf Prima II as well. The U300 can be fixed up as per below:
arch/arm/mach-u300/core.c +1 -1
@@ -1645,7 +1645,7 @@ static int __init u300_pinctrl_fetch(void)struct pinctrl *p;int ret; - p =pinctrl_get (u300_mux_hogs[i].dev,NULL ); + p =pinctrl_get (u300_mux_hogs[i].dev, u300_mux_hogs[i].name);if (IS_ERR (p)) {pr_err ("u300: could not get pinmux hog %s\n" , u300_mux_hogs[i].name);
The drivers/tty/serial/sirfsoc_uart.c asks for it's UART pinctrl like this:
sirfport->p = pinctrl_get(&pdev->dev, NULL);
I don't know quite what to encode in there, if "deafult" is sensible we might just
#define PIN_MAP_NAME_DEFAULT "default"
In <linux/pinctrl/consumer.h> and <linux/pinctrl/machine.h> alike, maybe in some <linux/pinctrl/mapnames.h> that both of these include?
the have the driver ask for:
sirfport->p = pinctrl_get(&pdev->dev, PIN_MAP_NAME_DEFAULT);
(Similar changes can be done for U300, naming all its map "default".)
Yours,
Linus Walleij
Re: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
Quoted 39 lines · Linus Walleij
Quoted 9 lines · Stephen Warren
pinctrl_register_mappings()already requires that every mapping table entry have a non-NULL name field.Logically, this makes sense too; drivers should always request a specific named state so they know what they're getting. Relying on getting the first mentioned state in the mapping table is error-prone, and a nasty special case to implement, given that a given the mapping table may define multiple states for a device.
Quoted 4 lines
Update a few places in the code and documentation that still allowed for NULL name fields.
Signed-off-by Stephen Warren <[email protected]>This causes a regression on U300 and most certainly on the Sirf Prima II as well. The U300 can be fixed up as per below:
arch/arm/mach-u300/core.c +1
-1@@ -1645,7 +1645,7 @@ static int __init u300_pinctrl_fetch(void) struct pinctrl *p; int ret; - p = pinctrl_get(u300_mux_hogs[i].dev, NULL); + p = pinctrl_get(u300_mux_hogs[i].dev, u300_mux_hogs[i].name); if (IS_ERR(p)) { pr_err("u300: could not get pinmux hog %s\n", u300_mux_hogs[i].name);The
drivers/tty/serial/sirfsoc_uart.casks for it's UART pinctrl like this:
sirfport->p=pinctrl_get(&pdev->dev, NULL);
Quoted 8 lines
I don't know quite what to encode in there, if "deafult" is sensible we might just
#define
PIN_MAP_NAME_DEFAULT"default"
In <linux/pinctrl/consumer.h> and <linux/pinctrl/machine.h> alike, maybe in some <linux/pinctrl/mapnames.h> that both of these include?
I feel a little strange to put such thing in common code. Personally i still like the original way you did.
Quoted 7 lines
the have the driver ask for:
sirfport->p=pinctrl_get(&pdev->dev, PIN_MAP_NAME_DEFAULT);(Similar changes can be done for U300, naming all its map "default".)
Regards
Dong Aisheng
Re: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
Quoted 43 lines · Dong Aisheng
Quoted 42 lines · Linus Walleij
Quoted 9 lines · Stephen Warren
pinctrl_register_mappings()already requires that every mapping table entry have a non-NULL name field.Logically, this makes sense too; drivers should always request a specific named state so they know what they're getting. Relying on getting the first mentioned state in the mapping table is error-prone, and a nasty special case to implement, given that a given the mapping table may define multiple states for a device.
Quoted 4 lines
Update a few places in the code and documentation that still allowed for NULL name fields.
Signed-off-by Stephen Warren <[email protected]>This causes a regression on U300 and most certainly on the Sirf Prima II as well. The U300 can be fixed up as per below:
arch/arm/mach-u300/core.c +1
-1@@ -1645,7 +1645,7 @@ static int __init u300_pinctrl_fetch(void) struct pinctrl *p; int ret; - p = pinctrl_get(u300_mux_hogs[i].dev, NULL); + p = pinctrl_get(u300_mux_hogs[i].dev, u300_mux_hogs[i].name); if (IS_ERR(p)) { pr_err("u300: could not get pinmux hog %s\n", u300_mux_hogs[i].name);The
drivers/tty/serial/sirfsoc_uart.casks for it's UART pinctrl like this:
sirfport->p=pinctrl_get(&pdev->dev, NULL);I don't know quite what to encode in there, if "deafult" is sensible we might just
Quoted 7 lines
Quoted 5 lines
#define
PIN_MAP_NAME_DEFAULT"default"
In <linux/pinctrl/consumer.h> and <linux/pinctrl/machine.h> alike, maybe in some <linux/pinctrl/mapnames.h> that both of these include?I feel a little strange to put such thing in common code. Personally i still like the original way you did.
I think with this patch alone it doesn't make much sense to enforce the request to specify a certain map, it only appears further ahead as we start to support states.
Let's look through the entire patch series so as to get the bigger picture.
Yours,
Linus Walleij
RE: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
In reply to Linus WalleijLinus Walleij wrote at Monday, February 20, 2012 2:42 PM:
Quoted 11 lines · Stephen Warren
Quoted 10 lines
pinctrl_register_mappings()already requires that every mapping table entry have a non-NULL name field.Logically, this makes sense too; drivers should always request a specific named state so they know what they're getting. Relying on getting the first mentioned state in the mapping table is error-prone, and a nasty special case to implement, given that a given the mapping table may define multiple states for a device.
Quoted 7 lines
Quoted 4 lines
Update a few places in the code and documentation that still allowed for NULL name fields.
Signed-off-by Stephen Warren <[email protected]>This causes a regression on U300 and most certainly on the Sirf Prima II as well. The U300 can be fixed up as per below:
Oh good point. I'd remembered to update those in later patches, but not this one...
arch/arm/mach-u300/core.c static int __init u300_pinctrl_fetch(void) · line 1651
Quoted 13 lines
arch/arm/mach-u300/core.c +1
-1@@ -1645,7 +1645,7 @@ static int __init u300_pinctrl_fetch(void)struct pinctrl *p;int ret; - p =pinctrl_get (u300_mux_hogs[i].dev,NULL ); + p =pinctrl_get (u300_mux_hogs[i].dev, u300_mux_hogs[i].name);if (IS_ERR (p)) {pr_err ("u300: could not get pinmux hog %s\n" , u300_mux_hogs[i].name);
I don't think that works as-is; currently, the names in the U300 map table Are MMCSD, SPI, UART0, whereas the names in u300_mux_hogs[] are mmc0, spi0, uart0. I can easily fix up the u300_mux_hogs[] in the same patch though.
Quoted 6 lines
The
drivers/tty/serial/sirfsoc_uart.casks for it's UART pinctrl like this:
sirfport->p=pinctrl_get(&pdev->dev, NULL);I don't know quite what to encode in there, if "default" is sensible
"default" seems reasonable to me.
I couldn't find any mapping table defined for Sirf Prima II; is there one checked in anywhere?
Quoted 7 lines
we might just
#define
PIN_MAP_NAME_DEFAULT"default"
In <linux/pinctrl/consumer.h> and <linux/pinctrl/machine.h> alike, maybe in some <linux/pinctrl/mapnames.h> that both of these include?
Quoted 6 lines
the have the driver ask for:
sirfport->p=pinctrl_get(&pdev->dev, PIN_MAP_NAME_DEFAULT);(Similar changes can be done for U300, naming all its map "default".)
I guess we could just modify pinmux_get() such that if NULL is passed as the state name, it uses "default" instead internally. The disadvantage I see here is that someone reading the client driver and writing the mapping table then has to know that pinmux_get() does that internally, rather than it being obvious right in the client driver code.
--
nvpublic
Re: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
Quoted 5 lines · Stephen Warren
I guess we could just modify
pinmux_get()such that if NULL is passed as the state name, it uses "default" instead internally. The disadvantage I see here is that someone reading the client driver and writing the mapping table then has to know thatpinmux_get()does that internally, rather than it being obvious right in the client driver code.
I would prefer this solution, it has the upside of not needing to touch the sirf driver.
And please #define the string somewhere instead of open-coding "default", it's too errorprone IMO.
Thanks,
Linus Walleij
Re: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
In reply to Stephen WarrenOn Tue, Feb 21, 2012 at 09:46:01AM -0800, Stephen Warren wrote:
....
Quoted 11 lines
Quoted 11 lines
we might just
#define
PIN_MAP_NAME_DEFAULT"default"
In <linux/pinctrl/consumer.h> and <linux/pinctrl/machine.h> alike, maybe in some <linux/pinctrl/mapnames.h> that both of these include?the have the driver ask for:
sirfport->p=pinctrl_get(&pdev->dev, PIN_MAP_NAME_DEFAULT);
Quoted 9 lines
Quoted 2 lines
(Similar changes can be done for U300, naming all its map "default".)
I guess we could just modify
pinmux_get()such that if NULL is passed as the state name, it uses "default" instead internally. The disadvantage I see here is that someone reading the client driver and writing the mapping table then has to know thatpinmux_get()does that internally, rather than it being obvious right in the client driver code.
It looks like a way out.
The left problem seems to be that we may force the mapping table writer to specify "default" name for map at least.
Is there any way to avoid it?
I just think it may be better if we do not have such restriction.
Regards
Dong Aisheng
RE: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
Dong Aisheng wrote at Tuesday, February 21, 2012 11:35 PM:
Quoted 22 lines · Stephen Warren
....
Quoted 11 lines
Quoted 11 lines
we might just
#define
PIN_MAP_NAME_DEFAULT"default"
In <linux/pinctrl/consumer.h> and <linux/pinctrl/machine.h> alike, maybe in some <linux/pinctrl/mapnames.h> that both of these include?the have the driver ask for:
sirfport->p=pinctrl_get(&pdev->dev, PIN_MAP_NAME_DEFAULT);Quoted 8 lines
Quoted 2 lines
(Similar changes can be done for U300, naming all its map "default".)
I guess we could just modify
pinmux_get()such that if NULL is passed as the state name, it uses "default" instead internally. The disadvantage I see here is that someone reading the client driver and writing the mapping table then has to know thatpinmux_get()does that internally, rather than it being obvious right in the client driver code.
Quoted 5 lines
It looks like a way out.
The left problem seems to be that we may force the mapping table writer to specify "default" name for map at least.
Is there any way to avoid it?
That specific restriction has been present since the very first patch that created the pinctrl subsystem.
Quoted 1 line
I just think it may be better if we do not have such restriction.
Given that all map entries have a name, I'd really prefer that all drivers had to request a specific matching name, rather than saying "just give me whatever is in the mapping table".
I don't see this as a restriction, but more of a correctness issue; every mapping table entry has a name and drivers (or device tree bindings) define what that name must be, so why shouldn't drivers be required to request that specific name, and experience an error if the mapping table author didn't create that name?
regulator_get(dev, id) requires id != NULL.
clk_get(dev, con_id) requires con_id != NULL in order to match a clock that has a non-NULL con_id defined (although clocks with a NULL con_id are also legal, in which case, the con_id parameter to clk_get is ignored)
So pinctrl_get(dev, state) requiring state != NULL seems consistent with existing practice.
Signature · 1 line
nvpublic
Re: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
Quoted 23 lines · Stephen Warren
Dong Aisheng wrote at Tuesday, February 21, 2012 11:35 PM:
Quoted 22 lines · Stephen Warren
....
Quoted 19 lines
Quoted 7 lines
we might just
#define
PIN_MAP_NAME_DEFAULT"default"
In <linux/pinctrl/consumer.h> and <linux/pinctrl/machine.h> alike, maybe in some <linux/pinctrl/mapnames.h> that both of these include?Quoted 6 lines
the have the driver ask for:
sirfport->p=pinctrl_get(&pdev->dev, PIN_MAP_NAME_DEFAULT);(Similar changes can be done for U300, naming all its map "default".)
I guess we could just modify
pinmux_get()such that if NULL is passed as the state name, it uses "default" instead internally. The disadvantage I see here is that someone reading the client driver and writing the mapping table then has to know thatpinmux_get()does that internally, rather than it being obvious right in the client driver code.
Quoted 9 lines
Quoted 5 lines
It looks like a way out.
The left problem seems to be that we may force the mapping table writer to specify "default" name for map at least.
Is there any way to avoid it?That specific restriction has been present since the very first patch that created the pinctrl subsystem.
Since i saw some code in pinctrl subsystem formerly like:
/*
* If we're looking for a specific named map, this must match,
* else we loop and look for the next.
*/
if (name != NULL) {
if (map->name == NULL)
continue;
if (strcmp(map->name, name))
continue;
}So i guessed the map->name could be NULL in the original design. Of course, if we used the convenience macro to define map, there's no chance to make map name NULL.
We did not force users to must convenience macros, right?
Quoted 6 lines
Quoted 1 line
I just think it may be better if we do not have such restriction.
Given that all map entries have a name, I'd really prefer that all drivers had to request a specific matching name, rather than saying "just give me whatever is in the mapping table".
Quoted 6 lines
I don't see this as a restriction, but more of a correctness issue; every mapping table entry has a name and drivers (or device tree bindings) define what that name must be, so why shouldn't drivers be required to request that specific name, and experience an error if the mapping table author didn't create that name?
Yes, i agree.
Based on this point, i feel maybe internally convert NULL to a "default" name for pinctrl_get does not make too much sense.
Quoted 10 lines
regulator_get(dev, id)requires id != NULL.
clk_get(dev, con_id)requirescon_id!= NULL in order to match a clock that has a non-NULLcon_iddefined (although clocks with a NULLcon_idare also legal, in which case, thecon_idparameter toclk_getis ignored)So
pinctrl_get(dev, state)requiring state != NULL seems consistent with existing practice.
Yes, it's true if given all map entries have a name.
Now i'm intend to the way you mentioned at:
https://lkml.org/lkml/2012/2/21/213
And i agree with the way you said:
If we continue to allow NULL names, I think we should change that to:
if name:
match = map->name && !strcmp(name, map->name)
else:
match = !map->nameAnd i think allowing map name to be NULL will make life easy for those devices who do not support multi states.
Originally i'm wondering how about more than one entries with a NULL name. But now i think it's actually not an issue since we indeed support multi entries with the same map name.
Regards
Dong Aisheng
RE: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
Dong Aisheng wrote at Wednesday, February 22, 2012 8:35 PM:
Quoted 44 lines · Stephen Warren
Quoted 23 lines
Dong Aisheng wrote at Tuesday, February 21, 2012 11:35 PM:
Quoted 22 lines · Stephen Warren
....
Quoted 19 lines
Quoted 7 lines
we might just
#define
PIN_MAP_NAME_DEFAULT"default"
In <linux/pinctrl/consumer.h> and <linux/pinctrl/machine.h> alike, maybe in some <linux/pinctrl/mapnames.h> that both of these include?Quoted 6 lines
the have the driver ask for:
sirfport->p=pinctrl_get(&pdev->dev, PIN_MAP_NAME_DEFAULT);(Similar changes can be done for U300, naming all its map "default".)
I guess we could just modify
pinmux_get()such that if NULL is passed as the state name, it uses "default" instead internally. The disadvantage I see here is that someone reading the client driver and writing the mapping table then has to know thatpinmux_get()does that internally, rather than it being obvious right in the client driver code.Quoted 8 lines
Quoted 5 lines
It looks like a way out.
The left problem seems to be that we may force the mapping table writer to specify "default" name for map at least.
Is there any way to avoid it?That specific restriction has been present since the very first patch that created the pinctrl subsystem.
Since i saw some code in pinctrl subsystem formerly like:
/*
* If we're looking for a specific named map, this must match,
* else we loop and look for the next.
*/if (name != NULL) { if (map->name == NULL) continue; if (strcmp(map->name, name)) continue; }
Quoted 3 lines
So i guessed the
map->namecould be NULL in the original design. Of course, if we used the convenience macro to define map, there's no chance to make map name NULL.
Admittedly, the code is a little inconsistent. I was thinking of:
+int __init pinmux_register_mappings(struct pinmux_map const *maps,
...
+ for (i = 0; i < num_maps; i++) {
+ /* Sanity check the mapping */
+ if (!maps[i].name) {
+ pr_err("failed to register map %d: "
+ "no map name given\n", i);
+ return -EINVAL;
+ }
Quoted 1 line
We did not force users to must convenience macros, right?
No. In fact, my patches for Tegra's board file didn't always use them.
Quoted 34 lines
Quoted 11 lines
Quoted 1 line
I just think it may be better if we do not have such restriction.
Given that all map entries have a name, I'd really prefer that all drivers had to request a specific matching name, rather than saying "just give me whatever is in the mapping table".
I don't see this as a restriction, but more of a correctness issue; every mapping table entry has a name and drivers (or device tree bindings) define what that name must be, so why shouldn't drivers be required to request that specific name, and experience an error if the mapping table author didn't create that name?
Yes, i agree.
Based on this point, i feel maybe internally convert NULL to a "default" name forpinctrl_getdoes not make too much sense.Quoted 9 lines
regulator_get(dev, id)requires id != NULL.
clk_get(dev, con_id)requirescon_id!= NULL in order to match a clock that has a non-NULLcon_iddefined (although clocks with a NULLcon_idare also legal, in which case, thecon_idparameter toclk_getis ignored)So
pinctrl_get(dev, state)requiring state != NULL seems consistent with existing practice.Yes, it's true if given all map entries have a name.
Now i'm intend to the way you mentioned at:
https://lkml.org/lkml/2012/2/21/213And i agree with the way you said:
If we continue to allow NULL names, I think we should change that to:
if name:
Quoted 6 lines
match = map->name && !strcmp(name, map->name) else: match = !map->nameAnd i think allowing map name to be NULL will make life easy for those devices who do not support multi states.
It does make it a little convenient for board files, but isn't really practical to implement for device-tree unless we modify the binding to have something that means "no name". I'd rather not allow more options in the binding though.
What's wrong with writing e.g. PINCTRL_DEFAULT instead of NULL when calling pinctrl_get() or pinctrl_lookup_state() though? Given pinctrl.h having:
#define PINCTRL_DEFAULT "default"
Quoted 3 lines
Originally I'm wondering how about more than one entries with a NULL name. But now i think it's actually not an issue since we indeed support multi entries with the same map name.
Yes.
If the mapping table contains a number of entries with the same string name, they're all part of the same single state with that name.
If entries with a name field set to NULL are allowed and exist, I'd similarly consider them all part of the same state, which just doesn't have a name.
Signature · 1 line
nvpublic
Re: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
Quoted 111 lines · Stephen Warren
Dong Aisheng wrote at Wednesday, February 22, 2012 8:35 PM:
Quoted 44 lines · Stephen Warren
Quoted 23 lines
Dong Aisheng wrote at Tuesday, February 21, 2012 11:35 PM:
Quoted 22 lines · Stephen Warren
....
Quoted 19 lines
Quoted 7 lines
we might just
#define
PIN_MAP_NAME_DEFAULT"default"
In <linux/pinctrl/consumer.h> and <linux/pinctrl/machine.h> alike, maybe in some <linux/pinctrl/mapnames.h> that both of these include?Quoted 6 lines
the have the driver ask for:
sirfport->p=pinctrl_get(&pdev->dev, PIN_MAP_NAME_DEFAULT);(Similar changes can be done for U300, naming all its map "default".)
I guess we could just modify
pinmux_get()such that if NULL is passed as the state name, it uses "default" instead internally. The disadvantage I see here is that someone reading the client driver and writing the mapping table then has to know thatpinmux_get()does that internally, rather than it being obvious right in the client driver code.Quoted 8 lines
Quoted 5 lines
It looks like a way out.
The left problem seems to be that we may force the mapping table writer to specify "default" name for map at least.
Is there any way to avoid it?That specific restriction has been present since the very first patch that created the pinctrl subsystem.
Since i saw some code in pinctrl subsystem formerly like:
/*
* If we're looking for a specific named map, this must match,
* else we loop and look for the next.
*/if (name != NULL) { if (map->name == NULL) continue; if (strcmp(map->name, name)) continue; }Quoted 3 lines
So i guessed the
map->namecould be NULL in the original design. Of course, if we used the convenience macro to define map, there's no chance to make map name NULL.Admittedly, the code is a little inconsistent. I was thinking of:
(quoted diff) +8
-0+int __init pinmux_register_mappings(struct pinmux_map const *maps, + for (i = 0; i < num_maps; i++) { + /* Sanity check the mapping */ + if (!maps[i].name) { + pr_err("failed to register map %d: " + "no map name given\n", i); + return -EINVAL; + }Quoted 2 lines
We did not force users to must convenience macros, right?
No. In fact, my patches for Tegra's board file didn't always use them.
Quoted 34 lines
Quoted 11 lines
Quoted 1 line
I just think it may be better if we do not have such restriction.
Given that all map entries have a name, I'd really prefer that all drivers had to request a specific matching name, rather than saying "just give me whatever is in the mapping table".
I don't see this as a restriction, but more of a correctness issue; every mapping table entry has a name and drivers (or device tree bindings) define what that name must be, so why shouldn't drivers be required to request that specific name, and experience an error if the mapping table author didn't create that name?
Yes, i agree.
Based on this point, i feel maybe internally convert NULL to a "default" name forpinctrl_getdoes not make too much sense.Quoted 9 lines
regulator_get(dev, id)requires id != NULL.
clk_get(dev, con_id)requirescon_id!= NULL in order to match a clock that has a non-NULLcon_iddefined (although clocks with a NULLcon_idare also legal, in which case, thecon_idparameter toclk_getis ignored)So
pinctrl_get(dev, state)requiring state != NULL seems consistent with existing practice.Yes, it's true if given all map entries have a name.
Now i'm intend to the way you mentioned at:
https://lkml.org/lkml/2012/2/21/213And i agree with the way you said:
If we continue to allow NULL names, I think we should change that to:
if name:Quoted 6 lines
match = map->name && !strcmp(name, map->name) else: match = !map->nameAnd i think allowing map name to be NULL will make life easy for those devices who do not support multi states.
It does make it a little convenient for board files, but isn't really practical to implement for device-tree unless we modify the binding to have something that means "no name". I'd rather not allow more options in the binding though.
Quoted 5 lines
What's wrong with writing e.g.
PINCTRL_DEFAULTinstead of NULL when callingpinctrl_get()orpinctrl_lookup_state()though? Givenpinctrl.hhaving:#define
PINCTRL_DEFAULT"default"
First, map writer needs know this logic.
Quoted 4 lines · all as you
Quoted 4 lines
Quoted 4 lines
every mapping table entry has a name and drivers (or device tree bindings) define what that name must be, so why shouldn't drivers be required to request that specific name, and experience an error if the mapping table author didn't create that name?
if want to keep align with regulator and clock,
i just feel a little that it does not make too much sense to internally convert NULL to "default", right?
Regards
Dong Aisheng
RE: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
Dong Aisheng wrote at Wednesday, February 22, 2012 8:57 PM:
Quoted 3 lines · Stephen Warren
Quoted 2 lines
Dong Aisheng wrote at Wednesday, February 22, 2012 8:35 PM:
Quoted 1 line · Stephen Warren
...
Quoted 30 lines
Quoted 30 lines
Quoted 18 lines
Quoted 9 lines
regulator_get(dev, id)requires id != NULL.
clk_get(dev, con_id)requirescon_id!= NULL in order to match a clock that has a non-NULLcon_iddefined (although clocks with a NULLcon_idare also legal, in which case, thecon_idparameter toclk_getis ignored)So
pinctrl_get(dev, state)requiring state != NULL seems consistent with existing practice.Yes, it's true if given all map entries have a name.
Now i'm intend to the way you mentioned at:
https://lkml.org/lkml/2012/2/21/213And i agree with the way you said:
If we continue to allow NULL names, I think we should change that to:
if name:Quoted 6 lines
match = map->name && !strcmp(name, map->name) else: match = !map->nameAnd i think allowing map name to be NULL will make life easy for those devices who do not support multi states.
It does make it a little convenient for board files, but isn't really practical to implement for device-tree unless we modify the binding to have something that means "no name". I'd rather not allow more options in the binding though.
Quoted 6 lines
Quoted 4 lines
What's wrong with writing e.g.
PINCTRL_DEFAULTinstead of NULL when callingpinctrl_get()orpinctrl_lookup_state()though? Givenpinctrl.hhaving:#define
PINCTRL_DEFAULT"default"First, map writer needs know this logic.
Sure, but that's always true; you need to know the state name in all cases. And this requirement seems extremely trivial for a map writer to implement.
Quoted 10 lines
Quoted 4 lines · all as you
Quoted 4 lines
Quoted 4 lines
every mapping table entry has a name and drivers (or device tree bindings) define what that name must be, so why shouldn't drivers be required to request that specific name, and experience an error if the mapping table author didn't create that name?
if want to keep align with regulator and clock,
i just feel a little that it does not make too much sense to internally convert NULL to "default", right?
I'm hoping that we don't do this internal conversion. The rules I'd like are:
* Every mapping table entry must include a non-NULL name field.
* Every call to pinctrl_get()/pinctrl_lookup_state() must pass a non-NULL name
----------==========----------==========----------==========----------==========--
nvpublic
Re: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
Quoted 52 lines · Stephen Warren
Dong Aisheng wrote at Wednesday, February 22, 2012 8:57 PM:
Quoted 3 lines · Stephen Warren
Quoted 2 lines
Dong Aisheng wrote at Wednesday, February 22, 2012 8:35 PM:
Quoted 1 line · Stephen Warren
...
Quoted 30 lines
Quoted 30 lines
Quoted 18 lines
Quoted 9 lines
regulator_get(dev, id)requires id != NULL.
clk_get(dev, con_id)requirescon_id!= NULL in order to match a clock that has a non-NULLcon_iddefined (although clocks with a NULLcon_idare also legal, in which case, thecon_idparameter toclk_getis ignored)So
pinctrl_get(dev, state)requiring state != NULL seems consistent with existing practice.Yes, it's true if given all map entries have a name.
Now i'm intend to the way you mentioned at:
https://lkml.org/lkml/2012/2/21/213And i agree with the way you said:
If we continue to allow NULL names, I think we should change that to:
if name:Quoted 6 lines
match = map->name && !strcmp(name, map->name) else: match = !map->nameAnd i think allowing map name to be NULL will make life easy for those devices who do not support multi states.
It does make it a little convenient for board files, but isn't really practical to implement for device-tree unless we modify the binding to have something that means "no name". I'd rather not allow more options in the binding though.
Quoted 6 lines
Quoted 4 lines
What's wrong with writing e.g.
PINCTRL_DEFAULTinstead of NULL when callingpinctrl_get()orpinctrl_lookup_state()though? Givenpinctrl.hhaving:#define
PINCTRL_DEFAULT"default"First, map writer needs know this logic.
Sure, but that's always true; you need to know the state name in all cases. And this requirement seems extremely trivial for a map writer to implement.
Quoted 7 lines
Quoted 4 lines · all as you
Quoted 4 lines
Quoted 4 lines
every mapping table entry has a name and drivers (or device tree bindings) define what that name must be, so why shouldn't drivers be required to request that specific name, and experience an error if the mapping table author didn't create that name?
Quoted 6 lines
Quoted 3 lines
if want to keep align with regulator and clock,
i just feel a little that it does not make too much sense to internally convert NULL to "default", right?I'm hoping that we don't do this internal conversion. The rules I'd like are:
I'm also agree that we either allow map name to be NULL or not but not do internal conversion.
Quoted 3 lines
* Every mapping table entry must include a non-NULL name field.
* Every call to pinctrl_get()/pinctrl_lookup_state() must pass a non-NULL name
This is a way.
Before using this, i'm still wondering what big problems do you think for us to support a NULL map name?
Because the name for devices do not have different state really does not make too much sense but extra overhead.
Regards
Dong Aisheng
RE: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
Dong Aisheng wrote at Wednesday, February 22, 2012 9:48 PM:
Quoted 1 line · Stephen Warren
...
Quoted 1 line
Quoted 1 line
I'm hoping that we don't do this internal conversion. The rules I'd like are:
...
Quoted 10 lines
Quoted 3 lines
* Every mapping table entry must include a non-NULL name field.
* Every call to pinctrl_get()/pinctrl_lookup_state() must pass a non-NULL name
This is a way.
Before using this, i'm still wondering what big problems do you think for us to support a NULL map name?
Because the name for devices do not have different state really does not make too much sense but extra overhead.
If we disallow NULL names, it simplifies the code in the pinctrl core; when registering mappings or right at the start of pinctrl_get() or pinctrl_lookup_state(), we check if the name is NULL and if so error out. Everywhere else can then assume name!=NULL, and hence not have special- cases for name==NULL, e.g.:
In debug code:
name ? name : "(unnamed)"
vs.:
name
When matching mapping table entries:
match = !name ? !map->name : !strcmp(name, map->name) vs.:
match = !strcmp(name, map->name)
Similar for the body of pinctrl_lookup_state().
Equally, it's not possible to generate a mapping table entry with a NULL name from device tree given the bindings we discussed, so disallowing them everywhere keeps things consistent.
Signature · 1 line
nvpublic
Re: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
Quoted 27 lines · Stephen Warren
Dong Aisheng wrote at Wednesday, February 22, 2012 9:48 PM:
Quoted 1 line · Stephen Warren
...
Quoted 1 line
Quoted 1 line
I'm hoping that we don't do this internal conversion. The rules I'd like are:
...
Quoted 10 lines
Quoted 3 lines
* Every mapping table entry must include a non-NULL name field.
* Every call to pinctrl_get()/pinctrl_lookup_state() must pass a non-NULL name
This is a way.
Before using this, i'm still wondering what big problems do you think for us to support a NULL map name?
Because the name for devices do not have different state really does not make too much sense but extra overhead.If we disallow NULL names, it simplifies the code in the pinctrl core; when registering mappings or right at the start of
pinctrl_get()orpinctrl_lookup_state(), we check if the name is NULL and if so error out. Everywhere else can then assume name!=NULL, and hence not have special- cases for name==NULL, e.g.:In debug code:
name ? name : "(unnamed)"
vs.:
name
Quoted 7 lines
When matching mapping table entries:
match = !name ? !map->name : !strcmp(name,map->name) vs.:
match = !strcmp(name,map->name)Similar for the body of
pinctrl_lookup_state().
Yes, it does make thing simple.
But i guess it's not the key point to not support NULL state name, right?
Quoted 4 lines
Equally, it's not possible to generate a mapping table entry with a NULL name from device tree given the bindings we discussed, so disallowing them everywhere keeps things consistent.
Yes, i'm wondering if we can change it a bit to support NULL name. I replied with my idea in another mail before this one.
Regards
Dong Aisheng
Re: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
In reply to Stephen WarrenQuoted 5 lines · Stephen Warren
pinctrl_register_mappings()already requires that every mapping table entry have a non-NULL name field.Logically, this makes sense too; drivers should always request a specific named state so they know what they're getting. Relying on getting the
Hmm? It makes me a little confused.
IIRC we allow the driver to request NULL map name in the linaro connect discussion.
For those devices they do not want to support multi states, they really don't want to care about the state name.
The original way is convenient for such a case.
Quoted 4 lines
first mentioned state in the mapping table is error-prone, and a nasty special case to implement, given that a given the mapping table may define multiple states for a device.
User should know this constraint.
Quoted 5 lines
drivers/pinctrl/core.c +0
-0
drivers/pinctrl/core.c static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) · line 494
Quoted 9 lines
drivers/pinctrl/core.c +2
-2@@ -488,8 +488,8 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) int i; struct pinctrl_map const *map; - /* We must have dev or ID or both */ - if (!dev && !name) + /* We must have a state name */ + if (WARN_ON(!name)) return ERR_PTR(-EINVAL);
We're already using the pinctrl device name for hog map. So should it be something like:
if (WARN_ON(!dev) || WARN_ON(!name))
Quoted 17 lines
drivers/pinctrl/core.c +2
-10if (dev)@@ -530,23 +530,16 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) pr_debug("in map, found pctldev %s to handle function %s", dev_name(pctldev->dev), map->function); - /* - * If we're looking for a specific named map, this must match, - * else we loop and look for the next. - */ - if (name != NULL) { - if (map->name == NULL) - continue; - if (strcmp(map->name, name)) - continue; - } + /* State name must be the one we're looking for */ + if (strcmp(map->name, name))
drivers/pinctrl/core.c static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) · line 543
Quoted 10 lines
drivers/pinctrl/core.c +2
-1+ continue; /* * This is for the case where no device name is given, we * already know that the function name matches from above * code. */ - if (!map->dev_name && (name != NULL)) + if (!map->dev_name) found_map = true;
Do we still need this?
Is there still a case the dev_name can be NULL?
Quoted 22 lines
drivers/pinctrl/core.c +2
-5/* If the mapping has a device set up it must match */@@ -570,16 +563,14 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) /* We should have atleast one map, right */ if (!num_maps) { pr_err("could not find any mux maps for device %s, ID %s\n", - devname ? devname : "(anonymous)", - name ? name : "(undefined)"); + devname ? devname : "(anonymous)", name); kfree(p); return ERR_PTR(-EINVAL); } pr_debug("found %u mux maps for device %s, UD %s\n", num_maps, - devname ? devname : "(anonymous)", - name ? name : "(undefined)"); + devname ? devname : "(anonymous)", name); /* Add the pinmux to the global list */ mutex_lock(&pinctrl_list_mutex); --
Quoted 2 lines
1.7.5.4
Regards
Dong Aisheng
RE: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
Dong Aisheng wrote at Tuesday, February 21, 2012 6:08 AM:
Quoted 7 lines · Stephen Warren
Quoted 5 lines
pinctrl_register_mappings()already requires that every mapping table entry have a non-NULL name field.Logically, this makes sense too; drivers should always request a specific named state so they know what they're getting. Relying on getting the
Quoted 6 lines
Hmm? It makes me a little confused.
IIRC we allow the driver to request NULL map name in the linaro connect discussion.
For those devices they do not want to support multi states, they really don't want to care about the state name.
The original way is convenient for such a case.
With device tree, every state is always going to have /some/ name; the binding we discussed didn't include any way to specify "no name" or "default name" or "default state", so this will keeps things a little more consistent.
I possibly could be persuaded to allow NULL state names in the mapping table. However, if so, I think they should work a little differently to the code currently in pinctrl: Right now, a NULL parameter to pinmux_get() allows matching against /any/ state name in the table. If we changed this to only allow matching against mapping table with a NULL name, that might be OK, since it'd be very explicit what it matched. But, as I mentione above, migrating such a driver to device tree would require changing this so I'm not inclined to like that solution without strong requirements.
In other words, what we have right now is something like:
if name:
match = !strcmp(name, map->name)
else:
match = true
If we continue to allow NULL names, I think we should change that to:
if name:
match = map->name && !strcmp(name, map->name)
else:
match = !map->nameQuoted 16 lines
drivers/pinctrl/core.c static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) · line 493
Quoted 13 lines
drivers/pinctrl/core.c +2
-2@@ -488,8 +488,8 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) int i; struct pinctrl_map const *map; - /* We must have dev or ID or both */ - if (!dev && !name) + /* We must have a state name */ + if (WARN_ON(!name)) return ERR_PTR(-EINVAL);We're already using the pinctrl device name for hog map. So should it be something like:
Quoted 1 line
if (WARN_ON(!dev) || WARN_ON(!name))
That's only true starting with the next patch in this series, which does modify the code roughly as you described.
Signature · 1 line
nvpublic
Re: [PATCH 08/20] pinctrl: Assume map table entries can't have a NULL name field
Quoted 8 lines · Stephen Warren
Dong Aisheng wrote at Tuesday, February 21, 2012 6:08 AM:
Quoted 7 lines · Stephen Warren
Quoted 5 lines
pinctrl_register_mappings()already requires that every mapping table entry have a non-NULL name field.Logically, this makes sense too; drivers should always request a specific named state so they know what they're getting. Relying on getting the
Quoted 8 lines
Quoted 6 lines
Hmm? It makes me a little confused.
IIRC we allow the driver to request NULL map name in the linaro connect discussion.
For those devices they do not want to support multi states, they really don't want to care about the state name.
The original way is convenient for such a case.With device tree, every state is always going to have /some/ name; the
I remember the discussion is that pinctrl-name is optional and map name is always specified by pinctrl-name or automatically generated by the id of pinctrl property (e.g. for pinctrl-0, 0 is the name) However user may not want to care about it although there's a name.
BTW my above comment may not right since i still have not read all you patches in the series and do not know if any difference on your implementation with the original proposal i will continue to read your patches.
Quoted 8 lines
binding we discussed didn't include any way to specify "no name" or "default name" or "default state", so this will keeps things a little more consistent.
I possibly could be persuaded to allow NULL state names in the mapping table. However, if so, I think they should work a little differently to the code currently in pinctrl: Right now, a NULL parameter to
pinmux_get()allows matching against /any/ state name in the table. If we changed this
Yes it's /any/ state but it's always the first state.
Quoted 2 lines
to only allow matching against mapping table with a NULL name, that might be OK, since it'd be very explicit what it matched. But, as I mentione
If that how about many states with NULL name?
Quoted 1 line
above, migrating such a driver to device tree would require changing this
I can see many changes, it looks just as the same as before (using first state as default state), did i understand right?
Quoted 9 lines
so I'm not inclined to like that solution without strong requirements.
In other words, what we have right now is something like:
if name:
match = !strcmp(name, map->name)else:
match = true
Quoted 6 lines
If we continue to allow NULL names, I think we should change that to:
if name:
match = map->name && !strcmp(name, map->name) else: match = !map->name
As above many states name may be NULL.
So here it becomes the first NULL name state.
Regards
Dong Aisheng
PATCH 9/20 pinctrl: Disallow map table entries with NULL dev_name field
In reply to Stephen WarrenHog entries are mapping table entries with .ctrl_dev_name == .dev_name. All other mapping table entries need .dev_name set so that they will match some pinctrl_get() call. All extant PIN_MAP*() macros set .dev_name.
So, there is no reason to allow mapping table entries without .dev_name set. Update the code and documentation to disallow this.
--- Documentation/pinctrl.txt | 15 +++----- drivers/pinctrl/core.c | 75 ++++++++++++-------------------------- include/linux/pinctrl/machine.h | 7 ---- 3 files changed, 29 insertions(+), 68 deletions(-)
Documentation/pinctrl.txt +5 -10
@@ -494,14 +494,10 @@ Definitions: {"map-i2c0", i2c0, pinctrl0, fi2c0, gi2c0} } - Every map must be assigned a symbolic name, pin controller and function. - The group is not compulsory - if it is omitted the first group presented by - the driver as applicable for the function will be selected, which is - useful for simple cases. - - The device name is present in map entries tied to specific devices. Maps - without device names are referred to as SYSTEM pinmuxes, such as can be taken - by the machine implementation on boot and not tied to any specific device. + Every map must be assigned a state name, pin controller, device and + function. The group is not compulsory - if it is omitted the first group + presented by the driver as applicable for the function will be selected, + which is useful for simple cases. It is possible to map several groups to the same combination of device, pin controller and function. This is for cases where a certain function on
@@ -979,8 +975,7 @@ after this you should be able to see this in the debugfs listing of all pins. System pin control hogging ========================== -A system pin control map entry, i.e. a pin control setting that does not have -a device associated with it, can be hogged by the core when the pin controller +Pin control map entries can be hogged by the core when the pin controller is registered. This means that the core will attempt to call pinctrl_get() and pinctrl_enable() on it immediately after the pin control device has been registered.
drivers/pinctrl/core.c +24 -51
130 lines not on this page · raw message
include/linux/pinctrl/machine.h +0 -7
@@ -46,13 +46,6 @@ struct pinctrl_map { { .name = a, .ctrl_dev_name = b, .function = c, .dev_name = d }/* -* Convenience macro to map a system function onto a certain pinctrl device. -* System functions are not assigned to a particular device. -*/ -#define PIN_MAP_SYS (a, b, c) \ - { .name = a, .ctrl_dev_name = b, .function = c } - -/* * Convenience macro to map a system function onto a certain pinctrl device, * to be hogged by the pin control core until the system shuts down. */
Signature · 1 line
1.7.5.4
Re: [PATCH 09/20] pinctrl: Disallow map table entries with NULL dev_name field
Quoted 9 lines · Stephen Warren
Hog entries are mapping table entries with .ctrl_dev_name == .dev_name. All other mapping table entries need .dev_name set so that they will match some
pinctrl_get()call. All extant PIN_MAP*() macros set .dev_name.So, there is no reason to allow mapping table entries without .dev_name set. Update the code and documentation to disallow this.
Signed-off-by Stephen Warren <[email protected]>
OK
I would have applied it if it wasn't that I had some questions on earlier patches that I didn't apply so it conflicts.
Yours,
Linus Walleij
Re: [PATCH 09/20] pinctrl: Disallow map table entries with NULL dev_name field
In reply to Stephen WarrenQuoted 10 lines · Stephen Warren
Hog entries are mapping table entries with .ctrl_dev_name == .dev_name. All other mapping table entries need .dev_name set so that they will match some
pinctrl_get()call. All extant PIN_MAP*() macros set .dev_name.So, there is no reason to allow mapping table entries without .dev_name set. Update the code and documentation to disallow this.
Signed-off-by Stephen Warren <[email protected]>---
Except code derived from last patch that not allow the map name to be NULL for pinctrl_get since it seems still not determined, for this patch itself:
Regards
Dong Aisheng
PATCH 10/20 pinctrl: Assume map table entries can't have a NULL ctrl_dev_name field
In reply to Stephen WarrenThese are already disallowed. Clean up some code that doesn't assume this.
--- drivers/pinctrl/core.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/pinctrl/core.c +1 -2
@@ -770,8 +770,7 @@ static int pinctrl_hog_maps(struct pinctrl_dev *pctldev)mutex_lock (&pinctrl_maps_mutex);for_each_maps (maps_node, i, map) { -if (map->ctrl_dev_name && - !strcmp (map->ctrl_dev_name, devname) && +if (!strcmp (map->ctrl_dev_name, devname) && !strcmp (map->dev_name, devname)) {/* OK time to hog! */ ret =pinctrl_hog_map (pctldev, map);
Signature · 1 line
1.7.5.4
Linus Walleij
AppliedRe: [PATCH 10/20] pinctrl: Assume map table entries can't have a NULL ctrl_dev_name field
Quoted 3 lines · Stephen Warren
These are already disallowed. Clean up some code that doesn't assume this.
Signed-off-by Stephen Warren <[email protected]>
Thanks, applied!
Yours,
Linus Walleij
Re: [PATCH 10/20] pinctrl: Assume map table entries can't have a NULL ctrl_dev_name field
In reply to Stephen WarrenQuoted 24 lines · Stephen Warren
These are already disallowed. Clean up some code that doesn't assume this.
Signed-off-by Stephen Warren <[email protected]>--- drivers/pinctrl/core.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)drivers/pinctrl/core.c +1
-2@@ -770,8 +770,7 @@ static int pinctrl_hog_maps(struct pinctrl_dev *pctldev)mutex_lock (&pinctrl_maps_mutex);for_each_maps (maps_node, i, map) { -if (map->ctrl_dev_name && - !strcmp (map->ctrl_dev_name, devname) && +if (!strcmp (map->ctrl_dev_name, devname) && !strcmp (map->dev_name, devname)) {/* OK time to hog! */ ret =pinctrl_hog_map (pctldev, map);Signature · 1 line
1.7.5.4
Regards
Dong Aisheng
PATCH 11/20 pinctrl: Downgrade pinctrl_get warning when no maps are found
In reply to Stephen WarrenThis may be perfectly legitimate. An IP block may get re-used across SoCs. Not all of those SoCs may need pinmux settings for the IP block, e.g. if one SoC dedicates pins to that function but another doesn't. The driver won't know this, and will always attempt to set up the pinmux. The mapping table defines whether any HW programming is actually needed.
--- drivers/pinctrl/core.c | 17 ++++++++++------- 1 files changed, 10 insertions(+), 7 deletions(-)
drivers/pinctrl/core.c +10 -7
@@ -542,13 +542,16 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) num_maps++; } -/* We should have atleast one map, right */ -if (!num_maps) { -pr_err ("could not find any mux maps for device %s, ID %s\n" , - devname, name); -kfree (p); -return ERR_PTR (-EINVAL ); - } +/* +* This may be perfectly legitimate. An IP block may get re-used +* across SoCs. Not all of those SoCs may need pinmux settings for the +* IP block, e.g. if one SoC dedicates pins to that function but +* another doesn't. The driver won't know this, and will always +* attempt to set up the pinmux. The mapping table defines whether any +* HW programming is actually needed. +*/ +if (!num_maps) +dev_info (dev,"zero maps found for state %s\n" , name);pr_debug ("found %u mux maps for device %s, UD %s\n" , num_maps, devname, name);
Signature · 1 line
1.7.5.4
Re: [PATCH 11/20] pinctrl: Downgrade pinctrl_get warning when no maps are found
Quoted 8 lines · Stephen Warren
This may be perfectly legitimate. An IP block may get re-used across SoCs. Not all of those SoCs may need pinmux settings for the IP block, e.g. if one SoC dedicates pins to that function but another doesn't. The driver won't know this, and will always attempt to set up the pinmux. The mapping table defines whether any HW programming is actually needed.
Signed-off-by Stephen Warren <[email protected]>
This is equivalent to providing dummy pincontrollers as was on my TODO for a while admittedly.
For consistency with regulators it would maybe be better to have optional dummy pin controllers but after thinking a bit about it I think this is more helpful, so I applied it anyway.
However I would invite more opinions...
Yours,
Linus Walleij
Shawn Guo
Acked-byRe: [PATCH 11/20] pinctrl: Downgrade pinctrl_get warning when no maps are found
Quoted 11 lines · Linus Walleij
Quoted 8 lines · Stephen Warren
This may be perfectly legitimate. An IP block may get re-used across SoCs. Not all of those SoCs may need pinmux settings for the IP block, e.g. if one SoC dedicates pins to that function but another doesn't. The driver won't know this, and will always attempt to set up the pinmux. The mapping table defines whether any HW programming is actually needed.
Signed-off-by Stephen Warren <[email protected]>
Quoted 9 lines
This is equivalent to providing dummy pincontrollers as was on my TODO for a while admittedly.
For consistency with regulators it would maybe be better to have optional dummy pin controllers but after thinking a bit about it I think this is more helpful, so I applied it anyway.
However I would invite more opinions...
I do not have an opinion on how we do it, and my opinion is just we need to have it. So,
Signature · 2 lines
Regards, Shawn
Re: [PATCH 11/20] pinctrl: Downgrade pinctrl_get warning when no maps are found
In reply to Linus WalleijQuoted 11 lines · Linus Walleij
Quoted 8 lines · Stephen Warren
This may be perfectly legitimate. An IP block may get re-used across SoCs. Not all of those SoCs may need pinmux settings for the IP block, e.g. if one SoC dedicates pins to that function but another doesn't. The driver won't know this, and will always attempt to set up the pinmux. The mapping table defines whether any HW programming is actually needed.
Signed-off-by Stephen Warren <[email protected]>
Quoted 9 lines
This is equivalent to providing dummy pincontrollers as was on my TODO for a while admittedly.
For consistency with regulators it would maybe be better to have optional dummy pin controllers but after thinking a bit about it I think this is more helpful, so I applied it anyway.
However I would invite more opinions...
I'm afraid this is a little error-prone, that means even we specifed the wrong map name or state name, the pinctrl_get still does not get failed and it is a little different as what we want in this patch.
Regards
Dong Aisheng
RE: [PATCH 11/20] pinctrl: Downgrade pinctrl_get warning when no maps are found
Dong Aisheng wrote at Tuesday, February 21, 2012 11:57 PM:
Quoted 19 lines · Linus Walleij
Quoted 18 lines · Stephen Warren
Quoted 9 lines
This may be perfectly legitimate. An IP block may get re-used across SoCs. Not all of those SoCs may need pinmux settings for the IP block, e.g. if one SoC dedicates pins to that function but another doesn't. The driver won't know this, and will always attempt to set up the pinmux. The mapping table defines whether any HW programming is actually needed.
Signed-off-by Stephen Warren <[email protected]>This is equivalent to providing dummy pincontrollers as was on my TODO for a while admittedly.
For consistency with regulators it would maybe be better to have optional dummy pin controllers but after thinking a bit about it I think this is more helpful, so I applied it anyway.
Quoted 5 lines
Quoted 1 line
However I would invite more opinions...
I'm afraid this is a little error-prone, that means even we specifed the wrong map name or state name, the
pinctrl_getstill does not get failed and it is a little different as what we want in this patch.
Yes, this does open up a small opportunity for an undetected error at this stage in the patch series.
However, this is closed later by the final patch that enhances the mapping table to represent pin config data, and "dummy" states.
I wrote/posted this patch to highlight that this code should be checking for non-existent states, rather than states which match no mapping table entries. Admittedly, there's no way to represent the difference at this point in the patch series. Once the final patch is applied, there's an explicit way to represent a state that exists, but has no mapping table entries, so the opportunity for error then no longer exists.
Signature · 1 line
nvpublic
Re: [PATCH 11/20] pinctrl: Downgrade pinctrl_get warning when no maps are found
On Wed, Feb 22, 2012 at 09:21:25AM -0800, Stephen Warren wrote:
...
Quoted 10 lines
Quoted 3 lines
I'm afraid this is a little error-prone, that means even we specifed the wrong map name or state name, the
pinctrl_getstill does not get failed and it is a little different as what we want in this patch.Yes, this does open up a small opportunity for an undetected error at this stage in the patch series.
However, this is closed later by the final patch that enhances the mapping table to represent pin config data, and "dummy" states.
Quoted 7 lines
I wrote/posted this patch to highlight that this code should be checking for non-existent states, rather than states which match no mapping table entries. Admittedly, there's no way to represent the difference at this point in the patch series. Once the final patch is applied, there's an explicit way to represent a state that exists, but has no mapping table entries, so the opportunity for error then no longer exists.
Ok, it's good.
Will see your final patch for this issue.
Regards
Dong Aisheng
PATCH 12/20 pinctrl: Use dev_*() instead of pr_*(), add some msgs, minor cleanups
In reply to Stephen Warrene.g. dev_err instead of pr_err prints messages in a slightly more standardized format.
Also, add a few more error messages to track down errors.
Also, some small cleanups of messages.
--- drivers/pinctrl/core.c | 38 ++++++++++++++++++++++---------------- 1 files changed, 22 insertions(+), 16 deletions(-)
drivers/pinctrl/core.c +22 -16
@@ -212,8 +212,10 @@ static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev, } pindesc =kzalloc (sizeof (*pindesc),GFP_KERNEL ); -if (pindesc ==NULL ) +if (pindesc ==NULL ) { +dev_err (pctldev->dev,"failed to alloc struct pin_desc\n" );return -ENOMEM ; + }spin_lock_init (&pindesc->lock);
@@ -493,7 +495,7 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) devname =dev_name (dev); -pr_debug ("get pin control handle device %s state %s\n" , devname, name); +dev_dbg (dev,"pinctrl_get() for state %s\n" , name);/* * create the state cookie holder struct pinctrl for each
@@ -501,8 +503,10 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)* a pin control handle with pinctrl_get() */ p =kzalloc (sizeof (struct pinctrl ),GFP_KERNEL ); -if (p ==NULL ) +if (p ==NULL ) { +dev_err (dev,"failed to alloc struct pinctrl\n" );return ERR_PTR (-ENOMEM ); + }mutex_init (&p->mutex);pinmux_init_pinctrl_handle (p);
@@ -513,17 +517,15 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)*/ pctldev =get_pinctrl_dev_from_devname (map->ctrl_dev_name);if (!pctldev) { -pr_warning ("could not find a pinctrl device for pinmux function %s, fishy, they shall all have one\n" , - map->function); -pr_warning ("given pinctrl device name: %s" , - map->ctrl_dev_name); +dev_warn (dev,"unknown pinctrl device %s in map entry" , + map->ctrl_dev_name);/* Continue to check the other mappings anyway... */ continue ; } -pr_debug ("in map, found pctldev %s to handle function %s" , -dev_name (pctldev->dev), map->function); +dev_dbg (dev,"in map, found pctldev %s to handle function %s" , +dev_name (pctldev->dev), map->function);/* Map must be for this device */ if (strcmp (map->dev_name, devname))
@@ -553,8 +555,7 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)if (!num_maps)dev_info (dev,"zero maps found for state %s\n" , name); -pr_debug ("found %u mux maps for device %s, UD %s\n" , - num_maps, devname, name); +dev_dbg (dev,"found %u maps for state %s\n" , num_maps, name);/* Add the pinmux to the global list */ mutex_lock (&pinctrl_list_mutex);
@@ -665,7 +666,7 @@ int pinctrl_register_mappings(struct pinctrl_map const *maps,for (i =0 ; i < num_maps; i++) {if (!maps[i].name) {pr_err ("failed to register map %d: no map name given\n" , - i); + i);return -EINVAL ; }
@@ -677,13 +678,13 @@ int pinctrl_register_mappings(struct pinctrl_map const *maps,if (!maps[i].function) {pr_err ("failed to register map %s (%d): no function ID given\n" , - maps[i].name, i); + maps[i].name, i);return -EINVAL ; }if (!maps[i].dev_name) {pr_err ("failed to register map %s (%d): no device given\n" , - maps[i].name, i); + maps[i].name, i);return -EINVAL ; } }
@@ -697,6 +698,7 @@ int pinctrl_register_mappings(struct pinctrl_map const *maps, maps_node->num_maps = num_maps; maps_node->maps =kmemdup (maps,sizeof (*maps) * num_maps,GFP_KERNEL );if (!maps_node->maps) { +pr_err ("failed to duplicate mapping table\n" );kfree (maps_node);return -ENOMEM ; }
@@ -717,8 +719,10 @@ static int pinctrl_hog_map(struct pinctrl_dev *pctldev,int ret; hog =kzalloc (sizeof (struct pinctrl_hog ),GFP_KERNEL ); -if (!hog) +if (!hog) { +dev_err (pctldev->dev,"failed to alloc struct pinctrl_hog\n" );return -ENOMEM ; + } p =pinctrl_get_locked (pctldev->dev, map->name);if (IS_ERR (p)) {
@@ -1149,8 +1153,10 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,return NULL ; pctldev =kzalloc (sizeof (struct pinctrl_dev ),GFP_KERNEL ); -if (pctldev ==NULL ) +if (pctldev ==NULL ) { +dev_err (dev,"failed to alloc struct pinctrl_dev\n" );return NULL ; + }/* Initialize pin control device struct */ pctldev->owner = pctldesc->owner;
Signature · 1 line
1.7.5.4
Re: [PATCH 12/20] pinctrl: Use dev_*() instead of pr_*(), add some msgs, minor cleanups
Quoted 2 lines · Stephen Warren
e.g.
dev_errinstead ofpr_errprints messages in a slightly more standardized format.
Fine with me but I couldn't apply it due to too many conflicts due to the unapplied patch for handling NULL regulators that we haven't ironed out yet, so will need some rebasing...
Thanks,
Linus Walleij
Re: [PATCH 12/20] pinctrl: Use dev_*() instead of pr_*(), add some msgs, minor cleanups
In reply to Stephen WarrenQuoted 9 lines · Stephen Warren
e.g.
dev_errinstead ofpr_errprints messages in a slightly more standardized format.Also, add a few more error messages to track down errors.
Also, some small cleanups of messages.
Signed-off-by Stephen Warren <[email protected]>---
Regards
Dong Aisheng
PATCH 13/20 pinctrl: Error if mapping table's control dev can't be found
In reply to Stephen WarrenThis is a serious error, and the pin control system will not function correctly if it ends up not programing the mapping table entries into the HW. Instead of just ignoring this, error out.
--- drivers/pinctrl/core.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
drivers/pinctrl/core.c +6 -5
@@ -517,11 +517,12 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)*/ pctldev =get_pinctrl_dev_from_devname (map->ctrl_dev_name);if (!pctldev) { -dev_warn (dev,"unknown pinctrl device %s in map entry" , - map->ctrl_dev_name); - -/* Continue to check the other mappings anyway... */ -continue ; +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 -ENODEV ; } dev_dbg(dev, "in map, found pctldev %s to handle function %s",
Signature · 1 line
1.7.5.4
Linus Walleij
AppliedRe: [PATCH 13/20] pinctrl: Error if mapping table's control dev can't be found
Quoted 5 lines · Stephen Warren
This is a serious error, and the pin control system will not function correctly if it ends up not programing the mapping table entries into the HW. Instead of just ignoring this, error out.
Signed-off-by Stephen Warren <[email protected]>
Thanks applied, this came to bite me today so I see the value of being strict here.
Quoted 2 lines
+ /* Eventually, this should trigger deferred probe */
+ return-ENODEV;
I changed this to ERR_PTR(-ENODEV) in my codebase as it returns a pointer.
Yours,
Linus Walleij
RE: [PATCH 13/20] pinctrl: Error if mapping table's control dev can't be found
Linus Walleij wrote at Tuesday, February 21, 2012 6:59 AM:
Quoted 8 lines · Stephen Warren
Quoted 6 lines
This is a serious error, and the pin control system will not function correctly if it ends up not programing the mapping table entries into the HW. Instead of just ignoring this, error out.
Signed-off-by Stephen Warren <[email protected]>
Quoted 8 lines
Thanks applied, this came to bite me today so I see the value of being strict here.
Quoted 2 lines
+ /* Eventually, this should trigger deferred probe */
+ return-ENODEV;I changed this to
ERR_PTR(-ENODEV)in my codebase as it returns a pointer.
Thanks. I thought I'd fixed that up after compiling each patch individually, but I guess I missed one:-(
Signature · 1 line
nvpublic
PATCH 14/20 pinctrl: Allocate sizeof(*p) instead of sizeof(struct foo)
In reply to Stephen WarrenThis hopefully makes it harder to take the sizeof the wrong type.
--- drivers/pinctrl/core.c | 8 ++++---- drivers/pinctrl/pinmux.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/pinctrl/core.c +4 -4
@@ -502,7 +502,7 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)* mapping, this is what consumers will get when requesting * a pin control handle with pinctrl_get() */ - p =kzalloc (sizeof (struct pinctrl ),GFP_KERNEL ); + p =kzalloc (sizeof (*p),GFP_KERNEL );if (p ==NULL ) {dev_err (dev,"failed to alloc struct pinctrl\n" );return ERR_PTR (-ENOMEM );
@@ -522,7 +522,7 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)pinmux_put (p);kfree (p);/* Eventually, this should trigger deferred probe */ -return -ENODEV ; +return ERR_PTR (-ENODEV ); } dev_dbg(dev, "in map, found pctldev %s to handle function %s",
@@ -719,7 +719,7 @@ static int pinctrl_hog_map(struct pinctrl_dev *pctldev,struct pinctrl *p;int ret; - hog =kzalloc (sizeof (struct pinctrl_hog ),GFP_KERNEL ); + hog =kzalloc (sizeof (*hog),GFP_KERNEL );if (!hog) {dev_err (pctldev->dev,"failed to alloc struct pinctrl_hog\n" );return -ENOMEM ;
@@ -1153,7 +1153,7 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,if (pctldesc->name ==NULL )return NULL ; - pctldev =kzalloc (sizeof (struct pinctrl_dev ),GFP_KERNEL ); + pctldev =kzalloc (sizeof (*pctldev),GFP_KERNEL );if (pctldev ==NULL ) {dev_err (dev,"failed to alloc struct pinctrl_dev\n" );return NULL ;
drivers/pinctrl/pinmux.c +1 -1
@@ -491,7 +491,7 @@ static int pinmux_enable_muxmap(struct pinctrl_dev *pctldev, p->func_selector = func_selector;/* Now add this group selector, we may have many of them */ - grp =kmalloc (sizeof (struct pinmux_group ),GFP_KERNEL ); + grp =kmalloc (sizeof (*grp),GFP_KERNEL );if (!grp)return -ENOMEM ; grp->group_selector = group_selector;
Signature · 1 line
1.7.5.4
Re: [PATCH 14/20] pinctrl: Allocate sizeof(*p) instead of sizeof(struct foo)
Quoted 3 lines · Stephen Warren
This hopefully makes it harder to take the sizeof the wrong type.
Signed-off-by Stephen Warren <[email protected]>
Would apply it if it wasn't for the conflicts...
Thanks,
Linus Walleij
Re: [PATCH 14/20] pinctrl: Allocate sizeof(*p) instead of sizeof(struct foo)
In reply to Stephen WarrenQuoted 3 lines · Stephen Warren
This hopefully makes it harder to take the sizeof the wrong type.
Signed-off-by Stephen Warren <[email protected]>
Regards
Dong Aisheng
PATCH 15/20 pinctrl: Fix and simplify locking
In reply to Stephen WarrenThere are many problems with the current pinctrl locking:
struct pinctrl_dev's pin_desc_tree_lock and pinctrl_hogs_lock aren't useful; the data they protect is read-only except when registering or unregistering a pinctrl_dev, and at those times, it doesn't make sense to protect one part of the structure independently from the rest.
struct pinctrl_dev's gpio_ranges_lock isn't effective; pinctrl_match_gpio_range() only holds this lock while searching for a gpio range, but the found range is return and manipulated after releading the lock. This could allow pinctrl_remove_gpio_range() for that range while it is in use, and the caller may very well delete the range after removing it, causing pinctrl code to touch the now-free range object.
Solving this requires the introduction of a higher-level lock, at least a lock per pin controller, which both gpio range registration and pinctrl_get()/put() will acquire.
There is missing locking on HW programming; pin controllers may pack the configuration for different pins/groups/config options/... into one register, and hence have to read-modify-write the register. This needs to be protected, but currently isn't. Related, a future change will add a "complete" op to the pin controller drivers, the idea being that each state's programming will be programmed into the pinctrl driver followed by the "complete" call, which may e.g. flush a register cache to HW. For this to work, it must not be possible to interleave the pinctrl driver calls for different devices.
As above, solving this requires the introduction of a higher-level lock, at least a lock per pin controller, which will be held for the duration of any pinctrl_enable()/disable() call.
However, each pinctrl mapping table entry may affect a different pin controller if necessary. Hence, with a per-pin-controller lock, almost any pinctrl API may need to acquire multiple locks, one per controller. To avoid deadlock, these would need to be acquired in the same order in all cases. This is extremely difficult to implement in the case of pinctrl_get(), which doesn't know which pin controllers to lock until it has parsed the entire mapping table, since it contains somewhat arbitrary data.
The simplest solution here is to introduce a single lock that covers all pin controllers at once. This will be acquired by all pinctrl APIs.
This then makes struct pinctrl's mutex irrelevant, since that single lock will always be held whenever this mutex is currently held.
--- drivers/pinctrl/core.c | 229 ++++++++++++++++++++++----------------- drivers/pinctrl/core.h | 21 ++-- drivers/pinctrl/pinconf.c | 107 ++++++++++++++----- drivers/pinctrl/pinmux.c | 22 ++--- include/linux/pinctrl/pinctrl.h | 1 - 5 files changed, 225 insertions(+), 155 deletions(-)
drivers/pinctrl/core.c +127 -102
@@ -18,11 +18,8 @@#include <linux/init.h> #include <linux/device.h> #include <linux/slab.h> -#include <linux/radix-tree.h> #include <linux/err.h> #include <linux/list.h> -#include <linux/mutex.h> -#include <linux/spinlock.h> #include <linux/sysfs.h> #include <linux/debugfs.h> #include <linux/seq_file.h>
@@ -56,16 +53,16 @@ struct pinctrl_hog {struct pinctrl *p; }; -/* Global list of pin control devices */ -static DEFINE_MUTEX (pinctrldev_list_mutex); +/* Mutex taken by all entry points */ +DEFINE_MUTEX (pinctrl_mutex); + +/* Global list of pin control devices (struct pinctrl_dev) */ static LIST_HEAD (pinctrldev_list); -/* List of pin controller handles */ -static DEFINE_MUTEX (pinctrl_list_mutex); +/* List of pin controller handles (struct pinctrl) */ static LIST_HEAD (pinctrl_list); -/* Global pinctrl maps */ -static DEFINE_MUTEX (pinctrl_maps_mutex); +/* List of pinctrl maps (struct pinctrl_maps) */ static LIST_HEAD (pinctrl_maps);#define for_each_maps (_maps_node_, _i_, _map_) \
@@ -102,7 +99,6 @@ struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *devname)if (!devname)return NULL ; -mutex_lock (&pinctrldev_list_mutex);list_for_each_entry (pctldev, &pinctrldev_list, node) {if (!strcmp (dev_name (pctldev->dev), devname)) {/* Matched on device name */
@@ -110,23 +106,10 @@ struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *devname)break ; } } -mutex_unlock (&pinctrldev_list_mutex);return found ? pctldev :NULL ; } -struct pin_desc *pin_desc_get (struct pinctrl_dev *pctldev,unsigned int pin) -{ -struct pin_desc *pindesc; -unsigned long flags; - -spin_lock_irqsave (&pctldev->pin_desc_tree_lock, flags); - pindesc =radix_tree_lookup (&pctldev->pin_desc_tree, pin); -spin_unlock_irqrestore (&pctldev->pin_desc_tree_lock, flags); - -return pindesc; -} -/** * pin_get_from_name() - look up a pin number from a name * @pctldev: the pin control device to lookup the pin on
@@ -167,11 +150,11 @@ bool pin_is_valid(struct pinctrl_dev *pctldev, int pin)if (pin <0 )return false; +mutex_lock (&pinctrl_mutex); pindesc =pin_desc_get (pctldev, pin); -if (pindesc ==NULL ) -return false; +mutex_unlock (&pinctrl_mutex); -return true; +return pindesc !=NULL ; }EXPORT_SYMBOL_GPL (pin_is_valid);
@@ -182,7 +165,6 @@ static void pinctrl_free_pindescs(struct pinctrl_dev *pctldev, {int i; -spin_lock (&pctldev->pin_desc_tree_lock);for (i =0 ; i < num_pins; i++) {struct pin_desc *pindesc;
@@ -196,7 +178,6 @@ static void pinctrl_free_pindescs(struct pinctrl_dev *pctldev, }kfree (pindesc); } -spin_unlock (&pctldev->pin_desc_tree_lock); } static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev,
@@ -217,8 +198,6 @@ static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev,return -ENOMEM ; } -spin_lock_init (&pindesc->lock); -/* Set owner */ pindesc->pctldev = pctldev;
@@ -232,9 +211,7 @@ static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev, pindesc->dynamic_name = true; } -spin_lock (&pctldev->pin_desc_tree_lock);radix_tree_insert (&pctldev->pin_desc_tree, number, pindesc); -spin_unlock (&pctldev->pin_desc_tree_lock);pr_debug ("registered pin %d (%s) on %s\n" , number, pindesc->name, pctldev->desc->name);return 0 ;
@@ -271,16 +248,13 @@ pinctrl_match_gpio_range(struct pinctrl_dev *pctldev, unsigned gpio)struct pinctrl_gpio_range *range =NULL ;/* Loop over the ranges */ -mutex_lock (&pctldev->gpio_ranges_lock);list_for_each_entry (range, &pctldev->gpio_ranges, node) {/* Check if we're in the valid range */ if (gpio >= range->base && gpio < range->base + range->npins) { -mutex_unlock (&pctldev->gpio_ranges_lock);return range; } } -mutex_unlock (&pctldev->gpio_ranges_lock);return NULL ; }
@@ -302,7 +276,6 @@ static int pinctrl_get_device_gpio_range(unsigned gpio,struct pinctrl_dev *pctldev =NULL ;/* Loop over the pin controllers */ -mutex_lock (&pinctrldev_list_mutex);list_for_each_entry (pctldev, &pinctrldev_list, node) {struct pinctrl_gpio_range *range;
@@ -310,11 +283,9 @@ static int pinctrl_get_device_gpio_range(unsigned gpio,if (range !=NULL ) { *outdev = pctldev; *outrange = range; -mutex_unlock (&pinctrldev_list_mutex);return 0 ; } } -mutex_unlock (&pinctrldev_list_mutex);return -EINVAL ; }
@@ -330,9 +301,9 @@ static int pinctrl_get_device_gpio_range(unsigned gpio,void pinctrl_add_gpio_range (struct pinctrl_dev *pctldev,struct pinctrl_gpio_range *range) { -mutex_lock (&pctldev->gpio_ranges_lock); +mutex_lock (&pinctrl_mutex);list_add_tail (&range->node, &pctldev->gpio_ranges); -mutex_unlock (&pctldev->gpio_ranges_lock); +mutex_unlock (&pinctrl_mutex); }EXPORT_SYMBOL_GPL (pinctrl_add_gpio_range);
@@ -344,9 +315,9 @@ EXPORT_SYMBOL_GPL(pinctrl_add_gpio_range);void pinctrl_remove_gpio_range (struct pinctrl_dev *pctldev,struct pinctrl_gpio_range *range) { -mutex_lock (&pctldev->gpio_ranges_lock); +mutex_lock (&pinctrl_mutex);list_del (&range->node); -mutex_unlock (&pctldev->gpio_ranges_lock); +mutex_unlock (&pinctrl_mutex); }EXPORT_SYMBOL_GPL (pinctrl_remove_gpio_range);
@@ -396,14 +367,21 @@ int pinctrl_request_gpio(unsigned gpio)int ret;int pin; +mutex_lock (&pinctrl_mutex); + ret =pinctrl_get_device_gpio_range (gpio, &pctldev, &range); -if (ret) +if (ret) { +mutex_unlock (&pinctrl_mutex);return -EINVAL ; + }/* Convert to the pin controllers number space */ pin = gpio - range->base + range->pin_base; -return pinmux_request_gpio (pctldev, range, pin, gpio); + ret =pinmux_request_gpio (pctldev, range, pin, gpio); + +mutex_unlock (&pinctrl_mutex); +return ret; }EXPORT_SYMBOL_GPL (pinctrl_request_gpio);
@@ -422,14 +400,20 @@ void pinctrl_free_gpio(unsigned gpio)int ret;int pin; +mutex_lock (&pinctrl_mutex); + ret =pinctrl_get_device_gpio_range (gpio, &pctldev, &range); -if (ret) +if (ret) { +mutex_unlock (&pinctrl_mutex);return ; + }/* Convert to the pin controllers number space */ pin = gpio - range->base + range->pin_base; -return pinmux_free_gpio (pctldev, pin, range); +pinmux_free_gpio (pctldev, pin, range); + +mutex_unlock (&pinctrl_mutex); }EXPORT_SYMBOL_GPL (pinctrl_free_gpio);
@@ -460,7 +444,11 @@ static int pinctrl_gpio_direction(unsigned gpio, bool input)*/ int pinctrl_gpio_direction_input (unsigned gpio) { -return pinctrl_gpio_direction (gpio, true); +int ret; +mutex_lock (&pinctrl_mutex); + ret =pinctrl_gpio_direction (gpio, true); +mutex_unlock (&pinctrl_mutex); +return ret; }EXPORT_SYMBOL_GPL (pinctrl_gpio_direction_input);
@@ -474,7 +462,11 @@ EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input);*/ int pinctrl_gpio_direction_output (unsigned gpio) { -return pinctrl_gpio_direction (gpio, false); +int ret; +mutex_lock (&pinctrl_mutex); + ret =pinctrl_gpio_direction (gpio, false); +mutex_unlock (&pinctrl_mutex); +return ret; }EXPORT_SYMBOL_GPL (pinctrl_gpio_direction_output);
@@ -507,7 +499,6 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)dev_err (dev,"failed to alloc struct pinctrl\n" );return ERR_PTR (-ENOMEM ); } -mutex_init (&p->mutex);pinmux_init_pinctrl_handle (p);/* Iterate over the pin control maps to locate the right ones */
@@ -559,9 +550,7 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)dev_dbg (dev,"found %u maps for state %s\n" , num_maps, name);/* Add the pinmux to the global list */ -mutex_lock (&pinctrl_list_mutex);list_add_tail (&p->node, &pinctrl_list); -mutex_unlock (&pinctrl_list_mutex);return p; }
@@ -577,74 +566,91 @@ struct pinctrl *pinctrl_get(struct device *dev, const char *name) {struct pinctrl *p; -mutex_lock (&pinctrl_maps_mutex); +mutex_lock (&pinctrl_mutex); p =pinctrl_get_locked (dev, name); -mutex_unlock (&pinctrl_maps_mutex); +mutex_unlock (&pinctrl_mutex);return p; }EXPORT_SYMBOL_GPL (pinctrl_get); -/** -* pinctrl_put() - release a previously claimed pin control handle -* @p: a pin control handle previously claimed by pinctrl_get() -*/ -void pinctrl_put (struct pinctrl *p) +static void pinctrl_put_locked (struct pinctrl *p) {if (p ==NULL )return ; -mutex_lock (&p->mutex);if (p->usecount)pr_warn ("releasing pin control handle with active users!\n" );/* Free the groups and all acquired pins */ pinmux_put (p); -mutex_unlock (&p->mutex);/* Remove from list */ -mutex_lock (&pinctrl_list_mutex);list_del (&p->node); -mutex_unlock (&pinctrl_list_mutex);kfree (p); } -EXPORT_SYMBOL_GPL (pinctrl_put);/** -* pinctrl_enable() - enable a certain pin controller setting -* @p: the pin control handle to enable, previously claimed by pinctrl_get() +* pinctrl_put() - release a previously claimed pin control handle +* @p: a pin control handle previously claimed by pinctrl_get() */ -int pinctrl_enable (struct pinctrl *p) +void pinctrl_put (struct pinctrl *p) +{ +mutex_lock (&pinctrl_mutex); +pinctrl_put (p); +mutex_unlock (&pinctrl_mutex); +} +EXPORT_SYMBOL_GPL (pinctrl_put); + +static int pinctrl_enable_locked (struct pinctrl *p) {int ret =0 ;if (p ==NULL )return -EINVAL ; -mutex_lock (&p->mutex); +if (p->usecount++ ==0 ) { ret =pinmux_enable (p);if (ret) p->usecount--; } -mutex_unlock (&p->mutex); +return ret; } -EXPORT_SYMBOL_GPL (pinctrl_enable);/** -* pinctrl_disable() - disable a certain pin control setting -* @p: the pin control handle to disable, previously claimed by pinctrl_get() +* pinctrl_enable() - enable a certain pin controller setting +* @p: the pin control handle to enable, previously claimed by pinctrl_get() */ -void pinctrl_disable (struct pinctrl *p) +int pinctrl_enable (struct pinctrl *p) +{ +int ret; +mutex_lock (&pinctrl_mutex); + ret =pinctrl_enable_locked (p); +mutex_unlock (&pinctrl_mutex); +return ret; +} +EXPORT_SYMBOL_GPL (pinctrl_enable); + +static void pinctrl_disable_locked (struct pinctrl *p) {if (p ==NULL )return ; -mutex_lock (&p->mutex);if (--p->usecount ==0 ) {pinmux_disable (p); } -mutex_unlock (&p->mutex); +} + +/** +* pinctrl_disable() - disable a certain pin control setting +* @p: the pin control handle to disable, previously claimed by pinctrl_get() +*/ +void pinctrl_disable (struct pinctrl *p) +{ +mutex_lock (&pinctrl_mutex); +pinctrl_disable_locked (p); +mutex_unlock (&pinctrl_mutex); }EXPORT_SYMBOL_GPL (pinctrl_disable);
@@ -704,9 +710,9 @@ int pinctrl_register_mappings(struct pinctrl_map const *maps,return -ENOMEM ; } -mutex_lock (&pinctrl_maps_mutex); +mutex_lock (&pinctrl_mutex);list_add_tail (&maps_node->node, &pinctrl_maps); -mutex_unlock (&pinctrl_maps_mutex); +mutex_unlock (&pinctrl_mutex);return 0 ; }
@@ -734,9 +740,9 @@ static int pinctrl_hog_map(struct pinctrl_dev *pctldev,return PTR_ERR (p); } - ret =pinctrl_enable (p); + ret =pinctrl_enable_locked (p);if (ret) { -pinctrl_put (p); +pinctrl_put_locked (p);kfree (hog); dev_err(pctldev->dev, "could not enable the %s pin control mapping for hogging\n",
@@ -749,9 +755,7 @@ static int pinctrl_hog_map(struct pinctrl_dev *pctldev,dev_info (pctldev->dev,"hogged map %s, function %s\n" , map->name, map->function); -mutex_lock (&pctldev->pinctrl_hogs_lock);list_add_tail (&hog->node, &pctldev->pinctrl_hogs); -mutex_unlock (&pctldev->pinctrl_hogs_lock);return 0 ; }
@@ -774,21 +778,16 @@ static int pinctrl_hog_maps(struct pinctrl_dev *pctldev)struct pinctrl_map const *map;INIT_LIST_HEAD (&pctldev->pinctrl_hogs); -mutex_init (&pctldev->pinctrl_hogs_lock); -mutex_lock (&pinctrl_maps_mutex);for_each_maps (maps_node, i, map) {if (!strcmp (map->ctrl_dev_name, devname) && !strcmp (map->dev_name, devname)) {/* OK time to hog! */ ret =pinctrl_hog_map (pctldev, map); -if (ret) { -mutex_unlock (&pinctrl_maps_mutex); +if (ret)return ret; - } } } -mutex_unlock (&pinctrl_maps_mutex);return 0 ; }
@@ -801,16 +800,14 @@ static void pinctrl_unhog_maps(struct pinctrl_dev *pctldev) {struct list_head *node, *tmp; -mutex_lock (&pctldev->pinctrl_hogs_lock);list_for_each_safe (node, tmp, &pctldev->pinctrl_hogs) {struct pinctrl_hog *hog = list_entry(node, struct pinctrl_hog, node); -pinctrl_disable (hog->p); -pinctrl_put (hog->p); +pinctrl_disable_locked (hog->p); +pinctrl_put_locked (hog->p);list_del (node);kfree (hog); } -mutex_unlock (&pctldev->pinctrl_hogs_lock); }#ifdef CONFIG_DEBUG_FS
@@ -823,6 +820,8 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)seq_printf (s,"registered pins: %d\n" , pctldev->desc->npins); +mutex_lock (&pinctrl_mutex); +/* The pin number can be retrived from the pin controller descriptor */ for (i =0 ; i < pctldev->desc->npins; i++) {struct pin_desc *desc;
@@ -843,6 +842,8 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)seq_puts (s,"\n" ); } +mutex_unlock (&pinctrl_mutex); +return 0 ; }
@@ -856,6 +857,8 @@ static int pinctrl_groups_show(struct seq_file *s, void *what)if (!ops)return 0 ; +mutex_lock (&pinctrl_mutex); +seq_puts (s,"registered pin groups:\n" );while (ops->list_groups (pctldev, selector) >=0 ) {const unsigned *pins;
@@ -878,6 +881,7 @@ static int pinctrl_groups_show(struct seq_file *s, void *what) selector++; } +mutex_unlock (&pinctrl_mutex);return 0 ; }
@@ -889,8 +893,9 @@ static int pinctrl_gpioranges_show(struct seq_file *s, void *what)seq_puts (s,"GPIO ranges handled:\n" ); +mutex_lock (&pinctrl_mutex); +/* Loop over the ranges */ -mutex_lock (&pctldev->gpio_ranges_lock);list_for_each_entry (range, &pctldev->gpio_ranges, node) { seq_printf(s, "%u: %s GPIOS [%u - %u] PINS [%u - %u]\n", range->id, range->name,
@@ -898,7 +903,8 @@ static int pinctrl_gpioranges_show(struct seq_file *s, void *what) range->pin_base, (range->pin_base + range->npins - 1)); } -mutex_unlock (&pctldev->gpio_ranges_lock); + +mutex_unlock (&pinctrl_mutex);return 0 ; }
@@ -911,7 +917,8 @@ static int pinctrl_maps_show(struct seq_file *s, void *what)seq_puts (s,"Pinctrl maps:\n" ); -mutex_lock (&pinctrl_maps_mutex); +mutex_lock (&pinctrl_mutex); +for_each_maps (maps_node, i, map) {seq_printf (s,"%s:\n" , map->name);seq_printf (s," device: %s\n" , map->dev_name);
@@ -920,7 +927,8 @@ static int pinctrl_maps_show(struct seq_file *s, void *what)seq_printf (s," group: %s\n" , map->group ? map->group :"(default)" ); } -mutex_unlock (&pinctrl_maps_mutex); + +mutex_unlock (&pinctrl_mutex);return 0 ; }
@@ -932,9 +940,13 @@ static int pinmux_hogs_show(struct seq_file *s, void *what)seq_puts (s,"Pin control map hogs held by device\n" ); +mutex_lock (&pinctrl_mutex); +list_for_each_entry (hog, &pctldev->pinctrl_hogs, node)seq_printf (s,"%s\n" , hog->map->name); +mutex_unlock (&pinctrl_mutex); +return 0 ; }
@@ -943,7 +955,9 @@ static int pinctrl_devices_show(struct seq_file *s, void *what)struct pinctrl_dev *pctldev;seq_puts (s,"name [pinmux] [pinconf]\n" ); -mutex_lock (&pinctrldev_list_mutex); + +mutex_lock (&pinctrl_mutex); +list_for_each_entry (pctldev, &pinctrldev_list, node) {seq_printf (s,"%s " , pctldev->desc->name);if (pctldev->desc->pmxops)
@@ -956,7 +970,8 @@ static int pinctrl_devices_show(struct seq_file *s, void *what)seq_puts (s,"no" );seq_puts (s,"\n" ); } -mutex_unlock (&pinctrldev_list_mutex); + +mutex_unlock (&pinctrl_mutex);return 0 ; }
@@ -966,6 +981,9 @@ static int pinctrl_show(struct seq_file *s, void *what)struct pinctrl *p;seq_puts (s,"Requested pin control handlers their pinmux maps:\n" ); + +mutex_lock (&pinctrl_mutex); +list_for_each_entry (p, &pinctrl_list, node) {struct pinctrl_dev *pctldev = p->pctldev;
@@ -984,6 +1002,8 @@ static int pinctrl_show(struct seq_file *s, void *what) p->dev ? dev_name(p->dev) : "(system)"); } +mutex_unlock (&pinctrl_mutex); +return 0 ; }
@@ -1164,9 +1184,7 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, pctldev->desc = pctldesc; pctldev->driver_data = driver_data;INIT_RADIX_TREE (&pctldev->pin_desc_tree,GFP_KERNEL ); -spin_lock_init (&pctldev->pin_desc_tree_lock);INIT_LIST_HEAD (&pctldev->gpio_ranges); -mutex_init (&pctldev->gpio_ranges_lock); pctldev->dev = dev;/* If we're implementing pinmuxing, check the ops for sanity */
@@ -1201,10 +1219,14 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, }pinctrl_init_device_debugfs (pctldev); -mutex_lock (&pinctrldev_list_mutex); + +mutex_lock (&pinctrl_mutex); +list_add_tail (&pctldev->node, &pinctrldev_list); -mutex_unlock (&pinctrldev_list_mutex);pinctrl_hog_maps (pctldev); + +mutex_unlock (&pinctrl_mutex); +return pctldev; out_err:
@@ -1225,15 +1247,18 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev)return ;pinctrl_remove_device_debugfs (pctldev); + +mutex_lock (&pinctrl_mutex); +pinctrl_unhog_maps (pctldev);/* TODO: check that no pinmuxes are still active? */ -mutex_lock (&pinctrldev_list_mutex);list_del (&pctldev->node); -mutex_unlock (&pinctrldev_list_mutex);/* Destroy descriptor tree */ pinctrl_free_pindescs (pctldev, pctldev->desc->pins, pctldev->desc->npins);kfree (pctldev); + +mutex_unlock (&pinctrl_mutex); }EXPORT_SYMBOL_GPL (pinctrl_unregister);
drivers/pinctrl/core.h +10 -11
@@ -9,6 +9,8 @@* License terms: GNU General Public License (GPL) version 2 */ +#include <linux/mutex.h> +#include <linux/radix-tree.h> #include <linux/pinctrl/pinconf.h> struct pinctrl_gpio_range ;
@@ -20,15 +22,12 @@ struct pinctrl_gpio_range;* controller * @pin_desc_tree: each pin descriptor for this pin controller is stored in * this radix tree -* @pin_desc_tree_lock: lock for the descriptor tree * @gpio_ranges: a list of GPIO ranges that is handled by this pin controller, * ranges are added to this list at runtime -* @gpio_ranges_lock: lock for the GPIO ranges list * @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 -* @pinctrl_hogs_lock: lock for the pin control hog list * @pinctrl_hogs: list of pin control maps hogged by this device * @device_root: debugfs root for this device */
@@ -36,13 +35,10 @@ struct pinctrl_dev {struct list_head node;struct pinctrl_desc *desc;struct radix_tree_root pin_desc_tree; -spinlock_t pin_desc_tree_lock;struct list_head gpio_ranges; -struct mutex gpio_ranges_lock;struct device *dev;struct module *owner;void *driver_data; -struct mutex pinctrl_hogs_lock;struct list_head pinctrl_hogs;#ifdef CONFIG_DEBUG_FS struct dentry *device_root;
@@ -56,7 +52,6 @@ struct pinctrl_dev {* @usecount: the number of active users of this pin controller setting, used * to keep track of nested use cases * @pctldev: pin control device handling this pin control handle -* @mutex: a lock for the pin control state holder * @func_selector: the function selector for the pinmux device handling * this pinmux * @groups: the group selectors for the pinmux device and
@@ -69,7 +64,6 @@ struct pinctrl {struct device *dev;unsigned usecount;struct pinctrl_dev *pctldev; -struct mutex mutex;#ifdef CONFIG_PINMUX unsigned func_selector;struct list_head groups;
@@ -82,7 +76,6 @@ struct pinctrl {* @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 -* @lock: a lock to protect the descriptor structure * @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 * subdrivers and shown in debugfs etc
@@ -91,7 +84,6 @@ struct pin_desc {struct pinctrl_dev *pctldev;const char *name;bool dynamic_name; -spinlock_t lock;/* These fields only added when supporting pinmux drivers */ #ifdef CONFIG_PINMUX const char *owner;
@@ -99,7 +91,14 @@ struct pin_desc { };struct pinctrl_dev *get_pinctrl_dev_from_devname (const char *dev_name); -struct pin_desc *pin_desc_get (struct pinctrl_dev *pctldev,unsigned int pin);int pin_get_from_name (struct pinctrl_dev *pctldev,const char *name);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); +} + +extern struct mutex pinctrl_mutex;
drivers/pinctrl/pinconf.c +79 -28
210 lines not on this page · raw message
drivers/pinctrl/pinmux.c +9 -13
@@ -19,8 +19,6 @@#include <linux/radix-tree.h> #include <linux/err.h> #include <linux/list.h> -#include <linux/mutex.h> -#include <linux/spinlock.h> #include <linux/string.h> #include <linux/sysfs.h> #include <linux/debugfs.h>
@@ -93,15 +91,12 @@ static int pin_request(struct pinctrl_dev *pctldev, goto out; } -spin_lock (&desc->lock);if (desc->owner &&strcmp (desc->owner, owner)) { -spin_unlock (&desc->lock);dev_err (pctldev->dev,"pin already requested\n" ); goto out; } desc->owner = owner; -spin_unlock (&desc->lock);/* Let each pin increase references to this module */ if (!try_module_get (pctldev->owner)) {
@@ -128,11 +123,8 @@ static int pin_request(struct pinctrl_dev *pctldev,dev_err (pctldev->dev,"->request on device %s failed for pin %d\n" , pctldev->desc->name, pin); out_free_pin: -if (status) { -spin_lock (&desc->lock); +if (status) desc->owner =NULL ; -spin_unlock (&desc->lock); - } out:if (status) dev_err(pctldev->dev, "pin-%d (%s) status %d\n",
@@ -175,10 +167,8 @@ static const char *pin_free(struct pinctrl_dev *pctldev, int pin,else if (ops->free) ops->free (pctldev, pin); -spin_lock (&desc->lock); owner = desc->owner; desc->owner =NULL ; -spin_unlock (&desc->lock);module_put (pctldev->owner);return owner;
@@ -590,6 +580,8 @@ static int pinmux_functions_show(struct seq_file *s, void *what)const struct pinmux_ops *pmxops = pctldev->desc->pmxops;unsigned func_selector =0 ; +mutex_lock (&pinctrl_mutex); +while (pmxops->list_functions (pctldev, func_selector) >=0 ) {const char *func = pmxops->get_function_name (pctldev, func_selector);
@@ -610,9 +602,10 @@ static int pinmux_functions_show(struct seq_file *s, void *what)seq_puts (s,"]\n" ); func_selector++; - } +mutex_unlock (&pinctrl_mutex); +return 0 ; }
@@ -624,9 +617,10 @@ static int pinmux_pins_show(struct seq_file *s, void *what)seq_puts (s,"Pinmux settings per pin\n" );seq_puts (s,"Format: pin (name): owner\n" ); +mutex_lock (&pinctrl_mutex); +/* The pin number can be retrived from the pin controller descriptor */ for (i =0 ; i < pctldev->desc->npins; i++) { -struct pin_desc *desc; pin = pctldev->desc->pins[i].number;
@@ -640,6 +634,8 @@ static int pinmux_pins_show(struct seq_file *s, void *what) desc->owner ? desc->owner : "UNCLAIMED"); } +mutex_unlock (&pinctrl_mutex); +return 0 ; }
include/linux/pinctrl/pinctrl.h +0 -1
@@ -15,7 +15,6 @@#ifdef CONFIG_PINCTRL #include <linux/radix-tree.h> -#include <linux/spinlock.h> #include <linux/list.h> #include <linux/seq_file.h>
Signature · 1 line
1.7.5.4
Re: [PATCH 15/20] pinctrl: Fix and simplify locking
Quoted 4 lines · Stephen Warren
struct pinctrl_dev's
pin_desc_tree_lockandpinctrl_hogs_lockaren't useful; the data they protect is read-only except when registering or unregistering apinctrl_dev, and at those times, it doesn't make sense to protect one part of the structure independently from the rest.
OK makes sense, please split this into a separate patch.
Quoted 10 lines
struct pinctrl_dev's
gpio_ranges_lockisn't effective;pinctrl_match_gpio_range()only holds this lock while searching for a gpio range, but the found range is return and manipulated after releading the lock. This could allowpinctrl_remove_gpio_range()for that range while it is in use, and the caller may very well delete the range after removing it, causing pinctrl code to touch the now-free range object.Solving this requires the introduction of a higher-level lock, at least a lock per pin controller, which both gpio range registration and pinctrl_get()/put() will acquire.
I don't really like this "big pinctrl lock" approach, atleast for the gpio ranges the proper approach would rather be to use RCU, would it not? The above looks like a textbook example of where RCU should be used.
Quoted 4 lines
There is missing locking on HW programming; pin controllers may pack the configuration for different pins/groups/config options/... into one register, and hence have to read-modify-write the register. This needs to be protected, but currently isn't.
Isn't that the responsibility of the driver? The subsystem should not make assumptions of what locking the driver may need of some drivers don't need it.
Quoted 10 lines
Related, a future change will add a
"complete" op to the pin controller drivers, the idea being that each state's programming will be programmed into the pinctrl driver followed by the "complete" call, which may e.g. flush a register cache to HW. For this to work, it must not be possible to interleave the pinctrl driver calls for different devices.As above, solving this requires the introduction of a higher-level lock, at least a lock per pin controller, which will be held for the duration of any pinctrl_enable()/disable() call.
I buy this reasoning though, we sure need something there, but then it can be introduced with the complete() call, and be a separate lock across the affected call.
Quoted 9 lines
However, each pinctrl mapping table entry may affect a different pin controller if necessary. Hence, with a per-pin-controller lock, almost any pinctrl API may need to acquire multiple locks, one per controller. To avoid deadlock, these would need to be acquired in the same order in all cases. This is extremely difficult to implement in the case of
pinctrl_get(), which doesn't know which pin controllers to lock until it has parsed the entire mapping table, since it contains somewhat arbitrary data.
Quoted 5 lines
The simplest solution here is to introduce a single lock that covers all pin controllers at once. This will be acquired by all pinctrl APIs.
This then makes struct pinctrl's mutex irrelevant, since that single lock will always be held whenever this mutex is currently held.
Introducing a big pincontroller lock :-(
As with the big kernel lock was the simplest approach to CPU locking.
I really would like to hold back on this, is it really that hard to have a more fine-granular locking here? Maybe this is a sign that we need to have the list of states sorted in pincontroller order simply? In that case we only need a lock per pincontroller I think.
Yours,
Linus Walleij
RE: [PATCH 15/20] pinctrl: Fix and simplify locking
Linus Walleij wrote at Wednesday, February 22, 2012 10:39 AM:
Quoted 16 lines · Stephen Warren
Quoted 5 lines
struct pinctrl_dev's
pin_desc_tree_lockandpinctrl_hogs_lockaren't useful; the data they protect is read-only except when registering or unregistering apinctrl_dev, and at those times, it doesn't make sense to protect one part of the structure independently from the rest.OK makes sense, please split this into a separate patch.
Quoted 7 lines
struct pinctrl_dev's
gpio_ranges_lockisn't effective;pinctrl_match_gpio_range()only holds this lock while searching for a gpio range, but the found range is return and manipulated after releading the lock. This could allowpinctrl_remove_gpio_range()for that range while it is in use, and the caller may very well delete the range after removing it, causing pinctrl code to touch the now-free range object.
Quoted 8 lines
Quoted 3 lines
Solving this requires the introduction of a higher-level lock, at least a lock per pin controller, which both gpio range registration and pinctrl_get()/put() will acquire.
I don't really like this "big pinctrl lock" approach, atleast for the gpio ranges the proper approach would rather be to use RCU, would it not? The above looks like a textbook example of where RCU should be used.
I'm not familiar with RCU specifically. If it's a single-writer-or- multiple-reader lock, that might well solve this issue.
Quoted 8 lines
Quoted 4 lines
There is missing locking on HW programming; pin controllers may pack the configuration for different pins/groups/config options/... into one register, and hence have to read-modify-write the register. This needs to be protected, but currently isn't.
Isn't that the responsibility of the driver? The subsystem should not make assumptions of what locking the driver may need of some drivers don't need it.
Deferring this to drivers might make sense. However, drivers don't have any way to do this right now, since they don't know when the start of a programming operation is. I suppose when adding complete() we could add a start() operation too, so the lock could be acquired there.
Quoted 32 lines
Quoted 10 lines
Related, a future change will add a
"complete" op to the pin controller drivers, the idea being that each state's programming will be programmed into the pinctrl driver followed by the "complete" call, which may e.g. flush a register cache to HW. For this to work, it must not be possible to interleave the pinctrl driver calls for different devices.As above, solving this requires the introduction of a higher-level lock, at least a lock per pin controller, which will be held for the duration of any pinctrl_enable()/disable() call.
I buy this reasoning though, we sure need something there, but then it can be introduced with the
complete()call, and be a separate lock across the affected call.Quoted 9 lines
However, each pinctrl mapping table entry may affect a different pin controller if necessary. Hence, with a per-pin-controller lock, almost any pinctrl API may need to acquire multiple locks, one per controller. To avoid deadlock, these would need to be acquired in the same order in all cases. This is extremely difficult to implement in the case of
pinctrl_get(), which doesn't know which pin controllers to lock until it has parsed the entire mapping table, since it contains somewhat arbitrary data.Quoted 5 lines
The simplest solution here is to introduce a single lock that covers all pin controllers at once. This will be acquired by all pinctrl APIs.
This then makes struct pinctrl's mutex irrelevant, since that single lock will always be held whenever this mutex is currently held.
Introducing a big pincontroller lock :-(
Quoted 7 lines
As with the big kernel lock was the simplest approach to CPU locking.
I really would like to hold back on this, is it really that hard to have a more fine-granular locking here? Maybe this is a sign that we need to have the list of states sorted in pincontroller order simply? In that case we only need a lock per pincontroller I think.
I'd rather not alter the order that the mapping table entries get applied in; I think that'd be confusing. I can certainly envisage use-cases where the order is important (e.g. must disable pin config feature X before enabling pin config feature Y when switching states, to avoid HW damage) and sorting the mapping table would violating such requirements much more likely.
Perhaps pinctrl_get() should keep a separate list of all pin controllers involved anywhere in all the struct pinctrl_settings it contains, and keep that list sorted, so that lock()/unlock() could be applied to that list up-front, rather than locking pin controllers lazily as the settings are applied in order. That'd be a bit more work but would probably allow us to avoid any global locks.
Then, I think we could get away with:
A global lock for (un)registering controllers, (un)registering mapping table entries, (un)registering GPIO ranges, parsing the mapping tables, but which would not be taken when simply programming HW.
I'm not sure whether breaking this up into multiple locks actually makes any sense; all of the above are relatively rare slow-paths anyway. The important thing would be to not take that lock when /just/ programming HW for state changes.
A lock per pin controller, implemented internally to the pin controller driver if required in begin()/end() ops.
Does that seem reasonable?
Related to that, I guess we're currently missing refcounts on pin controllers and GPIO ranges, so they can't be unregistered if pinctrl_get() returned an object that references them, or gpio_request() was called on a GPIO.
Signature · 1 line
nvpublic
RE: [PATCH 15/20] pinctrl: Fix and simplify locking
Stephen Warren wrote at Wednesday, February 22, 2012 11:27 AM:
Quoted 21 lines
Linus Walleij wrote at Wednesday, February 22, 2012 10:39 AM:
Quoted 20 lines · Stephen Warren
Quoted 5 lines
struct pinctrl_dev's
pin_desc_tree_lockandpinctrl_hogs_lockaren't useful; the data they protect is read-only except when registering or unregistering apinctrl_dev, and at those times, it doesn't make sense to protect one part of the structure independently from the rest.OK makes sense, please split this into a separate patch.
Quoted 10 lines
struct pinctrl_dev's
gpio_ranges_lockisn't effective;pinctrl_match_gpio_range()only holds this lock while searching for a gpio range, but the found range is return and manipulated after releading the lock. This could allowpinctrl_remove_gpio_range()for that range while it is in use, and the caller may very well delete the range after removing it, causing pinctrl code to touch the now-free range object.Solving this requires the introduction of a higher-level lock, at least a lock per pin controller, which both gpio range registration and pinctrl_get()/put() will acquire.
Quoted 7 lines
Quoted 4 lines
I don't really like this "big pinctrl lock" approach, atleast for the gpio ranges the proper approach would rather be to use RCU, would it not? The above looks like a textbook example of where RCU should be used.
I'm not familiar with RCU specifically. If it's a single-writer-or- multiple-reader lock, that might well solve this issue.
I don't think RCU is the answer here:
* RCU is great where the read path needs to be really fast at the (slight?) cost of write path speed. In pinctrl, I don't see that the paths that touch the GPIO ranges are especially time-critical since they're mostly probe/remove-time actions.
* RCU is easy to use for simple cases, but more tricky where you want to e.g. modify list elements in-place. While we don't right now, I'd like to add a "usecount" to the gpio_range, so we can guarantee one can't be unregistered while there's an active gpio_request() against it. Otherwise, it'd be impossible to gpio_free() later.
* RCU knows when you're done with something due to pre-emption. However, the internals of a pinctrl driver's gpio_request_enable might sleep e.g. if it needed to touch registers on an I2C bus. While there is a sleepable RCU, I don't think there's an sleepable equivalent of rculist.h.
...
Quoted 38 lines
Quoted 9 lines
Introducing a big pincontroller lock :-(
As with the big kernel lock was the simplest approach to CPU locking.
I really would like to hold back on this, is it really that hard to have a more fine-granular locking here? Maybe this is a sign that we need to have the list of states sorted in pincontroller order simply? In that case we only need a lock per pincontroller I think.
I'd rather not alter the order that the mapping table entries get applied in; I think that'd be confusing. I can certainly envisage use-cases where the order is important (e.g. must disable pin config feature X before enabling pin config feature Y when switching states, to avoid HW damage) and sorting the mapping table would violating such requirements much more likely.
Perhaps
pinctrl_get()should keep a separate list of all pin controllers involved anywhere in all the structpinctrl_settingsit contains, and keep that list sorted, so that lock()/unlock() could be applied to that list up-front, rather than locking pin controllers lazily as the settings are applied in order. That'd be a bit more work but would probably allow us to avoid any global locks.Then, I think we could get away with:
A global lock for (un)registering controllers, (un)registering mapping table entries, (un)registering GPIO ranges, parsing the mapping tables, but which would not be taken when simply programming HW.
I'm not sure whether breaking this up into multiple locks actually makes any sense; all of the above are relatively rare slow-paths anyway. The important thing would be to not take that lock when /just/ programming HW for state changes.
A lock per pin controller, implemented internally to the pin controller driver if required in begin()/end() ops.
Quoted 6 lines
Does that seem reasonable?
Related to that, I guess we're currently missing refcounts on pin controllers and GPIO ranges, so they can't be unregistered if
pinctrl_get()returned an object that references them, orgpio_request()was called on a GPIO.
I did start looking into having separate locks, and I don't think it's really feasible; I'd still like to go with the above; one lock for any slow-path data-manipulation and one per "struct pinctrl *p" to allow parallelism in the fast path. Some examples of issues with lots of locks:
It'd be nice to have a lock per struct pinctrl_dev.
I'd like to add a usecount to struct pinctrl_dev. Any struct pinctrl that uses a struct pinctrl_dev, or any gpio_request will increase the usecount, so that the struct pinctrl_dev can't be unregistered while a struct pinctrl or GPIO could use it. That'd require something like the following at the end of pinctrl_register():
mutex_lock(&pinctrldev_list_mutex); /* * Must do this first, because pinctrl_get needs to find this * device in the list in order to convert mapping table entries */ list_add_tail(&pctldev->node, &pinctrldev_list); /* * This must be held so that when pinctrldev_list_mutex is dropped, * other threads still can't touch pctldev and mess with it usecount * until we're through here. This could be done before the first * mutex_lock above too. */ mutex_lock(&pctldev->mutex); /* Done with list manipulations now */ mutex_unlock(&pinctrldev_list_mutex); pctldev->p = pinctrl_get(pctldev->dev, "default"); if (!IS_ERR(pctldev->p)) pinctrl_enable(pctldev->p); pctldev->usecount_post_hog = pctldev->usecount;
But, the internals of pinctrl_get() will need to increment the usecount of every pctldev it finds referenced from the mapping table. To do this, the pctldev must be locked since data inside it is being manipulated. However, that'd end up attempting to recursively lock this pctldev's lock, and Linux locks don't allow recursive locking.
Perhaps this could be solved by passing a bunch of parameters into pinctrl_get (or rather, an internal function called both from the public pinctrl_get and here) indicating what was already locked. However, that seems pretty nasty, and certainly not very simple.
Or perhaps, we should write some internal pinctrl_get that knows not to touch the pctldev's own usecount, so that we don't need the separate usecount_post_hog field, since that pinctrl_get wouldn't increment the regular usecount. However, that'd be a nasty special case to maintain.
So then I figured, let's just remove pctldev->mutex and use pinctrldev_list_mutex to cover both the list, and any/all struct pinctrl_dev manipulations. This has the nice advantage that pinctrl_get() no longer needs to lock/unlock a mutex for every mapping table entry, so speeds things up.
At this point, we could still have separate mutexes for:
pinctrldev_list_mutex: Any operation on a device.
pinctrl_list_mutex: Any operation on the list of struct pinctrl.
pinctrl_maps: Any operation on the mapping table list.
But then let's take a look at the public pinctrl_get: It needs to lock pinctrldev_list_mutex and pinctrl_maps for most of its operation, and pinctrl_list_mutex for a little.
Equally, pinctrl_put needs to lock pinctrldev_list_mutex for most of its operation since it'd be decreasing many struct pinctrl_dev.usecount in general, or at least doing it many times on a single pctldev. It'd need to lock pinctrl_list_mutex for at least a little.
All the GPIO functions also manipulate pctldev usecounts, so would need to hold pinctrldev_list_mutex for the data-manipulation portions of their run-time.
So, pinctrldev_list_mutex is almost a single global mutex anyway, except there are a bunch of other mutexes hanging around making life complex.
It turns out that the only real parallelism is:
pinctrl_register_mappings: Only needs pinctrl_maps, but this is probably the rarest operation and hardly needs to run parallel.
Every other list-manipulation operation needs to lock pinctrldev_list_mutex for either the majority of the time, or over-and-over so may as well just do it once.
pinctrl_enable/disable: The fast path. I think we can usefully have a separate mutex per each of these as I mentioned in the email I'm quoting.
So it seems again that we really need a single slow-path mutex, and a per-struct-pinctrl fast-path mutex.
Signature · 1 line
nvpublic
PATCH 16/20 pinctrl: Refactor struct pinctrl handling in core.c vs pinmux.c
In reply to Stephen WarrenThis 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.
--- drivers/pinctrl/core.c | 103 +++++++----- drivers/pinctrl/core.h | 26 ++- drivers/pinctrl/pinmux.c | 409 +++++++++++----------------------------------- drivers/pinctrl/pinmux.h | 42 ++--- 4 files changed, 193 insertions(+), 387 deletions(-)
drivers/pinctrl/core.c +64 -39
@@ -472,14 +472,15 @@ EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);static struct pinctrl *pinctrl_get_locked (struct device *dev,const char *name) { -struct pinctrl_dev *pctldev =NULL ; +struct pinctrl_dev *pctldev;const char *devname;struct pinctrl *p;unsigned num_maps =0 ; -int ret = -ENODEV ; +int ret;struct pinctrl_maps *maps_node;int i;struct pinctrl_map const *map; +struct pinctrl_setting *setting;/* We must have both dev and state name */ if (WARN_ON (!dev || !name))
@@ -499,10 +500,20 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)dev_err (dev,"failed to alloc struct pinctrl\n" );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 */ for_each_maps (maps_node, i, map) { +/* Map must be for this device */ +if (strcmp (map->dev_name, devname)) +continue ; + +/* State name must be the one we're looking for */ +if (strcmp (map->name, name)) +continue ; +/* * First, try to find the pctldev given in the map */
@@ -510,29 +521,28 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *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 ); + ret = -ENODEV ; + goto error; }dev_dbg (dev,"in map, found pctldev %s to handle function %s" ,dev_name (pctldev->dev), map->function); -/* Map must be for this device */ -if (strcmp (map->dev_name, devname)) -continue ; + setting =kzalloc (sizeof (*setting),GFP_KERNEL ); +if (setting ==NULL ) { +dev_err (dev, +"failed to alloc struct pinctrl_setting\n" ); + ret = -ENOMEM ; + goto error; + } -/* State name must be the one we're looking for */ -if (strcmp (map->name, name)) -continue ; + setting->pctldev = pctldev; + ret =pinmux_map_to_setting (map, setting); +if (ret <0 ) + goto error; - ret =pinmux_apply_muxmap (pctldev, p, dev, - devname, map); -if (ret) { -kfree (p); -return ERR_PTR (ret); - } +list_add_tail (&setting->node, &p->settings); num_maps++; }
@@ -553,6 +563,14 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)list_add_tail (&p->node, &pinctrl_list);return p; + +error: +list_for_each_entry (setting, &p->settings, node) +pinmux_free_setting (setting); + +kfree (p); + +return ERR_PTR (ret); }/**
@@ -576,13 +594,18 @@ EXPORT_SYMBOL_GPL(pinctrl_get);static void pinctrl_put_locked (struct pinctrl *p) { +struct pinctrl_setting *setting, *n; +if (p ==NULL )return ;if (p->usecount)pr_warn ("releasing pin control handle with active users!\n" ); -/* Free the groups and all acquired pins */ -pinmux_put (p); +list_for_each_entry_safe (setting, n, &p->settings, node) { +pinmux_free_setting (setting); +list_del (&setting->node); +kfree (setting); + }/* Remove from list */ list_del (&p->node);
@@ -604,18 +627,24 @@ EXPORT_SYMBOL_GPL(pinctrl_put);static int pinctrl_enable_locked (struct pinctrl *p) { -int ret =0 ; +struct pinctrl_setting *setting; +int ret;if (p ==NULL )return -EINVAL ;if (p->usecount++ ==0 ) { - ret =pinmux_enable (p); -if (ret) - p->usecount--; +list_for_each_entry (setting, &p->settings, node) { + ret =pinmux_enable_setting (setting); +if (ret <0 ) { +/* FIXME: Difficult to return to prev state */ + p->usecount--; +return ret; + } + } } -return ret; +return 0 ; }/**
@@ -634,11 +663,14 @@ EXPORT_SYMBOL_GPL(pinctrl_enable);static void pinctrl_disable_locked (struct pinctrl *p) { +struct pinctrl_setting *setting; +if (p ==NULL )return ;if (--p->usecount ==0 ) { -pinmux_disable (p); +list_for_each_entry (setting, &p->settings, node) +pinmux_disable_setting (setting); } }
@@ -979,27 +1011,20 @@ static int pinctrl_devices_show(struct seq_file *s, void *what)static int pinctrl_show (struct seq_file *s,void *what) {struct pinctrl *p; +struct pinctrl_setting *setting;seq_puts (s,"Requested pin control handlers their pinmux maps:\n" );mutex_lock (&pinctrl_mutex);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) { -seq_puts (s,"NO PIN CONTROLLER DEVICE\n" ); -continue ; +list_for_each_entry (setting, &p->settings, node) { +seq_printf (s," " ); +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);
drivers/pinctrl/core.h +16 -10
@@ -49,25 +49,31 @@ struct pinctrl_dev {* struct pinctrl - per-device pin control state holder * @node: global list node * @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 * to keep track of nested use cases -* @pctldev: pin control device handling this pin control handle -* @func_selector: the function selector for the pinmux device handling -* this pinmux -* @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 +* @settings: a list of settings for this device/state */ struct pinctrl {struct list_head node;struct device *dev; +const char *state;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; -#ifdef CONFIG_PINMUX +unsigned group_selector;unsigned func_selector; -struct list_head groups; -#endif };/**
drivers/pinctrl/pinmux.c +97 -312
480 lines not on this page · raw message
drivers/pinctrl/pinmux.h +16 -26
72 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Re: [PATCH 16/20] pinctrl: Refactor struct pinctrl handling in core.c vs pinmux.c
Quoted 23 lines · Stephen Warren
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 inpinmux.c, while the iteration over multiple settings is lifted tocore.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_stateobject will be inserted into the data model between the struct pinctrl and structpinctrl_setting.
Quoted 6 lines
3) The mapping table will be extended to allow specification of pin config settings too. To support this, struct
pinctrl_settingwill be enhanced to store either mux settings or config settings, and functions will be added topinconf.cto parse/execute pin configuration settings.Signed-off-by Stephen Warren <[email protected]>
This is elegant and exactly what we want to do.
Please rebase on top of well, whatever we agree upon for handling the get(NULL) case, and we're set to merge this too.
Thanks,
Linus Walleij
Re: [PATCH 16/20] pinctrl: Refactor struct pinctrl handling in core.c vs pinmux.c
In reply to Stephen WarrenQuoted 23 lines · Stephen Warren
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 inpinmux.c, while the iteration over multiple settings is lifted tocore.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_stateobject will be inserted into the data model between the struct pinctrl and structpinctrl_setting.
Quoted 6 lines
3) The mapping table will be extended to allow specification of pin config settings too. To support this, struct
pinctrl_settingwill be enhanced to store either mux settings or config settings, and functions will be added topinconf.cto parse/execute pin configuration settings.Signed-off-by Stephen Warren <[email protected]>
Looks good to me.
Please also with my tag.
BTW, one minor thing, see below:
...
Quoted 7 lines
drivers/pinctrl/pinmux.c +0
-7-/** -* 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 -*
drivers/pinctrl/pinmux.c int pinmux_gpio_direction(struct pinctrl_dev *pctldev, · line 237
Quoted 10 lines
drivers/pinctrl/pinmux.c +2
-8-* 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) +int pinmux_func_name_to_selector (struct pinctrl_dev *pctldev, + const char *function)
Static?
Regards
Dong Aisheng
PATCH 17/20 pinctrl: Add usecount to pins for muxing
In reply to Stephen WarrenMultiple mapping table entries could reference the same pin, and hence "own" it. This would be unusual now that pinctrl_get() represents a single state for a client device, but in the future when it represents all known states for a device, this is quite likely. Implement reference counting for pin ownership to handle this.
--- drivers/pinctrl/core.h | 1 + drivers/pinctrl/pinmux.c | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-)
drivers/pinctrl/core.h +1 -0
@@ -92,6 +92,7 @@ struct pin_desc {bool dynamic_name;/* These fields only added when supporting pinmux drivers */ #ifdef CONFIG_PINMUX +unsigned usecount;const char *owner;#endif };
drivers/pinctrl/pinmux.c +22 -7
@@ -83,11 +83,16 @@ static int pin_request(struct pinctrl_dev *pctldev, goto out; } -if (desc->owner &&strcmp (desc->owner, owner)) { +if (desc->usecount &&strcmp (desc->owner, owner)) {dev_err (pctldev->dev,"pin already requested\n" ); goto out; } + + desc->usecount++; +if (desc->usecount >1 ) +return 0 ; + desc->owner = owner;/* Let each pin increase references to this module */
@@ -100,9 +105,9 @@ static int pin_request(struct pinctrl_dev *pctldev, }/* -* If there is no kind of request function for the pin we just assume -* we got it by default and proceed. -*/ +* If there is no kind of request function for the pin we just assume +* we got it by default and proceed. +*/ if (gpio_range && ops->gpio_request_enable)/* This requests and enables a single GPIO pin */ status = ops->gpio_request_enable (pctldev, gpio_range, pin);
@@ -111,12 +116,18 @@ static int pin_request(struct pinctrl_dev *pctldev,else status =0 ; -if (status) +if (status) {dev_err (pctldev->dev,"->request on device %s failed for pin %d\n" , pctldev->desc->name, pin); +module_put (pctldev->owner); + } + out_free_pin: -if (status) - desc->owner =NULL ; +if (status) { + desc->usecount--; +if (!desc->usecount) + desc->owner =NULL ; + } out:if (status) dev_err(pctldev->dev, "pin-%d (%s) status %d\n",
@@ -150,6 +161,10 @@ static const char *pin_free(struct pinctrl_dev *pctldev, int pin,return NULL ; } + desc->usecount--; +if (desc->usecount) +return NULL ; +/* * If there is no kind of request function for the pin we just assume * we got it by default and proceed.
Signature · 1 line
1.7.5.4
Re: [PATCH 17/20] pinctrl: Add usecount to pins for muxing
Quoted 7 lines · Stephen Warren
Multiple mapping table entries could reference the same pin, and hence "own" it. This would be unusual now that
pinctrl_get()represents a single state for a client device, but in the future when it represents all known states for a device, this is quite likely. Implement reference counting for pin ownership to handle this.Signed-off-by Stephen Warren <[email protected]>
Seems like a good straight-forward way to solve this.
drivers/pinctrl/core.h struct pin_desc { · line 95
Quoted 9 lines
drivers/pinctrl/core.h +1
-0@@ -92,6 +92,7 @@ struct pin_desc { bool dynamic_name; /* These fields only added when supporting pinmux drivers */ #ifdef CONFIG_PINMUX + unsigned usecount;
kerneldoc for this? Preferably verbose...
Thanks,
Linus Walleij
Re: [PATCH 17/20] pinctrl: Add usecount to pins for muxing
In reply to Stephen WarrenQuoted 7 lines · Stephen Warren
Multiple mapping table entries could reference the same pin, and hence "own" it. This would be unusual now that
pinctrl_get()represents a single state for a client device, but in the future when it represents all known states for a device, this is quite likely. Implement reference counting for pin ownership to handle this.Signed-off-by Stephen Warren <[email protected]>
drivers/pinctrl/pinmux.c static int pin_request(struct pinctrl_dev *pctldev, · line 110
Quoted 7 lines
drivers/pinctrl/pinmux.c +3
-3/* -* If there is no kind of request function for the pin we just assume -* we got it by default and proceed. -*/ +* If there is no kind of request function for the pin we just assume +* we got it by default and proceed. +*/
I remember the correct format for multiple lines of comments is:
/*
* ...
*/
But i see the changes here are(i'm using mutt):
/*
* ...
*/
Can you help explain?
Else please also take my ACK:
Regards
Dong Aisheng
RE: [PATCH 17/20] pinctrl: Add usecount to pins for muxing
Dong Aisheng wrote at Monday, February 27, 2012 12:12 AM:
Quoted 8 lines · Stephen Warren
Quoted 7 lines
Multiple mapping table entries could reference the same pin, and hence "own" it. This would be unusual now that
pinctrl_get()represents a single state for a client device, but in the future when it represents all known states for a device, this is quite likely. Implement reference counting for pin ownership to handle this.Signed-off-by Stephen Warren <[email protected]>
...
Quoted 13 lines
drivers/pinctrl/pinmux.c static int pin_request(struct pinctrl_dev *pctldev, · line 110
Quoted 7 lines
drivers/pinctrl/pinmux.c +3
-3/* -* If there is no kind of request function for the pin we just assume -* we got it by default and proceed. -*/ +* If there is no kind of request function for the pin we just assume +* we got it by default and proceed. +*/ I remember the correct format for multiple lines of comments is:
/*
* ...
*/
Quoted 5 lines
But i see the changes here are(i'm using mutt):
/*
* ...
*/
Can you help explain?
It was a mistake; my editor corrupted it when I added or removed some indentation levels. I noticed this and fixed it locally when doing some rebasing.
Quoted 2 lines
Else please also take my ACK:
Acked-by Dong Aisheng <[email protected]>
Thanks.
Signature · 1 line
nvpublic
PATCH 18/20 pinctrl: Fix pinconf_groups_show() to emit newline
In reply to Stephen Warrenpinconf_groups_show() wrote all debug information on one line. Fix it to match pinconf_pins_show() and be legible.
--- drivers/pinctrl/pinconf.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/pinctrl/pinconf.c +2 -0
@@ -334,6 +334,8 @@ static int pinconf_groups_show(struct seq_file *s, void *what)seq_printf (s,"%u (%s):" , selector, gname);pinconf_dump_group (pctldev, s, selector, gname); +seq_printf (s,"\n" ); + selector++; }
Signature · 1 line
1.7.5.4
Linus Walleij
AppliedRe: [PATCH 18/20] pinctrl: Fix pinconf_groups_show() to emit newline
Quoted 4 lines · Stephen Warren
pinconf_groups_show()wrote all debug information on one line. Fix it to matchpinconf_pins_show()and be legible.Signed-off-by Stephen Warren <[email protected]>
Thanks, applied.
Linus Walleij
PATCH 19/20 pinctrl: API changes to support multiple states per device
In reply to Stephen WarrenThe API model is changed from:
p = pinctrl_get(dev, "state1");pinctrl_enable(p);
...pinctrl_disable(p);pinctrl_put(p);
p = pinctrl_get(dev, "state2");pinctrl_enable(p);
...pinctrl_disable(p);pinctrl_put(p);
to this:
p = pinctrl_get(dev);
s1 = pinctrl_lookup_state(p, "state1");
s2 = pinctrl_lookup_state(p, "state2");pinctrl_select_state(p, s1);
...pinctrl_select_state(p, s2);
...pinctrl_put(p);
This allows devices to directly transition between states without disabling the pin controller programming and put()/get()ing the configuration data each time. This model will also better suit pinconf programming, which doesn't have a concept of "disable".
The special-case hogging feature of pin controllers is re-written to use the regular APIs instead of special-case code. Hence, the pinmux-hogs debugfs file is removed; see the top-level pinctrl-handles files for equivalent data.
--- Documentation/pinctrl.txt | 153 ++++++++----- arch/arm/mach-u300/core.c | 28 +-- drivers/pinctrl/core.c | 491 +++++++++++++++++-------------------- drivers/pinctrl/core.h | 24 ++- drivers/tty/serial/sirfsoc_uart.c | 12 +- include/linux/pinctrl/consumer.h | 55 ++++- include/linux/pinctrl/machine.h | 21 +- 7 files changed, 408 insertions(+), 376 deletions(-)
Documentation/pinctrl.txt +97 -56
@@ -781,19 +781,22 @@ spi on the second function mapping: static const struct pinctrl_map __initdata mapping[] = { { + .dev_name = "foo-spi.0", + .name = "default", .ctrl_dev_name = "pinctrl-foo", .function = "spi0", - .dev_name = "foo-spi.0", }, { + .dev_name = "foo-i2c.0", + .name = "default", .ctrl_dev_name = "pinctrl-foo", .function = "i2c0", - .dev_name = "foo-i2c.0", }, { + .dev_name = "foo-mmc.0", + .name = "default", .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", - .dev_name = "foo-mmc.0", }, };
@@ -814,7 +817,7 @@ it even more compact which assumes you want to use pinctrl-foo and position 0 for mapping, for example: static struct pinctrl_map __initdata mapping[] = { - PIN_MAP("I2CMAP", "pinctrl-foo", "i2c0", "foo-i2c.0"), + PIN_MAP("default", "pinctrl-foo", "i2c0", "foo-i2c.0"), };
@@ -826,81 +829,88 @@ As it is possible to map a function to different groups of pins an optional ... { + .dev_name = "foo-spi.0", .name = "spi0-pos-A", .ctrl_dev_name = "pinctrl-foo", .function = "spi0", .group = "spi0_0_grp", - .dev_name = "foo-spi.0", }, { + .dev_name = "foo-spi.0", .name = "spi0-pos-B", .ctrl_dev_name = "pinctrl-foo", .function = "spi0", .group = "spi0_1_grp", - .dev_name = "foo-spi.0", }, ... This example mapping is used to switch between two positions for spi0 at runtime, as described further below under the heading "Runtime pinmuxing". -Further it is possible to match several groups of pins to the same function -for a single device, say for example in the mmc0 example above, where you can +Further it is possible for one named state to affect the muxing of several +groups of pins, say for example in the mmc0 example above, where you can additively expand the mmc0 bus from 2 to 4 to 8 pins. If we want to use all three groups for a total of 2+2+4 = 8 pins (for an 8-bit MMC bus as is the case), we define a mapping like this: ... { + .dev_name = "foo-mmc.0", .name = "2bit" .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_1_grp", - .dev_name = "foo-mmc.0", }, { + .dev_name = "foo-mmc.0", .name = "4bit" .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_1_grp", - .dev_name = "foo-mmc.0", }, { + .dev_name = "foo-mmc.0", .name = "4bit" .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_2_grp", - .dev_name = "foo-mmc.0", }, { + .dev_name = "foo-mmc.0", .name = "8bit" .ctrl_dev_name = "pinctrl-foo", + .function = "mmc0", .group = "mmc0_1_grp", - .dev_name = "foo-mmc.0", }, { + .dev_name = "foo-mmc.0", .name = "8bit" .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_2_grp", - .dev_name = "foo-mmc.0", }, { + .dev_name = "foo-mmc.0", .name = "8bit" .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_3_grp", - .dev_name = "foo-mmc.0", }, ... The result of grabbing this mapping from the device with something like this (see next paragraph): - p = pinctrl_get(&device, "8bit"); + p = pinctrl_get(dev); + s = pinctrl_lookup_state(p, "8bit"); + ret = pinctrl_select_state(p, s); + +or more simply: + + p = pinctrl_get_select(dev, "8bit"); Will be that you activate all the three bottom records in the mapping at -once. Since they share the same name, pin controller device, funcion and +once. Since they share the same name, pin controller device, function and device, and since we allow multiple groups to match to a single device, they all get selected, and they all get enabled and disable simultaneously by the pinmux core.
@@ -922,45 +932,63 @@ default state like this: struct foo_state { struct pinctrl *p; + struct pinctrl_state *s; ... }; foo_probe() { - /* Allocate a state holder named "state" etc */ - struct pinctrl p; + /* Allocate a state holder named "foo" etc */ + struct foo_state *foo = ...; - p = pinctrl_get(&device, "default"); - if IS_ERR(p) - return PTR_ERR(p); - pinctrl_enable(p); + foo->p = pinctrl_get(&device); + if (IS_ERR(foo->p)) { + /* FIXME: clean up "foo" here */ + return PTR_ERR(foo->p); + } + + foo->s = pinctrl_lookup_state(foo->p, "default"); + if (IS_ERR(foo->s)) { + pinctrl_put(foo->p); + /* FIXME: clean up "foo" here */ + return PTR_ERR(s); + } - state->p = p; + ret = pinctrl_select_state(s); + if (ret < 0) { + pinctrl_put(foo->p); + /* FIXME: clean up "foo" here */ + return ret; + } } foo_remove() { - pinctrl_disable(state->p); pinctrl_put(state->p); } -This get/enable/disable/put sequence can just as well be handled by bus drivers +This get/lookup/select/put sequence can just as well be handled by bus drivers if you don't want each and every driver to handle it and you know the arrangement on your bus. -The semantics of the get/enable respective disable/put is as follows: +The semantics of the pinctrl APIs are: + +- pinctrl_get() is called in process context to obtain a handle to all pinctrl + information for a given client device. It will allocate a struct from the + kernel memory to hold the pinmux state. All mapping table parsing or similar + slow operations take place within this API. -- pinctrl_get() is called in process context to reserve the pins affected with - a certain mapping and set up the pinmux core and the driver. It will allocate - a struct from the kernel memory to hold the pinmux state. +- pinctrl_lookup_state() is called in process context to obtain a handle to a + specific state for a the client device. This operation may be slow too. -- pinctrl_enable()/pinctrl_disable() is quick and can be called from fastpath - (irq context) when you quickly want to set up/tear down the hardware muxing - when running a device driver. Usually it will just poke some values into a - register. +- pinctrl_select_state() programs pin controller hardware according to the + definition of the state as given by the mapping table. In theory this is a + fast-path operation, since it only involved blasting some register settings + into hardware. However, note that some pin controllers may have their + registers on a slow/IRQ-based bus, so client devices should not assume they + can call pinctrl_select_state() from non-blocking contexts. -- pinctrl_disable() is called in process context to tear down the pin requests - and release the state holder struct for the mux setting etc. +- pinctrl_put() frees all information associated with a pinctrl handle. Usually the pin control core handled the get/put pair and call out to the device drivers bookkeeping operations, like checking available functions and
@@ -976,25 +1004,25 @@ System pin control hogging ========================== Pin control map entries can be hogged by the core when the pin controller -is registered. This means that the core will attempt to call pinctrl_get() and -pinctrl_enable() on it immediately after the pin control device has been -registered. +is registered. This means that the core will attempt to call pinctrl_get(), +lookup_state() and select_state() on it immediately after the pin control +device has been registered. -This is enabled by simply setting the .dev_name field in the map to the name -of the pin controller itself, like this: +This occurs for mapping table entries where the client device name is equal +to the pin controller device name, and the state name is "active". { - .name = "POWERMAP" + .dev_name = "pinctrl-foo", + .name = "active", .ctrl_dev_name = "pinctrl-foo", .function = "power_func", - .dev_name = "pinctrl-foo", }, Since it may be common to request the core to hog a few always-applicable mux settings on the primary pin controller, there is a convenience macro for this: -PIN_MAP_SYS_HOG("POWERMAP", "pinctrl-foo", "power_func") +PIN_MAP_SYS_HOG("active", "pinctrl-foo", "power_func") This gives the exact same result as the above construction.
@@ -1006,8 +1034,8 @@ It is possible to mux a certain function in and out at runtime, say to move an SPI port from one set of pins to another set of pins. Say for example for spi0 in the example above, we expose two different groups of pins for the same function, but with different named in the mapping as described under -"Advanced mapping" above. So we have two mappings named "spi0-pos-A" and -"spi0-pos-B". +"Advanced mapping" above. So that for an SPI device, we have two states named +"pos-A" and "pos-B". This snippet first muxes the function in the pins defined by group A, enables it, disables and releases it, and muxes it in on the pins defined by group B:
@@ -1017,23 +1045,36 @@ it, disables and releases it, and muxes it in on the pins defined by group B: foo_switch() { struct pinctrl *p; + struct pinctrl_state *s1, *s2; + + /* Setup */ + p = pinctrl_get(&device); + if (IS_ERR(p)) + ... + + s1 = pinctrl_lookup_state(foo->p, "pos-A"); + if (IS_ERR(s1)) + ... + + s2 = pinctrl_lookup_state(foo->p, "pos-B"); + if (IS_ERR(s2)) + ... /* Enable on position A */ - p = pinctrl_get(&device, "spi0-pos-A"); - if IS_ERR(p) - return PTR_ERR(p); - pinctrl_enable(p); + ret = pinctrl_select_state(s); + if (ret < 0) + ... - /* This releases the pins again */ - pinctrl_disable(p); - pinctrl_put(p); + ... /* Enable on position B */ - p = pinctrl_get(&device, "spi0-pos-B"); - if IS_ERR(p) - return PTR_ERR(p); - pinctrl_enable(p); + ret = pinctrl_select_state(s); + if (ret < 0) + ... + ... + + pinctrl_put(p); } The above has to be done from process context.
arch/arm/mach-u300/core.c +9 -19
@@ -1554,32 +1554,28 @@ static struct platform_device pinmux_device = {/* Pinmux settings */ static struct pinctrl_map __initdata u300_pinmux_map[] = {/* anonymous maps for chip power and EMIFs */ -PIN_MAP_SYS_HOG ("POWER" ,"pinmux-u300" ,"power" ), -PIN_MAP_SYS_HOG ("EMIF0" ,"pinmux-u300" ,"emif0" ), -PIN_MAP_SYS_HOG ("EMIF1" ,"pinmux-u300" ,"emif1" ), +PIN_MAP_SYS_HOG ("default" ,"pinmux-u300" ,"power" ), +PIN_MAP_SYS_HOG ("default" ,"pinmux-u300" ,"emif0" ), +PIN_MAP_SYS_HOG ("default" ,"pinmux-u300" ,"emif1" ),/* per-device maps for MMC/SD, SPI and UART */ -PIN_MAP ("MMCSD" ,"pinmux-u300" ,"mmc0" ,"mmci" ), -PIN_MAP ("SPI" ,"pinmux-u300" ,"spi0" ,"pl022" ), -PIN_MAP ("UART0" ,"pinmux-u300" ,"uart0" ,"uart0" ), +PIN_MAP ("default" ,"pinmux-u300" ,"mmc0" ,"mmci" ), +PIN_MAP ("default" ,"pinmux-u300" ,"spi0" ,"pl022" ), +PIN_MAP ("default" ,"pinmux-u300" ,"uart0" ,"uart0" ), };struct u300_mux_hog { -const char *name;struct device *dev;struct pinctrl *p; };static struct u300_mux_hog u300_mux_hogs[] = { { - .name ="uart0" , .dev = &uart0_device.dev, }, { - .name ="spi0" , .dev = &pl022_device.dev, }, { - .name ="mmc0" , .dev = &mmcsd_device.dev, }, };
@@ -1592,16 +1588,10 @@ static int __init u300_pinctrl_fetch(void)struct pinctrl *p;int ret; - p =pinctrl_get (u300_mux_hogs[i].dev,NULL ); + p =pinctrl_get_select_default (u300_mux_hogs[i].dev);if (IS_ERR (p)) { -pr_err ("u300: could not get pinmux hog %s\n" , - u300_mux_hogs[i].name); -continue ; - } - ret =pinctrl_enable (p); -if (ret) { -pr_err ("u300: could enable pinmux hog %s\n" , - u300_mux_hogs[i].name); +pr_err ("u300: could not get pinmux hog for dev %s\n" , +dev_name (u300_mux_hogs[i].dev));continue ; } u300_mux_hogs[i].p = p;
drivers/pinctrl/core.c +223 -268
641 lines not on this page · raw message
drivers/pinctrl/core.h +18 -6
@@ -28,7 +28,7 @@ struct pinctrl_gpio_range;* @owner: module providing the pin controller, used for refcounting * @driver_data: driver data for drivers registering to the pin controller * subsystem -* @pinctrl_hogs: list of pin control maps hogged by this device +* @p: result of pinctrl_get() for this device * @device_root: debugfs root for this device */ struct pinctrl_dev {
@@ -39,7 +39,7 @@ struct pinctrl_dev {struct device *dev;struct module *owner;void *driver_data; -struct list_head pinctrl_hogs; +struct pinctrl *p;#ifdef CONFIG_DEBUG_FS struct dentry *device_root;#endif
@@ -49,22 +49,34 @@ struct pinctrl_dev {* struct pinctrl - per-device pin control state holder * @node: global list node * @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 * to keep track of nested use cases -* @settings: a list of settings for this device/state +* @states: a list of states for this device +* @state: the current state */ struct pinctrl {struct list_head node;struct device *dev; -const char *state;unsigned usecount; +struct list_head states; +struct pinctrl_state *state; +}; + +/** +* 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 - an individual mux setting -* @node: list node for struct pinctrl's @settings field +* @node: list node for struct pinctrl_settings'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
drivers/tty/serial/sirfsoc_uart.c +3 -9
@@ -673,12 +673,10 @@ int sirfsoc_uart_probe(struct platform_device *pdev) port->irq = res->start;if (sirfport->hw_flow_ctrl) { - sirfport->p =pinctrl_get (&pdev->dev,NULL ); + sirfport->p =pinctrl_get_select_default (&pdev->dev); ret =IS_ERR (sirfport->p);if (ret) goto pin_err; - -pinctrl_enable (sirfport->p); } port->ops = &sirfsoc_uart_ops;
@@ -695,10 +693,8 @@ int sirfsoc_uart_probe(struct platform_device *pdev) port_err:platform_set_drvdata (pdev,NULL ); -if (sirfport->hw_flow_ctrl) { -pinctrl_disable (sirfport->p); +if (sirfport->hw_flow_ctrl)pinctrl_put (sirfport->p); - } pin_err: irq_err:devm_iounmap (&pdev->dev, port->membase);
@@ -711,10 +707,8 @@ static int sirfsoc_uart_remove(struct platform_device *pdev)struct sirfsoc_uart_port *sirfport =platform_get_drvdata (pdev);struct uart_port *port = &sirfport->port;platform_set_drvdata (pdev,NULL ); -if (sirfport->hw_flow_ctrl) { -pinctrl_disable (sirfport->p); +if (sirfport->hw_flow_ctrl)pinctrl_put (sirfport->p); - }devm_iounmap (&pdev->dev, port->membase);uart_remove_one_port (&sirfsoc_uart_drv, port);return 0 ;
include/linux/pinctrl/consumer.h +48 -7
94 lines not on this page · raw message
include/linux/pinctrl/machine.h +10 -11
@@ -14,28 +14,27 @@/** * struct pinctrl_map - boards/machines shall provide this map for devices +* @dev_name: the name of the device using this specific mapping, the name +* must be the same as in your struct device*. If this name is set to the +* same name as the pin controllers own dev_name(), the map entry will be +* hogged by the driver itself upon registration * @name: the name of this specific map entry for the particular machine. -* This is the second parameter passed to pinmux_get() when you want -* to have several mappings to the same device +* This is the parameter passed to pinmux_lookup_state() * @ctrl_dev_name: the name of the device controlling this specific mapping, * the name must be the same as in your struct device* -* @function: a function in the driver to use for this mapping, the driver -* will lookup the function referenced by this ID on the specified -* pin control device * @group: sometimes a function can map to different pin groups, so this * selects a certain specific pin group to activate for the function, if * left as NULL, the first applicable group will be used -* @dev_name: the name of the device using this specific mapping, the name -* must be the same as in your struct device*. If this name is set to the -* same name as the pin controllers own dev_name(), the map entry will be -* hogged by the driver itself upon registration +* @function: a function in the driver to use for this mapping, the driver +* will lookup the function referenced by this ID on the specified +* pin control device */ struct pinctrl_map { +const char *dev_name;const char *name;const char *ctrl_dev_name; -const char *function;const char *group; -const char *dev_name; +const char *function; };/*
Signature · 1 line
1.7.5.4
Re: [PATCH 19/20] pinctrl: API changes to support multiple states per device
Quoted 29 lines · Stephen Warren
The API model is changed from:
p =
pinctrl_get(dev, "state1");pinctrl_enable(p);
...pinctrl_disable(p);pinctrl_put(p);
p =pinctrl_get(dev, "state2");pinctrl_enable(p);
...pinctrl_disable(p);pinctrl_put(p);to this:
p =
pinctrl_get(dev);
s1 =pinctrl_lookup_state(p, "state1");
s2 =pinctrl_lookup_state(p, "state2");pinctrl_select_state(p, s1);
...pinctrl_select_state(p, s2);
...pinctrl_put(p);This allows devices to directly transition between states without disabling the pin controller programming and put()/get()ing the configuration data each time. This model will also better suit pinconf programming, which doesn't have a concept of "disable".
Quoted 6 lines
The special-case hogging feature of pin controllers is re-written to use the regular APIs instead of special-case code. Hence, the pinmux-hogs debugfs file is removed; see the top-level pinctrl-handles files for equivalent data.
Signed-off-by Stephen Warren <[email protected]>
Overall this is excellent and exactly what we have discussed and just what we want, good job!
Quoted 4 lines
static const struct
pinctrl_map__initdatamapping[] = { {
+ .dev_name = "foo-spi.0",
+ .name = "default",
I think we should introduce a
#define PINCTRL_DEFAULT_STATE "default"
And use that #define in examples and code from day 1.
That will ease the transition to generalized states like PINCTRL_IDLE_STATE etc further down the road.
Quoted 40 lines
{
+ .dev_name = "foo-mmc.0",
.name = "2bit"
.ctrl_dev_name = "pinctrl-foo",
.function = "mmc0",
.group = "mmc0_1_grp",
- .dev_name = "foo-mmc.0",
},
{
+ .dev_name = "foo-mmc.0",
.name = "4bit"
.ctrl_dev_name = "pinctrl-foo",
.function = "mmc0",
.group = "mmc0_1_grp",
- .dev_name = "foo-mmc.0",
},
{
+ .dev_name = "foo-mmc.0",
.name = "4bit"
.ctrl_dev_name = "pinctrl-foo",
.function = "mmc0",
.group = "mmc0_2_grp",
- .dev_name = "foo-mmc.0",
},
{
+ .dev_name = "foo-mmc.0",
.name = "8bit"
.ctrl_dev_name = "pinctrl-foo",
+ .function = "mmc0",
.group = "mmc0_1_grp",
- .dev_name = "foo-mmc.0",
},
{
+ .dev_name = "foo-mmc.0",
.name = "8bit"
.ctrl_dev_name = "pinctrl-foo",
.function = "mmc0",
.group = "mmc0_2_grp",
- .dev_name = "foo-mmc.0",
},
Quoted 8 lines
{
+ .dev_name = "foo-mmc.0",
.name = "8bit"
.ctrl_dev_name = "pinctrl-foo",
.function = "mmc0",
.group = "mmc0_3_grp",
- .dev_name = "foo-mmc.0",
},
Seems like random reordering but no big deal, could go in separate patch.
Documentation/pinctrl.txt As it is possible to map a function to different groups of pins an optional · line 910
Quoted 11 lines
The result of grabbing this mapping from the device with something like this (see next paragraph):
- p =
pinctrl_get(&device, "8bit");
+ p =pinctrl_get(dev);
+ s =pinctrl_lookup_state(p, "8bit");
+ ret =pinctrl_select_state(p, s);Documentation/pinctrl.txt +4
-0+ +or more simply: + + p = pinctrl_get_select(dev, "8bit");
Ohhh sweet! I like pinctrl_get_select()!
Quoted 13 lines
Pin control map entries can be hogged by the core when the pin controller
Documentation/pinctrl.txt +5
-5-is registered. This means that the core will attempt to call pinctrl_get() and -pinctrl_enable() on it immediately after the pin control device has been -registered. +is registered. This means that the core will attempt to call pinctrl_get(), +lookup_state() and select_state() on it immediately after the pin control +device has been registered. -This is enabled by simply setting the .dev_name field in the map to the name -of the pin controller itself, like this: +This occurs for mapping table entries where the client device name is equal +to the pin controller device name, and the state name is "active".
Quoted 4 lines
{
- .name = "POWERMAP"
+ .dev_name = "pinctrl-foo",
+ .name = "active",
Again define a standard name, I think PINCTRL_STATE_DEFAULT should be used for this too, since it means it defaults to active.
Documentation/pinctrl.txt System pin control hogging · line 1025
Quoted 2 lines
Documentation/pinctrl.txt +1
-1-PIN_MAP_SYS_HOG("POWERMAP", "pinctrl-foo", "power_func") +PIN_MAP_SYS_HOG("active", "pinctrl-foo", "power_func")
Then use that PINCTRL_STATE_DEFAULT
Quoted 47 lines
This snippet first muxes the function in the pins defined by group A, enables it, disables and releases it, and muxes it in on the pins defined by group B:
Documentation/pinctrl.txt +24
-11@@ -1017,23 +1045,36 @@ it, disables and releases it, and muxes it in on the pins defined by group B: foo_switch() { struct pinctrl *p; + struct pinctrl_state *s1, *s2; + + /* Setup */ + p = pinctrl_get(&device); + if (IS_ERR(p)) + ... + + s1 = pinctrl_lookup_state(foo->p, "pos-A"); + if (IS_ERR(s1)) + ... + + s2 = pinctrl_lookup_state(foo->p, "pos-B"); + if (IS_ERR(s2)) + ... /* Enable on position A */ - p = pinctrl_get(&device, "spi0-pos-A"); - if IS_ERR(p) - return PTR_ERR(p); - pinctrl_enable(p); + ret = pinctrl_select_state(s); + if (ret < 0) + ... - /* This releases the pins again */ - pinctrl_disable(p); - pinctrl_put(p); + ... /* Enable on position B */ - p = pinctrl_get(&device, "spi0-pos-B"); - if IS_ERR(p) - return PTR_ERR(p); - pinctrl_enable(p); + ret = pinctrl_select_state(s); + if (ret < 0) + ... + + + pinctrl_put(p);
Quoted 1 line
}
This is looking real good. I think recent discussion with Russell also ironed out the problems with potential gpio interaction.
Quoted 6 lines
-
PIN_MAP_SYS_HOG("POWER", "pinmux-u300", "power"),
-PIN_MAP_SYS_HOG("EMIF0", "pinmux-u300", "emif0"),
-PIN_MAP_SYS_HOG("EMIF1", "pinmux-u300", "emif1"),
+PIN_MAP_SYS_HOG("default", "pinmux-u300", "power"),
+PIN_MAP_SYS_HOG("default", "pinmux-u300", "emif0"),
+PIN_MAP_SYS_HOG("default", "pinmux-u300", "emif1"),
Quoted 8 lines
/* per-device maps for MMC/SD, SPI and UART */
-PIN_MAP("MMCSD", "pinmux-u300", "mmc0", "mmci"),
-PIN_MAP("SPI", "pinmux-u300", "spi0", "pl022"),
-PIN_MAP("UART0", "pinmux-u300", "uart0", "uart0"),
+PIN_MAP("default", "pinmux-u300", "mmc0", "mmci"),
+PIN_MAP("default", "pinmux-u300", "spi0", "pl022"),
+PIN_MAP("default", "pinmux-u300", "uart0", "uart0"), };
PINCTRL_STATE_DEFAULT
So far I really like this. I should look closer at the code but mainly I just have to trust you on it and fix any bugs later, this change is way more valuable as is.
Please move this patch as far to the head of the series as possible so we can get it in, I guess you need the state lookup in struct pinctrl to proceed but could we e.g. puy the locking changes after this?
Yours,
Linus Walleij
RE: [PATCH 19/20] pinctrl: API changes to support multiple states per device
Linus Walleij wrote at Wednesday, February 22, 2012 10:55 PM:
Quoted 1 line · Stephen Warren
...
Quoted 2 lines
This is looking real good. I think recent discussion with Russell also ironed out the problems with potential gpio interaction.
Hmm. I guess I need to go re-read that then; my impression was that we hadn't really reached a solid conclusion yet.
...
Quoted 3 lines
Please move this patch as far to the head of the series as possible so we can get it in, I guess you need the state lookup in struct pinctrl to proceed but could we e.g. puy the locking changes after this?
The main reason I wrote the patches like the locking patch was due to issues I found when working on these two main patches. I'm not sure that these later patches would work completely correctly without the locking rework first...
Signature · 1 line
nvpublic
Re: [PATCH 19/20] pinctrl: API changes to support multiple states per device
In reply to Stephen WarrenQuoted 24 lines · Stephen Warren
The API model is changed from:
p =
pinctrl_get(dev, "state1");pinctrl_enable(p);
...pinctrl_disable(p);pinctrl_put(p);
p =pinctrl_get(dev, "state2");pinctrl_enable(p);
...pinctrl_disable(p);pinctrl_put(p);to this:
p =
pinctrl_get(dev);
s1 =pinctrl_lookup_state(p, "state1");
s2 =pinctrl_lookup_state(p, "state2");pinctrl_select_state(p, s1);
...pinctrl_select_state(p, s2);
...pinctrl_put(p);
Quoted 5 lines
This allows devices to directly transition between states without disabling the pin controller programming and put()/get()ing the configuration data each time. This model will also better suit pinconf programming, which doesn't have a concept of "disable".
It's exactly what we discussed and wanted.
Thank for the great and hard work.
Quoted 19 lines
The special-case hogging feature of pin controllers is re-written to use the regular APIs instead of special-case code. Hence, the pinmux-hogs debugfs file is removed; see the top-level pinctrl-handles files for equivalent data.
Signed-off-by Stephen Warren <[email protected]>--- Documentation/pinctrl.txt | 153 ++++++++----- arch/arm/mach-u300/core.c | 28 +-- drivers/pinctrl/core.c | 491 +++++++++++++++++-------------------- drivers/pinctrl/core.h | 24 ++- drivers/tty/serial/sirfsoc_uart.c | 12 +- include/linux/pinctrl/consumer.h | 55 ++++- include/linux/pinctrl/machine.h | 21 +- 7 files changed, 408 insertions(+), 376 deletions(-)
Documentation/pinctrl.txt it even more compact which assumes you want to use pinctrl-foo and position · line 820
Quoted 5 lines
Documentation/pinctrl.txt +1
-1@@ -814,7 +817,7 @@ it even more compact which assumes you want to use pinctrl-foo and position 0 for mapping, for example: static struct pinctrl_map __initdata mapping[] = { - PIN_MAP("I2CMAP", "pinctrl-foo", "i2c0", "foo-i2c.0"), + PIN_MAP("default", "pinctrl-foo", "i2c0", "foo-i2c.0"),
I remember you said you will also change the PIN_MAP sequence that place the device name at first.
Will see your further patch.
Documentation/pinctrl.txt As it is possible to map a function to different groups of pins an optional · line 910
Quoted 12 lines
Documentation/pinctrl.txt +7
-1The result of grabbing this mapping from the device with something like this (see next paragraph): - p = pinctrl_get(&device, "8bit"); + p = pinctrl_get(dev); + s = pinctrl_lookup_state(p, "8bit"); + ret = pinctrl_select_state(p, s); + +or more simply: + + p = pinctrl_get_select(dev, "8bit");
Very glad to see this simply one. :-)
Quoted 17 lines
foo_probe()
{Documentation/pinctrl.txt +7
-6- /* Allocate a state holder named "state" etc */ - struct pinctrl p; + /* Allocate a state holder named "foo" etc */ + struct foo_state *foo = ...; - p = pinctrl_get(&device, "default"); - if IS_ERR(p) - return PTR_ERR(p); - pinctrl_enable(p); + foo->p = pinctrl_get(&device); + if (IS_ERR(foo->p)) { + /* FIXME: clean up "foo" here */ + return PTR_ERR(foo->p); + }
Documentation/pinctrl.txt default state like this: · line 957
Quoted 10 lines
Documentation/pinctrl.txt +8
-1+ + foo->s = pinctrl_lookup_state(foo->p, "default"); + if (IS_ERR(foo->s)) { + pinctrl_put(foo->p); + /* FIXME: clean up "foo" here */ + return PTR_ERR(s); + } - state->p = p; + ret = pinctrl_select_state(s);
s/s/foo->s
Quoted 10 lines
Documentation/pinctrl.txt +3
-3@@ -976,25 +1004,25 @@ System pin control hogging ========================== Pin control map entries can be hogged by the core when the pin controller -is registered. This means that the core will attempt to call pinctrl_get() and -pinctrl_enable() on it immediately after the pin control device has been -registered. +is registered. This means that the core will attempt to call pinctrl_get(), +lookup_state() and select_state() on it immediately after the pin control +device has been registered.
Documentation/pinctrl.txt System pin control hogging · line 1016
Quoted 10 lines
Documentation/pinctrl.txt +4
-3-This is enabled by simply setting the .dev_name field in the map to the name -of the pin controller itself, like this: +This occurs for mapping table entries where the client device name is equal +to the pin controller device name, and the state name is "active". { - .name = "POWERMAP" + .dev_name = "pinctrl-foo", + .name = "active",
I guess if we really decide to use a fixed state name for hog functions, we'd better not let users to write the state name, at least provide a macro.
Documentation/pinctrl.txt System pin control hogging · line 1025
Quoted 11 lines
Documentation/pinctrl.txt +1
-2.ctrl_dev_name = "pinctrl-foo", .function = "power_func", - .dev_name = "pinctrl-foo", }, Since it may be common to request the core to hog a few always-applicable mux settings on the primary pin controller, there is a convenience macro for this: -PIN_MAP_SYS_HOG("POWERMAP", "pinctrl-foo", "power_func") +PIN_MAP_SYS_HOG("active", "pinctrl-foo", "power_func")
I remember you had a patch changing this macro a bit. So here may also need change.
drivers/pinctrl/core.c int pinctrl_gpio_direction_output(unsigned gpio) · line 536
Quoted 6 lines
drivers/pinctrl/core.c +4
-1+static struct pinctrl *find_pinctrl (struct device *dev) +{ +struct pinctrl *p; -dev_dbg (dev,"pinctrl_get() for state %s\n" , name); +list_for_each_entry (p, &pinctrldev_list, node)
s/pinctrldev_list/pinctrl_list ?
Quoted 8 lines
drivers/pinctrl/core.c +4
-3+static struct pinctrl *pinctrl_get_locked (struct device *dev) +{ +struct pinctrl *p; -error: -list_for_each_entry (setting, &p->settings, node) -pinmux_free_setting (setting); +if (WARN_ON (!dev))
drivers/pinctrl/core.c static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) · line 601
Quoted 10 lines
drivers/pinctrl/core.c +8
-1+return ERR_PTR (-EINVAL ); -kfree (p); + p =find_pinctrl (dev); +if (p ==NULL ) + p =create_pinctrl (dev); +if (IS_ERR (p)) +return p; + + p->usecount++;
I still can not understand what's the purpose of p->usecount? For allowing multi times calling of pinctrl_get for on the same device?
Quoted 11 lines
include/linux/pinctrl/consumer.h +11
-0+static inline struct pinctrl *__must_check pinctrl_get_select ( +struct device *dev,const char *name) +{ +struct pinctrl *p; +struct pinctrl_state *s; +int ret; + + p =pinctrl_get (dev); +if (IS_ERR (p)) +return p; +
include/linux/pinctrl/consumer.h static inline void pinctrl_put(struct pinctrl *p) · line 104
Quoted 10 lines
include/linux/pinctrl/consumer.h +10
-0+ s =pinctrl_lookup_state (p, name); +if (IS_ERR (s)) { +pinctrl_put (p); +return ERR_PTR (PTR_ERR (s)); + } + + ret =pinctrl_select_state (p, s); +if (ret <0 ) { +pinctrl_put (p); +return ERR_PTR (ret);
s/ERR_PTR(ret)/ret ?
Regards
Dong Aisheng
RE: [PATCH 19/20] pinctrl: API changes to support multiple states per device
Dong Aisheng wrote at Monday, February 27, 2012 2:07 AM:
Quoted 8 lines · Stephen Warren
Documentation/pinctrl.txt System pin control hogging · line 1016
Quoted 4 lines
Documentation/pinctrl.txt +2
-1- .name = "POWERMAP" + .dev_name = "pinctrl-foo", + .name = "active",I guess if we really decide to use a fixed state name for hog functions, we'd better not let users to write the state name, at least provide a macro.
Yes, that's a good point for adding the special-case macros. I have added such special-case macros to my local version of patch 20, so they'll be there in the repost.
Quoted 10 lines
Quoted 10 lines
drivers/pinctrl/core.c +5
-3+static struct pinctrl *pinctrl_get_locked (struct device *dev) +{ +struct pinctrl *p; -error: -list_for_each_entry (setting, &p->settings, node) -pinmux_free_setting (setting); +if (WARN_ON (!dev)) +return ERR_PTR (-EINVAL );
Quoted 11 lines
drivers/pinctrl/core.c static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) · line 601
Quoted 8 lines
drivers/pinctrl/core.c +7
-1-kfree (p); + p =find_pinctrl (dev); +if (p ==NULL ) + p =create_pinctrl (dev); +if (IS_ERR (p)) +return p; + + p->usecount++;I still can not understand what's the purpose of
p->usecount? For allowing multi times calling ofpinctrl_getfor on the same device?
pinctrl_get() could be called multiple times for the same device. Rather than create a whole new struct pinctrl each time it's called, we just reference count the object so that each call returns the same one, and it won't be destroyed until all users have called pinctrl_put().
Hopefully it is true that multiple different pieces of code won't be screwing with the same device's pinctrl settings, but it's simple enough to do this so we may as well. This somewhat of a the moral equivalent of the old code's p->usecount manipulations in pinctrl_enable()/disable(), although admittedly a little different.
Quoted 15 lines
Quoted 15 lines
include/linux/pinctrl/consumer.h +15
-0+static inline struct pinctrl *__must_check pinctrl_get_select ( +struct device *dev,const char *name) +{ +struct pinctrl *p; +struct pinctrl_state *s; +int ret; + + p =pinctrl_get (dev); +if (IS_ERR (p)) +return p; + + s =pinctrl_lookup_state (p, name); +if (IS_ERR (s)) { +pinctrl_put (p); +return ERR_PTR (PTR_ERR (s));
Quoted 8 lines
include/linux/pinctrl/consumer.h static inline void pinctrl_put(struct pinctrl *p) · line 104
Quoted 6 lines
include/linux/pinctrl/consumer.h +6
-0+ } + + ret =pinctrl_select_state (p, s); +if (ret <0 ) { +pinctrl_put (p); +return ERR_PTR (ret);s/ERR_PTR(ret)/ret ?
The function returns a pointer, whereas ret is an int. ERR_PTR() is used to wrap the int error code into a pointer value so that the function can return either a valid pointer, or an error-code. See include/linux/err.h.
I've fixed locally up the other issues you pointed out. Thanks.
Signature · 1 line
nvpublic
Re: [PATCH 19/20] pinctrl: API changes to support multiple states per device
Quoted 2 lines · Stephen Warren
Dong Aisheng wrote at Monday, February 27, 2012 2:07 AM:
Quoted 1 line · Stephen Warren
..........
Quoted 29 lines
Quoted 11 lines
Quoted 11 lines
drivers/pinctrl/core.c +5
-3+static struct pinctrl *pinctrl_get_locked (struct device *dev) +{ +struct pinctrl *p; -error: -list_for_each_entry (setting, &p->settings, node) -pinmux_free_setting (setting); +if (WARN_ON (!dev)) +return ERR_PTR (-EINVAL );Quoted 11 lines
drivers/pinctrl/core.c static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) · line 601
Quoted 8 lines
drivers/pinctrl/core.c +7
-1-kfree (p); + p =find_pinctrl (dev); +if (p ==NULL ) + p =create_pinctrl (dev); +if (IS_ERR (p)) +return p; + + p->usecount++;I still can not understand what's the purpose of
p->usecount? For allowing multi times calling ofpinctrl_getfor on the same device?
pinctrl_get()could be called multiple times for the same device. Rather than create a whole new struct pinctrl each time it's called, we just reference count the object so that each call returns the same one, and it won't be destroyed until all users have calledpinctrl_put().
Quoted 6 lines
Hopefully it is true that multiple different pieces of code won't be screwing with the same device's pinctrl settings, but it's simple enough to do this so we may as well. This somewhat of a the moral equivalent of the old code's
p->usecountmanipulations in pinctrl_enable()/disable(), although admittedly a little different.
Hmm, yes, a slight difference after looking the old code.
Oringally the pinmux->usecount was introduced to allow nested call of pinmux_enable (but not pinmux_get since it will return an error due to pin conflicts). In the new way, you allow nested call of pinctrl_get.
I still can't find in which case the device will have such requirement since per my understanding pinctrl is a little different from clock (clock can be used by different devices but we do not allow pins to be used by difference devices at the same time).
However it's actually another issue which is not related to this patch since we're just trying to keep align with the old code.
So it's ok to me for you to keep it here first.
Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
include/linux/pinctrl/consumer.h +15
-0+static inline struct pinctrl *__must_check pinctrl_get_select ( +struct device *dev,const char *name) +{ +struct pinctrl *p; +struct pinctrl_state *s; +int ret; + + p =pinctrl_get (dev); +if (IS_ERR (p)) +return p; + + s =pinctrl_lookup_state (p, name); +if (IS_ERR (s)) { +pinctrl_put (p); +return ERR_PTR (PTR_ERR (s));Quoted 8 lines
include/linux/pinctrl/consumer.h static inline void pinctrl_put(struct pinctrl *p) · line 104
Quoted 6 lines
include/linux/pinctrl/consumer.h +6
-0+ } + + ret =pinctrl_select_state (p, s); +if (ret <0 ) { +pinctrl_put (p); +return ERR_PTR (ret);s/ERR_PTR(ret)/ret ?
Quoted 4 lines
The function returns a pointer, whereas ret is an int.
ERR_PTR()is used to wrap the int error code into a pointer value so that the function can return either a valid pointer, or an error-code. Seeinclude/linux/err.h.
Hmm, below is what i see in your patch:
+int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)
{
+ int ret;
+
mutex_lock(&pinctrl_mutex);
- pinctrl_disable_locked(p);
+ ret = pinctrl_select_state_locked(p, state);
mutex_unlock(&pinctrl_mutex);+
+ return ret;
}
It seems pinctrl_select_state does not return a pointer.
Quoted 2 lines
I've fixed locally up the other issues you pointed out. Thanks.
Great.
Thanks.
Regards
Dong Aisheng
RE: [PATCH 19/20] pinctrl: API changes to support multiple states per device
Dong Aisheng wrote at Monday, February 27, 2012 8:19 PM:
Quoted 31 lines · Stephen Warren
Quoted 2 lines
Dong Aisheng wrote at Monday, February 27, 2012 2:07 AM:
Quoted 1 line · Stephen Warren
..........
Quoted 27 lines
Quoted 11 lines
Quoted 11 lines
drivers/pinctrl/core.c +5
-3+static struct pinctrl *pinctrl_get_locked (struct device *dev) +{ +struct pinctrl *p; -error: -list_for_each_entry (setting, &p->settings, node) -pinmux_free_setting (setting); +if (WARN_ON (!dev)) +return ERR_PTR (-EINVAL );Quoted 11 lines
drivers/pinctrl/core.c static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) · line 601
Quoted 8 lines
drivers/pinctrl/core.c +7
-1-kfree (p); + p =find_pinctrl (dev); +if (p ==NULL ) + p =create_pinctrl (dev); +if (IS_ERR (p)) +return p; + + p->usecount++;I still can not understand what's the purpose of
p->usecount? For allowing multi times calling ofpinctrl_getfor on the same device?
pinctrl_get()could be called multiple times for the same device. Rather than create a whole new struct pinctrl each time it's called, we just reference count the object so that each call returns the same one, and it won't be destroyed until all users have calledpinctrl_put().
...
Quoted 4 lines
I still can't find in which case the device will have such requirement since per my understanding pinctrl is a little different from clock (clock can be used by different devices but we do not allow pins to be used by difference devices at the same time).
True. It's actually very easy to make pinctrl_get() fail if a struct pinctrl was already created for the device in question. If we do that, we can completely remove the usecount field. I'll update my patch to do that.
Quoted 41 lines
Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
include/linux/pinctrl/consumer.h +15
-0+static inline struct pinctrl *__must_check pinctrl_get_select ( +struct device *dev,const char *name) +{ +struct pinctrl *p; +struct pinctrl_state *s; +int ret; + + p =pinctrl_get (dev); +if (IS_ERR (p)) +return p; + + s =pinctrl_lookup_state (p, name); +if (IS_ERR (s)) { +pinctrl_put (p); +return ERR_PTR (PTR_ERR (s));Quoted 8 lines
include/linux/pinctrl/consumer.h static inline void pinctrl_put(struct pinctrl *p) · line 104
Quoted 6 lines
include/linux/pinctrl/consumer.h +6
-0+ } + + ret =pinctrl_select_state (p, s); +if (ret <0 ) { +pinctrl_put (p); +return ERR_PTR (ret);s/ERR_PTR(ret)/ret ?
Quoted 3 lines
The function returns a pointer, whereas ret is an int.
ERR_PTR()is used to wrap the int error code into a pointer value so that the function can return either a valid pointer, or an error-code. Seeinclude/linux/err.h.Hmm, below is what i see in your patch:
drivers/pinctrl/core.c +6
-1+int pinctrl_select_state (struct pinctrl *p,struct pinctrl_state *state) { +int ret; +mutex_lock (&pinctrl_mutex); -pinctrl_disable_locked (p); + ret =pinctrl_select_state_locked (p, state);mutex_unlock (&pinctrl_mutex); + +return ret; }
Quoted 1 line
It seems
pinctrl_select_statedoes not return a pointer.
pinctrl_select()_state() returns an int error code.
pinctrl_get_select() returns a pointer, or an error code encoded into a pointer.
ERR_PTR(ret) is used to convert pinctrl_select()'s int error code into a pointer representation of the error code for pinctrl_get_select() to return.
Signature · 1 line
nvpublic
Re: [PATCH 19/20] pinctrl: API changes to support multiple states per device
Quoted 38 lines · Stephen Warren
Dong Aisheng wrote at Monday, February 27, 2012 8:19 PM:
Quoted 31 lines · Stephen Warren
Quoted 2 lines
Dong Aisheng wrote at Monday, February 27, 2012 2:07 AM:
Quoted 1 line · Stephen Warren
..........
Quoted 27 lines
Quoted 11 lines
Quoted 11 lines
drivers/pinctrl/core.c +5
-3+static struct pinctrl *pinctrl_get_locked (struct device *dev) +{ +struct pinctrl *p; -error: -list_for_each_entry (setting, &p->settings, node) -pinmux_free_setting (setting); +if (WARN_ON (!dev)) +return ERR_PTR (-EINVAL );Quoted 11 lines
drivers/pinctrl/core.c static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) · line 601
Quoted 8 lines
drivers/pinctrl/core.c +7
-1-kfree (p); + p =find_pinctrl (dev); +if (p ==NULL ) + p =create_pinctrl (dev); +if (IS_ERR (p)) +return p; + + p->usecount++;I still can not understand what's the purpose of
p->usecount? For allowing multi times calling ofpinctrl_getfor on the same device?
pinctrl_get()could be called multiple times for the same device. Rather than create a whole new struct pinctrl each time it's called, we just reference count the object so that each call returns the same one, and it won't be destroyed until all users have calledpinctrl_put()....
Quoted 4 lines
I still can't find in which case the device will have such requirement since per my understanding pinctrl is a little different from clock (clock can be used by different devices but we do not allow pins to be used by difference devices at the same time).
Quoted 4 lines
True. It's actually very easy to make
pinctrl_get()fail if a struct pinctrl was already created for the device in question. If we do that, we can completely remove the usecount field. I'll update my patch to do that.
Great.
Quoted 46 lines
Quoted 42 lines
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
include/linux/pinctrl/consumer.h +15
-0+static inline struct pinctrl *__must_check pinctrl_get_select ( +struct device *dev,const char *name) +{ +struct pinctrl *p; +struct pinctrl_state *s; +int ret; + + p =pinctrl_get (dev); +if (IS_ERR (p)) +return p; + + s =pinctrl_lookup_state (p, name); +if (IS_ERR (s)) { +pinctrl_put (p); +return ERR_PTR (PTR_ERR (s));Quoted 8 lines
include/linux/pinctrl/consumer.h static inline void pinctrl_put(struct pinctrl *p) · line 104
Quoted 6 lines
include/linux/pinctrl/consumer.h +6
-0+ } + + ret =pinctrl_select_state (p, s); +if (ret <0 ) { +pinctrl_put (p); +return ERR_PTR (ret);s/ERR_PTR(ret)/ret ?
Quoted 3 lines
The function returns a pointer, whereas ret is an int.
ERR_PTR()is used to wrap the int error code into a pointer value so that the function can return either a valid pointer, or an error-code. Seeinclude/linux/err.h.Hmm, below is what i see in your patch:
drivers/pinctrl/core.c +6
-1+int pinctrl_select_state (struct pinctrl *p,struct pinctrl_state *state) { +int ret; +mutex_lock (&pinctrl_mutex); -pinctrl_disable_locked (p); + ret =pinctrl_select_state_locked (p, state);mutex_unlock (&pinctrl_mutex); + +return ret; }Quoted 1 line
It seems
pinctrl_select_statedoes not return a pointer.pinctrl_select()_state() returns an int error code.
Quoted 7 lines
pinctrl_get_select()returns a pointer, or an error code encoded into a pointer.
ERR_PTR(ret)is used to convert pinctrl_select()'s int error code into a pointer representation of the error code forpinctrl_get_select()to return.
Oh, i see.
You're right, sorry for the noise.
Regards
Dong Aisheng
PATCH 20/20 pinctrl: Enhance mapping table to support pin config operations
In reply to Stephen WarrenThe pinctrl mapping table can now contain entries to:
* Set the mux function of a pin group
* Apply a set of pin config options to a pin or a group
This allows pinctrl_select_state() to apply pin configs settings as well as mux settings.
--- Documentation/pinctrl.txt | 76 ++++++++++++++--- arch/arm/mach-u300/core.c | 12 ++-- drivers/pinctrl/core.c | 177 +++++++++++++++++++++++++++++++++------ drivers/pinctrl/core.h | 37 +++++++- drivers/pinctrl/pinconf.c | 164 ++++++++++++++++++++++++++++++++++++ drivers/pinctrl/pinconf.h | 40 +++++++++ drivers/pinctrl/pinmux.c | 69 ++++++++++------ drivers/pinctrl/pinmux.h | 23 ++++- include/linux/pinctrl/machine.h | 117 +++++++++++++++++++------- 9 files changed, 609 insertions(+), 106 deletions(-)
Documentation/pinctrl.txt +64 -12
@@ -206,14 +206,21 @@ using a certain resistor value - pull up and pull down - so that the pin has a stable value when nothing is driving the rail it is connected to, or when it's unconnected. -For example, a platform may do this: +Pin configuration can be programmed either using the explicit APIs described +immediately below, or by adding configuration entries into the mapping table; +see section "Board/machine configuration" below. + +For example, a platform may do the following to pull up a pin to VDD: #include <linux/pinctrl/consumer.h> ret = pin_config_set("foo-dev", "FOO_GPIO_PIN", PLATFORM_X_PULL_UP); -To pull up a pin to VDD. The pin configuration driver implements callbacks for -changing pin configuration in the pin controller ops like this: +The format and meaning of the configuration parameter, PLATFORM_X_PULL_UP +above, is entirely defined by the pin controller driver. + +The pin configuration driver implements callbacks for changing pin +configuration in the pin controller ops like this: #include <linux/pinctrl/pinctrl.h> #include <linux/pinctrl/pinconf.h>
@@ -765,7 +772,7 @@ obtain the function "gpioN" where "N" is the global GPIO pin number if no special GPIO-handler is registered. -Pinmux board/machine configuration +Board/machine configuration ================================== Boards and machines define how a certain complete running system is put
@@ -773,9 +780,9 @@ together, including how GPIOs and devices are muxed, how regulators are constrained and how the clock tree looks. Of course pinmux settings are also part of this. -A pinmux config for a machine looks pretty much like a simple regulator -configuration, so for the example array above we want to enable i2c and -spi on the second function mapping: +A pin controller configuration for a machine looks pretty much like a simple +regulator configuration, so for the example array above we want to enable i2c +and spi on the second function mapping: #include <linux/pinctrl/machine.h>
@@ -783,20 +790,23 @@ static const struct pinctrl_map __initdata mapping[] = { { .dev_name = "foo-spi.0", .name = "default", + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", - .function = "spi0", + .data.mux.function = "spi0", }, { .dev_name = "foo-i2c.0", .name = "default", + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", - .function = "i2c0", + .data.mux.function = "i2c0", }, { .dev_name = "foo-mmc.0", .name = "default", + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", - .function = "mmc0", + .data.mux.function = "mmc0", }, };
@@ -817,7 +827,40 @@ it even more compact which assumes you want to use pinctrl-foo and position 0 for mapping, for example: static struct pinctrl_map __initdata mapping[] = { - PIN_MAP("default", "pinctrl-foo", "i2c0", "foo-i2c.0"), + PIN_MAP_MUX_GROUP("foo-i2c.o", "default", "pinctrl-foo", NULL, "i2c0"), +}; + +The mapping table may also contain pin configuration entries. It's common for +each pin/group to have a number of configuration entries that affect it, so +the table entries for configuration reference an array of config parameters +and values. An example using the convenience macros is shown below: + +static unsigned long i2c_grp_configs[] = { + FOO_PIN_DRIVEN, + FOO_PIN_PULLUP, +}; + +static unsigned long i2c_pin_configs[] = { + FOO_OPEN_COLLECTOR, + FOO_SLEW_RATE_SLOW, +}; + +static struct pinctrl_map __initdata mapping[] = { + PIN_MAP_MUX_GROUP("foo-i2c.0", "default", "pinctrl-foo", "i2c0", "i2c0"), + PIN_MAP_MUX_CONFIGS_GROUP("foo-i2c.0", "default", "pinctrl-foo", "i2c0", i2c_grp_configs), + PIN_MAP_MUX_CONFIGS_PIN("foo-i2c.0", "default", "pinctrl-foo", "i2c0scl", i2c_pin_configs), + PIN_MAP_MUX_CONFIGS_PIN("foo-i2c.0", "default", "pinctrl-foo", "i2c0sda", i2c_pin_configs), +}; + +Finally, some devices expect the mapping table to contain certain specific +named states. When running on hardware that doesn't need any pin controller +configuration, the mapping table must still contain those named states, in +order to explicitly indicate that the states were provided and intended to +be empty. Table entry macro PIN_MAP_DUMMY_STATE serves the purpose of defining +a named state without causing any pin controller to be programmed: + +static struct pinctrl_map __initdata mapping[] = { + PIN_MAP_DUMMY_STATE("foo-i2c.0", "default"), };
@@ -831,6 +874,7 @@ As it is possible to map a function to different groups of pins an optional { .dev_name = "foo-spi.0", .name = "spi0-pos-A", + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "spi0", .group = "spi0_0_grp",
@@ -838,6 +882,7 @@ As it is possible to map a function to different groups of pins an optional { .dev_name = "foo-spi.0", .name = "spi0-pos-B", + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "spi0", .group = "spi0_1_grp",
@@ -857,6 +902,7 @@ case), we define a mapping like this: { .dev_name = "foo-mmc.0", .name = "2bit" + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_1_grp",
@@ -864,6 +910,7 @@ case), we define a mapping like this: { .dev_name = "foo-mmc.0", .name = "4bit" + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_1_grp",
@@ -871,6 +918,7 @@ case), we define a mapping like this: { .dev_name = "foo-mmc.0", .name = "4bit" + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_2_grp",
@@ -878,6 +926,7 @@ case), we define a mapping like this: { .dev_name = "foo-mmc.0", .name = "8bit" + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_1_grp",
@@ -885,6 +934,7 @@ case), we define a mapping like this: { .dev_name = "foo-mmc.0", .name = "8bit" + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_2_grp",
@@ -892,6 +942,7 @@ case), we define a mapping like this: { .dev_name = "foo-mmc.0", .name = "8bit" + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_3_grp",
@@ -1014,6 +1065,7 @@ to the pin controller device name, and the state name is "active". { .dev_name = "pinctrl-foo", .name = "active", + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "power_func", },
@@ -1022,7 +1074,7 @@ Since it may be common to request the core to hog a few always-applicable mux settings on the primary pin controller, there is a convenience macro for this: -PIN_MAP_SYS_HOG("active", "pinctrl-foo", "power_func") +PIN_MAP_MUX_GROUP("pinctrl-foo", "active", "pinctrl-foo", NULL, "power_func") This gives the exact same result as the above construction.
arch/arm/mach-u300/core.c +6 -6
@@ -1554,13 +1554,13 @@ static struct platform_device pinmux_device = {/* Pinmux settings */ static struct pinctrl_map __initdata u300_pinmux_map[] = {/* anonymous maps for chip power and EMIFs */ -PIN_MAP_SYS_HOG ("default" ,"pinmux-u300" ,"power" ), -PIN_MAP_SYS_HOG ("default" ,"pinmux-u300" ,"emif0" ), -PIN_MAP_SYS_HOG ("default" ,"pinmux-u300" ,"emif1" ), +PIN_MAP_MUX_GROUP ("pinmux-u300" ,"default" ,"pinmux-u300" ,NULL ,"power" ), +PIN_MAP_MUX_GROUP ("pinmux-u300" ,"default" ,"pinmux-u300" ,NULL ,"emif0" ), +PIN_MAP_MUX_GROUP ("pinmux-u300" ,"default" ,"pinmux-u300" ,NULL ,"emif1" ),/* per-device maps for MMC/SD, SPI and UART */ -PIN_MAP ("default" ,"pinmux-u300" ,"mmc0" ,"mmci" ), -PIN_MAP ("default" ,"pinmux-u300" ,"spi0" ,"pl022" ), -PIN_MAP ("default" ,"pinmux-u300" ,"uart0" ,"uart0" ), +PIN_MAP_MUX_GROUP ("mmci" ,"default" ,"pinmux-u300" ,NULL ,"mmc0" ), +PIN_MAP_MUX_GROUP ("pl022" ,"default" ,"pinmux-u300" ,NULL ,"spi0" ), +PIN_MAP_MUX_GROUP ("uart0" ,"default" ,"pinmux-u300" ,NULL ,"uart0" ), };struct u300_mux_hog {
drivers/pinctrl/core.c +152 -25
261 lines not on this page · raw message
drivers/pinctrl/core.h +33 -4
@@ -75,17 +75,44 @@ struct pinctrl_state { };/** +* 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 setting * @node: list node for struct pinctrl_settings's @settings field +* @type: the type of setting * @pctldev: pin control device handling to be programmed -* @group_selector: the group selector to program -* @func_selector: the function selector to program +* @data: Data specific to the setting type */ struct pinctrl_setting {struct list_head node; +enum pinctrl_map_type type;struct pinctrl_dev *pctldev; -unsigned group_selector; -unsigned func_selector; +union { +struct pinctrl_setting_mux mux; +struct pinctrl_setting_configs configs; + } data; };/**
@@ -113,6 +140,8 @@ struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);int pin_get_from_name (struct pinctrl_dev *pctldev,const char *name);int pinctrl_get_group_selector (struct pinctrl_dev *pctldev,const char *pin_group); +int pinctrl_get_pin_id (struct pinctrl_dev *pctldev, +const char *pin);static inline struct pin_desc *pin_desc_get (struct pinctrl_dev *pctldev,unsigned int pin)
drivers/pinctrl/pinconf.c +164 -0
178 lines not on this page · raw message
drivers/pinctrl/pinconf.h +40 -0
@@ -15,6 +15,16 @@int pinconf_check_ops (struct pinctrl_dev *pctldev); +int pinconf_validate_map (struct pinctrl_map const *map,int i); + +int pinconf_map_to_setting (struct pinctrl_map const *map, +struct pinctrl_setting *setting); +void pinconf_free_setting (struct pinctrl_setting const *setting); +int pinconf_apply_setting (struct pinctrl_setting const *setting); + +void pinconf_show_map (struct seq_file *s,struct pinctrl_map const *map); +void pinconf_show_setting (struct seq_file *s, +struct pinctrl_setting const *setting);void pinconf_init_device_debugfs (struct dentry *devroot,struct pinctrl_dev *pctldev);
@@ -25,6 +35,36 @@ static inline int pinconf_check_ops(struct pinctrl_dev *pctldev)return 0 ; } +static inline int pinconf_validate_map (struct pinctrl_map const *map,int i) +{ +return 0 ; +} + +static inline int pinconf_map_to_setting (struct pinctrl_map const *map, +struct pinctrl_setting *setting) +{ +return 0 ; +} + +static inline void pinconf_free_setting (struct pinctrl_setting const *setting) +{ +} + +static inline int pinconf_apply_setting (struct pinctrl_setting const *setting) +{ +return 0 ; +} + +static inline void pinconf_show_map (struct seq_file *s, +struct pinctrl_map const *map) +{ +} + +static inline void pinconf_show_setting (struct seq_file *s, +struct pinctrl_setting const *setting) +{ +} +static inline void pinconf_init_device_debugfs (struct dentry *devroot,struct pinctrl_dev *pctldev) {
drivers/pinctrl/pinmux.c +43 -26
132 lines not on this page · raw message
drivers/pinctrl/pinmux.h +19 -4
@@ -14,6 +14,8 @@int pinmux_check_ops (struct pinctrl_dev *pctldev); +int pinmux_validate_map (struct pinctrl_map const *map,int i); +int pinmux_request_gpio (struct pinctrl_dev *pctldev,struct pinctrl_gpio_range *range,unsigned pin,unsigned gpio);
@@ -29,7 +31,9 @@ void pinmux_free_setting(struct pinctrl_setting const *setting);int pinmux_enable_setting (struct pinctrl_setting const *setting);void pinmux_disable_setting (struct pinctrl_setting const *setting); -void pinmux_dbg_show (struct seq_file *s,struct pinctrl_setting const *setting); +void pinmux_show_map (struct seq_file *s,struct pinctrl_map const *map); +void pinmux_show_setting (struct seq_file *s, +struct pinctrl_setting const *setting);void pinmux_init_device_debugfs (struct dentry *devroot,struct pinctrl_dev *pctldev);
@@ -40,6 +44,11 @@ static inline int pinmux_check_ops(struct pinctrl_dev *pctldev)return 0 ; } +static inline int pinmux_validate_map (struct pinctrl_map const *map,int i) +{ +return 0 ; +} +static inline int pinmux_request_gpio (struct pinctrl_dev *pctldev,struct pinctrl_gpio_range *range,unsigned pin,unsigned gpio)
@@ -80,12 +89,18 @@ static inline void pinmux_disable_setting( { } -static inline void pinmux_init_device_debugfs (struct dentry *devroot, -struct pinctrl_dev *pctldev) +static inline void pinmux_show_map (struct seq_file *s, +struct pinctrl_map const *map) +{ +} + +static inline void pinmux_show_setting (struct seq_file *s, +struct pinctrl_setting const *setting) { } -static inline void pinmux_dbg_show (struct seq_file *s,struct pinctrl *p) +static inline void pinmux_init_device_debugfs (struct dentry *devroot, +struct pinctrl_dev *pctldev) { }
include/linux/pinctrl/machine.h +88 -29
139 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Re: [PATCH 20/20] pinctrl: Enhance mapping table to support pin config operations
Quoted 8 lines · Stephen Warren
The pinctrl mapping table can now contain entries to:
* Set the mux function of a pin group
* Apply a set of pin config options to a pin or a groupThis allows
pinctrl_select_state()to apply pin configs settings as well as mux settings.Signed-off-by Stephen Warren <[email protected]>
Overall excellent, just smaller things below:
Quoted 7 lines
(quoted diff) +0
-0@@ -817,7 +827,40 @@ it even more compact which assumes you want to use pinctrl-foo and position0 for mapping, for example:
static struct
pinctrl_map__initdatamapping[] = {
-PIN_MAP("default", "pinctrl-foo", "i2c0", "foo-i2c.0"),
+PIN_MAP_MUX_GROUP("foo-i2c.o", "default", "pinctrl-foo", NULL, "i2c0"), +};
OK looks good!
Quoted 11 lines
Documentation/pinctrl.txt +11
-0+The mapping table may also contain pin configuration entries. It's common for +each pin/group to have a number of configuration entries that affect it, so +the table entries for configuration reference an array of config parameters +and values. An example using the convenience macros is shown below: + +static unsigned long i2c_grp_configs[] = { + FOO_PIN_DRIVEN, + FOO_PIN_PULLUP, +}; + +static unsigned long i2c_pin_configs[] = {
Documentation/pinctrl.txt it even more compact which assumes you want to use pinctrl-foo and position · line 853
Quoted 10 lines
Documentation/pinctrl.txt +10
-0+ FOO_OPEN_COLLECTOR, + FOO_SLEW_RATE_SLOW, +}; + +static struct pinctrl_map __initdata mapping[] = { + PIN_MAP_MUX_GROUP("foo-i2c.0", "default", "pinctrl-foo", "i2c0", "i2c0"), + PIN_MAP_MUX_CONFIGS_GROUP("foo-i2c.0", "default", "pinctrl-foo", "i2c0", i2c_grp_configs), + PIN_MAP_MUX_CONFIGS_PIN("foo-i2c.0", "default", "pinctrl-foo", "i2c0scl", i2c_pin_configs), + PIN_MAP_MUX_CONFIGS_PIN("foo-i2c.0", "default", "pinctrl-foo", "i2c0sda", i2c_pin_configs), +};
I buy this too...
Quoted 10 lines
Documentation/pinctrl.txt +9
-0+Finally, some devices expect the mapping table to contain certain specific +named states. When running on hardware that doesn't need any pin controller +configuration, the mapping table must still contain those named states, in +order to explicitly indicate that the states were provided and intended to +be empty. Table entry macro PIN_MAP_DUMMY_STATE serves the purpose of defining +a named state without causing any pin controller to be programmed: + +static struct pinctrl_map __initdata mapping[] = { + PIN_MAP_DUMMY_STATE("foo-i2c.0", "default"),};
Looks useful so why not.
Documentation/pinctrl.txt Since it may be common to request the core to hog a few always-applicable · line 1077
Quoted 6 lines
(quoted diff) +0
-0@@ -1022,7 +1074,7 @@ Since it may be common to request the core to hog a few always-applicablemux settings on the primary pin controller, there is a convenience macro for this:
Documentation/pinctrl.txt +1
-1-PIN_MAP_SYS_HOG("active", "pinctrl-foo", "power_func") +PIN_MAP_MUX_GROUP("pinctrl-foo", "active", "pinctrl-foo", NULL, "power_func")
Please keep the explicit _HOG macros for readability. Relying on the implicit relation between dev and pctldev being the same and to be parsed by humans is vulnerable.
PIN_MAP_MUX_GROUP_HOG()
in this case, with the same arguments (though with PINCTRL_STATE_DEFAULT in place for "active") is better IMO.
Quoted 9 lines
/* Pinmux settings */
static structpinctrl_map__initdatau300_pinmux_map[] = {
/* anonymous maps for chip power and EMIFs */
-PIN_MAP_SYS_HOG("default", "pinmux-u300", "power"),
-PIN_MAP_SYS_HOG("default", "pinmux-u300", "emif0"),
-PIN_MAP_SYS_HOG("default", "pinmux-u300", "emif1"),
+PIN_MAP_MUX_GROUP("pinmux-u300", "default", "pinmux-u300", NULL, "power"),
+PIN_MAP_MUX_GROUP("pinmux-u300", "default", "pinmux-u300", NULL, "emif0"),
+PIN_MAP_MUX_GROUP("pinmux-u300", "default", "pinmux-u300", NULL, "emif1"),
Quoted 8 lines
/* per-device maps for MMC/SD, SPI and UART */
-PIN_MAP("default", "pinmux-u300", "mmc0", "mmci"),
-PIN_MAP("default", "pinmux-u300", "spi0", "pl022"),
-PIN_MAP("default", "pinmux-u300", "uart0", "uart0"),
+PIN_MAP_MUX_GROUP("mmci", "default", "pinmux-u300", NULL, "mmc0"),
+PIN_MAP_MUX_GROUP("pl022", "default", "pinmux-u300", NULL, "spi0"),
+PIN_MAP_MUX_GROUP("uart0", "default", "pinmux-u300", NULL, "uart0"), };
PIN_MAP_MUX_GROUP_HOG() please. PINCTRL_STATE_DEFAULT instead of "default".
Or maybe we should imply that PIN_MAP_MUX_GROUP_HOG() hogs the default state, or have PIN_MAP_MUX_GROUP_HOG_DEFAULT() even?
drivers/pinctrl/core.c int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, · line 346
Quoted 9 lines
drivers/pinctrl/core.c +3
-0@@ -341,6 +341,31 @@ int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, } /** +* pinctrl_get_pin_id() - returns the group selector for a group +* @pctldev: the pin controller handling the group +* @pin_group: the pin group to look up
This kerneldoc is wrong... pin, not group.
Quoted 15 lines
drivers/pinctrl/core.c +15
-0+*/ +int pinctrl_get_pin_id (struct pinctrl_dev *pctldev, + const char *pin) +{ + unsigned int i; + + for (i = 0; i < pctldev->desc->npins; i++) { + if (pctldev->desc->pins[i].name == NULL) + continue; + if (!strcmp(pin, pctldev->desc->pins[i].name)) { + dev_dbg(pctldev->dev, "found pin id %u for %s\n", + i, pin); + return i; + } + }
(...)
Quoted 8 lines
/* First sanity check the new mapping */
for (i = 0; i <num_maps; i++) {
+ if (!maps[i].dev_name) {
+ pr_err("failed to register map %s (%d): no device given\n",
+ maps[i].name, i);
+ return-EINVAL;
+ }
+
Hm should this not be done earlier in the patch series?
drivers/pinctrl/core.c
Quoted 9 lines
+ /*
+ * FIXME: We should really get the pin controler to dump the config
+ * values, so they can be decoded to something meaningful.
+ */
+ for (i = 0; i <setting->data.configs.num_configs; i++)
+seq_printf(s, " %08lx", setting->data.configs.configs[i]);drivers/pinctrl/core.c +3
-0+ + seq_printf(s, "\n"); +}
Per-device config print function? But no need to rush that.
Apart from this I mostly just trust this patch, like the previous one.
Yours,
Linus Walleij
RE: [PATCH 20/20] pinctrl: Enhance mapping table to support pin config operations
Linus Walleij wrote at Wednesday, February 22, 2012 11:09 PM:
Quoted 1 line · Stephen Warren
...
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -1022,7 +1074,7 @@ Since it may be common to request the core to hog a few always-applicablemux settings on the primary pin controller, there is a convenience macro for this:
Quoted 8 lines
Documentation/pinctrl.txt Since it may be common to request the core to hog a few always-applicable · line 1077
Quoted 2 lines
Documentation/pinctrl.txt +1
-1-PIN_MAP_SYS_HOG("active", "pinctrl-foo", "power_func") +PIN_MAP_MUX_GROUP("pinctrl-foo", "active", "pinctrl-foo", NULL, "power_func")Please keep the explicit
_HOGmacros for readability. Relying on the implicit relation between dev and pctldev being the same and to be parsed by humans is vulnerable.
PIN_MAP_MUX_GROUP_HOG()
OK, I guess I can add some of those back. The main reason I removed the special-cases was to avoid consumer.h being chock full of a ton of different macros you had to choose from. This wasn't so much of an issue before, but since the number of macros has grown now to support pin config, dummy states, etc., it seemed cluttered.
Still, I guess they're useful, so I can add them back since you asked.
Signature · 1 line
nvpublic
RE: [PATCH 20/20] pinctrl: Enhance mapping table to support pin config operations
In reply to Linus WalleijLinus Walleij wrote at Wednesday, February 22, 2012 11:09 PM:
Quoted 9 lines · Stephen Warren
Quoted 8 lines
The pinctrl mapping table can now contain entries to:
* Set the mux function of a pin group
* Apply a set of pin config options to a pin or a groupThis allows
pinctrl_select_state()to apply pin configs settings as well as mux settings.Signed-off-by Stephen Warren <[email protected]>
...
Quoted 10 lines
Quoted 8 lines
/* First sanity check the new mapping */
for (i = 0; i <num_maps; i++) {
+ if (!maps[i].dev_name) {
+ pr_err("failed to register map %s (%d): no device given\n",
+ maps[i].name, i);
+ return-EINVAL;
+ }
+Hm should this not be done earlier in the patch series?
This patch isn't adding that check, it's just moving it a little earlier in the same block.
The old code checked everything required for "MUX_GROUP" type mapping table entries, but in the new code not all those same checks exist for every type of mapping entry. I just moved all the common stuff to the top of the block in one common place, followed by the stuff that varies.
So, I think that chunk is OK.
Signature · 1 line
nvpublic
Re: [PATCH 20/20] pinctrl: Enhance mapping table to support pin config operations
In reply to Stephen WarrenQuoted 8 lines · Stephen Warren
The pinctrl mapping table can now contain entries to:
* Set the mux function of a pin group
* Apply a set of pin config options to a pin or a groupThis allows
pinctrl_select_state()to apply pin configs settings as well as mux settings.Signed-off-by Stephen Warren <[email protected]>
....
Quoted 14 lines
Documentation/pinctrl.txt +13
-1- PIN_MAP("default", "pinctrl-foo", "i2c0", "foo-i2c.0"), + PIN_MAP_MUX_GROUP("foo-i2c.o", "default", "pinctrl-foo", NULL, "i2c0"), +}; + +The mapping table may also contain pin configuration entries. It's common for +each pin/group to have a number of configuration entries that affect it, so +the table entries for configuration reference an array of config parameters +and values. An example using the convenience macros is shown below: + +static unsigned long i2c_grp_configs[] = { + FOO_PIN_DRIVEN, + FOO_PIN_PULLUP, +}; +
Documentation/pinctrl.txt it even more compact which assumes you want to use pinctrl-foo and position · line 852
Quoted 10 lines
Documentation/pinctrl.txt +10
-0+static unsigned long i2c_pin_configs[] = { + FOO_OPEN_COLLECTOR, + FOO_SLEW_RATE_SLOW, +}; + +static struct pinctrl_map __initdata mapping[] = { + PIN_MAP_MUX_GROUP("foo-i2c.0", "default", "pinctrl-foo", "i2c0", "i2c0"), + PIN_MAP_MUX_CONFIGS_GROUP("foo-i2c.0", "default", "pinctrl-foo", "i2c0", i2c_grp_configs), + PIN_MAP_MUX_CONFIGS_PIN("foo-i2c.0", "default", "pinctrl-foo", "i2c0scl", i2c_pin_configs), + PIN_MAP_MUX_CONFIGS_PIN("foo-i2c.0", "default", "pinctrl-foo", "i2c0sda", i2c_pin_configs),
I still have not read all over this patch.
But one question i'm considering is that
will this way here also work for "virtual" group?
For example, the virtual group "i2c_grp_configs" may actually contains the config for each pin in that group?
The core will handle this difference or let each driver to handle it?
Documentation/pinctrl.txt Since it may be common to request the core to hog a few always-applicable · line 1025
Quoted 5 lines
Documentation/pinctrl.txt +0
-1@@ -1022,7 +1074,7 @@ Since it may be common to request the core to hog a few always-applicable mux settings on the primary pin controller, there is a convenience macro for this: -PIN_MAP_SYS_HOG("active", "pinctrl-foo", "power_func")
Hmm?
Why remove this one?
Quoted 33 lines
Documentation/pinctrl.txt +1
-0+PIN_MAP_MUX_GROUP("pinctrl-foo", "active", "pinctrl-foo", NULL, "power_func") This gives the exact same result as the above construction.arch/arm/mach-u300/core.c +6
-6@@ -1554,13 +1554,13 @@ static struct platform_device pinmux_device = {/* Pinmux settings */ static struct pinctrl_map __initdata u300_pinmux_map[] = {/* anonymous maps for chip power and EMIFs */ -PIN_MAP_SYS_HOG ("default" ,"pinmux-u300" ,"power" ), -PIN_MAP_SYS_HOG ("default" ,"pinmux-u300" ,"emif0" ), -PIN_MAP_SYS_HOG ("default" ,"pinmux-u300" ,"emif1" ), +PIN_MAP_MUX_GROUP ("pinmux-u300" ,"default" ,"pinmux-u300" ,NULL ,"power" ), +PIN_MAP_MUX_GROUP ("pinmux-u300" ,"default" ,"pinmux-u300" ,NULL ,"emif0" ), +PIN_MAP_MUX_GROUP ("pinmux-u300" ,"default" ,"pinmux-u300" ,NULL ,"emif1" ),/* per-device maps for MMC/SD, SPI and UART */ -PIN_MAP ("default" ,"pinmux-u300" ,"mmc0" ,"mmci" ), -PIN_MAP ("default" ,"pinmux-u300" ,"spi0" ,"pl022" ), -PIN_MAP ("default" ,"pinmux-u300" ,"uart0" ,"uart0" ), +PIN_MAP_MUX_GROUP ("mmci" ,"default" ,"pinmux-u300" ,NULL ,"mmc0" ), +PIN_MAP_MUX_GROUP ("pl022" ,"default" ,"pinmux-u300" ,NULL ,"spi0" ), +PIN_MAP_MUX_GROUP ("uart0" ,"default" ,"pinmux-u300" ,NULL ,"uart0" ), };struct u300_mux_hog {drivers/pinctrl/core.c +0
-0
drivers/pinctrl/core.c int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, · line 346
Quoted 6 lines
drivers/pinctrl/core.c +3
-0@@ -341,6 +341,31 @@ int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, }/** +* pinctrl_get_pin_id() - returns the group selector for a group +* @pctldev: the pin controller handling the group +* @pin_group: the pin group to look up
The comment seems not correct here.
drivers/pinctrl/core.c int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, · line 359
Quoted 13 lines
drivers/pinctrl/core.c +13
-0+*/ +int pinctrl_get_pin_id (struct pinctrl_dev *pctldev, +const char *pin) +{ +unsigned int i; + +for (i =0 ; i < pctldev->desc->npins; i++) { +if (pctldev->desc->pins[i].name ==NULL ) +continue ; +if (!strcmp (pin, pctldev->desc->pins[i].name)) { +dev_dbg (pctldev->dev,"found pin id %u for %s\n" , + i, pin); +return i;
It looks actually this is not a PIN id.
It's just the index of the pin array.
Pin has its own id:
struct pinctrl_pin_desc {
unsigned number;
const char *name;
};Quoted 11 lines
drivers/pinctrl/core.c +4
-0static int pin_config_get_for_pin (struct pinctrl_dev *pctldev,unsigned pin,unsigned long *config) {@@ -260,8 +278,154 @@ unlock: }EXPORT_SYMBOL (pin_config_group_set); +int pinconf_map_to_setting (struct pinctrl_map const *map, +struct pinctrl_setting *setting) +{ +struct pinctrl_dev *pctldev = setting->pctldev;
drivers/pinctrl/core.c unlock: · line 294
Quoted 10 lines
drivers/pinctrl/core.c +10
-0+ +switch (setting->type) { +case PIN_MAP_TYPE_CONFIGS_PIN : + setting->data.configs.group_or_pin = +pinctrl_get_pin_id (pctldev, + map->data.configs.group_or_pin); +if (setting->data.configs.group_or_pin <0 ) +return setting->data.configs.group_or_pin; +break ; +break ;
Two break here.
Regards
Dong Aisheng
RE: [PATCH 20/20] pinctrl: Enhance mapping table to support pin config operations
Dong Aisheng wrote at Monday, February 27, 2012 5:21 AM:
Quoted 9 lines · Stephen Warren
Quoted 8 lines
The pinctrl mapping table can now contain entries to:
* Set the mux function of a pin group
* Apply a set of pin config options to a pin or a groupThis allows
pinctrl_select_state()to apply pin configs settings as well as mux settings.Signed-off-by Stephen Warren <[email protected]>
...
Quoted 19 lines
Quoted 19 lines
Documentation/pinctrl.txt +19
-0+The mapping table may also contain pin configuration entries. It's common for +each pin/group to have a number of configuration entries that affect it, so +the table entries for configuration reference an array of config parameters +and values. An example using the convenience macros is shown below: + +static unsigned long i2c_grp_configs[] = { + FOO_PIN_DRIVEN, + FOO_PIN_PULLUP, +}; + +static unsigned long i2c_pin_configs[] = { + FOO_OPEN_COLLECTOR, + FOO_SLEW_RATE_SLOW, +}; + +static struct pinctrl_map __initdata mapping[] = { + PIN_MAP_MUX_GROUP("foo-i2c.0", "default", "pinctrl-foo", "i2c0", "i2c0"), + PIN_MAP_MUX_CONFIGS_GROUP("foo-i2c.0", "default", "pinctrl-foo", "i2c0", i2c_grp_configs), + PIN_MAP_MUX_CONFIGS_PIN("foo-i2c.0", "default", "pinctrl-foo", "i2c0scl", i2c_pin_configs),
Quoted 8 lines
Documentation/pinctrl.txt it even more compact which assumes you want to use pinctrl-foo and position · line 852
Quoted 1 line
Documentation/pinctrl.txt +1
-0+ PIN_MAP_MUX_CONFIGS_PIN("foo-i2c.0", "default", "pinctrl-foo", "i2c0sda", i2c_pin_configs),I still have not read all over this patch.
But one question i'm considering is that
will this way here also work for "virtual" group?
For example, the virtual group "i2c_grp_configs" may actually contains the config for each pin in that group?
The core will handle this difference or let each driver to handle it?
Since the core has no knowledge of virtual groups, everything has to be handled inside the pin controller driver: When the core asks the driver to enumerate the groups it supports, those virtual groups must be included in the list. The mapping table may contain entries to configure those virtual groups, which will be passed on to the driver to implement as it sees fit. So, in short, yes, I believe this handles virtual groups just fine.
Quoted 8 lines
Documentation/pinctrl.txt Since it may be common to request the core to hog a few always-applicable · line 1025
Quoted 5 lines
Documentation/pinctrl.txt +0
-1@@ -1022,7 +1074,7 @@ Since it may be common to request the core to hog a few always-applicable mux settings on the primary pin controller, there is a convenience macro for this: -PIN_MAP_SYS_HOG("active", "pinctrl-foo", "power_func")Hmm?
Why remove this one?
In the patch I posted, I simplified the mapping table macros by replacing all mux entries with a single macro PIN_MAP_MUX_GROUP(). However, I've since modified the patch to include a number of special-case macros, so this macro has been added back (albeit under a slightly different name).
Quoted 16 lines
drivers/pinctrl/core.c int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, · line 359
Quoted 12 lines
drivers/pinctrl/core.c +12
-0+int pinctrl_get_pin_id (struct pinctrl_dev *pctldev, +const char *pin) +{ +unsigned int i; + +for (i =0 ; i < pctldev->desc->npins; i++) { +if (pctldev->desc->pins[i].name ==NULL ) +continue ; +if (!strcmp (pin, pctldev->desc->pins[i].name)) { +dev_dbg (pctldev->dev,"found pin id %u for %s\n" , + i, pin); +return i;It looks actually this is not a PIN id.
It's just the index of the pin array.
Pin has its own id:
Quoted 4 lines
struct pinctrl_pin_desc {
unsigned number;
const char *name;
};I guess I should just delete this function and call pin_get_from_name() instead.
However, this does raise one question:
Right now, pin_config_set() calls pin_get_from_name() to find the pin ID of a pin. This returns that "number" field in the struct above. This is then passed to the pin controller driver's pin_config_set() callback. Hence, the pin ID value passed to pin_config_set() can't be used to index into the driver's own pin_desc array if the pin numbers are sparse. Is that intended? I suppose it's OK since any driver-specific information about each pin can't be stored in the pin_desc array anyway, since that array has a standard type without space for driver-specific data, and any driver-specific array would probably be indexed by the values in the .number field, not the pin_desc array index.
Thanks.
Signature · 1 line
nvpublic
Re: [PATCH 20/20] pinctrl: Enhance mapping table to support pin config operations
Quoted 39 lines · Stephen Warren
Dong Aisheng wrote at Monday, February 27, 2012 5:21 AM:
Quoted 9 lines · Stephen Warren
Quoted 8 lines
The pinctrl mapping table can now contain entries to:
* Set the mux function of a pin group
* Apply a set of pin config options to a pin or a groupThis allows
pinctrl_select_state()to apply pin configs settings as well as mux settings.Signed-off-by Stephen Warren <[email protected]>...
Quoted 19 lines
Quoted 19 lines
Documentation/pinctrl.txt +19
-0+The mapping table may also contain pin configuration entries. It's common for +each pin/group to have a number of configuration entries that affect it, so +the table entries for configuration reference an array of config parameters +and values. An example using the convenience macros is shown below: + +static unsigned long i2c_grp_configs[] = { + FOO_PIN_DRIVEN, + FOO_PIN_PULLUP, +}; + +static unsigned long i2c_pin_configs[] = { + FOO_OPEN_COLLECTOR, + FOO_SLEW_RATE_SLOW, +}; + +static struct pinctrl_map __initdata mapping[] = { + PIN_MAP_MUX_GROUP("foo-i2c.0", "default", "pinctrl-foo", "i2c0", "i2c0"), + PIN_MAP_MUX_CONFIGS_GROUP("foo-i2c.0", "default", "pinctrl-foo", "i2c0", i2c_grp_configs), + PIN_MAP_MUX_CONFIGS_PIN("foo-i2c.0", "default", "pinctrl-foo", "i2c0scl", i2c_pin_configs),Quoted 8 lines
Documentation/pinctrl.txt it even more compact which assumes you want to use pinctrl-foo and position · line 852
Quoted 1 line
Documentation/pinctrl.txt +1
-0+ PIN_MAP_MUX_CONFIGS_PIN("foo-i2c.0", "default", "pinctrl-foo", "i2c0sda", i2c_pin_configs),I still have not read all over this patch.
But one question i'm considering is that
will this way here also work for "virtual" group?
For example, the virtual group "i2c_grp_configs" may actually contains the config for each pin in that group?
The core will handle this difference or let each driver to handle it?
Quoted 8 lines
Since the core has no knowledge of virtual groups, everything has to be handled inside the pin controller driver: When the core asks the driver to enumerate the groups it supports, those virtual groups must be included in the list. The mapping table may contain entries to configure those virtual groups, which will be passed on to the driver to implement as it sees fit. So, in short, yes, I believe this handles virtual groups just fine.
Ok, great.
Quoted 9 lines
Quoted 8 lines
Documentation/pinctrl.txt Since it may be common to request the core to hog a few always-applicable · line 1025
Quoted 5 lines
Documentation/pinctrl.txt +0
-1@@ -1022,7 +1074,7 @@ Since it may be common to request the core to hog a few always-applicable mux settings on the primary pin controller, there is a convenience macro for this: -PIN_MAP_SYS_HOG("active", "pinctrl-foo", "power_func")Hmm?
Why remove this one?
Quoted 5 lines
In the patch I posted, I simplified the mapping table macros by replacing all mux entries with a single macro
PIN_MAP_MUX_GROUP(). However, I've since modified the patch to include a number of special-case macros, so this macro has been added back (albeit under a slightly different name).
Sounds good.
Quoted 26 lines
Quoted 16 lines
drivers/pinctrl/core.c int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, · line 359
Quoted 12 lines
drivers/pinctrl/core.c +12
-0+int pinctrl_get_pin_id (struct pinctrl_dev *pctldev, +const char *pin) +{ +unsigned int i; + +for (i =0 ; i < pctldev->desc->npins; i++) { +if (pctldev->desc->pins[i].name ==NULL ) +continue ; +if (!strcmp (pin, pctldev->desc->pins[i].name)) { +dev_dbg (pctldev->dev,"found pin id %u for %s\n" , + i, pin); +return i;It looks actually this is not a PIN id.
It's just the index of the pin array.
Pin has its own id:Quoted 4 lines
struct pinctrl_pin_desc { unsigned number; const char *name; };I guess I should just delete this function and call
pin_get_from_name()instead.However, this does raise one question:
Quoted 10 lines
Right now,
pin_config_set()callspin_get_from_name()to find the pin ID of a pin. This returns that "number" field in the struct above. This is then passed to the pin controller driver'spin_config_set()callback. Hence, the pin ID value passed topin_config_set()can't be used to index into the driver's ownpin_descarray if the pin numbers are sparse. Is that intended? I suppose it's OK since any driver-specific information about each pin can't be stored in thepin_descarray anyway, since that array has a standard type without space for driver-specific data, and any driver-specific array would probably be indexed by the values in the .number field, not thepin_descarray index.
It's indeed.
Regards
Dong Aisheng
OK I got to patch 10 tonight, so I applied these to for-next and pushed:
3a4de0b pinctrl: core.c/h cleanups
144e2bb pinctrl: Re-order pinconf.[ch] to match each-other dd36982b pinctrl: Re-order pinmux.[ch] to match each-other 7dbf763 pinctrl: Store mapping table as a list of chunks 78917f6 pinctrl: use list_add_tail instead of list_add 9c8484d pinctrl: pinctrl_register_mappings() shouldn't be __init
Will continue reviewing tomorrow.
Thanks,
Linus Walleij