History

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.

Linus Walleij committed 14 years ago

Commit befe5bd1 parent e93bcee5 files · +779 −635Browse files

Unified · Split

5 files
  1. drivers/pinctrl/core.c +596 −2
  2. drivers/pinctrl/core.h +28 −2
  3. drivers/pinctrl/pinmux.c +90 −621
  4. drivers/pinctrl/pinmux.h +61 −6
  5. include/linux/pinctrl/consumer.h +4 −4
drivers/pinctrl/core.c+596−2
@@ -1,7 +1,7 @@
11 /*
22 * Core driver for the pin control subsystem
33 *
4− * Copyright (C) 2011 ST-Ericsson SA
4+ * Copyright (C) 2011-2012 ST-Ericsson SA
55 * Written on behalf of Linaro for ST-Ericsson
66 * Based on bits of regulator core, gpio core and clk core
77 *
@@ -30,10 +30,30 @@ · 22 unmodified lines
3030 #include "pinmux.h"
3131 #include "pinconf.h"
3232
33+/**
34+ * struct pinctrl_hog - a list item to stash control hogs
35+ * @node: pin control hog list node
36+ * @map: map entry responsible for this hogging
37+ * @pmx: the pin control hogged by this item
38+ */
39+struct pinctrl_hog {
40+ struct list_head node;
41+ struct pinctrl_map const *map;
42+ struct pinctrl *p;
43+};
44+
3345 /* Global list of pin control devices */
3446 static DEFINE_MUTEX(pinctrldev_list_mutex);
3547 static LIST_HEAD(pinctrldev_list);
3648
49+/* List of pin controller handles */
50+static DEFINE_MUTEX(pinctrl_list_mutex);
51+static LIST_HEAD(pinctrl_list);
52+
53+/* Global pinctrl maps */
54+static struct pinctrl_map *pinctrl_maps;
55+static unsigned pinctrl_maps_num;
56+
3757 const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev)
3858 {
3959 /* We're not allowed to register devices without name */
@@ -337,6 +357,476 @@ int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, · 297 unmodified lines
337357 return -EINVAL;
338358 }
339359
360+/**
361+ * pinctrl_request_gpio() - request a single pin to be used in as GPIO
362+ * @gpio: the GPIO pin number from the GPIO subsystem number space
363+ *
364+ * This function should *ONLY* be used from gpiolib-based GPIO drivers,
365+ * as part of their gpio_request() semantics, platforms and individual drivers
366+ * shall *NOT* request GPIO pins to be muxed in.
367+ */
368+int pinctrl_request_gpio(unsigned gpio)
369+{
370+ struct pinctrl_dev *pctldev;
371+ struct pinctrl_gpio_range *range;
372+ int ret;
373+ int pin;
374+
375+ ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
376+ if (ret)
377+ return -EINVAL;
378+
379+ /* Convert to the pin controllers number space */
380+ pin = gpio - range->base + range->pin_base;
381+
382+ return pinmux_request_gpio(pctldev, range, pin, gpio);
383+}
384+EXPORT_SYMBOL_GPL(pinctrl_request_gpio);
385+
386+/**
387+ * pinctrl_free_gpio() - free control on a single pin, currently used as GPIO
388+ * @gpio: the GPIO pin number from the GPIO subsystem number space
389+ *
390+ * This function should *ONLY* be used from gpiolib-based GPIO drivers,
391+ * as part of their gpio_free() semantics, platforms and individual drivers
392+ * shall *NOT* request GPIO pins to be muxed out.
393+ */
394+void pinctrl_free_gpio(unsigned gpio)
395+{
396+ struct pinctrl_dev *pctldev;
397+ struct pinctrl_gpio_range *range;
398+ int ret;
399+ int pin;
400+
401+ ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
402+ if (ret)
403+ return;
404+
405+ /* Convert to the pin controllers number space */
406+ pin = gpio - range->base + range->pin_base;
407+
408+ return pinmux_free_gpio(pctldev, pin, range);
409+}
410+EXPORT_SYMBOL_GPL(pinctrl_free_gpio);
411+
412+static int pinctrl_gpio_direction(unsigned gpio, bool input)
413+{
414+ struct pinctrl_dev *pctldev;
415+ struct pinctrl_gpio_range *range;
416+ int ret;
417+ int pin;
418+
419+ ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
420+ if (ret)
421+ return ret;
422+
423+ /* Convert to the pin controllers number space */
424+ pin = gpio - range->base + range->pin_base;
425+
426+ return pinmux_gpio_direction(pctldev, range, pin, input);
427+}
428+
429+/**
430+ * pinctrl_gpio_direction_input() - request a GPIO pin to go into input mode
431+ * @gpio: the GPIO pin number from the GPIO subsystem number space
432+ *
433+ * This function should *ONLY* be used from gpiolib-based GPIO drivers,
434+ * as part of their gpio_direction_input() semantics, platforms and individual
435+ * drivers shall *NOT* touch pin control GPIO calls.
436+ */
437+int pinctrl_gpio_direction_input(unsigned gpio)
438+{
439+ return pinctrl_gpio_direction(gpio, true);
440+}
441+EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input);
442+
443+/**
444+ * pinctrl_gpio_direction_output() - request a GPIO pin to go into output mode
445+ * @gpio: the GPIO pin number from the GPIO subsystem number space
446+ *
447+ * This function should *ONLY* be used from gpiolib-based GPIO drivers,
448+ * as part of their gpio_direction_output() semantics, platforms and individual
449+ * drivers shall *NOT* touch pin control GPIO calls.
450+ */
451+int pinctrl_gpio_direction_output(unsigned gpio)
452+{
453+ return pinctrl_gpio_direction(gpio, false);
454+}
455+EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
456+
457+/**
458+ * pinctrl_get() - retrieves the pin controller handle for a certain device
459+ * @dev: the device to get the pin controller handle for
460+ * @name: an optional specific control mapping name or NULL, the name is only
461+ * needed if you want to have more than one mapping per device, or if you
462+ * need an anonymous pin control (not tied to any specific device)
463+ */
464+struct pinctrl *pinctrl_get(struct device *dev, const char *name)
465+{
466+ struct pinctrl_map const *map = NULL;
467+ struct pinctrl_dev *pctldev = NULL;
468+ const char *devname = NULL;
469+ struct pinctrl *p;
470+ bool found_map;
471+ unsigned num_maps = 0;
472+ int ret = -ENODEV;
473+ int i;
474+
475+ /* We must have dev or ID or both */
476+ if (!dev && !name)
477+ return ERR_PTR(-EINVAL);
478+
479+ if (dev)
480+ devname = dev_name(dev);
481+
482+ pr_debug("get pin control handle %s for device %s\n", name,
483+ devname ? devname : "(none)");
484+
485+ /*
486+ * create the state cookie holder struct pinctrl for each
487+ * mapping, this is what consumers will get when requesting
488+ * a pin control handle with pinctrl_get()
489+ */
490+ p = kzalloc(sizeof(struct pinctrl), GFP_KERNEL);
491+ if (p == NULL)
492+ return ERR_PTR(-ENOMEM);
493+ mutex_init(&p->mutex);
494+ pinmux_init_pinctrl_handle(p);
495+
496+ /* Iterate over the pin control maps to locate the right ones */
497+ for (i = 0; i < pinctrl_maps_num; i++) {
498+ map = &pinctrl_maps[i];
499+ found_map = false;
500+
501+ /*
502+ * First, try to find the pctldev given in the map
503+ */
504+ pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name);
505+ if (!pctldev) {
506+ pr_warning("could not find a pinctrl device for pinmux function %s, fishy, they shall all have one\n",
507+ map->function);
508+ pr_warning("given pinctrl device name: %s",
509+ map->ctrl_dev_name);
510+
511+ /* Continue to check the other mappings anyway... */
512+ continue;
513+ }
514+
515+ pr_debug("in map, found pctldev %s to handle function %s",
516+ dev_name(pctldev->dev), map->function);
517+
518+
519+ /*
520+ * If we're looking for a specific named map, this must match,
521+ * else we loop and look for the next.
522+ */
523+ if (name != NULL) {
524+ if (map->name == NULL)
525+ continue;
526+ if (strcmp(map->name, name))
527+ continue;
528+ }
529+
530+ /*
531+ * This is for the case where no device name is given, we
532+ * already know that the function name matches from above
533+ * code.
534+ */
535+ if (!map->dev_name && (name != NULL))
536+ found_map = true;
537+
538+ /* If the mapping has a device set up it must match */
539+ if (map->dev_name &&
540+ (!devname || !strcmp(map->dev_name, devname)))
541+ /* MATCH! */
542+ found_map = true;
543+
544+ /* If this map is applicable, then apply it */
545+ if (found_map) {
546+ ret = pinmux_apply_muxmap(pctldev, p, dev,
547+ devname, map);
548+ if (ret) {
549+ kfree(p);
550+ return ERR_PTR(ret);
551+ }
552+ num_maps++;
553+ }
554+ }
555+
556+ /* We should have atleast one map, right */
557+ if (!num_maps) {
558+ pr_err("could not find any mux maps for device %s, ID %s\n",
559+ devname ? devname : "(anonymous)",
560+ name ? name : "(undefined)");
561+ kfree(p);
562+ return ERR_PTR(-EINVAL);
563+ }
564+
565+ pr_debug("found %u mux maps for device %s, UD %s\n",
566+ num_maps,
567+ devname ? devname : "(anonymous)",
568+ name ? name : "(undefined)");
569+
570+ /* Add the pinmux to the global list */
571+ mutex_lock(&pinctrl_list_mutex);
572+ list_add(&p->node, &pinctrl_list);
573+ mutex_unlock(&pinctrl_list_mutex);
574+
575+ return p;
576+}
577+EXPORT_SYMBOL_GPL(pinctrl_get);
578+
579+/**
580+ * pinctrl_put() - release a previously claimed pin control handle
581+ * @p: a pin control handle previously claimed by pinctrl_get()
582+ */
583+void pinctrl_put(struct pinctrl *p)
584+{
585+ if (p == NULL)
586+ return;
587+
588+ mutex_lock(&p->mutex);
589+ if (p->usecount)
590+ pr_warn("releasing pin control handle with active users!\n");
591+ /* Free the groups and all acquired pins */
592+ pinmux_put(p);
593+ mutex_unlock(&p->mutex);
594+
595+ /* Remove from list */
596+ mutex_lock(&pinctrl_list_mutex);
597+ list_del(&p->node);
598+ mutex_unlock(&pinctrl_list_mutex);
599+
600+ kfree(p);
601+}
602+EXPORT_SYMBOL_GPL(pinctrl_put);
603+
604+/**
605+ * pinctrl_enable() - enable a certain pin controller setting
606+ * @p: the pin control handle to enable, previously claimed by pinctrl_get()
607+ */
608+int pinctrl_enable(struct pinctrl *p)
609+{
610+ int ret = 0;
611+
612+ if (p == NULL)
613+ return -EINVAL;
614+ mutex_lock(&p->mutex);
615+ if (p->usecount++ == 0) {
616+ ret = pinmux_enable(p);
617+ if (ret)
618+ p->usecount--;
619+ }
620+ mutex_unlock(&p->mutex);
621+ return ret;
622+}
623+EXPORT_SYMBOL_GPL(pinctrl_enable);
624+
625+/**
626+ * pinctrl_disable() - disable a certain pin control setting
627+ * @p: the pin control handle to disable, previously claimed by pinctrl_get()
628+ */
629+void pinctrl_disable(struct pinctrl *p)
630+{
631+ if (p == NULL)
632+ return;
633+
634+ mutex_lock(&p->mutex);
635+ if (--p->usecount == 0) {
636+ pinmux_disable(p);
637+ }
638+ mutex_unlock(&p->mutex);
639+}
640+EXPORT_SYMBOL_GPL(pinctrl_disable);
641+
642+/**
643+ * pinctrl_register_mappings() - register a set of pin controller mappings
644+ * @maps: the pincontrol mappings table to register, this should be marked with
645+ * __initdata so it can be discarded after boot, this function will
646+ * perform a shallow copy for the mapping entries.
647+ * @num_maps: the number of maps in the mapping table
648+ *
649+ * Only call this once during initialization of your machine, the function is
650+ * tagged as __init and won't be callable after init has completed. The map
651+ * passed into this function will be owned by the pinmux core and cannot be
652+ * freed.
653+ */
654+int __init pinctrl_register_mappings(struct pinctrl_map const *maps,
655+ unsigned num_maps)
656+{
657+ void *tmp_maps;
658+ int i;
659+
660+ pr_debug("add %d pinmux maps\n", num_maps);
661+
662+ /* First sanity check the new mapping */
663+ for (i = 0; i < num_maps; i++) {
664+ if (!maps[i].name) {
665+ pr_err("failed to register map %d: no map name given\n",
666+ i);
667+ return -EINVAL;
668+ }
669+
670+ if (!maps[i].ctrl_dev_name) {
671+ pr_err("failed to register map %s (%d): no pin control device given\n",
672+ maps[i].name, i);
673+ return -EINVAL;
674+ }
675+
676+ if (!maps[i].function) {
677+ pr_err("failed to register map %s (%d): no function ID given\n",
678+ maps[i].name, i);
679+ return -EINVAL;
680+ }
681+
682+ if (!maps[i].dev_name)
683+ pr_debug("add system map %s function %s with no device\n",
684+ maps[i].name,
685+ maps[i].function);
686+ else
687+ pr_debug("register map %s, function %s\n",
688+ maps[i].name,
689+ maps[i].function);
690+ }
691+
692+ /*
693+ * Make a copy of the map array - string pointers will end up in the
694+ * kernel const section anyway so these do not need to be deep copied.
695+ */
696+ if (!pinctrl_maps_num) {
697+ /* On first call, just copy them */
698+ tmp_maps = kmemdup(maps,
699+ sizeof(struct pinctrl_map) * num_maps,
700+ GFP_KERNEL);
701+ if (!tmp_maps)
702+ return -ENOMEM;
703+ } else {
704+ /* Subsequent calls, reallocate array to new size */
705+ size_t oldsize = sizeof(struct pinctrl_map) * pinctrl_maps_num;
706+ size_t newsize = sizeof(struct pinctrl_map) * num_maps;
707+
708+ tmp_maps = krealloc(pinctrl_maps,
709+ oldsize + newsize, GFP_KERNEL);
710+ if (!tmp_maps)
711+ return -ENOMEM;
712+ memcpy((tmp_maps + oldsize), maps, newsize);
713+ }
714+
715+ pinctrl_maps = tmp_maps;
716+ pinctrl_maps_num += num_maps;
717+ return 0;
718+}
719+
720+/* Hog a single map entry and add to the hoglist */
721+static int pinctrl_hog_map(struct pinctrl_dev *pctldev,
722+ struct pinctrl_map const *map)
723+{
724+ struct pinctrl_hog *hog;
725+ struct pinctrl *p;
726+ int ret;
727+
728+ if (map->dev_name) {
729+ /*
730+ * TODO: the day we have device tree support, we can
731+ * traverse the device tree and hog to specific device nodes
732+ * without any problems, so then we can hog pinmuxes for
733+ * all devices that just want a static pin mux at this point.
734+ */
735+ dev_err(pctldev->dev, "map %s wants to hog a non-system pinmux, this is not going to work\n",
736+ map->name);
737+ return -EINVAL;
738+ }
739+
740+ hog = kzalloc(sizeof(struct pinctrl_hog), GFP_KERNEL);
741+ if (!hog)
742+ return -ENOMEM;
743+
744+ p = pinctrl_get(NULL, map->name);
745+ if (IS_ERR(p)) {
746+ kfree(hog);
747+ dev_err(pctldev->dev,
748+ "could not get the %s pin control mapping for hogging\n",
749+ map->name);
750+ return PTR_ERR(p);
751+ }
752+
753+ ret = pinctrl_enable(p);
754+ if (ret) {
755+ pinctrl_put(p);
756+ kfree(hog);
757+ dev_err(pctldev->dev,
758+ "could not enable the %s pin control mapping for hogging\n",
759+ map->name);
760+ return ret;
761+ }
762+
763+ hog->map = map;
764+ hog->p = p;
765+
766+ dev_info(pctldev->dev, "hogged map %s, function %s\n", map->name,
767+ map->function);
768+ mutex_lock(&pctldev->pinctrl_hogs_lock);
769+ list_add(&hog->node, &pctldev->pinctrl_hogs);
770+ mutex_unlock(&pctldev->pinctrl_hogs_lock);
771+
772+ return 0;
773+}
774+
775+/**
776+ * pinctrl_hog_maps() - hog specific map entries on controller device
777+ * @pctldev: the pin control device to hog entries on
778+ *
779+ * When the pin controllers are registered, there may be some specific pinmux
780+ * map entries that need to be hogged, i.e. get+enabled until the system shuts
781+ * down.
782+ */
783+int pinctrl_hog_maps(struct pinctrl_dev *pctldev)
784+{
785+ struct device *dev = pctldev->dev;
786+ const char *devname = dev_name(dev);
787+ int ret;
788+ int i;
789+
790+ INIT_LIST_HEAD(&pctldev->pinctrl_hogs);
791+ mutex_init(&pctldev->pinctrl_hogs_lock);
792+
793+ for (i = 0; i < pinctrl_maps_num; i++) {
794+ struct pinctrl_map const *map = &pinctrl_maps[i];
795+
796+ if (!map->hog_on_boot)
797+ continue;
798+
799+ if (map->ctrl_dev_name &&
800+ !strcmp(map->ctrl_dev_name, devname)) {
801+ /* OK time to hog! */
802+ ret = pinctrl_hog_map(pctldev, map);
803+ if (ret)
804+ return ret;
805+ }
806+ }
807+ return 0;
808+}
809+
810+/**
811+ * pinctrl_unhog_maps() - unhog specific map entries on controller device
812+ * @pctldev: the pin control device to unhog entries on
813+ */
814+void pinctrl_unhog_maps(struct pinctrl_dev *pctldev)
815+{
816+ struct list_head *node, *tmp;
817+
818+ mutex_lock(&pctldev->pinctrl_hogs_lock);
819+ list_for_each_safe(node, tmp, &pctldev->pinctrl_hogs) {
820+ struct pinctrl_hog *hog =
821+ list_entry(node, struct pinctrl_hog, node);
822+ pinctrl_disable(hog->p);
823+ pinctrl_put(hog->p);
824+ list_del(node);
825+ kfree(hog);
826+ }
827+ mutex_unlock(&pctldev->pinctrl_hogs_lock);
828+}
829+
340830 #ifdef CONFIG_DEBUG_FS
341831
342832 static int pinctrl_pins_show(struct seq_file *s, void *what)
@@ -427,6 +917,43 @@ static int pinctrl_gpioranges_show(struct seq_file *s, void *what) · 84 unmodified lines
427917 return 0;
428918 }
429919
920+static int pinctrl_maps_show(struct seq_file *s, void *what)
921+{
922+ int i;
923+
924+ seq_puts(s, "Pinctrl maps:\n");
925+
926+ for (i = 0; i < pinctrl_maps_num; i++) {
927+ struct pinctrl_map const *map = &pinctrl_maps[i];
928+
929+ seq_printf(s, "%s:\n", map->name);
930+ if (map->dev_name)
931+ seq_printf(s, " device: %s\n",
932+ map->dev_name);
933+ else
934+ seq_printf(s, " SYSTEM MUX\n");
935+ seq_printf(s, " controlling device %s\n",
936+ map->ctrl_dev_name);
937+ seq_printf(s, " function: %s\n", map->function);
938+ seq_printf(s, " group: %s\n", map->group ? map->group :
939+ "(default)");
940+ }
941+ return 0;
942+}
943+
944+static int pinmux_hogs_show(struct seq_file *s, void *what)
945+{
946+ struct pinctrl_dev *pctldev = s->private;
947+ struct pinctrl_hog *hog;
948+
949+ seq_puts(s, "Pin control map hogs held by device\n");
950+
951+ list_for_each_entry(hog, &pctldev->pinctrl_hogs, node)
952+ seq_printf(s, "%s\n", hog->map->name);
953+
954+ return 0;
955+}
956+
430957 static int pinctrl_devices_show(struct seq_file *s, void *what)
431958 {
432959 struct pinctrl_dev *pctldev;
@@ -450,6 +977,32 @@ static int pinctrl_devices_show(struct seq_file *s, void *what) · 17 unmodified lines
450977 return 0;
451978 }
452979
980+static int pinctrl_show(struct seq_file *s, void *what)
981+{
982+ struct pinctrl *p;
983+
984+ seq_puts(s, "Requested pin control handlers their pinmux maps:\n");
985+ list_for_each_entry(p, &pinctrl_list, node) {
986+ struct pinctrl_dev *pctldev = p->pctldev;
987+
988+ if (!pctldev) {
989+ seq_puts(s, "NO PIN CONTROLLER DEVICE\n");
990+ continue;
991+ }
992+
993+ seq_printf(s, "device: %s",
994+ pinctrl_dev_get_name(p->pctldev));
995+
996+ pinmux_dbg_show(s, p);
997+
998+ seq_printf(s, " users: %u map-> %s\n",
999+ p->usecount,
1000+ p->dev ? dev_name(p->dev) : "(system)");
1001+ }
1002+
1003+ return 0;
1004+}
1005+
4531006 static int pinctrl_pins_open(struct inode *inode, struct file *file)
4541007 {
4551008 return single_open(file, pinctrl_pins_show, inode->i_private);
@@ -465,11 +1018,26 @@ static int pinctrl_gpioranges_open(struct inode *inode, struct file *file) · 9 unmodified lines
4651018 return single_open(file, pinctrl_gpioranges_show, inode->i_private);
4661019 }
4671020
1021+static int pinctrl_maps_open(struct inode *inode, struct file *file)
1022+{
1023+ return single_open(file, pinctrl_maps_show, inode->i_private);
1024+}
1025+
1026+static int pinmux_hogs_open(struct inode *inode, struct file *file)
1027+{
1028+ return single_open(file, pinmux_hogs_show, inode->i_private);
1029+}
1030+
4681031 static int pinctrl_devices_open(struct inode *inode, struct file *file)
4691032 {
4701033 return single_open(file, pinctrl_devices_show, NULL);
4711034 }
4721035
1036+static int pinctrl_open(struct inode *inode, struct file *file)
1037+{
1038+ return single_open(file, pinctrl_show, NULL);
1039+}
1040+
4731041 static const struct file_operations pinctrl_pins_ops = {
4741042 .open = pinctrl_pins_open,
4751043 .read = seq_read,
@@ -491,6 +1059,20 @@ static const struct file_operations pinctrl_gpioranges_ops = { · 15 unmodified lines
4911059 .release = single_release,
4921060 };
4931061
1062+static const struct file_operations pinctrl_maps_ops = {
1063+ .open = pinctrl_maps_open,
1064+ .read = seq_read,
1065+ .llseek = seq_lseek,
1066+ .release = single_release,
1067+};
1068+
1069+static const struct file_operations pinmux_hogs_ops = {
1070+ .open = pinmux_hogs_open,
1071+ .read = seq_read,
1072+ .llseek = seq_lseek,
1073+ .release = single_release,
1074+};
1075+
4941076 static const struct file_operations pinctrl_devices_ops = {
4951077 .open = pinctrl_devices_open,
4961078 .read = seq_read,
@@ -498,6 +1080,13 @@ static const struct file_operations pinctrl_devices_ops = { · 1 unmodified line
4981080 .release = single_release,
4991081 };
5001082
1083+static const struct file_operations pinctrl_ops = {
1084+ .open = pinctrl_open,
1085+ .read = seq_read,
1086+ .llseek = seq_lseek,
1087+ .release = single_release,
1088+};
1089+
5011090 static struct dentry *debugfs_root;
5021091
5031092 static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
@@ -519,6 +1108,10 @@ static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev) · 15 unmodified lines
5191108 device_root, pctldev, &pinctrl_groups_ops);
5201109 debugfs_create_file("gpio-ranges", S_IFREG | S_IRUGO,
5211110 device_root, pctldev, &pinctrl_gpioranges_ops);
1111+ debugfs_create_file("pinctrl-maps", S_IFREG | S_IRUGO,
1112+ device_root, pctldev, &pinctrl_maps_ops);
1113+ debugfs_create_file("pinmux-hogs", S_IFREG | S_IRUGO,
1114+ device_root, pctldev, &pinmux_hogs_ops);
5221115 pinmux_init_device_debugfs(device_root, pctldev);
5231116 pinconf_init_device_debugfs(device_root, pctldev);
5241117 }
@@ -539,7 +1132,8 @@ static void pinctrl_init_debugfs(void) · 14 unmodified lines
5391132
5401133 debugfs_create_file("pinctrl-devices", S_IFREG | S_IRUGO,
5411134 debugfs_root, NULL, &pinctrl_devices_ops);
542− pinmux_init_debugfs(debugfs_root);
1135+ debugfs_create_file("pinctrl-handles", S_IFREG | S_IRUGO,
1136+ debugfs_root, NULL, &pinctrl_ops);
5431137 }
5441138
5451139 #else /* CONFIG_DEBUG_FS */
drivers/pinctrl/core.h+28−2
@@ -30,6 +30,7 @@ struct pinctrl_gpio_range; · 29 unmodified lines
3030 * subsystem
3131 * @pinctrl_hogs_lock: lock for the pin control hog list
3232 * @pinctrl_hogs: list of pin control maps hogged by this device
33+ * @device_root: debugfs root for this device
3334 */
3435 struct pinctrl_dev {
3536 struct list_head node;
@@ -41,12 +42,37 @@ struct pinctrl_dev { · 5 unmodified lines
4142 struct device *dev;
4243 struct module *owner;
4344 void *driver_data;
45+ struct mutex pinctrl_hogs_lock;
46+ struct list_head pinctrl_hogs;
4447 #ifdef CONFIG_DEBUG_FS
4548 struct dentry *device_root;
4649 #endif
50+};
51+
52+/**
53+ * struct pinctrl - per-device pin control state holder
54+ * @node: global list node
55+ * @dev: the device using this pin control handle
56+ * @usecount: the number of active users of this pin controller setting, used
57+ * to keep track of nested use cases
58+ * @pctldev: pin control device handling this pin control handle
59+ * @mutex: a lock for the pin control state holder
60+ * @func_selector: the function selector for the pinmux device handling
61+ * this pinmux
62+ * @groups: the group selectors for the pinmux device and
63+ * selector combination handling this pinmux, this is a list that
64+ * will be traversed on all pinmux operations such as
65+ * get/put/enable/disable
66+ */
67+struct pinctrl {
68+ struct list_head node;
69+ struct device *dev;
70+ unsigned usecount;
71+ struct pinctrl_dev *pctldev;
72+ struct mutex mutex;
4773 #ifdef CONFIG_PINMUX
48− struct mutex pinctrl_hogs_lock;
49− struct list_head pinctrl_hogs;
74+ unsigned func_selector;
75+ struct list_head groups;
5076 #endif
5177 };
5278
drivers/pinctrl/pinmux.c+90−621
@@ -28,14 +28,7 @@ · 27 unmodified lines
2828 #include <linux/pinctrl/machine.h>
2929 #include <linux/pinctrl/pinmux.h>
3030 #include "core.h"
31−
32−/* List of pin controller handles */
33−static DEFINE_MUTEX(pinctrl_list_mutex);
34−static LIST_HEAD(pinctrl_list);
35−
36−/* Global pinctrl maps */
37−static struct pinctrl_map *pinctrl_maps;
38−static unsigned pinctrl_maps_num;
31+#include "pinmux.h"
3932
4033 /**
4134 * struct pinmux_group - group list item for pinmux groups
@@ -47,43 +40,6 @@ struct pinmux_group { · 5 unmodified lines
4740 unsigned group_selector;
4841 };
4942
50−/**
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− */
65−struct 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− */
81−struct pinctrl_hog {
82− struct list_head node;
83− struct pinctrl_map const *map;
84− struct pinctrl *p;
85−};
86−
8743 /**
8844 * pin_request() - request a single pin to be muxed in, typically for GPIO
8945 * @pin: the pin number in the global pin space
@@ -207,28 +163,18 @@ static const char *pin_free(struct pinctrl_dev *pctldev, int pin, · 117 unmodified lines
207163 }
208164
209165 /**
210− * pinctrl_request_gpio() - request a single pin to be used in as GPIO
211− * @gpio: the GPIO pin number from the GPIO subsystem number space
212− *
213− * This function should *ONLY* be used from gpiolib-based GPIO drivers,
214− * as part of their gpio_request() semantics, platforms and individual drivers
215− * shall *NOT* request GPIO pins to be muxed in.
166+ * pinmux_request_gpio() - request pinmuxing for a GPIO pin
167+ * @pctldev: pin controller device affected
168+ * @pin: the pin to mux in for GPIO
169+ * @range: the applicable GPIO range
216170 */
217−int pinctrl_request_gpio(unsigned gpio)
171+int pinmux_request_gpio(struct pinctrl_dev *pctldev,
172+ struct pinctrl_gpio_range *range,
173+ unsigned pin, unsigned gpio)
218174 {
219175 char gpiostr[16];
220176 const char *function;
221− struct pinctrl_dev *pctldev;
222− struct pinctrl_gpio_range *range;
223177 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;
232178
233179 /* Conjure some name stating what chip and pin this is taken by */
234180 snprintf(gpiostr, 15, "%s:%d", range->name, gpio);
@@ -243,53 +189,38 @@ int pinctrl_request_gpio(unsigned gpio) · 8 unmodified lines
243189
244190 return ret;
245191 }
246−EXPORT_SYMBOL_GPL(pinctrl_request_gpio);
247192
248193 /**
249− * pinctrl_free_gpio() - free control on a single pin, currently used as GPIO
250− * @gpio: the GPIO pin number from the GPIO subsystem number space
251− *
252− * This function should *ONLY* be used from gpiolib-based GPIO drivers,
253− * as part of their gpio_free() semantics, platforms and individual drivers
254− * shall *NOT* request GPIO pins to be muxed out.
194+ * pinmux_free_gpio() - release a pin from GPIO muxing
195+ * @pctldev: the pin controller device for the pin
196+ * @pin: the affected currently GPIO-muxed in pin
197+ * @range: applicable GPIO range
255198 */
256−void pinctrl_free_gpio(unsigned gpio)
199+void pinmux_free_gpio(struct pinctrl_dev *pctldev, unsigned pin,
200+ struct pinctrl_gpio_range *range)
257201 {
258− struct pinctrl_dev *pctldev;
259− struct pinctrl_gpio_range *range;
260− int ret;
261− int pin;
262202 const char *func;
263203
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−
271204 func = pin_free(pctldev, pin, range);
272205 kfree(func);
273206 }
274−EXPORT_SYMBOL_GPL(pinctrl_free_gpio);
275207
276−static 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+ */
215+int pinmux_gpio_direction(struct pinctrl_dev *pctldev,
216+ struct pinctrl_gpio_range *range,
217+ unsigned pin, bool input)
277218 {
278− struct pinctrl_dev *pctldev;
279− struct pinctrl_gpio_range *range;
280219 const struct pinmux_ops *ops;
281220 int ret;
282− int pin;
283−
284− ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
285− if (ret)
286− return ret;
287221
288222 ops = pctldev->desc->pmxops;
289223
290− /* Convert to the pin controllers number space */
291− pin = gpio - range->base + range->pin_base;
292−
293224 if (ops->gpio_set_direction)
294225 ret = ops->gpio_set_direction(pctldev, range, pin, input);
295226 else
@@ -298,112 +229,6 @@ static int pinctrl_gpio_direction(unsigned gpio, bool input) · 2 unmodified lines
298229 return ret;
299230 }
300231
301−/**
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− */
309−int pinctrl_gpio_direction_input(unsigned gpio)
310−{
311− return pinctrl_gpio_direction(gpio, true);
312−}
313−EXPORT_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− */
323−int pinctrl_gpio_direction_output(unsigned gpio)
324−{
325− return pinctrl_gpio_direction(gpio, false);
326−}
327−EXPORT_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− */
341−int __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−
407232 /**
408233 * acquire_pins() - acquire all the pins for a certain function on a pinmux
409234 * @pctldev: the device to take the pins on
@@ -660,227 +485,81 @@ static int pinmux_enable_muxmap(struct pinctrl_dev *pctldev, · 250 unmodified lines
660485 return 0;
661486 }
662487
663−static 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−
677488 /**
678− * pinctrl_get() - retrieves the pin controller handle for a certain device
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)
489+ * pinmux_apply_muxmap() - apply a certain mux mapping entry
683490 */
684−struct pinctrl *pinctrl_get(struct device *dev, const char *name)
491+int 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)
685496 {
686− struct pinctrl_map const *map = NULL;
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−
497+ int ret;
778498
779− /* We should have atleast one map, right */
780− if (!num_maps) {
781− pr_err("could not find any mux maps for device %s, ID %s\n",
782− devname ? devname : "(anonymous)",
783− name ? name : "(undefined)");
784− kfree(p);
785− return ERR_PTR(-EINVAL);
499+ ret = pinmux_enable_muxmap(pctldev, p, dev,
500+ devname, map);
501+ if (ret) {
502+ pinmux_put(p);
503+ return ret;
786504 }
787505
788− pr_debug("found %u mux maps for device %s, UD %s\n",
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;
506+ return 0;
799507 }
800−EXPORT_SYMBOL_GPL(pinctrl_get);
801508
802509 /**
803− * pinctrl_put() - release a previously claimed pin control handle
804− * @p: a pin control handle previously claimed by pinctrl_get()
510+ * pinmux_put() - free up the pinmux portions of a pin controller handle
805511 */
806−void pinctrl_put(struct pinctrl *p)
512+void pinmux_put(struct pinctrl *p)
807513 {
808− if (p == NULL)
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);
514+ struct list_head *node, *tmp;
822515
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+ }
824524 }
825−EXPORT_SYMBOL_GPL(pinctrl_put);
826525
827526 /**
828− * pinctrl_enable() - enable a certain pin controller setting
829− * @p: the pin control handle to enable, previously claimed by pinctrl_get()
527+ * pinmux_enable() - enable the pinmux portion of a pin control handle
830528 */
831−int pinctrl_enable(struct pinctrl *p)
529+int pinmux_enable(struct pinctrl *p)
832530 {
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;
834535
835− if (p == NULL)
836− return -EINVAL;
837− mutex_lock(&p->mutex);
838− if (p->usecount++ == 0) {
839− struct pinctrl_dev *pctldev = p->pctldev;
840− const struct pinmux_ops *ops = pctldev->desc->pmxops;
841− struct pinmux_group *grp;
842−
843− list_for_each_entry(grp, &p->groups, node) {
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− }
536+ list_for_each_entry(grp, &p->groups, node) {
537+ ret = ops->enable(pctldev, p->func_selector,
538+ grp->group_selector);
539+ if (ret)
540+ /*
541+ * TODO: call disable() on all groups we called
542+ * enable() on to this point?
543+ */
544+ return ret;
855545 }
856− mutex_unlock(&p->mutex);
857− return ret;
546+ return 0;
858547 }
859−EXPORT_SYMBOL_GPL(pinctrl_enable);
860548
861549 /**
862− * pinctrl_disable() - disable a certain pin control setting
863− * @p: the pin control handle to disable, previously claimed by pinctrl_get()
550+ * pinmux_disable() - disable the pinmux portions of a pin control handle
864551 */
865−void pinctrl_disable(struct pinctrl *p)
552+void pinmux_disable(struct pinctrl *p)
866553 {
867− if (p == NULL)
868− return;
869−
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;
554+ struct pinctrl_dev *pctldev = p->pctldev;
555+ const struct pinmux_ops *ops = pctldev->desc->pmxops;
556+ struct pinmux_group *grp;
875557
876− list_for_each_entry(grp, &p->groups, node) {
877− ops->disable(pctldev, p->func_selector,
878− grp->group_selector);
879− }
558+ list_for_each_entry(grp, &p->groups, node) {
559+ ops->disable(pctldev, p->func_selector,
560+ grp->group_selector);
880561 }
881− mutex_unlock(&p->mutex);
882562 }
883−EXPORT_SYMBOL_GPL(pinctrl_disable);
884563
885564 int pinmux_check_ops(struct pinctrl_dev *pctldev)
886565 {
@@ -910,116 +589,6 @@ int pinmux_check_ops(struct pinctrl_dev *pctldev) · 23 unmodified lines
910589 return 0;
911590 }
912591
913−/* Hog a single map entry and add to the hoglist */
914−static 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− */
976−int 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− */
1007−void 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−
1023592 #ifdef CONFIG_DEBUG_FS
1024593
1025594 /* Called from pincontrol core */
@@ -1083,83 +652,29 @@ static int pinmux_pins_show(struct seq_file *s, void *what) · 57 unmodified lines
1083652 return 0;
1084653 }
1085654
1086−static int pinmux_hogs_show(struct seq_file *s, void *what)
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−
1099−static int pinmux_show(struct seq_file *s, void *what)
655+void pinmux_dbg_show(struct seq_file *s, struct pinctrl *p)
1100656 {
1101− struct pinctrl *p;
1102−
1103− seq_puts(s, "Requested pinmuxes and their maps:\n");
1104− list_for_each_entry(p, &pinctrl_list, node) {
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, " ]");
657+ struct pinctrl_dev *pctldev = p->pctldev;
658+ const struct pinmux_ops *pmxops;
659+ const struct pinctrl_ops *pctlops;
660+ struct pinmux_group *grp;
1132661
1133− seq_printf(s, " users: %u map-> %s\n",
1134− p->usecount,
1135− p->dev ? dev_name(p->dev) : "(system)");
1136− }
662+ pmxops = pctldev->desc->pmxops;
663+ pctlops = pctldev->desc->pctlops;
1137664
1138− return 0;
1139−}
1140−
1141−static int pinctrl_maps_show(struct seq_file *s, void *what)
1142−{
1143− int i;
665+ seq_printf(s, " function: %s (%u),",
666+ pmxops->get_function_name(pctldev,
667+ p->func_selector),
668+ p->func_selector);
1144669
1145− seq_puts(s, "Pinctrl maps:\n");
1146−
1147− for (i = 0; i < pinctrl_maps_num; i++) {
1148− struct pinctrl_map const *map = &pinctrl_maps[i];
1149−
1150− seq_printf(s, "%s:\n", map->name);
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)");
670+ seq_printf(s, " groups: [");
671+ list_for_each_entry(grp, &p->groups, node) {
672+ seq_printf(s, " %s (%u)",
673+ pctlops->get_group_name(pctldev,
674+ grp->group_selector),
675+ grp->group_selector);
1161676 }
1162− return 0;
677+ seq_printf(s, " ]");
1163678 }
1164679
1165680 static 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) · 6 unmodified lines
1172687 return single_open(file, pinmux_pins_show, inode->i_private);
1173688 }
1174689
1175−static int pinmux_hogs_open(struct inode *inode, struct file *file)
1176−{
1177− return single_open(file, pinmux_hogs_show, inode->i_private);
1178−}
1179−
1180−static int pinmux_open(struct inode *inode, struct file *file)
1181−{
1182− return single_open(file, pinmux_show, NULL);
1183−}
1184−
1185−static int pinctrl_maps_open(struct inode *inode, struct file *file)
1186−{
1187− return single_open(file, pinctrl_maps_show, NULL);
1188−}
1189−
1190690 static const struct file_operations pinmux_functions_ops = {
1191691 .open = pinmux_functions_open,
1192692 .read = seq_read,
@@ -1201,27 +701,6 @@ static const struct file_operations pinmux_pins_ops = { · 8 unmodified lines
1201701 .release = single_release,
1202702 };
1203703
1204−static 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−
1211−static const struct file_operations pinmux_ops = {
1212− .open = pinmux_open,
1213− .read = seq_read,
1214− .llseek = seq_lseek,
1215− .release = single_release,
1216−};
1217−
1218−static 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−
1225704 void pinmux_init_device_debugfs(struct dentry *devroot,
1226705 struct pinctrl_dev *pctldev)
1227706 {
@@ -1229,16 +708,6 @@ void pinmux_init_device_debugfs(struct dentry *devroot, · 1 unmodified line
1229708 devroot, pctldev, &pinmux_functions_ops);
1230709 debugfs_create_file("pinmux-pins", S_IFREG | S_IRUGO,
1231710 devroot, pctldev, &pinmux_pins_ops);
1232− debugfs_create_file("pinmux-hogs", S_IFREG | S_IRUGO,
1233− devroot, pctldev, &pinmux_hogs_ops);
1234−}
1235−
1236−void 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);
1242711 }
1243712
1244713 #endif /* CONFIG_DEBUG_FS */
drivers/pinctrl/pinmux.h+61−6
@@ -15,9 +15,28 @@ · 14 unmodified lines
1515 int pinmux_check_ops(struct pinctrl_dev *pctldev);
1616 void pinmux_init_device_debugfs(struct dentry *devroot,
1717 struct pinctrl_dev *pctldev);
18−void pinmux_init_debugfs(struct dentry *subsys_root);
19−int pinctrl_hog_maps(struct pinctrl_dev *pctldev);
20−void pinctrl_unhog_maps(struct pinctrl_dev *pctldev);
18+int pinmux_request_gpio(struct pinctrl_dev *pctldev,
19+ struct pinctrl_gpio_range *range,
20+ unsigned pin, unsigned gpio);
21+void pinmux_free_gpio(struct pinctrl_dev *pctldev, unsigned pin,
22+ struct pinctrl_gpio_range *range);
23+int pinmux_gpio_direction(struct pinctrl_dev *pctldev,
24+ struct pinctrl_gpio_range *range,
25+ unsigned pin, bool input);
26+static inline void pinmux_init_pinctrl_handle(struct pinctrl *p)
27+{
28+ p->func_selector = UINT_MAX;
29+ INIT_LIST_HEAD(&p->groups);
30+}
31+int pinmux_apply_muxmap(struct pinctrl_dev *pctldev,
32+ struct pinctrl *p,
33+ struct device *dev,
34+ const char *devname,
35+ struct pinctrl_map const *map);
36+void pinmux_put(struct pinctrl *p);
37+int pinmux_enable(struct pinctrl *p);
38+void pinmux_disable(struct pinctrl *p);
39+void pinmux_dbg_show(struct seq_file *s, struct pinctrl *p);
2140
2241 #else
2342
@@ -31,16 +50,52 @@ static inline void pinmux_init_device_debugfs(struct dentry *devroot, · 7 unmodified lines
3150 {
3251 }
3352
34−static inline void pinmux_init_debugfs(struct dentry *subsys_root)
53+static inline int pinmux_request_gpio(struct pinctrl_dev *pctldev,
54+ struct pinctrl_gpio_range *range,
55+ unsigned pin, unsigned gpio)
56+{
57+ return 0;
58+}
59+
60+static inline void pinmux_free_gpio(struct pinctrl_dev *pctldev,
61+ unsigned pin,
62+ struct pinctrl_gpio_range *range)
63+{
64+}
65+
66+static inline int pinmux_gpio_direction(struct pinctrl_dev *pctldev,
67+ struct pinctrl_gpio_range *range,
68+ unsigned pin, bool input)
69+{
70+ return 0;
71+}
72+
73+static inline void pinmux_init_pinctrl_handle(struct pinctrl *p)
3574 {
3675 }
3776
38−static inline int pinctrl_hog_maps(struct pinctrl_dev *pctldev)
77+static inline int pinmux_apply_muxmap(struct pinctrl_dev *pctldev,
78+ struct pinctrl *p,
79+ struct device *dev,
80+ const char *devname,
81+ struct pinctrl_map const *map)
3982 {
4083 return 0;
4184 }
4285
43−static inline void pinctrl_unhog_maps(struct pinctrl_dev *pctldev)
86+static inline void pinmux_put(struct pinctrl *p)
87+{
88+}
89+
90+static inline int pinmux_enable(struct pinctrl *p)
91+{
92+}
93+
94+static inline void pinmux_disable(struct pinctrl *p)
95+{
96+}
97+
98+void pinmux_dbg_show(struct seq_file *s, struct pinctrl *p)
4499 {
45100 }
46101
include/linux/pinctrl/consumer.h+4−4
@@ -19,9 +19,9 @@ · 18 unmodified lines
1919 /* This struct is private to the core and should be regarded as a cookie */
2020 struct pinctrl;
2121
22−#ifdef CONFIG_PINMUX
22+#ifdef CONFIG_PINCTRL
2323
24−/* External interface to pinmux */
24+/* External interface to pin control */
2525 extern int pinctrl_request_gpio(unsigned gpio);
2626 extern void pinctrl_free_gpio(unsigned gpio);
2727 extern int pinctrl_gpio_direction_input(unsigned gpio);
@@ -31,7 +31,7 @@ extern void pinctrl_put(struct pinctrl *p); · 3 unmodified lines
3131 extern int pinctrl_enable(struct pinctrl *p);
3232 extern void pinctrl_disable(struct pinctrl *p);
3333
34−#else /* !CONFIG_PINMUX */
34+#else /* !CONFIG_PINCTRL */
3535
3636 static inline int pinctrl_request_gpio(unsigned gpio)
3737 {
@@ -70,7 +70,7 @@ static inline void pinctrl_disable(struct pinctrl *p) · 32 unmodified lines
7070 {
7171 }
7272
73−#endif /* CONFIG_PINMUX */
73+#endif /* CONFIG_PINCTRL */
7474
7575 #ifdef CONFIG_PINCONF
7676

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t