xref: /freebsd/sys/dev/ic/nec765.h (revision 29363fb446372cb3f10bc98664e9767c53fbb457)
15b81b6b3SRodney W. Grimes /*-
2*7282444bSPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*7282444bSPedro F. Giffuni  *
45b81b6b3SRodney W. Grimes  * Copyright (c) 1991 The Regents of the University of California.
55b81b6b3SRodney W. Grimes  * All rights reserved.
65b81b6b3SRodney W. Grimes  *
75b81b6b3SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
85b81b6b3SRodney W. Grimes  * modification, are permitted provided that the following conditions
95b81b6b3SRodney W. Grimes  * are met:
105b81b6b3SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
115b81b6b3SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
125b81b6b3SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
135b81b6b3SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
145b81b6b3SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
15fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
165b81b6b3SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
175b81b6b3SRodney W. Grimes  *    without specific prior written permission.
185b81b6b3SRodney W. Grimes  *
195b81b6b3SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
205b81b6b3SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
215b81b6b3SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
225b81b6b3SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
235b81b6b3SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
245b81b6b3SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
255b81b6b3SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
265b81b6b3SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
275b81b6b3SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
285b81b6b3SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
295b81b6b3SRodney W. Grimes  * SUCH DAMAGE.
305b81b6b3SRodney W. Grimes  */
315b81b6b3SRodney W. Grimes 
325b81b6b3SRodney W. Grimes /*
335b81b6b3SRodney W. Grimes  * Nec 765 floppy disc controller definitions
345b81b6b3SRodney W. Grimes  */
355b81b6b3SRodney W. Grimes 
365b81b6b3SRodney W. Grimes /* Main status register */
375b81b6b3SRodney W. Grimes #define NE7_DAB		0x01	/* Diskette drive A is seeking, thus busy */
385b81b6b3SRodney W. Grimes #define NE7_DBB		0x02	/* Diskette drive B is seeking, thus busy */
395b81b6b3SRodney W. Grimes #define NE7_CB		0x10	/* Diskette Controller Busy */
405b81b6b3SRodney W. Grimes #define NE7_NDM		0x20	/* Diskette Controller in Non Dma Mode */
415b81b6b3SRodney W. Grimes #define NE7_DIO		0x40	/* Diskette Controller Data register I/O */
425b81b6b3SRodney W. Grimes #define NE7_RQM		0x80	/* Diskette Controller ReQuest for Master */
435b81b6b3SRodney W. Grimes 
445b81b6b3SRodney W. Grimes /* Status register ST0 */
453a2f7427SDavid Greenman #define NE7_ST0BITS	"\020\010invld\007abnrml\006seek_cmplt\005equ_chck\004drive_notrdy\003top_head"
463a2f7427SDavid Greenman 
473a2f7427SDavid Greenman #define NE7_ST0_IC	0xc0	/* interrupt completion code */
483a2f7427SDavid Greenman 
493a2f7427SDavid Greenman #define NE7_ST0_IC_RC	0xc0	/* terminated due to ready changed, n/a */
503a2f7427SDavid Greenman #define NE7_ST0_IC_IV	0x80	/* invalid command; must reset FDC */
513a2f7427SDavid Greenman #define NE7_ST0_IC_AT	0x40	/* abnormal termination, check error stat */
523a2f7427SDavid Greenman #define NE7_ST0_IC_NT	0x00	/* normal termination */
533a2f7427SDavid Greenman 
543a2f7427SDavid Greenman #define NE7_ST0_SE	0x20	/* seek end */
553a2f7427SDavid Greenman #define NE7_ST0_EC	0x10	/* equipment check, recalibrated but no trk0 */
563a2f7427SDavid Greenman #define NE7_ST0_NR	0x08	/* not ready (n/a) */
573a2f7427SDavid Greenman #define NE7_ST0_HD	0x04	/* upper head selected */
583a2f7427SDavid Greenman #define NE7_ST0_DR	0x03	/* drive code */
595b81b6b3SRodney W. Grimes 
605b81b6b3SRodney W. Grimes /* Status register ST1 */
615b81b6b3SRodney W. Grimes #define NE7_ST1BITS	"\020\010end_of_cyl\006bad_crc\005data_overrun\003sec_not_fnd\002write_protect\001no_am"
625b81b6b3SRodney W. Grimes 
633a2f7427SDavid Greenman #define NE7_ST1_EN	0x80	/* end of cylinder, access past last record */
643a2f7427SDavid Greenman #define NE7_ST1_DE	0x20	/* data error, CRC fail in ID or data */
653a2f7427SDavid Greenman #define NE7_ST1_OR	0x10	/* DMA overrun, DMA failed to do i/o quickly */
663a2f7427SDavid Greenman #define NE7_ST1_ND	0x04	/* no data, sector not found or CRC in ID f. */
673a2f7427SDavid Greenman #define NE7_ST1_NW	0x02	/* not writeable, attempt to violate WP */
683a2f7427SDavid Greenman #define NE7_ST1_MA	0x01	/* missing address mark (in ID or data field)*/
693a2f7427SDavid Greenman 
705b81b6b3SRodney W. Grimes /* Status register ST2 */
715b81b6b3SRodney W. Grimes #define NE7_ST2BITS	"\020\007ctrl_mrk\006bad_crc\005wrong_cyl\004scn_eq\003scn_not_fnd\002bad_cyl\001no_dam"
725b81b6b3SRodney W. Grimes 
733a2f7427SDavid Greenman #define NE7_ST2_CM	0x40	/* control mark; found deleted data */
743a2f7427SDavid Greenman #define NE7_ST2_DD	0x20	/* data error in data field, CRC fail */
753a2f7427SDavid Greenman #define NE7_ST2_WC	0x10	/* wrong cylinder, ID field mismatches cmd */
763a2f7427SDavid Greenman #define NE7_ST2_SH	0x08	/* scan equal hit */
773a2f7427SDavid Greenman #define NE7_ST2_SN	0x04	/* scan not satisfied */
783a2f7427SDavid Greenman #define NE7_ST2_BC	0x02	/* bad cylinder, cylinder marked 0xff */
793a2f7427SDavid Greenman #define NE7_ST2_MD	0x01	/* missing address mark in data field */
803a2f7427SDavid Greenman 
815b81b6b3SRodney W. Grimes /* Status register ST3 */
825b81b6b3SRodney W. Grimes #define NE7_ST3BITS	"\020\010fault\007write_protect\006drdy\005tk0\004two_side\003side_sel\002"
835b81b6b3SRodney W. Grimes 
843a2f7427SDavid Greenman #define NE7_ST3_FT	0x80	/* fault; PC: n/a */
853a2f7427SDavid Greenman #define NE7_ST3_WP	0x40	/* write protected */
863a2f7427SDavid Greenman #define NE7_ST3_RD	0x20	/* ready; PC: always true */
873a2f7427SDavid Greenman #define NE7_ST3_T0	0x10	/* track 0 */
883a2f7427SDavid Greenman #define NE7_ST3_TS	0x08	/* two-sided; PC: n/a */
893a2f7427SDavid Greenman #define NE7_ST3_HD	0x04	/* upper head select */
903a2f7427SDavid Greenman #define NE7_ST3_US	0x03	/* unit select */
913a2f7427SDavid Greenman 
9250d99d1aSJung-uk Kim /* Data Rate Select Register DSR (enhanced controller) */
9350d99d1aSJung-uk Kim #define I8207X_DSR_SR	0x80	/* software reset */
9450d99d1aSJung-uk Kim #define I8207X_DSR_LP	0x40	/* low power */
9550d99d1aSJung-uk Kim #define I8207X_DSR_PS	0x1c	/* precompensation select */
9650d99d1aSJung-uk Kim #define I8207X_DSR_RS	0x03	/* data rate select */
9750d99d1aSJung-uk Kim 
985b81b6b3SRodney W. Grimes /* Commands */
993a2f7427SDavid Greenman /*
1003a2f7427SDavid Greenman  * the top three bits -- where appropriate -- are set as follows:
1013a2f7427SDavid Greenman  *
10294896f7bSJoerg Wunsch  * MT  - multi-track; allow both sides to be handled in single cmd
10394896f7bSJoerg Wunsch  * MFM - modified frequency modulation; use MFM encoding
10494896f7bSJoerg Wunsch  * SK  - skip; skip sectors marked as "deleted"
1053a2f7427SDavid Greenman  */
10694896f7bSJoerg Wunsch 
10794896f7bSJoerg Wunsch #define NE7CMD_MT	0x80	/* READ, WRITE, WRITEDEL, READDEL, SCAN* */
10894896f7bSJoerg Wunsch #define NE7CMD_MFM	0x40	/* same as MT, plus READTRK, READID, FORMAT */
10994896f7bSJoerg Wunsch #define NE7CMD_SK	0x20	/* READ, READDEL, SCAN* */
11094896f7bSJoerg Wunsch 
1110da90eb8SJung-uk Kim #define NE7CMD_READTRK	0x02	/*  read whole track */
1120da90eb8SJung-uk Kim #define NE7CMD_SPECIFY	0x03	/*  specify drive parameters - requires unit
11394896f7bSJoerg Wunsch 				 *  parameters byte */
1140da90eb8SJung-uk Kim #define NE7CMD_SENSED	0x04	/*  sense drive - requires unit select byte */
1150da90eb8SJung-uk Kim #define NE7CMD_WRITE	0x05	/*  write - requires eight additional bytes */
1160da90eb8SJung-uk Kim #define NE7CMD_READ	0x06	/*  read - requires eight additional bytes */
1170da90eb8SJung-uk Kim #define NE7CMD_RECAL	0x07	/*  recalibrate drive - requires
11894896f7bSJoerg Wunsch 				 *  unit select byte */
1190da90eb8SJung-uk Kim #define NE7CMD_SENSEI	0x08	/*  sense controller interrupt status */
1200da90eb8SJung-uk Kim #define NE7CMD_WRITEDEL	0x09	/*  write deleted data */
1210da90eb8SJung-uk Kim #define NE7CMD_READID	0x0a	/*  read ID field */
1220da90eb8SJung-uk Kim #define NE7CMD_READDEL	0x0c	/*  read deleted data */
1230da90eb8SJung-uk Kim #define NE7CMD_FORMAT	0x0d	/*  format - requires five additional bytes */
1240da90eb8SJung-uk Kim #define NE7CMD_SEEK	0x0f	/*  seek drive - requires unit select byte
12594896f7bSJoerg Wunsch 				 *  and new cyl byte */
1260da90eb8SJung-uk Kim #define NE7CMD_VERSION	0x10	/*  get version */
12794896f7bSJoerg Wunsch #define NE7CMD_SCNEQU	0x11	/*  scan equal */
12894896f7bSJoerg Wunsch #define NE7CMD_SCNLE	0x19	/*  scan less or equal */
12994896f7bSJoerg Wunsch #define NE7CMD_SCNGE	0x1d	/*  scan greater or equal */
1303a2f7427SDavid Greenman 
131dc5df763SJoerg Wunsch /*
132dc5df763SJoerg Wunsch  * Enhanced controller commands:
133dc5df763SJoerg Wunsch  */
1340da90eb8SJung-uk Kim #define I8207X_DUMPREG	0x0e	/*  dump internal registers */
1350da90eb8SJung-uk Kim #define I8207X_CONFIG	0x13	/*  configure enhanced features */
1363a2f7427SDavid Greenman 
1373a2f7427SDavid Greenman /*
1383a2f7427SDavid Greenman  * "specify" definitions
1393a2f7427SDavid Greenman  *
1403a2f7427SDavid Greenman  * acronyms (times are relative to a FDC clock of 8 MHz):
1413a2f7427SDavid Greenman  * srt - step rate; PC usually 3 ms
1423a2f7427SDavid Greenman  * hut - head unload time; PC usually maximum of 240 ms
1433a2f7427SDavid Greenman  * hlt - head load time; PC usually minimum of 2 ms
1443a2f7427SDavid Greenman  * nd  - no DMA flag; PC usually not set (0)
1453a2f7427SDavid Greenman  */
1463a2f7427SDavid Greenman 
1473a2f7427SDavid Greenman #define NE7_SPEC_1(srt, hut)	(((16 - (srt)) << 4) | (((hut) / 16)))
1483a2f7427SDavid Greenman #define NE7_SPEC_2(hlt, nd)	(((hlt) & 0xFE) | ((nd) & 1))
149