wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, <wd@denx.de> |
| 4 | * |
| 5 | * (C) Copyright 2002 |
| 6 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 7 | * Marius Groeger <mgroeger@sysgo.de> |
| 8 | * |
| 9 | * (C) Copyright 2002 |
| 10 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 11 | * Alex Zuepke <azu@sysgo.de> |
| 12 | * |
| 13 | * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) |
| 14 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 15 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <common.h> |
| 19 | #include <asm/arch/ixp425.h> |
Michael Schwingen | 009e464 | 2011-05-22 23:59:59 +0200 | [diff] [blame] | 20 | #include <watchdog.h> |
Marek Vasut | b6cd0fe | 2012-09-14 22:35:14 +0200 | [diff] [blame] | 21 | #include <serial.h> |
| 22 | #include <linux/compiler.h> |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 23 | |
Jean-Christophe PLAGNIOL-VILLARD | 7b74ebe | 2007-12-08 16:34:08 +0100 | [diff] [blame] | 24 | /* |
| 25 | * 14.7456 MHz |
| 26 | * Baud Rate = -------------- |
| 27 | * 16 x Divisor |
| 28 | */ |
Wolfgang Denk | 07eb026 | 2008-01-09 13:43:38 +0100 | [diff] [blame] | 29 | #define SERIAL_CLOCK 921600 |
Jean-Christophe PLAGNIOL-VILLARD | 7b74ebe | 2007-12-08 16:34:08 +0100 | [diff] [blame] | 30 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
Marek Vasut | b6cd0fe | 2012-09-14 22:35:14 +0200 | [diff] [blame] | 33 | static void ixp_serial_setbrg(void) |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 34 | { |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 35 | unsigned int quot = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 36 | int uart = CONFIG_SYS_IXP425_CONSOLE; |
Wolfgang Denk | 07eb026 | 2008-01-09 13:43:38 +0100 | [diff] [blame] | 37 | |
Jean-Christophe PLAGNIOL-VILLARD | 7b74ebe | 2007-12-08 16:34:08 +0100 | [diff] [blame] | 38 | if ((gd->baudrate <= SERIAL_CLOCK) && (SERIAL_CLOCK % gd->baudrate == 0)) |
| 39 | quot = SERIAL_CLOCK / gd->baudrate; |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 40 | else |
| 41 | hang (); |
| 42 | |
| 43 | IER(uart) = 0; /* Disable for now */ |
| 44 | FCR(uart) = 0; /* No fifos enabled */ |
| 45 | |
| 46 | /* set baud rate */ |
| 47 | LCR(uart) = LCR_WLS0 | LCR_WLS1 | LCR_DLAB; |
| 48 | DLL(uart) = quot & 0xff; |
| 49 | DLH(uart) = quot >> 8; |
| 50 | LCR(uart) = LCR_WLS0 | LCR_WLS1; |
Michael Schwingen | 96bd462 | 2008-01-10 14:59:46 +0100 | [diff] [blame] | 51 | #ifdef CONFIG_SERIAL_RTS_ACTIVE |
| 52 | MCR(uart) = MCR_RTS; /* set RTS active */ |
| 53 | #else |
| 54 | MCR(uart) = 0; /* set RTS inactive */ |
| 55 | #endif |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 56 | IER(uart) = IER_UUE; |
| 57 | } |
| 58 | |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 59 | /* |
| 60 | * Initialise the serial port with the given baudrate. The settings |
| 61 | * are always 8 data bits, no parity, 1 stop bit, no start bits. |
| 62 | * |
| 63 | */ |
Marek Vasut | b6cd0fe | 2012-09-14 22:35:14 +0200 | [diff] [blame] | 64 | static int ixp_serial_init(void) |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 65 | { |
| 66 | serial_setbrg (); |
| 67 | |
| 68 | return (0); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | /* |
| 73 | * Output a single byte to the serial port. |
| 74 | */ |
Marek Vasut | b6cd0fe | 2012-09-14 22:35:14 +0200 | [diff] [blame] | 75 | static void ixp_serial_putc(const char c) |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 76 | { |
| 77 | /* wait for room in the tx FIFO on UART */ |
Michael Schwingen | 009e464 | 2011-05-22 23:59:59 +0200 | [diff] [blame] | 78 | while ((LSR(CONFIG_SYS_IXP425_CONSOLE) & LSR_TEMT) == 0) |
| 79 | WATCHDOG_RESET(); /* Reset HW Watchdog, if needed */ |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 80 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 81 | THR(CONFIG_SYS_IXP425_CONSOLE) = c; |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 82 | |
| 83 | /* If \n, also do \r */ |
| 84 | if (c == '\n') |
| 85 | serial_putc ('\r'); |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Read a single byte from the serial port. Returns 1 on success, 0 |
| 90 | * otherwise. When the function is succesfull, the character read is |
| 91 | * written into its argument c. |
| 92 | */ |
Marek Vasut | b6cd0fe | 2012-09-14 22:35:14 +0200 | [diff] [blame] | 93 | static int ixp_serial_tstc(void) |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 94 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 95 | return LSR(CONFIG_SYS_IXP425_CONSOLE) & LSR_DR; |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /* |
| 99 | * Read a single byte from the serial port. Returns 1 on success, 0 |
| 100 | * otherwise. When the function is succesfull, the character read is |
| 101 | * written into its argument c. |
| 102 | */ |
Marek Vasut | b6cd0fe | 2012-09-14 22:35:14 +0200 | [diff] [blame] | 103 | static int ixp_serial_getc(void) |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 104 | { |
Michael Schwingen | 009e464 | 2011-05-22 23:59:59 +0200 | [diff] [blame] | 105 | while (!(LSR(CONFIG_SYS_IXP425_CONSOLE) & LSR_DR)) |
| 106 | WATCHDOG_RESET(); /* Reset HW Watchdog, if needed */ |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 107 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 108 | return (char) RBR(CONFIG_SYS_IXP425_CONSOLE) & 0xff; |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Marek Vasut | b6cd0fe | 2012-09-14 22:35:14 +0200 | [diff] [blame] | 111 | static struct serial_device ixp_serial_drv = { |
| 112 | .name = "ixp_serial", |
| 113 | .start = ixp_serial_init, |
| 114 | .stop = NULL, |
| 115 | .setbrg = ixp_serial_setbrg, |
| 116 | .putc = ixp_serial_putc, |
Marek Vasut | ec3fd68 | 2012-10-06 14:07:02 +0000 | [diff] [blame] | 117 | .puts = default_serial_puts, |
Marek Vasut | b6cd0fe | 2012-09-14 22:35:14 +0200 | [diff] [blame] | 118 | .getc = ixp_serial_getc, |
| 119 | .tstc = ixp_serial_tstc, |
| 120 | }; |
| 121 | |
| 122 | void ixp_serial_initialize(void) |
| 123 | { |
| 124 | serial_register(&ixp_serial_drv); |
| 125 | } |
| 126 | |
| 127 | __weak struct serial_device *default_serial_console(void) |
| 128 | { |
| 129 | return &ixp_serial_drv; |
| 130 | } |