1 /* GD ROM driver for the SEGA Dreamcast
2 * copyright Adrian McMenamin, 2007
3 * With thanks to Marcus Comstedt and Nathan Keynes
4 * for work in reversing PIO and DMA
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <linux/init.h>
23 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/list.h>
27 #include <linux/slab.h>
28 #include <linux/dma-mapping.h>
29 #include <linux/cdrom.h>
30 #include <linux/genhd.h>
31 #include <linux/bio.h>
32 #include <linux/blkdev.h>
33 #include <linux/interrupt.h>
34 #include <linux/device.h>
35 #include <linux/wait.h>
36 #include <linux/workqueue.h>
37 #include <linux/platform_device.h>
38 #include <scsi/scsi.h>
41 #include <asm/delay.h>
43 #include <mach/sysasic.h>
45 #define GDROM_DEV_NAME "gdrom"
46 #define GD_SESSION_OFFSET 150
49 #define GDROM_COM_SOFTRESET 0x08
50 #define GDROM_COM_EXECDIAG 0x90
51 #define GDROM_COM_PACKET 0xA0
52 #define GDROM_COM_IDDEV 0xA1
54 /* GD Rom registers */
55 #define GDROM_BASE_REG 0xA05F7000
56 #define GDROM_ALTSTATUS_REG (GDROM_BASE_REG + 0x18)
57 #define GDROM_DATA_REG (GDROM_BASE_REG + 0x80)
58 #define GDROM_ERROR_REG (GDROM_BASE_REG + 0x84)
59 #define GDROM_INTSEC_REG (GDROM_BASE_REG + 0x88)
60 #define GDROM_SECNUM_REG (GDROM_BASE_REG + 0x8C)
61 #define GDROM_BCL_REG (GDROM_BASE_REG + 0x90)
62 #define GDROM_BCH_REG (GDROM_BASE_REG + 0x94)
63 #define GDROM_DSEL_REG (GDROM_BASE_REG + 0x98)
64 #define GDROM_STATUSCOMMAND_REG (GDROM_BASE_REG + 0x9C)
65 #define GDROM_RESET_REG (GDROM_BASE_REG + 0x4E4)
67 #define GDROM_DMA_STARTADDR_REG (GDROM_BASE_REG + 0x404)
68 #define GDROM_DMA_LENGTH_REG (GDROM_BASE_REG + 0x408)
69 #define GDROM_DMA_DIRECTION_REG (GDROM_BASE_REG + 0x40C)
70 #define GDROM_DMA_ENABLE_REG (GDROM_BASE_REG + 0x414)
71 #define GDROM_DMA_STATUS_REG (GDROM_BASE_REG + 0x418)
72 #define GDROM_DMA_WAIT_REG (GDROM_BASE_REG + 0x4A0)
73 #define GDROM_DMA_ACCESS_CTRL_REG (GDROM_BASE_REG + 0x4B8)
75 #define GDROM_HARD_SECTOR 2048
76 #define BLOCK_LAYER_SECTOR 512
79 #define GDROM_DEFAULT_TIMEOUT (HZ * 7)
83 const char * const text
;
86 {RECOVERED_ERROR
, "Recovered from error"},
87 {NOT_READY
, "Device not ready"},
88 {MEDIUM_ERROR
, "Disk not ready"},
89 {HARDWARE_ERROR
, "Hardware error"},
90 {ILLEGAL_REQUEST
, "Command has failed"},
91 {UNIT_ATTENTION
, "Device needs attention - disk may have been changed"},
92 {DATA_PROTECT
, "Data protection error"},
93 {ABORTED_COMMAND
, "Command aborted"},
96 static struct platform_device
*pd
;
97 static int gdrom_major
;
98 static DECLARE_WAIT_QUEUE_HEAD(command_queue
);
99 static DECLARE_WAIT_QUEUE_HEAD(request_queue
);
101 static DEFINE_SPINLOCK(gdrom_lock
);
102 static void gdrom_readdisk_dma(struct work_struct
*work
);
103 static DECLARE_WORK(work
, gdrom_readdisk_dma
);
104 static LIST_HEAD(gdrom_deferred
);
107 unsigned int entry
[99];
108 unsigned int first
, last
;
109 unsigned int leadout
;
112 static struct gdrom_unit
{
113 struct gendisk
*disk
;
114 struct cdrom_device_info
*cd_info
;
119 struct gdromtoc
*toc
;
120 struct request_queue
*gdrom_rq
;
134 static int gdrom_getsense(short *bufstring
);
135 static int gdrom_packetcommand(struct cdrom_device_info
*cd_info
,
136 struct packet_command
*command
);
137 static int gdrom_hardreset(struct cdrom_device_info
*cd_info
);
139 static bool gdrom_is_busy(void)
141 return (ctrl_inb(GDROM_ALTSTATUS_REG
) & 0x80) != 0;
144 static bool gdrom_data_request(void)
146 return (ctrl_inb(GDROM_ALTSTATUS_REG
) & 0x88) == 8;
149 static bool gdrom_wait_clrbusy(void)
151 unsigned long timeout
= jiffies
+ GDROM_DEFAULT_TIMEOUT
;
152 while ((ctrl_inb(GDROM_ALTSTATUS_REG
) & 0x80) &&
153 (time_before(jiffies
, timeout
)))
155 return time_before(jiffies
, timeout
+ 1);
158 static bool gdrom_wait_busy_sleeps(void)
160 unsigned long timeout
;
161 /* Wait to get busy first */
162 timeout
= jiffies
+ GDROM_DEFAULT_TIMEOUT
;
163 while (!gdrom_is_busy() && time_before(jiffies
, timeout
))
165 /* Now wait for busy to clear */
166 return gdrom_wait_clrbusy();
169 static void gdrom_identifydevice(void *buf
)
173 /* If the device won't clear it has probably
174 * been hit by a serious failure - but we'll
175 * try to return a sense key even so */
176 if (!gdrom_wait_clrbusy()) {
177 gdrom_getsense(NULL
);
180 ctrl_outb(GDROM_COM_IDDEV
, GDROM_STATUSCOMMAND_REG
);
181 if (!gdrom_wait_busy_sleeps()) {
182 gdrom_getsense(NULL
);
185 /* now read in the data */
186 for (c
= 0; c
< 40; c
++)
187 data
[c
] = ctrl_inw(GDROM_DATA_REG
);
190 static void gdrom_spicommand(void *spi_string
, int buflen
)
192 short *cmd
= spi_string
;
193 unsigned long timeout
;
195 /* ensure IRQ_WAIT is set */
196 ctrl_outb(0x08, GDROM_ALTSTATUS_REG
);
197 /* specify how many bytes we expect back */
198 ctrl_outb(buflen
& 0xFF, GDROM_BCL_REG
);
199 ctrl_outb((buflen
>> 8) & 0xFF, GDROM_BCH_REG
);
200 /* other parameters */
201 ctrl_outb(0, GDROM_INTSEC_REG
);
202 ctrl_outb(0, GDROM_SECNUM_REG
);
203 ctrl_outb(0, GDROM_ERROR_REG
);
204 /* Wait until we can go */
205 if (!gdrom_wait_clrbusy()) {
206 gdrom_getsense(NULL
);
209 timeout
= jiffies
+ GDROM_DEFAULT_TIMEOUT
;
210 ctrl_outb(GDROM_COM_PACKET
, GDROM_STATUSCOMMAND_REG
);
211 while (!gdrom_data_request() && time_before(jiffies
, timeout
))
213 if (!time_before(jiffies
, timeout
+ 1)) {
214 gdrom_getsense(NULL
);
217 outsw(PHYSADDR(GDROM_DATA_REG
), cmd
, 6);
221 /* gdrom_command_executediagnostic:
222 * Used to probe for presence of working GDROM
223 * Restarts GDROM device and then applies standard ATA 3
224 * Execute Diagnostic Command: a return of '1' indicates device 0
225 * present and device 1 absent
227 static char gdrom_execute_diagnostic(void)
229 gdrom_hardreset(gd
.cd_info
);
230 if (!gdrom_wait_clrbusy())
232 ctrl_outb(GDROM_COM_EXECDIAG
, GDROM_STATUSCOMMAND_REG
);
233 if (!gdrom_wait_busy_sleeps())
235 return ctrl_inb(GDROM_ERROR_REG
);
239 * Prepare disk command
243 static int gdrom_preparedisk_cmd(void)
245 struct packet_command
*spin_command
;
246 spin_command
= kzalloc(sizeof(struct packet_command
), GFP_KERNEL
);
249 spin_command
->cmd
[0] = 0x70;
250 spin_command
->cmd
[2] = 0x1f;
251 spin_command
->buflen
= 0;
253 gdrom_packetcommand(gd
.cd_info
, spin_command
);
254 /* 60 second timeout */
255 wait_event_interruptible_timeout(command_queue
, gd
.pending
== 0,
256 GDROM_DEFAULT_TIMEOUT
);
259 if (gd
.status
& 0x01) {
261 gdrom_getsense(NULL
);
271 * byte 3 = sizeof TOC >> 8 ie upper byte
272 * byte 4 = sizeof TOC & 0xff ie lower byte
274 static int gdrom_readtoc_cmd(struct gdromtoc
*toc
, int session
)
277 struct packet_command
*toc_command
;
280 toc_command
= kzalloc(sizeof(struct packet_command
), GFP_KERNEL
);
283 tocsize
= sizeof(struct gdromtoc
);
284 toc_command
->cmd
[0] = 0x14;
285 toc_command
->cmd
[1] = session
;
286 toc_command
->cmd
[3] = tocsize
>> 8;
287 toc_command
->cmd
[4] = tocsize
& 0xff;
288 toc_command
->buflen
= tocsize
;
291 goto cleanup_readtoc_final
;
294 gdrom_packetcommand(gd
.cd_info
, toc_command
);
295 wait_event_interruptible_timeout(command_queue
, gd
.pending
== 0,
296 GDROM_DEFAULT_TIMEOUT
);
299 goto cleanup_readtoc
;
301 insw(PHYSADDR(GDROM_DATA_REG
), toc
, tocsize
/2);
302 if (gd
.status
& 0x01)
307 cleanup_readtoc_final
:
313 static int get_entry_lba(int track
)
315 return (cpu_to_be32(track
& 0xffffff00) - GD_SESSION_OFFSET
);
318 static int get_entry_q_ctrl(int track
)
320 return (track
& 0x000000f0) >> 4;
323 static int get_entry_track(int track
)
325 return (track
& 0x0000ff00) >> 8;
328 static int gdrom_get_last_session(struct cdrom_device_info
*cd_info
,
329 struct cdrom_multisession
*ms_info
)
331 int fentry
, lentry
, track
, data
, tocuse
, err
;
335 /* Check if GD-ROM */
336 err
= gdrom_readtoc_cmd(gd
.toc
, 1);
337 /* Not a GD-ROM so check if standard CD-ROM */
340 err
= gdrom_readtoc_cmd(gd
.toc
, 0);
342 printk(KERN_INFO
"GDROM: Could not get CD "
343 "table of contents\n");
348 fentry
= get_entry_track(gd
.toc
->first
);
349 lentry
= get_entry_track(gd
.toc
->last
);
350 /* Find the first data track */
351 track
= get_entry_track(gd
.toc
->last
);
353 data
= gd
.toc
->entry
[track
- 1];
354 if (get_entry_q_ctrl(data
))
355 break; /* ie a real data track */
357 } while (track
>= fentry
);
359 if ((track
> 100) || (track
< get_entry_track(gd
.toc
->first
))) {
360 printk(KERN_INFO
"GDROM: No data on the last "
361 "session of the CD\n");
362 gdrom_getsense(NULL
);
366 ms_info
->addr_format
= CDROM_LBA
;
367 ms_info
->addr
.lba
= get_entry_lba(data
);
368 ms_info
->xa_flag
= 1;
372 static int gdrom_open(struct cdrom_device_info
*cd_info
, int purpose
)
374 /* spin up the disk */
375 return gdrom_preparedisk_cmd();
378 /* this function is required even if empty */
379 static void gdrom_release(struct cdrom_device_info
*cd_info
)
383 static int gdrom_drivestatus(struct cdrom_device_info
*cd_info
, int ignore
)
385 /* read the sense key */
386 char sense
= ctrl_inb(GDROM_ERROR_REG
);
391 return CDS_DRIVE_NOT_READY
;
396 static int gdrom_mediachanged(struct cdrom_device_info
*cd_info
, int ignore
)
398 /* check the sense key */
399 return (ctrl_inb(GDROM_ERROR_REG
) & 0xF0) == 0x60;
402 /* reset the G1 bus */
403 static int gdrom_hardreset(struct cdrom_device_info
*cd_info
)
406 ctrl_outl(0x1fffff, GDROM_RESET_REG
);
407 for (count
= 0xa0000000; count
< 0xa0200000; count
+= 4)
412 /* keep the function looking like the universal
413 * CD Rom specification - returning int */
414 static int gdrom_packetcommand(struct cdrom_device_info
*cd_info
,
415 struct packet_command
*command
)
417 gdrom_spicommand(&command
->cmd
, command
->buflen
);
421 /* Get Sense SPI command
422 * From Marcus Comstedt
424 * cmd + 4 = length of returned buffer
425 * Returns 5 16 bit words
427 static int gdrom_getsense(short *bufstring
)
429 struct packet_command
*sense_command
;
434 sense_command
= kzalloc(sizeof(struct packet_command
), GFP_KERNEL
);
437 sense_command
->cmd
[0] = 0x13;
438 sense_command
->cmd
[4] = 10;
439 sense_command
->buflen
= 10;
440 /* even if something is pending try to get
441 * the sense key if possible */
442 if (gd
.pending
&& !gdrom_wait_clrbusy()) {
444 goto cleanup_sense_final
;
447 gdrom_packetcommand(gd
.cd_info
, sense_command
);
448 wait_event_interruptible_timeout(command_queue
, gd
.pending
== 0,
449 GDROM_DEFAULT_TIMEOUT
);
452 insw(PHYSADDR(GDROM_DATA_REG
), &sense
, sense_command
->buflen
/2);
454 printk(KERN_INFO
"GDROM: Drive not ready - command aborted\n");
457 sense_key
= sense
[1] & 0x0F;
458 if (sense_key
< ARRAY_SIZE(sense_texts
))
459 printk(KERN_INFO
"GDROM: %s\n", sense_texts
[sense_key
].text
);
461 printk(KERN_ERR
"GDROM: Unknown sense key: %d\n", sense_key
);
462 if (bufstring
) /* return addional sense data */
463 memcpy(bufstring
, &sense
[4], 2);
470 kfree(sense_command
);
474 static int gdrom_audio_ioctl(struct cdrom_device_info
*cdi
, unsigned int cmd
,
480 static struct cdrom_device_ops gdrom_ops
= {
482 .release
= gdrom_release
,
483 .drive_status
= gdrom_drivestatus
,
484 .media_changed
= gdrom_mediachanged
,
485 .get_last_session
= gdrom_get_last_session
,
486 .reset
= gdrom_hardreset
,
487 .audio_ioctl
= gdrom_audio_ioctl
,
488 .capability
= CDC_MULTI_SESSION
| CDC_MEDIA_CHANGED
|
489 CDC_RESET
| CDC_DRIVE_STATUS
| CDC_CD_R
,
493 static int gdrom_bdops_open(struct block_device
*bdev
, fmode_t mode
)
495 return cdrom_open(gd
.cd_info
, bdev
, mode
);
498 static int gdrom_bdops_release(struct gendisk
*disk
, fmode_t mode
)
500 cdrom_release(gd
.cd_info
, mode
);
504 static int gdrom_bdops_mediachanged(struct gendisk
*disk
)
506 return cdrom_media_changed(gd
.cd_info
);
509 static int gdrom_bdops_ioctl(struct block_device
*bdev
, fmode_t mode
,
510 unsigned cmd
, unsigned long arg
)
512 return cdrom_ioctl(gd
.cd_info
, bdev
, mode
, cmd
, arg
);
515 static const struct block_device_operations gdrom_bdops
= {
516 .owner
= THIS_MODULE
,
517 .open
= gdrom_bdops_open
,
518 .release
= gdrom_bdops_release
,
519 .media_changed
= gdrom_bdops_mediachanged
,
520 .locked_ioctl
= gdrom_bdops_ioctl
,
523 static irqreturn_t
gdrom_command_interrupt(int irq
, void *dev_id
)
525 gd
.status
= ctrl_inb(GDROM_STATUSCOMMAND_REG
);
529 wake_up_interruptible(&command_queue
);
533 static irqreturn_t
gdrom_dma_interrupt(int irq
, void *dev_id
)
535 gd
.status
= ctrl_inb(GDROM_STATUSCOMMAND_REG
);
536 if (gd
.transfer
!= 1)
539 wake_up_interruptible(&request_queue
);
543 static int __devinit
gdrom_set_interrupt_handlers(void)
547 err
= request_irq(HW_EVENT_GDROM_CMD
, gdrom_command_interrupt
,
548 IRQF_DISABLED
, "gdrom_command", &gd
);
551 err
= request_irq(HW_EVENT_GDROM_DMA
, gdrom_dma_interrupt
,
552 IRQF_DISABLED
, "gdrom_dma", &gd
);
554 free_irq(HW_EVENT_GDROM_CMD
, &gd
);
558 /* Implement DMA read using SPI command
568 static void gdrom_readdisk_dma(struct work_struct
*work
)
570 int err
, block
, block_cnt
;
571 struct packet_command
*read_command
;
572 struct list_head
*elem
, *next
;
574 unsigned long timeout
;
576 if (list_empty(&gdrom_deferred
))
578 read_command
= kzalloc(sizeof(struct packet_command
), GFP_KERNEL
);
580 return; /* get more memory later? */
581 read_command
->cmd
[0] = 0x30;
582 read_command
->cmd
[1] = 0x20;
583 spin_lock(&gdrom_lock
);
584 list_for_each_safe(elem
, next
, &gdrom_deferred
) {
585 req
= list_entry(elem
, struct request
, queuelist
);
586 spin_unlock(&gdrom_lock
);
587 block
= blk_rq_pos(req
)/GD_TO_BLK
+ GD_SESSION_OFFSET
;
588 block_cnt
= blk_rq_sectors(req
)/GD_TO_BLK
;
589 ctrl_outl(PHYSADDR(req
->buffer
), GDROM_DMA_STARTADDR_REG
);
590 ctrl_outl(block_cnt
* GDROM_HARD_SECTOR
, GDROM_DMA_LENGTH_REG
);
591 ctrl_outl(1, GDROM_DMA_DIRECTION_REG
);
592 ctrl_outl(1, GDROM_DMA_ENABLE_REG
);
593 read_command
->cmd
[2] = (block
>> 16) & 0xFF;
594 read_command
->cmd
[3] = (block
>> 8) & 0xFF;
595 read_command
->cmd
[4] = block
& 0xFF;
596 read_command
->cmd
[8] = (block_cnt
>> 16) & 0xFF;
597 read_command
->cmd
[9] = (block_cnt
>> 8) & 0xFF;
598 read_command
->cmd
[10] = block_cnt
& 0xFF;
600 ctrl_outb(1, GDROM_ERROR_REG
);
601 /* other registers */
602 ctrl_outb(0, GDROM_SECNUM_REG
);
603 ctrl_outb(0, GDROM_BCL_REG
);
604 ctrl_outb(0, GDROM_BCH_REG
);
605 ctrl_outb(0, GDROM_DSEL_REG
);
606 ctrl_outb(0, GDROM_INTSEC_REG
);
607 /* Wait for registers to reset after any previous activity */
608 timeout
= jiffies
+ HZ
/ 2;
609 while (gdrom_is_busy() && time_before(jiffies
, timeout
))
611 ctrl_outb(GDROM_COM_PACKET
, GDROM_STATUSCOMMAND_REG
);
612 timeout
= jiffies
+ HZ
/ 2;
613 /* Wait for packet command to finish */
614 while (gdrom_is_busy() && time_before(jiffies
, timeout
))
618 outsw(PHYSADDR(GDROM_DATA_REG
), &read_command
->cmd
, 6);
619 timeout
= jiffies
+ HZ
/ 2;
620 /* Wait for any pending DMA to finish */
621 while (ctrl_inb(GDROM_DMA_STATUS_REG
) &&
622 time_before(jiffies
, timeout
))
625 ctrl_outb(1, GDROM_DMA_STATUS_REG
);
626 wait_event_interruptible_timeout(request_queue
,
627 gd
.transfer
== 0, GDROM_DEFAULT_TIMEOUT
);
628 err
= gd
.transfer
? -EIO
: 0;
631 /* now seek to take the request spinlock
632 * before handling ending the request */
633 spin_lock(&gdrom_lock
);
634 list_del_init(&req
->queuelist
);
635 __blk_end_request_all(req
, err
);
637 spin_unlock(&gdrom_lock
);
641 static void gdrom_request(struct request_queue
*rq
)
645 while ((req
= blk_fetch_request(rq
)) != NULL
) {
646 if (!blk_fs_request(req
)) {
647 printk(KERN_DEBUG
"GDROM: Non-fs request ignored\n");
648 __blk_end_request_all(req
, -EIO
);
651 if (rq_data_dir(req
) != READ
) {
652 printk(KERN_NOTICE
"GDROM: Read only device -");
653 printk(" write request ignored\n");
654 __blk_end_request_all(req
, -EIO
);
659 * Add to list of deferred work and then schedule
662 list_add_tail(&req
->queuelist
, &gdrom_deferred
);
663 schedule_work(&work
);
667 /* Print string identifying GD ROM device */
668 static int __devinit
gdrom_outputversion(void)
671 char *model_name
, *manuf_name
, *firmw_ver
;
674 /* query device ID */
675 id
= kzalloc(sizeof(struct gdrom_id
), GFP_KERNEL
);
678 gdrom_identifydevice(id
);
679 model_name
= kstrndup(id
->modname
, 16, GFP_KERNEL
);
682 manuf_name
= kstrndup(id
->mname
, 16, GFP_KERNEL
);
684 goto free_model_name
;
685 firmw_ver
= kstrndup(id
->firmver
, 16, GFP_KERNEL
);
687 goto free_manuf_name
;
688 printk(KERN_INFO
"GDROM: %s from %s with firmware %s\n",
689 model_name
, manuf_name
, firmw_ver
);
701 /* set the default mode for DMA transfer */
702 static int __devinit
gdrom_init_dma_mode(void)
704 ctrl_outb(0x13, GDROM_ERROR_REG
);
705 ctrl_outb(0x22, GDROM_INTSEC_REG
);
706 if (!gdrom_wait_clrbusy())
708 ctrl_outb(0xEF, GDROM_STATUSCOMMAND_REG
);
709 if (!gdrom_wait_busy_sleeps())
711 /* Memory protection setting for GDROM DMA
712 * Bits 31 - 16 security: 0x8843
713 * Bits 15 and 7 reserved (0)
714 * Bits 14 - 8 start of transfer range in 1 MB blocks OR'ed with 0x80
715 * Bits 6 - 0 end of transfer range in 1 MB blocks OR'ed with 0x80
716 * (0x40 | 0x80) = start range at 0x0C000000
717 * (0x7F | 0x80) = end range at 0x0FFFFFFF */
718 ctrl_outl(0x8843407F, GDROM_DMA_ACCESS_CTRL_REG
);
719 ctrl_outl(9, GDROM_DMA_WAIT_REG
); /* DMA word setting */
723 static void __devinit
probe_gdrom_setupcd(void)
725 gd
.cd_info
->ops
= &gdrom_ops
;
726 gd
.cd_info
->capacity
= 1;
727 strcpy(gd
.cd_info
->name
, GDROM_DEV_NAME
);
728 gd
.cd_info
->mask
= CDC_CLOSE_TRAY
|CDC_OPEN_TRAY
|CDC_LOCK
|
732 static void __devinit
probe_gdrom_setupdisk(void)
734 gd
.disk
->major
= gdrom_major
;
735 gd
.disk
->first_minor
= 1;
737 strcpy(gd
.disk
->disk_name
, GDROM_DEV_NAME
);
740 static int __devinit
probe_gdrom_setupqueue(void)
742 blk_queue_logical_block_size(gd
.gdrom_rq
, GDROM_HARD_SECTOR
);
743 /* using DMA so memory will need to be contiguous */
744 blk_queue_max_hw_segments(gd
.gdrom_rq
, 1);
745 /* set a large max size to get most from DMA */
746 blk_queue_max_segment_size(gd
.gdrom_rq
, 0x40000);
747 gd
.disk
->queue
= gd
.gdrom_rq
;
748 return gdrom_init_dma_mode();
752 * register this as a block device and as compliant with the
753 * universal CD Rom driver interface
755 static int __devinit
probe_gdrom(struct platform_device
*devptr
)
758 /* Start the device */
759 if (gdrom_execute_diagnostic() != 1) {
760 printk(KERN_WARNING
"GDROM: ATA Probe for GDROM failed.\n");
763 /* Print out firmware ID */
764 if (gdrom_outputversion())
767 gdrom_major
= register_blkdev(0, GDROM_DEV_NAME
);
768 if (gdrom_major
<= 0)
770 printk(KERN_INFO
"GDROM: Registered with major number %d\n",
772 /* Specify basic properties of drive */
773 gd
.cd_info
= kzalloc(sizeof(struct cdrom_device_info
), GFP_KERNEL
);
776 goto probe_fail_no_mem
;
778 probe_gdrom_setupcd();
779 gd
.disk
= alloc_disk(1);
782 goto probe_fail_no_disk
;
784 probe_gdrom_setupdisk();
785 if (register_cdrom(gd
.cd_info
)) {
787 goto probe_fail_cdrom_register
;
789 gd
.disk
->fops
= &gdrom_bdops
;
790 /* latch on to the interrupt */
791 err
= gdrom_set_interrupt_handlers();
793 goto probe_fail_cmdirq_register
;
794 gd
.gdrom_rq
= blk_init_queue(gdrom_request
, &gdrom_lock
);
796 goto probe_fail_requestq
;
798 err
= probe_gdrom_setupqueue();
802 gd
.toc
= kzalloc(sizeof(struct gdromtoc
), GFP_KERNEL
);
809 blk_cleanup_queue(gd
.gdrom_rq
);
811 free_irq(HW_EVENT_GDROM_DMA
, &gd
);
812 free_irq(HW_EVENT_GDROM_CMD
, &gd
);
813 probe_fail_cmdirq_register
:
814 probe_fail_cdrom_register
:
815 del_gendisk(gd
.disk
);
818 unregister_blkdev(gdrom_major
, GDROM_DEV_NAME
);
821 printk(KERN_WARNING
"GDROM: Probe failed - error is 0x%X\n", err
);
825 static int __devexit
remove_gdrom(struct platform_device
*devptr
)
827 flush_scheduled_work();
828 blk_cleanup_queue(gd
.gdrom_rq
);
829 free_irq(HW_EVENT_GDROM_CMD
, &gd
);
830 free_irq(HW_EVENT_GDROM_DMA
, &gd
);
831 del_gendisk(gd
.disk
);
833 unregister_blkdev(gdrom_major
, GDROM_DEV_NAME
);
834 unregister_cdrom(gd
.cd_info
);
839 static struct platform_driver gdrom_driver
= {
840 .probe
= probe_gdrom
,
841 .remove
= __devexit_p(remove_gdrom
),
843 .name
= GDROM_DEV_NAME
,
847 static int __init
init_gdrom(void)
851 rc
= platform_driver_register(&gdrom_driver
);
854 pd
= platform_device_register_simple(GDROM_DEV_NAME
, -1, NULL
, 0);
856 platform_driver_unregister(&gdrom_driver
);
862 static void __exit
exit_gdrom(void)
864 platform_device_unregister(pd
);
865 platform_driver_unregister(&gdrom_driver
);
869 module_init(init_gdrom
);
870 module_exit(exit_gdrom
);
871 MODULE_AUTHOR("Adrian McMenamin <adrian@mcmen.demon.co.uk>");
872 MODULE_DESCRIPTION("SEGA Dreamcast GD-ROM Driver");
873 MODULE_LICENSE("GPL");