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