Lines Matching +full:gpio +full:- +full:n
4 * SPDX-License-Identifier: Apache-2.0
10 #include <zephyr/drivers/gpio.h>
12 #include <zephyr/drivers/gpio/gpio_utils.h>
19 /* Get GPIO instance */
21 ((const struct gpio_b91_config *)dev->config)->gpio_base)
23 /* Get GPIO IRQ number defined in dts */
24 #define GET_IRQ_NUM(dev) (((const struct gpio_b91_config *)dev->config)->irq_num)
26 /* Get GPIO IRQ priority defined in dts */
27 #define GET_IRQ_PRIORITY(dev) (((const struct gpio_b91_config *)dev->config)->irq_priority)
29 /* Get GPIO port number: port A - 0, port B - 1, ..., port F - 5 */
30 #define GET_PORT_NUM(gpio) ((uint8_t)(((uint32_t)gpio - DT_REG_ADDR(DT_NODELABEL(gpioa))) / \ argument
33 /* Check that gpio is port C */
34 #define IS_PORT_C(gpio) ((uint32_t)gpio == DT_REG_ADDR(DT_NODELABEL(gpioc))) argument
36 /* Check that gpio is port D */
37 #define IS_PORT_D(gpio) ((uint32_t)gpio == DT_REG_ADDR(DT_NODELABEL(gpiod))) argument
49 /* Pull-up/down resistors */
54 /* GPIO interrupt types */
66 /* B91 GPIO registers structure */
71 uint8_t output; /* Output: configure GPIO output */
74 uint8_t actas_gpio; /* Act as GPIO: enable (1) or disable (0) GPIO function */
75 uint8_t irq_en; /* Act as GPIO: enable (1) or disable (0) GPIO function */
78 /* GPIO driver configuration structure */
87 /* GPIO driver data structure */
99 volatile struct gpio_b91_t *gpio = GET_GPIO(dev); in gpiob_b91_irq_en_set() local
102 BM_SET(gpio->irq_en, BIT(pin)); in gpiob_b91_irq_en_set()
104 BM_SET(reg_irq_risc0_en(GET_PORT_NUM(gpio)), BIT(pin)); in gpiob_b91_irq_en_set()
106 BM_SET(reg_irq_risc1_en(GET_PORT_NUM(gpio)), BIT(pin)); in gpiob_b91_irq_en_set()
108 __ASSERT(false, "Not supported GPIO IRQ number."); in gpiob_b91_irq_en_set()
116 volatile struct gpio_b91_t *gpio = GET_GPIO(dev); in gpiob_b91_irq_en_clr() local
119 BM_CLR(gpio->irq_en, BIT(pin)); in gpiob_b91_irq_en_clr()
121 BM_CLR(reg_irq_risc0_en(GET_PORT_NUM(gpio)), BIT(pin)); in gpiob_b91_irq_en_clr()
123 BM_CLR(reg_irq_risc1_en(GET_PORT_NUM(gpio)), BIT(pin)); in gpiob_b91_irq_en_clr()
132 volatile struct gpio_b91_t *gpio = GET_GPIO(dev); in gpio_b91_irq_en_get() local
135 status = gpio->irq_en; in gpio_b91_irq_en_get()
137 status = reg_irq_risc0_en(GET_PORT_NUM(gpio)); in gpio_b91_irq_en_get()
139 status = reg_irq_risc1_en(GET_PORT_NUM(gpio)); in gpio_b91_irq_en_get()
169 volatile struct gpio_b91_t *gpio = GET_GPIO(dev); in gpio_b91_irq_set() local
186 BM_CLR(gpio->polarity, BIT(pin)); in gpio_b91_irq_set()
191 BM_SET(gpio->polarity, BIT(pin)); in gpio_b91_irq_set()
196 BM_CLR(gpio->polarity, BIT(pin)); in gpio_b91_irq_set()
201 BM_SET(gpio->polarity, BIT(pin)); in gpio_b91_irq_set()
220 /* Set pin's pull-up/down resistor */
221 static void gpio_b91_up_down_res_set(volatile struct gpio_b91_t *gpio, in gpio_b91_up_down_res_set() argument
231 analog_reg = 0x0e + (GET_PORT_NUM(gpio) << 1) + ((pin & 0xf0) ? 1 : 0); in gpio_b91_up_down_res_set()
252 /* Config Pin pull-up / pull-down resistors */
253 static void gpio_b91_config_up_down_res(volatile struct gpio_b91_t *gpio, in gpio_b91_config_up_down_res() argument
258 gpio_b91_up_down_res_set(gpio, pin, GPIO_PIN_PULLUP_10K); in gpio_b91_config_up_down_res()
260 gpio_b91_up_down_res_set(gpio, pin, GPIO_PIN_PULLDOWN_100K); in gpio_b91_config_up_down_res()
262 gpio_b91_up_down_res_set(gpio, pin, GPIO_PIN_UP_DOWN_FLOAT); in gpio_b91_config_up_down_res()
267 static void gpio_b91_config_in_out(volatile struct gpio_b91_t *gpio, in gpio_b91_config_in_out() argument
274 if (IS_PORT_C(gpio)) { in gpio_b91_config_in_out()
276 } else if (IS_PORT_D(gpio)) { in gpio_b91_config_in_out()
281 WRITE_BIT(gpio->oen, pin, ~flags & GPIO_OUTPUT); in gpio_b91_config_in_out()
292 /* Input Enable registers of all other ports are located in common GPIO space */ in gpio_b91_config_in_out()
293 WRITE_BIT(gpio->ie, pin, flags & GPIO_INPUT); in gpio_b91_config_in_out()
297 /* GPIO driver initialization */
300 const struct gpio_b91_config *cfg = dev->config; in gpio_b91_init()
302 cfg->pirq_connect(); in gpio_b91_init()
312 volatile struct gpio_b91_t *gpio = GET_GPIO(dev); in gpio_b91_pin_configure() local
316 return -ENOTSUP; in gpio_b91_pin_configure()
319 /* Check input parameters: open-source and open-drain */ in gpio_b91_pin_configure()
321 return -ENOTSUP; in gpio_b91_pin_configure()
326 return -ENOTSUP; in gpio_b91_pin_configure()
329 /* Set GPIO init state if defined to avoid glitches */ in gpio_b91_pin_configure()
331 gpio->output |= BIT(pin); in gpio_b91_pin_configure()
333 gpio->output &= ~BIT(pin); in gpio_b91_pin_configure()
336 /* GPIO function enable */ in gpio_b91_pin_configure()
337 WRITE_BIT(gpio->actas_gpio, BIT(pin), 1); in gpio_b91_pin_configure()
339 /* Set GPIO pull-up / pull-down resistors */ in gpio_b91_pin_configure()
340 gpio_b91_config_up_down_res(gpio, pin, flags); in gpio_b91_pin_configure()
343 gpio_b91_config_in_out(gpio, pin, flags); in gpio_b91_pin_configure()
352 volatile struct gpio_b91_t *gpio = GET_GPIO(dev); in gpio_b91_port_get_raw() local
354 *value = gpio->input; in gpio_b91_port_get_raw()
364 volatile struct gpio_b91_t *gpio = GET_GPIO(dev); in gpio_b91_port_set_masked_raw() local
366 gpio->output = (gpio->output & ~mask) | (value & mask); in gpio_b91_port_set_masked_raw()
375 volatile struct gpio_b91_t *gpio = GET_GPIO(dev); in gpio_b91_port_set_bits_raw() local
377 gpio->output |= mask; in gpio_b91_port_set_bits_raw()
386 volatile struct gpio_b91_t *gpio = GET_GPIO(dev); in gpio_b91_port_clear_bits_raw() local
388 gpio->output &= ~mask; in gpio_b91_port_clear_bits_raw()
397 volatile struct gpio_b91_t *gpio = GET_GPIO(dev); in gpio_b91_port_toggle_bits() local
399 gpio->output ^= mask; in gpio_b91_port_toggle_bits()
409 struct gpio_b91_data *data = dev->data; in gpio_b91_irq_handler()
414 gpio_fire_callbacks(&data->callbacks, dev, status); in gpio_b91_irq_handler()
427 case GPIO_INT_MODE_DISABLED: /* GPIO interrupt disable */ in gpio_b91_pin_interrupt_configure()
432 if (trig == GPIO_INT_TRIG_HIGH) { /* GPIO interrupt High level */ in gpio_b91_pin_interrupt_configure()
434 } else if (trig == GPIO_INT_TRIG_LOW) { /* GPIO interrupt Low level */ in gpio_b91_pin_interrupt_configure()
437 ret_status = -ENOTSUP; in gpio_b91_pin_interrupt_configure()
442 if (trig == GPIO_INT_TRIG_HIGH) { /* GPIO interrupt Rising edge */ in gpio_b91_pin_interrupt_configure()
444 } else if (trig == GPIO_INT_TRIG_LOW) { /* GPIO interrupt Falling edge */ in gpio_b91_pin_interrupt_configure()
447 ret_status = -ENOTSUP; in gpio_b91_pin_interrupt_configure()
452 ret_status = -ENOTSUP; in gpio_b91_pin_interrupt_configure()
464 struct gpio_b91_data *data = dev->data; in gpio_b91_manage_callback()
466 return gpio_manage_callback(&data->callbacks, callback, set); in gpio_b91_manage_callback()
469 /* GPIO driver APIs structure */
470 static DEVICE_API(gpio, gpio_b91_driver_api) = {
541 /* GPIO driver registration */
542 #define GPIO_B91_INIT(n) \ argument
543 static const struct gpio_b91_config gpio_b91_config_##n = { \
545 .port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(n) \
547 .gpio_base = DT_INST_REG_ADDR(n), \
548 .irq_num = DT_INST_IRQN(n), \
549 .irq_priority = DT_INST_IRQ(n, priority), \
550 .pirq_connect = gpio_b91_irq_connect_##n \
552 static struct gpio_b91_data gpio_b91_data_##n; \
554 DEVICE_DT_INST_DEFINE(n, gpio_b91_init, \
556 &gpio_b91_data_##n, \
557 &gpio_b91_config_##n, \