can: dts: Convert can-primary alias to zephyr,can-primary chosen prop

Convert CAN to use a chosen node property that is similar to how we
handle zephyr,entroy or zephyr,flash-controller as the means to select a
specific peripheral instance utilized by a subsystem.

Replace references of the form:

alias {
	can-primary = &can1;
};

with:

chosen {
	zephyr,can-primary = &can1;
};

Replace various macro/define references with either
DT_CHOSEN(zephyr_can_primary) or replace DT_ALIAS_CAN_PRIMARY_LABEL
with DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2020-04-28 07:33:18 -05:00 committed by Kumar Gala
commit 3f236f2183
22 changed files with 40 additions and 25 deletions

View file

@ -17,6 +17,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,ccm = &ccm0;
zephyr,can-primary = &can2;
};
leds {
@ -48,7 +49,6 @@
};
aliases {
can-primary = &can2;
led0 = &green_led_1;
led1 = &green_led_2;
sw0 = &user_button_UP;

View file

@ -14,7 +14,6 @@
led2 = &red_led;
sw0 = &user_button_3;
sw1 = &user_button_2;
can-primary = &flexcan0;
};
chosen {
@ -24,6 +23,7 @@
zephyr,console = &uart0;
zephyr,shell-uart = &uart0;
zephyr,uart-pipe = &uart0;
zephyr,can-primary = &flexcan0;
};
leds {

View file

@ -18,6 +18,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,dtcm = &dtcm;
zephyr,can-primary = &can1;
};
leds {
@ -49,7 +50,6 @@
led1 = &blue_led;
led2 = &red_led;
sw0 = &user_button;
can-primary = &can1;
};
};

View file

@ -18,6 +18,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,dtcm = &dtcm;
zephyr,can-primary = &can1;
};
leds {
@ -49,7 +50,6 @@
led1 = &blue_led;
led2 = &red_led;
sw0 = &user_button;
can-primary = &can1;
};
};

View file

@ -16,6 +16,7 @@
zephyr,shell-uart = &usart2;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,can-primary = &can1;
};
leds {
@ -28,7 +29,6 @@
aliases {
led0 = &green_led;
can-primary = &can1;
};
};

View file

@ -17,6 +17,7 @@
zephyr,shell-uart = &usart2;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,can-primary = &can1;
};
leds {
@ -38,7 +39,6 @@
aliases {
led0 = &green_led;
sw0 = &user_button;
can-primary = &can1;
};
};

View file

@ -17,6 +17,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,ccm = &ccm0;
zephyr,can-primary = &can1;
};
leds {
@ -38,7 +39,6 @@
aliases {
led0 = &green_led_1;
sw0 = &user_button;
can-primary = &can1;
};
};

View file

@ -16,6 +16,7 @@
zephyr,shell-uart = &usart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,can-primary = &can1;
};
leds {
@ -42,7 +43,6 @@
led0 = &green_led_1;
led1 = &yellow_led_2;
sw0 = &user_button;
can-primary = &can1;
};
};

View file

@ -16,6 +16,7 @@
zephyr,shell-uart = &usart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,can-primary = &can1;
};
leds {
@ -52,7 +53,6 @@
led2 = &green_right_led_5;
led3 = &blue_low_led_6;
sw0 = &user_button;
can-primary = &can1;
};
};

View file

@ -16,6 +16,7 @@
zephyr,shell-uart = &usart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,can-primary = &can1;
};
leds {
@ -66,7 +67,6 @@
led0 = &green_led_6;
led1 = &green_led_7;
sw0 = &user_button;
can-primary = &can1;
};
};

View file

