1 /* stellarisUartDrv.c - Stellaris UART driver */
2
3 #define DT_DRV_COMPAT ti_stellaris_uart
4
5 /*
6 * Copyright (c) 2013-2015 Wind River Systems, Inc.
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10
11 /**
12 * @brief Driver for Stellaris UART
13 *
14 * Driver for Stellaris UART found namely on TI LM3S6965 board. It is similar to
15 * an 16550 in functionality, but is not register-compatible.
16 * It is also register-compatible with the UART found on TI CC2650 SoC,
17 * so it can be used for boards using it, like the TI SensorTag.
18 *
19 * There is only support for poll-mode, so it can only be used with the printk
20 * and STDOUT_CONSOLE APIs.
21 */
22
23 #include <kernel.h>
24 #include <arch/cpu.h>
25 #include <sys/__assert.h>
26 #include <soc.h>
27 #include <init.h>
28 #include <drivers/uart.h>
29 #include <linker/sections.h>
30
31 /* definitions */
32
33 /* Stellaris UART module */
34 struct _uart {
35 uint32_t dr;
36 union {
37 uint32_t _sr;
38 uint32_t _cr;
39 } u1;
40 uint8_t _res1[0x010];
41 uint32_t fr;
42 uint8_t _res2[0x04];
43 uint32_t ilpr;
44 uint32_t ibrd;
45 uint32_t fbrd;
46 uint32_t lcrh;
47 uint32_t ctl;
48 uint32_t ifls;
49 uint32_t im;
50 uint32_t ris;
51 uint32_t mis;
52 uint32_t icr;
53 uint8_t _res3[0xf8c];
54
55 uint32_t peripd_id4;
56 uint32_t peripd_id5;
57 uint32_t peripd_id6;
58 uint32_t peripd_id7;
59 uint32_t peripd_id0;
60 uint32_t peripd_id1;
61 uint32_t peripd_id2;
62 uint32_t peripd_id3;
63
64 uint32_t p_cell_id0;
65 uint32_t p_cell_id1;
66 uint32_t p_cell_id2;
67 uint32_t p_cell_id3;
68 };
69
70 /* Device data structure */
71 struct uart_stellaris_dev_data_t {
72 uint32_t baud_rate; /* Baud rate */
73
74 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
75 uart_irq_callback_user_data_t cb; /**< Callback function pointer */
76 void *cb_data; /**< Callback function arg */
77 #endif
78 };
79
80 /* convenience defines */
81
82 #define DEV_CFG(dev) \
83 ((const struct uart_device_config * const)(dev)->config)
84 #define DEV_DATA(dev) \
85 ((struct uart_stellaris_dev_data_t * const)(dev)->data)
86 #define UART_STRUCT(dev) \
87 ((volatile struct _uart *)(DEV_CFG(dev))->base)
88
89 /* registers */
90 #define UARTDR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x000)))
91 #define UARTSR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x004)))
92 #define UARTCR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x004)))
93 #define UARTFR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x018)))
94 #define UARTILPR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x020)))
95 #define UARTIBRD(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x024)))
96 #define UARTFBRD(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x028)))
97 #define UARTLCRH(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x02C)))
98 #define UARTCTL(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x030)))
99 #define UARTIFLS(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x034)))
100 #define UARTIM(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x038)))
101 #define UARTRIS(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x03C)))
102 #define UARTMIS(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x040)))
103 #define UARTICR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x044)))
104
105 /* ID registers: UARTPID = UARTPeriphID, UARTPCID = UARTPCellId */
106 #define UARTPID4(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFD0)))
107 #define UARTPID5(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFD4)))
108 #define UARTPID6(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFD8)))
109 #define UARTPID7(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFDC)))
110 #define UARTPID0(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFE0)))
111 #define UARTPID1(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFE4)))
112 #define UARTPID2(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFE8)))
113 #define UARTPID3(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFEC)))
114 #define UARTPCID0(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFF0)))
115 #define UARTPCID1(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFF4)))
116 #define UARTPCID2(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFF8)))
117 #define UARTPCID3(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFFC)))
118
119 /* muxed UART registers */
120 #define sr u1._sr /* Read: receive status */
121 #define cr u1._cr /* Write: receive error clear */
122
123 /* bits */
124 #define UARTFR_BUSY 0x00000008
125 #define UARTFR_RXFE 0x00000010
126 #define UARTFR_TXFF 0x00000020
127 #define UARTFR_RXFF 0x00000040
128 #define UARTFR_TXFE 0x00000080
129
130 #define UARTLCRH_FEN 0x00000010
131 #define UARTLCRH_WLEN 0x00000060
132
133 #define UARTCTL_UARTEN 0x00000001
134 #define UARTCTL_LBE 0x00000800
135 #define UARTCTL_TXEN 0x00000100
136 #define UARTCTL_RXEN 0x00000200
137
138 #define UARTTIM_RXIM 0x00000010
139 #define UARTTIM_TXIM 0x00000020
140 #define UARTTIM_RTIM 0x00000040
141 #define UARTTIM_FEIM 0x00000080
142 #define UARTTIM_PEIM 0x00000100
143 #define UARTTIM_BEIM 0x00000200
144 #define UARTTIM_OEIM 0x00000400
145
146 #define UARTMIS_RXMIS 0x00000010
147 #define UARTMIS_TXMIS 0x00000020
148
149 static const struct uart_driver_api uart_stellaris_driver_api;
150
151 /**
152 * @brief Set the baud rate
153 *
154 * This routine set the given baud rate for the UART.
155 *
156 * @param dev UART device struct
157 * @param baudrate Baud rate
158 * @param sys_clk_freq_hz System clock frequency in Hz
159 *
160 * @return N/A
161 */
baudrate_set(const struct device * dev,uint32_t baudrate,uint32_t sys_clk_freq_hz)162 static void baudrate_set(const struct device *dev,
163 uint32_t baudrate, uint32_t sys_clk_freq_hz)
164 {
165 volatile struct _uart *uart = UART_STRUCT(dev);
166 uint32_t brdi, brdf, div, rem;
167
168 /* upon reset, the system clock uses the intenal OSC @ 12MHz */
169
170 div = (baudrate * 16U);
171 rem = sys_clk_freq_hz % div;
172
173 /*
174 * floating part of baud rate (LM3S6965 p.433), equivalent to
175 * [float part of (SYSCLK / div)] * 64 + 0.5
176 */
177 brdf = ((((rem * 64U) << 1) / div) + 1) >> 1;
178
179 /* integer part of baud rate (LM3S6965 p.433) */
180 brdi = sys_clk_freq_hz / div;
181
182 /*
183 * those registers are 32-bit, but the reserved bits should be
184 * preserved
185 */
186 uart->ibrd = (uint16_t)(brdi & 0xffff); /* 16 bits */
187 uart->fbrd = (uint8_t)(brdf & 0x3f); /* 6 bits */
188 }
189
190 /**
191 * @brief Enable the UART
192 *
193 * This routine enables the given UART.
194 *
195 * @param dev UART device struct
196 *
197 * @return N/A
198 */
enable(const struct device * dev)199 static inline void enable(const struct device *dev)
200 {
201 volatile struct _uart *uart = UART_STRUCT(dev);
202
203 uart->ctl |= UARTCTL_UARTEN;
204 }
205
206 /**
207 * @brief Disable the UART
208 *
209 * This routine disables the given UART.
210 *
211 * @param dev UART device struct
212 *
213 * @return N/A
214 */
disable(const struct device * dev)215 static inline void disable(const struct device *dev)
216 {
217 volatile struct _uart *uart = UART_STRUCT(dev);
218
219 uart->ctl &= ~UARTCTL_UARTEN;
220
221 /* ensure transmissions are complete */
222 while (uart->fr & UARTFR_BUSY) {
223 }
224
225 /* flush the FIFOs by disabling them */
226 uart->lcrh &= ~UARTLCRH_FEN;
227 }
228
229 /*
230 * no stick parity
231 * 8-bit frame
232 * FIFOs disabled
233 * one stop bit
234 * parity disabled
235 * send break off
236 */
237 #define LINE_CONTROL_DEFAULTS UARTLCRH_WLEN
238
239 /**
240 * @brief Set the default UART line controls
241 *
242 * This routine sets the given UART's line controls to their default settings.
243 *
244 * @param dev UART device struct
245 *
246 * @return N/A
247 */
line_control_defaults_set(const struct device * dev)248 static inline void line_control_defaults_set(const struct device *dev)
249 {
250 volatile struct _uart *uart = UART_STRUCT(dev);
251
252 uart->lcrh = LINE_CONTROL_DEFAULTS;
253 }
254
255 /**
256 * @brief Initialize UART channel
257 *
258 * This routine is called to reset the chip in a quiescent state.
259 * It is assumed that this function is called only once per UART.
260 *
261 * @param dev UART device struct
262 *
263 * @return 0
264 */
uart_stellaris_init(const struct device * dev)265 static int uart_stellaris_init(const struct device *dev)
266 {
267 disable(dev);
268 baudrate_set(dev, DEV_DATA(dev)->baud_rate,
269 DEV_CFG(dev)->sys_clk_freq);
270 line_control_defaults_set(dev);
271 enable(dev);
272
273 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
274 DEV_CFG(dev)->irq_config_func(dev);
275 #endif
276
277 return 0;
278 }
279
280 /**
281 * @brief Get the UART transmit ready status
282 *
283 * This routine returns the given UART's transmit ready status.
284 *
285 * @param dev UART device struct
286 *
287 * @return 0 if ready to transmit, 1 otherwise
288 */
poll_tx_ready(const struct device * dev)289 static int poll_tx_ready(const struct device *dev)
290 {
291 volatile struct _uart *uart = UART_STRUCT(dev);
292
293 return (uart->fr & UARTFR_TXFE);
294 }
295
296 /**
297 * @brief Poll the device for input.
298 *
299 * @param dev UART device struct
300 * @param c Pointer to character
301 *
302 * @return 0 if a character arrived, -1 if the input buffer if empty.
303 */
304
uart_stellaris_poll_in(const struct device * dev,unsigned char * c)305 static int uart_stellaris_poll_in(const struct device *dev, unsigned char *c)
306 {
307 volatile struct _uart *uart = UART_STRUCT(dev);
308
309 if (uart->fr & UARTFR_RXFE) {
310 return (-1);
311 }
312
313 /* got a character */
314 *c = (unsigned char)uart->dr;
315
316 return 0;
317 }
318
319 /**
320 * @brief Output a character in polled mode.
321 *
322 * Checks if the transmitter is empty. If empty, a character is written to
323 * the data register.
324 *
325 * @param dev UART device struct
326 * @param c Character to send
327 */
uart_stellaris_poll_out(const struct device * dev,unsigned char c)328 static void uart_stellaris_poll_out(const struct device *dev,
329 unsigned char c)
330 {
331 volatile struct _uart *uart = UART_STRUCT(dev);
332
333 while (!poll_tx_ready(dev)) {
334 }
335
336 /* send a character */
337 uart->dr = (uint32_t)c;
338 }
339
340 #if CONFIG_UART_INTERRUPT_DRIVEN
341
342 /**
343 * @brief Fill FIFO with data
344 *
345 * @param dev UART device struct
346 * @param tx_data Data to transmit
347 * @param len Number of bytes to send
348 *
349 * @return Number of bytes sent
350 */
uart_stellaris_fifo_fill(const struct device * dev,const uint8_t * tx_data,int len)351 static int uart_stellaris_fifo_fill(const struct device *dev,
352 const uint8_t *tx_data,
353 int len)
354 {
355 volatile struct _uart *uart = UART_STRUCT(dev);
356 uint8_t num_tx = 0U;
357
358 while ((len - num_tx > 0) && ((uart->fr & UARTFR_TXFF) == 0U)) {
359 uart->dr = (uint32_t)tx_data[num_tx++];
360 }
361
362 return (int)num_tx;
363 }
364
365 /**
366 * @brief Read data from FIFO
367 *
368 * @param dev UART device struct
369 * @param rx_data Pointer to data container
370 * @param size Container size
371 *
372 * @return Number of bytes read
373 */
uart_stellaris_fifo_read(const struct device * dev,uint8_t * rx_data,const int size)374 static int uart_stellaris_fifo_read(const struct device *dev,
375 uint8_t *rx_data,
376 const int size)
377 {
378 volatile struct _uart *uart = UART_STRUCT(dev);
379 uint8_t num_rx = 0U;
380
381 while ((size - num_rx > 0) && ((uart->fr & UARTFR_RXFE) == 0U)) {
382 rx_data[num_rx++] = (uint8_t)uart->dr;
383 }
384
385 return num_rx;
386 }
387
388 /**
389 * @brief Enable TX interrupt
390 *
391 * @param dev UART device struct
392 *
393 * @return N/A
394 */
uart_stellaris_irq_tx_enable(const struct device * dev)395 static void uart_stellaris_irq_tx_enable(const struct device *dev)
396 {
397 static uint8_t first_time =
398 1U; /* used to allow the first transmission */
399 uint32_t saved_ctl; /* saved UARTCTL (control) register */
400 uint32_t saved_ibrd; /* saved UARTIBRD (integer baud rate) register */
401 uint32_t saved_fbrd; /* saved UARTFBRD (fractional baud rate) register
402 */
403 volatile struct _uart *uart = UART_STRUCT(dev);
404
405 if (first_time) {
406 /*
407 * The Tx interrupt will not be set when transmission is first
408 * enabled.
409 * A character has to be transmitted before Tx interrupts will
410 * work,
411 * so send one via loopback mode.
412 */
413 first_time = 0U;
414
415 /* save current control and baud rate settings */
416 saved_ctl = uart->ctl;
417 saved_ibrd = uart->ibrd;
418 saved_fbrd = uart->fbrd;
419
420 /* send a character with default settings via loopback */
421 disable(dev);
422 uart->fbrd = 0U;
423 uart->ibrd = 1U;
424 uart->lcrh = 0U;
425 uart->ctl = (UARTCTL_UARTEN | UARTCTL_TXEN | UARTCTL_LBE);
426 uart->dr = 0U;
427
428 while (uart->fr & UARTFR_BUSY) {
429 }
430
431 /* restore control and baud rate settings */
432 disable(dev);
433 uart->ibrd = saved_ibrd;
434 uart->fbrd = saved_fbrd;
435 line_control_defaults_set(dev);
436 uart->ctl = saved_ctl;
437 }
438
439 uart->im |= UARTTIM_TXIM;
440 }
441
442 /**
443 * @brief Disable TX interrupt in IER
444 *
445 * @param dev UART device struct
446 *
447 * @return N/A
448 */
uart_stellaris_irq_tx_disable(const struct device * dev)449 static void uart_stellaris_irq_tx_disable(const struct device *dev)
450 {
451 volatile struct _uart *uart = UART_STRUCT(dev);
452
453 uart->im &= ~UARTTIM_TXIM;
454 }
455
456 /**
457 * @brief Check if Tx IRQ has been raised
458 *
459 * @param dev UART device struct
460 *
461 * @return 1 if a Tx IRQ is pending, 0 otherwise
462 */
uart_stellaris_irq_tx_ready(const struct device * dev)463 static int uart_stellaris_irq_tx_ready(const struct device *dev)
464 {
465 volatile struct _uart *uart = UART_STRUCT(dev);
466
467 return ((uart->mis & UARTMIS_TXMIS) == UARTMIS_TXMIS);
468 }
469
470 /**
471 * @brief Enable RX interrupt in IER
472 *
473 * @param dev UART device struct
474 *
475 * @return N/A
476 */
uart_stellaris_irq_rx_enable(const struct device * dev)477 static void uart_stellaris_irq_rx_enable(const struct device *dev)
478 {
479 volatile struct _uart *uart = UART_STRUCT(dev);
480
481 uart->im |= UARTTIM_RXIM;
482 }
483
484 /**
485 * @brief Disable RX interrupt in IER
486 *
487 * @param dev UART device struct
488 *
489 * @return N/A
490 */
uart_stellaris_irq_rx_disable(const struct device * dev)491 static void uart_stellaris_irq_rx_disable(const struct device *dev)
492 {
493 volatile struct _uart *uart = UART_STRUCT(dev);
494
495 uart->im &= ~UARTTIM_RXIM;
496 }
497
498 /**
499 * @brief Check if Rx IRQ has been raised
500 *
501 * @param dev UART device struct
502 *
503 * @return 1 if an IRQ is ready, 0 otherwise
504 */
uart_stellaris_irq_rx_ready(const struct device * dev)505 static int uart_stellaris_irq_rx_ready(const struct device *dev)
506 {
507 volatile struct _uart *uart = UART_STRUCT(dev);
508
509 return ((uart->mis & UARTMIS_RXMIS) == UARTMIS_RXMIS);
510 }
511
512 /**
513 * @brief Enable error interrupts
514 *
515 * @param dev UART device struct
516 *
517 * @return N/A
518 */
uart_stellaris_irq_err_enable(const struct device * dev)519 static void uart_stellaris_irq_err_enable(const struct device *dev)
520 {
521 volatile struct _uart *uart = UART_STRUCT(dev);
522
523 uart->im |= (UARTTIM_RTIM | UARTTIM_FEIM | UARTTIM_PEIM |
524 UARTTIM_BEIM | UARTTIM_OEIM);
525 }
526
527 /**
528 * @brief Disable error interrupts
529 *
530 * @param dev UART device struct
531 *
532 * @return N/A
533 */
uart_stellaris_irq_err_disable(const struct device * dev)534 static void uart_stellaris_irq_err_disable(const struct device *dev)
535 {
536 volatile struct _uart *uart = UART_STRUCT(dev);
537
538 uart->im &= ~(UARTTIM_RTIM | UARTTIM_FEIM | UARTTIM_PEIM |
539 UARTTIM_BEIM | UARTTIM_OEIM);
540 }
541
542 /**
543 * @brief Check if Tx or Rx IRQ is pending
544 *
545 * @param dev UART device struct
546 *
547 * @return 1 if a Tx or Rx IRQ is pending, 0 otherwise
548 */
uart_stellaris_irq_is_pending(const struct device * dev)549 static int uart_stellaris_irq_is_pending(const struct device *dev)
550 {
551 volatile struct _uart *uart = UART_STRUCT(dev);
552
553 /* Look only at Tx and Rx data interrupt flags */
554 return ((uart->mis & (UARTMIS_RXMIS | UARTMIS_TXMIS)) ? 1 : 0);
555 }
556
557 /**
558 * @brief Update IRQ status
559 *
560 * @param dev UART device struct
561 *
562 * @return Always 1
563 */
uart_stellaris_irq_update(const struct device * dev)564 static int uart_stellaris_irq_update(const struct device *dev)
565 {
566 return 1;
567 }
568
569 /**
570 * @brief Set the callback function pointer for IRQ.
571 *
572 * @param dev UART device struct
573 * @param cb Callback function pointer.
574 *
575 * @return N/A
576 */
uart_stellaris_irq_callback_set(const struct device * dev,uart_irq_callback_user_data_t cb,void * cb_data)577 static void uart_stellaris_irq_callback_set(const struct device *dev,
578 uart_irq_callback_user_data_t cb,
579 void *cb_data)
580 {
581 struct uart_stellaris_dev_data_t * const dev_data = DEV_DATA(dev);
582
583 dev_data->cb = cb;
584 dev_data->cb_data = cb_data;
585 }
586
587 /**
588 * @brief Interrupt service routine.
589 *
590 * This simply calls the callback function, if one exists.
591 *
592 * @param arg Argument to ISR.
593 *
594 * @return N/A
595 */
uart_stellaris_isr(const struct device * dev)596 static void uart_stellaris_isr(const struct device *dev)
597 {
598 struct uart_stellaris_dev_data_t * const dev_data = DEV_DATA(dev);
599
600 if (dev_data->cb) {
601 dev_data->cb(dev, dev_data->cb_data);
602 }
603 }
604
605 #endif /* CONFIG_UART_INTERRUPT_DRIVEN */
606
607
608 static const struct uart_driver_api uart_stellaris_driver_api = {
609 .poll_in = uart_stellaris_poll_in,
610 .poll_out = uart_stellaris_poll_out,
611
612 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
613
614 .fifo_fill = uart_stellaris_fifo_fill,
615 .fifo_read = uart_stellaris_fifo_read,
616 .irq_tx_enable = uart_stellaris_irq_tx_enable,
617 .irq_tx_disable = uart_stellaris_irq_tx_disable,
618 .irq_tx_ready = uart_stellaris_irq_tx_ready,
619 .irq_rx_enable = uart_stellaris_irq_rx_enable,
620 .irq_rx_disable = uart_stellaris_irq_rx_disable,
621 .irq_rx_ready = uart_stellaris_irq_rx_ready,
622 .irq_err_enable = uart_stellaris_irq_err_enable,
623 .irq_err_disable = uart_stellaris_irq_err_disable,
624 .irq_is_pending = uart_stellaris_irq_is_pending,
625 .irq_update = uart_stellaris_irq_update,
626 .irq_callback_set = uart_stellaris_irq_callback_set,
627
628 #endif
629 };
630
631
632 #ifdef CONFIG_UART_STELLARIS_PORT_0
633
634 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
635 static void irq_config_func_0(const struct device *port);
636 #endif
637
638 static const struct uart_device_config uart_stellaris_dev_cfg_0 = {
639 .base = (uint8_t *)DT_INST_REG_ADDR(0),
640 .sys_clk_freq = DT_INST_PROP_BY_PHANDLE(0, clocks, clock_frequency),
641
642 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
643 .irq_config_func = irq_config_func_0,
644 #endif
645 };
646
647 static struct uart_stellaris_dev_data_t uart_stellaris_dev_data_0 = {
648 .baud_rate = DT_INST_PROP(0, current_speed),
649 };
650
651 DEVICE_DT_INST_DEFINE(0,
652 &uart_stellaris_init,
653 NULL,
654 &uart_stellaris_dev_data_0, &uart_stellaris_dev_cfg_0,
655 PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY,
656 &uart_stellaris_driver_api);
657
658 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
irq_config_func_0(const struct device * dev)659 static void irq_config_func_0(const struct device *dev)
660 {
661 IRQ_CONNECT(DT_INST_IRQN(0),
662 DT_INST_IRQ(0, priority),
663 uart_stellaris_isr, DEVICE_DT_INST_GET(0),
664 0);
665 irq_enable(DT_INST_IRQN(0));
666 }
667 #endif
668
669 #endif /* CONFIG_UART_STELLARIS_PORT_0 */
670
671 #ifdef CONFIG_UART_STELLARIS_PORT_1
672
673 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
674 static void irq_config_func_1(const struct device *port);
675 #endif
676
677 static struct uart_device_config uart_stellaris_dev_cfg_1 = {
678 .base = (uint8_t *)DT_INST_REG_ADDR(1),
679 .sys_clk_freq = DT_INST_PROP_BY_PHANDLE(1, clocks, clock_frequency),
680
681 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
682 .irq_config_func = irq_config_func_1,
683 #endif
684 };
685
686 static struct uart_stellaris_dev_data_t uart_stellaris_dev_data_1 = {
687 .baud_rate = DT_INST_PROP(1, current_speed),
688 };
689
690 DEVICE_DT_INST_DEFINE(1,
691 &uart_stellaris_init,
692 NULL,
693 &uart_stellaris_dev_data_1, &uart_stellaris_dev_cfg_1,
694 PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY,
695 &uart_stellaris_driver_api);
696
697 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
irq_config_func_1(const struct device * dev)698 static void irq_config_func_1(const struct device *dev)
699 {
700 IRQ_CONNECT(DT_INST_IRQN(1),
701 DT_INST_IRQ(1, priority),
702 uart_stellaris_isr, DEVICE_DT_INST_GET(1),
703 0);
704 irq_enable(DT_INST_IRQN(1));
705 }
706 #endif
707
708 #endif /* CONFIG_UART_STELLARIS_PORT_1 */
709
710 #ifdef CONFIG_UART_STELLARIS_PORT_2
711
712 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
713 static void irq_config_func_2(const struct device *port);
714 #endif
715
716 static const struct uart_device_config uart_stellaris_dev_cfg_2 = {
717 .base = (uint8_t *)DT_INST_REG_ADDR(2),
718 .sys_clk_freq = DT_INST_PROP_BY_PHANDLE(2, clocks, clock_frequency),
719
720 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
721 .irq_config_func = irq_config_func_2,
722 #endif
723 };
724
725 static struct uart_stellaris_dev_data_t uart_stellaris_dev_data_2 = {
726 .baud_rate = DT_INST_PROP(2, current_speed),
727 };
728
729 DEVICE_DT_INST_DEFINE(2,
730 &uart_stellaris_init,
731 NULL,
732 &uart_stellaris_dev_data_2, &uart_stellaris_dev_cfg_2,
733 PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY,
734 &uart_stellaris_driver_api);
735
736 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
irq_config_func_2(const struct device * dev)737 static void irq_config_func_2(const struct device *dev)
738 {
739 IRQ_CONNECT(DT_INST_IRQN(2),
740 DT_INST_IRQ(2, priority),
741 uart_stellaris_isr, DEVICE_DT_INST_GET(2),
742 0);
743 irq_enable(DT_INST_IRQN(2));
744 }
745 #endif
746
747 #endif /* CONFIG_UART_STELLARIS_PORT_2 */
748