11 #include <linux/slab.h>
12 #include <linux/sched.h>
58 static struct vmu_block *ofs_to_block(
unsigned long src_ofs,
71 if (src_ofs >= card->
parts[partition].numblocks * card->
blocklen)
75 if (num > card->
parts[partition].numblocks)
91 static void vmu_blockread(
struct mapleq *mq)
111 static int maple_vmu_read_block(
unsigned int num,
unsigned char *
buf,
118 unsigned char *blockread =
NULL;
126 pcache = card->
parts[partition].pcache;
133 dev_err(&mdev->
dev,
"VMU at (%d, %d) - read fails due"
134 " to lack of memory\n", mdev->
port,
153 dev_notice(&mdev->
dev,
"VMU at (%d, %d)"
154 " is busy\n", mdev->
port, mdev->
unit);
193 list_del_init(&(mdev->
mq->list));
198 " interrupted on block 0x%X\n",
201 dev_notice(&mdev->
dev,
"VMU read on (%d, %d)"
202 " timed out on block 0x%X\n",
228 static int maple_vmu_write_block(
unsigned int num,
const unsigned char *buf,
234 int partition,
error, locking,
x, phaselen,
wait;
249 for (x = 0; x < card->
writecnt; x++) {
250 sendbuf[0] =
cpu_to_be32(partition << 24 | x << 16 | num);
251 memcpy(&sendbuf[1], buf + phaselen * x, phaselen);
259 dev_notice(&mdev->
dev,
"VMU write at (%d, %d)"
260 "failed - device is busy\n",
281 " 0x%X at phase %d failed: could not"
282 " communicate with VMU", mdev->
port,
287 list_del_init(&(mdev->
mq->list));
304 static unsigned char vmu_flash_read_char(
unsigned long ofs,
int *
retval,
312 int partition,
error;
327 vblock = ofs_to_block(ofs, mtd, partition);
334 error = maple_vmu_read_block(vblock->
num, buf, mtd);
341 ret = buf[vblock->
ofs];
352 static int vmu_flash_read(
struct mtd_info *mtd, loff_t
from,
size_t len,
353 size_t *retlen,
u_char *buf)
360 int index = 0,
retval, partition, leftover, numblocks;
368 numblocks = card->
parts[partition].numblocks;
369 if (from + len > numblocks * card->
blocklen)
374 pcache = card->
parts[partition].pcache;
376 vblock = ofs_to_block(from + index, mtd, partition);
385 if (vblock->
ofs + len - index < card->blocklen) {
394 vblock->
ofs, leftover);
402 cx = vmu_flash_read_char(from + index, &retval, mtd);
408 memset(buf + index, cx, 1);
412 }
while (len > index);
418 static int vmu_flash_write(
struct mtd_info *mtd, loff_t to,
size_t len,
419 size_t *retlen,
const u_char *buf)
424 int index = 0,
partition, error = 0, numblocks;
434 numblocks = card->
parts[partition].numblocks;
435 if (to + len > numblocks * card->
blocklen)
436 len = numblocks * card->
blocklen - to;
442 vblock = ofs_to_block(to, mtd, partition);
456 error = maple_vmu_read_block(vblock->
num, buffer, mtd);
469 error = maple_vmu_write_block(vblock->
num, buffer, mtd);
471 pcache = card->
parts[partition].pcache;
479 }
while (len > index);
491 dev_err(&mdev->
dev,
"VMU write failing with error %d\n", error);
495 static void vmu_flash_sync(
struct mtd_info *mtd)
501 static void vmu_queryblocks(
struct mapleq *mq)
515 res = (
unsigned short *) (mq->
recvbuf->buf);
516 card->
tempA = res[12];
517 card->
tempB = res[6];
519 dev_info(&mdev->
dev,
"VMU device at partition %d has %d user "
520 "blocks with a root block at %d\n", card->
partition,
539 mtd_cur->
_write = vmu_flash_write;
540 mtd_cur->
_read = vmu_flash_read;
541 mtd_cur->
_sync = vmu_flash_sync;
550 mtd_cur->
priv = mpart;
555 goto fail_cache_create;
560 goto fail_mtd_register;
579 dev_err(&mdev->
dev,
"Could not register maple device at (%d, %d)"
580 "error is 0x%X\n", mdev->
port, mdev->
unit, error);
581 for (error = 0; error <= card->
partition; error++) {
587 for (error = 0; error <= card->
partition; error++) {
589 ((card->
mtd)[error]).priv =
NULL;
601 unsigned long test_flash_data, basic_flash_data;
610 c = hweight_long(test_flash_data);
620 card->
partitions = (basic_flash_data >> 24 & 0xFF) + 1;
621 card->
blocklen = ((basic_flash_data >> 16 & 0xFF) + 1) << 5;
622 card->
writecnt = basic_flash_data >> 12 & 0xF;
623 card->
readcnt = basic_flash_data >> 8 & 0xF;
636 goto fail_partitions;
661 dev_notice(&mdev->
dev,
"VMU at (%d, %d) is busy\n",
664 goto fail_device_busy;
677 dev_err(&mdev->
dev,
"Could not lock VMU at (%d, %d)"
678 " error is 0x%X\n", mdev->
port, mdev->
unit, error);
702 mpart = ((card->
mtd)[x]).priv;
723 mtd = &((card->
mtd)[x]);
730 #define ERRSTR "VMU at (%d, %d) file error -"
732 static void vmu_file_error(
struct maple_device *mdev,
void *recvbuf)
739 dev_notice(&mdev->
dev,
ERRSTR " invalid partition number\n",
744 dev_notice(&mdev->
dev,
ERRSTR " phase error\n",
749 dev_notice(&mdev->
dev,
ERRSTR " invalid block number\n",
754 dev_notice(&mdev->
dev,
ERRSTR " write error\n",
759 dev_notice(&mdev->
dev,
ERRSTR " invalid write length\n",
764 dev_notice(&mdev->
dev,
ERRSTR " bad CRC\n",
785 error = vmu_connect(mdev);
796 vmu_disconnect(mdev);
803 .name =
"Dreamcast_visual_memory",
804 .probe = probe_maple_vmu,
809 static int __init vmu_flash_map_init(
void)
814 static void __exit vmu_flash_map_exit(
void)