carl9170: Update based on commit 467556acea56f361a21b2a3761ca056b9da2d237 dated Nov...
[linux-libre-firmware.git] / carl9170fw / carlfw / src / uart.c
1 /*
2  * carl9170 firmware - used by the ar9170 wireless device
3  *
4  * UART debug interface functions.
5  *
6  * Copyright (c) 2000-2005 ZyDAS Technology Corporation
7  * Copyright (c) 2007-2009 Atheros Communications, Inc.
8  * Copyright    2009    Johannes Berg <johannes@sipsolutions.net>
9  * Copyright 2009-2011  Christian Lamparter <chunkeey@googlemail.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; If not, see <http://www.gnu.org/licenses/>.
23  */
24
25 #include "carl9170.h"
26 #include "uart.h"
27 #include "io.h"
28
29 #ifdef CONFIG_CARL9170FW_DEBUG_UART
30 void uart_putc(const char c)
31 {
32         set(AR9170_UART_REG_TX_HOLDING, c);
33
34         while (get(AR9170_UART_REG_LINE_STATUS) &
35                AR9170_UART_LINE_STS_TX_FIFO_NEAR_EMPTY) {
36                 /*
37                  * wait until the byte has made it
38                  */
39         }
40 }
41
42 void uart_print_hex_dump(const void *buf, const int len)
43 {
44         unsigned int offset = 0;
45
46         uart_putc('H');
47         uart_putc('D');
48         uart_putc(':');
49
50         while (len > 0) {
51                 uart_putc(*((uint8_t *) buf + offset));
52                 offset++;
53         }
54 }
55
56 void uart_init(void)
57 {
58         unsigned int timeout = 0;
59
60 #ifdef CONFIG_CARL9170FW_UART_CLOCK_25M
61         set(AR9170_UART_REG_DIVISOR_LSB, 0xc);
62 #elif CONFIG_CARL9170FW_UART_CLOCK_40M
63         set(AR9170_UART_REG_DIVISOR_LSB, 0x14); /* 40 MHz */
64         set(AR9170_UART_REG_REMAINDER, 0xb38e);
65 #else
66 #error "Unsupported UART clock"
67 #endif /* CARL9170FW_UART_CLOCK_25M */
68
69         while (get(AR9170_UART_REG_LINE_STATUS) &
70                AR9170_UART_LINE_STS_TRANSMITTER_EMPTY) {
71                 if (timeout++ >= 10000)
72                         break;
73         }
74 }
75 #endif /* CONFIG_CARL9170FW_DEBUG_UART */