|
From: Adrian M. <ad...@mc...> - 2002-08-15 23:07:42
|
As some of you might know, I am attempting to write a working vmu flash
driver. The diff below produces code that compiles but will not link
(functions still to be written). If anybody cares to comment, I am only too
happy to hear it.
--- vmu-old.c Fri Aug 16 00:05:22 2002
+++ vmu-flash.c Thu Aug 15 21:48:49 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,29 @@
/* MTD Information */
static struct mtd_info *vmu_flash_mtd = NULL;
+/* Persistent result */
+static struct mapleq lastmq;
+static struct maple_driver dc_flashmap_driver;
+
+
/* 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){
+ return 0;
+}
+
+int maple_vmu_write_block(unsigned int num, u_char *buf){
+ return 0;
+}
+/*************************************/
+
+
/**
* __ofs_to_block - Offset to Block Conversion
*
@@ -90,7 +111,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 +126,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 +150,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 +165,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 +175,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 +184,11 @@
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 routines */
+
+int vmu_flash_read(struct mtd_info *mtd, loff_t from, size_t len, u_char
*buf);
+int vmu_flash_write(struct mtd_info *mtd, loff_t to, size_t len, const u_char
*buf);
/**
* vmu_flash_map_init - Initialization
@@ -178,23 +198,12 @@
*/
static int __init vmu_flash_map_init(void)
{
- printk(KERN_NOTICE "Regestering VMU flash mapping\n");
+ 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 */
- /* Look for the flash */
- vmu_flash_mtd = do_map_probe("cfi", &vmu_flash_map);
-
- /* See if it's valid */
- if (!vmu_flash_mtd) {
- printk(KERN_ERR "Failed to setup flash map\n");
- return -ENXIO;
- }
-
- vmu_flash_mtd->module = THIS_MODULE;
- /* Register with MTD */
- add_mtd_device(vmu_flash_mtd);
return 0;
}
@@ -208,7 +217,7 @@
static void __exit vmu_flash_map_exit(void)
{
printk(KERN_NOTICE "Unregestering VMU flash mapping\n");
-
+ maple_unregister_driver(&dc_flashmap_driver);
/* See if there's anything to unregister */
if (!vmu_flash_mtd) {
printk(KERN_WARNING "Nothing to unregister\n");
@@ -220,6 +229,98 @@
map_destroy(vmu_flash_mtd);
}
+/***********Maple functions***************/
+
+
+static void dc_flashmap_callback(struct maple_driver_data *data)
+{
+
+
+ struct mapleq *mq = &data->mq;
+ if (mq->recvbuf[0] == 8){
+ /*Have data returned*/
+
+
+ /*********TO DO: Data copying routines here***************/
+
+ return;
+ }
+ else if (mq->recvbuf[0] == 7) printk("Data transferred\n");
+ else printk(KERN_WARNING "Transfer failed\n");
+}
+
+
+
+static int dc_flashmap_connect(struct maple_driver_data *d)
+{
+ printk("Registering VMU Flash mapping and loading VMU Flash driver\n");
+ /* Look for the flash */
+ if (!vmu_flash_mtd){
+ /* Populate a mtd_info */
+ vmu_flash_mtd = kmalloc(GFP_KERNEL, 1000);
+ vmu_flash_mtd->name="Dreamcast VMU Flash";
+
+ /* This is 'other'*/
+ vmu_flash_mtd->type = MTD_OTHER;
+ vmu_flash_mtd->flags = 0;
+
+ /* Mandatory functions */
+ vmu_flash_mtd->write = vmu_flash_write;
+ vmu_flash_mtd->read = vmu_flash_read;
+ }
+ /* See if it's valid */
+ if (!vmu_flash_mtd) {
+ printk(KERN_ERR "Failed to setup flash map\n");
+ return -ENXIO;
+ }
+ printk("VMU FLASH: mapping successful\n");
+
+ vmu_flash_mtd->module = THIS_MODULE;
+
+ /* Register with MTD */
+ add_mtd_device(vmu_flash_mtd);
+
+ return 0;
+}
+
+static void dc_flashmap_disconnect(struct maple_driver_data *d)
+{
+printk(KERN_NOTICE "Unregistering VMU flash mapping\n");
+
+ /* See if there's anything to unregister */
+ if (!vmu_flash_mtd) {
+ printk(KERN_WARNING "Nothing to unregister\n");
+ return;
+ }
+
+
+ if (vmu_flash_mtd){
+ /* Unregister from MTD */
+ del_mtd_device(vmu_flash_mtd);
+ map_destroy(vmu_flash_mtd);
+ vmu_flash_mtd = NULL;
+ }
+
+
+}
+
+
+/***********Maple device*****************/
+static struct maple_driver dc_flashmap_driver = {
+ function: MAPLE_FUNC_MEMCARD,
+ name:"VMU Flash Memory",
+ connect:dc_flashmap_connect,
+ disconnect:dc_flashmap_disconnect,
+ reply:dc_flashmap_callback,
+
+
+};
+
+
+
+
+
+
module_init(vmu_flash_map_init);
module_exit(vmu_flash_map_exit);
|