serial_cs.c

来自「linux 内核源代码」· C语言 代码 · 共 982 行 · 第 1/3 页

C
982
字号
/*======================================================================    A driver for PCMCIA serial devices    serial_cs.c 1.134 2002/05/04 05:48:53    The contents of this file are subject to the Mozilla Public    License Version 1.1 (the "License"); you may not use this file    except in compliance with the License. You may obtain a copy of    the License at http://www.mozilla.org/MPL/    Software distributed under the License is distributed on an "AS    IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or    implied. See the License for the specific language governing    rights and limitations under the License.    The initial developer of the original code is David A. Hinds    <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds    are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.    Alternatively, the contents of this file may be used under the    terms of the GNU General Public License version 2 (the "GPL"), in which    case the provisions of the GPL are applicable instead of the    above.  If you wish to allow the use of your version of this file    only under the terms of the GPL and not to allow others to use    your version of this file under the MPL, indicate your decision    by deleting the provisions above and replace them with the notice    and other provisions required by the GPL.  If you do not delete    the provisions above, a recipient may use your version of this    file under either the MPL or the GPL.    ======================================================================*/#include <linux/module.h>#include <linux/moduleparam.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/ptrace.h>#include <linux/slab.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/serial_core.h>#include <linux/delay.h>#include <linux/major.h>#include <asm/io.h>#include <asm/system.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/cistpl.h>#include <pcmcia/ciscode.h>#include <pcmcia/ds.h>#include <pcmcia/cisreg.h>#include "8250.h"#ifdef PCMCIA_DEBUGstatic int pc_debug = PCMCIA_DEBUG;module_param(pc_debug, int, 0644);#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)static char *version = "serial_cs.c 1.134 2002/05/04 05:48:53 (David Hinds)";#else#define DEBUG(n, args...)#endif/*====================================================================*//* Parameters that can be set with 'insmod' *//* Enable the speaker? */static int do_sound = 1;/* Skip strict UART tests? */static int buggy_uart;module_param(do_sound, int, 0444);module_param(buggy_uart, int, 0444);/*====================================================================*//* Table of multi-port card ID's */struct serial_quirk {	unsigned int manfid;	unsigned int prodid;	int multi;		/* 1 = multifunction, > 1 = # ports */	void (*config)(struct pcmcia_device *);	void (*setup)(struct pcmcia_device *, struct uart_port *);	void (*wakeup)(struct pcmcia_device *);	int (*post)(struct pcmcia_device *);};struct serial_info {	struct pcmcia_device	*p_dev;	int			ndev;	int			multi;	int			slave;	int			manfid;	int			prodid;	int			c950ctrl;	dev_node_t		node[4];	int			line[4];	const struct serial_quirk *quirk;};struct serial_cfg_mem {	tuple_t tuple;	cisparse_t parse;	u_char buf[256];};/* * vers_1 5.0, "Brain Boxes", "2-Port RS232 card", "r6" * manfid 0x0160, 0x0104 * This card appears to have a 14.7456MHz clock. */static void quirk_setup_brainboxes_0104(struct pcmcia_device *link, struct uart_port *port){	port->uartclk = 14745600;}static int quirk_post_ibm(struct pcmcia_device *link){	conf_reg_t reg = { 0, CS_READ, 0x800, 0 };	int last_ret, last_fn;	last_ret = pcmcia_access_configuration_register(link, &reg);	if (last_ret) {		last_fn = AccessConfigurationRegister;		goto cs_failed;	}	reg.Action = CS_WRITE;	reg.Value = reg.Value | 1;	last_ret = pcmcia_access_configuration_register(link, &reg);	if (last_ret) {		last_fn = AccessConfigurationRegister;		goto cs_failed;	}	return 0; cs_failed:	cs_error(link, last_fn, last_ret);	return -ENODEV;}/* * Nokia cards are not really multiport cards.  Shouldn't this * be handled by setting the quirk entry .multi = 0 | 1 ? */static void quirk_config_nokia(struct pcmcia_device *link){	struct serial_info *info = link->priv;	if (info->multi > 1)		info->multi = 1;}static void quirk_wakeup_oxsemi(struct pcmcia_device *link){	struct serial_info *info = link->priv;	outb(12, info->c950ctrl + 1);}/* request_region? oxsemi branch does no request_region too... *//* * This sequence is needed to properly initialize MC45 attached to OXCF950. * I tried decreasing these msleep()s, but it worked properly (survived * 1000 stop/start operations) with these timeouts (or bigger). */static void quirk_wakeup_possio_gcc(struct pcmcia_device *link){	struct serial_info *info = link->priv;	unsigned int ctrl = info->c950ctrl;	outb(0xA, ctrl + 1);	msleep(100);	outb(0xE, ctrl + 1);	msleep(300);	outb(0xC, ctrl + 1);	msleep(100);	outb(0xE, ctrl + 1);	msleep(200);	outb(0xF, ctrl + 1);	msleep(100);	outb(0xE, ctrl + 1);	msleep(100);	outb(0xC, ctrl + 1);}/* * Socket Dual IO: this enables irq's for second port */static void quirk_config_socket(struct pcmcia_device *link){	struct serial_info *info = link->priv;	if (info->multi) {		link->conf.Present |= PRESENT_EXT_STATUS;		link->conf.ExtStatus = ESR_REQ_ATTN_ENA;	}}static const struct serial_quirk quirks[] = {	{		.manfid	= 0x0160,		.prodid	= 0x0104,		.multi	= -1,		.setup	= quirk_setup_brainboxes_0104,	}, {		.manfid	= MANFID_IBM,		.prodid	= ~0,		.multi	= -1,		.post	= quirk_post_ibm,	}, {		.manfid	= MANFID_INTEL,		.prodid	= PRODID_INTEL_DUAL_RS232,		.multi	= 2,	}, {		.manfid	= MANFID_NATINST,		.prodid	= PRODID_NATINST_QUAD_RS232,		.multi	= 4,	}, {		.manfid	= MANFID_NOKIA,		.prodid	= ~0,		.multi	= -1,		.config	= quirk_config_nokia,	}, {		.manfid	= MANFID_OMEGA,		.prodid	= PRODID_OMEGA_QSP_100,		.multi	= 4,	}, {		.manfid	= MANFID_OXSEMI,		.prodid	= ~0,		.multi	= -1,		.wakeup	= quirk_wakeup_oxsemi,	}, {		.manfid	= MANFID_POSSIO,		.prodid	= PRODID_POSSIO_GCC,		.multi	= -1,		.wakeup	= quirk_wakeup_possio_gcc,	}, {		.manfid	= MANFID_QUATECH,		.prodid	= PRODID_QUATECH_DUAL_RS232,		.multi	= 2,	}, {		.manfid	= MANFID_QUATECH,		.prodid	= PRODID_QUATECH_DUAL_RS232_D1,		.multi	= 2,	}, {		.manfid	= MANFID_QUATECH,		.prodid	= PRODID_QUATECH_DUAL_RS232_G,		.multi	= 2,	}, {		.manfid	= MANFID_QUATECH,		.prodid	= PRODID_QUATECH_QUAD_RS232,		.multi	= 4,	}, {		.manfid	= MANFID_SOCKET,		.prodid	= PRODID_SOCKET_DUAL_RS232,		.multi	= 2,		.config	= quirk_config_socket,	}, {		.manfid	= MANFID_SOCKET,		.prodid	= ~0,		.multi	= -1,		.config	= quirk_config_socket,	}};static int serial_config(struct pcmcia_device * link);/*======================================================================    After a card is removed, serial_remove() will unregister    the serial device(s), and release the PCMCIA configuration.    ======================================================================*/static void serial_remove(struct pcmcia_device *link){	struct serial_info *info = link->priv;	int i;	DEBUG(0, "serial_release(0x%p)\n", link);	/*	 * Recheck to see if the device is still configured.	 */	for (i = 0; i < info->ndev; i++)		serial8250_unregister_port(info->line[i]);	info->p_dev->dev_node = NULL;	if (!info->slave)		pcmcia_disable_device(link);}static int serial_suspend(struct pcmcia_device *link){	struct serial_info *info = link->priv;	int i;	for (i = 0; i < info->ndev; i++)		serial8250_suspend_port(info->line[i]);	return 0;}static int serial_resume(struct pcmcia_device *link){	struct serial_info *info = link->priv;	int i;	for (i = 0; i < info->ndev; i++)		serial8250_resume_port(info->line[i]);	if (info->quirk && info->quirk->wakeup)		info->quirk->wakeup(link);	return 0;}/*======================================================================    serial_attach() creates an "instance" of the driver, allocating    local data structures for one device.  The device is registered

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?