14Srgrimes/*-
24Srgrimes * Copyright (c) 1991 The Regents of the University of California.
34Srgrimes * All rights reserved.
44Srgrimes *
54Srgrimes * Redistribution and use in source and binary forms, with or without
64Srgrimes * modification, are permitted provided that the following conditions
74Srgrimes * are met:
84Srgrimes * 1. Redistributions of source code must retain the above copyright
94Srgrimes *    notice, this list of conditions and the following disclaimer.
104Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
114Srgrimes *    notice, this list of conditions and the following disclaimer in the
124Srgrimes *    documentation and/or other materials provided with the distribution.
134Srgrimes * 4. Neither the name of the University nor the names of its contributors
144Srgrimes *    may be used to endorse or promote products derived from this software
154Srgrimes *    without specific prior written permission.
164Srgrimes *
174Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
184Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
194Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
204Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
214Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
224Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
234Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
244Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
254Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
264Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
274Srgrimes * SUCH DAMAGE.
284Srgrimes *
29619Srgrimes *	from: @(#)nec765.h	7.1 (Berkeley) 5/9/91
3050477Speter * $FreeBSD$
314Srgrimes */
324Srgrimes
334Srgrimes/*
344Srgrimes * Nec 765 floppy disc controller definitions
354Srgrimes */
364Srgrimes
374Srgrimes/* Main status register */
38162165Sjkim#define NE7_DAB		0x01	/* Diskette drive A is seeking, thus busy */
39162165Sjkim#define NE7_DBB		0x02	/* Diskette drive B is seeking, thus busy */
40162165Sjkim#define NE7_CB		0x10	/* Diskette Controller Busy */
41162165Sjkim#define NE7_NDM		0x20	/* Diskette Controller in Non Dma Mode */
42162165Sjkim#define NE7_DIO		0x40	/* Diskette Controller Data register I/O */
43162165Sjkim#define NE7_RQM		0x80	/* Diskette Controller ReQuest for Master */
444Srgrimes
454Srgrimes/* Status register ST0 */
462838Sdg#define NE7_ST0BITS	"\020\010invld\007abnrml\006seek_cmplt\005equ_chck\004drive_notrdy\003top_head"
474Srgrimes
482838Sdg#define NE7_ST0_IC	0xc0	/* interrupt completion code */
492838Sdg
502838Sdg#define NE7_ST0_IC_RC	0xc0	/* terminated due to ready changed, n/a */
512838Sdg#define NE7_ST0_IC_IV	0x80	/* invalid command; must reset FDC */
522838Sdg#define NE7_ST0_IC_AT	0x40	/* abnormal termination, check error stat */
532838Sdg#define NE7_ST0_IC_NT	0x00	/* normal termination */
542838Sdg
552838Sdg#define NE7_ST0_SE	0x20	/* seek end */
562838Sdg#define NE7_ST0_EC	0x10	/* equipment check, recalibrated but no trk0 */
572838Sdg#define NE7_ST0_NR	0x08	/* not ready (n/a) */
582838Sdg#define NE7_ST0_HD	0x04	/* upper head selected */
592838Sdg#define NE7_ST0_DR	0x03	/* drive code */
602838Sdg
614Srgrimes/* Status register ST1 */
624Srgrimes#define NE7_ST1BITS	"\020\010end_of_cyl\006bad_crc\005data_overrun\003sec_not_fnd\002write_protect\001no_am"
634Srgrimes
642838Sdg#define NE7_ST1_EN	0x80	/* end of cylinder, access past last record */
652838Sdg#define NE7_ST1_DE	0x20	/* data error, CRC fail in ID or data */
662838Sdg#define NE7_ST1_OR	0x10	/* DMA overrun, DMA failed to do i/o quickly */
672838Sdg#define NE7_ST1_ND	0x04	/* no data, sector not found or CRC in ID f. */
682838Sdg#define NE7_ST1_NW	0x02	/* not writeable, attempt to violate WP */
692838Sdg#define NE7_ST1_MA	0x01	/* missing address mark (in ID or data field)*/
702838Sdg
714Srgrimes/* Status register ST2 */
724Srgrimes#define NE7_ST2BITS	"\020\007ctrl_mrk\006bad_crc\005wrong_cyl\004scn_eq\003scn_not_fnd\002bad_cyl\001no_dam"
734Srgrimes
742838Sdg#define NE7_ST2_CM	0x40	/* control mark; found deleted data */
752838Sdg#define NE7_ST2_DD	0x20	/* data error in data field, CRC fail */
762838Sdg#define NE7_ST2_WC	0x10	/* wrong cylinder, ID field mismatches cmd */
772838Sdg#define NE7_ST2_SH	0x08	/* scan equal hit */
782838Sdg#define NE7_ST2_SN	0x04	/* scan not satisfied */
792838Sdg#define NE7_ST2_BC	0x02	/* bad cylinder, cylinder marked 0xff */
802838Sdg#define NE7_ST2_MD	0x01	/* missing address mark in data field */
812838Sdg
824Srgrimes/* Status register ST3 */
834Srgrimes#define NE7_ST3BITS	"\020\010fault\007write_protect\006drdy\005tk0\004two_side\003side_sel\002"
844Srgrimes
852838Sdg#define NE7_ST3_FT	0x80	/* fault; PC: n/a */
862838Sdg#define NE7_ST3_WP	0x40	/* write protected */
872838Sdg#define NE7_ST3_RD	0x20	/* ready; PC: always true */
882838Sdg#define NE7_ST3_T0	0x10	/* track 0 */
892838Sdg#define NE7_ST3_TS	0x08	/* two-sided; PC: n/a */
902838Sdg#define NE7_ST3_HD	0x04	/* upper head select */
912838Sdg#define NE7_ST3_US	0x03	/* unit select */
922838Sdg
93160137Sjkim/* Data Rate Select Register DSR (enhanced controller) */
94160137Sjkim#define I8207X_DSR_SR	0x80	/* software reset */
95160137Sjkim#define I8207X_DSR_LP	0x40	/* low power */
96160137Sjkim#define I8207X_DSR_PS	0x1c	/* precompensation select */
97160137Sjkim#define I8207X_DSR_RS	0x03	/* data rate select */
98160137Sjkim
994Srgrimes/* Commands */
1002838Sdg/*
1012838Sdg * the top three bits -- where appropriate -- are set as follows:
1022838Sdg *
10388010Sjoerg * MT  - multi-track; allow both sides to be handled in single cmd
10488010Sjoerg * MFM - modified frequency modulation; use MFM encoding
10588010Sjoerg * SK  - skip; skip sectors marked as "deleted"
1062838Sdg */
10788010Sjoerg
10888010Sjoerg#define NE7CMD_MT	0x80	/* READ, WRITE, WRITEDEL, READDEL, SCAN* */
10988010Sjoerg#define NE7CMD_MFM	0x40	/* same as MT, plus READTRK, READID, FORMAT */
11088010Sjoerg#define NE7CMD_SK	0x20	/* READ, READDEL, SCAN* */
11188010Sjoerg
112162165Sjkim#define NE7CMD_READTRK	0x02	/*  read whole track */
113162165Sjkim#define NE7CMD_SPECIFY	0x03	/*  specify drive parameters - requires unit
11488010Sjoerg				 *  parameters byte */
115162165Sjkim#define NE7CMD_SENSED	0x04	/*  sense drive - requires unit select byte */
116162165Sjkim#define NE7CMD_WRITE	0x05	/*  write - requires eight additional bytes */
117162165Sjkim#define NE7CMD_READ	0x06	/*  read - requires eight additional bytes */
118162165Sjkim#define NE7CMD_RECAL	0x07	/*  recalibrate drive - requires
11988010Sjoerg				 *  unit select byte */
120162165Sjkim#define NE7CMD_SENSEI	0x08	/*  sense controller interrupt status */
121162165Sjkim#define NE7CMD_WRITEDEL	0x09	/*  write deleted data */
122162165Sjkim#define NE7CMD_READID	0x0a	/*  read ID field */
123162165Sjkim#define NE7CMD_READDEL	0x0c	/*  read deleted data */
124162165Sjkim#define NE7CMD_FORMAT	0x0d	/*  format - requires five additional bytes */
125162165Sjkim#define NE7CMD_SEEK	0x0f	/*  seek drive - requires unit select byte
12688010Sjoerg				 *  and new cyl byte */
127162165Sjkim#define NE7CMD_VERSION	0x10	/*  get version */
12888010Sjoerg#define NE7CMD_SCNEQU	0x11	/*  scan equal */
12988010Sjoerg#define NE7CMD_SCNLE	0x19	/*  scan less or equal */
13088010Sjoerg#define NE7CMD_SCNGE	0x1d	/*  scan greater or equal */
1312838Sdg
1325417Sjoerg/*
1335417Sjoerg * Enhanced controller commands:
1345417Sjoerg */
135162165Sjkim#define I8207X_DUMPREG	0x0e	/*  dump internal registers */
136162165Sjkim#define I8207X_CONFIG	0x13	/*  configure enhanced features */
1372838Sdg
1382838Sdg/*
1392838Sdg * "specify" definitions
1402838Sdg *
1412838Sdg * acronyms (times are relative to a FDC clock of 8 MHz):
1422838Sdg * srt - step rate; PC usually 3 ms
1432838Sdg * hut - head unload time; PC usually maximum of 240 ms
1442838Sdg * hlt - head load time; PC usually minimum of 2 ms
1452838Sdg * nd  - no DMA flag; PC usually not set (0)
1462838Sdg */
1472838Sdg
148162165Sjkim#define NE7_SPEC_1(srt, hut)	(((16 - (srt)) << 4) | (((hut) / 16)))
149162165Sjkim#define NE7_SPEC_2(hlt, nd)	(((hlt) & 0xFE) | ((nd) & 1))
150