Skip to content

Commit c96175b

Browse files
jackrosenthalCommit Bot
authored andcommitted
zephyr: console: Use DT bindings to get shell uart dev on 2.7+
In Zephyr 2.7+, CONFIG_UART_SHELL_ON_DEV_NAME is removed in favor of using the zephyr,shell-uart device chosen by the UART driver. Since we choose zephyr,shell-uart on all of our boards, we are clear to make this change ahead of the v2.7 uprev. Also see zephyrproject-rtos/zephyr#37902. BUG=b:198824039 BRANCH=none TEST=zmake testall TEST=compile posix-ec with v2.7_rc1 Signed-off-by: Jack Rosenthal <[email protected]> Change-Id: Ic066ce0617fa900ae7c1c96a2cbece0b698764bc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3142750 Reviewed-by: Keith Short <[email protected]>
1 parent cb37719 commit c96175b

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

zephyr/shim/src/console.c

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
LOG_MODULE_REGISTER(shim_console, LOG_LEVEL_ERR);
2424

25+
static const struct device *uart_shell_dev =
26+
DEVICE_DT_GET(DT_CHOSEN(zephyr_shell_uart));
2527
static const struct shell *shell_zephyr;
2628
static struct k_poll_signal shell_uninit_signal;
2729
static struct k_poll_signal shell_init_signal;
@@ -62,21 +64,19 @@ static void uart_callback(const struct device *dev, void *user_data)
6264

6365
static void shell_uninit_callback(const struct shell *shell, int res)
6466
{
65-
const struct device *dev =
66-
device_get_binding(CONFIG_UART_SHELL_ON_DEV_NAME);
67-
6867
if (!res) {
6968
/* Set the new callback */
70-
uart_irq_callback_user_data_set(dev, uart_callback, NULL);
69+
uart_irq_callback_user_data_set(uart_shell_dev, uart_callback,
70+
NULL);
7171

7272
/*
7373
* Disable TX interrupts. We don't actually use TX but for some
7474
* reason none of this works without this line.
7575
*/
76-
uart_irq_tx_disable(dev);
76+
uart_irq_tx_disable(uart_shell_dev);
7777

7878
/* Enable RX interrupts */
79-
uart_irq_rx_enable(dev);
79+
uart_irq_rx_enable(uart_shell_dev);
8080
}
8181

8282
/* Notify the uninit signal that we finished */
@@ -88,15 +88,13 @@ int uart_shell_stop(void)
8888
struct k_poll_event event = K_POLL_EVENT_INITIALIZER(
8989
K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY,
9090
&shell_uninit_signal);
91-
const struct device *dev =
92-
device_get_binding(CONFIG_UART_SHELL_ON_DEV_NAME);
9391

9492
/* Clear all pending input */
9593
uart_clear_input();
9694

9795
/* Disable RX and TX interrupts */
98-
uart_irq_rx_disable(dev);
99-
uart_irq_tx_disable(dev);
96+
uart_irq_rx_disable(uart_shell_dev);
97+
uart_irq_tx_disable(uart_shell_dev);
10098

10199
/* Initialize the uninit signal */
102100
k_poll_signal_init(&shell_uninit_signal);
@@ -113,8 +111,6 @@ int uart_shell_stop(void)
113111

114112
static void shell_init_from_work(struct k_work *work)
115113
{
116-
const struct device *dev =
117-
device_get_binding(CONFIG_UART_SHELL_ON_DEV_NAME);
118114
bool log_backend = CONFIG_SHELL_BACKEND_SERIAL_LOG_LEVEL > 0;
119115
uint32_t level;
120116
ARG_UNUSED(work);
@@ -126,10 +122,10 @@ static void shell_init_from_work(struct k_work *work)
126122
}
127123

128124
/* Initialize the shell and re-enable both RX and TX */
129-
shell_init(shell_backend_uart_get_ptr(), dev, false, log_backend,
130-
level);
131-
uart_irq_rx_enable(dev);
132-
uart_irq_tx_enable(dev);
125+
shell_init(shell_backend_uart_get_ptr(), uart_shell_dev, false,
126+
log_backend, level);
127+
uart_irq_rx_enable(uart_shell_dev);
128+
uart_irq_tx_enable(uart_shell_dev);
133129

134130
/* Notify the init signal that initialization is complete */
135131
k_poll_signal_raise(&shell_init_signal, 0);
@@ -138,15 +134,13 @@ static void shell_init_from_work(struct k_work *work)
138134
void uart_shell_start(void)
139135
{
140136
static struct k_work shell_init_work;
141-
const struct device *dev =
142-
device_get_binding(CONFIG_UART_SHELL_ON_DEV_NAME);
143137
struct k_poll_event event = K_POLL_EVENT_INITIALIZER(
144138
K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY,
145139
&shell_init_signal);
146140

147141
/* Disable RX and TX interrupts */
148-
uart_irq_rx_disable(dev);
149-
uart_irq_tx_disable(dev);
142+
uart_irq_rx_disable(uart_shell_dev);
143+
uart_irq_tx_disable(uart_shell_dev);
150144

151145
/* Initialize k_work to call shell init (this makes it thread safe) */
152146
k_work_init(&shell_init_work, shell_init_from_work);
@@ -237,10 +231,7 @@ void uart_flush_output(void)
237231

238232
void uart_tx_flush(void)
239233
{
240-
const struct device *dev =
241-
device_get_binding(CONFIG_UART_SHELL_ON_DEV_NAME);
242-
243-
while (!uart_irq_tx_complete(dev))
234+
while (!uart_irq_tx_complete(uart_shell_dev))
244235
;
245236
}
246237

0 commit comments

Comments
 (0)