00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef _SLOT_USHC_H
00010 #define _SLOT_USHC_H
00011
00012 #include <oska/io.h>
00013
00014 enum ushc_request
00015 {
00016 USHC_GET_CAPS = 0x00,
00017 USHC_HOST_CTRL = 0x01,
00018 USHC_PWR_CTRL = 0x02,
00019 USHC_CLK_FREQ = 0x03,
00020 USHC_EXEC_CMD = 0x04,
00021 USHC_READ_RESP = 0x05,
00022 USHC_RESET = 0x06
00023 };
00024
00025 enum ushc_request_recipient
00026 {
00027 USHC_RECIPIENT_DEVICE = 0x00,
00028 USHC_RECIPIENT_INTERFACE = 0x01,
00029 USHC_RECIPIENT_ENDPOINT = 0x02,
00030 USHC_RECIPIENT_OTHER = 0x03
00031 };
00032
00033 enum ushc_request_direction
00034 {
00035 USHC_HOST_TO_DEVICE = 0x00,
00036 USHC_DEVICE_TO_HOST = 0x01
00037 };
00038
00039 struct sdioemb_ushc
00040 {
00041 struct sdioemb_slot *slot;
00042
00043 void (*enable_int)(struct sdioemb_slot *slot, uint32_t ints);
00044 void (*disable_int)(struct sdioemb_slot *slot, uint32_t ints);
00045 void (*cmd_complete)(struct sdioemb_slot *slot, struct sdioemb_cmd *cmd);
00046 int (*set_host_ctrl)(struct sdioemb_slot *slot, uint16_t controler_state);
00047 int (*submit_vendor_request)(struct sdioemb_slot *slot,
00048 enum ushc_request request,
00049 enum ushc_request_direction direction,
00050 enum ushc_request_recipient recipient,
00051 uint16_t value,
00052 uint16_t index,
00053 void* io_buffer,
00054 uint32_t io_buffer_length);
00055 int (*submit_cbw_request)(struct sdioemb_slot *slot, uint8_t cmd_index, uint16_t block_size, uint32_t cmd_arg);
00056 int (*submit_data_request)(struct sdioemb_slot *slot,
00057 enum ushc_request_direction direction,
00058 void* request_buffer,
00059 uint32_t request_buffer_length);
00060 int (*submit_csw_request)(struct sdioemb_slot *slot);
00061
00062 os_spinlock_t lock;
00063
00064 uint32_t base_clock;
00065 uint32_t controler_capabilities;
00066 uint16_t controler_state;
00067 struct sdioemb_cmd* current_cmd;
00068
00069 #define DISCONNECTED 0
00070 #define INT_EN 1
00071 #define IGNORE_NEXT_INT 2
00072 #define STOP 4
00073 uint32_t flags;
00074
00075 #define USHC_INT_STATUS_SDIO_INT (1 << 1)
00076 #define USHC_INT_STATUS_CARD_PRESENT (1 << 0)
00077 uint8_t interrupt_status;
00078
00079 size_t block_size;
00080 };
00081
00082 #define USHC_GET_CAPS_VERSION_MASK 0xff
00083 #define USHC_GET_CAPS_3V3 (1 << 8)
00084 #define USHC_GET_CAPS_3V0 (1 << 9)
00085 #define USHC_GET_CAPS_1V8 (1 << 10)
00086 #define USHC_GET_CAPS_HIGH_SPD (1 << 16)
00087
00088 #define USHC_PWR_CTRL_OFF 0x00
00089 #define USHC_PWR_CTRL_3V3 0x01
00090 #define USHC_PWR_CTRL_3V0 0x02
00091 #define USHC_PWR_CTRL_1V8 0x03
00092
00093 #define USHC_HOST_CTRL_4BIT (1 << 1)
00094 #define USHC_HOST_CTRL_HIGH_SPD (1 << 0)
00095
00096 #define USHC_READ_RESP_BUSY (1 << 4)
00097 #define USHC_READ_RESP_ERR_TIMEOUT (1 << 3)
00098 #define USHC_READ_RESP_ERR_CRC (1 << 2)
00099 #define USHC_READ_RESP_ERR_DAT (1 << 1)
00100 #define USHC_READ_RESP_ERR_CMD (1 << 0)
00101 #define USHC_READ_RESP_ERR_MASK 0x0f
00102
00103 void sdioemb_ushc_init(struct sdioemb_ushc* ushc);
00104 void sdioemb_ushc_clean_up(struct sdioemb_ushc* ushc);
00105
00106 int sdioemb_ushc_start(struct sdioemb_ushc* ushc);
00107 void sdioemb_ushc_stop(struct sdioemb_ushc* ushc);
00108
00109 bool sdioemb_ushc_isr(struct sdioemb_ushc* ushc, uint8_t int_stat);
00110
00111 int sdioemb_ushc_set_bus_freq(struct sdioemb_ushc* ushc, int clk);
00112 int sdioemb_ushc_set_bus_width(struct sdioemb_ushc* ushc, int bus_width);
00113 int sdioemb_ushc_start_cmd(struct sdioemb_ushc* ushc, struct sdioemb_cmd *cmd);
00114 int sdioemb_ushc_card_present(struct sdioemb_ushc* ushc);
00115 int sdioemb_ushc_card_power(struct sdioemb_ushc* ushc, enum sdioemb_power power);
00116 void sdioemb_ushc_enable_card_int(struct sdioemb_ushc* ushc);
00117 void sdioemb_ushc_disable_card_int(struct sdioemb_ushc* ushc);
00118 int sdioemb_ushc_hard_reset(struct sdioemb_ushc* ushc);
00119
00120 void sdioemb_ushc_command_complete(struct sdioemb_ushc* ushc, uint8_t status, uint32_t respones);
00121
00122 int ushc_hw_get_caps(struct sdioemb_ushc* ushc);
00123 static int ushc_hw_set_host_ctrl(struct sdioemb_ushc* ushc, uint16_t mask, uint16_t val);
00124 static int ushc_hw_submit_vendor_request(struct sdioemb_ushc* ushc,
00125 enum ushc_request request,
00126 enum ushc_request_recipient recipient,
00127 enum ushc_request_direction direction,
00128 uint16_t value,
00129 uint16_t index,
00130 void* io_buffer,
00131 uint32_t io_buffer_length);
00132
00133 #endif