Lines Matching refs:adnp

21 struct adnp {  struct
37 static int adnp_read(struct adnp *adnp, unsigned offset, uint8_t *value) in adnp_read() argument
41 err = i2c_smbus_read_byte_data(adnp->client, offset); in adnp_read()
43 dev_err(adnp->gpio.parent, "%s failed: %d\n", in adnp_read()
52 static int adnp_write(struct adnp *adnp, unsigned offset, uint8_t value) in adnp_write() argument
56 err = i2c_smbus_write_byte_data(adnp->client, offset, value); in adnp_write()
58 dev_err(adnp->gpio.parent, "%s failed: %d\n", in adnp_write()
68 struct adnp *adnp = gpiochip_get_data(chip); in adnp_gpio_get() local
69 unsigned int reg = offset >> adnp->reg_shift; in adnp_gpio_get()
74 err = adnp_read(adnp, GPIO_PLR(adnp) + reg, &value); in adnp_gpio_get()
81 static void __adnp_gpio_set(struct adnp *adnp, unsigned offset, int value) in __adnp_gpio_set() argument
83 unsigned int reg = offset >> adnp->reg_shift; in __adnp_gpio_set()
88 err = adnp_read(adnp, GPIO_PLR(adnp) + reg, &val); in __adnp_gpio_set()
97 adnp_write(adnp, GPIO_PLR(adnp) + reg, val); in __adnp_gpio_set()
102 struct adnp *adnp = gpiochip_get_data(chip); in adnp_gpio_set() local
104 mutex_lock(&adnp->i2c_lock); in adnp_gpio_set()
105 __adnp_gpio_set(adnp, offset, value); in adnp_gpio_set()
106 mutex_unlock(&adnp->i2c_lock); in adnp_gpio_set()
111 struct adnp *adnp = gpiochip_get_data(chip); in adnp_gpio_direction_input() local
112 unsigned int reg = offset >> adnp->reg_shift; in adnp_gpio_direction_input()
117 mutex_lock(&adnp->i2c_lock); in adnp_gpio_direction_input()
119 err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &value); in adnp_gpio_direction_input()
125 err = adnp_write(adnp, GPIO_DDR(adnp) + reg, value); in adnp_gpio_direction_input()
129 err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &value); in adnp_gpio_direction_input()
141 mutex_unlock(&adnp->i2c_lock); in adnp_gpio_direction_input()
148 struct adnp *adnp = gpiochip_get_data(chip); in adnp_gpio_direction_output() local
149 unsigned int reg = offset >> adnp->reg_shift; in adnp_gpio_direction_output()
154 mutex_lock(&adnp->i2c_lock); in adnp_gpio_direction_output()
156 err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &val); in adnp_gpio_direction_output()
162 err = adnp_write(adnp, GPIO_DDR(adnp) + reg, val); in adnp_gpio_direction_output()
166 err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &val); in adnp_gpio_direction_output()
175 __adnp_gpio_set(adnp, offset, value); in adnp_gpio_direction_output()
179 mutex_unlock(&adnp->i2c_lock); in adnp_gpio_direction_output()
185 struct adnp *adnp = gpiochip_get_data(chip); in adnp_gpio_dbg_show() local
186 unsigned int num_regs = 1 << adnp->reg_shift, i, j; in adnp_gpio_dbg_show()
192 mutex_lock(&adnp->i2c_lock); in adnp_gpio_dbg_show()
194 err = adnp_read(adnp, GPIO_DDR(adnp) + i, &ddr); in adnp_gpio_dbg_show()
198 err = adnp_read(adnp, GPIO_PLR(adnp) + i, &plr); in adnp_gpio_dbg_show()
202 err = adnp_read(adnp, GPIO_IER(adnp) + i, &ier); in adnp_gpio_dbg_show()
206 err = adnp_read(adnp, GPIO_ISR(adnp) + i, &isr); in adnp_gpio_dbg_show()
210 mutex_unlock(&adnp->i2c_lock); in adnp_gpio_dbg_show()
213 unsigned int bit = (i << adnp->reg_shift) + j; in adnp_gpio_dbg_show()
239 mutex_unlock(&adnp->i2c_lock); in adnp_gpio_dbg_show()
244 struct adnp *adnp = data; in adnp_irq() local
247 num_regs = 1 << adnp->reg_shift; in adnp_irq()
250 unsigned int base = i << adnp->reg_shift, bit; in adnp_irq()
255 mutex_lock(&adnp->i2c_lock); in adnp_irq()
257 err = adnp_read(adnp, GPIO_PLR(adnp) + i, &level); in adnp_irq()
259 mutex_unlock(&adnp->i2c_lock); in adnp_irq()
263 err = adnp_read(adnp, GPIO_ISR(adnp) + i, &isr); in adnp_irq()
265 mutex_unlock(&adnp->i2c_lock); in adnp_irq()
269 err = adnp_read(adnp, GPIO_IER(adnp) + i, &ier); in adnp_irq()
271 mutex_unlock(&adnp->i2c_lock); in adnp_irq()
275 mutex_unlock(&adnp->i2c_lock); in adnp_irq()
278 changed = level ^ adnp->irq_level[i]; in adnp_irq()
281 pending = changed & ((adnp->irq_fall[i] & ~level) | in adnp_irq()
282 (adnp->irq_rise[i] & level)); in adnp_irq()
285 pending |= (adnp->irq_high[i] & level) | in adnp_irq()
286 (adnp->irq_low[i] & ~level); in adnp_irq()
293 child_irq = irq_find_mapping(adnp->gpio.irq.domain, in adnp_irq()
305 struct adnp *adnp = gpiochip_get_data(gc); in adnp_irq_mask() local
306 unsigned int reg = d->hwirq >> adnp->reg_shift; in adnp_irq_mask()
309 adnp->irq_enable[reg] &= ~BIT(pos); in adnp_irq_mask()
316 struct adnp *adnp = gpiochip_get_data(gc); in adnp_irq_unmask() local
317 unsigned int reg = d->hwirq >> adnp->reg_shift; in adnp_irq_unmask()
321 adnp->irq_enable[reg] |= BIT(pos); in adnp_irq_unmask()
327 struct adnp *adnp = gpiochip_get_data(gc); in adnp_irq_set_type() local
328 unsigned int reg = d->hwirq >> adnp->reg_shift; in adnp_irq_set_type()
332 adnp->irq_rise[reg] |= BIT(pos); in adnp_irq_set_type()
334 adnp->irq_rise[reg] &= ~BIT(pos); in adnp_irq_set_type()
337 adnp->irq_fall[reg] |= BIT(pos); in adnp_irq_set_type()
339 adnp->irq_fall[reg] &= ~BIT(pos); in adnp_irq_set_type()
342 adnp->irq_high[reg] |= BIT(pos); in adnp_irq_set_type()
344 adnp->irq_high[reg] &= ~BIT(pos); in adnp_irq_set_type()
347 adnp->irq_low[reg] |= BIT(pos); in adnp_irq_set_type()
349 adnp->irq_low[reg] &= ~BIT(pos); in adnp_irq_set_type()
357 struct adnp *adnp = gpiochip_get_data(gc); in adnp_irq_bus_lock() local
359 mutex_lock(&adnp->irq_lock); in adnp_irq_bus_lock()
365 struct adnp *adnp = gpiochip_get_data(gc); in adnp_irq_bus_unlock() local
366 unsigned int num_regs = 1 << adnp->reg_shift, i; in adnp_irq_bus_unlock()
368 mutex_lock(&adnp->i2c_lock); in adnp_irq_bus_unlock()
371 adnp_write(adnp, GPIO_IER(adnp) + i, adnp->irq_enable[i]); in adnp_irq_bus_unlock()
373 mutex_unlock(&adnp->i2c_lock); in adnp_irq_bus_unlock()
374 mutex_unlock(&adnp->irq_lock); in adnp_irq_bus_unlock()
388 static int adnp_irq_setup(struct adnp *adnp) in adnp_irq_setup() argument
390 unsigned int num_regs = 1 << adnp->reg_shift, i; in adnp_irq_setup()
391 struct gpio_chip *chip = &adnp->gpio; in adnp_irq_setup()
394 mutex_init(&adnp->irq_lock); in adnp_irq_setup()
404 adnp->irq_enable = devm_kcalloc(chip->parent, num_regs, 6, in adnp_irq_setup()
406 if (!adnp->irq_enable) in adnp_irq_setup()
409 adnp->irq_level = adnp->irq_enable + (num_regs * 1); in adnp_irq_setup()
410 adnp->irq_rise = adnp->irq_enable + (num_regs * 2); in adnp_irq_setup()
411 adnp->irq_fall = adnp->irq_enable + (num_regs * 3); in adnp_irq_setup()
412 adnp->irq_high = adnp->irq_enable + (num_regs * 4); in adnp_irq_setup()
413 adnp->irq_low = adnp->irq_enable + (num_regs * 5); in adnp_irq_setup()
420 err = adnp_read(adnp, GPIO_PLR(adnp) + i, &adnp->irq_level[i]); in adnp_irq_setup()
425 err = adnp_write(adnp, GPIO_IER(adnp) + i, 0); in adnp_irq_setup()
429 adnp->irq_enable[i] = 0x00; in adnp_irq_setup()
432 err = devm_request_threaded_irq(chip->parent, adnp->client->irq, in adnp_irq_setup()
435 dev_name(chip->parent), adnp); in adnp_irq_setup()
438 adnp->client->irq, err); in adnp_irq_setup()
445 static int adnp_gpio_setup(struct adnp *adnp, unsigned int num_gpios, in adnp_gpio_setup() argument
448 struct gpio_chip *chip = &adnp->gpio; in adnp_gpio_setup()
451 adnp->reg_shift = get_count_order(num_gpios) - 3; in adnp_gpio_setup()
464 chip->label = adnp->client->name; in adnp_gpio_setup()
465 chip->parent = &adnp->client->dev; in adnp_gpio_setup()
471 err = adnp_irq_setup(adnp); in adnp_gpio_setup()
487 err = devm_gpiochip_add_data(&adnp->client->dev, chip, adnp); in adnp_gpio_setup()
497 struct adnp *adnp; in adnp_i2c_probe() local
505 adnp = devm_kzalloc(&client->dev, sizeof(*adnp), GFP_KERNEL); in adnp_i2c_probe()
506 if (!adnp) in adnp_i2c_probe()
509 mutex_init(&adnp->i2c_lock); in adnp_i2c_probe()
510 adnp->client = client; in adnp_i2c_probe()
512 err = adnp_gpio_setup(adnp, num_gpios, device_property_read_bool(dev, "interrupt-controller")); in adnp_i2c_probe()
516 i2c_set_clientdata(client, adnp); in adnp_i2c_probe()