Skip to content

Commit 2956b5d

Browse files
westeriLinus Walleij
authored andcommitted
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>
1 parent 15381bc commit 2956b5d

26 files changed

Lines changed: 297 additions & 218 deletions

‎Documentation/gpio/driver.txt‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ a pull-up resistor is needed on the outgoing rail to complete the circuit, and
146146
in the second case, a pull-down resistor is needed on the rail.
147147

148148
Hardware that supports open drain or open source or both, can implement a
149-
special callback in the gpio_chip: .set_single_ended() that takes an enum flag
150-
telling whether to configure the line as open drain, open source or push-pull.
151-
This will happen in response to the GPIO_OPEN_DRAIN or GPIO_OPEN_SOURCE flag
152-
set in the machine file, or coming from other hardware descriptions.
149+
special callback in the gpio_chip: .set_config() that takes a generic
150+
pinconf packed value telling whether to configure the line as open drain,
151+
open source or push-pull. This will happen in response to the
152+
GPIO_OPEN_DRAIN or GPIO_OPEN_SOURCE flag set in the machine file, or coming
153+
from other hardware descriptions.
153154

154155
If this state can not be configured in hardware, i.e. if the GPIO hardware does
155156
not support open drain/open source in hardware, the GPIO library will instead

‎drivers/gpio/gpio-bcm-kona.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,18 @@ static int bcm_kona_gpio_set_debounce(struct gpio_chip *chip, unsigned gpio,
308308
return 0;
309309
}
310310

311+
static int bcm_kona_gpio_set_config(struct gpio_chip *chip, unsigned gpio,
312+
unsigned long config)
313+
{
314+
u32 debounce;
315+
316+
if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
317+
return -ENOTSUPP;
318+
319+
debounce = pinconf_to_config_argument(config);
320+
return bcm_kona_gpio_set_debounce(chip, gpio, debounce);
321+
}
322+
311323
static const struct gpio_chip template_chip = {
312324
.label = "bcm-kona-gpio",
313325
.owner = THIS_MODULE,
@@ -318,7 +330,7 @@ static const struct gpio_chip template_chip = {
318330
.get = bcm_kona_gpio_get,
319331
.direction_output = bcm_kona_gpio_direction_output,
320332
.set = bcm_kona_gpio_set,
321-
.set_debounce = bcm_kona_gpio_set_debounce,
333+
.set_config = bcm_kona_gpio_set_config,
322334
.to_irq = bcm_kona_gpio_to_irq,
323335
.base = 0,
324336
};

‎drivers/gpio/gpio-dln2.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,16 @@ static int dln2_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
272272
return dln2_gpio_set_direction(chip, offset, DLN2_GPIO_DIRECTION_OUT);
273273
}
274274

275-
static int dln2_gpio_set_debounce(struct gpio_chip *chip, unsigned offset,
276-
unsigned debounce)
275+
static int dln2_gpio_set_config(struct gpio_chip *chip, unsigned offset,
276+
unsigned long config)
277277
{
278278
struct dln2_gpio *dln2 = gpiochip_get_data(chip);
279-
__le32 duration = cpu_to_le32(debounce);
279+
__le32 duration;
280280

281+
if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
282+
return -ENOTSUPP;
283+
284+
duration = cpu_to_le32(pinconf_to_config_argument(config));
281285
return dln2_transfer_tx(dln2->pdev, DLN2_GPIO_SET_DEBOUNCE,
282286
&duration, sizeof(duration));
283287
}
@@ -474,7 +478,7 @@ static int dln2_gpio_probe(struct platform_device *pdev)
474478
dln2->gpio.get_direction = dln2_gpio_get_direction;
475479
dln2->gpio.direction_input = dln2_gpio_direction_input;
476480
dln2->gpio.direction_output = dln2_gpio_direction_output;
477-
dln2->gpio.set_debounce = dln2_gpio_set_debounce;
481+
dln2->gpio.set_config = dln2_gpio_set_config;
478482

479483
platform_set_drvdata(pdev, dln2);
480484

‎drivers/gpio/gpio-dwapb.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,18 @@ static int dwapb_gpio_set_debounce(struct gpio_chip *gc,
279279
return 0;
280280
}
281281

