diff options
author | Anatolij Gustschin <agust@denx.de> | 2010-04-24 19:27:06 +0200 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2010-04-24 22:56:32 +0200 |
commit | 8e234e33bf60a850685c7e81ea92d383c643486b (patch) | |
tree | 2084e709ebde4f2bb4f751dcce98d95adf4e92bb /arch/powerpc/cpu/mpc512x | |
parent | e3b28e67329de99a315d509920760dcbc565f8c6 (diff) | |
download | u-boot-imx-8e234e33bf60a850685c7e81ea92d383c643486b.zip u-boot-imx-8e234e33bf60a850685c7e81ea92d383c643486b.tar.gz u-boot-imx-8e234e33bf60a850685c7e81ea92d383c643486b.tar.bz2 |
mpc5121: add PSC serial communication routines
Signed-off-by: Anatolij Gustschin <agust@denx.de>
Diffstat (limited to 'arch/powerpc/cpu/mpc512x')
-rw-r--r-- | arch/powerpc/cpu/mpc512x/serial.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/arch/powerpc/cpu/mpc512x/serial.c b/arch/powerpc/cpu/mpc512x/serial.c index f421968..cb5bbf0 100644 --- a/arch/powerpc/cpu/mpc512x/serial.c +++ b/arch/powerpc/cpu/mpc512x/serial.c @@ -401,3 +401,90 @@ int serial_getcts(void) return serial_getcts_dev(CONFIG_PSC_CONSOLE); } #endif /* CONFIG_PSC_CONSOLE */ + +#if defined(CONFIG_SERIAL_MULTI) +#include <stdio_dev.h> +/* + * Routines for communication with serial devices over PSC + */ +/* Bitfield for initialized PSCs */ +static unsigned int initialized; + +struct stdio_dev *open_port(int num, int baudrate) +{ + struct stdio_dev *port; + char env_var[16]; + char env_val[10]; + char name[7]; + + if (num < 0 || num > 11) + return NULL; + + sprintf(name, "psc%d", num); + port = stdio_get_by_name(name); + if (!port) + return NULL; + + if (!test_bit(num, &initialized)) { + sprintf(env_var, "psc%d_baudrate", num); + sprintf(env_val, "%d", baudrate); + setenv(env_var, env_val); + + if (port->start()) + return NULL; + + set_bit(num, &initialized); + } + + return port; +} + +int close_port(int num) +{ + struct stdio_dev *port; + int ret; + char name[7]; + + if (num < 0 || num > 11) + return -1; + + sprintf(name, "psc%d", num); + port = stdio_get_by_name(name); + if (!port) + return -1; + + ret = port->stop(); + clear_bit(num, &initialized); + + return ret; +} + +int write_port(struct stdio_dev *port, char *buf) +{ + if (!port || !buf) + return -1; + + port->puts(buf); + + return 0; +} + +int read_port(struct stdio_dev *port, char *buf, int size) +{ + int cnt = 0; + + if (!port || !buf) + return -1; + + if (!size) + return 0; + + while (port->tstc()) { + buf[cnt++] = port->getc(); + if (cnt > size) + break; + } + + return cnt; +} +#endif /* CONFIG_SERIAL_MULTI */ |