aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2012-02-20 01:45:44 -0500
committerLinus Walleij <linus.walleij@linaro.org>2012-02-22 11:59:35 -0500
commit3cc70ed32cd6c5cb57de17bde615148ed7eda88f (patch)
treef9eb9c82c9b5862617cf2bf18a1cb3c96fddc968 /drivers/pinctrl
parentb1eed4ece7064c361d6e03f6706d90e4e9dd7e96 (diff)
pinctrl: record a pin owner, not mux function, when requesting pins
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. 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. Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl')
-rw-r--r--drivers/pinctrl/core.h2
-rw-r--r--drivers/pinctrl/pinmux.c71
2 files changed, 32 insertions, 41 deletions
diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h
index 7c305672919e..061c57d0e8f9 100644
--- a/drivers/pinctrl/core.h
+++ b/drivers/pinctrl/core.h
@@ -94,7 +94,7 @@ struct pin_desc {
94 spinlock_t lock; 94 spinlock_t lock;
95 /* These fields only added when supporting pinmux drivers */ 95 /* These fields only added when supporting pinmux drivers */
96#ifdef CONFIG_PINMUX 96#ifdef CONFIG_PINMUX
97 const char *mux_function; 97 const char *owner;
98#endif 98#endif
99}; 99};
100 100
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index ea31c4655667..288789750f96 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -71,21 +71,20 @@ int pinmux_check_ops(struct pinctrl_dev *pctldev)
71/** 71/**
72 * pin_request() - request a single pin to be muxed in, typically for GPIO 72 * pin_request() - request a single pin to be muxed in, typically for GPIO
73 * @pin: the pin number in the global pin space 73 * @pin: the pin number in the global pin space
74 * @function: a functional name to give to this pin, passed to the driver 74 * @owner: a representation of the owner of this pin; typically the device
75 * so it knows what function to mux in, e.g. the string "gpioNN" 75 * name that controls its mux function, or the requested GPIO name
76 * means that you want to mux in the pin for use as GPIO number NN
77 * @gpio_range: the range matching the GPIO pin if this is a request for a 76 * @gpio_range: the range matching the GPIO pin if this is a request for a
78 * single GPIO pin 77 * single GPIO pin
79 */ 78 */
80static int pin_request(struct pinctrl_dev *pctldev, 79static int pin_request(struct pinctrl_dev *pctldev,
81 int pin, const char *function, 80 int pin, const char *owner,
82 struct pinctrl_gpio_range *gpio_range) 81 struct pinctrl_gpio_range *gpio_range)
83{ 82{
84 struct pin_desc *desc; 83 struct pin_desc *desc;
85 const struct pinmux_ops *ops = pctldev->desc->pmxops; 84 const struct pinmux_ops *ops = pctldev->desc->pmxops;
86 int status = -EINVAL; 85 int status = -EINVAL;
87 86
88 dev_dbg(pctldev->dev, "request pin %d for %s\n", pin, function); 87 dev_dbg(pctldev->dev, "request pin %d for %s\n", pin, owner);
89 88
90 desc = pin_desc_get(pctldev, pin); 89 desc = pin_desc_get(pctldev, pin);
91 if (desc == NULL) { 90 if (desc == NULL) {
@@ -94,19 +93,14 @@ static int pin_request(struct pinctrl_dev *pctldev,
94 goto out; 93 goto out;
95 } 94 }
96 95
97 if (!function) {
98 dev_err(pctldev->dev, "no function name given\n");
99 return -EINVAL;
100 }
101
102 spin_lock(&desc->lock); 96 spin_lock(&desc->lock);
103 if (desc->mux_function) { 97 if (desc->owner && strcmp(desc->owner, owner)) {
104 spin_unlock(&desc->lock); 98 spin_unlock(&desc->lock);
105 dev_err(pctldev->dev, 99 dev_err(pctldev->dev,
106 "pin already requested\n"); 100 "pin already requested\n");
107 goto out; 101 goto out;
108 } 102 }
109 desc->mux_function = function; 103 desc->owner = owner;
110 spin_unlock(&desc->lock); 104 spin_unlock(&desc->lock);
111 105
112 /* Let each pin increase references to this module */ 106 /* Let each pin increase references to this module */
@@ -136,13 +130,13 @@ static int pin_request(struct pinctrl_dev *pctldev,
136out_free_pin: 130out_free_pin:
137 if (status) { 131 if (status) {
138 spin_lock(&desc->lock); 132 spin_lock(&desc->lock);
139 desc->mux_function = NULL; 133 desc->owner = NULL;
140 spin_unlock(&desc->lock); 134 spin_unlock(&desc->lock);
141 } 135 }
142out: 136out:
143 if (status) 137 if (status)
144 dev_err(pctldev->dev, "pin-%d (%s) status %d\n", 138 dev_err(pctldev->dev, "pin-%d (%s) status %d\n",
145 pin, function ? : "?", status); 139 pin, owner, status);
146 140
147 return status; 141 return status;
148} 142}
@@ -154,8 +148,8 @@ out:
154 * @gpio_range: the range matching the GPIO pin if this is a request for a 148 * @gpio_range: the range matching the GPIO pin if this is a request for a
155 * single GPIO pin 149 * single GPIO pin
156 * 150 *
157 * This function returns a pointer to the function name in use. This is used 151 * This function returns a pointer to the previous owner. This is used
158 * for callers that dynamically allocate a function name so it can be freed 152 * for callers that dynamically allocate an owner name so it can be freed
159 * once the pin is free. This is done for GPIO request functions. 153 * once the pin is free. This is done for GPIO request functions.
160 */ 154 */
161static const char *pin_free(struct pinctrl_dev *pctldev, int pin, 155static const char *pin_free(struct pinctrl_dev *pctldev, int pin,
@@ -163,7 +157,7 @@ static const char *pin_free(struct pinctrl_dev *pctldev, int pin,
163{ 157{
164 const struct pinmux_ops *ops = pctldev->desc->pmxops; 158 const struct pinmux_ops *ops = pctldev->desc->pmxops;
165 struct pin_desc *desc; 159 struct pin_desc *desc;
166 const char *func; 160 const char *owner;
167 161
168 desc = pin_desc_get(pctldev, pin); 162 desc = pin_desc_get(pctldev, pin);
169 if (desc == NULL) { 163 if (desc == NULL) {
@@ -182,12 +176,12 @@ static const char *pin_free(struct pinctrl_dev *pctldev, int pin,
182 ops->free(pctldev, pin); 176 ops->free(pctldev, pin);
183 177
184 spin_lock(&desc->lock); 178 spin_lock(&desc->lock);
185 func = desc->mux_function; 179 owner = desc->owner;
186 desc->mux_function = NULL; 180 desc->owner = NULL;
187 spin_unlock(&desc->lock); 181 spin_unlock(&desc->lock);
188 module_put(pctldev->owner); 182 module_put(pctldev->owner);
189 183
190 return func; 184 return owner;
191} 185}
192 186
193/** 187/**
@@ -201,19 +195,19 @@ int pinmux_request_gpio(struct pinctrl_dev *pctldev,
201 unsigned pin, unsigned gpio) 195 unsigned pin, unsigned gpio)
202{ 196{
203 char gpiostr[16]; 197 char gpiostr[16];
204 const char *function; 198 const char *owner;
205 int ret; 199 int ret;
206 200
207 /* Conjure some name stating what chip and pin this is taken by */ 201 /* Conjure some name stating what chip and pin this is taken by */
208 snprintf(gpiostr, 15, "%s:%d", range->name, gpio); 202 snprintf(gpiostr, 15, "%s:%d", range->name, gpio);
209 203
210 function = kstrdup(gpiostr, GFP_KERNEL); 204 owner = kstrdup(gpiostr, GFP_KERNEL);
211 if (!function) 205 if (!owner)
212 return -EINVAL; 206 return -EINVAL;
213 207
214 ret = pin_request(pctldev, pin, function, range); 208 ret = pin_request(pctldev, pin, owner, range);
215 if (ret < 0) 209 if (ret < 0)
216 kfree(function); 210 kfree(owner);
217 211
218 return ret; 212 return ret;
219} 213}
@@ -227,10 +221,10 @@ int pinmux_request_gpio(struct pinctrl_dev *pctldev,
227void pinmux_free_gpio(struct pinctrl_dev *pctldev, unsigned pin, 221void pinmux_free_gpio(struct pinctrl_dev *pctldev, unsigned pin,
228 struct pinctrl_gpio_range *range) 222 struct pinctrl_gpio_range *range)
229{ 223{
230 const char *func; 224 const char *owner;
231 225
232 func = pin_free(pctldev, pin, range); 226 owner = pin_free(pctldev, pin, range);
233 kfree(func); 227 kfree(owner);
234} 228}
235 229
236/** 230/**
@@ -260,17 +254,15 @@ int pinmux_gpio_direction(struct pinctrl_dev *pctldev,
260/** 254/**
261 * acquire_pins() - acquire all the pins for a certain function on a pinmux 255 * acquire_pins() - acquire all the pins for a certain function on a pinmux
262 * @pctldev: the device to take the pins on 256 * @pctldev: the device to take the pins on
263 * @func_selector: the function selector to acquire the pins for 257 * @owner: a representation of the owner of this pin; typically the device
258 * name that controls its mux function
264 * @group_selector: the group selector containing the pins to acquire 259 * @group_selector: the group selector containing the pins to acquire
265 */ 260 */
266static int acquire_pins(struct pinctrl_dev *pctldev, 261static int acquire_pins(struct pinctrl_dev *pctldev,
267 unsigned func_selector, 262 const char *owner,
268 unsigned group_selector) 263 unsigned group_selector)
269{ 264{
270 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; 265 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
271 const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
272 const char *func = pmxops->get_function_name(pctldev,
273 func_selector);
274 const unsigned *pins; 266 const unsigned *pins;
275 unsigned num_pins; 267 unsigned num_pins;
276 int ret; 268 int ret;
@@ -286,11 +278,11 @@ static int acquire_pins(struct pinctrl_dev *pctldev,
286 278
287 /* Try to allocate all pins in this group, one by one */ 279 /* Try to allocate all pins in this group, one by one */
288 for (i = 0; i < num_pins; i++) { 280 for (i = 0; i < num_pins; i++) {
289 ret = pin_request(pctldev, pins[i], func, NULL); 281 ret = pin_request(pctldev, pins[i], owner, NULL);
290 if (ret) { 282 if (ret) {
291 dev_err(pctldev->dev, 283 dev_err(pctldev->dev,
292 "could not get pin %d for function %s on device %s - conflicting mux mappings?\n", 284 "could not get request pin %d on device %s - conflicting mux mappings?\n",
293 pins[i], func ? : "(undefined)", 285 pins[i],
294 pinctrl_dev_get_name(pctldev)); 286 pinctrl_dev_get_name(pctldev));
295 /* On error release all taken pins */ 287 /* On error release all taken pins */
296 i--; /* this pin just failed */ 288 i--; /* this pin just failed */
@@ -503,7 +495,7 @@ static int pinmux_enable_muxmap(struct pinctrl_dev *pctldev,
503 if (!grp) 495 if (!grp)
504 return -ENOMEM; 496 return -ENOMEM;
505 grp->group_selector = group_selector; 497 grp->group_selector = group_selector;
506 ret = acquire_pins(pctldev, func_selector, group_selector); 498 ret = acquire_pins(pctldev, devname, group_selector);
507 if (ret) { 499 if (ret) {
508 kfree(grp); 500 kfree(grp);
509 return ret; 501 return ret;
@@ -630,7 +622,7 @@ static int pinmux_pins_show(struct seq_file *s, void *what)
630 unsigned i, pin; 622 unsigned i, pin;
631 623
632 seq_puts(s, "Pinmux settings per pin\n"); 624 seq_puts(s, "Pinmux settings per pin\n");
633 seq_puts(s, "Format: pin (name): pinmuxfunction\n"); 625 seq_puts(s, "Format: pin (name): owner\n");
634 626
635 /* The pin number can be retrived from the pin controller descriptor */ 627 /* The pin number can be retrived from the pin controller descriptor */
636 for (i = 0; i < pctldev->desc->npins; i++) { 628 for (i = 0; i < pctldev->desc->npins; i++) {
@@ -645,8 +637,7 @@ static int pinmux_pins_show(struct seq_file *s, void *what)
645 637
646 seq_printf(s, "pin %d (%s): %s\n", pin, 638 seq_printf(s, "pin %d (%s): %s\n", pin,
647 desc->name ? desc->name : "unnamed", 639 desc->name ? desc->name : "unnamed",
648 desc->mux_function ? desc->mux_function 640 desc->owner ? desc->owner : "UNCLAIMED");
649 : "UNCLAIMED");
650 } 641 }
651 642
652 return 0; 643 return 0;