From 902d0adac02cef7623d71aec112807822ba822cb Mon Sep 17 00:00:00 2001 From: bushing Date: Sun, 1 Feb 2009 02:50:59 -0800 Subject: [PATCH] added code to support IPC for SDHC --- ipc.c | 4 ++++ ipc.h | 6 ++--- sdhc.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- sdhc.h | 6 +++++ 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/ipc.c b/ipc.c index 1994f75..77eaca7 100644 --- a/ipc.c +++ b/ipc.c @@ -7,6 +7,7 @@ #include "gecko.h" #include "ipc.h" #include "nand.h" +#include "sdhc.h" #include "crypto.h" static volatile ipc_request in_queue[IPC_IN_SIZE] ALIGNED(32) MEM2_BSS; @@ -96,6 +97,9 @@ static int process_slow(volatile ipc_request *req) case IPC_DEV_NAND: nand_ipc(req); break; + case IPC_DEV_SD: + sd_ipc(req); + break; case IPC_DEV_KEYS: crypto_ipc(req); break; diff --git a/ipc.h b/ipc.h index 9feecaa..3e167cc 100644 --- a/ipc.h +++ b/ipc.h @@ -37,9 +37,9 @@ #define IPC_NAND_WRITE 0x0003 #define IPC_NAND_ERASE 0x0004 -#define IPC_SD_RESET 0x0000 -#define IPC_SD_GETSTATUS 0x0001 -#define IPC_SD_GETSIZE 0x0002 +#define IPC_SD_MOUNT 0x0000 +#define IPC_SD_SELECT 0x0001 +#define IPC_SD_GETSTATE 0x0002 #define IPC_SD_READ 0x0003 #define IPC_SD_WRITE 0x0004 diff --git a/sdhc.c b/sdhc.c index 38218bc..a62ef27 100644 --- a/sdhc.c +++ b/sdhc.c @@ -178,6 +178,22 @@ #define EINTERRUPT_ALL 0x3ff +static int ipc_code = 0; +static int ipc_tag = 0; +static sdhci_t sdhci; + +// not currently used :( +void sd_irq(void) +{ + int code, tag; + if (ipc_code != 0) { + code = ipc_code; + tag = ipc_tag; + ipc_code = ipc_tag = 0; + ipc_post(code, tag, 0); + } +} + u8 __sd_read8(u32 addr) { u32 mask; @@ -449,7 +465,7 @@ static int __sd_power(sdhci_t *sdhci, int vdd) if(!(caps & vdd)) { - sdhc_error(sdhci->reg_base, "voltage %x not supported by the hc"); + sdhc_error(sdhci->reg_base, "voltage %x not supported by the hc", vdd); return SDHC_EINVAL; } @@ -1046,3 +1062,54 @@ int sd_write(sdhci_t *sdhci, u32 start_block, u32 blk_cnt, const void *buffer) } #endif + +void sd_initialize(void) +{ + ipc_code = ipc_tag = 0; + sd_init(&sdhci, 0); +// irq_enable(IRQ_NAND); ?? +} + +void sd_ipc(volatile ipc_request *req) +{ + int retval = 0; + if (ipc_code != 0 || ipc_tag != 0) { + gecko_printf("SDHC: previous IPC request is not done yet."); + ipc_post(req->code, req->tag, 1, -1); + return; + } + + switch (req->req) { + case IPC_SD_MOUNT: + retval = sd_mount(&sdhci); + ipc_post(req->code, req->tag, 1, retval); + break; + + case IPC_SD_SELECT: + retval = sd_select(&sdhci); + ipc_post(req->code, req->tag, 1, retval); + break; + + case IPC_SD_GETSTATE: + retval = __sd_read32(sdhci.reg_base + SDHC_PRESENT_STATE); + ipc_post(req->code, req->tag, 1, retval); + break; + + case IPC_SD_READ: + retval = sd_read(&sdhci, req->args[0], req->args[1], + (void *)req->args[2]); + ipc_post(req->code, req->tag, 1, retval); + break; + + case IPC_SD_WRITE: + retval = sd_write(&sdhci, req->args[0], req->args[1], + (void *)req->args[2]); + ipc_post(req->code, req->tag, 1, retval); + break; + + default: + gecko_printf("IPC: unknown SLOW NAND request %04x\n", + req->req); + + } +} diff --git a/sdhc.h b/sdhc.h index 4290216..083c476 100644 --- a/sdhc.h +++ b/sdhc.h @@ -2,6 +2,7 @@ #define __SDHC_H__ #include "types.h" +#include "ipc.h" #define SDHC_ENOCARD -0x1001 #define SDHC_ESTRANGE -0x1002 @@ -33,6 +34,11 @@ int sd_select(sdhci_t *sdhci); int sd_read(sdhci_t *sdhci, u32 start_block, u32 blk_cnt, void *buffer); int sd_write(sdhci_t *sdhci, u32 start_block, u32 blk_cnt, const void *buffer); +void sd_irq(void); +void sd_initialize(); + +void sd_ipc(volatile ipc_request *req); + u8 __sd_read8(u32 addr); u16 __sd_read16(u32 addr); u32 __sd_read32(u32 addr);