Skip to content

Commit ccd39d9

Browse files
IoanaCiorneigregkh
authored andcommitted
gpio: regmap: add the .fixed_direction_output configuration parameter
[ Upstream commit 00aaae6 ] There are GPIO controllers such as the one present in the LX2160ARDB QIXIS FPGA which have fixed-direction input and output GPIO lines mixed together in a single register. This cannot be modeled using the gpio-regmap as-is since there is no way to present the true direction of a GPIO line. In order to make this use case possible, add a new configuration parameter - fixed_direction_output - into the gpio_regmap_config structure. This will enable user drivers to provide a bitmap that represents the fixed direction of the GPIO lines. Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com> Acked-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Michael Walle <mwalle@kernel.org> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Stable-dep-of: 2ba5772 ("gpio: idio-16: Define fixed direction of the GPIO lines") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2325e44 commit ccd39d9

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

drivers/gpio/gpio-regmap.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct gpio_regmap {
3131
unsigned int reg_clr_base;
3232
unsigned int reg_dir_in_base;
3333
unsigned int reg_dir_out_base;
34+
unsigned long *fixed_direction_output;
3435

3536
#ifdef CONFIG_REGMAP_IRQ
3637
int regmap_irq_line;
@@ -134,6 +135,13 @@ static int gpio_regmap_get_direction(struct gpio_chip *chip,
134135
unsigned int base, val, reg, mask;
135136
int invert, ret;
136137

138+
if (gpio->fixed_direction_output) {
139+
if (test_bit(offset, gpio->fixed_direction_output))
140+
return GPIO_LINE_DIRECTION_OUT;
141+
else
142+
return GPIO_LINE_DIRECTION_IN;
143+
}
144+
137145
if (gpio->reg_dat_base && !gpio->reg_set_base)
138146
return GPIO_LINE_DIRECTION_IN;
139147
if (gpio->reg_set_base && !gpio->reg_dat_base)
@@ -283,6 +291,17 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
283291
goto err_free_gpio;
284292
}
285293

294+
if (config->fixed_direction_output) {
295+
gpio->fixed_direction_output = bitmap_alloc(chip->ngpio,
296+
GFP_KERNEL);
297+
if (!gpio->fixed_direction_output) {
298+
ret = -ENOMEM;
299+
goto err_free_gpio;
300+
}
301+
bitmap_copy(gpio->fixed_direction_output,
302+
config->fixed_direction_output, chip->ngpio);
303+
}
304+
286305
/* if not set, assume there is only one register */
287306
gpio->ngpio_per_reg = config->ngpio_per_reg;
288307
if (!gpio->ngpio_per_reg)
@@ -299,7 +318,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
299318

300319
ret = gpiochip_add_data(chip, gpio);
301320
if (ret < 0)
302-
goto err_free_gpio;
321+
goto err_free_bitmap;
303322

304323
#ifdef CONFIG_REGMAP_IRQ
305324
if (config->regmap_irq_chip) {
@@ -308,7 +327,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
308327
config->regmap_irq_line, config->regmap_irq_flags,
309328
0, config->regmap_irq_chip, &gpio->irq_chip_data);
310329
if (ret)
311-
goto err_free_gpio;
330+
goto err_free_bitmap;
312331

313332
irq_domain = regmap_irq_get_domain(gpio->irq_chip_data);
314333
} else
@@ -325,6 +344,8 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
325344

326345
err_remove_gpiochip:
327346
gpiochip_remove(chip);
347+
err_free_bitmap:
348+
bitmap_free(gpio->fixed_direction_output);
328349
err_free_gpio:
329350
kfree(gpio);
330351
return ERR_PTR(ret);
@@ -343,6 +364,7 @@ void gpio_regmap_unregister(struct gpio_regmap *gpio)
343364
#endif
344365

345366
gpiochip_remove(&gpio->gpio_chip);
367+
bitmap_free(gpio->fixed_direction_output);
346368
kfree(gpio);
347369
}
348370
EXPORT_SYMBOL_GPL(gpio_regmap_unregister);

include/linux/gpio/regmap.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ struct regmap;
3737
* offset to a register/bitmask pair. If not
3838
* given the default gpio_regmap_simple_xlate()
3939
* is used.
40+
* @fixed_direction_output:
41+
* (Optional) Bitmap representing the fixed direction of
42+
* the GPIO lines. Useful when there are GPIO lines with a
43+
* fixed direction mixed together in the same register.
4044
* @drvdata: (Optional) Pointer to driver specific data which is
4145
* not used by gpio-remap but is provided "as is" to the
4246
* driver callback(s).
@@ -82,6 +86,7 @@ struct gpio_regmap_config {
8286
int reg_stride;
8387
int ngpio_per_reg;
8488
struct irq_domain *irq_domain;
89+
unsigned long *fixed_direction_output;
8590

8691
#ifdef CONFIG_REGMAP_IRQ
8792
struct regmap_irq_chip *regmap_irq_chip;

0 commit comments

Comments
 (0)