Lines Matching +full:pmic +full:- +full:int +full:- +full:pin

3  * SPDX-License-Identifier: Apache-2.0
87 k_work_submit(&data->work); in gpio_callback()
93 const struct mfd_npm1300_config *config = data->dev->config; in work_callback()
95 int ret; in work_callback()
98 ret = mfd_npm1300_reg_read_burst(data->dev, MAIN_BASE, 0U, buf, sizeof(buf)); in work_callback()
100 k_work_submit(&data->work); in work_callback()
104 for (int i = 0; i < NPM1300_EVENT_MAX; i++) { in work_callback()
105 int offset = event_reg[i].offset + MAIN_OFFSET_CLR; in work_callback()
108 gpio_fire_callbacks(&data->callbacks, data->dev, BIT(i)); in work_callback()
110 ret = mfd_npm1300_reg_write(data->dev, MAIN_BASE, offset, in work_callback()
113 k_work_submit(&data->work); in work_callback()
120 if (gpio_pin_get_dt(&config->host_int_gpios) != 0) { in work_callback()
121 k_work_submit(&data->work); in work_callback()
125 static int mfd_npm1300_init(const struct device *dev) in mfd_npm1300_init()
127 const struct mfd_npm1300_config *config = dev->config; in mfd_npm1300_init()
128 struct mfd_npm1300_data *mfd_data = dev->data; in mfd_npm1300_init()
129 int ret; in mfd_npm1300_init()
131 if (!i2c_is_ready_dt(&config->i2c)) { in mfd_npm1300_init()
132 return -ENODEV; in mfd_npm1300_init()
135 k_mutex_init(&mfd_data->mutex); in mfd_npm1300_init()
137 mfd_data->dev = dev; in mfd_npm1300_init()
139 if (config->host_int_gpios.port != NULL) { in mfd_npm1300_init()
140 /* Set specified PMIC pin to be interrupt output */ in mfd_npm1300_init()
141 ret = mfd_npm1300_reg_write(dev, GPIO_BASE, GPIO_OFFSET_MODE + config->pmic_int_pin, in mfd_npm1300_init()
148 if (!gpio_is_ready_dt(&config->host_int_gpios)) { in mfd_npm1300_init()
149 return -ENODEV; in mfd_npm1300_init()
152 ret = gpio_pin_configure_dt(&config->host_int_gpios, GPIO_INPUT); in mfd_npm1300_init()
157 gpio_init_callback(&mfd_data->gpio_cb, gpio_callback, in mfd_npm1300_init()
158 BIT(config->host_int_gpios.pin)); in mfd_npm1300_init()
160 ret = gpio_add_callback(config->host_int_gpios.port, &mfd_data->gpio_cb); in mfd_npm1300_init()
165 mfd_data->work.handler = work_callback; in mfd_npm1300_init()
167 ret = gpio_pin_interrupt_configure_dt(&config->host_int_gpios, in mfd_npm1300_init()
174 ret = mfd_npm1300_reg_write(dev, SHIP_BASE, SHIP_OFFSET_CONFIG, config->active_time); in mfd_npm1300_init()
179 ret = mfd_npm1300_reg_write(dev, SHIP_BASE, SHIP_OFFSET_LPCONFIG, config->lp_reset); in mfd_npm1300_init()
187 int mfd_npm1300_reg_read_burst(const struct device *dev, uint8_t base, uint8_t offset, void *data, in mfd_npm1300_reg_read_burst()
190 const struct mfd_npm1300_config *config = dev->config; in mfd_npm1300_reg_read_burst()
193 return i2c_write_read_dt(&config->i2c, buff, sizeof(buff), data, len); in mfd_npm1300_reg_read_burst()
196 int mfd_npm1300_reg_read(const struct device *dev, uint8_t base, uint8_t offset, uint8_t *data) in mfd_npm1300_reg_read()
201 int mfd_npm1300_reg_write(const struct device *dev, uint8_t base, uint8_t offset, uint8_t data) in mfd_npm1300_reg_write()
203 const struct mfd_npm1300_config *config = dev->config; in mfd_npm1300_reg_write()
206 return i2c_write_dt(&config->i2c, buff, sizeof(buff)); in mfd_npm1300_reg_write()
209 int mfd_npm1300_reg_write2(const struct device *dev, uint8_t base, uint8_t offset, uint8_t data1, in mfd_npm1300_reg_write2()
212 const struct mfd_npm1300_config *config = dev->config; in mfd_npm1300_reg_write2()
215 return i2c_write_dt(&config->i2c, buff, sizeof(buff)); in mfd_npm1300_reg_write2()
218 int mfd_npm1300_reg_update(const struct device *dev, uint8_t base, uint8_t offset, uint8_t data, in mfd_npm1300_reg_update()
221 struct mfd_npm1300_data *mfd_data = dev->data; in mfd_npm1300_reg_update()
223 int ret; in mfd_npm1300_reg_update()
225 k_mutex_lock(&mfd_data->mutex, K_FOREVER); in mfd_npm1300_reg_update()
234 k_mutex_unlock(&mfd_data->mutex); in mfd_npm1300_reg_update()
239 int mfd_npm1300_set_timer(const struct device *dev, uint32_t time_ms) in mfd_npm1300_set_timer()
241 const struct mfd_npm1300_config *config = dev->config; in mfd_npm1300_set_timer()
246 return -EINVAL; in mfd_npm1300_set_timer()
251 int ret = i2c_write_dt(&config->i2c, buff, sizeof(buff)); in mfd_npm1300_set_timer()
260 int mfd_npm1300_reset(const struct device *dev) in mfd_npm1300_reset()
265 int mfd_npm1300_hibernate(const struct device *dev, uint32_t time_ms) in mfd_npm1300_hibernate()
267 int ret = mfd_npm1300_set_timer(dev, time_ms); in mfd_npm1300_hibernate()
276 int mfd_npm1300_add_callback(const struct device *dev, struct gpio_callback *callback) in mfd_npm1300_add_callback()
278 struct mfd_npm1300_data *data = dev->data; in mfd_npm1300_add_callback()
281 for (int i = 0; i < NPM1300_EVENT_MAX; i++) { in mfd_npm1300_add_callback()
282 if ((callback->pin_mask & BIT(i)) != 0U) { in mfd_npm1300_add_callback()
284 int ret = mfd_npm1300_reg_write(data->dev, MAIN_BASE, in mfd_npm1300_add_callback()
292 ret = mfd_npm1300_reg_write(data->dev, MAIN_BASE, in mfd_npm1300_add_callback()
301 return gpio_manage_callback(&data->callbacks, callback, true); in mfd_npm1300_add_callback()
304 int mfd_npm1300_remove_callback(const struct device *dev, struct gpio_callback *callback) in mfd_npm1300_remove_callback()
306 struct mfd_npm1300_data *data = dev->data; in mfd_npm1300_remove_callback()
308 return gpio_manage_callback(&data->callbacks, callback, false); in mfd_npm1300_remove_callback()