Lines Matching +full:in +full:- +full:trig +full:- +full:gpios

4  * SPDX-License-Identifier: Apache-2.0
43 const struct gpio_nct38xx_port_config *const config = dev->config; in gpio_nct38xx_pin_config()
44 struct gpio_nct38xx_port_data *const data = dev->data; in gpio_nct38xx_pin_config()
49 /* Don't support simultaneous in/out mode */ in gpio_nct38xx_pin_config()
51 return -ENOTSUP; in gpio_nct38xx_pin_config()
56 return -ENOTSUP; in gpio_nct38xx_pin_config()
59 /* Don't support pull-up/pull-down */ in gpio_nct38xx_pin_config()
61 return -ENOTSUP; in gpio_nct38xx_pin_config()
64 k_sem_take(data->lock, K_FOREVER); in gpio_nct38xx_pin_config()
67 if (config->gpio_port == 0) { in gpio_nct38xx_pin_config()
70 * of non-reserved bits. in gpio_nct38xx_pin_config()
72 new_reg = BIT(pin) & config->pinmux_mask; in gpio_nct38xx_pin_config()
73 mask = BIT(pin) | ~config->pinmux_mask; in gpio_nct38xx_pin_config()
75 ret = i2c_reg_update_byte_dt(data->i2c_dev, NCT38XX_REG_MUX_CONTROL, mask, new_reg); in gpio_nct38xx_pin_config()
86 ret = i2c_reg_update_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_DIR(config->gpio_port), in gpio_nct38xx_pin_config()
92 /* Select open drain 0:push-pull 1:open-drain */ in gpio_nct38xx_pin_config()
99 ret = i2c_reg_update_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_OD_SEL(config->gpio_port), in gpio_nct38xx_pin_config()
111 ret = i2c_reg_update_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_DATA_OUT(config->gpio_port), in gpio_nct38xx_pin_config()
120 ret = i2c_reg_update_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_DIR(config->gpio_port), in gpio_nct38xx_pin_config()
125 k_sem_give(data->lock); in gpio_nct38xx_pin_config()
132 const struct gpio_nct38xx_port_config *const config = dev->config; in gpio_nct38xx_pin_get_config()
133 struct gpio_nct38xx_port_data *const data = dev->data; in gpio_nct38xx_pin_get_config()
138 k_sem_take(data->lock, K_FOREVER); in gpio_nct38xx_pin_get_config()
140 if (config->gpio_port == 0) { in gpio_nct38xx_pin_get_config()
141 if (mask & (~config->common.port_pin_mask)) { in gpio_nct38xx_pin_get_config()
142 ret = -ENOTSUP; in gpio_nct38xx_pin_get_config()
146 ret = i2c_reg_read_byte_dt(data->i2c_dev, NCT38XX_REG_MUX_CONTROL, &reg); in gpio_nct38xx_pin_get_config()
151 if ((mask & config->pinmux_mask) && (mask & (~reg))) { in gpio_nct38xx_pin_get_config()
157 ret = i2c_reg_read_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_DIR(config->gpio_port), &reg); in gpio_nct38xx_pin_get_config()
166 /* 0 - push-pull, 1 - open-drain */ in gpio_nct38xx_pin_get_config()
167 ret = i2c_reg_read_byte_dt(data->i2c_dev, in gpio_nct38xx_pin_get_config()
168 NCT38XX_REG_GPIO_OD_SEL(config->gpio_port), &reg); in gpio_nct38xx_pin_get_config()
178 ret = i2c_reg_read_byte_dt(data->i2c_dev, in gpio_nct38xx_pin_get_config()
179 NCT38XX_REG_GPIO_DATA_OUT(config->gpio_port), &reg); in gpio_nct38xx_pin_get_config()
195 k_sem_give(data->lock); in gpio_nct38xx_pin_get_config()
203 const struct gpio_nct38xx_port_config *const config = dev->config; in gpio_nct38xx_port_get_raw()
204 struct gpio_nct38xx_port_data *const data = dev->data; in gpio_nct38xx_port_get_raw()
206 k_sem_take(data->lock, K_FOREVER); in gpio_nct38xx_port_get_raw()
208 ret = i2c_reg_read_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_DATA_IN(config->gpio_port), in gpio_nct38xx_port_get_raw()
211 k_sem_give(data->lock); in gpio_nct38xx_port_get_raw()
218 const struct gpio_nct38xx_port_config *const config = dev->config; in gpio_nct38xx_port_set_masked_raw()
219 struct gpio_nct38xx_port_data *const data = dev->data; in gpio_nct38xx_port_set_masked_raw()
222 k_sem_take(data->lock, K_FOREVER); in gpio_nct38xx_port_set_masked_raw()
224 ret = i2c_reg_update_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_DATA_OUT(config->gpio_port), in gpio_nct38xx_port_set_masked_raw()
227 k_sem_give(data->lock); in gpio_nct38xx_port_set_masked_raw()
234 const struct gpio_nct38xx_port_config *const config = dev->config; in gpio_nct38xx_port_set_bits_raw()
235 struct gpio_nct38xx_port_data *const data = dev->data; in gpio_nct38xx_port_set_bits_raw()
238 k_sem_take(data->lock, K_FOREVER); in gpio_nct38xx_port_set_bits_raw()
240 ret = i2c_reg_update_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_DATA_OUT(config->gpio_port), in gpio_nct38xx_port_set_bits_raw()
243 k_sem_give(data->lock); in gpio_nct38xx_port_set_bits_raw()
250 const struct gpio_nct38xx_port_config *const config = dev->config; in gpio_nct38xx_port_clear_bits_raw()
251 struct gpio_nct38xx_port_data *const data = dev->data; in gpio_nct38xx_port_clear_bits_raw()
254 k_sem_take(data->lock, K_FOREVER); in gpio_nct38xx_port_clear_bits_raw()
256 ret = i2c_reg_update_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_DATA_OUT(config->gpio_port), in gpio_nct38xx_port_clear_bits_raw()
259 k_sem_give(data->lock); in gpio_nct38xx_port_clear_bits_raw()
266 const struct gpio_nct38xx_port_config *const config = dev->config; in gpio_nct38xx_port_toggle_bits()
267 struct gpio_nct38xx_port_data *const data = dev->data; in gpio_nct38xx_port_toggle_bits()
271 k_sem_take(data->lock, K_FOREVER); in gpio_nct38xx_port_toggle_bits()
273 ret = i2c_reg_read_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_DATA_OUT(config->gpio_port), in gpio_nct38xx_port_toggle_bits()
280 ret = i2c_reg_write_byte_dt(data->i2c_dev, in gpio_nct38xx_port_toggle_bits()
281 NCT38XX_REG_GPIO_DATA_OUT(config->gpio_port), new_reg); in gpio_nct38xx_port_toggle_bits()
285 k_sem_give(data->lock); in gpio_nct38xx_port_toggle_bits()
291 enum gpio_int_mode mode, enum gpio_int_trig trig) in gpio_nct38xx_pin_interrupt_configure() argument
293 const struct gpio_nct38xx_port_config *const config = dev->config; in gpio_nct38xx_pin_interrupt_configure()
294 struct gpio_nct38xx_port_data *const data = dev->data; in gpio_nct38xx_pin_interrupt_configure()
299 k_sem_take(data->lock, K_FOREVER); in gpio_nct38xx_pin_interrupt_configure()
303 ret = i2c_reg_update_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_ALERT_MASK(config->gpio_port), in gpio_nct38xx_pin_interrupt_configure()
313 if (trig == GPIO_INT_TRIG_LOW) { in gpio_nct38xx_pin_interrupt_configure()
316 } else if (trig == GPIO_INT_TRIG_HIGH) { in gpio_nct38xx_pin_interrupt_configure()
319 } else if (trig == GPIO_INT_TRIG_BOTH) { in gpio_nct38xx_pin_interrupt_configure()
323 LOG_ERR("Invalid interrupt trigger type %d", trig); in gpio_nct38xx_pin_interrupt_configure()
324 return -EINVAL; in gpio_nct38xx_pin_interrupt_configure()
332 ret = i2c_reg_update_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_ALERT_RISE(config->gpio_port), in gpio_nct38xx_pin_interrupt_configure()
338 ret = i2c_reg_update_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_ALERT_FALL(config->gpio_port), in gpio_nct38xx_pin_interrupt_configure()
346 if (trig == GPIO_INT_TRIG_LOW) { in gpio_nct38xx_pin_interrupt_configure()
348 } else if (trig == GPIO_INT_TRIG_HIGH) { in gpio_nct38xx_pin_interrupt_configure()
351 LOG_ERR("Invalid interrupt trigger type %d", trig); in gpio_nct38xx_pin_interrupt_configure()
352 ret = -EINVAL; in gpio_nct38xx_pin_interrupt_configure()
355 ret = i2c_reg_update_byte_dt(data->i2c_dev, in gpio_nct38xx_pin_interrupt_configure()
356 NCT38XX_REG_GPIO_ALERT_LEVEL(config->gpio_port), mask, in gpio_nct38xx_pin_interrupt_configure()
365 ret = i2c_reg_write_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_ALERT_STAT(config->gpio_port), in gpio_nct38xx_pin_interrupt_configure()
373 ret = i2c_reg_update_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_ALERT_MASK(config->gpio_port), in gpio_nct38xx_pin_interrupt_configure()
377 k_sem_give(data->lock); in gpio_nct38xx_pin_interrupt_configure()
385 struct gpio_nct38xx_port_data *const data = dev->data; in gpio_nct38xx_manage_callback()
387 return gpio_manage_callback(&data->cb_list_gpio, callback, set); in gpio_nct38xx_manage_callback()
394 const struct gpio_nct38xx_port_config *const config = dev->config; in gpio_nct38xx_port_get_direction()
395 struct gpio_nct38xx_port_data *const data = dev->data; in gpio_nct38xx_port_get_direction()
399 k_sem_take(data->lock, K_FOREVER); in gpio_nct38xx_port_get_direction()
401 if (config->gpio_port == 0) { in gpio_nct38xx_port_get_direction()
403 /* Remove the disabled GPIOs from the mask */ in gpio_nct38xx_port_get_direction()
404 ret = i2c_reg_read_byte_dt(data->i2c_dev, NCT38XX_REG_MUX_CONTROL, &enabled_gpios); in gpio_nct38xx_port_get_direction()
405 mask &= (enabled_gpios & config->common.port_pin_mask); in gpio_nct38xx_port_get_direction()
412 /* Read direction register, 0 - input, 1 - output */ in gpio_nct38xx_port_get_direction()
413 ret = i2c_reg_read_byte_dt(data->i2c_dev, NCT38XX_REG_GPIO_DIR(config->gpio_port), in gpio_nct38xx_port_get_direction()
428 k_sem_give(data->lock); in gpio_nct38xx_port_get_direction()
435 const struct gpio_nct38xx_port_config *const config = dev->config; in gpio_nct38xx_dispatch_port_isr()
436 struct gpio_nct38xx_port_data *const data = dev->data; in gpio_nct38xx_dispatch_port_isr()
441 k_sem_take(data->lock, K_FOREVER); in gpio_nct38xx_dispatch_port_isr()
443 data->i2c_dev, NCT38XX_REG_GPIO_ALERT_STAT(config->gpio_port), &alert_pins); in gpio_nct38xx_dispatch_port_isr()
445 k_sem_give(data->lock); in gpio_nct38xx_dispatch_port_isr()
449 ret = i2c_reg_read_byte_dt(data->i2c_dev, in gpio_nct38xx_dispatch_port_isr()
450 NCT38XX_REG_GPIO_ALERT_MASK(config->gpio_port), &mask); in gpio_nct38xx_dispatch_port_isr()
452 k_sem_give(data->lock); in gpio_nct38xx_dispatch_port_isr()
457 ret = i2c_reg_write_byte_dt(data->i2c_dev, in gpio_nct38xx_dispatch_port_isr()
458 NCT38XX_REG_GPIO_ALERT_STAT(config->gpio_port), in gpio_nct38xx_dispatch_port_isr()
461 k_sem_give(data->lock); in gpio_nct38xx_dispatch_port_isr()
465 k_sem_give(data->lock); in gpio_nct38xx_dispatch_port_isr()
467 gpio_fire_callbacks(&data->cb_list_gpio, dev, alert_pins); in gpio_nct38xx_dispatch_port_isr()
498 const struct gpio_nct38xx_port_config *const config = dev->config; in gpio_nct38xx_port_init()
499 struct gpio_nct38xx_port_data *const data = dev->data; in gpio_nct38xx_port_init()
501 if (!device_is_ready(config->mfd)) { in gpio_nct38xx_port_init()
502 LOG_ERR("%s is not ready", config->mfd->name); in gpio_nct38xx_port_init()
503 return -ENODEV; in gpio_nct38xx_port_init()
506 data->lock = mfd_nct38xx_get_lock_reference(config->mfd); in gpio_nct38xx_port_init()
507 data->i2c_dev = mfd_nct38xx_get_i2c_dt_spec(config->mfd); in gpio_nct38xx_port_init()