mux.c
来自「linux 内核源代码」· C语言 代码 · 共 635 行 · 第 1/2 页
C
635 行
/*** mux.c:** serial driver for the Mux console found in some PA-RISC servers.**** (c) Copyright 2002 Ryan Bradetich** (c) Copyright 2002 Hewlett-Packard Company**** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This Driver currently only supports the console (port 0) on the MUX.** Additional work will be needed on this driver to enable the full** functionality of the MUX.***/#include <linux/module.h>#include <linux/tty.h>#include <linux/ioport.h>#include <linux/init.h>#include <linux/serial.h>#include <linux/console.h>#include <linux/slab.h>#include <linux/delay.h> /* for udelay */#include <linux/device.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/parisc-device.h>#ifdef CONFIG_MAGIC_SYSRQ#include <linux/sysrq.h>#define SUPPORT_SYSRQ#endif#include <linux/serial_core.h>#define MUX_OFFSET 0x800#define MUX_LINE_OFFSET 0x80#define MUX_FIFO_SIZE 255#define MUX_POLL_DELAY (30 * HZ / 1000)#define IO_DATA_REG_OFFSET 0x3c#define IO_DCOUNT_REG_OFFSET 0x40#define MUX_EOFIFO(status) ((status & 0xF000) == 0xF000)#define MUX_STATUS(status) ((status & 0xF000) == 0x8000)#define MUX_BREAK(status) ((status & 0xF000) == 0x2000)#define MUX_NR 256static unsigned int port_cnt __read_mostly;struct mux_port { struct uart_port port; int enabled;};static struct mux_port mux_ports[MUX_NR];static struct uart_driver mux_driver = { .owner = THIS_MODULE, .driver_name = "ttyB", .dev_name = "ttyB", .major = MUX_MAJOR, .minor = 0, .nr = MUX_NR,};static struct timer_list mux_timer;#define UART_PUT_CHAR(p, c) __raw_writel((c), (p)->membase + IO_DATA_REG_OFFSET)#define UART_GET_FIFO_CNT(p) __raw_readl((p)->membase + IO_DCOUNT_REG_OFFSET)/** * get_mux_port_count - Get the number of available ports on the Mux. * @dev: The parisc device. * * This function is used to determine the number of ports the Mux * supports. The IODC data reports the number of ports the Mux * can support, but there are cases where not all the Mux ports * are connected. This function can override the IODC and * return the true port count. */static int __init get_mux_port_count(struct parisc_device *dev){ int status; u8 iodc_data[32]; unsigned long bytecnt; /* If this is the built-in Mux for the K-Class (Eole CAP/MUX), * we only need to allocate resources for 1 port since the * other 7 ports are not connected. */ if(dev->id.hversion == 0x15) return 1; status = pdc_iodc_read(&bytecnt, dev->hpa.start, 0, iodc_data, 32); BUG_ON(status != PDC_OK); /* Return the number of ports specified in the iodc data. */ return ((((iodc_data)[4] & 0xf0) >> 4) * 8) + 8;}/** * mux_tx_empty - Check if the transmitter fifo is empty. * @port: Ptr to the uart_port. * * This function test if the transmitter fifo for the port * described by 'port' is empty. If it is empty, this function * should return TIOCSER_TEMT, otherwise return 0. */static unsigned int mux_tx_empty(struct uart_port *port){ return UART_GET_FIFO_CNT(port) ? 0 : TIOCSER_TEMT;} /** * mux_set_mctrl - Set the current state of the modem control inputs. * @ports: Ptr to the uart_port. * @mctrl: Modem control bits. * * The Serial MUX does not support CTS, DCD or DSR so this function * is ignored. */static void mux_set_mctrl(struct uart_port *port, unsigned int mctrl){}/** * mux_get_mctrl - Returns the current state of modem control inputs. * @port: Ptr to the uart_port. * * The Serial MUX does not support CTS, DCD or DSR so these lines are * treated as permanently active. */static unsigned int mux_get_mctrl(struct uart_port *port){ return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;}/** * mux_stop_tx - Stop transmitting characters. * @port: Ptr to the uart_port. * * The Serial MUX does not support this function. */static void mux_stop_tx(struct uart_port *port){}/** * mux_start_tx - Start transmitting characters. * @port: Ptr to the uart_port. * * The Serial Mux does not support this function. */static void mux_start_tx(struct uart_port *port){}/** * mux_stop_rx - Stop receiving characters. * @port: Ptr to the uart_port. * * The Serial Mux does not support this function. */static void mux_stop_rx(struct uart_port *port){}/** * mux_enable_ms - Enable modum status interrupts. * @port: Ptr to the uart_port. * * The Serial Mux does not support this function. */static void mux_enable_ms(struct uart_port *port){}/** * mux_break_ctl - Control the transmitssion of a break signal. * @port: Ptr to the uart_port. * @break_state: Raise/Lower the break signal. * * The Serial Mux does not support this function. */static void mux_break_ctl(struct uart_port *port, int break_state){}/** * mux_write - Write chars to the mux fifo. * @port: Ptr to the uart_port. * * This function writes all the data from the uart buffer to * the mux fifo. */static void mux_write(struct uart_port *port){ int count; struct circ_buf *xmit = &port->info->xmit; if(port->x_char) { UART_PUT_CHAR(port, port->x_char); port->icount.tx++; port->x_char = 0; return; } if(uart_circ_empty(xmit) || uart_tx_stopped(port)) { mux_stop_tx(port); return; } count = (port->fifosize) - UART_GET_FIFO_CNT(port); do { UART_PUT_CHAR(port, xmit->buf[xmit->tail]); xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); port->icount.tx++; if(uart_circ_empty(xmit)) break; } while(--count > 0); while(UART_GET_FIFO_CNT(port)) udelay(1); if(uart_circ_chars_pending(xmit) < WAKEUP_CHARS) uart_write_wakeup(port); if (uart_circ_empty(xmit)) mux_stop_tx(port);}/** * mux_read - Read chars from the mux fifo. * @port: Ptr to the uart_port. * * This reads all available data from the mux's fifo and pushes * the data to the tty layer. */static void mux_read(struct uart_port *port){ int data; struct tty_struct *tty = port->info->tty; __u32 start_count = port->icount.rx; while(1) { data = __raw_readl(port->membase + IO_DATA_REG_OFFSET); if (MUX_STATUS(data)) continue; if (MUX_EOFIFO(data)) break; port->icount.rx++; if (MUX_BREAK(data)) { port->icount.brk++; if(uart_handle_break(port)) continue; } if (uart_handle_sysrq_char(port, data & 0xffu)) continue; tty_insert_flip_char(tty, data & 0xFF, TTY_NORMAL); } if (start_count != port->icount.rx) { tty_flip_buffer_push(tty); }}/** * mux_startup - Initialize the port. * @port: Ptr to the uart_port. * * Grab any resources needed for this port and start the * mux timer. */static int mux_startup(struct uart_port *port){ mux_ports[port->line].enabled = 1; return 0;}/** * mux_shutdown - Disable the port. * @port: Ptr to the uart_port. * * Release any resources needed for the port. */static void mux_shutdown(struct uart_port *port){ mux_ports[port->line].enabled = 0;}/** * mux_set_termios - Chane port parameters. * @port: Ptr to the uart_port. * @termios: new termios settings. * @old: old termios settings. * * The Serial Mux does not support this function. */static voidmux_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old){}/** * mux_type - Describe the port. * @port: Ptr to the uart_port. *
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?