Lines Matching +full:nct38xx +full:- +full:gpio
4 * SPDX-License-Identifier: Apache-2.0
10 #include <zephyr/drivers/gpio.h>
11 #include <zephyr/drivers/gpio/gpio_nct38xx.h>
12 #include <zephyr/drivers/mfd/nct38xx.h>
22 /* Lock for NCT38xx register access */
30 /* Alert GPIO pin */
32 /* NCT38XX devices which share the same alert pin */
34 /* Number of NCT38XX devices on the alert pin */
46 /* Lock for NCT38xx register access */
56 k_work_submit(&data->alert_worker); in nct38xx_alert_callback()
64 k_sem_take(mfd->lock, K_FOREVER); in nct38xx_alert_is_active()
67 ret = i2c_burst_read_dt(mfd->i2c_dev, NCT38XX_REG_ALERT, (uint8_t *)&alert, in nct38xx_alert_is_active()
72 ret = i2c_burst_read_dt(mfd->i2c_dev, NCT38XX_REG_ALERT_MASK, in nct38xx_alert_is_active()
80 ret = i2c_burst_write_dt(mfd->i2c_dev, NCT38XX_REG_ALERT, in nct38xx_alert_is_active()
85 k_sem_give(mfd->lock); in nct38xx_alert_is_active()
103 const struct nct38xx_alert_config *const config = data->alert_dev->config; in nct38xx_alert_worker()
106 /* NCT38XX device handler */ in nct38xx_alert_worker()
107 for (int i = 0; i < config->nct38xx_num; i++) { in nct38xx_alert_worker()
108 struct nct38xx_mfd *mfd = &data->mfd[i]; in nct38xx_alert_worker()
111 nct38xx_gpio_alert_handler(config->nct38xx_dev[i]); in nct38xx_alert_worker()
115 } while (gpio_pin_get_dt(&config->irq_gpio)); in nct38xx_alert_worker()
120 const struct nct38xx_alert_config *const config = dev->config; in nct38xx_alert_init()
121 struct nct38xx_alert_data *const data = dev->data; in nct38xx_alert_init()
124 /* Check NCT38XX devices are all ready. */ in nct38xx_alert_init()
125 for (int i = 0; i < config->nct38xx_num; i++) { in nct38xx_alert_init()
126 if (!device_is_ready(config->nct38xx_dev[i])) { in nct38xx_alert_init()
127 LOG_ERR("%s device not ready", config->nct38xx_dev[i]->name); in nct38xx_alert_init()
128 return -ENODEV; in nct38xx_alert_init()
131 data->mfd[i].lock = mfd_nct38xx_get_lock_reference(config->nct38xx_dev[i]); in nct38xx_alert_init()
132 data->mfd[i].i2c_dev = mfd_nct38xx_get_i2c_dt_spec(config->nct38xx_dev[i]); in nct38xx_alert_init()
136 k_work_init(&data->alert_worker, nct38xx_alert_worker); in nct38xx_alert_init()
138 if (!gpio_is_ready_dt(&config->irq_gpio)) { in nct38xx_alert_init()
139 LOG_ERR("%s device not ready", config->irq_gpio.port->name); in nct38xx_alert_init()
140 return -ENODEV; in nct38xx_alert_init()
143 gpio_pin_configure_dt(&config->irq_gpio, GPIO_INPUT); in nct38xx_alert_init()
145 gpio_init_callback(&data->gpio_cb, nct38xx_alert_callback, BIT(config->irq_gpio.pin)); in nct38xx_alert_init()
147 ret = gpio_add_callback(config->irq_gpio.port, &data->gpio_cb); in nct38xx_alert_init()
152 gpio_pin_interrupt_configure_dt(&config->irq_gpio, GPIO_INT_EDGE_TO_ACTIVE); in nct38xx_alert_init()
157 /* NCT38XX alert driver must be initialized after NCT38XX GPIO driver */