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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24 #include <linux/init.h>
25 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/list.h>
29 #include <linux/slab.h>
30 #include <linux/dma-mapping.h>
31 #include <linux/cdrom.h>
32 #include <linux/genhd.h>
33 #include <linux/bio.h>
34 #include <linux/blkdev.h>
35 #include <linux/interrupt.h>
36 #include <linux/device.h>
37 #include <linux/mutex.h>
38 #include <linux/wait.h>
39 #include <linux/workqueue.h>
40 #include <linux/platform_device.h>
41 #include <scsi/scsi.h>
44 #include <asm/delay.h>
46 #include <mach/sysasic.h>
48 #define GDROM_DEV_NAME "gdrom"
49 #define GD_SESSION_OFFSET 150
52 #define GDROM_COM_SOFTRESET 0x08
53 #define GDROM_COM_EXECDIAG 0x90
54 #define GDROM_COM_PACKET 0xA0
55 #define GDROM_COM_IDDEV 0xA1
57 /* GD Rom registers */
58 #define GDROM_BASE_REG 0xA05F7000
59 #define GDROM_ALTSTATUS_REG (GDROM_BASE_REG + 0x18)
60 #define GDROM_DATA_REG (GDROM_BASE_REG + 0x80)
61 #define GDROM_ERROR_REG (GDROM_BASE_REG + 0x84)
62 #define GDROM_INTSEC_REG (GDROM_BASE_REG + 0x88)
63 #define GDROM_SECNUM_REG (GDROM_BASE_REG + 0x8C)
64 #define GDROM_BCL_REG (GDROM_BASE_REG + 0x90)
65 #define GDROM_BCH_REG (GDROM_BASE_REG + 0x94)
66 #define GDROM_DSEL_REG (GDROM_BASE_REG + 0x98)
67 #define GDROM_STATUSCOMMAND_REG (GDROM_BASE_REG + 0x9C)
68 #define GDROM_RESET_REG (GDROM_BASE_REG + 0x4E4)
70 #define GDROM_DMA_STARTADDR_REG (GDROM_BASE_REG + 0x404)
71 #define GDROM_DMA_LENGTH_REG (GDROM_BASE_REG + 0x408)
72 #define GDROM_DMA_DIRECTION_REG (GDROM_BASE_REG + 0x40C)
73 #define GDROM_DMA_ENABLE_REG (GDROM_BASE_REG + 0x414)
74 #define GDROM_DMA_STATUS_REG (GDROM_BASE_REG + 0x418)
75 #define GDROM_DMA_WAIT_REG (GDROM_BASE_REG + 0x4A0)
76 #define GDROM_DMA_ACCESS_CTRL_REG (GDROM_BASE_REG + 0x4B8)
78 #define GDROM_HARD_SECTOR 2048
79 #define BLOCK_LAYER_SECTOR 512
82 #define GDROM_DEFAULT_TIMEOUT (HZ * 7)
84 static DEFINE_MUTEX(gdrom_mutex
);
87 const char * const text
;
90 {RECOVERED_ERROR
, "Recovered from error"},
91 {NOT_READY
, "Device not ready"},
92 {MEDIUM_ERROR
, "Disk not ready"},
93 {HARDWARE_ERROR
, "Hardware error"},
94 {ILLEGAL_REQUEST
, "Command has failed"},
95 {UNIT_ATTENTION
, "Device needs attention - disk may have been changed"},
96 {DATA_PROTECT
, "Data protection error"},
97 {ABORTED_COMMAND
, "Command aborted"},
100 static struct platform_device
*pd
;
101 static int gdrom_major
;
102 static DECLARE_WAIT_QUEUE_HEAD(command_queue
);
103 static DECLARE_WAIT_QUEUE_HEAD(request_queue
);
105 static DEFINE_SPINLOCK(gdrom_lock
);
106 static void gdrom_readdisk_dma(struct work_struct
*work
);
107 static DECLARE_WORK(work
, gdrom_readdisk_dma
);
108 static LIST_HEAD(gdrom_deferred
);
111 unsigned int entry
[99];
112 unsigned int first
, last
;
113 unsigned int leadout
;
116 static struct gdrom_unit
{
117 struct gendisk
*disk
;
118 struct cdrom_device_info
*cd_info
;
123 struct gdromtoc
*toc
;
124 struct request_queue
*gdrom_rq
;
138 static int gdrom_getsense(short *bufstring
);
139 static int gdrom_packetcommand(struct cdrom_device_info
*cd_info
,
140 struct packet_command
*command
);
141 static int gdrom_hardreset(struct cdrom_device_info
*cd_info
);
143 static bool gdrom_is_busy(void)
145 return (__raw_readb(GDROM_ALTSTATUS_REG
) & 0x80) != 0;
148 static bool gdrom_data_request(void)
150 return (__raw_readb(GDROM_ALTSTATUS_REG
) & 0x88) == 8;
153 static bool gdrom_wait_clrbusy(void)
155 unsigned long timeout
= jiffies
+ GDROM_DEFAULT_TIMEOUT
;
156 while ((__raw_readb(GDROM_ALTSTATUS_REG
) & 0x80) &&
157 (time_before(jiffies
, timeout
)))
159 return time_before(jiffies
, timeout
+ 1);
162 static bool gdrom_wait_busy_sleeps(void)
164 unsigned long timeout
;
165 /* Wait to get busy first */
166 timeout
= jiffies
+ GDROM_DEFAULT_TIMEOUT
;
167 while (!gdrom_is_busy() && time_before(jiffies
, timeout
))
169 /* Now wait for busy to clear */
170 return gdrom_wait_clrbusy();
173 static void gdrom_identifydevice(void *buf
)
177 /* If the device won't clear it has probably
178 * been hit by a serious failure - but we'll
179 * try to return a sense key even so */
180 if (!gdrom_wait_clrbusy()) {
181 gdrom_getsense(NULL
);
184 __raw_writeb(GDROM_COM_IDDEV
, GDROM_STATUSCOMMAND_REG
);
185 if (!gdrom_wait_busy_sleeps()) {
186 gdrom_getsense(NULL
);
189 /* now read in the data */
190 for (c
= 0; c
< 40; c
++)
191 data
[c
] = __raw_readw(GDROM_DATA_REG
);
194 static void gdrom_spicommand(void *spi_string
, int buflen
)
196 short *cmd
= spi_string
;
197 unsigned long timeout
;
199 /* ensure IRQ_WAIT is set */
200 __raw_writeb(0x08, GDROM_ALTSTATUS_REG
);
201 /* specify how many bytes we expect back */
202 __raw_writeb(buflen
& 0xFF, GDROM_BCL_REG
);
203 __raw_writeb((buflen
>> 8) & 0xFF, GDROM_BCH_REG
);
204 /* other parameters */
205 __raw_writeb(0, GDROM_INTSEC_REG
);
206 __raw_writeb(0, GDROM_SECNUM_REG
);
207 __raw_writeb(0, GDROM_ERROR_REG
);
208 /* Wait until we can go */
209 if (!gdrom_wait_clrbusy()) {
210 gdrom_getsense(NULL
);
213 timeout
= jiffies
+ GDROM_DEFAULT_TIMEOUT
;
214 __raw_writeb(GDROM_COM_PACKET
, GDROM_STATUSCOMMAND_REG
);
215 while (!gdrom_data_request() && time_before(jiffies
, timeout
))
217 if (!time_before(jiffies
, timeout
+ 1)) {
218 gdrom_getsense(NULL
);
221 outsw(GDROM_DATA_REG
, cmd
, 6);
225 /* gdrom_command_executediagnostic:
226 * Used to probe for presence of working GDROM
227 * Restarts GDROM device and then applies standard ATA 3
228 * Execute Diagnostic Command: a return of '1' indicates device 0
229 * present and device 1 absent
231 static char gdrom_execute_diagnostic(void)
233 gdrom_hardreset(gd
.cd_info
);
234 if (!gdrom_wait_clrbusy())
236 __raw_writeb(GDROM_COM_EXECDIAG
, GDROM_STATUSCOMMAND_REG
);
237 if (!gdrom_wait_busy_sleeps())
239 return __raw_readb(GDROM_ERROR_REG
);
243 * Prepare disk command
247 static int gdrom_preparedisk_cmd(void)
249 struct packet_command
*spin_command
;
250 spin_command
= kzalloc(sizeof(struct packet_command
), GFP_KERNEL
);
253 spin_command
->cmd
[0] = 0x70;
254 spin_command
->cmd
[2] = 0x1f;
255 spin_command
->buflen
= 0;
257 gdrom_packetcommand(gd
.cd_info
, spin_command
);
258 /* 60 second timeout */
259 wait_event_interruptible_timeout(command_queue
, gd
.pending
== 0,
260 GDROM_DEFAULT_TIMEOUT
);
263 if (gd
.status
& 0x01) {
265 gdrom_getsense(NULL
);
275 * byte 3 = sizeof TOC >> 8 ie upper byte
276 * byte 4 = sizeof TOC & 0xff ie lower byte
278 static int gdrom_readtoc_cmd(struct gdromtoc
*toc
, int session
)
281 struct packet_command
*toc_command
;
284 toc_command
= kzalloc(sizeof(struct packet_command
), GFP_KERNEL
);
287 tocsize
= sizeof(struct gdromtoc
);
288 toc_command
->cmd
[0] = 0x14;
289 toc_command
->cmd
[1] = session
;
290 toc_command
->cmd
[3] = tocsize
>> 8;
291 toc_command
->cmd
[4] = tocsize
& 0xff;
292 toc_command
->buflen
= tocsize
;
295 goto cleanup_readtoc_final
;
298 gdrom_packetcommand(gd
.cd_info
, toc_command
);
299 wait_event_interruptible_timeout(command_queue
, gd
.pending
== 0,
300 GDROM_DEFAULT_TIMEOUT
);
303 goto cleanup_readtoc
;
305 insw(GDROM_DATA_REG
, toc
, tocsize
/2);
306 if (gd
.status
& 0x01)
311 cleanup_readtoc_final
:
317 static int get_entry_lba(int track
)
319 return (cpu_to_be32(track
& 0xffffff00) - GD_SESSION_OFFSET
);
322 static int get_entry_q_ctrl(int track
)
324 return (track
& 0x000000f0) >> 4;
327 static int get_entry_track(int track
)
329 return (track
& 0x0000ff00) >> 8;
332 static int gdrom_get_last_session(struct cdrom_device_info
*cd_info
,
333 struct cdrom_multisession
*ms_info
)
335 int fentry
, lentry
, track
, data
, tocuse
, err
;
339 /* Check if GD-ROM */
340 err
= gdrom_readtoc_cmd(gd
.toc
, 1);
341 /* Not a GD-ROM so check if standard CD-ROM */
344 err
= gdrom_readtoc_cmd(gd
.toc
, 0);
346 pr_info("Could not get CD table of contents\n");
351 fentry
= get_entry_track(gd
.toc
->first
);
352 lentry
= get_entry_track(gd
.toc
->last
);
353 /* Find the first data track */
354 track
= get_entry_track(gd
.toc
->last
);
356 data
= gd
.toc
->entry
[track
- 1];
357 if (get_entry_q_ctrl(data
))
358 break; /* ie a real data track */
360 } while (track
>= fentry
);
362 if ((track
> 100) || (track
< get_entry_track(gd
.toc
->first
))) {
363 pr_info("No data on the last session of the CD\n");
364 gdrom_getsense(NULL
);
368 ms_info
->addr_format
= CDROM_LBA
;
369 ms_info
->addr
.lba
= get_entry_lba(data
);
370 ms_info
->xa_flag
= 1;
374 static int gdrom_open(struct cdrom_device_info
*cd_info
, int purpose
)
376 /* spin up the disk */
377 return gdrom_preparedisk_cmd();
380 /* this function is required even if empty */
381 static void gdrom_release(struct cdrom_device_info
*cd_info
)
385 static int gdrom_drivestatus(struct cdrom_device_info
*cd_info
, int ignore
)
387 /* read the sense key */
388 char sense
= __raw_readb(GDROM_ERROR_REG
);
393 return CDS_DRIVE_NOT_READY
;
398 static unsigned int gdrom_check_events(struct cdrom_device_info
*cd_info
,
399 unsigned int clearing
, int ignore
)
401 /* check the sense key */
402 return (__raw_readb(GDROM_ERROR_REG
) & 0xF0) == 0x60 ?
403 DISK_EVENT_MEDIA_CHANGE
: 0;
406 /* reset the G1 bus */
407 static int gdrom_hardreset(struct cdrom_device_info
*cd_info
)
410 __raw_writel(0x1fffff, GDROM_RESET_REG
);
411 for (count
= 0xa0000000; count
< 0xa0200000; count
+= 4)
416 /* keep the function looking like the universal
417 * CD Rom specification - returning int */
418 static int gdrom_packetcommand(struct cdrom_device_info
*cd_info
,
419 struct packet_command
*command
)
421 gdrom_spicommand(&command
->cmd
, command
->buflen
);
425 /* Get Sense SPI command
426 * From Marcus Comstedt
428 * cmd + 4 = length of returned buffer
429 * Returns 5 16 bit words
431 static int gdrom_getsense(short *bufstring
)
433 struct packet_command
*sense_command
;
438 sense_command
= kzalloc(sizeof(struct packet_command
), GFP_KERNEL
);
441 sense_command
->cmd
[0] = 0x13;
442 sense_command
->cmd
[4] = 10;
443 sense_command
->buflen
= 10;
444 /* even if something is pending try to get
445 * the sense key if possible */
446 if (gd
.pending
&& !gdrom_wait_clrbusy()) {
448 goto cleanup_sense_final
;
451 gdrom_packetcommand(gd
.cd_info
, sense_command
);
452 wait_event_interruptible_timeout(command_queue
, gd
.pending
== 0,
453 GDROM_DEFAULT_TIMEOUT
);
456 insw(GDROM_DATA_REG
, &sense
, sense_command
->buflen
/2);
458 pr_info("Drive not ready - command aborted\n");
461 sense_key
= sense
[1] & 0x0F;
462 if (sense_key
< ARRAY_SIZE(sense_texts
))
463 pr_info("%s\n", sense_texts
[sense_key
].text
);
465 pr_err("Unknown sense key: %d\n", sense_key
);
466 if (bufstring
) /* return addional sense data */
467 memcpy(bufstring
, &sense
[4], 2);
474 kfree(sense_command
);
478 static int gdrom_audio_ioctl(struct cdrom_device_info
*cdi
, unsigned int cmd
,
484 static struct cdrom_device_ops gdrom_ops
= {
486 .release
= gdrom_release
,
487 .drive_status
= gdrom_drivestatus
,
488 .check_events
= gdrom_check_events
,
489 .get_last_session
= gdrom_get_last_session
,
490 .reset
= gdrom_hardreset
,
491 .audio_ioctl
= gdrom_audio_ioctl
,
492 .capability
= CDC_MULTI_SESSION
| CDC_MEDIA_CHANGED
|
493 CDC_RESET
| CDC_DRIVE_STATUS
| CDC_CD_R
,
497 static int gdrom_bdops_open(struct block_device
*bdev
, fmode_t mode
)
500 mutex_lock(&gdrom_mutex
);
501 ret
= cdrom_open(gd
.cd_info
, bdev
, mode
);
502 mutex_unlock(&gdrom_mutex
);
506 static int gdrom_bdops_release(struct gendisk
*disk
, fmode_t mode
)
508 mutex_lock(&gdrom_mutex
);
509 cdrom_release(gd
.cd_info
, mode
);
510 mutex_unlock(&gdrom_mutex
);
514 static unsigned int gdrom_bdops_check_events(struct gendisk
*disk
,
515 unsigned int clearing
)
517 return cdrom_check_events(gd
.cd_info
, clearing
);
520 static int gdrom_bdops_ioctl(struct block_device
*bdev
, fmode_t mode
,
521 unsigned cmd
, unsigned long arg
)
525 mutex_lock(&gdrom_mutex
);
526 ret
= cdrom_ioctl(gd
.cd_info
, bdev
, mode
, cmd
, arg
);
527 mutex_unlock(&gdrom_mutex
);
532 static const struct block_device_operations gdrom_bdops
= {
533 .owner
= THIS_MODULE
,
534 .open
= gdrom_bdops_open
,
535 .release
= gdrom_bdops_release
,
536 .check_events
= gdrom_bdops_check_events
,
537 .ioctl
= gdrom_bdops_ioctl
,
540 static irqreturn_t
gdrom_command_interrupt(int irq
, void *dev_id
)
542 gd
.status
= __raw_readb(GDROM_STATUSCOMMAND_REG
);
546 wake_up_interruptible(&command_queue
);
550 static irqreturn_t
gdrom_dma_interrupt(int irq
, void *dev_id
)
552 gd
.status
= __raw_readb(GDROM_STATUSCOMMAND_REG
);
553 if (gd
.transfer
!= 1)
556 wake_up_interruptible(&request_queue
);
560 static int __devinit
gdrom_set_interrupt_handlers(void)
564 err
= request_irq(HW_EVENT_GDROM_CMD
, gdrom_command_interrupt
,
565 IRQF_DISABLED
, "gdrom_command", &gd
);
568 err
= request_irq(HW_EVENT_GDROM_DMA
, gdrom_dma_interrupt
,
569 IRQF_DISABLED
, "gdrom_dma", &gd
);
571 free_irq(HW_EVENT_GDROM_CMD
, &gd
);
575 /* Implement DMA read using SPI command
585 static void gdrom_readdisk_dma(struct work_struct
*work
)
587 int err
, block
, block_cnt
;
588 struct packet_command
*read_command
;
589 struct list_head
*elem
, *next
;
591 unsigned long timeout
;
593 if (list_empty(&gdrom_deferred
))
595 read_command
= kzalloc(sizeof(struct packet_command
), GFP_KERNEL
);
597 return; /* get more memory later? */
598 read_command
->cmd
[0] = 0x30;
599 read_command
->cmd
[1] = 0x20;
600 spin_lock(&gdrom_lock
);
601 list_for_each_safe(elem
, next
, &gdrom_deferred
) {
602 req
= list_entry(elem
, struct request
, queuelist
);
603 spin_unlock(&gdrom_lock
);
604 block
= blk_rq_pos(req
)/GD_TO_BLK
+ GD_SESSION_OFFSET
;
605 block_cnt
= blk_rq_sectors(req
)/GD_TO_BLK
;
606 __raw_writel(virt_to_phys(req
->buffer
), GDROM_DMA_STARTADDR_REG
);
607 __raw_writel(block_cnt
* GDROM_HARD_SECTOR
, GDROM_DMA_LENGTH_REG
);
608 __raw_writel(1, GDROM_DMA_DIRECTION_REG
);
609 __raw_writel(1, GDROM_DMA_ENABLE_REG
);
610 read_command
->cmd
[2] = (block
>> 16) & 0xFF;
611 read_command
->cmd
[3] = (block
>> 8) & 0xFF;
612 read_command
->cmd
[4] = block
& 0xFF;
613 read_command
->cmd
[8] = (block_cnt
>> 16) & 0xFF;
614 read_command
->cmd
[9] = (block_cnt
>> 8) & 0xFF;
615 read_command
->cmd
[10] = block_cnt
& 0xFF;
617 __raw_writeb(1, GDROM_ERROR_REG
);
618 /* other registers */
619 __raw_writeb(0, GDROM_SECNUM_REG
);
620 __raw_writeb(0, GDROM_BCL_REG
);
621 __raw_writeb(0, GDROM_BCH_REG
);
622 __raw_writeb(0, GDROM_DSEL_REG
);
623 __raw_writeb(0, GDROM_INTSEC_REG
);
624 /* Wait for registers to reset after any previous activity */
625 timeout
= jiffies
+ HZ
/ 2;
626 while (gdrom_is_busy() && time_before(jiffies
, timeout
))
628 __raw_writeb(GDROM_COM_PACKET
, GDROM_STATUSCOMMAND_REG
);
629 timeout
= jiffies
+ HZ
/ 2;
630 /* Wait for packet command to finish */
631 while (gdrom_is_busy() && time_before(jiffies
, timeout
))
635 outsw(GDROM_DATA_REG
, &read_command
->cmd
, 6);
636 timeout
= jiffies
+ HZ
/ 2;
637 /* Wait for any pending DMA to finish */
638 while (__raw_readb(GDROM_DMA_STATUS_REG
) &&
639 time_before(jiffies
, timeout
))
642 __raw_writeb(1, GDROM_DMA_STATUS_REG
);
643 wait_event_interruptible_timeout(request_queue
,
644 gd
.transfer
== 0, GDROM_DEFAULT_TIMEOUT
);
645 err
= gd
.transfer
? -EIO
: 0;
648 /* now seek to take the request spinlock
649 * before handling ending the request */
650 spin_lock(&gdrom_lock
);
651 list_del_init(&req
->queuelist
);
652 __blk_end_request_all(req
, err
);
654 spin_unlock(&gdrom_lock
);
658 static void gdrom_request(struct request_queue
*rq
)
662 while ((req
= blk_fetch_request(rq
)) != NULL
) {
663 if (req
->cmd_type
!= REQ_TYPE_FS
) {
664 printk(KERN_DEBUG
"gdrom: Non-fs request ignored\n");
665 __blk_end_request_all(req
, -EIO
);
668 if (rq_data_dir(req
) != READ
) {
669 pr_notice("Read only device - write request ignored\n");
670 __blk_end_request_all(req
, -EIO
);
675 * Add to list of deferred work and then schedule
678 list_add_tail(&req
->queuelist
, &gdrom_deferred
);
679 schedule_work(&work
);
683 /* Print string identifying GD ROM device */
684 static int __devinit
gdrom_outputversion(void)
687 char *model_name
, *manuf_name
, *firmw_ver
;
690 /* query device ID */
691 id
= kzalloc(sizeof(struct gdrom_id
), GFP_KERNEL
);
694 gdrom_identifydevice(id
);
695 model_name
= kstrndup(id
->modname
, 16, GFP_KERNEL
);
698 manuf_name
= kstrndup(id
->mname
, 16, GFP_KERNEL
);
700 goto free_model_name
;
701 firmw_ver
= kstrndup(id
->firmver
, 16, GFP_KERNEL
);
703 goto free_manuf_name
;
704 pr_info("%s from %s with firmware %s\n",
705 model_name
, manuf_name
, firmw_ver
);
717 /* set the default mode for DMA transfer */
718 static int __devinit
gdrom_init_dma_mode(void)
720 __raw_writeb(0x13, GDROM_ERROR_REG
);
721 __raw_writeb(0x22, GDROM_INTSEC_REG
);
722 if (!gdrom_wait_clrbusy())
724 __raw_writeb(0xEF, GDROM_STATUSCOMMAND_REG
);
725 if (!gdrom_wait_busy_sleeps())
727 /* Memory protection setting for GDROM DMA
728 * Bits 31 - 16 security: 0x8843
729 * Bits 15 and 7 reserved (0)
730 * Bits 14 - 8 start of transfer range in 1 MB blocks OR'ed with 0x80
731 * Bits 6 - 0 end of transfer range in 1 MB blocks OR'ed with 0x80
732 * (0x40 | 0x80) = start range at 0x0C000000
733 * (0x7F | 0x80) = end range at 0x0FFFFFFF */
734 __raw_writel(0x8843407F, GDROM_DMA_ACCESS_CTRL_REG
);
735 __raw_writel(9, GDROM_DMA_WAIT_REG
); /* DMA word setting */
739 static void __devinit
probe_gdrom_setupcd(void)
741 gd
.cd_info
->ops
= &gdrom_ops
;
742 gd
.cd_info
->capacity
= 1;
743 strcpy(gd
.cd_info
->name
, GDROM_DEV_NAME
);
744 gd
.cd_info
->mask
= CDC_CLOSE_TRAY
|CDC_OPEN_TRAY
|CDC_LOCK
|
748 static void __devinit
probe_gdrom_setupdisk(void)
750 gd
.disk
->major
= gdrom_major
;
751 gd
.disk
->first_minor
= 1;
753 strcpy(gd
.disk
->disk_name
, GDROM_DEV_NAME
);
756 static int __devinit
probe_gdrom_setupqueue(void)
758 blk_queue_logical_block_size(gd
.gdrom_rq
, GDROM_HARD_SECTOR
);
759 /* using DMA so memory will need to be contiguous */
760 blk_queue_max_segments(gd
.gdrom_rq
, 1);
761 /* set a large max size to get most from DMA */
762 blk_queue_max_segment_size(gd
.gdrom_rq
, 0x40000);
763 gd
.disk
->queue
= gd
.gdrom_rq
;
764 return gdrom_init_dma_mode();
768 * register this as a block device and as compliant with the
769 * universal CD Rom driver interface
771 static int __devinit
probe_gdrom(struct platform_device
*devptr
)
774 /* Start the device */
775 if (gdrom_execute_diagnostic() != 1) {
776 pr_warning("ATA Probe for GDROM failed\n");
779 /* Print out firmware ID */
780 if (gdrom_outputversion())
783 gdrom_major
= register_blkdev(0, GDROM_DEV_NAME
);
784 if (gdrom_major
<= 0)
786 pr_info("Registered with major number %d\n",
788 /* Specify basic properties of drive */
789 gd
.cd_info
= kzalloc(sizeof(struct cdrom_device_info
), GFP_KERNEL
);
792 goto probe_fail_no_mem
;
794 probe_gdrom_setupcd();
795 gd
.disk
= alloc_disk(1);
798 goto probe_fail_no_disk
;
800 probe_gdrom_setupdisk();
801 if (register_cdrom(gd
.cd_info
)) {
803 goto probe_fail_cdrom_register
;
805 gd
.disk
->fops
= &gdrom_bdops
;
806 /* latch on to the interrupt */
807 err
= gdrom_set_interrupt_handlers();
809 goto probe_fail_cmdirq_register
;
810 gd
.gdrom_rq
= blk_init_queue(gdrom_request
, &gdrom_lock
);
812 goto probe_fail_requestq
;
814 err
= probe_gdrom_setupqueue();
818 gd
.toc
= kzalloc(sizeof(struct gdromtoc
), GFP_KERNEL
);
825 blk_cleanup_queue(gd
.gdrom_rq
);
827 free_irq(HW_EVENT_GDROM_DMA
, &gd
);
828 free_irq(HW_EVENT_GDROM_CMD
, &gd
);
829 probe_fail_cmdirq_register
:
830 probe_fail_cdrom_register
:
831 del_gendisk(gd
.disk
);
834 unregister_blkdev(gdrom_major
, GDROM_DEV_NAME
);
837 pr_warning("Probe failed - error is 0x%X\n", err
);
841 static int __devexit
remove_gdrom(struct platform_device
*devptr
)
843 flush_work_sync(&work
);
844 blk_cleanup_queue(gd
.gdrom_rq
);
845 free_irq(HW_EVENT_GDROM_CMD
, &gd
);
846 free_irq(HW_EVENT_GDROM_DMA
, &gd
);
847 del_gendisk(gd
.disk
);
849 unregister_blkdev(gdrom_major
, GDROM_DEV_NAME
);
850 unregister_cdrom(gd
.cd_info
);
855 static struct platform_driver gdrom_driver
= {
856 .probe
= probe_gdrom
,
857 .remove
= __devexit_p(remove_gdrom
),
859 .name
= GDROM_DEV_NAME
,
863 static int __init
init_gdrom(void)
867 rc
= platform_driver_register(&gdrom_driver
);
870 pd
= platform_device_register_simple(GDROM_DEV_NAME
, -1, NULL
, 0);
872 platform_driver_unregister(&gdrom_driver
);
878 static void __exit
exit_gdrom(void)
880 platform_device_unregister(pd
);
881 platform_driver_unregister(&gdrom_driver
);
885 module_init(init_gdrom
);
886 module_exit(exit_gdrom
);
887 MODULE_AUTHOR("Adrian McMenamin <adrian@mcmen.demon.co.uk>");
888 MODULE_DESCRIPTION("SEGA Dreamcast GD-ROM Driver");
889 MODULE_LICENSE("GPL");