From: Adrian M. <zx8...@us...> - 2002-08-31 18:17:16
|
Update of /cvsroot/linuxdc/linux-sh-dc/drivers/mtd/maps In directory usw-pr-cvs1:/tmp/cvs-serv23778/drivers/mtd/maps Modified Files: vmu-flash.c Log Message: VMU reads now verified as working Index: vmu-flash.c =================================================================== RCS file: /cvsroot/linuxdc/linux-sh-dc/drivers/mtd/maps/vmu-flash.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- vmu-flash.c 31 Aug 2002 11:40:30 -0000 1.6 +++ vmu-flash.c 31 Aug 2002 18:17:13 -0000 1.7 @@ -23,11 +23,11 @@ #include <asm/io.h> -static int VMU_NUM_BLOCKS; /* This is a dynamic property */ +static int VMU_NUM_BLOCKS; /* This is a dynamic property */ static int VMU_BLOCK_SIZE; /* Maple Device */ -static struct maple_device *vmu_flash_mdev __initdata = NULL; +static struct maple_device *vmu_flash_mdev = NULL; /* MTD Information */ static struct mtd_info *vmu_flash_mtd = NULL; @@ -42,7 +42,7 @@ /* Memory card details */ typedef struct memcard_s { long partitions; - long blocklen; + long blocklen; long writecnt; long readcnt; long removable; @@ -116,7 +116,7 @@ /* Now check if we've got a proper return */ if (block_buffer) { - memcpy(block_buffer, buf, 512); + memcpy(buf, block_buffer, 512); kfree(block_buffer); block_buffer = NULL; return 0; @@ -153,7 +153,7 @@ cpu_to_be32(MAPLE_FUNC_MEMCARD); ((unsigned long *) (mqu->recvbuf))[1] = num; - memcpy((mqu->recvbuf) + 8, buf, 512); + memcpy(buf, (mqu->recvbuf) + 8, 512); mqu->sendbuf = mqu->recvbuf; if (maple_add_packet(mqu) != 0) { @@ -248,7 +248,7 @@ if (vmu_cache->valid) { if (vmu_cache->block == block->num) { if ((vmu_cache->jiffies_atc + 10) >= jiffies) { /* short lifespan */ - memcpy(vmu_cache->buffer, buf, 512); + memcpy(buf, vmu_cache->buffer, 512); u_char *buf2 = buf; buf2 += block->ofs; @@ -332,7 +332,7 @@ /* Read and Write routines */ static int vmu_flash_read(struct mtd_info *mtd, loff_t from, size_t len, - size_t * retlen, u_char * buf) + size_t * retlen, u_char * buf) { /* printk("Reading from %llx with length %llx\n", from, len); */ if (len < 1) @@ -358,7 +358,7 @@ static int vmu_flash_write(struct mtd_info *mtd, loff_t from, size_t len, - size_t * retlen, const u_char * buf) + size_t * retlen, const u_char * buf) { if (len < 1) return -1; @@ -428,22 +428,22 @@ /***********Maple functions***************/ -static void dc_flashmap_callback(struct maple_driver_data *data) +void dc_flashmap_callback(struct maple_driver_data *data) { - struct mapleq *mq = &data->mq; - if (flash_queried == 0) { if (mq->recvbuf[0] == 5) { lastmq = mq; - flash_queried = 1; wake_up_interruptible(&wq_mq); /* Wake sleeping code */ return; + } else if (mq->recvbuf[0] == 8) { + lastmq = mq; + wake_up_interruptible(&wq_mq); /* Wake sleeping code */ + flash_queried = 1; + return; } - } - - + } if (mq->recvbuf[0] == 8) { /* int res = mq->recvbuf[0]; @@ -458,19 +458,17 @@ */ block_buffer = kmalloc(512, GFP_KERNEL); /* Copy over */ - memcpy(mq->recvbuf + 12, block_buffer, 512); + memcpy(block_buffer, mq->recvbuf + 12, 512); lastmq = mq; wake_up_interruptible(&wq_mq); /* Wake sleeping code */ - memcpy(block_buffer, vmu_cache->buffer, 512); + memcpy(vmu_cache->buffer, block_buffer, 512); vmu_cache->block = mq->recvbuf[11] & 0xff; vmu_cache->jiffies_atc = jiffies; /* Mark the creation time */ vmu_cache->valid = 1; /* Block is now valid */ return; } lastmq = mq; - - } @@ -487,7 +485,7 @@ mqu->command = 1; mqu->length = 0; - + lastmq = NULL; mqu->sendbuf = mqu->recvbuf; if (maple_add_packet(mqu) != 0) { printk(KERN_WARNING @@ -495,32 +493,28 @@ return -1; } - lastmq = NULL; - do { interruptible_sleep_on_timeout(&wq_mq, 1); } while (lastmq == NULL); - /* Read off the flash data */ - - - /* How many devices are here? */ int bit_cnt = 0; - unsigned long test_flash_data = be32_to_cpu(((unsigned long *)(lastmq->recvbuf))[1]); + unsigned long test_flash_data = + be32_to_cpu(((unsigned long *) (lastmq->recvbuf))[1]); int controller_here = test_flash_data & 0x01; int x; - for (x = 0; x < 32; x++) - { - if (test_flash_data & 0x01) bit_cnt++; - test_flash_data = test_flash_data >> 1; - } + for (x = 0; x < 32; x++) { + if (test_flash_data & 0x01) + bit_cnt++; + test_flash_data = test_flash_data >> 1; + } /* Only device with a lower index is a controller */ unsigned long basic_flash_data = - be32_to_cpu(((unsigned long *) (lastmq->recvbuf))[1 + bit_cnt - controller_here]); + be32_to_cpu(((unsigned long *) (lastmq->recvbuf))[1 + bit_cnt - + controller_here]); /* Create a permanent record */ @@ -529,24 +523,57 @@ 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); + printk(KERN_NOTICE " 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); + printk(KERN_NOTICE + " 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); + printk(KERN_NOTICE " 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); + printk(KERN_NOTICE " 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); - VMU_NUM_BLOCKS = 256; /* TO DO: Read this off */ VMU_BLOCK_SIZE = card->blocklen; - d->private_data = card; + /* Now query flash partition 0 to find definitve block size */ + mqu = (struct mapleq *) &(d->mq); + mqu->command = 10; + 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 + lastmq = NULL; - /* Now query each flash partition 0 */ + mqu->sendbuf = mqu->recvbuf; + if (maple_add_packet(mqu) != 0) { + printk(KERN_WARNING + "VMU FLASH: Could not add packet to query device\n"); + return -1; + } + + + do { + 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); + VMU_NUM_BLOCKS = root_block + 1; + + + /* Register the flash with mtd subsystem */ @@ -558,8 +585,8 @@ /* This is 'other' */ vmu_flash_mtd->type = MTD_OTHER; vmu_flash_mtd->flags = 0; - vmu_flash_mtd->size = VMU_NUM_BLOCKS * VMU_BLOCK_SIZE; - vmu_flash_mtd->erasesize = VMU_BLOCK_SIZE/card->writecnt; + vmu_flash_mtd->size = VMU_NUM_BLOCKS * VMU_BLOCK_SIZE; + vmu_flash_mtd->erasesize = VMU_BLOCK_SIZE / card->writecnt; /* Mandatory functions */ vmu_flash_mtd->write = vmu_flash_write; |