Skip to content

Commit ae49581

Browse files
IoanaCiorneiBartosz Golaszewski
authored andcommitted
gpio: regmap: add the .fixed_direction_output configuration parameter
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 <[email protected]> Acked-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Michael Walle <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent d589613 commit ae49581

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)
@@ -284,6 +292,17 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
284292
goto err_free_gpio;
285293
}
286294

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

301320
ret = gpiochip_add_data(chip, gpio);
302321
if (ret < 0)
303-
goto err_free_gpio;
322+
goto err_free_bitmap;
304323

305324
#ifdef CONFIG_REGMAP_IRQ
306325
if (config->regmap_irq_chip) {
@@ -309,7 +328,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
309328
config->regmap_irq_line, config->regmap_irq_flags,
310329
0, config->regmap_irq_chip, &gpio->irq_chip_data);
311330
if (ret)
312-
goto err_free_gpio;
331+
goto err_free_bitmap;
313332

314333
irq_domain = regmap_irq_get_domain(gpio->irq_chip_data);
315334
} else
@@ -326,6 +345,8 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
326345

327346
err_remove_gpiochip:
328347
gpiochip_remove(chip);
348+
err_free_bitmap:
349+
bitmap_free(gpio->fixed_direction_output);
329350
err_free_gpio:
330351
kfree(gpio);
331352
return ERR_PTR(ret);
@@ -344,6 +365,7 @@ void gpio_regmap_unregister(struct gpio_regmap *gpio)
344365
#endif
345366

346367
gpiochip_remove(&gpio->gpio_chip);
368+
bitmap_free(gpio->fixed_direction_output);
347369
kfree(gpio);
348370
}
349371
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
@@ -38,6 +38,10 @@ struct regmap;
3838
* offset to a register/bitmask pair. If not
3939
* given the default gpio_regmap_simple_xlate()
4040
* is used.
41+
* @fixed_direction_output:
42+
* (Optional) Bitmap representing the fixed direction of
43+
* the GPIO lines. Useful when there are GPIO lines with a
44+
* fixed direction mixed together in the same register.
4145
* @drvdata: (Optional) Pointer to driver specific data which is
4246
* not used by gpio-remap but is provided "as is" to the
4347
* driver callback(s).
@@ -85,6 +89,7 @@ struct gpio_regmap_config {
8589
int reg_stride;
8690
int ngpio_per_reg;
8791
struct irq_domain *irq_domain;
92+
unsigned long *fixed_direction_output;
8893

8994
#ifdef CONFIG_REGMAP_IRQ
9095
struct regmap_irq_chip *regmap_irq_chip;

0 commit comments

Comments
 (0)