From: Adrian M. <zx8...@us...> - 2002-09-10 22:55:54
|
Update of /cvsroot/linuxdc/linux-sh-dc/drivers/mtd/maps In directory usw-pr-cvs1:/tmp/cvs-serv5751/drivers/mtd/maps Modified Files: vmu-flash.c Log Message: Multiple VMU devices now supported Index: vmu-flash.c =================================================================== RCS file: /cvsroot/linuxdc/linux-sh-dc/drivers/mtd/maps/vmu-flash.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- vmu-flash.c 3 Sep 2002 21:46:31 -0000 1.9 +++ vmu-flash.c 10 Sep 2002 22:55:51 -0000 1.10 @@ -26,6 +26,15 @@ static int VMU_NUM_BLOCKS; /* This is a dynamic property */ static int VMU_BLOCK_SIZE; +#define _DEBUG_ + +#ifdef _DEBUG_ +#define DEBGM(fmt, args...) (printk(KERN_INFO fmt, ##args)) +#else +#define DEBGM(fmt, args...) ((void) 0) +#endif + + /* MTD Information */ static struct mtd_info *vmu_flash_mtd = NULL; @@ -45,6 +54,7 @@ long writecnt; long readcnt; long removable; + struct mtd_info *mtd; } memcard_t; @@ -69,10 +79,9 @@ wait_queue_head_t wq_mq; DECLARE_WAIT_QUEUE_HEAD(wq_mq); - -/*************************************/ /**********Read and write routines*************/ -static int maple_vmu_read_block(unsigned int num, u_char * buf) +static int maple_vmu_read_block(unsigned int num, u_char * buf, + struct mtd_info *mtd) { /* async maple call @@ -81,14 +90,14 @@ /* Sanity check */ - if (!vmu_flash_mtd) { - printk(KERN_WARNING - "VMU FLASH: Attempting to read data without having set up mtd.\n"); + if (!mtd) { + DEBGM(KERN_WARNING + "VMU FLASH: Attempting to read data without having set up mtd.\n"); return -1; } struct maple_driver_data *mdd = - (struct maple_driver_data *) (vmu_flash_mtd->priv); + (struct maple_driver_data *) (mtd->priv); memcard_t *memcard = (memcard_t *) (mdd->private_data); struct mapleq *mqu = (struct mapleq *) &(mdd->mq); mqu->command = MAPLE_COMMAND_BREAD; @@ -102,7 +111,7 @@ ((unsigned long *) (mqu->recvbuf))[1] = num << 24; mqu->sendbuf = mqu->recvbuf; if (maple_add_packet(mqu) != 0) { - printk(KERN_WARNING "VMU FLASH: Could not add packet\n"); + DEBGM(KERN_WARNING "VMU FLASH: Could not add packet\n"); return -1; } @@ -121,21 +130,21 @@ return 0; } - printk(KERN_WARNING - "VMU FLASH: Read has failed - return is 0x%X\n", - lastmq->recvbuf[0]); - printk(KERN_WARNING "ERROR code is 0x%X\n", lastmq->recvbuf[1]); + DEBGM(KERN_WARNING + "VMU FLASH: Read has failed - return is 0x%X\n", + lastmq->recvbuf[0]); + DEBGM(KERN_WARNING "ERROR code is 0x%X\n", lastmq->recvbuf[1]); return -1; } -static int maple_vmu_write_block(unsigned int num, u_char * buf) +static int maple_vmu_write_block(unsigned int num, u_char * buf, struct mtd_info *mtd) { /* Sanity check */ - if (!vmu_flash_mtd) { + if (!mtd) { printk(KERN_WARNING "VMU FLASH: Attempting to write data without having set up mtd.\n"); return -1; @@ -143,7 +152,7 @@ vmu_cache->valid = 0; /* Writing so any cache may be invalid */ struct maple_driver_data *mdd = - (struct maple_driver_data *) (vmu_flash_mtd->priv); + (struct maple_driver_data *) (mtd->priv); struct mapleq *mqu = (struct mapleq *) &(mdd->mq); memcard_t *memcard = (memcard_t *) mdd->private_data; @@ -200,7 +209,7 @@ /* Validate we've got allocated memory */ if (!block) { - printk(KERN_WARNING "Can't allocate block\n"); + DEBGM(KERN_WARNING "Can't allocate block\n"); return NULL; } @@ -209,8 +218,7 @@ /* Make sure we don't overstep our boundaries */ if (src_ofs >= VMU_NUM_BLOCKS * VMU_BLOCK_SIZE) { - printk(KERN_WARNING - "Source offset exceeds total offset\n"); + DEBGM(KERN_WARNING "Source offset exceeds total offset\n"); kfree(block); return NULL; } @@ -220,8 +228,8 @@ /* Validate we've got a valid block */ if (block->num > VMU_NUM_BLOCKS) { - printk(KERN_WARNING - "Block number exceeds number of blocks\n"); + DEBGM(KERN_WARNING + "Block number exceeds number of blocks\n"); kfree(block); return NULL; } @@ -243,7 +251,8 @@ * */ -static __u8 vmu_flash_read8(unsigned long ofs, long *retval) +static __u8 vmu_flash_read8(unsigned long ofs, long *retval, + struct mtd_info *mtd) { block_t *block; *retval = 0; @@ -253,7 +262,7 @@ /* Validate it was found */ if (!block) { - printk(KERN_WARNING "Got an invalid block\n"); + DEBGM(KERN_WARNING "Got an invalid block\n"); *retval = 1; return -1; } @@ -280,8 +289,8 @@ /* Read the block */ - if (maple_vmu_read_block(block->num, buf) == -1) { - printk(KERN_WARNING "Can't read block: %d\n", block->num); + if (maple_vmu_read_block(block->num, buf, mtd) == -1) { + DEBGM(KERN_WARNING "Can't read block: %d\n", block->num); kfree(block); *retval = 2; return -1; @@ -307,7 +316,8 @@ * Writes a byte to a VMU at the specified offset. * */ -static void vmu_flash_write8(__u8 d, unsigned long ofs) +static void vmu_flash_write8(__u8 d, unsigned long ofs, + struct mtd_info *mtd) { block_t *block; u_char *buf = kmalloc(VMU_BLOCK_SIZE, GFP_KERNEL); @@ -317,14 +327,14 @@ /* Validate it was found */ if (!block) { - printk(KERN_WARNING "Got an invalid block\n"); + DEBGM(KERN_WARNING "Got an invalid block\n"); return; } /* Read the block */ - if (maple_vmu_read_block(block->num, buf)) { - printk(KERN_WARNING "Can't read block: %d\n", block->num); + if (maple_vmu_read_block(block->num, buf, mtd)) { + DEBGM(KERN_WARNING "Can't read block: %d\n", block->num); kfree(block); return; } @@ -333,7 +343,7 @@ (__u8) (*(buf + block->ofs)) = d; /* Write the block */ - if (maple_vmu_write_block(block->num, buf)) { + if (maple_vmu_write_block(block->num, buf, mtd)) { printk(KERN_WARNING "Can't write block: %d\n", block->num); kfree(block); return; @@ -360,7 +370,7 @@ long retval = 0; int index = 0; do { - u8 cx = vmu_flash_read8(start_here + index, &retval); + u8 cx = vmu_flash_read8(start_here + index, &retval, mtd); if (retval) { *retlen = index; return -1; @@ -381,7 +391,7 @@ return -1; if (len == 1) { /* Simple one char write */ - vmu_flash_write8(buf[0], from); + vmu_flash_write8(buf[0], from, mtd); *retlen = 1; return 0; } @@ -402,16 +412,12 @@ do { - u_char *buffer = kmalloc(VMU_BLOCK_SIZE, GFP_KERNEL); - - - /* Read the block */ - if (maple_vmu_read_block(block->num, buffer)) { - printk(KERN_WARNING "Can't read block: %d\n", - block->num); + if (maple_vmu_read_block(block->num, buffer, mtd)) { + DEBGM(KERN_WARNING "Can't read block: %d\n", + block->num); kfree(block); *retlen = 0; return -1; @@ -424,7 +430,7 @@ if (index >= len) break; } while (block->ofs < VMU_BLOCK_SIZE); - maple_vmu_write_block(block->num, buffer); + maple_vmu_write_block(block->num, buffer, mtd); kfree(buffer); (block->num)++; block->ofs = 0; @@ -435,14 +441,16 @@ - - } static int vmu_flash_erase(struct mtd_info *mtd, struct erase_info *erase) { int z; + erase->state = MTD_ERASING; vmu_flash_write(mtd, erase->addr, erase->len, &z, "\0"); + erase->state = MTD_ERASE_DONE; + if (erase->callback) + (erase->callback) (erase); return 0; } @@ -461,12 +469,7 @@ static int __init vmu_flash_map_init(void) { printk(KERN_NOTICE "VMU flash driver available\n"); - maple_register_driver(&dc_flashmap_driver); - /* FIXME: We need to do something with the vmu_flash_mdev */ - - - return 0; } @@ -484,7 +487,7 @@ maple_unregister_driver(&dc_flashmap_driver); /* See if there's anything to unregister */ if (!vmu_flash_mtd) { - printk(KERN_WARNING "Nothing to unregister\n"); + DEBGM(KERN_WARNING "Nothing to unregister\n"); return; } @@ -543,7 +546,7 @@ static int dc_flashmap_connect(struct maple_driver_data *d) { - printk + DEBGM ("Registering VMU Flash mapping and loading VMU Flash driver\n"); /* What are the characteristics of the flash we have? */ @@ -556,8 +559,8 @@ lastmq = NULL; mqu->sendbuf = mqu->recvbuf; if (maple_add_packet(mqu) != 0) { - printk(KERN_WARNING - "VMU FLASH: Could not add packet to query device\n"); + DEBGM(KERN_WARNING + "VMU FLASH: Could not add packet to query device\n"); return -1; } @@ -566,7 +569,6 @@ } while (lastmq == NULL); /* Read off the flash data */ - /* How many devices are here? */ int bit_cnt = 0; unsigned long test_flash_data = @@ -591,21 +593,17 @@ memcard_t *card = kmalloc(sizeof(memcard_t), GFP_KERNEL); card->partitions = ((basic_flash_data >> 24) & 0xff) + 1; - printk(KERN_NOTICE " Flash device has %ld partitions\n", - card->partitions); + DEBGM(" Flash device has %ld partitions\n", card->partitions); card->blocklen = (((basic_flash_data >> 16) & 0xff) + 1) << 5; - printk(KERN_NOTICE - " Flash device has block length of %ld bytes\n", - card->blocklen); + DEBGM(" Flash device has block length of %ld bytes\n", + card->blocklen); card->writecnt = (basic_flash_data >> 12) & 0xf; - printk(KERN_NOTICE " Flash device has write count of %ld\n", - card->writecnt); + DEBGM(" Flash device has write count of %ld\n", card->writecnt); card->readcnt = (basic_flash_data >> 8) & 0xf; - printk(KERN_NOTICE " Flash device has read count of %ld\n", - card->readcnt); + DEBGM(" Flash device has read count of %ld\n", card->readcnt); card->removable = (basic_flash_data >> 7) & 1; - printk(KERN_NOTICE " Flash device removable status is %ld\n", - card->removable); + DEBGM(" Flash device removable status is %ld\n", + card->removable); VMU_BLOCK_SIZE = card->blocklen; d->private_data = card; @@ -616,13 +614,13 @@ mqu->length = 2; ((unsigned long *) (mqu->recvbuf))[0] = cpu_to_be32(MAPLE_FUNC_MEMCARD); - ((unsigned long *) (mqu->recvbuf))[1] = 0; // Assuming only have one partition + ((unsigned long *) (mqu->recvbuf))[1] = 0; /* Assuming only have one partition */ lastmq = NULL; mqu->sendbuf = mqu->recvbuf; if (maple_add_packet(mqu) != 0) { - printk(KERN_WARNING - "VMU FLASH: Could not add packet to query device\n"); + DEBGM(KERN_WARNING + "VMU FLASH: Could not add packet to query device\n"); return -1; } @@ -631,13 +629,11 @@ interruptible_sleep_on_timeout(&wq_mq, 1); } while (lastmq == NULL); - int user_blocks = ((unsigned short *) (lastmq->recvbuf))[12]; // User accessible blocks - int root_block = ((unsigned short *) (lastmq->recvbuf))[6]; // Root block location - printk(KERN_INFO - " Flash device has %d blocks available to user\n", - user_blocks); - printk(KERN_INFO " Flash root block is at block %d\n", - root_block); + int user_blocks = ((unsigned short *) (lastmq->recvbuf))[12]; /* User accessible blocks */ + int root_block = ((unsigned short *) (lastmq->recvbuf))[6]; /* Root block location */ + DEBGM(" Flash device has %d blocks available to user\n", + user_blocks); + DEBGM(" Flash root block is at block %d\n", root_block); VMU_NUM_BLOCKS = root_block + 1; @@ -645,27 +641,27 @@ /* Register the flash with mtd subsystem */ - if (!vmu_flash_mtd) { - /* Populate a mtd_info */ - vmu_flash_mtd = kmalloc(512, GFP_KERNEL); - vmu_flash_mtd->name = "Dreamcast VMU Flash"; - /* This is 'other' */ - vmu_flash_mtd->type = MTD_OTHER; - vmu_flash_mtd->flags = - MTD_CLEAR_BITS | MTD_SET_BITS | MTD_ERASEABLE | - MTD_WRITEB_WRITEABLE; - vmu_flash_mtd->size = VMU_NUM_BLOCKS * VMU_BLOCK_SIZE; - vmu_flash_mtd->erasesize = VMU_BLOCK_SIZE; + /* Populate a mtd_info */ + vmu_flash_mtd = kmalloc(512, GFP_KERNEL); + vmu_flash_mtd->name = "Dreamcast VMU Flash"; + + /* This is 'other' */ + vmu_flash_mtd->type = MTD_OTHER; + vmu_flash_mtd->flags = + MTD_CLEAR_BITS | MTD_SET_BITS | MTD_ERASEABLE | + MTD_WRITEB_WRITEABLE; + vmu_flash_mtd->size = VMU_NUM_BLOCKS * VMU_BLOCK_SIZE; + vmu_flash_mtd->erasesize = VMU_BLOCK_SIZE; + + /* Mandatory functions */ + vmu_flash_mtd->write = vmu_flash_write; + vmu_flash_mtd->read = vmu_flash_read; + vmu_flash_mtd->erase = vmu_flash_erase; + vmu_flash_mtd->sync = vmu_flash_sync; + /* Use private data to point to d */ + vmu_flash_mtd->priv = d; /* TO DO: Fix this */ - /* Mandatory functions */ - vmu_flash_mtd->write = vmu_flash_write; - vmu_flash_mtd->read = vmu_flash_read; - vmu_flash_mtd->erase = vmu_flash_erase; - vmu_flash_mtd->sync = vmu_flash_sync; - /* Use private data to point to d */ - vmu_flash_mtd->priv = d; - } vmu_flash_mtd->module = THIS_MODULE; @@ -675,12 +671,11 @@ /* Lock the device in */ vmu_flash_mtd = get_mtd_device(vmu_flash_mtd, -1); if (!vmu_flash_mtd) { - printk(KERN_ERR - "VMU Flash driver initialisation failed\n"); + DEBGM(KERN_ERR "VMU Flash driver initialisation failed\n"); return -1; } - + card->mtd = vmu_flash_mtd; /* Create the cache */ vmu_cache = kmalloc(64, GFP_KERNEL); vmu_cache->buffer = kmalloc(VMU_BLOCK_SIZE, GFP_KERNEL); @@ -693,19 +688,22 @@ { printk(KERN_NOTICE "Unregistering VMU flash mapping\n"); + /* Reead off the relevant mtd */ + memcard_t *card = (memcard_t *) (d->private_data); + /* See if there's anything to unregister */ - if (!vmu_flash_mtd) { - printk(KERN_WARNING "Nothing to unregister\n"); + if (!(card->mtd)) { + DEBGM(KERN_WARNING "Nothing to unregister\n"); return; } - if (vmu_flash_mtd) { + if (card->mtd) { /* Unregister from MTD */ - put_mtd_device(vmu_flash_mtd); - del_mtd_device(vmu_flash_mtd); - kfree(vmu_flash_mtd); - vmu_flash_mtd = NULL; + put_mtd_device(card->mtd); + del_mtd_device(card->mtd); + kfree(card->mtd); + card->mtd = NULL; } /* Clear the cache */ |