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