Lines Matching +full:set +full:- +full:bit +full:- +full:to +full:- +full:deassert

4  * SPDX-License-Identifier: Apache-2.0
20 #define AW9523B_GPOMD BIT(4)
61 const struct gpio_aw9523b_config *const config = dev->config; in gpio_aw9523b_pin_configure()
63 const uint8_t mask = BIT(pin % 8); in gpio_aw9523b_pin_configure()
70 return -EWOULDBLOCK; in gpio_aw9523b_pin_configure()
73 /* Either INPUT or OUTPUT must be set */ in gpio_aw9523b_pin_configure()
76 return -ENOTSUP; in gpio_aw9523b_pin_configure()
79 /* Open-drain support is per port, not per pin. in gpio_aw9523b_pin_configure()
80 * So can't really support the API as-is. in gpio_aw9523b_pin_configure()
82 if (port == 0 && !config->port0_push_pull) { in gpio_aw9523b_pin_configure()
84 return -ENOTSUP; in gpio_aw9523b_pin_configure()
88 return -ENOTSUP; in gpio_aw9523b_pin_configure()
93 return -ENOTSUP; in gpio_aw9523b_pin_configure()
96 k_sem_take(aw9523b_get_lock(config->mfd_dev), K_FOREVER); in gpio_aw9523b_pin_configure()
98 err = i2c_reg_update_byte_dt(&config->i2c, AW9523B_REG_CONFIG(port), mask, input_en); in gpio_aw9523b_pin_configure()
100 LOG_ERR("%s: Failed to set pin%d direction (%d)", dev->name, pin, err); in gpio_aw9523b_pin_configure()
105 if (config->int_gpio.port) { in gpio_aw9523b_pin_configure()
107 struct gpio_aw9523b_data *const data = dev->data; in gpio_aw9523b_pin_configure()
111 err = i2c_burst_read_dt(&config->i2c, AW9523B_REG_INPUT0, buf, sizeof(buf)); in gpio_aw9523b_pin_configure()
113 LOG_ERR("%s: Read initial pin state failed (%d)", dev->name, err); in gpio_aw9523b_pin_configure()
117 WRITE_BIT(data->prev_value, pin, sys_get_le16(buf) & BIT(pin)); in gpio_aw9523b_pin_configure()
119 struct gpio_aw9523b_data *const data = dev->data; in gpio_aw9523b_pin_configure()
121 WRITE_BIT(data->falling_event_pins, pin, 0); in gpio_aw9523b_pin_configure()
122 WRITE_BIT(data->rising_event_pins, pin, 0); in gpio_aw9523b_pin_configure()
127 err = i2c_reg_update_byte_dt(&config->i2c, AW9523B_REG_OUTPUT(port), mask, out_high); in gpio_aw9523b_pin_configure()
129 LOG_ERR("%s: Failed to set initial pin state (%d)", dev->name, err); in gpio_aw9523b_pin_configure()
134 k_sem_give(aw9523b_get_lock(config->mfd_dev)); in gpio_aw9523b_pin_configure()
143 * @param[in] mask Register mask to select pins to operate.
144 * @param[in,out] value When mode is READ, this param is pointer to result value storing region.
153 const struct gpio_aw9523b_config *const config = dev->config; in gpio_aw9523b_port_read_write_toggle()
161 return -EWOULDBLOCK; in gpio_aw9523b_port_read_write_toggle()
164 k_sem_take(aw9523b_get_lock(config->mfd_dev), K_FOREVER); in gpio_aw9523b_port_read_write_toggle()
168 * to keep the internal state correct. in gpio_aw9523b_port_read_write_toggle()
170 err = i2c_burst_read_dt(&config->i2c, AW9523B_REG_INPUT0, &buf[0], 1); in gpio_aw9523b_port_read_write_toggle()
172 LOG_ERR("%s: Failed to read port0 status (%d)", dev->name, err); in gpio_aw9523b_port_read_write_toggle()
175 err = i2c_burst_read_dt(&config->i2c, AW9523B_REG_INPUT1, &buf[1], 1); in gpio_aw9523b_port_read_write_toggle()
177 LOG_ERR("%s: Failed to read port1 status (%d)", dev->name, err); in gpio_aw9523b_port_read_write_toggle()
198 err = i2c_burst_write_dt(&config->i2c, AW9523B_REG_OUTPUT0, buf, sizeof(buf)); in gpio_aw9523b_port_read_write_toggle()
200 LOG_ERR("%s: Failed to set port (%d)", dev->name, err); in gpio_aw9523b_port_read_write_toggle()
204 k_sem_give(aw9523b_get_lock(config->mfd_dev)); in gpio_aw9523b_port_read_write_toggle()
246 const struct gpio_aw9523b_config *const config = data->dev->config; in gpio_aw9523b_interrupt_worker()
252 * We need to read INPUT0 to deassert INTN when that is asserted by in gpio_aw9523b_interrupt_worker()
253 * pin0-7 interruption, and same also INPUT1 for pin8-15. in gpio_aw9523b_interrupt_worker()
254 * It cannot deassert by burst-read. in gpio_aw9523b_interrupt_worker()
256 err = i2c_burst_read_dt(&config->i2c, AW9523B_REG_INPUT0, &buf[0], 1); in gpio_aw9523b_interrupt_worker()
258 LOG_ERR("%s: Failed to read INPUT0 %d", data->dev->name, err); in gpio_aw9523b_interrupt_worker()
260 err = i2c_burst_read_dt(&config->i2c, AW9523B_REG_INPUT1, &buf[1], 1); in gpio_aw9523b_interrupt_worker()
262 LOG_ERR("%s: Failed to read INPUT1 %d", data->dev->name, err); in gpio_aw9523b_interrupt_worker()
267 rising = (value ^ data->prev_value) & (value & data->rising_event_pins); in gpio_aw9523b_interrupt_worker()
268 falling = (value ^ data->prev_value) & (~value & data->falling_event_pins); in gpio_aw9523b_interrupt_worker()
270 data->prev_value = value; in gpio_aw9523b_interrupt_worker()
272 gpio_fire_callbacks(&data->callbacks, data->dev, rising | falling); in gpio_aw9523b_interrupt_worker()
280 const struct gpio_aw9523b_config *const config = dev->config; in gpio_aw9523b_pin_interrupt_configure()
281 struct gpio_aw9523b_data *const data = dev->data; in gpio_aw9523b_pin_interrupt_configure()
283 const uint8_t mask = BIT(port ? pin - 8 : pin); in gpio_aw9523b_pin_interrupt_configure()
290 return -EWOULDBLOCK; in gpio_aw9523b_pin_interrupt_configure()
294 return -ENOTSUP; in gpio_aw9523b_pin_interrupt_configure()
296 if (data->common.invert & BIT(pin)) { in gpio_aw9523b_pin_interrupt_configure()
297 WRITE_BIT(data->falling_event_pins, pin, trig & GPIO_INT_HIGH_1); in gpio_aw9523b_pin_interrupt_configure()
298 WRITE_BIT(data->rising_event_pins, pin, trig & GPIO_INT_LOW_0); in gpio_aw9523b_pin_interrupt_configure()
300 WRITE_BIT(data->falling_event_pins, pin, trig & GPIO_INT_LOW_0); in gpio_aw9523b_pin_interrupt_configure()
301 WRITE_BIT(data->rising_event_pins, pin, trig & GPIO_INT_HIGH_1); in gpio_aw9523b_pin_interrupt_configure()
304 k_sem_take(aw9523b_get_lock(config->mfd_dev), K_FOREVER); in gpio_aw9523b_pin_interrupt_configure()
306 err = i2c_reg_update_byte_dt(&config->i2c, AW9523B_REG_INT(port), mask, n_int_en); in gpio_aw9523b_pin_interrupt_configure()
308 LOG_ERR("%s: Failed to configure pin interruption (%d)", dev->name, err); in gpio_aw9523b_pin_interrupt_configure()
314 err = i2c_burst_read_dt(&config->i2c, AW9523B_REG_INPUT0, buf, sizeof(buf)); in gpio_aw9523b_pin_interrupt_configure()
316 LOG_ERR("%s: Failed to read initial pin state (%d)", dev->name, err); in gpio_aw9523b_pin_interrupt_configure()
320 WRITE_BIT(data->prev_value, pin, sys_get_le16(buf) & BIT(pin)); in gpio_aw9523b_pin_interrupt_configure()
322 WRITE_BIT(data->falling_event_pins, pin, 0); in gpio_aw9523b_pin_interrupt_configure()
323 WRITE_BIT(data->rising_event_pins, pin, 0); in gpio_aw9523b_pin_interrupt_configure()
327 k_sem_give(aw9523b_get_lock(config->mfd_dev)); in gpio_aw9523b_pin_interrupt_configure()
333 struct gpio_callback *callback, bool set) in gpio_aw9523b_manage_callback() argument
335 const struct gpio_aw9523b_config *const config = dev->config; in gpio_aw9523b_manage_callback()
336 struct gpio_aw9523b_data *const data = dev->data; in gpio_aw9523b_manage_callback()
339 k_sem_take(aw9523b_get_lock(config->mfd_dev), K_FOREVER); in gpio_aw9523b_manage_callback()
341 err = gpio_manage_callback(&data->callbacks, callback, set); in gpio_aw9523b_manage_callback()
343 LOG_ERR("%s: gpio_manage_callback failed (%d)", dev->name, err); in gpio_aw9523b_manage_callback()
346 k_sem_give(aw9523b_get_lock(config->mfd_dev)); in gpio_aw9523b_manage_callback()
356 k_work_submit(&data->intr_worker); in gpio_aw9523b_int_handler()
374 const struct gpio_aw9523b_config *const config = dev->config; in gpio_aw9523b_init()
379 struct gpio_aw9523b_data *const data = dev->data; in gpio_aw9523b_init()
381 if (!config->int_gpio.port) { in gpio_aw9523b_init()
385 /* Store self-reference for interrupt handling */ in gpio_aw9523b_init()
386 data->dev = dev; in gpio_aw9523b_init()
389 k_work_init(&data->intr_worker, gpio_aw9523b_interrupt_worker); in gpio_aw9523b_init()
391 if (!gpio_is_ready_dt(&config->int_gpio)) { in gpio_aw9523b_init()
392 LOG_ERR("%s: Interrupt GPIO not ready", dev->name); in gpio_aw9523b_init()
393 return -ENODEV; in gpio_aw9523b_init()
396 err = gpio_pin_configure_dt(&config->int_gpio, GPIO_INPUT); in gpio_aw9523b_init()
398 LOG_ERR("%s: Failed to configure interrupt pin %d (%d)", dev->name, in gpio_aw9523b_init()
399 config->int_gpio.pin, err); in gpio_aw9523b_init()
403 err = gpio_pin_interrupt_configure_dt(&config->int_gpio, GPIO_INT_EDGE_TO_ACTIVE); in gpio_aw9523b_init()
405 LOG_ERR("%s: Failed to configure interrupt %d (%d)", dev->name, in gpio_aw9523b_init()
406 config->int_gpio.pin, err); in gpio_aw9523b_init()
410 gpio_init_callback(&data->gpio_callback, config->int_cb, BIT(config->int_gpio.pin)); in gpio_aw9523b_init()
411 err = gpio_add_callback(config->int_gpio.port, &data->gpio_callback); in gpio_aw9523b_init()
413 LOG_ERR("%s: Failed to add interrupt callback for pin %d (%d)", dev->name, in gpio_aw9523b_init()
414 config->int_gpio.pin, err); in gpio_aw9523b_init()
422 if (!config->reset_gpio.port) { in gpio_aw9523b_init()
426 if (!gpio_is_ready_dt(&config->reset_gpio)) { in gpio_aw9523b_init()
427 LOG_ERR("%s: Reset GPIO not ready", dev->name); in gpio_aw9523b_init()
428 return -ENODEV; in gpio_aw9523b_init()
431 err = gpio_pin_configure_dt(&config->reset_gpio, GPIO_OUTPUT_ACTIVE); in gpio_aw9523b_init()
433 LOG_ERR("%s: Failed to configure reset pin %d (%d)", dev->name, in gpio_aw9523b_init()
434 config->reset_gpio.pin, err); in gpio_aw9523b_init()
440 err = gpio_pin_set_dt(&config->reset_gpio, 0); in gpio_aw9523b_init()
442 LOG_ERR("%s: Failed to set 0 reset pin %d (%d)", dev->name, config->reset_gpio.pin, in gpio_aw9523b_init()
450 if (!device_is_ready(config->i2c.bus)) { in gpio_aw9523b_init()
451 return -ENODEV; in gpio_aw9523b_init()
454 k_sem_init(aw9523b_get_lock(config->mfd_dev), 1, 1); in gpio_aw9523b_init()
457 err = i2c_reg_read_byte_dt(&config->i2c, AW9523B_REG_SW_RSTN, buf); in gpio_aw9523b_init()
459 LOG_ERR("%s: Failed to software reset (%d)", dev->name, err); in gpio_aw9523b_init()
464 err = i2c_burst_write_dt(&config->i2c, AW9523B_REG_INT0, int_init_data, sizeof(buf)); in gpio_aw9523b_init()
466 LOG_ERR("%s: Failed to disable all interrupts (%d)", dev->name, err); in gpio_aw9523b_init()
470 if (!config->port0_push_pull) { in gpio_aw9523b_init()
471 /* Configure port0 to push-pull mode */ in gpio_aw9523b_init()
472 err = i2c_reg_update_byte_dt(&config->i2c, AW9523B_REG_CTL, AW9523B_GPOMD, 0xFF); in gpio_aw9523b_init()
474 LOG_ERR("%s: Failed to configure port0 to push-pull (%d)", dev->name, err); in gpio_aw9523b_init()