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
- 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
- read_data_dma
- read_data_block
- get_data
- do_sony_cd_cmd
- handle_sony_cd_attention
- int_to_bcd
- bcd_to_int
- log_to_msf
- msf_to_log
- size_to_buf
- do_cdu31a_request
- sony_get_toc
- find_track
- read_subcode
- sony_get_subchnl_info
- scd_ioctl
- scd_open
- scd_release
- get_drive_configuration
- 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 #include <linux/errno.h>
120 #include <linux/signal.h>
121 #include <linux/sched.h>
122 #include <linux/timer.h>
123 #include <linux/fs.h>
124 #include <linux/kernel.h>
125 #include <linux/hdreg.h>
126 #include <linux/genhd.h>
127 #include <linux/ioport.h>
128 #include <linux/string.h>
129
130 #include <asm/system.h>
131 #include <asm/io.h>
132 #include <asm/segment.h>
133 #include <asm/dma.h>
134
135 #include <linux/cdrom.h>
136 #include <linux/cdu31a.h>
137
138 #define MAJOR_NR CDU31A_CDROM_MAJOR
139 #include "blk.h"
140
141 #define CDU31A_MAX_CONSECUTIVE_ATTENTIONS 10
142
143
144 #undef SONY_POLL_EACH_BYTE
145
146
147
148
149
150
151 static struct
152 {
153 unsigned short base;
154 short dma_num;
155 short int_num;
156
157 } cdu31a_addresses[] =
158 {
159 { 0x340, -1, 0 },
160 { 0x1f88, -1, 0 },
161 { 0x230, -1, 0 },
162 { 0x360, -1, 0 },
163 { 0x320, -1, 0 },
164 { 0x330, -1, 0 },
165 { 0x634, -1, 0 },
166 { 0x654, -1, 0 },
167 { 0 }
168 };
169
170 static int handle_sony_cd_attention(void);
171 static int read_subcode(void);
172 static void sony_get_toc(void);
173 static int scd_open(struct inode *inode, struct file *filp);
174 static void do_sony_cd_cmd(unsigned char cmd,
175 unsigned char *params,
176 unsigned int num_params,
177 unsigned char *result_buffer,
178 unsigned int *result_size);
179 static void size_to_buf(unsigned int size,
180 unsigned char *buf);
181
182
183
184
185 static unsigned short sony_cd_base_io = 0;
186
187
188
189
190
191 static volatile unsigned short sony_cd_cmd_reg;
192 static volatile unsigned short sony_cd_param_reg;
193 static volatile unsigned short sony_cd_write_reg;
194 static volatile unsigned short sony_cd_control_reg;
195 static volatile unsigned short sony_cd_status_reg;
196 static volatile unsigned short sony_cd_result_reg;
197 static volatile unsigned short sony_cd_read_reg;
198 static volatile unsigned short sony_cd_fifost_reg;
199
200
201 static int sony_disc_changed = 1;
202
203 static int sony_toc_read = 0;
204
205 static int sony_spun_up = 0;
206 static unsigned int sony_buffer_size;
207
208 static unsigned int sony_buffer_sectors;
209
210 static unsigned int sony_usage = 0;
211
212
213 static volatile int sony_first_block = -1;
214
215 static volatile int sony_last_block = -1;
216
217
218 static struct s_sony_toc *sony_toc;
219
220 static struct s_sony_subcode * volatile last_sony_subcode;
221
222 static unsigned char * volatile sony_buffer;
223
224
225 static volatile int sony_inuse = 0;
226
227
228 static struct wait_queue * sony_wait = NULL;
229
230 static struct task_struct *has_cd_task = NULL;
231
232
233 static int is_double_speed = 0;
234
235
236
237
238
239 static volatile int sony_audio_status = CDROM_AUDIO_NO_STATUS;
240
241
242
243
244
245
246
247
248 static unsigned volatile char cur_pos_msf[3] = { 0, 0, 0 };
249 static unsigned volatile char final_pos_msf[3] = { 0, 0, 0 };
250
251 static int irq_used = -1;
252 static int dma_channel = -1;
253 static struct wait_queue *cdu31a_irq_wait = NULL;
254
255 static int curr_control_reg = 0;
256
257
258
259
260
261 static int
262 scd_disk_change(dev_t full_dev)
263 {
264 int retval, target;
265
266
267 target = MINOR(full_dev);
268
269 if (target > 0) {
270 printk("Sony CD-ROM request error: invalid device.\n");
271 return 0;
272 }
273
274 retval = sony_disc_changed;
275 sony_disc_changed = 0;
276
277 return retval;
278 }
279
280 static inline void
281 enable_interrupts(void)
282 {
283 curr_control_reg |= ( SONY_ATTN_INT_EN_BIT
284 | SONY_RES_RDY_INT_EN_BIT
285 | SONY_DATA_RDY_INT_EN_BIT);
286 outb(curr_control_reg, sony_cd_control_reg);
287 }
288
289 static inline void
290 disable_interrupts(void)
291 {
292 curr_control_reg &= ~( SONY_ATTN_INT_EN_BIT
293 | SONY_RES_RDY_INT_EN_BIT
294 | SONY_DATA_RDY_INT_EN_BIT);
295 outb(curr_control_reg, sony_cd_control_reg);
296 }
297
298 static void
299 cdu31a_interrupt(int unused)
300 {
301 disable_interrupts();
302 wake_up(&cdu31a_irq_wait);
303 }
304
305
306
307
308
309 static inline void
310 sony_sleep(void)
311 {
312 if (irq_used <= 0)
313 {
314 current->state = TASK_INTERRUPTIBLE;
315 current->timeout = jiffies;
316 schedule();
317 }
318 else
319 {
320 cli();
321 enable_interrupts();
322 interruptible_sleep_on(&cdu31a_irq_wait);
323 sti();
324 }
325 }
326
327
328
329
330
331
332 static inline int
333 is_attention(void)
334 {
335 return((inb(sony_cd_status_reg) & SONY_ATTN_BIT) != 0);
336 }
337
338 static inline int
339 is_busy(void)
340 {
341 return((inb(sony_cd_status_reg) & SONY_BUSY_BIT) != 0);
342 }
343
344 static inline int
345 is_data_ready(void)
346 {
347 return((inb(sony_cd_status_reg) & SONY_DATA_RDY_BIT) != 0);
348 }
349
350 static inline int
351 is_data_requested(void)
352 {
353 return((inb(sony_cd_status_reg) & SONY_DATA_REQUEST_BIT) != 0);
354 }
355
356 static inline int
357 is_result_ready(void)
358 {
359 return((inb(sony_cd_status_reg) & SONY_RES_RDY_BIT) != 0);
360 }
361
362 static inline int
363 is_param_write_rdy(void)
364 {
365 return((inb(sony_cd_fifost_reg) & SONY_PARAM_WRITE_RDY_BIT) != 0);
366 }
367
368 static inline void
369 reset_drive(void)
370 {
371 curr_control_reg = 0;
372 outb(SONY_DRIVE_RESET_BIT, sony_cd_control_reg);
373 }
374
375 static inline void
376 clear_attention(void)
377 {
378 outb(curr_control_reg | SONY_ATTN_CLR_BIT, sony_cd_control_reg);
379 }
380
381 static inline void
382 clear_result_ready(void)
383 {
384 outb(curr_control_reg | SONY_RES_RDY_CLR_BIT, sony_cd_control_reg);
385 }
386
387 static inline void
388 clear_data_ready(void)
389 {
390 outb(curr_control_reg | SONY_DATA_RDY_CLR_BIT, sony_cd_control_reg);
391 }
392
393 static inline void
394 clear_param_reg(void)
395 {
396 outb(curr_control_reg | SONY_PARAM_CLR_BIT, sony_cd_control_reg);
397 }
398
399 static inline unsigned char
400 read_status_register(void)
401 {
402 return(inb(sony_cd_status_reg));
403 }
404
405 static inline unsigned char
406 read_result_register(void)
407 {
408 return(inb(sony_cd_result_reg));
409 }
410
411 static inline unsigned char
412 read_data_register(void)
413 {
414 return(inb(sony_cd_read_reg));
415 }
416
417 static inline void
418 write_param(unsigned char param)
419 {
420 outb(param, sony_cd_param_reg);
421 }
422
423 static inline void
424 write_cmd(unsigned char cmd)
425 {
426 outb(curr_control_reg | SONY_RES_RDY_INT_EN_BIT, sony_cd_control_reg);
427 outb(cmd, sony_cd_cmd_reg);
428 }
429
430
431
432
433
434 static void
435 set_drive_params(void)
436 {
437 unsigned char res_reg[2];
438 unsigned int res_size;
439 unsigned char params[3];
440
441
442 params[0] = SONY_SD_MECH_CONTROL;
443 params[1] = 0x03;
444 if (is_double_speed)
445 {
446 params[1] |= 0x04;
447 }
448 do_sony_cd_cmd(SONY_SET_DRIVE_PARAM_CMD,
449 params,
450 2,
451 res_reg,
452 &res_size);
453 if ((res_size < 2) || ((res_reg[0] & 0x20) == 0x20))
454 {
455 printk(" Unable to set mechanical parameters: 0x%2.2x\n", res_reg[1]);
456 }
457 }
458
459
460
461
462 static void
463 restart_on_error(void)
464 {
465 unsigned char res_reg[2];
466 unsigned int res_size;
467 unsigned int retry_count;
468
469
470 printk("cdu31a: Resetting drive on error\n");
471 reset_drive();
472 retry_count = jiffies + SONY_RESET_TIMEOUT;
473 while ((retry_count > jiffies) && (!is_attention()))
474 {
475 sony_sleep();
476 }
477 set_drive_params();
478 do_sony_cd_cmd(SONY_SPIN_UP_CMD, NULL, 0, res_reg, &res_size);
479 if ((res_size < 2) || ((res_reg[0] & 0x20) == 0x20))
480 {
481 printk("cdu31a: Unable to spin up drive: 0x%2.2x\n", res_reg[1]);
482 }
483
484 current->state = TASK_INTERRUPTIBLE;
485 current->timeout = jiffies + 200;
486 schedule();
487
488 do_sony_cd_cmd(SONY_READ_TOC_CMD, NULL, 0, res_reg, &res_size);
489 if ((res_size < 2) || ((res_reg[0] & 0x20) == 0x20))
490 {
491 printk("cdu31a: Unable to read TOC: 0x%2.2x\n", res_reg[1]);
492 }
493 sony_get_toc();
494 if (!sony_toc_read)
495 {
496 printk("cdu31a: Unable to get TOC data\n");
497 }
498 }
499
500
501
502
503
504 static int
505 write_params(unsigned char *params,
506 int num_params)
507 {
508 unsigned int retry_count;
509
510
511 retry_count = SONY_READY_RETRIES;
512 while ((retry_count > 0) && (!is_param_write_rdy()))
513 {
514 retry_count--;
515 }
516 if (!is_param_write_rdy())
517 {
518 return -EIO;
519 }
520
521 while (num_params > 0)
522 {
523 write_param(*params);
524 params++;
525 num_params--;
526 }
527
528 return 0;
529 }
530
531
532
533
534
535
536
537
538 static void
539 get_result(unsigned char *result_buffer,
540 unsigned int *result_size)
541 {
542 unsigned char a, b;
543 int i;
544 unsigned int retry_count;
545
546
547 while (handle_sony_cd_attention())
548 ;
549
550 retry_count = jiffies + SONY_JIFFIES_TIMEOUT;
551 while ((retry_count > jiffies) && (is_busy() || (!(is_result_ready()))))
552 {
553 sony_sleep();
554
555 while (handle_sony_cd_attention())
556 ;
557 }
558 if (is_busy() || (!(is_result_ready())))
559 {
560 result_buffer[0] = 0x20;
561 result_buffer[1] = SONY_TIMEOUT_OP_ERR;
562 *result_size = 2;
563 return;
564 }
565
566
567
568
569
570 clear_result_ready();
571 a = read_result_register();
572 *result_buffer = a;
573 result_buffer++;
574 b = read_result_register();
575 *result_buffer = b;
576 result_buffer++;
577 *result_size = 2;
578
579
580
581
582
583
584
585
586
587 if ((a & 0xf0) != 0x20)
588 {
589 if (b > 8)
590 {
591 for (i=0; i<8; i++)
592 {
593 *result_buffer = read_result_register();
594 result_buffer++;
595 (*result_size)++;
596 }
597 b = b - 8;
598
599 while (b > 10)
600 {
601 retry_count = SONY_READY_RETRIES;
602 while ((retry_count > 0) && (!is_result_ready()))
603 {
604 retry_count--;
605 }
606 if (!is_result_ready())
607 {
608 result_buffer[0] = 0x20;
609 result_buffer[1] = SONY_TIMEOUT_OP_ERR;
610 *result_size = 2;
611 return;
612 }
613
614 clear_result_ready();
615
616 for (i=0; i<10; i++)
617 {
618 *result_buffer = read_result_register();
619 result_buffer++;
620 (*result_size)++;
621 }
622 b = b - 10;
623 }
624
625 if (b > 0)
626 {
627 retry_count = SONY_READY_RETRIES;
628 while ((retry_count > 0) && (!is_result_ready()))
629 {
630 retry_count--;
631 }
632 if (!is_result_ready())
633 {
634 result_buffer[0] = 0x20;
635 result_buffer[1] = SONY_TIMEOUT_OP_ERR;
636 *result_size = 2;
637 return;
638 }
639 }
640 }
641
642 while (b > 0)
643 {
644 *result_buffer = read_result_register();
645 result_buffer++;
646 (*result_size)++;
647 b--;
648 }
649 }
650 }
651
652 static void
653 read_data_dma(unsigned char *data,
654 unsigned int data_size,
655 unsigned char *result_buffer,
656 unsigned int *result_size)
657 {
658 unsigned int retry_count;
659
660
661 cli();
662 disable_dma(dma_channel);
663 clear_dma_ff(dma_channel);
664 set_dma_mode(dma_channel, DMA_MODE_READ);
665 set_dma_addr(dma_channel, (int) data);
666 set_dma_count(dma_channel, data_size);
667 enable_dma(dma_channel);
668 sti();
669
670 retry_count = jiffies + SONY_JIFFIES_TIMEOUT;
671 while ( (retry_count > jiffies)
672 && (!is_data_ready())
673 && (!is_result_ready()))
674 {
675 while (handle_sony_cd_attention())
676 ;
677
678 sony_sleep();
679 }
680 if (!is_data_requested())
681 {
682 result_buffer[0] = 0x20;
683 result_buffer[1] = SONY_TIMEOUT_OP_ERR;
684 *result_size = 2;
685 return;
686 }
687 }
688
689
690
691
692 static void
693 read_data_block(unsigned char *data,
694 unsigned int data_size,
695 unsigned char *result_buffer,
696 unsigned int *result_size)
697 {
698 #ifdef SONY_POLL_EACH_BYTE
699 int i;
700 unsigned int retry_count;
701
702 for (i=0; i<data_size; i++)
703 {
704 retry_count = jiffies + SONY_JIFFIES_TIMEOUT;
705 while ((retry_count > jiffies) && (!is_data_requested()))
706 {
707 while (handle_sony_cd_attention())
708 ;
709
710 sony_sleep();
711 }
712 if (!is_data_requested())
713 {
714 result_buffer[0] = 0x20;
715 result_buffer[1] = SONY_TIMEOUT_OP_ERR;
716 *result_size = 2;
717 return;
718 }
719
720 *data = read_data_register();
721 data++;
722 }
723 #else
724 insb(sony_cd_read_reg, data, data_size);
725 #endif
726 }
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741 static unsigned int
742 get_data(unsigned char *orig_data,
743 unsigned char *params,
744
745 unsigned int orig_data_size,
746 unsigned char *result_buffer,
747 unsigned int *result_size)
748 {
749 unsigned int cur_offset;
750 unsigned int retry_count;
751 int result_read;
752 int num_retries;
753 unsigned int num_sectors_read = 0;
754 unsigned char *data = orig_data;
755 unsigned int data_size = orig_data_size;
756
757
758 num_retries = 0;
759 retry_data_operation:
760 result_buffer[0] = 0;
761 result_buffer[1] = 0;
762
763
764
765
766
767 while (handle_sony_cd_attention())
768 ;
769
770 retry_count = jiffies + SONY_JIFFIES_TIMEOUT;
771 while ((retry_count > jiffies) && (is_busy()))
772 {
773 sony_sleep();
774
775 while (handle_sony_cd_attention())
776 ;
777 }
778
779 if (is_busy())
780 {
781 result_buffer[0] = 0x20;
782 result_buffer[1] = SONY_TIMEOUT_OP_ERR;
783 *result_size = 2;
784 }
785 else
786 {
787
788 clear_result_ready();
789 clear_param_reg();
790
791 write_params(params, 6);
792 write_cmd(SONY_READ_CMD);
793
794
795
796
797
798
799 cur_offset = 0;
800 result_read = 0;
801 while ((data_size > 0) && (result_buffer[0] == 0))
802 {
803
804 retry_count = jiffies + SONY_JIFFIES_TIMEOUT;
805 while ((retry_count > jiffies) && (!(is_result_ready() || is_data_ready())))
806 {
807 while (handle_sony_cd_attention())
808 ;
809
810 sony_sleep();
811 }
812 if (!(is_result_ready() || is_data_ready()))
813 {
814 result_buffer[0] = 0x20;
815 result_buffer[1] = SONY_TIMEOUT_OP_ERR;
816 *result_size = 2;
817 }
818
819
820 else if (is_result_ready())
821 {
822 result_read = 1;
823 get_result(result_buffer, result_size);
824 }
825
826 else if (dma_channel > 0)
827 {
828 clear_data_ready();
829 read_data_dma(data, 2048, result_buffer, result_size);
830 data += 2048;
831 data_size -= 2048;
832 cur_offset = cur_offset + 2048;
833 num_sectors_read++;
834 }
835 else
836 {
837
838
839
840
841
842
843
844
845 clear_data_ready();
846 read_data_block(data, 2048, result_buffer, result_size);
847 data += 2048;
848 data_size -= 2048;
849 cur_offset = cur_offset + 2048;
850 num_sectors_read++;
851 }
852 }
853
854
855 if (!result_read)
856 {
857 get_result(result_buffer, result_size);
858 }
859 }
860
861 if ( ((result_buffer[0] & 0x20) == 0x20)
862 && (result_buffer[1] != SONY_NOT_SPIN_ERR)
863 && (num_retries < MAX_CDU31A_RETRIES))
864 {
865
866
867
868
869
870
871
872 data_size = 2048;
873 data = orig_data;
874 num_sectors_read = 0;
875 size_to_buf(1, ¶ms[3]);
876
877 num_retries++;
878
879 if (num_retries == 2)
880 {
881 restart_on_error();
882 }
883 else
884 {
885 current->state = TASK_INTERRUPTIBLE;
886 current->timeout = jiffies + 10;
887 schedule();
888 }
889
890
891 goto retry_data_operation;
892 }
893
894 return(num_sectors_read);
895 }
896
897
898
899
900
901
902
903 static void
904 do_sony_cd_cmd(unsigned char cmd,
905 unsigned char *params,
906 unsigned int num_params,
907 unsigned char *result_buffer,
908 unsigned int *result_size)
909 {
910 unsigned int retry_count;
911 int num_retries;
912 int recursive_call;
913
914
915 cli();
916 if (current != has_cd_task)
917 {
918 while (sony_inuse)
919 {
920 interruptible_sleep_on(&sony_wait);
921 if (current->signal & ~current->blocked)
922 {
923 result_buffer[0] = 0x20;
924 result_buffer[1] = SONY_SIGNAL_OP_ERR;
925 *result_size = 2;
926 return;
927 }
928 }
929 sony_inuse = 1;
930 has_cd_task = current;
931 recursive_call = 0;
932 }
933 else
934 {
935 recursive_call = 1;
936 }
937 sti();
938
939 num_retries = 0;
940 retry_cd_operation:
941
942 while (handle_sony_cd_attention())
943 ;
944
945 retry_count = jiffies + SONY_JIFFIES_TIMEOUT;
946 while ((retry_count > jiffies) && (is_busy()))
947 {
948 sony_sleep();
949
950 while (handle_sony_cd_attention())
951 ;
952 }
953 if (is_busy())
954 {
955 result_buffer[0] = 0x20;
956 result_buffer[1] = SONY_TIMEOUT_OP_ERR;
957 *result_size = 2;
958 }
959 else
960 {
961 clear_result_ready();
962 clear_param_reg();
963
964 write_params(params, num_params);
965 write_cmd(cmd);
966
967 get_result(result_buffer, result_size);
968 }
969
970 if ( ((result_buffer[0] & 0x20) == 0x20)
971 && (num_retries < MAX_CDU31A_RETRIES))
972 {
973 num_retries++;
974 current->state = TASK_INTERRUPTIBLE;
975 current->timeout = jiffies + 10;
976 schedule();
977 goto retry_cd_operation;
978 }
979
980 if (!recursive_call)
981 {
982 has_cd_task = NULL;
983 sony_inuse = 0;
984 wake_up_interruptible(&sony_wait);
985 }
986 }
987
988
989
990
991
992
993
994
995
996
997
998 static int
999 handle_sony_cd_attention(void)
1000 {
1001 unsigned char atten_code;
1002 static int num_consecutive_attentions = 0;
1003
1004
1005 if (is_attention())
1006 {
1007 if (num_consecutive_attentions > CDU31A_MAX_CONSECUTIVE_ATTENTIONS)
1008 {
1009 printk("cdu31a: Too many consecutive attentions: %d\n",
1010 num_consecutive_attentions);
1011 num_consecutive_attentions = 0;
1012 return(0);
1013 }
1014
1015 clear_attention();
1016 atten_code = read_result_register();
1017
1018 switch (atten_code)
1019 {
1020
1021 case SONY_MECH_LOADED_ATTN:
1022 sony_disc_changed = 1;
1023 sony_toc_read = 0;
1024 sony_audio_status = CDROM_AUDIO_NO_STATUS;
1025 sony_first_block = -1;
1026 sony_last_block = -1;
1027 break;
1028
1029 case SONY_AUDIO_PLAY_DONE_ATTN:
1030 sony_audio_status = CDROM_AUDIO_COMPLETED;
1031 read_subcode();
1032 break;
1033
1034 case SONY_EJECT_PUSHED_ATTN:
1035 sony_audio_status = CDROM_AUDIO_INVALID;
1036 break;
1037
1038 case SONY_LEAD_IN_ERR_ATTN:
1039 case SONY_LEAD_OUT_ERR_ATTN:
1040 case SONY_DATA_TRACK_ERR_ATTN:
1041 case SONY_AUDIO_PLAYBACK_ERR_ATTN:
1042 sony_audio_status = CDROM_AUDIO_ERROR;
1043 break;
1044 }
1045
1046 num_consecutive_attentions++;
1047 return(1);
1048 }
1049
1050 num_consecutive_attentions = 0;
1051 return(0);
1052 }
1053
1054
1055
1056 static inline unsigned int
1057 int_to_bcd(unsigned int val)
1058 {
1059 int retval;
1060
1061
1062 retval = (val / 10) << 4;
1063 retval = retval | val % 10;
1064 return(retval);
1065 }
1066
1067
1068
1069 static unsigned int
1070 bcd_to_int(unsigned int bcd)
1071 {
1072 return((((bcd >> 4) & 0x0f) * 10) + (bcd & 0x0f));
1073 }
1074
1075
1076
1077
1078
1079
1080 static void
1081 log_to_msf(unsigned int log, unsigned char *msf)
1082 {
1083 log = log + LOG_START_OFFSET;
1084 msf[0] = int_to_bcd(log / 4500);
1085 log = log % 4500;
1086 msf[1] = int_to_bcd(log / 75);
1087 msf[2] = int_to_bcd(log % 75);
1088 }
1089
1090
1091
1092
1093
1094 static unsigned int
1095 msf_to_log(unsigned char *msf)
1096 {
1097 unsigned int log;
1098
1099
1100 log = bcd_to_int(msf[2]);
1101 log += bcd_to_int(msf[1]) * 75;
1102 log += bcd_to_int(msf[0]) * 4500;
1103 log = log - LOG_START_OFFSET;
1104
1105 return log;
1106 }
1107
1108
1109
1110
1111
1112
1113 static void
1114 size_to_buf(unsigned int size,
1115 unsigned char *buf)
1116 {
1117 buf[0] = size / 65536;
1118 size = size % 65536;
1119 buf[1] = size / 256;
1120 buf[2] = size % 256;
1121 }
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131 static void
1132 do_cdu31a_request(void)
1133 {
1134 int block;
1135 unsigned int dev;
1136 int nsect;
1137 unsigned char params[10];
1138 unsigned char res_reg[2];
1139 unsigned int res_size;
1140 int copyoff;
1141 int spin_up_retry;
1142 unsigned int read_size;
1143
1144
1145
1146
1147
1148
1149 cli();
1150 while (sony_inuse)
1151 {
1152 interruptible_sleep_on(&sony_wait);
1153 if (current->signal & ~current->blocked)
1154 {
1155 return;
1156 }
1157 }
1158 sony_inuse = 1;
1159 has_cd_task = current;
1160 sti();
1161
1162 if (!sony_spun_up)
1163 {
1164 scd_open (NULL,NULL);
1165 }
1166
1167 while (1)
1168 {
1169 cdu31a_request_startover:
1170
1171
1172
1173
1174 if (!(CURRENT) || CURRENT->dev < 0)
1175 {
1176 goto end_do_cdu31a_request;
1177 }
1178
1179 INIT_REQUEST;
1180 dev = MINOR(CURRENT->dev);
1181 block = CURRENT->sector;
1182 nsect = CURRENT->nr_sectors;
1183 if (dev != 0)
1184 {
1185 end_request(0);
1186 goto cdu31a_request_startover;
1187 }
1188
1189 switch(CURRENT->cmd)
1190 {
1191 case READ:
1192
1193
1194
1195
1196 if ((block / 4) >= sony_toc->lead_out_start_lba)
1197 {
1198 end_request(0);
1199 goto cdu31a_request_startover;
1200 }
1201 if (((block + nsect) / 4) >= sony_toc->lead_out_start_lba)
1202 {
1203 end_request(0);
1204 goto cdu31a_request_startover;
1205 }
1206
1207 while (nsect > 0)
1208 {
1209
1210
1211
1212
1213 if ((block < sony_first_block) || (block > sony_last_block))
1214 {
1215 sony_first_block = (block / 4) * 4;
1216 log_to_msf(block/4, params);
1217
1218
1219
1220
1221
1222 if (((block / 4) + sony_buffer_sectors) >= sony_toc->lead_out_start_lba)
1223 {
1224 read_size = sony_toc->lead_out_start_lba - (block / 4);
1225 }
1226 else
1227 {
1228 read_size = sony_buffer_sectors;
1229 }
1230 size_to_buf(read_size, ¶ms[3]);
1231
1232
1233
1234
1235
1236 spin_up_retry = 0;
1237 try_read_again:
1238 sony_last_block = sony_first_block
1239 + (get_data(sony_buffer,
1240 params,
1241 (read_size * 2048),
1242 res_reg,
1243 &res_size) * 4) - 1;
1244 if ((res_size < 2) || (res_reg[0] != 0))
1245 {
1246 if ((res_reg[1] == SONY_NOT_SPIN_ERR) && (!spin_up_retry))
1247 {
1248 do_sony_cd_cmd(SONY_SPIN_UP_CMD, NULL, 0, res_reg, &res_size);
1249 spin_up_retry = 1;
1250 goto try_read_again;
1251 }
1252
1253 printk("Sony CDROM Read error: 0x%2.2x\n", res_reg[1]);
1254 sony_first_block = -1;
1255 sony_last_block = -1;
1256 end_request(0);
1257 goto cdu31a_request_startover;
1258 }
1259 }
1260
1261
1262
1263
1264
1265 copyoff = (block - sony_first_block) * 512;
1266 memcpy(CURRENT->buffer, sony_buffer+copyoff, 512);
1267
1268 block += 1;
1269 nsect -= 1;
1270 CURRENT->buffer += 512;
1271 }
1272
1273 end_request(1);
1274 break;
1275
1276 case WRITE:
1277 end_request(0);
1278 break;
1279
1280 default:
1281 panic("Unknown SONY CD cmd");
1282 }
1283 }
1284
1285 end_do_cdu31a_request:
1286 has_cd_task = NULL;
1287 sony_inuse = 0;
1288 wake_up_interruptible(&sony_wait);
1289 }
1290
1291
1292
1293
1294
1295
1296 static void
1297 sony_get_toc(void)
1298 {
1299 unsigned int res_size;
1300
1301
1302 if (!sony_toc_read)
1303 {
1304 do_sony_cd_cmd(SONY_REQ_TOC_DATA_CMD,
1305 NULL,
1306 0,
1307 (unsigned char *) sony_toc,
1308 &res_size);
1309 if ((res_size < 2) || ((sony_toc->exec_status[0] & 0x20) == 0x20))
1310 {
1311 return;
1312 }
1313 sony_toc->lead_out_start_lba = msf_to_log(sony_toc->lead_out_start_msf);
1314 sony_toc_read = 1;
1315 }
1316 }
1317
1318
1319
1320
1321
1322 static int
1323 find_track(int track)
1324 {
1325 int i;
1326 int num_tracks;
1327
1328
1329 num_tracks = sony_toc->last_track_num + sony_toc->first_track_num + 1;
1330 for (i = 0; i < num_tracks; i++)
1331 {
1332 if (sony_toc->tracks[i].track == track)
1333 {
1334 return i;
1335 }
1336 }
1337
1338 return -1;
1339 }
1340
1341
1342
1343
1344
1345 static int
1346 read_subcode(void)
1347 {
1348 unsigned int res_size;
1349
1350
1351 do_sony_cd_cmd(SONY_REQ_SUBCODE_ADDRESS_CMD,
1352 NULL,
1353 0,
1354 (unsigned char *) last_sony_subcode,
1355 &res_size);
1356 if ((res_size < 2) || ((last_sony_subcode->exec_status[0] & 0x20) == 0x20))
1357 {
1358 printk("Sony CDROM error 0x%2.2x (read_subcode)\n",
1359 last_sony_subcode->exec_status[1]);
1360 return -EIO;
1361 }
1362
1363 return 0;
1364 }
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374 static int
1375 sony_get_subchnl_info(long arg)
1376 {
1377 struct cdrom_subchnl schi;
1378
1379
1380
1381 while (handle_sony_cd_attention())
1382 ;
1383
1384 sony_get_toc();
1385 if (!sony_toc_read)
1386 {
1387 return -EIO;
1388 }
1389
1390 verify_area(VERIFY_READ, (char *) arg, sizeof(schi));
1391 verify_area(VERIFY_WRITE, (char *) arg, sizeof(schi));
1392
1393 memcpy_fromfs(&schi, (char *) arg, sizeof(schi));
1394
1395 switch (sony_audio_status)
1396 {
1397 case CDROM_AUDIO_PLAY:
1398 if (read_subcode() < 0)
1399 {
1400 return -EIO;
1401 }
1402 break;
1403
1404 case CDROM_AUDIO_PAUSED:
1405 case CDROM_AUDIO_COMPLETED:
1406 break;
1407
1408 case CDROM_AUDIO_NO_STATUS:
1409 schi.cdsc_audiostatus = sony_audio_status;
1410 memcpy_tofs((char *) arg, &schi, sizeof(schi));
1411 return 0;
1412 break;
1413
1414 case CDROM_AUDIO_INVALID:
1415 case CDROM_AUDIO_ERROR:
1416 default:
1417 return -EIO;
1418 }
1419
1420 schi.cdsc_audiostatus = sony_audio_status;
1421 schi.cdsc_adr = last_sony_subcode->address;
1422 schi.cdsc_ctrl = last_sony_subcode->control;
1423 schi.cdsc_trk = bcd_to_int(last_sony_subcode->track_num);
1424 schi.cdsc_ind = bcd_to_int(last_sony_subcode->index_num);
1425 if (schi.cdsc_format == CDROM_MSF)
1426 {
1427 schi.cdsc_absaddr.msf.minute = bcd_to_int(last_sony_subcode->abs_msf[0]);
1428 schi.cdsc_absaddr.msf.second = bcd_to_int(last_sony_subcode->abs_msf[1]);
1429 schi.cdsc_absaddr.msf.frame = bcd_to_int(last_sony_subcode->abs_msf[2]);
1430
1431 schi.cdsc_reladdr.msf.minute = bcd_to_int(last_sony_subcode->rel_msf[0]);
1432 schi.cdsc_reladdr.msf.second = bcd_to_int(last_sony_subcode->rel_msf[1]);
1433 schi.cdsc_reladdr.msf.frame = bcd_to_int(last_sony_subcode->rel_msf[2]);
1434 }
1435 else if (schi.cdsc_format == CDROM_LBA)
1436 {
1437 schi.cdsc_absaddr.lba = msf_to_log(last_sony_subcode->abs_msf);
1438 schi.cdsc_reladdr.lba = msf_to_log(last_sony_subcode->rel_msf);
1439 }
1440
1441 memcpy_tofs((char *) arg, &schi, sizeof(schi));
1442 return 0;
1443 }
1444
1445
1446
1447
1448
1449 static int
1450 scd_ioctl(struct inode *inode,
1451 struct file *file,
1452 unsigned int cmd,
1453 unsigned long arg)
1454 {
1455 unsigned int dev;
1456 unsigned char res_reg[2];
1457 unsigned int res_size;
1458 unsigned char params[7];
1459 int i;
1460
1461
1462 if (!inode)
1463 {
1464 return -EINVAL;
1465 }
1466 dev = MINOR(inode->i_rdev) >> 6;
1467 if (dev != 0)
1468 {
1469 return -EINVAL;
1470 }
1471
1472 switch (cmd)
1473 {
1474 case CDROMSTART:
1475 do_sony_cd_cmd(SONY_SPIN_UP_CMD, NULL, 0, res_reg, &res_size);
1476 if ((res_size < 2) || ((res_reg[0] & 0x20) == 0x20))
1477 {
1478 printk("Sony CDROM error 0x%2.2x (CDROMSTART)\n", res_reg[1]);
1479 return -EIO;
1480 }
1481 return 0;
1482 break;
1483
1484 case CDROMSTOP:
1485 do_sony_cd_cmd(SONY_AUDIO_STOP_CMD, NULL, 0, res_reg, &res_size);
1486
1487
1488
1489
1490
1491 sony_audio_status = CDROM_AUDIO_NO_STATUS;
1492 do_sony_cd_cmd(SONY_SPIN_DOWN_CMD, NULL, 0, res_reg, &res_size);
1493 if ( ((res_size < 2) || ((res_reg[0] & 0x20) == 0x20))
1494 && (res_reg[1] != SONY_NOT_SPIN_ERR))
1495 {
1496 printk("Sony CDROM error 0x%2.2x (CDROMSTOP)\n", res_reg[1]);
1497 return -EIO;
1498 }
1499
1500 return 0;
1501 break;
1502
1503 case CDROMPAUSE:
1504 do_sony_cd_cmd(SONY_AUDIO_STOP_CMD, NULL, 0, res_reg, &res_size);
1505 if ((res_size < 2) || ((res_reg[0] & 0x20) == 0x20))
1506 {
1507 printk("Sony CDROM error 0x%2.2x (CDROMPAUSE)\n", res_reg[1]);
1508 return -EIO;
1509 }
1510
1511
1512 if (read_subcode() < 0)
1513 {
1514 return -EIO;
1515 }
1516 cur_pos_msf[0] = last_sony_subcode->abs_msf[0];
1517 cur_pos_msf[1] = last_sony_subcode->abs_msf[1];
1518 cur_pos_msf[2] = last_sony_subcode->abs_msf[2];
1519 sony_audio_status = CDROM_AUDIO_PAUSED;
1520 return 0;
1521 break;
1522
1523 case CDROMRESUME:
1524 if (sony_audio_status != CDROM_AUDIO_PAUSED)
1525 {
1526 return -EINVAL;
1527 }
1528
1529 do_sony_cd_cmd(SONY_SPIN_UP_CMD, NULL, 0, res_reg, &res_size);
1530
1531
1532 params[1] = cur_pos_msf[0];
1533 params[2] = cur_pos_msf[1];
1534 params[3] = cur_pos_msf[2];
1535 params[4] = final_pos_msf[0];
1536 params[5] = final_pos_msf[1];
1537 params[6] = final_pos_msf[2];
1538 params[0] = 0x03;
1539 do_sony_cd_cmd(SONY_AUDIO_PLAYBACK_CMD, params, 7, res_reg, &res_size);
1540 if ((res_size < 2) || ((res_reg[0] & 0x20) == 0x20))
1541 {
1542 printk("Sony CDROM error 0x%2.2x (CDROMRESUME)\n", res_reg[1]);
1543 return -EIO;
1544 }
1545 sony_audio_status = CDROM_AUDIO_PLAY;
1546 return 0;
1547 break;
1548
1549 case CDROMPLAYMSF:
1550 verify_area(VERIFY_READ, (char *) arg, 6);
1551 do_sony_cd_cmd(SONY_SPIN_UP_CMD, NULL, 0, res_reg, &res_size);
1552 memcpy_fromfs(&(params[1]), (void *) arg, 6);
1553
1554
1555 for (i=1; i<7; i++)
1556 {
1557 params[i] = int_to_bcd(params[i]);
1558 }
1559 params[0] = 0x03;
1560 do_sony_cd_cmd(SONY_AUDIO_PLAYBACK_CMD, params, 7, res_reg, &res_size);
1561 if ((res_size < 2) || ((res_reg[0] & 0x20) == 0x20))
1562 {
1563 printk("Sony CDROM error 0x%2.2x (CDROMPLAYMSF)\n", res_reg[1]);
1564 return -EIO;
1565 }
1566
1567
1568 final_pos_msf[0] = params[4];
1569 final_pos_msf[1] = params[5];
1570 final_pos_msf[2] = params[6];
1571 sony_audio_status = CDROM_AUDIO_PLAY;
1572 return 0;
1573 break;
1574
1575 case CDROMREADTOCHDR:
1576 {
1577 struct cdrom_tochdr *hdr;
1578 struct cdrom_tochdr loc_hdr;
1579
1580 sony_get_toc();
1581 if (!sony_toc_read)
1582 {
1583 return -EIO;
1584 }
1585
1586 hdr = (struct cdrom_tochdr *) arg;
1587 verify_area(VERIFY_WRITE, hdr, sizeof(*hdr));
1588 loc_hdr.cdth_trk0 = bcd_to_int(sony_toc->first_track_num);
1589 loc_hdr.cdth_trk1 = bcd_to_int(sony_toc->last_track_num);
1590 memcpy_tofs(hdr, &loc_hdr, sizeof(*hdr));
1591 }
1592 return 0;
1593 break;
1594
1595 case CDROMREADTOCENTRY:
1596 {
1597 struct cdrom_tocentry *entry;
1598 struct cdrom_tocentry loc_entry;
1599 int track_idx;
1600 unsigned char *msf_val = NULL;
1601
1602 sony_get_toc();
1603 if (!sony_toc_read)
1604 {
1605 return -EIO;
1606 }
1607
1608 entry = (struct cdrom_tocentry *) arg;
1609 verify_area(VERIFY_READ, entry, sizeof(*entry));
1610 verify_area(VERIFY_WRITE, entry, sizeof(*entry));
1611
1612 memcpy_fromfs(&loc_entry, entry, sizeof(loc_entry));
1613
1614
1615 if (loc_entry.cdte_track == CDROM_LEADOUT)
1616 {
1617 loc_entry.cdte_adr = sony_toc->address2;
1618 loc_entry.cdte_ctrl = sony_toc->control2;
1619 msf_val = sony_toc->lead_out_start_msf;
1620 }
1621 else
1622 {
1623 track_idx = find_track(int_to_bcd(loc_entry.cdte_track));
1624 if (track_idx < 0)
1625 {
1626 return -EINVAL;
1627 }
1628
1629 loc_entry.cdte_adr = sony_toc->tracks[track_idx].address;
1630 loc_entry.cdte_ctrl = sony_toc->tracks[track_idx].control;
1631 msf_val = sony_toc->tracks[track_idx].track_start_msf;
1632 }
1633
1634
1635 if (loc_entry.cdte_format == CDROM_LBA)
1636 {
1637 loc_entry.cdte_addr.lba = msf_to_log(msf_val);
1638 }
1639 else if (loc_entry.cdte_format == CDROM_MSF)
1640 {
1641 loc_entry.cdte_addr.msf.minute = bcd_to_int(*msf_val);
1642 loc_entry.cdte_addr.msf.second = bcd_to_int(*(msf_val+1));
1643 loc_entry.cdte_addr.msf.frame = bcd_to_int(*(msf_val+2));
1644 }
1645 memcpy_tofs(entry, &loc_entry, sizeof(*entry));
1646 }
1647 return 0;
1648 break;
1649
1650 case CDROMPLAYTRKIND:
1651 {
1652 struct cdrom_ti ti;
1653 int track_idx;
1654
1655 sony_get_toc();
1656 if (!sony_toc_read)
1657 {
1658 return -EIO;
1659 }
1660
1661 verify_area(VERIFY_READ, (char *) arg, sizeof(ti));
1662
1663 memcpy_fromfs(&ti, (char *) arg, sizeof(ti));
1664 if ( (ti.cdti_trk0 < sony_toc->first_track_num)
1665 || (ti.cdti_trk0 > sony_toc->last_track_num)
1666 || (ti.cdti_trk1 < ti.cdti_trk0))
1667 {
1668 return -EINVAL;
1669 }
1670
1671 track_idx = find_track(int_to_bcd(ti.cdti_trk0));
1672 if (track_idx < 0)
1673 {
1674 return -EINVAL;
1675 }
1676 params[1] = sony_toc->tracks[track_idx].track_start_msf[0];
1677 params[2] = sony_toc->tracks[track_idx].track_start_msf[1];
1678 params[3] = sony_toc->tracks[track_idx].track_start_msf[2];
1679
1680
1681
1682
1683
1684 if (ti.cdti_trk1 >= bcd_to_int(sony_toc->last_track_num))
1685 {
1686 log_to_msf(msf_to_log(sony_toc->lead_out_start_msf)-1,
1687 &(params[4]));
1688 }
1689 else
1690 {
1691 track_idx = find_track(int_to_bcd(ti.cdti_trk1+1));
1692 if (track_idx < 0)
1693 {
1694 return -EINVAL;
1695 }
1696 log_to_msf(msf_to_log(sony_toc->tracks[track_idx].track_start_msf)-1,
1697 &(params[4]));
1698 }
1699 params[0] = 0x03;
1700
1701 do_sony_cd_cmd(SONY_SPIN_UP_CMD, NULL, 0, res_reg, &res_size);
1702
1703 do_sony_cd_cmd(SONY_AUDIO_PLAYBACK_CMD, params, 7, res_reg, &res_size);
1704 if ((res_size < 2) || ((res_reg[0] & 0x20) == 0x20))
1705 {
1706 printk("Params: %x %x %x %x %x %x %x\n", params[0], params[1],
1707 params[2], params[3], params[4], params[5], params[6]);
1708 printk("Sony CDROM error 0x%2.2x (CDROMPLAYTRKIND\n", res_reg[1]);
1709 return -EIO;
1710 }
1711
1712
1713 final_pos_msf[0] = params[4];
1714 final_pos_msf[1] = params[5];
1715 final_pos_msf[2] = params[6];
1716 sony_audio_status = CDROM_AUDIO_PLAY;
1717 return 0;
1718 }
1719
1720 case CDROMSUBCHNL:
1721 return sony_get_subchnl_info(arg);
1722
1723 case CDROMVOLCTRL:
1724 {
1725 struct cdrom_volctrl volctrl;
1726
1727 verify_area(VERIFY_READ, (char *) arg, sizeof(volctrl));
1728
1729 memcpy_fromfs(&volctrl, (char *) arg, sizeof(volctrl));
1730 params[0] = SONY_SD_AUDIO_VOLUME;
1731 params[1] = volctrl.channel0;
1732 params[2] = volctrl.channel1;
1733 do_sony_cd_cmd(SONY_SET_DRIVE_PARAM_CMD, params, 3, res_reg, &res_size);
1734 if ((res_size < 2) || ((res_reg[0] & 0x20) == 0x20))
1735 {
1736 printk("Sony CDROM error 0x%2.2x (CDROMVOLCTRL)\n", res_reg[1]);
1737 return -EIO;
1738 }
1739 }
1740 return 0;
1741
1742 case CDROMEJECT:
1743 do_sony_cd_cmd(SONY_AUDIO_STOP_CMD, NULL, 0, res_reg, &res_size);
1744 do_sony_cd_cmd(SONY_SPIN_DOWN_CMD, NULL, 0, res_reg, &res_size);
1745
1746 sony_audio_status = CDROM_AUDIO_INVALID;
1747 do_sony_cd_cmd(SONY_EJECT_CMD, NULL, 0, res_reg, &res_size);
1748 if ((res_size < 2) || ((res_reg[0] & 0x20) == 0x20))
1749 {
1750 printk("Sony CDROM error 0x%2.2x (CDROMEJECT)\n", res_reg[1]);
1751 return -EIO;
1752 }
1753 return 0;
1754 break;
1755
1756 default:
1757 return -EINVAL;
1758 }
1759 }
1760
1761
1762
1763
1764
1765
1766 static int
1767 scd_open(struct inode *inode,
1768 struct file *filp)
1769 {
1770 unsigned char res_reg[2];
1771 unsigned int res_size;
1772 int num_spin_ups;
1773
1774
1775 if (filp->f_mode & 2)
1776 return -EROFS;
1777
1778 if (!sony_spun_up)
1779 {
1780 num_spin_ups = 0;
1781
1782 respinup_on_open:
1783 do_sony_cd_cmd(SONY_SPIN_UP_CMD, NULL, 0, res_reg, &res_size);
1784
1785
1786
1787 if ((res_size < 2) || ((res_reg[0] != 0) && (res_reg[1] != 0)))
1788 {
1789 printk("Sony CDROM error 0x%2.2x (scd_open, spin up)\n", res_reg[1]);
1790 return -EIO;
1791 }
1792
1793 do_sony_cd_cmd(SONY_READ_TOC_CMD, NULL, 0, res_reg, &res_size);
1794
1795
1796
1797 if ((res_size < 2) || ((res_reg[0] != 0) && (res_reg[1] != 0)))
1798 {
1799
1800 if ((res_reg[1] == SONY_AUDIO_PLAYING_ERR) || (res_reg[1] == 0))
1801 {
1802 goto drive_spinning;
1803 }
1804
1805
1806
1807 if ( (res_reg[1] == SONY_NOT_SPIN_ERR)
1808 && (num_spin_ups < MAX_CDU31A_RETRIES))
1809 {
1810 num_spin_ups++;
1811 goto respinup_on_open;
1812 }
1813
1814 printk("Sony CDROM error 0x%2.2x (scd_open, read toc)\n", res_reg[1]);
1815 do_sony_cd_cmd(SONY_SPIN_DOWN_CMD, NULL, 0, res_reg, &res_size);
1816
1817 return -EIO;
1818 }
1819
1820 sony_get_toc();
1821 if (!sony_toc_read)
1822 {
1823 do_sony_cd_cmd(SONY_SPIN_DOWN_CMD, NULL, 0, res_reg, &res_size);
1824 return -EIO;
1825 }
1826
1827 sony_spun_up = 1;
1828 }
1829
1830 drive_spinning:
1831
1832 if (inode)
1833 {
1834 check_disk_change(inode->i_rdev);
1835 }
1836
1837 sony_usage++;
1838
1839 return 0;
1840 }
1841
1842
1843
1844
1845
1846
1847 static void
1848 scd_release(struct inode *inode,
1849 struct file *filp)
1850 {
1851 unsigned char res_reg[2];
1852 unsigned int res_size;
1853
1854
1855 if (sony_usage > 0)
1856 {
1857 sony_usage--;
1858 }
1859 if (sony_usage == 0)
1860 {
1861 sync_dev(inode->i_rdev);
1862 do_sony_cd_cmd(SONY_SPIN_DOWN_CMD, NULL, 0, res_reg, &res_size);
1863
1864 sony_spun_up = 0;
1865 }
1866 }
1867
1868
1869 static struct file_operations scd_fops = {
1870 NULL,
1871 block_read,
1872 block_write,
1873 NULL,
1874 NULL,
1875 scd_ioctl,
1876 NULL,
1877 scd_open,
1878 scd_release,
1879 NULL,
1880 NULL,
1881 scd_disk_change,
1882 NULL
1883 };
1884
1885
1886
1887 static char *load_mech[] = { "caddy", "tray", "pop-up", "unknown" };
1888
1889
1890
1891 static unsigned int mem_size[] = { 16384, 16384, 16384, 2048 };
1892
1893 void
1894 get_drive_configuration(unsigned short base_io,
1895 unsigned char res_reg[],
1896 unsigned int *res_size)
1897 {
1898 int retry_count;
1899
1900
1901
1902 sony_cd_base_io = base_io;
1903
1904
1905 sony_cd_cmd_reg = sony_cd_base_io + SONY_CMD_REG_OFFSET;
1906 sony_cd_param_reg = sony_cd_base_io + SONY_PARAM_REG_OFFSET;
1907 sony_cd_write_reg = sony_cd_base_io + SONY_WRITE_REG_OFFSET;
1908 sony_cd_control_reg = sony_cd_base_io + SONY_CONTROL_REG_OFFSET;
1909 sony_cd_status_reg = sony_cd_base_io + SONY_STATUS_REG_OFFSET;
1910 sony_cd_result_reg = sony_cd_base_io + SONY_RESULT_REG_OFFSET;
1911 sony_cd_read_reg = sony_cd_base_io + SONY_READ_REG_OFFSET;
1912 sony_cd_fifost_reg = sony_cd_base_io + SONY_FIFOST_REG_OFFSET;
1913
1914
1915
1916
1917
1918
1919 if (read_status_register() != 0xff)
1920 {
1921
1922
1923
1924
1925 reset_drive();
1926 retry_count = jiffies + SONY_RESET_TIMEOUT;
1927 while ((retry_count > jiffies) && (!is_attention()))
1928 {
1929 sony_sleep();
1930 }
1931
1932
1933 if (!is_attention())
1934 {
1935 res_reg[0] = 0x20;
1936 return;
1937 }
1938
1939
1940
1941
1942 do_sony_cd_cmd(SONY_REQ_DRIVE_CONFIG_CMD,
1943 NULL,
1944 0,
1945 (unsigned char *) res_reg,
1946 res_size);
1947 return;
1948 }
1949
1950
1951 res_reg[0] = 0x20;
1952 }
1953
1954
1955 static int cdu31a_block_size;
1956
1957
1958
1959
1960 unsigned long
1961 cdu31a_init(unsigned long mem_start, unsigned long mem_end)
1962 {
1963 struct s_sony_drive_config drive_config;
1964 unsigned int res_size;
1965 int i;
1966 int drive_found;
1967 int tmp_irq;
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977 outb(0xbc, 0x9a01);
1978 outb(0xe2, 0x9a01);
1979
1980 i = 0;
1981 drive_found = 0;
1982 while ( (cdu31a_addresses[i].base != 0)
1983 && (!drive_found))
1984 {
1985 if (check_region(cdu31a_addresses[i].base, 4)) {
1986 i++;
1987 continue;
1988 }
1989 get_drive_configuration(cdu31a_addresses[i].base,
1990 drive_config.exec_status,
1991 &res_size);
1992 if ((res_size > 2) && ((drive_config.exec_status[0] & 0x20) == 0x00))
1993 {
1994 drive_found = 1;
1995 snarf_region(cdu31a_addresses[i].base, 4);
1996
1997 if (register_blkdev(MAJOR_NR,"cdu31a",&scd_fops))
1998 {
1999 printk("Unable to get major %d for CDU-31a\n", MAJOR_NR);
2000 return mem_start;
2001 }
2002
2003 if (SONY_HWC_DOUBLE_SPEED(drive_config))
2004 {
2005 is_double_speed = 1;
2006 }
2007
2008 tmp_irq = cdu31a_addresses[i].int_num;
2009 if (tmp_irq < 0)
2010 {
2011 autoirq_setup(0);
2012 enable_interrupts();
2013 reset_drive();
2014 tmp_irq = autoirq_report(10);
2015 disable_interrupts();
2016
2017 set_drive_params();
2018 irq_used = tmp_irq;
2019 }
2020 else
2021 {
2022 set_drive_params();
2023 irq_used = tmp_irq;
2024 }
2025
2026 if (irq_used > 0)
2027 {
2028 if (request_irq(irq_used, cdu31a_interrupt, SA_INTERRUPT, "cdu31a"))
2029 {
2030 irq_used = 0;
2031 printk("Unable to grab IRQ%d for the CDU31A driver\n", irq_used);
2032 }
2033 }
2034
2035 dma_channel = cdu31a_addresses[i].dma_num;
2036 if (dma_channel > 0)
2037 {
2038 if (request_dma(dma_channel,"cdu31a"))
2039 {
2040 dma_channel = -1;
2041 printk("Unable to grab DMA%d for the CDU31A driver\n",
2042 dma_channel);
2043 }
2044 }
2045
2046 sony_buffer_size = mem_size[SONY_HWC_GET_BUF_MEM_SIZE(drive_config)];
2047 sony_buffer_sectors = sony_buffer_size / 2048;
2048
2049 printk("Sony I/F CDROM : %8.8s %16.16s %8.8s with %s load mechanism\n",
2050 drive_config.vendor_id,
2051 drive_config.product_id,
2052 drive_config.product_rev_level,
2053 load_mech[SONY_HWC_GET_LOAD_MECH(drive_config)]);
2054 printk(" using %d byte buffer", sony_buffer_size);
2055 if (SONY_HWC_AUDIO_PLAYBACK(drive_config))
2056 {
2057 printk(", audio");
2058 }
2059 if (SONY_HWC_EJECT(drive_config))
2060 {
2061 printk(", eject");
2062 }
2063 if (SONY_HWC_LED_SUPPORT(drive_config))
2064 {
2065 printk(", LED");
2066 }
2067 if (SONY_HWC_ELECTRIC_VOLUME(drive_config))
2068 {
2069 printk(", elec. Vol");
2070 }
2071 if (SONY_HWC_ELECTRIC_VOLUME_CTL(drive_config))
2072 {
2073 printk(", sep. Vol");
2074 }
2075 if (is_double_speed)
2076 {
2077 printk(", double speed");
2078 }
2079 if (irq_used > 0)
2080 {
2081 printk(", irq %d", irq_used);
2082 }
2083 if (dma_channel > 0)
2084 {
2085 printk(", drq %d", dma_channel);
2086 }
2087 printk("\n");
2088
2089 blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST;
2090 read_ahead[MAJOR_NR] = 32;
2091 cdu31a_block_size = 2048;
2092
2093 blksize_size[MAJOR_NR] = &cdu31a_block_size;
2094
2095 sony_toc = (struct s_sony_toc *) mem_start;
2096 mem_start += sizeof(*sony_toc);
2097 last_sony_subcode = (struct s_sony_subcode *) mem_start;
2098 mem_start += sizeof(*last_sony_subcode);
2099
2100
2101
2102
2103 if ( (dma_channel > 0)
2104 && ( ((mem_start) & (~0xffff))
2105 != (((mem_start) + sony_buffer_size) & (~0xffff))))
2106 {
2107 mem_start = (((int)mem_start) + 0x10000) & (~0xffff);
2108 }
2109
2110 sony_buffer = (unsigned char *) mem_start;
2111 mem_start += sony_buffer_size;
2112 }
2113
2114 i++;
2115 }
2116
2117 return mem_start;
2118 }
2119