drivers: can: RCar add pinctrl support

Get pin configuration from device tree to
set alternate pin function.

Signed-off-by: Julien Massot <julien.massot@iot.bzh>
This commit is contained in:
Julien Massot 2021-10-19 12:06:33 +02:00 committed by Carles Cufí
commit 15f4bbf86b
2 changed files with 11 additions and 1 deletions

View file

@ -11,6 +11,7 @@
#include <drivers/can.h> #include <drivers/can.h>
#include <drivers/clock_control.h> #include <drivers/clock_control.h>
#include <drivers/clock_control/rcar_clock_control.h> #include <drivers/clock_control/rcar_clock_control.h>
#include <drivers/pinctrl.h>
#include <logging/log.h> #include <logging/log.h>
LOG_MODULE_DECLARE(can_driver, CONFIG_CAN_LOG_LEVEL); LOG_MODULE_DECLARE(can_driver, CONFIG_CAN_LOG_LEVEL);
@ -179,6 +180,7 @@ struct can_rcar_cfg {
uint8_t phase_seg1; uint8_t phase_seg1;
uint8_t phase_seg2; uint8_t phase_seg2;
uint16_t sample_point; uint16_t sample_point;
const struct pinctrl_dev_config *pcfg;
}; };
struct can_rcar_tx_cb { struct can_rcar_tx_cb {
@ -868,6 +870,12 @@ static int can_rcar_init(const struct device *dev)
data->state_change_cb = NULL; data->state_change_cb = NULL;
data->state_change_cb_data = NULL; data->state_change_cb_data = NULL;
/* Configure dt provided device signals when available */
ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
if (ret < 0) {
return ret;
}
/* reset the registers */ /* reset the registers */
ret = clock_control_off(config->clock_dev, ret = clock_control_off(config->clock_dev,
(clock_control_subsys_t *)&config->mod_clk); (clock_control_subsys_t *)&config->mod_clk);
@ -1024,6 +1032,7 @@ static const struct can_driver_api can_rcar_driver_api = {
/* Device Instantiation */ /* Device Instantiation */
#define CAN_RCAR_INIT(n) \ #define CAN_RCAR_INIT(n) \
PINCTRL_DT_INST_DEFINE(n); \
static void can_rcar_##n##_init(const struct device *dev); \ static void can_rcar_##n##_init(const struct device *dev); \
static const struct can_rcar_cfg can_rcar_cfg_##n = { \ static const struct can_rcar_cfg can_rcar_cfg_##n = { \
.reg_addr = DT_INST_REG_ADDR(n), \ .reg_addr = DT_INST_REG_ADDR(n), \
@ -1045,6 +1054,7 @@ static const struct can_driver_api can_rcar_driver_api = {
.phase_seg1 = DT_INST_PROP_OR(n, phase_seg1, 0), \ .phase_seg1 = DT_INST_PROP_OR(n, phase_seg1, 0), \
.phase_seg2 = DT_INST_PROP_OR(n, phase_seg2, 0), \ .phase_seg2 = DT_INST_PROP_OR(n, phase_seg2, 0), \
.sample_point = DT_INST_PROP_OR(n, sample_point, 0), \ .sample_point = DT_INST_PROP_OR(n, sample_point, 0), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
}; \ }; \
static struct can_rcar_data can_rcar_data_##n; \ static struct can_rcar_data can_rcar_data_##n; \
\ \

View file

@ -2,7 +2,7 @@ description: Renesas R-Car CAN controller
compatible: "renesas,rcar-can" compatible: "renesas,rcar-can"
include: can-controller.yaml include: [can-controller.yaml, pinctrl-device.yaml]
properties: properties:
reg: reg: