summaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl
diff options
context:
space:
mode:
authorMika Westerberg <mika.westerberg@linux.intel.com>2017-01-23 07:34:34 -0500
committerLinus Walleij <linus.walleij@linaro.org>2017-01-26 09:27:37 -0500
commit2956b5d94a76b596fa5057c2b3ca915cb27d7652 (patch)
tree3a1dbce1201ef4923a4124f63eb209026e8fba7e /drivers/pinctrl
parent15381bc7c7f52d56f87c56dd7c948ad78704b852 (diff)
pinctrl / gpio: Introduce .set_config() callback for GPIO chips
Currently we already have two pin configuration related callbacks available for GPIO chips .set_single_ended() and .set_debounce(). In future we expect to have even more, which does not scale well if we need to add yet another callback to the GPIO chip structure for each possible configuration parameter. Better solution is to reuse what we already have available in the generic pinconf. To support this, we introduce a new .set_config() callback for GPIO chips. The callback takes a single packed pin configuration value as parameter. This can then be extended easily beyond what is currently supported by just adding new types to the generic pinconf enum. If the GPIO driver is backed up by a pinctrl driver the GPIO driver can just assign gpiochip_generic_config() (introduced in this patch) to .set_config and that will take care configuration requests are directed to the pinctrl driver. We then convert the existing drivers over .set_config() and finally remove the .set_single_ended() and .set_debounce() callbacks. Suggested-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl')
-rw-r--r--drivers/pinctrl/mediatek/pinctrl-mtk-common.c14
-rw-r--r--drivers/pinctrl/pinctrl-amd.c14
-rw-r--r--drivers/pinctrl/pinctrl-sx150x.c55
3 files changed, 41 insertions, 42 deletions
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
index f9aef2ac03a1..3cf384f8b122 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
@@ -1054,6 +1054,18 @@ static int mtk_gpio_set_debounce(struct gpio_chip *chip, unsigned offset,
1054 return 0; 1054 return 0;
1055} 1055}
1056 1056
1057static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned offset,
1058 unsigned long config)
1059{
1060 u32 debounce;
1061
1062 if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
1063 return -ENOTSUPP;
1064
1065 debounce = pinconf_to_config_argument(config);
1066 return mtk_gpio_set_debounce(chip, offset, debounce);
1067}
1068
1057static const struct gpio_chip mtk_gpio_chip = { 1069static const struct gpio_chip mtk_gpio_chip = {
1058 .owner = THIS_MODULE, 1070 .owner = THIS_MODULE,
1059 .request = gpiochip_generic_request, 1071 .request = gpiochip_generic_request,
@@ -1064,7 +1076,7 @@ static const struct gpio_chip mtk_gpio_chip = {
1064 .get = mtk_gpio_get, 1076 .get = mtk_gpio_get,
1065 .set = mtk_gpio_set, 1077 .set = mtk_gpio_set,
1066 .to_irq = mtk_gpio_to_irq, 1078 .to_irq = mtk_gpio_to_irq,
1067 .set_debounce = mtk_gpio_set_debounce, 1079 .set_config = mtk_gpio_set_config,
1068 .of_gpio_n_cells = 2, 1080 .of_gpio_n_cells = 2,
1069}; 1081};
1070 1082
diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
index aea310a91821..e440665ecc35 100644
--- a/drivers/pinctrl/pinctrl-amd.c
+++ b/drivers/pinctrl/pinctrl-amd.c
@@ -164,6 +164,18 @@ static int amd_gpio_set_debounce(struct gpio_chip *gc, unsigned offset,
164 return ret; 164 return ret;
165} 165}
166 166
167static int amd_gpio_set_config(struct gpio_chip *gc, unsigned offset,
168 unsigned long config)
169{
170 u32 debounce;
171
172 if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
173 return -ENOTSUPP;
174
175 debounce = pinconf_to_config_argument(config);
176 return amd_gpio_set_debounce(gc, offset, debounce);
177}
178
167#ifdef CONFIG_DEBUG_FS 179#ifdef CONFIG_DEBUG_FS
168static void amd_gpio_dbg_show(struct seq_file *s, struct gpio_chip *gc) 180static void amd_gpio_dbg_show(struct seq_file *s, struct gpio_chip *gc)
169{ 181{
@@ -761,7 +773,7 @@ static int amd_gpio_probe(struct platform_device *pdev)
761 gpio_dev->gc.direction_output = amd_gpio_direction_output; 773 gpio_dev->gc.direction_output = amd_gpio_direction_output;
762 gpio_dev->gc.get = amd_gpio_get_value; 774 gpio_dev->gc.get = amd_gpio_get_value;
763 gpio_dev->gc.set = amd_gpio_set_value; 775 gpio_dev->gc.set = amd_gpio_set_value;
764 gpio_dev->gc.set_debounce = amd_gpio_set_debounce; 776 gpio_dev->gc.set_config = amd_gpio_set_config;
765 gpio_dev->gc.dbg_show = amd_gpio_dbg_show; 777 gpio_dev->gc.dbg_show = amd_gpio_dbg_show;
766 778
767 gpio_dev->gc.base = 0; 779 gpio_dev->gc.base = 0;
diff --git a/drivers/pinctrl/pinctrl-sx150x.c b/drivers/pinctrl/pinctrl-sx150x.c
index 29fb7403d24e..7450f5118445 100644
--- a/drivers/pinctrl/pinctrl-sx150x.c
+++ b/drivers/pinctrl/pinctrl-sx150x.c
@@ -424,41 +424,6 @@ static int sx150x_gpio_get(struct gpio_chip *chip, unsigned int offset)
424 return !!(value & BIT(offset)); 424 return !!(value & BIT(offset));
425} 425}
426 426
427static int sx150x_gpio_set_single_ended(struct gpio_chip *chip,
428 unsigned int offset,
429 enum single_ended_mode mode)
430{
431 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
432 int ret;
433
434 switch (mode) {
435 case LINE_MODE_PUSH_PULL:
436 if (pctl->data->model != SX150X_789 ||
437 sx150x_pin_is_oscio(pctl, offset))
438 return 0;
439
440 ret = regmap_write_bits(pctl->regmap,
441 pctl->data->pri.x789.reg_drain,
442 BIT(offset), 0);
443 break;
444
445 case LINE_MODE_OPEN_DRAIN:
446 if (pctl->data->model != SX150X_789 ||
447 sx150x_pin_is_oscio(pctl, offset))
448 return -ENOTSUPP;
449
450 ret = regmap_write_bits(pctl->regmap,
451 pctl->data->pri.x789.reg_drain,
452 BIT(offset), BIT(offset));
453 break;
454 default:
455 ret = -ENOTSUPP;
456 break;
457 }
458
459 return ret;
460}
461
462static int __sx150x_gpio_set(struct sx150x_pinctrl *pctl, unsigned int offset, 427static int __sx150x_gpio_set(struct sx150x_pinctrl *pctl, unsigned int offset,
463 int value) 428 int value)
464{ 429{
@@ -811,16 +776,26 @@ static int sx150x_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
811 break; 776 break;
812 777
813 case PIN_CONFIG_DRIVE_OPEN_DRAIN: 778 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
814 ret = sx150x_gpio_set_single_ended(&pctl->gpio, 779 if (pctl->data->model != SX150X_789 ||
815 pin, LINE_MODE_OPEN_DRAIN); 780 sx150x_pin_is_oscio(pctl, pin))
781 return -ENOTSUPP;
782
783 ret = regmap_write_bits(pctl->regmap,
784 pctl->data->pri.x789.reg_drain,
785 BIT(pin), BIT(pin));
816 if (ret < 0) 786 if (ret < 0)
817 return ret; 787 return ret;
818 788
819 break; 789 break;
820 790
821 case PIN_CONFIG_DRIVE_PUSH_PULL: 791 case PIN_CONFIG_DRIVE_PUSH_PULL:
822 ret = sx150x_gpio_set_single_ended(&pctl->gpio, 792 if (pctl->data->model != SX150X_789 ||
823 pin, LINE_MODE_PUSH_PULL); 793 sx150x_pin_is_oscio(pctl, pin))
794 return 0;
795
796 ret = regmap_write_bits(pctl->regmap,
797 pctl->data->pri.x789.reg_drain,
798 BIT(pin), 0);
824 if (ret < 0) 799 if (ret < 0)
825 return ret; 800 return ret;
826 801
@@ -1178,7 +1153,7 @@ static int sx150x_probe(struct i2c_client *client,
1178 pctl->gpio.direction_output = sx150x_gpio_direction_output; 1153 pctl->gpio.direction_output = sx150x_gpio_direction_output;
1179 pctl->gpio.get = sx150x_gpio_get; 1154 pctl->gpio.get = sx150x_gpio_get;
1180 pctl->gpio.set = sx150x_gpio_set; 1155 pctl->gpio.set = sx150x_gpio_set;
1181 pctl->gpio.set_single_ended = sx150x_gpio_set_single_ended; 1156 pctl->gpio.set_config = gpiochip_generic_config;
1182 pctl->gpio.parent = dev; 1157 pctl->gpio.parent = dev;
1183#ifdef CONFIG_OF_GPIO 1158#ifdef CONFIG_OF_GPIO
1184 pctl->gpio.of_node = dev->of_node; 1159 pctl->gpio.of_node = dev->of_node;