From: Adrian M. <ad...@mc...> - 2002-08-18 23:26:39
|
I am edging closer to producing a simple driver that will have a character based interface to the vmu flash memory (more sophisticated front ends can then be built on top of that). Here is the latest diff of my work from Paul's core file in the CVS: --- vmu-old.c Fri Aug 16 00:05:22 2002 +++ vmu-flash.c Mon Aug 19 00:12:39 2002 @@ -2,6 +2,10 @@ * drivers/mtd/maps/vmu-flash.c * * (C)opyright 2001 Paul Mundt <le...@ch...> + + + + + + Messed about with and fragments copyright 2002, Adrian McMenamin <ad...@mc...> + + * * Flash mapping handler for the Sega Dreamcast VMU. * @@ -26,12 +30,84 @@ /* MTD Information */ static struct mtd_info *vmu_flash_mtd = NULL; +/* Persistent result */ +static struct mapleq lastmq; +static struct maple_driver dc_flashmap_driver; + +int waken_up = 1; + /* VMU Block */ typedef struct block_s { unsigned int num; /* Block Number */ unsigned int ofs; /* Block Offset */ } block_t; +/*************************************/ +/**********Read and write routines*************/ +int maple_vmu_read_block(unsigned int num, u_char *buf){ + + /* async maple call + assemble maple call + wait for return */ + + + /* Sanity check */ + if (!vmu_flash_mtd){ + printk(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 mapleq *mqu = (struct mapleq *) &(mdd->mq); + mqu->command = 11; + mqu->length = 2; + +((unsigned long *) (mqu->recvbuf))[0] = + cpu_to_be32(MAPLE_FUNC_MEMCARD); + + ((unsigned long *) (mqu->recvbuf))[1] = num; + mqu->sendbuf = mqu->recvbuf; + if (maple_add_packet(mqu) != 0){ + printk(KERN_WARNING "VMU FLASH: Could not add packet\n"); + return -1; + } + + return 0; + +} + +int maple_vmu_write_block(unsigned int num, u_char *buf){ + + + /* Sanity check */ + if (!vmu_flash_mtd){ + printk(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 mapleq *mqu = (struct mapleq *) &(mdd->mq); + mqu->command = 12; + mqu->length = 514; + +((unsigned long *) (mqu->recvbuf))[0] = + cpu_to_be32(MAPLE_FUNC_MEMCARD); + + ((unsigned long *) (mqu->recvbuf))[1] = num; + memcpy((mqu->recvbuf) + 8, buf, 512); + + mqu->sendbuf = mqu->recvbuf; + if (maple_add_packet(mqu) != 0){ + printk(KERN_WARNING "VMU FLASH: Could not add packet\n"); + return -1; + } + + return 0; + +} +/*************************************/ + + /** * __ofs_to_block - Offset to Block Conversion * @@ -90,7 +166,7 @@ * Reads a byte from a VMU at the specified offset. * */ -static __u8 vmu_flash_read8(struct map_info *map, unsigned long ofs) +static __u8 vmu_flash_read8(unsigned long ofs) { block_t *block; u_char *buf = NULL; @@ -105,7 +181,7 @@ } /* Read the block */ - if (maple_vmu_read_block(vmu_flash_mdev, block->num, buf)) { + if (maple_vmu_read_block(block->num, buf)) { printk(KERN_WARNING "Can't read block: %d\n", block->num); kfree(block); return 1; @@ -129,7 +205,7 @@ * Writes a byte to a VMU at the specified offset. * */ -static void vmu_flash_write8(struct map_info *map, __u8 d, unsigned long ofs) +static void vmu_flash_write8( __u8 d, unsigned long ofs) { block_t *block; u_char *buf = NULL; @@ -144,7 +220,7 @@ } /* Read the block */ - if (maple_vmu_read_block(vmu_flash_mdev, block->num, buf)) { + if (maple_vmu_read_block(block->num, buf)) { printk(KERN_WARNING "Can't read block: %d\n", block->num); kfree(block); return; @@ -154,7 +230,7 @@ (__u8)(*(buf + block->ofs)) = d; /* Write the block */ - if (maple_vmu_write_block(vmu_flash_mdev, block->num, buf)) { + if (maple_vmu_write_block(block->num, buf)) { printk(KERN_WARNING "Can't write block: %d\n", block->num); kfree(block); return; @@ -163,12 +239,35 @@ kfree(block); } -static struct map_info vmu_flash_map = { - name: "VMU Flash", - size: VMU_NUM_BLOCKS * VMU_BLOCK_SIZE, - read8: vmu_flash_read8, - write8: vmu_flash_write8, -}; +/***********************************************/ +/* Read and Write |