This source file includes following definitions.
- msg
- sbpcd_dbg_ioctl
- mark_timeout_delay
- mark_timeout_data
- mark_timeout_audio
- sbp_sleep
- lba2msf
- bin2bcdx
- blk2msf
- make16
- make32
- swap_nibbles
- byt2bcd
- bcd2bin
- msf2blk
- msf2lba
- sta2err
- clr_cmdbuf
- flush_status
- CDi_stat_loop
- tst_DataReady
- tst_ResultReady
- tst_Attention
- ResponseInfo
- EvaluateStatus
- get_state_T
- ResponseStatus
- cc_ReadStatus
- cc_ReadError
- cmd_out_T
- cmd_out
- cc_Seek
- cc_SpinUp
- cc_SpinDown
- cc_get_mode_T
- cc_set_mode_T
- cc_prep_mode_T
- cc_SetSpeed
- cc_SetVolume
- GetStatus
- cc_DriveReset
- SetSpeed
- DriveReset
- cc_PlayAudio
- cc_Pause_Resume
- cc_LockDoor
- UnLockDoor
- LockDoor
- cc_CloseTray
- cc_ReadSubQ
- cc_ModeSense
- cc_ModeSelect
- cc_GetVolume
- cc_ReadCapacity
- cc_ReadTocDescr
- cc_ReadTocEntry
- cc_ReadPacket
- convert_UPC
- cc_ReadUPC
- cc_CheckMultiSession
- cc_SubChanInfo
- check_datarate
- c2_ReadError
- ask_mail
- check_version
- switch_drive
- check_card
- check_drives
- obey_audio_state
- check_allowed1
- check_allowed2
- check_allowed3
- seek_pos_audio_end
- ReadToC
- DiskInfo
- prepare
- sbp_status
- sbpcd_ioctl
- sbp_transfer
- DO_SBPCD_REQUEST
- sbp_read_cmd
- sbp_data
- sbpcd_open
- sbpcd_release
- sbpcd_setup
- config_spea
- init_module
- cleanup_module
- sbpcd_chk_disk_change
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260 #ifndef SBPCD_ISSUE
261 #define SBPCD_ISSUE 1
262 #endif SBPCD_ISSUE
263
264 #include <linux/config.h>
265
266 #ifdef MODULE
267 #include <linux/module.h>
268 #include <linux/version.h>
269 #ifndef CONFIG_MODVERSIONS
270 char kernel_version[]=UTS_RELEASE;
271 #endif
272 #else
273 #define MOD_INC_USE_COUNT
274 #define MOD_DEC_USE_COUNT
275 #endif MODULE
276
277 #include <linux/errno.h>
278 #include <linux/sched.h>
279 #include <linux/mm.h>
280 #include <linux/timer.h>
281 #include <linux/fs.h>
282 #include <linux/kernel.h>
283 #include <linux/cdrom.h>
284 #include <linux/ioport.h>
285 #include <linux/major.h>
286 #include <linux/string.h>
287 #include <asm/system.h>
288 #include <asm/io.h>
289 #include <asm/segment.h>
290 #include <stdarg.h>
291 #include <linux/sbpcd.h>
292
293 #if !(SBPCD_ISSUE-1)
294 #define MAJOR_NR MATSUSHITA_CDROM_MAJOR
295 #endif
296 #if !(SBPCD_ISSUE-2)
297 #define MAJOR_NR MATSUSHITA_CDROM2_MAJOR
298 #endif
299 #if !(SBPCD_ISSUE-3)
300 #define MAJOR_NR MATSUSHITA_CDROM3_MAJOR
301 #endif
302 #if !(SBPCD_ISSUE-4)
303 #define MAJOR_NR MATSUSHITA_CDROM4_MAJOR
304 #endif
305
306 #include "blk.h"
307
308 #define VERSION "v3.9 Eberhard Moenkeberg <emoenke@gwdg.de>"
309
310
311
312
313
314
315 #if !(SBPCD_ISSUE-1)
316 #define DO_SBPCD_REQUEST(a) do_sbpcd_request(a)
317 #define SBPCD_INIT(a,b) sbpcd_init(a,b)
318 #endif
319 #if !(SBPCD_ISSUE-2)
320 #define DO_SBPCD_REQUEST(a) do_sbpcd2_request(a)
321 #define SBPCD_INIT(a,b) sbpcd2_init(a,b)
322 #endif
323 #if !(SBPCD_ISSUE-3)
324 #define DO_SBPCD_REQUEST(a) do_sbpcd3_request(a)
325 #define SBPCD_INIT(a,b) sbpcd3_init(a,b)
326 #endif
327 #if !(SBPCD_ISSUE-4)
328 #define DO_SBPCD_REQUEST(a) do_sbpcd4_request(a)
329 #define SBPCD_INIT(a,b) sbpcd4_init(a,b)
330 #endif
331
332 #if SBPCD_DIS_IRQ
333 #define SBPCD_CLI cli()
334 #define SBPCD_STI sti()
335 #else
336 #define SBPCD_CLI
337 #define SBPCD_STI
338 #endif SBPCD_DIS_IRQ
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356 #if !(SBPCD_ISSUE-1)
357 static int sbpcd[] =
358 {
359 CDROM_PORT, SBPRO,
360 #if DISTRIBUTION
361 0x230, 1,
362 0x300, 0,
363
364 0x250, 1,
365 0x260, 1,
366 0x320, 0,
367
368 0x338, 0,
369 0x340, 0,
370 0x360, 0,
371 0x270, 1,
372 0x670, 0,
373 0x690, 0,
374 0x338, 2,
375 0x328, 2,
376 0x348, 2,
377 0x634, 0,
378 0x638, 0,
379 0x230, 1,
380
381 0x630, 0,
382 0x650, 0,
383 #ifdef MODULE
384
385
386
387
388 0x330, 0,
389 0x350, 0,
390 0x358, 2,
391 0x370, 0,
392 0x290, 1,
393 0x310, 0,
394 #endif MODULE
395 #endif DISTRIBUTION
396 };
397 #else
398 static int sbpcd[] = {CDROM_PORT, SBPRO};
399 #endif
400
401 #define NUM_PROBE (sizeof(sbpcd) / sizeof(int))
402
403
404
405
406
407 #if !(SBPCD_ISSUE-1)
408 #ifdef CONFIG_SBPCD2
409 extern unsigned long sbpcd2_init(unsigned long, unsigned long);
410 #endif
411 #ifdef CONFIG_SBPCD3
412 extern unsigned long sbpcd3_init(unsigned long, unsigned long);
413 #endif
414 #ifdef CONFIG_SBPCD4
415 extern unsigned long sbpcd4_init(unsigned long, unsigned long);
416 #endif
417 #endif
418
419
420
421 #define INLINE inline
422
423
424
425
426
427 static void sbp_sleep(u_int);
428 static void mark_timeout_delay(u_long);
429 static void mark_timeout_data(u_long);
430 #if 0
431 static void mark_timeout_audio(u_long);
432 #endif
433 static void sbp_read_cmd(void);
434 static int sbp_data(void);
435 static int cmd_out(void);
436 static int DiskInfo(void);
437 static int sbpcd_chk_disk_change(dev_t);
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476 #if DISTRIBUTION
477 static int sbpcd_debug = (1<<DBG_INF);
478 #else
479 static int sbpcd_debug = ((1<<DBG_INF) |
480 (1<<DBG_TOC) |
481 (1<<DBG_MUL) |
482 (1<<DBG_UPC));
483 #endif DISTRIBUTION
484
485 static int sbpcd_ioaddr = CDROM_PORT;
486 static int sbpro_type = SBPRO;
487 static unsigned char setup_done = 0;
488 static int CDo_command, CDo_reset;
489 static int CDo_sel_i_d, CDo_enable;
490 static int CDi_info, CDi_status, CDi_data;
491 static int MIXER_addr, MIXER_data;
492 static struct cdrom_msf msf;
493 static struct cdrom_ti ti;
494 static struct cdrom_tochdr tochdr;
495 static struct cdrom_tocentry tocentry;
496 static struct cdrom_subchnl SC;
497 static struct cdrom_volctrl volctrl;
498 static struct cdrom_read_audio read_audio;
499 static struct cdrom_multisession ms_info;
500
501 static unsigned char msgnum=0;
502 static char msgbuf[80];
503
504 static const char *str_sb = "SoundBlaster";
505 static const char *str_sb_l = "soundblaster";
506 static const char *str_lm = "LaserMate";
507 static const char *str_sp = "SPEA";
508 static const char *str_sp_l = "spea";
509 static const char *str_ss = "SoundScape";
510 static const char *str_ss_l = "soundscape";
511 const char *type;
512
513 #if !(SBPCD_ISSUE-1)
514 static const char *major_name="sbpcd";
515 #endif
516 #if !(SBPCD_ISSUE-2)
517 static const char *major_name="sbpcd2";
518 #endif
519 #if !(SBPCD_ISSUE-3)
520 static const char *major_name="sbpcd3";
521 #endif
522 #if !(SBPCD_ISSUE-4)
523 static const char *major_name="sbpcd4";
524 #endif
525
526
527
528 #if FUTURE
529 static struct wait_queue *sbp_waitq = NULL;
530 #endif FUTURE
531
532
533 #define SBP_BUFFER_FRAMES 8
534
535
536 static u_char family0[]="MATSHITA";
537 static u_char family1[]="CR-56";
538 static u_char family2[]="CD200";
539 static u_char familyL[]="LCS-7260";
540 static u_char familyT[]="CD-55";
541
542 static u_int recursion=0;
543 static u_int fatal_err=0;
544 static u_int response_count=0;
545 static u_int flags_cmd_out;
546 static u_char cmd_type=0;
547 static u_char drvcmd[10];
548 static u_char infobuf[20];
549 static u_char xa_head_buf[CD_XA_HEAD];
550 static u_char xa_tail_buf[CD_XA_TAIL];
551
552 static volatile u_char busy_data=0;
553 static volatile u_char busy_audio=0;
554 static u_long timeout;
555 static volatile u_char timed_out_delay=0;
556 static volatile u_char timed_out_data=0;
557 #if 0
558 static volatile u_char timed_out_audio=0;
559 #endif
560 static u_int datarate= 1000000;
561 static u_int maxtim16=16000000;
562 static u_int maxtim04= 4000000;
563 static u_int maxtim02= 2000000;
564 static u_int maxtim_8= 30000;
565 #if LONG_TIMING
566 static u_int maxtim_data= 9000;
567 #else
568 static u_int maxtim_data= 3000;
569 #endif LONG_TIMING
570 #if DISTRIBUTION
571 static int n_retries=3;
572 #else
573 static int n_retries=1;
574 #endif
575
576
577 static int ndrives=0;
578 static u_char drv_pattern[NR_SBPCD]={speed_auto,speed_auto,speed_auto,speed_auto};
579 static int sbpcd_blocksizes[NR_SBPCD] = {0, };
580
581
582
583
584
585 static int d=0;
586
587 static struct {
588 char drv_id;
589 char drv_sel;
590
591 char drive_model[9];
592 u_char firmware_version[4];
593 char f_eject;
594 u_char *sbp_buf;
595
596 u_int sbp_bufsiz;
597 int sbp_first_frame;
598 int sbp_last_frame;
599 int sbp_read_frames;
600 int sbp_current;
601
602 u_char mode;
603 u_char *aud_buf;
604
605 u_int sbp_audsiz;
606 u_char drv_type;
607 u_char drv_options;
608 int status_bits;
609 u_char diskstate_flags;
610 u_char sense_byte;
611
612 u_char CD_changed;
613 char open_count;
614 u_char error_byte;
615
616 u_char f_multisession;
617 u_int lba_multi;
618 int first_session;
619 int last_session;
620 int track_of_last_session;
621
622 u_char audio_state;
623 u_int pos_audio_start;
624 u_int pos_audio_end;
625 char vol_chan0;
626 u_char vol_ctrl0;
627 char vol_chan1;
628 u_char vol_ctrl1;
629 #if 000
630 char vol_chan2;
631 u_char vol_ctrl2;
632 char vol_chan3;
633 u_char vol_ctrl3;
634 #endif 000
635 u_char volume_control;
636
637 u_char SubQ_ctl_adr;
638 u_char SubQ_trk;
639 u_char SubQ_pnt_idx;
640 u_int SubQ_run_tot;
641 u_int SubQ_run_trk;
642 u_char SubQ_whatisthis;
643
644 u_char UPC_ctl_adr;
645 u_char UPC_buf[7];
646
647 int frame_size;
648 int CDsize_frm;
649
650 u_char xa_byte;
651 u_char n_first_track;
652 u_char n_last_track;
653 u_int size_msf;
654 u_int size_blk;
655
656 u_char TocEnt_nixbyte;
657 u_char TocEnt_ctl_adr;
658 u_char TocEnt_number;
659 u_char TocEnt_format;
660 u_int TocEnt_address;
661 u_char ored_ctl_adr;
662
663 struct {
664 u_char nixbyte;
665 u_char ctl_adr;
666 u_char number;
667 u_char format;
668 u_int address;
669 } TocBuffer[MAX_TRACKS+1];
670
671 int in_SpinUp;
672 int n_bytes;
673 u_char error_state, b3, b4;
674 u_char f_drv_error;
675 u_char speed_byte;
676 int frmsiz;
677 u_char f_XA;
678 u_char type_byte;
679 u_char mode_xb_6;
680 u_char mode_yb_7;
681 u_char mode_xb_8;
682 u_char delay;
683
684 } D_S[NR_SBPCD];
685
686
687
688
689
690 #if 0
691 unsigned long cli_sti;
692 #endif
693
694 static struct timer_list delay_timer = { NULL, NULL, 0, 0, mark_timeout_delay};
695 static struct timer_list data_timer = { NULL, NULL, 0, 0, mark_timeout_data};
696 #if 0
697 static struct timer_list audio_timer = { NULL, NULL, 0, 0, mark_timeout_audio};
698 #endif
699
700
701
702
703 static void msg(int level, const char *fmt, ...)
704 {
705 char buf[256];
706 va_list args;
707
708 if (!(sbpcd_debug&(1<<level))) return;
709
710 msgnum++;
711 if (msgnum>99) msgnum=0;
712 sprintf(buf, "%s-%d [%02d]: ", major_name, d, msgnum);
713 va_start(args, fmt);
714 vsprintf(&buf[15], fmt, args);
715 va_end(args);
716 printk(buf);
717 sbp_sleep(55);
718 return;
719 }
720
721
722
723
724 static int sbpcd_dbg_ioctl(unsigned long arg, int level)
725 {
726 switch(arg)
727 {
728 case 0:
729 sbpcd_debug = DBG_INF;
730 break;
731
732 default:
733 if (arg>=128) sbpcd_debug &= ~(1<<(arg-128));
734 else sbpcd_debug |= (1<<arg);
735 }
736 return (arg);
737 }
738
739 static void mark_timeout_delay(u_long i)
740 {
741 timed_out_delay=1;
742 #if 0
743 msg(DBG_TIM,"delay timer expired.\n");
744 #endif
745 }
746
747 static void mark_timeout_data(u_long i)
748 {
749 timed_out_data=1;
750 #if 0
751 msg(DBG_TIM,"data timer expired.\n");
752 #endif
753 }
754
755 #if 0
756 static void mark_timeout_audio(u_long i)
757 {
758 timed_out_audio=1;
759 #if 0
760 msg(DBG_TIM,"audio timer expired.\n");
761 #endif
762 }
763 #endif
764
765
766
767
768 static void sbp_sleep(u_int time)
769 {
770 #ifndef MODULE
771 if (current == task[0])
772 {
773 del_timer(&delay_timer);
774 delay_timer.expires=jiffies+time;
775 timed_out_delay=0;
776 add_timer(&delay_timer);
777 while (!timed_out_delay) ;
778 return;
779 }
780 #endif MODULE
781 sti();
782 current->state = TASK_INTERRUPTIBLE;
783 current->timeout = jiffies + time;
784 schedule();
785 sti();
786 }
787
788
789
790
791 static INLINE void lba2msf(int lba, u_char *msf)
792 {
793 lba += CD_MSF_OFFSET;
794 msf[0] = lba / (CD_SECS*CD_FRAMES);
795 lba %= CD_SECS*CD_FRAMES;
796 msf[1] = lba / CD_FRAMES;
797 msf[2] = lba % CD_FRAMES;
798 }
799
800
801
802
803
804 static INLINE void bin2bcdx(u_char *p)
805 {
806 *p=((*p/10)<<4)|(*p%10);
807 }
808
809 static INLINE u_int blk2msf(u_int blk)
810 {
811 MSF msf;
812 u_int mm;
813
814 msf.c[3] = 0;
815 msf.c[2] = (blk + CD_MSF_OFFSET) / (CD_SECS * CD_FRAMES);
816 mm = (blk + CD_MSF_OFFSET) % (CD_SECS * CD_FRAMES);
817 msf.c[1] = mm / CD_FRAMES;
818 msf.c[0] = mm % CD_FRAMES;
819 return (msf.n);
820 }
821
822 static INLINE u_int make16(u_char rh, u_char rl)
823 {
824 return ((rh<<8)|rl);
825 }
826
827 static INLINE u_int make32(u_int rh, u_int rl)
828 {
829 return ((rh<<16)|rl);
830 }
831
832 static INLINE u_char swap_nibbles(u_char i)
833 {
834 return ((i<<4)|(i>>4));
835 }
836
837 static INLINE u_char byt2bcd(u_char i)
838 {
839 return (((i/10)<<4)+i%10);
840 }
841
842 static INLINE u_char bcd2bin(u_char bcd)
843 {
844 return ((bcd>>4)*10+(bcd&0x0F));
845 }
846
847 static INLINE int msf2blk(int msfx)
848 {
849 MSF msf;
850 int i;
851
852 msf.n=msfx;
853 i=(msf.c[2] * CD_SECS + msf.c[1]) * CD_FRAMES + msf.c[0] - CD_MSF_OFFSET;
854 if (i<0) return (0);
855 return (i);
856 }
857
858
859
860
861 static INLINE int msf2lba(u_char *msf)
862 {
863 int i;
864
865 i=(msf[0] * CD_SECS + msf[1]) * CD_FRAMES + msf[2] - CD_MSF_OFFSET;
866 if (i<0) return (0);
867 return (i);
868 }
869
870
871 static int sta2err(int sta)
872 {
873 if (famT_drive)
874 {
875 if (sta==0x00) return (0);
876 if (sta==0x01) return (-604);
877 if (sta==0x02) return (-602);
878 if (sta==0x03) return (-607);
879 if (sta==0x04) return (-612);
880 if (sta==0x05) return (0);
881 if (sta==0x06) return (-615);
882 if (sta==0x0b) return (-612);
883 if (sta==0xff) return (-612);
884 return (0);
885 }
886 else
887 {
888 if (sta<=2) return (sta);
889 if (sta==0x05) return (-604);
890 if (sta==0x06) return (-606);
891 if (sta==0x0d) return (-606);
892 if (sta==0x0e) return (-603);
893 if (sta==0x14) return (-603);
894 if (sta==0x0c) return (-611);
895 if (sta==0x0f) return (-611);
896 if (sta==0x10) return (-611);
897 if (sta>=0x16) return (-612);
898 D_S[d].CD_changed=0xFF;
899 if (sta==0x11) return (-615);
900 if (famL_drive)
901 if (sta==0x12) return (-615);
902 return (-602);
903 }
904 }
905
906 static INLINE void clr_cmdbuf(void)
907 {
908 int i;
909
910 for (i=0;i<10;i++) drvcmd[i]=0;
911 cmd_type=0;
912 }
913
914 static void flush_status(void)
915 {
916 int i;
917
918 #ifdef MODULE
919 sbp_sleep(15*HZ/10);
920 for (i=maxtim_data;i!=0;i--) inb(CDi_status);
921 #else
922 if (current == task[0])
923 for (i=maxtim02;i!=0;i--) inb(CDi_status);
924 else
925 {
926 sbp_sleep(15*HZ/10);
927 for (i=maxtim_data;i!=0;i--) inb(CDi_status);
928 }
929 #endif MODULE
930 }
931
932 static int CDi_stat_loop(void)
933 {
934 int i,j;
935
936 #ifdef MODULE
937 for(timeout = jiffies + 10*HZ, i=maxtim_data; timeout > jiffies; )
938 {
939 for ( ;i!=0;i--)
940 {
941 j=inb(CDi_status);
942 if (!(j&s_not_data_ready)) return (j);
943 if (!(j&s_not_result_ready)) return (j);
944 if (fam0L_drive) if (j&s_attention) return (j);
945 }
946 sbp_sleep(1);
947 i = 1;
948 }
949 #else
950 if (current == task[0])
951 for(i=maxtim16;i!=0;i--)
952 {
953 j=inb(CDi_status);
954 if (!(j&s_not_data_ready)) return (j);
955 if (!(j&s_not_result_ready)) return (j);
956 if (fam0L_drive) if (j&s_attention) return (j);
957 }
958 else
959 for(timeout = jiffies + 10*HZ, i=maxtim_data; timeout > jiffies; )
960 {
961 for ( ;i!=0;i--)
962 {
963 j=inb(CDi_status);
964 if (!(j&s_not_data_ready)) return (j);
965 if (!(j&s_not_result_ready)) return (j);
966 if (fam0L_drive) if (j&s_attention) return (j);
967 }
968 sbp_sleep(1);
969 i = 1;
970 }
971 #endif MODULE
972 msg(DBG_LCS,"CDi_stat_loop failed\n");
973 return (-1);
974 }
975
976 #if 00000
977
978 static int tst_DataReady(void)
979 {
980 int i;
981
982 i=inb(CDi_status);
983 if (i&s_not_data_ready) return (0);
984 return (1);
985 }
986
987 static int tst_ResultReady(void)
988 {
989 int i;
990
991 i=inb(CDi_status);
992 if (i&s_not_result_ready) return (0);
993 return (1);
994 }
995
996 static int tst_Attention(void)
997 {
998 int i;
999
1000 i=inb(CDi_status);
1001 if (i&s_attention) return (1);
1002 return (0);
1003 }
1004
1005 #endif 00000
1006
1007 static int ResponseInfo(void)
1008 {
1009 int i,j,st=0;
1010 u_long timeout;
1011
1012 #ifdef MODULE
1013 if (0)
1014 #else
1015 if (current == task[0])
1016 #endif MODULE
1017 for (i=0;i<response_count;i++)
1018 {
1019 for (j=maxtim_8;j!=0;j--)
1020 {
1021 st=inb(CDi_status);
1022 if (!(st&s_not_result_ready)) break;
1023 }
1024 if (j==0)
1025 {
1026 msg(DBG_SEQ,"ResponseInfo: not_result_ready (got %d of %d bytes).\n", i, response_count);
1027 break;
1028 }
1029 infobuf[i]=inb(CDi_info);
1030 }
1031 else
1032 {
1033 for (i=0,timeout=jiffies+HZ;i<response_count;i++)
1034 {
1035 for (j=maxtim_data; ; )
1036 {
1037 for ( ;j!=0;j-- )
1038 {
1039 st=inb(CDi_status);
1040 if (!(st&s_not_result_ready)) break;
1041 }
1042 if ((j!=0)||(timeout<=jiffies)) break;
1043 sbp_sleep(1);
1044 j = 1;
1045 }
1046 if (timeout<=jiffies) break;
1047 infobuf[i]=inb(CDi_info);
1048 }
1049 }
1050 #if 000
1051 while (!(inb(CDi_status)&s_not_result_ready))
1052 {
1053 infobuf[i++]=inb(CDi_info);
1054 }
1055 j=i-response_count;
1056 if (j>0) msg(DBG_INF,"ResponseInfo: got %d trailing bytes.\n",j);
1057 #endif 000
1058 for (j=0;j<i;j++)
1059 sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
1060 msgbuf[j*3]=0;
1061 msg(DBG_CMD,"ResponseInfo:%s (%d,%d)\n",msgbuf,response_count,i);
1062 j=response_count-i;
1063 if (j>0) return (-j);
1064 else return (i);
1065 }
1066
1067 static void EvaluateStatus(int st)
1068 {
1069 D_S[d].status_bits=0;
1070 if (fam1_drive) D_S[d].status_bits=st|p_success;
1071 else if (fam0_drive)
1072 {
1073 if (st&p_caddin_old) D_S[d].status_bits |= p_door_closed|p_caddy_in;
1074 if (st&p_spinning) D_S[d].status_bits |= p_spinning;
1075 if (st&p_check) D_S[d].status_bits |= p_check;
1076 if (st&p_success_old) D_S[d].status_bits |= p_success;
1077 if (st&p_busy_old) D_S[d].status_bits |= p_busy_new;
1078 if (st&p_disk_ok) D_S[d].status_bits |= p_disk_ok;
1079 }
1080 else if (famL_drive)
1081 {
1082 D_S[d].status_bits |= p_success;
1083 if (st&p_caddin_old) D_S[d].status_bits |= p_disk_ok|p_caddy_in;
1084 if (st&p_spinning) D_S[d].status_bits |= p_spinning;
1085 if (st&p_check) D_S[d].status_bits |= p_check;
1086 if (st&p_busy_old) D_S[d].status_bits |= p_busy_new;
1087 if (st&p_lcs_door_closed) D_S[d].status_bits |= p_door_closed;
1088 if (st&p_lcs_door_locked) D_S[d].status_bits |= p_door_locked;
1089 }
1090 else if (fam2_drive)
1091 {
1092 D_S[d].status_bits |= p_success;
1093 if (st&p2_check) D_S[d].status_bits |= p1_check;
1094 if (st&p2_door_closed) D_S[d].status_bits |= p1_door_closed;
1095 if (st&p2_disk_in) D_S[d].status_bits |= p1_disk_in;
1096 if (st&p2_busy1) D_S[d].status_bits |= p1_busy;
1097 if (st&p2_busy2) D_S[d].status_bits |= p1_busy;
1098 if (st&p2_spinning) D_S[d].status_bits |= p1_spinning;
1099 if (st&p2_door_locked) D_S[d].status_bits |= p1_door_locked;
1100 if (st&p2_disk_ok) D_S[d].status_bits |= p1_disk_ok;
1101 }
1102 else if (famT_drive)
1103 {
1104 return;
1105 D_S[d].status_bits |= p_success;
1106 if (st&p2_check) D_S[d].status_bits |= p1_check;
1107 if (st&p2_door_closed) D_S[d].status_bits |= p1_door_closed;
1108 if (st&p2_disk_in) D_S[d].status_bits |= p1_disk_in;
1109 if (st&p2_busy1) D_S[d].status_bits |= p1_busy;
1110 if (st&p2_busy2) D_S[d].status_bits |= p1_busy;
1111 if (st&p2_spinning) D_S[d].status_bits |= p1_spinning;
1112 if (st&p2_door_locked) D_S[d].status_bits |= p1_door_locked;
1113 if (st&p2_disk_ok) D_S[d].status_bits |= p1_disk_ok;
1114 }
1115 return;
1116 }
1117
1118 static int get_state_T(void)
1119 {
1120 int i;
1121
1122 static int cmd_out_T(void);
1123
1124 msg(DBG_TE2,"doing get_state_T...\n");
1125 clr_cmdbuf();
1126 D_S[d].n_bytes=1;
1127 drvcmd[0]=CMDT_STATUS;
1128 i=cmd_out_T();
1129 if (i>=0) i=infobuf[0];
1130 else
1131 {
1132 msg(DBG_TEA,"get_state_T error %d\n", i);
1133 return (i);
1134 }
1135 if (i>=0)
1136
1137 D_S[d].status_bits=p1_door_closed|p1_disk_in|p1_spinning|p1_disk_ok;
1138 else if (D_S[d].error_state==6)
1139
1140 D_S[d].status_bits=p1_door_closed|p1_disk_in;
1141 else if ((D_S[d].error_state!=2)||(D_S[d].b3!=0x3A)||(D_S[d].b4==0x00))
1142 {
1143
1144 D_S[d].status_bits=p1_door_closed;
1145 D_S[d].open_count=0;
1146 }
1147 else if (D_S[d].b4==0x01)
1148 {
1149
1150 D_S[d].status_bits=0;
1151 D_S[d].open_count=0;
1152 }
1153 else
1154 {
1155
1156 D_S[d].status_bits=p1_door_closed;
1157 D_S[d].open_count=0;
1158 }
1159 msg(DBG_TE2,"get_state_T done (%02X)...\n", D_S[d].status_bits);
1160 return (D_S[d].status_bits);
1161 }
1162
1163 static int ResponseStatus(void)
1164 {
1165 int i,j;
1166 u_long timeout;
1167
1168 msg(DBG_STA,"doing ResponseStatus...\n");
1169 if (famT_drive) return (get_state_T());
1170 #ifdef MODULE
1171 if (0)
1172 #else
1173 if (current == task[0])
1174 #endif MODULE
1175 {
1176 if (flags_cmd_out & f_respo3) j = maxtim_8;
1177 else if (flags_cmd_out&f_respo2) j=maxtim16;
1178 else j=maxtim04;
1179 for (;j!=0;j--)
1180 {
1181 i=inb(CDi_status);
1182 if (!(i&s_not_result_ready)) break;
1183 }
1184 }
1185 else
1186 {
1187 if (flags_cmd_out & f_respo3) timeout = jiffies;
1188 else if (flags_cmd_out & f_respo2) timeout = jiffies + 16*HZ;
1189 else timeout = jiffies + 4*HZ;
1190 j=maxtim_8;
1191 do
1192 {
1193 for ( ;j!=0;j--)
1194 {
1195 i=inb(CDi_status);
1196 if (!(i&s_not_result_ready)) break;
1197 }
1198 if ((j!=0)||(timeout<jiffies)) break;
1199 sbp_sleep(1);
1200 j = 1;
1201 }
1202 while (1);
1203 }
1204 if (j==0)
1205 {
1206 if ((flags_cmd_out & f_respo3) == 0)
1207 msg(DBG_STA,"ResponseStatus: timeout.\n");
1208 D_S[d].status_bits=0;
1209 return (-401);
1210 }
1211 i=inb(CDi_info);
1212 msg(DBG_STA,"ResponseStatus: response %02X.\n", i);
1213 EvaluateStatus(i);
1214 #if 0
1215 if (fam0_drive)
1216 #endif
1217 msg(DBG_STA,"status_bits=%02X, i=%02X\n",D_S[d].status_bits,i);
1218 #if 1
1219 return (D_S[d].status_bits);
1220 #else
1221 return (i);
1222 #endif 0
1223 }
1224
1225 static void cc_ReadStatus(void)
1226 {
1227 int i;
1228
1229 msg(DBG_STA,"giving cc_ReadStatus command\n");
1230 if (famT_drive) return;
1231 SBPCD_CLI;
1232 if (fam0L_drive) OUT(CDo_command,CMD0_STATUS);
1233 else if (fam1_drive) OUT(CDo_command,CMD1_STATUS);
1234 else if (fam2_drive) OUT(CDo_command,CMD2_STATUS);
1235 if (!fam0L_drive) for (i=0;i<6;i++) OUT(CDo_command,0);
1236 SBPCD_STI;
1237 }
1238
1239 static int cc_ReadError(void)
1240 {
1241 int i;
1242
1243 clr_cmdbuf();
1244 msg(DBG_ERR,"giving cc_ReadError command.\n");
1245 if (fam1_drive)
1246 {
1247 drvcmd[0]=CMD1_READ_ERR;
1248 response_count=8;
1249 flags_cmd_out=f_putcmd|f_ResponseStatus;
1250 }
1251 else if (fam0L_drive)
1252 {
1253 drvcmd[0]=CMD0_READ_ERR;
1254 response_count=6;
1255 if (famL_drive)
1256 flags_cmd_out=f_putcmd;
1257 else
1258 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus;
1259 }
1260 else if (fam2_drive)
1261 {
1262 drvcmd[0]=CMD2_READ_ERR;
1263 response_count=6;
1264 flags_cmd_out=f_putcmd;
1265 }
1266 else if (famT_drive)
1267 {
1268 response_count=5;
1269 drvcmd[0]=CMDT_READ_ERR;
1270 }
1271 i=cmd_out();
1272 D_S[d].error_byte=0;
1273 msg(DBG_ERR,"cc_ReadError: cmd_out(CMDx_READ_ERR) returns %d (%02X)\n",i,i);
1274 if (i<0) return (i);
1275 if (fam0_drive) i=1;
1276 else i=2;
1277 D_S[d].error_byte=infobuf[i];
1278 msg(DBG_ERR,"cc_ReadError: infobuf[%d] is %d (%02X)\n",i,D_S[d].error_byte,D_S[d].error_byte);
1279 i=sta2err(infobuf[i]);
1280 return (i);
1281 }
1282
1283 static int cmd_out_T(void)
1284 {
1285 #undef CMDT_TRIES
1286 #define CMDT_TRIES 1000
1287
1288 static int cc_DriveReset(void);
1289 int i, j, l, ntries;
1290
1291 D_S[d].error_state=0;
1292 D_S[d].b3=0;
1293 D_S[d].b4=0;
1294 D_S[d].f_drv_error=0;
1295 for (i=0;i<10;i++) sprintf(&msgbuf[i*3]," %02X",drvcmd[i]);
1296 msgbuf[i*3]=0;
1297 msg(DBG_CMD,"cmd_out_T:%s\n",msgbuf);
1298
1299 OUT(CDo_sel_i_d,0);
1300 OUT(CDo_enable,D_S[d].drv_sel);
1301 i=inb(CDi_status);
1302 if (!(i&s_not_result_ready))
1303 do
1304 {
1305 j=inb(CDi_info);
1306 i=inb(CDi_status);
1307 sbp_sleep(0);
1308 msg(DBG_TEA,"cmd_out_T: spurious !s_not_result_ready. (%02X)\n", j);
1309 }
1310 while (!(i&s_not_result_ready));
1311 cli();
1312 for (i=0;i<10;i++) OUT(CDo_command,drvcmd[i]);
1313 sti();
1314 for (ntries=CMDT_TRIES;ntries>0;ntries--)
1315 {
1316 if (drvcmd[0]==CMDT_READ_VER) sbp_sleep(HZ);
1317 #if 1
1318 OUT(CDo_sel_i_d,0);
1319 #endif
1320 i=inb(CDi_status);
1321 if (!(i&s_not_data_ready))
1322 {
1323 OUT(CDo_sel_i_d,1);
1324 if (drvcmd[0]==CMDT_READ) return (0);
1325 if (drvcmd[0]==CMDT_DISKINFO)
1326 {
1327 l=0;
1328 do
1329 {
1330 infobuf[l++]=inb(CDi_data);
1331 i=inb(CDi_status);
1332 }
1333 while (!(i&s_not_data_ready));
1334 for (j=0;j<l;j++) sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
1335 msgbuf[j*3]=0;
1336 msg(DBG_CMD,"cmd_out_T data response:%s\n", msgbuf);
1337 }
1338 else
1339 {
1340 msg(DBG_TEA,"cmd_out_T: data response with cmd_%02X !!!!!!!!!!!!!!!!!!!!\n", drvcmd[0]);
1341 j=0;
1342 do
1343 {
1344 i=inb(CDi_data);
1345 j++;
1346 i=inb(CDi_status);
1347 }
1348 while (!(i&s_not_data_ready));
1349 msg(DBG_TEA,"cmd_out_T: data response: discarded %d bytes.\n", j);
1350 fatal_err++;
1351 }
1352 }
1353 i=inb(CDi_status);
1354 if (!(i&s_not_result_ready))
1355 {
1356 OUT(CDo_sel_i_d,0);
1357 l=0;
1358 do
1359 {
1360 infobuf[l++]=inb(CDi_info);
1361 i=inb(CDi_status);
1362 }
1363 while (!(i&s_not_result_ready));
1364 for (j=0;j<l;j++) sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
1365 msgbuf[j*3]=0;
1366 msg(DBG_CMD,"cmd_out_T info response:%s\n", msgbuf);
1367 if (infobuf[0]!=0x02) return (l);
1368 do
1369 {
1370 ++recursion;
1371 if (recursion>1) msg(DBG_TEA,"cmd_out_T READ_ERR recursion (%02X): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", drvcmd[0], recursion);
1372 clr_cmdbuf();
1373 drvcmd[0]=CMDT_READ_ERR;
1374 j=cmd_out_T();
1375 --recursion;
1376 sbp_sleep(1);
1377 }
1378 while (j<0);
1379 D_S[d].error_state=infobuf[2];
1380 D_S[d].b3=infobuf[3];
1381 D_S[d].b4=infobuf[4];
1382 if (D_S[d].f_drv_error)
1383 {
1384 D_S[d].f_drv_error=0;
1385 cc_DriveReset();
1386 D_S[d].error_state=2;
1387 }
1388 return (-D_S[d].error_state-400);
1389 }
1390 if (drvcmd[0]==CMDT_READ) return (0);
1391 sbp_sleep(HZ/10);
1392 if (ntries>(CMDT_TRIES-50)) continue;
1393 msg(DBG_TEA,"cmd_out_T: next CMDT_TRIES (%02X): %d.\n", drvcmd[0], ntries-1);
1394 }
1395 D_S[d].f_drv_error=1;
1396 cc_DriveReset();
1397 D_S[d].error_state=2;
1398 return (-99);
1399 }
1400
1401 static int cmd_out(void)
1402 {
1403 int i=0;
1404
1405 if (famT_drive) return(cmd_out_T());
1406
1407 if (flags_cmd_out&f_putcmd)
1408 {
1409 for (i=0;i<7;i++)
1410 sprintf(&msgbuf[i*3], " %02X", drvcmd[i]);
1411 msgbuf[i*3]=0;
1412 msg(DBG_CMD,"cmd_out:%s\n", msgbuf);
1413 cli();
1414 for (i=0;i<7;i++) OUT(CDo_command,drvcmd[i]);
1415 sti();
1416 }
1417 if (response_count!=0)
1418 {
1419 if (cmd_type!=0)
1420 {
1421 if (sbpro_type==1) OUT(CDo_sel_i_d,1);
1422 msg(DBG_INF,"misleaded to try ResponseData.\n");
1423 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
1424 return (-22);
1425 }
1426 else i=ResponseInfo();
1427 if (i<0) return (i);
1428 }
1429 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to CDi_stat_loop.\n");
1430 if (flags_cmd_out&f_lopsta)
1431 {
1432 i=CDi_stat_loop();
1433 if ((i<0)||!(i&s_attention)) return (-8);
1434 }
1435 if (!(flags_cmd_out&f_getsta)) goto LOC_229;
1436
1437 LOC_228:
1438 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadStatus.\n");
1439 cc_ReadStatus();
1440
1441 LOC_229:
1442 if (flags_cmd_out&f_ResponseStatus)
1443 {
1444 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to ResponseStatus.\n");
1445 i=ResponseStatus();
1446
1447 if (i<0) return (i);
1448 if (flags_cmd_out&(f_bit1|f_wait_if_busy))
1449 {
1450 if (!st_check)
1451 {
1452 if ((flags_cmd_out&f_bit1)&&(i&p_success)) goto LOC_232;
1453 if ((!(flags_cmd_out&f_wait_if_busy))||(!st_busy)) goto LOC_228;
1454 }
1455 }
1456 }
1457 LOC_232:
1458 if (!(flags_cmd_out&f_obey_p_check)) return (0);
1459 if (!st_check) return (0);
1460 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadError.\n");
1461 i=cc_ReadError();
1462 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cmd_out OK.\n");
1463 msg(DBG_000,"cmd_out: cc_ReadError=%d\n", i);
1464 return (i);
1465 }
1466
1467 static int cc_Seek(u_int pos, char f_blk_msf)
1468 {
1469 int i;
1470
1471 clr_cmdbuf();
1472 if (f_blk_msf>1) return (-3);
1473 if (fam0_drive)
1474 {
1475 drvcmd[0]=CMD0_SEEK;
1476 if (f_blk_msf==1) pos=msf2blk(pos);
1477 drvcmd[2]=(pos>>16)&0x00FF;
1478 drvcmd[3]=(pos>>8)&0x00FF;
1479 drvcmd[4]=pos&0x00FF;
1480 flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
1481 f_ResponseStatus | f_obey_p_check | f_bit1;
1482 }
1483 else if (fam1L_drive)
1484 {
1485 drvcmd[0]=CMD1_SEEK;
1486 if (f_blk_msf==0) pos=blk2msf(pos);
1487 drvcmd[1]=(pos>>16)&0x00FF;
1488 drvcmd[2]=(pos>>8)&0x00FF;
1489 drvcmd[3]=pos&0x00FF;
1490 if (famL_drive)
1491 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
1492 else
1493 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1494 }
1495 else if (fam2_drive)
1496 {
1497 drvcmd[0]=CMD2_SEEK;
1498 if (f_blk_msf==0) pos=blk2msf(pos);
1499 drvcmd[2]=(pos>>24)&0x00FF;
1500 drvcmd[3]=(pos>>16)&0x00FF;
1501 drvcmd[4]=(pos>>8)&0x00FF;
1502 drvcmd[5]=pos&0x00FF;
1503 flags_cmd_out=f_putcmd|f_ResponseStatus;
1504 }
1505 else if (famT_drive)
1506 {
1507 drvcmd[0]=CMDT_SEEK;
1508 if (f_blk_msf==1) pos=msf2blk(pos);
1509 drvcmd[2]=(pos>>24)&0x00FF;
1510 drvcmd[3]=(pos>>16)&0x00FF;
1511 drvcmd[4]=(pos>>8)&0x00FF;
1512 drvcmd[5]=pos&0x00FF;
1513 D_S[d].n_bytes=1;
1514 }
1515 response_count=0;
1516 i=cmd_out();
1517 return (i);
1518 }
1519
1520 static int cc_SpinUp(void)
1521 {
1522 int i;
1523
1524 msg(DBG_SPI,"SpinUp.\n");
1525 D_S[d].in_SpinUp = 1;
1526 clr_cmdbuf();
1527 if (fam0L_drive)
1528 {
1529 drvcmd[0]=CMD0_SPINUP;
1530 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
1531 f_ResponseStatus|f_obey_p_check|f_bit1;
1532 }
1533 else if (fam1_drive)
1534 {
1535 drvcmd[0]=CMD1_SPINUP;
1536 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1537 }
1538 else if (fam2_drive)
1539 {
1540 drvcmd[0]=CMD2_TRAY_CTL;
1541 drvcmd[4]=0x01;
1542 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1543 }
1544 else if (famT_drive)
1545 {
1546 drvcmd[0]=CMDT_TRAY_CTL;
1547 drvcmd[4]=0x03;
1548 }
1549 response_count=0;
1550 i=cmd_out();
1551 D_S[d].in_SpinUp = 0;
1552 return (i);
1553 }
1554
1555 static int cc_SpinDown(void)
1556 {
1557 int i;
1558
1559 if (fam0_drive) return (0);
1560 clr_cmdbuf();
1561 response_count=0;
1562 if (fam1_drive)
1563 {
1564 drvcmd[0]=CMD1_SPINDOWN;
1565 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1566 }
1567 else if (fam2_drive)
1568 {
1569 drvcmd[0]=CMD2_TRAY_CTL;
1570 drvcmd[4]=0x02;
1571 flags_cmd_out=f_putcmd|f_ResponseStatus;
1572 }
1573 else if (famL_drive)
1574 {
1575 drvcmd[0]=CMDL_SPINDOWN;
1576 drvcmd[1]=1;
1577 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
1578 }
1579 else if (famT_drive)
1580 {
1581 drvcmd[0]=CMDT_TRAY_CTL;
1582 drvcmd[4]=0x02;
1583 }
1584 i=cmd_out();
1585 return (i);
1586 }
1587
1588 static int cc_get_mode_T(void)
1589 {
1590 int i;
1591
1592 clr_cmdbuf();
1593 response_count=10;
1594 drvcmd[0]=CMDT_GETMODE;
1595 drvcmd[4]=response_count;
1596 i=cmd_out_T();
1597 return (i);
1598 }
1599
1600 static int cc_set_mode_T(void)
1601 {
1602 int i;
1603
1604 clr_cmdbuf();
1605 response_count=1;
1606 drvcmd[0]=CMDT_SETMODE;
1607 drvcmd[1]=D_S[d].speed_byte;
1608 drvcmd[2]=D_S[d].frmsiz>>8;
1609 drvcmd[3]=D_S[d].frmsiz&0x0FF;
1610 drvcmd[4]=D_S[d].f_XA;
1611 drvcmd[5]=D_S[d].type_byte;
1612 drvcmd[6]=D_S[d].mode_xb_6;
1613 drvcmd[7]=D_S[d].mode_yb_7|D_S[d].volume_control;
1614 drvcmd[8]=D_S[d].mode_xb_8;
1615 drvcmd[9]=D_S[d].delay;
1616 i=cmd_out_T();
1617 return (i);
1618 }
1619
1620 static int cc_prep_mode_T(void)
1621 {
1622 int i, j;
1623
1624 i=cc_get_mode_T();
1625 if (i<0) return (i);
1626 for (i=0;i<10;i++)
1627 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
1628 msgbuf[i*3]=0;
1629 msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
1630 D_S[d].speed_byte=0x02;
1631 D_S[d].frmsiz=make16(infobuf[2],infobuf[3]);
1632 D_S[d].f_XA=infobuf[4];
1633 if (D_S[d].f_XA==0) D_S[d].type_byte=0;
1634 else D_S[d].type_byte=1;
1635 D_S[d].mode_xb_6=infobuf[6];
1636 D_S[d].mode_yb_7=1;
1637 D_S[d].mode_xb_8=infobuf[8];
1638 D_S[d].delay=0;
1639 j=cc_set_mode_T();
1640 i=cc_get_mode_T();
1641 for (i=0;i<10;i++)
1642 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
1643 msgbuf[i*3]=0;
1644 msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
1645 return (j);
1646 }
1647
1648 static int cc_SetSpeed(u_char speed, u_char x1, u_char x2)
1649 {
1650 int i;
1651
1652 if (fam0L_drive) return (-3);
1653 clr_cmdbuf();
1654 response_count=0;
1655 if (fam1_drive)
1656 {
1657 drvcmd[0]=CMD1_SETMODE;
1658 drvcmd[1]=0x03;
1659 drvcmd[2]=speed;
1660 drvcmd[3]=x1;
1661 drvcmd[4]=x2;
1662 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
1663 }
1664 else if (fam2_drive)
1665 {
1666 drvcmd[0]=CMD2_SETSPEED;
1667 if (speed&speed_auto)
1668 {
1669 drvcmd[2]=0xFF;
1670 drvcmd[3]=0xFF;
1671 }
1672 else
1673 {
1674 drvcmd[2]=0;
1675 drvcmd[3]=150;
1676 }
1677 flags_cmd_out=f_putcmd|f_ResponseStatus;
1678 }
1679 else if (famT_drive)
1680 {
1681 return (0);
1682 }
1683 i=cmd_out();
1684 return (i);
1685 }
1686
1687 static int cc_SetVolume(void)
1688 {
1689 int i;
1690 u_char channel0,channel1,volume0,volume1;
1691 u_char control0,value0,control1,value1;
1692
1693 D_S[d].diskstate_flags &= ~volume_bit;
1694 clr_cmdbuf();
1695 channel0=D_S[d].vol_chan0;
1696 volume0=D_S[d].vol_ctrl0;
1697 channel1=control1=D_S[d].vol_chan1;
1698 volume1=value1=D_S[d].vol_ctrl1;
1699 control0=value0=0;
1700
1701 if (((D_S[d].drv_options&audio_mono)!=0)&&(D_S[d].drv_type>=drv_211))
1702 {
1703 if ((volume0!=0)&&(volume1==0))
1704 {
1705 volume1=volume0;
1706 channel1=channel0;
1707 }
1708 else if ((volume0==0)&&(volume1!=0))
1709 {
1710 volume0=volume1;
1711 channel0=channel1;
1712 }
1713 }
1714 if (channel0>1)
1715 {
1716 channel0=0;
1717 volume0=0;
1718 }
1719 if (channel1>1)
1720 {
1721 channel1=1;
1722 volume1=0;
1723 }
1724
1725 if (fam1_drive)
1726 {
1727 control0=channel0+1;
1728 control1=channel1+1;
1729 value0=(volume0>volume1)?volume0:volume1;
1730 value1=value0;
1731 if (volume0==0) control0=0;
1732 if (volume1==0) control1=0;
1733 drvcmd[0]=CMD1_SETMODE;
1734 drvcmd[1]=0x05;
1735 drvcmd[3]=control0;
1736 drvcmd[4]=value0;
1737 drvcmd[5]=control1;
1738 drvcmd[6]=value1;
1739 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
1740 }
1741 else if (fam2_drive)
1742 {
1743 control0=channel0+1;
1744 control1=channel1+1;
1745 value0=(volume0>volume1)?volume0:volume1;
1746 value1=value0;
1747 if (volume0==0) control0=0;
1748 if (volume1==0) control1=0;
1749 drvcmd[0]=CMD2_SETMODE;
1750 drvcmd[1]=0x0E;
1751 drvcmd[3]=control0;
1752 drvcmd[4]=value0;
1753 drvcmd[5]=control1;
1754 drvcmd[6]=value1;
1755 flags_cmd_out=f_putcmd|f_ResponseStatus;
1756 }
1757 else if (famL_drive)
1758 {
1759 if ((volume0==0)||(channel0!=0)) control0 |= 0x80;
1760 if ((volume1==0)||(channel1!=1)) control0 |= 0x40;
1761 if (volume0|volume1) value0=0x80;
1762 drvcmd[0]=CMDL_SETMODE;
1763 drvcmd[1]=0x03;
1764 drvcmd[4]=control0;
1765 drvcmd[5]=value0;
1766 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
1767 }
1768 else if (fam0_drive)
1769 {
1770 if (D_S[d].drv_type>=drv_300)
1771 {
1772 control0=volume0&0xFC;
1773 value0=volume1&0xFC;
1774 if ((volume0!=0)&&(volume0<4)) control0 |= 0x04;
1775 if ((volume1!=0)&&(volume1<4)) value0 |= 0x04;
1776 if (channel0!=0) control0 |= 0x01;
1777 if (channel1==1) value0 |= 0x01;
1778 }
1779 else
1780 {
1781 value0=(volume0>volume1)?volume0:volume1;
1782 if (D_S[d].drv_type<drv_211)
1783 {
1784 if (channel0!=0)
1785 {
1786 i=channel1;
1787 channel1=channel0;
1788 channel0=i;
1789 i=volume1;
1790 volume1=volume0;
1791 volume0=i;
1792 }
1793 if (channel0==channel1)
1794 {
1795 if (channel0==0)
1796 {
1797 channel1=1;
1798 volume1=0;
1799 volume0=value0;
1800 }
1801 else
1802 {
1803 channel0=0;
1804 volume0=0;
1805 volume1=value0;
1806 }
1807 }
1808 }
1809
1810 if ((volume0!=0)&&(volume1!=0))
1811 {
1812 if (volume0==0xFF) volume1=0xFF;
1813 else if (volume1==0xFF) volume0=0xFF;
1814 }
1815 else if (D_S[d].drv_type<drv_201) volume0=volume1=value0;
1816
1817 if (D_S[d].drv_type>=drv_201)
1818 {
1819 if (volume0==0) control0 |= 0x80;
1820 if (volume1==0) control0 |= 0x40;
1821 }
1822 if (D_S[d].drv_type>=drv_211)
1823 {
1824 if (channel0!=0) control0 |= 0x20;
1825 if (channel1!=1) control0 |= 0x10;
1826 }
1827 }
1828 drvcmd[0]=CMD0_SETMODE;
1829 drvcmd[1]=0x83;
1830 drvcmd[4]=control0;
1831 drvcmd[5]=value0;
1832 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
1833 }
1834 else if (famT_drive)
1835 {
1836 D_S[d].volume_control=0;
1837 if (!volume0) D_S[d].volume_control|=0x10;
1838 if (!volume1) D_S[d].volume_control|=0x20;
1839 i=cc_prep_mode_T();
1840 if (i<0) return (i);
1841 }
1842 if (!famT_drive)
1843 {
1844 response_count=0;
1845 i=cmd_out();
1846 if (i<0) return (i);
1847 }
1848 D_S[d].diskstate_flags |= volume_bit;
1849 return (0);
1850 }
1851
1852 static int GetStatus(void)
1853 {
1854 int i;
1855
1856 if (famT_drive) return (0);
1857 flags_cmd_out=f_getsta|f_ResponseStatus|f_obey_p_check;
1858 response_count=0;
1859 cmd_type=0;
1860 i=cmd_out();
1861 return (i);
1862 }
1863
1864 static int cc_DriveReset(void)
1865 {
1866 int i;
1867
1868 msg(DBG_RES,"cc_DriveReset called.\n");
1869 clr_cmdbuf();
1870 response_count=0;
1871 if (fam0L_drive) OUT(CDo_reset,0x00);
1872 else if (fam1_drive)
1873 {
1874 drvcmd[0]=CMD1_RESET;
1875 flags_cmd_out=f_putcmd;
1876 i=cmd_out();
1877 }
1878 else if (fam2_drive)
1879 {
1880 drvcmd[0]=CMD2_RESET;
1881 flags_cmd_out=f_putcmd;
1882 i=cmd_out();
1883 OUT(CDo_reset,0x00);
1884 }
1885 else if (famT_drive)
1886 {
1887 OUT(CDo_sel_i_d,0);
1888 OUT(CDo_enable,D_S[d].drv_sel);
1889 OUT(CDo_command,CMDT_RESET);
1890 for (i=1;i<10;i++) OUT(CDo_command,0);
1891 }
1892 if (fam0L_drive) sbp_sleep(5*HZ);
1893 else sbp_sleep(1*HZ);
1894 #if 1
1895 if (famT_drive)
1896 {
1897 msg(DBG_TEA, "================CMDT_RESET given=================.\n");
1898 sbp_sleep(3*HZ);
1899 }
1900 #endif 1
1901 flush_status();
1902 i=GetStatus();
1903 if (i<0) return i;
1904 if (!famT_drive)
1905 if (D_S[d].error_byte!=aud_12) return -501;
1906 return (0);
1907 }
1908
1909 static int SetSpeed(void)
1910 {
1911 int i, speed;
1912
1913 if (!(D_S[d].drv_options&(speed_auto|speed_300|speed_150))) return (0);
1914 speed=speed_auto;
1915 if (!(D_S[d].drv_options&speed_auto))
1916 {
1917 speed |= speed_300;
1918 if (!(D_S[d].drv_options&speed_300)) speed=0;
1919 }
1920 i=cc_SetSpeed(speed,0,0);
1921 return (i);
1922 }
1923
1924 static int DriveReset(void)
1925 {
1926 int i;
1927
1928 i=cc_DriveReset();
1929 if (i<0) return (-22);
1930 do
1931 {
1932 i=GetStatus();
1933 if ((i<0)&&(i!=-615)) return (-2);
1934 if (!st_caddy_in) break;
1935 sbp_sleep(1);
1936 }
1937 while (!st_diskok);
1938 #if 000
1939 D_S[d].CD_changed=1;
1940 #endif
1941 if ((st_door_closed) && (st_caddy_in))
1942 {
1943 i=DiskInfo();
1944 if (i<0) return (-23);
1945 }
1946 return (0);
1947 }
1948
1949 static int cc_PlayAudio(int pos_audio_start,int pos_audio_end)
1950 {
1951 int i, j, n;
1952
1953 if (D_S[d].audio_state==audio_playing) return (-EINVAL);
1954 clr_cmdbuf();
1955 response_count=0;
1956 if (famL_drive)
1957 {
1958 drvcmd[0]=CMDL_PLAY;
1959 i=msf2blk(pos_audio_start);
1960 n=msf2blk(pos_audio_end)+1-i;
1961 drvcmd[1]=(i>>16)&0x00FF;
1962 drvcmd[2]=(i>>8)&0x00FF;
1963 drvcmd[3]=i&0x00FF;
1964 drvcmd[4]=(n>>16)&0x00FF;
1965 drvcmd[5]=(n>>8)&0x00FF;
1966 drvcmd[6]=n&0x00FF;
1967 flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
1968 f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
1969 }
1970 else
1971 {
1972 j=1;
1973 if (fam1_drive)
1974 {
1975 drvcmd[0]=CMD1_PLAY_MSF;
1976 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus |
1977 f_obey_p_check | f_wait_if_busy;
1978 }
1979 else if (fam2_drive)
1980 {
1981 drvcmd[0]=CMD2_PLAY_MSF;
1982 flags_cmd_out = f_putcmd | f_ResponseStatus;
1983 }
1984 else if (famT_drive)
1985 {
1986 drvcmd[0]=CMDT_PLAY_MSF;
1987 j=3;
1988 response_count=1;
1989 }
1990 else if (fam0_drive)
1991 {
1992 drvcmd[0]=CMD0_PLAY_MSF;
1993 flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
1994 f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
1995 }
1996 drvcmd[j]=(pos_audio_start>>16)&0x00FF;
1997 drvcmd[j+1]=(pos_audio_start>>8)&0x00FF;
1998 drvcmd[j+2]=pos_audio_start&0x00FF;
1999 drvcmd[j+3]=(pos_audio_end>>16)&0x00FF;
2000 drvcmd[j+4]=(pos_audio_end>>8)&0x00FF;
2001 drvcmd[j+5]=pos_audio_end&0x00FF;
2002 }
2003 i=cmd_out();
2004 return (i);
2005 }
2006
2007 static int cc_Pause_Resume(int pau_res)
2008 {
2009 int i;
2010
2011 clr_cmdbuf();
2012 response_count=0;
2013 if (fam1_drive)
2014 {
2015 drvcmd[0]=CMD1_PAU_RES;
2016 if (pau_res!=1) drvcmd[1]=0x80;
2017 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
2018 }
2019 else if (fam2_drive)
2020 {
2021 drvcmd[0]=CMD2_PAU_RES;
2022 if (pau_res!=1) drvcmd[2]=0x01;
2023 flags_cmd_out=f_putcmd|f_ResponseStatus;
2024 }
2025 else if (fam0L_drive)
2026 {
2027 drvcmd[0]=CMD0_PAU_RES;
2028 if (pau_res!=1) drvcmd[1]=0x80;
2029 if (famL_drive)
2030 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
2031 f_obey_p_check|f_bit1;
2032 else
2033 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
2034 f_obey_p_check;
2035 }
2036 else if (famT_drive)
2037 {
2038 if (pau_res==3) return (cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end));
2039 else if (pau_res==1) drvcmd[0]=CMDT_PAUSE;
2040 else return (-56);
2041 }
2042 i=cmd_out();
2043 return (i);
2044 }
2045
2046 static int cc_LockDoor(char lock)
2047 {
2048 int i;
2049
2050 if (fam0_drive) return (0);
2051 msg(DBG_LCK,"cc_LockDoor: %d (drive %d)\n", lock, d);
2052 msg(DBG_LCS,"p_door_locked bit %d before\n", st_door_locked);
2053 clr_cmdbuf();
2054 response_count=0;
2055 if (fam1_drive)
2056 {
2057 drvcmd[0]=CMD1_LOCK_CTL;
2058 if (lock==1) drvcmd[1]=0x01;
2059 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2060 }
2061 else if (fam2_drive)
2062 {
2063 drvcmd[0]=CMD2_LOCK_CTL;
2064 if (lock==1) drvcmd[4]=0x01;
2065 flags_cmd_out=f_putcmd|f_ResponseStatus;
2066 }
2067 else if (famL_drive)
2068 {
2069 drvcmd[0]=CMDL_LOCK_CTL;
2070 if (lock==1) drvcmd[1]=0x01;
2071 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
2072 }
2073 else if (famT_drive)
2074 {
2075 drvcmd[0]=CMDT_LOCK_CTL;
2076 if (lock==1) drvcmd[4]=0x01;
2077 }
2078 i=cmd_out();
2079 msg(DBG_LCS,"p_door_locked bit %d after\n", st_door_locked);
2080 return (i);
2081 }
2082
2083
2084 static int UnLockDoor(void)
2085 {
2086 int i,j;
2087
2088 j=20;
2089 do
2090 {
2091 i=cc_LockDoor(0);
2092 --j;
2093 sbp_sleep(1);
2094 }
2095 while ((i<0)&&(j));
2096 if (i<0)
2097 {
2098 cc_DriveReset();
2099 return -84;
2100 }
2101 return (0);
2102 }
2103
2104 static int LockDoor(void)
2105 {
2106 int i,j;
2107
2108 j=20;
2109 do
2110 {
2111 i=cc_LockDoor(1);
2112 --j;
2113 sbp_sleep(1);
2114 }
2115 while ((i<0)&&(j));
2116 if (j==0)
2117 {
2118 cc_DriveReset();
2119 j=20;
2120 do
2121 {
2122 i=cc_LockDoor(1);
2123 --j;
2124 sbp_sleep(1);
2125 }
2126 while ((i<0)&&(j));
2127 }
2128 return (i);
2129 }
2130
2131 static int cc_CloseTray(void)
2132 {
2133 int i;
2134
2135 if (fam0_drive) return (0);
2136 msg(DBG_LCK,"cc_CloseTray (drive %d)\n", d);
2137 msg(DBG_LCS,"p_door_closed bit %d before\n", st_door_closed);
2138
2139 clr_cmdbuf();
2140 response_count=0;
2141 if (fam1_drive)
2142 {
2143 drvcmd[0]=CMD1_TRAY_CTL;
2144 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
2145 }
2146 else if (fam2_drive)
2147 {
2148 drvcmd[0]=CMD2_TRAY_CTL;
2149 drvcmd[1]=0x01;
2150 drvcmd[4]=0x03;
2151 flags_cmd_out=f_putcmd|f_ResponseStatus;
2152 }
2153 else if (famL_drive)
2154 {
2155 drvcmd[0]=CMDL_TRAY_CTL;
2156 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
2157 f_ResponseStatus|f_obey_p_check|f_bit1;
2158 }
2159 else if (famT_drive)
2160 {
2161 drvcmd[0]=CMDT_TRAY_CTL;
2162 drvcmd[4]=0x03;
2163 }
2164 i=cmd_out();
2165 msg(DBG_LCS,"p_door_closed bit %d after\n", st_door_closed);
2166 return (i);
2167 }
2168
2169 static int cc_ReadSubQ(void)
2170 {
2171 int i,j;
2172
2173 D_S[d].diskstate_flags &= ~subq_bit;
2174 for (j=255;j>0;j--)
2175 {
2176 clr_cmdbuf();
2177 if (fam1_drive)
2178 {
2179 drvcmd[0]=CMD1_READSUBQ;
2180 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2181 response_count=11;
2182 }
2183 else if (fam2_drive)
2184 {
2185 drvcmd[0]=CMD2_READSUBQ;
2186 drvcmd[1]=0x02;
2187 drvcmd[3]=0x01;
2188 flags_cmd_out=f_putcmd;
2189 response_count=10;
2190 }
2191 else if (fam0L_drive)
2192 {
2193 drvcmd[0]=CMD0_READSUBQ;
2194 drvcmd[1]=0x02;
2195 if (famL_drive)
2196 flags_cmd_out=f_putcmd;
2197 else
2198 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2199 response_count=13;
2200 }
2201 else if (famT_drive)
2202 {
2203 response_count=12;
2204 drvcmd[0]=CMDT_READSUBQ;
2205 drvcmd[1]=0x02;
2206 drvcmd[2]=0x40;
2207 drvcmd[3]=0x01;
2208 drvcmd[8]=response_count;
2209 }
2210 i=cmd_out();
2211 if (i<0) return (i);
2212 for (i=0;i<response_count;i++)
2213 {
2214 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
2215 msgbuf[i*3]=0;
2216 msg(DBG_SQ1,"cc_ReadSubQ:%s\n", msgbuf);
2217 }
2218 if (famT_drive) break;
2219 if (infobuf[0]!=0) break;
2220 if ((!st_spinning) || (j==1))
2221 {
2222 D_S[d].SubQ_ctl_adr=D_S[d].SubQ_trk=D_S[d].SubQ_pnt_idx=D_S[d].SubQ_whatisthis=0;
2223 D_S[d].SubQ_run_tot=D_S[d].SubQ_run_trk=0;
2224 return (0);
2225 }
2226 }
2227 if (famT_drive) D_S[d].SubQ_ctl_adr=infobuf[1];
2228 else D_S[d].SubQ_ctl_adr=swap_nibbles(infobuf[1]);
2229 D_S[d].SubQ_trk=byt2bcd(infobuf[2]);
2230 D_S[d].SubQ_pnt_idx=byt2bcd(infobuf[3]);
2231 if (fam0L_drive) i=5;
2232 else if (fam12_drive) i=4;
2233 else if (famT_drive) i=8;
2234 D_S[d].SubQ_run_tot=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2]));
2235 i=7;
2236 if (fam0L_drive) i=9;
2237 else if (fam12_drive) i=7;
2238 else if (famT_drive) i=4;
2239 D_S[d].SubQ_run_trk=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2]));
2240 D_S[d].SubQ_whatisthis=infobuf[i+3];
2241 D_S[d].diskstate_flags |= subq_bit;
2242 return (0);
2243 }
2244
2245 static int cc_ModeSense(void)
2246 {
2247 int i;
2248
2249 if (fam2_drive) return (0);
2250 D_S[d].diskstate_flags &= ~frame_size_bit;
2251 clr_cmdbuf();
2252 if (fam1_drive)
2253 {
2254 response_count=5;
2255 drvcmd[0]=CMD1_GETMODE;
2256 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2257 }
2258 else if (fam0L_drive)
2259 {
2260 response_count=2;
2261 drvcmd[0]=CMD0_GETMODE;
2262 if (famL_drive) flags_cmd_out=f_putcmd;
2263 else flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2264 }
2265 else if (famT_drive)
2266 {
2267 response_count=10;
2268 drvcmd[0]=CMDT_GETMODE;
2269 drvcmd[4]=response_count;
2270 }
2271 i=cmd_out();
2272 if (i<0) return (i);
2273 i=0;
2274 D_S[d].sense_byte=0;
2275 if (fam1_drive) D_S[d].sense_byte=infobuf[i++];
2276 else if (famT_drive)
2277 {
2278 if (infobuf[4]==0x01) D_S[d].xa_byte=0x20;
2279 else D_S[d].xa_byte=0;
2280 i=2;
2281 }
2282 D_S[d].frame_size=make16(infobuf[i],infobuf[i+1]);
2283 for (i=0;i<response_count;i++)
2284 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
2285 msgbuf[i*3]=0;
2286 msg(DBG_XA1,"cc_ModeSense:%s\n", msgbuf);
2287
2288 D_S[d].diskstate_flags |= frame_size_bit;
2289 return (0);
2290 }
2291
2292
2293 static int cc_ModeSelect(int framesize)
2294 {
2295 int i;
2296
2297 if (fam2_drive) return (0);
2298 D_S[d].diskstate_flags &= ~frame_size_bit;
2299 clr_cmdbuf();
2300 D_S[d].frame_size=framesize;
2301 if (framesize==CD_FRAMESIZE_RAW) D_S[d].sense_byte=0x82;
2302 else D_S[d].sense_byte=0x00;
2303
2304 msg(DBG_XA1,"cc_ModeSelect: %02X %04X\n",
2305 D_S[d].sense_byte, D_S[d].frame_size);
2306
2307 if (fam1_drive)
2308 {
2309 drvcmd[0]=CMD1_SETMODE;
2310 drvcmd[1]=0x00;
2311 drvcmd[2]=D_S[d].sense_byte;
2312 drvcmd[3]=(D_S[d].frame_size>>8)&0xFF;
2313 drvcmd[4]=D_S[d].frame_size&0xFF;
2314 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2315 }
2316 else if (fam0L_drive)
2317 {
2318 drvcmd[0]=CMD0_SETMODE;
2319 drvcmd[1]=0x00;
2320 drvcmd[2]=(D_S[d].frame_size>>8)&0xFF;
2321 drvcmd[3]=D_S[d].frame_size&0xFF;
2322 drvcmd[4]=0x00;
2323 if(famL_drive)
2324 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check;
2325 else
2326 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2327 }
2328 else if (famT_drive)
2329 {
2330 return (-1);
2331 }
2332 response_count=0;
2333 i=cmd_out();
2334 if (i<0) return (i);
2335 D_S[d].diskstate_flags |= frame_size_bit;
2336 return (0);
2337 }
2338
2339 static int cc_GetVolume(void)
2340 {
2341 int i;
2342 u_char switches;
2343 u_char chan0=0;
2344 u_char vol0=0;
2345 u_char chan1=1;
2346 u_char vol1=0;
2347
2348 D_S[d].diskstate_flags &= ~volume_bit;
2349 clr_cmdbuf();
2350 if (fam1_drive)
2351 {
2352 drvcmd[0]=CMD1_GETMODE;
2353 drvcmd[1]=0x05;
2354 response_count=5;
2355 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2356 }
2357 else if (fam2_drive)
2358 {
2359 drvcmd[0]=CMD2_GETMODE;
2360 drvcmd[1]=0x0E;
2361 response_count=5;
2362 flags_cmd_out=f_putcmd;
2363 }
2364 else if (fam0L_drive)
2365 {
2366 drvcmd[0]=CMD0_GETMODE;
2367 drvcmd[1]=0x03;
2368 response_count=2;
2369 if(famL_drive)
2370 flags_cmd_out=f_putcmd;
2371 else
2372 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2373 }
2374 else if (famT_drive)
2375 {
2376 i=cc_get_mode_T();
2377 if (i<0) return (i);
2378 }
2379 if (!famT_drive)
2380 {
2381 i=cmd_out();
2382 if (i<0) return (i);
2383 }
2384 if (fam1_drive)
2385 {
2386 chan0=infobuf[1]&0x0F;
2387 vol0=infobuf[2];
2388 chan1=infobuf[3]&0x0F;
2389 vol1=infobuf[4];
2390 if (chan0==0)
2391 {
2392 chan0=1;
2393 vol0=0;
2394 }
2395 if (chan1==0)
2396 {
2397 chan1=2;
2398 vol1=0;
2399 }
2400 chan0 >>= 1;
2401 chan1 >>= 1;
2402 }
2403 else if (fam2_drive)
2404 {
2405 chan0=infobuf[1];
2406 vol0=infobuf[2];
2407 chan1=infobuf[3];
2408 vol1=infobuf[4];
2409 }
2410 else if (famL_drive)
2411 {
2412 chan0=0;
2413 chan1=1;
2414 vol0=vol1=infobuf[1];
2415 switches=infobuf[0];
2416 if ((switches&0x80)!=0) chan0=1;
2417 if ((switches&0x40)!=0) chan1=0;
2418 }
2419 else if (fam0_drive)
2420 {
2421 chan0=0;
2422 chan1=1;
2423 vol0=vol1=infobuf[1];
2424 if (D_S[d].drv_type>=drv_201)
2425 {
2426 if (D_S[d].drv_type<drv_300)
2427 {
2428 switches=infobuf[0];
2429 if ((switches&0x80)!=0) vol0=0;
2430 if ((switches&0x40)!=0) vol1=0;
2431 if (D_S[d].drv_type>=drv_211)
2432 {
2433 if ((switches&0x20)!=0) chan0=1;
2434 if ((switches&0x10)!=0) chan1=0;
2435 }
2436 }
2437 else
2438 {
2439 vol0=infobuf[0];
2440 if ((vol0&0x01)!=0) chan0=1;
2441 if ((vol1&0x01)==0) chan1=0;
2442 vol0 &= 0xFC;
2443 vol1 &= 0xFC;
2444 if (vol0!=0) vol0 += 3;
2445 if (vol1!=0) vol1 += 3;
2446 }
2447 }
2448 }
2449 else if (famT_drive)
2450 {
2451 D_S[d].volume_control=infobuf[7];
2452 chan0=0;
2453 chan1=1;
2454 if (D_S[d].volume_control&0x10) vol0=0;
2455 else vol0=0xff;
2456 if (D_S[d].volume_control&0x20) vol1=0;
2457 else vol1=0xff;
2458 }
2459 D_S[d].vol_chan0=chan0;
2460 D_S[d].vol_ctrl0=vol0;
2461 D_S[d].vol_chan1=chan1;
2462 D_S[d].vol_ctrl1=vol1;
2463 #if 000
2464 D_S[d].vol_chan2=2;
2465 D_S[d].vol_ctrl2=0xFF;
2466 D_S[d].vol_chan3=3;
2467 D_S[d].vol_ctrl3=0xFF;
2468 #endif 000
2469 D_S[d].diskstate_flags |= volume_bit;
2470 return (0);
2471 }
2472
2473 static int cc_ReadCapacity(void)
2474 {
2475 int i, j;
2476
2477 if (famL_drive) return (0);
2478 if (famT_drive) return (0);
2479 D_S[d].diskstate_flags &= ~cd_size_bit;
2480 for (j=3;j>0;j--)
2481 {
2482 clr_cmdbuf();
2483 if (fam1_drive)
2484 {
2485 drvcmd[0]=CMD1_CAPACITY;
2486 response_count=5;
2487 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2488 }
2489 else if (fam2_drive)
2490 {
2491 drvcmd[0]=CMD2_CAPACITY;
2492 response_count=8;
2493 flags_cmd_out=f_putcmd;
2494 }
2495 else if (fam0_drive)
2496 {
2497 drvcmd[0]=CMD0_CAPACITY;
2498 response_count=5;
2499 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2500 }
2501 i=cmd_out();
2502 if (i>=0) break;
2503 msg(DBG_000,"cc_ReadCapacity: cmd_out: err %d\n", i);
2504 cc_ReadError();
2505 }
2506 if (j==0) return (i);
2507 if (fam1_drive) D_S[d].CDsize_frm=msf2blk(make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2])))+CD_MSF_OFFSET;
2508 else if (fam0_drive) D_S[d].CDsize_frm=make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2]));
2509 else if (fam2_drive) D_S[d].CDsize_frm=make32(make16(infobuf[0],infobuf[1]),make16(infobuf[2],infobuf[3]));
2510 D_S[d].diskstate_flags |= cd_size_bit;
2511 msg(DBG_000,"cc_ReadCapacity: %d frames.\n", D_S[d].CDsize_frm);
2512 return (0);
2513 }
2514
2515 static int cc_ReadTocDescr(void)
2516 {
2517 int i;
2518
2519 D_S[d].diskstate_flags &= ~toc_bit;
2520 clr_cmdbuf();
2521 if (fam1_drive)
2522 {
2523 drvcmd[0]=CMD1_DISKINFO;
2524 response_count=6;
2525 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2526 }
2527 else if (fam0L_drive)
2528 {
2529 drvcmd[0]=CMD0_DISKINFO;
2530 response_count=6;
2531 if(famL_drive)
2532 flags_cmd_out=f_putcmd;
2533 else
2534 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2535 }
2536 else if (fam2_drive)
2537 {
2538
2539 D_S[d].f_multisession=0;
2540 drvcmd[0]=CMD2_DISKINFO;
2541 drvcmd[1]=0x02;
2542 drvcmd[2]=0xAB;
2543 drvcmd[3]=0xFF;
2544 response_count=8;
2545 flags_cmd_out=f_putcmd;
2546 }
2547 else if (famT_drive)
2548 {
2549 D_S[d].f_multisession=0;
2550 response_count=12;
2551 drvcmd[0]=CMDT_DISKINFO;
2552 drvcmd[1]=0x02;
2553 drvcmd[6]=CDROM_LEADOUT;
2554 drvcmd[8]=response_count;
2555 drvcmd[9]=0x00;
2556 }
2557 i=cmd_out();
2558 if (i<0) return (i);
2559 if ((fam1_drive)||(fam2_drive)||(famL_drive)||(fam0_drive))
2560 D_S[d].xa_byte=infobuf[0];
2561 if (fam2_drive)
2562 {
2563 D_S[d].first_session=infobuf[1];
2564 D_S[d].last_session=infobuf[2];
2565 D_S[d].n_first_track=infobuf[3];
2566 D_S[d].n_last_track=infobuf[4];
2567 if (D_S[d].first_session!=D_S[d].last_session)
2568 {
2569 D_S[d].f_multisession=1;
2570 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7])));
2571 }
2572 #if 0
2573 if (D_S[d].first_session!=D_S[d].last_session)
2574 {
2575 if (D_S[d].last_session<=20)
2576 zwanzig=D_S[d].last_session+1;
2577 else zwanzig=20;
2578 for (count=D_S[d].first_session;count<zwanzig;count++)
2579 {
2580 drvcmd[0]=CMD2_DISKINFO;
2581 drvcmd[1]=0x02;
2582 drvcmd[2]=0xAB;
2583 drvcmd[3]=count;
2584 response_count=8;
2585 flags_cmd_out=f_putcmd;
2586 i=cmd_out();
2587 if (i<0) return (i);
2588 D_S[d].msf_multi_n[count]=make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7]));
2589 }
2590 D_S[d].diskstate_flags |= multisession_bit;
2591 }
2592 #endif
2593 drvcmd[0]=CMD2_DISKINFO;
2594 drvcmd[1]=0x02;
2595 drvcmd[2]=0xAA;
2596 drvcmd[3]=0xFF;
2597 response_count=5;
2598 flags_cmd_out=f_putcmd;
2599 i=cmd_out();
2600 if (i<0) return (i);
2601 D_S[d].size_msf=make32(make16(0,infobuf[2]),make16(infobuf[3],infobuf[4]));
2602 D_S[d].size_blk=msf2blk(D_S[d].size_msf);
2603 }
2604 else if (famT_drive)
2605 {
2606 D_S[d].size_msf=make32(make16(infobuf[8],infobuf[9]),make16(infobuf[10],infobuf[11]));
2607 D_S[d].size_blk=msf2blk(D_S[d].size_msf);
2608 D_S[d].CDsize_frm=D_S[d].size_blk+1;
2609 D_S[d].n_first_track=infobuf[2];
2610 D_S[d].n_last_track=infobuf[3];
2611 }
2612 else
2613 {
2614 D_S[d].n_first_track=infobuf[1];
2615 D_S[d].n_last_track=infobuf[2];
2616 D_S[d].size_msf=make32(make16(0,infobuf[3]),make16(infobuf[4],infobuf[5]));
2617 D_S[d].size_blk=msf2blk(D_S[d].size_msf);
2618 if (famL_drive) D_S[d].CDsize_frm=D_S[d].size_blk+1;
2619 }
2620 D_S[d].diskstate_flags |= toc_bit;
2621 msg(DBG_TOC,"TocDesc: %02X %02X %02X %08X\n",
2622 D_S[d].xa_byte,
2623 D_S[d].n_first_track,
2624 D_S[d].n_last_track,
2625 D_S[d].size_msf);
2626 return (0);
2627 }
2628
2629 static int cc_ReadTocEntry(int num)
2630 {
2631 int i;
2632
2633 clr_cmdbuf();
2634 if (fam1_drive)
2635 {
2636 drvcmd[0]=CMD1_READTOC;
2637 drvcmd[2]=num;
2638 response_count=8;
2639 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2640 }
2641 else if (fam2_drive)
2642 {
2643
2644 drvcmd[0]=CMD2_DISKINFO;
2645 drvcmd[1]=0x02;
2646 drvcmd[2]=num;
2647 response_count=5;
2648 flags_cmd_out=f_putcmd;
2649 }
2650 else if (fam0L_drive)
2651 {
2652 drvcmd[0]=CMD0_READTOC;
2653 drvcmd[1]=0x02;
2654 drvcmd[2]=num;
2655 response_count=8;
2656 if(famL_drive)
2657 flags_cmd_out=f_putcmd;
2658 else
2659 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2660 }
2661 else if (famT_drive)
2662 {
2663 response_count=12;
2664 drvcmd[0]=CMDT_DISKINFO;
2665 drvcmd[1]=0x02;
2666 drvcmd[6]=num;
2667 drvcmd[8]=response_count;
2668 drvcmd[9]=0x00;
2669 }
2670 i=cmd_out();
2671 if (i<0) return (i);
2672 if ((fam1_drive)||(famL_drive)||(fam0_drive))
2673 {
2674 D_S[d].TocEnt_nixbyte=infobuf[0];
2675 i=1;
2676 }
2677 else if (fam2_drive) i=0;
2678 else if (famT_drive)
2679 {
2680 i=5;
2681 }
2682 D_S[d].TocEnt_ctl_adr=swap_nibbles(infobuf[i++]);
2683 if ((fam1_drive)||(famL_drive)||(fam0_drive))
2684 {
2685 D_S[d].TocEnt_number=infobuf[i++];
2686 D_S[d].TocEnt_format=infobuf[i];
2687 }
2688 else D_S[d].TocEnt_number=num;
2689 if (fam1_drive) i=4;
2690 else if (fam0L_drive) i=5;
2691 else if (fam2_drive) i=2;
2692 else if (famT_drive) i=9;
2693 D_S[d].TocEnt_address=make32(make16(0,infobuf[i]),
2694 make16(infobuf[i+1],infobuf[i+2]));
2695 msg(DBG_TOC,"TocEntry: %02X %02X %02X %02X %08X\n",
2696 D_S[d].TocEnt_nixbyte, D_S[d].TocEnt_ctl_adr,
2697 D_S[d].TocEnt_number, D_S[d].TocEnt_format,
2698 D_S[d].TocEnt_address);
2699 return (0);
2700 }
2701
2702 static int cc_ReadPacket(void)
2703 {
2704 int i;
2705
2706 clr_cmdbuf();
2707 drvcmd[0]=CMD0_PACKET;
2708 drvcmd[1]=response_count;
2709 if(famL_drive) flags_cmd_out=f_putcmd;
2710 else if (fam01_drive)
2711 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2712 else if (fam2_drive) return (-1);
2713 else if (famT_drive)
2714 {
2715 return (-1);
2716 }
2717 i=cmd_out();
2718 return (i);
2719 }
2720
2721 static int convert_UPC(u_char *p)
2722 {
2723 int i;
2724
2725 p++;
2726 if (fam0L_drive) p[13]=0;
2727 for (i=0;i<7;i++)
2728 {
2729 if (fam1_drive) D_S[d].UPC_buf[i]=swap_nibbles(*p++);
2730 else if (fam0L_drive)
2731 {
2732 D_S[d].UPC_buf[i]=((*p++)<<4)&0xFF;
2733 D_S[d].UPC_buf[i] |= *p++;
2734 }
2735 else if (famT_drive)
2736 {
2737 return (-1);
2738 }
2739 else
2740 {
2741 return (-1);
2742 }
2743 }
2744 D_S[d].UPC_buf[6] &= 0xF0;
2745 return (0);
2746 }
2747
2748 static int cc_ReadUPC(void)
2749 {
2750 int i;
2751 #if TEST_UPC
2752 int block, checksum;
2753 #endif TEST_UPC
2754
2755 if (fam2_drive) return (0);
2756 if (famT_drive) return (0);
2757 #if 1
2758 if (fam0_drive) return (0);
2759 #endif 1
2760
2761 D_S[d].diskstate_flags &= ~upc_bit;
2762 #if TEST_UPC
2763 for (block=CD_MSF_OFFSET+1;block<CD_MSF_OFFSET+200;block++)
2764 {
2765 #endif TEST_UPC
2766 clr_cmdbuf();
2767 if (fam1_drive)
2768 {
2769 drvcmd[0]=CMD1_READ_UPC;
2770 #if TEST_UPC
2771 drvcmd[1]=(block>>16)&0xFF;
2772 drvcmd[2]=(block>>8)&0xFF;
2773 drvcmd[3]=block&0xFF;
2774 #endif TEST_UPC
2775 response_count=8;
2776 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2777 }
2778 else if (fam0L_drive)
2779 {
2780 drvcmd[0]=CMD0_READ_UPC;
2781 #if TEST_UPC
2782 drvcmd[2]=(block>>16)&0xFF;
2783 drvcmd[3]=(block>>8)&0xFF;
2784 drvcmd[4]=block&0xFF;
2785 #endif TEST_UPC
2786 response_count=0;
2787 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
2788 }
2789 else if (fam2_drive)
2790 {
2791 return (-1);
2792 }
2793 else if (famT_drive)
2794 {
2795 return (-1);
2796 }
2797 i=cmd_out();
2798 if (i<0)
2799 {
2800 msg(DBG_000,"cc_ReadUPC cmd_out: err %d\n", i);
2801 return (i);
2802 }
2803 if (fam0L_drive)
2804 {
2805 response_count=16;
2806 if (famL_drive) flags_cmd_out=f_putcmd;
2807 i=cc_ReadPacket();
2808 if (i<0)
2809 {
2810 msg(DBG_000,"cc_ReadUPC ReadPacket: err %d\n", i);
2811 return (i);
2812 }
2813 }
2814 #if TEST_UPC
2815 checksum=0;
2816 #endif TEST_UPC
2817 for (i=0;i<(fam1_drive?8:16);i++)
2818 {
2819 #if TEST_UPC
2820 checksum |= infobuf[i];
2821 #endif TEST_UPC
2822 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
2823 }
2824 msgbuf[i*3]=0;
2825 msg(DBG_UPC,"UPC info:%s\n", msgbuf);
2826 #if TEST_UPC
2827 if ((checksum&0x7F)!=0) break;
2828 }
2829 #endif TEST_UPC
2830 D_S[d].UPC_ctl_adr=0;
2831 if (fam1_drive) i=0;
2832 else i=2;
2833 if ((infobuf[i]&0x80)!=0)
2834 {
2835 convert_UPC(&infobuf[i]);
2836 D_S[d].UPC_ctl_adr = (D_S[d].TocEnt_ctl_adr & 0xF0) | 0x02;
2837 }
2838 for (i=0;i<7;i++)
2839 sprintf(&msgbuf[i*3], " %02X", D_S[d].UPC_buf[i]);
2840 sprintf(&msgbuf[i*3], " (%02X)", D_S[d].UPC_ctl_adr);
2841 msgbuf[i*3+5]=0;
2842 msg(DBG_UPC,"UPC code:%s\n", msgbuf);
2843 D_S[d].diskstate_flags |= upc_bit;
2844 return (0);
2845 }
2846
2847 static int cc_CheckMultiSession(void)
2848 {
2849 int i;
2850
2851 if (fam2_drive) return (0);
2852 D_S[d].f_multisession=0;
2853 D_S[d].lba_multi=0;
2854 if (fam0_drive) return (0);
2855 clr_cmdbuf();
2856 if (fam1_drive)
2857 {
2858 drvcmd[0]=CMD1_MULTISESS;
2859 response_count=6;
2860 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2861 i=cmd_out();
2862 if (i<0) return (i);
2863 if ((infobuf[0]&0x80)!=0)
2864 {
2865 D_S[d].f_multisession=1;
2866 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[1]),
2867 make16(infobuf[2],infobuf[3])));
2868 }
2869 }
2870 else if (famL_drive)
2871 {
2872 drvcmd[0]=CMDL_MULTISESS;
2873 drvcmd[1]=3;
2874 drvcmd[2]=1;
2875 response_count=8;
2876 flags_cmd_out=f_putcmd;
2877 i=cmd_out();
2878 if (i<0) return (i);
2879 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[5]),
2880 make16(infobuf[6],infobuf[7])));
2881 }
2882 else if (famT_drive)
2883 {
2884 response_count=12;
2885 drvcmd[0]=CMDT_DISKINFO;
2886 drvcmd[1]=0x02;
2887 drvcmd[6]=0;
2888 drvcmd[8]=response_count;
2889 drvcmd[9]=0x40;
2890 i=cmd_out();
2891 if (i<0) return (i);
2892 D_S[d].first_session=infobuf[2];
2893 D_S[d].last_session=infobuf[3];
2894 D_S[d].track_of_last_session=infobuf[6];
2895 if (D_S[d].first_session!=D_S[d].last_session)
2896 {
2897 D_S[d].f_multisession=1;
2898 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[9]),make16(infobuf[10],infobuf[11])));
2899 }
2900 }
2901 for (i=0;i<response_count;i++)
2902 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
2903 msgbuf[i*3]=0;
2904 msg(DBG_MUL,"MultiSession Info:%s (%d)\n", msgbuf, D_S[d].lba_multi);
2905 if (D_S[d].lba_multi>200)
2906 {
2907 D_S[d].f_multisession=1;
2908 msg(DBG_MUL,"MultiSession base: %06X\n", D_S[d].lba_multi);
2909 }
2910 return (0);
2911 }
2912
2913 #if FUTURE
2914 static int cc_SubChanInfo(int frame, int count, u_char *buffer)
2915
2916 {
2917 int i;
2918
2919 if (fam0L_drive) return (-ENOSYS);
2920 if (famT_drive)
2921 {
2922 return (-1);
2923 }
2924 #if 0
2925 if (D_S[d].audio_state!=audio_playing) return (-ENODATA);
2926 #endif
2927 clr_cmdbuf();
2928 drvcmd[0]=CMD1_SUBCHANINF;
2929 drvcmd[1]=(frame>>16)&0xFF;
2930 drvcmd[2]=(frame>>8)&0xFF;
2931 drvcmd[3]=frame&0xFF;
2932 drvcmd[5]=(count>>8)&0xFF;
2933 drvcmd[6]=count&0xFF;
2934 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
2935 cmd_type=READ_SC;
2936 D_S[d].frame_size=CD_FRAMESIZE_SUB;
2937 i=cmd_out();
2938 return (i);
2939 }
2940 #endif FUTURE
2941
2942 static void check_datarate(void)
2943 {
2944 int i=0;
2945
2946 msg(DBG_IOX,"check_datarate entered.\n");
2947 datarate=0;
2948 #if TEST_STI
2949 for (i=0;i<=1000;i++) printk(".");
2950 #endif
2951
2952 #if 1
2953 del_timer(&delay_timer);
2954 #endif
2955 delay_timer.expires=jiffies+11*HZ/10;
2956 timed_out_delay=0;
2957 add_timer(&delay_timer);
2958 #if 0
2959 msg(DBG_TIM,"delay timer started (11*HZ/10).\n");
2960 #endif
2961 do
2962 {
2963 i=inb(CDi_status);
2964 datarate++;
2965 #if 1
2966 if (datarate>0x6FFFFFFF) break;
2967 #endif 00000
2968 }
2969 while (!timed_out_delay);
2970 del_timer(&delay_timer);
2971 #if 0
2972 msg(DBG_TIM,"datarate: %04X\n", datarate);
2973 #endif
2974 if (datarate<65536) datarate=65536;
2975 maxtim16=datarate*16;
2976 maxtim04=datarate*4;
2977 maxtim02=datarate*2;
2978 maxtim_8=datarate/32;
2979 #if LONG_TIMING
2980 maxtim_data=datarate/100;
2981 #else
2982 maxtim_data=datarate/300;
2983 #endif LONG_TIMING
2984 #if 0
2985 msg(DBG_TIM,"maxtim_8 %d, maxtim_data %d.\n", maxtim_8, maxtim_data);
2986 #endif
2987 }
2988
2989 #if 0
2990 static int c2_ReadError(int fam)
2991 {
2992 int i;
2993
2994 clr_cmdbuf();
2995 response_count=9;
2996 clr_respo_buf(9);
2997 if (fam==1)
2998 {
2999 drvcmd[0]=CMD0_READ_ERR;
3000 i=do_cmd(f_putcmd|f_lopsta|f_getsta|f_ResponseStatus);
3001 }
3002 else if (fam==2)
3003 {
3004 drvcmd[0]=CMD2_READ_ERR;
3005 i=do_cmd(f_putcmd);
3006 }
3007 else return (-1);
3008 return (i);
3009 }
3010 #endif
3011
3012 static void ask_mail(void)
3013 {
3014 int i;
3015
3016 msg(DBG_INF, "please mail the following lines to emoenke@gwdg.de:\n");
3017 msg(DBG_INF, "%s\n", VERSION);
3018 msg(DBG_INF, "address %03X, type %s, drive %s (ID %d)\n",
3019 CDo_command, type, D_S[d].drive_model, D_S[d].drv_id);
3020 for (i=0;i<12;i++)
3021 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3022 msgbuf[i*3]=0;
3023 msg(DBG_INF,"infobuf =%s\n", msgbuf);
3024 for (i=0;i<12;i++)
3025 sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
3026 msgbuf[i*3]=0;
3027 msg(DBG_INF,"infobuf =%s\n", msgbuf);
3028 }
3029
3030 static int check_version(void)
3031 {
3032 int i, j, l;
3033 int teac_possible=0;
3034
3035 msg(DBG_INI,"check_version entered.\n");
3036 msg(DBG_TE2,"check_version: id=%d, d=%d.\n", D_S[d].drv_id, d);
3037 D_S[d].drv_type=0;
3038
3039
3040
3041 clr_cmdbuf();
3042 drvcmd[0]=CMD0_READ_ERR;
3043 response_count=9;
3044 flags_cmd_out=f_putcmd;
3045 i=cmd_out();
3046 if (i<0) msg(DBG_INI,"CMD0_READERR returns %d (ok anyway).\n",i);
3047
3048 clr_cmdbuf();
3049 for (i=0;i<12;i++) infobuf[i]=0;
3050 drvcmd[0]=CMD0_READ_VER;
3051 response_count=12;
3052 flags_cmd_out=f_putcmd;
3053 i=cmd_out();
3054 if (i<-1) msg(DBG_INI,"CMD0_READ_VER returns %d\n",i);
3055 if (i==-11) teac_possible++;
3056 j=0;
3057 for (i=0;i<12;i++) j+=infobuf[i];
3058 if (j)
3059 {
3060 for (i=0;i<12;i++)
3061 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3062 msgbuf[i*3]=0;
3063 msg(DBG_IDX,"infobuf =%s\n", msgbuf);
3064 msg(DBG_000,"infobuf =%s\n", msgbuf);
3065 for (i=0;i<12;i++)
3066 sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
3067 msgbuf[i*3]=0;
3068 msg(DBG_IDX,"infobuf =%s\n", msgbuf);
3069 msg(DBG_000,"infobuf =%s\n", msgbuf);
3070 }
3071 for (i=0;i<4;i++) if (infobuf[i]!=family1[i]) break;
3072 if (i==4)
3073 {
3074 D_S[d].drive_model[0]='C';
3075 D_S[d].drive_model[1]='R';
3076 D_S[d].drive_model[2]='-';
3077 D_S[d].drive_model[3]='5';
3078 D_S[d].drive_model[4]=infobuf[i++];
3079 D_S[d].drive_model[5]=infobuf[i++];
3080 D_S[d].drive_model[6]=0;
3081 D_S[d].drv_type=drv_fam1;
3082 }
3083 if (!D_S[d].drv_type)
3084 {
3085 for (i=0;i<8;i++) if (infobuf[i]!=family0[i]) break;
3086 if (i==8)
3087 {
3088 D_S[d].drive_model[0]='C';
3089 D_S[d].drive_model[1]='R';
3090 D_S[d].drive_model[2]='-';
3091 D_S[d].drive_model[3]='5';
3092 D_S[d].drive_model[4]='2';
3093 D_S[d].drive_model[5]='x';
3094 D_S[d].drive_model[6]=0;
3095 D_S[d].drv_type=drv_fam0;
3096 }
3097 }
3098 if (!D_S[d].drv_type)
3099 {
3100 for (i=0;i<8;i++) if (infobuf[i]!=familyL[i]) break;
3101 if (i==8)
3102 {
3103 for (j=0;j<8;j++)
3104 D_S[d].drive_model[j]=infobuf[j];
3105 D_S[d].drive_model[8]=0;
3106 D_S[d].drv_type=drv_famL;
3107 }
3108 }
3109 if (!D_S[d].drv_type)
3110 {
3111
3112 clr_cmdbuf();
3113 drvcmd[0]=CMD2_READ_ERR;
3114 response_count=9;
3115 flags_cmd_out=f_putcmd;
3116 i=cmd_out();
3117 if (i<0) msg(DBG_INI,"CMD2_READERR returns %d (ok anyway).\n",i);
3118 if (i<0) msg(DBG_000,"CMD2_READERR returns %d (ok anyway).\n",i);
3119
3120 clr_cmdbuf();
3121 for (i=0;i<12;i++) infobuf[i]=0;
3122 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
3123 #if 0
3124 OUT(CDo_reset,0);
3125 sbp_sleep(6*HZ);
3126 OUT(CDo_enable,D_S[d].drv_sel);
3127 #endif 0
3128 drvcmd[0]=CMD2_READ_VER;
3129 response_count=12;
3130 flags_cmd_out=f_putcmd;
3131 i=cmd_out();
3132 if (i<0) msg(DBG_INI,"CMD2_READ_VER returns %d\n",i);
3133 if (i==-7) teac_possible++;
3134 j=0;
3135 for (i=0;i<12;i++) j+=infobuf[i];
3136 if (j)
3137 {
3138 for (i=0;i<12;i++)
3139 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3140 msgbuf[i*3]=0;
3141 msg(DBG_IDX,"infobuf =%s\n", msgbuf);
3142 for (i=0;i<12;i++)
3143 sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
3144 msgbuf[i*3]=0;
3145 msg(DBG_IDX,"infobuf =%s\n", msgbuf);
3146 }
3147 if (i>=0)
3148 {
3149 for (i=0;i<5;i++) if (infobuf[i]!=family2[i]) break;
3150 if (i==5)
3151 {
3152 D_S[d].drive_model[0]='C';
3153 D_S[d].drive_model[1]='D';
3154 D_S[d].drive_model[2]='2';
3155 D_S[d].drive_model[3]='0';
3156 D_S[d].drive_model[4]='0';
3157 D_S[d].drive_model[5]=infobuf[i++];
3158 D_S[d].drive_model[6]=infobuf[i++];
3159 D_S[d].drive_model[7]=0;
3160 D_S[d].drv_type=drv_fam2;
3161 }
3162 }
3163 }
3164 if (!D_S[d].drv_type)
3165 {
3166
3167 msg(DBG_TEA,"teac_possible: %d\n",teac_possible);
3168 for (j=1;j<=((D_S[d].drv_id==0)?3:1);j++)
3169 {
3170 for (l=1;l<=((D_S[d].drv_id==0)?10:1);l++)
3171 {
3172 msg(DBG_TEA,"TEAC reset #%d-%d.\n", j, l);
3173 if (sbpro_type==1) OUT(CDo_reset,0);
3174 else
3175 {
3176 OUT(CDo_enable,D_S[d].drv_sel);
3177 OUT(CDo_sel_i_d,0);
3178 OUT(CDo_command,CMDT_RESET);
3179 for (i=0;i<9;i++) OUT(CDo_command,0);
3180 }
3181 sbp_sleep(5*HZ/10);
3182 OUT(CDo_enable,D_S[d].drv_sel);
3183 OUT(CDo_sel_i_d,0);
3184 i=inb(CDi_status);
3185 msg(DBG_TEA,"TEAC CDi_status: %02X.\n",i);
3186 #if 0
3187 if (i&s_not_result_ready) continue;
3188 #endif
3189 i=inb(CDi_info);
3190 msg(DBG_TEA,"TEAC CDi_info: %02X.\n",i);
3191 if (i==0x55) break;
3192 }
3193 if (i==0x55) break;
3194 }
3195 if (i==0x55)
3196 {
3197 msg(DBG_TEA,"TEAC drive found.\n");
3198 clr_cmdbuf();
3199 flags_cmd_out=f_putcmd;
3200 response_count=12;
3201 drvcmd[0]=CMDT_READ_VER;
3202 drvcmd[4]=response_count;
3203 for (i=0;i<12;i++) infobuf[i]=0;
3204 i=cmd_out_T();
3205 if (i!=0) msg(DBG_TEA,"cmd_out_T(CMDT_READ_VER) returns %d.\n",i);
3206 for (i=1;i<6;i++) if (infobuf[i]!=familyT[i-1]) break;
3207 if (i==6)
3208 {
3209 D_S[d].drive_model[0]='C';
3210 D_S[d].drive_model[1]='D';
3211 D_S[d].drive_model[2]='-';
3212 D_S[d].drive_model[3]='5';
3213 D_S[d].drive_model[4]='5';
3214 D_S[d].drive_model[5]=0;
3215 D_S[d].drv_type=drv_famT;
3216 }
3217 }
3218 }
3219 if (!D_S[d].drv_type)
3220 {
3221 msg(DBG_TEA,"no drive found at address %03X under ID %d.\n",CDo_command,D_S[d].drv_id);
3222 return (-522);
3223 }
3224 for (j=0;j<4;j++) D_S[d].firmware_version[j]=infobuf[i+j];
3225 if (famL_drive)
3226 {
3227 u_char lcs_firm_e1[]="A E1";
3228 u_char lcs_firm_f4[]="A4F4";
3229
3230 for (j=0;j<4;j++)
3231 if (D_S[d].firmware_version[j]!=lcs_firm_e1[j]) break;
3232 if (j==4) D_S[d].drv_type=drv_e1;
3233
3234 for (j=0;j<4;j++)
3235 if (D_S[d].firmware_version[j]!=lcs_firm_f4[j]) break;
3236 if (j==4) D_S[d].drv_type=drv_f4;
3237
3238 if (D_S[d].drv_type==drv_famL) ask_mail();
3239 }
3240 else if (famT_drive)
3241 {
3242 j=infobuf[4];
3243 if (j=='5')
3244 {
3245 D_S[d].firmware_version[0]=infobuf[7];
3246 D_S[d].firmware_version[1]=infobuf[8];
3247 D_S[d].firmware_version[2]=infobuf[10];
3248 D_S[d].firmware_version[3]=infobuf[11];
3249 }
3250 else
3251 {
3252 if (j!=0x15) ask_mail();
3253 D_S[d].firmware_version[0]='0';
3254 D_S[d].firmware_version[1]='.';
3255 D_S[d].firmware_version[2]='0'+(j>>4);
3256 D_S[d].firmware_version[3]='0'+(j&0x0f);
3257 }
3258 }
3259 else
3260 {
3261 j = (D_S[d].firmware_version[0] & 0x0F) * 100 +
3262 (D_S[d].firmware_version[2] & 0x0F) *10 +
3263 (D_S[d].firmware_version[3] & 0x0F);
3264 if (fam0_drive)
3265 {
3266 if (j<200) D_S[d].drv_type=drv_199;
3267 else if (j<201) D_S[d].drv_type=drv_200;
3268 else if (j<210) D_S[d].drv_type=drv_201;
3269 else if (j<211) D_S[d].drv_type=drv_210;
3270 else if (j<300) D_S[d].drv_type=drv_211;
3271 else if (j>=300) D_S[d].drv_type=drv_300;
3272 }
3273 else if (fam1_drive)
3274 {
3275 if (j<100) D_S[d].drv_type=drv_099;
3276 else
3277 {
3278 D_S[d].drv_type=drv_100;
3279 if ((j!=500)&&(j!=102)) ask_mail();
3280 }
3281 }
3282 else if (fam2_drive)
3283 {
3284 msg(DBG_INF,"new drive CD200 (%s)detected.\n", D_S[d].firmware_version);
3285 msg(DBG_INF,"CD200 is not fully supported yet - CD200F should work.\n");
3286 if ((j!=1)&&(j!=101)&&(j!=35)) ask_mail();
3287 }
3288 }
3289 msg(DBG_LCS,"drive type %02X\n",D_S[d].drv_type);
3290 msg(DBG_INI,"check_version done.\n");
3291 return (0);
3292 }
3293
3294 static void switch_drive(int i)
3295 {
3296 d=i;
3297 OUT(CDo_enable,D_S[d].drv_sel);
3298 msg(DBG_DID,"drive %d (ID=%d) activated.\n", i, D_S[d].drv_id);
3299 return;
3300 }
3301
3302 #ifdef PATH_CHECK
3303
3304
3305
3306 static int check_card(int port)
3307 {
3308 #undef N_RESPO
3309 #define N_RESPO 20
3310 int i, j, k;
3311 u_char response[N_RESPO];
3312 u_char save_port0;
3313 u_char save_port3;
3314
3315 msg(DBG_INI,"check_card entered.\n");
3316 save_port0=inb(port+0);
3317 save_port3=inb(port+3);
3318
3319 for (j=0;j<NR_SBPCD;j++)
3320 {
3321 OUT(port+3,j) ;
3322 OUT(port+0,CMD0_PATH_CHECK);
3323 for (i=10;i>0;i--) OUT(port+0,0);
3324 for (k=0;k<N_RESPO;k++) response[k]=0;
3325 for (k=0;k<N_RESPO;k++)
3326 {
3327 for (i=10000;i>0;i--)
3328 {
3329 if (inb(port+1)&s_not_result_ready) continue;
3330 response[k]=inb(port+0);
3331 break;
3332 }
3333 }
3334 for (i=0;i<N_RESPO;i++)
3335 sprintf(&msgbuf[i*3], " %02X", response[i]);
3336 msgbuf[i*3]=0;
3337 msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
3338 OUT(port+0,CMD0_PATH_CHECK);
3339 for (i=10;i>0;i--) OUT(port+0,0);
3340 for (k=0;k<N_RESPO;k++) response[k]=0xFF;
3341 for (k=0;k<N_RESPO;k++)
3342 {
3343 for (i=10000;i>0;i--)
3344 {
3345 if (inb(port+1)&s_not_result_ready) continue;
3346 response[k]=inb(port+0);
3347 break;
3348 }
3349 }
3350 for (i=0;i<N_RESPO;i++)
3351 sprintf(&msgbuf[i*3], " %02X", response[i]);
3352 msgbuf[i*3]=0;
3353 msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
3354
3355 if (response[0]==0xAA)
3356 if (response[1]==0x55)
3357 return (0);
3358 }
3359 for (j=0;j<NR_SBPCD;j++)
3360 {
3361 OUT(port+3,j) ;
3362 OUT(port+0,CMD2_READ_VER);
3363 for (i=10;i>0;i--) OUT(port+0,0);
3364 for (k=0;k<N_RESPO;k++) response[k]=0;
3365 for (k=0;k<N_RESPO;k++)
3366 {
3367 for (i=1000000;i>0;i--)
3368 {
3369 if (inb(port+1)&s_not_result_ready) continue;
3370 response[k]=inb(port+0);
3371 break;
3372 }
3373 }
3374 for (i=0;i<N_RESPO;i++)
3375 sprintf(&msgbuf[i*3], " %02X", response[i]);
3376 msgbuf[i*3]=0;
3377 msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
3378
3379 OUT(port+0,CMD2_READ_VER);
3380 for (i=10;i>0;i--) OUT(port+0,0);
3381 for (k=0;k<N_RESPO;k++) response[k]=0xFF;
3382 for (k=0;k<N_RESPO;k++)
3383 {
3384 for (i=1000000;i>0;i--)
3385 {
3386 if (inb(port+1)&s_not_result_ready) continue;
3387 response[k]=inb(port+0);
3388 break;
3389 }
3390 }
3391 for (i=0;i<N_RESPO;i++)
3392 sprintf(&msgbuf[i*3], " %02X", response[i]);
3393 msgbuf[i*3]=0;
3394 msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
3395
3396 if (response[0]==0xAA)
3397 if (response[1]==0x55)
3398 return (0);
3399 }
3400 OUT(port+0,save_port0);
3401 OUT(port+3,save_port3);
3402 return (0);
3403 }
3404 #endif PATH_CHECK
3405
3406
3407
3408
3409
3410 static int check_drives(void)
3411 {
3412 int i, j;
3413
3414 msg(DBG_INI,"check_drives entered.\n");
3415 ndrives=0;
3416 for (j=0;j<MAX_DRIVES;j++)
3417 {
3418 D_S[ndrives].drv_id=j;
3419 if (sbpro_type==1) D_S[ndrives].drv_sel=(j&0x01)<<1|(j&0x02)>>1;
3420 else D_S[ndrives].drv_sel=j;
3421 switch_drive(ndrives);
3422 msg(DBG_INI,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
3423 msg(DBG_000,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
3424 i=check_version();
3425 if (i<0) msg(DBG_INI,"check_version returns %d.\n",i);
3426 else
3427 {
3428 D_S[d].drv_options=drv_pattern[j];
3429 if (fam0L_drive) D_S[d].drv_options&=~(speed_auto|speed_300|speed_150);
3430 msg(DBG_INF, "Drive %d (ID=%d): %.9s (%.4s) at 0x%03X (type %d)\n",
3431 d,
3432 D_S[d].drv_id,
3433 D_S[d].drive_model,
3434 D_S[d].firmware_version,
3435 CDo_command,
3436 sbpro_type);
3437 ndrives++;
3438 }
3439 }
3440 for (j=ndrives;j<NR_SBPCD;j++) D_S[j].drv_id=-1;
3441 if (ndrives==0) return (-1);
3442 return (0);
3443 }
3444
3445 #if FUTURE
3446
3447
3448
3449 static int obey_audio_state(u_char audio_state, u_char func,u_char subfunc)
3450 {
3451 switch (audio_state)
3452 {
3453 case aud_11:
3454 case audx11:
3455 switch (func)
3456 {
3457 case cmd_07:
3458 case cmd_0d:
3459 case cmd_0e:
3460 case cmd_0c:
3461 return (1);
3462 case cmd_03:
3463 switch (subfunc)
3464
3465 {
3466 case cxi_00:
3467 case cxi_06:
3468 case cxi_09:
3469 return (1);
3470 default:
3471 return (ERROR15);
3472 }
3473 return (1);
3474 default:
3475 return (ERROR15);
3476 }
3477 return (1);
3478 case aud_12:
3479 case audx12:
3480 return (1);
3481 default:
3482 return (2);
3483 }
3484 }
3485
3486
3487
3488
3489
3490
3491 static int check_allowed1(u_char func1, u_char func2)
3492 {
3493 #if 000
3494 if (func1==ioctl_o) return (0);
3495 if (func1==read_long) return (-1);
3496 if (func1==read_long_prefetch) return (-1);
3497 if (func1==seek) return (-1);
3498 if (func1==audio_play) return (-1);
3499 if (func1==audio_pause) return (-1);
3500 if (func1==audio_resume) return (-1);
3501 if (func1!=ioctl_i) return (0);
3502 if (func2==tell_SubQ_run_tot) return (-1);
3503 if (func2==tell_cdsize) return (-1);
3504 if (func2==tell_TocDescrip) return (-1);
3505 if (func2==tell_TocEntry) return (-1);
3506 if (func2==tell_subQ_info) return (-1);
3507 if (fam1_drive) if (func2==tell_SubChanInfo) return (-1);
3508 if (func2==tell_UPC) return (-1);
3509 #else
3510 return (0);
3511 #endif 000
3512 }
3513
3514 static int check_allowed2(u_char func1, u_char func2)
3515 {
3516 #if 000
3517 if (func1==read_long) return (-1);
3518 if (func1==read_long_prefetch) return (-1);
3519 if (func1==seek) return (-1);
3520 if (func1==audio_play) return (-1);
3521 if (func1!=ioctl_o) return (0);
3522 if (fam1_drive)
3523 {
3524 if (func2==EjectDisk) return (-1);
3525 if (func2==CloseTray) return (-1);
3526 }
3527 #else
3528 return (0);
3529 #endif 000
3530 }
3531
3532 static int check_allowed3(u_char func1, u_char func2)
3533 {
3534 #if 000
3535 if (func1==ioctl_i)
3536 {
3537 if (func2==tell_address) return (0);
3538 if (func2==tell_capabiliti) return (0);
3539 if (func2==tell_CD_changed) return (0);
3540 if (fam0L_drive) if (func2==tell_SubChanInfo) return (0);
3541 return (-1);
3542 }
3543 if (func1==ioctl_o)
3544 {
3545 if (func2==DriveReset) return (0);
3546 if (fam0L_drive)
3547 {
3548 if (func2==EjectDisk) return (0);
3549 if (func2==LockDoor) return (0);
3550 if (func2==CloseTray) return (0);
3551 }
3552 return (-1);
3553 }
3554 if (func1==flush_input) return (-1);
3555 if (func1==read_long) return (-1);
3556 if (func1==read_long_prefetch) return (-1);
3557 if (func1==seek) return (-1);
3558 if (func1==audio_play) return (-1);
3559 if (func1==audio_pause) return (-1);
3560 if (func1==audio_resume) return (-1);
3561 #else
3562 return (0);
3563 #endif 000
3564 }
3565
3566 static int seek_pos_audio_end(void)
3567 {
3568 int i;
3569
3570 i=msf2blk(D_S[d].pos_audio_end)-1;
3571 if (i<0) return (-1);
3572 i=cc_Seek(i,0);
3573 return (i);
3574 }
3575 #endif FUTURE
3576
3577 static int ReadToC(void)
3578 {
3579 int i, j;
3580 D_S[d].diskstate_flags &= ~toc_bit;
3581 D_S[d].ored_ctl_adr=0;
3582 for (j=D_S[d].n_first_track;j<=D_S[d].n_last_track;j++)
3583 {
3584 i=cc_ReadTocEntry(j);
3585 if (i<0)
3586 {
3587 msg(DBG_INF,"cc_ReadTocEntry(%d) returns %d.\n",j,i);
3588 return (i);
3589 }
3590 D_S[d].TocBuffer[j].nixbyte=D_S[d].TocEnt_nixbyte;
3591 D_S[d].TocBuffer[j].ctl_adr=D_S[d].TocEnt_ctl_adr;
3592 D_S[d].TocBuffer[j].number=D_S[d].TocEnt_number;
3593 D_S[d].TocBuffer[j].format=D_S[d].TocEnt_format;
3594 D_S[d].TocBuffer[j].address=D_S[d].TocEnt_address;
3595 D_S[d].ored_ctl_adr |= D_S[d].TocEnt_ctl_adr;
3596 }
3597
3598 D_S[d].TocBuffer[j].nixbyte=0;
3599 D_S[d].TocBuffer[j].ctl_adr=0;
3600 D_S[d].TocBuffer[j].number=CDROM_LEADOUT;
3601 D_S[d].TocBuffer[j].format=0;
3602 D_S[d].TocBuffer[j].address=D_S[d].size_msf;
3603
3604 D_S[d].diskstate_flags |= toc_bit;
3605 return (0);
3606 }
3607
3608 static int DiskInfo(void)
3609 {
3610 int i, j;
3611
3612 D_S[d].mode=READ_M1;
3613
3614 #undef LOOP_COUNT
3615 #define LOOP_COUNT 10
3616
3617 msg(DBG_000,"DiskInfo entered.\n");
3618 for (j=1;j<LOOP_COUNT;j++)
3619 {
3620 i=SetSpeed();
3621 if (i<0)
3622 {
3623 msg(DBG_INF,"DiskInfo: SetSpeed returns %d\n", i);
3624 continue;
3625 }
3626 i=cc_ModeSense();
3627 if (i<0)
3628 {
3629 msg(DBG_INF,"DiskInfo: cc_ModeSense returns %d\n", i);
3630 continue;
3631 }
3632 i=cc_ReadCapacity();
3633 if (i>=0) break;
3634 msg(DBG_INF,"DiskInfo: ReadCapacity #%d returns %d\n", j, i);
3635 i=cc_DriveReset();
3636 }
3637 if (j==LOOP_COUNT) return (-33);
3638
3639 i=cc_ReadTocDescr();
3640 if (i<0)
3641 {
3642 msg(DBG_INF,"DiskInfo: ReadTocDescr returns %d\n", i);
3643 return (i);
3644 }
3645 i=ReadToC();
3646 if (i<0)
3647 {
3648 msg(DBG_INF,"DiskInfo: ReadToC returns %d\n", i);
3649 return (i);
3650 }
3651 i=cc_CheckMultiSession();
3652 if (i<0)
3653 {
3654 msg(DBG_INF,"DiskInfo: cc_CheckMultiSession returns %d\n", i);
3655 return (i);
3656 }
3657 if (D_S[d].f_multisession) D_S[d].sbp_bufsiz=1;
3658 else D_S[d].sbp_bufsiz=SBP_BUFFER_FRAMES;
3659 i=cc_ReadTocEntry(D_S[d].n_first_track);
3660 if (i<0)
3661 {
3662 msg(DBG_INF,"DiskInfo: cc_ReadTocEntry(1) returns %d\n", i);
3663 return (i);
3664 }
3665 i=cc_ReadUPC();
3666 if (i<0) msg(DBG_INF,"DiskInfo: cc_ReadUPC returns %d\n", i);
3667 if ((fam0L_drive) && (D_S[d].xa_byte==0x20))
3668 {
3669
3670 cc_ModeSelect(CD_FRAMESIZE_RAW1);
3671 cc_ModeSense();
3672 }
3673 if (famT_drive) cc_prep_mode_T();
3674 msg(DBG_000,"DiskInfo done.\n");
3675 return (0);
3676 }
3677
3678 #if FUTURE
3679
3680
3681
3682
3683 static int prepare(u_char func, u_char subfunc)
3684 {
3685 int i;
3686
3687 if (fam0L_drive)
3688 {
3689 i=inb(CDi_status);
3690 if (i&s_attention) GetStatus();
3691 }
3692 else if (fam1_drive) GetStatus();
3693 else if (fam2_drive) GetStatus();
3694 else if (famT_drive) GetStatus();
3695 if (D_S[d].CD_changed==0xFF)
3696 {
3697 D_S[d].diskstate_flags=0;
3698 D_S[d].audio_state=0;
3699 if (!st_diskok)
3700 {
3701 i=check_allowed1(func,subfunc);
3702 if (i<0) return (-2);
3703 }
3704 else
3705 {
3706 i=check_allowed3(func,subfunc);
3707 if (i<0)
3708 {
3709 D_S[d].CD_changed=1;
3710 return (-15);
3711 }
3712 }
3713 }
3714 else
3715 {
3716 if (!st_diskok)
3717 {
3718 D_S[d].diskstate_flags=0;
3719 D_S[d].audio_state=0;
3720 i=check_allowed1(func,subfunc);
3721 if (i<0) return (-2);
3722 }
3723 else
3724 {
3725 if (st_busy)
3726 {
3727 if (D_S[d].audio_state!=audio_pausing)
3728 {
3729 i=check_allowed2(func,subfunc);
3730 if (i<0) return (-2);
3731 }
3732 }
3733 else
3734 {
3735 if (D_S[d].audio_state==audio_playing) seek_pos_audio_end();
3736 D_S[d].audio_state=0;
3737 }
3738 if (!frame_size_valid)
3739 {
3740 i=DiskInfo();
3741 if (i<0)
3742 {
3743 D_S[d].diskstate_flags=0;
3744 D_S[d].audio_state=0;
3745 i=check_allowed1(func,subfunc);
3746 if (i<0) return (-2);
3747 }
3748 }
3749 }
3750 }
3751 return (0);
3752 }
3753 #endif FUTURE
3754
3755
3756
3757
3758
3759 static int sbp_status(void)
3760 {
3761 int st;
3762
3763 st=ResponseStatus();
3764 if (st<0)
3765 {
3766 msg(DBG_INF,"sbp_status: timeout.\n");
3767 return (0);
3768 }
3769
3770 if (!st_spinning) msg(DBG_SPI,"motor got off - ignoring.\n");
3771
3772 if (st_check)
3773 {
3774 msg(DBG_INF,"st_check detected - retrying.\n");
3775 return (0);
3776 }
3777 if (!st_door_closed)
3778 {
3779 msg(DBG_INF,"door is open - retrying.\n");
3780 return (0);
3781 }
3782 if (!st_caddy_in)
3783 {
3784 msg(DBG_INF,"disk removed - retrying.\n");
3785 return (0);
3786 }
3787 if (!st_diskok)
3788 {
3789 msg(DBG_INF,"!st_diskok detected - retrying.\n");
3790 return (0);
3791 }
3792 if (st_busy)
3793 {
3794 msg(DBG_INF,"st_busy detected - retrying.\n");
3795 return (0);
3796 }
3797 return (1);
3798 }
3799
3800
3801
3802
3803
3804
3805
3806 static int sbpcd_ioctl(struct inode *inode, struct file *file, u_int cmd,
3807 u_long arg)
3808 {
3809 int i, st;
3810
3811 msg(DBG_IO2,"ioctl(%d, 0x%08lX, 0x%08lX)\n",
3812 MINOR(inode->i_rdev), cmd, arg);
3813 if (!inode) return (-EINVAL);
3814 i=MINOR(inode->i_rdev);
3815 if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
3816 {
3817 msg(DBG_INF, "ioctl: bad device: %04X\n", inode->i_rdev);
3818 return (-ENXIO);
3819 }
3820 if (d!=i) switch_drive(i);
3821
3822 #if 0
3823 st=GetStatus();
3824 if (st<0) return (-EIO);
3825
3826 if (!toc_valid)
3827 {
3828 i=DiskInfo();
3829 if (i<0) return (-EIO);
3830 }
3831 #endif
3832
3833 msg(DBG_IO2,"ioctl: device %d, request %04X\n",i,cmd);
3834 switch (cmd)
3835 {
3836 case DDIOCSDBG:
3837 if (!suser()) return (-EPERM);
3838 i=sbpcd_dbg_ioctl(arg,1);
3839 return (i);
3840
3841 case CDROMPAUSE:
3842 msg(DBG_IOC,"ioctl: CDROMPAUSE entered.\n");
3843
3844
3845
3846
3847 switch (D_S[d].audio_state)
3848 {
3849 case audio_playing:
3850 if (famL_drive) i=cc_ReadSubQ();
3851 else i=cc_Pause_Resume(1);
3852 if (i<0) return (-EIO);
3853 if (famL_drive) i=cc_Pause_Resume(1);
3854 else i=cc_ReadSubQ();
3855 if (i<0) return (-EIO);
3856 D_S[d].pos_audio_start=D_S[d].SubQ_run_tot;
3857 D_S[d].audio_state=audio_pausing;
3858 return (0);
3859 case audio_pausing:
3860 i=cc_Seek(D_S[d].pos_audio_start,1);
3861 if (i<0) return (-EIO);
3862 return (0);
3863 default:
3864 return (-EINVAL);
3865 }
3866
3867 case CDROMRESUME:
3868 msg(DBG_IOC,"ioctl: CDROMRESUME entered.\n");
3869
3870
3871
3872 if (D_S[d].audio_state!=audio_pausing) return -EINVAL;
3873 if (famL_drive)
3874 i=cc_PlayAudio(D_S[d].pos_audio_start,
3875 D_S[d].pos_audio_end);
3876 else i=cc_Pause_Resume(3);
3877 if (i<0) return (-EIO);
3878 D_S[d].audio_state=audio_playing;
3879 return (0);
3880
3881 case CDROMPLAYMSF:
3882 msg(DBG_IOC,"ioctl: CDROMPLAYMSF entered.\n");
3883 if (D_S[d].audio_state==audio_playing)
3884 {
3885 i=cc_Pause_Resume(1);
3886 if (i<0) return (-EIO);
3887 i=cc_ReadSubQ();
3888 if (i<0) return (-EIO);
3889 D_S[d].pos_audio_start=D_S[d].SubQ_run_tot;
3890 i=cc_Seek(D_S[d].pos_audio_start,1);
3891 }
3892 st=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_msf));
3893 if (st) return (st);
3894 memcpy_fromfs(&msf, (void *) arg, sizeof(struct cdrom_msf));
3895
3896 D_S[d].pos_audio_start = (msf.cdmsf_min0<<16) |
3897 (msf.cdmsf_sec0<<8) |
3898 msf.cdmsf_frame0;
3899 D_S[d].pos_audio_end = (msf.cdmsf_min1<<16) |
3900 (msf.cdmsf_sec1<<8) |
3901 msf.cdmsf_frame1;
3902 msg(DBG_IOX,"ioctl: CDROMPLAYMSF %08X %08X\n",
3903 D_S[d].pos_audio_start,D_S[d].pos_audio_end);
3904 i=cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end);
3905 msg(DBG_IOC,"ioctl: cc_PlayAudio returns %d\n",i);
3906 #if 0
3907 if (i<0) return (-EIO);
3908 #endif 0
3909 D_S[d].audio_state=audio_playing;
3910 return (0);
3911
3912 case CDROMPLAYTRKIND:
3913 msg(DBG_IOC,"ioctl: CDROMPLAYTRKIND entered.\n");
3914 if (D_S[d].audio_state==audio_playing)
3915 {
3916 msg(DBG_IOX,"CDROMPLAYTRKIND: already audio_playing.\n");
3917 return (0);
3918 return (-EINVAL);
3919 }
3920 st=verify_area(VERIFY_READ,(void *) arg,sizeof(struct cdrom_ti));
3921 if (st<0)
3922 {
3923 msg(DBG_IOX,"CDROMPLAYTRKIND: verify_area error.\n");
3924 return (st);
3925 }
3926 memcpy_fromfs(&ti,(void *) arg,sizeof(struct cdrom_ti));
3927 msg(DBG_IOX,"ioctl: trk0: %d, ind0: %d, trk1:%d, ind1:%d\n",
3928 ti.cdti_trk0,ti.cdti_ind0,ti.cdti_trk1,ti.cdti_ind1);
3929 if (ti.cdti_trk0<D_S[d].n_first_track) return (-EINVAL);
3930 if (ti.cdti_trk0>D_S[d].n_last_track) return (-EINVAL);
3931 if (ti.cdti_trk1<ti.cdti_trk0) ti.cdti_trk1=ti.cdti_trk0;
3932 if (ti.cdti_trk1>D_S[d].n_last_track) ti.cdti_trk1=D_S[d].n_last_track;
3933 D_S[d].pos_audio_start=D_S[d].TocBuffer[ti.cdti_trk0].address;
3934 D_S[d].pos_audio_end=D_S[d].TocBuffer[ti.cdti_trk1+1].address;
3935 i=cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end);
3936 #if 0
3937 if (i<0) return (-EIO);
3938 #endif 0
3939 D_S[d].audio_state=audio_playing;
3940 return (0);
3941
3942 case CDROMREADTOCHDR:
3943 msg(DBG_IOC,"ioctl: CDROMREADTOCHDR entered.\n");
3944 tochdr.cdth_trk0=D_S[d].n_first_track;
3945 tochdr.cdth_trk1=D_S[d].n_last_track;
3946 st=verify_area(VERIFY_WRITE, (void *) arg, sizeof(struct cdrom_tochdr));
3947 if (st) return (st);
3948 memcpy_tofs((void *) arg, &tochdr, sizeof(struct cdrom_tochdr));
3949 return (0);
3950
3951 case CDROMREADTOCENTRY:
3952 msg(DBG_IOC,"ioctl: CDROMREADTOCENTRY entered.\n");
3953 st=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_tocentry));
3954 if (st) return (st);
3955 memcpy_fromfs(&tocentry, (void *) arg, sizeof(struct cdrom_tocentry));
3956 i=tocentry.cdte_track;
3957 if (i==CDROM_LEADOUT) i=D_S[d].n_last_track+1;
3958 else if (i<D_S[d].n_first_track||i>D_S[d].n_last_track) return (-EINVAL);
3959 tocentry.cdte_adr=D_S[d].TocBuffer[i].ctl_adr&0x0F;
3960 tocentry.cdte_ctrl=(D_S[d].TocBuffer[i].ctl_adr>>4)&0x0F;
3961 tocentry.cdte_datamode=D_S[d].TocBuffer[i].format;
3962 if (tocentry.cdte_format==CDROM_MSF)
3963 {
3964 tocentry.cdte_addr.msf.minute=(D_S[d].TocBuffer[i].address>>16)&0x00FF;
3965 tocentry.cdte_addr.msf.second=(D_S[d].TocBuffer[i].address>>8)&0x00FF;
3966 tocentry.cdte_addr.msf.frame=D_S[d].TocBuffer[i].address&0x00FF;
3967 }
3968 else if (tocentry.cdte_format==CDROM_LBA)
3969 tocentry.cdte_addr.lba=msf2blk(D_S[d].TocBuffer[i].address);
3970 else return (-EINVAL);
3971 st=verify_area(VERIFY_WRITE,(void *) arg, sizeof(struct cdrom_tocentry));
3972 if (st) return (st);
3973 memcpy_tofs((void *) arg, &tocentry, sizeof(struct cdrom_tocentry));
3974 return (0);
3975
3976 case CDROMRESET:
3977 msg(DBG_IOC,"ioctl: CDROMRESET entered.\n");
3978 i=DriveReset();
3979 D_S[d].audio_state=0;
3980 return (i);
3981
3982 case CDROMSTOP:
3983 msg(DBG_IOC,"ioctl: CDROMSTOP entered.\n");
3984 i=cc_Pause_Resume(1);
3985 D_S[d].audio_state=0;
3986 return (i);
3987
3988 case CDROMSTART:
3989 msg(DBG_IOC,"ioctl: CDROMSTART entered.\n");
3990 cc_SpinUp();
3991 D_S[d].audio_state=0;
3992 return (0);
3993
3994 case CDROMEJECT:
3995 msg(DBG_IOC,"ioctl: CDROMEJECT entered.\n");
3996 if (fam0_drive) return (0);
3997 if (D_S[d].open_count>1) return (-EBUSY);
3998 i=UnLockDoor();
3999 D_S[d].open_count=-9;
4000 i=cc_SpinDown();
4001 msg(DBG_IOX,"ioctl: cc_SpinDown returned %d.\n", i);
4002 msg(DBG_TEA,"ioctl: cc_SpinDown returned %d.\n", i);
4003 if (i<0) return (-EIO);
4004 D_S[d].CD_changed=0xFF;
4005 D_S[d].diskstate_flags=0;
4006 D_S[d].audio_state=0;
4007 return (0);
4008
4009 case CDROMEJECT_SW:
4010 msg(DBG_IOC,"ioctl: CDROMEJECT_SW entered.\n");
4011 if (fam0_drive) return (0);
4012 D_S[d].f_eject=arg;
4013 return (0);
4014
4015 case CDROMVOLCTRL:
4016 msg(DBG_IOC,"ioctl: CDROMVOLCTRL entered.\n");
4017 st=verify_area(VERIFY_READ,(void *) arg,sizeof(volctrl));
4018 if (st) return (st);
4019 memcpy_fromfs(&volctrl,(char *) arg,sizeof(volctrl));
4020 D_S[d].vol_chan0=0;
4021 D_S[d].vol_ctrl0=volctrl.channel0;
4022 D_S[d].vol_chan1=1;
4023 D_S[d].vol_ctrl1=volctrl.channel1;
4024 i=cc_SetVolume();
4025 return (0);
4026
4027 case CDROMVOLREAD:
4028 msg(DBG_IOC,"ioctl: CDROMVOLREAD entered.\n");
4029 st=verify_area(VERIFY_WRITE,(void *)arg,sizeof(volctrl));
4030 if (st) return (st);
4031 st=cc_GetVolume();
4032 if (st<0) return (st);
4033 volctrl.channel0=D_S[d].vol_ctrl0;
4034 volctrl.channel1=D_S[d].vol_ctrl1;
4035 volctrl.channel2=0;
4036 volctrl.channel2=0;
4037 memcpy_tofs((void *)arg,&volctrl,sizeof(volctrl));
4038 return (0);
4039
4040 case CDROMSUBCHNL:
4041 msg(DBG_IOS,"ioctl: CDROMSUBCHNL entered.\n");
4042 if ((st_spinning)||(!subq_valid)) { i=cc_ReadSubQ();
4043 if (i<0) return (-EIO);
4044 }
4045 st=verify_area(VERIFY_WRITE, (void *) arg, sizeof(struct cdrom_subchnl));
4046 if (st) return (st);
4047 st=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_subchnl));
4048 if (st) return (st);
4049 memcpy_fromfs(&SC, (void *) arg, sizeof(struct cdrom_subchnl));
4050 switch (D_S[d].audio_state)
4051 {
4052 case audio_playing:
4053 SC.cdsc_audiostatus=CDROM_AUDIO_PLAY;
4054 break;
4055 case audio_pausing:
4056 SC.cdsc_audiostatus=CDROM_AUDIO_PAUSED;
4057 break;
4058 default:
4059 SC.cdsc_audiostatus=CDROM_AUDIO_NO_STATUS;
4060 break;
4061 }
4062 SC.cdsc_adr=D_S[d].SubQ_ctl_adr;
4063 SC.cdsc_ctrl=D_S[d].SubQ_ctl_adr>>4;
4064 SC.cdsc_trk=bcd2bin(D_S[d].SubQ_trk);
4065 SC.cdsc_ind=bcd2bin(D_S[d].SubQ_pnt_idx);
4066 if (SC.cdsc_format==CDROM_LBA)
4067 {
4068 SC.cdsc_absaddr.lba=msf2blk(D_S[d].SubQ_run_tot);
4069 SC.cdsc_reladdr.lba=msf2blk(D_S[d].SubQ_run_trk);
4070 }
4071 else
4072 {
4073 SC.cdsc_absaddr.msf.minute=(D_S[d].SubQ_run_tot>>16)&0x00FF;
4074 SC.cdsc_absaddr.msf.second=(D_S[d].SubQ_run_tot>>8)&0x00FF;
4075 SC.cdsc_absaddr.msf.frame=D_S[d].SubQ_run_tot&0x00FF;
4076 SC.cdsc_reladdr.msf.minute=(D_S[d].SubQ_run_trk>>16)&0x00FF;
4077 SC.cdsc_reladdr.msf.second=(D_S[d].SubQ_run_trk>>8)&0x00FF;
4078 SC.cdsc_reladdr.msf.frame=D_S[d].SubQ_run_trk&0x00FF;
4079 }
4080 memcpy_tofs((void *) arg, &SC, sizeof(struct cdrom_subchnl));
4081 msg(DBG_IOS,"CDROMSUBCHNL: %1X %02X %08X %08X %02X %02X %06X %06X\n",
4082 SC.cdsc_format,SC.cdsc_audiostatus,
4083 SC.cdsc_adr,SC.cdsc_ctrl,
4084 SC.cdsc_trk,SC.cdsc_ind,
4085 SC.cdsc_absaddr,SC.cdsc_reladdr);
4086 return (0);
4087
4088 case CDROMREADMODE1:
4089 msg(DBG_IOC,"ioctl: CDROMREADMODE1 requested.\n");
4090 cc_ModeSelect(CD_FRAMESIZE);
4091 cc_ModeSense();
4092 D_S[d].mode=READ_M1;
4093 return (0);
4094
4095 case CDROMREADMODE2:
4096 msg(DBG_IOC,"ioctl: CDROMREADMODE2 requested.\n");
4097 cc_ModeSelect(CD_FRAMESIZE_RAW1);
4098 cc_ModeSense();
4099 D_S[d].mode=READ_M2;
4100 return (0);
4101
4102 case CDROMAUDIOBUFSIZ:
4103 msg(DBG_IOC,"ioctl: CDROMAUDIOBUFSIZ entered.\n");
4104 #ifdef MODULE
4105 if (D_S[d].sbp_audsiz>0)
4106 vfree(D_S[d].aud_buf);
4107 #endif MODULE
4108 D_S[d].aud_buf=NULL;
4109 D_S[d].sbp_audsiz=arg;
4110 if (D_S[d].sbp_audsiz>0)
4111 {
4112 D_S[d].aud_buf=(u_char *) vmalloc(D_S[d].sbp_audsiz*CD_FRAMESIZE_RAW);
4113 if (D_S[d].aud_buf==NULL)
4114 {
4115 msg(DBG_INF,"audio buffer (%d frames) not available.\n",D_S[d].sbp_audsiz);
4116 D_S[d].sbp_audsiz=0;
4117 }
4118 else msg(DBG_INF,"audio buffer size: %d frames.\n",D_S[d].sbp_audsiz);
4119 }
4120 return (D_S[d].sbp_audsiz);
4121
4122 case CDROMREADAUDIO:
4123 {
4124 int i=0, j=0, frame, block;
4125 u_int try=0;
4126 u_long timeout;
4127 u_char *p;
4128 u_int data_tries = 0;
4129 u_int data_waits = 0;
4130 u_int data_retrying = 0;
4131 int status_tries;
4132 int error_flag;
4133
4134 msg(DBG_IOC,"ioctl: CDROMREADAUDIO entered.\n");
4135 if (fam0_drive) return (-EINVAL);
4136 if (famL_drive) return (-EINVAL);
4137 if (fam2_drive) return (-EINVAL);
4138 if (famT_drive) return (-EINVAL);
4139 if (D_S[d].aud_buf==NULL) return (-EINVAL);
4140 i=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_read_audio));
4141 if (i) return (i);
4142 memcpy_fromfs(&read_audio, (void *) arg, sizeof(struct cdrom_read_audio));
4143 if (read_audio.nframes>D_S[d].sbp_audsiz) return (-EINVAL);
4144 i=verify_area(VERIFY_WRITE, read_audio.buf,
4145 read_audio.nframes*CD_FRAMESIZE_RAW);
4146 if (i) return (i);
4147
4148 if (read_audio.addr_format==CDROM_MSF)
4149 block=msf2lba(&read_audio.addr.msf.minute);
4150 else if (read_audio.addr_format==CDROM_LBA)
4151 block=read_audio.addr.lba;
4152 else return (-EINVAL);
4153 i=cc_SetSpeed(speed_150,0,0);
4154 if (i) msg(DBG_AUD,"read_audio: SetSpeed error %d\n", i);
4155 msg(DBG_AUD,"read_audio: lba: %d, msf: %06X\n",
4156 block, blk2msf(block));
4157 msg(DBG_AUD,"read_audio: before cc_ReadStatus.\n");
4158 while (busy_data) sbp_sleep(HZ/10);
4159 busy_audio=1;
4160 error_flag=0;
4161 for (data_tries=5; data_tries>0; data_tries--)
4162 {
4163 msg(DBG_AUD,"data_tries=%d ...\n", data_tries);
4164 D_S[d].mode=READ_AU;
4165 cc_ModeSelect(CD_FRAMESIZE_RAW);
4166 cc_ModeSense();
4167 for (status_tries=3; status_tries > 0; status_tries--)
4168 {
4169 flags_cmd_out |= f_respo3;
4170 cc_ReadStatus();
4171 if (sbp_status() != 0) break;
4172 sbp_sleep(1);
4173 }
4174 if (status_tries == 0)
4175 {
4176 msg(DBG_AUD,"read_audio: sbp_status: failed after 3 tries.\n");
4177 continue;
4178 }
4179 msg(DBG_AUD,"read_audio: sbp_status: ok.\n");
4180
4181 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
4182 if (fam0L_drive)
4183 {
4184 flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
4185 cmd_type=READ_M2;
4186 drvcmd[0]=CMD0_READ_XA;
4187 drvcmd[1]=(block>>16)&0x000000ff;
4188 drvcmd[2]=(block>>8)&0x000000ff;
4189 drvcmd[3]=block&0x000000ff;
4190 drvcmd[4]=0;
4191 drvcmd[5]=read_audio.nframes;
4192 drvcmd[6]=0;
4193 }
4194 else if (fam1_drive)
4195 {
4196 drvcmd[0]=CMD1_READ;
4197 lba2msf(block,&drvcmd[1]);
4198 drvcmd[4]=0;
4199 drvcmd[5]=0;
4200 drvcmd[6]=read_audio.nframes;
4201 }
4202 else if (fam2_drive)
4203 {
4204 }
4205 else if (famT_drive)
4206 {
4207 }
4208 msg(DBG_AUD,"read_audio: before giving \"read\" command.\n");
4209 for (i=0;i<7;i++) OUT(CDo_command,drvcmd[i]);
4210 sbp_sleep(0);
4211 msg(DBG_AUD,"read_audio: after giving \"read\" command.\n");
4212 for (frame=1;frame<2 && !error_flag; frame++)
4213 {
4214 try=maxtim_data;
4215 for (timeout=jiffies+9*HZ; ; )
4216 {
4217 for ( ; try!=0;try--)
4218 {
4219 j=inb(CDi_status);
4220 if (!(j&s_not_data_ready)) break;
4221 if (!(j&s_not_result_ready)) break;
4222 if (fam0L_drive) if (j&s_attention) break;
4223 }
4224 if (try != 0 || timeout <= jiffies) break;
4225 if (data_retrying == 0) data_waits++;
4226 data_retrying = 1;
4227 sbp_sleep(1);
4228 try = 1;
4229 }
4230 if (try==0)
4231 {
4232 msg(DBG_INF,"read_audio: sbp_data: CDi_status timeout.\n");
4233 error_flag++;
4234 break;
4235 }
4236 msg(DBG_AUD,"read_audio: sbp_data: CDi_status ok.\n");
4237 if (j&s_not_data_ready)
4238 {
4239 msg(DBG_INF, "read_audio: sbp_data: DATA_READY timeout.\n");
4240 error_flag++;
4241 break;
4242 }
4243 msg(DBG_AUD,"read_audio: before reading data.\n");
4244 error_flag=0;
4245 p = D_S[d].aud_buf;
4246 if (sbpro_type==1) OUT(CDo_sel_i_d,1);
4247 insb(CDi_data, p, read_audio.nframes*CD_FRAMESIZE_RAW);
4248 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
4249 data_retrying = 0;
4250 }
4251 msg(DBG_AUD,"read_audio: after reading data.\n");
4252 if (error_flag)
4253 {
4254 msg(DBG_AUD,"read_audio: read aborted by drive\n");
4255 #if 0000
4256 i=cc_DriveReset();
4257 #else
4258 i=cc_ReadError();
4259 #endif 0000
4260 continue;
4261 }
4262 if (fam0L_drive)
4263 {
4264 i=maxtim_data;
4265 for (timeout=jiffies+9*HZ; timeout > jiffies; timeout--)
4266 {
4267 for ( ;i!=0;i--)
4268 {
4269 j=inb(CDi_status);
4270 if (!(j&s_not_data_ready)) break;
4271 if (!(j&s_not_result_ready)) break;
4272 if (j&s_attention) break;
4273 }
4274 if (i != 0 || timeout <= jiffies) break;
4275 sbp_sleep(0);
4276 i = 1;
4277 }
4278 if (i==0) msg(DBG_AUD,"read_audio: STATUS TIMEOUT AFTER READ");
4279 if (!(j&s_attention))
4280 {
4281 msg(DBG_AUD,"read_audio: sbp_data: timeout waiting DRV_ATTN - retrying\n");
4282 i=cc_DriveReset();
4283 continue;
4284 }
4285 }
4286 do
4287 {
4288 if (fam0L_drive) cc_ReadStatus();
4289 i=ResponseStatus();
4290 if (i<0) { msg(DBG_AUD,
4291 "read_audio: cc_ReadStatus error after read: %02X\n",
4292 D_S[d].status_bits);
4293 continue;
4294 }
4295 }
4296 while ((fam0L_drive)&&(!st_check)&&(!(i&p_success)));
4297 if (st_check)
4298 {
4299 i=cc_ReadError();
4300 msg(DBG_AUD,"read_audio: cc_ReadError was necessary after read: %02X\n",i);
4301 continue;
4302 }
4303 memcpy_tofs((u_char *) read_audio.buf,
4304 (u_char *) D_S[d].aud_buf,
4305 read_audio.nframes*CD_FRAMESIZE_RAW);
4306 msg(DBG_AUD,"read_audio: memcpy_tofs done.\n");
4307 break;
4308 }
4309 cc_ModeSelect(CD_FRAMESIZE);
4310 cc_ModeSense();
4311 D_S[d].mode=READ_M1;
4312 busy_audio=0;
4313 if (data_tries == 0)
4314 {
4315 msg(DBG_AUD,"read_audio: failed after 5 tries.\n");
4316 return (-8);
4317 }
4318 msg(DBG_AUD,"read_audio: successful return.\n");
4319 return (0);
4320 }
4321
4322 case CDROMMULTISESSION:
4323 msg(DBG_IOC,"ioctl: CDROMMULTISESSION entered.\n");
4324 st=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_multisession));
4325 if (st) return (st);
4326 memcpy_fromfs(&ms_info, (void *) arg, sizeof(struct cdrom_multisession));
4327 if (ms_info.addr_format==CDROM_MSF)
4328 lba2msf(D_S[d].lba_multi,&ms_info.addr.msf.minute);
4329 else if (ms_info.addr_format==CDROM_LBA)
4330 ms_info.addr.lba=D_S[d].lba_multi;
4331 else return (-EINVAL);
4332 if (D_S[d].f_multisession) ms_info.xa_flag=1;
4333 else ms_info.xa_flag=0;
4334 st=verify_area(VERIFY_WRITE,(void *) arg, sizeof(struct cdrom_multisession));
4335 if (st) return (st);
4336 memcpy_tofs((void *) arg, &ms_info, sizeof(struct cdrom_multisession));
4337 msg(DBG_MUL,"ioctl: CDROMMULTISESSION done (%d, %08X).\n",
4338 ms_info.xa_flag, ms_info.addr.lba);
4339 return (0);
4340
4341 case BLKRASET:
4342 if(!suser()) return -EACCES;
4343 if(!inode->i_rdev) return -EINVAL;
4344 if(arg > 0xff) return -EINVAL;
4345 read_ahead[MAJOR(inode->i_rdev)] = arg;
4346 return (0);
4347
4348 default:
4349 msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
4350 return (-EINVAL);
4351 }
4352 }
4353
4354
4355
4356
4357 static void sbp_transfer(void)
4358 {
4359 long offs;
4360
4361 while ( (CURRENT->nr_sectors > 0) &&
4362 (CURRENT->sector/4 >= D_S[d].sbp_first_frame) &&
4363 (CURRENT->sector/4 <= D_S[d].sbp_last_frame) )
4364 {
4365 offs = (CURRENT->sector - D_S[d].sbp_first_frame * 4) * 512;
4366 memcpy(CURRENT->buffer, D_S[d].sbp_buf + offs, 512);
4367 CURRENT->nr_sectors--;
4368 CURRENT->sector++;
4369 CURRENT->buffer += 512;
4370 }
4371 }
4372
4373
4374
4375
4376 static void DO_SBPCD_REQUEST(void)
4377 {
4378 u_int block;
4379 u_int nsect;
4380 int i, status_tries, data_tries;
4381
4382 request_loop:
4383 INIT_REQUEST;
4384 sti();
4385
4386 if ((CURRENT==NULL)||(CURRENT->dev<0)) goto err_done;
4387 if (CURRENT -> sector == -1) goto err_done;
4388 if (CURRENT->cmd != READ)
4389 {
4390 msg(DBG_INF, "bad cmd %d\n", CURRENT->cmd);
4391 goto err_done;
4392 }
4393 i = MINOR(CURRENT->dev);
4394 if ( (i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
4395 {
4396 msg(DBG_INF, "do_request: bad device: %04X\n", CURRENT->dev);
4397 goto err_done;
4398 }
4399 while (busy_audio) sbp_sleep(HZ);
4400 busy_data=1;
4401
4402 if (D_S[i].audio_state==audio_playing) goto err_done;
4403 if (d!=i) switch_drive(i);
4404
4405 block = CURRENT->sector;
4406 nsect = CURRENT->nr_sectors;
4407
4408 msg(DBG_BSZ,"read sector %d (%d sectors)\n", block, nsect);
4409 #if 0
4410 msg(DBG_MUL,"read LBA %d\n", block/4);
4411 #endif
4412
4413 sbp_transfer();
4414
4415 if (CURRENT->nr_sectors == 0)
4416 {
4417 end_request(1);
4418 goto request_loop;
4419 }
4420
4421 #if FUTURE
4422 i=prepare(0,0);
4423 if (i!=0)
4424 msg(DBG_INF,"\"prepare\" tells error %d -- ignored\n", i);
4425 #endif FUTURE
4426
4427 if (!st_spinning) cc_SpinUp();
4428
4429 for (data_tries=n_retries; data_tries > 0; data_tries--)
4430 {
4431 for (status_tries=3; status_tries > 0; status_tries--)
4432 {
4433 flags_cmd_out |= f_respo3;
4434 cc_ReadStatus();
4435 if (sbp_status() != 0) break;
4436 if (st_check) cc_ReadError();
4437 sbp_sleep(1);
4438 }
4439 if (status_tries == 0)
4440 {
4441 msg(DBG_INF,"sbp_status: failed after 3 tries\n");
4442 break;
4443 }
4444
4445 sbp_read_cmd();
4446 sbp_sleep(0);
4447 if (sbp_data() != 0)
4448 {
4449 end_request(1);
4450 goto request_loop;
4451 }
4452 }
4453
4454 err_done:
4455 busy_data=0;
4456 end_request(0);
4457 sbp_sleep(0);
4458 goto request_loop;
4459 }
4460
4461
4462
4463
4464 static void sbp_read_cmd(void)
4465 {
4466 #undef OLD
4467
4468 int i;
4469 int block;
4470
4471 D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1;
4472 D_S[d].sbp_current = 0;
4473 block=CURRENT->sector/4;
4474 if (block+D_S[d].sbp_bufsiz <= D_S[d].CDsize_frm)
4475 D_S[d].sbp_read_frames = D_S[d].sbp_bufsiz;
4476 else
4477 {
4478 D_S[d].sbp_read_frames=D_S[d].CDsize_frm-block;
4479
4480 if (D_S[d].sbp_read_frames < 1)
4481 {
4482 msg(DBG_INF,"requested frame %d, CD size %d ???\n",
4483 block, D_S[d].CDsize_frm);
4484 D_S[d].sbp_read_frames=1;
4485 }
4486 }
4487
4488 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
4489 clr_cmdbuf();
4490 if (fam0L_drive)
4491 {
4492 flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
4493 if (D_S[d].xa_byte==0x20)
4494 {
4495 cmd_type=READ_M2;
4496 drvcmd[0]=CMD0_READ_XA;
4497 drvcmd[1]=(block>>16)&0x000000ff;
4498 drvcmd[2]=(block>>8)&0x000000ff;
4499 drvcmd[3]=block&0x000000ff;
4500 drvcmd[5]=D_S[d].sbp_read_frames;
4501 }
4502 else
4503 {
4504 drvcmd[0]=CMD0_READ;
4505 if (D_S[d].drv_type>=drv_201)
4506 {
4507 lba2msf(block,&drvcmd[1]);
4508 bin2bcdx(&drvcmd[1]);
4509 bin2bcdx(&drvcmd[2]);
4510 bin2bcdx(&drvcmd[3]);
4511 }
4512 else
4513 {
4514 drvcmd[1]=(block>>16)&0x000000ff;
4515 drvcmd[2]=(block>>8)&0x000000ff;
4516 drvcmd[3]=block&0x000000ff;
4517 }
4518 drvcmd[5]=D_S[d].sbp_read_frames;
4519 drvcmd[6]=(D_S[d].drv_type<drv_201)?0:2;
4520 }
4521 }
4522 else if (fam1_drive)
4523 {
4524 drvcmd[0]=CMD1_READ;
4525 lba2msf(block,&drvcmd[1]);
4526 drvcmd[6]=D_S[d].sbp_read_frames;
4527 }
4528 else if (fam2_drive)
4529 {
4530 drvcmd[0]=CMD2_READ;
4531 lba2msf(block,&drvcmd[1]);
4532 drvcmd[5]=D_S[d].sbp_read_frames;
4533 drvcmd[6]=0x02;
4534 }
4535 else if (famT_drive)
4536 {
4537 drvcmd[0]=CMDT_READ;
4538 drvcmd[2]=(block>>24)&0x0ff;
4539 drvcmd[3]=(block>>16)&0x0ff;
4540 drvcmd[4]=(block>>8)&0x0ff;
4541 drvcmd[5]=block&0x0ff;
4542 drvcmd[7]=(D_S[d].sbp_read_frames>>8)&0x0ff;
4543 drvcmd[8]=D_S[d].sbp_read_frames&0x0ff;
4544 }
4545 #ifdef OLD
4546 SBPCD_CLI;
4547 for (i=0;i<7;i++) OUT(CDo_command,drvcmd[i]);
4548 if (famT_drive) for (i=7;i<10;i++) OUT(CDo_command,drvcmd[i]);
4549 SBPCD_STI;
4550 #else
4551 flags_cmd_out=f_putcmd;
4552 response_count=0;
4553 i=cmd_out();
4554 if (i<0) msg(DBG_INF,"error giving READ command: %0d\n", i);
4555 #endif OLD
4556 return;
4557 }
4558
4559
4560
4561
4562
4563 static int sbp_data(void)
4564 {
4565 int i=0, j=0, l, frame;
4566 u_int try=0;
4567 u_long timeout;
4568 u_char *p;
4569 u_int data_tries = 0;
4570 u_int data_waits = 0;
4571 u_int data_retrying = 0;
4572 int error_flag;
4573 int xa_count;
4574 int max_latency;
4575 int success;
4576 int wait;
4577 int duration;
4578
4579 error_flag=0;
4580 success=0;
4581 #if LONG_TIMING
4582 max_latency=9*HZ;
4583 #else
4584 if (D_S[d].f_multisession) max_latency=9*HZ;
4585 else max_latency=3*HZ;
4586 #endif
4587 msg(DBG_TE2,"beginning to READ\n");
4588 duration=jiffies;
4589 for (frame=0;frame<D_S[d].sbp_read_frames&&!error_flag; frame++)
4590 {
4591 SBPCD_CLI;
4592
4593 del_timer(&data_timer);
4594 data_timer.expires=jiffies+max_latency;
4595 timed_out_data=0;
4596 add_timer(&data_timer);
4597 while (!timed_out_data)
4598 {
4599 if (D_S[d].f_multisession) try=maxtim_data*4;
4600 else try=maxtim_data;
4601 msg(DBG_000,"sbp_data: CDi_status loop: try=%d.\n",try);
4602 for ( ; try!=0;try--)
4603 {
4604 j=inb(CDi_status);
4605 if (!(j&s_not_data_ready)) break;;
4606 if (!(j&s_not_result_ready)) break;
4607 if (fam0L_drive) if (j&s_attention) break;
4608 }
4609 if (!(j&s_not_data_ready)) goto data_ready;
4610 if (try==0)
4611 {
4612 if (data_retrying == 0) data_waits++;
4613 data_retrying = 1;
4614 msg(DBG_000,"sbp_data: CDi_status loop: sleeping.\n");
4615 sbp_sleep(1);
4616 try = 1;
4617 }
4618 }
4619 msg(DBG_INF,"sbp_data: CDi_status loop expired.\n");
4620 data_ready:
4621 del_timer(&data_timer);
4622
4623 if (timed_out_data)
4624 {
4625 msg(DBG_INF,"sbp_data: CDi_status timeout (timed_out_data) (%02X).\n", j);
4626 error_flag++;
4627 break;
4628 }
4629 if (try==0)
4630 {
4631 msg(DBG_INF,"sbp_data: CDi_status timeout (try=0) (%02X).\n", j);
4632 error_flag++;
4633 break;
4634 }
4635 if (!(j&s_not_result_ready))
4636 {
4637 msg(DBG_INF, "sbp_data: RESULT_READY where DATA_READY awaited (%02X).\n", j);
4638 response_count=20;
4639 j=ResponseInfo();
4640 j=inb(CDi_status);
4641 }
4642 if (j&s_not_data_ready)
4643 {
4644 if ((D_S[d].ored_ctl_adr&0x40)==0)
4645 msg(DBG_INF, "CD contains no data tracks.\n");
4646 else msg(DBG_INF, "sbp_data: DATA_READY timeout (%02X).\n", j);
4647 error_flag++;
4648 break;
4649 }
4650 SBPCD_STI;
4651 error_flag=0;
4652 msg(DBG_000, "sbp_data: beginning to read.\n");
4653 p = D_S[d].sbp_buf + frame * CD_FRAMESIZE;
4654 if (sbpro_type==1) OUT(CDo_sel_i_d,1);
4655 if (cmd_type==READ_M2) insb(CDi_data, xa_head_buf, CD_XA_HEAD);
4656 insb(CDi_data, p, CD_FRAMESIZE);
4657 if (cmd_type==READ_M2) insb(CDi_data, xa_tail_buf, CD_XA_TAIL);
4658 if (famT_drive) msg(DBG_TE2, "================frame read=================.\n");
4659 D_S[d].sbp_current++;
4660 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
4661 if (cmd_type==READ_M2)
4662 {
4663 for (xa_count=0;xa_count<CD_XA_HEAD;xa_count++)
4664 sprintf(&msgbuf[xa_count*3], " %02X", xa_head_buf[xa_count]);
4665 msgbuf[xa_count*3]=0;
4666 msg(DBG_XA1,"xa head:%s\n", msgbuf);
4667 }
4668 data_retrying = 0;
4669 data_tries++;
4670 if (data_tries >= 1000)
4671 {
4672 msg(DBG_INF,"sbp_data() statistics: %d waits in %d frames.\n", data_waits, data_tries);
4673 data_waits = data_tries = 0;
4674 }
4675 }
4676 duration=jiffies-duration;
4677 msg(DBG_TE2,"time to read %d frames: %d jiffies .\n",frame,duration);
4678 if (famT_drive)
4679 {
4680 wait=8;
4681 do
4682 {
4683 sbp_sleep(1);
4684 OUT(CDo_sel_i_d,0);
4685 i=inb(CDi_status);
4686 if (!(i&s_not_data_ready))
4687 {
4688 OUT(CDo_sel_i_d,1);
4689 j=0;
4690 do
4691 {
4692 i=inb(CDi_data);
4693 j++;
4694 i=inb(CDi_status);
4695 }
4696 while (!(i&s_not_data_ready));
4697 msg(DBG_TEA, "=============too much data (%d bytes)=================.\n", j);
4698 }
4699 if (!(i&s_not_result_ready))
4700 {
4701 OUT(CDo_sel_i_d,0);
4702 l=0;
4703 do
4704 {
4705 infobuf[l++]=inb(CDi_info);
4706 i=inb(CDi_status);
4707 }
4708 while (!(i&s_not_result_ready));
4709 if (infobuf[0]==0x00) success=1;
4710 #if 1
4711 for (j=0;j<l;j++) sprintf(&msgbuf[j*3], " %02X", infobuf[j]);
4712 msgbuf[j*3]=0;
4713 msg(DBG_TE2,"sbp_data info response:%s\n", msgbuf);
4714 #endif
4715 if (infobuf[0]==0x02)
4716 {
4717 error_flag++;
4718 do
4719 {
4720 ++recursion;
4721 if (recursion>1) msg(DBG_TEA,"cmd_out_T READ_ERR recursion (sbp_data): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",recursion);
4722 else msg(DBG_TEA,"sbp_data: CMDT_READ_ERR necessary.\n");
4723 clr_cmdbuf();
4724 drvcmd[0]=CMDT_READ_ERR;
4725 j=cmd_out_T();
4726 --recursion;
4727 sbp_sleep(1);
4728 }
4729 while (j<0);
4730 D_S[d].error_state=infobuf[2];
4731 D_S[d].b3=infobuf[3];
4732 D_S[d].b4=infobuf[4];
4733 }
4734 break;
4735 }
4736 else
4737 {
4738 #if 0
4739 msg(DBG_TEA, "============= waiting for result=================.\n");
4740 sbp_sleep(1);
4741 #endif
4742 }
4743 }
4744 while (wait--);
4745 }
4746
4747 if (error_flag)
4748 {
4749 msg(DBG_TEA, "================error flag: %d=================.\n", error_flag);
4750 msg(DBG_INF,"sbp_data: read aborted by drive.\n");
4751 #if 1
4752 i=cc_DriveReset();
4753 #else
4754 i=cc_ReadError();
4755 #endif
4756 return (0);
4757 }
4758
4759 if (fam0L_drive)
4760 {
4761 SBPCD_CLI;
4762 i=maxtim_data;
4763 for (timeout=jiffies+HZ; timeout > jiffies; timeout--)
4764 {
4765 for ( ;i!=0;i--)
4766 {
4767 j=inb(CDi_status);
4768 if (!(j&s_not_data_ready)) break;
4769 if (!(j&s_not_result_ready)) break;
4770 if (j&s_attention) break;
4771 }
4772 if (i != 0 || timeout <= jiffies) break;
4773 sbp_sleep(0);
4774 i = 1;
4775 }
4776 if (i==0) msg(DBG_INF,"status timeout after READ.\n");
4777 if (!(j&s_attention))
4778 {
4779 msg(DBG_INF,"sbp_data: timeout waiting DRV_ATTN - retrying.\n");
4780 i=cc_DriveReset();
4781 SBPCD_STI;
4782 return (0);
4783 }
4784 SBPCD_STI;
4785 }
4786
4787 #if 0
4788 if (!success)
4789 #endif 0
4790 do
4791 {
4792 if (fam0L_drive) cc_ReadStatus();
4793 #if 1
4794 if (famT_drive) msg(DBG_TE2, "================before ResponseStatus=================.\n", i);
4795 #endif 1
4796 i=ResponseStatus();
4797 #if 1
4798 if (famT_drive) msg(DBG_TE2, "================ResponseStatus: %d=================.\n", i);
4799 #endif 1
4800 if (i<0)
4801 {
4802 msg(DBG_INF,"bad cc_ReadStatus after read: %02X\n", D_S[d].status_bits);
4803 return (0);
4804 }
4805 }
4806 while ((fam0L_drive)&&(!st_check)&&(!(i&p_success)));
4807 if (st_check)
4808 {
4809 i=cc_ReadError();
4810 msg(DBG_INF,"cc_ReadError was necessary after read: %d\n",i);
4811 return (0);
4812 }
4813 if (fatal_err)
4814 {
4815 fatal_err=0;
4816 D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1;
4817 D_S[d].sbp_current = 0;
4818 msg(DBG_INF,"sbp_data: fatal_err - retrying.\n");
4819 return (0);
4820 }
4821
4822 D_S[d].sbp_first_frame = CURRENT -> sector / 4;
4823 D_S[d].sbp_last_frame = D_S[d].sbp_first_frame + D_S[d].sbp_read_frames - 1;
4824 sbp_transfer();
4825 #if 1
4826 if (famT_drive) msg(DBG_TE2, "================sbp_transfer() done=================.\n");
4827 #endif 1
4828 return (1);
4829 }
4830
4831
4832
4833
4834
4835 static int sbpcd_open(struct inode *ip, struct file *fp)
4836 {
4837 int i;
4838
4839 i = MINOR(ip->i_rdev);
4840 if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
4841 {
4842 msg(DBG_INF, "open: bad device: %04X\n", ip->i_rdev);
4843 return (-ENXIO);
4844 }
4845 if (fp->f_mode & 2)
4846 return -EROFS;
4847
4848 switch_drive(i);
4849
4850 i=cc_ReadError();
4851 flags_cmd_out |= f_respo2;
4852 cc_ReadStatus();
4853 i=ResponseStatus();
4854 if (famT_drive&&(i<0))
4855 {
4856 cc_DriveReset();
4857 i=ResponseStatus();
4858 i=ResponseStatus();
4859 }
4860 if (i<0)
4861 {
4862 msg(DBG_INF,"sbpcd_open: ResponseStatus timed out (%d).\n",i);
4863 return (-EIO);
4864 }
4865 if (famT_drive) msg(DBG_TE2,"sbpcd_open: ResponseStatus=%02X\n", i);
4866 if (!st_door_closed)
4867 {
4868 if (famT_drive) msg(DBG_TE2,"sbpcd_open: !st_door_closed.\n");
4869 cc_CloseTray();
4870 flags_cmd_out |= f_respo2;
4871 cc_ReadStatus();
4872 i=ResponseStatus();
4873 }
4874 if (!(famT_drive))
4875 if (!st_spinning)
4876 {
4877 if (famT_drive) msg(DBG_TE2,"sbpcd_open: !st_spinning.\n");
4878 cc_SpinUp();
4879 flags_cmd_out |= f_respo2;
4880 cc_ReadStatus();
4881 i=ResponseStatus();
4882 }
4883 if (famT_drive) msg(DBG_TE2,"sbpcd_open: status %02X\n", D_S[d].status_bits);
4884 if (!st_door_closed||!st_caddy_in)
4885 {
4886 msg(DBG_INF, "sbpcd_open: no disk in drive.\n");
4887 D_S[d].open_count=0;
4888 #if JUKEBOX
4889 if (!fam0_drive)
4890 {
4891 i=UnLockDoor();
4892 cc_SpinDown();
4893 }
4894 #endif
4895 return (-ENXIO);
4896 }
4897
4898
4899
4900 MOD_INC_USE_COUNT;
4901 msg(DBG_LCK,"open_count: %d -> %d\n",
4902 D_S[d].open_count,D_S[d].open_count+1);
4903 if (++D_S[d].open_count<=1)
4904 {
4905 i=LockDoor();
4906 D_S[d].open_count=1;
4907 if (famT_drive) msg(DBG_TE2,"sbpcd_open: before i=DiskInfo();.\n");
4908 i=DiskInfo();
4909 if (famT_drive) msg(DBG_TE2,"sbpcd_open: after i=DiskInfo();.\n");
4910 if ((D_S[d].ored_ctl_adr&0x40)==0)
4911 msg(DBG_INF,"CD contains no data tracks.\n");
4912 }
4913 if (!st_spinning) cc_SpinUp();
4914 return (0);
4915 }
4916
4917
4918
4919
4920 static void sbpcd_release(struct inode * ip, struct file * file)
4921 {
4922 int i;
4923
4924 i = MINOR(ip->i_rdev);
4925 if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
4926 {
4927 msg(DBG_INF, "release: bad device: %04X\n", ip->i_rdev);
4928 return;
4929 }
4930 switch_drive(i);
4931
4932 D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1;
4933 sync_dev(ip->i_rdev);
4934 invalidate_buffers(ip->i_rdev);
4935
4936
4937
4938
4939 MOD_DEC_USE_COUNT;
4940 msg(DBG_LCK,"open_count: %d -> %d\n",
4941 D_S[d].open_count,D_S[d].open_count-1);
4942 if (D_S[d].open_count>-2)
4943 {
4944 if (--D_S[d].open_count<=0)
4945 {
4946 i=UnLockDoor();
4947 if (D_S[d].audio_state!=audio_playing)
4948 if (D_S[d].f_eject) cc_SpinDown();
4949 D_S[d].diskstate_flags &= ~cd_size_bit;
4950 D_S[d].open_count=0;
4951 }
4952 }
4953 }
4954
4955
4956
4957
4958 static struct file_operations sbpcd_fops =
4959 {
4960 NULL,
4961 block_read,
4962 block_write,
4963 NULL,
4964 NULL,
4965 sbpcd_ioctl,
4966 NULL,
4967 sbpcd_open,
4968 sbpcd_release,
4969 NULL,
4970 NULL,
4971 sbpcd_chk_disk_change,
4972 NULL
4973 };
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998 #if (SBPCD_ISSUE-1)
4999 static
5000 #endif
5001 void sbpcd_setup(const char *s, int *p)
5002 {
5003 setup_done++;
5004 msg(DBG_INI,"sbpcd_setup called with %04X,%s\n",p[1], s);
5005 sbpro_type=0;
5006 if (p[0]>1) sbpro_type=p[2];
5007 if (!strcmp(s,str_sb)) sbpro_type=1;
5008 else if (!strcmp(s,str_sb_l)) sbpro_type=1;
5009 else if (!strcmp(s,str_sp)) sbpro_type=2;
5010 else if (!strcmp(s,str_sp_l)) sbpro_type=2;
5011 else if (!strcmp(s,str_ss)) sbpro_type=2;
5012 else if (!strcmp(s,str_ss_l)) sbpro_type=2;
5013 if (p[0]>0) sbpcd_ioaddr=p[1];
5014
5015 CDo_command=sbpcd_ioaddr;
5016 CDi_info=sbpcd_ioaddr;
5017 CDi_status=sbpcd_ioaddr+1;
5018 CDo_sel_i_d=sbpcd_ioaddr+1;
5019 CDo_reset=sbpcd_ioaddr+2;
5020 CDo_enable=sbpcd_ioaddr+3;
5021 if (sbpro_type==1)
5022 {
5023 MIXER_addr=sbpcd_ioaddr-0x10+0x04;
5024 MIXER_data=sbpcd_ioaddr-0x10+0x05;
5025 CDi_data=sbpcd_ioaddr;
5026 }
5027 else CDi_data=sbpcd_ioaddr+2;
5028 }
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046 static int config_spea(void)
5047 {
5048 int n_ports=0x10;
5049
5050 int irq_number=0;
5051 int dma_channel=0;
5052 int dack_polarity=0;
5053 int drq_polarity=0x40;
5054 int i;
5055
5056 #define SPEA_REG_1 sbpcd_ioaddr-0x08+4
5057 #define SPEA_REG_2 sbpcd_ioaddr-0x08+5
5058
5059 OUT(SPEA_REG_1,0xFF);
5060 i=inb(SPEA_REG_1);
5061 if (i!=0x0F)
5062 {
5063 msg(DBG_SEQ,"no SPEA interface at %04X present.\n", sbpcd_ioaddr);
5064 return (-1);
5065 }
5066 OUT(SPEA_REG_1,0x04);
5067 OUT(SPEA_REG_2,0xC0);
5068
5069 OUT(SPEA_REG_1,0x05);
5070 OUT(SPEA_REG_2,0x10|drq_polarity|dack_polarity);
5071
5072 #if 1
5073 #define SPEA_PATTERN 0x80
5074 #else
5075 #define SPEA_PATTERN 0x00
5076 #endif
5077 OUT(SPEA_REG_1,0x06);
5078 OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
5079 OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
5080
5081 OUT(SPEA_REG_1,0x09);
5082 i=(inb(SPEA_REG_2)&0xCF)|n_ports;
5083 OUT(SPEA_REG_2,i);
5084
5085 sbpro_type = 0;
5086 msg(DBG_SEQ,"found SoundScape interface at %04X.\n", sbpcd_ioaddr);
5087 return (0);
5088 }
5089
5090
5091
5092
5093 #ifdef MODULE
5094 int init_module(void)
5095 #else
5096 unsigned long SBPCD_INIT(u_long mem_start, u_long mem_end)
5097 #endif MODULE
5098 {
5099 int i=0, j=0;
5100 int addr[2]={1, CDROM_PORT};
5101 int port_index;
5102
5103 sti();
5104
5105 msg(DBG_INF,"sbpcd.c %s\n", VERSION);
5106 #ifndef MODULE
5107 #if DISTRIBUTION
5108 if (!setup_done)
5109 {
5110 msg(DBG_INF,"Looking for Matsushita/Panasonic, CreativeLabs, Longshine, TEAC CD-ROM drives\n");
5111 msg(DBG_INF,"= = = = = = = = = = W A R N I N G = = = = = = = = = =\n");
5112 msg(DBG_INF,"Auto-Probing can cause a hang (f.e. touching an NE2000 card).\n");
5113 msg(DBG_INF,"If that happens, you have to reboot and use the\n");
5114 msg(DBG_INF,"LILO (kernel) command line feature like:\n");
5115 msg(DBG_INF," LILO boot: ... sbpcd=0x230,SoundBlaster\n");
5116 msg(DBG_INF,"or like:\n");
5117 msg(DBG_INF," LILO boot: ... sbpcd=0x300,LaserMate\n");
5118 msg(DBG_INF,"or like:\n");
5119 msg(DBG_INF," LILO boot: ... sbpcd=0x338,SoundScape\n");
5120 msg(DBG_INF,"with your REAL address.\n");
5121 msg(DBG_INF,"= = = = = = = = = = END of WARNING = = = = = == = = =\n");
5122 }
5123 #endif DISTRIBUTION
5124 sbpcd[0]=sbpcd_ioaddr;
5125 sbpcd[1]=sbpro_type;
5126 #endif MODULE
5127
5128 for (port_index=0;port_index<NUM_PROBE;port_index+=2)
5129 {
5130 addr[1]=sbpcd[port_index];
5131 if (addr[1]==0) break;
5132 if (check_region(addr[1],4))
5133 {
5134 msg(DBG_INF,"check_region: %03X is not free.\n",addr[1]);
5135 continue;
5136 }
5137 if (sbpcd[port_index+1]==2) type=str_sp;
5138 else if (sbpcd[port_index+1]==1) type=str_sb;
5139 else type=str_lm;
5140 sbpcd_setup(type, addr);
5141 #if DISTRIBUTION
5142 msg(DBG_INF,"Scanning 0x%X (%s)...\n", CDo_command, type);
5143 #endif DISTRIBUTION
5144 if (sbpcd[port_index+1]==2)
5145 {
5146 i=config_spea();
5147 if (i<0) continue;
5148 }
5149 #ifdef PATH_CHECK
5150 if (check_card(addr[1])) continue;
5151 #endif PATH_CHECK
5152 i=check_drives();
5153 msg(DBG_INI,"check_drives done.\n");
5154 if (i>=0) break;
5155 }
5156
5157 if (ndrives==0)
5158 {
5159 msg(DBG_INF, "No drive found.\n");
5160 #ifdef MODULE
5161 return -EIO;
5162 #else
5163 goto init_done;
5164 #endif MODULE
5165 }
5166
5167 if (port_index>0)
5168 msg(DBG_INF, "You should configure sbpcd.h for your hardware.\n");
5169 check_datarate();
5170 msg(DBG_INI,"check_datarate done.\n");
5171
5172 #if 0
5173 if (!famL_drive)
5174 {
5175 OUT(CDo_reset,0);
5176 sbp_sleep(HZ);
5177 }
5178 #endif 0
5179
5180 for (j=0;j<NR_SBPCD;j++)
5181 {
5182 if (D_S[j].drv_id==-1) continue;
5183 switch_drive(j);
5184 #if 1
5185 if (!famL_drive) cc_DriveReset();
5186 #endif 0
5187 if (!st_spinning) cc_SpinUp();
5188 D_S[d].sbp_first_frame = -1;
5189 D_S[d].sbp_last_frame = -1;
5190 D_S[d].sbp_read_frames = 0;
5191 D_S[d].sbp_current = 0;
5192 D_S[d].CD_changed=1;
5193 D_S[d].frame_size=CD_FRAMESIZE;
5194 #if EJECT
5195 if (!fam0_drive) D_S[d].f_eject=1;
5196 else D_S[d].f_eject=0;
5197 #else
5198 D_S[d].f_eject=0;
5199 #endif
5200
5201 cc_ReadStatus();
5202 i=ResponseStatus();
5203 if (famT_drive) i=ResponseStatus();
5204 if (i<0)
5205 if (i!=-402)
5206 msg(DBG_INF,"init: ResponseStatus returns %d.\n",i);
5207 else
5208 {
5209 if (st_check)
5210 {
5211 i=cc_ReadError();
5212 msg(DBG_INI,"init: cc_ReadError returns %d\n",i);
5213 }
5214 }
5215 msg(DBG_INI,"init: first GetStatus: %d\n",i);
5216 msg(DBG_LCS,"init: first GetStatus: error_byte=%d\n",
5217 D_S[d].error_byte);
5218 if (D_S[d].error_byte==aud_12)
5219 {
5220 timeout=jiffies+2*HZ;
5221 do
5222 {
5223 i=GetStatus();
5224 msg(DBG_INI,"init: second GetStatus: %02X\n",i);
5225 msg(DBG_LCS,
5226 "init: second GetStatus: error_byte=%d\n",
5227 D_S[d].error_byte);
5228 if (i<0) break;
5229 if (!st_caddy_in) break;
5230 }
5231 while ((!st_diskok)||(timeout<jiffies));
5232 }
5233 i=SetSpeed();
5234 if (i>=0) D_S[d].CD_changed=1;
5235 }
5236
5237
5238
5239
5240
5241
5242 if ((sbpro_type==1) || (SOUND_BASE))
5243 {
5244 if (sbpro_type!=1)
5245 {
5246 MIXER_addr=SOUND_BASE+0x04;
5247 MIXER_data=SOUND_BASE+0x05;
5248 }
5249 OUT(MIXER_addr,MIXER_CD_Volume);
5250 OUT(MIXER_data,0xCC);
5251 }
5252
5253 if (register_blkdev(MAJOR_NR, major_name, &sbpcd_fops) != 0)
5254 {
5255 msg(DBG_INF, "Can't get MAJOR %d for Matsushita CDROM\n", MAJOR_NR);
5256 #ifdef MODULE
5257 return -EIO;
5258 #else
5259 goto init_done;
5260 #endif MODULE
5261 }
5262 blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST;
5263 read_ahead[MAJOR_NR] = SBP_BUFFER_FRAMES * (CD_FRAMESIZE / 512);
5264
5265 request_region(CDo_command,4,major_name);
5266
5267 for (j=0;j<NR_SBPCD;j++)
5268 {
5269 if (D_S[j].drv_id==-1) continue;
5270 switch_drive(j);
5271
5272
5273
5274 D_S[j].aud_buf=NULL;
5275 D_S[j].sbp_audsiz=0;
5276 D_S[j].sbp_bufsiz=SBP_BUFFER_FRAMES;
5277 if (D_S[j].drv_type&drv_fam1)
5278 if (READ_AUDIO>0) D_S[j].sbp_audsiz=READ_AUDIO;
5279 #ifdef MODULE
5280 D_S[j].sbp_buf=(u_char *) vmalloc(D_S[j].sbp_bufsiz*CD_FRAMESIZE);
5281 if (D_S[j].sbp_buf==NULL)
5282 {
5283 msg(DBG_INF,"data buffer (%d frames) not available.\n",D_S[j].sbp_bufsiz);
5284 return -EIO;
5285 }
5286 msg(DBG_INF,"data buffer size: %d frames.\n",SBP_BUFFER_FRAMES);
5287 if (D_S[j].sbp_audsiz>0)
5288 {
5289 D_S[j].aud_buf=(u_char *) vmalloc(D_S[j].sbp_audsiz*CD_FRAMESIZE_RAW);
5290 if (D_S[j].aud_buf==NULL) msg(DBG_INF,"audio buffer (%d frames) not available.\n",D_S[j].sbp_audsiz);
5291 else msg(DBG_INF,"audio buffer size: %d frames.\n",D_S[j].sbp_audsiz);
5292 }
5293 #else
5294 D_S[j].sbp_buf=(u_char *)mem_start;
5295 mem_start += D_S[j].sbp_bufsiz*CD_FRAMESIZE;
5296 if (D_S[j].sbp_audsiz>0)
5297 {
5298 D_S[j].aud_buf=(u_char *)mem_start;
5299 mem_start += D_S[j].sbp_audsiz*CD_FRAMESIZE_RAW;
5300 }
5301 #endif MODULE
5302
5303
5304
5305 sbpcd_blocksizes[j]=CD_FRAMESIZE;
5306 }
5307 blksize_size[MAJOR_NR]=sbpcd_blocksizes;
5308
5309 #ifdef MODULE
5310 return (0);
5311 #else
5312 init_done:
5313 #if !(SBPCD_ISSUE-1)
5314 #ifdef CONFIG_SBPCD2
5315 mem_start=sbpcd2_init(mem_start, mem_end);
5316 #endif
5317 #ifdef CONFIG_SBPCD3
5318 mem_start=sbpcd3_init(mem_start, mem_end);
5319 #endif
5320 #ifdef CONFIG_SBPCD4
5321 mem_start=sbpcd4_init(mem_start, mem_end);
5322 #endif
5323 #endif
5324 return (mem_start);
5325 #endif MODULE
5326 }
5327
5328 #ifdef MODULE
5329 void cleanup_module(void)
5330 {
5331 int j;
5332
5333 if (MOD_IN_USE)
5334 {
5335 msg(DBG_INF, "%s module in use - can't remove it.\n", major_name);
5336 return;
5337 }
5338 if ((unregister_blkdev(MAJOR_NR, major_name) == -EINVAL))
5339 {
5340 msg(DBG_INF, "What's that: can't unregister %s.\n", major_name);
5341 return;
5342 }
5343 release_region(CDo_command,4);
5344
5345 for (j=0;j<NR_SBPCD;j++)
5346 {
5347 if (D_S[j].drv_id==-1) continue;
5348 vfree(D_S[j].sbp_buf);
5349 if (D_S[j].sbp_audsiz>0)
5350 vfree(D_S[j].aud_buf);
5351 }
5352 msg(DBG_INF, "%s module released.\n", major_name);
5353 }
5354 #endif MODULE
5355
5356
5357
5358
5359
5360
5361 static int sbpcd_chk_disk_change(dev_t full_dev)
5362 {
5363 int i, st;
5364
5365 msg(DBG_CHK,"media_check (%d) called\n", MINOR(full_dev));
5366 return (0);
5367
5368 i=MINOR(full_dev);
5369 if ( (i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1) )
5370 {
5371 msg(DBG_INF, "media_check: invalid device %04X.\n", full_dev);
5372 return (-1);
5373 }
5374
5375 switch_drive(i);
5376
5377 cc_ReadStatus();
5378 st=ResponseStatus();
5379 msg(DBG_CHK,"media_check: %02X\n",D_S[d].status_bits);
5380 if (st<0)
5381 {
5382 msg(DBG_INF,"media_check: ResponseStatus error.\n");
5383 return (1);
5384 }
5385 if (D_S[d].CD_changed==0xFF) msg(DBG_CHK,"media_check: \"changed\" assumed.\n");
5386 if (!st_spinning) msg(DBG_CHK,"media_check: motor off.\n");
5387 if (!st_door_closed)
5388 {
5389 msg(DBG_CHK,"media_check: door open.\n");
5390 D_S[d].CD_changed=0xFF;
5391 }
5392 if (!st_caddy_in)
5393 {
5394 msg(DBG_CHK,"media_check: no disk in drive.\n");
5395 D_S[d].open_count=0;
5396 D_S[d].CD_changed=0xFF;
5397 }
5398 if (!st_diskok) msg(DBG_CHK,"media_check: !st_diskok.\n");
5399
5400 #if 0000
5401 if (D_S[d].CD_changed==0xFF)
5402 {
5403 D_S[d].CD_changed=1;
5404 return (1);
5405 }
5406 #endif 0000
5407
5408 if (!st_diskok) return (1);
5409 if (!st_caddy_in) return (1);
5410 if (!st_door_closed) return (1);
5411 return (0);
5412 }
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429