@ -17,6 +17,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,ccm = &ccm0;
zephyr,can-primary = &can2;
};
leds {
@ -48,7 +49,6 @@
};
aliases {
can-primary = &can2;
led0 = &green_led_4;
led1 = &orange_led_3;
led2 = &red_led_5;

View file

@ -31,7 +31,6 @@
blue-pwm-led = &tri_blue_pwm_led;
sw0 = &user_button_3;
sw1 = &user_button_2;
can-primary = &flexcan0;
};
chosen {
@ -41,6 +40,7 @@
zephyr,console = &lpuart0;
zephyr,shell-uart = &lpuart0;
zephyr,uart-pipe = &lpuart0;
zephyr,can-primary = &flexcan0;
};
leds {

View file

@ -27,7 +27,7 @@
};
/ {
aliases {
can-primary = &can1;
chosen {
zephyr,can-primary = &can1;
};
};

View file

@ -372,9 +372,11 @@ static struct net_can_api net_can_api_inst = {
static int net_can_init(struct device *dev)
{
struct device *can_dev = device_get_binding(DT_ALIAS_CAN_PRIMARY_LABEL);
struct device *can_dev;
struct net_can_context *ctx = dev->driver_data;
can_dev = device_get_binding(DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL);
ctx->recv_filter_id = CAN_NET_FILTER_NOT_SET;
#ifdef CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR
ctx->eth_bridge_filter_id = CAN_NET_FILTER_NOT_SET;
@ -383,7 +385,7 @@ static int net_can_init(struct device *dev)
if (!can_dev) {
NET_ERR("Can't get binding to CAN device %s",
DT_ALIAS_CAN_PRIMARY_LABEL);
DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL);
return -EIO;
}

View file

@ -44,6 +44,15 @@
* a label property, that property's value. Undefined otherwise.
*/
#define DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL ""
/**
* @def DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL
*
* @brief If there is a chosen node zephyr,can-primary property which has
* a label property, that property's value. Undefined otherwise.
*/
#define DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL ""
#endif /* DT_DOXYGEN */
#if DT_NODE_HAS_PROP(DT_CHOSEN(zephyr_entropy), label)
@ -55,6 +64,10 @@
DT_LABEL(DT_CHOSEN(zephyr_flash_controller))
#endif
#if DT_NODE_HAS_PROP(DT_CHOSEN(zephyr_can_primary), label)
#define DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL \
DT_LABEL(DT_CHOSEN(zephyr_can_primary))
#endif
/**
* @}
*/

View file

@ -195,7 +195,7 @@ void main(void)
k_tid_t rx_tid, get_state_tid;
int ret;
can_dev = device_get_binding(DT_ALIAS_CAN_PRIMARY_LABEL);
can_dev = device_get_binding(DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL);
if (!can_dev) {
printk("CAN: Device driver not found.\n");

View file

@ -15,9 +15,9 @@
LOG_MODULE_REGISTER(app);
#define CAN_INTERFACE DT_ALIAS_CAN_PRIMARY_LABEL
#define CAN_BITRATE (DT_ALIAS_CAN_PRIMARY_BUS_SPEED / 1000)
#if !defined(DT_ALIAS_CAN_PRIMARY_LABEL)
#define CAN_INTERFACE DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL
#define CAN_BITRATE (DT_PROP(DT_CHOSEN(zephyr_can_primary), bus_speed) / 1000)
#if !defined(DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL)
#error CANopen CAN interface not set
#endif

View file

@ -148,7 +148,7 @@ void main(void)
static struct isotp_send_ctx send_ctx_0_5;
int ret = 0;
can_dev = device_get_binding(DT_ALIAS_CAN_PRIMARY_LABEL);
can_dev = device_get_binding(DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL);
if (!can_dev) {
printk("CAN: Device driver not found.\n");
return;

View file

@ -44,7 +44,7 @@
#if defined(CONFIG_CAN_LOOPBACK_DEV_NAME)
#define CAN_DEVICE_NAME CONFIG_CAN_LOOPBACK_DEV_NAME
#else
#define CAN_DEVICE_NAME DT_ALIAS_CAN_PRIMARY_LABEL
#define CAN_DEVICE_NAME DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL
#endif
CAN_DEFINE_MSGQ(can_msgq, 5);

View file

@ -130,7 +130,7 @@ static void test_filter_handling(void)
int ret, filter_id_1, filter_id_2;
struct zcan_frame msg_buffer;
can_dev = device_get_binding(DT_ALIAS_CAN_PRIMARY_LABEL);
can_dev = device_get_binding(DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL);
ret = can_configure(can_dev, CAN_LOOPBACK_MODE, 0);

View file

@ -46,7 +46,7 @@
#if defined(CONFIG_CAN_LOOPBACK_DEV_NAME)
#define CAN_DEVICE_NAME CONFIG_CAN_LOOPBACK_DEV_NAME
#else
#define CAN_DEVICE_NAME DT_ALIAS_CAN_PRIMARY_LABEL
#define CAN_DEVICE_NAME DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL
#endif
/*

View file

@ -15,7 +15,7 @@
#if defined(CONFIG_CAN_LOOPBACK_DEV_NAME)
#define CAN_DEVICE_NAME CONFIG_CAN_LOOPBACK_DEV_NAME
#else
#define CAN_DEVICE_NAME DT_ALIAS_CAN_PRIMARY_LABEL
#define CAN_DEVICE_NAME DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL
#endif
/*