Lines Matching +full:init +full:- +full:b +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0-only
14 #include <linux/init.h>
26 * - Push Pull Output
27 * - Input
28 * - Open Drain I/O
37 * - Group A : by I2C address 0b'110xxxx
38 * - Group B : by I2C address 0b'101xxxx
49 * and GPIOs from GROUP_A are numbered before those from GROUP_B
52 * NOTE: MAX7328/MAX7329 are drop-in replacements for PCF8574/a, so
57 #define PORT_OUTPUT 0x1 /* 'O' Push-Pull, Output Only */
59 #define PORT_OPENDRAIN 0x3 /* 'P' Open-Drain, I/O */
67 #define GROUP_A(x) ((x) & 0xffff) /* I2C Addr: 0b'110xxxx */
68 #define GROUP_B(x) ((x) << 16) /* I2C Addr: 0b'101xxxx */
159 client = group_a ? chip->client_group_a : chip->client_group_b; in max732x_writeb()
162 dev_err(&client->dev, "failed writing\n"); in max732x_writeb()
174 client = group_a ? chip->client_group_a : chip->client_group_b; in max732x_readb()
177 dev_err(&client->dev, "failed reading\n"); in max732x_readb()
187 return (1u << off) & chip->mask_group_a; in is_group_a()
210 mutex_lock(&chip->lock); in max732x_gpio_set_mask()
212 reg_out = (off > 7) ? chip->reg_out[1] : chip->reg_out[0]; in max732x_gpio_set_mask()
221 chip->reg_out[1] = reg_out; in max732x_gpio_set_mask()
223 chip->reg_out[0] = reg_out; in max732x_gpio_set_mask()
225 mutex_unlock(&chip->lock); in max732x_gpio_set_mask()
253 if ((mask & chip->dir_input) == 0) { in max732x_gpio_direction_input()
254 dev_dbg(&chip->client->dev, "%s port %d is output only\n", in max732x_gpio_direction_input()
255 chip->client->name, off); in max732x_gpio_direction_input()
256 return -EACCES; in max732x_gpio_direction_input()
260 * Open-drain pins must be set to high impedance (which is in max732x_gpio_direction_input()
261 * equivalent to output-high) to be turned into an input. in max732x_gpio_direction_input()
263 if ((mask & chip->dir_output)) in max732x_gpio_direction_input()
275 if ((mask & chip->dir_output) == 0) { in max732x_gpio_direction_output()
276 dev_dbg(&chip->client->dev, "%s port %d is input only\n", in max732x_gpio_direction_output()
277 chip->client->name, off); in max732x_gpio_direction_output()
278 return -EACCES; in max732x_gpio_direction_output()
292 ret = i2c_master_send(chip->client_group_a, (char *)&val, 2); in max732x_writew()
294 dev_err(&chip->client_group_a->dev, "failed writing\n"); in max732x_writew()
305 ret = i2c_master_recv(chip->client_group_a, (char *)val, 2); in max732x_readw()
307 dev_err(&chip->client_group_a->dev, "failed reading\n"); in max732x_readw()
319 if (chip->irq_mask == chip->irq_mask_cur) in max732x_irq_update_mask()
322 chip->irq_mask = chip->irq_mask_cur; in max732x_irq_update_mask()
324 if (chip->irq_features == INT_NO_MASK) in max732x_irq_update_mask()
327 mutex_lock(&chip->lock); in max732x_irq_update_mask()
329 switch (chip->irq_features) { in max732x_irq_update_mask()
331 msg = (chip->irq_mask << 8) | chip->reg_out[0]; in max732x_irq_update_mask()
336 msg = chip->irq_mask | chip->reg_out[0]; in max732x_irq_update_mask()
341 mutex_unlock(&chip->lock); in max732x_irq_update_mask()
349 chip->irq_mask_cur &= ~(1 << d->hwirq); in max732x_irq_mask()
359 chip->irq_mask_cur |= 1 << d->hwirq; in max732x_irq_unmask()
367 mutex_lock(&chip->irq_lock); in max732x_irq_bus_lock()
368 chip->irq_mask_cur = chip->irq_mask; in max732x_irq_bus_lock()
380 new_irqs = chip->irq_trig_fall | chip->irq_trig_raise; in max732x_irq_bus_sync_unlock()
383 max732x_gpio_direction_input(&chip->gpio_chip, level); in max732x_irq_bus_sync_unlock()
387 mutex_unlock(&chip->irq_lock); in max732x_irq_bus_sync_unlock()
394 uint16_t off = d->hwirq; in max732x_irq_set_type()
397 if (!(mask & chip->dir_input)) { in max732x_irq_set_type()
398 dev_dbg(&chip->client->dev, "%s port %d is output only\n", in max732x_irq_set_type()
399 chip->client->name, off); in max732x_irq_set_type()
400 return -EACCES; in max732x_irq_set_type()
404 dev_err(&chip->client->dev, "irq %d: unsupported type %d\n", in max732x_irq_set_type()
405 d->irq, type); in max732x_irq_set_type()
406 return -EINVAL; in max732x_irq_set_type()
410 chip->irq_trig_fall |= mask; in max732x_irq_set_type()
412 chip->irq_trig_fall &= ~mask; in max732x_irq_set_type()
415 chip->irq_trig_raise |= mask; in max732x_irq_set_type()
417 chip->irq_trig_raise &= ~mask; in max732x_irq_set_type()
426 irq_set_irq_wake(chip->client->irq, on); in max732x_irq_set_wake()
456 trigger &= chip->irq_mask; in max732x_irq_pending()
462 cur_stat &= chip->irq_mask; in max732x_irq_pending()
466 pending = (old_stat & chip->irq_trig_fall) | in max732x_irq_pending()
467 (cur_stat & chip->irq_trig_raise); in max732x_irq_pending()
486 handle_nested_irq(irq_find_mapping(chip->gpio_chip.irq.domain, in max732x_irq_handler()
498 struct i2c_client *client = chip->client; in max732x_irq_setup()
499 int has_irq = max732x_features[id->driver_data] >> 32; in max732x_irq_setup()
503 if (client->irq && has_irq != INT_NONE) { in max732x_irq_setup()
506 chip->irq_features = has_irq; in max732x_irq_setup()
507 mutex_init(&chip->irq_lock); in max732x_irq_setup()
509 ret = devm_request_threaded_irq(&client->dev, client->irq, in max732x_irq_setup()
512 dev_name(&client->dev), chip); in max732x_irq_setup()
514 dev_err(&client->dev, "failed to request irq %d\n", in max732x_irq_setup()
515 client->irq); in max732x_irq_setup()
519 girq = &chip->gpio_chip.irq; in max732x_irq_setup()
522 girq->parent_handler = NULL; in max732x_irq_setup()
523 girq->num_parents = 0; in max732x_irq_setup()
524 girq->parents = NULL; in max732x_irq_setup()
525 girq->default_type = IRQ_TYPE_NONE; in max732x_irq_setup()
526 girq->handler = handle_simple_irq; in max732x_irq_setup()
527 girq->threaded = true; in max732x_irq_setup()
528 girq->first = irq_base; /* FIXME: get rid of this */ in max732x_irq_setup()
538 struct i2c_client *client = chip->client; in max732x_irq_setup()
539 int has_irq = max732x_features[id->driver_data] >> 32; in max732x_irq_setup()
541 if (client->irq && has_irq != INT_NONE) in max732x_irq_setup()
542 dev_warn(&client->dev, "interrupt support not compiled in\n"); in max732x_irq_setup()
552 struct gpio_chip *gc = &chip->gpio_chip; in max732x_setup_gpio()
553 uint32_t id_data = (uint32_t)max732x_features[id->driver_data]; in max732x_setup_gpio()
561 chip->dir_output |= mask; in max732x_setup_gpio()
564 chip->dir_input |= mask; in max732x_setup_gpio()
567 chip->dir_output |= mask; in max732x_setup_gpio()
568 chip->dir_input |= mask; in max732x_setup_gpio()
575 chip->mask_group_a |= mask; in max732x_setup_gpio()
579 if (chip->dir_input) in max732x_setup_gpio()
580 gc->direction_input = max732x_gpio_direction_input; in max732x_setup_gpio()
581 if (chip->dir_output) { in max732x_setup_gpio()
582 gc->direction_output = max732x_gpio_direction_output; in max732x_setup_gpio()
583 gc->set = max732x_gpio_set_value; in max732x_setup_gpio()
584 gc->set_multiple = max732x_gpio_set_multiple; in max732x_setup_gpio()
586 gc->get = max732x_gpio_get_value; in max732x_setup_gpio()
587 gc->can_sleep = true; in max732x_setup_gpio()
589 gc->base = gpio_start; in max732x_setup_gpio()
590 gc->ngpio = port; in max732x_setup_gpio()
591 gc->label = chip->client->name; in max732x_setup_gpio()
592 gc->parent = &chip->client->dev; in max732x_setup_gpio()
593 gc->owner = THIS_MODULE; in max732x_setup_gpio()
606 pdata->gpio_base = -1; in of_gpio_max732x()
621 pdata = dev_get_platdata(&client->dev); in max732x_probe()
622 node = client->dev.of_node; in max732x_probe()
625 pdata = of_gpio_max732x(&client->dev); in max732x_probe()
628 dev_dbg(&client->dev, "no platform data\n"); in max732x_probe()
629 return -EINVAL; in max732x_probe()
632 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); in max732x_probe()
634 return -ENOMEM; in max732x_probe()
635 chip->client = client; in max732x_probe()
637 nr_port = max732x_setup_gpio(chip, id, pdata->gpio_base); in max732x_probe()
638 chip->gpio_chip.parent = &client->dev; in max732x_probe()
640 addr_a = (client->addr & 0x0f) | 0x60; in max732x_probe()
641 addr_b = (client->addr & 0x0f) | 0x50; in max732x_probe()
643 switch (client->addr & 0x70) { in max732x_probe()
645 chip->client_group_a = client; in max732x_probe()
647 c = devm_i2c_new_dummy_device(&client->dev, in max732x_probe()
648 client->adapter, addr_b); in max732x_probe()
650 dev_err(&client->dev, in max732x_probe()
654 chip->client_group_b = chip->client_dummy = c; in max732x_probe()
658 chip->client_group_b = client; in max732x_probe()
660 c = devm_i2c_new_dummy_device(&client->dev, in max732x_probe()
661 client->adapter, addr_a); in max732x_probe()
663 dev_err(&client->dev, in max732x_probe()
667 chip->client_group_a = chip->client_dummy = c; in max732x_probe()
671 dev_err(&client->dev, "invalid I2C address specified %02x\n", in max732x_probe()
672 client->addr); in max732x_probe()
673 return -EINVAL; in max732x_probe()
676 if (nr_port > 8 && !chip->client_dummy) { in max732x_probe()
677 dev_err(&client->dev, in max732x_probe()
679 return -ENODEV; in max732x_probe()
682 mutex_init(&chip->lock); in max732x_probe()
684 ret = max732x_readb(chip, is_group_a(chip, 0), &chip->reg_out[0]); in max732x_probe()
688 ret = max732x_readb(chip, is_group_a(chip, 8), &chip->reg_out[1]); in max732x_probe()
697 ret = devm_gpiochip_add_data(&client->dev, &chip->gpio_chip, chip); in max732x_probe()
719 * subsys initcalls that may rely on these GPIOs