drivers: serial: uart_pl011: implemented pinctrl

Added pinctrl to pl011 uart driver. This makes it usable
with the rp2040.

Signed-off-by: Lukas Gehreke <lk.gehreke@gmail.com>
This commit is contained in:
Lukas Gehreke 2022-10-13 09:53:29 +02:00 committed by Carles Cufí
commit 6fa4d722a6
2 changed files with 24 additions and 2 deletions

View file

@ -14,6 +14,9 @@
#include <zephyr/device.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/sys/device_mmio.h>
#if IS_ENABLED(CONFIG_PINCTRL)
#include <zephyr/drivers/pinctrl.h>
#endif
#ifdef CONFIG_CPU_CORTEX_M
#include <cmsis_compiler.h>
@ -47,6 +50,9 @@ struct pl011_regs {
struct pl011_config {
DEVICE_MMIO_ROM;
uint32_t sys_clk_freq;
#if IS_ENABLED(CONFIG_PINCTRL)
const struct pinctrl_dev_config *pincfg;
#endif
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
uart_irq_config_func_t irq_config_func;
#endif
@ -388,6 +394,12 @@ static int pl011_init(const struct device *dev)
* virtualization software).
*/
if (!data->sbsa) {
#if IS_ENABLED(CONFIG_PINCTRL)
ret = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
if (ret) {
return ret;
}
#endif
/* disable the uart */
pl011_disable(dev);
pl011_disable_fifo(dev);
@ -429,6 +441,14 @@ static int pl011_init(const struct device *dev)
return 0;
}
#if IS_ENABLED(CONFIG_PINCTRL)
#define PINCTRL_DEFINE(n) PINCTRL_DT_INST_DEFINE(n);
#define PINCTRL_INIT(n) .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n),
#else
#define PINCTRL_DEFINE(n)
#define PINCTRL_INIT(n)
#endif /* CONFIG_PINCTRL */
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
void pl011_isr(const struct device *dev)
{
@ -462,6 +482,7 @@ void pl011_isr(const struct device *dev)
static struct pl011_config pl011_cfg_port_##n = { \
DEVICE_MMIO_ROM_INIT(DT_DRV_INST(n)), \
.sys_clk_freq = DT_INST_PROP_BY_PHANDLE(n, clocks, clock_frequency), \
PINCTRL_INIT(n) \
.irq_config_func = pl011_irq_config_func_##n, \
};
#else
@ -469,11 +490,12 @@ void pl011_isr(const struct device *dev)
static struct pl011_config pl011_cfg_port_##n = { \
DEVICE_MMIO_ROM_INIT(DT_DRV_INST(n)), \
.sys_clk_freq = DT_INST_PROP_BY_PHANDLE(n, clocks, clock_frequency), \
PINCTRL_INIT(n) \
};
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
#define PL011_INIT(n) \
\
PINCTRL_DEFINE(n) \
PL011_CONFIG_PORT(n) \
\
static struct pl011_data pl011_data_port_##n = { \

View file

@ -2,7 +2,7 @@ description: ARM PL011 UART
compatible: "arm,pl011"
include: uart-controller.yaml
include: [uart-controller.yaml, pinctrl-device.yaml]
properties:
reg: