Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl: documentation update

Update the docs removing an obsolete __refdata tag and document
the mysterious return value of pin_free(). And fixes up some various
confusions in the pinctrl documentation.

Reported-by: Rajendra Nayak <rnayak@ti.com>
Reported-by: Randy Dunlap <rdunlap@xenotime.net>
Reported-by: Thomas Abraham <thomas.abraham@linaro.org>
Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

+35 -31
+30 -30
Documentation/pinctrl.txt
··· 32 32 be sparse - i.e. there may be gaps in the space with numbers where no 33 33 pin exists. 34 34 35 - When a PIN CONTROLLER is instatiated, it will register a descriptor to the 35 + When a PIN CONTROLLER is instantiated, it will register a descriptor to the 36 36 pin control framework, and this descriptor contains an array of pin descriptors 37 37 describing the pins handled by this specific pin controller. 38 38 ··· 61 61 62 62 #include <linux/pinctrl/pinctrl.h> 63 63 64 - const struct pinctrl_pin_desc __refdata foo_pins[] = { 65 - PINCTRL_PIN(0, "A1"), 66 - PINCTRL_PIN(1, "A2"), 67 - PINCTRL_PIN(2, "A3"), 64 + const struct pinctrl_pin_desc foo_pins[] = { 65 + PINCTRL_PIN(0, "A8"), 66 + PINCTRL_PIN(1, "B8"), 67 + PINCTRL_PIN(2, "C8"), 68 68 ... 69 - PINCTRL_PIN(61, "H6"), 70 - PINCTRL_PIN(62, "H7"), 71 - PINCTRL_PIN(63, "H8"), 69 + PINCTRL_PIN(61, "F1"), 70 + PINCTRL_PIN(62, "G1"), 71 + PINCTRL_PIN(63, "H1"), 72 72 }; 73 73 74 74 static struct pinctrl_desc foo_desc = { ··· 91 91 Pins usually have fancier names than this. You can find these in the dataheet 92 92 for your chip. Notice that the core pinctrl.h file provides a fancy macro 93 93 called PINCTRL_PIN() to create the struct entries. As you can see I enumerated 94 - the pins from 0 in the upper left corner to 63 in the lower right corner, 95 - this enumeration was arbitrarily chosen, in practice you need to think 94 + the pins from 0 in the upper left corner to 63 in the lower right corner. 95 + This enumeration was arbitrarily chosen, in practice you need to think 96 96 through your numbering system so that it matches the layout of registers 97 97 and such things in your driver, or the code may become complicated. You must 98 98 also consider matching of offsets to the GPIO ranges that may be handled by ··· 133 133 const unsigned num_pins; 134 134 }; 135 135 136 - static unsigned int spi0_pins[] = { 0, 8, 16, 24 }; 137 - static unsigned int i2c0_pins[] = { 24, 25 }; 136 + static const unsigned int spi0_pins[] = { 0, 8, 16, 24 }; 137 + static const unsigned int i2c0_pins[] = { 24, 25 }; 138 138 139 139 static const struct foo_group foo_groups[] = { 140 140 { ··· 242 242 chip b: [48 .. 55] 243 243 244 244 When GPIO-specific functions in the pin control subsystem are called, these 245 - ranges will be used to look up the apropriate pin controller by inspecting 245 + ranges will be used to look up the appropriate pin controller by inspecting 246 246 and matching the pin to the pin ranges across all controllers. When a 247 247 pin controller handling the matching range is found, GPIO-specific functions 248 248 will be called on that specific pin controller. ··· 438 438 439 439 Assumptions: 440 440 441 - We assume that the number possible function maps to pin groups is limited by 441 + We assume that the number of possible function maps to pin groups is limited by 442 442 the hardware. I.e. we assume that there is no system where any function can be 443 443 mapped to any pin, like in a phone exchange. So the available pins groups for 444 444 a certain function will be limited to a few choices (say up to eight or so), ··· 585 585 586 586 const char *foo_get_fname(struct pinctrl_dev *pctldev, unsigned selector) 587 587 { 588 - return myfuncs[selector].name; 588 + return foo_functions[selector].name; 589 589 } 590 590 591 591 static int foo_get_groups(struct pinctrl_dev *pctldev, unsigned selector, ··· 600 600 int foo_enable(struct pinctrl_dev *pctldev, unsigned selector, 601 601 unsigned group) 602 602 { 603 - u8 regbit = (1 << group); 603 + u8 regbit = (1 << selector + group); 604 604 605 605 writeb((readb(MUX)|regbit), MUX) 606 606 return 0; 607 607 } 608 608 609 - int foo_disable(struct pinctrl_dev *pctldev, unsigned selector, 609 + void foo_disable(struct pinctrl_dev *pctldev, unsigned selector, 610 610 unsigned group) 611 611 { 612 - u8 regbit = (1 << group); 612 + u8 regbit = (1 << selector + group); 613 613 614 614 writeb((readb(MUX) & ~(regbit)), MUX) 615 615 return 0; ··· 683 683 684 684 #include <linux/pinctrl/machine.h> 685 685 686 - static struct pinmux_map pmx_mapping[] = { 686 + static const struct pinmux_map pmx_mapping[] = { 687 687 { 688 688 .ctrl_dev_name = "pinctrl.0", 689 689 .function = "spi0", ··· 714 714 715 715 You register this pinmux mapping to the pinmux subsystem by simply: 716 716 717 - ret = pinmux_register_mappings(&pmx_mapping, ARRAY_SIZE(pmx_mapping)); 717 + ret = pinmux_register_mappings(pmx_mapping, ARRAY_SIZE(pmx_mapping)); 718 718 719 719 Since the above construct is pretty common there is a helper macro to make 720 720 it even more compact which assumes you want to use pinctrl.0 and position ··· 762 762 .name "2bit" 763 763 .ctrl_dev_name = "pinctrl.0", 764 764 .function = "mmc0", 765 - .group = "mmc0_0_grp", 766 - .dev_name = "foo-mmc.0", 767 - }, 768 - { 769 - .name "4bit" 770 - .ctrl_dev_name = "pinctrl.0", 771 - .function = "mmc0", 772 - .group = "mmc0_0_grp", 765 + .group = "mmc0_1_grp", 773 766 .dev_name = "foo-mmc.0", 774 767 }, 775 768 { ··· 773 780 .dev_name = "foo-mmc.0", 774 781 }, 775 782 { 776 - .name "8bit" 783 + .name "4bit" 777 784 .ctrl_dev_name = "pinctrl.0", 778 785 .function = "mmc0", 779 - .group = "mmc0_0_grp", 786 + .group = "mmc0_2_grp", 780 787 .dev_name = "foo-mmc.0", 781 788 }, 782 789 { ··· 791 798 .ctrl_dev_name = "pinctrl.0", 792 799 .function = "mmc0", 793 800 .group = "mmc0_2_grp", 801 + .dev_name = "foo-mmc.0", 802 + }, 803 + { 804 + .name "8bit" 805 + .ctrl_dev_name = "pinctrl.0", 806 + .function = "mmc0", 807 + .group = "mmc0_3_grp", 794 808 .dev_name = "foo-mmc.0", 795 809 }, 796 810 ...
+5 -1
drivers/pinctrl/pinmux.c
··· 174 174 * @pin: the pin to free 175 175 * @gpio_range: the range matching the GPIO pin if this is a request for a 176 176 * single GPIO pin 177 + * 178 + * This function returns a pointer to the function name in use. This is used 179 + * for callers that dynamically allocate a function name so it can be freed 180 + * once the pin is free. This is done for GPIO request functions. 177 181 */ 178 182 static const char *pin_free(struct pinctrl_dev *pctldev, int pin, 179 183 struct pinctrl_gpio_range *gpio_range) ··· 923 919 } 924 920 925 921 /** 926 - * pinmux_hog_maps() - unhog specific map entries on controller device 922 + * pinmux_unhog_maps() - unhog specific map entries on controller device 927 923 * @pctldev: the pin control device to unhog entries on 928 924 */ 929 925 void pinmux_unhog_maps(struct pinctrl_dev *pctldev)