1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Inc. (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * * Neither the name of Cavium Inc. nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
23 * This Software, including technical data, may be subject to U.S. export control
24 * laws, including the U.S. Export Administration Act and its associated
25 * regulations, and may be subject to export or import regulations in other
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
49 * interface to the serial port UART hardware
51 * <hr>$Revision: 70030 $<hr>
55 #ifndef __CVMX_UART_H__
56 #define __CVMX_UART_H__
62 #define CVMX_UART_NUM_PORTS 2
63 #define CVMX_UART_TX_FIFO_SIZE 64
64 #define CVMX_UART_RX_FIFO_SIZE 64
66 /* CSR typedefs have been moved to cvmx-uart-defs.h */
68 typedef void (*cvmx_uart_intr_handler_t)(int, uint64_t[], void *);
70 extern void cvmx_uart_enable_intr(int, cvmx_uart_intr_handler_t);
71 extern int cvmx_uart_setup2(int, int, int);
72 extern int cvmx_uart_setup(int);
74 /* Defined in libc. */
75 unsigned __octeon_uart_trylock (void);
76 void __octeon_uart_unlock (void);
79 * Get a single byte from serial port.
81 * @param uart_index Uart to read from (0 or 1)
82 * @return The byte read
84 static inline uint8_t cvmx_uart_read_byte(int uart_index)
86 cvmx_uart_lsr_t lsrval;
88 /* Spin until data is available */
91 lsrval.u64 = cvmx_read_csr(CVMX_MIO_UARTX_LSR(uart_index));
92 } while (!lsrval.s.dr);
94 /* Read and return the data */
95 return cvmx_read_csr(CVMX_MIO_UARTX_RBR(uart_index));
99 * Get a single byte from serial port with a timeout.
101 * @param uart_index Uart to read from (0 or 1)
102 * @param timedout Record if a timeout has happened
103 * @param timeout the timeout count
104 * @return The byte read
106 static inline uint8_t cvmx_uart_read_byte_with_timeout(int uart_index, int *timedout, volatile unsigned timeout)
108 cvmx_uart_lsr_t lsrval;
110 /* Spin until data is available */
119 lsrval.u64 = cvmx_read_csr(CVMX_MIO_UARTX_LSR(uart_index));
121 } while (!lsrval.s.dr);
123 /* Read and return the data */
124 return cvmx_read_csr(CVMX_MIO_UARTX_RBR(uart_index));
129 * Put a single byte to uart port.
131 * @param uart_index Uart to write to (0 or 1)
132 * @param ch Byte to write
134 static inline void cvmx_uart_write_byte(int uart_index, uint8_t ch)
136 cvmx_uart_lsr_t lsrval;
138 /* Spin until there is room */
141 lsrval.u64 = cvmx_read_csr(CVMX_MIO_UARTX_LSR(uart_index));
143 while (lsrval.s.thre == 0);
146 cvmx_write_csr(CVMX_MIO_UARTX_THR(uart_index), ch);
150 * Write a string to the uart
152 * @param uart_index Uart to use (0 or 1)
153 * @param str String to write
155 static inline void cvmx_uart_write_string(int uart_index, const char *str)
157 /* Just loop writing one byte at a time */
160 cvmx_uart_write_byte(uart_index, *str);
169 #endif /* __CVM_UART_H__ */