blob: c8410dc66985f9d1d791c2bd6c03fa88bc6b60a6 [file] [log] [blame]
Arun Kumar Neelakantam406e5692013-01-17 18:58:04 +05301/* Copyright (c) 2011-2013, The Linux Foundation. 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 Hugo3910ee12012-08-21 14:08:20 -060030#include <linux/of.h>
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +053031#include <mach/msm_ipc_logging.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070032#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
174#define A2_DEFAULT_DESCRIPTORS 32
175#define A2_PHYS_BASE 0x124C2000
176#define A2_PHYS_SIZE 0x2000
177#define BUFFER_SIZE 2048
178#define NUM_BUFFERS 32
Jeff Hugo3910ee12012-08-21 14:08:20 -0600179
180#ifndef A2_BAM_IRQ
181#define A2_BAM_IRQ -1
182#endif
183
184static void *a2_phys_base;
185static uint32_t a2_phys_size;
186static int a2_bam_irq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187static struct sps_bam_props a2_props;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600188static u32 a2_device_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700189static struct sps_pipe *bam_tx_pipe;
190static struct sps_pipe *bam_rx_pipe;
191static struct sps_connect tx_connection;
192static struct sps_connect rx_connection;
193static struct sps_mem_buffer tx_desc_mem_buf;
194static struct sps_mem_buffer rx_desc_mem_buf;
195static struct sps_register_event tx_register_event;
Jeff Hugo33dbc002011-08-25 15:52:53 -0600196static struct sps_register_event rx_register_event;
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 Hugo988e7ba2012-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 Hugoa82a95c2012-12-14 17:56:19 -0700272static int in_ssr;
273static int ssr_skipped_disconnect;
Jeff Hugocb798022012-04-09 14:55:40 -0600274
275struct outside_notify_func {
276 void (*notify)(void *, int, unsigned long);
277 void *priv;
278 struct list_head list_node;
279};
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600280/* End A2 power collaspe */
281
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600282/* subsystem restart */
283static int restart_notifier_cb(struct notifier_block *this,
284 unsigned long code,
285 void *data);
286
287static struct notifier_block restart_notifier = {
288 .notifier_call = restart_notifier_cb,
289};
290static int in_global_reset;
291/* end subsystem restart */
292
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700293#define bam_ch_is_open(x) \
294 (bam_ch[(x)].status == (BAM_CH_LOCAL_OPEN | BAM_CH_REMOTE_OPEN))
295
296#define bam_ch_is_local_open(x) \
297 (bam_ch[(x)].status & BAM_CH_LOCAL_OPEN)
298
299#define bam_ch_is_remote_open(x) \
300 (bam_ch[(x)].status & BAM_CH_REMOTE_OPEN)
301
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600302#define bam_ch_is_in_reset(x) \
303 (bam_ch[(x)].status & BAM_CH_IN_RESET)
304
Eric Holmberg878923a2012-01-10 14:28:19 -0700305struct kfifo bam_dmux_state_log;
Eric Holmberg878923a2012-01-10 14:28:19 -0700306static int bam_dmux_uplink_vote;
307static int bam_dmux_power_state;
308
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530309static void *bam_ipc_log_txt;
310
311#define BAM_IPC_LOG_PAGES 5
312
Eric Holmberg878923a2012-01-10 14:28:19 -0700313/**
314 * Log a state change along with a small message.
Eric Holmberg878923a2012-01-10 14:28:19 -0700315 * Complete size of messsage is limited to @todo.
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530316 * Logging is done using IPC Logging infrastructure.
317 *
318 * States
319 * D: 1 = Power collapse disabled
320 * R: 1 = in global reset
321 * P: 1 = BAM is powered up
322 * A: 1 = BAM initialized and ready for data
323 * V: 1 = Uplink vote for power
324 * U: 1 = Uplink active
325 * W: 1 = Uplink Wait-for-ack
326 * A: 1 = Uplink ACK received
327 * #: >=1 On-demand uplink vote
328 * D: 1 = Disconnect ACK active
Eric Holmberg878923a2012-01-10 14:28:19 -0700329 */
Eric Holmberg878923a2012-01-10 14:28:19 -0700330
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530331#define BAM_DMUX_LOG(fmt, args...) \
332do { \
333 if (bam_ipc_log_txt) { \
334 ipc_log_string(bam_ipc_log_txt, \
335 "<DMUX> %c%c%c%c %c%c%c%c%d%c " fmt, \
336 a2_pc_disabled ? 'D' : 'd', \
337 in_global_reset ? 'R' : 'r', \
338 bam_dmux_power_state ? 'P' : 'p', \
339 bam_connection_is_active ? 'A' : 'a', \
340 bam_dmux_uplink_vote ? 'V' : 'v', \
341 bam_is_connected ? 'U' : 'u', \
342 wait_for_ack ? 'W' : 'w', \
343 ul_wakeup_ack_completion.done ? 'A' : 'a', \
344 atomic_read(&ul_ondemand_vote), \
345 disconnect_ack ? 'D' : 'd', \
346 args); \
347 } \
348} while (0)
Eric Holmberg878923a2012-01-10 14:28:19 -0700349
Zaheerulla Meerf800bba2013-02-13 15:49:14 +0530350#define DMUX_LOG_KERR(fmt, args...) \
351do { \
352 BAM_DMUX_LOG(fmt, args); \
353 pr_err(fmt, args); \
354} while (0)
355
Eric Holmberg878923a2012-01-10 14:28:19 -0700356static inline void set_tx_timestamp(struct tx_pkt_info *pkt)
357{
358 unsigned long long t_now;
359
360 t_now = sched_clock();
361 pkt->ts_nsec = do_div(t_now, 1000000000U);
362 pkt->ts_sec = (unsigned)t_now;
363}
364
365static inline void verify_tx_queue_is_empty(const char *func)
366{
367 unsigned long flags;
368 struct tx_pkt_info *info;
369 int reported = 0;
370
371 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
372 list_for_each_entry(info, &bam_tx_pool, list_node) {
373 if (!reported) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530374 BAM_DMUX_LOG("%s: tx pool not empty\n", func);
Eric Holmberg454d9da2012-01-12 09:37:14 -0700375 if (!in_global_reset)
376 pr_err("%s: tx pool not empty\n", func);
Eric Holmberg878923a2012-01-10 14:28:19 -0700377 reported = 1;
378 }
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530379 BAM_DMUX_LOG("%s: node=%p ts=%u.%09lu\n", __func__,
Eric Holmberg454d9da2012-01-12 09:37:14 -0700380 &info->list_node, info->ts_sec, info->ts_nsec);
381 if (!in_global_reset)
382 pr_err("%s: node=%p ts=%u.%09lu\n", __func__,
383 &info->list_node, info->ts_sec, info->ts_nsec);
Eric Holmberg878923a2012-01-10 14:28:19 -0700384 }
385 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
386}
387
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700388static void queue_rx(void)
389{
390 void *ptr;
391 struct rx_pkt_info *info;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700392 int ret;
393 int rx_len_cached;
Jeff Hugo949080a2011-08-30 11:58:56 -0600394
Jeff Hugoc9749932011-11-02 17:50:40 -0600395 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700396 rx_len_cached = bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -0600397 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -0600398
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600399 while (bam_connection_is_active && rx_len_cached < NUM_BUFFERS) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700400 if (in_global_reset)
401 goto fail;
402
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600403 info = kmalloc(sizeof(struct rx_pkt_info),
404 GFP_NOWAIT | __GFP_NOWARN);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700405 if (!info) {
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600406 DMUX_LOG_KERR(
407 "%s: unable to alloc rx_pkt_info, will retry later\n",
408 __func__);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700409 goto fail;
410 }
411
412 INIT_WORK(&info->work, handle_bam_mux_cmd);
413
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600414 info->skb = __dev_alloc_skb(BUFFER_SIZE,
415 GFP_NOWAIT | __GFP_NOWARN);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700416 if (info->skb == NULL) {
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600417 DMUX_LOG_KERR(
418 "%s: unable to alloc skb, will retry later\n",
419 __func__);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700420 goto fail_info;
421 }
422 ptr = skb_put(info->skb, BUFFER_SIZE);
423
424 info->dma_address = dma_map_single(NULL, ptr, BUFFER_SIZE,
425 DMA_FROM_DEVICE);
426 if (info->dma_address == 0 || info->dma_address == ~0) {
427 DMUX_LOG_KERR("%s: dma_map_single failure %p for %p\n",
428 __func__, (void *)info->dma_address, ptr);
429 goto fail_skb;
430 }
431
432 mutex_lock(&bam_rx_pool_mutexlock);
433 list_add_tail(&info->list_node, &bam_rx_pool);
434 rx_len_cached = ++bam_rx_pool_len;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700435 ret = sps_transfer_one(bam_rx_pipe, info->dma_address,
436 BUFFER_SIZE, info,
437 SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700438 if (ret) {
Eric Holmberg00cf8692012-07-16 14:21:19 -0600439 list_del(&info->list_node);
440 rx_len_cached = --bam_rx_pool_len;
441 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700442 DMUX_LOG_KERR("%s: sps_transfer_one failed %d\n",
443 __func__, ret);
Eric Holmberg00cf8692012-07-16 14:21:19 -0600444
445 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
446 DMA_FROM_DEVICE);
447
448 goto fail_skb;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700449 }
Eric Holmberg00cf8692012-07-16 14:21:19 -0600450 mutex_unlock(&bam_rx_pool_mutexlock);
451
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700452 }
453 return;
454
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700455fail_skb:
456 dev_kfree_skb_any(info->skb);
457
458fail_info:
459 kfree(info);
460
461fail:
Arun Kumar Neelakantam799447f2012-12-13 18:06:49 +0530462 if (rx_len_cached == 0 && !in_global_reset) {
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600463 DMUX_LOG_KERR("%s: rescheduling\n", __func__);
464 schedule_delayed_work(&queue_rx_work, msecs_to_jiffies(100));
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700465 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700466}
467
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600468static void queue_rx_work_func(struct work_struct *work)
469{
470 queue_rx();
471}
472
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700473static void bam_mux_process_data(struct sk_buff *rx_skb)
474{
475 unsigned long flags;
476 struct bam_mux_hdr *rx_hdr;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600477 unsigned long event_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700478
479 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
480
481 rx_skb->data = (unsigned char *)(rx_hdr + 1);
482 rx_skb->tail = rx_skb->data + rx_hdr->pkt_len;
483 rx_skb->len = rx_hdr->pkt_len;
Jeff Hugoee88f672011-10-04 17:14:52 -0600484 rx_skb->truesize = rx_hdr->pkt_len + sizeof(struct sk_buff);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700485
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600486 event_data = (unsigned long)(rx_skb);
487
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700488 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600489 if (bam_ch[rx_hdr->ch_id].notify)
490 bam_ch[rx_hdr->ch_id].notify(
491 bam_ch[rx_hdr->ch_id].priv, BAM_DMUX_RECEIVE,
492 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700493 else
494 dev_kfree_skb_any(rx_skb);
495 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
496
497 queue_rx();
498}
499
Eric Holmberg006057d2012-01-11 10:10:42 -0700500static inline void handle_bam_mux_cmd_open(struct bam_mux_hdr *rx_hdr)
501{
502 unsigned long flags;
503 int ret;
504
Eric Holmberga623da82012-07-12 09:37:09 -0600505 mutex_lock(&bam_pdev_mutexlock);
506 if (in_global_reset) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530507 BAM_DMUX_LOG("%s: open cid %d aborted due to ssr\n",
Eric Holmberga623da82012-07-12 09:37:09 -0600508 __func__, rx_hdr->ch_id);
509 mutex_unlock(&bam_pdev_mutexlock);
510 queue_rx();
511 return;
512 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700513 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
514 bam_ch[rx_hdr->ch_id].status |= BAM_CH_REMOTE_OPEN;
515 bam_ch[rx_hdr->ch_id].num_tx_pkts = 0;
516 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Eric Holmberg006057d2012-01-11 10:10:42 -0700517 ret = platform_device_add(bam_ch[rx_hdr->ch_id].pdev);
518 if (ret)
519 pr_err("%s: platform_device_add() error: %d\n",
520 __func__, ret);
Eric Holmberga623da82012-07-12 09:37:09 -0600521 mutex_unlock(&bam_pdev_mutexlock);
522 queue_rx();
Eric Holmberg006057d2012-01-11 10:10:42 -0700523}
524
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700525static void handle_bam_mux_cmd(struct work_struct *work)
526{
527 unsigned long flags;
528 struct bam_mux_hdr *rx_hdr;
529 struct rx_pkt_info *info;
530 struct sk_buff *rx_skb;
531
532 info = container_of(work, struct rx_pkt_info, work);
533 rx_skb = info->skb;
Jeff Hugo949080a2011-08-30 11:58:56 -0600534 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE, DMA_FROM_DEVICE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700535 kfree(info);
536
537 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
538
539 DBG_INC_READ_CNT(sizeof(struct bam_mux_hdr));
540 DBG("%s: magic %x reserved %d cmd %d pad %d ch %d len %d\n", __func__,
541 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
542 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
543 if (rx_hdr->magic_num != BAM_MUX_HDR_MAGIC_NO) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700544 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
545 " reserved %d cmd %d"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700546 " pad %d ch %d len %d\n", __func__,
547 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
548 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
549 dev_kfree_skb_any(rx_skb);
550 queue_rx();
551 return;
552 }
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700553
554 if (rx_hdr->ch_id >= BAM_DMUX_NUM_CHANNELS) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700555 DMUX_LOG_KERR("%s: dropping invalid LCID %d"
556 " reserved %d cmd %d"
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700557 " pad %d ch %d len %d\n", __func__,
558 rx_hdr->ch_id, rx_hdr->reserved, rx_hdr->cmd,
559 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
560 dev_kfree_skb_any(rx_skb);
561 queue_rx();
562 return;
563 }
564
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700565 switch (rx_hdr->cmd) {
566 case BAM_MUX_HDR_CMD_DATA:
567 DBG_INC_READ_CNT(rx_hdr->pkt_len);
568 bam_mux_process_data(rx_skb);
569 break;
570 case BAM_MUX_HDR_CMD_OPEN:
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530571 BAM_DMUX_LOG("%s: opening cid %d PC enabled\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700572 rx_hdr->ch_id);
Eric Holmberg006057d2012-01-11 10:10:42 -0700573 handle_bam_mux_cmd_open(rx_hdr);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600574 if (!(rx_hdr->reserved & ENABLE_DISCONNECT_ACK)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530575 BAM_DMUX_LOG("%s: deactivating disconnect ack\n",
Jeff Hugod7d2b062012-07-24 14:29:56 -0600576 __func__);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600577 disconnect_ack = 0;
Jeff Hugo0b13a352012-03-17 23:18:30 -0600578 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700579 dev_kfree_skb_any(rx_skb);
580 break;
581 case BAM_MUX_HDR_CMD_OPEN_NO_A2_PC:
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530582 BAM_DMUX_LOG("%s: opening cid %d PC disabled\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -0700583 rx_hdr->ch_id);
584
585 if (!a2_pc_disabled) {
586 a2_pc_disabled = 1;
Jeff Hugo322179f2012-02-29 10:52:34 -0700587 ul_wakeup();
Eric Holmberg006057d2012-01-11 10:10:42 -0700588 }
589
590 handle_bam_mux_cmd_open(rx_hdr);
Eric Holmberge779dba2011-11-04 18:22:01 -0600591 dev_kfree_skb_any(rx_skb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700592 break;
593 case BAM_MUX_HDR_CMD_CLOSE:
594 /* probably should drop pending write */
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530595 BAM_DMUX_LOG("%s: closing cid %d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700596 rx_hdr->ch_id);
Eric Holmberga623da82012-07-12 09:37:09 -0600597 mutex_lock(&bam_pdev_mutexlock);
598 if (in_global_reset) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530599 BAM_DMUX_LOG("%s: close cid %d aborted due to ssr\n",
Eric Holmberga623da82012-07-12 09:37:09 -0600600 __func__, rx_hdr->ch_id);
601 mutex_unlock(&bam_pdev_mutexlock);
602 break;
603 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700604 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
605 bam_ch[rx_hdr->ch_id].status &= ~BAM_CH_REMOTE_OPEN;
606 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo7960abd2011-08-02 15:39:38 -0600607 platform_device_unregister(bam_ch[rx_hdr->ch_id].pdev);
608 bam_ch[rx_hdr->ch_id].pdev =
609 platform_device_alloc(bam_ch[rx_hdr->ch_id].name, 2);
610 if (!bam_ch[rx_hdr->ch_id].pdev)
611 pr_err("%s: platform_device_alloc failed\n", __func__);
Eric Holmberga623da82012-07-12 09:37:09 -0600612 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberge779dba2011-11-04 18:22:01 -0600613 dev_kfree_skb_any(rx_skb);
Eric Holmberga623da82012-07-12 09:37:09 -0600614 queue_rx();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700615 break;
616 default:
Eric Holmberg878923a2012-01-10 14:28:19 -0700617 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
618 " reserved %d cmd %d pad %d ch %d len %d\n",
619 __func__, rx_hdr->magic_num, rx_hdr->reserved,
620 rx_hdr->cmd, rx_hdr->pad_len, rx_hdr->ch_id,
621 rx_hdr->pkt_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700622 dev_kfree_skb_any(rx_skb);
623 queue_rx();
624 return;
625 }
626}
627
628static int bam_mux_write_cmd(void *data, uint32_t len)
629{
630 int rc;
631 struct tx_pkt_info *pkt;
632 dma_addr_t dma_address;
Jeff Hugo626303bf2011-11-21 11:43:28 -0700633 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700634
Eric Holmbergd83cd2b2011-11-04 15:54:17 -0600635 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700636 if (pkt == NULL) {
637 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
638 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700639 return rc;
640 }
641
642 dma_address = dma_map_single(NULL, data, len,
643 DMA_TO_DEVICE);
644 if (!dma_address) {
645 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugo96cb7482011-12-07 13:28:31 -0700646 kfree(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700647 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700648 return rc;
649 }
650 pkt->skb = (struct sk_buff *)(data);
651 pkt->len = len;
652 pkt->dma_address = dma_address;
653 pkt->is_cmd = 1;
Eric Holmberg878923a2012-01-10 14:28:19 -0700654 set_tx_timestamp(pkt);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600655 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700656 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600657 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700658 rc = sps_transfer_one(bam_tx_pipe, dma_address, len,
659 pkt, SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600660 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700661 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
662 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600663 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700664 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700665 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700666 dma_unmap_single(NULL, pkt->dma_address,
667 pkt->len,
668 DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600669 kfree(pkt);
Jeff Hugobb6da952012-01-16 15:02:42 -0700670 } else {
671 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600672 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700673
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600674 ul_packet_written = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700675 return rc;
676}
677
678static void bam_mux_write_done(struct work_struct *work)
679{
680 struct sk_buff *skb;
681 struct bam_mux_hdr *hdr;
682 struct tx_pkt_info *info;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700683 struct tx_pkt_info *info_expected;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600684 unsigned long event_data;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700685 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700686
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600687 if (in_global_reset)
688 return;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700689
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700690 info = container_of(work, struct tx_pkt_info, work);
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700691
692 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
693 info_expected = list_first_entry(&bam_tx_pool,
694 struct tx_pkt_info, list_node);
695 if (unlikely(info != info_expected)) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700696 struct tx_pkt_info *errant_pkt;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700697
Eric Holmberg878923a2012-01-10 14:28:19 -0700698 DMUX_LOG_KERR("%s: bam_tx_pool mismatch .next=%p,"
699 " list_node=%p, ts=%u.%09lu\n",
700 __func__, bam_tx_pool.next, &info->list_node,
701 info->ts_sec, info->ts_nsec
702 );
703
704 list_for_each_entry(errant_pkt, &bam_tx_pool, list_node) {
705 DMUX_LOG_KERR("%s: node=%p ts=%u.%09lu\n", __func__,
706 &errant_pkt->list_node, errant_pkt->ts_sec,
707 errant_pkt->ts_nsec);
708
709 }
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700710 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
711 BUG();
712 }
713 list_del(&info->list_node);
714 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
715
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600716 if (info->is_cmd) {
717 kfree(info->skb);
718 kfree(info);
719 return;
720 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700721 skb = info->skb;
722 kfree(info);
723 hdr = (struct bam_mux_hdr *)skb->data;
Eric Holmberg9fdef262012-02-14 11:46:05 -0700724 DBG_INC_WRITE_CNT(skb->len);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600725 event_data = (unsigned long)(skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700726 spin_lock_irqsave(&bam_ch[hdr->ch_id].lock, flags);
727 bam_ch[hdr->ch_id].num_tx_pkts--;
728 spin_unlock_irqrestore(&bam_ch[hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600729 if (bam_ch[hdr->ch_id].notify)
730 bam_ch[hdr->ch_id].notify(
731 bam_ch[hdr->ch_id].priv, BAM_DMUX_WRITE_DONE,
732 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700733 else
734 dev_kfree_skb_any(skb);
735}
736
737int msm_bam_dmux_write(uint32_t id, struct sk_buff *skb)
738{
739 int rc = 0;
740 struct bam_mux_hdr *hdr;
741 unsigned long flags;
742 struct sk_buff *new_skb = NULL;
743 dma_addr_t dma_address;
744 struct tx_pkt_info *pkt;
745
746 if (id >= BAM_DMUX_NUM_CHANNELS)
747 return -EINVAL;
748 if (!skb)
749 return -EINVAL;
750 if (!bam_mux_initialized)
751 return -ENODEV;
752
753 DBG("%s: writing to ch %d len %d\n", __func__, id, skb->len);
754 spin_lock_irqsave(&bam_ch[id].lock, flags);
755 if (!bam_ch_is_open(id)) {
756 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
757 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
758 return -ENODEV;
759 }
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700760
761 if (bam_ch[id].use_wm &&
762 (bam_ch[id].num_tx_pkts >= HIGH_WATERMARK)) {
763 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
764 pr_err("%s: watermark exceeded: %d\n", __func__, id);
765 return -EAGAIN;
766 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700767 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
768
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600769 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600770 if (!bam_is_connected) {
771 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600772 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700773 if (unlikely(in_global_reset == 1))
774 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600775 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600776 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600777 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600778
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700779 /* if skb do not have any tailroom for padding,
780 copy the skb into a new expanded skb */
781 if ((skb->len & 0x3) && (skb_tailroom(skb) < (4 - (skb->len & 0x3)))) {
782 /* revisit, probably dev_alloc_skb and memcpy is effecient */
783 new_skb = skb_copy_expand(skb, skb_headroom(skb),
784 4 - (skb->len & 0x3), GFP_ATOMIC);
785 if (new_skb == NULL) {
786 pr_err("%s: cannot allocate skb\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600787 goto write_fail;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700788 }
789 dev_kfree_skb_any(skb);
790 skb = new_skb;
791 DBG_INC_WRITE_CPY(skb->len);
792 }
793
794 hdr = (struct bam_mux_hdr *)skb_push(skb, sizeof(struct bam_mux_hdr));
795
796 /* caller should allocate for hdr and padding
797 hdr is fine, padding is tricky */
798 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
799 hdr->cmd = BAM_MUX_HDR_CMD_DATA;
800 hdr->reserved = 0;
801 hdr->ch_id = id;
802 hdr->pkt_len = skb->len - sizeof(struct bam_mux_hdr);
803 if (skb->len & 0x3)
804 skb_put(skb, 4 - (skb->len & 0x3));
805
806 hdr->pad_len = skb->len - (sizeof(struct bam_mux_hdr) + hdr->pkt_len);
807
808 DBG("%s: data %p, tail %p skb len %d pkt len %d pad len %d\n",
809 __func__, skb->data, skb->tail, skb->len,
810 hdr->pkt_len, hdr->pad_len);
811
812 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
813 if (pkt == NULL) {
814 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600815 goto write_fail2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700816 }
817
818 dma_address = dma_map_single(NULL, skb->data, skb->len,
819 DMA_TO_DEVICE);
820 if (!dma_address) {
821 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600822 goto write_fail3;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700823 }
824 pkt->skb = skb;
825 pkt->dma_address = dma_address;
826 pkt->is_cmd = 0;
Eric Holmberg878923a2012-01-10 14:28:19 -0700827 set_tx_timestamp(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700828 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700829 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600830 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700831 rc = sps_transfer_one(bam_tx_pipe, dma_address, skb->len,
832 pkt, SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600833 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700834 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
835 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600836 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700837 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700838 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700839 dma_unmap_single(NULL, pkt->dma_address,
840 pkt->skb->len, DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600841 kfree(pkt);
Jeff Hugo872bd062011-11-15 17:47:21 -0700842 if (new_skb)
843 dev_kfree_skb_any(new_skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700844 } else {
Jeff Hugobb6da952012-01-16 15:02:42 -0700845 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700846 spin_lock_irqsave(&bam_ch[id].lock, flags);
847 bam_ch[id].num_tx_pkts++;
848 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600849 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600850 ul_packet_written = 1;
851 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700852 return rc;
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600853
854write_fail3:
855 kfree(pkt);
856write_fail2:
Arun Kumar Neelakantam406e5692013-01-17 18:58:04 +0530857 skb_pull(skb, sizeof(struct bam_mux_hdr));
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600858 if (new_skb)
859 dev_kfree_skb_any(new_skb);
860write_fail:
861 read_unlock(&ul_wakeup_lock);
862 return -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700863}
864
865int msm_bam_dmux_open(uint32_t id, void *priv,
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600866 void (*notify)(void *, int, unsigned long))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700867{
868 struct bam_mux_hdr *hdr;
869 unsigned long flags;
870 int rc = 0;
871
872 DBG("%s: opening ch %d\n", __func__, id);
Eric Holmberg5d775432011-11-09 10:23:35 -0700873 if (!bam_mux_initialized) {
874 DBG("%s: not inititialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700875 return -ENODEV;
Eric Holmberg5d775432011-11-09 10:23:35 -0700876 }
877 if (id >= BAM_DMUX_NUM_CHANNELS) {
878 pr_err("%s: invalid channel id %d\n", __func__, id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700879 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700880 }
881 if (notify == NULL) {
882 pr_err("%s: notify function is NULL\n", __func__);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600883 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700884 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700885
886 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_KERNEL);
887 if (hdr == NULL) {
888 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
889 return -ENOMEM;
890 }
891 spin_lock_irqsave(&bam_ch[id].lock, flags);
892 if (bam_ch_is_open(id)) {
893 DBG("%s: Already opened %d\n", __func__, id);
894 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
895 kfree(hdr);
896 goto open_done;
897 }
898 if (!bam_ch_is_remote_open(id)) {
899 DBG("%s: Remote not open; ch: %d\n", __func__, id);
900 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
901 kfree(hdr);
Eric Holmberg5d775432011-11-09 10:23:35 -0700902 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700903 }
904
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600905 bam_ch[id].notify = notify;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700906 bam_ch[id].priv = priv;
907 bam_ch[id].status |= BAM_CH_LOCAL_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700908 bam_ch[id].num_tx_pkts = 0;
909 bam_ch[id].use_wm = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700910 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
911
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600912 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600913 if (!bam_is_connected) {
914 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600915 ul_wakeup();
Brent Hronik96630422013-05-01 16:38:43 -0600916 if (unlikely(in_global_reset == 1)) {
917 kfree(hdr);
Jeff Hugo4838f412012-01-20 11:19:37 -0700918 return -EFAULT;
Brent Hronik96630422013-05-01 16:38:43 -0600919 }
Jeff Hugo061ce672011-10-21 17:15:32 -0600920 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600921 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600922 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600923
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700924 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
925 hdr->cmd = BAM_MUX_HDR_CMD_OPEN;
926 hdr->reserved = 0;
927 hdr->ch_id = id;
928 hdr->pkt_len = 0;
929 hdr->pad_len = 0;
930
931 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600932 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700933
934open_done:
935 DBG("%s: opened ch %d\n", __func__, id);
936 return rc;
937}
938
939int msm_bam_dmux_close(uint32_t id)
940{
941 struct bam_mux_hdr *hdr;
942 unsigned long flags;
943 int rc;
944
945 if (id >= BAM_DMUX_NUM_CHANNELS)
946 return -EINVAL;
947 DBG("%s: closing ch %d\n", __func__, id);
948 if (!bam_mux_initialized)
949 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700950
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600951 read_lock(&ul_wakeup_lock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600952 if (!bam_is_connected && !bam_ch_is_in_reset(id)) {
Jeff Hugo061ce672011-10-21 17:15:32 -0600953 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600954 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700955 if (unlikely(in_global_reset == 1))
956 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600957 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600958 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600959 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600960
Jeff Hugo061ce672011-10-21 17:15:32 -0600961 spin_lock_irqsave(&bam_ch[id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600962 bam_ch[id].notify = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700963 bam_ch[id].priv = NULL;
964 bam_ch[id].status &= ~BAM_CH_LOCAL_OPEN;
965 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
966
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600967 if (bam_ch_is_in_reset(id)) {
968 read_unlock(&ul_wakeup_lock);
969 bam_ch[id].status &= ~BAM_CH_IN_RESET;
970 return 0;
971 }
972
Jeff Hugobb5802f2011-11-02 17:10:29 -0600973 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700974 if (hdr == NULL) {
975 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600976 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700977 return -ENOMEM;
978 }
979 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
980 hdr->cmd = BAM_MUX_HDR_CMD_CLOSE;
981 hdr->reserved = 0;
982 hdr->ch_id = id;
983 hdr->pkt_len = 0;
984 hdr->pad_len = 0;
985
986 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600987 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700988
989 DBG("%s: closed ch %d\n", __func__, id);
990 return rc;
991}
992
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700993int msm_bam_dmux_is_ch_full(uint32_t id)
994{
995 unsigned long flags;
996 int ret;
997
998 if (id >= BAM_DMUX_NUM_CHANNELS)
999 return -EINVAL;
1000
1001 spin_lock_irqsave(&bam_ch[id].lock, flags);
1002 bam_ch[id].use_wm = 1;
1003 ret = bam_ch[id].num_tx_pkts >= HIGH_WATERMARK;
1004 DBG("%s: ch %d num tx pkts=%d, HWM=%d\n", __func__,
1005 id, bam_ch[id].num_tx_pkts, ret);
1006 if (!bam_ch_is_local_open(id)) {
1007 ret = -ENODEV;
1008 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1009 }
1010 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
1011
1012 return ret;
1013}
1014
1015int msm_bam_dmux_is_ch_low(uint32_t id)
1016{
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001017 unsigned long flags;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001018 int ret;
1019
1020 if (id >= BAM_DMUX_NUM_CHANNELS)
1021 return -EINVAL;
1022
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001023 spin_lock_irqsave(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001024 bam_ch[id].use_wm = 1;
1025 ret = bam_ch[id].num_tx_pkts <= LOW_WATERMARK;
1026 DBG("%s: ch %d num tx pkts=%d, LWM=%d\n", __func__,
1027 id, bam_ch[id].num_tx_pkts, ret);
1028 if (!bam_ch_is_local_open(id)) {
1029 ret = -ENODEV;
1030 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1031 }
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001032 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001033
1034 return ret;
1035}
1036
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001037static void rx_switch_to_interrupt_mode(void)
1038{
1039 struct sps_connect cur_rx_conn;
1040 struct sps_iovec iov;
1041 struct rx_pkt_info *info;
1042 int ret;
1043
1044 /*
1045 * Attempt to enable interrupts - if this fails,
1046 * continue polling and we will retry later.
1047 */
1048 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1049 if (ret) {
1050 pr_err("%s: sps_get_config() failed %d\n", __func__, ret);
1051 goto fail;
1052 }
1053
1054 rx_register_event.options = SPS_O_EOT;
1055 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
1056 if (ret) {
1057 pr_err("%s: sps_register_event() failed %d\n", __func__, ret);
1058 goto fail;
1059 }
1060
1061 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
1062 SPS_O_EOT | SPS_O_ACK_TRANSFERS;
1063 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1064 if (ret) {
1065 pr_err("%s: sps_set_config() failed %d\n", __func__, ret);
1066 goto fail;
1067 }
1068 polling_mode = 0;
Eric Holmberg006057d2012-01-11 10:10:42 -07001069 release_wakelock();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001070
1071 /* handle any rx packets before interrupt was enabled */
1072 while (bam_connection_is_active && !polling_mode) {
1073 ret = sps_get_iovec(bam_rx_pipe, &iov);
1074 if (ret) {
1075 pr_err("%s: sps_get_iovec failed %d\n",
1076 __func__, ret);
1077 break;
1078 }
1079 if (iov.addr == 0)
1080 break;
1081
1082 mutex_lock(&bam_rx_pool_mutexlock);
1083 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001084 DMUX_LOG_KERR("%s: have iovec %p but rx pool empty\n",
1085 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001086 mutex_unlock(&bam_rx_pool_mutexlock);
1087 continue;
1088 }
1089 info = list_first_entry(&bam_rx_pool, struct rx_pkt_info,
1090 list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001091 if (info->dma_address != iov.addr) {
1092 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1093 __func__,
1094 (void *)iov.addr,
1095 (void *)info->dma_address);
1096 list_for_each_entry(info, &bam_rx_pool, list_node) {
1097 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1098 (void *)info->dma_address);
1099 if (iov.addr == info->dma_address)
1100 break;
1101 }
1102 }
1103 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001104 list_del(&info->list_node);
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001105 --bam_rx_pool_len;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001106 mutex_unlock(&bam_rx_pool_mutexlock);
1107 handle_bam_mux_cmd(&info->work);
1108 }
1109 return;
1110
1111fail:
1112 pr_err("%s: reverting to polling\n", __func__);
Jeff Hugofff43af92012-03-29 17:54:52 -06001113 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001114}
1115
Jeff Hugo949080a2011-08-30 11:58:56 -06001116static void rx_timer_work_func(struct work_struct *work)
1117{
1118 struct sps_iovec iov;
Jeff Hugo949080a2011-08-30 11:58:56 -06001119 struct rx_pkt_info *info;
1120 int inactive_cycles = 0;
1121 int ret;
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001122 u32 buffs_unused, buffs_used;
Jeff Hugo949080a2011-08-30 11:58:56 -06001123
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001124 while (bam_connection_is_active) { /* timer loop */
Jeff Hugo949080a2011-08-30 11:58:56 -06001125 ++inactive_cycles;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001126 while (bam_connection_is_active) { /* deplete queue loop */
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001127 if (in_global_reset)
1128 return;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001129
1130 ret = sps_get_iovec(bam_rx_pipe, &iov);
1131 if (ret) {
1132 pr_err("%s: sps_get_iovec failed %d\n",
1133 __func__, ret);
1134 break;
1135 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001136 if (iov.addr == 0)
1137 break;
1138 inactive_cycles = 0;
Jeff Hugoc9749932011-11-02 17:50:40 -06001139 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001140 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001141 DMUX_LOG_KERR(
1142 "%s: have iovec %p but rx pool empty\n",
1143 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001144 mutex_unlock(&bam_rx_pool_mutexlock);
1145 continue;
1146 }
1147 info = list_first_entry(&bam_rx_pool,
1148 struct rx_pkt_info, list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001149 if (info->dma_address != iov.addr) {
1150 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1151 __func__,
1152 (void *)iov.addr,
1153 (void *)info->dma_address);
1154 list_for_each_entry(info, &bam_rx_pool,
1155 list_node) {
1156 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1157 (void *)info->dma_address);
1158 if (iov.addr == info->dma_address)
1159 break;
1160 }
1161 }
1162 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001163 list_del(&info->list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001164 --bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -06001165 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -06001166 handle_bam_mux_cmd(&info->work);
1167 }
1168
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001169 if (inactive_cycles >= POLLING_INACTIVITY) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001170 rx_switch_to_interrupt_mode();
1171 break;
Jeff Hugo949080a2011-08-30 11:58:56 -06001172 }
1173
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001174 if (bam_adaptive_timer_enabled) {
1175 usleep_range(rx_timer_interval, rx_timer_interval + 50);
1176
1177 ret = sps_get_unused_desc_num(bam_rx_pipe,
1178 &buffs_unused);
1179
1180 if (ret) {
1181 pr_err("%s: error getting num buffers unused after sleep\n",
1182 __func__);
1183
1184 break;
1185 }
1186
1187 buffs_used = NUM_BUFFERS - buffs_unused;
1188
1189 if (buffs_unused == 0) {
1190 rx_timer_interval = MIN_POLLING_SLEEP;
1191 } else {
1192 if (buffs_used > 0) {
1193 rx_timer_interval =
1194 (2 * NUM_BUFFERS *
1195 rx_timer_interval)/
1196 (3 * buffs_used);
1197 } else {
1198 rx_timer_interval =
1199 MAX_POLLING_SLEEP;
1200 }
1201 }
1202
1203 if (rx_timer_interval > MAX_POLLING_SLEEP)
1204 rx_timer_interval = MAX_POLLING_SLEEP;
1205 else if (rx_timer_interval < MIN_POLLING_SLEEP)
1206 rx_timer_interval = MIN_POLLING_SLEEP;
1207 } else {
1208 usleep_range(POLLING_MIN_SLEEP, POLLING_MAX_SLEEP);
1209 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001210 }
1211}
1212
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001213static void bam_mux_tx_notify(struct sps_event_notify *notify)
1214{
1215 struct tx_pkt_info *pkt;
1216
1217 DBG("%s: event %d notified\n", __func__, notify->event_id);
1218
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001219 if (in_global_reset)
1220 return;
1221
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001222 switch (notify->event_id) {
1223 case SPS_EVENT_EOT:
1224 pkt = notify->data.transfer.user;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001225 if (!pkt->is_cmd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001226 dma_unmap_single(NULL, pkt->dma_address,
1227 pkt->skb->len,
1228 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001229 else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001230 dma_unmap_single(NULL, pkt->dma_address,
1231 pkt->len,
1232 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001233 queue_work(bam_mux_tx_workqueue, &pkt->work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001234 break;
1235 default:
1236 pr_err("%s: recieved unexpected event id %d\n", __func__,
1237 notify->event_id);
1238 }
1239}
1240
Jeff Hugo33dbc002011-08-25 15:52:53 -06001241static void bam_mux_rx_notify(struct sps_event_notify *notify)
1242{
Jeff Hugo949080a2011-08-30 11:58:56 -06001243 int ret;
1244 struct sps_connect cur_rx_conn;
Jeff Hugo33dbc002011-08-25 15:52:53 -06001245
1246 DBG("%s: event %d notified\n", __func__, notify->event_id);
1247
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001248 if (in_global_reset)
1249 return;
1250
Jeff Hugo33dbc002011-08-25 15:52:53 -06001251 switch (notify->event_id) {
1252 case SPS_EVENT_EOT:
Jeff Hugo949080a2011-08-30 11:58:56 -06001253 /* attempt to disable interrupts in this pipe */
1254 if (!polling_mode) {
1255 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1256 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001257 pr_err("%s: sps_get_config() failed %d, interrupts"
1258 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001259 break;
1260 }
Jeff Hugoa9d32ba2011-11-21 14:59:48 -07001261 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
Jeff Hugo949080a2011-08-30 11:58:56 -06001262 SPS_O_ACK_TRANSFERS | SPS_O_POLL;
1263 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1264 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001265 pr_err("%s: sps_set_config() failed %d, interrupts"
1266 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001267 break;
1268 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001269 grab_wakelock();
Jeff Hugo949080a2011-08-30 11:58:56 -06001270 polling_mode = 1;
Jeff Hugofff43af92012-03-29 17:54:52 -06001271 /*
1272 * run on core 0 so that netif_rx() in rmnet uses only
1273 * one queue
1274 */
1275 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Jeff Hugo949080a2011-08-30 11:58:56 -06001276 }
Jeff Hugo33dbc002011-08-25 15:52:53 -06001277 break;
1278 default:
1279 pr_err("%s: recieved unexpected event id %d\n", __func__,
1280 notify->event_id);
1281 }
1282}
1283
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001284#ifdef CONFIG_DEBUG_FS
1285
1286static int debug_tbl(char *buf, int max)
1287{
1288 int i = 0;
1289 int j;
1290
1291 for (j = 0; j < BAM_DMUX_NUM_CHANNELS; ++j) {
1292 i += scnprintf(buf + i, max - i,
1293 "ch%02d local open=%s remote open=%s\n",
1294 j, bam_ch_is_local_open(j) ? "Y" : "N",
1295 bam_ch_is_remote_open(j) ? "Y" : "N");
1296 }
1297
1298 return i;
1299}
1300
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001301static int debug_ul_pkt_cnt(char *buf, int max)
1302{
1303 struct list_head *p;
1304 unsigned long flags;
1305 int n = 0;
1306
1307 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
1308 __list_for_each(p, &bam_tx_pool) {
1309 ++n;
1310 }
1311 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
1312
1313 return scnprintf(buf, max, "Number of UL packets in flight: %d\n", n);
1314}
1315
1316static int debug_stats(char *buf, int max)
1317{
1318 int i = 0;
1319
1320 i += scnprintf(buf + i, max - i,
Eric Holmberg9fdef262012-02-14 11:46:05 -07001321 "skb read cnt: %u\n"
1322 "skb write cnt: %u\n"
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001323 "skb copy cnt: %u\n"
1324 "skb copy bytes: %u\n"
Eric Holmberg6074aba2012-01-18 17:59:44 -07001325 "sps tx failures: %u\n"
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001326 "sps tx stalls: %u\n"
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001327 "rx queue len: %d\n"
1328 "a2 ack out cnt: %d\n"
1329 "a2 ack in cnt: %d\n"
1330 "a2 pwr cntl in: %d\n",
Eric Holmberg9fdef262012-02-14 11:46:05 -07001331 bam_dmux_read_cnt,
1332 bam_dmux_write_cnt,
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001333 bam_dmux_write_cpy_cnt,
1334 bam_dmux_write_cpy_bytes,
Eric Holmberg6074aba2012-01-18 17:59:44 -07001335 bam_dmux_tx_sps_failure_cnt,
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001336 bam_dmux_tx_stall_cnt,
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001337 bam_rx_pool_len,
1338 atomic_read(&bam_dmux_ack_out_cnt),
1339 atomic_read(&bam_dmux_ack_in_cnt),
1340 atomic_read(&bam_dmux_a2_pwr_cntl_in_cnt)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001341 );
1342
1343 return i;
1344}
1345
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001346#define DEBUG_BUFMAX 4096
1347static char debug_buffer[DEBUG_BUFMAX];
1348
1349static ssize_t debug_read(struct file *file, char __user *buf,
1350 size_t count, loff_t *ppos)
1351{
1352 int (*fill)(char *buf, int max) = file->private_data;
1353 int bsize = fill(debug_buffer, DEBUG_BUFMAX);
1354 return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
1355}
1356
1357static int debug_open(struct inode *inode, struct file *file)
1358{
1359 file->private_data = inode->i_private;
1360 return 0;
1361}
1362
1363
1364static const struct file_operations debug_ops = {
1365 .read = debug_read,
1366 .open = debug_open,
1367};
1368
1369static void debug_create(const char *name, mode_t mode,
1370 struct dentry *dent,
1371 int (*fill)(char *buf, int max))
1372{
Eric Holmberge4ac80b2012-01-12 09:21:59 -07001373 struct dentry *file;
1374
1375 file = debugfs_create_file(name, mode, dent, fill, &debug_ops);
1376 if (IS_ERR(file))
1377 pr_err("%s: debugfs create failed %d\n", __func__,
1378 (int)PTR_ERR(file));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001379}
1380
1381#endif
1382
Jeff Hugod98b1082011-10-24 10:30:23 -06001383static void notify_all(int event, unsigned long data)
1384{
1385 int i;
Jeff Hugocb798022012-04-09 14:55:40 -06001386 struct list_head *temp;
1387 struct outside_notify_func *func;
Jeff Hugod98b1082011-10-24 10:30:23 -06001388
1389 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
Eric Holmberg454d9da2012-01-12 09:37:14 -07001390 if (bam_ch_is_open(i)) {
Jeff Hugod98b1082011-10-24 10:30:23 -06001391 bam_ch[i].notify(bam_ch[i].priv, event, data);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301392 BAM_DMUX_LOG("%s: cid=%d, event=%d, data=%lu\n",
Eric Holmberg454d9da2012-01-12 09:37:14 -07001393 __func__, i, event, data);
1394 }
Jeff Hugod98b1082011-10-24 10:30:23 -06001395 }
Jeff Hugocb798022012-04-09 14:55:40 -06001396
1397 __list_for_each(temp, &bam_other_notify_funcs) {
1398 func = container_of(temp, struct outside_notify_func,
1399 list_node);
1400 func->notify(func->priv, event, data);
1401 }
Jeff Hugod98b1082011-10-24 10:30:23 -06001402}
1403
1404static void kickoff_ul_wakeup_func(struct work_struct *work)
1405{
1406 read_lock(&ul_wakeup_lock);
1407 if (!bam_is_connected) {
1408 read_unlock(&ul_wakeup_lock);
1409 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -07001410 if (unlikely(in_global_reset == 1))
1411 return;
Jeff Hugod98b1082011-10-24 10:30:23 -06001412 read_lock(&ul_wakeup_lock);
1413 ul_packet_written = 1;
1414 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
1415 }
1416 read_unlock(&ul_wakeup_lock);
1417}
1418
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001419int msm_bam_dmux_kickoff_ul_wakeup(void)
Jeff Hugod98b1082011-10-24 10:30:23 -06001420{
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001421 int is_connected;
1422
1423 read_lock(&ul_wakeup_lock);
1424 ul_packet_written = 1;
1425 is_connected = bam_is_connected;
1426 if (!is_connected)
1427 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1428 read_unlock(&ul_wakeup_lock);
1429
1430 return is_connected;
Jeff Hugod98b1082011-10-24 10:30:23 -06001431}
1432
Eric Holmberg878923a2012-01-10 14:28:19 -07001433static void power_vote(int vote)
1434{
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301435 BAM_DMUX_LOG("%s: curr=%d, vote=%d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -07001436 bam_dmux_uplink_vote, vote);
1437
1438 if (bam_dmux_uplink_vote == vote)
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301439 BAM_DMUX_LOG("%s: warning - duplicate power vote\n", __func__);
Eric Holmberg878923a2012-01-10 14:28:19 -07001440
1441 bam_dmux_uplink_vote = vote;
1442 if (vote)
1443 smsm_change_state(SMSM_APPS_STATE, 0, SMSM_A2_POWER_CONTROL);
1444 else
1445 smsm_change_state(SMSM_APPS_STATE, SMSM_A2_POWER_CONTROL, 0);
1446}
1447
Eric Holmberg454d9da2012-01-12 09:37:14 -07001448/*
1449 * @note: Must be called with ul_wakeup_lock locked.
1450 */
1451static inline void ul_powerdown(void)
1452{
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301453 BAM_DMUX_LOG("%s: powerdown\n", __func__);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001454 verify_tx_queue_is_empty(__func__);
1455
1456 if (a2_pc_disabled) {
1457 wait_for_dfab = 1;
1458 INIT_COMPLETION(dfab_unvote_completion);
1459 release_wakelock();
1460 } else {
1461 wait_for_ack = 1;
1462 INIT_COMPLETION(ul_wakeup_ack_completion);
1463 power_vote(0);
1464 }
1465 bam_is_connected = 0;
1466 notify_all(BAM_DMUX_UL_DISCONNECTED, (unsigned long)(NULL));
1467}
1468
1469static inline void ul_powerdown_finish(void)
1470{
1471 if (a2_pc_disabled && wait_for_dfab) {
1472 unvote_dfab();
1473 complete_all(&dfab_unvote_completion);
1474 wait_for_dfab = 0;
1475 }
1476}
1477
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001478/*
1479 * Votes for UL power and returns current power state.
1480 *
1481 * @returns true if currently connected
1482 */
1483int msm_bam_dmux_ul_power_vote(void)
1484{
1485 int is_connected;
1486
1487 read_lock(&ul_wakeup_lock);
1488 atomic_inc(&ul_ondemand_vote);
1489 is_connected = bam_is_connected;
1490 if (!is_connected)
1491 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1492 read_unlock(&ul_wakeup_lock);
1493
1494 return is_connected;
1495}
1496
1497/*
1498 * Unvotes for UL power.
1499 *
1500 * @returns true if vote count is 0 (UL shutdown possible)
1501 */
1502int msm_bam_dmux_ul_power_unvote(void)
1503{
1504 int vote;
1505
1506 read_lock(&ul_wakeup_lock);
1507 vote = atomic_dec_return(&ul_ondemand_vote);
1508 if (unlikely(vote) < 0)
1509 DMUX_LOG_KERR("%s: invalid power vote %d\n", __func__, vote);
1510 read_unlock(&ul_wakeup_lock);
1511
1512 return vote == 0;
1513}
1514
Jeff Hugocb798022012-04-09 14:55:40 -06001515int msm_bam_dmux_reg_notify(void *priv,
1516 void (*notify)(void *priv, int event_type,
1517 unsigned long data))
1518{
1519 struct outside_notify_func *func;
1520
1521 if (!notify)
1522 return -EINVAL;
1523
1524 func = kmalloc(sizeof(struct outside_notify_func), GFP_KERNEL);
1525 if (!func)
1526 return -ENOMEM;
1527
1528 func->notify = notify;
1529 func->priv = priv;
1530 list_add(&func->list_node, &bam_other_notify_funcs);
1531
1532 return 0;
1533}
1534
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001535static void ul_timeout(struct work_struct *work)
1536{
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001537 unsigned long flags;
1538 int ret;
1539
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001540 if (in_global_reset)
1541 return;
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001542 ret = write_trylock_irqsave(&ul_wakeup_lock, flags);
1543 if (!ret) { /* failed to grab lock, reschedule and bail */
1544 schedule_delayed_work(&ul_timeout_work,
1545 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1546 return;
1547 }
Eric Holmberg454d9da2012-01-12 09:37:14 -07001548 if (bam_is_connected) {
Eric Holmberg6074aba2012-01-18 17:59:44 -07001549 if (!ul_packet_written) {
1550 spin_lock(&bam_tx_pool_spinlock);
1551 if (!list_empty(&bam_tx_pool)) {
1552 struct tx_pkt_info *info;
1553
1554 info = list_first_entry(&bam_tx_pool,
1555 struct tx_pkt_info, list_node);
1556 DMUX_LOG_KERR("%s: UL delayed ts=%u.%09lu\n",
1557 __func__, info->ts_sec, info->ts_nsec);
1558 DBG_INC_TX_STALL_CNT();
1559 ul_packet_written = 1;
1560 }
1561 spin_unlock(&bam_tx_pool_spinlock);
1562 }
1563
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001564 if (ul_packet_written || atomic_read(&ul_ondemand_vote)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301565 BAM_DMUX_LOG("%s: pkt written %d\n",
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001566 __func__, ul_packet_written);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001567 ul_packet_written = 0;
1568 schedule_delayed_work(&ul_timeout_work,
1569 msecs_to_jiffies(UL_TIMEOUT_DELAY));
Eric Holmberg006057d2012-01-11 10:10:42 -07001570 } else {
Eric Holmberg454d9da2012-01-12 09:37:14 -07001571 ul_powerdown();
Eric Holmberg006057d2012-01-11 10:10:42 -07001572 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001573 }
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001574 write_unlock_irqrestore(&ul_wakeup_lock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001575 ul_powerdown_finish();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001576}
Jeff Hugo4838f412012-01-20 11:19:37 -07001577
1578static int ssrestart_check(void)
1579{
Jeff Hugob8156d72013-06-04 12:51:10 -06001580 int ret = 0;
1581
1582 DMUX_LOG_KERR("%s: modem timeout: BAM DMUX disabled for SSR\n",
1583 __func__);
Eric Holmberg90285e22012-02-22 12:33:05 -07001584 in_global_reset = 1;
Jeff Hugob8156d72013-06-04 12:51:10 -06001585 ret = subsystem_restart("modem");
1586 if (ret == -ENODEV)
1587 panic("modem subsystem restart failed\n");
Eric Holmberg90285e22012-02-22 12:33:05 -07001588 return 1;
Jeff Hugo4838f412012-01-20 11:19:37 -07001589}
1590
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001591static void ul_wakeup(void)
1592{
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001593 int ret;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001594 int do_vote_dfab = 0;
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001595
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001596 mutex_lock(&wakeup_lock);
1597 if (bam_is_connected) { /* bam got connected before lock grabbed */
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301598 BAM_DMUX_LOG("%s Already awake\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001599 mutex_unlock(&wakeup_lock);
1600 return;
1601 }
Eric Holmberg878923a2012-01-10 14:28:19 -07001602
Jeff Hugoc2696142012-05-03 11:42:13 -06001603 /*
Jeff Hugof5001732012-08-27 13:19:09 -06001604 * if this gets hit, that means restart_notifier_cb() has started
1605 * but probably not finished, thus we know SSR has happened, but
1606 * haven't been able to send that info to our clients yet.
1607 * in that case, abort the ul_wakeup() so that we don't undo any
1608 * work restart_notifier_cb() has done. The clients will be notified
1609 * shortly. No cleanup necessary (reschedule the wakeup) as our and
1610 * their SSR handling will cover it
1611 */
1612 if (unlikely(in_global_reset == 1)) {
1613 mutex_unlock(&wakeup_lock);
1614 return;
1615 }
1616
1617 /*
Jeff Hugoc2696142012-05-03 11:42:13 -06001618 * if someone is voting for UL before bam is inited (modem up first
1619 * time), set flag for init to kickoff ul wakeup once bam is inited
1620 */
1621 mutex_lock(&delayed_ul_vote_lock);
1622 if (unlikely(!bam_mux_initialized)) {
1623 need_delayed_ul_vote = 1;
1624 mutex_unlock(&delayed_ul_vote_lock);
1625 mutex_unlock(&wakeup_lock);
1626 return;
1627 }
1628 mutex_unlock(&delayed_ul_vote_lock);
1629
Eric Holmberg006057d2012-01-11 10:10:42 -07001630 if (a2_pc_disabled) {
1631 /*
1632 * don't grab the wakelock the first time because it is
1633 * already grabbed when a2 powers on
1634 */
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001635 if (likely(a2_pc_disabled_wakelock_skipped)) {
Eric Holmberg006057d2012-01-11 10:10:42 -07001636 grab_wakelock();
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001637 do_vote_dfab = 1; /* vote must occur after wait */
1638 } else {
Jeff Hugo583a6da2012-02-03 11:37:30 -07001639 a2_pc_disabled_wakelock_skipped = 1;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001640 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001641 if (wait_for_dfab) {
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001642 ret = wait_for_completion_timeout(
Eric Holmberg006057d2012-01-11 10:10:42 -07001643 &dfab_unvote_completion, HZ);
1644 BUG_ON(ret == 0);
1645 }
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001646 if (likely(do_vote_dfab))
1647 vote_dfab();
Eric Holmberg006057d2012-01-11 10:10:42 -07001648 schedule_delayed_work(&ul_timeout_work,
1649 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1650 bam_is_connected = 1;
1651 mutex_unlock(&wakeup_lock);
1652 return;
1653 }
1654
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001655 /*
1656 * must wait for the previous power down request to have been acked
1657 * chances are it already came in and this will just fall through
1658 * instead of waiting
1659 */
1660 if (wait_for_ack) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301661 BAM_DMUX_LOG("%s waiting for previous ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001662 ret = wait_for_completion_timeout(
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001663 &ul_wakeup_ack_completion, HZ);
Eric Holmberg006057d2012-01-11 10:10:42 -07001664 wait_for_ack = 0;
Jeff Hugo4838f412012-01-20 11:19:37 -07001665 if (unlikely(ret == 0) && ssrestart_check()) {
1666 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301667 BAM_DMUX_LOG("%s timeout previous ack\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001668 return;
1669 }
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001670 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001671 INIT_COMPLETION(ul_wakeup_ack_completion);
Eric Holmberg878923a2012-01-10 14:28:19 -07001672 power_vote(1);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301673 BAM_DMUX_LOG("%s waiting for wakeup ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001674 ret = wait_for_completion_timeout(&ul_wakeup_ack_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001675 if (unlikely(ret == 0) && ssrestart_check()) {
1676 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301677 BAM_DMUX_LOG("%s timeout wakeup ack\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001678 return;
1679 }
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301680 BAM_DMUX_LOG("%s waiting completion\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001681 ret = wait_for_completion_timeout(&bam_connection_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001682 if (unlikely(ret == 0) && ssrestart_check()) {
1683 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301684 BAM_DMUX_LOG("%s timeout power on\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001685 return;
1686 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001687
1688 bam_is_connected = 1;
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301689 BAM_DMUX_LOG("%s complete\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001690 schedule_delayed_work(&ul_timeout_work,
1691 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1692 mutex_unlock(&wakeup_lock);
1693}
1694
1695static void reconnect_to_bam(void)
1696{
1697 int i;
1698
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001699 in_global_reset = 0;
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001700 in_ssr = 0;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001701 vote_dfab();
Jeff Hugo18792a32012-06-20 15:25:55 -06001702 if (!power_management_only_mode) {
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001703 if (ssr_skipped_disconnect) {
1704 /* delayed to here to prevent bus stall */
1705 sps_disconnect(bam_tx_pipe);
1706 sps_disconnect(bam_rx_pipe);
1707 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1708 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
1709 }
1710 ssr_skipped_disconnect = 0;
Jeff Hugo18792a32012-06-20 15:25:55 -06001711 i = sps_device_reset(a2_device_handle);
1712 if (i)
1713 pr_err("%s: device reset failed rc = %d\n", __func__,
1714 i);
1715 i = sps_connect(bam_tx_pipe, &tx_connection);
1716 if (i)
1717 pr_err("%s: tx connection failed rc = %d\n", __func__,
1718 i);
1719 i = sps_connect(bam_rx_pipe, &rx_connection);
1720 if (i)
1721 pr_err("%s: rx connection failed rc = %d\n", __func__,
1722 i);
1723 i = sps_register_event(bam_tx_pipe, &tx_register_event);
1724 if (i)
1725 pr_err("%s: tx event reg failed rc = %d\n", __func__,
1726 i);
1727 i = sps_register_event(bam_rx_pipe, &rx_register_event);
1728 if (i)
1729 pr_err("%s: rx event reg failed rc = %d\n", __func__,
1730 i);
1731 }
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001732
1733 bam_connection_is_active = 1;
1734
1735 if (polling_mode)
1736 rx_switch_to_interrupt_mode();
1737
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001738 toggle_apps_ack();
1739 complete_all(&bam_connection_completion);
Jeff Hugo18792a32012-06-20 15:25:55 -06001740 if (!power_management_only_mode)
1741 queue_rx();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001742}
1743
1744static void disconnect_to_bam(void)
1745{
1746 struct list_head *node;
1747 struct rx_pkt_info *info;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001748 unsigned long flags;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001749
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001750 bam_connection_is_active = 0;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001751
1752 /* handle disconnect during active UL */
1753 write_lock_irqsave(&ul_wakeup_lock, flags);
1754 if (bam_is_connected) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301755 BAM_DMUX_LOG("%s: UL active - forcing powerdown\n", __func__);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001756 ul_powerdown();
1757 }
1758 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1759 ul_powerdown_finish();
1760
1761 /* tear down BAM connection */
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001762 INIT_COMPLETION(bam_connection_completion);
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001763
1764 /* in_ssr documentation/assumptions found in restart_notifier_cb */
Jeff Hugo18792a32012-06-20 15:25:55 -06001765 if (!power_management_only_mode) {
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001766 if (likely(!in_ssr)) {
1767 sps_disconnect(bam_tx_pipe);
1768 sps_disconnect(bam_rx_pipe);
1769 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1770 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
1771 sps_device_reset(a2_device_handle);
1772 } else {
1773 ssr_skipped_disconnect = 1;
1774 }
Jeff Hugo18792a32012-06-20 15:25:55 -06001775 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001776 unvote_dfab();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001777
1778 mutex_lock(&bam_rx_pool_mutexlock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001779 while (!list_empty(&bam_rx_pool)) {
1780 node = bam_rx_pool.next;
1781 list_del(node);
1782 info = container_of(node, struct rx_pkt_info, list_node);
1783 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
1784 DMA_FROM_DEVICE);
1785 dev_kfree_skb_any(info->skb);
1786 kfree(info);
1787 }
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001788 bam_rx_pool_len = 0;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001789 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmberg878923a2012-01-10 14:28:19 -07001790
Jeff Hugo0b13a352012-03-17 23:18:30 -06001791 if (disconnect_ack)
1792 toggle_apps_ack();
1793
Eric Holmberg878923a2012-01-10 14:28:19 -07001794 verify_tx_queue_is_empty(__func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001795}
1796
1797static void vote_dfab(void)
1798{
Jeff Hugoca0caa82011-12-05 16:05:23 -07001799 int rc;
1800
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301801 BAM_DMUX_LOG("%s\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001802 mutex_lock(&dfab_status_lock);
1803 if (dfab_is_on) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301804 BAM_DMUX_LOG("%s: dfab is already on\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001805 mutex_unlock(&dfab_status_lock);
1806 return;
1807 }
Jeff Hugod0befde2012-08-09 15:32:49 -06001808 if (dfab_clk) {
1809 rc = clk_prepare_enable(dfab_clk);
1810 if (rc)
1811 DMUX_LOG_KERR("bam_dmux vote for dfab failed rc = %d\n",
1812 rc);
1813 }
1814 if (xo_clk) {
1815 rc = clk_prepare_enable(xo_clk);
1816 if (rc)
1817 DMUX_LOG_KERR("bam_dmux vote for xo failed rc = %d\n",
1818 rc);
1819 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001820 dfab_is_on = 1;
1821 mutex_unlock(&dfab_status_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001822}
1823
1824static void unvote_dfab(void)
1825{
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301826 BAM_DMUX_LOG("%s\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001827 mutex_lock(&dfab_status_lock);
1828 if (!dfab_is_on) {
1829 DMUX_LOG_KERR("%s: dfab is already off\n", __func__);
1830 dump_stack();
1831 mutex_unlock(&dfab_status_lock);
1832 return;
1833 }
Jeff Hugod0befde2012-08-09 15:32:49 -06001834 if (dfab_clk)
1835 clk_disable_unprepare(dfab_clk);
1836 if (xo_clk)
1837 clk_disable_unprepare(xo_clk);
Eric Holmberg006057d2012-01-11 10:10:42 -07001838 dfab_is_on = 0;
1839 mutex_unlock(&dfab_status_lock);
1840}
1841
1842/* reference counting wrapper around wakelock */
1843static void grab_wakelock(void)
1844{
1845 unsigned long flags;
1846
1847 spin_lock_irqsave(&wakelock_reference_lock, flags);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301848 BAM_DMUX_LOG("%s: ref count = %d\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -07001849 wakelock_reference_count);
1850 if (wakelock_reference_count == 0)
1851 wake_lock(&bam_wakelock);
1852 ++wakelock_reference_count;
1853 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1854}
1855
1856static void release_wakelock(void)
1857{
1858 unsigned long flags;
1859
1860 spin_lock_irqsave(&wakelock_reference_lock, flags);
1861 if (wakelock_reference_count == 0) {
1862 DMUX_LOG_KERR("%s: bam_dmux wakelock not locked\n", __func__);
1863 dump_stack();
1864 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1865 return;
1866 }
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301867 BAM_DMUX_LOG("%s: ref count = %d\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -07001868 wakelock_reference_count);
1869 --wakelock_reference_count;
1870 if (wakelock_reference_count == 0)
1871 wake_unlock(&bam_wakelock);
1872 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001873}
1874
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001875static int restart_notifier_cb(struct notifier_block *this,
1876 unsigned long code,
1877 void *data)
1878{
1879 int i;
1880 struct list_head *node;
1881 struct tx_pkt_info *info;
1882 int temp_remote_status;
Jeff Hugo626303bf2011-11-21 11:43:28 -07001883 unsigned long flags;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001884
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001885 /*
1886 * Bam_dmux counts on the fact that the BEFORE_SHUTDOWN level of
1887 * notifications are guarenteed to execute before the AFTER_SHUTDOWN
1888 * level of notifications, and that BEFORE_SHUTDOWN always occurs in
1889 * all SSR events, no matter what triggered the SSR. Also, bam_dmux
1890 * assumes that SMD does its SSR processing in the AFTER_SHUTDOWN level
1891 * thus bam_dmux is guarenteed to detect SSR before SMD, since the
1892 * callbacks for all the drivers within the AFTER_SHUTDOWN level could
1893 * occur in any order. Bam_dmux uses this knowledge to skip accessing
1894 * the bam hardware when disconnect_to_bam() is triggered by SMD's SSR
1895 * processing. We do not wat to access the bam hardware during SSR
1896 * because a watchdog crash from a bus stall would likely occur.
1897 */
Jeff Hugo199294b2013-02-25 13:46:56 -07001898 if (code == SUBSYS_BEFORE_SHUTDOWN) {
1899 in_global_reset = 1;
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001900 in_ssr = 1;
Zaheerulla Meerf800bba2013-02-13 15:49:14 +05301901 BAM_DMUX_LOG("%s: begin\n", __func__);
Jeff Hugo199294b2013-02-25 13:46:56 -07001902 flush_workqueue(bam_mux_rx_workqueue);
1903 }
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001904 if (code != SUBSYS_AFTER_SHUTDOWN)
1905 return NOTIFY_DONE;
1906
Eric Holmberg454d9da2012-01-12 09:37:14 -07001907 /* Handle uplink Powerdown */
1908 write_lock_irqsave(&ul_wakeup_lock, flags);
1909 if (bam_is_connected) {
1910 ul_powerdown();
1911 wait_for_ack = 0;
1912 }
Jeff Hugo4838f412012-01-20 11:19:37 -07001913 /*
1914 * if modem crash during ul_wakeup(), power_vote is 1, needs to be
1915 * reset to 0. harmless if bam_is_connected check above passes
1916 */
1917 power_vote(0);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001918 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1919 ul_powerdown_finish();
Eric Holmberg006057d2012-01-11 10:10:42 -07001920 a2_pc_disabled = 0;
Jeff Hugo583a6da2012-02-03 11:37:30 -07001921 a2_pc_disabled_wakelock_skipped = 0;
Jeff Hugof62029d2012-07-17 13:39:53 -06001922 disconnect_ack = 1;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001923
1924 /* Cleanup Channel States */
Eric Holmberga623da82012-07-12 09:37:09 -06001925 mutex_lock(&bam_pdev_mutexlock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001926 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
1927 temp_remote_status = bam_ch_is_remote_open(i);
1928 bam_ch[i].status &= ~BAM_CH_REMOTE_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001929 bam_ch[i].num_tx_pkts = 0;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001930 if (bam_ch_is_local_open(i))
1931 bam_ch[i].status |= BAM_CH_IN_RESET;
1932 if (temp_remote_status) {
1933 platform_device_unregister(bam_ch[i].pdev);
1934 bam_ch[i].pdev = platform_device_alloc(
1935 bam_ch[i].name, 2);
1936 }
1937 }
Eric Holmberga623da82012-07-12 09:37:09 -06001938 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001939
1940 /* Cleanup pending UL data */
Jeff Hugo626303bf2011-11-21 11:43:28 -07001941 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001942 while (!list_empty(&bam_tx_pool)) {
1943 node = bam_tx_pool.next;
1944 list_del(node);
1945 info = container_of(node, struct tx_pkt_info,
1946 list_node);
1947 if (!info->is_cmd) {
1948 dma_unmap_single(NULL, info->dma_address,
1949 info->skb->len,
1950 DMA_TO_DEVICE);
1951 dev_kfree_skb_any(info->skb);
1952 } else {
1953 dma_unmap_single(NULL, info->dma_address,
1954 info->len,
1955 DMA_TO_DEVICE);
1956 kfree(info->skb);
1957 }
1958 kfree(info);
1959 }
Jeff Hugo626303bf2011-11-21 11:43:28 -07001960 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001961
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301962 BAM_DMUX_LOG("%s: complete\n", __func__);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001963 return NOTIFY_DONE;
1964}
1965
Jeff Hugo9dea05c2011-12-21 12:23:05 -07001966static int bam_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001967{
1968 u32 h;
1969 dma_addr_t dma_addr;
1970 int ret;
1971 void *a2_virt_addr;
Jeff Hugo4b2890d2012-01-16 16:14:21 -07001972 int skip_iounmap = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001973
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001974 vote_dfab();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001975 /* init BAM */
Jeff Hugo3910ee12012-08-21 14:08:20 -06001976 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
1977 a2_phys_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001978 if (!a2_virt_addr) {
1979 pr_err("%s: ioremap failed\n", __func__);
1980 ret = -ENOMEM;
Jeff Hugo994a92d2012-01-05 13:25:21 -07001981 goto ioremap_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001982 }
Jeff Hugo3910ee12012-08-21 14:08:20 -06001983 a2_props.phys_addr = (u32)(a2_phys_base);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001984 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo3910ee12012-08-21 14:08:20 -06001985 a2_props.virt_size = a2_phys_size;
1986 a2_props.irq = a2_bam_irq;
Jeff Hugo927cba62011-11-11 11:49:52 -07001987 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001988 a2_props.num_pipes = A2_NUM_PIPES;
1989 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
Jeff Hugo75913c82011-12-05 15:59:01 -07001990 if (cpu_is_msm9615())
1991 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001992 /* need to free on tear down */
1993 ret = sps_register_bam_device(&a2_props, &h);
1994 if (ret < 0) {
1995 pr_err("%s: register bam error %d\n", __func__, ret);
1996 goto register_bam_failed;
1997 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001998 a2_device_handle = h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001999
2000 bam_tx_pipe = sps_alloc_endpoint();
2001 if (bam_tx_pipe == NULL) {
2002 pr_err("%s: tx alloc endpoint failed\n", __func__);
2003 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002004 goto tx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002005 }
2006 ret = sps_get_config(bam_tx_pipe, &tx_connection);
2007 if (ret) {
2008 pr_err("%s: tx get config failed %d\n", __func__, ret);
2009 goto tx_get_config_failed;
2010 }
2011
2012 tx_connection.source = SPS_DEV_HANDLE_MEM;
2013 tx_connection.src_pipe_index = 0;
2014 tx_connection.destination = h;
2015 tx_connection.dest_pipe_index = 4;
2016 tx_connection.mode = SPS_MODE_DEST;
2017 tx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT;
2018 tx_desc_mem_buf.size = 0x800; /* 2k */
2019 tx_desc_mem_buf.base = dma_alloc_coherent(NULL, tx_desc_mem_buf.size,
2020 &dma_addr, 0);
2021 if (tx_desc_mem_buf.base == NULL) {
2022 pr_err("%s: tx memory alloc failed\n", __func__);
2023 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002024 goto tx_get_config_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002025 }
2026 tx_desc_mem_buf.phys_base = dma_addr;
2027 memset(tx_desc_mem_buf.base, 0x0, tx_desc_mem_buf.size);
2028 tx_connection.desc = tx_desc_mem_buf;
2029 tx_connection.event_thresh = 0x10;
2030
2031 ret = sps_connect(bam_tx_pipe, &tx_connection);
2032 if (ret < 0) {
2033 pr_err("%s: tx connect error %d\n", __func__, ret);
2034 goto tx_connect_failed;
2035 }
2036
2037 bam_rx_pipe = sps_alloc_endpoint();
2038 if (bam_rx_pipe == NULL) {
2039 pr_err("%s: rx alloc endpoint failed\n", __func__);
2040 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002041 goto rx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002042 }
2043 ret = sps_get_config(bam_rx_pipe, &rx_connection);
2044 if (ret) {
2045 pr_err("%s: rx get config failed %d\n", __func__, ret);
2046 goto rx_get_config_failed;
2047 }
2048
2049 rx_connection.source = h;
2050 rx_connection.src_pipe_index = 5;
2051 rx_connection.destination = SPS_DEV_HANDLE_MEM;
2052 rx_connection.dest_pipe_index = 1;
2053 rx_connection.mode = SPS_MODE_SRC;
Jeff Hugo949080a2011-08-30 11:58:56 -06002054 rx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT |
2055 SPS_O_ACK_TRANSFERS;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002056 rx_desc_mem_buf.size = 0x800; /* 2k */
2057 rx_desc_mem_buf.base = dma_alloc_coherent(NULL, rx_desc_mem_buf.size,
2058 &dma_addr, 0);
2059 if (rx_desc_mem_buf.base == NULL) {
2060 pr_err("%s: rx memory alloc failed\n", __func__);
2061 ret = -ENOMEM;
2062 goto rx_mem_failed;
2063 }
2064 rx_desc_mem_buf.phys_base = dma_addr;
2065 memset(rx_desc_mem_buf.base, 0x0, rx_desc_mem_buf.size);
2066 rx_connection.desc = rx_desc_mem_buf;
2067 rx_connection.event_thresh = 0x10;
2068
2069 ret = sps_connect(bam_rx_pipe, &rx_connection);
2070 if (ret < 0) {
2071 pr_err("%s: rx connect error %d\n", __func__, ret);
2072 goto rx_connect_failed;
2073 }
2074
2075 tx_register_event.options = SPS_O_EOT;
2076 tx_register_event.mode = SPS_TRIGGER_CALLBACK;
2077 tx_register_event.xfer_done = NULL;
2078 tx_register_event.callback = bam_mux_tx_notify;
2079 tx_register_event.user = NULL;
2080 ret = sps_register_event(bam_tx_pipe, &tx_register_event);
2081 if (ret < 0) {
2082 pr_err("%s: tx register event error %d\n", __func__, ret);
2083 goto rx_event_reg_failed;
2084 }
2085
Jeff Hugo33dbc002011-08-25 15:52:53 -06002086 rx_register_event.options = SPS_O_EOT;
2087 rx_register_event.mode = SPS_TRIGGER_CALLBACK;
2088 rx_register_event.xfer_done = NULL;
2089 rx_register_event.callback = bam_mux_rx_notify;
2090 rx_register_event.user = NULL;
2091 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
2092 if (ret < 0) {
2093 pr_err("%s: tx register event error %d\n", __func__, ret);
2094 goto rx_event_reg_failed;
2095 }
2096
Jeff Hugoc2696142012-05-03 11:42:13 -06002097 mutex_lock(&delayed_ul_vote_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002098 bam_mux_initialized = 1;
Jeff Hugoc2696142012-05-03 11:42:13 -06002099 if (need_delayed_ul_vote) {
2100 need_delayed_ul_vote = 0;
2101 msm_bam_dmux_kickoff_ul_wakeup();
2102 }
2103 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002104 toggle_apps_ack();
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002105 bam_connection_is_active = 1;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002106 complete_all(&bam_connection_completion);
Jeff Hugo2fb555e2012-03-14 16:33:47 -06002107 queue_rx();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002108 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002109
2110rx_event_reg_failed:
2111 sps_disconnect(bam_rx_pipe);
2112rx_connect_failed:
2113 dma_free_coherent(NULL, rx_desc_mem_buf.size, rx_desc_mem_buf.base,
2114 rx_desc_mem_buf.phys_base);
2115rx_mem_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002116rx_get_config_failed:
2117 sps_free_endpoint(bam_rx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002118rx_alloc_endpoint_failed:
2119 sps_disconnect(bam_tx_pipe);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002120tx_connect_failed:
2121 dma_free_coherent(NULL, tx_desc_mem_buf.size, tx_desc_mem_buf.base,
2122 tx_desc_mem_buf.phys_base);
2123tx_get_config_failed:
2124 sps_free_endpoint(bam_tx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002125tx_alloc_endpoint_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002126 sps_deregister_bam_device(h);
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002127 /*
2128 * sps_deregister_bam_device() calls iounmap. calling iounmap on the
2129 * same handle below will cause a crash, so skip it if we've freed
2130 * the handle here.
2131 */
2132 skip_iounmap = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002133register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002134 if (!skip_iounmap)
2135 iounmap(a2_virt_addr);
Jeff Hugo994a92d2012-01-05 13:25:21 -07002136ioremap_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002137 /*destroy_workqueue(bam_mux_workqueue);*/
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002138 return ret;
2139}
2140
2141static int bam_init_fallback(void)
2142{
2143 u32 h;
2144 int ret;
2145 void *a2_virt_addr;
2146
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002147 /* init BAM */
Jeff Hugo3910ee12012-08-21 14:08:20 -06002148 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
2149 a2_phys_size);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002150 if (!a2_virt_addr) {
2151 pr_err("%s: ioremap failed\n", __func__);
2152 ret = -ENOMEM;
2153 goto ioremap_failed;
2154 }
Jeff Hugo3910ee12012-08-21 14:08:20 -06002155 a2_props.phys_addr = (u32)(a2_phys_base);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002156 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo3910ee12012-08-21 14:08:20 -06002157 a2_props.virt_size = a2_phys_size;
2158 a2_props.irq = a2_bam_irq;
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002159 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
2160 a2_props.num_pipes = A2_NUM_PIPES;
2161 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
2162 if (cpu_is_msm9615())
2163 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
2164 ret = sps_register_bam_device(&a2_props, &h);
2165 if (ret < 0) {
2166 pr_err("%s: register bam error %d\n", __func__, ret);
2167 goto register_bam_failed;
2168 }
2169 a2_device_handle = h;
Jeff Hugoc2696142012-05-03 11:42:13 -06002170
2171 mutex_lock(&delayed_ul_vote_lock);
2172 bam_mux_initialized = 1;
2173 if (need_delayed_ul_vote) {
2174 need_delayed_ul_vote = 0;
2175 msm_bam_dmux_kickoff_ul_wakeup();
2176 }
2177 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugo2bec9772012-04-05 12:25:16 -06002178 toggle_apps_ack();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002179
Jeff Hugo18792a32012-06-20 15:25:55 -06002180 power_management_only_mode = 1;
2181 bam_connection_is_active = 1;
2182 complete_all(&bam_connection_completion);
2183
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002184 return 0;
2185
2186register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002187 iounmap(a2_virt_addr);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002188ioremap_failed:
2189 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002190}
Jeff Hugoade1f842011-08-03 15:53:59 -06002191
Jeff Hugoa670b762012-03-15 15:58:28 -06002192static void msm9615_bam_init(void)
Eric Holmberg604ab252012-01-15 00:01:18 -07002193{
2194 int ret = 0;
2195
2196 ret = bam_init();
2197 if (ret) {
2198 ret = bam_init_fallback();
2199 if (ret)
2200 pr_err("%s: bam init fallback failed: %d",
2201 __func__, ret);
2202 }
2203}
2204
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002205static void toggle_apps_ack(void)
2206{
2207 static unsigned int clear_bit; /* 0 = set the bit, else clear bit */
Eric Holmberg878923a2012-01-10 14:28:19 -07002208
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302209 BAM_DMUX_LOG("%s: apps ack %d->%d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -07002210 clear_bit & 0x1, ~clear_bit & 0x1);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002211 smsm_change_state(SMSM_APPS_STATE,
2212 clear_bit & SMSM_A2_POWER_CONTROL_ACK,
2213 ~clear_bit & SMSM_A2_POWER_CONTROL_ACK);
2214 clear_bit = ~clear_bit;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002215 DBG_INC_ACK_OUT_CNT();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002216}
2217
Jeff Hugoade1f842011-08-03 15:53:59 -06002218static void bam_dmux_smsm_cb(void *priv, uint32_t old_state, uint32_t new_state)
2219{
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002220 static int last_processed_state;
2221
2222 mutex_lock(&smsm_cb_lock);
Eric Holmberg878923a2012-01-10 14:28:19 -07002223 bam_dmux_power_state = new_state & SMSM_A2_POWER_CONTROL ? 1 : 0;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002224 DBG_INC_A2_POWER_CONTROL_IN_CNT();
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302225 BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
Eric Holmberg878923a2012-01-10 14:28:19 -07002226 new_state);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002227 if (last_processed_state == (new_state & SMSM_A2_POWER_CONTROL)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302228 BAM_DMUX_LOG("%s: already processed this state\n", __func__);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002229 mutex_unlock(&smsm_cb_lock);
2230 return;
2231 }
2232
2233 last_processed_state = new_state & SMSM_A2_POWER_CONTROL;
Eric Holmberg878923a2012-01-10 14:28:19 -07002234
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002235 if (bam_mux_initialized && new_state & SMSM_A2_POWER_CONTROL) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302236 BAM_DMUX_LOG("%s: reconnect\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002237 grab_wakelock();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002238 reconnect_to_bam();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002239 } else if (bam_mux_initialized &&
2240 !(new_state & SMSM_A2_POWER_CONTROL)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302241 BAM_DMUX_LOG("%s: disconnect\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002242 disconnect_to_bam();
Eric Holmberg006057d2012-01-11 10:10:42 -07002243 release_wakelock();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002244 } else if (new_state & SMSM_A2_POWER_CONTROL) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302245 BAM_DMUX_LOG("%s: init\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002246 grab_wakelock();
Jeff Hugoa670b762012-03-15 15:58:28 -06002247 if (cpu_is_msm9615())
2248 msm9615_bam_init();
2249 else
Eric Holmberg604ab252012-01-15 00:01:18 -07002250 bam_init();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002251 } else {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302252 BAM_DMUX_LOG("%s: bad state change\n", __func__);
Jeff Hugoade1f842011-08-03 15:53:59 -06002253 pr_err("%s: unsupported state change\n", __func__);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002254 }
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002255 mutex_unlock(&smsm_cb_lock);
Jeff Hugoade1f842011-08-03 15:53:59 -06002256
2257}
2258
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002259static void bam_dmux_smsm_ack_cb(void *priv, uint32_t old_state,
2260 uint32_t new_state)
2261{
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002262 DBG_INC_ACK_IN_CNT();
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302263 BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
Eric Holmberg878923a2012-01-10 14:28:19 -07002264 new_state);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002265 complete_all(&ul_wakeup_ack_completion);
2266}
2267
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002268static int bam_dmux_probe(struct platform_device *pdev)
2269{
2270 int rc;
Jeff Hugo3910ee12012-08-21 14:08:20 -06002271 struct resource *r;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002272
2273 DBG("%s probe called\n", __func__);
2274 if (bam_mux_initialized)
2275 return 0;
2276
Jeff Hugo3910ee12012-08-21 14:08:20 -06002277 if (pdev->dev.of_node) {
2278 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2279 if (!r) {
2280 pr_err("%s: reg field missing\n", __func__);
2281 return -ENODEV;
2282 }
2283 a2_phys_base = (void *)(r->start);
2284 a2_phys_size = (uint32_t)(resource_size(r));
2285 a2_bam_irq = platform_get_irq(pdev, 0);
2286 if (a2_bam_irq == -ENXIO) {
2287 pr_err("%s: irq field missing\n", __func__);
2288 return -ENODEV;
2289 }
2290 DBG("%s: base:%p size:%x irq:%d\n", __func__,
2291 a2_phys_base,
2292 a2_phys_size,
2293 a2_bam_irq);
2294 } else { /* fallback to default init data */
2295 a2_phys_base = (void *)(A2_PHYS_BASE);
2296 a2_phys_size = A2_PHYS_SIZE;
2297 a2_bam_irq = A2_BAM_IRQ;
2298 }
2299
Stephen Boyd69d35e32012-02-14 15:33:30 -08002300 xo_clk = clk_get(&pdev->dev, "xo");
2301 if (IS_ERR(xo_clk)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302302 BAM_DMUX_LOG("%s: did not get xo clock\n", __func__);
Jeff Hugod0befde2012-08-09 15:32:49 -06002303 xo_clk = NULL;
Stephen Boyd69d35e32012-02-14 15:33:30 -08002304 }
Stephen Boyd1c51a492011-10-26 12:11:47 -07002305 dfab_clk = clk_get(&pdev->dev, "bus_clk");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002306 if (IS_ERR(dfab_clk)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302307 BAM_DMUX_LOG("%s: did not get dfab clock\n", __func__);
Jeff Hugod0befde2012-08-09 15:32:49 -06002308 dfab_clk = NULL;
2309 } else {
2310 rc = clk_set_rate(dfab_clk, 64000000);
2311 if (rc)
2312 pr_err("%s: unable to set dfab clock rate\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002313 }
2314
Jeff Hugofff43af92012-03-29 17:54:52 -06002315 /*
2316 * setup the workqueue so that it can be pinned to core 0 and not
2317 * block the watchdog pet function, so that netif_rx() in rmnet
2318 * only uses one queue.
2319 */
2320 bam_mux_rx_workqueue = alloc_workqueue("bam_dmux_rx",
2321 WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002322 if (!bam_mux_rx_workqueue)
2323 return -ENOMEM;
2324
2325 bam_mux_tx_workqueue = create_singlethread_workqueue("bam_dmux_tx");
2326 if (!bam_mux_tx_workqueue) {
2327 destroy_workqueue(bam_mux_rx_workqueue);
2328 return -ENOMEM;
2329 }
2330
Jeff Hugo7960abd2011-08-02 15:39:38 -06002331 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002332 spin_lock_init(&bam_ch[rc].lock);
Jeff Hugo7960abd2011-08-02 15:39:38 -06002333 scnprintf(bam_ch[rc].name, BAM_DMUX_CH_NAME_MAX_LEN,
2334 "bam_dmux_ch_%d", rc);
2335 /* bus 2, ie a2 stream 2 */
2336 bam_ch[rc].pdev = platform_device_alloc(bam_ch[rc].name, 2);
2337 if (!bam_ch[rc].pdev) {
2338 pr_err("%s: platform device alloc failed\n", __func__);
2339 destroy_workqueue(bam_mux_rx_workqueue);
2340 destroy_workqueue(bam_mux_tx_workqueue);
2341 return -ENOMEM;
2342 }
2343 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002344
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002345 init_completion(&ul_wakeup_ack_completion);
2346 init_completion(&bam_connection_completion);
Eric Holmberg006057d2012-01-11 10:10:42 -07002347 init_completion(&dfab_unvote_completion);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002348 INIT_DELAYED_WORK(&ul_timeout_work, ul_timeout);
Jeff Hugo988e7ba2012-10-03 15:53:54 -06002349 INIT_DELAYED_WORK(&queue_rx_work, queue_rx_work_func);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002350 wake_lock_init(&bam_wakelock, WAKE_LOCK_SUSPEND, "bam_dmux_wakelock");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002351
Jeff Hugoade1f842011-08-03 15:53:59 -06002352 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL,
2353 bam_dmux_smsm_cb, NULL);
2354
2355 if (rc) {
2356 destroy_workqueue(bam_mux_rx_workqueue);
2357 destroy_workqueue(bam_mux_tx_workqueue);
2358 pr_err("%s: smsm cb register failed, rc: %d\n", __func__, rc);
2359 return -ENOMEM;
2360 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002361
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002362 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL_ACK,
2363 bam_dmux_smsm_ack_cb, NULL);
2364
2365 if (rc) {
2366 destroy_workqueue(bam_mux_rx_workqueue);
2367 destroy_workqueue(bam_mux_tx_workqueue);
2368 smsm_state_cb_deregister(SMSM_MODEM_STATE,
2369 SMSM_A2_POWER_CONTROL,
2370 bam_dmux_smsm_cb, NULL);
2371 pr_err("%s: smsm ack cb register failed, rc: %d\n", __func__,
2372 rc);
2373 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc)
2374 platform_device_put(bam_ch[rc].pdev);
2375 return -ENOMEM;
2376 }
2377
Eric Holmbergfd1e2ae2011-11-15 18:28:17 -07002378 if (smsm_get_state(SMSM_MODEM_STATE) & SMSM_A2_POWER_CONTROL)
2379 bam_dmux_smsm_cb(NULL, 0, smsm_get_state(SMSM_MODEM_STATE));
2380
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002381 return 0;
2382}
2383
Jeff Hugo3910ee12012-08-21 14:08:20 -06002384static struct of_device_id msm_match_table[] = {
2385 {.compatible = "qcom,bam_dmux"},
2386 {},
2387};
2388
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002389static struct platform_driver bam_dmux_driver = {
2390 .probe = bam_dmux_probe,
2391 .driver = {
2392 .name = "BAM_RMNT",
2393 .owner = THIS_MODULE,
Jeff Hugo3910ee12012-08-21 14:08:20 -06002394 .of_match_table = msm_match_table,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002395 },
2396};
2397
2398static int __init bam_dmux_init(void)
2399{
2400#ifdef CONFIG_DEBUG_FS
2401 struct dentry *dent;
2402
2403 dent = debugfs_create_dir("bam_dmux", 0);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002404 if (!IS_ERR(dent)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002405 debug_create("tbl", 0444, dent, debug_tbl);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002406 debug_create("ul_pkt_cnt", 0444, dent, debug_ul_pkt_cnt);
2407 debug_create("stats", 0444, dent, debug_stats);
2408 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002409#endif
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302410
2411 bam_ipc_log_txt = ipc_log_context_create(BAM_IPC_LOG_PAGES, "bam_dmux");
2412 if (!bam_ipc_log_txt) {
2413 pr_err("%s : unable to create IPC Logging Context", __func__);
Eric Holmberg878923a2012-01-10 14:28:19 -07002414 }
2415
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07002416 rx_timer_interval = DEFAULT_POLLING_MIN_SLEEP;
2417
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002418 subsys_notif_register_notifier("modem", &restart_notifier);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002419 return platform_driver_register(&bam_dmux_driver);
2420}
2421
Jeff Hugoade1f842011-08-03 15:53:59 -06002422late_initcall(bam_dmux_init); /* needs to init after SMD */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002423MODULE_DESCRIPTION("MSM BAM DMUX");
2424MODULE_LICENSE("GPL v2");