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