blob: 87e8ac6832f319387bfa3d6ad2918680eaf5b301 [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,
Jeff Hugoc85df962013-04-05 13:22:48 -0600436 BUFFER_SIZE, info, 0);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700437 if (ret) {
Eric Holmberg00cf8692012-07-16 14:21:19 -0600438 list_del(&info->list_node);
439 rx_len_cached = --bam_rx_pool_len;
440 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700441 DMUX_LOG_KERR("%s: sps_transfer_one failed %d\n",
442 __func__, ret);
Eric Holmberg00cf8692012-07-16 14:21:19 -0600443
444 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
445 DMA_FROM_DEVICE);
446
447 goto fail_skb;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700448 }
Eric Holmberg00cf8692012-07-16 14:21:19 -0600449 mutex_unlock(&bam_rx_pool_mutexlock);
450
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700451 }
452 return;
453
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700454fail_skb:
455 dev_kfree_skb_any(info->skb);
456
457fail_info:
458 kfree(info);
459
460fail:
Arun Kumar Neelakantam799447f2012-12-13 18:06:49 +0530461 if (rx_len_cached == 0 && !in_global_reset) {
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600462 DMUX_LOG_KERR("%s: rescheduling\n", __func__);
463 schedule_delayed_work(&queue_rx_work, msecs_to_jiffies(100));
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700464 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700465}
466
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600467static void queue_rx_work_func(struct work_struct *work)
468{
469 queue_rx();
470}
471
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700472static void bam_mux_process_data(struct sk_buff *rx_skb)
473{
474 unsigned long flags;
475 struct bam_mux_hdr *rx_hdr;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600476 unsigned long event_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700477
478 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
479
480 rx_skb->data = (unsigned char *)(rx_hdr + 1);
481 rx_skb->tail = rx_skb->data + rx_hdr->pkt_len;
482 rx_skb->len = rx_hdr->pkt_len;
Jeff Hugoee88f672011-10-04 17:14:52 -0600483 rx_skb->truesize = rx_hdr->pkt_len + sizeof(struct sk_buff);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700484
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600485 event_data = (unsigned long)(rx_skb);
486
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700487 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600488 if (bam_ch[rx_hdr->ch_id].notify)
489 bam_ch[rx_hdr->ch_id].notify(
490 bam_ch[rx_hdr->ch_id].priv, BAM_DMUX_RECEIVE,
491 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700492 else
493 dev_kfree_skb_any(rx_skb);
494 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
495
496 queue_rx();
497}
498
Eric Holmberg006057d2012-01-11 10:10:42 -0700499static inline void handle_bam_mux_cmd_open(struct bam_mux_hdr *rx_hdr)
500{
501 unsigned long flags;
502 int ret;
503
Eric Holmberga623da82012-07-12 09:37:09 -0600504 mutex_lock(&bam_pdev_mutexlock);
505 if (in_global_reset) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530506 BAM_DMUX_LOG("%s: open cid %d aborted due to ssr\n",
Eric Holmberga623da82012-07-12 09:37:09 -0600507 __func__, rx_hdr->ch_id);
508 mutex_unlock(&bam_pdev_mutexlock);
509 queue_rx();
510 return;
511 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700512 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
513 bam_ch[rx_hdr->ch_id].status |= BAM_CH_REMOTE_OPEN;
514 bam_ch[rx_hdr->ch_id].num_tx_pkts = 0;
515 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Eric Holmberg006057d2012-01-11 10:10:42 -0700516 ret = platform_device_add(bam_ch[rx_hdr->ch_id].pdev);
517 if (ret)
518 pr_err("%s: platform_device_add() error: %d\n",
519 __func__, ret);
Eric Holmberga623da82012-07-12 09:37:09 -0600520 mutex_unlock(&bam_pdev_mutexlock);
521 queue_rx();
Eric Holmberg006057d2012-01-11 10:10:42 -0700522}
523
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700524static void handle_bam_mux_cmd(struct work_struct *work)
525{
526 unsigned long flags;
527 struct bam_mux_hdr *rx_hdr;
528 struct rx_pkt_info *info;
529 struct sk_buff *rx_skb;
530
531 info = container_of(work, struct rx_pkt_info, work);
532 rx_skb = info->skb;
Jeff Hugo949080a2011-08-30 11:58:56 -0600533 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE, DMA_FROM_DEVICE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700534 kfree(info);
535
536 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
537
538 DBG_INC_READ_CNT(sizeof(struct bam_mux_hdr));
539 DBG("%s: magic %x reserved %d cmd %d pad %d ch %d len %d\n", __func__,
540 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
541 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
542 if (rx_hdr->magic_num != BAM_MUX_HDR_MAGIC_NO) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700543 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
544 " reserved %d cmd %d"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700545 " pad %d ch %d len %d\n", __func__,
546 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
547 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
548 dev_kfree_skb_any(rx_skb);
549 queue_rx();
550 return;
551 }
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700552
553 if (rx_hdr->ch_id >= BAM_DMUX_NUM_CHANNELS) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700554 DMUX_LOG_KERR("%s: dropping invalid LCID %d"
555 " reserved %d cmd %d"
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700556 " pad %d ch %d len %d\n", __func__,
557 rx_hdr->ch_id, rx_hdr->reserved, rx_hdr->cmd,
558 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
559 dev_kfree_skb_any(rx_skb);
560 queue_rx();
561 return;
562 }
563
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700564 switch (rx_hdr->cmd) {
565 case BAM_MUX_HDR_CMD_DATA:
566 DBG_INC_READ_CNT(rx_hdr->pkt_len);
567 bam_mux_process_data(rx_skb);
568 break;
569 case BAM_MUX_HDR_CMD_OPEN:
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530570 BAM_DMUX_LOG("%s: opening cid %d PC enabled\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700571 rx_hdr->ch_id);
Eric Holmberg006057d2012-01-11 10:10:42 -0700572 handle_bam_mux_cmd_open(rx_hdr);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600573 if (!(rx_hdr->reserved & ENABLE_DISCONNECT_ACK)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530574 BAM_DMUX_LOG("%s: deactivating disconnect ack\n",
Jeff Hugod7d2b062012-07-24 14:29:56 -0600575 __func__);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600576 disconnect_ack = 0;
Jeff Hugo0b13a352012-03-17 23:18:30 -0600577 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700578 dev_kfree_skb_any(rx_skb);
579 break;
580 case BAM_MUX_HDR_CMD_OPEN_NO_A2_PC:
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530581 BAM_DMUX_LOG("%s: opening cid %d PC disabled\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -0700582 rx_hdr->ch_id);
583
584 if (!a2_pc_disabled) {
585 a2_pc_disabled = 1;
Jeff Hugo322179f2012-02-29 10:52:34 -0700586 ul_wakeup();
Eric Holmberg006057d2012-01-11 10:10:42 -0700587 }
588
589 handle_bam_mux_cmd_open(rx_hdr);
Eric Holmberge779dba2011-11-04 18:22:01 -0600590 dev_kfree_skb_any(rx_skb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700591 break;
592 case BAM_MUX_HDR_CMD_CLOSE:
593 /* probably should drop pending write */
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530594 BAM_DMUX_LOG("%s: closing cid %d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700595 rx_hdr->ch_id);
Eric Holmberga623da82012-07-12 09:37:09 -0600596 mutex_lock(&bam_pdev_mutexlock);
597 if (in_global_reset) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530598 BAM_DMUX_LOG("%s: close cid %d aborted due to ssr\n",
Eric Holmberga623da82012-07-12 09:37:09 -0600599 __func__, rx_hdr->ch_id);
600 mutex_unlock(&bam_pdev_mutexlock);
601 break;
602 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700603 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
604 bam_ch[rx_hdr->ch_id].status &= ~BAM_CH_REMOTE_OPEN;
605 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo7960abd2011-08-02 15:39:38 -0600606 platform_device_unregister(bam_ch[rx_hdr->ch_id].pdev);
607 bam_ch[rx_hdr->ch_id].pdev =
608 platform_device_alloc(bam_ch[rx_hdr->ch_id].name, 2);
609 if (!bam_ch[rx_hdr->ch_id].pdev)
610 pr_err("%s: platform_device_alloc failed\n", __func__);
Eric Holmberga623da82012-07-12 09:37:09 -0600611 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberge779dba2011-11-04 18:22:01 -0600612 dev_kfree_skb_any(rx_skb);
Eric Holmberga623da82012-07-12 09:37:09 -0600613 queue_rx();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700614 break;
615 default:
Eric Holmberg878923a2012-01-10 14:28:19 -0700616 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
617 " reserved %d cmd %d pad %d ch %d len %d\n",
618 __func__, rx_hdr->magic_num, rx_hdr->reserved,
619 rx_hdr->cmd, rx_hdr->pad_len, rx_hdr->ch_id,
620 rx_hdr->pkt_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700621 dev_kfree_skb_any(rx_skb);
622 queue_rx();
623 return;
624 }
625}
626
627static int bam_mux_write_cmd(void *data, uint32_t len)
628{
629 int rc;
630 struct tx_pkt_info *pkt;
631 dma_addr_t dma_address;
Jeff Hugo626303bf2011-11-21 11:43:28 -0700632 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700633
Eric Holmbergd83cd2b2011-11-04 15:54:17 -0600634 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700635 if (pkt == NULL) {
636 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
637 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700638 return rc;
639 }
640
641 dma_address = dma_map_single(NULL, data, len,
642 DMA_TO_DEVICE);
643 if (!dma_address) {
644 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugo96cb7482011-12-07 13:28:31 -0700645 kfree(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700646 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700647 return rc;
648 }
649 pkt->skb = (struct sk_buff *)(data);
650 pkt->len = len;
651 pkt->dma_address = dma_address;
652 pkt->is_cmd = 1;
Eric Holmberg878923a2012-01-10 14:28:19 -0700653 set_tx_timestamp(pkt);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600654 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700655 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600656 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700657 rc = sps_transfer_one(bam_tx_pipe, dma_address, len,
Jeff Hugoc85df962013-04-05 13:22:48 -0600658 pkt, SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600659 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700660 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
661 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600662 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700663 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700664 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700665 dma_unmap_single(NULL, pkt->dma_address,
666 pkt->len,
667 DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600668 kfree(pkt);
Jeff Hugobb6da952012-01-16 15:02:42 -0700669 } else {
670 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600671 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700672
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600673 ul_packet_written = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700674 return rc;
675}
676
677static void bam_mux_write_done(struct work_struct *work)
678{
679 struct sk_buff *skb;
680 struct bam_mux_hdr *hdr;
681 struct tx_pkt_info *info;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700682 struct tx_pkt_info *info_expected;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600683 unsigned long event_data;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700684 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700685
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600686 if (in_global_reset)
687 return;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700688
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700689 info = container_of(work, struct tx_pkt_info, work);
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700690
691 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
692 info_expected = list_first_entry(&bam_tx_pool,
693 struct tx_pkt_info, list_node);
694 if (unlikely(info != info_expected)) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700695 struct tx_pkt_info *errant_pkt;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700696
Eric Holmberg878923a2012-01-10 14:28:19 -0700697 DMUX_LOG_KERR("%s: bam_tx_pool mismatch .next=%p,"
698 " list_node=%p, ts=%u.%09lu\n",
699 __func__, bam_tx_pool.next, &info->list_node,
700 info->ts_sec, info->ts_nsec
701 );
702
703 list_for_each_entry(errant_pkt, &bam_tx_pool, list_node) {
704 DMUX_LOG_KERR("%s: node=%p ts=%u.%09lu\n", __func__,
705 &errant_pkt->list_node, errant_pkt->ts_sec,
706 errant_pkt->ts_nsec);
707
708 }
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700709 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
710 BUG();
711 }
712 list_del(&info->list_node);
713 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
714
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600715 if (info->is_cmd) {
716 kfree(info->skb);
717 kfree(info);
718 return;
719 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700720 skb = info->skb;
721 kfree(info);
722 hdr = (struct bam_mux_hdr *)skb->data;
Eric Holmberg9fdef262012-02-14 11:46:05 -0700723 DBG_INC_WRITE_CNT(skb->len);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600724 event_data = (unsigned long)(skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700725 spin_lock_irqsave(&bam_ch[hdr->ch_id].lock, flags);
726 bam_ch[hdr->ch_id].num_tx_pkts--;
727 spin_unlock_irqrestore(&bam_ch[hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600728 if (bam_ch[hdr->ch_id].notify)
729 bam_ch[hdr->ch_id].notify(
730 bam_ch[hdr->ch_id].priv, BAM_DMUX_WRITE_DONE,
731 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700732 else
733 dev_kfree_skb_any(skb);
734}
735
736int msm_bam_dmux_write(uint32_t id, struct sk_buff *skb)
737{
738 int rc = 0;
739 struct bam_mux_hdr *hdr;
740 unsigned long flags;
741 struct sk_buff *new_skb = NULL;
742 dma_addr_t dma_address;
743 struct tx_pkt_info *pkt;
744
745 if (id >= BAM_DMUX_NUM_CHANNELS)
746 return -EINVAL;
747 if (!skb)
748 return -EINVAL;
749 if (!bam_mux_initialized)
750 return -ENODEV;
751
752 DBG("%s: writing to ch %d len %d\n", __func__, id, skb->len);
753 spin_lock_irqsave(&bam_ch[id].lock, flags);
754 if (!bam_ch_is_open(id)) {
755 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
756 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
757 return -ENODEV;
758 }
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700759
760 if (bam_ch[id].use_wm &&
761 (bam_ch[id].num_tx_pkts >= HIGH_WATERMARK)) {
762 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
763 pr_err("%s: watermark exceeded: %d\n", __func__, id);
764 return -EAGAIN;
765 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700766 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
767
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600768 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600769 if (!bam_is_connected) {
770 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600771 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700772 if (unlikely(in_global_reset == 1))
773 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600774 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600775 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600776 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600777
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700778 /* if skb do not have any tailroom for padding,
779 copy the skb into a new expanded skb */
780 if ((skb->len & 0x3) && (skb_tailroom(skb) < (4 - (skb->len & 0x3)))) {
781 /* revisit, probably dev_alloc_skb and memcpy is effecient */
782 new_skb = skb_copy_expand(skb, skb_headroom(skb),
783 4 - (skb->len & 0x3), GFP_ATOMIC);
784 if (new_skb == NULL) {
785 pr_err("%s: cannot allocate skb\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600786 goto write_fail;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700787 }
788 dev_kfree_skb_any(skb);
789 skb = new_skb;
790 DBG_INC_WRITE_CPY(skb->len);
791 }
792
793 hdr = (struct bam_mux_hdr *)skb_push(skb, sizeof(struct bam_mux_hdr));
794
795 /* caller should allocate for hdr and padding
796 hdr is fine, padding is tricky */
797 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
798 hdr->cmd = BAM_MUX_HDR_CMD_DATA;
799 hdr->reserved = 0;
800 hdr->ch_id = id;
801 hdr->pkt_len = skb->len - sizeof(struct bam_mux_hdr);
802 if (skb->len & 0x3)
803 skb_put(skb, 4 - (skb->len & 0x3));
804
805 hdr->pad_len = skb->len - (sizeof(struct bam_mux_hdr) + hdr->pkt_len);
806
807 DBG("%s: data %p, tail %p skb len %d pkt len %d pad len %d\n",
808 __func__, skb->data, skb->tail, skb->len,
809 hdr->pkt_len, hdr->pad_len);
810
811 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
812 if (pkt == NULL) {
813 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600814 goto write_fail2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700815 }
816
817 dma_address = dma_map_single(NULL, skb->data, skb->len,
818 DMA_TO_DEVICE);
819 if (!dma_address) {
820 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600821 goto write_fail3;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700822 }
823 pkt->skb = skb;
824 pkt->dma_address = dma_address;
825 pkt->is_cmd = 0;
Eric Holmberg878923a2012-01-10 14:28:19 -0700826 set_tx_timestamp(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700827 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700828 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600829 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700830 rc = sps_transfer_one(bam_tx_pipe, dma_address, skb->len,
Jeff Hugoc85df962013-04-05 13:22:48 -0600831 pkt, SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600832 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700833 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
834 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600835 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700836 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700837 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700838 dma_unmap_single(NULL, pkt->dma_address,
839 pkt->skb->len, DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600840 kfree(pkt);
Jeff Hugo872bd062011-11-15 17:47:21 -0700841 if (new_skb)
842 dev_kfree_skb_any(new_skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700843 } else {
Jeff Hugobb6da952012-01-16 15:02:42 -0700844 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700845 spin_lock_irqsave(&bam_ch[id].lock, flags);
846 bam_ch[id].num_tx_pkts++;
847 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600848 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600849 ul_packet_written = 1;
850 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700851 return rc;
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600852
853write_fail3:
854 kfree(pkt);
855write_fail2:
Arun Kumar Neelakantam406e5692013-01-17 18:58:04 +0530856 skb_pull(skb, sizeof(struct bam_mux_hdr));
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600857 if (new_skb)
858 dev_kfree_skb_any(new_skb);
859write_fail:
860 read_unlock(&ul_wakeup_lock);
861 return -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700862}
863
864int msm_bam_dmux_open(uint32_t id, void *priv,
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600865 void (*notify)(void *, int, unsigned long))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700866{
867 struct bam_mux_hdr *hdr;
868 unsigned long flags;
869 int rc = 0;
870
871 DBG("%s: opening ch %d\n", __func__, id);
Eric Holmberg5d775432011-11-09 10:23:35 -0700872 if (!bam_mux_initialized) {
873 DBG("%s: not inititialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874 return -ENODEV;
Eric Holmberg5d775432011-11-09 10:23:35 -0700875 }
876 if (id >= BAM_DMUX_NUM_CHANNELS) {
877 pr_err("%s: invalid channel id %d\n", __func__, id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700878 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700879 }
880 if (notify == NULL) {
881 pr_err("%s: notify function is NULL\n", __func__);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600882 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700883 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700884
885 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_KERNEL);
886 if (hdr == NULL) {
887 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
888 return -ENOMEM;
889 }
890 spin_lock_irqsave(&bam_ch[id].lock, flags);
891 if (bam_ch_is_open(id)) {
892 DBG("%s: Already opened %d\n", __func__, id);
893 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
894 kfree(hdr);
895 goto open_done;
896 }
897 if (!bam_ch_is_remote_open(id)) {
898 DBG("%s: Remote not open; ch: %d\n", __func__, id);
899 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
900 kfree(hdr);
Eric Holmberg5d775432011-11-09 10:23:35 -0700901 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700902 }
903
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600904 bam_ch[id].notify = notify;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700905 bam_ch[id].priv = priv;
906 bam_ch[id].status |= BAM_CH_LOCAL_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700907 bam_ch[id].num_tx_pkts = 0;
908 bam_ch[id].use_wm = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700909 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
910
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600911 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600912 if (!bam_is_connected) {
913 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600914 ul_wakeup();
Brent Hronik96630422013-05-01 16:38:43 -0600915 if (unlikely(in_global_reset == 1)) {
916 kfree(hdr);
Jeff Hugo4838f412012-01-20 11:19:37 -0700917 return -EFAULT;
Brent Hronik96630422013-05-01 16:38:43 -0600918 }
Jeff Hugo061ce672011-10-21 17:15:32 -0600919 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600920 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600921 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600922
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700923 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
924 hdr->cmd = BAM_MUX_HDR_CMD_OPEN;
925 hdr->reserved = 0;
926 hdr->ch_id = id;
927 hdr->pkt_len = 0;
928 hdr->pad_len = 0;
929
930 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600931 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700932
933open_done:
934 DBG("%s: opened ch %d\n", __func__, id);
935 return rc;
936}
937
938int msm_bam_dmux_close(uint32_t id)
939{
940 struct bam_mux_hdr *hdr;
941 unsigned long flags;
942 int rc;
943
944 if (id >= BAM_DMUX_NUM_CHANNELS)
945 return -EINVAL;
946 DBG("%s: closing ch %d\n", __func__, id);
947 if (!bam_mux_initialized)
948 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700949
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600950 read_lock(&ul_wakeup_lock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600951 if (!bam_is_connected && !bam_ch_is_in_reset(id)) {
Jeff Hugo061ce672011-10-21 17:15:32 -0600952 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600953 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700954 if (unlikely(in_global_reset == 1))
955 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600956 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600957 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600958 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600959
Jeff Hugo061ce672011-10-21 17:15:32 -0600960 spin_lock_irqsave(&bam_ch[id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600961 bam_ch[id].notify = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700962 bam_ch[id].priv = NULL;
963 bam_ch[id].status &= ~BAM_CH_LOCAL_OPEN;
964 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
965
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600966 if (bam_ch_is_in_reset(id)) {
967 read_unlock(&ul_wakeup_lock);
968 bam_ch[id].status &= ~BAM_CH_IN_RESET;
969 return 0;
970 }
971
Jeff Hugobb5802f2011-11-02 17:10:29 -0600972 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700973 if (hdr == NULL) {
974 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600975 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700976 return -ENOMEM;
977 }
978 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
979 hdr->cmd = BAM_MUX_HDR_CMD_CLOSE;
980 hdr->reserved = 0;
981 hdr->ch_id = id;
982 hdr->pkt_len = 0;
983 hdr->pad_len = 0;
984
985 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600986 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700987
988 DBG("%s: closed ch %d\n", __func__, id);
989 return rc;
990}
991
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700992int msm_bam_dmux_is_ch_full(uint32_t id)
993{
994 unsigned long flags;
995 int ret;
996
997 if (id >= BAM_DMUX_NUM_CHANNELS)
998 return -EINVAL;
999
1000 spin_lock_irqsave(&bam_ch[id].lock, flags);
1001 bam_ch[id].use_wm = 1;
1002 ret = bam_ch[id].num_tx_pkts >= HIGH_WATERMARK;
1003 DBG("%s: ch %d num tx pkts=%d, HWM=%d\n", __func__,
1004 id, bam_ch[id].num_tx_pkts, ret);
1005 if (!bam_ch_is_local_open(id)) {
1006 ret = -ENODEV;
1007 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1008 }
1009 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
1010
1011 return ret;
1012}
1013
1014int msm_bam_dmux_is_ch_low(uint32_t id)
1015{
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001016 unsigned long flags;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001017 int ret;
1018
1019 if (id >= BAM_DMUX_NUM_CHANNELS)
1020 return -EINVAL;
1021
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001022 spin_lock_irqsave(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001023 bam_ch[id].use_wm = 1;
1024 ret = bam_ch[id].num_tx_pkts <= LOW_WATERMARK;
1025 DBG("%s: ch %d num tx pkts=%d, LWM=%d\n", __func__,
1026 id, bam_ch[id].num_tx_pkts, ret);
1027 if (!bam_ch_is_local_open(id)) {
1028 ret = -ENODEV;
1029 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1030 }
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001031 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001032
1033 return ret;
1034}
1035
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001036static void rx_switch_to_interrupt_mode(void)
1037{
1038 struct sps_connect cur_rx_conn;
1039 struct sps_iovec iov;
1040 struct rx_pkt_info *info;
1041 int ret;
1042
1043 /*
1044 * Attempt to enable interrupts - if this fails,
1045 * continue polling and we will retry later.
1046 */
1047 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1048 if (ret) {
1049 pr_err("%s: sps_get_config() failed %d\n", __func__, ret);
1050 goto fail;
1051 }
1052
1053 rx_register_event.options = SPS_O_EOT;
1054 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
1055 if (ret) {
1056 pr_err("%s: sps_register_event() failed %d\n", __func__, ret);
1057 goto fail;
1058 }
1059
1060 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
1061 SPS_O_EOT | SPS_O_ACK_TRANSFERS;
1062 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1063 if (ret) {
1064 pr_err("%s: sps_set_config() failed %d\n", __func__, ret);
1065 goto fail;
1066 }
1067 polling_mode = 0;
Eric Holmberg006057d2012-01-11 10:10:42 -07001068 release_wakelock();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001069
1070 /* handle any rx packets before interrupt was enabled */
1071 while (bam_connection_is_active && !polling_mode) {
1072 ret = sps_get_iovec(bam_rx_pipe, &iov);
1073 if (ret) {
1074 pr_err("%s: sps_get_iovec failed %d\n",
1075 __func__, ret);
1076 break;
1077 }
1078 if (iov.addr == 0)
1079 break;
1080
1081 mutex_lock(&bam_rx_pool_mutexlock);
1082 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001083 DMUX_LOG_KERR("%s: have iovec %p but rx pool empty\n",
1084 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001085 mutex_unlock(&bam_rx_pool_mutexlock);
1086 continue;
1087 }
1088 info = list_first_entry(&bam_rx_pool, struct rx_pkt_info,
1089 list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001090 if (info->dma_address != iov.addr) {
1091 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1092 __func__,
1093 (void *)iov.addr,
1094 (void *)info->dma_address);
1095 list_for_each_entry(info, &bam_rx_pool, list_node) {
1096 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1097 (void *)info->dma_address);
1098 if (iov.addr == info->dma_address)
1099 break;
1100 }
1101 }
1102 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001103 list_del(&info->list_node);
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001104 --bam_rx_pool_len;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001105 mutex_unlock(&bam_rx_pool_mutexlock);
1106 handle_bam_mux_cmd(&info->work);
1107 }
1108 return;
1109
1110fail:
1111 pr_err("%s: reverting to polling\n", __func__);
Jeff Hugofff43af92012-03-29 17:54:52 -06001112 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001113}
1114
Jeff Hugo949080a2011-08-30 11:58:56 -06001115static void rx_timer_work_func(struct work_struct *work)
1116{
1117 struct sps_iovec iov;
Jeff Hugo949080a2011-08-30 11:58:56 -06001118 struct rx_pkt_info *info;
1119 int inactive_cycles = 0;
1120 int ret;
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001121 u32 buffs_unused, buffs_used;
Jeff Hugo949080a2011-08-30 11:58:56 -06001122
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001123 while (bam_connection_is_active) { /* timer loop */
Jeff Hugo949080a2011-08-30 11:58:56 -06001124 ++inactive_cycles;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001125 while (bam_connection_is_active) { /* deplete queue loop */
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001126 if (in_global_reset)
1127 return;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001128
1129 ret = sps_get_iovec(bam_rx_pipe, &iov);
1130 if (ret) {
1131 pr_err("%s: sps_get_iovec failed %d\n",
1132 __func__, ret);
1133 break;
1134 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001135 if (iov.addr == 0)
1136 break;
1137 inactive_cycles = 0;
Jeff Hugoc9749932011-11-02 17:50:40 -06001138 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001139 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001140 DMUX_LOG_KERR(
1141 "%s: have iovec %p but rx pool empty\n",
1142 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001143 mutex_unlock(&bam_rx_pool_mutexlock);
1144 continue;
1145 }
1146 info = list_first_entry(&bam_rx_pool,
1147 struct rx_pkt_info, list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001148 if (info->dma_address != iov.addr) {
1149 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1150 __func__,
1151 (void *)iov.addr,
1152 (void *)info->dma_address);
1153 list_for_each_entry(info, &bam_rx_pool,
1154 list_node) {
1155 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1156 (void *)info->dma_address);
1157 if (iov.addr == info->dma_address)
1158 break;
1159 }
1160 }
1161 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001162 list_del(&info->list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001163 --bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -06001164 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -06001165 handle_bam_mux_cmd(&info->work);
1166 }
1167
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001168 if (inactive_cycles >= POLLING_INACTIVITY) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001169 rx_switch_to_interrupt_mode();
1170 break;
Jeff Hugo949080a2011-08-30 11:58:56 -06001171 }
1172
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001173 if (bam_adaptive_timer_enabled) {
1174 usleep_range(rx_timer_interval, rx_timer_interval + 50);
1175
1176 ret = sps_get_unused_desc_num(bam_rx_pipe,
1177 &buffs_unused);
1178
1179 if (ret) {
1180 pr_err("%s: error getting num buffers unused after sleep\n",
1181 __func__);
1182
1183 break;
1184 }
1185
1186 buffs_used = NUM_BUFFERS - buffs_unused;
1187
1188 if (buffs_unused == 0) {
1189 rx_timer_interval = MIN_POLLING_SLEEP;
1190 } else {
1191 if (buffs_used > 0) {
1192 rx_timer_interval =
1193 (2 * NUM_BUFFERS *
1194 rx_timer_interval)/
1195 (3 * buffs_used);
1196 } else {
1197 rx_timer_interval =
1198 MAX_POLLING_SLEEP;
1199 }
1200 }
1201
1202 if (rx_timer_interval > MAX_POLLING_SLEEP)
1203 rx_timer_interval = MAX_POLLING_SLEEP;
1204 else if (rx_timer_interval < MIN_POLLING_SLEEP)
1205 rx_timer_interval = MIN_POLLING_SLEEP;
1206 } else {
1207 usleep_range(POLLING_MIN_SLEEP, POLLING_MAX_SLEEP);
1208 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001209 }
1210}
1211
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001212static void bam_mux_tx_notify(struct sps_event_notify *notify)
1213{
1214 struct tx_pkt_info *pkt;
1215
1216 DBG("%s: event %d notified\n", __func__, notify->event_id);
1217
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001218 if (in_global_reset)
1219 return;
1220
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001221 switch (notify->event_id) {
1222 case SPS_EVENT_EOT:
1223 pkt = notify->data.transfer.user;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001224 if (!pkt->is_cmd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001225 dma_unmap_single(NULL, pkt->dma_address,
1226 pkt->skb->len,
1227 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001228 else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001229 dma_unmap_single(NULL, pkt->dma_address,
1230 pkt->len,
1231 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001232 queue_work(bam_mux_tx_workqueue, &pkt->work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001233 break;
1234 default:
1235 pr_err("%s: recieved unexpected event id %d\n", __func__,
1236 notify->event_id);
1237 }
1238}
1239
Jeff Hugo33dbc002011-08-25 15:52:53 -06001240static void bam_mux_rx_notify(struct sps_event_notify *notify)
1241{
Jeff Hugo949080a2011-08-30 11:58:56 -06001242 int ret;
1243 struct sps_connect cur_rx_conn;
Jeff Hugo33dbc002011-08-25 15:52:53 -06001244
1245 DBG("%s: event %d notified\n", __func__, notify->event_id);
1246
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001247 if (in_global_reset)
1248 return;
1249
Jeff Hugo33dbc002011-08-25 15:52:53 -06001250 switch (notify->event_id) {
1251 case SPS_EVENT_EOT:
Jeff Hugo949080a2011-08-30 11:58:56 -06001252 /* attempt to disable interrupts in this pipe */
1253 if (!polling_mode) {
1254 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1255 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001256 pr_err("%s: sps_get_config() failed %d, interrupts"
1257 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001258 break;
1259 }
Jeff Hugoa9d32ba2011-11-21 14:59:48 -07001260 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
Jeff Hugo949080a2011-08-30 11:58:56 -06001261 SPS_O_ACK_TRANSFERS | SPS_O_POLL;
1262 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1263 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001264 pr_err("%s: sps_set_config() failed %d, interrupts"
1265 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001266 break;
1267 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001268 grab_wakelock();
Jeff Hugo949080a2011-08-30 11:58:56 -06001269 polling_mode = 1;
Jeff Hugofff43af92012-03-29 17:54:52 -06001270 /*
1271 * run on core 0 so that netif_rx() in rmnet uses only
1272 * one queue
1273 */
1274 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Jeff Hugo949080a2011-08-30 11:58:56 -06001275 }
Jeff Hugo33dbc002011-08-25 15:52:53 -06001276 break;
1277 default:
1278 pr_err("%s: recieved unexpected event id %d\n", __func__,
1279 notify->event_id);
1280 }
1281}
1282
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001283#ifdef CONFIG_DEBUG_FS
1284
1285static int debug_tbl(char *buf, int max)
1286{
1287 int i = 0;
1288 int j;
1289
1290 for (j = 0; j < BAM_DMUX_NUM_CHANNELS; ++j) {
1291 i += scnprintf(buf + i, max - i,
1292 "ch%02d local open=%s remote open=%s\n",
1293 j, bam_ch_is_local_open(j) ? "Y" : "N",
1294 bam_ch_is_remote_open(j) ? "Y" : "N");
1295 }
1296
1297 return i;
1298}
1299
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001300static int debug_ul_pkt_cnt(char *buf, int max)
1301{
1302 struct list_head *p;
1303 unsigned long flags;
1304 int n = 0;
1305
1306 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
1307 __list_for_each(p, &bam_tx_pool) {
1308 ++n;
1309 }
1310 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
1311
1312 return scnprintf(buf, max, "Number of UL packets in flight: %d\n", n);
1313}
1314
1315static int debug_stats(char *buf, int max)
1316{
1317 int i = 0;
1318
1319 i += scnprintf(buf + i, max - i,
Eric Holmberg9fdef262012-02-14 11:46:05 -07001320 "skb read cnt: %u\n"
1321 "skb write cnt: %u\n"
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001322 "skb copy cnt: %u\n"
1323 "skb copy bytes: %u\n"
Eric Holmberg6074aba2012-01-18 17:59:44 -07001324 "sps tx failures: %u\n"
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001325 "sps tx stalls: %u\n"
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001326 "rx queue len: %d\n"
1327 "a2 ack out cnt: %d\n"
1328 "a2 ack in cnt: %d\n"
1329 "a2 pwr cntl in: %d\n",
Eric Holmberg9fdef262012-02-14 11:46:05 -07001330 bam_dmux_read_cnt,
1331 bam_dmux_write_cnt,
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001332 bam_dmux_write_cpy_cnt,
1333 bam_dmux_write_cpy_bytes,
Eric Holmberg6074aba2012-01-18 17:59:44 -07001334 bam_dmux_tx_sps_failure_cnt,
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001335 bam_dmux_tx_stall_cnt,
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001336 bam_rx_pool_len,
1337 atomic_read(&bam_dmux_ack_out_cnt),
1338 atomic_read(&bam_dmux_ack_in_cnt),
1339 atomic_read(&bam_dmux_a2_pwr_cntl_in_cnt)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001340 );
1341
1342 return i;
1343}
1344
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001345#define DEBUG_BUFMAX 4096
1346static char debug_buffer[DEBUG_BUFMAX];
1347
1348static ssize_t debug_read(struct file *file, char __user *buf,
1349 size_t count, loff_t *ppos)
1350{
1351 int (*fill)(char *buf, int max) = file->private_data;
1352 int bsize = fill(debug_buffer, DEBUG_BUFMAX);
1353 return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
1354}
1355
1356static int debug_open(struct inode *inode, struct file *file)
1357{
1358 file->private_data = inode->i_private;
1359 return 0;
1360}
1361
1362
1363static const struct file_operations debug_ops = {
1364 .read = debug_read,
1365 .open = debug_open,
1366};
1367
1368static void debug_create(const char *name, mode_t mode,
1369 struct dentry *dent,
1370 int (*fill)(char *buf, int max))
1371{
Eric Holmberge4ac80b2012-01-12 09:21:59 -07001372 struct dentry *file;
1373
1374 file = debugfs_create_file(name, mode, dent, fill, &debug_ops);
1375 if (IS_ERR(file))
1376 pr_err("%s: debugfs create failed %d\n", __func__,
1377 (int)PTR_ERR(file));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001378}
1379
1380#endif
1381
Jeff Hugod98b1082011-10-24 10:30:23 -06001382static void notify_all(int event, unsigned long data)
1383{
1384 int i;
Jeff Hugocb798022012-04-09 14:55:40 -06001385 struct list_head *temp;
1386 struct outside_notify_func *func;
Jeff Hugod98b1082011-10-24 10:30:23 -06001387
1388 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
Eric Holmberg454d9da2012-01-12 09:37:14 -07001389 if (bam_ch_is_open(i)) {
Jeff Hugod98b1082011-10-24 10:30:23 -06001390 bam_ch[i].notify(bam_ch[i].priv, event, data);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301391 BAM_DMUX_LOG("%s: cid=%d, event=%d, data=%lu\n",
Eric Holmberg454d9da2012-01-12 09:37:14 -07001392 __func__, i, event, data);
1393 }
Jeff Hugod98b1082011-10-24 10:30:23 -06001394 }
Jeff Hugocb798022012-04-09 14:55:40 -06001395
1396 __list_for_each(temp, &bam_other_notify_funcs) {
1397 func = container_of(temp, struct outside_notify_func,
1398 list_node);
1399 func->notify(func->priv, event, data);
1400 }
Jeff Hugod98b1082011-10-24 10:30:23 -06001401}
1402
1403static void kickoff_ul_wakeup_func(struct work_struct *work)
1404{
1405 read_lock(&ul_wakeup_lock);
1406 if (!bam_is_connected) {
1407 read_unlock(&ul_wakeup_lock);
1408 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -07001409 if (unlikely(in_global_reset == 1))
1410 return;
Jeff Hugod98b1082011-10-24 10:30:23 -06001411 read_lock(&ul_wakeup_lock);
1412 ul_packet_written = 1;
1413 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
1414 }
1415 read_unlock(&ul_wakeup_lock);
1416}
1417
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001418int msm_bam_dmux_kickoff_ul_wakeup(void)
Jeff Hugod98b1082011-10-24 10:30:23 -06001419{
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001420 int is_connected;
1421
1422 read_lock(&ul_wakeup_lock);
1423 ul_packet_written = 1;
1424 is_connected = bam_is_connected;
1425 if (!is_connected)
1426 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1427 read_unlock(&ul_wakeup_lock);
1428
1429 return is_connected;
Jeff Hugod98b1082011-10-24 10:30:23 -06001430}
1431
Eric Holmberg878923a2012-01-10 14:28:19 -07001432static void power_vote(int vote)
1433{
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301434 BAM_DMUX_LOG("%s: curr=%d, vote=%d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -07001435 bam_dmux_uplink_vote, vote);
1436
1437 if (bam_dmux_uplink_vote == vote)
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301438 BAM_DMUX_LOG("%s: warning - duplicate power vote\n", __func__);
Eric Holmberg878923a2012-01-10 14:28:19 -07001439
1440 bam_dmux_uplink_vote = vote;
1441 if (vote)
1442 smsm_change_state(SMSM_APPS_STATE, 0, SMSM_A2_POWER_CONTROL);
1443 else
1444 smsm_change_state(SMSM_APPS_STATE, SMSM_A2_POWER_CONTROL, 0);
1445}
1446
Eric Holmberg454d9da2012-01-12 09:37:14 -07001447/*
1448 * @note: Must be called with ul_wakeup_lock locked.
1449 */
1450static inline void ul_powerdown(void)
1451{
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301452 BAM_DMUX_LOG("%s: powerdown\n", __func__);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001453 verify_tx_queue_is_empty(__func__);
1454
1455 if (a2_pc_disabled) {
1456 wait_for_dfab = 1;
1457 INIT_COMPLETION(dfab_unvote_completion);
1458 release_wakelock();
1459 } else {
1460 wait_for_ack = 1;
1461 INIT_COMPLETION(ul_wakeup_ack_completion);
1462 power_vote(0);
1463 }
1464 bam_is_connected = 0;
1465 notify_all(BAM_DMUX_UL_DISCONNECTED, (unsigned long)(NULL));
1466}
1467
1468static inline void ul_powerdown_finish(void)
1469{
1470 if (a2_pc_disabled && wait_for_dfab) {
1471 unvote_dfab();
1472 complete_all(&dfab_unvote_completion);
1473 wait_for_dfab = 0;
1474 }
1475}
1476
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001477/*
1478 * Votes for UL power and returns current power state.
1479 *
1480 * @returns true if currently connected
1481 */
1482int msm_bam_dmux_ul_power_vote(void)
1483{
1484 int is_connected;
1485
1486 read_lock(&ul_wakeup_lock);
1487 atomic_inc(&ul_ondemand_vote);
1488 is_connected = bam_is_connected;
1489 if (!is_connected)
1490 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1491 read_unlock(&ul_wakeup_lock);
1492
1493 return is_connected;
1494}
1495
1496/*
1497 * Unvotes for UL power.
1498 *
1499 * @returns true if vote count is 0 (UL shutdown possible)
1500 */
1501int msm_bam_dmux_ul_power_unvote(void)
1502{
1503 int vote;
1504
1505 read_lock(&ul_wakeup_lock);
1506 vote = atomic_dec_return(&ul_ondemand_vote);
1507 if (unlikely(vote) < 0)
1508 DMUX_LOG_KERR("%s: invalid power vote %d\n", __func__, vote);
1509 read_unlock(&ul_wakeup_lock);
1510
1511 return vote == 0;
1512}
1513
Jeff Hugocb798022012-04-09 14:55:40 -06001514int msm_bam_dmux_reg_notify(void *priv,
1515 void (*notify)(void *priv, int event_type,
1516 unsigned long data))
1517{
1518 struct outside_notify_func *func;
1519
1520 if (!notify)
1521 return -EINVAL;
1522
1523 func = kmalloc(sizeof(struct outside_notify_func), GFP_KERNEL);
1524 if (!func)
1525 return -ENOMEM;
1526
1527 func->notify = notify;
1528 func->priv = priv;
1529 list_add(&func->list_node, &bam_other_notify_funcs);
1530
1531 return 0;
1532}
1533
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001534static void ul_timeout(struct work_struct *work)
1535{
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001536 unsigned long flags;
1537 int ret;
1538
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001539 if (in_global_reset)
1540 return;
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001541 ret = write_trylock_irqsave(&ul_wakeup_lock, flags);
1542 if (!ret) { /* failed to grab lock, reschedule and bail */
1543 schedule_delayed_work(&ul_timeout_work,
1544 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1545 return;
1546 }
Eric Holmberg454d9da2012-01-12 09:37:14 -07001547 if (bam_is_connected) {
Eric Holmberg6074aba2012-01-18 17:59:44 -07001548 if (!ul_packet_written) {
1549 spin_lock(&bam_tx_pool_spinlock);
1550 if (!list_empty(&bam_tx_pool)) {
1551 struct tx_pkt_info *info;
1552
1553 info = list_first_entry(&bam_tx_pool,
1554 struct tx_pkt_info, list_node);
1555 DMUX_LOG_KERR("%s: UL delayed ts=%u.%09lu\n",
1556 __func__, info->ts_sec, info->ts_nsec);
1557 DBG_INC_TX_STALL_CNT();
1558 ul_packet_written = 1;
1559 }
1560 spin_unlock(&bam_tx_pool_spinlock);
1561 }
1562
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001563 if (ul_packet_written || atomic_read(&ul_ondemand_vote)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301564 BAM_DMUX_LOG("%s: pkt written %d\n",
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001565 __func__, ul_packet_written);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001566 ul_packet_written = 0;
1567 schedule_delayed_work(&ul_timeout_work,
1568 msecs_to_jiffies(UL_TIMEOUT_DELAY));
Eric Holmberg006057d2012-01-11 10:10:42 -07001569 } else {
Eric Holmberg454d9da2012-01-12 09:37:14 -07001570 ul_powerdown();
Eric Holmberg006057d2012-01-11 10:10:42 -07001571 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001572 }
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001573 write_unlock_irqrestore(&ul_wakeup_lock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001574 ul_powerdown_finish();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001575}
Jeff Hugo4838f412012-01-20 11:19:37 -07001576
1577static int ssrestart_check(void)
1578{
Jeff Hugob8156d72013-06-04 12:51:10 -06001579 int ret = 0;
1580
1581 DMUX_LOG_KERR("%s: modem timeout: BAM DMUX disabled for SSR\n",
1582 __func__);
Eric Holmberg90285e22012-02-22 12:33:05 -07001583 in_global_reset = 1;
Jeff Hugob8156d72013-06-04 12:51:10 -06001584 ret = subsystem_restart("modem");
1585 if (ret == -ENODEV)
1586 panic("modem subsystem restart failed\n");
Eric Holmberg90285e22012-02-22 12:33:05 -07001587 return 1;
Jeff Hugo4838f412012-01-20 11:19:37 -07001588}
1589
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001590static void ul_wakeup(void)
1591{
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001592 int ret;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001593 int do_vote_dfab = 0;
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001594
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001595 mutex_lock(&wakeup_lock);
1596 if (bam_is_connected) { /* bam got connected before lock grabbed */
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301597 BAM_DMUX_LOG("%s Already awake\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001598 mutex_unlock(&wakeup_lock);
1599 return;
1600 }
Eric Holmberg878923a2012-01-10 14:28:19 -07001601
Jeff Hugoc2696142012-05-03 11:42:13 -06001602 /*
Jeff Hugof5001732012-08-27 13:19:09 -06001603 * if this gets hit, that means restart_notifier_cb() has started
1604 * but probably not finished, thus we know SSR has happened, but
1605 * haven't been able to send that info to our clients yet.
1606 * in that case, abort the ul_wakeup() so that we don't undo any
1607 * work restart_notifier_cb() has done. The clients will be notified
1608 * shortly. No cleanup necessary (reschedule the wakeup) as our and
1609 * their SSR handling will cover it
1610 */
1611 if (unlikely(in_global_reset == 1)) {
1612 mutex_unlock(&wakeup_lock);
1613 return;
1614 }
1615
1616 /*
Jeff Hugoc2696142012-05-03 11:42:13 -06001617 * if someone is voting for UL before bam is inited (modem up first
1618 * time), set flag for init to kickoff ul wakeup once bam is inited
1619 */
1620 mutex_lock(&delayed_ul_vote_lock);
1621 if (unlikely(!bam_mux_initialized)) {
1622 need_delayed_ul_vote = 1;
1623 mutex_unlock(&delayed_ul_vote_lock);
1624 mutex_unlock(&wakeup_lock);
1625 return;
1626 }
1627 mutex_unlock(&delayed_ul_vote_lock);
1628
Eric Holmberg006057d2012-01-11 10:10:42 -07001629 if (a2_pc_disabled) {
1630 /*
1631 * don't grab the wakelock the first time because it is
1632 * already grabbed when a2 powers on
1633 */
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001634 if (likely(a2_pc_disabled_wakelock_skipped)) {
Eric Holmberg006057d2012-01-11 10:10:42 -07001635 grab_wakelock();
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001636 do_vote_dfab = 1; /* vote must occur after wait */
1637 } else {
Jeff Hugo583a6da2012-02-03 11:37:30 -07001638 a2_pc_disabled_wakelock_skipped = 1;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001639 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001640 if (wait_for_dfab) {
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001641 ret = wait_for_completion_timeout(
Eric Holmberg006057d2012-01-11 10:10:42 -07001642 &dfab_unvote_completion, HZ);
1643 BUG_ON(ret == 0);
1644 }
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001645 if (likely(do_vote_dfab))
1646 vote_dfab();
Eric Holmberg006057d2012-01-11 10:10:42 -07001647 schedule_delayed_work(&ul_timeout_work,
1648 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1649 bam_is_connected = 1;
1650 mutex_unlock(&wakeup_lock);
1651 return;
1652 }
1653
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001654 /*
1655 * must wait for the previous power down request to have been acked
1656 * chances are it already came in and this will just fall through
1657 * instead of waiting
1658 */
1659 if (wait_for_ack) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301660 BAM_DMUX_LOG("%s waiting for previous ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001661 ret = wait_for_completion_timeout(
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001662 &ul_wakeup_ack_completion, HZ);
Eric Holmberg006057d2012-01-11 10:10:42 -07001663 wait_for_ack = 0;
Jeff Hugo4838f412012-01-20 11:19:37 -07001664 if (unlikely(ret == 0) && ssrestart_check()) {
1665 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301666 BAM_DMUX_LOG("%s timeout previous ack\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001667 return;
1668 }
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001669 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001670 INIT_COMPLETION(ul_wakeup_ack_completion);
Eric Holmberg878923a2012-01-10 14:28:19 -07001671 power_vote(1);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301672 BAM_DMUX_LOG("%s waiting for wakeup ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001673 ret = wait_for_completion_timeout(&ul_wakeup_ack_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001674 if (unlikely(ret == 0) && ssrestart_check()) {
1675 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301676 BAM_DMUX_LOG("%s timeout wakeup ack\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001677 return;
1678 }
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301679 BAM_DMUX_LOG("%s waiting completion\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001680 ret = wait_for_completion_timeout(&bam_connection_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001681 if (unlikely(ret == 0) && ssrestart_check()) {
1682 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301683 BAM_DMUX_LOG("%s timeout power on\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001684 return;
1685 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001686
1687 bam_is_connected = 1;
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301688 BAM_DMUX_LOG("%s complete\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001689 schedule_delayed_work(&ul_timeout_work,
1690 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1691 mutex_unlock(&wakeup_lock);
1692}
1693
1694static void reconnect_to_bam(void)
1695{
1696 int i;
1697
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001698 in_global_reset = 0;
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001699 in_ssr = 0;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001700 vote_dfab();
Jeff Hugo18792a32012-06-20 15:25:55 -06001701 if (!power_management_only_mode) {
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001702 if (ssr_skipped_disconnect) {
1703 /* delayed to here to prevent bus stall */
1704 sps_disconnect(bam_tx_pipe);
1705 sps_disconnect(bam_rx_pipe);
1706 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1707 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
1708 }
1709 ssr_skipped_disconnect = 0;
Jeff Hugo18792a32012-06-20 15:25:55 -06001710 i = sps_device_reset(a2_device_handle);
1711 if (i)
1712 pr_err("%s: device reset failed rc = %d\n", __func__,
1713 i);
1714 i = sps_connect(bam_tx_pipe, &tx_connection);
1715 if (i)
1716 pr_err("%s: tx connection failed rc = %d\n", __func__,
1717 i);
1718 i = sps_connect(bam_rx_pipe, &rx_connection);
1719 if (i)
1720 pr_err("%s: rx connection failed rc = %d\n", __func__,
1721 i);
1722 i = sps_register_event(bam_tx_pipe, &tx_register_event);
1723 if (i)
1724 pr_err("%s: tx event reg failed rc = %d\n", __func__,
1725 i);
1726 i = sps_register_event(bam_rx_pipe, &rx_register_event);
1727 if (i)
1728 pr_err("%s: rx event reg failed rc = %d\n", __func__,
1729 i);
1730 }
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001731
1732 bam_connection_is_active = 1;
1733
1734 if (polling_mode)
1735 rx_switch_to_interrupt_mode();
1736
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001737 toggle_apps_ack();
1738 complete_all(&bam_connection_completion);
Jeff Hugo18792a32012-06-20 15:25:55 -06001739 if (!power_management_only_mode)
1740 queue_rx();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001741}
1742
1743static void disconnect_to_bam(void)
1744{
1745 struct list_head *node;
1746 struct rx_pkt_info *info;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001747 unsigned long flags;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001748
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001749 bam_connection_is_active = 0;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001750
1751 /* handle disconnect during active UL */
1752 write_lock_irqsave(&ul_wakeup_lock, flags);
1753 if (bam_is_connected) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301754 BAM_DMUX_LOG("%s: UL active - forcing powerdown\n", __func__);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001755 ul_powerdown();
1756 }
1757 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1758 ul_powerdown_finish();
1759
1760 /* tear down BAM connection */
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001761 INIT_COMPLETION(bam_connection_completion);
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001762
1763 /* in_ssr documentation/assumptions found in restart_notifier_cb */
Jeff Hugo18792a32012-06-20 15:25:55 -06001764 if (!power_management_only_mode) {
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001765 if (likely(!in_ssr)) {
1766 sps_disconnect(bam_tx_pipe);
1767 sps_disconnect(bam_rx_pipe);
1768 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1769 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
1770 sps_device_reset(a2_device_handle);
1771 } else {
1772 ssr_skipped_disconnect = 1;
1773 }
Jeff Hugo18792a32012-06-20 15:25:55 -06001774 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001775 unvote_dfab();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001776
1777 mutex_lock(&bam_rx_pool_mutexlock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001778 while (!list_empty(&bam_rx_pool)) {
1779 node = bam_rx_pool.next;
1780 list_del(node);
1781 info = container_of(node, struct rx_pkt_info, list_node);
1782 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
1783 DMA_FROM_DEVICE);
1784 dev_kfree_skb_any(info->skb);
1785 kfree(info);
1786 }
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001787 bam_rx_pool_len = 0;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001788 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmberg878923a2012-01-10 14:28:19 -07001789
Jeff Hugo0b13a352012-03-17 23:18:30 -06001790 if (disconnect_ack)
1791 toggle_apps_ack();
1792
Eric Holmberg878923a2012-01-10 14:28:19 -07001793 verify_tx_queue_is_empty(__func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001794}
1795
1796static void vote_dfab(void)
1797{
Jeff Hugoca0caa82011-12-05 16:05:23 -07001798 int rc;
1799
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301800 BAM_DMUX_LOG("%s\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001801 mutex_lock(&dfab_status_lock);
1802 if (dfab_is_on) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301803 BAM_DMUX_LOG("%s: dfab is already on\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001804 mutex_unlock(&dfab_status_lock);
1805 return;
1806 }
Jeff Hugod0befde2012-08-09 15:32:49 -06001807 if (dfab_clk) {
1808 rc = clk_prepare_enable(dfab_clk);
1809 if (rc)
1810 DMUX_LOG_KERR("bam_dmux vote for dfab failed rc = %d\n",
1811 rc);
1812 }
1813 if (xo_clk) {
1814 rc = clk_prepare_enable(xo_clk);
1815 if (rc)
1816 DMUX_LOG_KERR("bam_dmux vote for xo failed rc = %d\n",
1817 rc);
1818 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001819 dfab_is_on = 1;
1820 mutex_unlock(&dfab_status_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001821}
1822
1823static void unvote_dfab(void)
1824{
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301825 BAM_DMUX_LOG("%s\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001826 mutex_lock(&dfab_status_lock);
1827 if (!dfab_is_on) {
1828 DMUX_LOG_KERR("%s: dfab is already off\n", __func__);
1829 dump_stack();
1830 mutex_unlock(&dfab_status_lock);
1831 return;
1832 }
Jeff Hugod0befde2012-08-09 15:32:49 -06001833 if (dfab_clk)
1834 clk_disable_unprepare(dfab_clk);
1835 if (xo_clk)
1836 clk_disable_unprepare(xo_clk);
Eric Holmberg006057d2012-01-11 10:10:42 -07001837 dfab_is_on = 0;
1838 mutex_unlock(&dfab_status_lock);
1839}
1840
1841/* reference counting wrapper around wakelock */
1842static void grab_wakelock(void)
1843{
1844 unsigned long flags;
1845
1846 spin_lock_irqsave(&wakelock_reference_lock, flags);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301847 BAM_DMUX_LOG("%s: ref count = %d\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -07001848 wakelock_reference_count);
1849 if (wakelock_reference_count == 0)
1850 wake_lock(&bam_wakelock);
1851 ++wakelock_reference_count;
1852 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1853}
1854
1855static void release_wakelock(void)
1856{
1857 unsigned long flags;
1858
1859 spin_lock_irqsave(&wakelock_reference_lock, flags);
1860 if (wakelock_reference_count == 0) {
1861 DMUX_LOG_KERR("%s: bam_dmux wakelock not locked\n", __func__);
1862 dump_stack();
1863 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1864 return;
1865 }
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301866 BAM_DMUX_LOG("%s: ref count = %d\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -07001867 wakelock_reference_count);
1868 --wakelock_reference_count;
1869 if (wakelock_reference_count == 0)
1870 wake_unlock(&bam_wakelock);
1871 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001872}
1873
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001874static int restart_notifier_cb(struct notifier_block *this,
1875 unsigned long code,
1876 void *data)
1877{
1878 int i;
1879 struct list_head *node;
1880 struct tx_pkt_info *info;
1881 int temp_remote_status;
Jeff Hugo626303bf2011-11-21 11:43:28 -07001882 unsigned long flags;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001883
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001884 /*
1885 * Bam_dmux counts on the fact that the BEFORE_SHUTDOWN level of
1886 * notifications are guarenteed to execute before the AFTER_SHUTDOWN
1887 * level of notifications, and that BEFORE_SHUTDOWN always occurs in
1888 * all SSR events, no matter what triggered the SSR. Also, bam_dmux
1889 * assumes that SMD does its SSR processing in the AFTER_SHUTDOWN level
1890 * thus bam_dmux is guarenteed to detect SSR before SMD, since the
1891 * callbacks for all the drivers within the AFTER_SHUTDOWN level could
1892 * occur in any order. Bam_dmux uses this knowledge to skip accessing
1893 * the bam hardware when disconnect_to_bam() is triggered by SMD's SSR
1894 * processing. We do not wat to access the bam hardware during SSR
1895 * because a watchdog crash from a bus stall would likely occur.
1896 */
Jeff Hugo199294b2013-02-25 13:46:56 -07001897 if (code == SUBSYS_BEFORE_SHUTDOWN) {
1898 in_global_reset = 1;
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001899 in_ssr = 1;
Zaheerulla Meerf800bba2013-02-13 15:49:14 +05301900 BAM_DMUX_LOG("%s: begin\n", __func__);
Jeff Hugo199294b2013-02-25 13:46:56 -07001901 flush_workqueue(bam_mux_rx_workqueue);
1902 }
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001903 if (code != SUBSYS_AFTER_SHUTDOWN)
1904 return NOTIFY_DONE;
1905
Eric Holmberg454d9da2012-01-12 09:37:14 -07001906 /* Handle uplink Powerdown */
1907 write_lock_irqsave(&ul_wakeup_lock, flags);
1908 if (bam_is_connected) {
1909 ul_powerdown();
1910 wait_for_ack = 0;
1911 }
Jeff Hugo4838f412012-01-20 11:19:37 -07001912 /*
1913 * if modem crash during ul_wakeup(), power_vote is 1, needs to be
1914 * reset to 0. harmless if bam_is_connected check above passes
1915 */
1916 power_vote(0);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001917 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1918 ul_powerdown_finish();
Eric Holmberg006057d2012-01-11 10:10:42 -07001919 a2_pc_disabled = 0;
Jeff Hugo583a6da2012-02-03 11:37:30 -07001920 a2_pc_disabled_wakelock_skipped = 0;
Jeff Hugof62029d2012-07-17 13:39:53 -06001921 disconnect_ack = 1;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001922
1923 /* Cleanup Channel States */
Eric Holmberga623da82012-07-12 09:37:09 -06001924 mutex_lock(&bam_pdev_mutexlock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001925 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
1926 temp_remote_status = bam_ch_is_remote_open(i);
1927 bam_ch[i].status &= ~BAM_CH_REMOTE_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001928 bam_ch[i].num_tx_pkts = 0;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001929 if (bam_ch_is_local_open(i))
1930 bam_ch[i].status |= BAM_CH_IN_RESET;
1931 if (temp_remote_status) {
1932 platform_device_unregister(bam_ch[i].pdev);
1933 bam_ch[i].pdev = platform_device_alloc(
1934 bam_ch[i].name, 2);
1935 }
1936 }
Eric Holmberga623da82012-07-12 09:37:09 -06001937 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001938
1939 /* Cleanup pending UL data */
Jeff Hugo626303bf2011-11-21 11:43:28 -07001940 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001941 while (!list_empty(&bam_tx_pool)) {
1942 node = bam_tx_pool.next;
1943 list_del(node);
1944 info = container_of(node, struct tx_pkt_info,
1945 list_node);
1946 if (!info->is_cmd) {
1947 dma_unmap_single(NULL, info->dma_address,
1948 info->skb->len,
1949 DMA_TO_DEVICE);
1950 dev_kfree_skb_any(info->skb);
1951 } else {
1952 dma_unmap_single(NULL, info->dma_address,
1953 info->len,
1954 DMA_TO_DEVICE);
1955 kfree(info->skb);
1956 }
1957 kfree(info);
1958 }
Jeff Hugo626303bf2011-11-21 11:43:28 -07001959 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001960
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301961 BAM_DMUX_LOG("%s: complete\n", __func__);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001962 return NOTIFY_DONE;
1963}
1964
Jeff Hugo9dea05c2011-12-21 12:23:05 -07001965static int bam_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001966{
1967 u32 h;
1968 dma_addr_t dma_addr;
1969 int ret;
1970 void *a2_virt_addr;
Jeff Hugo4b2890d2012-01-16 16:14:21 -07001971 int skip_iounmap = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001972
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001973 vote_dfab();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001974 /* init BAM */
Jeff Hugo3910ee12012-08-21 14:08:20 -06001975 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
1976 a2_phys_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001977 if (!a2_virt_addr) {
1978 pr_err("%s: ioremap failed\n", __func__);
1979 ret = -ENOMEM;
Jeff Hugo994a92d2012-01-05 13:25:21 -07001980 goto ioremap_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001981 }
Jeff Hugo3910ee12012-08-21 14:08:20 -06001982 a2_props.phys_addr = (u32)(a2_phys_base);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001983 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo3910ee12012-08-21 14:08:20 -06001984 a2_props.virt_size = a2_phys_size;
1985 a2_props.irq = a2_bam_irq;
Jeff Hugo927cba62011-11-11 11:49:52 -07001986 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001987 a2_props.num_pipes = A2_NUM_PIPES;
1988 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
Jeff Hugo75913c82011-12-05 15:59:01 -07001989 if (cpu_is_msm9615())
1990 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001991 /* need to free on tear down */
1992 ret = sps_register_bam_device(&a2_props, &h);
1993 if (ret < 0) {
1994 pr_err("%s: register bam error %d\n", __func__, ret);
1995 goto register_bam_failed;
1996 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001997 a2_device_handle = h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001998
1999 bam_tx_pipe = sps_alloc_endpoint();
2000 if (bam_tx_pipe == NULL) {
2001 pr_err("%s: tx alloc endpoint failed\n", __func__);
2002 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002003 goto tx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002004 }
2005 ret = sps_get_config(bam_tx_pipe, &tx_connection);
2006 if (ret) {
2007 pr_err("%s: tx get config failed %d\n", __func__, ret);
2008 goto tx_get_config_failed;
2009 }
2010
2011 tx_connection.source = SPS_DEV_HANDLE_MEM;
2012 tx_connection.src_pipe_index = 0;
2013 tx_connection.destination = h;
2014 tx_connection.dest_pipe_index = 4;
2015 tx_connection.mode = SPS_MODE_DEST;
2016 tx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT;
2017 tx_desc_mem_buf.size = 0x800; /* 2k */
2018 tx_desc_mem_buf.base = dma_alloc_coherent(NULL, tx_desc_mem_buf.size,
2019 &dma_addr, 0);
2020 if (tx_desc_mem_buf.base == NULL) {
2021 pr_err("%s: tx memory alloc failed\n", __func__);
2022 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002023 goto tx_get_config_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002024 }
2025 tx_desc_mem_buf.phys_base = dma_addr;
2026 memset(tx_desc_mem_buf.base, 0x0, tx_desc_mem_buf.size);
2027 tx_connection.desc = tx_desc_mem_buf;
2028 tx_connection.event_thresh = 0x10;
2029
2030 ret = sps_connect(bam_tx_pipe, &tx_connection);
2031 if (ret < 0) {
2032 pr_err("%s: tx connect error %d\n", __func__, ret);
2033 goto tx_connect_failed;
2034 }
2035
2036 bam_rx_pipe = sps_alloc_endpoint();
2037 if (bam_rx_pipe == NULL) {
2038 pr_err("%s: rx alloc endpoint failed\n", __func__);
2039 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002040 goto rx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002041 }
2042 ret = sps_get_config(bam_rx_pipe, &rx_connection);
2043 if (ret) {
2044 pr_err("%s: rx get config failed %d\n", __func__, ret);
2045 goto rx_get_config_failed;
2046 }
2047
2048 rx_connection.source = h;
2049 rx_connection.src_pipe_index = 5;
2050 rx_connection.destination = SPS_DEV_HANDLE_MEM;
2051 rx_connection.dest_pipe_index = 1;
2052 rx_connection.mode = SPS_MODE_SRC;
Jeff Hugo949080a2011-08-30 11:58:56 -06002053 rx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT |
2054 SPS_O_ACK_TRANSFERS;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002055 rx_desc_mem_buf.size = 0x800; /* 2k */
2056 rx_desc_mem_buf.base = dma_alloc_coherent(NULL, rx_desc_mem_buf.size,
2057 &dma_addr, 0);
2058 if (rx_desc_mem_buf.base == NULL) {
2059 pr_err("%s: rx memory alloc failed\n", __func__);
2060 ret = -ENOMEM;
2061 goto rx_mem_failed;
2062 }
2063 rx_desc_mem_buf.phys_base = dma_addr;
2064 memset(rx_desc_mem_buf.base, 0x0, rx_desc_mem_buf.size);
2065 rx_connection.desc = rx_desc_mem_buf;
2066 rx_connection.event_thresh = 0x10;
2067
2068 ret = sps_connect(bam_rx_pipe, &rx_connection);
2069 if (ret < 0) {
2070 pr_err("%s: rx connect error %d\n", __func__, ret);
2071 goto rx_connect_failed;
2072 }
2073
2074 tx_register_event.options = SPS_O_EOT;
2075 tx_register_event.mode = SPS_TRIGGER_CALLBACK;
2076 tx_register_event.xfer_done = NULL;
2077 tx_register_event.callback = bam_mux_tx_notify;
2078 tx_register_event.user = NULL;
2079 ret = sps_register_event(bam_tx_pipe, &tx_register_event);
2080 if (ret < 0) {
2081 pr_err("%s: tx register event error %d\n", __func__, ret);
2082 goto rx_event_reg_failed;
2083 }
2084
Jeff Hugo33dbc002011-08-25 15:52:53 -06002085 rx_register_event.options = SPS_O_EOT;
2086 rx_register_event.mode = SPS_TRIGGER_CALLBACK;
2087 rx_register_event.xfer_done = NULL;
2088 rx_register_event.callback = bam_mux_rx_notify;
2089 rx_register_event.user = NULL;
2090 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
2091 if (ret < 0) {
2092 pr_err("%s: tx register event error %d\n", __func__, ret);
2093 goto rx_event_reg_failed;
2094 }
2095
Jeff Hugoc2696142012-05-03 11:42:13 -06002096 mutex_lock(&delayed_ul_vote_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002097 bam_mux_initialized = 1;
Jeff Hugoc2696142012-05-03 11:42:13 -06002098 if (need_delayed_ul_vote) {
2099 need_delayed_ul_vote = 0;
2100 msm_bam_dmux_kickoff_ul_wakeup();
2101 }
2102 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002103 toggle_apps_ack();
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002104 bam_connection_is_active = 1;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002105 complete_all(&bam_connection_completion);
Jeff Hugo2fb555e2012-03-14 16:33:47 -06002106 queue_rx();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002107 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002108
2109rx_event_reg_failed:
2110 sps_disconnect(bam_rx_pipe);
2111rx_connect_failed:
2112 dma_free_coherent(NULL, rx_desc_mem_buf.size, rx_desc_mem_buf.base,
2113 rx_desc_mem_buf.phys_base);
2114rx_mem_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002115rx_get_config_failed:
2116 sps_free_endpoint(bam_rx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002117rx_alloc_endpoint_failed:
2118 sps_disconnect(bam_tx_pipe);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002119tx_connect_failed:
2120 dma_free_coherent(NULL, tx_desc_mem_buf.size, tx_desc_mem_buf.base,
2121 tx_desc_mem_buf.phys_base);
2122tx_get_config_failed:
2123 sps_free_endpoint(bam_tx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002124tx_alloc_endpoint_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002125 sps_deregister_bam_device(h);
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002126 /*
2127 * sps_deregister_bam_device() calls iounmap. calling iounmap on the
2128 * same handle below will cause a crash, so skip it if we've freed
2129 * the handle here.
2130 */
2131 skip_iounmap = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002132register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002133 if (!skip_iounmap)
2134 iounmap(a2_virt_addr);
Jeff Hugo994a92d2012-01-05 13:25:21 -07002135ioremap_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002136 /*destroy_workqueue(bam_mux_workqueue);*/
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002137 return ret;
2138}
2139
2140static int bam_init_fallback(void)
2141{
2142 u32 h;
2143 int ret;
2144 void *a2_virt_addr;
2145
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002146 /* init BAM */
Jeff Hugo3910ee12012-08-21 14:08:20 -06002147 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
2148 a2_phys_size);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002149 if (!a2_virt_addr) {
2150 pr_err("%s: ioremap failed\n", __func__);
2151 ret = -ENOMEM;
2152 goto ioremap_failed;
2153 }
Jeff Hugo3910ee12012-08-21 14:08:20 -06002154 a2_props.phys_addr = (u32)(a2_phys_base);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002155 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo3910ee12012-08-21 14:08:20 -06002156 a2_props.virt_size = a2_phys_size;
2157 a2_props.irq = a2_bam_irq;
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002158 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
2159 a2_props.num_pipes = A2_NUM_PIPES;
2160 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
2161 if (cpu_is_msm9615())
2162 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
2163 ret = sps_register_bam_device(&a2_props, &h);
2164 if (ret < 0) {
2165 pr_err("%s: register bam error %d\n", __func__, ret);
2166 goto register_bam_failed;
2167 }
2168 a2_device_handle = h;
Jeff Hugoc2696142012-05-03 11:42:13 -06002169
2170 mutex_lock(&delayed_ul_vote_lock);
2171 bam_mux_initialized = 1;
2172 if (need_delayed_ul_vote) {
2173 need_delayed_ul_vote = 0;
2174 msm_bam_dmux_kickoff_ul_wakeup();
2175 }
2176 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugo2bec9772012-04-05 12:25:16 -06002177 toggle_apps_ack();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002178
Jeff Hugo18792a32012-06-20 15:25:55 -06002179 power_management_only_mode = 1;
2180 bam_connection_is_active = 1;
2181 complete_all(&bam_connection_completion);
2182
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002183 return 0;
2184
2185register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002186 iounmap(a2_virt_addr);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002187ioremap_failed:
2188 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002189}
Jeff Hugoade1f842011-08-03 15:53:59 -06002190
Jeff Hugoa670b762012-03-15 15:58:28 -06002191static void msm9615_bam_init(void)
Eric Holmberg604ab252012-01-15 00:01:18 -07002192{
2193 int ret = 0;
2194
2195 ret = bam_init();
2196 if (ret) {
2197 ret = bam_init_fallback();
2198 if (ret)
2199 pr_err("%s: bam init fallback failed: %d",
2200 __func__, ret);
2201 }
2202}
2203
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002204static void toggle_apps_ack(void)
2205{
2206 static unsigned int clear_bit; /* 0 = set the bit, else clear bit */
Eric Holmberg878923a2012-01-10 14:28:19 -07002207
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302208 BAM_DMUX_LOG("%s: apps ack %d->%d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -07002209 clear_bit & 0x1, ~clear_bit & 0x1);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002210 smsm_change_state(SMSM_APPS_STATE,
2211 clear_bit & SMSM_A2_POWER_CONTROL_ACK,
2212 ~clear_bit & SMSM_A2_POWER_CONTROL_ACK);
2213 clear_bit = ~clear_bit;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002214 DBG_INC_ACK_OUT_CNT();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002215}
2216
Jeff Hugoade1f842011-08-03 15:53:59 -06002217static void bam_dmux_smsm_cb(void *priv, uint32_t old_state, uint32_t new_state)
2218{
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002219 static int last_processed_state;
2220
2221 mutex_lock(&smsm_cb_lock);
Eric Holmberg878923a2012-01-10 14:28:19 -07002222 bam_dmux_power_state = new_state & SMSM_A2_POWER_CONTROL ? 1 : 0;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002223 DBG_INC_A2_POWER_CONTROL_IN_CNT();
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302224 BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
Eric Holmberg878923a2012-01-10 14:28:19 -07002225 new_state);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002226 if (last_processed_state == (new_state & SMSM_A2_POWER_CONTROL)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302227 BAM_DMUX_LOG("%s: already processed this state\n", __func__);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002228 mutex_unlock(&smsm_cb_lock);
2229 return;
2230 }
2231
2232 last_processed_state = new_state & SMSM_A2_POWER_CONTROL;
Eric Holmberg878923a2012-01-10 14:28:19 -07002233
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002234 if (bam_mux_initialized && new_state & SMSM_A2_POWER_CONTROL) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302235 BAM_DMUX_LOG("%s: reconnect\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002236 grab_wakelock();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002237 reconnect_to_bam();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002238 } else if (bam_mux_initialized &&
2239 !(new_state & SMSM_A2_POWER_CONTROL)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302240 BAM_DMUX_LOG("%s: disconnect\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002241 disconnect_to_bam();
Eric Holmberg006057d2012-01-11 10:10:42 -07002242 release_wakelock();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002243 } else if (new_state & SMSM_A2_POWER_CONTROL) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302244 BAM_DMUX_LOG("%s: init\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002245 grab_wakelock();
Jeff Hugoa670b762012-03-15 15:58:28 -06002246 if (cpu_is_msm9615())
2247 msm9615_bam_init();
2248 else
Eric Holmberg604ab252012-01-15 00:01:18 -07002249 bam_init();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002250 } else {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302251 BAM_DMUX_LOG("%s: bad state change\n", __func__);
Jeff Hugoade1f842011-08-03 15:53:59 -06002252 pr_err("%s: unsupported state change\n", __func__);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002253 }
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002254 mutex_unlock(&smsm_cb_lock);
Jeff Hugoade1f842011-08-03 15:53:59 -06002255
2256}
2257
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002258static void bam_dmux_smsm_ack_cb(void *priv, uint32_t old_state,
2259 uint32_t new_state)
2260{
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002261 DBG_INC_ACK_IN_CNT();
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302262 BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
Eric Holmberg878923a2012-01-10 14:28:19 -07002263 new_state);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002264 complete_all(&ul_wakeup_ack_completion);
2265}
2266
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002267static int bam_dmux_probe(struct platform_device *pdev)
2268{
2269 int rc;
Jeff Hugo3910ee12012-08-21 14:08:20 -06002270 struct resource *r;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002271
2272 DBG("%s probe called\n", __func__);
2273 if (bam_mux_initialized)
2274 return 0;
2275
Jeff Hugo3910ee12012-08-21 14:08:20 -06002276 if (pdev->dev.of_node) {
2277 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2278 if (!r) {
2279 pr_err("%s: reg field missing\n", __func__);
2280 return -ENODEV;
2281 }
2282 a2_phys_base = (void *)(r->start);
2283 a2_phys_size = (uint32_t)(resource_size(r));
2284 a2_bam_irq = platform_get_irq(pdev, 0);
2285 if (a2_bam_irq == -ENXIO) {
2286 pr_err("%s: irq field missing\n", __func__);
2287 return -ENODEV;
2288 }
2289 DBG("%s: base:%p size:%x irq:%d\n", __func__,
2290 a2_phys_base,
2291 a2_phys_size,
2292 a2_bam_irq);
2293 } else { /* fallback to default init data */
2294 a2_phys_base = (void *)(A2_PHYS_BASE);
2295 a2_phys_size = A2_PHYS_SIZE;
2296 a2_bam_irq = A2_BAM_IRQ;
2297 }
2298
Stephen Boyd69d35e32012-02-14 15:33:30 -08002299 xo_clk = clk_get(&pdev->dev, "xo");
2300 if (IS_ERR(xo_clk)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302301 BAM_DMUX_LOG("%s: did not get xo clock\n", __func__);
Jeff Hugod0befde2012-08-09 15:32:49 -06002302 xo_clk = NULL;
Stephen Boyd69d35e32012-02-14 15:33:30 -08002303 }
Stephen Boyd1c51a492011-10-26 12:11:47 -07002304 dfab_clk = clk_get(&pdev->dev, "bus_clk");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002305 if (IS_ERR(dfab_clk)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302306 BAM_DMUX_LOG("%s: did not get dfab clock\n", __func__);
Jeff Hugod0befde2012-08-09 15:32:49 -06002307 dfab_clk = NULL;
2308 } else {
2309 rc = clk_set_rate(dfab_clk, 64000000);
2310 if (rc)
2311 pr_err("%s: unable to set dfab clock rate\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002312 }
2313
Jeff Hugofff43af92012-03-29 17:54:52 -06002314 /*
2315 * setup the workqueue so that it can be pinned to core 0 and not
2316 * block the watchdog pet function, so that netif_rx() in rmnet
2317 * only uses one queue.
2318 */
2319 bam_mux_rx_workqueue = alloc_workqueue("bam_dmux_rx",
2320 WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002321 if (!bam_mux_rx_workqueue)
2322 return -ENOMEM;
2323
2324 bam_mux_tx_workqueue = create_singlethread_workqueue("bam_dmux_tx");
2325 if (!bam_mux_tx_workqueue) {
2326 destroy_workqueue(bam_mux_rx_workqueue);
2327 return -ENOMEM;
2328 }
2329
Jeff Hugo7960abd2011-08-02 15:39:38 -06002330 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002331 spin_lock_init(&bam_ch[rc].lock);
Jeff Hugo7960abd2011-08-02 15:39:38 -06002332 scnprintf(bam_ch[rc].name, BAM_DMUX_CH_NAME_MAX_LEN,
2333 "bam_dmux_ch_%d", rc);
2334 /* bus 2, ie a2 stream 2 */
2335 bam_ch[rc].pdev = platform_device_alloc(bam_ch[rc].name, 2);
2336 if (!bam_ch[rc].pdev) {
2337 pr_err("%s: platform device alloc failed\n", __func__);
2338 destroy_workqueue(bam_mux_rx_workqueue);
2339 destroy_workqueue(bam_mux_tx_workqueue);
2340 return -ENOMEM;
2341 }
2342 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002343
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002344 init_completion(&ul_wakeup_ack_completion);
2345 init_completion(&bam_connection_completion);
Eric Holmberg006057d2012-01-11 10:10:42 -07002346 init_completion(&dfab_unvote_completion);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002347 INIT_DELAYED_WORK(&ul_timeout_work, ul_timeout);
Jeff Hugo988e7ba2012-10-03 15:53:54 -06002348 INIT_DELAYED_WORK(&queue_rx_work, queue_rx_work_func);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002349 wake_lock_init(&bam_wakelock, WAKE_LOCK_SUSPEND, "bam_dmux_wakelock");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002350
Jeff Hugoade1f842011-08-03 15:53:59 -06002351 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL,
2352 bam_dmux_smsm_cb, NULL);
2353
2354 if (rc) {
2355 destroy_workqueue(bam_mux_rx_workqueue);
2356 destroy_workqueue(bam_mux_tx_workqueue);
2357 pr_err("%s: smsm cb register failed, rc: %d\n", __func__, rc);
2358 return -ENOMEM;
2359 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002360
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002361 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL_ACK,
2362 bam_dmux_smsm_ack_cb, NULL);
2363
2364 if (rc) {
2365 destroy_workqueue(bam_mux_rx_workqueue);
2366 destroy_workqueue(bam_mux_tx_workqueue);
2367 smsm_state_cb_deregister(SMSM_MODEM_STATE,
2368 SMSM_A2_POWER_CONTROL,
2369 bam_dmux_smsm_cb, NULL);
2370 pr_err("%s: smsm ack cb register failed, rc: %d\n", __func__,
2371 rc);
2372 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc)
2373 platform_device_put(bam_ch[rc].pdev);
2374 return -ENOMEM;
2375 }
2376
Eric Holmbergfd1e2ae2011-11-15 18:28:17 -07002377 if (smsm_get_state(SMSM_MODEM_STATE) & SMSM_A2_POWER_CONTROL)
2378 bam_dmux_smsm_cb(NULL, 0, smsm_get_state(SMSM_MODEM_STATE));
2379
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002380 return 0;
2381}
2382
Jeff Hugo3910ee12012-08-21 14:08:20 -06002383static struct of_device_id msm_match_table[] = {
2384 {.compatible = "qcom,bam_dmux"},
2385 {},
2386};
2387
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002388static struct platform_driver bam_dmux_driver = {
2389 .probe = bam_dmux_probe,
2390 .driver = {
2391 .name = "BAM_RMNT",
2392 .owner = THIS_MODULE,
Jeff Hugo3910ee12012-08-21 14:08:20 -06002393 .of_match_table = msm_match_table,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002394 },
2395};
2396
2397static int __init bam_dmux_init(void)
2398{
2399#ifdef CONFIG_DEBUG_FS
2400 struct dentry *dent;
2401
2402 dent = debugfs_create_dir("bam_dmux", 0);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002403 if (!IS_ERR(dent)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002404 debug_create("tbl", 0444, dent, debug_tbl);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002405 debug_create("ul_pkt_cnt", 0444, dent, debug_ul_pkt_cnt);
2406 debug_create("stats", 0444, dent, debug_stats);
2407 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002408#endif
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302409
2410 bam_ipc_log_txt = ipc_log_context_create(BAM_IPC_LOG_PAGES, "bam_dmux");
2411 if (!bam_ipc_log_txt) {
2412 pr_err("%s : unable to create IPC Logging Context", __func__);
Eric Holmberg878923a2012-01-10 14:28:19 -07002413 }
2414
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07002415 rx_timer_interval = DEFAULT_POLLING_MIN_SLEEP;
2416
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002417 subsys_notif_register_notifier("modem", &restart_notifier);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002418 return platform_driver_register(&bam_dmux_driver);
2419}
2420
Jeff Hugoade1f842011-08-03 15:53:59 -06002421late_initcall(bam_dmux_init); /* needs to init after SMD */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002422MODULE_DESCRIPTION("MSM BAM DMUX");
2423MODULE_LICENSE("GPL v2");