ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / cdrom / cdu31a.h
1 /*
2  * Definitions for a Sony interface CDROM drive.
3  *
4  * Corey Minyard (minyard@wf-rch.cirr.com)
5  *
6  *  Copyright (C) 1993  Corey Minyard
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */
23
24 /*
25  * General defines.
26  */
27 #define SONY_XA_DISK_TYPE 0x20
28
29 /*
30  * Offsets (from the base address) and bits for the various write registers
31  * of the drive.
32  */
33 #define SONY_CMD_REG_OFFSET     0
34 #define SONY_PARAM_REG_OFFSET   1
35 #define SONY_WRITE_REG_OFFSET   2
36 #define SONY_CONTROL_REG_OFFSET 3
37 #       define SONY_ATTN_CLR_BIT        0x01
38 #       define SONY_RES_RDY_CLR_BIT     0x02
39 #       define SONY_DATA_RDY_CLR_BIT    0x04
40 #       define SONY_ATTN_INT_EN_BIT     0x08
41 #       define SONY_RES_RDY_INT_EN_BIT  0x10
42 #       define SONY_DATA_RDY_INT_EN_BIT 0x20
43 #       define SONY_PARAM_CLR_BIT       0x40
44 #       define SONY_DRIVE_RESET_BIT     0x80
45
46 /*
47  * Offsets (from the base address) and bits for the various read registers
48  * of the drive.
49  */
50 #define SONY_STATUS_REG_OFFSET  0
51 #       define SONY_ATTN_BIT            0x01
52 #       define SONY_RES_RDY_BIT         0x02
53 #       define SONY_DATA_RDY_BIT        0x04
54 #       define SONY_ATTN_INT_ST_BIT     0x08
55 #       define SONY_RES_RDY_INT_ST_BIT  0x10
56 #       define SONY_DATA_RDY_INT_ST_BIT 0x20
57 #       define SONY_DATA_REQUEST_BIT    0x40
58 #       define SONY_BUSY_BIT            0x80
59 #define SONY_RESULT_REG_OFFSET  1
60 #define SONY_READ_REG_OFFSET    2
61 #define SONY_FIFOST_REG_OFFSET  3
62 #       define SONY_PARAM_WRITE_RDY_BIT 0x01
63 #       define SONY_PARAM_REG_EMPTY_BIT 0x02
64 #       define SONY_RES_REG_NOT_EMP_BIT 0x04
65 #       define SONY_RES_REG_FULL_BIT    0x08
66
67 #define LOG_START_OFFSET        150     /* Offset of first logical sector */
68
69 #define SONY_DETECT_TIMEOUT     (8*HZ/10) /* Maximum amount of time
70                                            that drive detection code
71                                            will wait for response
72                                            from drive (in 1/100th's
73                                            of seconds). */
74  
75 #define SONY_JIFFIES_TIMEOUT    1000    /* Maximum number of times the
76                                            drive will wait/try for an
77                                            operation */
78 #define SONY_RESET_TIMEOUT      100     /* Maximum number of times the
79                                            drive will wait/try a reset
80                                            operation */
81 #define SONY_READY_RETRIES      20000   /* How many times to retry a
82                                            spin waiting for a register
83                                            to come ready */
84
85 #define MAX_CDU31A_RETRIES      3       /* How many times to retry an
86                                            operation */
87
88 /* Commands to request or set drive control parameters and disc information */
89 #define SONY_REQ_DRIVE_CONFIG_CMD       0x00    /* Returns s_sony_drive_config */
90 #define SONY_REQ_DRIVE_MODE_CMD         0x01
91 #define SONY_REQ_DRIVE_PARAM_CMD        0x02
92 #define SONY_REQ_MECH_STATUS_CMD        0x03
93 #define SONY_REQ_AUDIO_STATUS_CMD       0x04
94 #define SONY_SET_DRIVE_PARAM_CMD        0x10
95 #define SONY_REQ_TOC_DATA_CMD           0x20    /* Returns s_sony_toc */
96 #define SONY_REQ_SUBCODE_ADDRESS_CMD    0x21    /* Returns s_sony_subcode */
97 #define SONY_REQ_UPC_EAN_CMD            0x22
98 #define SONY_REQ_ISRC_CMD               0x23
99 #define SONY_REQ_TOC_DATA_SPEC_CMD      0x24    /* Returns s_sony_session_toc */
100
101 /* Commands to request information from the drive */
102 #define SONY_READ_TOC_CMD               0x30    /* let the drive firmware grab the TOC */
103 #define SONY_SEEK_CMD                   0x31
104 #define SONY_READ_CMD                   0x32
105 #define SONY_READ_BLKERR_STAT_CMD       0x34
106 #define SONY_ABORT_CMD                  0x35
107 #define SONY_READ_TOC_SPEC_CMD          0x36
108
109 /* Commands to control audio */
110 #define SONY_AUDIO_PLAYBACK_CMD         0x40
111 #define SONY_AUDIO_STOP_CMD             0x41
112 #define SONY_AUDIO_SCAN_CMD             0x42
113
114 /* Miscellaneous control commands */
115 #define SONY_EJECT_CMD                  0x50
116 #define SONY_SPIN_UP_CMD                0x51
117 #define SONY_SPIN_DOWN_CMD              0x52
118
119 /* Diagnostic commands */
120 #define SONY_WRITE_BUFFER_CMD           0x60
121 #define SONY_READ_BUFFER_CMD            0x61
122 #define SONY_DIAGNOSTICS_CMD            0x62
123
124
125 /*
126  * The following are command parameters for the set drive parameter command
127  */
128 #define SONY_SD_DECODE_PARAM            0x00
129 #define SONY_SD_INTERFACE_PARAM         0x01
130 #define SONY_SD_BUFFERING_PARAM         0x02
131 #define SONY_SD_AUDIO_PARAM             0x03
132 #define SONY_SD_AUDIO_VOLUME            0x04
133 #define SONY_SD_MECH_CONTROL            0x05
134 #define SONY_SD_AUTO_SPIN_DOWN_TIME     0x06
135
136 /*
137  * The following are parameter bits for the mechanical control command
138  */
139 #define SONY_AUTO_SPIN_UP_BIT           0x01
140 #define SONY_AUTO_EJECT_BIT             0x02
141 #define SONY_DOUBLE_SPEED_BIT           0x04
142
143 /*
144  * The following extract information from the drive configuration about
145  * the drive itself.
146  */
147 #define SONY_HWC_GET_LOAD_MECH(c)       (c.hw_config[0] & 0x03)
148 #define SONY_HWC_EJECT(c)               (c.hw_config[0] & 0x04)
149 #define SONY_HWC_LED_SUPPORT(c)         (c.hw_config[0] & 0x08)
150 #define SONY_HWC_DOUBLE_SPEED(c)        (c.hw_config[0] & 0x10)
151 #define SONY_HWC_GET_BUF_MEM_SIZE(c)    ((c.hw_config[0] & 0xc0) >> 6)
152 #define SONY_HWC_AUDIO_PLAYBACK(c)      (c.hw_config[1] & 0x01)
153 #define SONY_HWC_ELECTRIC_VOLUME(c)     (c.hw_config[1] & 0x02)
154 #define SONY_HWC_ELECTRIC_VOLUME_CTL(c) (c.hw_config[1] & 0x04)
155
156 #define SONY_HWC_CADDY_LOAD_MECH        0x00
157 #define SONY_HWC_TRAY_LOAD_MECH         0x01
158 #define SONY_HWC_POPUP_LOAD_MECH        0x02
159 #define SONY_HWC_UNKWN_LOAD_MECH        0x03
160
161 #define SONY_HWC_8KB_BUFFER             0x00
162 #define SONY_HWC_32KB_BUFFER            0x01
163 #define SONY_HWC_64KB_BUFFER            0x02
164 #define SONY_HWC_UNKWN_BUFFER           0x03
165
166 /*
167  * This is the complete status returned from the drive configuration request
168  * command.
169  */
170 struct s_sony_drive_config
171 {
172    unsigned char exec_status[2];
173    char vendor_id[8];
174    char product_id[16];
175    char product_rev_level[8];
176    unsigned char hw_config[2];
177 };
178
179 /* The following is returned from the request subcode address command */
180 struct s_sony_subcode
181 {
182    unsigned char exec_status[2];
183    unsigned char address        :4;
184    unsigned char control        :4;
185    unsigned char track_num;
186    unsigned char index_num;
187    unsigned char rel_msf[3];
188    unsigned char reserved1;
189    unsigned char abs_msf[3];
190 };
191
192 #define MAX_TRACKS 100  /* The maximum tracks a disk may have. */
193 /*
194  * The following is returned from the request TOC (Table Of Contents) command.
195  * (last_track_num-first_track_num+1) values are valid in tracks.
196  */
197 struct s_sony_toc
198 {
199    unsigned char exec_status[2];
200    unsigned char address0       :4;
201    unsigned char control0       :4;
202    unsigned char point0;
203    unsigned char first_track_num;
204    unsigned char disk_type;
205    unsigned char dummy0;
206    unsigned char address1       :4;
207    unsigned char control1       :4;
208    unsigned char point1;
209    unsigned char last_track_num;
210    unsigned char dummy1;
211    unsigned char dummy2;
212    unsigned char address2       :4;
213    unsigned char control2       :4;
214    unsigned char point2;
215    unsigned char lead_out_start_msf[3];
216    struct
217    {
218       unsigned char address     :4;
219       unsigned char control     :4;
220       unsigned char track;
221       unsigned char track_start_msf[3];
222    } tracks[MAX_TRACKS];
223
224    unsigned int lead_out_start_lba;
225 };
226
227 struct s_sony_session_toc
228 {
229    unsigned char exec_status[2];
230    unsigned char session_number;
231    unsigned char address0       :4;
232    unsigned char control0       :4;
233    unsigned char point0;
234    unsigned char first_track_num;
235    unsigned char disk_type;
236    unsigned char dummy0;
237    unsigned char address1       :4;
238    unsigned char control1       :4;
239    unsigned char point1;
240    unsigned char last_track_num;
241    unsigned char dummy1;
242    unsigned char dummy2;
243    unsigned char address2       :4;
244    unsigned char control2       :4;
245    unsigned char point2;
246    unsigned char lead_out_start_msf[3];
247    unsigned char addressb0      :4;
248    unsigned char controlb0      :4;
249    unsigned char pointb0;
250    unsigned char next_poss_prog_area_msf[3];
251    unsigned char num_mode_5_pointers;
252    unsigned char max_start_outer_leadout_msf[3];
253    unsigned char addressb1      :4;
254    unsigned char controlb1      :4;
255    unsigned char pointb1;
256    unsigned char dummyb0_1[4];
257    unsigned char num_skip_interval_pointers;
258    unsigned char num_skip_track_assignments;
259    unsigned char dummyb0_2;
260    unsigned char addressb2      :4;
261    unsigned char controlb2      :4;
262    unsigned char pointb2;
263    unsigned char tracksb2[7];
264    unsigned char addressb3      :4;
265    unsigned char controlb3      :4;
266    unsigned char pointb3;
267    unsigned char tracksb3[7];
268    unsigned char addressb4      :4;
269    unsigned char controlb4      :4;
270    unsigned char pointb4;
271    unsigned char tracksb4[7];
272    unsigned char addressc0      :4;
273    unsigned char controlc0      :4;
274    unsigned char pointc0;
275    unsigned char dummyc0[7];
276    struct
277    {
278       unsigned char address     :4;
279       unsigned char control     :4;
280       unsigned char track;
281       unsigned char track_start_msf[3];
282    } tracks[MAX_TRACKS];
283
284    unsigned int start_track_lba;
285    unsigned int lead_out_start_lba;
286    unsigned int mint;
287    unsigned int maxt;
288 };
289
290 struct s_all_sessions_toc
291 {
292    unsigned char sessions;
293    unsigned int track_entries;
294    unsigned char first_track_num;
295    unsigned char last_track_num;
296    unsigned char disk_type;
297    unsigned char lead_out_start_msf[3];
298    struct
299    {
300       unsigned char address     :4;
301       unsigned char control     :4;
302       unsigned char track;
303       unsigned char track_start_msf[3];
304    } tracks[MAX_TRACKS];
305
306    unsigned int start_track_lba;
307    unsigned int lead_out_start_lba;
308 };
309
310
311 /*
312  * The following are errors returned from the drive.
313  */
314
315 /* Command error group */
316 #define SONY_ILL_CMD_ERR                0x10
317 #define SONY_ILL_PARAM_ERR              0x11
318
319 /* Mechanism group */
320 #define SONY_NOT_LOAD_ERR               0x20
321 #define SONY_NO_DISK_ERR                0x21
322 #define SONY_NOT_SPIN_ERR               0x22
323 #define SONY_SPIN_ERR                   0x23
324 #define SONY_SPINDLE_SERVO_ERR          0x25
325 #define SONY_FOCUS_SERVO_ERR            0x26
326 #define SONY_EJECT_MECH_ERR             0x29
327 #define SONY_AUDIO_PLAYING_ERR          0x2a
328 #define SONY_EMERGENCY_EJECT_ERR        0x2c
329
330 /* Seek error group */
331 #define SONY_FOCUS_ERR                  0x30
332 #define SONY_FRAME_SYNC_ERR             0x31
333 #define SONY_SUBCODE_ADDR_ERR           0x32
334 #define SONY_BLOCK_SYNC_ERR             0x33
335 #define SONY_HEADER_ADDR_ERR            0x34
336
337 /* Read error group */
338 #define SONY_ILL_TRACK_R_ERR            0x40
339 #define SONY_MODE_0_R_ERR               0x41
340 #define SONY_ILL_MODE_R_ERR             0x42
341 #define SONY_ILL_BLOCK_SIZE_R_ERR       0x43
342 #define SONY_MODE_R_ERR                 0x44
343 #define SONY_FORM_R_ERR                 0x45
344 #define SONY_LEAD_OUT_R_ERR             0x46
345 #define SONY_BUFFER_OVERRUN_R_ERR       0x47
346
347 /* Data error group */
348 #define SONY_UNREC_CIRC_ERR             0x53
349 #define SONY_UNREC_LECC_ERR             0x57
350
351 /* Subcode error group */
352 #define SONY_NO_TOC_ERR                 0x60
353 #define SONY_SUBCODE_DATA_NVAL_ERR      0x61
354 #define SONY_FOCUS_ON_TOC_READ_ERR      0x63
355 #define SONY_FRAME_SYNC_ON_TOC_READ_ERR 0x64
356 #define SONY_TOC_DATA_ERR               0x65
357
358 /* Hardware failure group */
359 #define SONY_HW_FAILURE_ERR             0x70
360 #define SONY_LEAD_IN_A_ERR              0x91
361 #define SONY_LEAD_OUT_A_ERR             0x92
362 #define SONY_DATA_TRACK_A_ERR           0x93
363
364 /*
365  * The following are returned from the Read With Block Error Status command.
366  * They are not errors but information (Errors from the 0x5x group above may
367  * also be returned
368  */
369 #define SONY_NO_CIRC_ERR_BLK_STAT       0x50
370 #define SONY_NO_LECC_ERR_BLK_STAT       0x54
371 #define SONY_RECOV_LECC_ERR_BLK_STAT    0x55
372 #define SONY_NO_ERR_DETECTION_STAT      0x59
373
374 /* 
375  * The following is not an error returned by the drive, but by the code
376  * that talks to the drive.  It is returned because of a timeout.
377  */
378 #define SONY_TIMEOUT_OP_ERR             0x01
379 #define SONY_SIGNAL_OP_ERR              0x02
380 #define SONY_BAD_DATA_ERR               0x03
381
382
383 /*
384  * The following are attention code for asynchronous events from the drive.
385  */
386
387 /* Standard attention group */
388 #define SONY_EMER_EJECT_ATTN            0x2c
389 #define SONY_HW_FAILURE_ATTN            0x70
390 #define SONY_MECH_LOADED_ATTN           0x80
391 #define SONY_EJECT_PUSHED_ATTN          0x81
392
393 /* Audio attention group */
394 #define SONY_AUDIO_PLAY_DONE_ATTN       0x90
395 #define SONY_LEAD_IN_ERR_ATTN           0x91
396 #define SONY_LEAD_OUT_ERR_ATTN          0x92
397 #define SONY_DATA_TRACK_ERR_ATTN        0x93
398 #define SONY_AUDIO_PLAYBACK_ERR_ATTN    0x94
399
400 /* Auto spin up group */
401 #define SONY_SPIN_UP_COMPLETE_ATTN      0x24
402 #define SONY_SPINDLE_SERVO_ERR_ATTN     0x25
403 #define SONY_FOCUS_SERVO_ERR_ATTN       0x26
404 #define SONY_TOC_READ_DONE_ATTN         0x62
405 #define SONY_FOCUS_ON_TOC_READ_ERR_ATTN 0x63
406 #define SONY_SYNC_ON_TOC_READ_ERR_ATTN  0x65
407
408 /* Auto eject group */
409 #define SONY_SPIN_DOWN_COMPLETE_ATTN    0x27
410 #define SONY_EJECT_COMPLETE_ATTN        0x28
411 #define SONY_EJECT_MECH_ERR_ATTN        0x29