summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx233/uartdbg-imx233.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-06-18 16:24:28 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-06-18 16:24:28 +0200
commitbbb789120ce4c2eb470233920e602e5f79c62430 (patch)
treeecc93452c0b4d5b5e243c34c2e90d511b671b679 /firmware/target/arm/imx233/uartdbg-imx233.c
parent49628540053103315a188164c96fdedb524ae59c (diff)
downloadrockbox-bbb789120ce4c2eb470233920e602e5f79c62430.tar.gz
rockbox-bbb789120ce4c2eb470233920e602e5f79c62430.zip
imx233: add uartdbg driver
The driver is current unused and very minimal. It can used on targets which have an accessible UART port and it will be used on some creative targets as backlight control. Change-Id: Id710d63574aadb0a2d7327b03187506b469470b1
Diffstat (limited to 'firmware/target/arm/imx233/uartdbg-imx233.c')
-rw-r--r--firmware/target/arm/imx233/uartdbg-imx233.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/uartdbg-imx233.c b/firmware/target/arm/imx233/uartdbg-imx233.c
new file mode 100644
index 0000000000..077b405f49
--- /dev/null
+++ b/firmware/target/arm/imx233/uartdbg-imx233.c
@@ -0,0 +1,74 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2013 by Lorenzo Miori
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "uartdbg-imx233.h"
22#include "pinctrl-imx233.h"
23#include "clkctrl-imx233.h"
24
25void imx233_uartdbg_init(unsigned long baud)
26{
27 /* Enable UART clock */
28 imx233_clkctrl_enable(CLK_UART, true);
29 /* Configure UART pins */
30 imx233_pinctrl_setup_vpin(VPIN_UARTDBG_TX, "uartdbg tx", PINCTRL_DRIVE_4mA, false);
31 imx233_pinctrl_setup_vpin(VPIN_UARTDBG_RX, "uartdbg rx", PINCTRL_DRIVE_4mA, false);
32
33 /* Set baud rate */
34 HW_UARTDBG_IBRD = baud >> 16;
35 HW_UARTDBG_FBRD = baud & 0xFFFF;
36
37 /* Set port options (actually needed to set baud rate), 8 bit char, enable FIFO buffer */
38 BF_WR(UARTDBG_LCR_H, WLEN, 3);
39 BF_WR(UARTDBG_LCR_H, FEN, 1);
40
41 /* Finally enable UART device, TX enable, RX enable, device enable */
42 BF_WR(UARTDBG_CR, TXE, 1);
43 BF_WR(UARTDBG_CR, RXE, 1);
44 BF_WR(UARTDBG_CR, UARTEN, 1);
45}
46
47void imx233_uartdbg_send(unsigned char data)
48{
49 /* Wait to transmit if TX FIFO buffer is full*/
50 while (BF_RD(UARTDBG_FR, TXFF));
51 BF_WR(UARTDBG_DR, DATA, data);
52}
53
54void uart_tx(const char* data)
55{
56 while (*data != 0)
57 imx233_uartdbg_send(*data++);
58}
59
60unsigned int uart_rx(char* rx_buf, unsigned int len)
61{
62 unsigned int i = 0;
63
64 while(i < len)
65 {
66 /* Check if the UART Rx Buffer has something into -> RXFE */
67 if(!BF_RD(UARTDBG_FR, RXFE))
68 {
69 rx_buf[i] = HW_UARTDBG_DR;
70 i++;
71 }
72 }
73 return i;
74} \ No newline at end of file