aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/pinmux.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2012-02-09 13:47:48 -0500
committerLinus Walleij <linus.walleij@linaro.org>2012-02-10 15:33:06 -0500
commitbefe5bdfbb698b3bc57c58d0bd7ca3391c9275ed (patch)
tree71416f2adc515f010f54de2371e29626cd144a5b /drivers/pinctrl/pinmux.c
parente93bcee00c43e2bd4037291262111016f4c05793 (diff)
pinctrl: factor pin control handles over to the core
This moves the per-devices struct pinctrl handles and device map over from the pinmux part of the subsystem to the core pinctrl part. This makes the device handles core infrastructure with the goal of using these handles also for pin configuration, so that device drivers (or boards etc) will need one and only one handle to the pin control core. Acked-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/pinmux.c')
-rw-r--r--drivers/pinctrl/pinmux.c711
1 files changed, 90 insertions, 621 deletions
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index 773835d18f55..fe4a00751c60 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -28,14 +28,7 @@
28#include <linux/pinctrl/machine.h> 28#include <linux/pinctrl/machine.h>
29#include <linux/pinctrl/pinmux.h> 29#include <linux/pinctrl/pinmux.h>
30#include "core.h" 30#include "core.h"
31 31#include "pinmux.h"
32/* List of pin controller handles */
33static DEFINE_MUTEX(pinctrl_list_mutex);
34static LIST_HEAD(pinctrl_list);
35
36/* Global pinctrl maps */
37static struct pinctrl_map *pinctrl_maps;
38static unsigned pinctrl_maps_num;
39 32
40/** 33/**
41 * struct pinmux_group - group list item for pinmux groups 34 * struct pinmux_group - group list item for pinmux groups
@@ -48,43 +41,6 @@ struct pinmux_group {
48}; 41};
49 42
50/** 43/**
51 * struct pinctrl - per-device pin control state holder
52 * @node: global list node
53 * @dev: the device using this pin control handle
54 * @usecount: the number of active users of this pin controller setting, used
55 * to keep track of nested use cases
56 * @pctldev: pin control device handling this pin control handle
57 * @func_selector: the function selector for the pinmux device handling
58 * this pinmux
59 * @groups: the group selectors for the pinmux device and
60 * selector combination handling this pinmux, this is a list that
61 * will be traversed on all pinmux operations such as
62 * get/put/enable/disable
63 * @mutex: a lock for the pinmux state holder
64 */
65struct pinctrl {
66 struct list_head node;
67 struct device *dev;
68 unsigned usecount;
69 struct pinctrl_dev *pctldev;
70 unsigned func_selector;
71 struct list_head groups;
72 struct mutex mutex;
73};
74
75/**
76 * struct pinctrl_hog - a list item to stash control hogs
77 * @node: pin control hog list node
78 * @map: map entry responsible for this hogging
79 * @pmx: the pin control hogged by this item
80 */
81struct pinctrl_hog {
82 struct list_head node;
83 struct pinctrl_map const *map;
84 struct pinctrl *p;
85};
86
87/**
88 * pin_request() - request a single pin to be muxed in, typically for GPIO 44 * pin_request() - request a single pin to be muxed in, typically for GPIO
89 * @pin: the pin number in the global pin space 45 * @pin: the pin number in the global pin space
90 * @function: a functional name to give to this pin, passed to the driver 46 * @function: a functional name to give to this pin, passed to the driver
@@ -207,28 +163,18 @@ static const char *pin_free(struct pinctrl_dev *pctldev, int pin,
207} 163}
208 164
209/** 165/**
210 * pinctrl_request_gpio() - request a single pin to be used in as GPIO 166 * pinmux_request_gpio() - request pinmuxing for a GPIO pin
211 * @gpio: the GPIO pin number from the GPIO subsystem number space 167 * @pctldev: pin controller device affected
212 * 168 * @pin: the pin to mux in for GPIO
213 * This function should *ONLY* be used from gpiolib-based GPIO drivers, 169 * @range: the applicable GPIO range
214 * as part of their gpio_request() semantics, platforms and individual drivers
215 * shall *NOT* request GPIO pins to be muxed in.
216 */ 170 */
217int pinctrl_request_gpio(unsigned gpio) 171int pinmux_request_gpio(struct pinctrl_dev *pctldev,
172 struct pinctrl_gpio_range *range,
173 unsigned pin, unsigned gpio)
218{ 174{
219 char gpiostr[16]; 175 char gpiostr[16];
220 const char *function; 176 const char *function;
221 struct pinctrl_dev *pctldev;
222 struct pinctrl_gpio_range *range;
223 int ret; 177 int ret;
224 int pin;
225
226 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
227 if (ret)
228 return -EINVAL;
229
230 /* Convert to the pin controllers number space */
231 pin = gpio - range->base + range->pin_base;
232 178
233 /* Conjure some name stating what chip and pin this is taken by */ 179 /* Conjure some name stating what chip and pin this is taken by */
234 snprintf(gpiostr, 15, "%s:%d", range->name, gpio); 180 snprintf(gpiostr, 15, "%s:%d", range->name, gpio);
@@ -243,53 +189,38 @@ int pinctrl_request_gpio(unsigned gpio)
243 189
244 return ret; 190 return ret;
245} 191}
246EXPORT_SYMBOL_GPL(pinctrl_request_gpio);
247 192
248/** 193/**
249 * pinctrl_free_gpio() - free control on a single pin, currently used as GPIO 194 * pinmux_free_gpio() - release a pin from GPIO muxing
250 * @gpio: the GPIO pin number from the GPIO subsystem number space 195 * @pctldev: the pin controller device for the pin
251 * 196 * @pin: the affected currently GPIO-muxed in pin
252 * This function should *ONLY* be used from gpiolib-based GPIO drivers, 197 * @range: applicable GPIO range
253 * as part of their gpio_free() semantics, platforms and individual drivers
254 * shall *NOT* request GPIO pins to be muxed out.
255 */ 198 */
256void pinctrl_free_gpio(unsigned gpio) 199void pinmux_free_gpio(struct pinctrl_dev *pctldev, unsigned pin,
200 struct pinctrl_gpio_range *range)
257{ 201{
258 struct pinctrl_dev *pctldev;
259 struct pinctrl_gpio_range *range;
260 int ret;
261 int pin;
262 const char *func; 202 const char *func;
263 203
264 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
265 if (ret)
266 return;
267
268 /* Convert to the pin controllers number space */
269 pin = gpio - range->base + range->pin_base;
270
271 func = pin_free(pctldev, pin, range); 204 func = pin_free(pctldev, pin, range);
272 kfree(func); 205 kfree(func);
273} 206}
274EXPORT_SYMBOL_GPL(pinctrl_free_gpio);
275 207
276static int pinctrl_gpio_direction(unsigned gpio, bool input) 208/**
209 * pinmux_gpio_direction() - set the direction of a single muxed-in GPIO pin
210 * @pctldev: the pin controller handling this pin
211 * @range: applicable GPIO range
212 * @pin: the affected GPIO pin in this controller
213 * @input: true if we set the pin as input, false for output
214 */
215int pinmux_gpio_direction(struct pinctrl_dev *pctldev,
216 struct pinctrl_gpio_range *range,
217 unsigned pin, bool input)
277{ 218{
278 struct pinctrl_dev *pctldev;
279 struct pinctrl_gpio_range *range;
280 const struct pinmux_ops *ops; 219 const struct pinmux_ops *ops;
281 int ret; 220 int ret;
282 int pin;
283
284 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
285 if (ret)
286 return ret;
287 221
288 ops = pctldev->desc->pmxops; 222 ops = pctldev->desc->pmxops;
289 223
290 /* Convert to the pin controllers number space */
291 pin = gpio - range->base + range->pin_base;
292
293 if (ops->gpio_set_direction) 224 if (ops->gpio_set_direction)
294 ret = ops->gpio_set_direction(pctldev, range, pin, input); 225 ret = ops->gpio_set_direction(pctldev, range, pin, input);
295 else 226 else
@@ -299,112 +230,6 @@ static int pinctrl_gpio_direction(unsigned gpio, bool input)
299} 230}
300 231
301/** 232/**
302 * pinctrl_gpio_direction_input() - request a GPIO pin to go into input mode
303 * @gpio: the GPIO pin number from the GPIO subsystem number space
304 *
305 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
306 * as part of their gpio_direction_input() semantics, platforms and individual
307 * drivers shall *NOT* touch pin control GPIO calls.
308 */
309int pinctrl_gpio_direction_input(unsigned gpio)
310{
311 return pinctrl_gpio_direction(gpio, true);
312}
313EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input);
314
315/**
316 * pinctrl_gpio_direction_output() - request a GPIO pin to go into output mode
317 * @gpio: the GPIO pin number from the GPIO subsystem number space
318 *
319 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
320 * as part of their gpio_direction_output() semantics, platforms and individual
321 * drivers shall *NOT* touch pin control GPIO calls.
322 */
323int pinctrl_gpio_direction_output(unsigned gpio)
324{
325 return pinctrl_gpio_direction(gpio, false);
326}
327EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
328
329/**
330 * pinctrl_register_mappings() - register a set of pin controller mappings
331 * @maps: the pincontrol mappings table to register, this should be marked with
332 * __initdata so it can be discarded after boot, this function will
333 * perform a shallow copy for the mapping entries.
334 * @num_maps: the number of maps in the mapping table
335 *
336 * Only call this once during initialization of your machine, the function is
337 * tagged as __init and won't be callable after init has completed. The map
338 * passed into this function will be owned by the pinmux core and cannot be
339 * freed.
340 */
341int __init pinctrl_register_mappings(struct pinctrl_map const *maps,
342 unsigned num_maps)
343{
344 void *tmp_maps;
345 int i;
346
347 pr_debug("add %d pinmux maps\n", num_maps);
348
349 /* First sanity check the new mapping */
350 for (i = 0; i < num_maps; i++) {
351 if (!maps[i].name) {
352 pr_err("failed to register map %d: no map name given\n",
353 i);
354 return -EINVAL;
355 }
356
357 if (!maps[i].ctrl_dev_name) {
358 pr_err("failed to register map %s (%d): no pin control device given\n",
359 maps[i].name, i);
360 return -EINVAL;
361 }
362
363 if (!maps[i].function) {
364 pr_err("failed to register map %s (%d): no function ID given\n",
365 maps[i].name, i);
366 return -EINVAL;
367 }
368
369 if (!maps[i].dev_name)
370 pr_debug("add system map %s function %s with no device\n",
371 maps[i].name,
372 maps[i].function);
373 else
374 pr_debug("register map %s, function %s\n",
375 maps[i].name,
376 maps[i].function);
377 }
378
379 /*
380 * Make a copy of the map array - string pointers will end up in the
381 * kernel const section anyway so these do not need to be deep copied.
382 */
383 if (!pinctrl_maps_num) {
384 /* On first call, just copy them */
385 tmp_maps = kmemdup(maps,
386 sizeof(struct pinctrl_map) * num_maps,
387 GFP_KERNEL);
388 if (!tmp_maps)
389 return -ENOMEM;
390 } else {
391 /* Subsequent calls, reallocate array to new size */
392 size_t oldsize = sizeof(struct pinctrl_map) * pinctrl_maps_num;
393 size_t newsize = sizeof(struct pinctrl_map) * num_maps;
394
395 tmp_maps = krealloc(pinctrl_maps,
396 oldsize + newsize, GFP_KERNEL);
397 if (!tmp_maps)
398 return -ENOMEM;
399 memcpy((tmp_maps + oldsize), maps, newsize);
400 }
401
402 pinctrl_maps = tmp_maps;
403 pinctrl_maps_num += num_maps;
404 return 0;
405}
406
407/**
408 * acquire_pins() - acquire all the pins for a certain function on a pinmux 233 * acquire_pins() - acquire all the pins for a certain function on a pinmux
409 * @pctldev: the device to take the pins on 234 * @pctldev: the device to take the pins on
410 * @func_selector: the function selector to acquire the pins for 235 * @func_selector: the function selector to acquire the pins for
@@ -660,227 +485,81 @@ static int pinmux_enable_muxmap(struct pinctrl_dev *pctldev,
660 return 0; 485 return 0;
661} 486}
662 487
663static void pinmux_free_groups(struct pinctrl *p)
664{
665 struct list_head *node, *tmp;
666
667 list_for_each_safe(node, tmp, &p->groups) {
668 struct pinmux_group *grp =
669 list_entry(node, struct pinmux_group, node);
670 /* Release all pins taken by this group */
671 release_pins(p->pctldev, grp->group_selector);
672 list_del(node);
673 kfree(grp);
674 }
675}
676
677/** 488/**
678 * pinctrl_get() - retrieves the pin controller handle for a certain device 489 * pinmux_apply_muxmap() - apply a certain mux mapping entry
679 * @dev: the device to get the pin controller handle for
680 * @name: an optional specific control mapping name or NULL, the name is only
681 * needed if you want to have more than one mapping per device, or if you
682 * need an anonymous pin control (not tied to any specific device)
683 */ 490 */
684struct pinctrl *pinctrl_get(struct device *dev, const char *name) 491int pinmux_apply_muxmap(struct pinctrl_dev *pctldev,
492 struct pinctrl *p,
493 struct device *dev,
494 const char *devname,
495 struct pinctrl_map const *map)
685{ 496{
686 struct pinctrl_map const *map = NULL; 497 int ret;
687 struct pinctrl_dev *pctldev = NULL;
688 const char *devname = NULL;
689 struct pinctrl *p;
690 bool found_map;
691 unsigned num_maps = 0;
692 int ret = -ENODEV;
693 int i;
694
695 /* We must have dev or ID or both */
696 if (!dev && !name)
697 return ERR_PTR(-EINVAL);
698
699 if (dev)
700 devname = dev_name(dev);
701
702 pr_debug("get mux %s for device %s\n", name,
703 devname ? devname : "(none)");
704
705 /*
706 * create the state cookie holder struct pinmux for each
707 * mapping, this is what consumers will get when requesting
708 * a pinmux handle with pinmux_get()
709 */
710 p = kzalloc(sizeof(struct pinctrl), GFP_KERNEL);
711 if (p == NULL)
712 return ERR_PTR(-ENOMEM);
713 mutex_init(&p->mutex);
714 p->func_selector = UINT_MAX;
715 INIT_LIST_HEAD(&p->groups);
716
717 /* Iterate over the pin control maps to locate the right ones */
718 for (i = 0; i < pinctrl_maps_num; i++) {
719 map = &pinctrl_maps[i];
720 found_map = false;
721
722 /*
723 * First, try to find the pctldev given in the map
724 */
725 pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name);
726 if (!pctldev) {
727 pr_warning("could not find a pinctrl device for pinmux function %s, fishy, they shall all have one\n",
728 map->function);
729 pr_warning("given pinctrl device name: %s",
730 map->ctrl_dev_name);
731
732 /* Continue to check the other mappings anyway... */
733 continue;
734 }
735
736 pr_debug("in map, found pctldev %s to handle function %s",
737 dev_name(pctldev->dev), map->function);
738
739
740 /*
741 * If we're looking for a specific named map, this must match,
742 * else we loop and look for the next.
743 */
744 if (name != NULL) {
745 if (map->name == NULL)
746 continue;
747 if (strcmp(map->name, name))
748 continue;
749 }
750
751 /*
752 * This is for the case where no device name is given, we
753 * already know that the function name matches from above
754 * code.
755 */
756 if (!map->dev_name && (name != NULL))
757 found_map = true;
758
759 /* If the mapping has a device set up it must match */
760 if (map->dev_name &&
761 (!devname || !strcmp(map->dev_name, devname)))
762 /* MATCH! */
763 found_map = true;
764
765 /* If this map is applicable, then apply it */
766 if (found_map) {
767 ret = pinmux_enable_muxmap(pctldev, p, dev,
768 devname, map);
769 if (ret) {
770 pinmux_free_groups(p);
771 kfree(p);
772 return ERR_PTR(ret);
773 }
774 num_maps++;
775 }
776 }
777
778 498
779 /* We should have atleast one map, right */ 499 ret = pinmux_enable_muxmap(pctldev, p, dev,
780 if (!num_maps) { 500 devname, map);
781 pr_err("could not find any mux maps for device %s, ID %s\n", 501 if (ret) {
782 devname ? devname : "(anonymous)", 502 pinmux_put(p);
783 name ? name : "(undefined)"); 503 return ret;
784 kfree(p);
785 return ERR_PTR(-EINVAL);
786 } 504 }
787 505
788 pr_debug("found %u mux maps for device %s, UD %s\n", 506 return 0;
789 num_maps,
790 devname ? devname : "(anonymous)",
791 name ? name : "(undefined)");
792
793 /* Add the pinmux to the global list */
794 mutex_lock(&pinctrl_list_mutex);
795 list_add(&p->node, &pinctrl_list);
796 mutex_unlock(&pinctrl_list_mutex);
797
798 return p;
799} 507}
800EXPORT_SYMBOL_GPL(pinctrl_get);
801 508
802/** 509/**
803 * pinctrl_put() - release a previously claimed pin control handle 510 * pinmux_put() - free up the pinmux portions of a pin controller handle
804 * @p: a pin control handle previously claimed by pinctrl_get()
805 */ 511 */
806void pinctrl_put(struct pinctrl *p) 512void pinmux_put(struct pinctrl *p)
807{ 513{
808 if (p == NULL) 514 struct list_head *node, *tmp;
809 return;
810
811 mutex_lock(&p->mutex);
812 if (p->usecount)
813 pr_warn("releasing pin control handle with active users!\n");
814 /* Free the groups and all acquired pins */
815 pinmux_free_groups(p);
816 mutex_unlock(&p->mutex);
817
818 /* Remove from list */
819 mutex_lock(&pinctrl_list_mutex);
820 list_del(&p->node);
821 mutex_unlock(&pinctrl_list_mutex);
822 515
823 kfree(p); 516 list_for_each_safe(node, tmp, &p->groups) {
517 struct pinmux_group *grp =
518 list_entry(node, struct pinmux_group, node);
519 /* Release all pins taken by this group */
520 release_pins(p->pctldev, grp->group_selector);
521 list_del(node);
522 kfree(grp);
523 }
824} 524}
825EXPORT_SYMBOL_GPL(pinctrl_put);
826 525
827/** 526/**
828 * pinctrl_enable() - enable a certain pin controller setting 527 * pinmux_enable() - enable the pinmux portion of a pin control handle
829 * @p: the pin control handle to enable, previously claimed by pinctrl_get()
830 */ 528 */
831int pinctrl_enable(struct pinctrl *p) 529int pinmux_enable(struct pinctrl *p)
832{ 530{
833 int ret = 0; 531 struct pinctrl_dev *pctldev = p->pctldev;
532 const struct pinmux_ops *ops = pctldev->desc->pmxops;
533 struct pinmux_group *grp;
534 int ret;
834 535
835 if (p == NULL) 536 list_for_each_entry(grp, &p->groups, node) {
836 return -EINVAL; 537 ret = ops->enable(pctldev, p->func_selector,
837 mutex_lock(&p->mutex); 538 grp->group_selector);
838 if (p->usecount++ == 0) { 539 if (ret)
839 struct pinctrl_dev *pctldev = p->pctldev; 540 /*
840 const struct pinmux_ops *ops = pctldev->desc->pmxops; 541 * TODO: call disable() on all groups we called
841 struct pinmux_group *grp; 542 * enable() on to this point?
842 543 */
843 list_for_each_entry(grp, &p->groups, node) { 544 return ret;
844 ret = ops->enable(pctldev, p->func_selector,
845 grp->group_selector);
846 if (ret) {
847 /*
848 * TODO: call disable() on all groups we called
849 * enable() on to this point?
850 */
851 p->usecount--;
852 break;
853 }
854 }
855 } 545 }
856 mutex_unlock(&p->mutex); 546 return 0;
857 return ret;
858} 547}
859EXPORT_SYMBOL_GPL(pinctrl_enable);
860 548
861/** 549/**
862 * pinctrl_disable() - disable a certain pin control setting 550 * pinmux_disable() - disable the pinmux portions of a pin control handle
863 * @p: the pin control handle to disable, previously claimed by pinctrl_get()
864 */ 551 */
865void pinctrl_disable(struct pinctrl *p) 552void pinmux_disable(struct pinctrl *p)
866{ 553{
867 if (p == NULL) 554 struct pinctrl_dev *pctldev = p->pctldev;
868 return; 555 const struct pinmux_ops *ops = pctldev->desc->pmxops;
869 556 struct pinmux_group *grp;
870 mutex_lock(&p->mutex);
871 if (--p->usecount == 0) {
872 struct pinctrl_dev *pctldev = p->pctldev;
873 const struct pinmux_ops *ops = pctldev->desc->pmxops;
874 struct pinmux_group *grp;
875 557
876 list_for_each_entry(grp, &p->groups, node) { 558 list_for_each_entry(grp, &p->groups, node) {
877 ops->disable(pctldev, p->func_selector, 559 ops->disable(pctldev, p->func_selector,
878 grp->group_selector); 560 grp->group_selector);
879 }
880 } 561 }
881 mutex_unlock(&p->mutex);
882} 562}
883EXPORT_SYMBOL_GPL(pinctrl_disable);
884 563
885int pinmux_check_ops(struct pinctrl_dev *pctldev) 564int pinmux_check_ops(struct pinctrl_dev *pctldev)
886{ 565{
@@ -910,116 +589,6 @@ int pinmux_check_ops(struct pinctrl_dev *pctldev)
910 return 0; 589 return 0;
911} 590}
912 591
913/* Hog a single map entry and add to the hoglist */
914static int pinctrl_hog_map(struct pinctrl_dev *pctldev,
915 struct pinctrl_map const *map)
916{
917 struct pinctrl_hog *hog;
918 struct pinctrl *p;
919 int ret;
920
921 if (map->dev_name) {
922 /*
923 * TODO: the day we have device tree support, we can
924 * traverse the device tree and hog to specific device nodes
925 * without any problems, so then we can hog pinmuxes for
926 * all devices that just want a static pin mux at this point.
927 */
928 dev_err(pctldev->dev, "map %s wants to hog a non-system pinmux, this is not going to work\n",
929 map->name);
930 return -EINVAL;
931 }
932
933 hog = kzalloc(sizeof(struct pinctrl_hog), GFP_KERNEL);
934 if (!hog)
935 return -ENOMEM;
936
937 p = pinctrl_get(NULL, map->name);
938 if (IS_ERR(p)) {
939 kfree(hog);
940 dev_err(pctldev->dev,
941 "could not get the %s pin control mapping for hogging\n",
942 map->name);
943 return PTR_ERR(p);
944 }
945
946 ret = pinctrl_enable(p);
947 if (ret) {
948 pinctrl_put(p);
949 kfree(hog);
950 dev_err(pctldev->dev,
951 "could not enable the %s pin control mapping for hogging\n",
952 map->name);
953 return ret;
954 }
955
956 hog->map = map;
957 hog->p = p;
958
959 dev_info(pctldev->dev, "hogged map %s, function %s\n", map->name,
960 map->function);
961 mutex_lock(&pctldev->pinctrl_hogs_lock);
962 list_add(&hog->node, &pctldev->pinctrl_hogs);
963 mutex_unlock(&pctldev->pinctrl_hogs_lock);
964
965 return 0;
966}
967
968/**
969 * pinctrl_hog_maps() - hog specific map entries on controller device
970 * @pctldev: the pin control device to hog entries on
971 *
972 * When the pin controllers are registered, there may be some specific pinmux
973 * map entries that need to be hogged, i.e. get+enabled until the system shuts
974 * down.
975 */
976int pinctrl_hog_maps(struct pinctrl_dev *pctldev)
977{
978 struct device *dev = pctldev->dev;
979 const char *devname = dev_name(dev);
980 int ret;
981 int i;
982
983 INIT_LIST_HEAD(&pctldev->pinctrl_hogs);
984 mutex_init(&pctldev->pinctrl_hogs_lock);
985
986 for (i = 0; i < pinctrl_maps_num; i++) {
987 struct pinctrl_map const *map = &pinctrl_maps[i];
988
989 if (!map->hog_on_boot)
990 continue;
991
992 if (map->ctrl_dev_name &&
993 !strcmp(map->ctrl_dev_name, devname)) {
994 /* OK time to hog! */
995 ret = pinctrl_hog_map(pctldev, map);
996 if (ret)
997 return ret;
998 }
999 }
1000 return 0;
1001}
1002
1003/**
1004 * pinctrl_unhog_maps() - unhog specific map entries on controller device
1005 * @pctldev: the pin control device to unhog entries on
1006 */
1007void pinctrl_unhog_maps(struct pinctrl_dev *pctldev)
1008{
1009 struct list_head *node, *tmp;
1010
1011 mutex_lock(&pctldev->pinctrl_hogs_lock);
1012 list_for_each_safe(node, tmp, &pctldev->pinctrl_hogs) {
1013 struct pinctrl_hog *hog =
1014 list_entry(node, struct pinctrl_hog, node);
1015 pinctrl_disable(hog->p);
1016 pinctrl_put(hog->p);
1017 list_del(node);
1018 kfree(hog);
1019 }
1020 mutex_unlock(&pctldev->pinctrl_hogs_lock);
1021}
1022
1023#ifdef CONFIG_DEBUG_FS 592#ifdef CONFIG_DEBUG_FS
1024 593
1025/* Called from pincontrol core */ 594/* Called from pincontrol core */
@@ -1083,83 +652,29 @@ static int pinmux_pins_show(struct seq_file *s, void *what)
1083 return 0; 652 return 0;
1084} 653}
1085 654
1086static int pinmux_hogs_show(struct seq_file *s, void *what) 655void pinmux_dbg_show(struct seq_file *s, struct pinctrl *p)
1087{
1088 struct pinctrl_dev *pctldev = s->private;
1089 struct pinctrl_hog *hog;
1090
1091 seq_puts(s, "Pin control map hogs held by device\n");
1092
1093 list_for_each_entry(hog, &pctldev->pinctrl_hogs, node)
1094 seq_printf(s, "%s\n", hog->map->name);
1095
1096 return 0;
1097}
1098
1099static int pinmux_show(struct seq_file *s, void *what)
1100{ 656{
1101 struct pinctrl *p; 657 struct pinctrl_dev *pctldev = p->pctldev;
1102 658 const struct pinmux_ops *pmxops;
1103 seq_puts(s, "Requested pinmuxes and their maps:\n"); 659 const struct pinctrl_ops *pctlops;
1104 list_for_each_entry(p, &pinctrl_list, node) { 660 struct pinmux_group *grp;
1105 struct pinctrl_dev *pctldev = p->pctldev;
1106 const struct pinmux_ops *pmxops;
1107 const struct pinctrl_ops *pctlops;
1108 struct pinmux_group *grp;
1109
1110 if (!pctldev) {
1111 seq_puts(s, "NO PIN CONTROLLER DEVICE\n");
1112 continue;
1113 }
1114
1115 pmxops = pctldev->desc->pmxops;
1116 pctlops = pctldev->desc->pctlops;
1117
1118 seq_printf(s, "device: %s function: %s (%u),",
1119 pinctrl_dev_get_name(p->pctldev),
1120 pmxops->get_function_name(pctldev,
1121 p->func_selector),
1122 p->func_selector);
1123
1124 seq_printf(s, " groups: [");
1125 list_for_each_entry(grp, &p->groups, node) {
1126 seq_printf(s, " %s (%u)",
1127 pctlops->get_group_name(pctldev,
1128 grp->group_selector),
1129 grp->group_selector);
1130 }
1131 seq_printf(s, " ]");
1132 661
1133 seq_printf(s, " users: %u map-> %s\n", 662 pmxops = pctldev->desc->pmxops;
1134 p->usecount, 663 pctlops = pctldev->desc->pctlops;
1135 p->dev ? dev_name(p->dev) : "(system)");
1136 }
1137 664
1138 return 0; 665 seq_printf(s, " function: %s (%u),",
1139} 666 pmxops->get_function_name(pctldev,
1140 667 p->func_selector),
1141static int pinctrl_maps_show(struct seq_file *s, void *what) 668 p->func_selector);
1142{
1143 int i;
1144 669
1145 seq_puts(s, "Pinctrl maps:\n"); 670 seq_printf(s, " groups: [");
1146 671 list_for_each_entry(grp, &p->groups, node) {
1147 for (i = 0; i < pinctrl_maps_num; i++) { 672 seq_printf(s, " %s (%u)",
1148 struct pinctrl_map const *map = &pinctrl_maps[i]; 673 pctlops->get_group_name(pctldev,
1149 674 grp->group_selector),
1150 seq_printf(s, "%s:\n", map->name); 675 grp->group_selector);
1151 if (map->dev_name)
1152 seq_printf(s, " device: %s\n",
1153 map->dev_name);
1154 else
1155 seq_printf(s, " SYSTEM MUX\n");
1156 seq_printf(s, " controlling device %s\n",
1157 map->ctrl_dev_name);
1158 seq_printf(s, " function: %s\n", map->function);
1159 seq_printf(s, " group: %s\n", map->group ? map->group :
1160 "(default)");
1161 } 676 }
1162 return 0; 677 seq_printf(s, " ]");
1163} 678}
1164 679
1165static int pinmux_functions_open(struct inode *inode, struct file *file) 680static int pinmux_functions_open(struct inode *inode, struct file *file)
@@ -1172,21 +687,6 @@ static int pinmux_pins_open(struct inode *inode, struct file *file)
1172 return single_open(file, pinmux_pins_show, inode->i_private); 687 return single_open(file, pinmux_pins_show, inode->i_private);
1173} 688}
1174 689
1175static int pinmux_hogs_open(struct inode *inode, struct file *file)
1176{
1177 return single_open(file, pinmux_hogs_show, inode->i_private);
1178}
1179
1180static int pinmux_open(struct inode *inode, struct file *file)
1181{
1182 return single_open(file, pinmux_show, NULL);
1183}
1184
1185static int pinctrl_maps_open(struct inode *inode, struct file *file)
1186{
1187 return single_open(file, pinctrl_maps_show, NULL);
1188}
1189
1190static const struct file_operations pinmux_functions_ops = { 690static const struct file_operations pinmux_functions_ops = {
1191 .open = pinmux_functions_open, 691 .open = pinmux_functions_open,
1192 .read = seq_read, 692 .read = seq_read,
@@ -1201,27 +701,6 @@ static const struct file_operations pinmux_pins_ops = {
1201 .release = single_release, 701 .release = single_release,
1202}; 702};
1203 703
1204static const struct file_operations pinmux_hogs_ops = {
1205 .open = pinmux_hogs_open,
1206 .read = seq_read,
1207 .llseek = seq_lseek,
1208 .release = single_release,
1209};
1210
1211static const struct file_operations pinmux_ops = {
1212 .open = pinmux_open,
1213 .read = seq_read,
1214 .llseek = seq_lseek,
1215 .release = single_release,
1216};
1217
1218static const struct file_operations pinctrl_maps_ops = {
1219 .open = pinctrl_maps_open,
1220 .read = seq_read,
1221 .llseek = seq_lseek,
1222 .release = single_release,
1223};
1224
1225void pinmux_init_device_debugfs(struct dentry *devroot, 704void pinmux_init_device_debugfs(struct dentry *devroot,
1226 struct pinctrl_dev *pctldev) 705 struct pinctrl_dev *pctldev)
1227{ 706{
@@ -1229,16 +708,6 @@ void pinmux_init_device_debugfs(struct dentry *devroot,
1229 devroot, pctldev, &pinmux_functions_ops); 708 devroot, pctldev, &pinmux_functions_ops);
1230 debugfs_create_file("pinmux-pins", S_IFREG | S_IRUGO, 709 debugfs_create_file("pinmux-pins", S_IFREG | S_IRUGO,
1231 devroot, pctldev, &pinmux_pins_ops); 710 devroot, pctldev, &pinmux_pins_ops);
1232 debugfs_create_file("pinmux-hogs", S_IFREG | S_IRUGO,
1233 devroot, pctldev, &pinmux_hogs_ops);
1234}
1235
1236void pinmux_init_debugfs(struct dentry *subsys_root)
1237{
1238 debugfs_create_file("pinmuxes", S_IFREG | S_IRUGO,
1239 subsys_root, NULL, &pinmux_ops);
1240 debugfs_create_file("pinctrl-maps", S_IFREG | S_IRUGO,
1241 subsys_root, NULL, &pinctrl_maps_ops);
1242} 711}
1243 712
1244#endif /* CONFIG_DEBUG_FS */ 713#endif /* CONFIG_DEBUG_FS */