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**************************************/
41 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
42 #include <linux/module.h>
43 #include <asm/octeon/cvmx.h>
44 #include <asm/octeon/cvmx-clock.h>
45 #include <asm/octeon/cvmx-uart.h>
48 #include "cvmx-uart.h"
49 #include "cvmx-interrupt.h"
52 #ifndef CVMX_BUILD_FOR_TOOLCHAIN
53 void cvmx_uart_enable_intr(int uart, cvmx_uart_intr_handler_t handler)
55 #ifndef CVMX_BUILD_FOR_LINUX_KERNEL
58 cvmx_interrupt_register(CVMX_IRQ_UART0 + uart, handler, NULL);
59 /* Enable uart interrupts for debugger Control-C processing */
60 ier.u64 = cvmx_read_csr(CVMX_MIO_UARTX_IER(uart));
62 cvmx_write_csr(CVMX_MIO_UARTX_IER(uart), ier.u64);
64 cvmx_interrupt_unmask_irq(CVMX_IRQ_UART0 + uart);
69 static int cvmx_uart_simulator_p(void)
71 #ifndef CVMX_BUILD_FOR_TOOLCHAIN
72 return cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_SIM;
74 extern int __octeon_simulator_p;
75 return __octeon_simulator_p;
81 * Function that does the real work of setting up the Octeon uart.
82 * Takes all parameters as arguments, so it does not require gd
83 * structure to be set up.
85 * @param uart_index Index of uart to configure
86 * @param cpu_clock_hertz
87 * CPU clock frequency in Hz
88 * @param baudrate Baudrate to configure
90 * @return 0 on success
93 int cvmx_uart_setup2(int uart_index, int cpu_clock_hertz, int baudrate)
96 cvmx_uart_fcr_t fcrval;
97 cvmx_uart_mcr_t mcrval;
98 cvmx_uart_lcr_t lcrval;
101 fcrval.s.en = 1; /* enable the FIFO's */
102 fcrval.s.rxfr = 1; /* reset the RX fifo */
103 fcrval.s.txfr = 1; /* reset the TX fifo */
105 if (cvmx_uart_simulator_p())
108 divisor = ((unsigned long)(cpu_clock_hertz + 8 * baudrate) / (unsigned long)(16 * baudrate));
110 cvmx_write_csr(CVMX_MIO_UARTX_FCR(uart_index), fcrval.u64);
113 if (uart_index == 1 && cvmx_uart_simulator_p())
114 mcrval.s.afce = 1; /* enable auto flow control for simulator. Needed for gdb regression callfuncs.exp. */
116 mcrval.s.afce = 0; /* disable auto flow control so board can power on without serial port connected */
118 mcrval.s.rts = 1; /* looks like this must be set for auto flow control to work */
120 cvmx_read_csr(CVMX_MIO_UARTX_LSR(uart_index));
123 lcrval.s.cls = CVMX_UART_BITS8;
124 lcrval.s.stop = 0; /* stop bit included? */
125 lcrval.s.pen = 0; /* no parity? */
126 lcrval.s.eps = 1; /* even parity? */
127 lcrval.s.dlab = 1; /* temporary to program the divisor */
128 cvmx_write_csr(CVMX_MIO_UARTX_LCR(uart_index), lcrval.u64);
130 cvmx_write_csr(CVMX_MIO_UARTX_DLL(uart_index), divisor & 0xff);
131 cvmx_write_csr(CVMX_MIO_UARTX_DLH(uart_index), (divisor>>8) & 0xff);
133 lcrval.s.dlab = 0; /* divisor is programmed now, set this back to normal */
134 cvmx_write_csr(CVMX_MIO_UARTX_LCR(uart_index), lcrval.u64);
136 /* spec says need to wait after you program the divisor */
137 if (!cvmx_uart_simulator_p())
140 CVMX_MF_CYCLE (read_cycle);
141 read_cycle += (2 * divisor * 16) + 10000;
147 CVMX_MF_CYCLE (new_cycle);
148 if (new_cycle >= read_cycle)
153 /* Don't enable flow control until after baud rate is configured. - we don't want
154 ** to allow characters in until after the baud rate is fully configured */
155 cvmx_write_csr(CVMX_MIO_UARTX_MCR(uart_index), mcrval.u64);
161 * Setup a uart for use
163 * @param uart_index Uart to setup (0 or 1)
164 * @return Zero on success
166 int cvmx_uart_setup (int uart_index)
168 return cvmx_uart_setup2(uart_index, cvmx_clock_get_rate (CVMX_CLOCK_SCLK), 115200);