Hi,
As Linus suggested you could have a look at devm_gpio_regmap_register()
with a custom xlate() callback and some improvements. But I've never
worked with pinctrl so I might be wrong. See below.
+static int axp192_gpio_get(struct gpio_chip *chip, unsigned int
offset)
+{
+ struct axp192_pctl *pctl = gpiochip_get_data(chip);
+ const struct axp192_pctl_reg_info *reginfo =
&pctl->desc->in_regs[offset];
+ unsigned int val;
+ int ret;
+
+ ret = regmap_read(pctl->regmap, reginfo->reg, &val);
+ if (ret)
+ return ret;
+
+ return !!(val & reginfo->mask);
+}
This should work.
+
+static int axp192_gpio_get_direction(struct gpio_chip *chip, unsigned
int offset)
+{
+ struct axp192_pctl *pctl = gpiochip_get_data(chip);
+ const struct axp192_pctl_reg_info *reginfo =
&pctl->desc->ctrl_regs[offset];
+ const u8 *input_muxvals =
pctl->desc->functions[AXP192_FUNC_INPUT].muxvals;
+ unsigned int val;
+ int ret;
+
+ ret = regmap_read(pctl->regmap, reginfo->reg, &val);
+ if (ret)
+ return ret;
+
+ if ((val & reginfo->mask) == (input_muxvals[offset] <<
(ffs(reginfo->mask) - 1)))
+ return GPIO_LINE_DIRECTION_IN;
This isn't supported (yet) in gpio-regmap...
+
+ return GPIO_LINE_DIRECTION_OUT;
+}
+
+static void axp192_gpio_set(struct gpio_chip *chip, unsigned int
offset, int value)
+{
+ struct axp192_pctl *pctl = gpiochip_get_data(chip);
+ const struct axp192_pctl_reg_info *reginfo =
&pctl->desc->out_regs[offset];
+
+ regmap_update_bits(pctl->regmap, reginfo->reg, reginfo->mask, value
? reginfo->mask : 0);
+}
+
+static int axp192_gpio_direction_input(struct gpio_chip *chip,
unsigned int offset)
+{
+ return pinctrl_gpio_direction_input(chip->base + offset);
+}
..as well as this.
+
+static int axp192_gpio_direction_output(struct gpio_chip *chip,
unsigned int offset, int value)
+{
+ chip->set(chip, offset, value);
Why don't you call pinctrl_gpio_direction_output() here?
I *think* what is needed for gpio-regmap to support this is:
- support values and masks for the direction, for now, we
only support single bits.
- support the pinctrl_gpio_direction_{input,output} calls
-michael