282+
static int dwapb_gpio_set_config(struct gpio_chip *gc, unsigned offset,
283+
unsigned long config)
284+
{
285+
u32 debounce;
286+
287+
if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
288+
return -ENOTSUPP;
289+
290+
debounce = pinconf_to_config_argument(config);
291+
return dwapb_gpio_set_debounce(gc, offset, debounce);
292+
}
293+
282294
static irqreturn_t dwapb_irq_handler_mfd(int irq, void *dev_id)
283295
{
284296
u32 worked;
@@ -426,7 +438,7 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
426438

427439
/* Only port A support debounce */
428440
if (pp->idx == 0)
429-
port->gc.set_debounce = dwapb_gpio_set_debounce;
441+
port->gc.set_config = dwapb_gpio_set_config;
430442

431443
if (pp->irq)
432444
dwapb_configure_irqs(gpio, port, pp);

‎drivers/gpio/gpio-ep93xx.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,20 @@ static struct ep93xx_gpio_bank ep93xx_gpio_banks[] = {
291291
EP93XX_GPIO_BANK("H", 0x40, 0x44, 56, false),
292292
};
293293

294-
static int ep93xx_gpio_set_debounce(struct gpio_chip *chip,
295-
unsigned offset, unsigned debounce)
294+
static int ep93xx_gpio_set_config(struct gpio_chip *chip, unsigned offset,
295+
unsigned long config)
296296
{
297297
int gpio = chip->base + offset;
298298
int irq = gpio_to_irq(gpio);
299+
u32 debounce;
300+
301+
if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
302+
return -ENOTSUPP;
299303

300304
if (irq < 0)
301305
return -EINVAL;
302306

307+
debounce = pinconf_to_config_argument(config);
303308
ep93xx_gpio_int_debounce(irq, debounce ? true : false);
304309

305310
return 0;
@@ -335,7 +340,7 @@ static int ep93xx_gpio_add_bank(struct gpio_chip *gc, struct device *dev,
335340
gc->base = bank->base;
336341

337342
if (bank->has_debounce) {
338-
gc->set_debounce = ep93xx_gpio_set_debounce;
343+
gc->set_config = ep93xx_gpio_set_config;
339344
gc->to_irq = ep93xx_gpio_to_irq;
340345
}
341346

‎drivers/gpio/gpio-f7188x.c‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ static int f7188x_gpio_get(struct gpio_chip *chip, unsigned offset);
131131
static int f7188x_gpio_direction_out(struct gpio_chip *chip,
132132
unsigned offset, int value);
133133
static void f7188x_gpio_set(struct gpio_chip *chip, unsigned offset, int value);
134-
static int f7188x_gpio_set_single_ended(struct gpio_chip *gc,
135-
unsigned offset,
136-
enum single_ended_mode mode);
134+
static int f7188x_gpio_set_config(struct gpio_chip *chip, unsigned offset,
135+
unsigned long config);
137136

138137
#define F7188X_GPIO_BANK(_base, _ngpio, _regbase) \
139138
{ \
@@ -145,7 +144,7 @@ static int f7188x_gpio_set_single_ended(struct gpio_chip *gc,
145144
.get = f7188x_gpio_get, \
146145
.direction_output = f7188x_gpio_direction_out, \
147146
.set = f7188x_gpio_set, \
148-
.set_single_ended = f7188x_gpio_set_single_ended, \
147+
.set_config = f7188x_gpio_set_config, \
149148
.base = _base, \
150149
.ngpio = _ngpio, \
151150
.can_sleep = true, \
@@ -326,17 +325,17 @@ static void f7188x_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
326325
superio_exit(sio->addr);
327326
}
328327

329-
static int f7188x_gpio_set_single_ended(struct gpio_chip *chip,
330-
unsigned offset,
331-
enum single_ended_mode mode)
328+
static int f7188x_gpio_set_config(struct gpio_chip *chip, unsigned offset,
329+
unsigned long config)
332330
{
333331
int err;
332+
enum pin_config_param param = pinconf_to_config_param(config);
334333
struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
335334
struct f7188x_sio *sio = bank->data->sio;
336335
u8 data;
337336

338-
if (mode != LINE_MODE_OPEN_DRAIN &&
339-
mode != LINE_MODE_PUSH_PULL)
337+
if (param != PIN_CONFIG_DRIVE_OPEN_DRAIN &&
338+
param != PIN_CONFIG_DRIVE_PUSH_PULL)
340339
return -ENOTSUPP;
341340

342341
err = superio_enter(sio->addr);
@@ -345,7 +344,7 @@ static int f7188x_gpio_set_single_ended(struct gpio_chip *chip,
345344
superio_select(sio->addr, SIO_LD_GPIO);
346345

347346
data = superio_inb(sio->addr, gpio_out_mode(bank->regbase));
348-
if (mode == LINE_MODE_OPEN_DRAIN)
347+
if (param == PIN_CONFIG_DRIVE_OPEN_DRAIN)
349348
data &= ~BIT(offset);
350349
else
351350
data |= BIT(offset);

‎drivers/gpio/gpio-lp873x.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,21 @@ static int lp873x_gpio_request(struct gpio_chip *gc, unsigned int offset)
100100
return 0;
101101
}
102102

103-
static int lp873x_gpio_set_single_ended(struct gpio_chip *gc,
104-
unsigned int offset,
105-
enum single_ended_mode mode)
103+
static int lp873x_gpio_set_config(struct gpio_chip *gc, unsigned offset,
104+
unsigned long config)
106105
{
107106
struct lp873x_gpio *gpio = gpiochip_get_data(gc);
108107

109-
switch (mode) {
110-
case LINE_MODE_OPEN_DRAIN:
108+
switch (pinconf_to_config_param(config)) {
109+
case PIN_CONFIG_DRIVE_OPEN_DRAIN:
111110
return regmap_update_bits(gpio->lp873->regmap,
112111
LP873X_REG_GPO_CTRL,
113112
BIT(offset * BITS_PER_GPO +
114113
LP873X_GPO_CTRL_OD),
115114
BIT(offset * BITS_PER_GPO +
116115
LP873X_GPO_CTRL_OD));
117-
case LINE_MODE_PUSH_PULL:
116+
117+
case PIN_CONFIG_DRIVE_PUSH_PULL:
118118
return regmap_update_bits(gpio->lp873->regmap,
119119
LP873X_REG_GPO_CTRL,
120120
BIT(offset * BITS_PER_GPO +
@@ -133,7 +133,7 @@ static const struct gpio_chip template_chip = {
133133
.direction_output = lp873x_gpio_direction_output,
134134
.get = lp873x_gpio_get,
135135
.set = lp873x_gpio_set,
136-
.set_single_ended = lp873x_gpio_set_single_ended,
136+
.set_config = lp873x_gpio_set_config,
137137
.base = -1,
138138
.ngpio = 2,
139139
.can_sleep = true,

‎drivers/gpio/gpio-max77620.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,10 @@ static int max77620_gpio_dir_output(struct gpio_chip *gc, unsigned int offset,
152152
return ret;
153153
}
154154

155-
static int max77620_gpio_set_debounce(struct gpio_chip *gc,
155+
static int max77620_gpio_set_debounce(struct max77620_gpio *mgpio,
156156
unsigned int offset,
157157
unsigned int debounce)
158158
{
159-
struct max77620_gpio *mgpio = gpiochip_get_data(gc);
160159
u8 val;
161160
int ret;
162161

@@ -202,21 +201,23 @@ static void max77620_gpio_set(struct gpio_chip *gc, unsigned int offset,
202201
dev_err(mgpio->dev, "CNFG_GPIO_OUT update failed: %d\n", ret);
203202
}
204203

205-
static int max77620_gpio_set_single_ended(struct gpio_chip *gc,
206-
unsigned int offset,
207-
enum single_ended_mode mode)
204+
static int max77620_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
205+
unsigned long config)
208206
{
209207
struct max77620_gpio *mgpio = gpiochip_get_data(gc);
210208

211-
switch (mode) {
212-
case LINE_MODE_OPEN_DRAIN:
209+
switch (pinconf_to_config_param(config)) {
210+
case PIN_CONFIG_DRIVE_OPEN_DRAIN:
213211
return regmap_update_bits(mgpio->rmap, GPIO_REG_ADDR(offset),
214212
MAX77620_CNFG_GPIO_DRV_MASK,
215213
MAX77620_CNFG_GPIO_DRV_OPENDRAIN);
216-
case LINE_MODE_PUSH_PULL:
214+
case PIN_CONFIG_DRIVE_PUSH_PULL:
217215
return regmap_update_bits(mgpio->rmap, GPIO_REG_ADDR(offset),
218216
MAX77620_CNFG_GPIO_DRV_MASK,
219217
MAX77620_CNFG_GPIO_DRV_PUSHPULL);
218+
case PIN_CONFIG_INPUT_DEBOUNCE:
219+
return max77620_gpio_set_debounce(mgpio, offset,
220+
pinconf_to_config_argument(config));
220221
default:
221222
break;
222223
}
@@ -257,9 +258,8 @@ static int max77620_gpio_probe(struct platform_device *pdev)
257258
mgpio->gpio_chip.direction_input = max77620_gpio_dir_input;
258259
mgpio->gpio_chip.get = max77620_gpio_get;
259260
mgpio->gpio_chip.direction_output = max77620_gpio_dir_output;
260-
mgpio->gpio_chip.set_debounce = max77620_gpio_set_debounce;
261261
mgpio->gpio_chip.set = max77620_gpio_set;
262-
mgpio->gpio_chip.set_single_ended = max77620_gpio_set_single_ended;
262+
mgpio->gpio_chip.set_config = max77620_gpio_set_config;
263263
mgpio->gpio_chip.to_irq = max77620_gpio_to_irq;
264264
mgpio->gpio_chip.ngpio = MAX77620_GPIO_NR;
265265
mgpio->gpio_chip.can_sleep = 1;

‎drivers/gpio/gpio-menz127.c‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,18 @@ static int men_z127_debounce(struct gpio_chip *gc, unsigned gpio,
8989

9090
static int men_z127_set_single_ended(struct gpio_chip *gc,
9191
unsigned offset,
92-
enum single_ended_mode mode)
92+
enum pin_config_param param)
9393
{
9494
struct men_z127_gpio *priv = gpiochip_get_data(gc);
9595
u32 od_en;
9696

97-
if (mode != LINE_MODE_OPEN_DRAIN &&
98-
mode != LINE_MODE_PUSH_PULL)
99-
return -ENOTSUPP;
100-
10197
spin_lock(&gc->bgpio_lock);
10298
od_en = readl(priv->reg_base + MEN_Z127_ODER);
10399

104-
if (mode == LINE_MODE_OPEN_DRAIN)
100+
if (param == PIN_CONFIG_DRIVE_OPEN_DRAIN)
105101
od_en |= BIT(offset);
106102
else
107-
/* Implicitly LINE_MODE_PUSH_PULL */
103+
/* Implicitly PIN_CONFIG_DRIVE_PUSH_PULL */
108104
od_en &= ~BIT(offset);
109105

110106
writel(od_en, priv->reg_base + MEN_Z127_ODER);
@@ -113,6 +109,27 @@ static int men_z127_set_single_ended(struct gpio_chip *gc,
113109
return 0;
114110
}
115111

112+
static int men_z127_set_config(struct gpio_chip *gc, unsigned offset,
113+
unsigned long config)
114+
{
115+
enum pin_config_param param = pinconf_to_config_param(config);
116+
117+
switch (param) {
118+
case PIN_CONFIG_DRIVE_OPEN_DRAIN:
119+
case PIN_CONFIG_DRIVE_PUSH_PULL:
120+
return men_z127_set_single_ended(gc, offset, param);
121+
122+
case PIN_CONFIG_INPUT_DEBOUNCE:
123+
return men_z127_debounce(gc, offset,
124+
pinconf_to_config_argument(config));
125+
126+
default:
127+
break;
128+
}
129+
130+
return -ENOTSUPP;
131+
}
132+
116133
static int men_z127_probe(struct mcb_device *mdev,
117134
const struct mcb_device_id *id)
118135
{
@@ -149,8 +166,7 @@ static int men_z127_probe(struct mcb_device *mdev,
149166
if (ret)
150167
goto err_unmap;
151168

152-
men_z127_gpio->gc.set_debounce = men_z127_debounce;
153-
men_z127_gpio->gc.set_single_ended = men_z127_set_single_ended;
169+
men_z127_gpio->gc.set_config = men_z127_set_config;
154170

155171
ret = gpiochip_add_data(&men_z127_gpio->gc, men_z127_gpio);
156172
if (ret) {

‎drivers/gpio/gpio-merrifield.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@ static int mrfld_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset,
190190
return 0;
191191
}
192192

193+
static int mrfld_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
194+
unsigned long config)
195+
{
196+
u32 debounce;
197+
198+
if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
199+
return -ENOTSUPP;
200+
201+
debounce = pinconf_to_config_argument(config);
202+
return mrfld_gpio_set_debounce(chip, offset, debounce);
203+
}
204+
193205
static void mrfld_irq_ack(struct irq_data *d)
194206
{
195207
struct mrfld_gpio *priv = irq_data_get_irq_chip_data(d);
@@ -414,7 +426,7 @@ static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *id
414426
priv->chip.get = mrfld_gpio_get;
415427
priv->chip.set = mrfld_gpio_set;
416428
priv->chip.get_direction = mrfld_gpio_get_direction;
417-
priv->chip.set_debounce = mrfld_gpio_set_debounce;
429+
priv->chip.set_config = mrfld_gpio_set_config;
418430
priv->chip.base = gpio_base;
419431
priv->chip.ngpio = MRFLD_NGPIO;
420432
priv->chip.can_sleep = false;

0 commit comments

Comments
 (0)