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

pinctrl: support pinconfig on the U300

This adds pin configuration support for the U300 driver pair,
we can now read out the biasing and drive mode in debugfs and
configure it using the new configuration API.

ChangeLog v1->v2:
- Migrate to pin config and generic pin config changes.
ChangeLog v2->v3:
- Adjust to generic pin config changes in v7 patch set.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

+135 -8
+1
drivers/pinctrl/Kconfig
··· 73 73 bool "U300 pin controller driver" 74 74 depends on ARCH_U300 75 75 select PINMUX 76 + select GENERIC_PINCONF 76 77 77 78 config PINCTRL_COH901 78 79 bool "ST-Ericsson U300 COH 901 335/571 GPIO"
+69 -8
drivers/pinctrl/pinctrl-coh901.c
··· 23 23 #include <linux/list.h> 24 24 #include <linux/slab.h> 25 25 #include <linux/pinctrl/consumer.h> 26 + #include <linux/pinctrl/pinconf-generic.h> 26 27 #include <mach/gpio-u300.h> 28 + #include "pinctrl-coh901.h" 27 29 28 30 /* 29 31 * Register definitions for COH 901 335 variant ··· 420 418 return retirq; 421 419 } 422 420 423 - static int u300_gpio_config(struct gpio_chip *chip, unsigned offset, 424 - enum pin_config_param param, unsigned long data) 421 + /* Returning -EINVAL means "supported but not available" */ 422 + int u300_gpio_config_get(struct gpio_chip *chip, 423 + unsigned offset, 424 + unsigned long *config) 425 + { 426 + struct u300_gpio *gpio = to_u300_gpio(chip); 427 + enum pin_config_param param = (enum pin_config_param) *config; 428 + bool biasmode; 429 + u32 drmode; 430 + 431 + /* One bit per pin, clamp to bool range */ 432 + biasmode = !!(readl(U300_PIN_REG(offset, per)) & U300_PIN_BIT(offset)); 433 + 434 + /* Mask out the two bits for this pin and shift to bits 0,1 */ 435 + drmode = readl(U300_PIN_REG(offset, pcr)); 436 + drmode &= (U300_GPIO_PXPCR_PIN_MODE_MASK << ((offset & 0x07) << 1)); 437 + drmode >>= ((offset & 0x07) << 1); 438 + 439 + switch(param) { 440 + case PIN_CONFIG_BIAS_HIGH_IMPEDANCE: 441 + *config = 0; 442 + if (biasmode) 443 + return 0; 444 + else 445 + return -EINVAL; 446 + break; 447 + case PIN_CONFIG_BIAS_PULL_UP: 448 + *config = 0; 449 + if (!biasmode) 450 + return 0; 451 + else 452 + return -EINVAL; 453 + break; 454 + case PIN_CONFIG_DRIVE_PUSH_PULL: 455 + *config = 0; 456 + if (drmode == U300_GPIO_PXPCR_PIN_MODE_OUTPUT_PUSH_PULL) 457 + return 0; 458 + else 459 + return -EINVAL; 460 + break; 461 + case PIN_CONFIG_DRIVE_OPEN_DRAIN: 462 + *config = 0; 463 + if (drmode == U300_GPIO_PXPCR_PIN_MODE_OUTPUT_OPEN_DRAIN) 464 + return 0; 465 + else 466 + return -EINVAL; 467 + break; 468 + case PIN_CONFIG_DRIVE_OPEN_SOURCE: 469 + *config = 0; 470 + if (drmode == U300_GPIO_PXPCR_PIN_MODE_OUTPUT_OPEN_SOURCE) 471 + return 0; 472 + else 473 + return -EINVAL; 474 + break; 475 + default: 476 + break; 477 + } 478 + return -ENOTSUPP; 479 + } 480 + 481 + int u300_gpio_config_set(struct gpio_chip *chip, unsigned offset, 482 + enum pin_config_param param) 425 483 { 426 484 struct u300_gpio *gpio = to_u300_gpio(chip); 427 485 unsigned long flags; ··· 682 620 u300_gpio_direction_output(&gpio->chip, offset, conf->outval); 683 621 684 622 /* Deactivate bias mode for output */ 685 - u300_gpio_config(&gpio->chip, offset, 686 - PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 687 - 0); 623 + u300_gpio_config_set(&gpio->chip, offset, 624 + PIN_CONFIG_BIAS_HIGH_IMPEDANCE); 688 625 689 626 /* Set drive mode for output */ 690 - u300_gpio_config(&gpio->chip, offset, 691 - PIN_CONFIG_DRIVE_PUSH_PULL, 0); 627 + u300_gpio_config_set(&gpio->chip, offset, 628 + PIN_CONFIG_DRIVE_PUSH_PULL); 692 629 693 630 dev_dbg(gpio->dev, "set up pin %d as output, value: %d\n", 694 631 offset, conf->outval); ··· 698 637 u300_gpio_set(&gpio->chip, offset, 0); 699 638 700 639 /* Set bias mode for input */ 701 - u300_gpio_config(&gpio->chip, offset, conf->bias_mode, 0); 640 + u300_gpio_config_set(&gpio->chip, offset, conf->bias_mode); 702 641 703 642 dev_dbg(gpio->dev, "set up pin %d as input, bias: %04x\n", 704 643 offset, conf->bias_mode);
+5
drivers/pinctrl/pinctrl-coh901.h
··· 1 + int u300_gpio_config_get(struct gpio_chip *chip, 2 + unsigned offset, 3 + unsigned long *config); 4 + int u300_gpio_config_set(struct gpio_chip *chip, unsigned offset, 5 + enum pin_config_param param);
+60
drivers/pinctrl/pinctrl-u300.c
··· 19 19 #include <linux/err.h> 20 20 #include <linux/pinctrl/pinctrl.h> 21 21 #include <linux/pinctrl/pinmux.h> 22 + #include <linux/pinctrl/pinconf.h> 23 + #include <linux/pinctrl/pinconf-generic.h> 24 + #include "pinctrl-coh901.h" 22 25 23 26 /* 24 27 * Register definitions for the U300 Padmux control registers in the ··· 1047 1044 U300_GPIO_RANGE(25, 181, 1), 1048 1045 }; 1049 1046 1047 + static struct pinctrl_gpio_range *u300_match_gpio_range(unsigned pin) 1048 + { 1049 + int i; 1050 + 1051 + for (i = 0; i < ARRAY_SIZE(u300_gpio_ranges); i++) { 1052 + struct pinctrl_gpio_range *range; 1053 + 1054 + range = &u300_gpio_ranges[i]; 1055 + if (pin >= range->pin_base && 1056 + pin <= (range->pin_base + range->npins - 1)) 1057 + return range; 1058 + } 1059 + return NULL; 1060 + } 1061 + 1062 + int u300_pin_config_get(struct pinctrl_dev *pctldev, 1063 + unsigned pin, 1064 + unsigned long *config) 1065 + { 1066 + struct pinctrl_gpio_range *range = u300_match_gpio_range(pin); 1067 + 1068 + /* We get config for those pins we CAN get it for and that's it */ 1069 + if (!range) 1070 + return -ENOTSUPP; 1071 + 1072 + return u300_gpio_config_get(range->gc, 1073 + (pin - range->pin_base + range->base), 1074 + config); 1075 + } 1076 + 1077 + int u300_pin_config_set(struct pinctrl_dev *pctldev, 1078 + unsigned pin, 1079 + unsigned long config) 1080 + { 1081 + struct pinctrl_gpio_range *range = u300_match_gpio_range(pin); 1082 + int ret; 1083 + 1084 + if (!range) 1085 + return -EINVAL; 1086 + 1087 + /* Note: none of these configurations take any argument */ 1088 + ret = u300_gpio_config_set(range->gc, 1089 + (pin - range->pin_base + range->base), 1090 + pinconf_to_config_param(config)); 1091 + if (ret) 1092 + return ret; 1093 + 1094 + return 0; 1095 + } 1096 + 1097 + static struct pinconf_ops u300_pconf_ops = { 1098 + .is_generic = true, 1099 + .pin_config_get = u300_pin_config_get, 1100 + .pin_config_set = u300_pin_config_set, 1101 + }; 1102 + 1050 1103 static struct pinctrl_desc u300_pmx_desc = { 1051 1104 .name = DRIVER_NAME, 1052 1105 .pins = u300_pads, 1053 1106 .npins = ARRAY_SIZE(u300_pads), 1054 1107 .pctlops = &u300_pctrl_ops, 1055 1108 .pmxops = &u300_pmx_ops, 1109 + .confops = &u300_pconf_ops, 1056 1110 .owner = THIS_MODULE, 1057 1111 }; 1058 1112