Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 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 |
| 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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. |
| 19 | * |
| 20 | */ |
| 21 | |
Joe Perches | e597cd0 | 2010-07-01 08:24:32 +0200 | [diff] [blame] | 22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 23 | |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 24 | #include <linux/init.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/fs.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> |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 37 | #include <linux/mutex.h> |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 38 | #include <linux/wait.h> |
| 39 | #include <linux/workqueue.h> |
| 40 | #include <linux/platform_device.h> |
| 41 | #include <scsi/scsi.h> |
| 42 | #include <asm/io.h> |
| 43 | #include <asm/dma.h> |
| 44 | #include <asm/delay.h> |
Paul Mundt | 0764bff | 2008-07-29 22:10:01 +0900 | [diff] [blame] | 45 | #include <mach/dma.h> |
| 46 | #include <mach/sysasic.h> |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 47 | |
| 48 | #define GDROM_DEV_NAME "gdrom" |
| 49 | #define GD_SESSION_OFFSET 150 |
| 50 | |
| 51 | /* GD Rom commands */ |
| 52 | #define GDROM_COM_SOFTRESET 0x08 |
| 53 | #define GDROM_COM_EXECDIAG 0x90 |
| 54 | #define GDROM_COM_PACKET 0xA0 |
| 55 | #define GDROM_COM_IDDEV 0xA1 |
| 56 | |
| 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) |
| 69 | |
| 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) |
| 77 | |
| 78 | #define GDROM_HARD_SECTOR 2048 |
| 79 | #define BLOCK_LAYER_SECTOR 512 |
| 80 | #define GD_TO_BLK 4 |
| 81 | |
| 82 | #define GDROM_DEFAULT_TIMEOUT (HZ * 7) |
| 83 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 84 | static DEFINE_MUTEX(gdrom_mutex); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 85 | static const struct { |
| 86 | int sense_key; |
| 87 | const char * const text; |
| 88 | } sense_texts[] = { |
| 89 | {NO_SENSE, "OK"}, |
| 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"}, |
| 98 | }; |
| 99 | |
| 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); |
| 104 | |
| 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); |
| 109 | |
| 110 | struct gdromtoc { |
| 111 | unsigned int entry[99]; |
| 112 | unsigned int first, last; |
| 113 | unsigned int leadout; |
| 114 | }; |
| 115 | |
| 116 | static struct gdrom_unit { |
| 117 | struct gendisk *disk; |
| 118 | struct cdrom_device_info *cd_info; |
| 119 | int status; |
| 120 | int pending; |
| 121 | int transfer; |
| 122 | char disk_type; |
| 123 | struct gdromtoc *toc; |
| 124 | struct request_queue *gdrom_rq; |
| 125 | } gd; |
| 126 | |
| 127 | struct gdrom_id { |
| 128 | char mid; |
| 129 | char modid; |
| 130 | char verid; |
| 131 | char padA[13]; |
| 132 | char mname[16]; |
| 133 | char modname[16]; |
| 134 | char firmver[16]; |
| 135 | char padB[16]; |
| 136 | }; |
| 137 | |
| 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); |
| 142 | |
| 143 | static bool gdrom_is_busy(void) |
| 144 | { |
| 145 | return (ctrl_inb(GDROM_ALTSTATUS_REG) & 0x80) != 0; |
| 146 | } |
| 147 | |
| 148 | static bool gdrom_data_request(void) |
| 149 | { |
| 150 | return (ctrl_inb(GDROM_ALTSTATUS_REG) & 0x88) == 8; |
| 151 | } |
| 152 | |
| 153 | static bool gdrom_wait_clrbusy(void) |
| 154 | { |
| 155 | unsigned long timeout = jiffies + GDROM_DEFAULT_TIMEOUT; |
| 156 | while ((ctrl_inb(GDROM_ALTSTATUS_REG) & 0x80) && |
| 157 | (time_before(jiffies, timeout))) |
| 158 | cpu_relax(); |
| 159 | return time_before(jiffies, timeout + 1); |
| 160 | } |
| 161 | |
| 162 | static bool gdrom_wait_busy_sleeps(void) |
| 163 | { |
| 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)) |
| 168 | cpu_relax(); |
| 169 | /* Now wait for busy to clear */ |
| 170 | return gdrom_wait_clrbusy(); |
| 171 | } |
| 172 | |
| 173 | static void gdrom_identifydevice(void *buf) |
| 174 | { |
| 175 | int c; |
| 176 | short *data = 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); |
| 182 | return; |
| 183 | } |
| 184 | ctrl_outb(GDROM_COM_IDDEV, GDROM_STATUSCOMMAND_REG); |
| 185 | if (!gdrom_wait_busy_sleeps()) { |
| 186 | gdrom_getsense(NULL); |
| 187 | return; |
| 188 | } |
| 189 | /* now read in the data */ |
| 190 | for (c = 0; c < 40; c++) |
| 191 | data[c] = ctrl_inw(GDROM_DATA_REG); |
| 192 | } |
| 193 | |
| 194 | static void gdrom_spicommand(void *spi_string, int buflen) |
| 195 | { |
| 196 | short *cmd = spi_string; |
| 197 | unsigned long timeout; |
| 198 | |
| 199 | /* ensure IRQ_WAIT is set */ |
| 200 | ctrl_outb(0x08, GDROM_ALTSTATUS_REG); |
| 201 | /* specify how many bytes we expect back */ |
| 202 | ctrl_outb(buflen & 0xFF, GDROM_BCL_REG); |
| 203 | ctrl_outb((buflen >> 8) & 0xFF, GDROM_BCH_REG); |
| 204 | /* other parameters */ |
| 205 | ctrl_outb(0, GDROM_INTSEC_REG); |
| 206 | ctrl_outb(0, GDROM_SECNUM_REG); |
| 207 | ctrl_outb(0, GDROM_ERROR_REG); |
| 208 | /* Wait until we can go */ |
| 209 | if (!gdrom_wait_clrbusy()) { |
| 210 | gdrom_getsense(NULL); |
| 211 | return; |
| 212 | } |
| 213 | timeout = jiffies + GDROM_DEFAULT_TIMEOUT; |
| 214 | ctrl_outb(GDROM_COM_PACKET, GDROM_STATUSCOMMAND_REG); |
| 215 | while (!gdrom_data_request() && time_before(jiffies, timeout)) |
| 216 | cpu_relax(); |
| 217 | if (!time_before(jiffies, timeout + 1)) { |
| 218 | gdrom_getsense(NULL); |
| 219 | return; |
| 220 | } |
Paul Mundt | 54d5102 | 2009-10-13 12:30:40 +0900 | [diff] [blame] | 221 | outsw(GDROM_DATA_REG, cmd, 6); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | |
| 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 |
| 230 | */ |
| 231 | static char gdrom_execute_diagnostic(void) |
| 232 | { |
| 233 | gdrom_hardreset(gd.cd_info); |
| 234 | if (!gdrom_wait_clrbusy()) |
| 235 | return 0; |
| 236 | ctrl_outb(GDROM_COM_EXECDIAG, GDROM_STATUSCOMMAND_REG); |
| 237 | if (!gdrom_wait_busy_sleeps()) |
| 238 | return 0; |
| 239 | return ctrl_inb(GDROM_ERROR_REG); |
| 240 | } |
| 241 | |
| 242 | /* |
| 243 | * Prepare disk command |
| 244 | * byte 0 = 0x70 |
| 245 | * byte 1 = 0x1f |
| 246 | */ |
| 247 | static int gdrom_preparedisk_cmd(void) |
| 248 | { |
| 249 | struct packet_command *spin_command; |
| 250 | spin_command = kzalloc(sizeof(struct packet_command), GFP_KERNEL); |
| 251 | if (!spin_command) |
| 252 | return -ENOMEM; |
| 253 | spin_command->cmd[0] = 0x70; |
| 254 | spin_command->cmd[2] = 0x1f; |
| 255 | spin_command->buflen = 0; |
| 256 | gd.pending = 1; |
| 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); |
| 261 | gd.pending = 0; |
| 262 | kfree(spin_command); |
| 263 | if (gd.status & 0x01) { |
| 264 | /* log an error */ |
| 265 | gdrom_getsense(NULL); |
| 266 | return -EIO; |
| 267 | } |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | /* |
| 272 | * Read TOC command |
| 273 | * byte 0 = 0x14 |
| 274 | * byte 1 = session |
| 275 | * byte 3 = sizeof TOC >> 8 ie upper byte |
| 276 | * byte 4 = sizeof TOC & 0xff ie lower byte |
| 277 | */ |
| 278 | static int gdrom_readtoc_cmd(struct gdromtoc *toc, int session) |
| 279 | { |
| 280 | int tocsize; |
| 281 | struct packet_command *toc_command; |
| 282 | int err = 0; |
| 283 | |
| 284 | toc_command = kzalloc(sizeof(struct packet_command), GFP_KERNEL); |
| 285 | if (!toc_command) |
| 286 | return -ENOMEM; |
| 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; |
| 293 | if (gd.pending) { |
| 294 | err = -EBUSY; |
| 295 | goto cleanup_readtoc_final; |
| 296 | } |
| 297 | gd.pending = 1; |
| 298 | gdrom_packetcommand(gd.cd_info, toc_command); |
| 299 | wait_event_interruptible_timeout(command_queue, gd.pending == 0, |
| 300 | GDROM_DEFAULT_TIMEOUT); |
| 301 | if (gd.pending) { |
| 302 | err = -EINVAL; |
| 303 | goto cleanup_readtoc; |
| 304 | } |
Paul Mundt | 54d5102 | 2009-10-13 12:30:40 +0900 | [diff] [blame] | 305 | insw(GDROM_DATA_REG, toc, tocsize/2); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 306 | if (gd.status & 0x01) |
| 307 | err = -EINVAL; |
| 308 | |
| 309 | cleanup_readtoc: |
| 310 | gd.pending = 0; |
| 311 | cleanup_readtoc_final: |
| 312 | kfree(toc_command); |
| 313 | return err; |
| 314 | } |
| 315 | |
| 316 | /* TOC helpers */ |
| 317 | static int get_entry_lba(int track) |
| 318 | { |
| 319 | return (cpu_to_be32(track & 0xffffff00) - GD_SESSION_OFFSET); |
| 320 | } |
| 321 | |
| 322 | static int get_entry_q_ctrl(int track) |
| 323 | { |
| 324 | return (track & 0x000000f0) >> 4; |
| 325 | } |
| 326 | |
| 327 | static int get_entry_track(int track) |
| 328 | { |
| 329 | return (track & 0x0000ff00) >> 8; |
| 330 | } |
| 331 | |
| 332 | static int gdrom_get_last_session(struct cdrom_device_info *cd_info, |
| 333 | struct cdrom_multisession *ms_info) |
| 334 | { |
| 335 | int fentry, lentry, track, data, tocuse, err; |
| 336 | if (!gd.toc) |
| 337 | return -ENOMEM; |
| 338 | tocuse = 1; |
| 339 | /* Check if GD-ROM */ |
| 340 | err = gdrom_readtoc_cmd(gd.toc, 1); |
| 341 | /* Not a GD-ROM so check if standard CD-ROM */ |
| 342 | if (err) { |
| 343 | tocuse = 0; |
| 344 | err = gdrom_readtoc_cmd(gd.toc, 0); |
| 345 | if (err) { |
Joe Perches | e597cd0 | 2010-07-01 08:24:32 +0200 | [diff] [blame] | 346 | pr_info("Could not get CD table of contents\n"); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 347 | return -ENXIO; |
| 348 | } |
| 349 | } |
| 350 | |
| 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); |
| 355 | do { |
| 356 | data = gd.toc->entry[track - 1]; |
| 357 | if (get_entry_q_ctrl(data)) |
| 358 | break; /* ie a real data track */ |
| 359 | track--; |
| 360 | } while (track >= fentry); |
| 361 | |
| 362 | if ((track > 100) || (track < get_entry_track(gd.toc->first))) { |
Joe Perches | e597cd0 | 2010-07-01 08:24:32 +0200 | [diff] [blame] | 363 | pr_info("No data on the last session of the CD\n"); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 364 | gdrom_getsense(NULL); |
| 365 | return -ENXIO; |
| 366 | } |
| 367 | |
| 368 | ms_info->addr_format = CDROM_LBA; |
| 369 | ms_info->addr.lba = get_entry_lba(data); |
| 370 | ms_info->xa_flag = 1; |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | static int gdrom_open(struct cdrom_device_info *cd_info, int purpose) |
| 375 | { |
| 376 | /* spin up the disk */ |
| 377 | return gdrom_preparedisk_cmd(); |
| 378 | } |
| 379 | |
| 380 | /* this function is required even if empty */ |
| 381 | static void gdrom_release(struct cdrom_device_info *cd_info) |
| 382 | { |
| 383 | } |
| 384 | |
| 385 | static int gdrom_drivestatus(struct cdrom_device_info *cd_info, int ignore) |
| 386 | { |
| 387 | /* read the sense key */ |
| 388 | char sense = ctrl_inb(GDROM_ERROR_REG); |
| 389 | sense &= 0xF0; |
| 390 | if (sense == 0) |
| 391 | return CDS_DISC_OK; |
| 392 | if (sense == 0x20) |
| 393 | return CDS_DRIVE_NOT_READY; |
| 394 | /* default */ |
| 395 | return CDS_NO_INFO; |
| 396 | } |
| 397 | |
| 398 | static int gdrom_mediachanged(struct cdrom_device_info *cd_info, int ignore) |
| 399 | { |
| 400 | /* check the sense key */ |
| 401 | return (ctrl_inb(GDROM_ERROR_REG) & 0xF0) == 0x60; |
| 402 | } |
| 403 | |
| 404 | /* reset the G1 bus */ |
| 405 | static int gdrom_hardreset(struct cdrom_device_info *cd_info) |
| 406 | { |
| 407 | int count; |
| 408 | ctrl_outl(0x1fffff, GDROM_RESET_REG); |
| 409 | for (count = 0xa0000000; count < 0xa0200000; count += 4) |
| 410 | ctrl_inl(count); |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | /* keep the function looking like the universal |
| 415 | * CD Rom specification - returning int */ |
| 416 | static int gdrom_packetcommand(struct cdrom_device_info *cd_info, |
| 417 | struct packet_command *command) |
| 418 | { |
| 419 | gdrom_spicommand(&command->cmd, command->buflen); |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | /* Get Sense SPI command |
| 424 | * From Marcus Comstedt |
| 425 | * cmd = 0x13 |
| 426 | * cmd + 4 = length of returned buffer |
| 427 | * Returns 5 16 bit words |
| 428 | */ |
| 429 | static int gdrom_getsense(short *bufstring) |
| 430 | { |
| 431 | struct packet_command *sense_command; |
| 432 | short sense[5]; |
| 433 | int sense_key; |
| 434 | int err = -EIO; |
| 435 | |
| 436 | sense_command = kzalloc(sizeof(struct packet_command), GFP_KERNEL); |
| 437 | if (!sense_command) |
| 438 | return -ENOMEM; |
| 439 | sense_command->cmd[0] = 0x13; |
| 440 | sense_command->cmd[4] = 10; |
| 441 | sense_command->buflen = 10; |
| 442 | /* even if something is pending try to get |
| 443 | * the sense key if possible */ |
| 444 | if (gd.pending && !gdrom_wait_clrbusy()) { |
| 445 | err = -EBUSY; |
| 446 | goto cleanup_sense_final; |
| 447 | } |
| 448 | gd.pending = 1; |
| 449 | gdrom_packetcommand(gd.cd_info, sense_command); |
| 450 | wait_event_interruptible_timeout(command_queue, gd.pending == 0, |
| 451 | GDROM_DEFAULT_TIMEOUT); |
| 452 | if (gd.pending) |
| 453 | goto cleanup_sense; |
Paul Mundt | 54d5102 | 2009-10-13 12:30:40 +0900 | [diff] [blame] | 454 | insw(GDROM_DATA_REG, &sense, sense_command->buflen/2); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 455 | if (sense[1] & 40) { |
Joe Perches | e597cd0 | 2010-07-01 08:24:32 +0200 | [diff] [blame] | 456 | pr_info("Drive not ready - command aborted\n"); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 457 | goto cleanup_sense; |
| 458 | } |
| 459 | sense_key = sense[1] & 0x0F; |
| 460 | if (sense_key < ARRAY_SIZE(sense_texts)) |
Joe Perches | e597cd0 | 2010-07-01 08:24:32 +0200 | [diff] [blame] | 461 | pr_info("%s\n", sense_texts[sense_key].text); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 462 | else |
Joe Perches | e597cd0 | 2010-07-01 08:24:32 +0200 | [diff] [blame] | 463 | pr_err("Unknown sense key: %d\n", sense_key); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 464 | if (bufstring) /* return addional sense data */ |
| 465 | memcpy(bufstring, &sense[4], 2); |
| 466 | if (sense_key < 2) |
| 467 | err = 0; |
| 468 | |
| 469 | cleanup_sense: |
| 470 | gd.pending = 0; |
| 471 | cleanup_sense_final: |
| 472 | kfree(sense_command); |
| 473 | return err; |
| 474 | } |
| 475 | |
Borislav Petkov | d15cad5 | 2008-08-18 21:40:04 +0200 | [diff] [blame] | 476 | static int gdrom_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, |
| 477 | void *arg) |
| 478 | { |
| 479 | return -EINVAL; |
| 480 | } |
| 481 | |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 482 | static struct cdrom_device_ops gdrom_ops = { |
| 483 | .open = gdrom_open, |
| 484 | .release = gdrom_release, |
| 485 | .drive_status = gdrom_drivestatus, |
| 486 | .media_changed = gdrom_mediachanged, |
| 487 | .get_last_session = gdrom_get_last_session, |
| 488 | .reset = gdrom_hardreset, |
Borislav Petkov | d15cad5 | 2008-08-18 21:40:04 +0200 | [diff] [blame] | 489 | .audio_ioctl = gdrom_audio_ioctl, |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 490 | .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED | |
| 491 | CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R, |
| 492 | .n_minors = 1, |
| 493 | }; |
| 494 | |
Al Viro | 8389feb | 2008-03-02 10:25:18 -0500 | [diff] [blame] | 495 | static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode) |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 496 | { |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 497 | int ret; |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 498 | mutex_lock(&gdrom_mutex); |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 499 | ret = cdrom_open(gd.cd_info, bdev, mode); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 500 | mutex_unlock(&gdrom_mutex); |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 501 | return ret; |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 502 | } |
| 503 | |
Nobuhiro Iwamatsu | 545727f | 2008-10-27 11:32:27 +0900 | [diff] [blame] | 504 | static int gdrom_bdops_release(struct gendisk *disk, fmode_t mode) |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 505 | { |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 506 | mutex_lock(&gdrom_mutex); |
Nobuhiro Iwamatsu | 545727f | 2008-10-27 11:32:27 +0900 | [diff] [blame] | 507 | cdrom_release(gd.cd_info, mode); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 508 | mutex_unlock(&gdrom_mutex); |
Nobuhiro Iwamatsu | 545727f | 2008-10-27 11:32:27 +0900 | [diff] [blame] | 509 | return 0; |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | static int gdrom_bdops_mediachanged(struct gendisk *disk) |
| 513 | { |
| 514 | return cdrom_media_changed(gd.cd_info); |
| 515 | } |
| 516 | |
Al Viro | 8389feb | 2008-03-02 10:25:18 -0500 | [diff] [blame] | 517 | static int gdrom_bdops_ioctl(struct block_device *bdev, fmode_t mode, |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 518 | unsigned cmd, unsigned long arg) |
| 519 | { |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 520 | int ret; |
| 521 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 522 | mutex_lock(&gdrom_mutex); |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 523 | ret = cdrom_ioctl(gd.cd_info, bdev, mode, cmd, arg); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 524 | mutex_unlock(&gdrom_mutex); |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 525 | |
| 526 | return ret; |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 527 | } |
| 528 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 529 | static const struct block_device_operations gdrom_bdops = { |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 530 | .owner = THIS_MODULE, |
Al Viro | 8389feb | 2008-03-02 10:25:18 -0500 | [diff] [blame] | 531 | .open = gdrom_bdops_open, |
| 532 | .release = gdrom_bdops_release, |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 533 | .media_changed = gdrom_bdops_mediachanged, |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 534 | .ioctl = gdrom_bdops_ioctl, |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 535 | }; |
| 536 | |
| 537 | static irqreturn_t gdrom_command_interrupt(int irq, void *dev_id) |
| 538 | { |
| 539 | gd.status = ctrl_inb(GDROM_STATUSCOMMAND_REG); |
| 540 | if (gd.pending != 1) |
| 541 | return IRQ_HANDLED; |
| 542 | gd.pending = 0; |
| 543 | wake_up_interruptible(&command_queue); |
| 544 | return IRQ_HANDLED; |
| 545 | } |
| 546 | |
| 547 | static irqreturn_t gdrom_dma_interrupt(int irq, void *dev_id) |
| 548 | { |
| 549 | gd.status = ctrl_inb(GDROM_STATUSCOMMAND_REG); |
| 550 | if (gd.transfer != 1) |
| 551 | return IRQ_HANDLED; |
| 552 | gd.transfer = 0; |
| 553 | wake_up_interruptible(&request_queue); |
| 554 | return IRQ_HANDLED; |
| 555 | } |
| 556 | |
| 557 | static int __devinit gdrom_set_interrupt_handlers(void) |
| 558 | { |
| 559 | int err; |
| 560 | |
| 561 | err = request_irq(HW_EVENT_GDROM_CMD, gdrom_command_interrupt, |
| 562 | IRQF_DISABLED, "gdrom_command", &gd); |
| 563 | if (err) |
| 564 | return err; |
| 565 | err = request_irq(HW_EVENT_GDROM_DMA, gdrom_dma_interrupt, |
| 566 | IRQF_DISABLED, "gdrom_dma", &gd); |
| 567 | if (err) |
| 568 | free_irq(HW_EVENT_GDROM_CMD, &gd); |
| 569 | return err; |
| 570 | } |
| 571 | |
| 572 | /* Implement DMA read using SPI command |
| 573 | * 0 -> 0x30 |
| 574 | * 1 -> mode |
| 575 | * 2 -> block >> 16 |
| 576 | * 3 -> block >> 8 |
| 577 | * 4 -> block |
| 578 | * 8 -> sectors >> 16 |
| 579 | * 9 -> sectors >> 8 |
| 580 | * 10 -> sectors |
| 581 | */ |
| 582 | static void gdrom_readdisk_dma(struct work_struct *work) |
| 583 | { |
| 584 | int err, block, block_cnt; |
| 585 | struct packet_command *read_command; |
| 586 | struct list_head *elem, *next; |
| 587 | struct request *req; |
| 588 | unsigned long timeout; |
| 589 | |
| 590 | if (list_empty(&gdrom_deferred)) |
| 591 | return; |
| 592 | read_command = kzalloc(sizeof(struct packet_command), GFP_KERNEL); |
| 593 | if (!read_command) |
| 594 | return; /* get more memory later? */ |
| 595 | read_command->cmd[0] = 0x30; |
| 596 | read_command->cmd[1] = 0x20; |
| 597 | spin_lock(&gdrom_lock); |
| 598 | list_for_each_safe(elem, next, &gdrom_deferred) { |
| 599 | req = list_entry(elem, struct request, queuelist); |
| 600 | spin_unlock(&gdrom_lock); |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 601 | block = blk_rq_pos(req)/GD_TO_BLK + GD_SESSION_OFFSET; |
| 602 | block_cnt = blk_rq_sectors(req)/GD_TO_BLK; |
Paul Mundt | 54d5102 | 2009-10-13 12:30:40 +0900 | [diff] [blame] | 603 | ctrl_outl(virt_to_phys(req->buffer), GDROM_DMA_STARTADDR_REG); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 604 | ctrl_outl(block_cnt * GDROM_HARD_SECTOR, GDROM_DMA_LENGTH_REG); |
| 605 | ctrl_outl(1, GDROM_DMA_DIRECTION_REG); |
| 606 | ctrl_outl(1, GDROM_DMA_ENABLE_REG); |
| 607 | read_command->cmd[2] = (block >> 16) & 0xFF; |
| 608 | read_command->cmd[3] = (block >> 8) & 0xFF; |
| 609 | read_command->cmd[4] = block & 0xFF; |
| 610 | read_command->cmd[8] = (block_cnt >> 16) & 0xFF; |
| 611 | read_command->cmd[9] = (block_cnt >> 8) & 0xFF; |
| 612 | read_command->cmd[10] = block_cnt & 0xFF; |
| 613 | /* set for DMA */ |
| 614 | ctrl_outb(1, GDROM_ERROR_REG); |
| 615 | /* other registers */ |
| 616 | ctrl_outb(0, GDROM_SECNUM_REG); |
| 617 | ctrl_outb(0, GDROM_BCL_REG); |
| 618 | ctrl_outb(0, GDROM_BCH_REG); |
| 619 | ctrl_outb(0, GDROM_DSEL_REG); |
| 620 | ctrl_outb(0, GDROM_INTSEC_REG); |
| 621 | /* Wait for registers to reset after any previous activity */ |
| 622 | timeout = jiffies + HZ / 2; |
| 623 | while (gdrom_is_busy() && time_before(jiffies, timeout)) |
| 624 | cpu_relax(); |
| 625 | ctrl_outb(GDROM_COM_PACKET, GDROM_STATUSCOMMAND_REG); |
| 626 | timeout = jiffies + HZ / 2; |
| 627 | /* Wait for packet command to finish */ |
| 628 | while (gdrom_is_busy() && time_before(jiffies, timeout)) |
| 629 | cpu_relax(); |
| 630 | gd.pending = 1; |
| 631 | gd.transfer = 1; |
Paul Mundt | 54d5102 | 2009-10-13 12:30:40 +0900 | [diff] [blame] | 632 | outsw(GDROM_DATA_REG, &read_command->cmd, 6); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 633 | timeout = jiffies + HZ / 2; |
| 634 | /* Wait for any pending DMA to finish */ |
| 635 | while (ctrl_inb(GDROM_DMA_STATUS_REG) && |
| 636 | time_before(jiffies, timeout)) |
| 637 | cpu_relax(); |
| 638 | /* start transfer */ |
| 639 | ctrl_outb(1, GDROM_DMA_STATUS_REG); |
| 640 | wait_event_interruptible_timeout(request_queue, |
| 641 | gd.transfer == 0, GDROM_DEFAULT_TIMEOUT); |
Kiyoshi Ueda | 7afb3a6 | 2008-10-01 10:13:02 -0400 | [diff] [blame] | 642 | err = gd.transfer ? -EIO : 0; |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 643 | gd.transfer = 0; |
| 644 | gd.pending = 0; |
| 645 | /* now seek to take the request spinlock |
| 646 | * before handling ending the request */ |
| 647 | spin_lock(&gdrom_lock); |
| 648 | list_del_init(&req->queuelist); |
Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 649 | __blk_end_request_all(req, err); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 650 | } |
| 651 | spin_unlock(&gdrom_lock); |
| 652 | kfree(read_command); |
| 653 | } |
| 654 | |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 655 | static void gdrom_request(struct request_queue *rq) |
| 656 | { |
| 657 | struct request *req; |
| 658 | |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 659 | while ((req = blk_fetch_request(rq)) != NULL) { |
Christoph Hellwig | 33659eb | 2010-08-07 18:17:56 +0200 | [diff] [blame] | 660 | if (req->cmd_type != REQ_TYPE_FS) { |
Joe Perches | e597cd0 | 2010-07-01 08:24:32 +0200 | [diff] [blame] | 661 | printk(KERN_DEBUG "gdrom: Non-fs request ignored\n"); |
Tejun Heo | 2343046 | 2009-05-08 11:54:14 +0900 | [diff] [blame] | 662 | __blk_end_request_all(req, -EIO); |
| 663 | continue; |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 664 | } |
| 665 | if (rq_data_dir(req) != READ) { |
Joe Perches | e597cd0 | 2010-07-01 08:24:32 +0200 | [diff] [blame] | 666 | pr_notice("Read only device - write request ignored\n"); |
Tejun Heo | 2343046 | 2009-05-08 11:54:14 +0900 | [diff] [blame] | 667 | __blk_end_request_all(req, -EIO); |
| 668 | continue; |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 669 | } |
Tejun Heo | 2343046 | 2009-05-08 11:54:14 +0900 | [diff] [blame] | 670 | |
| 671 | /* |
| 672 | * Add to list of deferred work and then schedule |
| 673 | * workqueue. |
| 674 | */ |
| 675 | list_add_tail(&req->queuelist, &gdrom_deferred); |
| 676 | schedule_work(&work); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | |
| 680 | /* Print string identifying GD ROM device */ |
| 681 | static int __devinit gdrom_outputversion(void) |
| 682 | { |
| 683 | struct gdrom_id *id; |
| 684 | char *model_name, *manuf_name, *firmw_ver; |
| 685 | int err = -ENOMEM; |
| 686 | |
| 687 | /* query device ID */ |
| 688 | id = kzalloc(sizeof(struct gdrom_id), GFP_KERNEL); |
| 689 | if (!id) |
| 690 | return err; |
| 691 | gdrom_identifydevice(id); |
| 692 | model_name = kstrndup(id->modname, 16, GFP_KERNEL); |
| 693 | if (!model_name) |
| 694 | goto free_id; |
| 695 | manuf_name = kstrndup(id->mname, 16, GFP_KERNEL); |
| 696 | if (!manuf_name) |
| 697 | goto free_model_name; |
| 698 | firmw_ver = kstrndup(id->firmver, 16, GFP_KERNEL); |
| 699 | if (!firmw_ver) |
| 700 | goto free_manuf_name; |
Joe Perches | e597cd0 | 2010-07-01 08:24:32 +0200 | [diff] [blame] | 701 | pr_info("%s from %s with firmware %s\n", |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 702 | model_name, manuf_name, firmw_ver); |
| 703 | err = 0; |
| 704 | kfree(firmw_ver); |
| 705 | free_manuf_name: |
| 706 | kfree(manuf_name); |
| 707 | free_model_name: |
| 708 | kfree(model_name); |
| 709 | free_id: |
| 710 | kfree(id); |
| 711 | return err; |
| 712 | } |
| 713 | |
| 714 | /* set the default mode for DMA transfer */ |
| 715 | static int __devinit gdrom_init_dma_mode(void) |
| 716 | { |
| 717 | ctrl_outb(0x13, GDROM_ERROR_REG); |
| 718 | ctrl_outb(0x22, GDROM_INTSEC_REG); |
| 719 | if (!gdrom_wait_clrbusy()) |
| 720 | return -EBUSY; |
| 721 | ctrl_outb(0xEF, GDROM_STATUSCOMMAND_REG); |
| 722 | if (!gdrom_wait_busy_sleeps()) |
| 723 | return -EBUSY; |
| 724 | /* Memory protection setting for GDROM DMA |
| 725 | * Bits 31 - 16 security: 0x8843 |
| 726 | * Bits 15 and 7 reserved (0) |
| 727 | * Bits 14 - 8 start of transfer range in 1 MB blocks OR'ed with 0x80 |
| 728 | * Bits 6 - 0 end of transfer range in 1 MB blocks OR'ed with 0x80 |
| 729 | * (0x40 | 0x80) = start range at 0x0C000000 |
| 730 | * (0x7F | 0x80) = end range at 0x0FFFFFFF */ |
| 731 | ctrl_outl(0x8843407F, GDROM_DMA_ACCESS_CTRL_REG); |
| 732 | ctrl_outl(9, GDROM_DMA_WAIT_REG); /* DMA word setting */ |
| 733 | return 0; |
| 734 | } |
| 735 | |
| 736 | static void __devinit probe_gdrom_setupcd(void) |
| 737 | { |
| 738 | gd.cd_info->ops = &gdrom_ops; |
| 739 | gd.cd_info->capacity = 1; |
| 740 | strcpy(gd.cd_info->name, GDROM_DEV_NAME); |
| 741 | gd.cd_info->mask = CDC_CLOSE_TRAY|CDC_OPEN_TRAY|CDC_LOCK| |
| 742 | CDC_SELECT_DISC; |
| 743 | } |
| 744 | |
| 745 | static void __devinit probe_gdrom_setupdisk(void) |
| 746 | { |
| 747 | gd.disk->major = gdrom_major; |
| 748 | gd.disk->first_minor = 1; |
| 749 | gd.disk->minors = 1; |
| 750 | strcpy(gd.disk->disk_name, GDROM_DEV_NAME); |
| 751 | } |
| 752 | |
| 753 | static int __devinit probe_gdrom_setupqueue(void) |
| 754 | { |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 755 | blk_queue_logical_block_size(gd.gdrom_rq, GDROM_HARD_SECTOR); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 756 | /* using DMA so memory will need to be contiguous */ |
Martin K. Petersen | 8a78362 | 2010-02-26 00:20:39 -0500 | [diff] [blame] | 757 | blk_queue_max_segments(gd.gdrom_rq, 1); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 758 | /* set a large max size to get most from DMA */ |
| 759 | blk_queue_max_segment_size(gd.gdrom_rq, 0x40000); |
| 760 | gd.disk->queue = gd.gdrom_rq; |
| 761 | return gdrom_init_dma_mode(); |
| 762 | } |
| 763 | |
| 764 | /* |
| 765 | * register this as a block device and as compliant with the |
| 766 | * universal CD Rom driver interface |
| 767 | */ |
| 768 | static int __devinit probe_gdrom(struct platform_device *devptr) |
| 769 | { |
| 770 | int err; |
| 771 | /* Start the device */ |
| 772 | if (gdrom_execute_diagnostic() != 1) { |
Joe Perches | e597cd0 | 2010-07-01 08:24:32 +0200 | [diff] [blame] | 773 | pr_warning("ATA Probe for GDROM failed\n"); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 774 | return -ENODEV; |
| 775 | } |
| 776 | /* Print out firmware ID */ |
| 777 | if (gdrom_outputversion()) |
| 778 | return -ENOMEM; |
| 779 | /* Register GDROM */ |
| 780 | gdrom_major = register_blkdev(0, GDROM_DEV_NAME); |
| 781 | if (gdrom_major <= 0) |
| 782 | return gdrom_major; |
Joe Perches | e597cd0 | 2010-07-01 08:24:32 +0200 | [diff] [blame] | 783 | pr_info("Registered with major number %d\n", |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 784 | gdrom_major); |
| 785 | /* Specify basic properties of drive */ |
| 786 | gd.cd_info = kzalloc(sizeof(struct cdrom_device_info), GFP_KERNEL); |
| 787 | if (!gd.cd_info) { |
| 788 | err = -ENOMEM; |
| 789 | goto probe_fail_no_mem; |
| 790 | } |
| 791 | probe_gdrom_setupcd(); |
| 792 | gd.disk = alloc_disk(1); |
| 793 | if (!gd.disk) { |
| 794 | err = -ENODEV; |
| 795 | goto probe_fail_no_disk; |
| 796 | } |
| 797 | probe_gdrom_setupdisk(); |
| 798 | if (register_cdrom(gd.cd_info)) { |
| 799 | err = -ENODEV; |
| 800 | goto probe_fail_cdrom_register; |
| 801 | } |
| 802 | gd.disk->fops = &gdrom_bdops; |
| 803 | /* latch on to the interrupt */ |
| 804 | err = gdrom_set_interrupt_handlers(); |
| 805 | if (err) |
| 806 | goto probe_fail_cmdirq_register; |
| 807 | gd.gdrom_rq = blk_init_queue(gdrom_request, &gdrom_lock); |
| 808 | if (!gd.gdrom_rq) |
| 809 | goto probe_fail_requestq; |
| 810 | |
| 811 | err = probe_gdrom_setupqueue(); |
| 812 | if (err) |
| 813 | goto probe_fail_toc; |
| 814 | |
| 815 | gd.toc = kzalloc(sizeof(struct gdromtoc), GFP_KERNEL); |
| 816 | if (!gd.toc) |
| 817 | goto probe_fail_toc; |
| 818 | add_disk(gd.disk); |
| 819 | return 0; |
| 820 | |
| 821 | probe_fail_toc: |
| 822 | blk_cleanup_queue(gd.gdrom_rq); |
| 823 | probe_fail_requestq: |
| 824 | free_irq(HW_EVENT_GDROM_DMA, &gd); |
| 825 | free_irq(HW_EVENT_GDROM_CMD, &gd); |
| 826 | probe_fail_cmdirq_register: |
| 827 | probe_fail_cdrom_register: |
| 828 | del_gendisk(gd.disk); |
| 829 | probe_fail_no_disk: |
| 830 | kfree(gd.cd_info); |
| 831 | unregister_blkdev(gdrom_major, GDROM_DEV_NAME); |
| 832 | gdrom_major = 0; |
| 833 | probe_fail_no_mem: |
Joe Perches | e597cd0 | 2010-07-01 08:24:32 +0200 | [diff] [blame] | 834 | pr_warning("Probe failed - error is 0x%X\n", err); |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 835 | return err; |
| 836 | } |
| 837 | |
| 838 | static int __devexit remove_gdrom(struct platform_device *devptr) |
| 839 | { |
| 840 | flush_scheduled_work(); |
| 841 | blk_cleanup_queue(gd.gdrom_rq); |
| 842 | free_irq(HW_EVENT_GDROM_CMD, &gd); |
| 843 | free_irq(HW_EVENT_GDROM_DMA, &gd); |
| 844 | del_gendisk(gd.disk); |
| 845 | if (gdrom_major) |
| 846 | unregister_blkdev(gdrom_major, GDROM_DEV_NAME); |
Akinobu Mita | 0a0c411 | 2008-03-26 12:09:02 +0100 | [diff] [blame] | 847 | unregister_cdrom(gd.cd_info); |
| 848 | |
| 849 | return 0; |
Adrian McMenamin | 74ee1a7 | 2008-01-21 18:52:48 +0900 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | static struct platform_driver gdrom_driver = { |
| 853 | .probe = probe_gdrom, |
| 854 | .remove = __devexit_p(remove_gdrom), |
| 855 | .driver = { |
| 856 | .name = GDROM_DEV_NAME, |
| 857 | }, |
| 858 | }; |
| 859 | |
| 860 | static int __init init_gdrom(void) |
| 861 | { |
| 862 | int rc; |
| 863 | gd.toc = NULL; |
| 864 | rc = platform_driver_register(&gdrom_driver); |
| 865 | if (rc) |
| 866 | return rc; |
| 867 | pd = platform_device_register_simple(GDROM_DEV_NAME, -1, NULL, 0); |
| 868 | if (IS_ERR(pd)) { |
| 869 | platform_driver_unregister(&gdrom_driver); |
| 870 | return PTR_ERR(pd); |
| 871 | } |
| 872 | return 0; |
| 873 | } |
| 874 | |
| 875 | static void __exit exit_gdrom(void) |
| 876 | { |
| 877 | platform_device_unregister(pd); |
| 878 | platform_driver_unregister(&gdrom_driver); |
| 879 | kfree(gd.toc); |
| 880 | } |
| 881 | |
| 882 | module_init(init_gdrom); |
| 883 | module_exit(exit_gdrom); |
| 884 | MODULE_AUTHOR("Adrian McMenamin <adrian@mcmen.demon.co.uk>"); |
| 885 | MODULE_DESCRIPTION("SEGA Dreamcast GD-ROM Driver"); |
| 886 | MODULE_LICENSE("GPL"); |