Lines Matching +full:gpio +full:- +full:bank
4 * SPDX-License-Identifier: Apache-2.0
8 #include <zephyr/drivers/gpio.h>
9 #include <zephyr/drivers/gpio/gpio_utils.h>
69 const struct adp5585_gpio_config *cfg = dev->config; in gpio_adp5585_config()
70 struct adp5585_gpio_data *data = dev->data; in gpio_adp5585_config()
72 (struct mfd_adp5585_config *)(cfg->mfd_dev->config); in gpio_adp5585_config()
73 struct mfd_adp5585_data *parent_data = (struct mfd_adp5585_data *)(cfg->mfd_dev->data); in gpio_adp5585_config()
78 /* ADP5585 has non-contiguous gpio pin layouts, account for this */ in gpio_adp5585_config()
79 if ((pin & cfg->common.port_pin_mask) == 0) { in gpio_adp5585_config()
81 return -ENOTSUP; in gpio_adp5585_config()
84 uint8_t bank = ADP5585_BANK(pin); in gpio_adp5585_config() local
89 return -EWOULDBLOCK; in gpio_adp5585_config()
94 return -ENOTSUP; in gpio_adp5585_config()
99 return -ENOTSUP; in gpio_adp5585_config()
102 k_sem_take(&parent_data->lock, K_FOREVER); in gpio_adp5585_config()
109 ret = i2c_reg_update_byte_dt(&parent_cfg->i2c_bus, ADP5585_GPO_OUT_MODE_A + bank, in gpio_adp5585_config()
115 uint8_t regaddr = ADP5585_RPULL_CONFIG_A + (bank << 1); in gpio_adp5585_config()
120 shift = (bank_pin - 3U) << 1; in gpio_adp5585_config()
130 ret = i2c_reg_update_byte_dt(&parent_cfg->i2c_bus, regaddr, in gpio_adp5585_config()
141 data->output &= ~BIT(pin); in gpio_adp5585_config()
143 data->output |= BIT(pin); in gpio_adp5585_config()
145 if (bank == 0) { in gpio_adp5585_config()
147 reg_value = (uint8_t)data->output; in gpio_adp5585_config()
150 reg_value = (uint8_t)(data->output >> 8); in gpio_adp5585_config()
152 ret = i2c_reg_write_byte_dt(&parent_cfg->i2c_bus, in gpio_adp5585_config()
153 ADP5585_GPO_OUT_MODE_A + bank, in gpio_adp5585_config()
165 ret = i2c_reg_update_byte_dt(&parent_cfg->i2c_bus, in gpio_adp5585_config()
166 ADP5585_GPIO_DIRECTION_A + bank, in gpio_adp5585_config()
170 k_sem_give(&parent_data->lock); in gpio_adp5585_config()
179 const struct adp5585_gpio_config *cfg = dev->config; in gpio_adp5585_port_read()
180 /* struct adp5585_gpio_data *data = dev->data; */ in gpio_adp5585_port_read()
182 (struct mfd_adp5585_config *)(cfg->mfd_dev->config); in gpio_adp5585_port_read()
183 struct mfd_adp5585_data *parent_data = (struct mfd_adp5585_data *)(cfg->mfd_dev->data); in gpio_adp5585_port_read()
190 return -EWOULDBLOCK; in gpio_adp5585_port_read()
193 k_sem_take(&parent_data->lock, K_FOREVER); in gpio_adp5585_port_read()
200 ret = i2c_write_read_dt(&parent_cfg->i2c_bus, &gpi_status_reg, 1U, in gpio_adp5585_port_read()
209 k_sem_give(&parent_data->lock); in gpio_adp5585_port_read()
217 const struct adp5585_gpio_config *cfg = dev->config; in gpio_adp5585_port_write()
218 struct adp5585_gpio_data *data = dev->data; in gpio_adp5585_port_write()
220 (struct mfd_adp5585_config *)(cfg->mfd_dev->config); in gpio_adp5585_port_write()
221 struct mfd_adp5585_data *parent_data = (struct mfd_adp5585_data *)(cfg->mfd_dev->data); in gpio_adp5585_port_write()
230 return -EWOULDBLOCK; in gpio_adp5585_port_write()
233 k_sem_take(&parent_data->lock, K_FOREVER); in gpio_adp5585_port_write()
235 orig_out = data->output; in gpio_adp5585_port_write()
242 ret = i2c_write_dt(&parent_cfg->i2c_bus, gpo_data_out_buf, sizeof(gpo_data_out_buf)); in gpio_adp5585_port_write()
247 data->output = out; in gpio_adp5585_port_write()
250 k_sem_give(&parent_data->lock); in gpio_adp5585_port_write()
279 const struct adp5585_gpio_config *cfg = dev->config; in gpio_adp5585_pin_interrupt_configure()
280 /* struct adp5585_gpio_data *data = dev->data; */ in gpio_adp5585_pin_interrupt_configure()
282 (struct mfd_adp5585_config *)(cfg->mfd_dev->config); in gpio_adp5585_pin_interrupt_configure()
283 struct mfd_adp5585_data *parent_data = (struct mfd_adp5585_data *)(cfg->mfd_dev->data); in gpio_adp5585_pin_interrupt_configure()
286 if (parent_cfg->nint_gpio.port == NULL) { in gpio_adp5585_pin_interrupt_configure()
287 return -ENOTSUP; in gpio_adp5585_pin_interrupt_configure()
290 /* ADP5585 has non-contiguous gpio pin layouts, account for this */ in gpio_adp5585_pin_interrupt_configure()
291 if ((pin & cfg->common.port_pin_mask) == 0) { in gpio_adp5585_pin_interrupt_configure()
293 return -ENOTSUP; in gpio_adp5585_pin_interrupt_configure()
296 /* This device supports only level-triggered interrupts. */ in gpio_adp5585_pin_interrupt_configure()
297 /* This device does NOT support either-level interrupt. */ in gpio_adp5585_pin_interrupt_configure()
299 return -ENOTSUP; in gpio_adp5585_pin_interrupt_configure()
302 return -EWOULDBLOCK; in gpio_adp5585_pin_interrupt_configure()
305 uint8_t bank = ADP5585_BANK(pin); in gpio_adp5585_pin_interrupt_configure() local
308 k_sem_take(&parent_data->lock, K_FOREVER); in gpio_adp5585_pin_interrupt_configure()
311 ret = i2c_reg_update_byte_dt(&parent_cfg->i2c_bus, in gpio_adp5585_pin_interrupt_configure()
312 ADP5585_GPI_INTERRUPT_EN_A + bank, BIT(bank_pin), in gpio_adp5585_pin_interrupt_configure()
317 &parent_cfg->i2c_bus, ADP5585_GPI_INT_LEVEL_A + bank, in gpio_adp5585_pin_interrupt_configure()
321 &parent_cfg->i2c_bus, ADP5585_GPI_INT_LEVEL_A + bank, in gpio_adp5585_pin_interrupt_configure()
326 ret = i2c_reg_update_byte_dt(&parent_cfg->i2c_bus, in gpio_adp5585_pin_interrupt_configure()
327 ADP5585_GPI_EVENT_EN_A + bank, BIT(bank_pin), 0U); in gpio_adp5585_pin_interrupt_configure()
328 ret = i2c_reg_update_byte_dt(&parent_cfg->i2c_bus, in gpio_adp5585_pin_interrupt_configure()
329 ADP5585_GPI_INTERRUPT_EN_A + bank, in gpio_adp5585_pin_interrupt_configure()
333 k_sem_give(&parent_data->lock); in gpio_adp5585_pin_interrupt_configure()
340 struct adp5585_gpio_data *data = dev->data; in gpio_adp5585_manage_callback()
342 return gpio_manage_callback(&data->callbacks, callback, set); in gpio_adp5585_manage_callback()
347 const struct adp5585_gpio_config *cfg = dev->config; in gpio_adp5585_irq_handler()
348 struct adp5585_gpio_data *data = dev->data; in gpio_adp5585_irq_handler()
350 (struct mfd_adp5585_config *)(cfg->mfd_dev->config); in gpio_adp5585_irq_handler()
351 struct mfd_adp5585_data *parent_data = (struct mfd_adp5585_data *)(cfg->mfd_dev->data); in gpio_adp5585_irq_handler()
356 k_sem_take(&parent_data->lock, K_FOREVER); in gpio_adp5585_irq_handler()
359 ret = i2c_burst_read_dt(&parent_cfg->i2c_bus, ADP5585_GPI_INT_STAT_A, in gpio_adp5585_irq_handler()
362 LOG_WRN("%s failed to read interrupt status %d", dev->name, ret); in gpio_adp5585_irq_handler()
367 k_sem_give(&parent_data->lock); in gpio_adp5585_irq_handler()
370 gpio_fire_callbacks(&data->callbacks, dev, reg_int_status); in gpio_adp5585_irq_handler()
385 const struct adp5585_gpio_config *cfg = dev->config; in gpio_adp5585_init()
386 struct adp5585_gpio_data *data = dev->data; in gpio_adp5585_init()
388 (struct mfd_adp5585_config *)(cfg->mfd_dev->config); in gpio_adp5585_init()
389 struct mfd_adp5585_data *parent_data = (struct mfd_adp5585_data *)(cfg->mfd_dev->data); in gpio_adp5585_init()
392 if (!device_is_ready(cfg->mfd_dev)) { in gpio_adp5585_init()
393 LOG_ERR("%s: parent dev not ready", dev->name); in gpio_adp5585_init()
394 ret = -ENODEV; in gpio_adp5585_init()
398 if (!device_is_ready(parent_cfg->i2c_bus.bus)) { in gpio_adp5585_init()
400 ret = -EIO; in gpio_adp5585_init()
404 k_sem_take(&parent_data->lock, K_FOREVER); in gpio_adp5585_init()
410 ret = i2c_write_read_dt(&parent_cfg->i2c_bus, gpo_data_out_buf, 1U, in gpio_adp5585_init()
415 data->output = sys_le16_to_cpu(*((uint16_t *)(gpo_data_out_buf + 1))); in gpio_adp5585_init()
417 /** Set RPULL to high-z by default */ in gpio_adp5585_init()
421 ret = i2c_write_dt(&parent_cfg->i2c_bus, rpull_config_buf, sizeof(rpull_config_buf)); in gpio_adp5585_init()
426 parent_data->child.gpio_dev = dev; in gpio_adp5585_init()
429 if ((ret == 0) && gpio_is_ready_dt(&parent_cfg->nint_gpio)) { in gpio_adp5585_init()
430 ret = i2c_reg_update_byte_dt(&parent_cfg->i2c_bus, ADP5585_INT_EN, (1U << 1), in gpio_adp5585_init()
435 k_sem_give(&parent_data->lock); in gpio_adp5585_init()
437 LOG_ERR("%s init failed: %d", dev->name, ret); in gpio_adp5585_init()
439 LOG_INF("%s init ok", dev->name); in gpio_adp5585_init()
444 static DEVICE_API(gpio, api_table) = {