Skip to content

Commit 1ceb99d

Browse files
committed
[dm][pinctrl] new interface for 'pin_gpio_request'
Some GPIO should apply GPIO mode by pinctrl, add `pin_ctrl_gpio_request` for GPIO driver to apply it auto. Signed-off-by: GuEe-GUI <[email protected]>
1 parent 2fb53c8 commit 1ceb99d

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

components/drivers/include/drivers/dev_pin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ struct rt_pin_ops
224224
#endif
225225
#ifdef RT_USING_PINCTRL
226226
rt_err_t (*pin_ctrl_confs_apply)(struct rt_device *device, void *fw_conf_np);
227+
rt_err_t (*pin_ctrl_gpio_request)(struct rt_device *device, rt_base_t gpio, rt_uint32_t flags);
227228
#endif /* RT_USING_PINCTRL */
228229
};
229230

components/drivers/pin/dev_pin_dm.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,20 @@ rt_ssize_t rt_pin_get_named_pin_count(struct rt_device *dev, const char *propnam
456456

457457
return count;
458458
}
459+
460+
#ifdef RT_USING_PINCTRL
461+
rt_err_t pin_gpio_request(struct rt_device_pin *pinctrl, rt_base_t gpio, rt_uint32_t flags)
462+
{
463+
if (!pinctrl || gpio < 0)
464+
{
465+
return -RT_EINVAL;
466+
}
467+
468+
if (pinctrl->ops->pin_ctrl_gpio_request)
469+
{
470+
return pinctrl->ops->pin_ctrl_gpio_request(&pinctrl->parent, gpio, flags);
471+
}
472+
473+
return RT_EOK;
474+
}
475+
#endif /* RT_USING_PINCTRL */

components/drivers/pin/dev_pin_dm.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,47 @@
1515
#include <rtthread.h>
1616
#include <rtdevice.h>
1717

18+
/**
19+
* Bind GPIO pin to system PIN API
20+
*
21+
* @param gpio Pin device
22+
* @param pin_nr GPIO pin number
23+
*
24+
* @return RT_EOK on success, error code otherwise
25+
*/
1826
rt_err_t pin_api_init(struct rt_device_pin *gpio, rt_size_t pin_nr);
1927

28+
/**
29+
* Bind GPIO pin to system PIN PIC
30+
*
31+
* @param gpio Pin device
32+
* @param pin_irq GPIO irqno
33+
*
34+
* @return RT_EOK on success, error code otherwise
35+
*/
2036
rt_err_t pin_pic_init(struct rt_device_pin *gpio, int pin_irq);
37+
38+
/**
39+
* Handle GPIO one pin's ISR
40+
*
41+
* @param gpio Pin device
42+
* @param pin GPIO pin
43+
*
44+
* @return RT_EOK on success, error code otherwise
45+
*/
2146
rt_err_t pin_pic_handle_isr(struct rt_device_pin *gpio, rt_base_t pin);
2247

48+
#ifdef RT_USING_PINCTRL
49+
/**
50+
* Request GPIO pin configuration from pinctrl
51+
*
52+
* @param pinctrl Pinctrl device
53+
* @param gpio GPIO pin number
54+
* @param flags GPIO configuration flags
55+
*
56+
* @return RT_EOK on success, error code otherwise
57+
*/
58+
rt_err_t pin_gpio_request(struct rt_device_pin *pinctrl, rt_base_t gpio, rt_uint32_t flags);
59+
#endif
60+
2361
#endif /* __DEV_PIN_DM_H__ */

0 commit comments

Comments
 (0)