drivers: serial: telink_b91: replace Pinmux by Pinctrl
Updated driver to use new Pinctrl driver. Signed-off-by: Yuriy Vynnychek <yura.vynnychek@telink-semi.com>
This commit is contained in:
parent
4089ef71e5
commit
b7f1b58810
1 changed files with 10 additions and 17 deletions
|
@ -9,8 +9,7 @@
|
||||||
|
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
#include <drivers/uart.h>
|
#include <drivers/uart.h>
|
||||||
#include <drivers/pinmux.h>
|
#include <drivers/pinctrl.h>
|
||||||
#include <dt-bindings/pinctrl/b91-pinctrl.h>
|
|
||||||
|
|
||||||
|
|
||||||
/* Driver dts compatibility: telink,b91_uart */
|
/* Driver dts compatibility: telink,b91_uart */
|
||||||
|
@ -65,8 +64,7 @@ struct uart_b91_data {
|
||||||
|
|
||||||
/* B91 UART config structure */
|
/* B91 UART config structure */
|
||||||
struct uart_b91_config {
|
struct uart_b91_config {
|
||||||
const uint32_t *pinctrl_list;
|
const struct pinctrl_dev_config *pcfg;
|
||||||
size_t pinctrl_list_size;
|
|
||||||
uint32_t uart_addr;
|
uint32_t uart_addr;
|
||||||
uint32_t baud_rate;
|
uint32_t baud_rate;
|
||||||
void (*pirq_connect)(void);
|
void (*pirq_connect)(void);
|
||||||
|
@ -292,6 +290,7 @@ static int uart_b91_config_get(const struct device *dev,
|
||||||
struct uart_config *cfg)
|
struct uart_config *cfg)
|
||||||
{
|
{
|
||||||
struct uart_b91_data *data = dev->data;
|
struct uart_b91_data *data = dev->data;
|
||||||
|
|
||||||
*cfg = data->cfg;
|
*cfg = data->cfg;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -300,20 +299,16 @@ static int uart_b91_config_get(const struct device *dev,
|
||||||
/* API implementation: driver initialization */
|
/* API implementation: driver initialization */
|
||||||
static int uart_b91_driver_init(const struct device *dev)
|
static int uart_b91_driver_init(const struct device *dev)
|
||||||
{
|
{
|
||||||
|
int status = 0;
|
||||||
uint16_t divider = 0u;
|
uint16_t divider = 0u;
|
||||||
uint8_t bwpc = 0u;
|
uint8_t bwpc = 0u;
|
||||||
const struct device *pinmux;
|
|
||||||
volatile struct uart_b91_t *uart = GET_UART(dev);
|
volatile struct uart_b91_t *uart = GET_UART(dev);
|
||||||
const struct uart_b91_config *cfg = dev->config;
|
const struct uart_b91_config *cfg = dev->config;
|
||||||
|
|
||||||
pinmux = DEVICE_DT_GET(DT_NODELABEL(pinmux));
|
/* configure pins */
|
||||||
if (!device_is_ready(pinmux)) {
|
status = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
|
||||||
return -ENODEV;
|
if (status < 0) {
|
||||||
}
|
return status;
|
||||||
|
|
||||||
for (int i = 0; i < cfg->pinctrl_list_size; i++) {
|
|
||||||
pinmux_pin_set(pinmux, B91_PINMUX_GET_PIN(cfg->pinctrl_list[i]),
|
|
||||||
B91_PINMUX_GET_FUNC(cfg->pinctrl_list[i]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uart_b91_cal_div_and_bwpc(cfg->baud_rate, sys_clk.pclk * 1000 * 1000, ÷r, &bwpc);
|
uart_b91_cal_div_and_bwpc(cfg->baud_rate, sys_clk.pclk * 1000 * 1000, ÷r, &bwpc);
|
||||||
|
@ -543,15 +538,13 @@ static const struct uart_driver_api uart_b91_driver_api = {
|
||||||
\
|
\
|
||||||
static void uart_b91_irq_connect_##n(void); \
|
static void uart_b91_irq_connect_##n(void); \
|
||||||
\
|
\
|
||||||
static const uint32_t uart_pins_##n[] = \
|
PINCTRL_DT_INST_DEFINE(n); \
|
||||||
B91_PINMUX_DT_INST_GET_ARRAY(n, 0); \
|
|
||||||
\
|
\
|
||||||
static const struct uart_b91_config uart_b91_cfg_##n = \
|
static const struct uart_b91_config uart_b91_cfg_##n = \
|
||||||
{ \
|
{ \
|
||||||
.uart_addr = DT_INST_REG_ADDR(n), \
|
.uart_addr = DT_INST_REG_ADDR(n), \
|
||||||
.baud_rate = DT_INST_PROP(n, current_speed), \
|
.baud_rate = DT_INST_PROP(n, current_speed), \
|
||||||
.pinctrl_list_size = ARRAY_SIZE(uart_pins_##n), \
|
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
|
||||||
.pinctrl_list = uart_pins_##n, \
|
|
||||||
.pirq_connect = uart_b91_irq_connect_##n \
|
.pirq_connect = uart_b91_irq_connect_##n \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue