This source file includes following definitions.
- scd_disk_change
- enable_interrupts
- disable_interrupts
- cdu31a_interrupt
- sony_sleep
- is_attention
- is_busy
- is_data_ready
- is_data_requested
- is_result_ready
- is_param_write_rdy
- is_result_reg_not_empty
- reset_drive
- clear_attention
- clear_result_ready
- clear_data_ready
- clear_param_reg
- read_status_register
- read_result_register
- read_data_register
- write_param
- write_cmd
- set_drive_params
- restart_on_error
- write_params
- get_result
- do_sony_cd_cmd
- handle_sony_cd_attention
- int_to_bcd
- bcd_to_int
- log_to_msf
- msf_to_log
- size_to_buf
- start_request
- abort_read
- handle_abort_timeout
- input_data
- read_data_block
- do_cdu31a_request
- mcovlp
- sony_get_toc
- find_track
- read_subcode
- sony_get_subchnl_info
- read_audio_data
- read_audio
- do_sony_cd_cmd_chk
- scd_ioctl
- scd_open
- scd_release
- get_drive_configuration
- cdu31a_setup
- cdu31a_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163 #include <linux/errno.h>
164 #include <linux/signal.h>
165 #include <linux/sched.h>
166 #include <linux/timer.h>
167 #include <linux/fs.h>
168 #include <linux/kernel.h>
169 #include <linux/hdreg.h>
170 #include <linux/genhd.h>
171 #include <linux/ioport.h>
172 #include <linux/string.h>
173 #include <linux/malloc.h>
174
175 #include <asm/system.h>
176 #include <asm/io.h>
177 #include <asm/segment.h>
178 #include <asm/dma.h>
179
180 #include <linux/cdrom.h>
181 #include <linux/cdu31a.h>
182
183 #define MAJOR_NR CDU31A_CDROM_MAJOR
184 #include "blk.h"
185
186 #define DEBUG 0
187
188 #define CDU31A_READAHEAD 128
189 #define CDU31A_MAX_CONSECUTIVE_ATTENTIONS 10
190
191
192 #undef SONY_POLL_EACH_BYTE
193
194
195
196
197
198
199 static struct
200 {
201 unsigned short base;
202 short int_num;
203
204 } cdu31a_addresses[] =
205 {
206 #if 0
207
208 { 0x340, 0 },
209 { 0x1f88, 0 },
210 { 0x230, 0 },
211 { 0x360, 0 },
212 { 0x320, 0 },
213 { 0x330, 0 },
214 { 0x634, 0 },
215 { 0x654, 0 },
216 #endif
217 { 0 }
218 };
219
220 static int handle_sony_cd_attention(void);
221 static int read_subcode(void);
222 static void sony_get_toc(void);
223 static int scd_open(struct inode *inode, struct file *filp);
224 static void do_sony_cd_cmd(unsigned char cmd,
225 unsigned char *params,
226 unsigned int num_params,
227 unsigned char *result_buffer,
228 unsigned int *result_size);
229 static void size_to_buf(unsigned int size,
230 unsigned char *buf);
231
232
233 static unsigned int sony_next_block;
234 static unsigned int sony_blocks_left = 0;
235
236
237
238
239
240 static unsigned short sony_cd_base_io = 0;
241
242
243
244
245
246 static volatile unsigned short sony_cd_cmd_reg;
247 static volatile unsigned short sony_cd_param_reg;
248 static volatile unsigned short sony_cd_write_reg;
249 static volatile unsigned short sony_cd_control_reg;
250 static volatile unsigned short sony_cd_status_reg;
251 static volatile unsigned short sony_cd_result_reg;
252 static volatile unsigned short sony_cd_read_reg;
253 static volatile unsigned short sony_cd_fifost_reg;
254
255
256 static int sony_spun_up = 0;
257
258 static int sony_xa_mode = 0;
259
260
261 static int sony_raw_data_mode = 1;
262
263
264 static unsigned int sony_usage = 0;
265
266
267 static int sony_pas_init = 0;
268
269
270 static struct s_sony_session_toc *sony_toc;
271
272
273
274 static int sony_toc_read = 0;
275
276
277 static struct s_sony_subcode * volatile last_sony_subcode;
278
279
280 static volatile int sony_inuse = 0;
281
282
283 static struct wait_queue * sony_wait = NULL;
284
285 static struct task_struct *has_cd_task = NULL;
286
287
288
289 static int is_double_speed = 0;
290
291
292
293
294
295 static volatile int sony_audio_status = CDROM_AUDIO_NO_STATUS;
296
297
298
299
300
301
302
303
304 static unsigned volatile char cur_pos_msf[3] = { 0, 0, 0 };
305 static unsigned volatile char final_pos_msf[3] = { 0, 0, 0 };
306
307
308 static int irq_used = 0;
309
310
311
312 static struct wait_queue *cdu31a_irq_wait = NULL;
313
314 static int curr_control_reg = 0;
315
316
317
318
319 static char disk_changed;
320
321
322
323
324 static char *readahead_buffer = NULL;
325 static int readahead_dataleft = 0;
326 static int readahead_bad = 0;
327
328
329
330
331 static struct timer_list cdu31a_abort_timer;
332
333
334
335
336
337
338 static int
339 scd_disk_change(dev_t full_dev)
340 {
341 int retval;
342
343 retval = disk_changed;
344 disk_changed = 0;
345
346 return retval;
347 }
348
349 static inline void
350 enable_interrupts(void)
351 {
352 curr_control_reg |= ( SONY_ATTN_INT_EN_BIT
353 | SONY_RES_RDY_INT_EN_BIT
354 | SONY_DATA_RDY_INT_EN_BIT);
355 outb(curr_control_reg, sony_cd_control_reg);
356 }
357
358 static inline void
359 disable_interrupts(void)
360 {
361 curr_control_reg &= ~( SONY_ATTN_INT_EN_BIT
362 | SONY_RES_RDY_INT_EN_BIT
363 | SONY_DATA_RDY_INT_EN_BIT);
364 outb(curr_control_reg, sony_cd_control_reg);
365 }
366
367 static void
368 cdu31a_interrupt(int irq, struct pt_regs *regs)
369 {
370 disable_interrupts();
371 if (cdu31a_irq_wait != NULL)
372 {
373 wake_up(&cdu31a_irq_wait);
374 }
375 else
376 {
377 printk("CDU31A: Got an interrupt but nothing was waiting\n");
378 }
379 }
380
381
382
383
384
385 static inline void
386 sony_sleep(void)
387 {
388 unsigned long flags;
389
390 if (irq_used <= 0)
391 {
392 current->state = TASK_INTERRUPTIBLE;
393 current->timeout = jiffies;
394 schedule();
395 }
396 else
397 {
398 save_flags(flags);
399 cli();
400 enable_interrupts();
401 interruptible_sleep_on(&cdu31a_irq_wait);
402 restore_flags(flags);
403 }
404 }
405
406
407
408
409
410
411 static inline int
412 is_attention(void)
413 {
414 return((inb(sony_cd_status_reg) & SONY_ATTN_BIT) != 0);
415 }
416
417 static inline int
418 is_busy(void)
419 {
420 return((inb(sony_cd_status_reg) & SONY_BUSY_BIT) != 0);
421 }
422
423 static inline int
424 is_data_ready(void)
425 {
426 return((inb(sony_cd_status_reg) & SONY_DATA_RDY_BIT) != 0);
427 }
428
429 static inline int
430 is_data_requested(void)
431 {
432 return((inb(sony_cd_status_reg) & SONY_DATA_REQUEST_BIT) != 0);
433 }
434
435 static inline int
436 is_result_ready(void)
437 {
438 return((inb(sony_cd_status_reg) & SONY_RES_RDY_BIT) != 0);
439 }
440
441 static inline int
442 is_param_write_rdy(void)
443 {
444 return((inb(sony_cd_fifost_reg) & SONY_PARAM_WRITE_RDY_BIT) != 0);
445 }
446
447 static inline int
448 is_result_reg_not_empty(void)
449 {
450 return((inb(sony_cd_fifost_reg) & SONY_RES_REG_NOT_EMP_BIT) != 0);
451 }
452
453 static inline void
454 reset_drive(void)
455 {
456 curr_control_reg = 0;
457 outb(SONY_DRIVE_RESET_BIT, sony_cd_control_reg);
458 }
459
460 static inline void
461 clear_attention(void)
462 {
463 outb(curr_control_reg | SONY_ATTN_CLR_BIT, sony_cd_control_reg);
464 }
465
466 static inline void
467 clear_result_ready(void)
468 {
469 outb(curr_control_reg | SONY_RES_RDY_CLR_BIT, sony_cd_control_reg);
470 }
471
472 static inline void
473 clear_data_ready(void)
474 {
475 outb(curr_control_reg | SONY_DATA_RDY_CLR_BIT, sony_cd_control_reg);
476 }
477
478 static inline void
479 clear_param_reg(void)
480 {
481 outb(curr_control_reg | SONY_PARAM_CLR_BIT, sony_cd_control_reg);
482 }
483
484 static inline unsigned char
485 read_status_register(void)
486 {
487 return(inb(sony_cd_status_reg));
488 }
489
490 static inline unsigned char
491 read_result_register(void)
492 {
493 return(inb(sony_cd_result_reg));
494 }
495
496 static inline unsigned char
497 read_data_register(void)
498 {
499 return(inb(sony_cd_read_reg));
500 }
501
502 static inline void
503 write_param(unsigned char param)
504 {
505 outb(param, sony_cd_param_reg);
506 }
507
508 static inline void
509 write_cmd(unsigned char cmd)
510 {
511 outb(curr_control_reg | SONY_RES_RDY_INT_EN_BIT, sony_cd_control_reg);
512 outb(cmd, sony_cd_cmd_reg);
513 }
514
515
516
517
518
519 static void
520 set_drive_params(void)
521 {
522 unsigned char res_reg[12];
523 unsigned int res_size;
524 unsigned char params[3];
525
526
527 params[0] = SONY_SD_AUTO_SPIN_DOWN_TIME;
528 params[1] = 0x00;
529 do_sony_cd_cmd(SONY_SET_DRIVE_PARAM_CMD,
530 params,
531 2,
532 res_reg,
533 &res_size);
534 if ((res_size < 2) || ((res_reg[0] & 0xf0) == 0x20))
535 {
536 printk(" Unable to set spin-down time: 0x%2.2x\n", res_reg[1]);
537 }
538
539 params[0] = SONY_SD_MECH_CONTROL;
540 params[1] = 0x03;
541 if (is_double_speed)
542 {
543 params[1] |= 0x04;
544 }
545 do_sony_cd_cmd(SONY_SET_DRIVE_PARAM_CMD,
546 params,
547 2,
548 res_reg,
549 &res_size);
550 if ((res_size < 2) || ((res_reg[0] & 0xf0) == 0x20))
551 {
552 printk(" Unable to set mechanical parameters: 0x%2.2x\n", res_reg[1]);
553 }
554 }
555
556
557
558
559 static void
560 restart_on_error(void)
561 {
562 unsigned char res_reg[12];
563 unsigned int res_size;
564 unsigned int retry_count;
565
566
567 printk("cdu31a: Resetting drive on error\n");
568 reset_drive();
569 retry_count = jiffies + SONY_RESET_TIMEOUT;
570 while ((retry_count > jiffies) && (!is_attention()))
571 {
572 sony_sleep();
573 }
574 set_drive_params();
575 do_sony_cd_cmd(SONY_SPIN_UP_CMD, NULL, 0, res_reg, &res_size);
576 if ((res_size < 2) || ((res_reg[0] & 0xf0) == 0x20))
577 {
578 printk("cdu31a: Unable to spin up drive: 0x%2.2x\n", res_reg[1]);
579 }
580
581 current->state = TASK_INTERRUPTIBLE;
582 current->timeout = jiffies + 200;
583 schedule();
584
585 do_sony_cd_cmd(SONY_READ_TOC_CMD, NULL, 0, res_reg, &res_size);
586 if ((res_size < 2) || ((res_reg[0] & 0xf0) == 0x20))
587 {
588 printk("cdu31a: Unable to read TOC: 0x%2.2x\n", res_reg[1]);
589 }
590 }
591
592
593
594
595
596 static int
597 write_params(unsigned char *params,
598 int num_params)
599 {
600 unsigned int retry_count;
601
602
603 retry_count = SONY_READY_RETRIES;
604 while ((retry_count > 0) && (!is_param_write_rdy()))
605 {
606 retry_count--;
607 }
608 if (!is_param_write_rdy())
609 {
610 return -EIO;
611 }
612
613 while (num_params > 0)
614 {
615 write_param(*params);
616 params++;
617 num_params--;
618 }
619
620 return 0;
621 }
622
623
624
625
626
627
628
629
630 static void
631 get_result(unsigned char *result_buffer,
632 unsigned int *result_size)
633 {
634 unsigned char a, b;
635 int i;
636 unsigned int retry_count;
637
638
639 while (handle_sony_cd_attention())
640 ;
641
642 retry_count = jiffies + SONY_JIFFIES_TIMEOUT;
643 while ((retry_count > jiffies) && (is_busy() || (!(is_result_ready()))))
644 {
645 sony_sleep();
646
647 while (handle_sony_cd_attention())
648 ;
649 }
650 if (is_busy() || (!(is_result_ready())))
651 {
652 #if DEBUG
653 printk("CDU31A timeout out %d\n", __LINE__);
654 #endif
655 result_buffer[0] = 0x20;
656 result_buffer[1] = SONY_TIMEOUT_OP_ERR;
657 *result_size = 2;
658 return;
659 }
660
661
662
663
664
665 clear_result_ready();
666 a = read_result_register();
667 *result_buffer = a;
668 result_buffer++;
669
670
671 if ((a & 0xf0) == 0x50)
672 {
673 *result_size = 1;
674 return;
675 }
676
677 b = read_result_register();
678 *result_buffer = b;
679 result_buffer++;
680 *result_size = 2;
681
682
683
684
685
686
687
688
689
690 if ((a & 0xf0) != 0x20)
691 {
692 if (b > 8)
693 {
694 for (i=0; i<8; i++)
695 {
696 *result_buffer = read_result_register();
697 result_buffer++;
698 (*result_size)++;
699 }
700 b = b - 8;
701
702 while (b > 10)
703 {
704 retry_count = SONY_READY_RETRIES;
705 while ((retry_count > 0) && (!is_result_ready()))
706 {
707 retry_count--;
708 }
709 if (!is_result_ready())
710 {
711 #if DEBUG
712 printk("CDU31A timeout out %d\n", __LINE__);
713 #endif
714 result_buffer[0] = 0x20;
715 result_buffer[1] = SONY_TIMEOUT_OP_ERR;
716 *result_size = 2;
717 return;
718 }
719
720 clear_result_ready();
721
722 for (i=0; i<10; i++)
723 {
724 *result_buffer = read_result_register();
725 result_buffer++;
726 (*result_size)++;
727 }
728 b = b - 10;
729 }
730
731 if (b > 0)
732 {
733 retry_count = SONY_READY_RETRIES;
734 while ((retry_count > 0) && (!is_result_ready()))
735 {
736 retry_count--;
737 }
738 if (!is_result_ready())
739 {
740 #if DEBUG
741 printk("CDU31A timeout out %d\n", __LINE__);
742 #endif
743 result_buffer[0] = 0x20;
744 result_buffer[1] = SONY_TIMEOUT_OP_ERR;
745 *result_size = 2;
746 return;
747 }
748 }
749 }
750
751 while (b > 0)
752 {
753 *result_buffer = read_result_register();
754 result_buffer++;
755 (*result_size)++;
756 b--;
757 }
758 }
759 }
760
761
762
763
764
765
766 static void
767 do_sony_cd_cmd(unsigned char cmd,
768 unsigned char *params,
769 unsigned int num_params,
770 unsigned char *result_buffer,
771 unsigned int *result_size)
772 {
773 unsigned int retry_count;
774 int num_retries;
775 int recursive_call;
776 unsigned long flags;
777
778
779 save_flags(flags);
780 cli();
781 if (current != has_cd_task)
782 {
783 while (sony_inuse)
784 {
785 interruptible_sleep_on(&sony_wait);
786 if (current->signal & ~current->blocked)
787 {
788 result_buffer[0] = 0x20;
789 result_buffer[1] = SONY_SIGNAL_OP_ERR;
790 *result_size = 2;
791 return;
792 }
793 }
794 sony_inuse = 1;
795 has_cd_task = current;
796 recursive_call = 0;
797 }
798 else
799 {
800 recursive_call = 1;
801 }
802 restore_flags(flags);
803
804 num_retries = 0;
805 retry_cd_operation:
806
807 while (handle_sony_cd_attention())
808 ;
809
810 retry_count = jiffies + SONY_JIFFIES_TIMEOUT;
811 while ((retry_count > jiffies) && (is_busy()))
812 {
813 sony_sleep();
814
815 while (handle_sony_cd_attention())
816 ;
817 }
818 if (is_busy())
819 {
820 #if DEBUG
821 printk("CDU31A timeout out %d\n", __LINE__);
822 #endif
823 result_buffer[0] = 0x20;
824 result_buffer[1] = SONY_TIMEOUT_OP_ERR;
825 *result_size = 2;
826 }
827 else
828 {
829 clear_result_ready();
830 clear_param_reg();
831
832 write_params(params, num_params);
833 write_cmd(cmd);
834
835 get_result(result_buffer, result_size);
836 }
837
838 if ( ((result_buffer[0] & 0xf0) == 0x20)
839 && (num_retries < MAX_CDU31A_RETRIES))
840 {
841 num_retries++;
842 current->state = TASK_INTERRUPTIBLE;
843 current->timeout = jiffies + 10;
844 schedule();
845 goto retry_cd_operation;
846 }
847
848 if (!recursive_call)
849 {
850 has_cd_task = NULL;
851 sony_inuse = 0;
852 wake_up_interruptible(&sony_wait);
853 }
854 }
855
856
857
858
859
860
861
862
863
864
865
866 static int
867 handle_sony_cd_attention(void)
868 {
869 unsigned char atten_code;
870 static int num_consecutive_attentions = 0;
871
872
873 if (is_attention())
874 {
875 if (num_consecutive_attentions > CDU31A_MAX_CONSECUTIVE_ATTENTIONS)
876 {
877 printk("cdu31a: Too many consecutive attentions: %d\n",
878 num_consecutive_attentions);
879 num_consecutive_attentions = 0;
880 return(0);
881 }
882
883 clear_attention();
884 atten_code = read_result_register();
885
886 switch (atten_code)
887 {
888
889 case SONY_MECH_LOADED_ATTN:
890 disk_changed = 1;
891 sony_toc_read = 0;
892 sony_audio_status = CDROM_AUDIO_NO_STATUS;
893 sony_blocks_left = 0;
894 break;
895
896 case SONY_SPIN_DOWN_COMPLETE_ATTN:
897
898 sony_spun_up = 0;
899 break;
900
901 case SONY_AUDIO_PLAY_DONE_ATTN:
902 sony_audio_status = CDROM_AUDIO_COMPLETED;
903 read_subcode();
904 break;
905
906 case SONY_EJECT_PUSHED_ATTN:
907 sony_audio_status = CDROM_AUDIO_INVALID;
908 break;
909
910 case SONY_LEAD_IN_ERR_ATTN:
911 case SONY_LEAD_OUT_ERR_ATTN:
912 case SONY_DATA_TRACK_ERR_ATTN:
913 case SONY_AUDIO_PLAYBACK_ERR_ATTN:
914 sony_audio_status = CDROM_AUDIO_ERROR;
915 break;
916 }
917
918 num_consecutive_attentions++;
919 return(1);
920 }
921
922 num_consecutive_attentions = 0;
923 return(0);
924 }
925
926
927
928 static inline unsigned int
929 int_to_bcd(unsigned int val)
930 {
931 int retval;
932
933
934 retval = (val / 10) << 4;
935 retval = retval | val % 10;
936 return(retval);
937 }
938
939
940
941 static unsigned int
942 bcd_to_int(unsigned int bcd)
943 {
944 return((((bcd >> 4) & 0x0f) * 10) + (bcd & 0x0f));
945 }
946
947
948
949
950
951
952 static void
953 log_to_msf(unsigned int log, unsigned char *msf)
954 {
955 log = log + LOG_START_OFFSET;
956 msf[0] = int_to_bcd(log / 4500);
957 log = log % 4500;
958 msf[1] = int_to_bcd(log / 75);
959 msf[2] = int_to_bcd(log % 75);
960 }
961
962
963
964
965
966 static unsigned int
967 msf_to_log(unsigned char *msf)
968 {
969 unsigned int log;
970
971
972 log = bcd_to_int(msf[2]);
973 log += bcd_to_int(msf[1]) * 75;
974 log += bcd_to_int(msf[0]) * 4500;
975 log = log - LOG_START_OFFSET;
976
977 return log;
978 }
979
980
981
982
983
984
985 static void
986 size_to_buf(unsigned int size,
987 unsigned char *buf)
988 {
989 buf[0] = size / 65536;
990 size = size % 65536;
991 buf[1] = size / 256;
992 buf[2] = size % 256;
993 }
994
995
996
997
998
999
1000
1001 static int
1002 start_request(unsigned int sector,
1003 unsigned int nsect,
1004 int read_nsect_only)
1005 {
1006 unsigned char params[6];
1007 unsigned int read_size;
1008 unsigned int retry_count;
1009
1010
1011 log_to_msf(sector, params);
1012
1013 if (read_nsect_only)
1014 {
1015 read_size = nsect;
1016 }
1017
1018
1019
1020
1021 else if ((sector + nsect) >= sony_toc->lead_out_start_lba)
1022 {
1023 read_size = sony_toc->lead_out_start_lba - sector;
1024 }
1025
1026 else
1027 {
1028 read_size = CDU31A_READAHEAD;
1029 }
1030 size_to_buf(read_size, ¶ms[3]);
1031
1032
1033
1034
1035
1036 while (handle_sony_cd_attention())
1037 ;
1038
1039 retry_count = jiffies + SONY_JIFFIES_TIMEOUT;
1040 while ((retry_count > jiffies) && (is_busy()))
1041 {
1042 sony_sleep();
1043
1044 while (handle_sony_cd_attention())
1045 ;
1046 }
1047
1048 if (is_busy())
1049 {
1050 printk("CDU31A: Timeout while waiting to issue command\n");
1051 return(1);
1052 }
1053 else
1054 {
1055
1056 clear_result_ready();
1057 clear_param_reg();
1058
1059 write_params(params, 6);
1060 write_cmd(SONY_READ_BLKERR_STAT_CMD);
1061
1062 sony_blocks_left = read_size * 4;
1063 sony_next_block = sector * 4;
1064 readahead_dataleft = 0;
1065 readahead_bad = 0;
1066 return(0);
1067 }
1068 }
1069
1070
1071
1072 static void
1073 abort_read(void)
1074 {
1075 unsigned char result_reg[2];
1076 int result_size;
1077 volatile int val;
1078
1079
1080 do_sony_cd_cmd(SONY_ABORT_CMD, NULL, 0, result_reg, &result_size);
1081 if ((result_reg[0] & 0xf0) == 0x20)
1082 {
1083 printk("CDU31A: Error aborting read, error = 0x%2.2x\n",
1084 result_reg[1]);
1085 }
1086
1087 while (is_result_reg_not_empty())
1088 {
1089 val = read_result_register();
1090 }
1091 clear_data_ready();
1092 clear_result_ready();
1093
1094 while (is_data_requested())
1095 {
1096 val = read_data_register();
1097 }
1098
1099 sony_blocks_left = 0;
1100 readahead_dataleft = 0;
1101 readahead_bad = 0;
1102 }
1103
1104
1105
1106 static void
1107 handle_abort_timeout(unsigned long data)
1108 {
1109 abort_read();
1110 }
1111
1112
1113 static void
1114 input_data(char *buffer,
1115 unsigned int bytesleft,
1116 unsigned int nblocks,
1117 unsigned int offset,
1118 unsigned int skip)
1119 {
1120 int i;
1121 volatile unsigned char val;
1122
1123
1124
1125
1126 if (sony_xa_mode)
1127 {
1128 for(i=0; i<CD_XA_HEAD; i++)
1129 {
1130 val = read_data_register();
1131 }
1132 }
1133
1134 clear_data_ready();
1135
1136 if (bytesleft == 2048)
1137 {
1138 insb(sony_cd_read_reg, buffer, 2048);
1139 readahead_dataleft = 0;
1140 }
1141 else
1142 {
1143
1144
1145 if (skip != 0)
1146 {
1147 insb(sony_cd_read_reg, readahead_buffer, skip);
1148 }
1149
1150
1151 insb(sony_cd_read_reg, &buffer[offset], bytesleft);
1152
1153
1154
1155 readahead_dataleft = (2048 - skip) - bytesleft;
1156 insb(sony_cd_read_reg,
1157 readahead_buffer + bytesleft,
1158 readahead_dataleft);
1159 }
1160 sony_blocks_left -= nblocks;
1161 sony_next_block += nblocks;
1162
1163
1164
1165 if (sony_xa_mode)
1166 {
1167 for(i=0; i<CD_XA_TAIL; i++)
1168 {
1169 val = read_data_register();
1170 }
1171 }
1172 }
1173
1174
1175 static void
1176 read_data_block(char *buffer,
1177 unsigned int block,
1178 unsigned int nblocks,
1179 unsigned char res_reg[],
1180 int *res_size)
1181 {
1182 unsigned int retry_count;
1183 unsigned int bytesleft;
1184 unsigned int offset;
1185 unsigned int skip;
1186
1187
1188 res_reg[0] = 0;
1189 res_reg[1] = 0;
1190 *res_size = 0;
1191 bytesleft = nblocks * 512;
1192 offset = 0;
1193
1194
1195
1196 if (((block % 4) * 512) != ((2048 - readahead_dataleft) % 2048))
1197 {
1198 sony_next_block += block % 4;
1199 sony_blocks_left -= block % 4;
1200 skip = (block % 4) * 512;
1201 }
1202 else
1203 {
1204 skip = 0;
1205 }
1206
1207
1208
1209 if (readahead_dataleft != 0)
1210 {
1211 if (bytesleft > readahead_dataleft)
1212 {
1213
1214
1215 memcpy(buffer,
1216 readahead_buffer + (2048 - readahead_dataleft),
1217 readahead_dataleft);
1218 readahead_dataleft = 0;
1219 bytesleft -= readahead_dataleft;
1220 offset += readahead_dataleft;
1221 }
1222 else
1223 {
1224
1225
1226 memcpy(buffer,
1227 readahead_buffer + (2048 - readahead_dataleft),
1228 bytesleft);
1229 readahead_dataleft -= bytesleft;
1230 bytesleft = 0;
1231 sony_blocks_left -= nblocks;
1232 sony_next_block += nblocks;
1233
1234
1235
1236 if (readahead_bad)
1237 {
1238 res_reg[0] = 0x20;
1239 res_reg[1] = SONY_BAD_DATA_ERR;
1240 *res_size = 2;
1241 }
1242
1243 if (readahead_dataleft == 0)
1244 {
1245 readahead_bad = 0;
1246 }
1247
1248
1249 if (sony_blocks_left == 0)
1250 {
1251 get_result(res_reg, res_size);
1252 }
1253 return;
1254 }
1255 }
1256
1257
1258 retry_count = jiffies + SONY_JIFFIES_TIMEOUT;
1259 while ((retry_count > jiffies) && !(is_data_ready()))
1260 {
1261 while (handle_sony_cd_attention())
1262 ;
1263
1264 sony_sleep();
1265 }
1266 if (!(is_data_ready()))
1267 {
1268 if (is_result_ready())
1269 {
1270 get_result(res_reg, res_size);
1271 if ((res_reg[0] & 0xf0) != 0x20)
1272 {
1273 printk("CDU31A: Got result that should have been error: %d\n",
1274 res_reg[0]);
1275 res_reg[0] = 0x20;
1276 res_reg[1] = SONY_BAD_DATA_ERR;
1277 *res_size = 2;
1278 }
1279 abort_read();
1280 }
1281 else
1282 {
1283 #if DEBUG
1284 printk("CDU31A timeout out %d\n", __LINE__);
1285 #endif
1286 res_reg[0] = 0x20;
1287 res_reg[1] = SONY_TIMEOUT_OP_ERR;
1288 *res_size = 2;
1289 abort_read();
1290 }
1291 }
1292 else
1293 {
1294 input_data(buffer, bytesleft, nblocks, offset, skip);
1295
1296
1297 retry_count = jiffies + SONY_JIFFIES_TIMEOUT;
1298 while ((retry_count > jiffies) && !(is_result_ready()))
1299 {
1300 while (handle_sony_cd_attention())
1301 ;
1302
1303 sony_sleep();
1304 }
1305
1306 if (!is_result_ready())
1307 {
1308 #if DEBUG
1309 printk("CDU31A timeout out %d\n", __LINE__);
1310 #endif
1311 res_reg[0] = 0x20;
1312 res_reg[1] = SONY_TIMEOUT_OP_ERR;
1313 *res_size = 2;
1314 abort_read();
1315 }
1316 else
1317 {
1318 get_result(res_reg, res_size);
1319
1320
1321 if ((res_reg[0] & 0xf0) == 0x50)
1322 {
1323
1324 if ( (res_reg[0] == SONY_NO_CIRC_ERR_BLK_STAT)
1325 || (res_reg[0] == SONY_NO_LECC_ERR_BLK_STAT)
1326 || (res_reg[0] == SONY_RECOV_LECC_ERR_BLK_STAT))
1327 {
1328
1329
1330
1331 if (readahead_bad)
1332 {
1333 readahead_bad = 0;
1334 res_reg[0] = 0x20;
1335 res_reg[1] = SONY_BAD_DATA_ERR;
1336 *res_size = 2;
1337 }
1338 }
1339 else
1340 {
1341 printk("CDU31A: Data block error: 0x%x\n", res_reg[0]);
1342 res_reg[0] = 0x20;
1343 res_reg[1] = SONY_BAD_DATA_ERR;
1344 *res_size = 2;
1345
1346
1347
1348 if (bytesleft != 2048)
1349 {
1350 readahead_bad = 1;
1351 }
1352 }
1353
1354
1355 if (sony_blocks_left == 0)
1356 {
1357 get_result(res_reg, res_size);
1358 }
1359 }
1360 else if ((res_reg[0] & 0xf0) != 0x20)
1361 {
1362
1363
1364 printk("CDU31A: Invalid block status: 0x%x\n", res_reg[0]);
1365 restart_on_error();
1366 res_reg[0] = 0x20;
1367 res_reg[1] = SONY_BAD_DATA_ERR;
1368 *res_size = 2;
1369 }
1370 }
1371 }
1372 }
1373
1374
1375
1376
1377
1378
1379
1380
1381 static void
1382 do_cdu31a_request(void)
1383 {
1384 int block;
1385 int nblock;
1386 unsigned char res_reg[12];
1387 unsigned int res_size;
1388 int num_retries;
1389 unsigned long flags;
1390
1391
1392
1393
1394
1395
1396 save_flags(flags);
1397 cli();
1398 while (sony_inuse)
1399 {
1400 interruptible_sleep_on(&sony_wait);
1401 if (current->signal & ~current->blocked)
1402 {
1403 restore_flags(flags);
1404 if (CURRENT && (CURRENT->dev > 0))
1405 {
1406 end_request(0);
1407 }
1408 restore_flags(flags);
1409 return;
1410 }
1411 }
1412 sony_inuse = 1;
1413 has_cd_task = current;
1414 sti();
1415
1416
1417 while (handle_sony_cd_attention())
1418 ;
1419
1420
1421 if (cdu31a_abort_timer.next != NULL)
1422 {
1423 del_timer(&cdu31a_abort_timer);
1424 }
1425
1426 while (1)
1427 {
1428 cdu31a_request_startover:
1429
1430
1431
1432
1433 if (!(CURRENT) || CURRENT->dev < 0)
1434 {
1435 goto end_do_cdu31a_request;
1436 }
1437
1438 if (!sony_spun_up)
1439 {
1440 struct inode in;
1441
1442
1443
1444
1445 in.i_rdev = CURRENT->dev;
1446 scd_open(&in,NULL);
1447 }
1448
1449
1450
1451
1452 if (MAJOR(CURRENT->dev) != MAJOR_NR)
1453 {
1454 panic(DEVICE_NAME ": request list destroyed");
1455 }
1456 if (CURRENT->bh)
1457 {
1458 if (!CURRENT->bh->b_lock)
1459 {
1460 panic(DEVICE_NAME ": block not locked");
1461 }
1462 }
1463
1464 block = CURRENT->sector;
1465 nblock = CURRENT->nr_sectors;
1466
1467 if (!sony_toc_read)
1468 {
1469 printk("CDU31A: TOC not read\n");
1470 end_request(0);
1471 goto cdu31a_request_startover;
1472 }
1473
1474
1475
1476
1477
1478 if (block < 80)
1479 {
1480
1481 block += (sony_toc->start_track_lba * 4);
1482 }
1483
1484 switch(CURRENT->cmd)
1485 {
1486 case READ:
1487
1488
1489
1490
1491 #if 0
1492 if ((block / 4) < sony_toc->start_track_lba)
1493 {
1494 printk("CDU31A: Request before beginning of media\n");
1495 end_request(0);
1496 goto cdu31a_request_startover;
1497 }
1498 #endif
1499 if ((block / 4) >= sony_toc->lead_out_start_lba)
1500 {
1501 printk("CDU31A: Request past end of media\n");
1502 end_request(0);
1503 goto cdu31a_request_startover;
1504 }
1505 if (((block + nblock) / 4) >= sony_toc->lead_out_start_lba)
1506 {
1507 printk("CDU31A: Request past end of media\n");
1508 end_request(0);
1509 goto cdu31a_request_startover;
1510 }
1511
1512 num_retries = 0;
1513
1514 try_read_again:
1515 while (handle_sony_cd_attention())
1516 ;
1517
1518 if (!sony_toc_read)
1519 {
1520 printk("CDU31A: TOC not read\n");
1521 end_request(0);
1522 goto cdu31a_request_startover;
1523 }
1524
1525
1526
1527 if (sony_blocks_left == 0)
1528 {
1529 if (start_request(block / 4, CDU31A_READAHEAD / 4, 0))
1530 {
1531 end_request(0);
1532 goto cdu31a_request_startover;
1533 }
1534 }
1535
1536
1537
1538 else if (block != sony_next_block)
1539 {
1540 #if DEBUG
1541 printk("CDU31A Warning: Read for block %d, expected %d\n",
1542 block,
1543 sony_next_block);
1544 #endif
1545 abort_read();
1546 if (!sony_toc_read)
1547 {
1548 printk("CDU31A: TOC not read\n");
1549 end_request(0);
1550 goto cdu31a_request_startover;
1551 }
1552 if (start_request(block / 4, CDU31A_READAHEAD / 4, 0))
1553 {
1554 printk("CDU31a: start request failed\n");
1555 end_request(0);
1556 goto cdu31a_request_startover;
1557 }
1558 }
1559
1560 read_data_block(CURRENT->buffer, block, nblock, res_reg, &res_size);
1561 if (res_reg[0] == 0x20)
1562 {
1563 if (num_retries > MAX_CDU31A_RETRIES)
1564 {
1565 end_request(0);
1566 goto cdu31a_request_startover;
1567 }
1568
1569 num_retries++;
1570 if (res_reg[1] == SONY_NOT_SPIN_ERR)
1571 {
1572 do_sony_cd_cmd(SONY_SPIN_UP_CMD, NULL, 0, res_reg, &res_size);
1573 }
1574 else
1575 {
1576 printk("CDU31A: Read error: 0x%2.2x\n", res_reg[1]);
1577 }
1578 goto try_read_again;
1579 }
1580 else
1581 {
1582 end_request(1);
1583 }
1584 break;
1585
1586 case WRITE:
1587 end_request(0);
1588 break;
1589
1590 default:
1591 panic("CDU31A: Unknown cmd");
1592 }
1593 }
1594
1595 end_do_cdu31a_request:
1596 #if 0
1597
1598 abort_read();
1599 #else
1600
1601
1602 cdu31a_abort_timer.expires = 200;
1603 add_timer(&cdu31a_abort_timer);
1604 #endif
1605
1606 has_cd_task = NULL;
1607 sony_inuse = 0;
1608 wake_up_interruptible(&sony_wait);
1609 restore_flags(flags);
1610 }
1611
1612
1613 static void
1614 mcovlp(char *dst,
1615 char *src,
1616 int size)
1617 {
1618 src += (size - 1);
1619 dst += (size - 1);
1620 while (size > 0)
1621 {
1622 *dst = *src;
1623 size--;
1624 dst--;
1625 src--;
1626 }
1627 }
1628
1629
1630
1631
1632
1633
1634 static void
1635 sony_get_toc(void)
1636 {
1637 unsigned char res_reg[2];
1638 unsigned int res_size;
1639 unsigned char parms[1];
1640 int session;
1641
1642
1643 #if DEBUG
1644 printk("Entering sony_get_toc\n");
1645 #endif
1646
1647 if (!sony_toc_read)
1648 {
1649
1650
1651
1652
1653
1654
1655 session = 2;
1656 while (1)
1657 {
1658 #if DEBUG
1659 printk("Trying session %d\n", session);
1660 #endif
1661 parms[0] = session;
1662 do_sony_cd_cmd(SONY_READ_TOC_SPEC_CMD,
1663 parms,
1664 1,
1665 res_reg,
1666 &res_size);
1667
1668 #if DEBUG
1669 printk("%2.2x %2.2x\n", res_reg[0], res_reg[1]);
1670 #endif
1671
1672 if ((res_size < 2) || ((res_reg[0] & 0xf0) == 0x20))
1673 {
1674
1675 break;
1676 }
1677
1678 session++;
1679
1680
1681 if (session > 20)
1682 {
1683 return;
1684 }
1685 }
1686
1687 session--;
1688
1689 #if DEBUG
1690 printk("Reading session %d\n", session);
1691 #endif
1692
1693 parms[0] = session;
1694 do_sony_cd_cmd(SONY_REQ_TOC_DATA_SPEC_CMD,
1695 parms,
1696 1,
1697 (unsigned char *) sony_toc,
1698 &res_size);
1699 if ((res_size < 2) || ((sony_toc->exec_status[0] & 0xf0) == 0x20))
1700 {
1701
1702
1703 return;
1704 }
1705
1706 sony_toc_read = 1;
1707
1708
1709
1710 if (sony_toc->pointb0 != 0xb0)
1711 {
1712 mcovlp(((char *) sony_toc) + 27,
1713 ((char *) sony_toc) + 18,
1714 res_size - 18);
1715 res_size += 9;
1716 }
1717 if (sony_toc->pointb1 != 0xb1)
1718 {
1719 mcovlp(((char *) sony_toc) + 36,
1720 ((char *) sony_toc) + 27,
1721 res_size - 27);
1722 res_size += 9;
1723 }
1724 if (sony_toc->pointb2 != 0xb2)
1725 {
1726 mcovlp(((char *) sony_toc) + 45,
1727 ((char *) sony_toc) + 36,
1728 res_size - 36);
1729 res_size += 9;
1730 }
1731 if (sony_toc->pointb3 != 0xb3)
1732 {
1733 mcovlp(((char *) sony_toc) + 54,
1734 ((char *) sony_toc) + 45,
1735 res_size - 45);
1736 res_size += 9;
1737 }
1738 if (sony_toc->pointb4 != 0xb4)
1739 {
1740 mcovlp(((char *) sony_toc) + 63,
1741 ((char *) sony_toc) + 54,
1742 res_size - 54);
1743 res_size += 9;
1744 }
1745 if (sony_toc->pointc0 != 0xc0)
1746 {
1747 mcovlp(((char *) sony_toc) + 72,
1748 ((char *) sony_toc) + 63,
1749 res_size - 63);
1750 res_size += 9;
1751 }
1752
1753 sony_toc->start_track_lba = msf_to_log(sony_toc->tracks[0].track_start_msf);
1754 sony_toc->lead_out_start_lba = msf_to_log(sony_toc->lead_out_start_msf);
1755
1756 #if DEBUG
1757 printk("Disk session %d, start track: %d, stop track: %d\n",
1758 session,
1759 sony_toc->start_track_lba,
1760 sony_toc->lead_out_start_lba);
1761 #endif
1762 }
1763 #if DEBUG
1764 printk("Leaving sony_get_toc\n");
1765 #endif
1766 }
1767
1768
1769
1770
1771
1772 static int
1773 find_track(int track)
1774 {
1775 int i;
1776 int num_tracks;
1777
1778
1779 num_tracks = sony_toc->last_track_num - sony_toc->first_track_num + 1;
1780 for (i = 0; i < num_tracks; i++)
1781 {
1782 if (sony_toc->tracks[i].track == track)
1783 {
1784 return i;
1785 }
1786 }
1787
1788 return -1;
1789 }
1790
1791
1792
1793
1794
1795 static int
1796 read_subcode(void)
1797 {
1798 unsigned int res_size;
1799
1800
1801 do_sony_cd_cmd(SONY_REQ_SUBCODE_ADDRESS_CMD,
1802 NULL,
1803 0,
1804 (unsigned char *) last_sony_subcode,
1805 &res_size);
1806 if ((res_size < 2) || ((last_sony_subcode->exec_status[0] & 0xf0) == 0x20))
1807 {
1808 printk("Sony CDROM error 0x%2.2x (read_subcode)\n",
1809 last_sony_subcode->exec_status[1]);
1810 return -EIO;
1811 }
1812
1813 return 0;
1814 }
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824 static int
1825 sony_get_subchnl_info(long arg)
1826 {
1827 struct cdrom_subchnl schi;
1828
1829
1830
1831 while (handle_sony_cd_attention())
1832 ;
1833
1834 sony_get_toc();
1835 if (!sony_toc_read)
1836 {
1837 return -EIO;
1838 }
1839
1840 verify_area(VERIFY_READ, (char *) arg, sizeof(schi));
1841 verify_area(VERIFY_WRITE, (char *) arg, sizeof(schi));
1842
1843 memcpy_fromfs(&schi, (char *) arg, sizeof(schi));
1844
1845 switch (sony_audio_status)
1846 {
1847 case CDROM_AUDIO_PLAY:
1848 if (read_subcode() < 0)
1849 {
1850 return -EIO;
1851 }
1852 break;
1853
1854 case CDROM_AUDIO_PAUSED:
1855 case CDROM_AUDIO_COMPLETED:
1856 break;
1857
1858 case CDROM_AUDIO_NO_STATUS:
1859 schi.cdsc_audiostatus = sony_audio_status;
1860 memcpy_tofs((char *) arg, &schi, sizeof(schi));
1861 return 0;
1862 break;
1863
1864 case CDROM_AUDIO_INVALID:
1865 case CDROM_AUDIO_ERROR:
1866 default:
1867 return -EIO;
1868 }
1869
1870 schi.cdsc_audiostatus = sony_audio_status;
1871 schi.cdsc_adr = last_sony_subcode->address;
1872 schi.cdsc_ctrl = last_sony_subcode->control;
1873 schi.cdsc_trk = bcd_to_int(last_sony_subcode->track_num);
1874 schi.cdsc_ind = bcd_to_int(last_sony_subcode->index_num);
1875 if (schi.cdsc_format == CDROM_MSF)
1876 {
1877 schi.cdsc_absaddr.msf.minute = bcd_to_int(last_sony_subcode->abs_msf[0]);
1878 schi.cdsc_absaddr.msf.second = bcd_to_int(last_sony_subcode->abs_msf[1]);
1879 schi.cdsc_absaddr.msf.frame = bcd_to_int(last_sony_subcode->abs_msf[2]);
1880
1881 schi.cdsc_reladdr.msf.minute = bcd_to_int(last_sony_subcode->rel_msf[0]);
1882 schi.cdsc_reladdr.msf.second = bcd_to_int(last_sony_subcode->rel_msf[1]);
1883 schi.cdsc_reladdr.msf.frame = bcd_to_int(last_sony_subcode->rel_msf[2]);
1884 }
1885 else if (schi.cdsc_format == CDROM_LBA)
1886 {
1887 schi.cdsc_absaddr.lba = msf_to_log(last_sony_subcode->abs_msf);
1888 schi.cdsc_reladdr.lba = msf_to_log(last_sony_subcode->rel_msf);
1889 }
1890
1891 memcpy_tofs((char *) arg, &schi, sizeof(schi));
1892 return 0;
1893 }
1894
1895
1896
1897
1898
1899 static void
1900 read_audio_data(char *buffer,
1901 unsigned char res_reg[],
1902 int *res_size)
1903 {
1904 unsigned int retry_count;
1905 int result_read;
1906
1907
1908 res_reg[0] = 0;
1909 res_reg[1] = 0;
1910 *res_size = 0;
1911 result_read = 0;
1912
1913
1914 retry_count = jiffies + SONY_JIFFIES_TIMEOUT;
1915 continue_read_audio_wait:
1916 while ( (retry_count > jiffies)
1917 && !(is_data_ready())
1918 && !(is_result_ready() || result_read))
1919 {
1920 while (handle_sony_cd_attention())
1921 ;
1922
1923 sony_sleep();
1924 }
1925 if (!(is_data_ready()))
1926 {
1927 if (is_result_ready() && !result_read)
1928 {
1929 get_result(res_reg, res_size);
1930
1931
1932 if ((res_reg[0] & 0xf0) == 0x50)
1933 {
1934 result_read = 1;
1935 goto continue_read_audio_wait;
1936 }
1937
1938 else if ((res_reg[0] & 0xf0) != 0x20)
1939 {
1940 printk("CDU31A: Got result that should have been error: %d\n",
1941 res_reg[0]);
1942 res_reg[0] = 0x20;
1943 res_reg[1] = SONY_BAD_DATA_ERR;
1944 *res_size = 2;
1945 }
1946 abort_read();
1947 }
1948 else
1949 {
1950 #if DEBUG
1951 printk("CDU31A timeout out %d\n", __LINE__);
1952 #endif
1953 res_reg[0] = 0x20;
1954 res_reg[1] = SONY_TIMEOUT_OP_ERR;
1955 *res_size = 2;
1956 abort_read();
1957 }
1958 }
1959 else
1960 {
1961 clear_data_ready();
1962
1963
1964 if (sony_raw_data_mode)
1965 {
1966 insb(sony_cd_read_reg, buffer + CD_XA_HEAD, CD_FRAMESIZE_XA);
1967 }
1968 else
1969 {
1970
1971 insb(sony_cd_read_reg, buffer, CD_FRAMESIZE_RAW);
1972 }
1973
1974
1975 if (!result_read)
1976 {
1977
1978 retry_count = jiffies + SONY_JIFFIES_TIMEOUT;
1979 while ((retry_count > jiffies) && !(is_result_ready()))
1980 {
1981 while (handle_sony_cd_attention())
1982 ;
1983
1984 sony_sleep();
1985 }
1986
1987 if (!is_result_ready())
1988 {
1989 #if DEBUG
1990 printk("CDU31A timeout out %d\n", __LINE__);
1991 #endif
1992 res_reg[0] = 0x20;
1993 res_reg[1] = SONY_TIMEOUT_OP_ERR;
1994 *res_size = 2;
1995 abort_read();
1996 return;
1997 }
1998 else
1999 {
2000 get_result(res_reg, res_size);
2001 }
2002 }
2003
2004 if ((res_reg[0] & 0xf0) == 0x50)
2005 {
2006 if ( (res_reg[0] == SONY_NO_CIRC_ERR_BLK_STAT)
2007 || (res_reg[0] == SONY_NO_LECC_ERR_BLK_STAT)
2008 || (res_reg[0] == SONY_RECOV_LECC_ERR_BLK_STAT)
2009 || (res_reg[0] == SONY_NO_ERR_DETECTION_STAT))
2010 {
2011
2012 }
2013 else
2014 {
2015 printk("CDU31A: Data block error: 0x%x\n", res_reg[0]);
2016 res_reg[0] = 0x20;
2017 res_reg[1] = SONY_BAD_DATA_ERR;
2018 *res_size = 2;
2019 }
2020 }
2021 else if ((res_reg[0] & 0xf0) != 0x20)
2022 {
2023
2024
2025 printk("CDU31A: Invalid block status: 0x%x\n", res_reg[0]);
2026 restart_on_error();
2027 res_reg[0] = 0x20;
2028 res_reg[1] = SONY_BAD_DATA_ERR;
2029 *res_size = 2;
2030 }
2031 }
2032 }
2033
2034
2035
2036 static int
2037 read_audio(struct cdrom_read_audio *ra,
2038 struct inode *inode)
2039 {
2040 int retval;
2041 unsigned char params[2];
2042 unsigned char res_reg[12];
2043 unsigned int res_size;
2044 unsigned int cframe;
2045 unsigned long flags;
2046
2047
2048
2049
2050
2051 save_flags(flags);
2052 cli();
2053 while (sony_inuse)
2054 {
2055 interruptible_sleep_on(&sony_wait);
2056 if (current->signal & ~current->blocked)
2057 {
2058 return -EAGAIN;
2059 }
2060 }
2061 sony_inuse = 1;
2062 has_cd_task = current;
2063 restore_flags(flags);
2064
2065 if (!sony_spun_up)
2066 {
2067 scd_open (inode, NULL);
2068 }
2069
2070
2071 params[0] = SONY_SD_DECODE_PARAM;
2072 params[1] = 0x06 | sony_raw_data_mode;
2073 do_sony_cd_cmd(SONY_SET_DRIVE_PARAM_CMD,
2074 params,
2075 2,
2076 res_reg,
2077 &res_size);
2078 if ((res_size < 2) || ((res_reg[0] & 0xf0) == 0x20))
2079 {
2080 printk("CDU31A: Unable to set decode params: 0x%2.2x\n", res_reg[1]);
2081 return -EIO;
2082 }
2083
2084
2085
2086
2087
2088 retval = 0;
2089
2090 if (start_request(ra->addr.lba, ra->nframes, 1))
2091 {
2092 retval = -EIO;
2093 goto exit_read_audio;
2094 }
2095
2096
2097 cframe = 0;
2098 while (cframe < ra->nframes)
2099 {
2100 read_audio_data(readahead_buffer, res_reg, &res_size);
2101 if ((res_reg[0] & 0xf0) == 0x20)
2102 {
2103 if (res_reg[1] == SONY_BAD_DATA_ERR)
2104 {
2105 printk("CDU31A: Data error on audio sector %d\n",
2106 ra->addr.lba + cframe);
2107 }
2108 else if (res_reg[1] == SONY_ILL_TRACK_R_ERR)
2109 {
2110
2111 sony_raw_data_mode = (sony_raw_data_mode) ? 0 : 1;
2112
2113
2114 params[0] = SONY_SD_DECODE_PARAM;
2115 params[1] = 0x06 | sony_raw_data_mode;
2116 do_sony_cd_cmd(SONY_SET_DRIVE_PARAM_CMD,
2117 params,
2118 2,
2119 res_reg,
2120 &res_size);
2121 if ((res_size < 2) || ((res_reg[0] & 0xf0) == 0x20))
2122 {
2123 printk("CDU31A: Unable to set decode params: 0x%2.2x\n", res_reg[1]);
2124 retval = -EIO;
2125 goto exit_read_audio;
2126 }
2127
2128
2129 if (start_request(ra->addr.lba + cframe, ra->nframes - cframe, 1))
2130 {
2131 retval = -EIO;
2132 goto exit_read_audio;
2133 }
2134
2135
2136
2137
2138 read_audio_data(readahead_buffer, res_reg, &res_size);
2139 if ((res_reg[0] & 0xf0) == 0x20)
2140 {
2141 if (res_reg[1] == SONY_BAD_DATA_ERR)
2142 {
2143 printk("CDU31A: Data error on audio sector %d\n",
2144 ra->addr.lba + cframe);
2145 }
2146 else
2147 {
2148 printk("CDU31A: Error reading audio data on sector %d: 0x%x\n",
2149 ra->addr.lba + cframe,
2150 res_reg[1]);
2151 retval = -EIO;
2152 goto exit_read_audio;
2153 }
2154 }
2155 else
2156 {
2157 memcpy_tofs((char *) (ra->buf + (CD_FRAMESIZE_RAW * cframe)),
2158 (char *) readahead_buffer,
2159 CD_FRAMESIZE_RAW);
2160 }
2161 }
2162 else
2163 {
2164 printk("CDU31A: Error reading audio data on sector %d: 0x%x\n",
2165 ra->addr.lba + cframe,
2166 res_reg[1]);
2167 retval = -EIO;
2168 goto exit_read_audio;
2169 }
2170 }
2171 else
2172 {
2173 memcpy_tofs((char *) (ra->buf + (CD_FRAMESIZE_RAW * cframe)),
2174 (char *) readahead_buffer,
2175 CD_FRAMESIZE_RAW);
2176 }
2177
2178 cframe++;
2179 }
2180
2181 get_result(res_reg, &res_size);
2182 if ((res_reg[0] & 0xf0) == 0x20)
2183 {
2184 printk("CDU31A: Error return from audio read: 0x%x\n",
2185 res_reg[1]);
2186 retval = -EIO;
2187 goto exit_read_audio;
2188 }
2189
2190 exit_read_audio:
2191
2192
2193 params[0] = SONY_SD_DECODE_PARAM;
2194 if (!sony_xa_mode)
2195 {
2196 params[1] = 0x0f;
2197 }
2198 else
2199 {
2200 params[1] = 0x07;
2201 }
2202 do_sony_cd_cmd(SONY_SET_DRIVE_PARAM_CMD,
2203 params,
2204 2,
2205 res_reg,
2206 &res_size);
2207 if ((res_size < 2) || ((res_reg[0] & 0xf0) == 0x20))
2208 {
2209 printk("CDU31A: Unable to reset decode params: 0x%2.2x\n", res_reg[1]);
2210 return -EIO;
2211 }
2212
2213 has_cd_task = NULL;
2214 sony_inuse = 0;
2215 wake_up_interruptible(&sony_wait);
2216
2217 return(retval);
2218 }
2219
2220
2221
2222
2223
2224 static int do_sony_cd_cmd_chk(char *name, unsigned char cmd, unsigned char *params, unsigned int num_params,
2225 unsigned char *result_buffer, unsigned int *result_size)
2226 {
2227 do_sony_cd_cmd(cmd, params, num_params, result_buffer, result_size);
2228 if ((*result_size < 2) || ((result_buffer[0] & 0xf0) == 0x20))
2229 {
2230 printk("Sony CDROM error 0x%2.2x (CDROM%s)\n", result_buffer[1], name);
2231 return -EIO;
2232 }
2233 return 0;
2234 }
2235
2236 static int scd_ioctl(struct inode *inode,
2237 struct file *file,
2238 unsigned int cmd,
2239 unsigned long arg)
2240 {
2241 unsigned char res_reg[12];
2242 unsigned int res_size;
2243 unsigned char params[7];
2244 int i;
2245
2246
2247 if (!inode)
2248 {
2249 return -EINVAL;
2250 }
2251
2252 switch (cmd)
2253 {
2254 case CDROMSTART:
2255 return do_sony_cd_cmd_chk("START",SONY_SPIN_UP_CMD, NULL, 0, res_reg, &res_size);
2256 return 0;
2257 break;
2258
2259 case CDROMSTOP:
2260 do_sony_cd_cmd(SONY_AUDIO_STOP_CMD, NULL, 0, res_reg, &res_size);
2261
2262
2263
2264
2265
2266 sony_audio_status = CDROM_AUDIO_NO_STATUS;
2267 return do_sony_cd_cmd_chk("STOP",SONY_SPIN_DOWN_CMD, NULL, 0, res_reg, &res_size);
2268
2269 case CDROMPAUSE:
2270 if(do_sony_cd_cmd_chk("PAUSE", SONY_AUDIO_STOP_CMD, NULL, 0, res_reg, &res_size))
2271 return -EIO;
2272
2273 if (read_subcode() < 0)
2274 {
2275 return -EIO;
2276 }
2277 cur_pos_msf[0] = last_sony_subcode->abs_msf[0];
2278 cur_pos_msf[1] = last_sony_subcode->abs_msf[1];
2279 cur_pos_msf[2] = last_sony_subcode->abs_msf[2];
2280 sony_audio_status = CDROM_AUDIO_PAUSED;
2281 return 0;
2282 break;
2283
2284 case CDROMRESUME:
2285 if (sony_audio_status != CDROM_AUDIO_PAUSED)
2286 {
2287 return -EINVAL;
2288 }
2289
2290 do_sony_cd_cmd(SONY_SPIN_UP_CMD, NULL, 0, res_reg, &res_size);
2291
2292
2293 params[1] = cur_pos_msf[0];
2294 params[2] = cur_pos_msf[1];
2295 params[3] = cur_pos_msf[2];
2296 params[4] = final_pos_msf[0];
2297 params[5] = final_pos_msf[1];
2298 params[6] = final_pos_msf[2];
2299 params[0] = 0x03;
2300 if(do_sony_cd_cmd_chk("RESUME",SONY_AUDIO_PLAYBACK_CMD, params, 7, res_reg, &res_size)<0)
2301 return -EIO;
2302 sony_audio_status = CDROM_AUDIO_PLAY;
2303 return 0;
2304
2305 case CDROMPLAYMSF:
2306 i=verify_area(VERIFY_READ, (char *) arg, 6);
2307 if(i)
2308 return i;
2309 do_sony_cd_cmd(SONY_SPIN_UP_CMD, NULL, 0, res_reg, &res_size);
2310 memcpy_fromfs(&(params[1]), (void *) arg, 6);
2311
2312
2313 for (i=1; i<7; i++)
2314 {
2315 params[i] = int_to_bcd(params[i]);
2316 }
2317 params[0] = 0x03;
2318 if(do_sony_cd_cmd_chk("PLAYMSF",SONY_AUDIO_PLAYBACK_CMD, params, 7, res_reg, &res_size)<0)
2319 return -EIO;
2320
2321
2322 final_pos_msf[0] = params[4];
2323 final_pos_msf[1] = params[5];
2324 final_pos_msf[2] = params[6];
2325 sony_audio_status = CDROM_AUDIO_PLAY;
2326 return 0;
2327
2328 case CDROMREADTOCHDR:
2329 {
2330 struct cdrom_tochdr *hdr;
2331 struct cdrom_tochdr loc_hdr;
2332
2333 sony_get_toc();
2334 if (!sony_toc_read)
2335 {
2336 return -EIO;
2337 }
2338
2339 hdr = (struct cdrom_tochdr *) arg;
2340 i=verify_area(VERIFY_WRITE, hdr, sizeof(*hdr));
2341 if(i<0)
2342 return i;
2343 loc_hdr.cdth_trk0 = bcd_to_int(sony_toc->first_track_num);
2344 loc_hdr.cdth_trk1 = bcd_to_int(sony_toc->last_track_num);
2345 memcpy_tofs(hdr, &loc_hdr, sizeof(*hdr));
2346 }
2347 return 0;
2348
2349 case CDROMREADTOCENTRY:
2350 {
2351 struct cdrom_tocentry *entry;
2352 struct cdrom_tocentry loc_entry;
2353 int track_idx;
2354 unsigned char *msf_val = NULL;
2355
2356 sony_get_toc();
2357 if (!sony_toc_read)
2358 {
2359 return -EIO;
2360 }
2361
2362 entry = (struct cdrom_tocentry *) arg;
2363 i=verify_area(VERIFY_READ, entry, sizeof(*entry));
2364 if(i<0)
2365 return i;
2366 i=verify_area(VERIFY_WRITE, entry, sizeof(*entry));
2367 if(i<0)
2368 return i;
2369
2370 memcpy_fromfs(&loc_entry, entry, sizeof(loc_entry));
2371
2372
2373 if (loc_entry.cdte_track == CDROM_LEADOUT)
2374 {
2375 loc_entry.cdte_adr = sony_toc->address2;
2376 loc_entry.cdte_ctrl = sony_toc->control2;
2377 msf_val = sony_toc->lead_out_start_msf;
2378 }
2379 else
2380 {
2381 track_idx = find_track(int_to_bcd(loc_entry.cdte_track));
2382 if (track_idx < 0)
2383 {
2384 return -EINVAL;
2385 }
2386
2387 loc_entry.cdte_adr = sony_toc->tracks[track_idx].address;
2388 loc_entry.cdte_ctrl = sony_toc->tracks[track_idx].control;
2389 msf_val = sony_toc->tracks[track_idx].track_start_msf;
2390 }
2391
2392
2393 if (loc_entry.cdte_format == CDROM_LBA)
2394 {
2395 loc_entry.cdte_addr.lba = msf_to_log(msf_val);
2396 }
2397 else if (loc_entry.cdte_format == CDROM_MSF)
2398 {
2399 loc_entry.cdte_addr.msf.minute = bcd_to_int(*msf_val);
2400 loc_entry.cdte_addr.msf.second = bcd_to_int(*(msf_val+1));
2401 loc_entry.cdte_addr.msf.frame = bcd_to_int(*(msf_val+2));
2402 }
2403 memcpy_tofs(entry, &loc_entry, sizeof(*entry));
2404 }
2405 return 0;
2406 break;
2407
2408 case CDROMPLAYTRKIND:
2409 {
2410 struct cdrom_ti ti;
2411 int track_idx;
2412
2413 sony_get_toc();
2414 if (!sony_toc_read)
2415 {
2416 return -EIO;
2417 }
2418
2419 i=verify_area(VERIFY_READ, (char *) arg, sizeof(ti));
2420 if(i<0)
2421 return i;
2422
2423 memcpy_fromfs(&ti, (char *) arg, sizeof(ti));
2424 if ( (ti.cdti_trk0 < sony_toc->first_track_num)
2425 || (ti.cdti_trk0 > sony_toc->last_track_num)
2426 || (ti.cdti_trk1 < ti.cdti_trk0))
2427 {
2428 return -EINVAL;
2429 }
2430
2431 track_idx = find_track(int_to_bcd(ti.cdti_trk0));
2432 if (track_idx < 0)
2433 {
2434 return -EINVAL;
2435 }
2436 params[1] = sony_toc->tracks[track_idx].track_start_msf[0];
2437 params[2] = sony_toc->tracks[track_idx].track_start_msf[1];
2438 params[3] = sony_toc->tracks[track_idx].track_start_msf[2];
2439
2440
2441
2442
2443
2444 if (ti.cdti_trk1 >= bcd_to_int(sony_toc->last_track_num))
2445 {
2446 log_to_msf(msf_to_log(sony_toc->lead_out_start_msf)-1,
2447 &(params[4]));
2448 }
2449 else
2450 {
2451 track_idx = find_track(int_to_bcd(ti.cdti_trk1+1));
2452 if (track_idx < 0)
2453 {
2454 return -EINVAL;
2455 }
2456 log_to_msf(msf_to_log(sony_toc->tracks[track_idx].track_start_msf)-1,
2457 &(params[4]));
2458 }
2459 params[0] = 0x03;
2460
2461 do_sony_cd_cmd(SONY_SPIN_UP_CMD, NULL, 0, res_reg, &res_size);
2462
2463 do_sony_cd_cmd(SONY_AUDIO_PLAYBACK_CMD, params, 7, res_reg, &res_size);
2464
2465 if ((res_size < 2) || ((res_reg[0] & 0xf0) == 0x20))
2466 {
2467 printk("Params: %x %x %x %x %x %x %x\n", params[0], params[1],
2468 params[2], params[3], params[4], params[5], params[6]);
2469 printk("Sony CDROM error 0x%2.2x (CDROMPLAYTRKIND\n", res_reg[1]);
2470 return -EIO;
2471 }
2472
2473
2474 final_pos_msf[0] = params[4];
2475 final_pos_msf[1] = params[5];
2476 final_pos_msf[2] = params[6];
2477 sony_audio_status = CDROM_AUDIO_PLAY;
2478 return 0;
2479 }
2480
2481 case CDROMSUBCHNL:
2482 return sony_get_subchnl_info(arg);
2483
2484 case CDROMVOLCTRL:
2485 {
2486 struct cdrom_volctrl volctrl;
2487
2488 i=verify_area(VERIFY_READ, (char *) arg, sizeof(volctrl));
2489 if(i<0)
2490 return i;
2491
2492 memcpy_fromfs(&volctrl, (char *) arg, sizeof(volctrl));
2493 params[0] = SONY_SD_AUDIO_VOLUME;
2494 params[1] = volctrl.channel0;
2495 params[2] = volctrl.channel1;
2496 return do_sony_cd_cmd_chk("VOLCTRL",SONY_SET_DRIVE_PARAM_CMD, params, 3, res_reg, &res_size);
2497 }
2498 case CDROMEJECT:
2499 do_sony_cd_cmd(SONY_AUDIO_STOP_CMD, NULL, 0, res_reg, &res_size);
2500 do_sony_cd_cmd(SONY_SPIN_DOWN_CMD, NULL, 0, res_reg, &res_size);
2501
2502 sony_audio_status = CDROM_AUDIO_INVALID;
2503 return do_sony_cd_cmd_chk("EJECT",SONY_EJECT_CMD, NULL, 0, res_reg, &res_size);
2504
2505 case CDROMREADAUDIO:
2506
2507 {
2508 struct cdrom_read_audio ra;
2509
2510
2511 sony_get_toc();
2512 if (!sony_toc_read)
2513 {
2514 return -EIO;
2515 }
2516
2517 i=verify_area(VERIFY_READ, (char *) arg, sizeof(ra));
2518 if(i<0)
2519 return i;
2520 memcpy_fromfs(&ra, (char *) arg, sizeof(ra));
2521
2522 i=verify_area(VERIFY_WRITE, ra.buf, CD_FRAMESIZE_RAW * ra.nframes);
2523 if(i<0)
2524 return i;
2525
2526 if (ra.addr_format == CDROM_LBA)
2527 {
2528 if ( (ra.addr.lba >= sony_toc->lead_out_start_lba)
2529 || (ra.addr.lba + ra.nframes >= sony_toc->lead_out_start_lba))
2530 {
2531 return -EINVAL;
2532 }
2533 }
2534 else if (ra.addr_format == CDROM_MSF)
2535 {
2536 if ( (ra.addr.msf.minute >= 75)
2537 || (ra.addr.msf.second >= 60)
2538 || (ra.addr.msf.frame >= 75))
2539 {
2540 return -EINVAL;
2541 }
2542
2543 ra.addr.lba = ( (ra.addr.msf.minute * 4500)
2544 + (ra.addr.msf.second * 75)
2545 + ra.addr.msf.frame);
2546 if ( (ra.addr.lba >= sony_toc->lead_out_start_lba)
2547 || (ra.addr.lba + ra.nframes >= sony_toc->lead_out_start_lba))
2548 {
2549 return -EINVAL;
2550 }
2551
2552
2553
2554
2555 ra.addr.lba -= LOG_START_OFFSET;
2556 }
2557 else
2558 {
2559 return -EINVAL;
2560 }
2561
2562 return(read_audio(&ra, inode));
2563 }
2564 return 0;
2565 break;
2566
2567 default:
2568 return -EINVAL;
2569 }
2570 }
2571
2572
2573
2574
2575
2576
2577 static int
2578 scd_open(struct inode *inode,
2579 struct file *filp)
2580 {
2581 unsigned char res_reg[12];
2582 unsigned int res_size;
2583 int num_spin_ups;
2584 unsigned char params[2];
2585
2586
2587 if ((filp) && filp->f_mode & 2)
2588 return -EROFS;
2589
2590 if (!sony_spun_up)
2591 {
2592 num_spin_ups = 0;
2593
2594 respinup_on_open:
2595 do_sony_cd_cmd(SONY_SPIN_UP_CMD, NULL, 0, res_reg, &res_size);
2596
2597
2598
2599 if ((res_size < 2) || ((res_reg[0] != 0) && (res_reg[1] != 0)))
2600 {
2601 printk("Sony CDROM error 0x%2.2x (scd_open, spin up)\n", res_reg[1]);
2602 return -EIO;
2603 }
2604
2605 do_sony_cd_cmd(SONY_READ_TOC_CMD, NULL, 0, res_reg, &res_size);
2606
2607
2608
2609 if ((res_size < 2) || ((res_reg[0] != 0) && (res_reg[1] != 0)))
2610 {
2611
2612 if ((res_reg[1] == SONY_AUDIO_PLAYING_ERR) || (res_reg[1] == 0))
2613 {
2614 goto drive_spinning;
2615 }
2616
2617
2618
2619 if ( (res_reg[1] == SONY_NOT_SPIN_ERR)
2620 && (num_spin_ups < MAX_CDU31A_RETRIES))
2621 {
2622 num_spin_ups++;
2623 goto respinup_on_open;
2624 }
2625
2626 printk("Sony CDROM error 0x%2.2x (scd_open, read toc)\n", res_reg[1]);
2627 do_sony_cd_cmd(SONY_SPIN_DOWN_CMD, NULL, 0, res_reg, &res_size);
2628
2629 return -EIO;
2630 }
2631
2632 sony_get_toc();
2633 if (!sony_toc_read)
2634 {
2635 do_sony_cd_cmd(SONY_SPIN_DOWN_CMD, NULL, 0, res_reg, &res_size);
2636 return -EIO;
2637 }
2638
2639
2640
2641 if ( (sony_toc->disk_type == SONY_XA_DISK_TYPE)
2642 && (!is_double_speed))
2643 {
2644 params[0] = SONY_SD_DECODE_PARAM;
2645 params[1] = 0x07;
2646 do_sony_cd_cmd(SONY_SET_DRIVE_PARAM_CMD,
2647 params,
2648 2,
2649 res_reg,
2650 &res_size);
2651 if ((res_size < 2) || ((res_reg[0] & 0xf0) == 0x20))
2652 {
2653 printk("CDU31A: Unable to set XA params: 0x%2.2x\n", res_reg[1]);
2654 }
2655 sony_xa_mode = 1;
2656 }
2657
2658 else if (sony_xa_mode)
2659 {
2660 params[0] = SONY_SD_DECODE_PARAM;
2661 params[1] = 0x0f;
2662 do_sony_cd_cmd(SONY_SET_DRIVE_PARAM_CMD,
2663 params,
2664 2,
2665 res_reg,
2666 &res_size);
2667 if ((res_size < 2) || ((res_reg[0] & 0xf0) == 0x20))
2668 {
2669 printk("CDU31A: Unable to reset XA params: 0x%2.2x\n", res_reg[1]);
2670 }
2671 sony_xa_mode = 0;
2672 }
2673
2674 sony_spun_up = 1;
2675 }
2676
2677 drive_spinning:
2678
2679
2680 if (filp)
2681 {
2682 check_disk_change(inode->i_rdev);
2683 }
2684
2685 sony_usage++;
2686
2687 return 0;
2688 }
2689
2690
2691
2692
2693
2694
2695 static void
2696 scd_release(struct inode *inode,
2697 struct file *filp)
2698 {
2699 unsigned char res_reg[12];
2700 unsigned int res_size;
2701
2702
2703 if (sony_usage > 0)
2704 {
2705 sony_usage--;
2706 }
2707 if (sony_usage == 0)
2708 {
2709 sync_dev(inode->i_rdev);
2710 do_sony_cd_cmd(SONY_SPIN_DOWN_CMD, NULL, 0, res_reg, &res_size);
2711
2712 sony_spun_up = 0;
2713 }
2714 }
2715
2716
2717 static struct file_operations scd_fops = {
2718 NULL,
2719 block_read,
2720 block_write,
2721 NULL,
2722 NULL,
2723 scd_ioctl,
2724 NULL,
2725 scd_open,
2726 scd_release,
2727 NULL,
2728 NULL,
2729 scd_disk_change,
2730 NULL
2731 };
2732
2733
2734
2735 static char *load_mech[] = { "caddy", "tray", "pop-up", "unknown" };
2736
2737 static void
2738 get_drive_configuration(unsigned short base_io,
2739 unsigned char res_reg[],
2740 unsigned int *res_size)
2741 {
2742 int retry_count;
2743
2744
2745
2746 sony_cd_base_io = base_io;
2747
2748
2749 sony_cd_cmd_reg = sony_cd_base_io + SONY_CMD_REG_OFFSET;
2750 sony_cd_param_reg = sony_cd_base_io + SONY_PARAM_REG_OFFSET;
2751 sony_cd_write_reg = sony_cd_base_io + SONY_WRITE_REG_OFFSET;
2752 sony_cd_control_reg = sony_cd_base_io + SONY_CONTROL_REG_OFFSET;
2753 sony_cd_status_reg = sony_cd_base_io + SONY_STATUS_REG_OFFSET;
2754 sony_cd_result_reg = sony_cd_base_io + SONY_RESULT_REG_OFFSET;
2755 sony_cd_read_reg = sony_cd_base_io + SONY_READ_REG_OFFSET;
2756 sony_cd_fifost_reg = sony_cd_base_io + SONY_FIFOST_REG_OFFSET;
2757
2758
2759
2760
2761
2762
2763 if (read_status_register() != 0xff)
2764 {
2765
2766
2767
2768
2769 reset_drive();
2770 retry_count = jiffies + SONY_RESET_TIMEOUT;
2771 while ((retry_count > jiffies) && (!is_attention()))
2772 {
2773 sony_sleep();
2774 }
2775
2776 #if 0
2777
2778 if (!is_attention())
2779 {
2780 res_reg[0] = 0x20;
2781 return;
2782 }
2783 #endif
2784
2785
2786
2787
2788 do_sony_cd_cmd(SONY_REQ_DRIVE_CONFIG_CMD,
2789 NULL,
2790 0,
2791 (unsigned char *) res_reg,
2792 res_size);
2793 return;
2794 }
2795
2796
2797 res_reg[0] = 0x20;
2798 }
2799
2800
2801
2802
2803 void
2804 cdu31a_setup(char *strings,
2805 int *ints)
2806 {
2807 if (ints[0] > 0)
2808 {
2809 sony_cd_base_io = ints[1];
2810 }
2811 if (ints[0] > 1)
2812 {
2813 irq_used = ints[2];
2814 }
2815 if ((strings != NULL) && (*strings != '\0'))
2816 {
2817 if (strcmp(strings, "PAS") == 0)
2818 {
2819 sony_pas_init = 1;
2820 }
2821 else
2822 {
2823 printk("CDU31A: Unknown interface type: %s\n", strings);
2824 }
2825 }
2826 }
2827
2828 static int cdu31a_block_size;
2829
2830
2831
2832
2833 unsigned long
2834 cdu31a_init(unsigned long mem_start, unsigned long mem_end)
2835 {
2836 struct s_sony_drive_config drive_config;
2837 unsigned int res_size;
2838 int i;
2839 int drive_found;
2840 int tmp_irq;
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850 if (sony_pas_init)
2851 {
2852 outb(0xbc, 0x9a01);
2853 outb(0xe2, 0x9a01);
2854 }
2855
2856 drive_found = 0;
2857
2858
2859 if (sony_cd_base_io == 0xffff)
2860 {
2861 }
2862 else if (sony_cd_base_io != 0)
2863 {
2864 tmp_irq = irq_used;
2865 irq_used = 0;
2866
2867 get_drive_configuration(sony_cd_base_io,
2868 drive_config.exec_status,
2869 &res_size);
2870 if ((res_size > 2) && ((drive_config.exec_status[0] & 0xf0) == 0x00))
2871 {
2872 drive_found = 1;
2873 }
2874
2875 irq_used = tmp_irq;
2876 }
2877 else
2878 {
2879 irq_used = 0;
2880 i = 0;
2881 while ( (cdu31a_addresses[i].base != 0)
2882 && (!drive_found))
2883 {
2884 if (check_region(cdu31a_addresses[i].base, 4)) {
2885 i++;
2886 continue;
2887 }
2888 get_drive_configuration(cdu31a_addresses[i].base,
2889 drive_config.exec_status,
2890 &res_size);
2891 if ((res_size > 2) && ((drive_config.exec_status[0] & 0xf0) == 0x00))
2892 {
2893 drive_found = 1;
2894 irq_used = cdu31a_addresses[i].int_num;
2895 }
2896 else
2897 {
2898 i++;
2899 }
2900 }
2901 }
2902
2903 if (drive_found)
2904 {
2905 request_region(sony_cd_base_io, 4,"cdu31a");
2906
2907 if (register_blkdev(MAJOR_NR,"cdu31a",&scd_fops))
2908 {
2909 printk("Unable to get major %d for CDU-31a\n", MAJOR_NR);
2910 return mem_start;
2911 }
2912
2913 if (SONY_HWC_DOUBLE_SPEED(drive_config))
2914 {
2915 is_double_speed = 1;
2916 }
2917
2918
2919 if (irq_used < 0)
2920 {
2921 autoirq_setup(0);
2922 enable_interrupts();
2923 reset_drive();
2924 tmp_irq = autoirq_report(10);
2925 disable_interrupts();
2926
2927 irq_used = 0;
2928 set_drive_params();
2929 irq_used = tmp_irq;
2930 }
2931 else
2932 {
2933 tmp_irq = irq_used;
2934 irq_used = 0;
2935
2936 set_drive_params();
2937
2938 irq_used = tmp_irq;
2939 }
2940
2941 if (irq_used > 0)
2942 {
2943 if (request_irq(irq_used, cdu31a_interrupt, SA_INTERRUPT, "cdu31a"))
2944 {
2945 printk("Unable to grab IRQ%d for the CDU31A driver\n", irq_used);
2946 irq_used = 0;
2947 }
2948 }
2949
2950 printk("Sony I/F CDROM : %8.8s %16.16s %8.8s\n",
2951 drive_config.vendor_id,
2952 drive_config.product_id,
2953 drive_config.product_rev_level);
2954 printk(" Capabilities: %s",
2955 load_mech[SONY_HWC_GET_LOAD_MECH(drive_config)]);
2956 if (SONY_HWC_AUDIO_PLAYBACK(drive_config))
2957 {
2958 printk(", audio");
2959 }
2960 if (SONY_HWC_EJECT(drive_config))
2961 {
2962 printk(", eject");
2963 }
2964 if (SONY_HWC_LED_SUPPORT(drive_config))
2965 {
2966 printk(", LED");
2967 }
2968 if (SONY_HWC_ELECTRIC_VOLUME(drive_config))
2969 {
2970 printk(", elec. Vol");
2971 }
2972 if (SONY_HWC_ELECTRIC_VOLUME_CTL(drive_config))
2973 {
2974 printk(", sep. Vol");
2975 }
2976 if (is_double_speed)
2977 {
2978 printk(", double speed");
2979 }
2980 if (irq_used > 0)
2981 {
2982 printk(", irq %d", irq_used);
2983 }
2984 printk("\n");
2985
2986 blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST;
2987 read_ahead[MAJOR_NR] = CDU31A_READAHEAD;
2988 cdu31a_block_size = 1024;
2989
2990 blksize_size[MAJOR_NR] = &cdu31a_block_size;
2991
2992 last_sony_subcode = (struct s_sony_subcode *) mem_start;
2993 mem_start += sizeof(*last_sony_subcode);
2994 readahead_buffer = (unsigned char *) mem_start;
2995 mem_start += CD_FRAMESIZE_RAW;
2996 sony_toc = (struct s_sony_session_toc *) mem_start;
2997 mem_start += sizeof(struct s_sony_session_toc);
2998
2999 cdu31a_abort_timer.next = NULL;
3000 cdu31a_abort_timer.prev = NULL;
3001 cdu31a_abort_timer.function = handle_abort_timeout;
3002 }
3003
3004
3005 disk_changed = 1;
3006
3007 return mem_start;
3008 }