blob: 663388a73d4ecbe997e7a0fc5a22f6328edaa0b9 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Simulated Serial Driver (fake serial)
4 *
5 * This driver is mostly used for bringup purposes and will go away.
6 * It has a strong dependency on the system console. All outputs
7 * are rerouted to the same facility as the one used by printk which, in our
Jiri Slabyadb636f2012-03-05 14:52:39 +01008 * case means sys_sim.c console (goes via the simulator).
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
10 * Copyright (C) 1999-2000, 2002-2003 Hewlett-Packard Co
11 * Stephane Eranian <eranian@hpl.hp.com>
12 * David Mosberger-Tang <davidm@hpl.hp.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 */
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/init.h>
16#include <linux/errno.h>
17#include <linux/sched.h>
Ingo Molnarb17b0152017-02-08 18:51:35 +010018#include <linux/sched/debug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/tty.h>
20#include <linux/tty_flip.h>
21#include <linux/major.h>
22#include <linux/fcntl.h>
23#include <linux/mm.h>
Alexey Dobriyanbf542152009-03-31 15:19:23 -070024#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/slab.h>
Randy Dunlapa9415642006-01-11 12:17:48 -080026#include <linux/capability.h>
Jiri Slaby3c4782d2012-03-05 14:52:31 +010027#include <linux/circ_buf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/console.h>
Jiri Slaby8b916332012-03-05 14:52:40 +010029#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/module.h>
31#include <linux/serial.h>
David Mosberger-Tang819c67e2005-06-09 22:40:00 -070032#include <linux/sysrq.h>
Jiri Slaby8b916332012-03-05 14:52:40 +010033#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Jiri Slaby035cfe52012-03-08 21:01:17 +010035#include <asm/hpsim.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Jiri Slaby035cfe52012-03-08 21:01:17 +010037#include "hpsim_ssc.h"
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#undef SIMSERIAL_DEBUG /* define this to get some debug information */
40
41#define KEYBOARD_INTR 3 /* must match with simulator! */
42
43#define NR_PORTS 1 /* only one port for now */
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Jiri Slaby3c4782d2012-03-05 14:52:31 +010045struct serial_state {
Jiri Slaby7f32f8d2012-03-05 14:52:32 +010046 struct tty_port port;
Jiri Slaby3c4782d2012-03-05 14:52:31 +010047 struct circ_buf xmit;
48 int irq;
49 int x_char;
50};
51
Jiri Slabyfd2d7a62012-03-05 14:52:28 +010052static struct serial_state rs_table[NR_PORTS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54struct tty_driver *hp_simserial_driver;
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056static struct console *console;
57
Jiri Slaby2e124b42013-01-03 15:53:06 +010058static void receive_chars(struct tty_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
60 unsigned char ch;
61 static unsigned char seen_esc = 0;
62
63 while ( (ch = ia64_ssc(0, 0, 0, 0, SSC_GETCHAR)) ) {
Jiri Slabyf66279c2012-03-05 14:52:41 +010064 if (ch == 27 && seen_esc == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 seen_esc = 1;
66 continue;
Jiri Slabyf66279c2012-03-05 14:52:41 +010067 } else if (seen_esc == 1 && ch == 'O') {
68 seen_esc = 2;
69 continue;
70 } else if (seen_esc == 2) {
71 if (ch == 'P') /* F1 */
72 show_state();
David Mosberger-Tang819c67e2005-06-09 22:40:00 -070073#ifdef CONFIG_MAGIC_SYSRQ
Jiri Slabyf66279c2012-03-05 14:52:41 +010074 if (ch == 'S') { /* F4 */
75 do {
76 ch = ia64_ssc(0, 0, 0, 0, SSC_GETCHAR);
77 } while (!ch);
78 handle_sysrq(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 }
Jiri Slabyf66279c2012-03-05 14:52:41 +010080#endif
81 seen_esc = 0;
82 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 }
84 seen_esc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Jiri Slaby92a19f92013-01-03 15:53:03 +010086 if (tty_insert_flip_char(port, ch, TTY_NORMAL) == 0)
Andreas Schwabd50f5c52006-01-13 23:46:38 +010087 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
Jiri Slaby2e124b42013-01-03 15:53:06 +010089 tty_flip_buffer_push(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
92/*
93 * This is the serial driver's interrupt routine for a single port
94 */
Al Viro5dcded12006-10-08 14:59:19 +010095static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Jiri Slaby916b7652012-03-05 14:52:20 +010097 struct serial_state *info = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Jiri Slaby2e124b42013-01-03 15:53:06 +010099 receive_chars(&info->port);
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 return IRQ_HANDLED;
102}
103
104/*
105 * -------------------------------------------------------------------
106 * Here ends the serial interrupt routines.
107 * -------------------------------------------------------------------
108 */
109
Alan Coxf34d7a52008-04-30 00:54:13 -0700110static int rs_put_char(struct tty_struct *tty, unsigned char ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
Jiri Slaby916b7652012-03-05 14:52:20 +0100112 struct serial_state *info = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 unsigned long flags;
114
Jiri Slaby6e9ebcf2012-03-05 14:52:42 +0100115 if (!info->xmit.buf)
Alan Coxf34d7a52008-04-30 00:54:13 -0700116 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 local_irq_save(flags);
119 if (CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) == 0) {
120 local_irq_restore(flags);
Alan Coxf34d7a52008-04-30 00:54:13 -0700121 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123 info->xmit.buf[info->xmit.head] = ch;
124 info->xmit.head = (info->xmit.head + 1) & (SERIAL_XMIT_SIZE-1);
125 local_irq_restore(flags);
Alan Coxf34d7a52008-04-30 00:54:13 -0700126 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
Jiri Slaby5e99d542012-03-05 14:52:23 +0100129static void transmit_chars(struct tty_struct *tty, struct serial_state *info,
130 int *intr_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
132 int count;
133 unsigned long flags;
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 local_irq_save(flags);
136
137 if (info->x_char) {
138 char c = info->x_char;
139
140 console->write(console, &c, 1);
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 info->x_char = 0;
143
144 goto out;
145 }
146
Jiri Slabyee797062013-03-07 13:12:34 +0100147 if (info->xmit.head == info->xmit.tail || tty->stopped) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#ifdef SIMSERIAL_DEBUG
149 printk("transmit_chars: head=%d, tail=%d, stopped=%d\n",
Jiri Slaby5e99d542012-03-05 14:52:23 +0100150 info->xmit.head, info->xmit.tail, tty->stopped);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#endif
152 goto out;
153 }
154 /*
155 * We removed the loop and try to do it in to chunks. We need
156 * 2 operations maximum because it's a ring buffer.
157 *
158 * First from current to tail if possible.
159 * Then from the beginning of the buffer until necessary
160 */
161
162 count = min(CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE),
163 SERIAL_XMIT_SIZE - info->xmit.tail);
164 console->write(console, info->xmit.buf+info->xmit.tail, count);
165
166 info->xmit.tail = (info->xmit.tail+count) & (SERIAL_XMIT_SIZE-1);
167
168 /*
169 * We have more at the beginning of the buffer
170 */
171 count = CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
172 if (count) {
173 console->write(console, info->xmit.buf, count);
174 info->xmit.tail += count;
175 }
176out:
177 local_irq_restore(flags);
178}
179
180static void rs_flush_chars(struct tty_struct *tty)
181{
Jiri Slaby916b7652012-03-05 14:52:20 +0100182 struct serial_state *info = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Jiri Slabyf66279c2012-03-05 14:52:41 +0100184 if (info->xmit.head == info->xmit.tail || tty->stopped ||
Jiri Slabyee797062013-03-07 13:12:34 +0100185 !info->xmit.buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 return;
187
Jiri Slaby5e99d542012-03-05 14:52:23 +0100188 transmit_chars(tty, info, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189}
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191static int rs_write(struct tty_struct * tty,
192 const unsigned char *buf, int count)
193{
Jiri Slaby916b7652012-03-05 14:52:20 +0100194 struct serial_state *info = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 int c, ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 unsigned long flags;
197
Jiri Slaby6e9ebcf2012-03-05 14:52:42 +0100198 if (!info->xmit.buf)
Jiri Slabyd88405d2012-03-05 14:52:29 +0100199 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 local_irq_save(flags);
202 while (1) {
203 c = CIRC_SPACE_TO_END(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
204 if (count < c)
205 c = count;
206 if (c <= 0) {
207 break;
208 }
209 memcpy(info->xmit.buf + info->xmit.head, buf, c);
210 info->xmit.head = ((info->xmit.head + c) &
211 (SERIAL_XMIT_SIZE-1));
212 buf += c;
213 count -= c;
214 ret += c;
215 }
216 local_irq_restore(flags);
217 /*
218 * Hey, we transmit directly from here in our case
219 */
Jiri Slabyf66279c2012-03-05 14:52:41 +0100220 if (CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) &&
Jiri Slabyee797062013-03-07 13:12:34 +0100221 !tty->stopped)
Jiri Slaby5e99d542012-03-05 14:52:23 +0100222 transmit_chars(tty, info, NULL);
Jiri Slabyf66279c2012-03-05 14:52:41 +0100223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 return ret;
225}
226
227static int rs_write_room(struct tty_struct *tty)
228{
Jiri Slaby916b7652012-03-05 14:52:20 +0100229 struct serial_state *info = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
232}
233
234static int rs_chars_in_buffer(struct tty_struct *tty)
235{
Jiri Slaby916b7652012-03-05 14:52:20 +0100236 struct serial_state *info = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 return CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
239}
240
241static void rs_flush_buffer(struct tty_struct *tty)
242{
Jiri Slaby916b7652012-03-05 14:52:20 +0100243 struct serial_state *info = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 unsigned long flags;
245
246 local_irq_save(flags);
247 info->xmit.head = info->xmit.tail = 0;
248 local_irq_restore(flags);
249
Alan Cox15648f12008-07-16 21:52:25 +0100250 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251}
252
253/*
254 * This function is used to send a high-priority XON/XOFF character to
255 * the device
256 */
257static void rs_send_xchar(struct tty_struct *tty, char ch)
258{
Jiri Slaby916b7652012-03-05 14:52:20 +0100259 struct serial_state *info = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261 info->x_char = ch;
262 if (ch) {
263 /*
264 * I guess we could call console->write() directly but
265 * let's do that for now.
266 */
Jiri Slaby5e99d542012-03-05 14:52:23 +0100267 transmit_chars(tty, info, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269}
270
271/*
272 * ------------------------------------------------------------
273 * rs_throttle()
274 *
275 * This routine is called by the upper-layer tty layer to signal that
276 * incoming characters should be throttled.
277 * ------------------------------------------------------------
278 */
279static void rs_throttle(struct tty_struct * tty)
280{
Jiri Slabyf66279c2012-03-05 14:52:41 +0100281 if (I_IXOFF(tty))
282 rs_send_xchar(tty, STOP_CHAR(tty));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 printk(KERN_INFO "simrs_throttle called\n");
285}
286
287static void rs_unthrottle(struct tty_struct * tty)
288{
Jiri Slaby916b7652012-03-05 14:52:20 +0100289 struct serial_state *info = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 if (I_IXOFF(tty)) {
292 if (info->x_char)
293 info->x_char = 0;
294 else
295 rs_send_xchar(tty, START_CHAR(tty));
296 }
297 printk(KERN_INFO "simrs_unthrottle called\n");
298}
299
Luck, Tony10e82f62011-02-22 11:47:04 -0800300static int rs_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
302 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
303 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
Alan Cox05871022010-09-16 18:21:52 +0100304 (cmd != TIOCMIWAIT)) {
Peter Hurley18900ca2016-04-09 17:06:48 -0700305 if (tty_io_error(tty))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 return -EIO;
307 }
308
309 switch (cmd) {
Jiri Slabyf66279c2012-03-05 14:52:41 +0100310 case TIOCGSERIAL:
311 case TIOCSSERIAL:
312 case TIOCSERGSTRUCT:
313 case TIOCMIWAIT:
314 return 0;
315 case TIOCSERCONFIG:
316 case TIOCSERGETLSR: /* Get line status register */
317 return -EINVAL;
318 case TIOCSERGWILD:
319 case TIOCSERSWILD:
320 /* "setserial -W" is called in Debian boot */
321 printk (KERN_INFO "TIOCSER?WILD ioctl obsolete, ignored.\n");
322 return 0;
323 }
324 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325}
326
327#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329/*
330 * This routine will shutdown a serial port; interrupts are disabled, and
331 * DTR is dropped if the hangup on close termio flag is on.
332 */
Jiri Slaby458cd312012-03-05 14:52:38 +0100333static void shutdown(struct tty_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Jiri Slaby458cd312012-03-05 14:52:38 +0100335 struct serial_state *info = container_of(port, struct serial_state,
336 port);
337 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 local_irq_save(flags);
Jiri Slabyf66279c2012-03-05 14:52:41 +0100340 if (info->irq)
341 free_irq(info->irq, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Jiri Slabyf66279c2012-03-05 14:52:41 +0100343 if (info->xmit.buf) {
344 free_page((unsigned long) info->xmit.buf);
345 info->xmit.buf = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 }
347 local_irq_restore(flags);
348}
349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350static void rs_close(struct tty_struct *tty, struct file * filp)
351{
Jiri Slaby916b7652012-03-05 14:52:20 +0100352 struct serial_state *info = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Jiri Slaby458cd312012-03-05 14:52:38 +0100354 tty_port_close(&info->port, tty, filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355}
356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357static void rs_hangup(struct tty_struct *tty)
358{
Jiri Slaby916b7652012-03-05 14:52:20 +0100359 struct serial_state *info = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 rs_flush_buffer(tty);
Jiri Slaby458cd312012-03-05 14:52:38 +0100362 tty_port_hangup(&info->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363}
364
Jiri Slaby9aead902012-03-05 14:52:37 +0100365static int activate(struct tty_port *port, struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
Jiri Slaby9aead902012-03-05 14:52:37 +0100367 struct serial_state *state = container_of(port, struct serial_state,
368 port);
Jiri Slabyf66279c2012-03-05 14:52:41 +0100369 unsigned long flags, page;
370 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 page = get_zeroed_page(GFP_KERNEL);
373 if (!page)
374 return -ENOMEM;
375
376 local_irq_save(flags);
377
Jiri Slaby916b7652012-03-05 14:52:20 +0100378 if (state->xmit.buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 free_page(page);
380 else
Jiri Slaby916b7652012-03-05 14:52:20 +0100381 state->xmit.buf = (unsigned char *) page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Jiri Slaby964105b2012-03-05 14:52:17 +0100383 if (state->irq) {
Jiri Slaby2f8c5212012-03-05 14:52:18 +0100384 retval = request_irq(state->irq, rs_interrupt_single, 0,
Jiri Slaby916b7652012-03-05 14:52:20 +0100385 "simserial", state);
Jiri Slaby9e12dd52012-03-08 21:01:19 +0100386 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 goto errout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 }
389
Jiri Slaby916b7652012-03-05 14:52:20 +0100390 state->xmit.head = state->xmit.tail = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391errout:
392 local_irq_restore(flags);
393 return retval;
394}
395
396
397/*
398 * This routine is called whenever a serial port is opened. It
399 * enables interrupts for a serial port, linking in its async structure into
400 * the IRQ chain. It also performs the serial-specific
401 * initialization for the tty structure.
402 */
403static int rs_open(struct tty_struct *tty, struct file * filp)
404{
Jiri Slaby916b7652012-03-05 14:52:20 +0100405 struct serial_state *info = rs_table + tty->index;
Jiri Slaby7f32f8d2012-03-05 14:52:32 +0100406 struct tty_port *port = &info->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Jiri Slaby916b7652012-03-05 14:52:20 +0100408 tty->driver_data = info;
Jiri Slabyd6c53c02013-01-03 15:53:05 +0100409 port->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 * figure out which console to use (should be one already)
413 */
414 console = console_drivers;
415 while (console) {
416 if ((console->flags & CON_ENABLED) && console->write) break;
417 console = console->next;
418 }
419
Jiri Slaby9aead902012-03-05 14:52:37 +0100420 return tty_port_open(port, tty, filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421}
422
423/*
424 * /proc fs routines....
425 */
426
Alexey Dobriyanbf542152009-03-31 15:19:23 -0700427static int rs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
Alexey Dobriyanbf542152009-03-31 15:19:23 -0700429 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Jiri Slaby6e9ebcf2012-03-05 14:52:42 +0100431 seq_printf(m, "simserinfo:1.0\n");
Alexey Dobriyanbf542152009-03-31 15:19:23 -0700432 for (i = 0; i < NR_PORTS; i++)
Jiri Slaby98e3a9e2012-03-05 14:52:30 +0100433 seq_printf(m, "%d: uart:16550 port:3F8 irq:%d\n",
434 i, rs_table[i].irq);
Alexey Dobriyanbf542152009-03-31 15:19:23 -0700435 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436}
437
Jeff Dikeb68e31d2006-10-02 02:17:18 -0700438static const struct tty_operations hp_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 .open = rs_open,
440 .close = rs_close,
441 .write = rs_write,
442 .put_char = rs_put_char,
443 .flush_chars = rs_flush_chars,
444 .write_room = rs_write_room,
445 .chars_in_buffer = rs_chars_in_buffer,
446 .flush_buffer = rs_flush_buffer,
447 .ioctl = rs_ioctl,
448 .throttle = rs_throttle,
449 .unthrottle = rs_unthrottle,
450 .send_xchar = rs_send_xchar,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 .hangup = rs_hangup,
Christoph Hellwig8a8dcab2018-04-13 21:04:45 +0200452 .proc_show = rs_proc_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453};
454
Jiri Slaby37343032012-03-05 14:52:34 +0100455static const struct tty_port_operations hp_port_ops = {
Jiri Slaby9aead902012-03-05 14:52:37 +0100456 .activate = activate,
Jiri Slaby458cd312012-03-05 14:52:38 +0100457 .shutdown = shutdown,
Jiri Slaby37343032012-03-05 14:52:34 +0100458};
459
Jiri Slabyfd2d7a62012-03-05 14:52:28 +0100460static int __init simrs_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461{
Jiri Slabyfd2d7a62012-03-05 14:52:28 +0100462 struct serial_state *state;
463 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465 if (!ia64_platform_is("hpsim"))
466 return -ENODEV;
467
Jiri Slaby410235f2012-03-05 14:52:01 +0100468 hp_simserial_driver = alloc_tty_driver(NR_PORTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 if (!hp_simserial_driver)
470 return -ENOMEM;
471
Jiri Slaby6e9ebcf2012-03-05 14:52:42 +0100472 printk(KERN_INFO "SimSerial driver with no serial options enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
474 /* Initialize the tty_driver structure */
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 hp_simserial_driver->driver_name = "simserial";
477 hp_simserial_driver->name = "ttyS";
478 hp_simserial_driver->major = TTY_MAJOR;
479 hp_simserial_driver->minor_start = 64;
480 hp_simserial_driver->type = TTY_DRIVER_TYPE_SERIAL;
481 hp_simserial_driver->subtype = SERIAL_TYPE_NORMAL;
482 hp_simserial_driver->init_termios = tty_std_termios;
483 hp_simserial_driver->init_termios.c_cflag =
484 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
485 hp_simserial_driver->flags = TTY_DRIVER_REAL_RAW;
486 tty_set_operations(hp_simserial_driver, &hp_ops);
487
Jiri Slabyfd2d7a62012-03-05 14:52:28 +0100488 state = rs_table;
Jiri Slaby7f32f8d2012-03-05 14:52:32 +0100489 tty_port_init(&state->port);
Jiri Slaby37343032012-03-05 14:52:34 +0100490 state->port.ops = &hp_port_ops;
Jiri Slaby7f32f8d2012-03-05 14:52:32 +0100491 state->port.close_delay = 0; /* XXX really 0? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Jiri Slabyfd2d7a62012-03-05 14:52:28 +0100493 retval = hpsim_get_irq(KEYBOARD_INTR);
494 if (retval < 0) {
495 printk(KERN_ERR "%s: out of interrupt vectors!\n",
496 __func__);
497 goto err_free_tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
499
Jiri Slabyfd2d7a62012-03-05 14:52:28 +0100500 state->irq = retval;
501
502 /* the port is imaginary */
Jiri Slaby98e3a9e2012-03-05 14:52:30 +0100503 printk(KERN_INFO "ttyS0 at 0x03f8 (irq = %d) is a 16550\n", state->irq);
Jiri Slabyfd2d7a62012-03-05 14:52:28 +0100504
Jiri Slabyb19e2ca2012-08-07 21:47:51 +0200505 tty_port_link_device(&state->port, hp_simserial_driver, 0);
Jiri Slabyfd2d7a62012-03-05 14:52:28 +0100506 retval = tty_register_driver(hp_simserial_driver);
507 if (retval) {
508 printk(KERN_ERR "Couldn't register simserial driver\n");
509 goto err_free_tty;
510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 return 0;
Jiri Slabyfd2d7a62012-03-05 14:52:28 +0100513err_free_tty:
514 put_tty_driver(hp_simserial_driver);
Jiri Slaby191c5f12012-11-15 09:49:56 +0100515 tty_port_destroy(&state->port);
Jiri Slabyfd2d7a62012-03-05 14:52:28 +0100516 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517}
518
519#ifndef MODULE
520__initcall(simrs_init);
521#endif