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