Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * SDIO-Abstraction-Layer internal interface. |
| 15 | */ |
| 16 | |
| 17 | #ifndef __SDIO_AL_PRIVATE__ |
| 18 | #define __SDIO_AL_PRIVATE__ |
| 19 | |
| 20 | #include <linux/mmc/card.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <mach/sdio_al.h> |
| 23 | |
| 24 | #define DRV_VERSION "1.30" |
| 25 | #define MODULE_NAME "sdio_al" |
| 26 | #define SDIOC_CHAN_TO_FUNC_NUM(x) ((x)+2) |
| 27 | #define REAL_FUNC_TO_FUNC_IN_ARRAY(x) ((x)-1) |
| 28 | #define SDIO_PREFIX "SDIO_" |
| 29 | #define PEER_CHANNEL_NAME_SIZE 4 |
| 30 | #define CHANNEL_NAME_SIZE (sizeof(SDIO_PREFIX) + PEER_CHANNEL_NAME_SIZE) |
| 31 | #define SDIO_TEST_POSTFIX_SIZE 5 |
Yaniv Gardi | 3e32776 | 2011-07-27 11:11:04 +0300 | [diff] [blame] | 32 | #define MAX_NUM_OF_SDIO_DEVICES 2 |
Maya Erez | 8afd564f | 2011-08-24 15:57:06 +0300 | [diff] [blame] | 33 | #define TEST_CH_NAME_SIZE (CHANNEL_NAME_SIZE + SDIO_TEST_POSTFIX_SIZE) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 34 | |
| 35 | struct sdio_al_device; /* Forward Declaration */ |
| 36 | |
Konstantin Dorfman | ee2e308 | 2011-08-16 15:12:01 +0300 | [diff] [blame] | 37 | enum sdio_channel_state { |
| 38 | SDIO_CHANNEL_STATE_INVALID, /* before reading software header */ |
| 39 | SDIO_CHANNEL_STATE_IDLE, /* channel valid, not opened */ |
| 40 | SDIO_CHANNEL_STATE_CLOSED, /* was closed */ |
| 41 | SDIO_CHANNEL_STATE_OPEN, /* opened */ |
| 42 | SDIO_CHANNEL_STATE_CLOSING, /* during flush, when closing */ |
| 43 | }; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Peer SDIO-Client channel configuration. |
| 46 | * |
| 47 | * @is_ready - channel is ready and the data is valid. |
| 48 | * |
| 49 | * @max_rx_threshold - maximum rx threshold, according to the |
| 50 | * total buffers size on the peer pipe. |
| 51 | * @max_tx_threshold - maximum tx threshold, according to the |
| 52 | * total buffers size on the peer pipe. |
| 53 | * @tx_buf_size - size of a single buffer on the peer pipe; a |
| 54 | * transfer smaller than the buffer size still |
| 55 | * make the buffer unusable for the next transfer. |
| 56 | * @max_packet_size |
| 57 | * @is_host_ok_to_sleep - Host marks this bit when it's okay to |
| 58 | * sleep (no pending transactions) |
| 59 | */ |
| 60 | struct peer_sdioc_channel_config { |
| 61 | u32 is_ready; |
| 62 | u32 max_rx_threshold; /* Downlink */ |
| 63 | u32 max_tx_threshold; /* Uplink */ |
| 64 | u32 tx_buf_size; |
| 65 | u32 max_packet_size; |
| 66 | u32 is_host_ok_to_sleep; |
| 67 | u32 is_packet_mode; |
Konstantin Dorfman | ee2e308 | 2011-08-16 15:12:01 +0300 | [diff] [blame] | 68 | u32 peer_operation; |
Maya Erez | 3eb7d4c | 2011-10-17 15:08:42 +0200 | [diff] [blame] | 69 | u32 is_low_latency_ch; |
| 70 | u32 reserved[23]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | |
| 74 | /** |
| 75 | * Peer SDIO-Client channel statsitics. |
| 76 | * |
| 77 | * @last_any_read_avail - the last read avail in all the |
| 78 | * channels including this channel. |
| 79 | * @last_read_avail - the last read_avail that was read from HW |
| 80 | * mailbox. |
| 81 | * @last_old_read_avail - the last read_avail channel shadow. |
| 82 | * @total_notifs - the total number of read notifications sent |
| 83 | * to this channel client |
| 84 | * @total_read_times - the total number of successful sdio_read |
| 85 | * calls for this channel |
| 86 | */ |
| 87 | struct sdio_channel_statistics { |
| 88 | int last_any_read_avail; |
| 89 | int last_read_avail; |
| 90 | int last_old_read_avail; |
| 91 | int total_notifs; |
| 92 | int total_read_times; |
| 93 | }; |
| 94 | |
| 95 | /** |
| 96 | * SDIO Channel context. |
| 97 | * |
| 98 | * @name - channel name. Used by the caller to open the |
| 99 | * channel. |
| 100 | * |
| 101 | * @read_threshold - Threshold on SDIO-Client mailbox for Rx |
| 102 | * Data available bytes. When the limit exceed |
| 103 | * the SDIO-Client generates an interrupt to the |
| 104 | * host. |
| 105 | * |
| 106 | * @write_threshold - Threshold on SDIO-Client mailbox for Tx |
| 107 | * Data available bytes. When the limit exceed |
| 108 | * the SDIO-Client generates an interrupt to the |
| 109 | * host. |
| 110 | * |
| 111 | * @def_read_threshold - Default theshold on SDIO-Client for Rx |
| 112 | * |
| 113 | * @min_write_avail - Threshold of minimal available bytes |
| 114 | * to write. Below that threshold the host |
| 115 | * will initiate reading the mailbox. |
| 116 | * |
| 117 | * @poll_delay_msec - Delay between polling the mailbox. When |
| 118 | * the SDIO-Client doesn't generates EOT |
| 119 | * interrupt for Rx Available bytes, the host |
| 120 | * should poll the SDIO-Client mailbox. |
| 121 | * |
| 122 | * @is_packet_mode - The host get interrupt when a packet is |
| 123 | * available at the SDIO-client (pipe EOT |
| 124 | * indication). |
| 125 | * |
| 126 | * @num - channel number. |
| 127 | * |
| 128 | * @notify - Client's callback. Should not call sdio read/write. |
| 129 | * |
| 130 | * @priv - Client's private context, provided to callback. |
| 131 | * |
| 132 | * @is_valid - Channel is used (we have a list of |
| 133 | * SDIO_AL_MAX_CHANNELS and not all of them are in |
| 134 | * use). |
| 135 | * |
| 136 | * @is_open - Channel is open. |
| 137 | * |
| 138 | * @func - SDIO Function handle. |
| 139 | * |
| 140 | * @rx_pipe_index - SDIO-Client Pipe Index for Rx Data. |
| 141 | * |
| 142 | * @tx_pipe_index - SDIO-Client Pipe Index for Tx Data. |
| 143 | * |
| 144 | * @ch_lock - Channel lock to protect channel specific Data |
| 145 | * |
| 146 | * @rx_pending_bytes - Total number of Rx pending bytes, at Rx |
| 147 | * packet list. Maximum of 16KB-1 limited by |
| 148 | * SDIO-Client specification. |
| 149 | * |
| 150 | * @read_avail - Available bytes to read. |
| 151 | * |
| 152 | * @write_avail - Available bytes to write. |
| 153 | * |
| 154 | * @rx_size_list_head - The head of Rx Pending Packets List. |
| 155 | * |
| 156 | * @pdev - platform device - clients to probe for the sdio-al. |
| 157 | * |
| 158 | * @signature - Context Validity check. |
| 159 | * |
| 160 | * @sdio_al_dev - a pointer to the sdio_al_device instance of |
| 161 | * this channel |
| 162 | * |
| 163 | * @statistics - channel statistics |
| 164 | * |
| 165 | */ |
| 166 | struct sdio_channel { |
| 167 | /* Channel Configuration Parameters*/ |
| 168 | char name[CHANNEL_NAME_SIZE]; |
Maya Erez | 8afd564f | 2011-08-24 15:57:06 +0300 | [diff] [blame] | 169 | char ch_test_name[TEST_CH_NAME_SIZE]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 170 | int read_threshold; |
| 171 | int write_threshold; |
| 172 | int def_read_threshold; |
Maya Erez | 8ed0a9a | 2011-07-19 14:46:53 +0300 | [diff] [blame] | 173 | int threshold_change_cnt; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 174 | int min_write_avail; |
| 175 | int poll_delay_msec; |
| 176 | int is_packet_mode; |
Maya Erez | 3eb7d4c | 2011-10-17 15:08:42 +0200 | [diff] [blame] | 177 | int is_low_latency_ch; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 178 | |
| 179 | struct peer_sdioc_channel_config ch_config; |
| 180 | |
| 181 | /* Channel Info */ |
| 182 | int num; |
| 183 | |
| 184 | void (*notify)(void *priv, unsigned channel_event); |
| 185 | void *priv; |
| 186 | |
Konstantin Dorfman | ee2e308 | 2011-08-16 15:12:01 +0300 | [diff] [blame] | 187 | int state; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 188 | |
| 189 | struct sdio_func *func; |
| 190 | |
| 191 | int rx_pipe_index; |
| 192 | int tx_pipe_index; |
| 193 | |
| 194 | struct mutex ch_lock; |
| 195 | |
| 196 | u32 read_avail; |
| 197 | u32 write_avail; |
| 198 | |
| 199 | u32 peer_tx_buf_size; |
| 200 | |
| 201 | u16 rx_pending_bytes; |
| 202 | |
| 203 | struct list_head rx_size_list_head; |
| 204 | |
| 205 | struct platform_device *pdev; |
| 206 | |
| 207 | u32 total_rx_bytes; |
| 208 | u32 total_tx_bytes; |
| 209 | |
| 210 | u32 signature; |
| 211 | |
| 212 | struct sdio_al_device *sdio_al_dev; |
| 213 | |
| 214 | struct sdio_channel_statistics statistics; |
| 215 | }; |
| 216 | |
| 217 | /** |
| 218 | * sdio_downloader_setup |
| 219 | * initializes the TTY driver |
| 220 | * |
| 221 | * @card: a pointer to mmc_card. |
| 222 | * @num_of_devices: number of devices. |
| 223 | * @channel_number: channel number. |
| 224 | * @return 0 on success or negative value on error. |
| 225 | * |
| 226 | * The TTY stack needs to know in advance how many devices it should |
| 227 | * plan to manage. Use this call to set up the ports that will |
| 228 | * be exported through SDIO. |
| 229 | */ |
| 230 | int sdio_downloader_setup(struct mmc_card *card, |
| 231 | unsigned int num_of_devices, |
| 232 | int func_number, |
| 233 | int(*func)(void)); |
| 234 | |
| 235 | /** |
| 236 | * test_channel_init |
| 237 | * initializes a test channel |
| 238 | * |
| 239 | * @name: the channel name. |
| 240 | * @return 0 on success or negative value on error. |
| 241 | * |
| 242 | */ |
| 243 | int test_channel_init(char *name); |
| 244 | |
| 245 | /** |
| 246 | * sdio_al_register_lpm_cb |
| 247 | * Allow the sdio_al test to register for lpm voting |
| 248 | * notifications |
| 249 | * |
| 250 | * @device_handle: the device handle. |
| 251 | * @wakeup_callback: callback function to be called when voting. |
| 252 | * |
| 253 | */ |
| 254 | void sdio_al_register_lpm_cb(void *device_handle, |
| 255 | int(*lpm_callback)(void *, int)); |
| 256 | |
| 257 | /** |
| 258 | * sdio_al_unregister_lpm_cb |
| 259 | * Allow the sdio_al test to unregister for lpm voting |
| 260 | * notifications |
| 261 | * |
| 262 | * @device_handle: the device handle. |
| 263 | * |
| 264 | */ |
| 265 | void sdio_al_unregister_lpm_cb(void *device_handle); |
| 266 | |
| 267 | #endif /* __SDIO_AL_PRIVATE__ */ |