summaryrefslogtreecommitdiffstats
path: root/drivers/serial/serial_mpc5xxx.c
blob: 54c2d02ba67fa7cff130dc803709ebc1b0b7a453 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * (C) Copyright 2000 - 2003
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 *
 * Hacked for MPC8260 by Murray.Jensen@cmst.csiro.au, 19-Oct-00, with
 * changes based on the file arch/ppc/mbxboot/m8260_tty.c from the
 * Linux/PPC sources (m8260_tty.c had no copyright info in it).
 *
 * Martin Krause, 8 Jun 2006
 * Added CONFIG_SERIAL_MULTI support
 */

/*
 * Minimal serial functions needed to use one of the PSC ports
 * as serial console interface.
 */

#include <common.h>
#include <asm/arch/mpc5xxx.h>
#include <driver.h>
#include <init.h>
#include <console.h>
#include <xfuncs.h>
#include <asm/arch/clocks.h>

static void mpc5xxx_serial_setbrg(struct console_device *cdev)
{
	struct device_d *dev = cdev->dev;
	volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev->map_base;
	unsigned long baseclk;
	int div;
return;
	printf("%s: ipb\n", __FUNCTION__);
#if defined(CONFIG_MGT5100)
	baseclk = (CFG_MPC5XXX_CLKIN + 16) / 32;
#elif defined(CONFIG_MPC5200)
	baseclk = (get_ipb_clock() + 16) / 32;
#endif
	printf("done: %d\n", get_ipb_clock());
	/* set up UART divisor */
#if 0
	div = (baseclk + (gd->baudrate/2)) / gd->baudrate;
#else
#warning mpc5200 serial: temporary baudrate hack
	div = (baseclk + (115200 / 2)) / 115200;
#endif
	psc->ctur = (div >> 8) & 0xFF;
	psc->ctlr =  div & 0xff;
}

static int mpc5xxx_serial_init(struct console_device *cdev)
{
	struct device_d *dev = cdev->dev;
	volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev->map_base;
return 0;
	/* reset PSC */
	psc->command = PSC_SEL_MODE_REG_1;

	/* select clock sources */
#if defined(CONFIG_MGT5100)
	psc->psc_clock_select = 0xdd00;
#elif defined(CONFIG_MPC5200)
	psc->psc_clock_select = 0;
#endif

	/* switch to UART mode */
	psc->sicr = 0;

	/* configure parity, bit length and so on */
#if defined(CONFIG_MGT5100)
	psc->mode = PSC_MODE_ERR | PSC_MODE_8_BITS | PSC_MODE_PARNONE;
#elif defined(CONFIG_MPC5200)
	psc->mode = PSC_MODE_8_BITS | PSC_MODE_PARNONE;
#endif
	psc->mode = PSC_MODE_ONE_STOP;

	mpc5xxx_serial_setbrg(cdev);

	/* disable all interrupts */
	psc->psc_imr = 0;

	/* reset and enable Rx/Tx */
	psc->command = PSC_RST_RX;
	psc->command = PSC_RST_TX;
	psc->command = PSC_RX_ENABLE | PSC_TX_ENABLE;

	return (0);
}

static void mpc5xxx_serial_putc (struct console_device *cdev, const char c)
{
	struct device_d *dev = cdev->dev;
	volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev->map_base;

	/* Wait for last character to go. */
	while (!(psc->psc_status & PSC_SR_TXEMP))
		;

	psc->psc_buffer_8 = c;
}

static int mpc5xxx_serial_getc (struct console_device *cdev)
{
	struct device_d *dev = cdev->dev;
	volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev->map_base;

	/* Wait for a character to arrive. */
	while (!(psc->psc_status & PSC_SR_RXRDY))
		;

	return psc->psc_buffer_8;
}

static int mpc5xxx_serial_tstc (struct console_device *cdev)
{
	struct device_d *dev = cdev->dev;
	volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev->map_base;

	return (psc->psc_status & PSC_SR_RXRDY);
}

static int mpc5xxx_serial_probe(struct device_d *dev)
{
	struct console_device *cdev;

	cdev = xzalloc(sizeof(struct console_device));
	dev->type_data = cdev;
	cdev->dev = dev;
	cdev->f_caps = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR;
	cdev->tstc = mpc5xxx_serial_tstc;
	cdev->putc = mpc5xxx_serial_putc;
	cdev->getc = mpc5xxx_serial_getc;

	mpc5xxx_serial_init(cdev);

	console_register(cdev);

	return 0;
}

static struct driver_d mpc5xxx_serial_driver = {
        .name  = "mpc5xxx_serial",
        .probe = mpc5xxx_serial_probe,
        .type  = DEVICE_TYPE_CONSOLE,
};

static int mpc5xxx_serial_register(void)
{
	register_driver(&mpc5xxx_serial_driver);
	return 0;
}

console_initcall(mpc5xxx_serial_register);