1/*	$NetBSD: mcdreg.h,v 1.8 1997/04/04 18:59:37 christos Exp $	*/
2
3/*
4 * Copyright 1993 by Holger Veit (data part)
5 * Copyright 1993 by Brian Moore (audio part)
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *	This software was developed by Holger Veit and Brian Moore
19 *      for use with "386BSD" and similar operating systems.
20 *    "Similar operating systems" includes mainly non-profit oriented
21 *    systems for research and education, including but not restricted to
22 *    "NetBSD", "FreeBSD", "Mach" (by CMU).
23 * 4. Neither the name of the developer(s) nor the name "386BSD"
24 *    may be used to endorse or promote products derived from this
25 *    software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER(S) ``AS IS'' AND ANY
28 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE DEVELOPER(S) BE
31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
32 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
33 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
34 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *
39 * This file contains definitions for some cdrom control commands
40 * and status codes. This info was "inherited" from the DOS MTMCDE.SYS
41 * driver, and is thus not complete (and may even be wrong). Some day
42 * the manufacturer or anyone else might provide better documentation,
43 * so this file (and the driver) will then have a better quality.
44 */
45
46#if __GNUC__ >= 2
47#pragma pack(1)
48#endif
49
50typedef unsigned char	bcd_t;
51#define	M_msf(msf)	msf[0]
52#define	S_msf(msf)	msf[1]
53#define	F_msf(msf)	msf[2]
54
55#define	MCD_COMMAND	0
56#define	MCD_STATUS	0
57#define	MCD_RDATA	0
58#define	MCD_RESET	1
59#define	MCD_XFER	1
60#define	MCD_CTL2	2 /* XXX Is this right? */
61#define	MCD_CONFIG	3
62#define MCD_NPORT	4
63
64#define	MCD_MASK_DMA	0x07	/* bits 2-0 = DMA channel */
65#define	MCD_MASK_IRQ	0x70	/* bits 6-4 = INT number */
66				/* 001 = int 2,9 */
67				/* 010 = int 3 */
68				/* 011 = int 5 */
69				/* 100 = int 10 */
70				/* 101 = int 11 */
71
72/* Status bits */
73#define	MCD_ST_DOOROPEN		0x80
74#define	MCD_ST_DSKIN		0x40
75#define	MCD_ST_DSKCHNG		0x20
76#define	MCD_ST_SPINNING		0x10
77#define	MCD_ST_AUDIODISK	0x08	/* audio disk is in */
78#define	MCD_ST_READERR		0x04
79#define	MCD_ST_AUDIOBSY		0x02	/* audio disk is playing */
80#define	MCD_ST_CMDCHECK		0x01	/* command error */
81
82/* Xfer bits */
83#define	MCD_XF_STATUSUNAVAIL	0x04
84#define	MCD_XF_DATAUNAVAIL	0x02
85
86/* Modes */
87#define	MCD_MD_TESTMODE		0x80	/* 0 = DATALENGTH is valid */
88#define	MCD_MD_DATALENGTH	0x40	/* 1 = read ECC data also */
89#define	MCD_MD_ECCMODE		0x20	/* 1 = disable secondary ECC */
90#define	MCD_MD_SPINDOWN		0x08	/* 1 = spin down */
91#define	MCD_MD_READTOC		0x04	/* 1 = read TOC on GETQCHN */
92#define	MCD_MD_PLAYAUDIO	0x01	/* 1 = play audio through headphones */
93
94#define	MCD_MD_RAW		(MCD_MD_PLAYAUDIO|MCD_MD_ECCMODE|MCD_MD_DATALENGTH)
95#define	MCD_MD_COOKED		(MCD_MD_PLAYAUDIO)
96#define	MCD_MD_TOC		(MCD_MD_PLAYAUDIO|MCD_MD_READTOC)
97#define	MCD_MD_SLEEP		(MCD_MD_PLAYAUDIO|MCD_MD_SPINDOWN)
98
99#define	MCD_BLKSIZE_RAW		sizeof(struct mcd_rawsector)
100#define	MCD_BLKSIZE_COOKED	2048
101
102/* Lock states */
103#define	MCD_LK_UNLOCK		0x00
104#define	MCD_LK_LOCK		0x01
105#define	MCD_LK_TEST		0x02
106
107/* Config commands */
108#define	MCD_CF_IRQENABLE	0x10
109#define	MCD_CF_DMATIMEOUT	0x08
110#define	MCD_CF_READUPC		0x04
111#define	MCD_CF_DMAENABLE	0x02
112#define	MCD_CF_BLOCKSIZE	0x01
113
114/* UPC subcommands */
115#define	MCD_UPC_DISABLE		0x00
116#define	MCD_UPC_ENABLE		0x01
117
118/* commands known by the controller */
119#define	MCD_CMDRESET		0x00
120#define	MCD_CMDGETVOLINFO	0x10	/* gets mcd_volinfo */
121#define	MCD_CMDGETDISKINFO	0x11	/* gets mcd_disk */
122#define	MCD_CMDGETQCHN		0x20	/* gets mcd_qchninfo */
123#define	MCD_CMDGETSENSE		0x30	/* gets sense info */
124#define	MCD_CMDGETSTAT		0x40	/* gets a byte of status */
125#define	MCD_CMDSETMODE		0x50	/* set transmission mode, needs byte */
126#define	MCD_CMDSTOPAUDIO	0x70
127#define	MCD_CMDSTOPAUDIOTIME	0x80
128#define	MCD_CMDGETVOLUME	0x8E	/* gets mcd_volume */
129#define	MCD_CMDCONFIGDRIVE	0x90
130#define	MCD_CMDSETDRIVEMODE	0xa0	/* set drive mode */
131#define	MCD_CMDSETVOLUME	0xae	/* sets mcd_volume */
132#define	MCD_CMDREAD1		0xb0	/* read n sectors */
133#define	MCD_CMDREADSINGLESPEED	0xc0	/* read (single speed) */
134#define	MCD_CMDREADDOUBLESPEED	0xc1	/* read (double speed) */
135#define	MCD_CMDGETDRIVEMODE	0xc2	/* get drive mode */
136#define	MCD_CMDREAD3		0xc3	/* ? */
137#define	MCD_CMDSETINTERLEAVE	0xc8	/* set interleave for read */
138#define	MCD_CMDCONTINFO		0xdc	/* get controller info */
139#define	MCD_CMDSTOP		0xf0	/* stop everything */
140#define	MCD_CMDEJECTDISK	0xf6
141#define	MCD_CMDCLOSETRAY	0xf8
142#define	MCD_CMDSETLOCK		0xfe	/* needs byte */
143
144union mcd_qchninfo {
145	struct {
146		u_char	control:4;
147		u_char	addr_type:4;
148		u_char	trk_no;
149		u_char	idx_no;
150		bcd_t	track_size[3];
151		u_char	:8;
152		bcd_t	absolute_pos[3];
153	} toc;
154	struct {
155		u_char	control:4;
156		u_char	addr_type:4;
157		u_char	trk_no;
158		u_char	idx_no;
159		bcd_t	relative_pos[3];
160		u_char	:8;
161		bcd_t	absolute_pos[3];
162	} current;
163	struct {
164		u_char	control:4;
165		u_char	addr_type:4;
166		u_char	upccode[7];
167		u_char	junk[2];
168	} upc;
169};
170
171struct mcd_volinfo {
172	bcd_t	trk_low;
173	bcd_t	trk_high;
174	bcd_t	vol_msf[3];
175	bcd_t	trk1_msf[3];
176};
177
178struct mcd_result {
179	u_char	length;
180	union {
181		struct {
182			u_char	data[1];
183		} raw;
184		struct {
185			u_char	code;
186			u_char	version;
187		} continfo;
188		union mcd_qchninfo qchninfo;
189		struct mcd_volinfo volinfo;
190	} data;
191};
192
193struct mcd_command {
194	u_char	opcode;
195	u_char	length;
196	union {
197		struct {
198			u_char	data[1];
199		} raw;
200		struct {
201			bcd_t	start_msf[3];
202			bcd_t	reserved[3];
203		} seek;
204		struct {
205			bcd_t	start_msf[3];
206			bcd_t	length[3];
207		} read;
208		struct {
209			bcd_t	start_msf[3];
210			bcd_t	end_msf[3];
211		} play;
212		struct {
213			u_char	mode;
214		} datamode;
215		struct {
216			u_char	time;
217		} hold;
218		struct {
219			u_char	mode;
220		} drivemode;
221		struct {
222			u_char	mode;
223		} lockmode;
224		struct {
225			u_char	subcommand;
226			u_char	data1, data2;
227		} config;
228	} data;
229};
230
231struct mcd_mbox {
232	struct mcd_command cmd;
233	struct mcd_result res;
234};
235
236struct mcd_volume {
237	u_char	v0l;
238	u_char	v0rs;
239	u_char	v0r;
240	u_char	v0ls;
241};
242
243struct mcd_rawsector {
244	u_char	sync1[12];
245	u_char	header[4];
246	u_char	subheader1[4];
247	u_char	subheader2[4];
248	u_char	data[MCD_BLKSIZE_COOKED];
249	u_char	ecc_bits[280];
250};
251
252#if __GNUC__ >= 2
253#pragma pack()
254#endif
255