/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */

#ident "$Id: sd.h,v 1.2 2005/12/21 03:54:39 gbarnard Exp $"

#define MAX_DEV 4

typedef enum _status {
    st_illegal, /* not an error but an invalid value */
    st_success,
    st_fail_bad_op,
    st_fail_no_ops,
    st_fail_no_slots,
    st_fail_bad_slot_count,
    st_fail_no_sdh,
    st_fail_bad_slot_window,
} status_t;

typedef enum SDStatusCode
{
        SD_STATUS_SUCCESS                         = 0x00000000L,
        SD_STATUS_PENDING                         = 0x00000001L,
        SD_STATUS_BUFFER_OVERFLOW                 = 0xC0000001L,
        SD_STATUS_DEVICE_BUSY                     = 0xC0000002L,
        SD_STATUS_UNSUCCESSFUL                    = 0xC0000003L,
        SD_STATUS_NOT_IMPLEMENTED                 = 0xC0000004L,
        SD_STATUS_ACCESS_VIOLATION                = 0xC0000005L,
        SD_STATUS_INVALID_HANDLE                  = 0xC0000006L,
        SD_STATUS_INVALID_PARAMETER               = 0xC0000007L,
        SD_STATUS_NO_SUCH_DEVICE                  = 0xC0000008L,
        SD_STATUS_INVALID_DEVICE_REQUEST          = 0xC0000009L,
        SD_STATUS_NO_MEMORY                       = 0xC000000AL,
        SD_STATUS_BUS_DRIVER_NOT_READY            = 0xC000000BL,
        SD_STATUS_DATA_ERROR                      = 0xC000000CL,
        SD_STATUS_CRC_ERROR                       = 0xC000000DL,
        SD_STATUS_INSUFFICIENT_RESOURCES          = 0xC000000EL,
        SD_STATUS_DEVICE_NOT_CONNECTED            = 0xC0000010L,
        SD_STATUS_DEVICE_REMOVED                  = 0xC0000011L,
        SD_STATUS_DEVICE_NOT_RESPONDING           = 0xC0000012L,
        SD_STATUS_CANCELED                        = 0xC0000013L,
        SD_STATUS_RESPONSE_TIMEOUT                = 0xC0000014L,
        SD_STATUS_DATA_TIMEOUT                    = 0xC0000015L,
        SD_STATUS_DEVICE_RESPONSE_ERROR           = 0xC0000016L,
        SD_STATUS_DEVICE_UNSUPPORTED              = 0xC0000017L,
        SD_STATUS_SHUT_DOWN                       = 0xC0000018L,
        SD_STATUS_OUT_OF_RANGE                    = 0xC0000019L,
        SD_STATUS_FUNCTION_NUMBER_ERR             = 0xC0000020L,
        SD_STATUS_ILLEGAL_CMD                     = 0xC0000021L,
        SD_STATUS_CMD_TIMEOUT                     = 0xC0000022L,
        SD_STATUS_UNKNOWN_ERR                     = 0xC0000023L
} SD_API_STATUS;

/*
 * enum for response types 
 */
typedef enum  _sd_response_type
{
    NoResponse  = 0,
    ResponseR1  = 1,
    ResponseR1b = 2,
    ResponseR2  = 3,
    ResponseR3  = 4,
    ResponseR4  = 5,
    ResponseR5  = 6,
    ResponseR6  = 7
} sd_response_type;

#define NUM_RESP_REGS 8
/*
 * Global memory structure passed to bus driver.
 * 
 * command: to execute.
 * commmand type: read write.
 * response type: R4, etc
 * req_size: for block copy.
 * response: response for results from resp0-7.
 * callback: callback for async
 * callback_on_irq: on which irqs do we want callback to be called
 */
typedef struct _sd_request {
    unsigned int command;
    unsigned int cmd_type;
    unsigned int resp_type;
    unsigned int req_size;
    unsigned int cmd_arg;
    unsigned int cmd_wait;
    unsigned int status;
    unsigned int norint;
    unsigned int (*callback)(void *arg);
    unsigned int callback_on_irq;
    unsigned int heartbeat;
    unsigned short response[NUM_RESP_REGS];
} sd_request;


/*
 * Inlines
 */

/*
 * Prototypes
 */

/*
 * sdstdhost.c
 */
extern u8 READ_HOST_U8(u32 base, u16 reg);
extern void WRITE_HOST_U8(u32 base, u16 reg, u8 val);
extern u16 READ_HOST_U16(u32 base, u16 reg);
extern void WRITE_HOST_U16(u32 base, u16 reg, u16 val);
extern u32 READ_HOST_U32(u32 base, u16 reg);
extern void WRITE_HOST_U32(u32 base, u16 reg, u32 val);

/*
 * sd-pci.c
 */
extern char *decode_status (status_t status);

/* eof */
