+static int ad7173_mask_xlate(struct gpio_regmap *gpio, unsigned int base,
+ unsigned int offset, unsigned int *reg,
+ unsigned int *mask)
+{
+ *mask = AD7173_GPO_DATA(offset);
+ *reg = AD7173_REG_GPIO;
+ return 0;
+}
+
+static int ad7173_gpio_init(struct iio_dev *indio_dev)
+{
+ struct ad7173_state *st = iio_priv(indio_dev);
+ struct gpio_regmap_config gpio_regmap = {};
+ struct device *dev = &st->sd.spi->dev;
+ unsigned int mask;
+
+ st->regmap = devm_regmap_init_spi(st->sd.spi, &ad7173_regmap_config);
+ if (IS_ERR(st->regmap)) {
+ return dev_err_probe(dev, PTR_ERR(st->regmap),
+ "Unable to init regmap\n");
+ }
+
+ mask = AD7173_GPIO_OP_EN0 | AD7173_GPIO_OP_EN1 | AD7173_GPIO_OP_EN2_3;
+ regmap_update_bits(st->regmap, AD7173_REG_GPIO, mask, mask);
+
+ gpio_regmap.parent = dev;
+ gpio_regmap.regmap = st->regmap;
+ gpio_regmap.ngpio = st->info->num_gpios;
+ gpio_regmap.reg_set_base = GPIO_REGMAP_ADDR_ZERO;
+ gpio_regmap.reg_mask_xlate = ad7173_mask_xlate;
+
+ st->gpio_regmap = devm_gpio_regmap_register(dev, &gpio_regmap);
+ if (IS_ERR(st->gpio_regmap)) {
+ return dev_err_probe(dev, PTR_ERR(st->gpio_regmap),
+ "Unable to init gpio-regmap\n");
+ }
+
+ return 0;
+}
+
+#endif /* CONFIG_GPIOLIB */