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 | /* |
| 15 | * BAM DMUX module. |
| 16 | */ |
| 17 | |
| 18 | #define DEBUG |
| 19 | |
| 20 | #include <linux/delay.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/netdevice.h> |
| 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/sched.h> |
| 25 | #include <linux/skbuff.h> |
| 26 | #include <linux/debugfs.h> |
| 27 | |
| 28 | #include <mach/sps.h> |
| 29 | #include <mach/bam_dmux.h> |
Jeff Hugo | ade1f84 | 2011-08-03 15:53:59 -0600 | [diff] [blame] | 30 | #include <mach/msm_smsm.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 31 | |
| 32 | #define BAM_CH_LOCAL_OPEN 0x1 |
| 33 | #define BAM_CH_REMOTE_OPEN 0x2 |
| 34 | |
| 35 | #define BAM_MUX_HDR_MAGIC_NO 0x33fc |
| 36 | |
| 37 | #define BAM_MUX_HDR_CMD_DATA 0 |
| 38 | #define BAM_MUX_HDR_CMD_OPEN 1 |
| 39 | #define BAM_MUX_HDR_CMD_CLOSE 2 |
| 40 | |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 41 | #define POLLING_MIN_SLEEP 950 /* 0.95 ms */ |
| 42 | #define POLLING_MAX_SLEEP 1050 /* 1.05 ms */ |
| 43 | #define POLLING_INACTIVITY 40 /* cycles before switch to intr mode */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 44 | |
| 45 | |
| 46 | static int msm_bam_dmux_debug_enable; |
| 47 | module_param_named(debug_enable, msm_bam_dmux_debug_enable, |
| 48 | int, S_IRUGO | S_IWUSR | S_IWGRP); |
| 49 | |
| 50 | #if defined(DEBUG) |
| 51 | static uint32_t bam_dmux_read_cnt; |
| 52 | static uint32_t bam_dmux_write_cnt; |
| 53 | static uint32_t bam_dmux_write_cpy_cnt; |
| 54 | static uint32_t bam_dmux_write_cpy_bytes; |
| 55 | |
| 56 | #define DBG(x...) do { \ |
| 57 | if (msm_bam_dmux_debug_enable) \ |
| 58 | pr_debug(x); \ |
| 59 | } while (0) |
| 60 | |
| 61 | #define DBG_INC_READ_CNT(x) do { \ |
| 62 | bam_dmux_read_cnt += (x); \ |
| 63 | if (msm_bam_dmux_debug_enable) \ |
| 64 | pr_debug("%s: total read bytes %u\n", \ |
| 65 | __func__, bam_dmux_read_cnt); \ |
| 66 | } while (0) |
| 67 | |
| 68 | #define DBG_INC_WRITE_CNT(x) do { \ |
| 69 | bam_dmux_write_cnt += (x); \ |
| 70 | if (msm_bam_dmux_debug_enable) \ |
| 71 | pr_debug("%s: total written bytes %u\n", \ |
| 72 | __func__, bam_dmux_write_cnt); \ |
| 73 | } while (0) |
| 74 | |
| 75 | #define DBG_INC_WRITE_CPY(x) do { \ |
| 76 | bam_dmux_write_cpy_bytes += (x); \ |
| 77 | bam_dmux_write_cpy_cnt++; \ |
| 78 | if (msm_bam_dmux_debug_enable) \ |
| 79 | pr_debug("%s: total write copy cnt %u, bytes %u\n", \ |
| 80 | __func__, bam_dmux_write_cpy_cnt, \ |
| 81 | bam_dmux_write_cpy_bytes); \ |
| 82 | } while (0) |
| 83 | #else |
| 84 | #define DBG(x...) do { } while (0) |
| 85 | #define DBG_INC_READ_CNT(x...) do { } while (0) |
| 86 | #define DBG_INC_WRITE_CNT(x...) do { } while (0) |
| 87 | #define DBG_INC_WRITE_CPY(x...) do { } while (0) |
| 88 | #endif |
| 89 | |
| 90 | struct bam_ch_info { |
| 91 | uint32_t status; |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 92 | void (*notify)(void *, int, unsigned long); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 93 | void *priv; |
| 94 | spinlock_t lock; |
Jeff Hugo | 7960abd | 2011-08-02 15:39:38 -0600 | [diff] [blame] | 95 | struct platform_device *pdev; |
| 96 | char name[BAM_DMUX_CH_NAME_MAX_LEN]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | struct tx_pkt_info { |
| 100 | struct sk_buff *skb; |
| 101 | dma_addr_t dma_address; |
| 102 | char is_cmd; |
| 103 | uint32_t len; |
| 104 | struct work_struct work; |
| 105 | }; |
| 106 | |
| 107 | struct rx_pkt_info { |
| 108 | struct sk_buff *skb; |
| 109 | dma_addr_t dma_address; |
| 110 | struct work_struct work; |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 111 | struct list_head list_node; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | #define A2_NUM_PIPES 6 |
| 115 | #define A2_SUMMING_THRESHOLD 4096 |
| 116 | #define A2_DEFAULT_DESCRIPTORS 32 |
| 117 | #define A2_PHYS_BASE 0x124C2000 |
| 118 | #define A2_PHYS_SIZE 0x2000 |
| 119 | #define BUFFER_SIZE 2048 |
| 120 | #define NUM_BUFFERS 32 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 121 | static struct sps_bam_props a2_props; |
| 122 | static struct sps_pipe *bam_tx_pipe; |
| 123 | static struct sps_pipe *bam_rx_pipe; |
| 124 | static struct sps_connect tx_connection; |
| 125 | static struct sps_connect rx_connection; |
| 126 | static struct sps_mem_buffer tx_desc_mem_buf; |
| 127 | static struct sps_mem_buffer rx_desc_mem_buf; |
| 128 | static struct sps_register_event tx_register_event; |
Jeff Hugo | 33dbc00 | 2011-08-25 15:52:53 -0600 | [diff] [blame] | 129 | static struct sps_register_event rx_register_event; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 130 | |
| 131 | static struct bam_ch_info bam_ch[BAM_DMUX_NUM_CHANNELS]; |
| 132 | static int bam_mux_initialized; |
| 133 | |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 134 | static int polling_mode; |
| 135 | |
| 136 | static LIST_HEAD(bam_rx_pool); |
| 137 | static DEFINE_MUTEX(bam_rx_pool_lock); |
| 138 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 139 | struct bam_mux_hdr { |
| 140 | uint16_t magic_num; |
| 141 | uint8_t reserved; |
| 142 | uint8_t cmd; |
| 143 | uint8_t pad_len; |
| 144 | uint8_t ch_id; |
| 145 | uint16_t pkt_len; |
| 146 | }; |
| 147 | |
| 148 | static void bam_mux_write_done(struct work_struct *work); |
| 149 | static void handle_bam_mux_cmd(struct work_struct *work); |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 150 | static void rx_timer_work_func(struct work_struct *work); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 151 | |
| 152 | static DEFINE_MUTEX(bam_mux_lock); |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 153 | static DECLARE_WORK(rx_timer_work, rx_timer_work_func); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 154 | |
| 155 | static struct workqueue_struct *bam_mux_rx_workqueue; |
| 156 | static struct workqueue_struct *bam_mux_tx_workqueue; |
| 157 | |
| 158 | #define bam_ch_is_open(x) \ |
| 159 | (bam_ch[(x)].status == (BAM_CH_LOCAL_OPEN | BAM_CH_REMOTE_OPEN)) |
| 160 | |
| 161 | #define bam_ch_is_local_open(x) \ |
| 162 | (bam_ch[(x)].status & BAM_CH_LOCAL_OPEN) |
| 163 | |
| 164 | #define bam_ch_is_remote_open(x) \ |
| 165 | (bam_ch[(x)].status & BAM_CH_REMOTE_OPEN) |
| 166 | |
| 167 | static void queue_rx(void) |
| 168 | { |
| 169 | void *ptr; |
| 170 | struct rx_pkt_info *info; |
| 171 | |
| 172 | info = kmalloc(sizeof(struct rx_pkt_info), GFP_KERNEL); |
| 173 | if (!info) |
| 174 | return; /*need better way to handle this */ |
| 175 | |
| 176 | INIT_WORK(&info->work, handle_bam_mux_cmd); |
| 177 | |
| 178 | info->skb = __dev_alloc_skb(BUFFER_SIZE, GFP_KERNEL); |
| 179 | ptr = skb_put(info->skb, BUFFER_SIZE); |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 180 | |
| 181 | mutex_lock(&bam_rx_pool_lock); |
| 182 | list_add_tail(&info->list_node, &bam_rx_pool); |
| 183 | mutex_unlock(&bam_rx_pool_lock); |
| 184 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 185 | /* need a way to handle error case */ |
| 186 | info->dma_address = dma_map_single(NULL, ptr, BUFFER_SIZE, |
| 187 | DMA_FROM_DEVICE); |
| 188 | sps_transfer_one(bam_rx_pipe, info->dma_address, |
Jeff Hugo | 33dbc00 | 2011-08-25 15:52:53 -0600 | [diff] [blame] | 189 | BUFFER_SIZE, info, |
| 190 | SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static void bam_mux_process_data(struct sk_buff *rx_skb) |
| 194 | { |
| 195 | unsigned long flags; |
| 196 | struct bam_mux_hdr *rx_hdr; |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 197 | unsigned long event_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 198 | |
| 199 | rx_hdr = (struct bam_mux_hdr *)rx_skb->data; |
| 200 | |
| 201 | rx_skb->data = (unsigned char *)(rx_hdr + 1); |
| 202 | rx_skb->tail = rx_skb->data + rx_hdr->pkt_len; |
| 203 | rx_skb->len = rx_hdr->pkt_len; |
Jeff Hugo | ee88f67 | 2011-10-04 17:14:52 -0600 | [diff] [blame^] | 204 | rx_skb->truesize = rx_hdr->pkt_len + sizeof(struct sk_buff); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 205 | |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 206 | event_data = (unsigned long)(rx_skb); |
| 207 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 208 | spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags); |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 209 | if (bam_ch[rx_hdr->ch_id].notify) |
| 210 | bam_ch[rx_hdr->ch_id].notify( |
| 211 | bam_ch[rx_hdr->ch_id].priv, BAM_DMUX_RECEIVE, |
| 212 | event_data); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 213 | else |
| 214 | dev_kfree_skb_any(rx_skb); |
| 215 | spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags); |
| 216 | |
| 217 | queue_rx(); |
| 218 | } |
| 219 | |
| 220 | static void handle_bam_mux_cmd(struct work_struct *work) |
| 221 | { |
| 222 | unsigned long flags; |
| 223 | struct bam_mux_hdr *rx_hdr; |
| 224 | struct rx_pkt_info *info; |
| 225 | struct sk_buff *rx_skb; |
Jeff Hugo | 7960abd | 2011-08-02 15:39:38 -0600 | [diff] [blame] | 226 | int ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 227 | |
| 228 | info = container_of(work, struct rx_pkt_info, work); |
| 229 | rx_skb = info->skb; |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 230 | dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE, DMA_FROM_DEVICE); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 231 | kfree(info); |
| 232 | |
| 233 | rx_hdr = (struct bam_mux_hdr *)rx_skb->data; |
| 234 | |
| 235 | DBG_INC_READ_CNT(sizeof(struct bam_mux_hdr)); |
| 236 | DBG("%s: magic %x reserved %d cmd %d pad %d ch %d len %d\n", __func__, |
| 237 | rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd, |
| 238 | rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len); |
| 239 | if (rx_hdr->magic_num != BAM_MUX_HDR_MAGIC_NO) { |
| 240 | pr_err("%s: dropping invalid hdr. magic %x reserved %d cmd %d" |
| 241 | " pad %d ch %d len %d\n", __func__, |
| 242 | rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd, |
| 243 | rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len); |
| 244 | dev_kfree_skb_any(rx_skb); |
| 245 | queue_rx(); |
| 246 | return; |
| 247 | } |
| 248 | switch (rx_hdr->cmd) { |
| 249 | case BAM_MUX_HDR_CMD_DATA: |
| 250 | DBG_INC_READ_CNT(rx_hdr->pkt_len); |
| 251 | bam_mux_process_data(rx_skb); |
| 252 | break; |
| 253 | case BAM_MUX_HDR_CMD_OPEN: |
| 254 | spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags); |
| 255 | bam_ch[rx_hdr->ch_id].status |= BAM_CH_REMOTE_OPEN; |
| 256 | spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags); |
| 257 | dev_kfree_skb_any(rx_skb); |
| 258 | queue_rx(); |
Jeff Hugo | 7960abd | 2011-08-02 15:39:38 -0600 | [diff] [blame] | 259 | ret = platform_device_add(bam_ch[rx_hdr->ch_id].pdev); |
| 260 | if (ret) |
| 261 | pr_err("%s: platform_device_add() error: %d\n", |
| 262 | __func__, ret); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 263 | break; |
| 264 | case BAM_MUX_HDR_CMD_CLOSE: |
| 265 | /* probably should drop pending write */ |
| 266 | spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags); |
| 267 | bam_ch[rx_hdr->ch_id].status &= ~BAM_CH_REMOTE_OPEN; |
| 268 | spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags); |
| 269 | dev_kfree_skb_any(rx_skb); |
| 270 | queue_rx(); |
Jeff Hugo | 7960abd | 2011-08-02 15:39:38 -0600 | [diff] [blame] | 271 | platform_device_unregister(bam_ch[rx_hdr->ch_id].pdev); |
| 272 | bam_ch[rx_hdr->ch_id].pdev = |
| 273 | platform_device_alloc(bam_ch[rx_hdr->ch_id].name, 2); |
| 274 | if (!bam_ch[rx_hdr->ch_id].pdev) |
| 275 | pr_err("%s: platform_device_alloc failed\n", __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 276 | break; |
| 277 | default: |
| 278 | pr_err("%s: dropping invalid hdr. magic %x reserved %d cmd %d" |
| 279 | " pad %d ch %d len %d\n", __func__, |
| 280 | rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd, |
| 281 | rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len); |
| 282 | dev_kfree_skb_any(rx_skb); |
| 283 | queue_rx(); |
| 284 | return; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | static int bam_mux_write_cmd(void *data, uint32_t len) |
| 289 | { |
| 290 | int rc; |
| 291 | struct tx_pkt_info *pkt; |
| 292 | dma_addr_t dma_address; |
| 293 | |
| 294 | mutex_lock(&bam_mux_lock); |
| 295 | pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_KERNEL); |
| 296 | if (pkt == NULL) { |
| 297 | pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__); |
| 298 | rc = -ENOMEM; |
| 299 | mutex_unlock(&bam_mux_lock); |
| 300 | return rc; |
| 301 | } |
| 302 | |
| 303 | dma_address = dma_map_single(NULL, data, len, |
| 304 | DMA_TO_DEVICE); |
| 305 | if (!dma_address) { |
| 306 | pr_err("%s: dma_map_single() failed\n", __func__); |
| 307 | rc = -ENOMEM; |
| 308 | mutex_unlock(&bam_mux_lock); |
| 309 | return rc; |
| 310 | } |
| 311 | pkt->skb = (struct sk_buff *)(data); |
| 312 | pkt->len = len; |
| 313 | pkt->dma_address = dma_address; |
| 314 | pkt->is_cmd = 1; |
| 315 | rc = sps_transfer_one(bam_tx_pipe, dma_address, len, |
| 316 | pkt, SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT); |
| 317 | |
| 318 | mutex_unlock(&bam_mux_lock); |
| 319 | return rc; |
| 320 | } |
| 321 | |
| 322 | static void bam_mux_write_done(struct work_struct *work) |
| 323 | { |
| 324 | struct sk_buff *skb; |
| 325 | struct bam_mux_hdr *hdr; |
| 326 | struct tx_pkt_info *info; |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 327 | unsigned long event_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 328 | |
| 329 | info = container_of(work, struct tx_pkt_info, work); |
| 330 | skb = info->skb; |
| 331 | kfree(info); |
| 332 | hdr = (struct bam_mux_hdr *)skb->data; |
| 333 | DBG_INC_WRITE_CNT(skb->data_len); |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 334 | event_data = (unsigned long)(skb); |
| 335 | if (bam_ch[hdr->ch_id].notify) |
| 336 | bam_ch[hdr->ch_id].notify( |
| 337 | bam_ch[hdr->ch_id].priv, BAM_DMUX_WRITE_DONE, |
| 338 | event_data); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 339 | else |
| 340 | dev_kfree_skb_any(skb); |
| 341 | } |
| 342 | |
| 343 | int msm_bam_dmux_write(uint32_t id, struct sk_buff *skb) |
| 344 | { |
| 345 | int rc = 0; |
| 346 | struct bam_mux_hdr *hdr; |
| 347 | unsigned long flags; |
| 348 | struct sk_buff *new_skb = NULL; |
| 349 | dma_addr_t dma_address; |
| 350 | struct tx_pkt_info *pkt; |
| 351 | |
| 352 | if (id >= BAM_DMUX_NUM_CHANNELS) |
| 353 | return -EINVAL; |
| 354 | if (!skb) |
| 355 | return -EINVAL; |
| 356 | if (!bam_mux_initialized) |
| 357 | return -ENODEV; |
| 358 | |
| 359 | DBG("%s: writing to ch %d len %d\n", __func__, id, skb->len); |
| 360 | spin_lock_irqsave(&bam_ch[id].lock, flags); |
| 361 | if (!bam_ch_is_open(id)) { |
| 362 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
| 363 | pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status); |
| 364 | return -ENODEV; |
| 365 | } |
| 366 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
| 367 | |
| 368 | /* if skb do not have any tailroom for padding, |
| 369 | copy the skb into a new expanded skb */ |
| 370 | if ((skb->len & 0x3) && (skb_tailroom(skb) < (4 - (skb->len & 0x3)))) { |
| 371 | /* revisit, probably dev_alloc_skb and memcpy is effecient */ |
| 372 | new_skb = skb_copy_expand(skb, skb_headroom(skb), |
| 373 | 4 - (skb->len & 0x3), GFP_ATOMIC); |
| 374 | if (new_skb == NULL) { |
| 375 | pr_err("%s: cannot allocate skb\n", __func__); |
| 376 | return -ENOMEM; |
| 377 | } |
| 378 | dev_kfree_skb_any(skb); |
| 379 | skb = new_skb; |
| 380 | DBG_INC_WRITE_CPY(skb->len); |
| 381 | } |
| 382 | |
| 383 | hdr = (struct bam_mux_hdr *)skb_push(skb, sizeof(struct bam_mux_hdr)); |
| 384 | |
| 385 | /* caller should allocate for hdr and padding |
| 386 | hdr is fine, padding is tricky */ |
| 387 | hdr->magic_num = BAM_MUX_HDR_MAGIC_NO; |
| 388 | hdr->cmd = BAM_MUX_HDR_CMD_DATA; |
| 389 | hdr->reserved = 0; |
| 390 | hdr->ch_id = id; |
| 391 | hdr->pkt_len = skb->len - sizeof(struct bam_mux_hdr); |
| 392 | if (skb->len & 0x3) |
| 393 | skb_put(skb, 4 - (skb->len & 0x3)); |
| 394 | |
| 395 | hdr->pad_len = skb->len - (sizeof(struct bam_mux_hdr) + hdr->pkt_len); |
| 396 | |
| 397 | DBG("%s: data %p, tail %p skb len %d pkt len %d pad len %d\n", |
| 398 | __func__, skb->data, skb->tail, skb->len, |
| 399 | hdr->pkt_len, hdr->pad_len); |
| 400 | |
| 401 | pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC); |
| 402 | if (pkt == NULL) { |
| 403 | pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__); |
| 404 | if (new_skb) |
| 405 | dev_kfree_skb_any(new_skb); |
| 406 | return -ENOMEM; |
| 407 | } |
| 408 | |
| 409 | dma_address = dma_map_single(NULL, skb->data, skb->len, |
| 410 | DMA_TO_DEVICE); |
| 411 | if (!dma_address) { |
| 412 | pr_err("%s: dma_map_single() failed\n", __func__); |
| 413 | if (new_skb) |
| 414 | dev_kfree_skb_any(new_skb); |
| 415 | kfree(pkt); |
| 416 | return -ENOMEM; |
| 417 | } |
| 418 | pkt->skb = skb; |
| 419 | pkt->dma_address = dma_address; |
| 420 | pkt->is_cmd = 0; |
| 421 | INIT_WORK(&pkt->work, bam_mux_write_done); |
| 422 | rc = sps_transfer_one(bam_tx_pipe, dma_address, skb->len, |
| 423 | pkt, SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT); |
| 424 | return rc; |
| 425 | } |
| 426 | |
| 427 | int msm_bam_dmux_open(uint32_t id, void *priv, |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 428 | void (*notify)(void *, int, unsigned long)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 429 | { |
| 430 | struct bam_mux_hdr *hdr; |
| 431 | unsigned long flags; |
| 432 | int rc = 0; |
| 433 | |
| 434 | DBG("%s: opening ch %d\n", __func__, id); |
| 435 | if (!bam_mux_initialized) |
| 436 | return -ENODEV; |
| 437 | if (id >= BAM_DMUX_NUM_CHANNELS) |
| 438 | return -EINVAL; |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 439 | if (notify == NULL) |
| 440 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 441 | |
| 442 | hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_KERNEL); |
| 443 | if (hdr == NULL) { |
| 444 | pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id); |
| 445 | return -ENOMEM; |
| 446 | } |
| 447 | spin_lock_irqsave(&bam_ch[id].lock, flags); |
| 448 | if (bam_ch_is_open(id)) { |
| 449 | DBG("%s: Already opened %d\n", __func__, id); |
| 450 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
| 451 | kfree(hdr); |
| 452 | goto open_done; |
| 453 | } |
| 454 | if (!bam_ch_is_remote_open(id)) { |
| 455 | DBG("%s: Remote not open; ch: %d\n", __func__, id); |
| 456 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
| 457 | kfree(hdr); |
| 458 | rc = -ENODEV; |
| 459 | goto open_done; |
| 460 | } |
| 461 | |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 462 | bam_ch[id].notify = notify; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 463 | bam_ch[id].priv = priv; |
| 464 | bam_ch[id].status |= BAM_CH_LOCAL_OPEN; |
| 465 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
| 466 | |
| 467 | hdr->magic_num = BAM_MUX_HDR_MAGIC_NO; |
| 468 | hdr->cmd = BAM_MUX_HDR_CMD_OPEN; |
| 469 | hdr->reserved = 0; |
| 470 | hdr->ch_id = id; |
| 471 | hdr->pkt_len = 0; |
| 472 | hdr->pad_len = 0; |
| 473 | |
| 474 | rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr)); |
| 475 | |
| 476 | open_done: |
| 477 | DBG("%s: opened ch %d\n", __func__, id); |
| 478 | return rc; |
| 479 | } |
| 480 | |
| 481 | int msm_bam_dmux_close(uint32_t id) |
| 482 | { |
| 483 | struct bam_mux_hdr *hdr; |
| 484 | unsigned long flags; |
| 485 | int rc; |
| 486 | |
| 487 | if (id >= BAM_DMUX_NUM_CHANNELS) |
| 488 | return -EINVAL; |
| 489 | DBG("%s: closing ch %d\n", __func__, id); |
| 490 | if (!bam_mux_initialized) |
| 491 | return -ENODEV; |
| 492 | spin_lock_irqsave(&bam_ch[id].lock, flags); |
| 493 | |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 494 | bam_ch[id].notify = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 495 | bam_ch[id].priv = NULL; |
| 496 | bam_ch[id].status &= ~BAM_CH_LOCAL_OPEN; |
| 497 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
| 498 | |
| 499 | hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_KERNEL); |
| 500 | if (hdr == NULL) { |
| 501 | pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id); |
| 502 | return -ENOMEM; |
| 503 | } |
| 504 | hdr->magic_num = BAM_MUX_HDR_MAGIC_NO; |
| 505 | hdr->cmd = BAM_MUX_HDR_CMD_CLOSE; |
| 506 | hdr->reserved = 0; |
| 507 | hdr->ch_id = id; |
| 508 | hdr->pkt_len = 0; |
| 509 | hdr->pad_len = 0; |
| 510 | |
| 511 | rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr)); |
| 512 | |
| 513 | DBG("%s: closed ch %d\n", __func__, id); |
| 514 | return rc; |
| 515 | } |
| 516 | |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 517 | static void rx_timer_work_func(struct work_struct *work) |
| 518 | { |
| 519 | struct sps_iovec iov; |
| 520 | struct list_head *node; |
| 521 | struct rx_pkt_info *info; |
| 522 | int inactive_cycles = 0; |
| 523 | int ret; |
| 524 | struct sps_connect cur_rx_conn; |
| 525 | |
| 526 | while (1) { /* timer loop */ |
| 527 | ++inactive_cycles; |
| 528 | while (1) { /* deplete queue loop */ |
| 529 | sps_get_iovec(bam_rx_pipe, &iov); |
| 530 | if (iov.addr == 0) |
| 531 | break; |
| 532 | inactive_cycles = 0; |
| 533 | mutex_lock(&bam_rx_pool_lock); |
| 534 | node = bam_rx_pool.next; |
| 535 | list_del(node); |
| 536 | mutex_unlock(&bam_rx_pool_lock); |
| 537 | info = container_of(node, struct rx_pkt_info, |
| 538 | list_node); |
| 539 | handle_bam_mux_cmd(&info->work); |
| 540 | } |
| 541 | |
| 542 | if (inactive_cycles == POLLING_INACTIVITY) { |
| 543 | /* |
| 544 | * attempt to enable interrupts in this pipe |
| 545 | * if enabling interrupts fails, continue polling |
| 546 | */ |
| 547 | ret = sps_get_config(bam_rx_pipe, &cur_rx_conn); |
| 548 | if (ret) { |
| 549 | pr_err("%s: sps_get_config() failed, interrupts" |
| 550 | " not enabled\n", __func__); |
| 551 | queue_work(bam_mux_rx_workqueue, |
| 552 | &rx_timer_work); |
| 553 | return; |
| 554 | } else { |
| 555 | rx_register_event.options = SPS_O_EOT; |
| 556 | /* should check return value */ |
| 557 | sps_register_event(bam_rx_pipe, |
| 558 | &rx_register_event); |
| 559 | cur_rx_conn.options = SPS_O_AUTO_ENABLE | |
| 560 | SPS_O_EOT | SPS_O_ACK_TRANSFERS; |
| 561 | ret = sps_set_config(bam_rx_pipe, &cur_rx_conn); |
| 562 | if (ret) { |
| 563 | pr_err("%s: sps_set_config() failed, " |
| 564 | "interrupts not enabled\n", |
| 565 | __func__); |
| 566 | queue_work(bam_mux_rx_workqueue, |
| 567 | &rx_timer_work); |
| 568 | return; |
| 569 | } |
| 570 | polling_mode = 0; |
| 571 | } |
| 572 | /* handle race condition - missed packet? */ |
| 573 | sps_get_iovec(bam_rx_pipe, &iov); |
| 574 | if (iov.addr == 0) |
| 575 | return; |
| 576 | inactive_cycles = 0; |
| 577 | mutex_lock(&bam_rx_pool_lock); |
| 578 | node = bam_rx_pool.next; |
| 579 | list_del(node); |
| 580 | mutex_unlock(&bam_rx_pool_lock); |
| 581 | info = container_of(node, struct rx_pkt_info, |
| 582 | list_node); |
| 583 | handle_bam_mux_cmd(&info->work); |
| 584 | return; |
| 585 | } |
| 586 | |
| 587 | usleep_range(POLLING_MIN_SLEEP, POLLING_MAX_SLEEP); |
| 588 | } |
| 589 | } |
| 590 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 591 | static void bam_mux_tx_notify(struct sps_event_notify *notify) |
| 592 | { |
| 593 | struct tx_pkt_info *pkt; |
| 594 | |
| 595 | DBG("%s: event %d notified\n", __func__, notify->event_id); |
| 596 | |
| 597 | switch (notify->event_id) { |
| 598 | case SPS_EVENT_EOT: |
| 599 | pkt = notify->data.transfer.user; |
| 600 | if (!pkt->is_cmd) { |
| 601 | dma_unmap_single(NULL, pkt->dma_address, |
| 602 | pkt->skb->len, |
| 603 | DMA_TO_DEVICE); |
| 604 | queue_work(bam_mux_tx_workqueue, &pkt->work); |
| 605 | } else { |
| 606 | dma_unmap_single(NULL, pkt->dma_address, |
| 607 | pkt->len, |
| 608 | DMA_TO_DEVICE); |
| 609 | kfree(pkt->skb); |
| 610 | kfree(pkt); |
| 611 | } |
| 612 | break; |
| 613 | default: |
| 614 | pr_err("%s: recieved unexpected event id %d\n", __func__, |
| 615 | notify->event_id); |
| 616 | } |
| 617 | } |
| 618 | |
Jeff Hugo | 33dbc00 | 2011-08-25 15:52:53 -0600 | [diff] [blame] | 619 | static void bam_mux_rx_notify(struct sps_event_notify *notify) |
| 620 | { |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 621 | int ret; |
| 622 | struct sps_connect cur_rx_conn; |
Jeff Hugo | 33dbc00 | 2011-08-25 15:52:53 -0600 | [diff] [blame] | 623 | |
| 624 | DBG("%s: event %d notified\n", __func__, notify->event_id); |
| 625 | |
Jeff Hugo | 33dbc00 | 2011-08-25 15:52:53 -0600 | [diff] [blame] | 626 | switch (notify->event_id) { |
| 627 | case SPS_EVENT_EOT: |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 628 | /* attempt to disable interrupts in this pipe */ |
| 629 | if (!polling_mode) { |
| 630 | ret = sps_get_config(bam_rx_pipe, &cur_rx_conn); |
| 631 | if (ret) { |
| 632 | pr_err("%s: sps_get_config() failed, interrupts" |
| 633 | " not disabled\n", __func__); |
| 634 | break; |
| 635 | } |
| 636 | rx_register_event.options = 0; |
| 637 | ret = sps_register_event(bam_rx_pipe, |
| 638 | &rx_register_event); |
| 639 | if (ret) { |
| 640 | pr_err("%s: sps_register_event ret = %d\n", |
| 641 | __func__, ret); |
| 642 | break; |
| 643 | } |
| 644 | cur_rx_conn.options = SPS_O_AUTO_ENABLE | SPS_O_EOT | |
| 645 | SPS_O_ACK_TRANSFERS | SPS_O_POLL; |
| 646 | ret = sps_set_config(bam_rx_pipe, &cur_rx_conn); |
| 647 | if (ret) { |
| 648 | pr_err("%s: sps_set_config() failed, interrupts" |
| 649 | " not disabled\n", __func__); |
| 650 | break; |
| 651 | } |
| 652 | polling_mode = 1; |
| 653 | queue_work(bam_mux_rx_workqueue, &rx_timer_work); |
| 654 | } |
Jeff Hugo | 33dbc00 | 2011-08-25 15:52:53 -0600 | [diff] [blame] | 655 | break; |
| 656 | default: |
| 657 | pr_err("%s: recieved unexpected event id %d\n", __func__, |
| 658 | notify->event_id); |
| 659 | } |
| 660 | } |
| 661 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 662 | #ifdef CONFIG_DEBUG_FS |
| 663 | |
| 664 | static int debug_tbl(char *buf, int max) |
| 665 | { |
| 666 | int i = 0; |
| 667 | int j; |
| 668 | |
| 669 | for (j = 0; j < BAM_DMUX_NUM_CHANNELS; ++j) { |
| 670 | i += scnprintf(buf + i, max - i, |
| 671 | "ch%02d local open=%s remote open=%s\n", |
| 672 | j, bam_ch_is_local_open(j) ? "Y" : "N", |
| 673 | bam_ch_is_remote_open(j) ? "Y" : "N"); |
| 674 | } |
| 675 | |
| 676 | return i; |
| 677 | } |
| 678 | |
| 679 | #define DEBUG_BUFMAX 4096 |
| 680 | static char debug_buffer[DEBUG_BUFMAX]; |
| 681 | |
| 682 | static ssize_t debug_read(struct file *file, char __user *buf, |
| 683 | size_t count, loff_t *ppos) |
| 684 | { |
| 685 | int (*fill)(char *buf, int max) = file->private_data; |
| 686 | int bsize = fill(debug_buffer, DEBUG_BUFMAX); |
| 687 | return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize); |
| 688 | } |
| 689 | |
| 690 | static int debug_open(struct inode *inode, struct file *file) |
| 691 | { |
| 692 | file->private_data = inode->i_private; |
| 693 | return 0; |
| 694 | } |
| 695 | |
| 696 | |
| 697 | static const struct file_operations debug_ops = { |
| 698 | .read = debug_read, |
| 699 | .open = debug_open, |
| 700 | }; |
| 701 | |
| 702 | static void debug_create(const char *name, mode_t mode, |
| 703 | struct dentry *dent, |
| 704 | int (*fill)(char *buf, int max)) |
| 705 | { |
| 706 | debugfs_create_file(name, mode, dent, fill, &debug_ops); |
| 707 | } |
| 708 | |
| 709 | #endif |
| 710 | |
Jeff Hugo | ade1f84 | 2011-08-03 15:53:59 -0600 | [diff] [blame] | 711 | static void bam_init(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 712 | { |
| 713 | u32 h; |
| 714 | dma_addr_t dma_addr; |
| 715 | int ret; |
| 716 | void *a2_virt_addr; |
| 717 | int i; |
| 718 | |
| 719 | /* init BAM */ |
| 720 | a2_virt_addr = ioremap_nocache(A2_PHYS_BASE, A2_PHYS_SIZE); |
| 721 | if (!a2_virt_addr) { |
| 722 | pr_err("%s: ioremap failed\n", __func__); |
| 723 | ret = -ENOMEM; |
| 724 | goto register_bam_failed; |
| 725 | } |
| 726 | a2_props.phys_addr = A2_PHYS_BASE; |
| 727 | a2_props.virt_addr = a2_virt_addr; |
| 728 | a2_props.virt_size = A2_PHYS_SIZE; |
| 729 | a2_props.irq = A2_BAM_IRQ; |
| 730 | a2_props.num_pipes = A2_NUM_PIPES; |
| 731 | a2_props.summing_threshold = A2_SUMMING_THRESHOLD; |
| 732 | /* need to free on tear down */ |
| 733 | ret = sps_register_bam_device(&a2_props, &h); |
| 734 | if (ret < 0) { |
| 735 | pr_err("%s: register bam error %d\n", __func__, ret); |
| 736 | goto register_bam_failed; |
| 737 | } |
| 738 | |
| 739 | bam_tx_pipe = sps_alloc_endpoint(); |
| 740 | if (bam_tx_pipe == NULL) { |
| 741 | pr_err("%s: tx alloc endpoint failed\n", __func__); |
| 742 | ret = -ENOMEM; |
| 743 | goto register_bam_failed; |
| 744 | } |
| 745 | ret = sps_get_config(bam_tx_pipe, &tx_connection); |
| 746 | if (ret) { |
| 747 | pr_err("%s: tx get config failed %d\n", __func__, ret); |
| 748 | goto tx_get_config_failed; |
| 749 | } |
| 750 | |
| 751 | tx_connection.source = SPS_DEV_HANDLE_MEM; |
| 752 | tx_connection.src_pipe_index = 0; |
| 753 | tx_connection.destination = h; |
| 754 | tx_connection.dest_pipe_index = 4; |
| 755 | tx_connection.mode = SPS_MODE_DEST; |
| 756 | tx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT; |
| 757 | tx_desc_mem_buf.size = 0x800; /* 2k */ |
| 758 | tx_desc_mem_buf.base = dma_alloc_coherent(NULL, tx_desc_mem_buf.size, |
| 759 | &dma_addr, 0); |
| 760 | if (tx_desc_mem_buf.base == NULL) { |
| 761 | pr_err("%s: tx memory alloc failed\n", __func__); |
| 762 | ret = -ENOMEM; |
| 763 | goto tx_mem_failed; |
| 764 | } |
| 765 | tx_desc_mem_buf.phys_base = dma_addr; |
| 766 | memset(tx_desc_mem_buf.base, 0x0, tx_desc_mem_buf.size); |
| 767 | tx_connection.desc = tx_desc_mem_buf; |
| 768 | tx_connection.event_thresh = 0x10; |
| 769 | |
| 770 | ret = sps_connect(bam_tx_pipe, &tx_connection); |
| 771 | if (ret < 0) { |
| 772 | pr_err("%s: tx connect error %d\n", __func__, ret); |
| 773 | goto tx_connect_failed; |
| 774 | } |
| 775 | |
| 776 | bam_rx_pipe = sps_alloc_endpoint(); |
| 777 | if (bam_rx_pipe == NULL) { |
| 778 | pr_err("%s: rx alloc endpoint failed\n", __func__); |
| 779 | ret = -ENOMEM; |
| 780 | goto tx_connect_failed; |
| 781 | } |
| 782 | ret = sps_get_config(bam_rx_pipe, &rx_connection); |
| 783 | if (ret) { |
| 784 | pr_err("%s: rx get config failed %d\n", __func__, ret); |
| 785 | goto rx_get_config_failed; |
| 786 | } |
| 787 | |
| 788 | rx_connection.source = h; |
| 789 | rx_connection.src_pipe_index = 5; |
| 790 | rx_connection.destination = SPS_DEV_HANDLE_MEM; |
| 791 | rx_connection.dest_pipe_index = 1; |
| 792 | rx_connection.mode = SPS_MODE_SRC; |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 793 | rx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT | |
| 794 | SPS_O_ACK_TRANSFERS; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 795 | rx_desc_mem_buf.size = 0x800; /* 2k */ |
| 796 | rx_desc_mem_buf.base = dma_alloc_coherent(NULL, rx_desc_mem_buf.size, |
| 797 | &dma_addr, 0); |
| 798 | if (rx_desc_mem_buf.base == NULL) { |
| 799 | pr_err("%s: rx memory alloc failed\n", __func__); |
| 800 | ret = -ENOMEM; |
| 801 | goto rx_mem_failed; |
| 802 | } |
| 803 | rx_desc_mem_buf.phys_base = dma_addr; |
| 804 | memset(rx_desc_mem_buf.base, 0x0, rx_desc_mem_buf.size); |
| 805 | rx_connection.desc = rx_desc_mem_buf; |
| 806 | rx_connection.event_thresh = 0x10; |
| 807 | |
| 808 | ret = sps_connect(bam_rx_pipe, &rx_connection); |
| 809 | if (ret < 0) { |
| 810 | pr_err("%s: rx connect error %d\n", __func__, ret); |
| 811 | goto rx_connect_failed; |
| 812 | } |
| 813 | |
| 814 | tx_register_event.options = SPS_O_EOT; |
| 815 | tx_register_event.mode = SPS_TRIGGER_CALLBACK; |
| 816 | tx_register_event.xfer_done = NULL; |
| 817 | tx_register_event.callback = bam_mux_tx_notify; |
| 818 | tx_register_event.user = NULL; |
| 819 | ret = sps_register_event(bam_tx_pipe, &tx_register_event); |
| 820 | if (ret < 0) { |
| 821 | pr_err("%s: tx register event error %d\n", __func__, ret); |
| 822 | goto rx_event_reg_failed; |
| 823 | } |
| 824 | |
Jeff Hugo | 33dbc00 | 2011-08-25 15:52:53 -0600 | [diff] [blame] | 825 | rx_register_event.options = SPS_O_EOT; |
| 826 | rx_register_event.mode = SPS_TRIGGER_CALLBACK; |
| 827 | rx_register_event.xfer_done = NULL; |
| 828 | rx_register_event.callback = bam_mux_rx_notify; |
| 829 | rx_register_event.user = NULL; |
| 830 | ret = sps_register_event(bam_rx_pipe, &rx_register_event); |
| 831 | if (ret < 0) { |
| 832 | pr_err("%s: tx register event error %d\n", __func__, ret); |
| 833 | goto rx_event_reg_failed; |
| 834 | } |
| 835 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 836 | bam_mux_initialized = 1; |
| 837 | for (i = 0; i < NUM_BUFFERS; ++i) |
| 838 | queue_rx(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 839 | return; |
| 840 | |
| 841 | rx_event_reg_failed: |
| 842 | sps_disconnect(bam_rx_pipe); |
| 843 | rx_connect_failed: |
| 844 | dma_free_coherent(NULL, rx_desc_mem_buf.size, rx_desc_mem_buf.base, |
| 845 | rx_desc_mem_buf.phys_base); |
| 846 | rx_mem_failed: |
| 847 | sps_disconnect(bam_tx_pipe); |
| 848 | rx_get_config_failed: |
| 849 | sps_free_endpoint(bam_rx_pipe); |
| 850 | tx_connect_failed: |
| 851 | dma_free_coherent(NULL, tx_desc_mem_buf.size, tx_desc_mem_buf.base, |
| 852 | tx_desc_mem_buf.phys_base); |
| 853 | tx_get_config_failed: |
| 854 | sps_free_endpoint(bam_tx_pipe); |
| 855 | tx_mem_failed: |
| 856 | sps_deregister_bam_device(h); |
| 857 | register_bam_failed: |
| 858 | /*destroy_workqueue(bam_mux_workqueue);*/ |
| 859 | /*return ret;*/ |
| 860 | return; |
| 861 | } |
Jeff Hugo | ade1f84 | 2011-08-03 15:53:59 -0600 | [diff] [blame] | 862 | |
| 863 | static void bam_dmux_smsm_cb(void *priv, uint32_t old_state, uint32_t new_state) |
| 864 | { |
| 865 | DBG("%s: smsm activity\n", __func__); |
| 866 | if (bam_mux_initialized) |
| 867 | pr_err("%s: bam_dmux already initialized\n", __func__); |
| 868 | else if (new_state & SMSM_A2_POWER_CONTROL) |
| 869 | bam_init(); |
| 870 | else |
| 871 | pr_err("%s: unsupported state change\n", __func__); |
| 872 | |
| 873 | } |
| 874 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 875 | static int bam_dmux_probe(struct platform_device *pdev) |
| 876 | { |
| 877 | int rc; |
| 878 | |
| 879 | DBG("%s probe called\n", __func__); |
| 880 | if (bam_mux_initialized) |
| 881 | return 0; |
| 882 | |
| 883 | bam_mux_rx_workqueue = create_singlethread_workqueue("bam_dmux_rx"); |
| 884 | if (!bam_mux_rx_workqueue) |
| 885 | return -ENOMEM; |
| 886 | |
| 887 | bam_mux_tx_workqueue = create_singlethread_workqueue("bam_dmux_tx"); |
| 888 | if (!bam_mux_tx_workqueue) { |
| 889 | destroy_workqueue(bam_mux_rx_workqueue); |
| 890 | return -ENOMEM; |
| 891 | } |
| 892 | |
Jeff Hugo | 7960abd | 2011-08-02 15:39:38 -0600 | [diff] [blame] | 893 | for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 894 | spin_lock_init(&bam_ch[rc].lock); |
Jeff Hugo | 7960abd | 2011-08-02 15:39:38 -0600 | [diff] [blame] | 895 | scnprintf(bam_ch[rc].name, BAM_DMUX_CH_NAME_MAX_LEN, |
| 896 | "bam_dmux_ch_%d", rc); |
| 897 | /* bus 2, ie a2 stream 2 */ |
| 898 | bam_ch[rc].pdev = platform_device_alloc(bam_ch[rc].name, 2); |
| 899 | if (!bam_ch[rc].pdev) { |
| 900 | pr_err("%s: platform device alloc failed\n", __func__); |
| 901 | destroy_workqueue(bam_mux_rx_workqueue); |
| 902 | destroy_workqueue(bam_mux_tx_workqueue); |
| 903 | return -ENOMEM; |
| 904 | } |
| 905 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 906 | |
Jeff Hugo | ade1f84 | 2011-08-03 15:53:59 -0600 | [diff] [blame] | 907 | rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL, |
| 908 | bam_dmux_smsm_cb, NULL); |
| 909 | |
| 910 | if (rc) { |
| 911 | destroy_workqueue(bam_mux_rx_workqueue); |
| 912 | destroy_workqueue(bam_mux_tx_workqueue); |
| 913 | pr_err("%s: smsm cb register failed, rc: %d\n", __func__, rc); |
| 914 | return -ENOMEM; |
| 915 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 916 | |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | static struct platform_driver bam_dmux_driver = { |
| 921 | .probe = bam_dmux_probe, |
| 922 | .driver = { |
| 923 | .name = "BAM_RMNT", |
| 924 | .owner = THIS_MODULE, |
| 925 | }, |
| 926 | }; |
| 927 | |
| 928 | static int __init bam_dmux_init(void) |
| 929 | { |
| 930 | #ifdef CONFIG_DEBUG_FS |
| 931 | struct dentry *dent; |
| 932 | |
| 933 | dent = debugfs_create_dir("bam_dmux", 0); |
| 934 | if (!IS_ERR(dent)) |
| 935 | debug_create("tbl", 0444, dent, debug_tbl); |
| 936 | #endif |
| 937 | return platform_driver_register(&bam_dmux_driver); |
| 938 | } |
| 939 | |
Jeff Hugo | ade1f84 | 2011-08-03 15:53:59 -0600 | [diff] [blame] | 940 | late_initcall(bam_dmux_init); /* needs to init after SMD */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 941 | MODULE_DESCRIPTION("MSM BAM DMUX"); |
| 942 | MODULE_LICENSE("GPL v2"); |