Lines Matching +full:rt1718s +full:- +full:gpio +full:- +full:port

4  * SPDX-License-Identifier: Apache-2.0
15 #include <zephyr/drivers/gpio.h>
16 #include <zephyr/drivers/gpio/gpio_utils.h>
24 /* RT1718S chip device */
32 /* GPIO callback list */
34 /* lock GPIO registers access */
38 /* GPIO api functions */
41 const struct gpio_rt1718s_port_config *const config = dev->config; in gpio_rt1718s_pin_config()
42 struct gpio_rt1718s_port_data *const data = dev->data; in gpio_rt1718s_pin_config()
48 return -ENOTSUP; in gpio_rt1718s_pin_config()
53 return -ENOTSUP; in gpio_rt1718s_pin_config()
56 /* RT1718S has 3 GPIOs so check range */ in gpio_rt1718s_pin_config()
58 return -EINVAL; in gpio_rt1718s_pin_config()
64 /* Set pull-high/low input */ in gpio_rt1718s_pin_config()
72 /* Set GPIO as output */ in gpio_rt1718s_pin_config()
75 /* Set push-pull or open-drain */ in gpio_rt1718s_pin_config()
86 k_sem_take(&data->lock, K_FOREVER); in gpio_rt1718s_pin_config()
87 ret = rt1718s_reg_write_byte(config->rt1718s_dev, RT1718S_REG_GPIO_CTRL(pin), new_reg); in gpio_rt1718s_pin_config()
88 k_sem_give(&data->lock); in gpio_rt1718s_pin_config()
95 const struct gpio_rt1718s_port_config *const config = dev->config; in gpio_rt1718s_port_get_raw()
99 ret = rt1718s_reg_read_byte(config->rt1718s_dev, RT1718S_REG_RT_ST8, &reg); in gpio_rt1718s_port_get_raw()
109 const struct gpio_rt1718s_port_config *const config = dev->config; in gpio_rt1718s_port_set_masked_raw()
110 struct gpio_rt1718s_port_data *const data = dev->data; in gpio_rt1718s_port_set_masked_raw()
114 k_sem_take(&data->lock, K_FOREVER); in gpio_rt1718s_port_set_masked_raw()
118 ret = rt1718s_reg_read_byte(config->rt1718s_dev, RT1718S_REG_GPIO_CTRL(pin), in gpio_rt1718s_port_set_masked_raw()
129 ret = rt1718s_reg_update(config->rt1718s_dev, RT1718S_REG_GPIO_CTRL(pin), in gpio_rt1718s_port_set_masked_raw()
134 k_sem_give(&data->lock); in gpio_rt1718s_port_set_masked_raw()
141 const struct gpio_rt1718s_port_config *const config = dev->config; in gpio_rt1718s_port_set_bits_raw()
142 struct gpio_rt1718s_port_data *const data = dev->data; in gpio_rt1718s_port_set_bits_raw()
146 k_sem_take(&data->lock, K_FOREVER); in gpio_rt1718s_port_set_bits_raw()
150 ret = rt1718s_reg_read_byte(config->rt1718s_dev, RT1718S_REG_GPIO_CTRL(pin), in gpio_rt1718s_port_set_bits_raw()
156 ret = rt1718s_reg_update(config->rt1718s_dev, RT1718S_REG_GPIO_CTRL(pin), in gpio_rt1718s_port_set_bits_raw()
161 k_sem_give(&data->lock); in gpio_rt1718s_port_set_bits_raw()
168 const struct gpio_rt1718s_port_config *const config = dev->config; in gpio_rt1718s_port_clear_bits_raw()
169 struct gpio_rt1718s_port_data *const data = dev->data; in gpio_rt1718s_port_clear_bits_raw()
173 k_sem_take(&data->lock, K_FOREVER); in gpio_rt1718s_port_clear_bits_raw()
177 ret = rt1718s_reg_read_byte(config->rt1718s_dev, RT1718S_REG_GPIO_CTRL(pin), in gpio_rt1718s_port_clear_bits_raw()
183 ret = rt1718s_reg_update(config->rt1718s_dev, RT1718S_REG_GPIO_CTRL(pin), in gpio_rt1718s_port_clear_bits_raw()
188 k_sem_give(&data->lock); in gpio_rt1718s_port_clear_bits_raw()
195 const struct gpio_rt1718s_port_config *const config = dev->config; in gpio_rt1718s_port_toggle_bits()
196 struct gpio_rt1718s_port_data *const data = dev->data; in gpio_rt1718s_port_toggle_bits()
200 k_sem_take(&data->lock, K_FOREVER); in gpio_rt1718s_port_toggle_bits()
204 ret = rt1718s_reg_read_byte(config->rt1718s_dev, RT1718S_REG_GPIO_CTRL(pin), in gpio_rt1718s_port_toggle_bits()
210 ret = rt1718s_reg_update(config->rt1718s_dev, RT1718S_REG_GPIO_CTRL(pin), in gpio_rt1718s_port_toggle_bits()
215 k_sem_give(&data->lock); in gpio_rt1718s_port_toggle_bits()
223 const struct gpio_rt1718s_port_config *const config = dev->config; in gpio_rt1718s_pin_interrupt_configure()
224 struct gpio_rt1718s_port_data *const data = dev->data; in gpio_rt1718s_pin_interrupt_configure()
225 struct rt1718s_data *const data_rt1718s = config->rt1718s_dev->data; in gpio_rt1718s_pin_interrupt_configure()
233 return -ENOTSUP; in gpio_rt1718s_pin_interrupt_configure()
236 k_sem_take(&data->lock, K_FOREVER); in gpio_rt1718s_pin_interrupt_configure()
237 k_sem_take(&data_rt1718s->lock_tcpci, K_FOREVER); in gpio_rt1718s_pin_interrupt_configure()
239 ret = rt1718s_reg_read_byte(config->rt1718s_dev, RT1718S_REG_RT_MASK8, &reg_mask8); in gpio_rt1718s_pin_interrupt_configure()
244 /* Disable GPIO interrupt */ in gpio_rt1718s_pin_interrupt_configure()
259 ret = -EINVAL; in gpio_rt1718s_pin_interrupt_configure()
263 ret = rt1718s_reg_burst_read(config->rt1718s_dev, RT1718S_REG_ALERT_MASK, in gpio_rt1718s_pin_interrupt_configure()
269 /* Enable Vendor Defined Alert for GPIO interrupts */ in gpio_rt1718s_pin_interrupt_configure()
272 ret = rt1718s_reg_burst_write(config->rt1718s_dev, RT1718S_REG_ALERT_MASK, in gpio_rt1718s_pin_interrupt_configure()
284 rt1718s_reg_write_byte(config->rt1718s_dev, RT1718S_REG_RT_INT8, reg_int8); in gpio_rt1718s_pin_interrupt_configure()
288 ret = rt1718s_reg_update(config->rt1718s_dev, RT1718S_REG_RT_MASK8, reg_mask8, in gpio_rt1718s_pin_interrupt_configure()
292 k_sem_give(&data_rt1718s->lock_tcpci); in gpio_rt1718s_pin_interrupt_configure()
293 k_sem_give(&data->lock); in gpio_rt1718s_pin_interrupt_configure()
301 struct gpio_rt1718s_port_data *const data = dev->data; in gpio_rt1718s_manage_callback()
303 return gpio_manage_callback(&data->cb_list_gpio, callback, set); in gpio_rt1718s_manage_callback()
308 const struct rt1718s_config *const config = dev->config; in rt1718s_gpio_alert_handler()
309 struct gpio_rt1718s_port_data *const data_port = config->gpio_port_dev->data; in rt1718s_gpio_alert_handler()
312 k_sem_take(&data_port->lock, K_FOREVER); in rt1718s_gpio_alert_handler()
314 /* Get mask and state of GPIO interrupts */ in rt1718s_gpio_alert_handler()
317 k_sem_give(&data_port->lock); in rt1718s_gpio_alert_handler()
326 k_sem_give(&data_port->lock); in rt1718s_gpio_alert_handler()
332 k_sem_give(&data_port->lock); in rt1718s_gpio_alert_handler()
335 /* Call the GPIO callbacks for rising *or* falling edge */ in rt1718s_gpio_alert_handler()
336 gpio_fire_callbacks(&data_port->cb_list_gpio, config->gpio_port_dev, in rt1718s_gpio_alert_handler()
341 static DEVICE_API(gpio, gpio_rt1718s_driver) = {
354 const struct gpio_rt1718s_port_config *const config = dev->config; in gpio_rt1718s_port_init()
355 struct gpio_rt1718s_port_data *const data = dev->data; in gpio_rt1718s_port_init()
357 if (!device_is_ready(config->rt1718s_dev)) { in gpio_rt1718s_port_init()
358 LOG_ERR("%s is not ready", config->rt1718s_dev->name); in gpio_rt1718s_port_init()
359 return -ENODEV; in gpio_rt1718s_port_init()
362 k_sem_init(&data->lock, 1, 1); in gpio_rt1718s_port_init()
367 /* RT1718S GPIO port driver must be initialized after RT1718S chip driver */