OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [arch/] [or32/] [kernel/] [dbgport.c] - Rev 1765

Compare with Previous | Blame | View Log

/*
 *  linux/arch/or32/kernel/dbgport.c
 *
 *  or32 version
 *    author(s): Simon Srot (srot@opencores.org)
 *
 *  changes:
 *  18. 11. 2003: Matjaz Breskvar (phoenix@opencores.org)
 *    initial port to or32 architecture
 *
 */
 
#include <linux/kernel.h> 
#include <linux/init.h>
#include <linux/major.h>
#include <linux/console.h>
#include <linux/serial_reg.h>
#include <asm/system.h>
#include <asm/board.h>
 
#define BASE_BAUD_OR1K ( SYS_CLK / 16 )
 
#define REG8(x) (*(volatile unsigned char *)(x))
 
#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
#define WAIT_FOR_XMITR \
 do { \
       lsr = REG8(UART_BASE_ADD + UART_LSR); \
 } while ((lsr & BOTH_EMPTY) != BOTH_EMPTY)
 
kdev_t or32_console_device(struct console *c)
{
	return MKDEV(TTY_MAJOR, 64 + c->index);
}
 
int or32_console_setup(struct console *co, char *options)
{
 
	int devisor;
 
	/* Reset receiver and transmiter */
	REG8(UART_BASE_ADD + UART_FCR) = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT;
 
	/* Disable all interrupts */
	REG8(UART_BASE_ADD + UART_IER) = 0x00;
 
	/* Set 8 bit char, 1 stop bit, no parity */
	REG8(UART_BASE_ADD + UART_LCR) = UART_LCR_WLEN8 & ~(UART_LCR_STOP | UART_LCR_PARITY); 
 
	/* Set baud rate */
	devisor = BASE_BAUD_OR1K/OR32_CONSOLE_BAUD;
	REG8(UART_BASE_ADD + UART_LCR) |= UART_LCR_DLAB;
	REG8(UART_BASE_ADD + UART_DLL) = devisor & 0x000000ff;
	REG8(UART_BASE_ADD + UART_DLM) = (devisor >> 8) & 0x000000ff;
	REG8(UART_BASE_ADD + UART_LCR) &= ~(UART_LCR_DLAB); 
 
	return 0;
}
 
 
void or32_console_write(struct console *co, const char *buf, unsigned int len)
{
 
	char c;
	unsigned char ier, lsr;
	unsigned long flags;
 
	extern void putc(char);
 
	save_flags(flags);
	cli();
 
	ier = REG8(UART_BASE_ADD + UART_IER);
	REG8(UART_BASE_ADD + UART_IER) = 0x00;
 
	for (; len; len--, buf++) {
		c = *buf;
 
		WAIT_FOR_XMITR;
		REG8(UART_BASE_ADD + UART_TX) = c;
 
		if (c == '\n') {
			WAIT_FOR_XMITR;
			REG8(UART_BASE_ADD + UART_TX) = '\r';
		}
	}
 
	WAIT_FOR_XMITR;
	REG8(UART_BASE_ADD + UART_IER) = ier;
 
	/* Dummy read to clear all pending interrupt */
	REG8(UART_BASE_ADD + UART_IIR);
	REG8(UART_BASE_ADD + UART_LSR);
 
	restore_flags(flags);
 
	return;
}
 
static struct console or32_console = {
	name:    "ttyS",
	write:   or32_console_write,
	device:  or32_console_device,
	unblank: NULL,
	setup:   or32_console_setup,
	flags:   CON_PRINTBUFFER,
	index:   -1,
	cflag:   0,
	next:    NULL
};
 
void __init init_or32_console(void)
{
        register_console(&or32_console);
}
 
 

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.