TTY: pdc_cons, use tty_port
[deliverable/linux.git] / arch / parisc / kernel / pdc_cons.c
CommitLineData
1da177e4
LT
1/*
2 * PDC Console support - ie use firmware to dump text via boot console
3 *
4 * Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>
5 * Copyright (C) 2000 Martin K Petersen <mkp at mkp.net>
6 * Copyright (C) 2000 John Marvin <jsm at parisc-linux.org>
7 * Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>
8 * Copyright (C) 2000 Philipp Rumpf <prumpf with tux.org>
9 * Copyright (C) 2000 Michael Ang <mang with subcarrier.org>
10 * Copyright (C) 2000 Grant Grundler <grundler with parisc-linux.org>
11 * Copyright (C) 2001-2002 Ryan Bradetich <rbrad at parisc-linux.org>
12 * Copyright (C) 2001 Helge Deller <deller at parisc-linux.org>
13 * Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org>
14 * Copyright (C) 2002 Randolph Chung <tausq with parisc-linux.org>
650a35f8 15 * Copyright (C) 2010 Guy Martin <gmsoft at tuxicoman.be>
1da177e4
LT
16 *
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 */
32
33/*
34 * The PDC console is a simple console, which can be used for debugging
650a35f8
GM
35 * boot related problems on HP PA-RISC machines. It is also useful when no
36 * other console works.
1da177e4
LT
37 *
38 * This code uses the ROM (=PDC) based functions to read and write characters
39 * from and to PDC's boot path.
1da177e4
LT
40 */
41
42/* Define EARLY_BOOTUP_DEBUG to debug kernel related boot problems.
43 * On production kernels EARLY_BOOTUP_DEBUG should be undefined. */
7c92e972 44#define EARLY_BOOTUP_DEBUG
1da177e4
LT
45
46
1da177e4
LT
47#include <linux/kernel.h>
48#include <linux/console.h>
49#include <linux/string.h>
50#include <linux/init.h>
1da177e4
LT
51#include <linux/major.h>
52#include <linux/tty.h>
1da177e4
LT
53#include <asm/pdc.h> /* for iodc_call() proto and friends */
54
aefa8b6b 55static DEFINE_SPINLOCK(pdc_console_lock);
650a35f8 56static struct console pdc_cons;
1da177e4
LT
57
58static void pdc_console_write(struct console *co, const char *s, unsigned count)
59{
ef1afd4d
KM
60 int i = 0;
61 unsigned long flags;
62
63 spin_lock_irqsave(&pdc_console_lock, flags);
64 do {
65 i += pdc_iodc_print(s + i, count - i);
66 } while (i < count);
67 spin_unlock_irqrestore(&pdc_console_lock, flags);
1da177e4
LT
68}
69
1da177e4
LT
70int pdc_console_poll_key(struct console *co)
71{
ef1afd4d
KM
72 int c;
73 unsigned long flags;
74
75 spin_lock_irqsave(&pdc_console_lock, flags);
76 c = pdc_iodc_getc();
77 spin_unlock_irqrestore(&pdc_console_lock, flags);
78
79 return c;
1da177e4
LT
80}
81
82static int pdc_console_setup(struct console *co, char *options)
83{
84 return 0;
85}
86
87#if defined(CONFIG_PDC_CONSOLE)
a8f340e3 88#include <linux/vt_kern.h>
650a35f8
GM
89#include <linux/tty_flip.h>
90
91#define PDC_CONS_POLL_DELAY (30 * HZ / 1000)
92
52b762f7
JS
93static void pdc_console_poll(unsigned long unused);
94static DEFINE_TIMER(pdc_console_timer, pdc_console_poll, 0, 0);
5dd5bc40 95static struct tty_port tty_port;
650a35f8 96
650a35f8
GM
97static int pdc_console_tty_open(struct tty_struct *tty, struct file *filp)
98{
5dd5bc40 99 tty_port_tty_set(&tty_port, tty);
650a35f8
GM
100 mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY);
101
102 return 0;
103}
104
105static void pdc_console_tty_close(struct tty_struct *tty, struct file *filp)
106{
5dd5bc40 107 if (!tty->count) {
e380a81e 108 del_timer_sync(&pdc_console_timer);
5dd5bc40
JS
109 tty_port_tty_set(&tty_port, NULL);
110 }
650a35f8
GM
111}
112
113static int pdc_console_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
114{
115 pdc_console_write(NULL, buf, count);
116 return count;
117}
118
119static int pdc_console_tty_write_room(struct tty_struct *tty)
120{
121 return 32768; /* no limit, no buffer used */
122}
123
124static int pdc_console_tty_chars_in_buffer(struct tty_struct *tty)
125{
126 return 0; /* no buffer */
127}
128
650a35f8
GM
129static const struct tty_operations pdc_console_tty_ops = {
130 .open = pdc_console_tty_open,
131 .close = pdc_console_tty_close,
132 .write = pdc_console_tty_write,
133 .write_room = pdc_console_tty_write_room,
134 .chars_in_buffer = pdc_console_tty_chars_in_buffer,
135};
136
137static void pdc_console_poll(unsigned long unused)
138{
650a35f8 139 int data, count = 0;
5dd5bc40 140 struct tty_struct *tty = tty_port_tty_get(&tty_port);
650a35f8
GM
141
142 if (!tty)
143 return;
144
145 while (1) {
146 data = pdc_console_poll_key(NULL);
147 if (data == -1)
148 break;
149 tty_insert_flip_char(tty, data & 0xFF, TTY_NORMAL);
150 count ++;
151 }
152
153 if (count)
154 tty_flip_buffer_push(tty);
155
5dd5bc40
JS
156 tty_kref_put(tty);
157
e380a81e 158 if (pdc_cons.flags & CON_ENABLED)
650a35f8
GM
159 mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY);
160}
161
5dd5bc40
JS
162static struct tty_driver *pdc_console_tty_driver;
163
650a35f8
GM
164static int __init pdc_console_tty_driver_init(void)
165{
650a35f8 166 int err;
650a35f8
GM
167
168 /* Check if the console driver is still registered.
169 * It is unregistered if the pdc console was not selected as the
170 * primary console. */
171
597c606f 172 struct console *tmp;
650a35f8 173
ac751efa 174 console_lock();
597c606f 175 for_each_console(tmp)
650a35f8
GM
176 if (tmp == &pdc_cons)
177 break;
ac751efa 178 console_unlock();
650a35f8
GM
179
180 if (!tmp) {
181 printk(KERN_INFO "PDC console driver not registered anymore, not creating %s\n", pdc_cons.name);
182 return -ENODEV;
183 }
184
185 printk(KERN_INFO "The PDC console driver is still registered, removing CON_BOOT flag\n");
186 pdc_cons.flags &= ~CON_BOOT;
187
5dd5bc40
JS
188 tty_port_init(&tty_port);
189
0b479d54 190 pdc_console_tty_driver = alloc_tty_driver(1);
650a35f8 191
0b479d54 192 if (!pdc_console_tty_driver)
650a35f8
GM
193 return -ENOMEM;
194
0b479d54
JS
195 pdc_console_tty_driver->driver_name = "pdc_cons";
196 pdc_console_tty_driver->name = "ttyB";
197 pdc_console_tty_driver->major = MUX_MAJOR;
198 pdc_console_tty_driver->minor_start = 0;
199 pdc_console_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM;
200 pdc_console_tty_driver->init_termios = tty_std_termios;
201 pdc_console_tty_driver->flags = TTY_DRIVER_REAL_RAW |
202 TTY_DRIVER_RESET_TERMIOS;
203 tty_set_operations(pdc_console_tty_driver, &pdc_console_tty_ops);
204
205 err = tty_register_driver(pdc_console_tty_driver);
650a35f8
GM
206 if (err) {
207 printk(KERN_ERR "Unable to register the PDC console TTY driver\n");
208 return err;
209 }
210
650a35f8
GM
211 return 0;
212}
213
214module_init(pdc_console_tty_driver_init);
a8f340e3 215
1da177e4
LT
216static struct tty_driver * pdc_console_device (struct console *c, int *index)
217{
650a35f8
GM
218 *index = c->index;
219 return pdc_console_tty_driver;
1da177e4
LT
220}
221#else
7c92e972 222#define pdc_console_device NULL
1da177e4
LT
223#endif
224
225static struct console pdc_cons = {
226 .name = "ttyB",
227 .write = pdc_console_write,
7c92e972 228 .device = pdc_console_device,
1da177e4 229 .setup = pdc_console_setup,
650a35f8 230 .flags = CON_BOOT | CON_PRINTBUFFER,
1da177e4
LT
231 .index = -1,
232};
233
234static int pdc_console_initialized;
1da177e4
LT
235
236static void pdc_console_init_force(void)
237{
238 if (pdc_console_initialized)
239 return;
240 ++pdc_console_initialized;
241
242 /* If the console is duplex then copy the COUT parameters to CIN. */
243 if (PAGE0->mem_cons.cl_class == CL_DUPLEX)
244 memcpy(&PAGE0->mem_kbd, &PAGE0->mem_cons, sizeof(PAGE0->mem_cons));
245
246 /* register the pdc console */
247 register_console(&pdc_cons);
248}
249
250void __init pdc_console_init(void)
251{
252#if defined(EARLY_BOOTUP_DEBUG) || defined(CONFIG_PDC_CONSOLE)
253 pdc_console_init_force();
254#endif
255#ifdef EARLY_BOOTUP_DEBUG
256 printk(KERN_INFO "Initialized PDC Console for debugging.\n");
257#endif
258}
259
260
1da177e4
LT
261/*
262 * Used for emergencies. Currently only used if an HPMC occurs. If an
263 * HPMC occurs, it is possible that the current console may not be
7c92e972
MW
264 * properly initialised after the PDC IO reset. This routine unregisters
265 * all of the current consoles, reinitializes the pdc console and
1da177e4
LT
266 * registers it.
267 */
268
269void pdc_console_restart(void)
270{
271 struct console *console;
272
273 if (pdc_console_initialized)
274 return;
275
7c92e972
MW
276 /* If we've already seen the output, don't bother to print it again */
277 if (console_drivers != NULL)
278 pdc_cons.flags &= ~CON_PRINTBUFFER;
279
1da177e4
LT
280 while ((console = console_drivers) != NULL)
281 unregister_console(console_drivers);
282
1da177e4
LT
283 /* force registering the pdc console */
284 pdc_console_init_force();
285}
This page took 0.630922 seconds and 5 git commands to generate.