Skip to content

Commit 0537e52

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 <[email protected]> Acked-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Michael Walle <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]> Stable-dep-of: 2ba5772 ("gpio: idio-16: Define fixed direction of the GPIO lines") Signed-off-by: William Breathitt Gray <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 512c193 commit 0537e52

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
@@ -29,6 +29,7 @@ struct gpio_regmap {
2929
unsigned int reg_clr_base;
3030
unsigned int reg_dir_in_base;
3131
unsigned int reg_dir_out_base;
32+
unsigned long *fixed_direction_output;
3233

3334
#ifdef CONFIG_REGMAP_IRQ
3435
int regmap_irq_line;
@@ -122,6 +123,13 @@ static int gpio_regmap_get_direction(struct gpio_chip *chip,
122123
unsigned int base, val, reg, mask;
123124
int invert, ret;
124125

126+
if (gpio->fixed_direction_output) {
127+
if (test_bit(offset, gpio->fixed_direction_output))
128+
return GPIO_LINE_DIRECTION_OUT;
129+
else
130+
return GPIO_LINE_DIRECTION_IN;
131+
}
132+
125133
if (gpio->reg_dat_base && !gpio->reg_set_base)
126134
return GPIO_LINE_DIRECTION_IN;
127135
if (gpio->reg_set_base && !gpio->reg_dat_base)
@@ -280,9 +288,20 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
280288
chip->direction_output = gpio_regmap_direction_output;
281289
}
282290

291+
if (config->fixed_direction_output) {
292+
gpio->fixed_direction_output = bitmap_alloc(chip->ngpio,
293+
GFP_KERNEL);
294+
if (!gpio->fixed_direction_output) {
295+
ret = -ENOMEM;
296+
goto err_free_gpio;
297+
}
298+
bitmap_copy(gpio->fixed_direction_output,
299+
config->fixed_direction_output, chip->ngpio);
300+
}
301+
283302
ret = gpiochip_add_data(chip, gpio);
284303
if (ret < 0)
285-
goto err_free_gpio;
304+
goto err_free_bitmap;
286305

287306
#ifdef CONFIG_REGMAP_IRQ
288307
if (config->regmap_irq_chip) {
@@ -291,7 +310,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
291310
config->regmap_irq_line, config->regmap_irq_flags,
292311
0, config->regmap_irq_chip, &gpio->irq_chip_data);
293312
if (ret)
294-
goto err_free_gpio;
313+
goto err_free_bitmap;
295314

296315
irq_domain = regmap_irq_get_domain(gpio->irq_chip_data);
297316
} else
@@ -308,6 +327,8 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
308327

309328
err_remove_gpiochip:
310329
gpiochip_remove(chip);
330+
err_free_bitmap:
331+
bitmap_free(gpio->fixed_direction_output);
311332
err_free_gpio:
312333
kfree(gpio);
313334
return ERR_PTR(ret);
@@ -326,6 +347,7 @@ void gpio_regmap_unregister(struct gpio_regmap *gpio)
326347
#endif
327348

328349
gpiochip_remove(&gpio->gpio_chip);
350+
bitmap_free(gpio->fixed_direction_output);
329351
kfree(gpio);
330352
}
331353
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)