|
From: Adrian M. <zx8...@us...> - 2002-08-31 11:40:33
|
Update of /cvsroot/linuxdc/linux-sh-dc/drivers/mtd/maps
In directory usw-pr-cvs1:/tmp/cvs-serv2764/drivers/mtd/maps
Modified Files:
vmu-flash.c
Log Message:
VMU Flash code updated
Index: vmu-flash.c
===================================================================
RCS file: /cvsroot/linuxdc/linux-sh-dc/drivers/mtd/maps/vmu-flash.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- vmu-flash.c 30 Aug 2002 23:31:52 -0000 1.5
+++ vmu-flash.c 31 Aug 2002 11:40:30 -0000 1.6
@@ -22,26 +22,27 @@
#include <linux/mtd/map.h>
#include <asm/io.h>
-#define VMU_NUM_BLOCKS 0x100 /* Standard VMU has 256 blocks */
-#define VMU_BLOCK_SIZE 0x200 /* Standard VMU block is 512 bytes */
+
+static int VMU_NUM_BLOCKS; /* This is a dynamic property */
+static int VMU_BLOCK_SIZE;
/* Maple Device */
-struct maple_device *vmu_flash_mdev __initdata = NULL;
+static struct maple_device *vmu_flash_mdev __initdata = NULL;
/* MTD Information */
-struct mtd_info *vmu_flash_mtd = NULL;
+static struct mtd_info *vmu_flash_mtd = NULL;
-/* Instance variables - not statics */
-struct mapleq *lastmq;
-struct maple_driver dc_flashmap_driver;
-int flash_queried = 0;
+static struct mapleq *lastmq;
+static struct maple_driver dc_flashmap_driver;
-char *block_buffer = NULL;
+static int flash_queried = 0;
+
+static char *block_buffer = NULL;
/* Memory card details */
typedef struct memcard_s {
long partitions;
- long blocks;
+ long blocklen;
long writecnt;
long readcnt;
long removable;
@@ -64,7 +65,7 @@
} vmu_cache_t;
-vmu_cache_t *vmu_cache = NULL;
+static vmu_cache_t *vmu_cache = NULL;
wait_queue_head_t wq_mq;
DECLARE_WAIT_QUEUE_HEAD(wq_mq);
@@ -72,7 +73,7 @@
/*************************************/
/**********Read and write routines*************/
-int maple_vmu_read_block(unsigned int num, u_char * buf)
+static int maple_vmu_read_block(unsigned int num, u_char * buf)
{
/* async maple call
@@ -130,7 +131,7 @@
}
-int maple_vmu_write_block(unsigned int num, u_char * buf)
+static int maple_vmu_write_block(unsigned int num, u_char * buf)
{
/* This function does not have to sleep */
@@ -330,7 +331,7 @@
/***********************************************/
/* Read and Write routines */
-int vmu_flash_read(struct mtd_info *mtd, loff_t from, size_t len,
+static int vmu_flash_read(struct mtd_info *mtd, loff_t from, size_t len,
size_t * retlen, u_char * buf)
{
/* printk("Reading from %llx with length %llx\n", from, len); */
@@ -356,7 +357,7 @@
}
-int vmu_flash_write(struct mtd_info *mtd, loff_t from, size_t len,
+static int vmu_flash_write(struct mtd_info *mtd, loff_t from, size_t len,
size_t * retlen, const u_char * buf)
{
if (len < 1)
@@ -370,7 +371,7 @@
return 0;
}
-int vmu_flash_erase(struct mtd_info *mtd, struct erase_info *erase)
+static int vmu_flash_erase(struct mtd_info *mtd, struct erase_info *erase)
{
int z;
vmu_flash_write(mtd, erase->addr, erase->len, &z, "\0");
@@ -378,7 +379,7 @@
return 0;
}
-void vmu_flash_sync(struct mtd_info *mtd)
+static void vmu_flash_sync(struct mtd_info *mtd)
{
/* Do nothing */
}
@@ -434,8 +435,6 @@
if (flash_queried == 0) {
if (mq->recvbuf[0] == 5) {
- int res = mq->recvbuf[0];
-
lastmq = mq;
flash_queried = 1;
wake_up_interruptible(&wq_mq); /* Wake sleeping code */
@@ -504,44 +503,63 @@
/* 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]);
+ 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;
+ }
+
+ /* Only device with a lower index is a controller */
unsigned long basic_flash_data =
- be32_to_cpu(((unsigned long *) (lastmq->recvbuf))[4]);
+ be32_to_cpu(((unsigned long *) (lastmq->recvbuf))[1 + bit_cnt - controller_here]);
+
+
/* Create a permanent record */
/* With thanks to Marcus Comstedt */
memcard_t *card = kmalloc(sizeof(memcard_t), GFP_KERNEL);
card->partitions = ((basic_flash_data >> 24) & 0xff) + 1;
- printk("\tFlash device has %ld partitions\n", card->partitions);
- card->blocks = (((basic_flash_data >> 16) & 0xff) + 1) << 5;
- printk("\tFlash device has %ld blocks \n", card->blocks);
+ 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);
card->writecnt = (basic_flash_data >> 12) & 0xf;
- printk("\tFlash 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("\tFlash 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("\tFlash device removable status is %ld\n",
+ 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;
lastmq = NULL;
- /* Now query each flash partition */
+ /* Now query each flash partition 0 */
/* Register the flash with mtd subsystem */
if (!vmu_flash_mtd) {
/* Populate a mtd_info */
- vmu_flash_mtd = kmalloc(1000, GFP_KERNEL);
+ 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 = 0;
- vmu_flash_mtd->size = 1024 * 128; /* 128k */
- vmu_flash_mtd->erasesize = 512;
+ 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;
@@ -605,7 +623,7 @@
/***********Maple device*****************/
-struct maple_driver dc_flashmap_driver = {
+static struct maple_driver dc_flashmap_driver = {
function:MAPLE_FUNC_MEMCARD,
name:"VMU Flash Memory",
connect:dc_flashmap_connect,
|