|
@@ -80,20 +80,18 @@ void uart_flush ( struct uart *uart ) {
|
80
|
80
|
}
|
81
|
81
|
|
82
|
82
|
/**
|
83
|
|
- * Initialise UART
|
|
83
|
+ * Check for existence of UART
|
84
|
84
|
*
|
85
|
85
|
* @v uart UART
|
86
|
|
- * @v baud Baud rate, or zero to leave unchanged
|
87
|
|
- * @v lcr Line control register value, or zero to leave unchanged
|
88
|
86
|
* @ret rc Return status code
|
89
|
87
|
*/
|
90
|
|
-int uart_init ( struct uart *uart, unsigned int baud, uint8_t lcr ) {
|
91
|
|
- uint8_t dlm;
|
92
|
|
- uint8_t dll;
|
|
88
|
+int uart_exists ( struct uart *uart ) {
|
93
|
89
|
|
94
|
|
- /* Check for existence of UART */
|
|
90
|
+ /* Fail if no UART port is defined */
|
95
|
91
|
if ( ! uart->base )
|
96
|
92
|
return -ENODEV;
|
|
93
|
+
|
|
94
|
+ /* Fail if UART scratch register seems not to be present */
|
97
|
95
|
uart_write ( uart, UART_SCR, 0x18 );
|
98
|
96
|
if ( uart_read ( uart, UART_SCR ) != 0x18 )
|
99
|
97
|
return -ENODEV;
|
|
@@ -101,6 +99,26 @@ int uart_init ( struct uart *uart, unsigned int baud, uint8_t lcr ) {
|
101
|
99
|
if ( uart_read ( uart, UART_SCR ) != 0xae )
|
102
|
100
|
return -ENODEV;
|
103
|
101
|
|
|
102
|
+ return 0;
|
|
103
|
+}
|
|
104
|
+
|
|
105
|
+/**
|
|
106
|
+ * Initialise UART
|
|
107
|
+ *
|
|
108
|
+ * @v uart UART
|
|
109
|
+ * @v baud Baud rate, or zero to leave unchanged
|
|
110
|
+ * @v lcr Line control register value, or zero to leave unchanged
|
|
111
|
+ * @ret rc Return status code
|
|
112
|
+ */
|
|
113
|
+int uart_init ( struct uart *uart, unsigned int baud, uint8_t lcr ) {
|
|
114
|
+ uint8_t dlm;
|
|
115
|
+ uint8_t dll;
|
|
116
|
+ int rc;
|
|
117
|
+
|
|
118
|
+ /* Check for existence of UART */
|
|
119
|
+ if ( ( rc = uart_exists ( uart ) ) != 0 )
|
|
120
|
+ return rc;
|
|
121
|
+
|
104
|
122
|
/* Configure divisor and line control register, if applicable */
|
105
|
123
|
if ( ! lcr )
|
106
|
124
|
lcr = uart_read ( uart, UART_LCR );
|