wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 1 | /* |
Michal Simek | 403d619 | 2008-07-11 10:10:31 +0200 | [diff] [blame] | 2 | * (C) Copyright 2008 Michal Simek <monstr@monstr.eu> |
| 3 | * Clean driver and add xilinx constant from header file |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 4 | * |
Michal Simek | 403d619 | 2008-07-11 10:10:31 +0200 | [diff] [blame] | 5 | * (C) Copyright 2004 Atmark Techno, Inc. |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 6 | * Yasushi SHOJI <yashi@atmark-techno.com> |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (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 |
Michal Simek | 403d619 | 2008-07-11 10:10:31 +0200 | [diff] [blame] | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <config.h> |
Michal Simek | 403d619 | 2008-07-11 10:10:31 +0200 | [diff] [blame] | 28 | #include <asm/io.h> |
wdenk | e44b911 | 2004-04-18 23:32:11 +0000 | [diff] [blame] | 29 | |
Michal Simek | fbb2d01 | 2007-09-24 00:25:11 +0200 | [diff] [blame] | 30 | #ifdef CONFIG_XILINX_UARTLITE |
wdenk | e44b911 | 2004-04-18 23:32:11 +0000 | [diff] [blame] | 31 | |
Michal Simek | 403d619 | 2008-07-11 10:10:31 +0200 | [diff] [blame] | 32 | #define RX_FIFO_OFFSET 0 /* receive FIFO, read only */ |
| 33 | #define TX_FIFO_OFFSET 4 /* transmit FIFO, write only */ |
| 34 | #define STATUS_REG_OFFSET 8 /* status register, read only */ |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 35 | |
Michal Simek | 403d619 | 2008-07-11 10:10:31 +0200 | [diff] [blame] | 36 | #define SR_TX_FIFO_FULL 0x08 /* transmit FIFO full */ |
| 37 | #define SR_RX_FIFO_VALID_DATA 0x01 /* data in receive FIFO */ |
| 38 | #define SR_RX_FIFO_FULL 0x02 /* receive FIFO full */ |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 39 | |
Michal Simek | 403d619 | 2008-07-11 10:10:31 +0200 | [diff] [blame] | 40 | #define UARTLITE_STATUS (CONFIG_SERIAL_BASE + STATUS_REG_OFFSET) |
| 41 | #define UARTLITE_TX_FIFO (CONFIG_SERIAL_BASE + TX_FIFO_OFFSET) |
| 42 | #define UARTLITE_RX_FIFO (CONFIG_SERIAL_BASE + RX_FIFO_OFFSET) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 43 | |
| 44 | int serial_init(void) |
| 45 | { |
| 46 | /* FIXME: Nothing for now. We should initialize fifo, etc */ |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | void serial_setbrg(void) |
| 51 | { |
| 52 | /* FIXME: what's this for? */ |
| 53 | } |
| 54 | |
| 55 | void serial_putc(const char c) |
| 56 | { |
Michal Simek | 403d619 | 2008-07-11 10:10:31 +0200 | [diff] [blame] | 57 | if (c == '\n') |
| 58 | serial_putc('\r'); |
Stefan Roese | 1fbbe60 | 2008-07-18 12:24:41 +0200 | [diff] [blame] | 59 | while (in_be32((void *)UARTLITE_STATUS) & SR_TX_FIFO_FULL); |
| 60 | out_be32((void *)UARTLITE_TX_FIFO, (unsigned char) (c & 0xff)); |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void serial_puts(const char * s) |
| 64 | { |
| 65 | while (*s) { |
| 66 | serial_putc(*s++); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | int serial_getc(void) |
| 71 | { |
Stefan Roese | 1fbbe60 | 2008-07-18 12:24:41 +0200 | [diff] [blame] | 72 | while (!(in_be32((void *)UARTLITE_STATUS) & SR_RX_FIFO_VALID_DATA)); |
| 73 | return in_be32((void *)UARTLITE_RX_FIFO) & 0xff; |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | int serial_tstc(void) |
| 77 | { |
Stefan Roese | 1fbbe60 | 2008-07-18 12:24:41 +0200 | [diff] [blame] | 78 | return (in_be32((void *)UARTLITE_STATUS) & SR_RX_FIFO_VALID_DATA); |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 79 | } |
wdenk | e44b911 | 2004-04-18 23:32:11 +0000 | [diff] [blame] | 80 | |
| 81 | #endif /* CONFIG_MICROBLZE */ |