Lines Matching +full:reg +full:- +full:offset
3 * SPDX-License-Identifier: Apache-2.0
62 uint8_t offset; member
87 k_work_submit(&data->work); in gpio_callback()
93 const struct mfd_npm1300_config *config = data->dev->config; 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()
105 int offset = event_reg[i].offset + MAIN_OFFSET_CLR; in work_callback() local
107 if ((buf[offset] & event_reg[i].mask) != 0U) { 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()
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()
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()
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() argument
190 const struct mfd_npm1300_config *config = dev->config; in mfd_npm1300_reg_read_burst()
191 uint8_t buff[] = {base, offset}; 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() argument
198 return mfd_npm1300_reg_read_burst(dev, base, offset, data, 1U); 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() argument
203 const struct mfd_npm1300_config *config = dev->config; in mfd_npm1300_reg_write()
204 uint8_t buff[] = {base, offset, data}; 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() argument
212 const struct mfd_npm1300_config *config = dev->config; in mfd_npm1300_reg_write2()
213 uint8_t buff[] = {base, offset, data1, data2}; 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() argument
221 struct mfd_npm1300_data *mfd_data = dev->data; in mfd_npm1300_reg_update()
222 uint8_t reg; in mfd_npm1300_reg_update() local
225 k_mutex_lock(&mfd_data->mutex, K_FOREVER); in mfd_npm1300_reg_update()
227 ret = mfd_npm1300_reg_read(dev, base, offset, ®); in mfd_npm1300_reg_update()
230 reg = (reg & ~mask) | (data & mask); in mfd_npm1300_reg_update()
231 ret = mfd_npm1300_reg_write(dev, base, offset, reg); in mfd_npm1300_reg_update()
234 k_mutex_unlock(&mfd_data->mutex); in mfd_npm1300_reg_update()
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()
278 struct mfd_npm1300_data *data = dev->data; 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()
285 event_reg[i].offset + MAIN_OFFSET_CLR, in mfd_npm1300_add_callback()
292 ret = mfd_npm1300_reg_write(data->dev, MAIN_BASE, in mfd_npm1300_add_callback()
293 event_reg[i].offset + MAIN_OFFSET_INTENSET, in mfd_npm1300_add_callback()
301 return gpio_manage_callback(&data->callbacks, callback, true); in mfd_npm1300_add_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()