Lines Matching +full:reg +full:- +full:offset

1 // SPDX-License-Identifier: GPL-2.0-only
3 * GPIO driver for EXAR XRA1403 16-bit GPIO expander
24 #define XRA_PUR 0x08 /* Input Internal Pull-up Resistor Enable/Disable */
26 #define XRA_TSCR 0x0C /* Output Three-State Control */
46 static unsigned int to_reg(unsigned int reg, unsigned int offset) in to_reg() argument
48 return reg + (offset > 7); in to_reg()
51 static int xra1403_direction_input(struct gpio_chip *chip, unsigned int offset) in xra1403_direction_input() argument
55 return regmap_update_bits(xra->regmap, to_reg(XRA_GCR, offset), in xra1403_direction_input()
56 BIT(offset % 8), BIT(offset % 8)); in xra1403_direction_input()
59 static int xra1403_direction_output(struct gpio_chip *chip, unsigned int offset, in xra1403_direction_output() argument
65 ret = regmap_update_bits(xra->regmap, to_reg(XRA_GCR, offset), in xra1403_direction_output()
66 BIT(offset % 8), 0); in xra1403_direction_output()
70 ret = regmap_update_bits(xra->regmap, to_reg(XRA_OCR, offset), in xra1403_direction_output()
71 BIT(offset % 8), value ? BIT(offset % 8) : 0); in xra1403_direction_output()
76 static int xra1403_get_direction(struct gpio_chip *chip, unsigned int offset) in xra1403_get_direction() argument
82 ret = regmap_read(xra->regmap, to_reg(XRA_GCR, offset), &val); in xra1403_get_direction()
86 if (val & BIT(offset % 8)) in xra1403_get_direction()
92 static int xra1403_get(struct gpio_chip *chip, unsigned int offset) in xra1403_get() argument
98 ret = regmap_read(xra->regmap, to_reg(XRA_GSR, offset), &val); in xra1403_get()
102 return !!(val & BIT(offset % 8)); in xra1403_get()
105 static void xra1403_set(struct gpio_chip *chip, unsigned int offset, int value) in xra1403_set() argument
110 ret = regmap_update_bits(xra->regmap, to_reg(XRA_OCR, offset), in xra1403_set()
111 BIT(offset % 8), value ? BIT(offset % 8) : 0); in xra1403_set()
113 dev_err(chip->parent, "Failed to set pin: %d, ret: %d\n", in xra1403_set()
114 offset, ret); in xra1403_set()
120 int reg; in xra1403_dbg_show() local
128 seq_puts(s, "xra reg:"); in xra1403_dbg_show()
129 for (reg = 0; reg <= XRA_LAST; reg++) in xra1403_dbg_show()
130 seq_printf(s, " %2.2x", reg); in xra1403_dbg_show()
132 for (reg = 0; reg < XRA_LAST; reg++) { in xra1403_dbg_show()
133 regmap_read(xra->regmap, reg, &value[reg]); in xra1403_dbg_show()
134 seq_printf(s, " %2.2x", value[reg]); in xra1403_dbg_show()
141 seq_printf(s, " gpio-%-3d (%-12s) %s %s\n", in xra1403_dbg_show()
142 chip->base + i, label, in xra1403_dbg_show()
157 xra = devm_kzalloc(&spi->dev, sizeof(*xra), GFP_KERNEL); in xra1403_probe()
159 return -ENOMEM; in xra1403_probe()
162 reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_LOW); in xra1403_probe()
164 dev_warn(&spi->dev, "Could not get reset-gpios\n"); in xra1403_probe()
166 xra->chip.direction_input = xra1403_direction_input; in xra1403_probe()
167 xra->chip.direction_output = xra1403_direction_output; in xra1403_probe()
168 xra->chip.get_direction = xra1403_get_direction; in xra1403_probe()
169 xra->chip.get = xra1403_get; in xra1403_probe()
170 xra->chip.set = xra1403_set; in xra1403_probe()
172 xra->chip.dbg_show = xra1403_dbg_show; in xra1403_probe()
174 xra->chip.ngpio = 16; in xra1403_probe()
175 xra->chip.label = "xra1403"; in xra1403_probe()
177 xra->chip.base = -1; in xra1403_probe()
178 xra->chip.can_sleep = true; in xra1403_probe()
179 xra->chip.parent = &spi->dev; in xra1403_probe()
180 xra->chip.owner = THIS_MODULE; in xra1403_probe()
182 xra->regmap = devm_regmap_init_spi(spi, &xra1403_regmap_cfg); in xra1403_probe()
183 if (IS_ERR(xra->regmap)) { in xra1403_probe()
184 ret = PTR_ERR(xra->regmap); in xra1403_probe()
185 dev_err(&spi->dev, "Failed to allocate regmap: %d\n", ret); in xra1403_probe()
189 return devm_gpiochip_add_data(&spi->dev, &xra->chip, xra); in xra1403_probe()