2017-11-06 17:11:51 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2006-06-29 22:13:17 +00:00
|
|
|
/* sunzilog.c: Zilog serial driver for Sparc systems.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Driver for Zilog serial chips found on Sun workstations and
|
|
|
|
* servers. This driver could actually be made more generic.
|
|
|
|
*
|
|
|
|
* This is based on the old drivers/sbus/char/zs.c code. A lot
|
|
|
|
* of code has been simply moved over directly from there but
|
|
|
|
* much has been rewritten. Credits therefore go out to Eddie
|
|
|
|
* C. Dost, Pete Zaitcev, Ted Ts'o and Alex Buell for their
|
|
|
|
* work there.
|
|
|
|
*
|
2007-07-16 06:53:32 +00:00
|
|
|
* Copyright (C) 2002, 2006, 2007 David S. Miller (davem@davemloft.net)
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/major.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/circ_buf.h>
|
|
|
|
#include <linux/serial.h>
|
|
|
|
#include <linux/sysrq.h>
|
|
|
|
#include <linux/console.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#ifdef CONFIG_SERIO
|
|
|
|
#include <linux/serio.h>
|
|
|
|
#endif
|
|
|
|
#include <linux/init.h>
|
2008-08-11 21:30:53 +00:00
|
|
|
#include <linux/of_device.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-05-13 03:01:42 +00:00
|
|
|
#include <linux/io.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/irq.h>
|
2006-06-29 22:13:17 +00:00
|
|
|
#include <asm/prom.h>
|
2012-03-28 17:30:03 +00:00
|
|
|
#include <asm/setup.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <linux/serial_core.h>
|
2012-02-09 23:48:19 +00:00
|
|
|
#include <linux/sunserialcore.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include "sunzilog.h"
|
|
|
|
|
|
|
|
/* On 32-bit sparcs we need to delay after register accesses
|
|
|
|
* to accommodate sun4 systems, but we do not need to flush writes.
|
|
|
|
* On 64-bit sparc we only need to flush single writes to ensure
|
|
|
|
* completion.
|
|
|
|
*/
|
|
|
|
#ifndef CONFIG_SPARC64
|
|
|
|
#define ZSDELAY() udelay(5)
|
|
|
|
#define ZSDELAY_LONG() udelay(20)
|
|
|
|
#define ZS_WSYNC(channel) do { } while (0)
|
|
|
|
#else
|
|
|
|
#define ZSDELAY()
|
|
|
|
#define ZSDELAY_LONG()
|
|
|
|
#define ZS_WSYNC(__channel) \
|
2006-06-29 22:13:17 +00:00
|
|
|
readb(&((__channel)->control))
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ZS_CLOCK 4915200 /* Zilog input clock rate. */
|
|
|
|
#define ZS_CLOCK_DIVISOR 16 /* Divisor this driver uses. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We wrap our port structure around the generic uart_port.
|
|
|
|
*/
|
|
|
|
struct uart_sunzilog_port {
|
|
|
|
struct uart_port port;
|
|
|
|
|
|
|
|
/* IRQ servicing chain. */
|
|
|
|
struct uart_sunzilog_port *next;
|
|
|
|
|
|
|
|
/* Current values of Zilog write registers. */
|
|
|
|
unsigned char curregs[NUM_ZSREGS];
|
|
|
|
|
|
|
|
unsigned int flags;
|
|
|
|
#define SUNZILOG_FLAG_CONS_KEYB 0x00000001
|
|
|
|
#define SUNZILOG_FLAG_CONS_MOUSE 0x00000002
|
|
|
|
#define SUNZILOG_FLAG_IS_CONS 0x00000004
|
|
|
|
#define SUNZILOG_FLAG_IS_KGDB 0x00000008
|
|
|
|
#define SUNZILOG_FLAG_MODEM_STATUS 0x00000010
|
|
|
|
#define SUNZILOG_FLAG_IS_CHANNEL_A 0x00000020
|
|
|
|
#define SUNZILOG_FLAG_REGS_HELD 0x00000040
|
|
|
|
#define SUNZILOG_FLAG_TX_STOPPED 0x00000080
|
|
|
|
#define SUNZILOG_FLAG_TX_ACTIVE 0x00000100
|
2007-05-09 20:49:04 +00:00
|
|
|
#define SUNZILOG_FLAG_ESCC 0x00000200
|
|
|
|
#define SUNZILOG_FLAG_ISR_HANDLER 0x00000400
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
unsigned int cflag;
|
|
|
|
|
|
|
|
unsigned char parity_mask;
|
|
|
|
unsigned char prev_status;
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIO
|
2006-06-29 22:13:17 +00:00
|
|
|
struct serio serio;
|
2005-04-16 22:20:36 +00:00
|
|
|
int serio_open;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2010-05-21 02:04:23 +00:00
|
|
|
static void sunzilog_putchar(struct uart_port *port, int ch);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#define ZILOG_CHANNEL_FROM_PORT(PORT) ((struct zilog_channel __iomem *)((PORT)->membase))
|
|
|
|
#define UART_ZILOG(PORT) ((struct uart_sunzilog_port *)(PORT))
|
|
|
|
|
|
|
|
#define ZS_IS_KEYB(UP) ((UP)->flags & SUNZILOG_FLAG_CONS_KEYB)
|
|
|
|
#define ZS_IS_MOUSE(UP) ((UP)->flags & SUNZILOG_FLAG_CONS_MOUSE)
|
|
|
|
#define ZS_IS_CONS(UP) ((UP)->flags & SUNZILOG_FLAG_IS_CONS)
|
|
|
|
#define ZS_IS_KGDB(UP) ((UP)->flags & SUNZILOG_FLAG_IS_KGDB)
|
|
|
|
#define ZS_WANTS_MODEM_STATUS(UP) ((UP)->flags & SUNZILOG_FLAG_MODEM_STATUS)
|
|
|
|
#define ZS_IS_CHANNEL_A(UP) ((UP)->flags & SUNZILOG_FLAG_IS_CHANNEL_A)
|
|
|
|
#define ZS_REGS_HELD(UP) ((UP)->flags & SUNZILOG_FLAG_REGS_HELD)
|
|
|
|
#define ZS_TX_STOPPED(UP) ((UP)->flags & SUNZILOG_FLAG_TX_STOPPED)
|
|
|
|
#define ZS_TX_ACTIVE(UP) ((UP)->flags & SUNZILOG_FLAG_TX_ACTIVE)
|
|
|
|
|
|
|
|
/* Reading and writing Zilog8530 registers. The delays are to make this
|
|
|
|
* driver work on the Sun4 which needs a settling delay after each chip
|
|
|
|
* register access, other machines handle this in hardware via auxiliary
|
|
|
|
* flip-flops which implement the settle time we do in software.
|
|
|
|
*
|
|
|
|
* The port lock must be held and local IRQs must be disabled
|
|
|
|
* when {read,write}_zsreg is invoked.
|
|
|
|
*/
|
|
|
|
static unsigned char read_zsreg(struct zilog_channel __iomem *channel,
|
|
|
|
unsigned char reg)
|
|
|
|
{
|
|
|
|
unsigned char retval;
|
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(reg, &channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
2006-06-29 22:13:17 +00:00
|
|
|
retval = readb(&channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_zsreg(struct zilog_channel __iomem *channel,
|
|
|
|
unsigned char reg, unsigned char value)
|
|
|
|
{
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(reg, &channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(value, &channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunzilog_clear_fifo(struct zilog_channel __iomem *channel)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
unsigned char regval;
|
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
regval = readb(&channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
if (regval & Rx_CH_AV)
|
|
|
|
break;
|
|
|
|
|
|
|
|
regval = read_zsreg(channel, R1);
|
2006-06-29 22:13:17 +00:00
|
|
|
readb(&channel->data);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
|
|
|
|
if (regval & (PAR_ERR | Rx_OVR | CRC_ERR)) {
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(ERR_RES, &channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
ZS_WSYNC(channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function must only be called when the TX is not busy. The UART
|
|
|
|
* port lock must be held and local interrupts disabled.
|
|
|
|
*/
|
2007-05-09 20:49:04 +00:00
|
|
|
static int __load_zsregs(struct zilog_channel __iomem *channel, unsigned char *regs)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
2007-05-09 20:49:04 +00:00
|
|
|
int escc;
|
|
|
|
unsigned char r15;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Let pending transmits finish. */
|
|
|
|
for (i = 0; i < 1000; i++) {
|
|
|
|
unsigned char stat = read_zsreg(channel, R1);
|
|
|
|
if (stat & ALL_SNT)
|
|
|
|
break;
|
|
|
|
udelay(100);
|
|
|
|
}
|
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(ERR_RES, &channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
ZS_WSYNC(channel);
|
|
|
|
|
|
|
|
sunzilog_clear_fifo(channel);
|
|
|
|
|
|
|
|
/* Disable all interrupts. */
|
|
|
|
write_zsreg(channel, R1,
|
|
|
|
regs[R1] & ~(RxINT_MASK | TxINT_ENAB | EXT_INT_ENAB));
|
|
|
|
|
|
|
|
/* Set parity, sync config, stop bits, and clock divisor. */
|
|
|
|
write_zsreg(channel, R4, regs[R4]);
|
|
|
|
|
|
|
|
/* Set misc. TX/RX control bits. */
|
|
|
|
write_zsreg(channel, R10, regs[R10]);
|
|
|
|
|
|
|
|
/* Set TX/RX controls sans the enable bits. */
|
|
|
|
write_zsreg(channel, R3, regs[R3] & ~RxENAB);
|
|
|
|
write_zsreg(channel, R5, regs[R5] & ~TxENAB);
|
|
|
|
|
|
|
|
/* Synchronous mode config. */
|
|
|
|
write_zsreg(channel, R6, regs[R6]);
|
|
|
|
write_zsreg(channel, R7, regs[R7]);
|
|
|
|
|
|
|
|
/* Don't mess with the interrupt vector (R2, unused by us) and
|
|
|
|
* master interrupt control (R9). We make sure this is setup
|
|
|
|
* properly at probe time then never touch it again.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Disable baud generator. */
|
|
|
|
write_zsreg(channel, R14, regs[R14] & ~BRENAB);
|
|
|
|
|
|
|
|
/* Clock mode control. */
|
|
|
|
write_zsreg(channel, R11, regs[R11]);
|
|
|
|
|
|
|
|
/* Lower and upper byte of baud rate generator divisor. */
|
|
|
|
write_zsreg(channel, R12, regs[R12]);
|
|
|
|
write_zsreg(channel, R13, regs[R13]);
|
|
|
|
|
|
|
|
/* Now rewrite R14, with BRENAB (if set). */
|
|
|
|
write_zsreg(channel, R14, regs[R14]);
|
|
|
|
|
|
|
|
/* External status interrupt control. */
|
2007-05-09 20:49:04 +00:00
|
|
|
write_zsreg(channel, R15, (regs[R15] | WR7pEN) & ~FIFOEN);
|
|
|
|
|
|
|
|
/* ESCC Extension Register */
|
|
|
|
r15 = read_zsreg(channel, R15);
|
|
|
|
if (r15 & 0x01) {
|
|
|
|
write_zsreg(channel, R7, regs[R7p]);
|
|
|
|
|
|
|
|
/* External status interrupt and FIFO control. */
|
|
|
|
write_zsreg(channel, R15, regs[R15] & ~WR7pEN);
|
|
|
|
escc = 1;
|
|
|
|
} else {
|
|
|
|
/* Clear FIFO bit case it is an issue */
|
|
|
|
regs[R15] &= ~FIFOEN;
|
|
|
|
escc = 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Reset external status interrupts. */
|
2007-05-09 20:49:04 +00:00
|
|
|
write_zsreg(channel, R0, RES_EXT_INT); /* First Latch */
|
|
|
|
write_zsreg(channel, R0, RES_EXT_INT); /* Second Latch */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Rewrite R3/R5, this time without enables masked. */
|
|
|
|
write_zsreg(channel, R3, regs[R3]);
|
|
|
|
write_zsreg(channel, R5, regs[R5]);
|
|
|
|
|
|
|
|
/* Rewrite R1, this time without IRQ enabled masked. */
|
|
|
|
write_zsreg(channel, R1, regs[R1]);
|
2007-05-09 20:49:04 +00:00
|
|
|
|
|
|
|
return escc;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Reprogram the Zilog channel HW registers with the copies found in the
|
|
|
|
* software state struct. If the transmitter is busy, we defer this update
|
|
|
|
* until the next TX complete interrupt. Else, we do it right now.
|
|
|
|
*
|
|
|
|
* The UART port lock must be held and local interrupts disabled.
|
|
|
|
*/
|
|
|
|
static void sunzilog_maybe_update_regs(struct uart_sunzilog_port *up,
|
|
|
|
struct zilog_channel __iomem *channel)
|
|
|
|
{
|
|
|
|
if (!ZS_REGS_HELD(up)) {
|
|
|
|
if (ZS_TX_ACTIVE(up)) {
|
|
|
|
up->flags |= SUNZILOG_FLAG_REGS_HELD;
|
|
|
|
} else {
|
|
|
|
__load_zsregs(channel, up->curregs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunzilog_change_mouse_baud(struct uart_sunzilog_port *up)
|
|
|
|
{
|
|
|
|
unsigned int cur_cflag = up->cflag;
|
|
|
|
int brg, new_baud;
|
|
|
|
|
|
|
|
up->cflag &= ~CBAUD;
|
|
|
|
up->cflag |= suncore_mouse_baud_cflag_next(cur_cflag, &new_baud);
|
|
|
|
|
|
|
|
brg = BPS_TO_BRG(new_baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
|
|
|
|
up->curregs[R12] = (brg & 0xff);
|
|
|
|
up->curregs[R13] = (brg >> 8) & 0xff;
|
|
|
|
sunzilog_maybe_update_regs(up, ZILOG_CHANNEL_FROM_PORT(&up->port));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunzilog_kbdms_receive_chars(struct uart_sunzilog_port *up,
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
unsigned char ch, int is_break)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
if (ZS_IS_KEYB(up)) {
|
|
|
|
/* Stop-A is handled by drivers/char/keyboard.c now. */
|
|
|
|
#ifdef CONFIG_SERIO
|
|
|
|
if (up->serio_open)
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
serio_interrupt(&up->serio, ch, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
} else if (ZS_IS_MOUSE(up)) {
|
|
|
|
int ret = suncore_mouse_baud_detection(ch, is_break);
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case 2:
|
|
|
|
sunzilog_change_mouse_baud(up);
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough;
|
2005-04-16 22:20:36 +00:00
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
#ifdef CONFIG_SERIO
|
|
|
|
if (up->serio_open)
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
serio_interrupt(&up->serio, ch, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
break;
|
2013-10-08 23:14:21 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 14:53:06 +00:00
|
|
|
static struct tty_port *
|
2005-04-16 22:20:36 +00:00
|
|
|
sunzilog_receive_chars(struct uart_sunzilog_port *up,
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
struct zilog_channel __iomem *channel)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2013-01-03 14:53:03 +00:00
|
|
|
struct tty_port *port = NULL;
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 04:54:13 +00:00
|
|
|
unsigned char ch, r1, flag;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2013-01-03 14:53:06 +00:00
|
|
|
if (up->port.state != NULL) /* Unopened serial console */
|
2013-01-03 14:53:03 +00:00
|
|
|
port = &up->port.state->port;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
|
|
|
r1 = read_zsreg(channel, R1);
|
|
|
|
if (r1 & (PAR_ERR | Rx_OVR | CRC_ERR)) {
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(ERR_RES, &channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
ZS_WSYNC(channel);
|
|
|
|
}
|
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
ch = readb(&channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
|
|
|
|
/* This funny hack depends upon BRK_ABRT not interfering
|
|
|
|
* with the other bits we care about in R1.
|
|
|
|
*/
|
|
|
|
if (ch & BRK_ABRT)
|
|
|
|
r1 |= BRK_ABRT;
|
|
|
|
|
|
|
|
if (!(ch & Rx_CH_AV))
|
|
|
|
break;
|
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
ch = readb(&channel->data);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
|
|
|
|
ch &= up->parity_mask;
|
|
|
|
|
|
|
|
if (unlikely(ZS_IS_KEYB(up)) || unlikely(ZS_IS_MOUSE(up))) {
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
sunzilog_kbdms_receive_chars(up, ch, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A real serial line, record the character and status. */
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 04:54:13 +00:00
|
|
|
flag = TTY_NORMAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
up->port.icount.rx++;
|
|
|
|
if (r1 & (BRK_ABRT | PAR_ERR | Rx_OVR | CRC_ERR)) {
|
|
|
|
if (r1 & BRK_ABRT) {
|
|
|
|
r1 &= ~(PAR_ERR | CRC_ERR);
|
|
|
|
up->port.icount.brk++;
|
|
|
|
if (uart_handle_break(&up->port))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (r1 & PAR_ERR)
|
|
|
|
up->port.icount.parity++;
|
|
|
|
else if (r1 & CRC_ERR)
|
|
|
|
up->port.icount.frame++;
|
|
|
|
if (r1 & Rx_OVR)
|
|
|
|
up->port.icount.overrun++;
|
|
|
|
r1 &= up->port.read_status_mask;
|
|
|
|
if (r1 & BRK_ABRT)
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 04:54:13 +00:00
|
|
|
flag = TTY_BREAK;
|
2005-04-16 22:20:36 +00:00
|
|
|
else if (r1 & PAR_ERR)
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 04:54:13 +00:00
|
|
|
flag = TTY_PARITY;
|
2005-04-16 22:20:36 +00:00
|
|
|
else if (r1 & CRC_ERR)
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 04:54:13 +00:00
|
|
|
flag = TTY_FRAME;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
TTY: serial, stop accessing potential NULLs
The following commits:
* 6732c8bb8671acbdac6cdc93dd72ddd581dd5e25 (TTY: switch
tty_schedule_flip)
* 2e124b4a390ca85325fae75764bef92f0547fa25 (TTY: switch
tty_flip_buffer_push)
* 05c7cd39907184328f48d3e7899f9cdd653ad336 (TTY: switch
tty_insert_flip_string)
* 92a19f9cec9a80ad93c06e115822deb729e2c6ad (TTY: switch
tty_insert_flip_char)
* 227434f8986c3827a1faedd1feb437acd6285315 (TTY: switch
tty_buffer_request_room to tty_port)
introduced a potential NULL dereference to some drivers. In
particular, when the device is used as a console, incoming bytes can
kill the box. This is caused by removed checks for TTY against NULL.
It happened because it was unclear to me why the checks were there. I
assumed them superfluous because the interrupts were unbound or
otherwise stopped. But this is not the case for consoles for these
drivers, as was pointed out by David Miller.
Now, this patch re-introduces the checks (at this point we check
port->state, not the tty proper, as we do not care about tty pointers
anymore). For both of the drivers, we place the check below the
handling of break signal so that sysrq can actually work. (One needs
to issue a break and then sysrq key within the following 5 seconds.)
We do not change sc26xx, sunhv, and sunsu here because they behave the
same as before. People having that hardware should fix the driver
eventually, however. They always could unconditionally dereference tty
in receive_chars, port->state in uart_handle_dcd_change, and
up->port.state->port.tty.
There is perhaps more to fix in all those drivers, but they are at
least in a state they were before.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Rob Herring <rob.herring@calxeda.com>
Cc: sparclinux@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-03-13 23:30:34 +00:00
|
|
|
if (uart_handle_sysrq_char(&up->port, ch) || !port)
|
2005-04-16 22:20:36 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (up->port.ignore_status_mask == 0xff ||
|
|
|
|
(r1 & up->port.ignore_status_mask) == 0) {
|
2013-01-03 14:53:03 +00:00
|
|
|
tty_insert_flip_char(port, ch, flag);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 04:54:13 +00:00
|
|
|
if (r1 & Rx_OVR)
|
2013-01-03 14:53:03 +00:00
|
|
|
tty_insert_flip_char(port, 0, TTY_OVERRUN);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 14:53:06 +00:00
|
|
|
return port;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sunzilog_status_handle(struct uart_sunzilog_port *up,
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
struct zilog_channel __iomem *channel)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned char status;
|
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
status = readb(&channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(RES_EXT_INT, &channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
ZS_WSYNC(channel);
|
|
|
|
|
|
|
|
if (status & BRK_ABRT) {
|
|
|
|
if (ZS_IS_MOUSE(up))
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
sunzilog_kbdms_receive_chars(up, 0, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (ZS_IS_CONS(up)) {
|
|
|
|
/* Wait for BREAK to deassert to avoid potentially
|
|
|
|
* confusing the PROM.
|
|
|
|
*/
|
|
|
|
while (1) {
|
2006-06-29 22:13:17 +00:00
|
|
|
status = readb(&channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
if (!(status & BRK_ABRT))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sun_do_break();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ZS_WANTS_MODEM_STATUS(up)) {
|
|
|
|
if (status & SYNC)
|
|
|
|
up->port.icount.dsr++;
|
|
|
|
|
|
|
|
/* The Zilog just gives us an interrupt when DCD/CTS/etc. change.
|
|
|
|
* But it does not tell us which bit has changed, we have to keep
|
|
|
|
* track of this ourselves.
|
|
|
|
*/
|
|
|
|
if ((status ^ up->prev_status) ^ DCD)
|
|
|
|
uart_handle_dcd_change(&up->port,
|
|
|
|
(status & DCD));
|
|
|
|
if ((status ^ up->prev_status) ^ CTS)
|
|
|
|
uart_handle_cts_change(&up->port,
|
|
|
|
(status & CTS));
|
|
|
|
|
2009-09-19 20:13:31 +00:00
|
|
|
wake_up_interruptible(&up->port.state->port.delta_msr_wait);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
up->prev_status = status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunzilog_transmit_chars(struct uart_sunzilog_port *up,
|
|
|
|
struct zilog_channel __iomem *channel)
|
|
|
|
{
|
|
|
|
struct circ_buf *xmit;
|
|
|
|
|
|
|
|
if (ZS_IS_CONS(up)) {
|
2006-06-29 22:13:17 +00:00
|
|
|
unsigned char status = readb(&channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
|
|
|
|
/* TX still busy? Just wait for the next TX done interrupt.
|
|
|
|
*
|
|
|
|
* It can occur because of how we do serial console writes. It would
|
|
|
|
* be nice to transmit console writes just like we normally would for
|
|
|
|
* a TTY line. (ie. buffered and TX interrupt driven). That is not
|
|
|
|
* easy because console writes cannot sleep. One solution might be
|
2011-03-31 01:57:33 +00:00
|
|
|
* to poll on enough port->xmit space becoming free. -DaveM
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
if (!(status & Tx_BUF_EMP))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
up->flags &= ~SUNZILOG_FLAG_TX_ACTIVE;
|
|
|
|
|
|
|
|
if (ZS_REGS_HELD(up)) {
|
|
|
|
__load_zsregs(channel, up->curregs);
|
|
|
|
up->flags &= ~SUNZILOG_FLAG_REGS_HELD;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ZS_TX_STOPPED(up)) {
|
|
|
|
up->flags &= ~SUNZILOG_FLAG_TX_STOPPED;
|
|
|
|
goto ack_tx_int;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (up->port.x_char) {
|
|
|
|
up->flags |= SUNZILOG_FLAG_TX_ACTIVE;
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(up->port.x_char, &channel->data);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
ZS_WSYNC(channel);
|
|
|
|
|
|
|
|
up->port.icount.tx++;
|
|
|
|
up->port.x_char = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-19 20:13:28 +00:00
|
|
|
if (up->port.state == NULL)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto ack_tx_int;
|
2009-09-19 20:13:28 +00:00
|
|
|
xmit = &up->port.state->xmit;
|
2005-10-11 03:43:22 +00:00
|
|
|
if (uart_circ_empty(xmit))
|
2005-04-16 22:20:36 +00:00
|
|
|
goto ack_tx_int;
|
2005-10-11 03:43:22 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (uart_tx_stopped(&up->port))
|
|
|
|
goto ack_tx_int;
|
|
|
|
|
|
|
|
up->flags |= SUNZILOG_FLAG_TX_ACTIVE;
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(xmit->buf[xmit->tail], &channel->data);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
ZS_WSYNC(channel);
|
|
|
|
|
|
|
|
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
|
|
|
|
up->port.icount.tx++;
|
|
|
|
|
|
|
|
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
|
|
|
|
uart_write_wakeup(&up->port);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
ack_tx_int:
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(RES_Tx_P, &channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
ZS_WSYNC(channel);
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static irqreturn_t sunzilog_interrupt(int irq, void *dev_id)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct uart_sunzilog_port *up = dev_id;
|
|
|
|
|
|
|
|
while (up) {
|
|
|
|
struct zilog_channel __iomem *channel
|
|
|
|
= ZILOG_CHANNEL_FROM_PORT(&up->port);
|
2013-01-03 14:53:06 +00:00
|
|
|
struct tty_port *port;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned char r3;
|
|
|
|
|
|
|
|
spin_lock(&up->port.lock);
|
|
|
|
r3 = read_zsreg(channel, R3);
|
|
|
|
|
|
|
|
/* Channel A */
|
2013-01-03 14:53:06 +00:00
|
|
|
port = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (r3 & (CHAEXT | CHATxIP | CHARxIP)) {
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(RES_H_IUS, &channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
ZS_WSYNC(channel);
|
|
|
|
|
|
|
|
if (r3 & CHARxIP)
|
2013-01-03 14:53:06 +00:00
|
|
|
port = sunzilog_receive_chars(up, channel);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (r3 & CHAEXT)
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
sunzilog_status_handle(up, channel);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (r3 & CHATxIP)
|
|
|
|
sunzilog_transmit_chars(up, channel);
|
|
|
|
}
|
|
|
|
spin_unlock(&up->port.lock);
|
|
|
|
|
2013-01-03 14:53:06 +00:00
|
|
|
if (port)
|
|
|
|
tty_flip_buffer_push(port);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Channel B */
|
|
|
|
up = up->next;
|
|
|
|
channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
|
|
|
|
|
|
|
|
spin_lock(&up->port.lock);
|
2013-01-03 14:53:06 +00:00
|
|
|
port = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) {
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(RES_H_IUS, &channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
ZS_WSYNC(channel);
|
|
|
|
|
|
|
|
if (r3 & CHBRxIP)
|
2013-01-03 14:53:06 +00:00
|
|
|
port = sunzilog_receive_chars(up, channel);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (r3 & CHBEXT)
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
sunzilog_status_handle(up, channel);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (r3 & CHBTxIP)
|
|
|
|
sunzilog_transmit_chars(up, channel);
|
|
|
|
}
|
|
|
|
spin_unlock(&up->port.lock);
|
|
|
|
|
2013-01-03 14:53:06 +00:00
|
|
|
if (port)
|
|
|
|
tty_flip_buffer_push(port);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
up = up->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A convenient way to quickly get R0 status. The caller must _not_ hold the
|
|
|
|
* port lock, it is acquired here.
|
|
|
|
*/
|
|
|
|
static __inline__ unsigned char sunzilog_read_channel_status(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct zilog_channel __iomem *channel;
|
|
|
|
unsigned char status;
|
|
|
|
|
|
|
|
channel = ZILOG_CHANNEL_FROM_PORT(port);
|
2006-06-29 22:13:17 +00:00
|
|
|
status = readb(&channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The port lock is not held. */
|
|
|
|
static unsigned int sunzilog_tx_empty(struct uart_port *port)
|
|
|
|
{
|
2005-06-29 08:42:38 +00:00
|
|
|
unsigned long flags;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned char status;
|
|
|
|
unsigned int ret;
|
|
|
|
|
2005-06-29 08:42:38 +00:00
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
status = sunzilog_read_channel_status(port);
|
2005-06-29 08:42:38 +00:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status & Tx_BUF_EMP)
|
|
|
|
ret = TIOCSER_TEMT;
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-06-29 08:42:38 +00:00
|
|
|
/* The port lock is held and interrupts are disabled. */
|
2005-04-16 22:20:36 +00:00
|
|
|
static unsigned int sunzilog_get_mctrl(struct uart_port *port)
|
|
|
|
{
|
|
|
|
unsigned char status;
|
|
|
|
unsigned int ret;
|
|
|
|
|
|
|
|
status = sunzilog_read_channel_status(port);
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
if (status & DCD)
|
|
|
|
ret |= TIOCM_CAR;
|
|
|
|
if (status & SYNC)
|
|
|
|
ret |= TIOCM_DSR;
|
|
|
|
if (status & CTS)
|
|
|
|
ret |= TIOCM_CTS;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The port lock is held and interrupts are disabled. */
|
|
|
|
static void sunzilog_set_mctrl(struct uart_port *port, unsigned int mctrl)
|
|
|
|
{
|
2014-10-05 17:19:48 +00:00
|
|
|
struct uart_sunzilog_port *up =
|
|
|
|
container_of(port, struct uart_sunzilog_port, port);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct zilog_channel __iomem *channel = ZILOG_CHANNEL_FROM_PORT(port);
|
|
|
|
unsigned char set_bits, clear_bits;
|
|
|
|
|
|
|
|
set_bits = clear_bits = 0;
|
|
|
|
|
|
|
|
if (mctrl & TIOCM_RTS)
|
|
|
|
set_bits |= RTS;
|
|
|
|
else
|
|
|
|
clear_bits |= RTS;
|
|
|
|
if (mctrl & TIOCM_DTR)
|
|
|
|
set_bits |= DTR;
|
|
|
|
else
|
|
|
|
clear_bits |= DTR;
|
|
|
|
|
|
|
|
/* NOTE: Not subject to 'transmitter active' rule. */
|
|
|
|
up->curregs[R5] |= set_bits;
|
|
|
|
up->curregs[R5] &= ~clear_bits;
|
|
|
|
write_zsreg(channel, R5, up->curregs[R5]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The port lock is held and interrupts are disabled. */
|
2005-08-31 09:12:14 +00:00
|
|
|
static void sunzilog_stop_tx(struct uart_port *port)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2014-10-05 17:19:48 +00:00
|
|
|
struct uart_sunzilog_port *up =
|
|
|
|
container_of(port, struct uart_sunzilog_port, port);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
up->flags |= SUNZILOG_FLAG_TX_STOPPED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The port lock is held and interrupts are disabled. */
|
2005-08-31 09:12:14 +00:00
|
|
|
static void sunzilog_start_tx(struct uart_port *port)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2014-10-05 17:19:48 +00:00
|
|
|
struct uart_sunzilog_port *up =
|
|
|
|
container_of(port, struct uart_sunzilog_port, port);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct zilog_channel __iomem *channel = ZILOG_CHANNEL_FROM_PORT(port);
|
|
|
|
unsigned char status;
|
|
|
|
|
|
|
|
up->flags |= SUNZILOG_FLAG_TX_ACTIVE;
|
|
|
|
up->flags &= ~SUNZILOG_FLAG_TX_STOPPED;
|
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
status = readb(&channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
|
|
|
|
/* TX busy? Just wait for the TX done interrupt. */
|
|
|
|
if (!(status & Tx_BUF_EMP))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Send the first character to jump-start the TX done
|
|
|
|
* IRQ sending engine.
|
|
|
|
*/
|
|
|
|
if (port->x_char) {
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(port->x_char, &channel->data);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
ZS_WSYNC(channel);
|
|
|
|
|
|
|
|
port->icount.tx++;
|
|
|
|
port->x_char = 0;
|
|
|
|
} else {
|
2009-09-19 20:13:28 +00:00
|
|
|
struct circ_buf *xmit = &port->state->xmit;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-07-06 15:29:52 +00:00
|
|
|
if (uart_circ_empty(xmit))
|
|
|
|
return;
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(xmit->buf[xmit->tail], &channel->data);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
ZS_WSYNC(channel);
|
|
|
|
|
|
|
|
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
|
|
|
|
port->icount.tx++;
|
|
|
|
|
|
|
|
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
|
|
|
|
uart_write_wakeup(&up->port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The port lock is held. */
|
|
|
|
static void sunzilog_stop_rx(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct uart_sunzilog_port *up = UART_ZILOG(port);
|
|
|
|
struct zilog_channel __iomem *channel;
|
|
|
|
|
|
|
|
if (ZS_IS_CONS(up))
|
|
|
|
return;
|
|
|
|
|
|
|
|
channel = ZILOG_CHANNEL_FROM_PORT(port);
|
|
|
|
|
|
|
|
/* Disable all RX interrupts. */
|
|
|
|
up->curregs[R1] &= ~RxINT_MASK;
|
|
|
|
sunzilog_maybe_update_regs(up, channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The port lock is held. */
|
|
|
|
static void sunzilog_enable_ms(struct uart_port *port)
|
|
|
|
{
|
2014-10-05 17:19:48 +00:00
|
|
|
struct uart_sunzilog_port *up =
|
|
|
|
container_of(port, struct uart_sunzilog_port, port);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct zilog_channel __iomem *channel = ZILOG_CHANNEL_FROM_PORT(port);
|
|
|
|
unsigned char new_reg;
|
|
|
|
|
|
|
|
new_reg = up->curregs[R15] | (DCDIE | SYNCIE | CTSIE);
|
|
|
|
if (new_reg != up->curregs[R15]) {
|
|
|
|
up->curregs[R15] = new_reg;
|
|
|
|
|
|
|
|
/* NOTE: Not subject to 'transmitter active' rule. */
|
2007-05-09 20:49:04 +00:00
|
|
|
write_zsreg(channel, R15, up->curregs[R15] & ~WR7pEN);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The port lock is not held. */
|
|
|
|
static void sunzilog_break_ctl(struct uart_port *port, int break_state)
|
|
|
|
{
|
2014-10-05 17:19:48 +00:00
|
|
|
struct uart_sunzilog_port *up =
|
|
|
|
container_of(port, struct uart_sunzilog_port, port);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct zilog_channel __iomem *channel = ZILOG_CHANNEL_FROM_PORT(port);
|
|
|
|
unsigned char set_bits, clear_bits, new_reg;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
set_bits = clear_bits = 0;
|
|
|
|
|
|
|
|
if (break_state)
|
|
|
|
set_bits |= SND_BRK;
|
|
|
|
else
|
|
|
|
clear_bits |= SND_BRK;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
|
|
|
|
|
|
|
new_reg = (up->curregs[R5] | set_bits) & ~clear_bits;
|
|
|
|
if (new_reg != up->curregs[R5]) {
|
|
|
|
up->curregs[R5] = new_reg;
|
|
|
|
|
|
|
|
/* NOTE: Not subject to 'transmitter active' rule. */
|
|
|
|
write_zsreg(channel, R5, up->curregs[R5]);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __sunzilog_startup(struct uart_sunzilog_port *up)
|
|
|
|
{
|
|
|
|
struct zilog_channel __iomem *channel;
|
|
|
|
|
|
|
|
channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
|
2006-06-29 22:13:17 +00:00
|
|
|
up->prev_status = readb(&channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Enable receiver and transmitter. */
|
|
|
|
up->curregs[R3] |= RxENAB;
|
|
|
|
up->curregs[R5] |= TxENAB;
|
|
|
|
|
|
|
|
up->curregs[R1] |= EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB;
|
|
|
|
sunzilog_maybe_update_regs(up, channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sunzilog_startup(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct uart_sunzilog_port *up = UART_ZILOG(port);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (ZS_IS_CONS(up))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
|
|
|
__sunzilog_startup(up);
|
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The test for ZS_IS_CONS is explained by the following e-mail:
|
|
|
|
*****
|
|
|
|
* From: Russell King <rmk@arm.linux.org.uk>
|
|
|
|
* Date: Sun, 8 Dec 2002 10:18:38 +0000
|
|
|
|
*
|
|
|
|
* On Sun, Dec 08, 2002 at 02:43:36AM -0500, Pete Zaitcev wrote:
|
|
|
|
* > I boot my 2.5 boxes using "console=ttyS0,9600" argument,
|
|
|
|
* > and I noticed that something is not right with reference
|
|
|
|
* > counting in this case. It seems that when the console
|
|
|
|
* > is open by kernel initially, this is not accounted
|
|
|
|
* > as an open, and uart_startup is not called.
|
|
|
|
*
|
|
|
|
* That is correct. We are unable to call uart_startup when the serial
|
|
|
|
* console is initialised because it may need to allocate memory (as
|
|
|
|
* request_irq does) and the memory allocators may not have been
|
|
|
|
* initialised.
|
|
|
|
*
|
|
|
|
* 1. initialise the port into a state where it can send characters in the
|
|
|
|
* console write method.
|
|
|
|
*
|
|
|
|
* 2. don't do the actual hardware shutdown in your shutdown() method (but
|
|
|
|
* do the normal software shutdown - ie, free irqs etc)
|
|
|
|
*****
|
|
|
|
*/
|
|
|
|
static void sunzilog_shutdown(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct uart_sunzilog_port *up = UART_ZILOG(port);
|
|
|
|
struct zilog_channel __iomem *channel;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (ZS_IS_CONS(up))
|
|
|
|
return;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
|
|
|
|
|
|
|
channel = ZILOG_CHANNEL_FROM_PORT(port);
|
|
|
|
|
|
|
|
/* Disable receiver and transmitter. */
|
|
|
|
up->curregs[R3] &= ~RxENAB;
|
|
|
|
up->curregs[R5] &= ~TxENAB;
|
|
|
|
|
|
|
|
/* Disable all interrupts and BRK assertion. */
|
|
|
|
up->curregs[R1] &= ~(EXT_INT_ENAB | TxINT_ENAB | RxINT_MASK);
|
|
|
|
up->curregs[R5] &= ~SND_BRK;
|
|
|
|
sunzilog_maybe_update_regs(up, channel);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Shared by TTY driver and serial console setup. The port lock is held
|
|
|
|
* and local interrupts are disabled.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sunzilog_convert_to_zs(struct uart_sunzilog_port *up, unsigned int cflag,
|
|
|
|
unsigned int iflag, int brg)
|
|
|
|
{
|
|
|
|
|
|
|
|
up->curregs[R10] = NRZ;
|
|
|
|
up->curregs[R11] = TCBR | RCBR;
|
|
|
|
|
|
|
|
/* Program BAUD and clock source. */
|
|
|
|
up->curregs[R4] &= ~XCLK_MASK;
|
|
|
|
up->curregs[R4] |= X16CLK;
|
|
|
|
up->curregs[R12] = brg & 0xff;
|
|
|
|
up->curregs[R13] = (brg >> 8) & 0xff;
|
|
|
|
up->curregs[R14] = BRSRC | BRENAB;
|
|
|
|
|
|
|
|
/* Character size, stop bits, and parity. */
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R3] &= ~RxN_MASK;
|
|
|
|
up->curregs[R5] &= ~TxN_MASK;
|
2005-04-16 22:20:36 +00:00
|
|
|
switch (cflag & CSIZE) {
|
|
|
|
case CS5:
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R3] |= Rx5;
|
|
|
|
up->curregs[R5] |= Tx5;
|
2005-04-16 22:20:36 +00:00
|
|
|
up->parity_mask = 0x1f;
|
|
|
|
break;
|
|
|
|
case CS6:
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R3] |= Rx6;
|
|
|
|
up->curregs[R5] |= Tx6;
|
2005-04-16 22:20:36 +00:00
|
|
|
up->parity_mask = 0x3f;
|
|
|
|
break;
|
|
|
|
case CS7:
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R3] |= Rx7;
|
|
|
|
up->curregs[R5] |= Tx7;
|
2005-04-16 22:20:36 +00:00
|
|
|
up->parity_mask = 0x7f;
|
|
|
|
break;
|
|
|
|
case CS8:
|
|
|
|
default:
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R3] |= Rx8;
|
|
|
|
up->curregs[R5] |= Tx8;
|
2005-04-16 22:20:36 +00:00
|
|
|
up->parity_mask = 0xff;
|
|
|
|
break;
|
2013-10-08 23:14:21 +00:00
|
|
|
}
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R4] &= ~0x0c;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (cflag & CSTOPB)
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R4] |= SB2;
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R4] |= SB1;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (cflag & PARENB)
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R4] |= PAR_ENAB;
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R4] &= ~PAR_ENAB;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!(cflag & PARODD))
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R4] |= PAR_EVEN;
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R4] &= ~PAR_EVEN;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
up->port.read_status_mask = Rx_OVR;
|
|
|
|
if (iflag & INPCK)
|
|
|
|
up->port.read_status_mask |= CRC_ERR | PAR_ERR;
|
2014-06-16 12:10:41 +00:00
|
|
|
if (iflag & (IGNBRK | BRKINT | PARMRK))
|
2005-04-16 22:20:36 +00:00
|
|
|
up->port.read_status_mask |= BRK_ABRT;
|
|
|
|
|
|
|
|
up->port.ignore_status_mask = 0;
|
|
|
|
if (iflag & IGNPAR)
|
|
|
|
up->port.ignore_status_mask |= CRC_ERR | PAR_ERR;
|
|
|
|
if (iflag & IGNBRK) {
|
|
|
|
up->port.ignore_status_mask |= BRK_ABRT;
|
|
|
|
if (iflag & IGNPAR)
|
|
|
|
up->port.ignore_status_mask |= Rx_OVR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cflag & CREAD) == 0)
|
|
|
|
up->port.ignore_status_mask = 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The port lock is not held. */
|
|
|
|
static void
|
2006-12-08 10:38:45 +00:00
|
|
|
sunzilog_set_termios(struct uart_port *port, struct ktermios *termios,
|
|
|
|
struct ktermios *old)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2014-10-05 17:19:48 +00:00
|
|
|
struct uart_sunzilog_port *up =
|
|
|
|
container_of(port, struct uart_sunzilog_port, port);
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
int baud, brg;
|
|
|
|
|
|
|
|
baud = uart_get_baud_rate(port, termios, old, 1200, 76800);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
|
|
|
|
|
|
|
brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
|
|
|
|
|
|
|
|
sunzilog_convert_to_zs(up, termios->c_cflag, termios->c_iflag, brg);
|
|
|
|
|
|
|
|
if (UART_ENABLE_MS(&up->port, termios->c_cflag))
|
|
|
|
up->flags |= SUNZILOG_FLAG_MODEM_STATUS;
|
|
|
|
else
|
|
|
|
up->flags &= ~SUNZILOG_FLAG_MODEM_STATUS;
|
|
|
|
|
|
|
|
up->cflag = termios->c_cflag;
|
|
|
|
|
|
|
|
sunzilog_maybe_update_regs(up, ZILOG_CHANNEL_FROM_PORT(port));
|
|
|
|
|
|
|
|
uart_update_timeout(port, termios->c_cflag, baud);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *sunzilog_type(struct uart_port *port)
|
|
|
|
{
|
2007-05-09 20:49:04 +00:00
|
|
|
struct uart_sunzilog_port *up = UART_ZILOG(port);
|
|
|
|
|
|
|
|
return (up->flags & SUNZILOG_FLAG_ESCC) ? "zs (ESCC)" : "zs";
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We do not request/release mappings of the registers here, this
|
|
|
|
* happens at early serial probe time.
|
|
|
|
*/
|
|
|
|
static void sunzilog_release_port(struct uart_port *port)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sunzilog_request_port(struct uart_port *port)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These do not need to do anything interesting either. */
|
|
|
|
static void sunzilog_config_port(struct uart_port *port, int flags)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We do not support letting the user mess with the divisor, IRQ, etc. */
|
|
|
|
static int sunzilog_verify_port(struct uart_port *port, struct serial_struct *ser)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-05-21 02:04:23 +00:00
|
|
|
#ifdef CONFIG_CONSOLE_POLL
|
|
|
|
static int sunzilog_get_poll_char(struct uart_port *port)
|
|
|
|
{
|
|
|
|
unsigned char ch, r1;
|
2014-10-05 17:19:48 +00:00
|
|
|
struct uart_sunzilog_port *up =
|
|
|
|
container_of(port, struct uart_sunzilog_port, port);
|
2010-05-21 02:04:23 +00:00
|
|
|
struct zilog_channel __iomem *channel
|
|
|
|
= ZILOG_CHANNEL_FROM_PORT(&up->port);
|
|
|
|
|
|
|
|
|
|
|
|
r1 = read_zsreg(channel, R1);
|
|
|
|
if (r1 & (PAR_ERR | Rx_OVR | CRC_ERR)) {
|
|
|
|
writeb(ERR_RES, &channel->control);
|
|
|
|
ZSDELAY();
|
|
|
|
ZS_WSYNC(channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
ch = readb(&channel->control);
|
|
|
|
ZSDELAY();
|
|
|
|
|
|
|
|
/* This funny hack depends upon BRK_ABRT not interfering
|
|
|
|
* with the other bits we care about in R1.
|
|
|
|
*/
|
|
|
|
if (ch & BRK_ABRT)
|
|
|
|
r1 |= BRK_ABRT;
|
|
|
|
|
|
|
|
if (!(ch & Rx_CH_AV))
|
|
|
|
return NO_POLL_CHAR;
|
|
|
|
|
|
|
|
ch = readb(&channel->data);
|
|
|
|
ZSDELAY();
|
|
|
|
|
|
|
|
ch &= up->parity_mask;
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunzilog_put_poll_char(struct uart_port *port,
|
|
|
|
unsigned char ch)
|
|
|
|
{
|
2014-10-05 17:19:48 +00:00
|
|
|
struct uart_sunzilog_port *up =
|
|
|
|
container_of(port, struct uart_sunzilog_port, port);
|
2010-05-21 02:04:23 +00:00
|
|
|
|
|
|
|
sunzilog_putchar(&up->port, ch);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_CONSOLE_POLL */
|
|
|
|
|
2017-01-25 17:48:52 +00:00
|
|
|
static const struct uart_ops sunzilog_pops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.tx_empty = sunzilog_tx_empty,
|
|
|
|
.set_mctrl = sunzilog_set_mctrl,
|
|
|
|
.get_mctrl = sunzilog_get_mctrl,
|
|
|
|
.stop_tx = sunzilog_stop_tx,
|
|
|
|
.start_tx = sunzilog_start_tx,
|
|
|
|
.stop_rx = sunzilog_stop_rx,
|
|
|
|
.enable_ms = sunzilog_enable_ms,
|
|
|
|
.break_ctl = sunzilog_break_ctl,
|
|
|
|
.startup = sunzilog_startup,
|
|
|
|
.shutdown = sunzilog_shutdown,
|
|
|
|
.set_termios = sunzilog_set_termios,
|
|
|
|
.type = sunzilog_type,
|
|
|
|
.release_port = sunzilog_release_port,
|
|
|
|
.request_port = sunzilog_request_port,
|
|
|
|
.config_port = sunzilog_config_port,
|
|
|
|
.verify_port = sunzilog_verify_port,
|
2010-05-21 02:04:23 +00:00
|
|
|
#ifdef CONFIG_CONSOLE_POLL
|
|
|
|
.poll_get_char = sunzilog_get_poll_char,
|
|
|
|
.poll_put_char = sunzilog_put_poll_char,
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2008-04-24 10:37:51 +00:00
|
|
|
static int uart_chip_count;
|
2005-04-16 22:20:36 +00:00
|
|
|
static struct uart_sunzilog_port *sunzilog_port_table;
|
|
|
|
static struct zilog_layout __iomem **sunzilog_chip_regs;
|
|
|
|
|
|
|
|
static struct uart_sunzilog_port *sunzilog_irq_chain;
|
|
|
|
|
|
|
|
static struct uart_driver sunzilog_reg = {
|
|
|
|
.owner = THIS_MODULE,
|
2008-05-01 08:14:27 +00:00
|
|
|
.driver_name = "sunzilog",
|
2005-04-16 22:20:36 +00:00
|
|
|
.dev_name = "ttyS",
|
|
|
|
.major = TTY_MAJOR,
|
|
|
|
};
|
|
|
|
|
2007-12-11 11:37:04 +00:00
|
|
|
static int __init sunzilog_alloc_tables(int num_sunzilog)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-06-29 22:13:17 +00:00
|
|
|
struct uart_sunzilog_port *up;
|
|
|
|
unsigned long size;
|
2007-12-11 11:37:04 +00:00
|
|
|
int num_channels = num_sunzilog * 2;
|
2006-06-29 22:13:17 +00:00
|
|
|
int i;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-12-11 11:37:04 +00:00
|
|
|
size = num_channels * sizeof(struct uart_sunzilog_port);
|
2006-06-29 22:13:17 +00:00
|
|
|
sunzilog_port_table = kzalloc(size, GFP_KERNEL);
|
|
|
|
if (!sunzilog_port_table)
|
|
|
|
return -ENOMEM;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-12-11 11:37:04 +00:00
|
|
|
for (i = 0; i < num_channels; i++) {
|
2006-06-29 22:13:17 +00:00
|
|
|
up = &sunzilog_port_table[i];
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
spin_lock_init(&up->port.lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
if (i == 0)
|
|
|
|
sunzilog_irq_chain = up;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-12-11 11:37:04 +00:00
|
|
|
if (i < num_channels - 1)
|
2006-06-29 22:13:17 +00:00
|
|
|
up->next = up + 1;
|
|
|
|
else
|
|
|
|
up->next = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 11:37:04 +00:00
|
|
|
size = num_sunzilog * sizeof(struct zilog_layout __iomem *);
|
2006-06-29 22:13:17 +00:00
|
|
|
sunzilog_chip_regs = kzalloc(size, GFP_KERNEL);
|
|
|
|
if (!sunzilog_chip_regs) {
|
|
|
|
kfree(sunzilog_port_table);
|
|
|
|
sunzilog_irq_chain = NULL;
|
|
|
|
return -ENOMEM;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
static void sunzilog_free_tables(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-06-29 22:13:17 +00:00
|
|
|
kfree(sunzilog_port_table);
|
|
|
|
sunzilog_irq_chain = NULL;
|
|
|
|
kfree(sunzilog_chip_regs);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ZS_PUT_CHAR_MAX_DELAY 2000 /* 10 ms */
|
|
|
|
|
2006-03-20 20:00:09 +00:00
|
|
|
static void sunzilog_putchar(struct uart_port *port, int ch)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-10-10 21:44:47 +00:00
|
|
|
struct zilog_channel __iomem *channel = ZILOG_CHANNEL_FROM_PORT(port);
|
2005-04-16 22:20:36 +00:00
|
|
|
int loops = ZS_PUT_CHAR_MAX_DELAY;
|
|
|
|
|
|
|
|
/* This is a timed polling loop so do not switch the explicit
|
|
|
|
* udelay with ZSDELAY as that is a NOP on some platforms. -DaveM
|
|
|
|
*/
|
|
|
|
do {
|
2006-06-29 22:13:17 +00:00
|
|
|
unsigned char val = readb(&channel->control);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (val & Tx_BUF_EMP) {
|
|
|
|
ZSDELAY();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
udelay(5);
|
|
|
|
} while (--loops);
|
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
writeb(ch, &channel->data);
|
2005-04-16 22:20:36 +00:00
|
|
|
ZSDELAY();
|
|
|
|
ZS_WSYNC(channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIO
|
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(sunzilog_serio_lock);
|
|
|
|
|
|
|
|
static int sunzilog_serio_write(struct serio *serio, unsigned char ch)
|
|
|
|
{
|
|
|
|
struct uart_sunzilog_port *up = serio->port_data;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sunzilog_serio_lock, flags);
|
|
|
|
|
2006-03-20 20:00:09 +00:00
|
|
|
sunzilog_putchar(&up->port, ch);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&sunzilog_serio_lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sunzilog_serio_open(struct serio *serio)
|
|
|
|
{
|
|
|
|
struct uart_sunzilog_port *up = serio->port_data;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sunzilog_serio_lock, flags);
|
|
|
|
if (!up->serio_open) {
|
|
|
|
up->serio_open = 1;
|
|
|
|
ret = 0;
|
|
|
|
} else
|
|
|
|
ret = -EBUSY;
|
|
|
|
spin_unlock_irqrestore(&sunzilog_serio_lock, flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunzilog_serio_close(struct serio *serio)
|
|
|
|
{
|
|
|
|
struct uart_sunzilog_port *up = serio->port_data;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sunzilog_serio_lock, flags);
|
|
|
|
up->serio_open = 0;
|
|
|
|
spin_unlock_irqrestore(&sunzilog_serio_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_SERIO */
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_SUNZILOG_CONSOLE
|
|
|
|
static void
|
|
|
|
sunzilog_console_write(struct console *con, const char *s, unsigned int count)
|
|
|
|
{
|
|
|
|
struct uart_sunzilog_port *up = &sunzilog_port_table[con->index];
|
|
|
|
unsigned long flags;
|
2007-07-16 06:53:32 +00:00
|
|
|
int locked = 1;
|
|
|
|
|
2014-03-04 20:28:35 +00:00
|
|
|
if (up->port.sysrq || oops_in_progress)
|
|
|
|
locked = spin_trylock_irqsave(&up->port.lock, flags);
|
|
|
|
else
|
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-03-20 20:00:09 +00:00
|
|
|
uart_console_write(&up->port, s, count, sunzilog_putchar);
|
2005-04-16 22:20:36 +00:00
|
|
|
udelay(2);
|
2007-07-16 06:53:32 +00:00
|
|
|
|
|
|
|
if (locked)
|
2014-03-04 20:28:35 +00:00
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init sunzilog_console_setup(struct console *con, char *options)
|
|
|
|
{
|
|
|
|
struct uart_sunzilog_port *up = &sunzilog_port_table[con->index];
|
|
|
|
unsigned long flags;
|
|
|
|
int baud, brg;
|
|
|
|
|
2006-08-23 22:53:39 +00:00
|
|
|
if (up->port.type != PORT_SUNZILOG)
|
2020-06-18 16:47:48 +00:00
|
|
|
return -EINVAL;
|
2006-08-23 22:53:39 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
printk(KERN_INFO "Console: ttyS%d (SunZilog zs%d)\n",
|
|
|
|
(sunzilog_reg.minor - 64) + con->index, con->index);
|
|
|
|
|
|
|
|
/* Get firmware console settings. */
|
2010-08-06 15:25:50 +00:00
|
|
|
sunserial_console_termios(con, up->port.dev->of_node);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Firmware console speed is limited to 150-->38400 baud so
|
|
|
|
* this hackish cflag thing is OK.
|
|
|
|
*/
|
|
|
|
switch (con->cflag & CBAUD) {
|
|
|
|
case B150: baud = 150; break;
|
|
|
|
case B300: baud = 300; break;
|
|
|
|
case B600: baud = 600; break;
|
|
|
|
case B1200: baud = 1200; break;
|
|
|
|
case B2400: baud = 2400; break;
|
|
|
|
case B4800: baud = 4800; break;
|
|
|
|
default: case B9600: baud = 9600; break;
|
|
|
|
case B19200: baud = 19200; break;
|
|
|
|
case B38400: baud = 38400; break;
|
2013-10-08 23:14:21 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
|
|
|
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R15] |= BRKIE;
|
2005-04-16 22:20:36 +00:00
|
|
|
sunzilog_convert_to_zs(up, con->cflag, 0, brg);
|
|
|
|
|
|
|
|
sunzilog_set_mctrl(&up->port, TIOCM_DTR | TIOCM_RTS);
|
|
|
|
__sunzilog_startup(up);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-10 21:44:01 +00:00
|
|
|
static struct console sunzilog_console_ops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.name = "ttyS",
|
|
|
|
.write = sunzilog_console_write,
|
|
|
|
.device = uart_console_device,
|
|
|
|
.setup = sunzilog_console_setup,
|
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
.index = -1,
|
|
|
|
.data = &sunzilog_reg,
|
|
|
|
};
|
|
|
|
|
2006-02-14 04:09:10 +00:00
|
|
|
static inline struct console *SUNZILOG_CONSOLE(void)
|
|
|
|
{
|
2006-10-10 21:44:01 +00:00
|
|
|
return &sunzilog_console_ops;
|
2006-02-14 04:09:10 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#else
|
2006-02-14 04:09:10 +00:00
|
|
|
#define SUNZILOG_CONSOLE() (NULL)
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
|
2012-11-19 18:21:50 +00:00
|
|
|
static void sunzilog_init_kbdms(struct uart_sunzilog_port *up)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int baud, brg;
|
|
|
|
|
2006-07-20 05:55:08 +00:00
|
|
|
if (up->flags & SUNZILOG_FLAG_CONS_KEYB) {
|
2005-04-16 22:20:36 +00:00
|
|
|
up->cflag = B1200 | CS8 | CLOCAL | CREAD;
|
|
|
|
baud = 1200;
|
|
|
|
} else {
|
|
|
|
up->cflag = B4800 | CS8 | CLOCAL | CREAD;
|
|
|
|
baud = 4800;
|
|
|
|
}
|
|
|
|
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R15] |= BRKIE;
|
2005-04-16 22:20:36 +00:00
|
|
|
brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
|
|
|
|
sunzilog_convert_to_zs(up, up->cflag, 0, brg);
|
|
|
|
sunzilog_set_mctrl(&up->port, TIOCM_DTR | TIOCM_RTS);
|
|
|
|
__sunzilog_startup(up);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIO
|
2012-11-19 18:21:50 +00:00
|
|
|
static void sunzilog_register_serio(struct uart_sunzilog_port *up)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-06-29 22:13:17 +00:00
|
|
|
struct serio *serio = &up->serio;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
serio->port_data = up;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
serio->id.type = SERIO_RS232;
|
2006-07-20 05:55:08 +00:00
|
|
|
if (up->flags & SUNZILOG_FLAG_CONS_KEYB) {
|
2006-06-29 22:13:17 +00:00
|
|
|
serio->id.proto = SERIO_SUNKBD;
|
|
|
|
strlcpy(serio->name, "zskbd", sizeof(serio->name));
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2006-06-29 22:13:17 +00:00
|
|
|
serio->id.proto = SERIO_SUN;
|
|
|
|
serio->id.extra = 1;
|
|
|
|
strlcpy(serio->name, "zsms", sizeof(serio->name));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-06-29 22:13:17 +00:00
|
|
|
strlcpy(serio->phys,
|
2006-07-20 05:55:08 +00:00
|
|
|
((up->flags & SUNZILOG_FLAG_CONS_KEYB) ?
|
|
|
|
"zs/serio0" : "zs/serio1"),
|
2006-06-29 22:13:17 +00:00
|
|
|
sizeof(serio->phys));
|
|
|
|
|
|
|
|
serio->write = sunzilog_serio_write;
|
|
|
|
serio->open = sunzilog_serio_open;
|
|
|
|
serio->close = sunzilog_serio_close;
|
|
|
|
serio->dev.parent = up->port.dev;
|
|
|
|
|
|
|
|
serio_register_port(serio);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-19 18:21:50 +00:00
|
|
|
static void sunzilog_init_hw(struct uart_sunzilog_port *up)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-06-29 22:13:17 +00:00
|
|
|
struct zilog_channel __iomem *channel;
|
|
|
|
unsigned long flags;
|
|
|
|
int baud, brg;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
|
|
|
if (ZS_IS_CHANNEL_A(up)) {
|
|
|
|
write_zsreg(channel, R9, FHWRES);
|
|
|
|
ZSDELAY_LONG();
|
|
|
|
(void) read_zsreg(channel, R0);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-07-20 05:55:08 +00:00
|
|
|
if (up->flags & (SUNZILOG_FLAG_CONS_KEYB |
|
|
|
|
SUNZILOG_FLAG_CONS_MOUSE)) {
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R1] = EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB;
|
|
|
|
up->curregs[R4] = PAR_EVEN | X16CLK | SB1;
|
|
|
|
up->curregs[R3] = RxENAB | Rx8;
|
|
|
|
up->curregs[R5] = TxENAB | Tx8;
|
|
|
|
up->curregs[R6] = 0x00; /* SDLC Address */
|
|
|
|
up->curregs[R7] = 0x7E; /* SDLC Flag */
|
|
|
|
up->curregs[R9] = NV;
|
|
|
|
up->curregs[R7p] = 0x00;
|
2008-04-27 06:10:19 +00:00
|
|
|
sunzilog_init_kbdms(up);
|
2007-05-09 20:49:04 +00:00
|
|
|
/* Only enable interrupts if an ISR handler available */
|
|
|
|
if (up->flags & SUNZILOG_FLAG_ISR_HANDLER)
|
|
|
|
up->curregs[R9] |= MIE;
|
2006-06-29 22:13:17 +00:00
|
|
|
write_zsreg(channel, R9, up->curregs[R9]);
|
|
|
|
} else {
|
|
|
|
/* Normal serial TTY. */
|
|
|
|
up->parity_mask = 0xff;
|
|
|
|
up->curregs[R1] = EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB;
|
|
|
|
up->curregs[R4] = PAR_EVEN | X16CLK | SB1;
|
|
|
|
up->curregs[R3] = RxENAB | Rx8;
|
|
|
|
up->curregs[R5] = TxENAB | Tx8;
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R6] = 0x00; /* SDLC Address */
|
|
|
|
up->curregs[R7] = 0x7E; /* SDLC Flag */
|
|
|
|
up->curregs[R9] = NV;
|
2006-06-29 22:13:17 +00:00
|
|
|
up->curregs[R10] = NRZ;
|
|
|
|
up->curregs[R11] = TCBR | RCBR;
|
|
|
|
baud = 9600;
|
|
|
|
brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
|
|
|
|
up->curregs[R12] = (brg & 0xff);
|
|
|
|
up->curregs[R13] = (brg >> 8) & 0xff;
|
|
|
|
up->curregs[R14] = BRSRC | BRENAB;
|
2007-05-09 20:49:04 +00:00
|
|
|
up->curregs[R15] = FIFOEN; /* Use FIFO if on ESCC */
|
|
|
|
up->curregs[R7p] = TxFIFO_LVL | RxFIFO_LVL;
|
|
|
|
if (__load_zsregs(channel, up->curregs)) {
|
|
|
|
up->flags |= SUNZILOG_FLAG_ESCC;
|
|
|
|
}
|
|
|
|
/* Only enable interrupts if an ISR handler available */
|
|
|
|
if (up->flags & SUNZILOG_FLAG_ISR_HANDLER)
|
|
|
|
up->curregs[R9] |= MIE;
|
2006-06-29 22:13:17 +00:00
|
|
|
write_zsreg(channel, R9, up->curregs[R9]);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_SERIO
|
2006-07-20 05:55:08 +00:00
|
|
|
if (up->flags & (SUNZILOG_FLAG_CONS_KEYB |
|
|
|
|
SUNZILOG_FLAG_CONS_MOUSE))
|
|
|
|
sunzilog_register_serio(up);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-01-26 17:44:09 +00:00
|
|
|
static int zilog_irq;
|
2006-06-29 22:13:40 +00:00
|
|
|
|
2012-11-19 18:21:50 +00:00
|
|
|
static int zs_probe(struct platform_device *op)
|
2006-06-29 22:13:17 +00:00
|
|
|
{
|
2008-04-24 10:37:51 +00:00
|
|
|
static int kbm_inst, uart_inst;
|
|
|
|
int inst;
|
2006-06-29 22:13:17 +00:00
|
|
|
struct uart_sunzilog_port *up;
|
|
|
|
struct zilog_layout __iomem *rp;
|
2008-04-24 10:37:51 +00:00
|
|
|
int keyboard_mouse = 0;
|
2006-06-29 22:13:17 +00:00
|
|
|
int err;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-04-13 23:12:29 +00:00
|
|
|
if (of_find_property(op->dev.of_node, "keyboard", NULL))
|
2006-07-20 05:55:08 +00:00
|
|
|
keyboard_mouse = 1;
|
|
|
|
|
2008-04-24 10:37:51 +00:00
|
|
|
/* uarts must come before keyboards/mice */
|
|
|
|
if (keyboard_mouse)
|
|
|
|
inst = uart_chip_count + kbm_inst;
|
|
|
|
else
|
|
|
|
inst = uart_inst;
|
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
sunzilog_chip_regs[inst] = of_ioremap(&op->resource[0], 0,
|
|
|
|
sizeof(struct zilog_layout),
|
|
|
|
"zs");
|
|
|
|
if (!sunzilog_chip_regs[inst])
|
|
|
|
return -ENOMEM;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
rp = sunzilog_chip_regs[inst];
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-01-26 17:44:09 +00:00
|
|
|
if (!zilog_irq)
|
2010-06-18 17:09:58 +00:00
|
|
|
zilog_irq = op->archdata.irqs[0];
|
2006-02-14 04:09:10 +00:00
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
up = &sunzilog_port_table[inst * 2];
|
|
|
|
|
|
|
|
/* Channel A */
|
|
|
|
up[0].port.mapbase = op->resource[0].start + 0x00;
|
|
|
|
up[0].port.membase = (void __iomem *) &rp->channelA;
|
|
|
|
up[0].port.iotype = UPIO_MEM;
|
2010-06-18 17:09:58 +00:00
|
|
|
up[0].port.irq = op->archdata.irqs[0];
|
2006-06-29 22:13:17 +00:00
|
|
|
up[0].port.uartclk = ZS_CLOCK;
|
|
|
|
up[0].port.fifosize = 1;
|
|
|
|
up[0].port.ops = &sunzilog_pops;
|
|
|
|
up[0].port.type = PORT_SUNZILOG;
|
|
|
|
up[0].port.flags = 0;
|
|
|
|
up[0].port.line = (inst * 2) + 0;
|
|
|
|
up[0].port.dev = &op->dev;
|
|
|
|
up[0].flags |= SUNZILOG_FLAG_IS_CHANNEL_A;
|
2019-12-13 00:06:47 +00:00
|
|
|
up[0].port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SUNZILOG_CONSOLE);
|
2006-07-20 05:55:08 +00:00
|
|
|
if (keyboard_mouse)
|
2006-06-29 22:13:17 +00:00
|
|
|
up[0].flags |= SUNZILOG_FLAG_CONS_KEYB;
|
|
|
|
sunzilog_init_hw(&up[0]);
|
|
|
|
|
|
|
|
/* Channel B */
|
|
|
|
up[1].port.mapbase = op->resource[0].start + 0x04;
|
|
|
|
up[1].port.membase = (void __iomem *) &rp->channelB;
|
|
|
|
up[1].port.iotype = UPIO_MEM;
|
2010-06-18 17:09:58 +00:00
|
|
|
up[1].port.irq = op->archdata.irqs[0];
|
2006-06-29 22:13:17 +00:00
|
|
|
up[1].port.uartclk = ZS_CLOCK;
|
|
|
|
up[1].port.fifosize = 1;
|
|
|
|
up[1].port.ops = &sunzilog_pops;
|
|
|
|
up[1].port.type = PORT_SUNZILOG;
|
|
|
|
up[1].port.flags = 0;
|
|
|
|
up[1].port.line = (inst * 2) + 1;
|
|
|
|
up[1].port.dev = &op->dev;
|
|
|
|
up[1].flags |= 0;
|
2019-12-13 00:06:47 +00:00
|
|
|
up[1].port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SUNZILOG_CONSOLE);
|
2006-07-20 05:55:08 +00:00
|
|
|
if (keyboard_mouse)
|
2006-06-29 22:13:17 +00:00
|
|
|
up[1].flags |= SUNZILOG_FLAG_CONS_MOUSE;
|
|
|
|
sunzilog_init_hw(&up[1]);
|
|
|
|
|
2006-07-20 05:55:08 +00:00
|
|
|
if (!keyboard_mouse) {
|
2010-04-13 23:12:29 +00:00
|
|
|
if (sunserial_console_match(SUNZILOG_CONSOLE(), op->dev.of_node,
|
2009-11-24 22:03:34 +00:00
|
|
|
&sunzilog_reg, up[0].port.line,
|
|
|
|
false))
|
2007-07-20 23:59:26 +00:00
|
|
|
up->flags |= SUNZILOG_FLAG_IS_CONS;
|
2006-06-29 22:13:17 +00:00
|
|
|
err = uart_add_one_port(&sunzilog_reg, &up[0].port);
|
|
|
|
if (err) {
|
2006-12-29 05:01:32 +00:00
|
|
|
of_iounmap(&op->resource[0],
|
|
|
|
rp, sizeof(struct zilog_layout));
|
2006-06-29 22:13:17 +00:00
|
|
|
return err;
|
|
|
|
}
|
2010-04-13 23:12:29 +00:00
|
|
|
if (sunserial_console_match(SUNZILOG_CONSOLE(), op->dev.of_node,
|
2009-11-24 22:03:34 +00:00
|
|
|
&sunzilog_reg, up[1].port.line,
|
|
|
|
false))
|
2007-07-20 23:59:26 +00:00
|
|
|
up->flags |= SUNZILOG_FLAG_IS_CONS;
|
2006-06-29 22:13:17 +00:00
|
|
|
err = uart_add_one_port(&sunzilog_reg, &up[1].port);
|
|
|
|
if (err) {
|
|
|
|
uart_remove_one_port(&sunzilog_reg, &up[0].port);
|
2006-12-29 05:01:32 +00:00
|
|
|
of_iounmap(&op->resource[0],
|
|
|
|
rp, sizeof(struct zilog_layout));
|
2006-06-29 22:13:17 +00:00
|
|
|
return err;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-04-24 10:37:51 +00:00
|
|
|
uart_inst++;
|
2006-07-20 05:55:08 +00:00
|
|
|
} else {
|
2007-08-25 22:17:31 +00:00
|
|
|
printk(KERN_INFO "%s: Keyboard at MMIO 0x%llx (irq = %d) "
|
2007-05-09 20:49:04 +00:00
|
|
|
"is a %s\n",
|
2009-03-24 23:38:21 +00:00
|
|
|
dev_name(&op->dev),
|
2007-08-25 22:17:31 +00:00
|
|
|
(unsigned long long) up[0].port.mapbase,
|
2010-06-18 17:09:58 +00:00
|
|
|
op->archdata.irqs[0], sunzilog_type(&up[0].port));
|
2007-08-25 22:17:31 +00:00
|
|
|
printk(KERN_INFO "%s: Mouse at MMIO 0x%llx (irq = %d) "
|
2007-05-09 20:49:04 +00:00
|
|
|
"is a %s\n",
|
2009-03-24 23:38:21 +00:00
|
|
|
dev_name(&op->dev),
|
2007-08-25 22:17:31 +00:00
|
|
|
(unsigned long long) up[1].port.mapbase,
|
2010-06-18 17:09:58 +00:00
|
|
|
op->archdata.irqs[0], sunzilog_type(&up[1].port));
|
2008-04-24 10:37:51 +00:00
|
|
|
kbm_inst++;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2013-05-23 10:39:36 +00:00
|
|
|
platform_set_drvdata(op, &up[0]);
|
2006-06-29 22:13:40 +00:00
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 18:26:18 +00:00
|
|
|
static void zs_remove_one(struct uart_sunzilog_port *up)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-06-29 22:13:17 +00:00
|
|
|
if (ZS_IS_KEYB(up) || ZS_IS_MOUSE(up)) {
|
|
|
|
#ifdef CONFIG_SERIO
|
|
|
|
serio_unregister_port(&up->serio);
|
|
|
|
#endif
|
|
|
|
} else
|
|
|
|
uart_remove_one_port(&sunzilog_reg, &up->port);
|
2006-06-29 22:13:40 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-11-19 18:26:18 +00:00
|
|
|
static int zs_remove(struct platform_device *op)
|
2006-06-29 22:13:40 +00:00
|
|
|
{
|
2013-05-23 10:39:36 +00:00
|
|
|
struct uart_sunzilog_port *up = platform_get_drvdata(op);
|
2006-06-29 22:13:40 +00:00
|
|
|
struct zilog_layout __iomem *regs;
|
|
|
|
|
|
|
|
zs_remove_one(&up[0]);
|
|
|
|
zs_remove_one(&up[1]);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-29 22:13:40 +00:00
|
|
|
regs = sunzilog_chip_regs[up[0].port.line / 2];
|
2006-12-29 05:01:32 +00:00
|
|
|
of_iounmap(&op->resource[0], regs, sizeof(struct zilog_layout));
|
2006-06-29 22:13:40 +00:00
|
|
|
|
2006-06-29 22:13:17 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-08-31 08:23:17 +00:00
|
|
|
static const struct of_device_id zs_match[] = {
|
2006-06-29 22:13:17 +00:00
|
|
|
{
|
|
|
|
.name = "zs",
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, zs_match);
|
|
|
|
|
2011-02-23 04:10:26 +00:00
|
|
|
static struct platform_driver zs_driver = {
|
2010-04-13 23:13:02 +00:00
|
|
|
.driver = {
|
|
|
|
.name = "zs",
|
|
|
|
.of_match_table = zs_match,
|
|
|
|
},
|
2006-06-29 22:13:17 +00:00
|
|
|
.probe = zs_probe,
|
2012-11-19 18:21:34 +00:00
|
|
|
.remove = zs_remove,
|
2006-06-29 22:13:17 +00:00
|
|
|
};
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static int __init sunzilog_init(void)
|
|
|
|
{
|
2006-06-29 22:13:17 +00:00
|
|
|
struct device_node *dp;
|
2008-04-24 10:37:51 +00:00
|
|
|
int err;
|
|
|
|
int num_keybms = 0;
|
2007-12-11 11:37:04 +00:00
|
|
|
int num_sunzilog = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-07-20 05:55:08 +00:00
|
|
|
for_each_node_by_name(dp, "zs") {
|
2007-12-11 11:37:04 +00:00
|
|
|
num_sunzilog++;
|
2006-07-20 05:55:08 +00:00
|
|
|
if (of_find_property(dp, "keyboard", NULL))
|
|
|
|
num_keybms++;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-12-11 11:37:04 +00:00
|
|
|
if (num_sunzilog) {
|
|
|
|
err = sunzilog_alloc_tables(num_sunzilog);
|
2006-06-29 22:13:17 +00:00
|
|
|
if (err)
|
2006-07-18 04:07:17 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-24 10:37:51 +00:00
|
|
|
uart_chip_count = num_sunzilog - num_keybms;
|
2006-06-29 22:13:17 +00:00
|
|
|
|
2008-04-24 10:37:51 +00:00
|
|
|
err = sunserial_register_minors(&sunzilog_reg,
|
|
|
|
uart_chip_count * 2);
|
2006-07-18 04:07:17 +00:00
|
|
|
if (err)
|
|
|
|
goto out_free_tables;
|
2006-06-29 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2011-02-23 04:10:26 +00:00
|
|
|
err = platform_driver_register(&zs_driver);
|
2006-07-18 04:07:17 +00:00
|
|
|
if (err)
|
|
|
|
goto out_unregister_uart;
|
|
|
|
|
2012-04-04 07:35:06 +00:00
|
|
|
if (zilog_irq) {
|
2007-05-09 20:49:04 +00:00
|
|
|
struct uart_sunzilog_port *up = sunzilog_irq_chain;
|
2006-07-18 04:07:17 +00:00
|
|
|
err = request_irq(zilog_irq, sunzilog_interrupt, IRQF_SHARED,
|
|
|
|
"zs", sunzilog_irq_chain);
|
|
|
|
if (err)
|
|
|
|
goto out_unregister_driver;
|
2007-05-09 20:49:04 +00:00
|
|
|
|
|
|
|
/* Enable Interrupts */
|
|
|
|
while (up) {
|
|
|
|
struct zilog_channel __iomem *channel;
|
|
|
|
|
|
|
|
/* printk (KERN_INFO "Enable IRQ for ZILOG Hardware %p\n", up); */
|
|
|
|
channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
|
|
|
|
up->flags |= SUNZILOG_FLAG_ISR_HANDLER;
|
|
|
|
up->curregs[R9] |= MIE;
|
|
|
|
write_zsreg(channel, R9, up->curregs[R9]);
|
|
|
|
up = up->next;
|
|
|
|
}
|
2006-07-18 04:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
|
|
|
|
out_unregister_driver:
|
2011-02-23 04:10:26 +00:00
|
|
|
platform_driver_unregister(&zs_driver);
|
2006-07-18 04:07:17 +00:00
|
|
|
|
|
|
|
out_unregister_uart:
|
2007-12-11 11:37:04 +00:00
|
|
|
if (num_sunzilog) {
|
|
|
|
sunserial_unregister_minors(&sunzilog_reg, num_sunzilog);
|
2006-07-18 04:07:17 +00:00
|
|
|
sunzilog_reg.cons = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
out_free_tables:
|
|
|
|
sunzilog_free_tables();
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit sunzilog_exit(void)
|
|
|
|
{
|
2011-02-23 04:10:26 +00:00
|
|
|
platform_driver_unregister(&zs_driver);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-04-04 07:35:06 +00:00
|
|
|
if (zilog_irq) {
|
2007-05-09 20:49:04 +00:00
|
|
|
struct uart_sunzilog_port *up = sunzilog_irq_chain;
|
|
|
|
|
|
|
|
/* Disable Interrupts */
|
|
|
|
while (up) {
|
|
|
|
struct zilog_channel __iomem *channel;
|
|
|
|
|
|
|
|
/* printk (KERN_INFO "Disable IRQ for ZILOG Hardware %p\n", up); */
|
|
|
|
channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
|
|
|
|
up->flags &= ~SUNZILOG_FLAG_ISR_HANDLER;
|
|
|
|
up->curregs[R9] &= ~MIE;
|
|
|
|
write_zsreg(channel, R9, up->curregs[R9]);
|
|
|
|
up = up->next;
|
|
|
|
}
|
|
|
|
|
2006-06-29 22:13:40 +00:00
|
|
|
free_irq(zilog_irq, sunzilog_irq_chain);
|
2012-01-26 17:44:09 +00:00
|
|
|
zilog_irq = 0;
|
2006-06-29 22:13:40 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 11:37:04 +00:00
|
|
|
if (sunzilog_reg.nr) {
|
|
|
|
sunserial_unregister_minors(&sunzilog_reg, sunzilog_reg.nr);
|
2006-06-29 22:13:17 +00:00
|
|
|
sunzilog_free_tables();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(sunzilog_init);
|
|
|
|
module_exit(sunzilog_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("David S. Miller");
|
|
|
|
MODULE_DESCRIPTION("Sun Zilog serial port driver");
|
2006-06-29 22:14:17 +00:00
|
|
|
MODULE_VERSION("2.0");
|
2005-04-16 22:20:36 +00:00
|
|
|
MODULE_LICENSE("GPL");
|