2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Simulated Serial Driver (fake serial)
|
|
|
|
*
|
|
|
|
* This driver is mostly used for bringup purposes and will go away.
|
|
|
|
* It has a strong dependency on the system console. All outputs
|
|
|
|
* are rerouted to the same facility as the one used by printk which, in our
|
2012-03-05 21:52:39 +08:00
|
|
|
* case means sys_sim.c console (goes via the simulator).
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 1999-2000, 2002-2003 Hewlett-Packard Co
|
|
|
|
* Stephane Eranian <eranian@hpl.hp.com>
|
|
|
|
* David Mosberger-Tang <davidm@hpl.hp.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/major.h>
|
|
|
|
#include <linux/fcntl.h>
|
|
|
|
#include <linux/mm.h>
|
2009-04-01 06:19:23 +08:00
|
|
|
#include <linux/seq_file.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/slab.h>
|
2006-01-12 04:17:48 +08:00
|
|
|
#include <linux/capability.h>
|
2012-03-05 21:52:31 +08:00
|
|
|
#include <linux/circ_buf.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/console.h>
|
2012-03-05 21:52:40 +08:00
|
|
|
#include <linux/irq.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/serial.h>
|
2005-06-10 13:40:00 +08:00
|
|
|
#include <linux/sysrq.h>
|
2012-03-05 21:52:40 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 04:01:17 +08:00
|
|
|
#include <asm/hpsim.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 04:01:17 +08:00
|
|
|
#include "hpsim_ssc.h"
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#undef SIMSERIAL_DEBUG /* define this to get some debug information */
|
|
|
|
|
|
|
|
#define KEYBOARD_INTR 3 /* must match with simulator! */
|
|
|
|
|
|
|
|
#define NR_PORTS 1 /* only one port for now */
|
|
|
|
|
2012-03-05 21:52:31 +08:00
|
|
|
struct serial_state {
|
2012-03-05 21:52:32 +08:00
|
|
|
struct tty_port port;
|
2012-03-05 21:52:31 +08:00
|
|
|
struct circ_buf xmit;
|
|
|
|
int irq;
|
|
|
|
int x_char;
|
|
|
|
};
|
|
|
|
|
2012-03-05 21:52:28 +08:00
|
|
|
static struct serial_state rs_table[NR_PORTS];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct tty_driver *hp_simserial_driver;
|
|
|
|
|
|
|
|
static struct console *console;
|
|
|
|
|
2013-01-03 22:53:06 +08:00
|
|
|
static void receive_chars(struct tty_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char ch;
|
|
|
|
static unsigned char seen_esc = 0;
|
|
|
|
|
|
|
|
while ( (ch = ia64_ssc(0, 0, 0, 0, SSC_GETCHAR)) ) {
|
2012-03-05 21:52:41 +08:00
|
|
|
if (ch == 27 && seen_esc == 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
seen_esc = 1;
|
|
|
|
continue;
|
2012-03-05 21:52:41 +08:00
|
|
|
} else if (seen_esc == 1 && ch == 'O') {
|
|
|
|
seen_esc = 2;
|
|
|
|
continue;
|
|
|
|
} else if (seen_esc == 2) {
|
|
|
|
if (ch == 'P') /* F1 */
|
|
|
|
show_state();
|
2005-06-10 13:40:00 +08:00
|
|
|
#ifdef CONFIG_MAGIC_SYSRQ
|
2012-03-05 21:52:41 +08:00
|
|
|
if (ch == 'S') { /* F4 */
|
|
|
|
do {
|
|
|
|
ch = ia64_ssc(0, 0, 0, 0, SSC_GETCHAR);
|
|
|
|
} while (!ch);
|
|
|
|
handle_sysrq(ch);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2012-03-05 21:52:41 +08:00
|
|
|
#endif
|
|
|
|
seen_esc = 0;
|
|
|
|
continue;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
seen_esc = 0;
|
|
|
|
|
2013-01-03 22:53:03 +08:00
|
|
|
if (tty_insert_flip_char(port, ch, TTY_NORMAL) == 0)
|
2006-01-14 06:46:38 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2013-01-03 22:53:06 +08:00
|
|
|
tty_flip_buffer_push(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the serial driver's interrupt routine for a single port
|
|
|
|
*/
|
2006-10-08 21:59:19 +08:00
|
|
|
static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-03-05 21:52:20 +08:00
|
|
|
struct serial_state *info = dev_id;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-01-03 22:53:06 +08:00
|
|
|
receive_chars(&info->port);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -------------------------------------------------------------------
|
|
|
|
* Here ends the serial interrupt routines.
|
|
|
|
* -------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2008-04-30 15:54:13 +08:00
|
|
|
static int rs_put_char(struct tty_struct *tty, unsigned char ch)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-03-05 21:52:20 +08:00
|
|
|
struct serial_state *info = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2012-03-05 21:52:42 +08:00
|
|
|
if (!info->xmit.buf)
|
2008-04-30 15:54:13 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
if (CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) == 0) {
|
|
|
|
local_irq_restore(flags);
|
2008-04-30 15:54:13 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
info->xmit.buf[info->xmit.head] = ch;
|
|
|
|
info->xmit.head = (info->xmit.head + 1) & (SERIAL_XMIT_SIZE-1);
|
|
|
|
local_irq_restore(flags);
|
2008-04-30 15:54:13 +08:00
|
|
|
return 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-03-05 21:52:23 +08:00
|
|
|
static void transmit_chars(struct tty_struct *tty, struct serial_state *info,
|
|
|
|
int *intr_done)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
if (info->x_char) {
|
|
|
|
char c = info->x_char;
|
|
|
|
|
|
|
|
console->write(console, &c, 1);
|
|
|
|
|
|
|
|
info->x_char = 0;
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-03-07 20:12:34 +08:00
|
|
|
if (info->xmit.head == info->xmit.tail || tty->stopped) {
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef SIMSERIAL_DEBUG
|
|
|
|
printk("transmit_chars: head=%d, tail=%d, stopped=%d\n",
|
2012-03-05 21:52:23 +08:00
|
|
|
info->xmit.head, info->xmit.tail, tty->stopped);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We removed the loop and try to do it in to chunks. We need
|
|
|
|
* 2 operations maximum because it's a ring buffer.
|
|
|
|
*
|
|
|
|
* First from current to tail if possible.
|
|
|
|
* Then from the beginning of the buffer until necessary
|
|
|
|
*/
|
|
|
|
|
|
|
|
count = min(CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE),
|
|
|
|
SERIAL_XMIT_SIZE - info->xmit.tail);
|
|
|
|
console->write(console, info->xmit.buf+info->xmit.tail, count);
|
|
|
|
|
|
|
|
info->xmit.tail = (info->xmit.tail+count) & (SERIAL_XMIT_SIZE-1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have more at the beginning of the buffer
|
|
|
|
*/
|
|
|
|
count = CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
|
|
|
|
if (count) {
|
|
|
|
console->write(console, info->xmit.buf, count);
|
|
|
|
info->xmit.tail += count;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rs_flush_chars(struct tty_struct *tty)
|
|
|
|
{
|
2012-03-05 21:52:20 +08:00
|
|
|
struct serial_state *info = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-05 21:52:41 +08:00
|
|
|
if (info->xmit.head == info->xmit.tail || tty->stopped ||
|
2013-03-07 20:12:34 +08:00
|
|
|
!info->xmit.buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
2012-03-05 21:52:23 +08:00
|
|
|
transmit_chars(tty, info, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rs_write(struct tty_struct * tty,
|
|
|
|
const unsigned char *buf, int count)
|
|
|
|
{
|
2012-03-05 21:52:20 +08:00
|
|
|
struct serial_state *info = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
int c, ret = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2012-03-05 21:52:42 +08:00
|
|
|
if (!info->xmit.buf)
|
2012-03-05 21:52:29 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
while (1) {
|
|
|
|
c = CIRC_SPACE_TO_END(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
|
|
|
|
if (count < c)
|
|
|
|
c = count;
|
|
|
|
if (c <= 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memcpy(info->xmit.buf + info->xmit.head, buf, c);
|
|
|
|
info->xmit.head = ((info->xmit.head + c) &
|
|
|
|
(SERIAL_XMIT_SIZE-1));
|
|
|
|
buf += c;
|
|
|
|
count -= c;
|
|
|
|
ret += c;
|
|
|
|
}
|
|
|
|
local_irq_restore(flags);
|
|
|
|
/*
|
|
|
|
* Hey, we transmit directly from here in our case
|
|
|
|
*/
|
2012-03-05 21:52:41 +08:00
|
|
|
if (CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) &&
|
2013-03-07 20:12:34 +08:00
|
|
|
!tty->stopped)
|
2012-03-05 21:52:23 +08:00
|
|
|
transmit_chars(tty, info, NULL);
|
2012-03-05 21:52:41 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rs_write_room(struct tty_struct *tty)
|
|
|
|
{
|
2012-03-05 21:52:20 +08:00
|
|
|
struct serial_state *info = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rs_chars_in_buffer(struct tty_struct *tty)
|
|
|
|
{
|
2012-03-05 21:52:20 +08:00
|
|
|
struct serial_state *info = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rs_flush_buffer(struct tty_struct *tty)
|
|
|
|
{
|
2012-03-05 21:52:20 +08:00
|
|
|
struct serial_state *info = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
info->xmit.head = info->xmit.tail = 0;
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
2008-07-17 04:52:25 +08:00
|
|
|
tty_wakeup(tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is used to send a high-priority XON/XOFF character to
|
|
|
|
* the device
|
|
|
|
*/
|
|
|
|
static void rs_send_xchar(struct tty_struct *tty, char ch)
|
|
|
|
{
|
2012-03-05 21:52:20 +08:00
|
|
|
struct serial_state *info = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
info->x_char = ch;
|
|
|
|
if (ch) {
|
|
|
|
/*
|
|
|
|
* I guess we could call console->write() directly but
|
|
|
|
* let's do that for now.
|
|
|
|
*/
|
2012-03-05 21:52:23 +08:00
|
|
|
transmit_chars(tty, info, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
* rs_throttle()
|
|
|
|
*
|
|
|
|
* This routine is called by the upper-layer tty layer to signal that
|
|
|
|
* incoming characters should be throttled.
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void rs_throttle(struct tty_struct * tty)
|
|
|
|
{
|
2012-03-05 21:52:41 +08:00
|
|
|
if (I_IXOFF(tty))
|
|
|
|
rs_send_xchar(tty, STOP_CHAR(tty));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
printk(KERN_INFO "simrs_throttle called\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rs_unthrottle(struct tty_struct * tty)
|
|
|
|
{
|
2012-03-05 21:52:20 +08:00
|
|
|
struct serial_state *info = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (I_IXOFF(tty)) {
|
|
|
|
if (info->x_char)
|
|
|
|
info->x_char = 0;
|
|
|
|
else
|
|
|
|
rs_send_xchar(tty, START_CHAR(tty));
|
|
|
|
}
|
|
|
|
printk(KERN_INFO "simrs_unthrottle called\n");
|
|
|
|
}
|
|
|
|
|
2011-02-23 03:47:04 +08:00
|
|
|
static int rs_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
|
|
|
|
(cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
|
2010-09-17 01:21:52 +08:00
|
|
|
(cmd != TIOCMIWAIT)) {
|
2016-04-10 08:06:48 +08:00
|
|
|
if (tty_io_error(tty))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
2012-03-05 21:52:41 +08:00
|
|
|
case TIOCGSERIAL:
|
|
|
|
case TIOCSSERIAL:
|
|
|
|
case TIOCSERGSTRUCT:
|
|
|
|
case TIOCMIWAIT:
|
|
|
|
return 0;
|
|
|
|
case TIOCSERCONFIG:
|
|
|
|
case TIOCSERGETLSR: /* Get line status register */
|
|
|
|
return -EINVAL;
|
|
|
|
case TIOCSERGWILD:
|
|
|
|
case TIOCSERSWILD:
|
|
|
|
/* "setserial -W" is called in Debian boot */
|
|
|
|
printk (KERN_INFO "TIOCSER?WILD ioctl obsolete, ignored.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -ENOIOCTLCMD;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine will shutdown a serial port; interrupts are disabled, and
|
|
|
|
* DTR is dropped if the hangup on close termio flag is on.
|
|
|
|
*/
|
2012-03-05 21:52:38 +08:00
|
|
|
static void shutdown(struct tty_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-03-05 21:52:38 +08:00
|
|
|
struct serial_state *info = container_of(port, struct serial_state,
|
|
|
|
port);
|
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
local_irq_save(flags);
|
2012-03-05 21:52:41 +08:00
|
|
|
if (info->irq)
|
|
|
|
free_irq(info->irq, info);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-05 21:52:41 +08:00
|
|
|
if (info->xmit.buf) {
|
|
|
|
free_page((unsigned long) info->xmit.buf);
|
|
|
|
info->xmit.buf = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rs_close(struct tty_struct *tty, struct file * filp)
|
|
|
|
{
|
2012-03-05 21:52:20 +08:00
|
|
|
struct serial_state *info = tty->driver_data;
|
2012-03-05 21:52:34 +08:00
|
|
|
|
2012-03-05 21:52:38 +08:00
|
|
|
tty_port_close(&info->port, tty, filp);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rs_hangup(struct tty_struct *tty)
|
|
|
|
{
|
2012-03-05 21:52:20 +08:00
|
|
|
struct serial_state *info = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
rs_flush_buffer(tty);
|
2012-03-05 21:52:38 +08:00
|
|
|
tty_port_hangup(&info->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-03-05 21:52:37 +08:00
|
|
|
static int activate(struct tty_port *port, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-03-05 21:52:37 +08:00
|
|
|
struct serial_state *state = container_of(port, struct serial_state,
|
|
|
|
port);
|
2012-03-05 21:52:41 +08:00
|
|
|
unsigned long flags, page;
|
|
|
|
int retval = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
page = get_zeroed_page(GFP_KERNEL);
|
|
|
|
if (!page)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
2012-03-05 21:52:20 +08:00
|
|
|
if (state->xmit.buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
free_page(page);
|
|
|
|
else
|
2012-03-05 21:52:20 +08:00
|
|
|
state->xmit.buf = (unsigned char *) page;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-05 21:52:17 +08:00
|
|
|
if (state->irq) {
|
2012-03-05 21:52:18 +08:00
|
|
|
retval = request_irq(state->irq, rs_interrupt_single, 0,
|
2012-03-05 21:52:20 +08:00
|
|
|
"simserial", state);
|
2012-03-09 04:01:19 +08:00
|
|
|
if (retval)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2012-03-05 21:52:20 +08:00
|
|
|
state->xmit.head = state->xmit.tail = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the tty->alt_speed kludge
|
|
|
|
*/
|
2012-03-05 21:52:27 +08:00
|
|
|
if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
|
2012-03-05 21:52:23 +08:00
|
|
|
tty->alt_speed = 57600;
|
2012-03-05 21:52:27 +08:00
|
|
|
if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
|
2012-03-05 21:52:23 +08:00
|
|
|
tty->alt_speed = 115200;
|
2012-03-05 21:52:27 +08:00
|
|
|
if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
|
2012-03-05 21:52:23 +08:00
|
|
|
tty->alt_speed = 230400;
|
2012-03-05 21:52:27 +08:00
|
|
|
if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
|
2012-03-05 21:52:23 +08:00
|
|
|
tty->alt_speed = 460800;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
errout:
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine is called whenever a serial port is opened. It
|
|
|
|
* enables interrupts for a serial port, linking in its async structure into
|
|
|
|
* the IRQ chain. It also performs the serial-specific
|
|
|
|
* initialization for the tty structure.
|
|
|
|
*/
|
|
|
|
static int rs_open(struct tty_struct *tty, struct file * filp)
|
|
|
|
{
|
2012-03-05 21:52:20 +08:00
|
|
|
struct serial_state *info = rs_table + tty->index;
|
2012-03-05 21:52:32 +08:00
|
|
|
struct tty_port *port = &info->port;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-05 21:52:20 +08:00
|
|
|
tty->driver_data = info;
|
2013-01-03 22:53:05 +08:00
|
|
|
port->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* figure out which console to use (should be one already)
|
|
|
|
*/
|
|
|
|
console = console_drivers;
|
|
|
|
while (console) {
|
|
|
|
if ((console->flags & CON_ENABLED) && console->write) break;
|
|
|
|
console = console->next;
|
|
|
|
}
|
|
|
|
|
2012-03-05 21:52:37 +08:00
|
|
|
return tty_port_open(port, tty, filp);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* /proc fs routines....
|
|
|
|
*/
|
|
|
|
|
2009-04-01 06:19:23 +08:00
|
|
|
static int rs_proc_show(struct seq_file *m, void *v)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-04-01 06:19:23 +08:00
|
|
|
int i;
|
|
|
|
|
2012-03-05 21:52:42 +08:00
|
|
|
seq_printf(m, "simserinfo:1.0\n");
|
2009-04-01 06:19:23 +08:00
|
|
|
for (i = 0; i < NR_PORTS; i++)
|
2012-03-05 21:52:30 +08:00
|
|
|
seq_printf(m, "%d: uart:16550 port:3F8 irq:%d\n",
|
|
|
|
i, rs_table[i].irq);
|
2009-04-01 06:19:23 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-04-01 06:19:23 +08:00
|
|
|
static int rs_proc_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, rs_proc_show, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations rs_proc_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = rs_proc_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
2006-10-02 17:17:18 +08:00
|
|
|
static const struct tty_operations hp_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.open = rs_open,
|
|
|
|
.close = rs_close,
|
|
|
|
.write = rs_write,
|
|
|
|
.put_char = rs_put_char,
|
|
|
|
.flush_chars = rs_flush_chars,
|
|
|
|
.write_room = rs_write_room,
|
|
|
|
.chars_in_buffer = rs_chars_in_buffer,
|
|
|
|
.flush_buffer = rs_flush_buffer,
|
|
|
|
.ioctl = rs_ioctl,
|
|
|
|
.throttle = rs_throttle,
|
|
|
|
.unthrottle = rs_unthrottle,
|
|
|
|
.send_xchar = rs_send_xchar,
|
|
|
|
.hangup = rs_hangup,
|
2009-04-01 06:19:23 +08:00
|
|
|
.proc_fops = &rs_proc_fops,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2012-03-05 21:52:34 +08:00
|
|
|
static const struct tty_port_operations hp_port_ops = {
|
2012-03-05 21:52:37 +08:00
|
|
|
.activate = activate,
|
2012-03-05 21:52:38 +08:00
|
|
|
.shutdown = shutdown,
|
2012-03-05 21:52:34 +08:00
|
|
|
};
|
|
|
|
|
2012-03-05 21:52:28 +08:00
|
|
|
static int __init simrs_init(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-03-05 21:52:28 +08:00
|
|
|
struct serial_state *state;
|
|
|
|
int retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!ia64_platform_is("hpsim"))
|
|
|
|
return -ENODEV;
|
|
|
|
|
2012-03-05 21:52:01 +08:00
|
|
|
hp_simserial_driver = alloc_tty_driver(NR_PORTS);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!hp_simserial_driver)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-03-05 21:52:42 +08:00
|
|
|
printk(KERN_INFO "SimSerial driver with no serial options enabled\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Initialize the tty_driver structure */
|
|
|
|
|
|
|
|
hp_simserial_driver->driver_name = "simserial";
|
|
|
|
hp_simserial_driver->name = "ttyS";
|
|
|
|
hp_simserial_driver->major = TTY_MAJOR;
|
|
|
|
hp_simserial_driver->minor_start = 64;
|
|
|
|
hp_simserial_driver->type = TTY_DRIVER_TYPE_SERIAL;
|
|
|
|
hp_simserial_driver->subtype = SERIAL_TYPE_NORMAL;
|
|
|
|
hp_simserial_driver->init_termios = tty_std_termios;
|
|
|
|
hp_simserial_driver->init_termios.c_cflag =
|
|
|
|
B9600 | CS8 | CREAD | HUPCL | CLOCAL;
|
|
|
|
hp_simserial_driver->flags = TTY_DRIVER_REAL_RAW;
|
|
|
|
tty_set_operations(hp_simserial_driver, &hp_ops);
|
|
|
|
|
2012-03-05 21:52:28 +08:00
|
|
|
state = rs_table;
|
2012-03-05 21:52:32 +08:00
|
|
|
tty_port_init(&state->port);
|
2012-03-05 21:52:34 +08:00
|
|
|
state->port.ops = &hp_port_ops;
|
2012-03-05 21:52:32 +08:00
|
|
|
state->port.close_delay = 0; /* XXX really 0? */
|
2012-03-05 21:52:28 +08:00
|
|
|
|
|
|
|
retval = hpsim_get_irq(KEYBOARD_INTR);
|
|
|
|
if (retval < 0) {
|
|
|
|
printk(KERN_ERR "%s: out of interrupt vectors!\n",
|
|
|
|
__func__);
|
|
|
|
goto err_free_tty;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-05 21:52:28 +08:00
|
|
|
state->irq = retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-05 21:52:28 +08:00
|
|
|
/* the port is imaginary */
|
2012-03-05 21:52:30 +08:00
|
|
|
printk(KERN_INFO "ttyS0 at 0x03f8 (irq = %d) is a 16550\n", state->irq);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-08-08 03:47:51 +08:00
|
|
|
tty_port_link_device(&state->port, hp_simserial_driver, 0);
|
2012-03-05 21:52:28 +08:00
|
|
|
retval = tty_register_driver(hp_simserial_driver);
|
|
|
|
if (retval) {
|
|
|
|
printk(KERN_ERR "Couldn't register simserial driver\n");
|
|
|
|
goto err_free_tty;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2012-03-05 21:52:28 +08:00
|
|
|
err_free_tty:
|
|
|
|
put_tty_driver(hp_simserial_driver);
|
2012-11-15 16:49:56 +08:00
|
|
|
tty_port_destroy(&state->port);
|
2012-03-05 21:52:28 +08:00
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef MODULE
|
|
|
|
__initcall(simrs_init);
|
|
|
|
#endif
|