blob: c475e2d9678e11d17261f311883cb7f13e89d90a [file] [log] [blame]
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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>
Jeff Hugoaab7ebc2011-09-07 16:46:04 -060027#include <linux/clk.h>
Jeff Hugoae3a85e2011-12-02 17:10:18 -070028#include <linux/wakelock.h>
Eric Holmberg878923a2012-01-10 14:28:19 -070029#include <linux/kfifo.h>
Jeff Hugo7bf02052012-08-21 14:08:20 -060030#include <linux/of.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031
32#include <mach/sps.h>
33#include <mach/bam_dmux.h>
Jeff Hugoade1f842011-08-03 15:53:59 -060034#include <mach/msm_smsm.h>
Jeff Hugo6e7a92a2011-10-24 05:25:13 -060035#include <mach/subsystem_notif.h>
Jeff Hugo75913c82011-12-05 15:59:01 -070036#include <mach/socinfo.h>
Jeff Hugo4838f412012-01-20 11:19:37 -070037#include <mach/subsystem_restart.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038
39#define BAM_CH_LOCAL_OPEN 0x1
40#define BAM_CH_REMOTE_OPEN 0x2
Jeff Hugo6e7a92a2011-10-24 05:25:13 -060041#define BAM_CH_IN_RESET 0x4
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042
43#define BAM_MUX_HDR_MAGIC_NO 0x33fc
44
Eric Holmberg006057d2012-01-11 10:10:42 -070045#define BAM_MUX_HDR_CMD_DATA 0
46#define BAM_MUX_HDR_CMD_OPEN 1
47#define BAM_MUX_HDR_CMD_CLOSE 2
48#define BAM_MUX_HDR_CMD_STATUS 3 /* unused */
49#define BAM_MUX_HDR_CMD_OPEN_NO_A2_PC 4
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070051
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -070052#define LOW_WATERMARK 2
53#define HIGH_WATERMARK 4
Anurag Singhdcd8b4e2012-07-30 16:46:37 -070054#define DEFAULT_POLLING_MIN_SLEEP (950)
55#define MAX_POLLING_SLEEP (6050)
56#define MIN_POLLING_SLEEP (950)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070057
58static int msm_bam_dmux_debug_enable;
59module_param_named(debug_enable, msm_bam_dmux_debug_enable,
60 int, S_IRUGO | S_IWUSR | S_IWGRP);
Anurag Singhdcd8b4e2012-07-30 16:46:37 -070061static int POLLING_MIN_SLEEP = 950;
62module_param_named(min_sleep, POLLING_MIN_SLEEP,
63 int, S_IRUGO | S_IWUSR | S_IWGRP);
64static int POLLING_MAX_SLEEP = 1050;
65module_param_named(max_sleep, POLLING_MAX_SLEEP,
66 int, S_IRUGO | S_IWUSR | S_IWGRP);
67static int POLLING_INACTIVITY = 40;
68module_param_named(inactivity, POLLING_INACTIVITY,
69 int, S_IRUGO | S_IWUSR | S_IWGRP);
70static int bam_adaptive_timer_enabled = 1;
71module_param_named(adaptive_timer_enabled,
72 bam_adaptive_timer_enabled,
73 int, S_IRUGO | S_IWUSR | S_IWGRP);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070074
75#if defined(DEBUG)
76static uint32_t bam_dmux_read_cnt;
77static uint32_t bam_dmux_write_cnt;
78static uint32_t bam_dmux_write_cpy_cnt;
79static uint32_t bam_dmux_write_cpy_bytes;
Eric Holmberg2fddbcd2011-11-28 18:25:57 -070080static uint32_t bam_dmux_tx_sps_failure_cnt;
Eric Holmberg6074aba2012-01-18 17:59:44 -070081static uint32_t bam_dmux_tx_stall_cnt;
Eric Holmberg1f1255d2012-02-22 13:37:21 -070082static atomic_t bam_dmux_ack_out_cnt = ATOMIC_INIT(0);
83static atomic_t bam_dmux_ack_in_cnt = ATOMIC_INIT(0);
84static atomic_t bam_dmux_a2_pwr_cntl_in_cnt = ATOMIC_INIT(0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070085
86#define DBG(x...) do { \
87 if (msm_bam_dmux_debug_enable) \
88 pr_debug(x); \
89 } while (0)
90
91#define DBG_INC_READ_CNT(x) do { \
92 bam_dmux_read_cnt += (x); \
93 if (msm_bam_dmux_debug_enable) \
94 pr_debug("%s: total read bytes %u\n", \
95 __func__, bam_dmux_read_cnt); \
96 } while (0)
97
98#define DBG_INC_WRITE_CNT(x) do { \
99 bam_dmux_write_cnt += (x); \
100 if (msm_bam_dmux_debug_enable) \
101 pr_debug("%s: total written bytes %u\n", \
102 __func__, bam_dmux_write_cnt); \
103 } while (0)
104
105#define DBG_INC_WRITE_CPY(x) do { \
106 bam_dmux_write_cpy_bytes += (x); \
107 bam_dmux_write_cpy_cnt++; \
108 if (msm_bam_dmux_debug_enable) \
109 pr_debug("%s: total write copy cnt %u, bytes %u\n", \
110 __func__, bam_dmux_write_cpy_cnt, \
111 bam_dmux_write_cpy_bytes); \
112 } while (0)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700113
114#define DBG_INC_TX_SPS_FAILURE_CNT() do { \
115 bam_dmux_tx_sps_failure_cnt++; \
116} while (0)
117
Eric Holmberg6074aba2012-01-18 17:59:44 -0700118#define DBG_INC_TX_STALL_CNT() do { \
119 bam_dmux_tx_stall_cnt++; \
120} while (0)
121
Eric Holmberg1f1255d2012-02-22 13:37:21 -0700122#define DBG_INC_ACK_OUT_CNT() \
123 atomic_inc(&bam_dmux_ack_out_cnt)
124
125#define DBG_INC_A2_POWER_CONTROL_IN_CNT() \
126 atomic_inc(&bam_dmux_a2_pwr_cntl_in_cnt)
127
128#define DBG_INC_ACK_IN_CNT() \
129 atomic_inc(&bam_dmux_ack_in_cnt)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700130#else
131#define DBG(x...) do { } while (0)
132#define DBG_INC_READ_CNT(x...) do { } while (0)
133#define DBG_INC_WRITE_CNT(x...) do { } while (0)
134#define DBG_INC_WRITE_CPY(x...) do { } while (0)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700135#define DBG_INC_TX_SPS_FAILURE_CNT() do { } while (0)
Eric Holmberg6074aba2012-01-18 17:59:44 -0700136#define DBG_INC_TX_STALL_CNT() do { } while (0)
Eric Holmberg1f1255d2012-02-22 13:37:21 -0700137#define DBG_INC_ACK_OUT_CNT() do { } while (0)
138#define DBG_INC_A2_POWER_CONTROL_IN_CNT() \
139 do { } while (0)
140#define DBG_INC_ACK_IN_CNT() do { } while (0)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700141#endif
142
143struct bam_ch_info {
144 uint32_t status;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600145 void (*notify)(void *, int, unsigned long);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700146 void *priv;
147 spinlock_t lock;
Jeff Hugo7960abd2011-08-02 15:39:38 -0600148 struct platform_device *pdev;
149 char name[BAM_DMUX_CH_NAME_MAX_LEN];
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700150 int num_tx_pkts;
151 int use_wm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700152};
153
154struct tx_pkt_info {
155 struct sk_buff *skb;
156 dma_addr_t dma_address;
157 char is_cmd;
158 uint32_t len;
159 struct work_struct work;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600160 struct list_head list_node;
Eric Holmberg878923a2012-01-10 14:28:19 -0700161 unsigned ts_sec;
162 unsigned long ts_nsec;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700163};
164
165struct rx_pkt_info {
166 struct sk_buff *skb;
167 dma_addr_t dma_address;
168 struct work_struct work;
Jeff Hugo949080a2011-08-30 11:58:56 -0600169 struct list_head list_node;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700170};
171
172#define A2_NUM_PIPES 6
173#define A2_SUMMING_THRESHOLD 4096
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700174#define A2_PHYS_BASE 0x124C2000
175#define A2_PHYS_SIZE 0x2000
176#define BUFFER_SIZE 2048
177#define NUM_BUFFERS 32
Jeff Hugo7bf02052012-08-21 14:08:20 -0600178
179#ifndef A2_BAM_IRQ
180#define A2_BAM_IRQ -1
181#endif
182
183static void *a2_phys_base;
184static uint32_t a2_phys_size;
185static int a2_bam_irq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700186static struct sps_bam_props a2_props;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600187static u32 a2_device_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700188static struct sps_pipe *bam_tx_pipe;
189static struct sps_pipe *bam_rx_pipe;
190static struct sps_connect tx_connection;
191static struct sps_connect rx_connection;
192static struct sps_mem_buffer tx_desc_mem_buf;
193static struct sps_mem_buffer rx_desc_mem_buf;
194static struct sps_register_event tx_register_event;
Jeff Hugo33dbc002011-08-25 15:52:53 -0600195static struct sps_register_event rx_register_event;
Jeff Hugo0682dad2012-10-22 11:34:28 -0600196static bool satellite_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700197
198static struct bam_ch_info bam_ch[BAM_DMUX_NUM_CHANNELS];
199static int bam_mux_initialized;
200
Jeff Hugo949080a2011-08-30 11:58:56 -0600201static int polling_mode;
Anurag Singhdcd8b4e2012-07-30 16:46:37 -0700202static unsigned long rx_timer_interval;
Jeff Hugo949080a2011-08-30 11:58:56 -0600203
204static LIST_HEAD(bam_rx_pool);
Jeff Hugoc9749932011-11-02 17:50:40 -0600205static DEFINE_MUTEX(bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700206static int bam_rx_pool_len;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600207static LIST_HEAD(bam_tx_pool);
Jeff Hugoc9749932011-11-02 17:50:40 -0600208static DEFINE_SPINLOCK(bam_tx_pool_spinlock);
Eric Holmberga623da82012-07-12 09:37:09 -0600209static DEFINE_MUTEX(bam_pdev_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -0600210
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700211struct bam_mux_hdr {
212 uint16_t magic_num;
213 uint8_t reserved;
214 uint8_t cmd;
215 uint8_t pad_len;
216 uint8_t ch_id;
217 uint16_t pkt_len;
218};
219
Jeff Hugod98b1082011-10-24 10:30:23 -0600220static void notify_all(int event, unsigned long data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700221static void bam_mux_write_done(struct work_struct *work);
222static void handle_bam_mux_cmd(struct work_struct *work);
Jeff Hugo949080a2011-08-30 11:58:56 -0600223static void rx_timer_work_func(struct work_struct *work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700224
Jeff Hugo949080a2011-08-30 11:58:56 -0600225static DECLARE_WORK(rx_timer_work, rx_timer_work_func);
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600226static struct delayed_work queue_rx_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700227
228static struct workqueue_struct *bam_mux_rx_workqueue;
229static struct workqueue_struct *bam_mux_tx_workqueue;
230
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600231/* A2 power collaspe */
232#define UL_TIMEOUT_DELAY 1000 /* in ms */
Jeff Hugo0b13a352012-03-17 23:18:30 -0600233#define ENABLE_DISCONNECT_ACK 0x1
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600234static void toggle_apps_ack(void);
235static void reconnect_to_bam(void);
236static void disconnect_to_bam(void);
237static void ul_wakeup(void);
238static void ul_timeout(struct work_struct *work);
239static void vote_dfab(void);
240static void unvote_dfab(void);
Jeff Hugod98b1082011-10-24 10:30:23 -0600241static void kickoff_ul_wakeup_func(struct work_struct *work);
Eric Holmberg006057d2012-01-11 10:10:42 -0700242static void grab_wakelock(void);
243static void release_wakelock(void);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600244
245static int bam_is_connected;
246static DEFINE_MUTEX(wakeup_lock);
247static struct completion ul_wakeup_ack_completion;
248static struct completion bam_connection_completion;
249static struct delayed_work ul_timeout_work;
250static int ul_packet_written;
Eric Holmbergbc9f21c2012-01-18 11:33:33 -0700251static atomic_t ul_ondemand_vote = ATOMIC_INIT(0);
Stephen Boyd69d35e32012-02-14 15:33:30 -0800252static struct clk *dfab_clk, *xo_clk;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600253static DEFINE_RWLOCK(ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600254static DECLARE_WORK(kickoff_ul_wakeup, kickoff_ul_wakeup_func);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600255static int bam_connection_is_active;
Jeff Hugof6c1c1e2011-12-01 17:43:49 -0700256static int wait_for_ack;
Jeff Hugoae3a85e2011-12-02 17:10:18 -0700257static struct wake_lock bam_wakelock;
Eric Holmberg006057d2012-01-11 10:10:42 -0700258static int a2_pc_disabled;
259static DEFINE_MUTEX(dfab_status_lock);
260static int dfab_is_on;
261static int wait_for_dfab;
262static struct completion dfab_unvote_completion;
263static DEFINE_SPINLOCK(wakelock_reference_lock);
264static int wakelock_reference_count;
Jeff Hugo583a6da2012-02-03 11:37:30 -0700265static int a2_pc_disabled_wakelock_skipped;
Jeff Hugob1e7c582012-06-20 15:02:11 -0600266static int disconnect_ack = 1;
Jeff Hugocb798022012-04-09 14:55:40 -0600267static LIST_HEAD(bam_other_notify_funcs);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -0600268static DEFINE_MUTEX(smsm_cb_lock);
Jeff Hugoc2696142012-05-03 11:42:13 -0600269static DEFINE_MUTEX(delayed_ul_vote_lock);
270static int need_delayed_ul_vote;
Jeff Hugo18792a32012-06-20 15:25:55 -0600271static int power_management_only_mode;
Jeff Hugocb798022012-04-09 14:55:40 -0600272
273struct outside_notify_func {
274 void (*notify)(void *, int, unsigned long);
275 void *priv;
276 struct list_head list_node;
277};
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600278/* End A2 power collaspe */
279
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600280/* subsystem restart */
281static int restart_notifier_cb(struct notifier_block *this,
282 unsigned long code,
283 void *data);
284
285static struct notifier_block restart_notifier = {
286 .notifier_call = restart_notifier_cb,
287};
288static int in_global_reset;
289/* end subsystem restart */
290
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700291#define bam_ch_is_open(x) \
292 (bam_ch[(x)].status == (BAM_CH_LOCAL_OPEN | BAM_CH_REMOTE_OPEN))
293
294#define bam_ch_is_local_open(x) \
295 (bam_ch[(x)].status & BAM_CH_LOCAL_OPEN)
296
297#define bam_ch_is_remote_open(x) \
298 (bam_ch[(x)].status & BAM_CH_REMOTE_OPEN)
299
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600300#define bam_ch_is_in_reset(x) \
301 (bam_ch[(x)].status & BAM_CH_IN_RESET)
302
Eric Holmberg878923a2012-01-10 14:28:19 -0700303#define LOG_MESSAGE_MAX_SIZE 80
304struct kfifo bam_dmux_state_log;
305static uint32_t bam_dmux_state_logging_disabled;
306static DEFINE_SPINLOCK(bam_dmux_logging_spinlock);
307static int bam_dmux_uplink_vote;
308static int bam_dmux_power_state;
309
Jeff Hugod7d2b062012-07-24 14:29:56 -0600310static void bam_dmux_log(const char *fmt, ...)
311 __printf(1, 2);
312
Eric Holmberg878923a2012-01-10 14:28:19 -0700313
314#define DMUX_LOG_KERR(fmt...) \
315do { \
316 bam_dmux_log(fmt); \
317 pr_err(fmt); \
318} while (0)
319
320/**
321 * Log a state change along with a small message.
322 *
323 * Complete size of messsage is limited to @todo.
324 */
325static void bam_dmux_log(const char *fmt, ...)
326{
327 char buff[LOG_MESSAGE_MAX_SIZE];
328 unsigned long flags;
329 va_list arg_list;
330 unsigned long long t_now;
331 unsigned long nanosec_rem;
332 int len = 0;
333
334 if (bam_dmux_state_logging_disabled)
335 return;
336
337 t_now = sched_clock();
338 nanosec_rem = do_div(t_now, 1000000000U);
339
340 /*
341 * States
Eric Holmberg006057d2012-01-11 10:10:42 -0700342 * D: 1 = Power collapse disabled
Eric Holmberg878923a2012-01-10 14:28:19 -0700343 * R: 1 = in global reset
344 * P: 1 = BAM is powered up
345 * A: 1 = BAM initialized and ready for data
346 *
347 * V: 1 = Uplink vote for power
348 * U: 1 = Uplink active
349 * W: 1 = Uplink Wait-for-ack
350 * A: 1 = Uplink ACK received
Eric Holmbergbc9f21c2012-01-18 11:33:33 -0700351 * #: >=1 On-demand uplink vote
Jeff Hugo0b13a352012-03-17 23:18:30 -0600352 * D: 1 = Disconnect ACK active
Eric Holmberg878923a2012-01-10 14:28:19 -0700353 */
354 len += scnprintf(buff, sizeof(buff),
Jeff Hugo0b13a352012-03-17 23:18:30 -0600355 "<DMUX> %u.%09lu %c%c%c%c %c%c%c%c%d%c ",
Eric Holmberg878923a2012-01-10 14:28:19 -0700356 (unsigned)t_now, nanosec_rem,
Eric Holmberg006057d2012-01-11 10:10:42 -0700357 a2_pc_disabled ? 'D' : 'd',
Eric Holmberg878923a2012-01-10 14:28:19 -0700358 in_global_reset ? 'R' : 'r',
359 bam_dmux_power_state ? 'P' : 'p',
360 bam_connection_is_active ? 'A' : 'a',
361 bam_dmux_uplink_vote ? 'V' : 'v',
362 bam_is_connected ? 'U' : 'u',
363 wait_for_ack ? 'W' : 'w',
Eric Holmbergbc9f21c2012-01-18 11:33:33 -0700364 ul_wakeup_ack_completion.done ? 'A' : 'a',
Jeff Hugo0b13a352012-03-17 23:18:30 -0600365 atomic_read(&ul_ondemand_vote),
366 disconnect_ack ? 'D' : 'd'
Eric Holmberg878923a2012-01-10 14:28:19 -0700367 );
368
369 va_start(arg_list, fmt);
370 len += vscnprintf(buff + len, sizeof(buff) - len, fmt, arg_list);
371 va_end(arg_list);
372 memset(buff + len, 0x0, sizeof(buff) - len);
373
374 spin_lock_irqsave(&bam_dmux_logging_spinlock, flags);
375 if (kfifo_avail(&bam_dmux_state_log) < LOG_MESSAGE_MAX_SIZE) {
376 char junk[LOG_MESSAGE_MAX_SIZE];
377 int ret;
378
379 ret = kfifo_out(&bam_dmux_state_log, junk, sizeof(junk));
380 if (ret != LOG_MESSAGE_MAX_SIZE) {
381 pr_err("%s: unable to empty log %d\n", __func__, ret);
382 spin_unlock_irqrestore(&bam_dmux_logging_spinlock,
383 flags);
384 return;
385 }
386 }
387 kfifo_in(&bam_dmux_state_log, buff, sizeof(buff));
388 spin_unlock_irqrestore(&bam_dmux_logging_spinlock, flags);
389}
390
391static inline void set_tx_timestamp(struct tx_pkt_info *pkt)
392{
393 unsigned long long t_now;
394
395 t_now = sched_clock();
396 pkt->ts_nsec = do_div(t_now, 1000000000U);
397 pkt->ts_sec = (unsigned)t_now;
398}
399
400static inline void verify_tx_queue_is_empty(const char *func)
401{
402 unsigned long flags;
403 struct tx_pkt_info *info;
404 int reported = 0;
405
406 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
407 list_for_each_entry(info, &bam_tx_pool, list_node) {
408 if (!reported) {
Eric Holmberg454d9da2012-01-12 09:37:14 -0700409 bam_dmux_log("%s: tx pool not empty\n", func);
410 if (!in_global_reset)
411 pr_err("%s: tx pool not empty\n", func);
Eric Holmberg878923a2012-01-10 14:28:19 -0700412 reported = 1;
413 }
Eric Holmberg454d9da2012-01-12 09:37:14 -0700414 bam_dmux_log("%s: node=%p ts=%u.%09lu\n", __func__,
415 &info->list_node, info->ts_sec, info->ts_nsec);
416 if (!in_global_reset)
417 pr_err("%s: node=%p ts=%u.%09lu\n", __func__,
418 &info->list_node, info->ts_sec, info->ts_nsec);
Eric Holmberg878923a2012-01-10 14:28:19 -0700419 }
420 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
421}
422
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700423static void queue_rx(void)
424{
425 void *ptr;
426 struct rx_pkt_info *info;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700427 int ret;
428 int rx_len_cached;
Jeff Hugo949080a2011-08-30 11:58:56 -0600429
Jeff Hugoc9749932011-11-02 17:50:40 -0600430 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700431 rx_len_cached = bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -0600432 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -0600433
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600434 while (bam_connection_is_active && rx_len_cached < NUM_BUFFERS) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700435 if (in_global_reset)
436 goto fail;
437
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600438 info = kmalloc(sizeof(struct rx_pkt_info),
439 GFP_NOWAIT | __GFP_NOWARN);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700440 if (!info) {
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600441 DMUX_LOG_KERR(
442 "%s: unable to alloc rx_pkt_info, will retry later\n",
443 __func__);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700444 goto fail;
445 }
446
447 INIT_WORK(&info->work, handle_bam_mux_cmd);
448
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600449 info->skb = __dev_alloc_skb(BUFFER_SIZE,
450 GFP_NOWAIT | __GFP_NOWARN);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700451 if (info->skb == NULL) {
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600452 DMUX_LOG_KERR(
453 "%s: unable to alloc skb, will retry later\n",
454 __func__);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700455 goto fail_info;
456 }
457 ptr = skb_put(info->skb, BUFFER_SIZE);
458
459 info->dma_address = dma_map_single(NULL, ptr, BUFFER_SIZE,
460 DMA_FROM_DEVICE);
461 if (info->dma_address == 0 || info->dma_address == ~0) {
462 DMUX_LOG_KERR("%s: dma_map_single failure %p for %p\n",
463 __func__, (void *)info->dma_address, ptr);
464 goto fail_skb;
465 }
466
467 mutex_lock(&bam_rx_pool_mutexlock);
468 list_add_tail(&info->list_node, &bam_rx_pool);
469 rx_len_cached = ++bam_rx_pool_len;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700470 ret = sps_transfer_one(bam_rx_pipe, info->dma_address,
471 BUFFER_SIZE, info,
472 SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700473 if (ret) {
Eric Holmberg00cf8692012-07-16 14:21:19 -0600474 list_del(&info->list_node);
475 rx_len_cached = --bam_rx_pool_len;
476 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700477 DMUX_LOG_KERR("%s: sps_transfer_one failed %d\n",
478 __func__, ret);
Eric Holmberg00cf8692012-07-16 14:21:19 -0600479
480 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
481 DMA_FROM_DEVICE);
482
483 goto fail_skb;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700484 }
Eric Holmberg00cf8692012-07-16 14:21:19 -0600485 mutex_unlock(&bam_rx_pool_mutexlock);
486
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700487 }
488 return;
489
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700490fail_skb:
491 dev_kfree_skb_any(info->skb);
492
493fail_info:
494 kfree(info);
495
496fail:
497 if (rx_len_cached == 0) {
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600498 DMUX_LOG_KERR("%s: rescheduling\n", __func__);
499 schedule_delayed_work(&queue_rx_work, msecs_to_jiffies(100));
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700500 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700501}
502
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600503static void queue_rx_work_func(struct work_struct *work)
504{
505 queue_rx();
506}
507
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700508static void bam_mux_process_data(struct sk_buff *rx_skb)
509{
510 unsigned long flags;
511 struct bam_mux_hdr *rx_hdr;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600512 unsigned long event_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700513
514 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
515
516 rx_skb->data = (unsigned char *)(rx_hdr + 1);
517 rx_skb->tail = rx_skb->data + rx_hdr->pkt_len;
518 rx_skb->len = rx_hdr->pkt_len;
Jeff Hugoee88f672011-10-04 17:14:52 -0600519 rx_skb->truesize = rx_hdr->pkt_len + sizeof(struct sk_buff);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700520
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600521 event_data = (unsigned long)(rx_skb);
522
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700523 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600524 if (bam_ch[rx_hdr->ch_id].notify)
525 bam_ch[rx_hdr->ch_id].notify(
526 bam_ch[rx_hdr->ch_id].priv, BAM_DMUX_RECEIVE,
527 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700528 else
529 dev_kfree_skb_any(rx_skb);
530 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
531
532 queue_rx();
533}
534
Eric Holmberg006057d2012-01-11 10:10:42 -0700535static inline void handle_bam_mux_cmd_open(struct bam_mux_hdr *rx_hdr)
536{
537 unsigned long flags;
538 int ret;
539
Eric Holmberga623da82012-07-12 09:37:09 -0600540 mutex_lock(&bam_pdev_mutexlock);
541 if (in_global_reset) {
542 bam_dmux_log("%s: open cid %d aborted due to ssr\n",
543 __func__, rx_hdr->ch_id);
544 mutex_unlock(&bam_pdev_mutexlock);
545 queue_rx();
546 return;
547 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700548 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
549 bam_ch[rx_hdr->ch_id].status |= BAM_CH_REMOTE_OPEN;
550 bam_ch[rx_hdr->ch_id].num_tx_pkts = 0;
551 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Eric Holmberg006057d2012-01-11 10:10:42 -0700552 ret = platform_device_add(bam_ch[rx_hdr->ch_id].pdev);
553 if (ret)
554 pr_err("%s: platform_device_add() error: %d\n",
555 __func__, ret);
Eric Holmberga623da82012-07-12 09:37:09 -0600556 mutex_unlock(&bam_pdev_mutexlock);
557 queue_rx();
Eric Holmberg006057d2012-01-11 10:10:42 -0700558}
559
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700560static void handle_bam_mux_cmd(struct work_struct *work)
561{
562 unsigned long flags;
563 struct bam_mux_hdr *rx_hdr;
564 struct rx_pkt_info *info;
565 struct sk_buff *rx_skb;
566
567 info = container_of(work, struct rx_pkt_info, work);
568 rx_skb = info->skb;
Jeff Hugo949080a2011-08-30 11:58:56 -0600569 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE, DMA_FROM_DEVICE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700570 kfree(info);
571
572 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
573
574 DBG_INC_READ_CNT(sizeof(struct bam_mux_hdr));
575 DBG("%s: magic %x reserved %d cmd %d pad %d ch %d len %d\n", __func__,
576 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
577 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
578 if (rx_hdr->magic_num != BAM_MUX_HDR_MAGIC_NO) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700579 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
580 " reserved %d cmd %d"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700581 " pad %d ch %d len %d\n", __func__,
582 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
583 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
584 dev_kfree_skb_any(rx_skb);
585 queue_rx();
586 return;
587 }
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700588
589 if (rx_hdr->ch_id >= BAM_DMUX_NUM_CHANNELS) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700590 DMUX_LOG_KERR("%s: dropping invalid LCID %d"
591 " reserved %d cmd %d"
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700592 " pad %d ch %d len %d\n", __func__,
593 rx_hdr->ch_id, rx_hdr->reserved, rx_hdr->cmd,
594 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
595 dev_kfree_skb_any(rx_skb);
596 queue_rx();
597 return;
598 }
599
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700600 switch (rx_hdr->cmd) {
601 case BAM_MUX_HDR_CMD_DATA:
602 DBG_INC_READ_CNT(rx_hdr->pkt_len);
603 bam_mux_process_data(rx_skb);
604 break;
605 case BAM_MUX_HDR_CMD_OPEN:
Eric Holmberg006057d2012-01-11 10:10:42 -0700606 bam_dmux_log("%s: opening cid %d PC enabled\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700607 rx_hdr->ch_id);
Eric Holmberg006057d2012-01-11 10:10:42 -0700608 handle_bam_mux_cmd_open(rx_hdr);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600609 if (!(rx_hdr->reserved & ENABLE_DISCONNECT_ACK)) {
Jeff Hugod7d2b062012-07-24 14:29:56 -0600610 bam_dmux_log("%s: deactivating disconnect ack\n",
611 __func__);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600612 disconnect_ack = 0;
Jeff Hugo0b13a352012-03-17 23:18:30 -0600613 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700614 dev_kfree_skb_any(rx_skb);
615 break;
616 case BAM_MUX_HDR_CMD_OPEN_NO_A2_PC:
617 bam_dmux_log("%s: opening cid %d PC disabled\n", __func__,
618 rx_hdr->ch_id);
619
620 if (!a2_pc_disabled) {
621 a2_pc_disabled = 1;
Jeff Hugo322179f2012-02-29 10:52:34 -0700622 ul_wakeup();
Eric Holmberg006057d2012-01-11 10:10:42 -0700623 }
624
625 handle_bam_mux_cmd_open(rx_hdr);
Eric Holmberge779dba2011-11-04 18:22:01 -0600626 dev_kfree_skb_any(rx_skb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700627 break;
628 case BAM_MUX_HDR_CMD_CLOSE:
629 /* probably should drop pending write */
Eric Holmberg878923a2012-01-10 14:28:19 -0700630 bam_dmux_log("%s: closing cid %d\n", __func__,
631 rx_hdr->ch_id);
Eric Holmberga623da82012-07-12 09:37:09 -0600632 mutex_lock(&bam_pdev_mutexlock);
633 if (in_global_reset) {
634 bam_dmux_log("%s: close cid %d aborted due to ssr\n",
635 __func__, rx_hdr->ch_id);
636 mutex_unlock(&bam_pdev_mutexlock);
637 break;
638 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700639 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
640 bam_ch[rx_hdr->ch_id].status &= ~BAM_CH_REMOTE_OPEN;
641 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo7960abd2011-08-02 15:39:38 -0600642 platform_device_unregister(bam_ch[rx_hdr->ch_id].pdev);
643 bam_ch[rx_hdr->ch_id].pdev =
644 platform_device_alloc(bam_ch[rx_hdr->ch_id].name, 2);
645 if (!bam_ch[rx_hdr->ch_id].pdev)
646 pr_err("%s: platform_device_alloc failed\n", __func__);
Eric Holmberga623da82012-07-12 09:37:09 -0600647 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberge779dba2011-11-04 18:22:01 -0600648 dev_kfree_skb_any(rx_skb);
Eric Holmberga623da82012-07-12 09:37:09 -0600649 queue_rx();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700650 break;
651 default:
Eric Holmberg878923a2012-01-10 14:28:19 -0700652 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
653 " reserved %d cmd %d pad %d ch %d len %d\n",
654 __func__, rx_hdr->magic_num, rx_hdr->reserved,
655 rx_hdr->cmd, rx_hdr->pad_len, rx_hdr->ch_id,
656 rx_hdr->pkt_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700657 dev_kfree_skb_any(rx_skb);
658 queue_rx();
659 return;
660 }
661}
662
663static int bam_mux_write_cmd(void *data, uint32_t len)
664{
665 int rc;
666 struct tx_pkt_info *pkt;
667 dma_addr_t dma_address;
Jeff Hugo626303bf2011-11-21 11:43:28 -0700668 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700669
Eric Holmbergd83cd2b2011-11-04 15:54:17 -0600670 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700671 if (pkt == NULL) {
672 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
673 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700674 return rc;
675 }
676
677 dma_address = dma_map_single(NULL, data, len,
678 DMA_TO_DEVICE);
679 if (!dma_address) {
680 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugo96cb7482011-12-07 13:28:31 -0700681 kfree(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700682 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700683 return rc;
684 }
685 pkt->skb = (struct sk_buff *)(data);
686 pkt->len = len;
687 pkt->dma_address = dma_address;
688 pkt->is_cmd = 1;
Eric Holmberg878923a2012-01-10 14:28:19 -0700689 set_tx_timestamp(pkt);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600690 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700691 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600692 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700693 rc = sps_transfer_one(bam_tx_pipe, dma_address, len,
694 pkt, SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600695 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700696 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
697 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600698 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700699 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700700 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700701 dma_unmap_single(NULL, pkt->dma_address,
702 pkt->len,
703 DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600704 kfree(pkt);
Jeff Hugobb6da952012-01-16 15:02:42 -0700705 } else {
706 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600707 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700708
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600709 ul_packet_written = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700710 return rc;
711}
712
713static void bam_mux_write_done(struct work_struct *work)
714{
715 struct sk_buff *skb;
716 struct bam_mux_hdr *hdr;
717 struct tx_pkt_info *info;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700718 struct tx_pkt_info *info_expected;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600719 unsigned long event_data;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700720 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700721
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600722 if (in_global_reset)
723 return;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700724
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700725 info = container_of(work, struct tx_pkt_info, work);
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700726
727 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
728 info_expected = list_first_entry(&bam_tx_pool,
729 struct tx_pkt_info, list_node);
730 if (unlikely(info != info_expected)) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700731 struct tx_pkt_info *errant_pkt;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700732
Eric Holmberg878923a2012-01-10 14:28:19 -0700733 DMUX_LOG_KERR("%s: bam_tx_pool mismatch .next=%p,"
734 " list_node=%p, ts=%u.%09lu\n",
735 __func__, bam_tx_pool.next, &info->list_node,
736 info->ts_sec, info->ts_nsec
737 );
738
739 list_for_each_entry(errant_pkt, &bam_tx_pool, list_node) {
740 DMUX_LOG_KERR("%s: node=%p ts=%u.%09lu\n", __func__,
741 &errant_pkt->list_node, errant_pkt->ts_sec,
742 errant_pkt->ts_nsec);
743
744 }
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700745 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
746 BUG();
747 }
748 list_del(&info->list_node);
749 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
750
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600751 if (info->is_cmd) {
752 kfree(info->skb);
753 kfree(info);
754 return;
755 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700756 skb = info->skb;
757 kfree(info);
758 hdr = (struct bam_mux_hdr *)skb->data;
Eric Holmberg9fdef262012-02-14 11:46:05 -0700759 DBG_INC_WRITE_CNT(skb->len);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600760 event_data = (unsigned long)(skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700761 spin_lock_irqsave(&bam_ch[hdr->ch_id].lock, flags);
762 bam_ch[hdr->ch_id].num_tx_pkts--;
763 spin_unlock_irqrestore(&bam_ch[hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600764 if (bam_ch[hdr->ch_id].notify)
765 bam_ch[hdr->ch_id].notify(
766 bam_ch[hdr->ch_id].priv, BAM_DMUX_WRITE_DONE,
767 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700768 else
769 dev_kfree_skb_any(skb);
770}
771
772int msm_bam_dmux_write(uint32_t id, struct sk_buff *skb)
773{
774 int rc = 0;
775 struct bam_mux_hdr *hdr;
776 unsigned long flags;
777 struct sk_buff *new_skb = NULL;
778 dma_addr_t dma_address;
779 struct tx_pkt_info *pkt;
780
781 if (id >= BAM_DMUX_NUM_CHANNELS)
782 return -EINVAL;
783 if (!skb)
784 return -EINVAL;
785 if (!bam_mux_initialized)
786 return -ENODEV;
787
788 DBG("%s: writing to ch %d len %d\n", __func__, id, skb->len);
789 spin_lock_irqsave(&bam_ch[id].lock, flags);
790 if (!bam_ch_is_open(id)) {
791 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
792 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
793 return -ENODEV;
794 }
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700795
796 if (bam_ch[id].use_wm &&
797 (bam_ch[id].num_tx_pkts >= HIGH_WATERMARK)) {
798 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
799 pr_err("%s: watermark exceeded: %d\n", __func__, id);
800 return -EAGAIN;
801 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700802 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
803
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600804 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600805 if (!bam_is_connected) {
806 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600807 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700808 if (unlikely(in_global_reset == 1))
809 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600810 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600811 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600812 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600813
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700814 /* if skb do not have any tailroom for padding,
815 copy the skb into a new expanded skb */
816 if ((skb->len & 0x3) && (skb_tailroom(skb) < (4 - (skb->len & 0x3)))) {
817 /* revisit, probably dev_alloc_skb and memcpy is effecient */
818 new_skb = skb_copy_expand(skb, skb_headroom(skb),
819 4 - (skb->len & 0x3), GFP_ATOMIC);
820 if (new_skb == NULL) {
821 pr_err("%s: cannot allocate skb\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600822 goto write_fail;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700823 }
824 dev_kfree_skb_any(skb);
825 skb = new_skb;
826 DBG_INC_WRITE_CPY(skb->len);
827 }
828
829 hdr = (struct bam_mux_hdr *)skb_push(skb, sizeof(struct bam_mux_hdr));
830
831 /* caller should allocate for hdr and padding
832 hdr is fine, padding is tricky */
833 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
834 hdr->cmd = BAM_MUX_HDR_CMD_DATA;
835 hdr->reserved = 0;
836 hdr->ch_id = id;
837 hdr->pkt_len = skb->len - sizeof(struct bam_mux_hdr);
838 if (skb->len & 0x3)
839 skb_put(skb, 4 - (skb->len & 0x3));
840
841 hdr->pad_len = skb->len - (sizeof(struct bam_mux_hdr) + hdr->pkt_len);
842
843 DBG("%s: data %p, tail %p skb len %d pkt len %d pad len %d\n",
844 __func__, skb->data, skb->tail, skb->len,
845 hdr->pkt_len, hdr->pad_len);
846
847 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
848 if (pkt == NULL) {
849 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600850 goto write_fail2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700851 }
852
853 dma_address = dma_map_single(NULL, skb->data, skb->len,
854 DMA_TO_DEVICE);
855 if (!dma_address) {
856 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600857 goto write_fail3;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700858 }
859 pkt->skb = skb;
860 pkt->dma_address = dma_address;
861 pkt->is_cmd = 0;
Eric Holmberg878923a2012-01-10 14:28:19 -0700862 set_tx_timestamp(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700863 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700864 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600865 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700866 rc = sps_transfer_one(bam_tx_pipe, dma_address, skb->len,
867 pkt, SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600868 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700869 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
870 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600871 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700872 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700873 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700874 dma_unmap_single(NULL, pkt->dma_address,
875 pkt->skb->len, DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600876 kfree(pkt);
Jeff Hugo872bd062011-11-15 17:47:21 -0700877 if (new_skb)
878 dev_kfree_skb_any(new_skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700879 } else {
Jeff Hugobb6da952012-01-16 15:02:42 -0700880 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700881 spin_lock_irqsave(&bam_ch[id].lock, flags);
882 bam_ch[id].num_tx_pkts++;
883 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600884 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600885 ul_packet_written = 1;
886 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700887 return rc;
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600888
889write_fail3:
890 kfree(pkt);
891write_fail2:
892 if (new_skb)
893 dev_kfree_skb_any(new_skb);
894write_fail:
895 read_unlock(&ul_wakeup_lock);
896 return -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700897}
898
899int msm_bam_dmux_open(uint32_t id, void *priv,
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600900 void (*notify)(void *, int, unsigned long))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700901{
902 struct bam_mux_hdr *hdr;
903 unsigned long flags;
904 int rc = 0;
905
906 DBG("%s: opening ch %d\n", __func__, id);
Eric Holmberg5d775432011-11-09 10:23:35 -0700907 if (!bam_mux_initialized) {
908 DBG("%s: not inititialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700909 return -ENODEV;
Eric Holmberg5d775432011-11-09 10:23:35 -0700910 }
911 if (id >= BAM_DMUX_NUM_CHANNELS) {
912 pr_err("%s: invalid channel id %d\n", __func__, id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700913 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700914 }
915 if (notify == NULL) {
916 pr_err("%s: notify function is NULL\n", __func__);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600917 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700918 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700919
920 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_KERNEL);
921 if (hdr == NULL) {
922 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
923 return -ENOMEM;
924 }
925 spin_lock_irqsave(&bam_ch[id].lock, flags);
926 if (bam_ch_is_open(id)) {
927 DBG("%s: Already opened %d\n", __func__, id);
928 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
929 kfree(hdr);
930 goto open_done;
931 }
932 if (!bam_ch_is_remote_open(id)) {
933 DBG("%s: Remote not open; ch: %d\n", __func__, id);
934 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
935 kfree(hdr);
Eric Holmberg5d775432011-11-09 10:23:35 -0700936 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700937 }
938
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600939 bam_ch[id].notify = notify;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700940 bam_ch[id].priv = priv;
941 bam_ch[id].status |= BAM_CH_LOCAL_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700942 bam_ch[id].num_tx_pkts = 0;
943 bam_ch[id].use_wm = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700944 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
945
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600946 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600947 if (!bam_is_connected) {
948 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600949 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700950 if (unlikely(in_global_reset == 1))
951 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600952 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600953 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600954 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600955
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700956 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
957 hdr->cmd = BAM_MUX_HDR_CMD_OPEN;
958 hdr->reserved = 0;
959 hdr->ch_id = id;
960 hdr->pkt_len = 0;
961 hdr->pad_len = 0;
962
963 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600964 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700965
966open_done:
967 DBG("%s: opened ch %d\n", __func__, id);
968 return rc;
969}
970
971int msm_bam_dmux_close(uint32_t id)
972{
973 struct bam_mux_hdr *hdr;
974 unsigned long flags;
975 int rc;
976
977 if (id >= BAM_DMUX_NUM_CHANNELS)
978 return -EINVAL;
979 DBG("%s: closing ch %d\n", __func__, id);
980 if (!bam_mux_initialized)
981 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700982
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600983 read_lock(&ul_wakeup_lock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600984 if (!bam_is_connected && !bam_ch_is_in_reset(id)) {
Jeff Hugo061ce672011-10-21 17:15:32 -0600985 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600986 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700987 if (unlikely(in_global_reset == 1))
988 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600989 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600990 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600991 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600992
Jeff Hugo061ce672011-10-21 17:15:32 -0600993 spin_lock_irqsave(&bam_ch[id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600994 bam_ch[id].notify = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700995 bam_ch[id].priv = NULL;
996 bam_ch[id].status &= ~BAM_CH_LOCAL_OPEN;
997 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
998
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600999 if (bam_ch_is_in_reset(id)) {
1000 read_unlock(&ul_wakeup_lock);
1001 bam_ch[id].status &= ~BAM_CH_IN_RESET;
1002 return 0;
1003 }
1004
Jeff Hugobb5802f2011-11-02 17:10:29 -06001005 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001006 if (hdr == NULL) {
1007 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
Jeff Hugoc6af54d2011-11-02 17:00:27 -06001008 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001009 return -ENOMEM;
1010 }
1011 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
1012 hdr->cmd = BAM_MUX_HDR_CMD_CLOSE;
1013 hdr->reserved = 0;
1014 hdr->ch_id = id;
1015 hdr->pkt_len = 0;
1016 hdr->pad_len = 0;
1017
1018 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001019 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001020
1021 DBG("%s: closed ch %d\n", __func__, id);
1022 return rc;
1023}
1024
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001025int msm_bam_dmux_is_ch_full(uint32_t id)
1026{
1027 unsigned long flags;
1028 int ret;
1029
1030 if (id >= BAM_DMUX_NUM_CHANNELS)
1031 return -EINVAL;
1032
1033 spin_lock_irqsave(&bam_ch[id].lock, flags);
1034 bam_ch[id].use_wm = 1;
1035 ret = bam_ch[id].num_tx_pkts >= HIGH_WATERMARK;
1036 DBG("%s: ch %d num tx pkts=%d, HWM=%d\n", __func__,
1037 id, bam_ch[id].num_tx_pkts, ret);
1038 if (!bam_ch_is_local_open(id)) {
1039 ret = -ENODEV;
1040 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1041 }
1042 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
1043
1044 return ret;
1045}
1046
1047int msm_bam_dmux_is_ch_low(uint32_t id)
1048{
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001049 unsigned long flags;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001050 int ret;
1051
1052 if (id >= BAM_DMUX_NUM_CHANNELS)
1053 return -EINVAL;
1054
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001055 spin_lock_irqsave(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001056 bam_ch[id].use_wm = 1;
1057 ret = bam_ch[id].num_tx_pkts <= LOW_WATERMARK;
1058 DBG("%s: ch %d num tx pkts=%d, LWM=%d\n", __func__,
1059 id, bam_ch[id].num_tx_pkts, ret);
1060 if (!bam_ch_is_local_open(id)) {
1061 ret = -ENODEV;
1062 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1063 }
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001064 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001065
1066 return ret;
1067}
1068
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001069static void rx_switch_to_interrupt_mode(void)
1070{
1071 struct sps_connect cur_rx_conn;
1072 struct sps_iovec iov;
1073 struct rx_pkt_info *info;
1074 int ret;
1075
1076 /*
1077 * Attempt to enable interrupts - if this fails,
1078 * continue polling and we will retry later.
1079 */
1080 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1081 if (ret) {
1082 pr_err("%s: sps_get_config() failed %d\n", __func__, ret);
1083 goto fail;
1084 }
1085
1086 rx_register_event.options = SPS_O_EOT;
1087 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
1088 if (ret) {
1089 pr_err("%s: sps_register_event() failed %d\n", __func__, ret);
1090 goto fail;
1091 }
1092
1093 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
1094 SPS_O_EOT | SPS_O_ACK_TRANSFERS;
1095 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1096 if (ret) {
1097 pr_err("%s: sps_set_config() failed %d\n", __func__, ret);
1098 goto fail;
1099 }
1100 polling_mode = 0;
Eric Holmberg006057d2012-01-11 10:10:42 -07001101 release_wakelock();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001102
1103 /* handle any rx packets before interrupt was enabled */
1104 while (bam_connection_is_active && !polling_mode) {
1105 ret = sps_get_iovec(bam_rx_pipe, &iov);
1106 if (ret) {
1107 pr_err("%s: sps_get_iovec failed %d\n",
1108 __func__, ret);
1109 break;
1110 }
1111 if (iov.addr == 0)
1112 break;
1113
1114 mutex_lock(&bam_rx_pool_mutexlock);
1115 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001116 DMUX_LOG_KERR("%s: have iovec %p but rx pool empty\n",
1117 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001118 mutex_unlock(&bam_rx_pool_mutexlock);
1119 continue;
1120 }
1121 info = list_first_entry(&bam_rx_pool, struct rx_pkt_info,
1122 list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001123 if (info->dma_address != iov.addr) {
1124 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1125 __func__,
1126 (void *)iov.addr,
1127 (void *)info->dma_address);
1128 list_for_each_entry(info, &bam_rx_pool, list_node) {
1129 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1130 (void *)info->dma_address);
1131 if (iov.addr == info->dma_address)
1132 break;
1133 }
1134 }
1135 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001136 list_del(&info->list_node);
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001137 --bam_rx_pool_len;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001138 mutex_unlock(&bam_rx_pool_mutexlock);
1139 handle_bam_mux_cmd(&info->work);
1140 }
1141 return;
1142
1143fail:
1144 pr_err("%s: reverting to polling\n", __func__);
Jeff Hugofff43af92012-03-29 17:54:52 -06001145 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001146}
1147
Jeff Hugo949080a2011-08-30 11:58:56 -06001148static void rx_timer_work_func(struct work_struct *work)
1149{
1150 struct sps_iovec iov;
Jeff Hugo949080a2011-08-30 11:58:56 -06001151 struct rx_pkt_info *info;
1152 int inactive_cycles = 0;
1153 int ret;
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001154 u32 buffs_unused, buffs_used;
Jeff Hugo949080a2011-08-30 11:58:56 -06001155
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001156 while (bam_connection_is_active) { /* timer loop */
Jeff Hugo949080a2011-08-30 11:58:56 -06001157 ++inactive_cycles;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001158 while (bam_connection_is_active) { /* deplete queue loop */
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001159 if (in_global_reset)
1160 return;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001161
1162 ret = sps_get_iovec(bam_rx_pipe, &iov);
1163 if (ret) {
1164 pr_err("%s: sps_get_iovec failed %d\n",
1165 __func__, ret);
1166 break;
1167 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001168 if (iov.addr == 0)
1169 break;
1170 inactive_cycles = 0;
Jeff Hugoc9749932011-11-02 17:50:40 -06001171 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001172 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001173 DMUX_LOG_KERR(
1174 "%s: have iovec %p but rx pool empty\n",
1175 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001176 mutex_unlock(&bam_rx_pool_mutexlock);
1177 continue;
1178 }
1179 info = list_first_entry(&bam_rx_pool,
1180 struct rx_pkt_info, list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001181 if (info->dma_address != iov.addr) {
1182 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1183 __func__,
1184 (void *)iov.addr,
1185 (void *)info->dma_address);
1186 list_for_each_entry(info, &bam_rx_pool,
1187 list_node) {
1188 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1189 (void *)info->dma_address);
1190 if (iov.addr == info->dma_address)
1191 break;
1192 }
1193 }
1194 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001195 list_del(&info->list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001196 --bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -06001197 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -06001198 handle_bam_mux_cmd(&info->work);
1199 }
1200
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001201 if (inactive_cycles >= POLLING_INACTIVITY) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001202 rx_switch_to_interrupt_mode();
1203 break;
Jeff Hugo949080a2011-08-30 11:58:56 -06001204 }
1205
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001206 if (bam_adaptive_timer_enabled) {
1207 usleep_range(rx_timer_interval, rx_timer_interval + 50);
1208
1209 ret = sps_get_unused_desc_num(bam_rx_pipe,
1210 &buffs_unused);
1211
1212 if (ret) {
1213 pr_err("%s: error getting num buffers unused after sleep\n",
1214 __func__);
1215
1216 break;
1217 }
1218
1219 buffs_used = NUM_BUFFERS - buffs_unused;
1220
1221 if (buffs_unused == 0) {
1222 rx_timer_interval = MIN_POLLING_SLEEP;
1223 } else {
1224 if (buffs_used > 0) {
1225 rx_timer_interval =
1226 (2 * NUM_BUFFERS *
1227 rx_timer_interval)/
1228 (3 * buffs_used);
1229 } else {
1230 rx_timer_interval =
1231 MAX_POLLING_SLEEP;
1232 }
1233 }
1234
1235 if (rx_timer_interval > MAX_POLLING_SLEEP)
1236 rx_timer_interval = MAX_POLLING_SLEEP;
1237 else if (rx_timer_interval < MIN_POLLING_SLEEP)
1238 rx_timer_interval = MIN_POLLING_SLEEP;
1239 } else {
1240 usleep_range(POLLING_MIN_SLEEP, POLLING_MAX_SLEEP);
1241 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001242 }
1243}
1244
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001245static void bam_mux_tx_notify(struct sps_event_notify *notify)
1246{
1247 struct tx_pkt_info *pkt;
1248
1249 DBG("%s: event %d notified\n", __func__, notify->event_id);
1250
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001251 if (in_global_reset)
1252 return;
1253
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001254 switch (notify->event_id) {
1255 case SPS_EVENT_EOT:
1256 pkt = notify->data.transfer.user;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001257 if (!pkt->is_cmd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001258 dma_unmap_single(NULL, pkt->dma_address,
1259 pkt->skb->len,
1260 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001261 else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001262 dma_unmap_single(NULL, pkt->dma_address,
1263 pkt->len,
1264 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001265 queue_work(bam_mux_tx_workqueue, &pkt->work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001266 break;
1267 default:
1268 pr_err("%s: recieved unexpected event id %d\n", __func__,
1269 notify->event_id);
1270 }
1271}
1272
Jeff Hugo33dbc002011-08-25 15:52:53 -06001273static void bam_mux_rx_notify(struct sps_event_notify *notify)
1274{
Jeff Hugo949080a2011-08-30 11:58:56 -06001275 int ret;
1276 struct sps_connect cur_rx_conn;
Jeff Hugo33dbc002011-08-25 15:52:53 -06001277
1278 DBG("%s: event %d notified\n", __func__, notify->event_id);
1279
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001280 if (in_global_reset)
1281 return;
1282
Jeff Hugo33dbc002011-08-25 15:52:53 -06001283 switch (notify->event_id) {
1284 case SPS_EVENT_EOT:
Jeff Hugo949080a2011-08-30 11:58:56 -06001285 /* attempt to disable interrupts in this pipe */
1286 if (!polling_mode) {
1287 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1288 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001289 pr_err("%s: sps_get_config() failed %d, interrupts"
1290 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001291 break;
1292 }
Jeff Hugoa9d32ba2011-11-21 14:59:48 -07001293 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
Jeff Hugo949080a2011-08-30 11:58:56 -06001294 SPS_O_ACK_TRANSFERS | SPS_O_POLL;
1295 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1296 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001297 pr_err("%s: sps_set_config() failed %d, interrupts"
1298 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001299 break;
1300 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001301 grab_wakelock();
Jeff Hugo949080a2011-08-30 11:58:56 -06001302 polling_mode = 1;
Jeff Hugofff43af92012-03-29 17:54:52 -06001303 /*
1304 * run on core 0 so that netif_rx() in rmnet uses only
1305 * one queue
1306 */
1307 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Jeff Hugo949080a2011-08-30 11:58:56 -06001308 }
Jeff Hugo33dbc002011-08-25 15:52:53 -06001309 break;
1310 default:
1311 pr_err("%s: recieved unexpected event id %d\n", __func__,
1312 notify->event_id);
1313 }
1314}
1315
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001316#ifdef CONFIG_DEBUG_FS
1317
1318static int debug_tbl(char *buf, int max)
1319{
1320 int i = 0;
1321 int j;
1322
1323 for (j = 0; j < BAM_DMUX_NUM_CHANNELS; ++j) {
1324 i += scnprintf(buf + i, max - i,
1325 "ch%02d local open=%s remote open=%s\n",
1326 j, bam_ch_is_local_open(j) ? "Y" : "N",
1327 bam_ch_is_remote_open(j) ? "Y" : "N");
1328 }
1329
1330 return i;
1331}
1332
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001333static int debug_ul_pkt_cnt(char *buf, int max)
1334{
1335 struct list_head *p;
1336 unsigned long flags;
1337 int n = 0;
1338
1339 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
1340 __list_for_each(p, &bam_tx_pool) {
1341 ++n;
1342 }
1343 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
1344
1345 return scnprintf(buf, max, "Number of UL packets in flight: %d\n", n);
1346}
1347
1348static int debug_stats(char *buf, int max)
1349{
1350 int i = 0;
1351
1352 i += scnprintf(buf + i, max - i,
Eric Holmberg9fdef262012-02-14 11:46:05 -07001353 "skb read cnt: %u\n"
1354 "skb write cnt: %u\n"
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001355 "skb copy cnt: %u\n"
1356 "skb copy bytes: %u\n"
Eric Holmberg6074aba2012-01-18 17:59:44 -07001357 "sps tx failures: %u\n"
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001358 "sps tx stalls: %u\n"
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001359 "rx queue len: %d\n"
1360 "a2 ack out cnt: %d\n"
1361 "a2 ack in cnt: %d\n"
1362 "a2 pwr cntl in: %d\n",
Eric Holmberg9fdef262012-02-14 11:46:05 -07001363 bam_dmux_read_cnt,
1364 bam_dmux_write_cnt,
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001365 bam_dmux_write_cpy_cnt,
1366 bam_dmux_write_cpy_bytes,
Eric Holmberg6074aba2012-01-18 17:59:44 -07001367 bam_dmux_tx_sps_failure_cnt,
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001368 bam_dmux_tx_stall_cnt,
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001369 bam_rx_pool_len,
1370 atomic_read(&bam_dmux_ack_out_cnt),
1371 atomic_read(&bam_dmux_ack_in_cnt),
1372 atomic_read(&bam_dmux_a2_pwr_cntl_in_cnt)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001373 );
1374
1375 return i;
1376}
1377
Eric Holmberg878923a2012-01-10 14:28:19 -07001378static int debug_log(char *buff, int max, loff_t *ppos)
1379{
1380 unsigned long flags;
1381 int i = 0;
1382
1383 if (bam_dmux_state_logging_disabled) {
1384 i += scnprintf(buff - i, max - i, "Logging disabled\n");
1385 return i;
1386 }
1387
1388 if (*ppos == 0) {
1389 i += scnprintf(buff - i, max - i,
1390 "<DMUX> timestamp FLAGS [Message]\n"
1391 "FLAGS:\n"
Eric Holmberg006057d2012-01-11 10:10:42 -07001392 "\tD: 1 = Power collapse disabled\n"
Eric Holmberg878923a2012-01-10 14:28:19 -07001393 "\tR: 1 = in global reset\n"
1394 "\tP: 1 = BAM is powered up\n"
1395 "\tA: 1 = BAM initialized and ready for data\n"
1396 "\n"
1397 "\tV: 1 = Uplink vote for power\n"
1398 "\tU: 1 = Uplink active\n"
1399 "\tW: 1 = Uplink Wait-for-ack\n"
1400 "\tA: 1 = Uplink ACK received\n"
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001401 "\t#: >=1 On-demand uplink vote\n"
Jeff Hugo0b13a352012-03-17 23:18:30 -06001402 "\tD: 1 = Disconnect ACK active\n"
Eric Holmberg878923a2012-01-10 14:28:19 -07001403 );
1404 buff += i;
1405 }
1406
1407 spin_lock_irqsave(&bam_dmux_logging_spinlock, flags);
1408 while (kfifo_len(&bam_dmux_state_log)
1409 && (i + LOG_MESSAGE_MAX_SIZE) < max) {
1410 int k_len;
1411 k_len = kfifo_out(&bam_dmux_state_log,
1412 buff, LOG_MESSAGE_MAX_SIZE);
1413 if (k_len != LOG_MESSAGE_MAX_SIZE) {
1414 pr_err("%s: retrieve failure %d\n", __func__, k_len);
1415 break;
1416 }
1417
1418 /* keep non-null portion of string and add line break */
1419 k_len = strnlen(buff, LOG_MESSAGE_MAX_SIZE);
1420 buff += k_len;
1421 i += k_len;
1422 if (k_len && *(buff - 1) != '\n') {
1423 *buff++ = '\n';
1424 ++i;
1425 }
1426 }
1427 spin_unlock_irqrestore(&bam_dmux_logging_spinlock, flags);
1428
1429 return i;
1430}
1431
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001432#define DEBUG_BUFMAX 4096
1433static char debug_buffer[DEBUG_BUFMAX];
1434
1435static ssize_t debug_read(struct file *file, char __user *buf,
1436 size_t count, loff_t *ppos)
1437{
1438 int (*fill)(char *buf, int max) = file->private_data;
1439 int bsize = fill(debug_buffer, DEBUG_BUFMAX);
1440 return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
1441}
1442
Eric Holmberg878923a2012-01-10 14:28:19 -07001443static ssize_t debug_read_multiple(struct file *file, char __user *buff,
1444 size_t count, loff_t *ppos)
1445{
1446 int (*util_func)(char *buf, int max, loff_t *) = file->private_data;
1447 char *buffer;
1448 int bsize;
1449
1450 buffer = kmalloc(count, GFP_KERNEL);
1451 if (!buffer)
1452 return -ENOMEM;
1453
1454 bsize = util_func(buffer, count, ppos);
1455
1456 if (bsize >= 0) {
1457 if (copy_to_user(buff, buffer, bsize)) {
1458 kfree(buffer);
1459 return -EFAULT;
1460 }
1461 *ppos += bsize;
1462 }
1463 kfree(buffer);
1464 return bsize;
1465}
1466
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001467static int debug_open(struct inode *inode, struct file *file)
1468{
1469 file->private_data = inode->i_private;
1470 return 0;
1471}
1472
1473
1474static const struct file_operations debug_ops = {
1475 .read = debug_read,
1476 .open = debug_open,
1477};
1478
Eric Holmberg878923a2012-01-10 14:28:19 -07001479static const struct file_operations debug_ops_multiple = {
1480 .read = debug_read_multiple,
1481 .open = debug_open,
1482};
1483
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001484static void debug_create(const char *name, mode_t mode,
1485 struct dentry *dent,
1486 int (*fill)(char *buf, int max))
1487{
Eric Holmberge4ac80b2012-01-12 09:21:59 -07001488 struct dentry *file;
1489
1490 file = debugfs_create_file(name, mode, dent, fill, &debug_ops);
1491 if (IS_ERR(file))
1492 pr_err("%s: debugfs create failed %d\n", __func__,
1493 (int)PTR_ERR(file));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001494}
1495
Eric Holmberge4ac80b2012-01-12 09:21:59 -07001496static void debug_create_multiple(const char *name, mode_t mode,
1497 struct dentry *dent,
1498 int (*fill)(char *buf, int max, loff_t *ppos))
1499{
1500 struct dentry *file;
1501
1502 file = debugfs_create_file(name, mode, dent, fill, &debug_ops_multiple);
1503 if (IS_ERR(file))
1504 pr_err("%s: debugfs create failed %d\n", __func__,
1505 (int)PTR_ERR(file));
1506}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001507#endif
1508
Jeff Hugod98b1082011-10-24 10:30:23 -06001509static void notify_all(int event, unsigned long data)
1510{
1511 int i;
Jeff Hugocb798022012-04-09 14:55:40 -06001512 struct list_head *temp;
1513 struct outside_notify_func *func;
Jeff Hugod98b1082011-10-24 10:30:23 -06001514
1515 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
Eric Holmberg454d9da2012-01-12 09:37:14 -07001516 if (bam_ch_is_open(i)) {
Jeff Hugod98b1082011-10-24 10:30:23 -06001517 bam_ch[i].notify(bam_ch[i].priv, event, data);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001518 bam_dmux_log("%s: cid=%d, event=%d, data=%lu\n",
1519 __func__, i, event, data);
1520 }
Jeff Hugod98b1082011-10-24 10:30:23 -06001521 }
Jeff Hugocb798022012-04-09 14:55:40 -06001522
1523 __list_for_each(temp, &bam_other_notify_funcs) {
1524 func = container_of(temp, struct outside_notify_func,
1525 list_node);
1526 func->notify(func->priv, event, data);
1527 }
Jeff Hugod98b1082011-10-24 10:30:23 -06001528}
1529
1530static void kickoff_ul_wakeup_func(struct work_struct *work)
1531{
1532 read_lock(&ul_wakeup_lock);
1533 if (!bam_is_connected) {
1534 read_unlock(&ul_wakeup_lock);
1535 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -07001536 if (unlikely(in_global_reset == 1))
1537 return;
Jeff Hugod98b1082011-10-24 10:30:23 -06001538 read_lock(&ul_wakeup_lock);
1539 ul_packet_written = 1;
1540 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
1541 }
1542 read_unlock(&ul_wakeup_lock);
1543}
1544
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001545int msm_bam_dmux_kickoff_ul_wakeup(void)
Jeff Hugod98b1082011-10-24 10:30:23 -06001546{
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001547 int is_connected;
1548
1549 read_lock(&ul_wakeup_lock);
1550 ul_packet_written = 1;
1551 is_connected = bam_is_connected;
1552 if (!is_connected)
1553 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1554 read_unlock(&ul_wakeup_lock);
1555
1556 return is_connected;
Jeff Hugod98b1082011-10-24 10:30:23 -06001557}
1558
Eric Holmberg878923a2012-01-10 14:28:19 -07001559static void power_vote(int vote)
1560{
1561 bam_dmux_log("%s: curr=%d, vote=%d\n", __func__,
1562 bam_dmux_uplink_vote, vote);
1563
1564 if (bam_dmux_uplink_vote == vote)
1565 bam_dmux_log("%s: warning - duplicate power vote\n", __func__);
1566
1567 bam_dmux_uplink_vote = vote;
1568 if (vote)
1569 smsm_change_state(SMSM_APPS_STATE, 0, SMSM_A2_POWER_CONTROL);
1570 else
1571 smsm_change_state(SMSM_APPS_STATE, SMSM_A2_POWER_CONTROL, 0);
1572}
1573
Eric Holmberg454d9da2012-01-12 09:37:14 -07001574/*
1575 * @note: Must be called with ul_wakeup_lock locked.
1576 */
1577static inline void ul_powerdown(void)
1578{
1579 bam_dmux_log("%s: powerdown\n", __func__);
1580 verify_tx_queue_is_empty(__func__);
1581
1582 if (a2_pc_disabled) {
1583 wait_for_dfab = 1;
1584 INIT_COMPLETION(dfab_unvote_completion);
1585 release_wakelock();
1586 } else {
1587 wait_for_ack = 1;
1588 INIT_COMPLETION(ul_wakeup_ack_completion);
1589 power_vote(0);
1590 }
1591 bam_is_connected = 0;
1592 notify_all(BAM_DMUX_UL_DISCONNECTED, (unsigned long)(NULL));
1593}
1594
1595static inline void ul_powerdown_finish(void)
1596{
1597 if (a2_pc_disabled && wait_for_dfab) {
1598 unvote_dfab();
1599 complete_all(&dfab_unvote_completion);
1600 wait_for_dfab = 0;
1601 }
1602}
1603
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001604/*
1605 * Votes for UL power and returns current power state.
1606 *
1607 * @returns true if currently connected
1608 */
1609int msm_bam_dmux_ul_power_vote(void)
1610{
1611 int is_connected;
1612
1613 read_lock(&ul_wakeup_lock);
1614 atomic_inc(&ul_ondemand_vote);
1615 is_connected = bam_is_connected;
1616 if (!is_connected)
1617 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1618 read_unlock(&ul_wakeup_lock);
1619
1620 return is_connected;
1621}
1622
1623/*
1624 * Unvotes for UL power.
1625 *
1626 * @returns true if vote count is 0 (UL shutdown possible)
1627 */
1628int msm_bam_dmux_ul_power_unvote(void)
1629{
1630 int vote;
1631
1632 read_lock(&ul_wakeup_lock);
1633 vote = atomic_dec_return(&ul_ondemand_vote);
1634 if (unlikely(vote) < 0)
1635 DMUX_LOG_KERR("%s: invalid power vote %d\n", __func__, vote);
1636 read_unlock(&ul_wakeup_lock);
1637
1638 return vote == 0;
1639}
1640
Jeff Hugocb798022012-04-09 14:55:40 -06001641int msm_bam_dmux_reg_notify(void *priv,
1642 void (*notify)(void *priv, int event_type,
1643 unsigned long data))
1644{
1645 struct outside_notify_func *func;
1646
1647 if (!notify)
1648 return -EINVAL;
1649
1650 func = kmalloc(sizeof(struct outside_notify_func), GFP_KERNEL);
1651 if (!func)
1652 return -ENOMEM;
1653
1654 func->notify = notify;
1655 func->priv = priv;
1656 list_add(&func->list_node, &bam_other_notify_funcs);
1657
1658 return 0;
1659}
1660
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001661static void ul_timeout(struct work_struct *work)
1662{
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001663 unsigned long flags;
1664 int ret;
1665
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001666 if (in_global_reset)
1667 return;
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001668 ret = write_trylock_irqsave(&ul_wakeup_lock, flags);
1669 if (!ret) { /* failed to grab lock, reschedule and bail */
1670 schedule_delayed_work(&ul_timeout_work,
1671 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1672 return;
1673 }
Eric Holmberg454d9da2012-01-12 09:37:14 -07001674 if (bam_is_connected) {
Eric Holmberg6074aba2012-01-18 17:59:44 -07001675 if (!ul_packet_written) {
1676 spin_lock(&bam_tx_pool_spinlock);
1677 if (!list_empty(&bam_tx_pool)) {
1678 struct tx_pkt_info *info;
1679
1680 info = list_first_entry(&bam_tx_pool,
1681 struct tx_pkt_info, list_node);
1682 DMUX_LOG_KERR("%s: UL delayed ts=%u.%09lu\n",
1683 __func__, info->ts_sec, info->ts_nsec);
1684 DBG_INC_TX_STALL_CNT();
1685 ul_packet_written = 1;
1686 }
1687 spin_unlock(&bam_tx_pool_spinlock);
1688 }
1689
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001690 if (ul_packet_written || atomic_read(&ul_ondemand_vote)) {
1691 bam_dmux_log("%s: pkt written %d\n",
1692 __func__, ul_packet_written);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001693 ul_packet_written = 0;
1694 schedule_delayed_work(&ul_timeout_work,
1695 msecs_to_jiffies(UL_TIMEOUT_DELAY));
Eric Holmberg006057d2012-01-11 10:10:42 -07001696 } else {
Eric Holmberg454d9da2012-01-12 09:37:14 -07001697 ul_powerdown();
Eric Holmberg006057d2012-01-11 10:10:42 -07001698 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001699 }
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001700 write_unlock_irqrestore(&ul_wakeup_lock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001701 ul_powerdown_finish();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001702}
Jeff Hugo4838f412012-01-20 11:19:37 -07001703
1704static int ssrestart_check(void)
1705{
Eric Holmberg90285e22012-02-22 12:33:05 -07001706 DMUX_LOG_KERR("%s: modem timeout: BAM DMUX disabled\n", __func__);
1707 in_global_reset = 1;
1708 if (get_restart_level() <= RESET_SOC)
1709 DMUX_LOG_KERR("%s: ssrestart not enabled\n", __func__);
1710 return 1;
Jeff Hugo4838f412012-01-20 11:19:37 -07001711}
1712
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001713static void ul_wakeup(void)
1714{
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001715 int ret;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001716 int do_vote_dfab = 0;
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001717
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001718 mutex_lock(&wakeup_lock);
1719 if (bam_is_connected) { /* bam got connected before lock grabbed */
Eric Holmberg878923a2012-01-10 14:28:19 -07001720 bam_dmux_log("%s Already awake\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001721 mutex_unlock(&wakeup_lock);
1722 return;
1723 }
Eric Holmberg878923a2012-01-10 14:28:19 -07001724
Jeff Hugoc2696142012-05-03 11:42:13 -06001725 /*
Jeff Hugo00424ff2012-08-27 13:19:09 -06001726 * if this gets hit, that means restart_notifier_cb() has started
1727 * but probably not finished, thus we know SSR has happened, but
1728 * haven't been able to send that info to our clients yet.
1729 * in that case, abort the ul_wakeup() so that we don't undo any
1730 * work restart_notifier_cb() has done. The clients will be notified
1731 * shortly. No cleanup necessary (reschedule the wakeup) as our and
1732 * their SSR handling will cover it
1733 */
1734 if (unlikely(in_global_reset == 1)) {
1735 mutex_unlock(&wakeup_lock);
1736 return;
1737 }
1738
1739 /*
Jeff Hugoc2696142012-05-03 11:42:13 -06001740 * if someone is voting for UL before bam is inited (modem up first
1741 * time), set flag for init to kickoff ul wakeup once bam is inited
1742 */
1743 mutex_lock(&delayed_ul_vote_lock);
1744 if (unlikely(!bam_mux_initialized)) {
1745 need_delayed_ul_vote = 1;
1746 mutex_unlock(&delayed_ul_vote_lock);
1747 mutex_unlock(&wakeup_lock);
1748 return;
1749 }
1750 mutex_unlock(&delayed_ul_vote_lock);
1751
Eric Holmberg006057d2012-01-11 10:10:42 -07001752 if (a2_pc_disabled) {
1753 /*
1754 * don't grab the wakelock the first time because it is
1755 * already grabbed when a2 powers on
1756 */
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001757 if (likely(a2_pc_disabled_wakelock_skipped)) {
Eric Holmberg006057d2012-01-11 10:10:42 -07001758 grab_wakelock();
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001759 do_vote_dfab = 1; /* vote must occur after wait */
1760 } else {
Jeff Hugo583a6da2012-02-03 11:37:30 -07001761 a2_pc_disabled_wakelock_skipped = 1;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001762 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001763 if (wait_for_dfab) {
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001764 ret = wait_for_completion_timeout(
Eric Holmberg006057d2012-01-11 10:10:42 -07001765 &dfab_unvote_completion, HZ);
1766 BUG_ON(ret == 0);
1767 }
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001768 if (likely(do_vote_dfab))
1769 vote_dfab();
Eric Holmberg006057d2012-01-11 10:10:42 -07001770 schedule_delayed_work(&ul_timeout_work,
1771 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1772 bam_is_connected = 1;
1773 mutex_unlock(&wakeup_lock);
1774 return;
1775 }
1776
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001777 /*
1778 * must wait for the previous power down request to have been acked
1779 * chances are it already came in and this will just fall through
1780 * instead of waiting
1781 */
1782 if (wait_for_ack) {
Eric Holmberg878923a2012-01-10 14:28:19 -07001783 bam_dmux_log("%s waiting for previous ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001784 ret = wait_for_completion_timeout(
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001785 &ul_wakeup_ack_completion, HZ);
Eric Holmberg006057d2012-01-11 10:10:42 -07001786 wait_for_ack = 0;
Jeff Hugo4838f412012-01-20 11:19:37 -07001787 if (unlikely(ret == 0) && ssrestart_check()) {
1788 mutex_unlock(&wakeup_lock);
1789 bam_dmux_log("%s timeout previous ack\n", __func__);
1790 return;
1791 }
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001792 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001793 INIT_COMPLETION(ul_wakeup_ack_completion);
Eric Holmberg878923a2012-01-10 14:28:19 -07001794 power_vote(1);
1795 bam_dmux_log("%s waiting for wakeup ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001796 ret = wait_for_completion_timeout(&ul_wakeup_ack_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001797 if (unlikely(ret == 0) && ssrestart_check()) {
1798 mutex_unlock(&wakeup_lock);
1799 bam_dmux_log("%s timeout wakeup ack\n", __func__);
1800 return;
1801 }
Eric Holmberg878923a2012-01-10 14:28:19 -07001802 bam_dmux_log("%s waiting completion\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001803 ret = wait_for_completion_timeout(&bam_connection_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001804 if (unlikely(ret == 0) && ssrestart_check()) {
1805 mutex_unlock(&wakeup_lock);
1806 bam_dmux_log("%s timeout power on\n", __func__);
1807 return;
1808 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001809
1810 bam_is_connected = 1;
Eric Holmberg878923a2012-01-10 14:28:19 -07001811 bam_dmux_log("%s complete\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001812 schedule_delayed_work(&ul_timeout_work,
1813 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1814 mutex_unlock(&wakeup_lock);
1815}
1816
1817static void reconnect_to_bam(void)
1818{
1819 int i;
1820
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001821 in_global_reset = 0;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001822 vote_dfab();
Jeff Hugo18792a32012-06-20 15:25:55 -06001823 if (!power_management_only_mode) {
Jeff Hugob11a52c2012-09-21 12:28:09 -06001824 sps_disconnect(bam_tx_pipe);
1825 sps_disconnect(bam_rx_pipe);
1826 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1827 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
Jeff Hugo18792a32012-06-20 15:25:55 -06001828 i = sps_device_reset(a2_device_handle);
1829 if (i)
1830 pr_err("%s: device reset failed rc = %d\n", __func__,
1831 i);
1832 i = sps_connect(bam_tx_pipe, &tx_connection);
1833 if (i)
1834 pr_err("%s: tx connection failed rc = %d\n", __func__,
1835 i);
1836 i = sps_connect(bam_rx_pipe, &rx_connection);
1837 if (i)
1838 pr_err("%s: rx connection failed rc = %d\n", __func__,
1839 i);
1840 i = sps_register_event(bam_tx_pipe, &tx_register_event);
1841 if (i)
1842 pr_err("%s: tx event reg failed rc = %d\n", __func__,
1843 i);
1844 i = sps_register_event(bam_rx_pipe, &rx_register_event);
1845 if (i)
1846 pr_err("%s: rx event reg failed rc = %d\n", __func__,
1847 i);
1848 }
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001849
1850 bam_connection_is_active = 1;
1851
1852 if (polling_mode)
1853 rx_switch_to_interrupt_mode();
1854
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001855 toggle_apps_ack();
1856 complete_all(&bam_connection_completion);
Jeff Hugo18792a32012-06-20 15:25:55 -06001857 if (!power_management_only_mode)
1858 queue_rx();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001859}
1860
1861static void disconnect_to_bam(void)
1862{
1863 struct list_head *node;
1864 struct rx_pkt_info *info;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001865 unsigned long flags;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001866
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001867 bam_connection_is_active = 0;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001868
1869 /* handle disconnect during active UL */
1870 write_lock_irqsave(&ul_wakeup_lock, flags);
1871 if (bam_is_connected) {
1872 bam_dmux_log("%s: UL active - forcing powerdown\n", __func__);
1873 ul_powerdown();
1874 }
1875 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1876 ul_powerdown_finish();
1877
1878 /* tear down BAM connection */
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001879 INIT_COMPLETION(bam_connection_completion);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001880 unvote_dfab();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001881
1882 mutex_lock(&bam_rx_pool_mutexlock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001883 while (!list_empty(&bam_rx_pool)) {
1884 node = bam_rx_pool.next;
1885 list_del(node);
1886 info = container_of(node, struct rx_pkt_info, list_node);
1887 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
1888 DMA_FROM_DEVICE);
1889 dev_kfree_skb_any(info->skb);
1890 kfree(info);
1891 }
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001892 bam_rx_pool_len = 0;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001893 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmberg878923a2012-01-10 14:28:19 -07001894
Jeff Hugo0b13a352012-03-17 23:18:30 -06001895 if (disconnect_ack)
1896 toggle_apps_ack();
1897
Eric Holmberg878923a2012-01-10 14:28:19 -07001898 verify_tx_queue_is_empty(__func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001899}
1900
1901static void vote_dfab(void)
1902{
Jeff Hugoca0caa82011-12-05 16:05:23 -07001903 int rc;
1904
Eric Holmberg006057d2012-01-11 10:10:42 -07001905 bam_dmux_log("%s\n", __func__);
1906 mutex_lock(&dfab_status_lock);
1907 if (dfab_is_on) {
1908 bam_dmux_log("%s: dfab is already on\n", __func__);
1909 mutex_unlock(&dfab_status_lock);
1910 return;
1911 }
Jeff Hugo0c9371a2012-08-09 15:32:49 -06001912 if (dfab_clk) {
1913 rc = clk_prepare_enable(dfab_clk);
1914 if (rc)
1915 DMUX_LOG_KERR("bam_dmux vote for dfab failed rc = %d\n",
1916 rc);
1917 }
1918 if (xo_clk) {
1919 rc = clk_prepare_enable(xo_clk);
1920 if (rc)
1921 DMUX_LOG_KERR("bam_dmux vote for xo failed rc = %d\n",
1922 rc);
1923 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001924 dfab_is_on = 1;
1925 mutex_unlock(&dfab_status_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001926}
1927
1928static void unvote_dfab(void)
1929{
Eric Holmberg006057d2012-01-11 10:10:42 -07001930 bam_dmux_log("%s\n", __func__);
1931 mutex_lock(&dfab_status_lock);
1932 if (!dfab_is_on) {
1933 DMUX_LOG_KERR("%s: dfab is already off\n", __func__);
1934 dump_stack();
1935 mutex_unlock(&dfab_status_lock);
1936 return;
1937 }
Jeff Hugo0c9371a2012-08-09 15:32:49 -06001938 if (dfab_clk)
1939 clk_disable_unprepare(dfab_clk);
1940 if (xo_clk)
1941 clk_disable_unprepare(xo_clk);
Eric Holmberg006057d2012-01-11 10:10:42 -07001942 dfab_is_on = 0;
1943 mutex_unlock(&dfab_status_lock);
1944}
1945
1946/* reference counting wrapper around wakelock */
1947static void grab_wakelock(void)
1948{
1949 unsigned long flags;
1950
1951 spin_lock_irqsave(&wakelock_reference_lock, flags);
1952 bam_dmux_log("%s: ref count = %d\n", __func__,
1953 wakelock_reference_count);
1954 if (wakelock_reference_count == 0)
1955 wake_lock(&bam_wakelock);
1956 ++wakelock_reference_count;
1957 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1958}
1959
1960static void release_wakelock(void)
1961{
1962 unsigned long flags;
1963
1964 spin_lock_irqsave(&wakelock_reference_lock, flags);
1965 if (wakelock_reference_count == 0) {
1966 DMUX_LOG_KERR("%s: bam_dmux wakelock not locked\n", __func__);
1967 dump_stack();
1968 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1969 return;
1970 }
1971 bam_dmux_log("%s: ref count = %d\n", __func__,
1972 wakelock_reference_count);
1973 --wakelock_reference_count;
1974 if (wakelock_reference_count == 0)
1975 wake_unlock(&bam_wakelock);
1976 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001977}
1978
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001979static int restart_notifier_cb(struct notifier_block *this,
1980 unsigned long code,
1981 void *data)
1982{
1983 int i;
1984 struct list_head *node;
1985 struct tx_pkt_info *info;
1986 int temp_remote_status;
Jeff Hugo626303bf2011-11-21 11:43:28 -07001987 unsigned long flags;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001988
1989 if (code != SUBSYS_AFTER_SHUTDOWN)
1990 return NOTIFY_DONE;
1991
Eric Holmberg878923a2012-01-10 14:28:19 -07001992 bam_dmux_log("%s: begin\n", __func__);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001993 in_global_reset = 1;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001994
1995 /* Handle uplink Powerdown */
1996 write_lock_irqsave(&ul_wakeup_lock, flags);
1997 if (bam_is_connected) {
1998 ul_powerdown();
1999 wait_for_ack = 0;
2000 }
Jeff Hugo4838f412012-01-20 11:19:37 -07002001 /*
2002 * if modem crash during ul_wakeup(), power_vote is 1, needs to be
2003 * reset to 0. harmless if bam_is_connected check above passes
2004 */
2005 power_vote(0);
Eric Holmberg454d9da2012-01-12 09:37:14 -07002006 write_unlock_irqrestore(&ul_wakeup_lock, flags);
2007 ul_powerdown_finish();
Eric Holmberg006057d2012-01-11 10:10:42 -07002008 a2_pc_disabled = 0;
Jeff Hugo583a6da2012-02-03 11:37:30 -07002009 a2_pc_disabled_wakelock_skipped = 0;
Jeff Hugof62029d2012-07-17 13:39:53 -06002010 disconnect_ack = 1;
Eric Holmberg454d9da2012-01-12 09:37:14 -07002011
2012 /* Cleanup Channel States */
Eric Holmberga623da82012-07-12 09:37:09 -06002013 mutex_lock(&bam_pdev_mutexlock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002014 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
2015 temp_remote_status = bam_ch_is_remote_open(i);
2016 bam_ch[i].status &= ~BAM_CH_REMOTE_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07002017 bam_ch[i].num_tx_pkts = 0;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002018 if (bam_ch_is_local_open(i))
2019 bam_ch[i].status |= BAM_CH_IN_RESET;
2020 if (temp_remote_status) {
2021 platform_device_unregister(bam_ch[i].pdev);
2022 bam_ch[i].pdev = platform_device_alloc(
2023 bam_ch[i].name, 2);
2024 }
2025 }
Eric Holmberga623da82012-07-12 09:37:09 -06002026 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberg454d9da2012-01-12 09:37:14 -07002027
2028 /* Cleanup pending UL data */
Jeff Hugo626303bf2011-11-21 11:43:28 -07002029 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002030 while (!list_empty(&bam_tx_pool)) {
2031 node = bam_tx_pool.next;
2032 list_del(node);
2033 info = container_of(node, struct tx_pkt_info,
2034 list_node);
2035 if (!info->is_cmd) {
2036 dma_unmap_single(NULL, info->dma_address,
2037 info->skb->len,
2038 DMA_TO_DEVICE);
2039 dev_kfree_skb_any(info->skb);
2040 } else {
2041 dma_unmap_single(NULL, info->dma_address,
2042 info->len,
2043 DMA_TO_DEVICE);
2044 kfree(info->skb);
2045 }
2046 kfree(info);
2047 }
Jeff Hugo626303bf2011-11-21 11:43:28 -07002048 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07002049
Eric Holmberg878923a2012-01-10 14:28:19 -07002050 bam_dmux_log("%s: complete\n", __func__);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002051 return NOTIFY_DONE;
2052}
2053
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002054static int bam_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002055{
2056 u32 h;
2057 dma_addr_t dma_addr;
2058 int ret;
2059 void *a2_virt_addr;
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002060 int skip_iounmap = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002061
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002062 vote_dfab();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002063 /* init BAM */
Jeff Hugo7bf02052012-08-21 14:08:20 -06002064 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
2065 a2_phys_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002066 if (!a2_virt_addr) {
2067 pr_err("%s: ioremap failed\n", __func__);
2068 ret = -ENOMEM;
Jeff Hugo994a92d2012-01-05 13:25:21 -07002069 goto ioremap_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002070 }
Jeff Hugo7bf02052012-08-21 14:08:20 -06002071 a2_props.phys_addr = (u32)(a2_phys_base);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002072 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo7bf02052012-08-21 14:08:20 -06002073 a2_props.virt_size = a2_phys_size;
2074 a2_props.irq = a2_bam_irq;
Jeff Hugo927cba62011-11-11 11:49:52 -07002075 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002076 a2_props.num_pipes = A2_NUM_PIPES;
2077 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
Jeff Hugo0682dad2012-10-22 11:34:28 -06002078 if (cpu_is_msm9615() || satellite_mode)
Jeff Hugo75913c82011-12-05 15:59:01 -07002079 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002080 /* need to free on tear down */
2081 ret = sps_register_bam_device(&a2_props, &h);
2082 if (ret < 0) {
2083 pr_err("%s: register bam error %d\n", __func__, ret);
2084 goto register_bam_failed;
2085 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002086 a2_device_handle = h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002087
2088 bam_tx_pipe = sps_alloc_endpoint();
2089 if (bam_tx_pipe == NULL) {
2090 pr_err("%s: tx alloc endpoint failed\n", __func__);
2091 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002092 goto tx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002093 }
2094 ret = sps_get_config(bam_tx_pipe, &tx_connection);
2095 if (ret) {
2096 pr_err("%s: tx get config failed %d\n", __func__, ret);
2097 goto tx_get_config_failed;
2098 }
2099
2100 tx_connection.source = SPS_DEV_HANDLE_MEM;
2101 tx_connection.src_pipe_index = 0;
2102 tx_connection.destination = h;
2103 tx_connection.dest_pipe_index = 4;
2104 tx_connection.mode = SPS_MODE_DEST;
2105 tx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT;
2106 tx_desc_mem_buf.size = 0x800; /* 2k */
2107 tx_desc_mem_buf.base = dma_alloc_coherent(NULL, tx_desc_mem_buf.size,
2108 &dma_addr, 0);
2109 if (tx_desc_mem_buf.base == NULL) {
2110 pr_err("%s: tx memory alloc failed\n", __func__);
2111 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002112 goto tx_get_config_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002113 }
2114 tx_desc_mem_buf.phys_base = dma_addr;
2115 memset(tx_desc_mem_buf.base, 0x0, tx_desc_mem_buf.size);
2116 tx_connection.desc = tx_desc_mem_buf;
2117 tx_connection.event_thresh = 0x10;
2118
2119 ret = sps_connect(bam_tx_pipe, &tx_connection);
2120 if (ret < 0) {
2121 pr_err("%s: tx connect error %d\n", __func__, ret);
2122 goto tx_connect_failed;
2123 }
2124
2125 bam_rx_pipe = sps_alloc_endpoint();
2126 if (bam_rx_pipe == NULL) {
2127 pr_err("%s: rx alloc endpoint failed\n", __func__);
2128 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002129 goto rx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002130 }
2131 ret = sps_get_config(bam_rx_pipe, &rx_connection);
2132 if (ret) {
2133 pr_err("%s: rx get config failed %d\n", __func__, ret);
2134 goto rx_get_config_failed;
2135 }
2136
2137 rx_connection.source = h;
2138 rx_connection.src_pipe_index = 5;
2139 rx_connection.destination = SPS_DEV_HANDLE_MEM;
2140 rx_connection.dest_pipe_index = 1;
2141 rx_connection.mode = SPS_MODE_SRC;
Jeff Hugo949080a2011-08-30 11:58:56 -06002142 rx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT |
2143 SPS_O_ACK_TRANSFERS;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002144 rx_desc_mem_buf.size = 0x800; /* 2k */
2145 rx_desc_mem_buf.base = dma_alloc_coherent(NULL, rx_desc_mem_buf.size,
2146 &dma_addr, 0);
2147 if (rx_desc_mem_buf.base == NULL) {
2148 pr_err("%s: rx memory alloc failed\n", __func__);
2149 ret = -ENOMEM;
2150 goto rx_mem_failed;
2151 }
2152 rx_desc_mem_buf.phys_base = dma_addr;
2153 memset(rx_desc_mem_buf.base, 0x0, rx_desc_mem_buf.size);
2154 rx_connection.desc = rx_desc_mem_buf;
2155 rx_connection.event_thresh = 0x10;
2156
2157 ret = sps_connect(bam_rx_pipe, &rx_connection);
2158 if (ret < 0) {
2159 pr_err("%s: rx connect error %d\n", __func__, ret);
2160 goto rx_connect_failed;
2161 }
2162
2163 tx_register_event.options = SPS_O_EOT;
2164 tx_register_event.mode = SPS_TRIGGER_CALLBACK;
2165 tx_register_event.xfer_done = NULL;
2166 tx_register_event.callback = bam_mux_tx_notify;
2167 tx_register_event.user = NULL;
2168 ret = sps_register_event(bam_tx_pipe, &tx_register_event);
2169 if (ret < 0) {
2170 pr_err("%s: tx register event error %d\n", __func__, ret);
2171 goto rx_event_reg_failed;
2172 }
2173
Jeff Hugo33dbc002011-08-25 15:52:53 -06002174 rx_register_event.options = SPS_O_EOT;
2175 rx_register_event.mode = SPS_TRIGGER_CALLBACK;
2176 rx_register_event.xfer_done = NULL;
2177 rx_register_event.callback = bam_mux_rx_notify;
2178 rx_register_event.user = NULL;
2179 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
2180 if (ret < 0) {
2181 pr_err("%s: tx register event error %d\n", __func__, ret);
2182 goto rx_event_reg_failed;
2183 }
2184
Jeff Hugoc2696142012-05-03 11:42:13 -06002185 mutex_lock(&delayed_ul_vote_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002186 bam_mux_initialized = 1;
Jeff Hugoc2696142012-05-03 11:42:13 -06002187 if (need_delayed_ul_vote) {
2188 need_delayed_ul_vote = 0;
2189 msm_bam_dmux_kickoff_ul_wakeup();
2190 }
2191 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002192 toggle_apps_ack();
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002193 bam_connection_is_active = 1;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002194 complete_all(&bam_connection_completion);
Jeff Hugo2fb555e2012-03-14 16:33:47 -06002195 queue_rx();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002196 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002197
2198rx_event_reg_failed:
2199 sps_disconnect(bam_rx_pipe);
2200rx_connect_failed:
2201 dma_free_coherent(NULL, rx_desc_mem_buf.size, rx_desc_mem_buf.base,
2202 rx_desc_mem_buf.phys_base);
2203rx_mem_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002204rx_get_config_failed:
2205 sps_free_endpoint(bam_rx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002206rx_alloc_endpoint_failed:
2207 sps_disconnect(bam_tx_pipe);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002208tx_connect_failed:
2209 dma_free_coherent(NULL, tx_desc_mem_buf.size, tx_desc_mem_buf.base,
2210 tx_desc_mem_buf.phys_base);
2211tx_get_config_failed:
2212 sps_free_endpoint(bam_tx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002213tx_alloc_endpoint_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002214 sps_deregister_bam_device(h);
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002215 /*
2216 * sps_deregister_bam_device() calls iounmap. calling iounmap on the
2217 * same handle below will cause a crash, so skip it if we've freed
2218 * the handle here.
2219 */
2220 skip_iounmap = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002221register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002222 if (!skip_iounmap)
2223 iounmap(a2_virt_addr);
Jeff Hugo994a92d2012-01-05 13:25:21 -07002224ioremap_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002225 /*destroy_workqueue(bam_mux_workqueue);*/
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002226 return ret;
2227}
2228
2229static int bam_init_fallback(void)
2230{
2231 u32 h;
2232 int ret;
2233 void *a2_virt_addr;
2234
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002235 /* init BAM */
Jeff Hugo7bf02052012-08-21 14:08:20 -06002236 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
2237 a2_phys_size);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002238 if (!a2_virt_addr) {
2239 pr_err("%s: ioremap failed\n", __func__);
2240 ret = -ENOMEM;
2241 goto ioremap_failed;
2242 }
Jeff Hugo7bf02052012-08-21 14:08:20 -06002243 a2_props.phys_addr = (u32)(a2_phys_base);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002244 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo7bf02052012-08-21 14:08:20 -06002245 a2_props.virt_size = a2_phys_size;
2246 a2_props.irq = a2_bam_irq;
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002247 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
2248 a2_props.num_pipes = A2_NUM_PIPES;
2249 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
Jeff Hugo0682dad2012-10-22 11:34:28 -06002250 if (cpu_is_msm9615() || satellite_mode)
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002251 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
2252 ret = sps_register_bam_device(&a2_props, &h);
2253 if (ret < 0) {
2254 pr_err("%s: register bam error %d\n", __func__, ret);
2255 goto register_bam_failed;
2256 }
2257 a2_device_handle = h;
Jeff Hugoc2696142012-05-03 11:42:13 -06002258
2259 mutex_lock(&delayed_ul_vote_lock);
2260 bam_mux_initialized = 1;
2261 if (need_delayed_ul_vote) {
2262 need_delayed_ul_vote = 0;
2263 msm_bam_dmux_kickoff_ul_wakeup();
2264 }
2265 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugo2bec9772012-04-05 12:25:16 -06002266 toggle_apps_ack();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002267
Jeff Hugo18792a32012-06-20 15:25:55 -06002268 power_management_only_mode = 1;
2269 bam_connection_is_active = 1;
2270 complete_all(&bam_connection_completion);
2271
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002272 return 0;
2273
2274register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002275 iounmap(a2_virt_addr);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002276ioremap_failed:
2277 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002278}
Jeff Hugoade1f842011-08-03 15:53:59 -06002279
Jeff Hugoa670b762012-03-15 15:58:28 -06002280static void msm9615_bam_init(void)
Eric Holmberg604ab252012-01-15 00:01:18 -07002281{
2282 int ret = 0;
2283
2284 ret = bam_init();
2285 if (ret) {
2286 ret = bam_init_fallback();
2287 if (ret)
2288 pr_err("%s: bam init fallback failed: %d",
2289 __func__, ret);
2290 }
2291}
2292
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002293static void toggle_apps_ack(void)
2294{
2295 static unsigned int clear_bit; /* 0 = set the bit, else clear bit */
Eric Holmberg878923a2012-01-10 14:28:19 -07002296
2297 bam_dmux_log("%s: apps ack %d->%d\n", __func__,
2298 clear_bit & 0x1, ~clear_bit & 0x1);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002299 smsm_change_state(SMSM_APPS_STATE,
2300 clear_bit & SMSM_A2_POWER_CONTROL_ACK,
2301 ~clear_bit & SMSM_A2_POWER_CONTROL_ACK);
2302 clear_bit = ~clear_bit;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002303 DBG_INC_ACK_OUT_CNT();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002304}
2305
Jeff Hugoade1f842011-08-03 15:53:59 -06002306static void bam_dmux_smsm_cb(void *priv, uint32_t old_state, uint32_t new_state)
2307{
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002308 static int last_processed_state;
2309
2310 mutex_lock(&smsm_cb_lock);
Eric Holmberg878923a2012-01-10 14:28:19 -07002311 bam_dmux_power_state = new_state & SMSM_A2_POWER_CONTROL ? 1 : 0;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002312 DBG_INC_A2_POWER_CONTROL_IN_CNT();
Eric Holmberg878923a2012-01-10 14:28:19 -07002313 bam_dmux_log("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
2314 new_state);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002315 if (last_processed_state == (new_state & SMSM_A2_POWER_CONTROL)) {
2316 bam_dmux_log("%s: already processed this state\n", __func__);
2317 mutex_unlock(&smsm_cb_lock);
2318 return;
2319 }
2320
2321 last_processed_state = new_state & SMSM_A2_POWER_CONTROL;
Eric Holmberg878923a2012-01-10 14:28:19 -07002322
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002323 if (bam_mux_initialized && new_state & SMSM_A2_POWER_CONTROL) {
Eric Holmberg878923a2012-01-10 14:28:19 -07002324 bam_dmux_log("%s: reconnect\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002325 grab_wakelock();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002326 reconnect_to_bam();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002327 } else if (bam_mux_initialized &&
2328 !(new_state & SMSM_A2_POWER_CONTROL)) {
Eric Holmberg878923a2012-01-10 14:28:19 -07002329 bam_dmux_log("%s: disconnect\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002330 disconnect_to_bam();
Eric Holmberg006057d2012-01-11 10:10:42 -07002331 release_wakelock();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002332 } else if (new_state & SMSM_A2_POWER_CONTROL) {
Eric Holmberg878923a2012-01-10 14:28:19 -07002333 bam_dmux_log("%s: init\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002334 grab_wakelock();
Jeff Hugoa670b762012-03-15 15:58:28 -06002335 if (cpu_is_msm9615())
2336 msm9615_bam_init();
2337 else
Eric Holmberg604ab252012-01-15 00:01:18 -07002338 bam_init();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002339 } else {
Eric Holmberg878923a2012-01-10 14:28:19 -07002340 bam_dmux_log("%s: bad state change\n", __func__);
Jeff Hugoade1f842011-08-03 15:53:59 -06002341 pr_err("%s: unsupported state change\n", __func__);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002342 }
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002343 mutex_unlock(&smsm_cb_lock);
Jeff Hugoade1f842011-08-03 15:53:59 -06002344
2345}
2346
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002347static void bam_dmux_smsm_ack_cb(void *priv, uint32_t old_state,
2348 uint32_t new_state)
2349{
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002350 DBG_INC_ACK_IN_CNT();
Eric Holmberg878923a2012-01-10 14:28:19 -07002351 bam_dmux_log("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
2352 new_state);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002353 complete_all(&ul_wakeup_ack_completion);
2354}
2355
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002356static int bam_dmux_probe(struct platform_device *pdev)
2357{
2358 int rc;
Jeff Hugo7bf02052012-08-21 14:08:20 -06002359 struct resource *r;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002360
2361 DBG("%s probe called\n", __func__);
2362 if (bam_mux_initialized)
2363 return 0;
2364
Jeff Hugo7bf02052012-08-21 14:08:20 -06002365 if (pdev->dev.of_node) {
2366 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2367 if (!r) {
2368 pr_err("%s: reg field missing\n", __func__);
2369 return -ENODEV;
2370 }
2371 a2_phys_base = (void *)(r->start);
2372 a2_phys_size = (uint32_t)(resource_size(r));
2373 a2_bam_irq = platform_get_irq(pdev, 0);
2374 if (a2_bam_irq == -ENXIO) {
2375 pr_err("%s: irq field missing\n", __func__);
2376 return -ENODEV;
2377 }
Jeff Hugo0682dad2012-10-22 11:34:28 -06002378 satellite_mode = of_property_read_bool(pdev->dev.of_node,
2379 "qcom,satellite-mode");
2380
2381 DBG("%s: base:%p size:%x irq:%d satellite:%d\n", __func__,
Jeff Hugo7bf02052012-08-21 14:08:20 -06002382 a2_phys_base,
2383 a2_phys_size,
Jeff Hugo0682dad2012-10-22 11:34:28 -06002384 a2_bam_irq,
2385 satellite_mode);
Jeff Hugo7bf02052012-08-21 14:08:20 -06002386 } else { /* fallback to default init data */
2387 a2_phys_base = (void *)(A2_PHYS_BASE);
2388 a2_phys_size = A2_PHYS_SIZE;
2389 a2_bam_irq = A2_BAM_IRQ;
2390 }
2391
Stephen Boyd69d35e32012-02-14 15:33:30 -08002392 xo_clk = clk_get(&pdev->dev, "xo");
2393 if (IS_ERR(xo_clk)) {
Jeff Hugo0c9371a2012-08-09 15:32:49 -06002394 bam_dmux_log("%s: did not get xo clock\n", __func__);
2395 xo_clk = NULL;
Stephen Boyd69d35e32012-02-14 15:33:30 -08002396 }
Stephen Boyd1c51a492011-10-26 12:11:47 -07002397 dfab_clk = clk_get(&pdev->dev, "bus_clk");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002398 if (IS_ERR(dfab_clk)) {
Jeff Hugo0c9371a2012-08-09 15:32:49 -06002399 bam_dmux_log("%s: did not get dfab clock\n", __func__);
2400 dfab_clk = NULL;
2401 } else {
2402 rc = clk_set_rate(dfab_clk, 64000000);
2403 if (rc)
2404 pr_err("%s: unable to set dfab clock rate\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002405 }
2406
Jeff Hugofff43af92012-03-29 17:54:52 -06002407 /*
2408 * setup the workqueue so that it can be pinned to core 0 and not
2409 * block the watchdog pet function, so that netif_rx() in rmnet
2410 * only uses one queue.
2411 */
2412 bam_mux_rx_workqueue = alloc_workqueue("bam_dmux_rx",
2413 WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002414 if (!bam_mux_rx_workqueue)
2415 return -ENOMEM;
2416
2417 bam_mux_tx_workqueue = create_singlethread_workqueue("bam_dmux_tx");
2418 if (!bam_mux_tx_workqueue) {
2419 destroy_workqueue(bam_mux_rx_workqueue);
2420 return -ENOMEM;
2421 }
2422
Jeff Hugo7960abd2011-08-02 15:39:38 -06002423 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002424 spin_lock_init(&bam_ch[rc].lock);
Jeff Hugo7960abd2011-08-02 15:39:38 -06002425 scnprintf(bam_ch[rc].name, BAM_DMUX_CH_NAME_MAX_LEN,
2426 "bam_dmux_ch_%d", rc);
2427 /* bus 2, ie a2 stream 2 */
2428 bam_ch[rc].pdev = platform_device_alloc(bam_ch[rc].name, 2);
2429 if (!bam_ch[rc].pdev) {
2430 pr_err("%s: platform device alloc failed\n", __func__);
2431 destroy_workqueue(bam_mux_rx_workqueue);
2432 destroy_workqueue(bam_mux_tx_workqueue);
2433 return -ENOMEM;
2434 }
2435 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002436
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002437 init_completion(&ul_wakeup_ack_completion);
2438 init_completion(&bam_connection_completion);
Eric Holmberg006057d2012-01-11 10:10:42 -07002439 init_completion(&dfab_unvote_completion);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002440 INIT_DELAYED_WORK(&ul_timeout_work, ul_timeout);
Jeff Hugoad75d8d2012-10-03 15:53:54 -06002441 INIT_DELAYED_WORK(&queue_rx_work, queue_rx_work_func);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002442 wake_lock_init(&bam_wakelock, WAKE_LOCK_SUSPEND, "bam_dmux_wakelock");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002443
Jeff Hugoade1f842011-08-03 15:53:59 -06002444 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL,
2445 bam_dmux_smsm_cb, NULL);
2446
2447 if (rc) {
2448 destroy_workqueue(bam_mux_rx_workqueue);
2449 destroy_workqueue(bam_mux_tx_workqueue);
2450 pr_err("%s: smsm cb register failed, rc: %d\n", __func__, rc);
2451 return -ENOMEM;
2452 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002453
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002454 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL_ACK,
2455 bam_dmux_smsm_ack_cb, NULL);
2456
2457 if (rc) {
2458 destroy_workqueue(bam_mux_rx_workqueue);
2459 destroy_workqueue(bam_mux_tx_workqueue);
2460 smsm_state_cb_deregister(SMSM_MODEM_STATE,
2461 SMSM_A2_POWER_CONTROL,
2462 bam_dmux_smsm_cb, NULL);
2463 pr_err("%s: smsm ack cb register failed, rc: %d\n", __func__,
2464 rc);
2465 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc)
2466 platform_device_put(bam_ch[rc].pdev);
2467 return -ENOMEM;
2468 }
2469
Eric Holmbergfd1e2ae2011-11-15 18:28:17 -07002470 if (smsm_get_state(SMSM_MODEM_STATE) & SMSM_A2_POWER_CONTROL)
2471 bam_dmux_smsm_cb(NULL, 0, smsm_get_state(SMSM_MODEM_STATE));
2472
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002473 return 0;
2474}
2475
Jeff Hugo7bf02052012-08-21 14:08:20 -06002476static struct of_device_id msm_match_table[] = {
2477 {.compatible = "qcom,bam_dmux"},
2478 {},
2479};
2480
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002481static struct platform_driver bam_dmux_driver = {
2482 .probe = bam_dmux_probe,
2483 .driver = {
2484 .name = "BAM_RMNT",
2485 .owner = THIS_MODULE,
Jeff Hugo7bf02052012-08-21 14:08:20 -06002486 .of_match_table = msm_match_table,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002487 },
2488};
2489
2490static int __init bam_dmux_init(void)
2491{
Eric Holmberg878923a2012-01-10 14:28:19 -07002492 int ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002493#ifdef CONFIG_DEBUG_FS
2494 struct dentry *dent;
2495
2496 dent = debugfs_create_dir("bam_dmux", 0);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002497 if (!IS_ERR(dent)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002498 debug_create("tbl", 0444, dent, debug_tbl);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002499 debug_create("ul_pkt_cnt", 0444, dent, debug_ul_pkt_cnt);
2500 debug_create("stats", 0444, dent, debug_stats);
Eric Holmberge4ac80b2012-01-12 09:21:59 -07002501 debug_create_multiple("log", 0444, dent, debug_log);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002502 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002503#endif
Eric Holmberg878923a2012-01-10 14:28:19 -07002504 ret = kfifo_alloc(&bam_dmux_state_log, PAGE_SIZE, GFP_KERNEL);
2505 if (ret) {
2506 pr_err("%s: failed to allocate log %d\n", __func__, ret);
2507 bam_dmux_state_logging_disabled = 1;
2508 }
2509
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07002510 rx_timer_interval = DEFAULT_POLLING_MIN_SLEEP;
2511
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002512 subsys_notif_register_notifier("modem", &restart_notifier);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002513 return platform_driver_register(&bam_dmux_driver);
2514}
2515
Jeff Hugoade1f842011-08-03 15:53:59 -06002516late_initcall(bam_dmux_init); /* needs to init after SMD */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002517MODULE_DESCRIPTION("MSM BAM DMUX");
2518MODULE_LICENSE("GPL v2");