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