⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cm206.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* cm206.c. A linux-driver for the cm206 cdrom player with cm260 adapter card.   Copyright (c) 1995--1997 David A. van Leeuwen.   $Id: cm206.c,v 1.5 1997/12/26 11:02:51 david Exp $        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 program is distributed in the hope that it will be useful,     but WITHOUT ANY WARRANTY; without even the implied warranty of     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     GNU General Public License for more details.          You should have received a copy of the GNU General Public License     along with this program; if not, write to the Free Software     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.History: Started 25 jan 1994. Waiting for documentation... 22 feb 1995: 0.1a first reasonably safe polling driver.	      Two major bugs, one in read_sector and one in 	      do_cm206_request, happened to cancel! 25 feb 1995: 0.2a first reasonable interrupt driven version of above.              uart writes are still done in polling mode.  25 feb 1995: 0.21a writes also in interrupt mode, still some	      small bugs to be found... Larger buffer.   2 mrt 1995: 0.22 Bug found (cd-> nowhere, interrupt was called in              initialization), read_ahead of 16. Timeouts implemented.	      unclear if they do something...  7 mrt 1995: 0.23 Start of background read-ahead. 18 mrt 1995: 0.24 Working background read-ahead. (still problems) 26 mrt 1995: 0.25 Multi-session ioctl added (kernel v1.2).              Statistics implemented, though separate stats206.h.	      Accessible trough ioctl 0x1000 (just a number).	      Hard to choose between v1.2 development and 1.1.75.	      Bottom-half doesn't work with 1.2...	      0.25a: fixed... typo. Still problems...  1 apr 1995: 0.26 Module support added. Most bugs found. Use kernel 1.2.n.  5 apr 1995: 0.27 Auto-probe for the adapter card base address.              Auto-probe for the adaptor card irq line.  7 apr 1995: 0.28 Added lilo setup support for base address and irq.              Use major number 32 (not in this source), officially	      assigned to this driver.  9 apr 1995: 0.29 Added very limited audio support. Toc_header, stop, pause,              resume, eject. Play_track ignores track info, because we can't 	      read a table-of-contents entry. Toc_entry is implemented	      as a `placebo' function: always returns start of disc.   3 may 1995: 0.30 Audio support completed. The get_toc_entry function              is implemented as a binary search.  15 may 1995: 0.31 More work on audio stuff. Workman is not easy to               satisfy; changed binary search into linear search.	      Auto-probe for base address somewhat relaxed.  1 jun 1995: 0.32 Removed probe_irq_on/off for module version. 10 jun 1995: 0.33 Workman still behaves funny, but you should be              able to eject and substitute another disc. An adaptation of 0.33 is included in linux-1.3.7 by Eberhard Moenkeberg 18 jul 1995: 0.34 Patch by Heiko Eissfeldt included, mainly considering               verify_area's in the ioctls. Some bugs introduced by 	      EM considering the base port and irq fixed.  18 dec 1995: 0.35 Add some code for error checking... no luck... We jump to reach our goal: version 1.0 in the next stable linux kernel. 19 mar 1996: 0.95 Different implementation of CDROM_GET_UPC, on	      request of Thomas Quinot.  25 mar 1996: 0.96 Interpretation of opening with O_WRONLY or O_RDWR:	      open only for ioctl operation, e.g., for operation of	      tray etc. 4 apr 1996:  0.97 First implementation of layer between VFS and cdrom              driver, a generic interface. Much of the functionality	      of cm206_open() and cm206_ioctl() is transferred to a	      new file cdrom.c and its header ucdrom.h. 	      Upgrade to Linux kernel 1.3.78.  11 apr 1996  0.98 Upgrade to Linux kernel 1.3.85              More code moved to cdrom.c  	      0.99 Some more small changes to decrease number 	      of oopses at module load;   27 jul 1996  0.100 Many hours of debugging, kernel change from 1.2.13	      to 2.0.7 seems to have introduced some weird behavior	      in (interruptible_)sleep_on(&cd->data): the process	      seems to be woken without any explicit wake_up in my own	      code. Patch to try 100x in case such untriggered wake_up's 	      occur.  28 jul 1996  0.101 Rewriting of the code that receives the command echo,	      using a fifo to store echoed bytes.  	      Branch from 0.99:  	      0.99.1.0 Update to kernel release 2.0.10 dev_t -> kdev_t 	      (emoenke) various typos found by others.  extra 	      module-load oops protection.  	      0.99.1.1 Initialization constant cdrom_dops.speed 	      changed from float (2.0) to int (2); Cli()-sti() pair 	      around cm260_reset() in module initialization code.  	      0.99.1.2 Changes literally as proposed by Scott Snyder 	      <snyder@d0sgif.fnal.gov> for the 2.1 kernel line, which 	      have to do mainly with the poor minor support i had. The 	      major new concept is to change a cdrom driver's 	      operations struct from the capabilities struct. This 	      reflects the fact that there is one major for a driver, 	      whilst there can be many minors whith completely 	      different capabilities.	      0.99.1.3 More changes for operations/info separation.	      0.99.1.4 Added speed selection (someone had to do this	      first).  23 jan 1997 0.99.1.5 MODULE_PARMS call added.  23 jan 1997 0.100.1.2--0.100.1.5 following similar lines as   	      0.99.1.1--0.99.1.5. I get too many complaints about the	      drive making read errors. What't wrong with the 2.0+	      kernel line? Why get i (and othe cm206 owners) weird	      results? Why were things good in the good old 1.1--1.2 	      era? Why don't i throw away the drive? 2 feb 1997   0.102 Added `volatile' to values in cm206_struct. Seems to  	      reduce many of the problems. Rewrote polling routines	      to use fixed delays between polls. 	      0.103 Changed printk behavior. 	      0.104 Added a 0.100 -> 0.100.1.1 change11 feb 1997   0.105 Allow auto_probe during module load, disable              with module option "auto_probe=0". Moved some debugging	      statements to lower priority. Implemented select_speed()	      function. 13 feb 1997   1.0 Final version for 2.0 kernel line. 	      All following changes will be for the 2.1 kernel line. 15 feb 1997   1.1 Keep up with kernel 2.1.26, merge in changes from               cdrom.c 0.100.1.1--1.0. Add some more MODULE_PARMS. 14 sep 1997   1.2 Upgrade to Linux 2.1.55.  Added blksize_size[], patch              sent by James Bottomley <James.Bottomley@columbiasc.ncr.com>.21 dec 1997   1.4 Upgrade to Linux 2.1.72.  24 jan 1998   Removed the cm206_disc_status() function, as it was now dead              code.  The Uniform CDROM driver now provides this functionality.	      9 Nov. 1999   Make kernel-parameter implementation work with 2.3.x 	      Removed init_module & cleanup_module in favor of 	      module_init & module_exit.	      Torben Mathiasen <tmm@image.dk> *  * Parts of the code are based upon lmscd.c written by Kai Petzke, * sbpcd.c written by Eberhard Moenkeberg, and mcd.c by Martin * Harriss, but any off-the-shelf dynamic programming algorithm won't * be able to find them. * * The cm206 drive interface and the cm260 adapter card seem to be  * sufficiently different from their cm205/cm250 counterparts * in order to write a complete new driver. *  * I call all routines connected to the Linux kernel something * with `cm206' in it, as this stuff is too series-dependent.  *  * Currently, my limited knowledge is based on: * - The Linux Kernel Hacker's guide, v. 0.5, by Michael K. Johnson * - Linux Kernel Programmierung, by Michael Beck and others * - Philips/LMS cm206 and cm226 product specification * - Philips/LMS cm260 product specification * * David van Leeuwen, david@tm.tno.nl.  */#define REVISION "$Revision: 1.5 $"#include <linux/module.h>	#include <linux/errno.h>	/* These include what we really need */#include <linux/delay.h>#include <linux/string.h>#include <linux/sched.h>#include <linux/interrupt.h>#include <linux/timer.h>#include <linux/cdrom.h>#include <linux/devfs_fs_kernel.h>#include <linux/ioport.h>#include <linux/mm.h>#include <linux/malloc.h>#include <linux/init.h>/* #include <linux/ucdrom.h> */#include <asm/io.h>#define MAJOR_NR CM206_CDROM_MAJOR#include <linux/blk.h>#undef DEBUG#define STATISTICS		/* record times and frequencies of events */#define AUTO_PROBE_MODULE#define USE_INSW#include "cm206.h"/* This variable defines whether or not to probe for adapter base port    address and interrupt request. It can be overridden by the boot    parameter `auto'.*/static int auto_probe=1;	/* Yes, why not? */static int cm206_base = CM206_BASE;static int cm206_irq = CM206_IRQ; static int cm206[2] = {0,0};	/* for compatible `insmod' parameter passing */MODULE_PARM(cm206_base, "i");	/* base */MODULE_PARM(cm206_irq, "i");	/* irq */MODULE_PARM(cm206, "1-2i");	/* base,irq or irq,base */MODULE_PARM(auto_probe, "i");	/* auto probe base and irq */#define POLLOOP 100		/* milliseconds */#define READ_AHEAD 1		/* defines private buffer, waste! */#define BACK_AHEAD 1		/* defines adapter-read ahead */#define DATA_TIMEOUT (3*HZ)	/* measured in jiffies (10 ms) */#define UART_TIMEOUT (5*HZ/100)#define DSB_TIMEOUT (7*HZ)	/* time for the slowest command to finish */#define UR_SIZE 4		/* uart receive buffer fifo size */#define LINUX_BLOCK_SIZE 512	/* WHERE is this defined? */#define RAW_SECTOR_SIZE 2352	/* ok, is also defined in cdrom.h */#define ISO_SECTOR_SIZE 2048#define BLOCKS_ISO (ISO_SECTOR_SIZE/LINUX_BLOCK_SIZE) /* 4 */#define CD_SYNC_HEAD 16		/* CD_SYNC + CD_HEAD */#ifdef STATISTICS		/* keep track of errors in counters */#define stats(i) { ++cd->stats[st_ ## i]; \		     cd->last_stat[st_ ## i] = cd->stat_counter++; \		 }#else#define stats(i) (void) 0;#endif#define Debug(a) {printk (KERN_DEBUG); printk a;}#ifdef DEBUG#define debug(a) Debug(a)#else#define debug(a) (void) 0;#endiftypedef unsigned char uch;	/* 8-bits */typedef unsigned short ush;	/* 16-bits */struct toc_struct{		/* private copy of Table of Contents */  uch track, fsm[3], q0;};static int cm206_blocksizes[1] = { 2048 };struct cm206_struct {  volatile ush intr_ds;		/* data status read on last interrupt */  volatile ush intr_ls;		/* uart line status read on last interrupt*/  volatile uch ur[UR_SIZE];	/* uart receive buffer fifo */  volatile uch ur_w, ur_r;	/* write/read buffer index */  volatile uch dsb, cc;	 /* drive status byte and condition (error) code */  int command;			/* command to be written to the uart */  int openfiles;  ush sector[READ_AHEAD*RAW_SECTOR_SIZE/2]; /* buffered cd-sector */  int sector_first, sector_last; /* range of these sectors */  wait_queue_head_t uart;	/* wait queues for interrupt */  wait_queue_head_t data;  struct timer_list timer;	/* time-out */  char timed_out;  signed char max_sectors;	/* number of sectors that fit in adapter mem */  char wait_back;		/* we're waiting for a background-read */  char background;		/* is a read going on in the background? */  int adapter_first;		/* if so, that's the starting sector */  int adapter_last;  char fifo_overflowed;  uch disc_status[7];		/* result of get_disc_status command */#ifdef STATISTICS  int stats[NR_STATS];  int last_stat[NR_STATS];	/* `time' at which stat was stat */  int stat_counter;#endif    struct toc_struct toc[101];	/* The whole table of contents + lead-out */  uch q[10];			/* Last read q-channel info */  uch audio_status[5];		/* last read position on pause */  uch media_changed;		/* record if media changed */};#define DISC_STATUS cd->disc_status[0]#define FIRST_TRACK cd->disc_status[1]#define LAST_TRACK cd->disc_status[2]#define PAUSED cd->audio_status[0] /* misuse this memory byte! */#define PLAY_TO cd->toc[0]	/* toc[0] records end-time in play */static struct cm206_struct * cd; /* the main memory structure *//* First, we define some polling functions. These are actually   only being used in the initialization. */void send_command_polled(int command){  int loop=POLLOOP;  while (!(inw(r_line_status) & ls_transmitter_buffer_empty) && loop>0) {    mdelay(1);		/* one millisec delay */    --loop;  }  outw(command, r_uart_transmit);}uch receive_echo_polled(void){  int loop=POLLOOP;  while (!(inw(r_line_status) & ls_receive_buffer_full) && loop>0) {    mdelay(1);    --loop;  }  return ((uch) inw(r_uart_receive));}uch send_receive_polled(int command){  send_command_polled(command);  return receive_echo_polled();}inline void clear_ur(void) {  if (cd->ur_r != cd->ur_w) {    debug(("Deleting bytes from fifo:"));    for(;cd->ur_r != cd->ur_w; cd->ur_r++, cd->ur_r %= UR_SIZE)      debug((" 0x%x", cd->ur[cd->ur_r]));    debug(("\n"));  }}/* The interrupt handler. When the cm260 generates an interrupt, very   much care has to be taken in reading out the registers in the right   order; in case of a receive_buffer_full interrupt, first the   uart_receive must be read, and then the line status again to   de-assert the interrupt line. It took me a couple of hours to find   this out:-(    The function reset_cm206 appears to cause an interrupt, because   pulling up the INIT line clears both the uart-write-buffer /and/   the uart-write-buffer-empty mask. We call this a `lost interrupt,'   as there seems so reason for this to happen.*/static void cm206_interrupt(int sig, void *dev_id, struct pt_regs * regs) /* you rang? */{  volatile ush fool;  cd->intr_ds = inw(r_data_status); /* resets data_ready, data_error,				       crc_error, sync_error, toc_ready 				       interrupts */  cd->intr_ls = inw(r_line_status); /* resets overrun bit */  debug(("Intr, 0x%x 0x%x, %d\n", cd->intr_ds, cd->intr_ls, cd->background));  if (cd->intr_ls & ls_attention) stats(attention);  /* receive buffer full? */  if (cd->intr_ls & ls_receive_buffer_full) {	    cd->ur[cd->ur_w] = inb(r_uart_receive); /* get order right! */    cd->intr_ls = inw(r_line_status); /* resets rbf interrupt */    debug(("receiving #%d: 0x%x\n", cd->ur_w, cd->ur[cd->ur_w]));    cd->ur_w++; cd->ur_w %= UR_SIZE;    if (cd->ur_w == cd->ur_r) debug(("cd->ur overflow!\n"));    if (waitqueue_active(&cd->uart) && cd->background < 2) { 

⌨️ 快捷键说明

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