From: Albert H. <he...@us...> - 2009-02-01 18:29:49
|
Update of /cvsroot/gc-linux/linux/drivers/block In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17186/drivers/block Modified Files: Kconfig Makefile gcn-aram.c gcn-sd.c rvl-mem2.c rvl-stsd.c Log Message: Merge 2.6.28. Also: - run checkpatch against the non-broken source code - add GPIO driver fixes - implement getgeo for the special block drivers - small fixes Index: gcn-aram.c =================================================================== RCS file: /cvsroot/gc-linux/linux/drivers/block/gcn-aram.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- gcn-aram.c 13 Sep 2008 19:42:53 -0000 1.18 +++ gcn-aram.c 1 Feb 2009 18:29:35 -0000 1.19 @@ -2,9 +2,9 @@ * drivers/block/gcn-aram.c * * Nintendo GameCube Auxiliary RAM (ARAM) block driver - * Copyright (C) 2004-2008 The GameCube Linux Team + * Copyright (C) 2004-2009 The GameCube Linux Team * Copyright (C) 2005 Todd Jeffreys <to...@vo...> - * Copyright (C) 2005,2007,2008 Albert Herranz + * Copyright (C) 2005,2007,2008,2009 Albert Herranz * * Based on previous work by Franz Lehner. * @@ -23,7 +23,7 @@ #include <linux/major.h> #include <linux/module.h> #include <linux/of_platform.h> -#include <asm/io.h> +#include <linux/io.h> #define DRV_MODULE_NAME "gcn-aram" @@ -110,20 +110,18 @@ static inline enum dma_data_direction rq_dir_to_dma_dir(struct request *req) { - if (rq_data_dir(req) == READ) { + if (rq_data_dir(req) == READ) return DMA_FROM_DEVICE; - } else { + else return DMA_TO_DEVICE; - } } static inline int rq_dir_to_aram_dir(struct request *req) { - if (rq_data_dir(req) == READ) { + if (rq_data_dir(req) == READ) return AR_READ; - } else { + else return AR_WRITE; - } } static void aram_start_dma_transfer(struct aram_drvdata *drvdata, @@ -175,7 +173,7 @@ drvdata->req = NULL; spin_unlock_irqrestore(&drvdata->io_lock, flags); - + if (req) { __blk_end_request(req, 0, req->current_nr_sectors << 9); dma_unmap_single(drvdata->dev, @@ -200,7 +198,7 @@ unsigned long flags; req = elv_next_request(q); - while(req) { + while (req) { spin_lock_irqsave(&drvdata->io_lock, flags); /* we schedule a single request each time */ @@ -257,28 +255,28 @@ * */ -static int aram_open(struct inode *inode, struct file *filp) +static int aram_open(struct block_device *bdev, fmode_t mode) { - struct aram_drvdata *drvdata = inode->i_bdev->bd_disk->private_data; + struct aram_drvdata *drvdata = bdev->bd_disk->private_data; unsigned long flags; int retval = 0; spin_lock_irqsave(&drvdata->lock, flags); /* only allow a minor of 0 to be opened */ - if (iminor(inode)) { + if (MINOR(bdev->bd_dev)) { retval = -ENODEV; goto out; } /* honor exclusive open mode */ if (drvdata->ref_count == -1 || - (drvdata->ref_count && (filp->f_flags & O_EXCL))) { + (drvdata->ref_count && (mode & FMODE_EXCL))) { retval = -EBUSY; goto out; } - if ((filp->f_flags & O_EXCL)) + if ((mode & FMODE_EXCL)) drvdata->ref_count = -1; else drvdata->ref_count++; @@ -288,9 +286,9 @@ return retval; } -static int aram_release(struct inode *inode, struct file *filp) +static int aram_release(struct gendisk *disk, fmode_t mode) { - struct aram_drvdata *drvdata = inode->i_bdev->bd_disk->private_data; + struct aram_drvdata *drvdata = disk->private_data; unsigned long flags; spin_lock_irqsave(&drvdata->lock, flags); @@ -299,46 +297,23 @@ else drvdata->ref_count = 0; spin_unlock_irqrestore(&drvdata->lock, flags); - + return 0; } -static int aram_ioctl(struct inode *inode, struct file *file, - unsigned int cmd, unsigned long arg) +static int aram_getgeo(struct block_device *bdev, struct hd_geometry *geo) { - struct hd_geometry geo; - - switch (cmd) { - case BLKRAGET: - case BLKFRAGET: - case BLKROGET: - case BLKBSZGET: - case BLKSSZGET: - case BLKSECTGET: - case BLKGETSIZE: - case BLKGETSIZE64: - case BLKFLSBUF: - return ioctl_by_bdev(inode->i_bdev,cmd,arg); - case HDIO_GETGEO: - /* fake the entries */ - geo.heads = 16; - geo.sectors = 32; - geo.start = 0; - geo.cylinders = ARAM_BUFFERSIZE / (geo.heads * geo.sectors); - if (copy_to_user((void __user*)arg,&geo,sizeof(geo))) - return -EFAULT; - return 0; - default: - return -ENOTTY; - } + geo->cylinders = get_capacity(bdev->bd_disk) / (4 * 16); + geo->heads = 4; + geo->sectors = 16; + return 0; } - static struct block_device_operations aram_fops = { .owner = THIS_MODULE, .open = aram_open, .release = aram_release, - .ioctl = aram_ioctl, + .getgeo = aram_getgeo, }; @@ -358,7 +333,7 @@ retval = register_blkdev(ARAM_MAJOR, ARAM_NAME); if (retval) goto err_register_blkdev; - + retval = -ENOMEM; spin_lock_init(&drvdata->lock); spin_lock_init(&drvdata->io_lock); @@ -427,7 +402,7 @@ spin_unlock_irqrestore(&drvdata->io_lock, flags); /* wait until pending transfers are finished */ - while(in_be16(csr_reg) & DSP_CSR_DSPDMA) + while (in_be16(csr_reg) & DSP_CSR_DSPDMA) cpu_relax(); } @@ -474,15 +449,14 @@ { int retval; - drvdata->io_base = ioremap(mem->start, mem->end - mem->start + 1); + drvdata->io_base = ioremap(mem->start, mem->end - mem->start + 1); drvdata->irq = irq; retval = aram_init_blk_dev(drvdata); if (!retval) { retval = aram_init_irq(drvdata); - if (retval) { + if (retval) aram_exit_blk_dev(drvdata); - } } return retval; } @@ -558,11 +532,11 @@ struct resource res; int retval; - retval = of_address_to_resource(odev->node, 0, &res); - if (retval) { + retval = of_address_to_resource(odev->node, 0, &res); + if (retval) { drv_printk(KERN_ERR, "no io memory range found\n"); - return -ENODEV; - } + return -ENODEV; + } return aram_do_probe(&odev->dev, &res, irq_of_parse_and_map(odev->node, 0)); @@ -583,7 +557,7 @@ { .compatible = "nintendo,flipper-auxram" }, { }, }; - + MODULE_DEVICE_TABLE(of, aram_of_match); Index: gcn-sd.c =================================================================== RCS file: /cvsroot/gc-linux/linux/drivers/block/gcn-sd.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- gcn-sd.c 4 Apr 2008 19:17:53 -0000 1.15 +++ gcn-sd.c 1 Feb 2009 18:29:35 -0000 1.16 @@ -2,10 +2,10 @@ * drivers/block/gcn-sd.c * * MMC/SD card block driver for the Nintendo GameCube/Wii - * Copyright (C) 2004-2008 The GameCube Linux Team + * Copyright (C) 2004-2009 The GameCube Linux Team * Copyright (C) 2004,2005 Rob Reylink * Copyright (C) 2005 Todd Jeffreys - * Copyright (C) 2005,2006,2007,2008 Albert Herranz + * Copyright (C) 2005,2006,2007,2008,2009 Albert Herranz * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -74,9 +74,9 @@ #define DRV_MODULE_NAME "gcn-sd" #define DRV_DESCRIPTION "MMC/SD card block driver for the Nintendo GameCube/Wii" -#define DRV_AUTHOR "Rob Reylink, " \ +#define DRV_AUTHOR "Rob Reylink, " \ "Todd Jeffreys, " \ - "Albert Herranz" + "Albert Herranz" static char sd_driver_version[] = "4.1i"; @@ -85,7 +85,7 @@ #ifdef SD_DEBUG # define DBG(fmt, args...) \ - printk(KERN_ERR "%s: " fmt, __FUNCTION__ , ## args) + printk(KERN_ERR "%s: " fmt, __func__ , ## args) #else # define DBG(fmt, args...) #endif @@ -272,7 +272,7 @@ return crc; } -#define UNSTUFF_BITS(resp,start,size) \ +#define UNSTUFF_BITS(resp, start, size) \ ({ \ const int __size = size; \ const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \ @@ -427,7 +427,7 @@ /* */ static inline unsigned int ms_to_cycles(unsigned int ms, unsigned int clock) { - return (ms * (clock / 1000)); + return ms * (clock / 1000); } /* */ @@ -577,17 +577,19 @@ /* * */ -static int sd_write_data(struct sd_host *host, void *data, size_t len, int token) +static int sd_write_data(struct sd_host *host, void *data, size_t len, + int token) { u16 crc; - u8 t; + u8 t, *d; + size_t l; int retval = 0; /* FIXME, rewrite this a bit */ { crc = 0; - u8 *d = data; - int l = len; + d = data; + l = len; while (l-- > 0) crc = crc_xmodem_update(crc, *d++); @@ -714,6 +716,8 @@ { struct sd_command *cmd = &host->cmd; u16 crc, calc_crc = 0xffff; + u8 *d; + size_t l; int retval; /* build raw command */ @@ -741,8 +745,8 @@ /* FIXME, rewrite this a bit */ { calc_crc = 0; - u8 *d = data; - int l = len; + d = data; + l = len; while (l-- > 0) calc_crc = crc_xmodem_update(calc_crc, *d++); @@ -797,9 +801,8 @@ /* burn extra cycles and deselect card */ sd_end_command(host); - if (retval < 0) { + if (retval < 0) DBG("write, offset=%d, len=%d\n", arg, len); - } return retval; } @@ -885,8 +888,8 @@ * */ static inline int sd_write_single_block(struct sd_host *host, - unsigned long start, - void *data, size_t len) + unsigned long start, + void *data, size_t len) { int retval; @@ -1006,7 +1009,7 @@ } /* - * + * */ static int sd_welcome_card(struct sd_host *host) { @@ -1052,7 +1055,7 @@ host->card.cid.prod_name, (unsigned long)((host->card.csd.capacity * (1 << host->card.csd.read_blkbits)) / 1024), - 1 << host->card.csd.read_blkbits, + 1 << host->card.csd.read_blkbits, host->card.cid.serial); retval = 0; @@ -1152,7 +1155,7 @@ /* * Verifies if a request should be dispatched or not. - * + * * Returns: * <0 in case of error. * 0 if request passes the checks @@ -1195,7 +1198,7 @@ if (retval) return 0; - switch(rq_data_dir(req)) { + switch (rq_data_dir(req)) { case WRITE: retval = sd_write_request(host, req); break; @@ -1212,11 +1215,11 @@ */ static int sd_io_thread(void *param) { - struct sd_host *host = param; + struct sd_host *host = param; struct request *req; - int uptodate; unsigned long flags; - int retval; + int nr_sectors; + int error; #if 0 /* @@ -1224,13 +1227,13 @@ * above. At least, be nice with other processes trying to use the * cpu. */ - set_user_nice(current, 0); + set_user_nice(current, 0); #endif - current->flags |= PF_NOFREEZE|PF_MEMALLOC; + current->flags |= PF_NOFREEZE|PF_MEMALLOC; mutex_lock(&host->io_mutex); - for(;;) { + for (;;) { req = NULL; set_current_state(TASK_INTERRUPTIBLE); @@ -1250,11 +1253,11 @@ continue; } set_current_state(TASK_INTERRUPTIBLE); - retval = sd_do_request(host, req); + nr_sectors = sd_do_request(host, req); + error = (nr_sectors < 0) ? nr_sectors : 0; - uptodate = (retval > 0)?1:0; spin_lock_irqsave(&host->queue_lock, flags); - end_queued_request(req, uptodate); + __blk_end_request(req, error, nr_sectors << 9); spin_unlock_irqrestore(&host->queue_lock, flags); } mutex_unlock(&host->io_mutex); @@ -1282,9 +1285,9 @@ /* * Opens the drive device. */ -static int sd_open(struct inode *inode, struct file *filp) +static int sd_open(struct block_device *bdev, fmode_t mode) { - struct sd_host *host = inode->i_bdev->bd_disk->private_data; + struct sd_host *host = bdev->bd_disk->private_data; int retval = 0; if (!host || !host->exi_device) @@ -1292,13 +1295,13 @@ /* honor exclusive open mode */ if (host->refcnt == -1 || - (host->refcnt && (filp->f_flags & O_EXCL))) { + (host->refcnt && (mode & FMODE_EXCL))) { retval = -EBUSY; goto out; } /* this takes care of revalidating the media if needed */ - check_disk_change(inode->i_bdev); + check_disk_change(bdev); if (!host->card.csd.capacity) { retval = -ENOMEDIUM; goto out; @@ -1306,7 +1309,7 @@ down(&open_lock); - if ((filp->f_flags & O_EXCL)) + if ((mode & FMODE_EXCL)) host->refcnt = -1; else host->refcnt++; @@ -1321,9 +1324,9 @@ /* * Releases the drive device. */ -static int sd_release(struct inode *inode, struct file *filp) +static int sd_release(struct gendisk *disk, fmode_t mode) { - struct sd_host *host = inode->i_bdev->bd_disk->private_data; + struct sd_host *host = disk->private_data; if (!host) return -ENXIO; @@ -1332,15 +1335,14 @@ if (host->refcnt > 0) host->refcnt--; - else { + else host->refcnt = 0; - } up(&open_lock); - /* lazy removal of unreferenced zombies */ - if (!host->refcnt && !host->exi_device) - kfree(host); + /* lazy removal of unreferenced zombies */ + if (!host->refcnt && !host->exi_device) + kfree(host); return 0; } @@ -1365,11 +1367,10 @@ /* check if the serial number of the card changed */ last_serial = host->card.cid.serial; retval = sd_read_cid(host); - if (!retval && last_serial == host->card.cid.serial && last_serial) { + if (!retval && last_serial == host->card.cid.serial && last_serial) clear_bit(__SD_MEDIA_CHANGED, &host->flags); - } else { + else set_bit(__SD_MEDIA_CHANGED, &host->flags); - } return (host->flags & SD_MEDIA_CHANGED) ? 1 : 0; } @@ -1410,51 +1411,22 @@ return retval; } -/* - * Ioctl. - */ -static int sd_ioctl(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +static int sd_getgeo(struct block_device *bdev, struct hd_geometry *geo) { - struct block_device *bdev = inode->i_bdev; - struct hd_geometry geo; - - switch (cmd) { -#if 0 - case BLKRAGET: - case BLKFRAGET: - case BLKROGET: - case BLKBSZGET: - case BLKSSZGET: - case BLKSECTGET: - case BLKGETSIZE: - case BLKGETSIZE64: - case BLKFLSBUF: - return ioctl_by_bdev(bdev, cmd, arg); -#endif - case HDIO_GETGEO: - /* fake the entries */ - geo.cylinders = get_capacity(bdev->bd_disk) / (4 * 16); - geo.heads = 4; - geo.sectors = 16; - geo.start = get_start_sect(bdev); - - if (copy_to_user((void __user *)arg, &geo, sizeof(geo))) - return -EFAULT; - return 0; - default: - return -ENOTTY; - } - return -EINVAL; + geo->cylinders = get_capacity(bdev->bd_disk) / (4 * 16); + geo->heads = 4; + geo->sectors = 16; + return 0; } + static struct block_device_operations sd_fops = { .owner = THIS_MODULE, .open = sd_open, .release = sd_release, .revalidate_disk = sd_revalidate_disk, .media_changed = sd_media_changed, - .ioctl = sd_ioctl, + .getgeo = sd_getgeo, }; /* @@ -1576,7 +1548,7 @@ } retval = sd_init_io_thread(host); - if (retval) + if (retval) goto err_blk_dev; add_disk(host->disk); Index: Kconfig =================================================================== RCS file: /cvsroot/gc-linux/linux/drivers/block/Kconfig,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- Kconfig 15 Nov 2008 20:10:14 -0000 1.34 +++ Kconfig 1 Feb 2009 18:29:35 -0000 1.35 @@ -21,7 +21,8 @@ ---help--- If you want to use the floppy disk drive(s) of your PC under Linux, say Y. Information about this driver, especially important for IBM - Thinkpad users, is contained in <file:Documentation/floppy.txt>. + Thinkpad users, is contained in + <file:Documentation/blockdev/floppy.txt>. That file also contains the location of the Floppy driver FAQ as well as location of the fdutils package used to configure additional parameters of the driver at run time. @@ -55,15 +56,42 @@ To compile this driver as a module, choose M here: the module will be called z2ram. +config GAMECUBE_SD + tristate "Nintendo GameCube/Wii MMC/SD card" + depends on GAMECUBE_EXI + help + This enables support for using SD and MMC cards through + the Nintendo SD Card Adapter (DOL-019) or compatible hardware. + + You probably want to compile FAT support, and the required + codepages, or mount will complain. See Filesystems -> DOS/FAT/NT + filesystems and Filesystems -> Native Language Support + + Say Y if you want to include this driver in the kernel. + + To compile this driver as a module, choose M here: the + module will be called gcn-sd. + +config GAMECUBE_ARAM + tristate "Nintendo GameCube Auxiliary RAM (ARAM)" + depends on GAMECUBE + help + This enables support for using the 16MB of ARAM found in the + Nintendo GameCube as a block device. + Say Y if you want to include this driver in the kernel. + + To compile this driver as a module, choose M here: the + module will be called gcn-aram. + config GAMECUBE_DI - tristate "Nintendo GameCube Drive Interface (DI)" + tristate "Nintendo GameCube Disk Interface (DI)" depends on GAMECUBE help - This enables support for using DVD-R media on - the Nintendo GameCube DVD drive. + This enables support for using the DVD drive unit found + in the Nintendo GameCube. Say Y if you want to include this driver in the kernel. - - To compile this driver as a module, choose M here: the + + To compile this driver as a module, choose M here: the module will be called gcn-di. config GAMECUBE_DVD @@ -73,21 +101,10 @@ This enables support for using the mini-DVD drive on the Nintendo Gamecube. Say Y if you want to include this driver in the kernel. - + To compile this driver as a module, choose M here: the module will be called gcn-dvd -config GAMECUBE_ARAM - tristate "Nintendo GameCube Auxiliary RAM (ARAM)" - depends on GAMECUBE - help - This enables support for using the 16MB of ARAM found in the - Nintendo GameCube as a ramdisk or as a swap partition. - Say Y if you want to include this driver in the kernel. - - To compile this driver as a module, choose M here: the - module will be called gcn-aram. - config GAMECUBE_MEMCARD tristate "Nintendo GameCube/Wii memory card (EXPERIMENTAL)" depends on GAMECUBE_EXI && EXPERIMENTAL && BROKEN @@ -95,54 +112,36 @@ This enables support for using memory cards compatible with the Nintendo GameCube. Say Y if you want to include this driver in the kernel. - + To compile this driver as a module, choose M here: the module will be called gcn-memcard. -config GAMECUBE_SD - tristate "Nintendo GameCube/Wii MMC/SD card" - depends on GAMECUBE_EXI +config WII_MEM2 + tristate "Nintendo Wii MEM2" + depends on WII help - This enables support for using SD and MMC cards through - the Nintendo SD Card Adapter (DOL-019) or compatible hardware. - - Currently, only read support is enabled. - - You probably want to compile FAT support, and the required - codepages, or mount will complain. See Filesystems -> DOS/FAT/NT - filesystems and Filesystems -> Native Language Support - + This enables support for using the MEM2 found in the + Nintendo Wii as a block device. Say Y if you want to include this driver in the kernel. - + To compile this driver as a module, choose M here: the - module will be called gcn-sd. + module will be called rvl-mem2. -config WII_SD + config WII_SD tristate "Nintendo Wii front slot MMC/SD" depends on WII help - This enables support for MMC/SD cards using the front slot of - the Nintendo Wii. - + This enables support for MMC/SD cards using the front SD card + slot of the Nintendo Wii. + You probably want to compile FAT support, and the required codepages, or mount will complain. See Filesystems -> DOS/FAT/NT filesystems and Filesystems -> Native Language Support Say Y if you want to include this driver in the kernel. - - To compile this driver as a module, choose M here: the - module will be called rvl-stsd. -config WII_MEM2 - tristate "Nintendo Wii MEM2" - depends on WII - help - This enables support for using the MEM2 found in the - Nintendo Wii as a ramdisk or as a swap partition. - Say Y if you want to include this driver in the kernel. - To compile this driver as a module, choose M here: the - module will be called rvl-mem2. + module will be called rvl-stsd. config BLK_DEV_XD tristate "XT hard disk support" @@ -165,7 +164,7 @@ your computer's parallel port. Most of them are actually IDE devices using a parallel port IDE adapter. This option enables the PARIDE subsystem which contains drivers for many of these external drives. - Read <file:Documentation/paride.txt> for more information. + Read <file:Documentation/blockdev/paride.txt> for more information. If you have said Y to the "Parallel-port support" configuration option, you may share a single port between your printer and other @@ -203,9 +202,9 @@ help This is the driver for Compaq Smart Array controllers. Everyone using these boards should say Y here. See the file - <file:Documentation/cpqarray.txt> for the current list of boards - supported by this driver, and for further information on the use of - this driver. + <file:Documentation/blockdev/cpqarray.txt> for the current list of + boards supported by this driver, and for further information on the + use of this driver. config BLK_CPQ_CISS_DA tristate "Compaq Smart Array 5xxx support" @@ -213,7 +212,7 @@ help This is the driver for Compaq Smart Array 5xxx controllers. Everyone using these boards should say Y here. - See <file:Documentation/cciss.txt> for the current list of + See <file:Documentation/blockdev/cciss.txt> for the current list of boards supported by this driver, and for further information on the use of this driver. @@ -224,7 +223,7 @@ help When enabled (Y), this option allows SCSI tape drives and SCSI medium changers (tape robots) to be accessed via a Compaq 5xxx array - controller. (See <file:Documentation/cciss.txt> for more details.) + controller. (See <file:Documentation/blockdev/cciss.txt> for more details.) "SCSI support" and "SCSI tape support" must also be enabled for this option to work. @@ -238,8 +237,8 @@ help This driver adds support for the Mylex DAC960, AcceleRAID, and eXtremeRAID PCI RAID controllers. See the file - <file:Documentation/README.DAC960> for further information about - this driver. + <file:Documentation/blockdev/README.DAC960> for further information + about this driver. To compile this driver as a module, choose M here: the module will be called DAC960. @@ -367,9 +366,9 @@ userland (making server and client physically the same computer, communicating using the loopback network device). - Read <file:Documentation/nbd.txt> for more information, especially - about where to find the server code, which runs in user space and - does not need special kernel support. + Read <file:Documentation/blockdev/nbd.txt> for more information, + especially about where to find the server code, which runs in user + space and does not need special kernel support. Note that this has nothing to do with the network file systems NFS or Coda; you can say N here even if you intend to use NFS or Coda. @@ -410,8 +409,8 @@ store a copy of a minimal root file system off of a floppy into RAM during the initial install of Linux. - Note that the kernel command line option "ramdisk=XX" is now - obsolete. For details, read <file:Documentation/ramdisk.txt>. + Note that the kernel command line option "ramdisk=XX" is now obsolete. + For details, read <file:Documentation/blockdev/ramdisk.txt>. To compile this driver as a module, choose M here: the module will be called rd. Index: rvl-mem2.c =================================================================== RCS file: /cvsroot/gc-linux/linux/drivers/block/rvl-mem2.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- rvl-mem2.c 27 Mar 2008 22:35:35 -0000 1.4 +++ rvl-mem2.c 1 Feb 2009 18:29:35 -0000 1.5 @@ -2,10 +2,10 @@ * drivers/block/rvl-mem2.c * * Nintendo Wii MEM2 block driver - * Copyright (C) 2008 The GameCube Linux Team - * Copyright (C) 2008 Albert Herranz + * Copyright (C) 2008-2009 The GameCube Linux Team + * Copyright (C) 2008,2009 Albert Herranz * - * Based on gcn-mem2.c. + * Based on gcn-aram.c. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -20,7 +20,7 @@ #include <linux/blkdev.h> #include <linux/fcntl.h> /* O_ACCMODE */ #include <linux/hdreg.h> /* HDIO_GETGEO */ -#include <asm/io.h> +#include <linux/io.h> #define DRV_MODULE_NAME "rvl-mem2" @@ -70,10 +70,10 @@ struct request *req; unsigned long mem2_addr; size_t len; - int uptodate; + int error; req = elv_next_request(q); - while(req) { + while (req) { if (blk_fs_request(req)) { /* calculate the MEM2 address and length */ mem2_addr = req->sector << 9; @@ -84,24 +84,25 @@ drv_printk(KERN_ERR, "bad access: block=%lu," " size=%u\n", (unsigned long)req->sector, len); - uptodate = 0; + error = -EIO; } else { - switch(rq_data_dir(req)) { + switch (rq_data_dir(req)) { case READ: memcpy(req->buffer, - drvdata->io_base + mem2_addr, len); + drvdata->io_base + mem2_addr, + len); break; case WRITE: memcpy(drvdata->io_base + mem2_addr, req->buffer, len); break; } - uptodate = 1; + error = 0; } + blk_end_request(req, error, len); } else { - uptodate = 0; + end_request(req, 0); } - end_queued_request(req, uptodate); req = elv_next_request(q); } } @@ -109,28 +110,28 @@ /* * Opens the MEM2 device. */ -static int mem2_open(struct inode *inode, struct file *filp) +static int mem2_open(struct block_device *bdev, fmode_t mode) { - struct mem2_drvdata *drvdata = inode->i_bdev->bd_disk->private_data; + struct mem2_drvdata *drvdata = bdev->bd_disk->private_data; unsigned long flags; int retval = 0; spin_lock_irqsave(&drvdata->lock, flags); /* only allow a minor of 0 to be opened */ - if (iminor(inode)) { + if (MINOR(bdev->bd_dev)) { retval = -ENODEV; goto out; } /* honor exclusive open mode */ if (drvdata->ref_count == -1 || - (drvdata->ref_count && (filp->f_flags & O_EXCL))) { + (drvdata->ref_count && (mode & FMODE_EXCL))) { retval = -EBUSY; goto out; } - if ((filp->f_flags & O_EXCL)) + if ((mode & FMODE_EXCL)) drvdata->ref_count = -1; else drvdata->ref_count++; @@ -143,9 +144,9 @@ /* * Closes the MEM2 device. */ -static int mem2_release(struct inode *inode, struct file *filp) +static int mem2_release(struct gendisk *disk, fmode_t mode) { - struct mem2_drvdata *drvdata = inode->i_bdev->bd_disk->private_data; + struct mem2_drvdata *drvdata = disk->private_data; unsigned long flags; spin_lock_irqsave(&drvdata->lock, flags); @@ -154,42 +155,16 @@ else drvdata->ref_count = 0; spin_unlock_irqrestore(&drvdata->lock, flags); - + return 0; } -/* - * Minimal ioctl for the MEM2 device. - */ -static int mem2_ioctl(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +static int mem2_getgeo(struct block_device *bdev, struct hd_geometry *geo) { - struct mem2_drvdata *drvdata = inode->i_bdev->bd_disk->private_data; - struct hd_geometry geo; - - switch (cmd) { - case BLKRAGET: - case BLKFRAGET: - case BLKROGET: - case BLKBSZGET: - case BLKSSZGET: - case BLKSECTGET: - case BLKGETSIZE: - case BLKGETSIZE64: - case BLKFLSBUF: - return ioctl_by_bdev(inode->i_bdev,cmd,arg); - case HDIO_GETGEO: - /* fake the entries */ - geo.heads = 16; - geo.sectors = 32; - geo.start = 0; - geo.cylinders = drvdata->size / (geo.heads * geo.sectors); - if (copy_to_user((void __user*)arg,&geo,sizeof(geo))) - return -EFAULT; - return 0; - default: - return -ENOTTY; - } + geo->cylinders = get_capacity(bdev->bd_disk) / (4 * 16); + geo->heads = 4; + geo->sectors = 16; + return 0; } @@ -197,7 +172,7 @@ .owner = THIS_MODULE, .open = mem2_open, .release = mem2_release, - .ioctl = mem2_ioctl, + .getgeo = mem2_getgeo, }; @@ -215,7 +190,7 @@ retval = register_blkdev(MEM2_MAJOR, MEM2_NAME); if (retval) goto err_register_blkdev; - + retval = -ENOMEM; spin_lock_init(&drvdata->lock); queue = blk_init_queue(mem2_do_request, &drvdata->lock); @@ -286,9 +261,8 @@ } retval = mem2_init_blk_dev(drvdata); - if (retval) { + if (retval) iounmap(drvdata->io_base); - } return retval; } Index: Makefile =================================================================== RCS file: /cvsroot/gc-linux/linux/drivers/block/Makefile,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- Makefile 15 Nov 2008 20:10:14 -0000 1.21 +++ Makefile 1 Feb 2009 18:29:35 -0000 1.22 @@ -11,11 +11,11 @@ obj-$(CONFIG_PS3_DISK) += ps3disk.o obj-$(CONFIG_ATARI_FLOPPY) += ataflop.o obj-$(CONFIG_AMIGA_Z2RAM) += z2ram.o +obj-$(CONFIG_GAMECUBE_SD) += gcn-sd.o +obj-$(CONFIG_GAMECUBE_ARAM) += gcn-aram.o obj-$(CONFIG_GAMECUBE_DI) += gcn-di/ obj-$(CONFIG_GAMECUBE_DVD) += gcn-dvd/ -obj-$(CONFIG_GAMECUBE_ARAM) += gcn-aram.o obj-$(CONFIG_GAMECUBE_MEMCARD) += gcn-memcard.o -obj-$(CONFIG_GAMECUBE_SD) += gcn-sd.o obj-$(CONFIG_WII_MEM2) += rvl-mem2.o obj-$(CONFIG_WII_SD) += rvl-stsd.o obj-$(CONFIG_BLK_DEV_RAM) += brd.o Index: rvl-stsd.c =================================================================== RCS file: /cvsroot/gc-linux/linux/drivers/block/rvl-stsd.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- rvl-stsd.c 15 Nov 2008 20:10:14 -0000 1.5 +++ rvl-stsd.c 1 Feb 2009 18:29:35 -0000 1.6 @@ -2,8 +2,8 @@ * drivers/block/rvl-stsd.c * * Block driver for the Nintendo Wii SD front slot. - * Copyright (C) 2008 The GameCube Linux Team - * Copyright (C) 2008 Albert Herranz + * Copyright (C) 2008-2009 The GameCube Linux Team + * Copyright (C) 2008,2009 Albert Herranz * * Based on drivers/block/gcn-sd.c * @@ -21,7 +21,7 @@ #define DEBUG -//#define DBG(fmt, arg...) pr_debug(fmt, ##arg) +/*#define DBG(fmt, arg...) pr_debug(fmt, ##arg)*/ #define DBG(fmt, arg...) drv_printk(KERN_ERR, fmt, ##arg) #include <linux/blkdev.h> @@ -51,7 +51,7 @@ #define DRV_DESCRIPTION "Block driver for the Nintendo Wii SD front slot" #define DRV_AUTHOR "Albert Herranz" -static char stsd_driver_version[] = "0.2i"; +static char stsd_driver_version[] = "0.3i"; #define drv_printk(level, format, arg...) \ printk(level DRV_MODULE_NAME ": " format , ## arg) @@ -125,7 +125,9 @@ */ /* we are recycling the stuff already in "../mmc/host/sdhci.h" */ -#define STSD_TIMEOUT_CONTROL_DIV(a) (((a)-13)&0xf) /* TMCLK*2^a a=[13..27] */ + +/* TMCLK*2^a a=[13..27] */ +#define STSD_TIMEOUT_CONTROL_DIV(a) (((a)-13)&0xf) static char stsd_dev_sdio_slot0[] = "/dev/sdio/slot0"; @@ -244,13 +246,13 @@ #define __case_string(_s) \ case _s: \ str = #_s; \ - break; + break; static char *stsd_opcode_string(u32 opcode) { char *str = "unknown"; - switch(opcode) { + switch (opcode) { __case_string(MMC_GO_IDLE_STATE) __case_string(MMC_SEND_OP_COND) __case_string(MMC_ALL_SEND_CID) @@ -285,9 +287,9 @@ __case_string(MMC_FAST_IO) __case_string(MMC_GO_IRQ_STATE) __case_string(MMC_LOCK_UNLOCK) -//__case_string(SD_SEND_RELATIVE_ADDR) -//__case_string(SD_SEND_IF_COND) -//__case_string(SD_SWITCH) +/*__case_string(SD_SEND_RELATIVE_ADDR)*/ +/*__case_string(SD_SEND_IF_COND)*/ +/*__case_string(SD_SWITCH)*/ __case_string(SD_IO_SEND_OP_COND) __case_string(SD_IO_RW_DIRECT) __case_string(SD_IO_RW_EXTENDED) @@ -300,7 +302,7 @@ { char *str = "unknown"; - switch(rsptype) { + switch (rsptype) { __case_string(STSD_RSPTYPE_NONE) __case_string(STSD_RSPTYPE_R1) __case_string(STSD_RSPTYPE_R1B) @@ -319,7 +321,7 @@ { char *str = "unknown"; - switch(cmdtype) { + switch (cmdtype) { __case_string(STSD_CMDTYPE_BC) __case_string(STSD_CMDTYPE_BCR) __case_string(STSD_CMDTYPE_AC) @@ -333,7 +335,7 @@ { char *str = "unknown"; - switch(statusbit) { + switch (statusbit) { __case_string(R1_OUT_OF_RANGE) __case_string(R1_ADDRESS_ERROR) __case_string(R1_BLOCK_LEN_ERROR) @@ -364,34 +366,34 @@ { char *str = "unknown"; - switch(R1_CURRENT_STATE(status)) { - case 0: - str = "IDLE"; - break; - case 1: - str ="READY"; - break; - case 2: - str ="IDENT"; - break; - case 3: - str ="STANDBY"; - break; - case 4: - str ="TRANSFER"; - break; - case 5: - str = "SEND"; - break; - case 6: - str = "RECEIVE"; - break; - case 7: - str = "PROGRAM"; - break; - case 8: - str = "DISCONNECT"; - break; + switch (R1_CURRENT_STATE(status)) { + case 0: + str = "IDLE"; + break; + case 1: + str = "READY"; + break; + case 2: + str = "IDENT"; + break; + case 3: + str = "STANDBY"; + break; + case 4: + str = "TRANSFER"; + break; + case 5: + str = "SEND"; + break; + case 6: + str = "RECEIVE"; + break; + case 7: + str = "PROGRAM"; + break; + case 8: + str = "DISCONNECT"; + break; } return str; @@ -400,7 +402,8 @@ { u32 i, bit; - drv_printk(KERN_INFO, "card state %s\n", stsd_card_state_string(status)); + drv_printk(KERN_INFO, "card state %s\n", + stsd_card_state_string(status)); i = 13; for (i = 13; i <= 31; i++) { @@ -469,40 +472,40 @@ static void stsd_dump_hs_regs(struct stsd_host *host) { - drv_printk(KERN_DEBUG, "============== REGISTER DUMP ==============\n"); + drv_printk(KERN_DEBUG, "============== REGISTER DUMP ==============\n"); - drv_printk(KERN_DEBUG, "Sys addr: 0x%08x | Version: 0x%08x\n", - stsd_hsr_in_u32(host, SDHCI_DMA_ADDRESS), - stsd_hsr_in_u16(host, SDHCI_HOST_VERSION)); - drv_printk(KERN_DEBUG, "Blk size: 0x%08x | Blk cnt: 0x%08x\n", - stsd_hsr_in_u16(host, SDHCI_BLOCK_SIZE), - stsd_hsr_in_u16(host, SDHCI_BLOCK_COUNT)); - drv_printk(KERN_DEBUG, "Argument: 0x%08x | Trn mode: 0x%08x\n", - stsd_hsr_in_u32(host, SDHCI_ARGUMENT), - stsd_hsr_in_u16(host, SDHCI_TRANSFER_MODE)); - drv_printk(KERN_DEBUG, "Present: 0x%08x | Host ctl: 0x%08x\n", - stsd_hsr_in_u32(host, SDHCI_PRESENT_STATE), - stsd_hsr_in_u8(host, SDHCI_HOST_CONTROL)); - drv_printk(KERN_DEBUG, "Power: 0x%08x | Blk gap: 0x%08x\n", - stsd_hsr_in_u8(host, SDHCI_POWER_CONTROL), - stsd_hsr_in_u8(host, SDHCI_BLOCK_GAP_CONTROL)); - drv_printk(KERN_DEBUG, "Wake-up: 0x%08x | Clock: 0x%08x\n", - stsd_hsr_in_u8(host, SDHCI_WAKE_UP_CONTROL), - stsd_hsr_in_u16(host, SDHCI_CLOCK_CONTROL)); - drv_printk(KERN_DEBUG, "Timeout: 0x%08x | Int stat: 0x%08x\n", - stsd_hsr_in_u8(host, SDHCI_TIMEOUT_CONTROL), - stsd_hsr_in_u32(host, SDHCI_INT_STATUS)); - drv_printk(KERN_DEBUG, "Int enab: 0x%08x | Sig enab: 0x%08x\n", - stsd_hsr_in_u32(host, SDHCI_INT_ENABLE), - stsd_hsr_in_u32(host, SDHCI_SIGNAL_ENABLE)); - drv_printk(KERN_DEBUG, "AC12 err: 0x%08x | Slot int: 0x%08x\n", - stsd_hsr_in_u16(host, SDHCI_ACMD12_ERR), - stsd_hsr_in_u16(host, SDHCI_SLOT_INT_STATUS)); - drv_printk(KERN_DEBUG, "Caps: 0x%08x | Max curr: 0x%08x\n", - stsd_hsr_in_u32(host, SDHCI_CAPABILITIES), - stsd_hsr_in_u32(host, SDHCI_MAX_CURRENT)); + drv_printk(KERN_DEBUG, "Sys addr: 0x%08x | Version: 0x%08x\n", + stsd_hsr_in_u32(host, SDHCI_DMA_ADDRESS), + stsd_hsr_in_u16(host, SDHCI_HOST_VERSION)); + drv_printk(KERN_DEBUG, "Blk size: 0x%08x | Blk cnt: 0x%08x\n", + stsd_hsr_in_u16(host, SDHCI_BLOCK_SIZE), + stsd_hsr_in_u16(host, SDHCI_BLOCK_COUNT)); + drv_printk(KERN_DEBUG, "Argument: 0x%08x | Trn mode: 0x%08x\n", + stsd_hsr_in_u32(host, SDHCI_ARGUMENT), + stsd_hsr_in_u16(host, SDHCI_TRANSFER_MODE)); + drv_printk(KERN_DEBUG, "Present: 0x%08x | Host ctl: 0x%08x\n", + stsd_hsr_in_u32(host, SDHCI_PRESENT_STATE), + stsd_hsr_in_u8(host, SDHCI_HOST_CONTROL)); + drv_printk(KERN_DEBUG, "Power: 0x%08x | Blk gap: 0x%08x\n", + stsd_hsr_in_u8(host, SDHCI_POWER_CONTROL), + stsd_hsr_in_u8(host, SDHCI_BLOCK_GAP_CONTROL)); + drv_printk(KERN_DEBUG, "Wake-up: 0x%08x | Clock: 0x%08x\n", + stsd_hsr_in_u8(host, SDHCI_WAKE_UP_CONTROL), + stsd_hsr_in_u16(host, SDHCI_CLOCK_CONTROL)); + drv_printk(KERN_DEBUG, "Timeout: 0x%08x | Int stat: 0x%08x\n", + stsd_hsr_in_u8(host, SDHCI_TIMEOUT_CONTROL), + stsd_hsr_in_u32(host, SDHCI_INT_STATUS)); + drv_printk(KERN_DEBUG, "Int enab: 0x%08x | Sig enab: 0x%08x\n", + stsd_hsr_in_u32(host, SDHCI_INT_ENABLE), + stsd_hsr_in_u32(host, SDHCI_SIGNAL_ENABLE)); + drv_printk(KERN_DEBUG, "AC12 err: 0x%08x | Slot int: 0x%08x\n", + stsd_hsr_in_u16(host, SDHCI_ACMD12_ERR), + stsd_hsr_in_u16(host, SDHCI_SLOT_INT_STATUS)); + drv_printk(KERN_DEBUG, "Caps: 0x%08x | Max curr: 0x%08x\n", + stsd_hsr_in_u32(host, SDHCI_CAPABILITIES), + stsd_hsr_in_u32(host, SDHCI_MAX_CURRENT)); - drv_printk(KERN_DEBUG, "===========================================\n"); + drv_printk(KERN_DEBUG, "===========================================\n"); } #endif /* DEBUG */ @@ -513,7 +516,7 @@ * Borrowed from MMC layer. */ -#define UNSTUFF_BITS(resp,start,size) \ +#define UNSTUFF_BITS(resp, start, size) \ ({ \ const int __size = size; \ const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \ @@ -625,7 +628,7 @@ return -EINVAL; } - //stsd_print_csd(csd); + /*stsd_print_csd(csd);*/ return 0; } @@ -674,7 +677,7 @@ break; case SD_SEND_IF_COND: /* WEIRD */ - //rsptype = STSD_RSPTYPE_R7; + /*rsptype = STSD_RSPTYPE_R7;*/ rsptype = STSD_RSPTYPE_R6; break; default: @@ -689,6 +692,11 @@ set_bit(__STSD_BAD_CARD, &host->flags); } +static inline void stsd_card_unset_bad(struct stsd_host *host) +{ + clear_bit(__STSD_BAD_CARD, &host->flags); +} + static inline int stsd_card_is_bad(struct stsd_host *host) { return test_bit(__STSD_BAD_CARD, &host->flags); @@ -835,7 +843,7 @@ } -static int stsd_hsr_in(struct stsd_host *host, +static int stsd_hsr_in(struct stsd_host *host, u32 reg, void *buf, size_t size) { u32 *local_buf; @@ -851,19 +859,19 @@ error = __stsd_hsr_in(host, reg, local_buf, size); if (!error) { - switch(size) { - case 1: - *(u8 *)buf = *local_buf & 0xff; - break; - case 2: - *(u16 *)buf = *local_buf & 0xffff; - break; - case 4: - *(u32 *)buf = *local_buf; - break; - default: - BUG(); - break; + switch (size) { + case 1: + *(u8 *)buf = *local_buf & 0xff; + break; + case 2: + *(u16 *)buf = *local_buf & 0xffff; + break; + case 4: + *(u32 *)buf = *local_buf; + break; + default: + BUG(); + break; } } @@ -872,7 +880,7 @@ return error; } -static int stsd_hsr_out(struct stsd_host *host, +static int stsd_hsr_out(struct stsd_host *host, u32 reg, void *buf, size_t size) { u32 *local_buf; @@ -886,19 +894,19 @@ if (!local_buf) return -ENOMEM; - switch(size) { - case 1: - *local_buf = *(u8 *)buf; - break; - case 2: - *local_buf = *(u16 *)buf; - break; - case 4: - *local_buf = *(u32 *)buf; - break; - default: - BUG(); - break; + switch (size) { + case 1: + *local_buf = *(u8 *)buf; + break; + case 2: + *local_buf = *(u16 *)buf; + break; + case 4: + *local_buf = *(u32 *)buf; + break; + default: + BUG(); + break; } error = __stsd_hsr_out(host, reg, local_buf, size); @@ -931,7 +939,7 @@ __declare_stsd_hsr_wait_for_resp(u16); #define __declare_stsd_hsr_in(_type) \ -static inline _type stsd_hsr_in_##_type(struct stsd_host *host, u32 reg) \ +static inline _type stsd_hsr_in_##_type(struct stsd_host *host, u32 reg) \ { \ _type val; \ \ @@ -1077,11 +1085,16 @@ static int stsd_reset_card(struct stsd_host *host) { + struct mmc_card *card = &host->card; int error; u32 status; + stsd_card_unset_bad(host); stsd_card_unset_sdhc(host); stsd_card_unset_manual_setup(host); + + memset(&card->cid, 0, sizeof(struct mmc_cid)); + memset(&card->csd, 0, sizeof(struct mmc_csd)); host->card.rca = 0; error = stsd_ioctl_small_read(host, STSD_IOCTL_RESET, @@ -1132,7 +1145,7 @@ reply_len = 4 * sizeof(u32); if (buf_len > reply_len) return -EINVAL; - + cmd = starlet_kzalloc(sizeof(*cmd), GFP_NOIO); if (!cmd) return -ENOMEM; @@ -1191,7 +1204,7 @@ { int error; - error = stsd_send_command(host, MMC_APP_CMD, STSD_CMDTYPE_AC, + error = stsd_send_command(host, MMC_APP_CMD, STSD_CMDTYPE_AC, host->card.rca << 16, NULL, 0); if (!error) { error = stsd_send_command(host, opcode, type, arg, @@ -1214,7 +1227,7 @@ u8 *p, crc; const size_t size = 128/8*sizeof(u8); - error = stsd_send_command(host, request, STSD_CMDTYPE_AC, + error = stsd_send_command(host, request, STSD_CMDTYPE_AC, host->card.rca << 16, buf, size); if (!error) { @@ -1262,7 +1275,7 @@ const size_t size = 128/8*sizeof(u8); /* WEIRD, don't use CMDTYPE_BCR for MMC_ALL_SEND_CID */ - return stsd_send_command(host, MMC_ALL_SEND_CID, 0, + return stsd_send_command(host, MMC_ALL_SEND_CID, 0, host->card.rca << 16, host->card.raw_cid, size); } @@ -1272,7 +1285,7 @@ int error; u32 reply; - error = stsd_send_command(host, MMC_SET_RELATIVE_ADDR, STSD_CMDTYPE_AC, + error = stsd_send_command(host, MMC_SET_RELATIVE_ADDR, STSD_CMDTYPE_AC, rca, &reply, sizeof(reply)); if (!error) { host->card.rca = reply >> 16; @@ -1314,7 +1327,7 @@ val = SD_BUS_WIDTH_1; error = stsd_send_app_command(host, SD_APP_SET_BUS_WIDTH, - STSD_CMDTYPE_AC, + STSD_CMDTYPE_AC, val, NULL, 0); if (error) DBG("%s: error=%d (%08x)\n", __func__, error, error); @@ -1430,7 +1443,7 @@ int error; /* WEIRD, don't use CMDTYPE_BC for MMC_GO_IDLE_STATE */ - error = stsd_send_command(host, MMC_GO_IDLE_STATE, 0, + error = stsd_send_command(host, MMC_GO_IDLE_STATE, 0, 0, NULL, 0); if (error) goto done; @@ -1440,7 +1453,7 @@ /* WEIRD, don't use CMDTYPE_BC for SD_SEND_IF_COND */ arg = STSD_VHS_27_36 | check_pattern; - error = stsd_send_command(host, SD_SEND_IF_COND, 0, + error = stsd_send_command(host, SD_SEND_IF_COND, 0, arg, &resp, sizeof(resp)); if (error) goto done; @@ -1463,19 +1476,19 @@ #define STSD_OCR_HCS (1<<30) /* Host Capacity Support */ #define STSD_OCR_CCS (1<<30) /* Card Capacity Support */ - for(i=0; i<100; i++) { + for (i = 0; i < 100; i++) { /* WEIRD, don't use CMDTYPE_BCR for MMC_APP_CMD */ - error = stsd_send_command(host, MMC_APP_CMD, STSD_CMDTYPE_AC, + error = stsd_send_command(host, MMC_APP_CMD, STSD_CMDTYPE_AC, 0, NULL, 0); if (error) goto done; /* WEIRD, don't use CMDTYPE_BCR for SD_APP_OP_COND */ - error = stsd_send_command(host, SD_APP_OP_COND, 0, + error = stsd_send_command(host, SD_APP_OP_COND, 0, STSD_OCR_HCS| MMC_VDD_32_33|MMC_VDD_33_34, &resp, sizeof(resp)); - if (error) + if (error) goto done; if ((resp[0] & MMC_CARD_BUSY) != 0) { @@ -1497,11 +1510,11 @@ } error = stsd_cmd_all_send_cid(host); - if (error) + if (error) goto done; error = stsd_cmd_set_relative_addr(host, 0); - if (error) + if (error) goto done; done: @@ -1551,7 +1564,7 @@ stsd_reset_card(host); error = stsd_get_status(host, &status); - if (error) + if (error) goto err_bad_card; if (!stsd_card_status_is_inserted(status)) { drv_printk(KERN_ERR, "no card found\n"); @@ -1627,7 +1640,7 @@ host->card.cid.prod_name, (unsigned long)((host->card.csd.capacity / 1024) * (1 << host->card.csd.read_blkbits)), - 1 << host->card.csd.read_blkbits, + 1 << host->card.csd.read_blkbits, host->card.cid.serial); error = 0; @@ -1654,7 +1667,7 @@ struct stsd_command *cmd = xfer->cmd; int error; - xfer->direction = (write)?DMA_TO_DEVICE:DMA_FROM_DEVICE; + xfer->direction = (write) ? DMA_TO_DEVICE : DMA_FROM_DEVICE; xfer->size = nr_blocks * xfer->blk_size; if (xfer->size > xfer->bounce_buf_size) { @@ -1683,7 +1696,8 @@ starlet_ioh_sg_init_table(xfer->io, 1); starlet_ioh_sg_set_buf(&xfer->io[0], xfer->reply, xfer->reply_len); - cmd->opcode = (write)?MMC_WRITE_MULTIPLE_BLOCK:MMC_READ_MULTIPLE_BLOCK; + cmd->opcode = (write) ? MMC_WRITE_MULTIPLE_BLOCK : + MMC_READ_MULTIPLE_BLOCK; cmd->arg = start; cmd->cmdtype = STSD_CMDTYPE_AC; /* STSD_CMDTYPE_ADTC */ cmd->rsptype = stsd_opcode_to_rsptype(cmd->opcode); @@ -1749,35 +1763,33 @@ if (uptodate <= 0) return uptodate; - write = (rq_data_dir(req) == READ)?0:1; + write = (rq_data_dir(req) == READ) ? 0 : 1; start = req->sector; if (!stsd_card_is_sdhc(host)) start <<= KERNEL_SECTOR_SHIFT; nr_blocks = req->current_nr_sectors; - uptodate = 1; error = stsd_do_block_transfer(host, write, start, req->buffer, nr_blocks); - if (error) { - DBG("%s: error=%d (%08x), start=%lu, \n", __func__, error, error, start); - uptodate = error; - } + if (error) + DBG("%s: error=%d (%08x), start=%lu, \n", __func__, + error, error, start); - return uptodate; + return error; } static int stsd_io_thread(void *param) { - struct stsd_host *host = param; + struct stsd_host *host = param; struct request *req; - int uptodate; unsigned long flags; + int error; - current->flags |= PF_NOFREEZE|PF_MEMALLOC; + current->flags |= PF_NOFREEZE|PF_MEMALLOC; mutex_lock(&host->io_mutex); - for(;;) { + for (;;) { req = NULL; set_current_state(TASK_INTERRUPTIBLE); @@ -1797,10 +1809,10 @@ continue; } set_current_state(TASK_INTERRUPTIBLE); - uptodate = stsd_do_request(host, req); + error = stsd_do_request(host, req); spin_lock_irqsave(&host->queue_lock, flags); - end_queued_request(req, uptodate); + __blk_end_request(req, error, blk_rq_bytes(req)); spin_unlock_irqrestore(&host->queue_lock, flags); } mutex_unlock(&host->io_mutex); @@ -1822,9 +1834,9 @@ static DECLARE_MUTEX(open_lock); -static int stsd_open(struct inode *inode, struct file *filp) +static int stsd_open(struct block_device *bdev, fmode_t mode) { - struct stsd_host *host = inode->i_bdev->bd_disk->private_data; + struct stsd_host *host = bdev->bd_disk->private_data; int error = 0; if (!host || host->fd < 0) @@ -1832,13 +1844,13 @@ /* honor exclusive open mode */ if (host->refcnt == -1 || - (host->refcnt && (filp->f_flags & O_EXCL))) { + (host->refcnt && (mode & FMODE_EXCL))) { error = -EBUSY; goto out; } /* this takes care of revalidating the media if needed */ - check_disk_change(inode->i_bdev); + check_disk_change(bdev); if (!host->card.csd.capacity) { error = -ENOMEDIUM; goto out; @@ -1846,7 +1858,7 @@ down(&open_lock); - if ((filp->f_flags & O_EXCL)) + if ((mode & FMODE_EXCL)) host->refcnt = -1; else host->refcnt++; @@ -1858,9 +1870,9 @@ } -static int stsd_release(struct inode *inode, struct file *filp) +static int stsd_release(struct gendisk *disk, fmode_t mode) { - struct stsd_host *host = inode->i_bdev->bd_disk->private_data; + struct stsd_host *host = disk->private_data; if (!host) return -ENXIO; @@ -1869,14 +1881,13 @@ if (host->refcnt > 0) host->refcnt--; - else { + else host->refcnt = 0; - } up(&open_lock); - if (!host->refcnt && host->fd == -1) - kfree(host); + if (!host->refcnt && host->fd == -1) + kfree(host); return 0; } @@ -1910,11 +1921,10 @@ mutex_unlock(&host->io_mutex); - if (!error && last_serial == host->card.cid.serial && last_serial) { + if (!error && last_serial == host->card.cid.serial && last_serial) clear_bit(__STSD_MEDIA_CHANGED, &host->flags); - } else { + else set_bit(__STSD_MEDIA_CHANGED, &host->flags); - } return (host->flags & STSD_MEDIA_CHANGED) ? 1 : 0; } @@ -1943,7 +1953,7 @@ if (error < 0) drv_printk(KERN_ERR, "error = %d\n", error); error = -ENOMEDIUM; - goto out; + /* FALL THROUGH */ } /* inform the block layer about various sizes */ @@ -1959,27 +1969,12 @@ return error; } -static int stsd_ioctl(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +static int stsd_getgeo(struct block_device *bdev, struct hd_geometry *geo) { - struct block_device *bdev = inode->i_bdev; - struct hd_geometry geo; - - switch (cmd) { - case HDIO_GETGEO: - /* fake the entries */ - geo.cylinders = get_capacity(bdev->bd_disk) / (4 * 16); - geo.heads = 4; - geo.sectors = 16; - geo.start = get_start_sect(bdev); - - if (copy_to_user((void __user *)arg, &geo, sizeof(geo))) - return -EFAULT; - return 0; - default: - return -ENOTTY; - } - return -EINVAL; + geo->cylinders = get_capacity(bdev->bd_disk) / (4 * 16); + geo->heads = 4; + geo->sectors = 16; + return 0; } static struct block_device_operations stsd_fops = { @@ -1988,7 +1983,7 @@ .release = stsd_release, .revalidate_disk = stsd_revalidate_disk, .media_changed = stsd_media_changed, - .ioctl = stsd_ioctl, + .getgeo = stsd_getgeo, }; /* @@ -2151,7 +2146,7 @@ #endif error = stsd_init_io_thread(host); - if (error) + if (error) goto err_xfer; add_disk(host->disk); @@ -2272,7 +2267,7 @@ static int __init stsd_init_module(void) { - drv_printk(KERN_INFO, "%s - version %s\n", DRV_DESCRIPTION, + drv_printk(KERN_INFO, "%s - version %s\n", DRV_DESCRIPTION, stsd_driver_version); if (register_blkdev(STSD_MAJOR, DRV_MODULE_NAME)) { |