Lines Matching +full:pin +full:- +full:mask
4 * SPDX-License-Identifier: Apache-2.0
24 /* GPIO port 0 pinmux mask */
41 static int gpio_nct38xx_pin_config(const struct device *dev, gpio_pin_t pin, gpio_flags_t flags) in gpio_nct38xx_pin_config() argument
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()
45 uint32_t mask; in gpio_nct38xx_pin_config() local
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()
66 /* Pin multiplexing */ 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()
81 /* Configure pin as input. */ in gpio_nct38xx_pin_config()
85 mask = BIT(pin); 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()
87 mask, new_reg); in gpio_nct38xx_pin_config()
92 /* Select open drain 0:push-pull 1:open-drain */ in gpio_nct38xx_pin_config()
93 mask = BIT(pin); in gpio_nct38xx_pin_config()
95 new_reg = mask; 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()
100 mask, new_reg); in gpio_nct38xx_pin_config()
107 new_reg = mask; 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()
112 mask, new_reg); in gpio_nct38xx_pin_config()
117 /* Configure pin as output, if requested 0:input 1:output */ in gpio_nct38xx_pin_config()
119 new_reg = BIT(pin); 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()
121 mask, new_reg); in gpio_nct38xx_pin_config()
125 k_sem_give(data->lock); in gpio_nct38xx_pin_config()
130 int gpio_nct38xx_pin_get_config(const struct device *dev, gpio_pin_t pin, gpio_flags_t *flags) in gpio_nct38xx_pin_get_config() argument
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()
134 uint32_t mask = BIT(pin); in gpio_nct38xx_pin_get_config() local
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, ®); 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), ®); in gpio_nct38xx_pin_get_config()
162 if (reg & mask) { 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), ®); in gpio_nct38xx_pin_get_config()
173 if (mask & 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), ®); in gpio_nct38xx_pin_get_config()
184 if (mask & 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()
215 static int gpio_nct38xx_port_set_masked_raw(const struct device *dev, gpio_port_pins_t mask, in gpio_nct38xx_port_set_masked_raw() argument
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()
225 mask, value); in gpio_nct38xx_port_set_masked_raw()
227 k_sem_give(data->lock); in gpio_nct38xx_port_set_masked_raw()
232 static int gpio_nct38xx_port_set_bits_raw(const struct device *dev, gpio_port_pins_t mask) in gpio_nct38xx_port_set_bits_raw() argument
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()
241 mask, mask); in gpio_nct38xx_port_set_bits_raw()
243 k_sem_give(data->lock); in gpio_nct38xx_port_set_bits_raw()
248 static int gpio_nct38xx_port_clear_bits_raw(const struct device *dev, gpio_port_pins_t mask) in gpio_nct38xx_port_clear_bits_raw() argument
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()
257 mask, 0); in gpio_nct38xx_port_clear_bits_raw()
259 k_sem_give(data->lock); in gpio_nct38xx_port_clear_bits_raw()
264 static int gpio_nct38xx_port_toggle_bits(const struct device *dev, gpio_port_pins_t mask) in gpio_nct38xx_port_toggle_bits() argument
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()
278 new_reg = reg ^ mask; 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()
290 static int gpio_nct38xx_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, 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()
297 uint32_t mask = BIT(pin); in gpio_nct38xx_pin_interrupt_configure() local
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()
304 mask, new_reg); in gpio_nct38xx_pin_interrupt_configure()
315 new_fall = mask; in gpio_nct38xx_pin_interrupt_configure()
317 new_rise = mask; in gpio_nct38xx_pin_interrupt_configure()
320 new_rise = mask; in gpio_nct38xx_pin_interrupt_configure()
321 new_fall = mask; 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()
333 mask, new_rise); 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()
339 mask, new_fall); in gpio_nct38xx_pin_interrupt_configure()
349 new_reg = mask; 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()
366 mask); in gpio_nct38xx_pin_interrupt_configure()
372 new_reg = mask; 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()
374 mask, new_reg); 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()
391 static int gpio_nct38xx_port_get_direction(const struct device *dev, gpio_port_pins_t mask, in gpio_nct38xx_port_get_direction() argument
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()
420 *inputs = mask & (~dir_reg); in gpio_nct38xx_port_get_direction()
424 *outputs = mask & dir_reg; 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()
437 uint8_t alert_pins, mask; in gpio_nct38xx_dispatch_port_isr() local
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()
455 alert_pins &= mask; 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()