1/*
2 * kgdb debug routines for swarm board.
3 *
4 * Copyright (C) 2001 MontaVista Software Inc.
5 * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
6 *
7 * This program is free software; you can redistribute  it and/or modify it
8 * under  the terms of  the GNU General  Public License as published by the
9 * Free Software Foundation;  either version 2 of the  License, or (at your
10 * option) any later version.
11 *
12 */
13
14/* -------------------- BEGINNING OF CONFIG --------------------- */
15
16#include <linux/delay.h>
17#include <asm/sibyte/sb1250.h>
18#include <asm/sibyte/sb1250_regs.h>
19#include <asm/sibyte/sb1250_uart.h>
20#include <asm/sibyte/sb1250_int.h>
21#include <asm/sibyte/64bit.h>
22#include <asm/addrspace.h>
23
24/*
25 * We use the second serial port for kgdb traffic.
26 * 	115200, 8, N, 1.
27 */
28
29#define	BAUD_RATE		115200
30#define	CLK_DIVISOR		V_DUART_BAUD_RATE(BAUD_RATE)
31#define	DATA_BITS		V_DUART_BITS_PER_CHAR_8		/* or 7    */
32#define	PARITY			V_DUART_PARITY_MODE_NONE	/* or even */
33#define	STOP_BITS		M_DUART_STOP_BIT_LEN_1		/* or 2    */
34
35static int duart_initialized = 0;	/* 0: need to be init'ed by kgdb */
36
37/* -------------------- END OF CONFIG --------------------- */
38
39
40#define	duart_out(reg, val)	out64(val, KSEG1 + A_DUART_CHANREG(1,reg))
41#define duart_in(reg)		in64(KSEG1 + A_DUART_CHANREG(1,reg))
42
43extern void set_async_breakpoint(unsigned int epc);
44
45void putDebugChar(unsigned char c);
46unsigned char getDebugChar(void);
47static void
48duart_init(int clk_divisor, int data, int parity, int stop)
49{
50	duart_out(R_DUART_MODE_REG_1, data | parity);
51	duart_out(R_DUART_MODE_REG_2, stop);
52	duart_out(R_DUART_CLK_SEL, clk_divisor);
53
54	duart_out(R_DUART_CMD, M_DUART_RX_EN | M_DUART_TX_EN);	/* enable rx and tx */
55}
56
57void
58putDebugChar(unsigned char c)
59{
60	if (!duart_initialized) {
61		duart_initialized = 1;
62		duart_init(CLK_DIVISOR, DATA_BITS, PARITY, STOP_BITS);
63	}
64	while ((duart_in(R_DUART_STATUS) & M_DUART_TX_RDY) == 0);
65	duart_out(R_DUART_TX_HOLD, c);
66}
67
68unsigned char
69getDebugChar(void)
70{
71	if (!duart_initialized) {
72		duart_initialized = 1;
73		duart_init(CLK_DIVISOR, DATA_BITS, PARITY, STOP_BITS);
74	}
75	while ((duart_in(R_DUART_STATUS) & M_DUART_RX_RDY) == 0) ;
76	return duart_in(R_DUART_RX_HOLD);
77}
78
79