blob: ee7647f455435cbf3379194d474a1713e2e8c6d0 [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
309
310#define DMUX_LOG_KERR(fmt...) \
311do { \
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530312 BAM_DMUX_LOG(fmt); \
Eric Holmberg878923a2012-01-10 14:28:19 -0700313 pr_err(fmt); \
314} while (0)
315
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530316static void *bam_ipc_log_txt;
317
318#define BAM_IPC_LOG_PAGES 5
319
Eric Holmberg878923a2012-01-10 14:28:19 -0700320/**
321 * Log a state change along with a small message.
Eric Holmberg878923a2012-01-10 14:28:19 -0700322 * Complete size of messsage is limited to @todo.
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530323 * Logging is done using IPC Logging infrastructure.
324 *
325 * States
326 * D: 1 = Power collapse disabled
327 * R: 1 = in global reset
328 * P: 1 = BAM is powered up
329 * A: 1 = BAM initialized and ready for data
330 * V: 1 = Uplink vote for power
331 * U: 1 = Uplink active
332 * W: 1 = Uplink Wait-for-ack
333 * A: 1 = Uplink ACK received
334 * #: >=1 On-demand uplink vote
335 * D: 1 = Disconnect ACK active
Eric Holmberg878923a2012-01-10 14:28:19 -0700336 */
Eric Holmberg878923a2012-01-10 14:28:19 -0700337
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530338#define BAM_DMUX_LOG(fmt, args...) \
339do { \
340 if (bam_ipc_log_txt) { \
341 ipc_log_string(bam_ipc_log_txt, \
342 "<DMUX> %c%c%c%c %c%c%c%c%d%c " fmt, \
343 a2_pc_disabled ? 'D' : 'd', \
344 in_global_reset ? 'R' : 'r', \
345 bam_dmux_power_state ? 'P' : 'p', \
346 bam_connection_is_active ? 'A' : 'a', \
347 bam_dmux_uplink_vote ? 'V' : 'v', \
348 bam_is_connected ? 'U' : 'u', \
349 wait_for_ack ? 'W' : 'w', \
350 ul_wakeup_ack_completion.done ? 'A' : 'a', \
351 atomic_read(&ul_ondemand_vote), \
352 disconnect_ack ? 'D' : 'd', \
353 args); \
354 } \
355} while (0)
Eric Holmberg878923a2012-01-10 14:28:19 -0700356
357static inline void set_tx_timestamp(struct tx_pkt_info *pkt)
358{
359 unsigned long long t_now;
360
361 t_now = sched_clock();
362 pkt->ts_nsec = do_div(t_now, 1000000000U);
363 pkt->ts_sec = (unsigned)t_now;
364}
365
366static inline void verify_tx_queue_is_empty(const char *func)
367{
368 unsigned long flags;
369 struct tx_pkt_info *info;
370 int reported = 0;
371
372 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
373 list_for_each_entry(info, &bam_tx_pool, list_node) {
374 if (!reported) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530375 BAM_DMUX_LOG("%s: tx pool not empty\n", func);
Eric Holmberg454d9da2012-01-12 09:37:14 -0700376 if (!in_global_reset)
377 pr_err("%s: tx pool not empty\n", func);
Eric Holmberg878923a2012-01-10 14:28:19 -0700378 reported = 1;
379 }
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530380 BAM_DMUX_LOG("%s: node=%p ts=%u.%09lu\n", __func__,
Eric Holmberg454d9da2012-01-12 09:37:14 -0700381 &info->list_node, info->ts_sec, info->ts_nsec);
382 if (!in_global_reset)
383 pr_err("%s: node=%p ts=%u.%09lu\n", __func__,
384 &info->list_node, info->ts_sec, info->ts_nsec);
Eric Holmberg878923a2012-01-10 14:28:19 -0700385 }
386 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
387}
388
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700389static void queue_rx(void)
390{
391 void *ptr;
392 struct rx_pkt_info *info;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700393 int ret;
394 int rx_len_cached;
Jeff Hugo949080a2011-08-30 11:58:56 -0600395
Jeff Hugoc9749932011-11-02 17:50:40 -0600396 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700397 rx_len_cached = bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -0600398 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -0600399
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600400 while (bam_connection_is_active && rx_len_cached < NUM_BUFFERS) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700401 if (in_global_reset)
402 goto fail;
403
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600404 info = kmalloc(sizeof(struct rx_pkt_info),
405 GFP_NOWAIT | __GFP_NOWARN);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700406 if (!info) {
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600407 DMUX_LOG_KERR(
408 "%s: unable to alloc rx_pkt_info, will retry later\n",
409 __func__);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700410 goto fail;
411 }
412
413 INIT_WORK(&info->work, handle_bam_mux_cmd);
414
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600415 info->skb = __dev_alloc_skb(BUFFER_SIZE,
416 GFP_NOWAIT | __GFP_NOWARN);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700417 if (info->skb == NULL) {
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600418 DMUX_LOG_KERR(
419 "%s: unable to alloc skb, will retry later\n",
420 __func__);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700421 goto fail_info;
422 }
423 ptr = skb_put(info->skb, BUFFER_SIZE);
424
425 info->dma_address = dma_map_single(NULL, ptr, BUFFER_SIZE,
426 DMA_FROM_DEVICE);
427 if (info->dma_address == 0 || info->dma_address == ~0) {
428 DMUX_LOG_KERR("%s: dma_map_single failure %p for %p\n",
429 __func__, (void *)info->dma_address, ptr);
430 goto fail_skb;
431 }
432
433 mutex_lock(&bam_rx_pool_mutexlock);
434 list_add_tail(&info->list_node, &bam_rx_pool);
435 rx_len_cached = ++bam_rx_pool_len;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700436 ret = sps_transfer_one(bam_rx_pipe, info->dma_address,
437 BUFFER_SIZE, info,
438 SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700439 if (ret) {
Eric Holmberg00cf8692012-07-16 14:21:19 -0600440 list_del(&info->list_node);
441 rx_len_cached = --bam_rx_pool_len;
442 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700443 DMUX_LOG_KERR("%s: sps_transfer_one failed %d\n",
444 __func__, ret);
Eric Holmberg00cf8692012-07-16 14:21:19 -0600445
446 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
447 DMA_FROM_DEVICE);
448
449 goto fail_skb;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700450 }
Eric Holmberg00cf8692012-07-16 14:21:19 -0600451 mutex_unlock(&bam_rx_pool_mutexlock);
452
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700453 }
454 return;
455
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700456fail_skb:
457 dev_kfree_skb_any(info->skb);
458
459fail_info:
460 kfree(info);
461
462fail:
Arun Kumar Neelakantam799447f2012-12-13 18:06:49 +0530463 if (rx_len_cached == 0 && !in_global_reset) {
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600464 DMUX_LOG_KERR("%s: rescheduling\n", __func__);
465 schedule_delayed_work(&queue_rx_work, msecs_to_jiffies(100));
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700466 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700467}
468
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600469static void queue_rx_work_func(struct work_struct *work)
470{
471 queue_rx();
472}
473
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700474static void bam_mux_process_data(struct sk_buff *rx_skb)
475{
476 unsigned long flags;
477 struct bam_mux_hdr *rx_hdr;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600478 unsigned long event_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700479
480 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
481
482 rx_skb->data = (unsigned char *)(rx_hdr + 1);
483 rx_skb->tail = rx_skb->data + rx_hdr->pkt_len;
484 rx_skb->len = rx_hdr->pkt_len;
Jeff Hugoee88f672011-10-04 17:14:52 -0600485 rx_skb->truesize = rx_hdr->pkt_len + sizeof(struct sk_buff);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700486
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600487 event_data = (unsigned long)(rx_skb);
488
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700489 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600490 if (bam_ch[rx_hdr->ch_id].notify)
491 bam_ch[rx_hdr->ch_id].notify(
492 bam_ch[rx_hdr->ch_id].priv, BAM_DMUX_RECEIVE,
493 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700494 else
495 dev_kfree_skb_any(rx_skb);
496 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
497
498 queue_rx();
499}
500
Eric Holmberg006057d2012-01-11 10:10:42 -0700501static inline void handle_bam_mux_cmd_open(struct bam_mux_hdr *rx_hdr)
502{
503 unsigned long flags;
504 int ret;
505
Eric Holmberga623da82012-07-12 09:37:09 -0600506 mutex_lock(&bam_pdev_mutexlock);
507 if (in_global_reset) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530508 BAM_DMUX_LOG("%s: open cid %d aborted due to ssr\n",
Eric Holmberga623da82012-07-12 09:37:09 -0600509 __func__, rx_hdr->ch_id);
510 mutex_unlock(&bam_pdev_mutexlock);
511 queue_rx();
512 return;
513 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700514 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
515 bam_ch[rx_hdr->ch_id].status |= BAM_CH_REMOTE_OPEN;
516 bam_ch[rx_hdr->ch_id].num_tx_pkts = 0;
517 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Eric Holmberg006057d2012-01-11 10:10:42 -0700518 ret = platform_device_add(bam_ch[rx_hdr->ch_id].pdev);
519 if (ret)
520 pr_err("%s: platform_device_add() error: %d\n",
521 __func__, ret);
Eric Holmberga623da82012-07-12 09:37:09 -0600522 mutex_unlock(&bam_pdev_mutexlock);
523 queue_rx();
Eric Holmberg006057d2012-01-11 10:10:42 -0700524}
525
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700526static void handle_bam_mux_cmd(struct work_struct *work)
527{
528 unsigned long flags;
529 struct bam_mux_hdr *rx_hdr;
530 struct rx_pkt_info *info;
531 struct sk_buff *rx_skb;
532
533 info = container_of(work, struct rx_pkt_info, work);
534 rx_skb = info->skb;
Jeff Hugo949080a2011-08-30 11:58:56 -0600535 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE, DMA_FROM_DEVICE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700536 kfree(info);
537
538 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
539
540 DBG_INC_READ_CNT(sizeof(struct bam_mux_hdr));
541 DBG("%s: magic %x reserved %d cmd %d pad %d ch %d len %d\n", __func__,
542 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
543 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
544 if (rx_hdr->magic_num != BAM_MUX_HDR_MAGIC_NO) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700545 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
546 " reserved %d cmd %d"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700547 " pad %d ch %d len %d\n", __func__,
548 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
549 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
550 dev_kfree_skb_any(rx_skb);
551 queue_rx();
552 return;
553 }
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700554
555 if (rx_hdr->ch_id >= BAM_DMUX_NUM_CHANNELS) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700556 DMUX_LOG_KERR("%s: dropping invalid LCID %d"
557 " reserved %d cmd %d"
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700558 " pad %d ch %d len %d\n", __func__,
559 rx_hdr->ch_id, rx_hdr->reserved, rx_hdr->cmd,
560 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
561 dev_kfree_skb_any(rx_skb);
562 queue_rx();
563 return;
564 }
565
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700566 switch (rx_hdr->cmd) {
567 case BAM_MUX_HDR_CMD_DATA:
568 DBG_INC_READ_CNT(rx_hdr->pkt_len);
569 bam_mux_process_data(rx_skb);
570 break;
571 case BAM_MUX_HDR_CMD_OPEN:
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530572 BAM_DMUX_LOG("%s: opening cid %d PC enabled\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700573 rx_hdr->ch_id);
Eric Holmberg006057d2012-01-11 10:10:42 -0700574 handle_bam_mux_cmd_open(rx_hdr);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600575 if (!(rx_hdr->reserved & ENABLE_DISCONNECT_ACK)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530576 BAM_DMUX_LOG("%s: deactivating disconnect ack\n",
Jeff Hugod7d2b062012-07-24 14:29:56 -0600577 __func__);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600578 disconnect_ack = 0;
Jeff Hugo0b13a352012-03-17 23:18:30 -0600579 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700580 dev_kfree_skb_any(rx_skb);
581 break;
582 case BAM_MUX_HDR_CMD_OPEN_NO_A2_PC:
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530583 BAM_DMUX_LOG("%s: opening cid %d PC disabled\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -0700584 rx_hdr->ch_id);
585
586 if (!a2_pc_disabled) {
587 a2_pc_disabled = 1;
Jeff Hugo322179f2012-02-29 10:52:34 -0700588 ul_wakeup();
Eric Holmberg006057d2012-01-11 10:10:42 -0700589 }
590
591 handle_bam_mux_cmd_open(rx_hdr);
Eric Holmberge779dba2011-11-04 18:22:01 -0600592 dev_kfree_skb_any(rx_skb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700593 break;
594 case BAM_MUX_HDR_CMD_CLOSE:
595 /* probably should drop pending write */
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530596 BAM_DMUX_LOG("%s: closing cid %d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700597 rx_hdr->ch_id);
Eric Holmberga623da82012-07-12 09:37:09 -0600598 mutex_lock(&bam_pdev_mutexlock);
599 if (in_global_reset) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530600 BAM_DMUX_LOG("%s: close cid %d aborted due to ssr\n",
Eric Holmberga623da82012-07-12 09:37:09 -0600601 __func__, rx_hdr->ch_id);
602 mutex_unlock(&bam_pdev_mutexlock);
603 break;
604 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700605 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
606 bam_ch[rx_hdr->ch_id].status &= ~BAM_CH_REMOTE_OPEN;
607 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo7960abd2011-08-02 15:39:38 -0600608 platform_device_unregister(bam_ch[rx_hdr->ch_id].pdev);
609 bam_ch[rx_hdr->ch_id].pdev =
610 platform_device_alloc(bam_ch[rx_hdr->ch_id].name, 2);
611 if (!bam_ch[rx_hdr->ch_id].pdev)
612 pr_err("%s: platform_device_alloc failed\n", __func__);
Eric Holmberga623da82012-07-12 09:37:09 -0600613 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberge779dba2011-11-04 18:22:01 -0600614 dev_kfree_skb_any(rx_skb);
Eric Holmberga623da82012-07-12 09:37:09 -0600615 queue_rx();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700616 break;
617 default:
Eric Holmberg878923a2012-01-10 14:28:19 -0700618 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
619 " reserved %d cmd %d pad %d ch %d len %d\n",
620 __func__, rx_hdr->magic_num, rx_hdr->reserved,
621 rx_hdr->cmd, rx_hdr->pad_len, rx_hdr->ch_id,
622 rx_hdr->pkt_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700623 dev_kfree_skb_any(rx_skb);
624 queue_rx();
625 return;
626 }
627}
628
629static int bam_mux_write_cmd(void *data, uint32_t len)
630{
631 int rc;
632 struct tx_pkt_info *pkt;
633 dma_addr_t dma_address;
Jeff Hugo626303bf2011-11-21 11:43:28 -0700634 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700635
Eric Holmbergd83cd2b2011-11-04 15:54:17 -0600636 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700637 if (pkt == NULL) {
638 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
639 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700640 return rc;
641 }
642
643 dma_address = dma_map_single(NULL, data, len,
644 DMA_TO_DEVICE);
645 if (!dma_address) {
646 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugo96cb7482011-12-07 13:28:31 -0700647 kfree(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700648 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700649 return rc;
650 }
651 pkt->skb = (struct sk_buff *)(data);
652 pkt->len = len;
653 pkt->dma_address = dma_address;
654 pkt->is_cmd = 1;
Eric Holmberg878923a2012-01-10 14:28:19 -0700655 set_tx_timestamp(pkt);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600656 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700657 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600658 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700659 rc = sps_transfer_one(bam_tx_pipe, dma_address, len,
660 pkt, SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600661 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700662 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
663 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600664 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700665 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700666 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700667 dma_unmap_single(NULL, pkt->dma_address,
668 pkt->len,
669 DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600670 kfree(pkt);
Jeff Hugobb6da952012-01-16 15:02:42 -0700671 } else {
672 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600673 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700674
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600675 ul_packet_written = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700676 return rc;
677}
678
679static void bam_mux_write_done(struct work_struct *work)
680{
681 struct sk_buff *skb;
682 struct bam_mux_hdr *hdr;
683 struct tx_pkt_info *info;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700684 struct tx_pkt_info *info_expected;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600685 unsigned long event_data;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700686 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700687
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600688 if (in_global_reset)
689 return;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700690
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700691 info = container_of(work, struct tx_pkt_info, work);
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700692
693 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
694 info_expected = list_first_entry(&bam_tx_pool,
695 struct tx_pkt_info, list_node);
696 if (unlikely(info != info_expected)) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700697 struct tx_pkt_info *errant_pkt;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700698
Eric Holmberg878923a2012-01-10 14:28:19 -0700699 DMUX_LOG_KERR("%s: bam_tx_pool mismatch .next=%p,"
700 " list_node=%p, ts=%u.%09lu\n",
701 __func__, bam_tx_pool.next, &info->list_node,
702 info->ts_sec, info->ts_nsec
703 );
704
705 list_for_each_entry(errant_pkt, &bam_tx_pool, list_node) {
706 DMUX_LOG_KERR("%s: node=%p ts=%u.%09lu\n", __func__,
707 &errant_pkt->list_node, errant_pkt->ts_sec,
708 errant_pkt->ts_nsec);
709
710 }
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700711 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
712 BUG();
713 }
714 list_del(&info->list_node);
715 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
716
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600717 if (info->is_cmd) {
718 kfree(info->skb);
719 kfree(info);
720 return;
721 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700722 skb = info->skb;
723 kfree(info);
724 hdr = (struct bam_mux_hdr *)skb->data;
Eric Holmberg9fdef262012-02-14 11:46:05 -0700725 DBG_INC_WRITE_CNT(skb->len);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600726 event_data = (unsigned long)(skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700727 spin_lock_irqsave(&bam_ch[hdr->ch_id].lock, flags);
728 bam_ch[hdr->ch_id].num_tx_pkts--;
729 spin_unlock_irqrestore(&bam_ch[hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600730 if (bam_ch[hdr->ch_id].notify)
731 bam_ch[hdr->ch_id].notify(
732 bam_ch[hdr->ch_id].priv, BAM_DMUX_WRITE_DONE,
733 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700734 else
735 dev_kfree_skb_any(skb);
736}
737
738int msm_bam_dmux_write(uint32_t id, struct sk_buff *skb)
739{
740 int rc = 0;
741 struct bam_mux_hdr *hdr;
742 unsigned long flags;
743 struct sk_buff *new_skb = NULL;
744 dma_addr_t dma_address;
745 struct tx_pkt_info *pkt;
746
747 if (id >= BAM_DMUX_NUM_CHANNELS)
748 return -EINVAL;
749 if (!skb)
750 return -EINVAL;
751 if (!bam_mux_initialized)
752 return -ENODEV;
753
754 DBG("%s: writing to ch %d len %d\n", __func__, id, skb->len);
755 spin_lock_irqsave(&bam_ch[id].lock, flags);
756 if (!bam_ch_is_open(id)) {
757 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
758 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
759 return -ENODEV;
760 }
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700761
762 if (bam_ch[id].use_wm &&
763 (bam_ch[id].num_tx_pkts >= HIGH_WATERMARK)) {
764 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
765 pr_err("%s: watermark exceeded: %d\n", __func__, id);
766 return -EAGAIN;
767 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700768 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
769
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600770 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600771 if (!bam_is_connected) {
772 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600773 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700774 if (unlikely(in_global_reset == 1))
775 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600776 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600777 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600778 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600779
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700780 /* if skb do not have any tailroom for padding,
781 copy the skb into a new expanded skb */
782 if ((skb->len & 0x3) && (skb_tailroom(skb) < (4 - (skb->len & 0x3)))) {
783 /* revisit, probably dev_alloc_skb and memcpy is effecient */
784 new_skb = skb_copy_expand(skb, skb_headroom(skb),
785 4 - (skb->len & 0x3), GFP_ATOMIC);
786 if (new_skb == NULL) {
787 pr_err("%s: cannot allocate skb\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600788 goto write_fail;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700789 }
790 dev_kfree_skb_any(skb);
791 skb = new_skb;
792 DBG_INC_WRITE_CPY(skb->len);
793 }
794
795 hdr = (struct bam_mux_hdr *)skb_push(skb, sizeof(struct bam_mux_hdr));
796
797 /* caller should allocate for hdr and padding
798 hdr is fine, padding is tricky */
799 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
800 hdr->cmd = BAM_MUX_HDR_CMD_DATA;
801 hdr->reserved = 0;
802 hdr->ch_id = id;
803 hdr->pkt_len = skb->len - sizeof(struct bam_mux_hdr);
804 if (skb->len & 0x3)
805 skb_put(skb, 4 - (skb->len & 0x3));
806
807 hdr->pad_len = skb->len - (sizeof(struct bam_mux_hdr) + hdr->pkt_len);
808
809 DBG("%s: data %p, tail %p skb len %d pkt len %d pad len %d\n",
810 __func__, skb->data, skb->tail, skb->len,
811 hdr->pkt_len, hdr->pad_len);
812
813 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
814 if (pkt == NULL) {
815 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600816 goto write_fail2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700817 }
818
819 dma_address = dma_map_single(NULL, skb->data, skb->len,
820 DMA_TO_DEVICE);
821 if (!dma_address) {
822 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600823 goto write_fail3;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700824 }
825 pkt->skb = skb;
826 pkt->dma_address = dma_address;
827 pkt->is_cmd = 0;
Eric Holmberg878923a2012-01-10 14:28:19 -0700828 set_tx_timestamp(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700829 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700830 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600831 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700832 rc = sps_transfer_one(bam_tx_pipe, dma_address, skb->len,
833 pkt, SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600834 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700835 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
836 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600837 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700838 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700839 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700840 dma_unmap_single(NULL, pkt->dma_address,
841 pkt->skb->len, DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600842 kfree(pkt);
Jeff Hugo872bd062011-11-15 17:47:21 -0700843 if (new_skb)
844 dev_kfree_skb_any(new_skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700845 } else {
Jeff Hugobb6da952012-01-16 15:02:42 -0700846 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700847 spin_lock_irqsave(&bam_ch[id].lock, flags);
848 bam_ch[id].num_tx_pkts++;
849 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600850 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600851 ul_packet_written = 1;
852 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700853 return rc;
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600854
855write_fail3:
856 kfree(pkt);
857write_fail2:
Arun Kumar Neelakantam406e5692013-01-17 18:58:04 +0530858 skb_pull(skb, sizeof(struct bam_mux_hdr));
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600859 if (new_skb)
860 dev_kfree_skb_any(new_skb);
861write_fail:
862 read_unlock(&ul_wakeup_lock);
863 return -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700864}
865
866int msm_bam_dmux_open(uint32_t id, void *priv,
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600867 void (*notify)(void *, int, unsigned long))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700868{
869 struct bam_mux_hdr *hdr;
870 unsigned long flags;
871 int rc = 0;
872
873 DBG("%s: opening ch %d\n", __func__, id);
Eric Holmberg5d775432011-11-09 10:23:35 -0700874 if (!bam_mux_initialized) {
875 DBG("%s: not inititialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700876 return -ENODEV;
Eric Holmberg5d775432011-11-09 10:23:35 -0700877 }
878 if (id >= BAM_DMUX_NUM_CHANNELS) {
879 pr_err("%s: invalid channel id %d\n", __func__, id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700880 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700881 }
882 if (notify == NULL) {
883 pr_err("%s: notify function is NULL\n", __func__);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600884 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700885 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700886
887 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_KERNEL);
888 if (hdr == NULL) {
889 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
890 return -ENOMEM;
891 }
892 spin_lock_irqsave(&bam_ch[id].lock, flags);
893 if (bam_ch_is_open(id)) {
894 DBG("%s: Already opened %d\n", __func__, id);
895 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
896 kfree(hdr);
897 goto open_done;
898 }
899 if (!bam_ch_is_remote_open(id)) {
900 DBG("%s: Remote not open; ch: %d\n", __func__, id);
901 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
902 kfree(hdr);
Eric Holmberg5d775432011-11-09 10:23:35 -0700903 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700904 }
905
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600906 bam_ch[id].notify = notify;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700907 bam_ch[id].priv = priv;
908 bam_ch[id].status |= BAM_CH_LOCAL_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700909 bam_ch[id].num_tx_pkts = 0;
910 bam_ch[id].use_wm = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700911 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
912
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600913 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600914 if (!bam_is_connected) {
915 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600916 ul_wakeup();
Brent Hronik96630422013-05-01 16:38:43 -0600917 if (unlikely(in_global_reset == 1)) {
918 kfree(hdr);
Jeff Hugo4838f412012-01-20 11:19:37 -0700919 return -EFAULT;
Brent Hronik96630422013-05-01 16:38:43 -0600920 }
Jeff Hugo061ce672011-10-21 17:15:32 -0600921 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600922 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600923 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600924
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700925 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
926 hdr->cmd = BAM_MUX_HDR_CMD_OPEN;
927 hdr->reserved = 0;
928 hdr->ch_id = id;
929 hdr->pkt_len = 0;
930 hdr->pad_len = 0;
931
932 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600933 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700934
935open_done:
936 DBG("%s: opened ch %d\n", __func__, id);
937 return rc;
938}
939
940int msm_bam_dmux_close(uint32_t id)
941{
942 struct bam_mux_hdr *hdr;
943 unsigned long flags;
944 int rc;
945
946 if (id >= BAM_DMUX_NUM_CHANNELS)
947 return -EINVAL;
948 DBG("%s: closing ch %d\n", __func__, id);
949 if (!bam_mux_initialized)
950 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700951
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600952 read_lock(&ul_wakeup_lock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600953 if (!bam_is_connected && !bam_ch_is_in_reset(id)) {
Jeff Hugo061ce672011-10-21 17:15:32 -0600954 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600955 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700956 if (unlikely(in_global_reset == 1))
957 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600958 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600959 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600960 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600961
Jeff Hugo061ce672011-10-21 17:15:32 -0600962 spin_lock_irqsave(&bam_ch[id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600963 bam_ch[id].notify = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700964 bam_ch[id].priv = NULL;
965 bam_ch[id].status &= ~BAM_CH_LOCAL_OPEN;
966 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
967
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600968 if (bam_ch_is_in_reset(id)) {
969 read_unlock(&ul_wakeup_lock);
970 bam_ch[id].status &= ~BAM_CH_IN_RESET;
971 return 0;
972 }
973
Jeff Hugobb5802f2011-11-02 17:10:29 -0600974 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700975 if (hdr == NULL) {
976 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600977 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700978 return -ENOMEM;
979 }
980 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
981 hdr->cmd = BAM_MUX_HDR_CMD_CLOSE;
982 hdr->reserved = 0;
983 hdr->ch_id = id;
984 hdr->pkt_len = 0;
985 hdr->pad_len = 0;
986
987 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600988 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700989
990 DBG("%s: closed ch %d\n", __func__, id);
991 return rc;
992}
993
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700994int msm_bam_dmux_is_ch_full(uint32_t id)
995{
996 unsigned long flags;
997 int ret;
998
999 if (id >= BAM_DMUX_NUM_CHANNELS)
1000 return -EINVAL;
1001
1002 spin_lock_irqsave(&bam_ch[id].lock, flags);
1003 bam_ch[id].use_wm = 1;
1004 ret = bam_ch[id].num_tx_pkts >= HIGH_WATERMARK;
1005 DBG("%s: ch %d num tx pkts=%d, HWM=%d\n", __func__,
1006 id, bam_ch[id].num_tx_pkts, ret);
1007 if (!bam_ch_is_local_open(id)) {
1008 ret = -ENODEV;
1009 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1010 }
1011 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
1012
1013 return ret;
1014}
1015
1016int msm_bam_dmux_is_ch_low(uint32_t id)
1017{
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001018 unsigned long flags;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001019 int ret;
1020
1021 if (id >= BAM_DMUX_NUM_CHANNELS)
1022 return -EINVAL;
1023
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001024 spin_lock_irqsave(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001025 bam_ch[id].use_wm = 1;
1026 ret = bam_ch[id].num_tx_pkts <= LOW_WATERMARK;
1027 DBG("%s: ch %d num tx pkts=%d, LWM=%d\n", __func__,
1028 id, bam_ch[id].num_tx_pkts, ret);
1029 if (!bam_ch_is_local_open(id)) {
1030 ret = -ENODEV;
1031 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1032 }
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001033 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001034
1035 return ret;
1036}
1037
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001038static void rx_switch_to_interrupt_mode(void)
1039{
1040 struct sps_connect cur_rx_conn;
1041 struct sps_iovec iov;
1042 struct rx_pkt_info *info;
1043 int ret;
1044
1045 /*
1046 * Attempt to enable interrupts - if this fails,
1047 * continue polling and we will retry later.
1048 */
1049 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1050 if (ret) {
1051 pr_err("%s: sps_get_config() failed %d\n", __func__, ret);
1052 goto fail;
1053 }
1054
1055 rx_register_event.options = SPS_O_EOT;
1056 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
1057 if (ret) {
1058 pr_err("%s: sps_register_event() failed %d\n", __func__, ret);
1059 goto fail;
1060 }
1061
1062 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
1063 SPS_O_EOT | SPS_O_ACK_TRANSFERS;
1064 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1065 if (ret) {
1066 pr_err("%s: sps_set_config() failed %d\n", __func__, ret);
1067 goto fail;
1068 }
1069 polling_mode = 0;
Eric Holmberg006057d2012-01-11 10:10:42 -07001070 release_wakelock();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001071
1072 /* handle any rx packets before interrupt was enabled */
1073 while (bam_connection_is_active && !polling_mode) {
1074 ret = sps_get_iovec(bam_rx_pipe, &iov);
1075 if (ret) {
1076 pr_err("%s: sps_get_iovec failed %d\n",
1077 __func__, ret);
1078 break;
1079 }
1080 if (iov.addr == 0)
1081 break;
1082
1083 mutex_lock(&bam_rx_pool_mutexlock);
1084 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001085 DMUX_LOG_KERR("%s: have iovec %p but rx pool empty\n",
1086 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001087 mutex_unlock(&bam_rx_pool_mutexlock);
1088 continue;
1089 }
1090 info = list_first_entry(&bam_rx_pool, struct rx_pkt_info,
1091 list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001092 if (info->dma_address != iov.addr) {
1093 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1094 __func__,
1095 (void *)iov.addr,
1096 (void *)info->dma_address);
1097 list_for_each_entry(info, &bam_rx_pool, list_node) {
1098 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1099 (void *)info->dma_address);
1100 if (iov.addr == info->dma_address)
1101 break;
1102 }
1103 }
1104 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001105 list_del(&info->list_node);
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001106 --bam_rx_pool_len;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001107 mutex_unlock(&bam_rx_pool_mutexlock);
1108 handle_bam_mux_cmd(&info->work);
1109 }
1110 return;
1111
1112fail:
1113 pr_err("%s: reverting to polling\n", __func__);
Jeff Hugofff43af92012-03-29 17:54:52 -06001114 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001115}
1116
Jeff Hugo949080a2011-08-30 11:58:56 -06001117static void rx_timer_work_func(struct work_struct *work)
1118{
1119 struct sps_iovec iov;
Jeff Hugo949080a2011-08-30 11:58:56 -06001120 struct rx_pkt_info *info;
1121 int inactive_cycles = 0;
1122 int ret;
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001123 u32 buffs_unused, buffs_used;
Jeff Hugo949080a2011-08-30 11:58:56 -06001124
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001125 while (bam_connection_is_active) { /* timer loop */
Jeff Hugo949080a2011-08-30 11:58:56 -06001126 ++inactive_cycles;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001127 while (bam_connection_is_active) { /* deplete queue loop */
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001128 if (in_global_reset)
1129 return;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001130
1131 ret = sps_get_iovec(bam_rx_pipe, &iov);
1132 if (ret) {
1133 pr_err("%s: sps_get_iovec failed %d\n",
1134 __func__, ret);
1135 break;
1136 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001137 if (iov.addr == 0)
1138 break;
1139 inactive_cycles = 0;
Jeff Hugoc9749932011-11-02 17:50:40 -06001140 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001141 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001142 DMUX_LOG_KERR(
1143 "%s: have iovec %p but rx pool empty\n",
1144 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001145 mutex_unlock(&bam_rx_pool_mutexlock);
1146 continue;
1147 }
1148 info = list_first_entry(&bam_rx_pool,
1149 struct rx_pkt_info, list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001150 if (info->dma_address != iov.addr) {
1151 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1152 __func__,
1153 (void *)iov.addr,
1154 (void *)info->dma_address);
1155 list_for_each_entry(info, &bam_rx_pool,
1156 list_node) {
1157 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1158 (void *)info->dma_address);
1159 if (iov.addr == info->dma_address)
1160 break;
1161 }
1162 }
1163 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001164 list_del(&info->list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001165 --bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -06001166 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -06001167 handle_bam_mux_cmd(&info->work);
1168 }
1169
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001170 if (inactive_cycles >= POLLING_INACTIVITY) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001171 rx_switch_to_interrupt_mode();
1172 break;
Jeff Hugo949080a2011-08-30 11:58:56 -06001173 }
1174
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001175 if (bam_adaptive_timer_enabled) {
1176 usleep_range(rx_timer_interval, rx_timer_interval + 50);
1177
1178 ret = sps_get_unused_desc_num(bam_rx_pipe,
1179 &buffs_unused);
1180
1181 if (ret) {
1182 pr_err("%s: error getting num buffers unused after sleep\n",
1183 __func__);
1184
1185 break;
1186 }
1187
1188 buffs_used = NUM_BUFFERS - buffs_unused;
1189
1190 if (buffs_unused == 0) {
1191 rx_timer_interval = MIN_POLLING_SLEEP;
1192 } else {
1193 if (buffs_used > 0) {
1194 rx_timer_interval =
1195 (2 * NUM_BUFFERS *
1196 rx_timer_interval)/
1197 (3 * buffs_used);
1198 } else {
1199 rx_timer_interval =
1200 MAX_POLLING_SLEEP;
1201 }
1202 }
1203
1204 if (rx_timer_interval > MAX_POLLING_SLEEP)
1205 rx_timer_interval = MAX_POLLING_SLEEP;
1206 else if (rx_timer_interval < MIN_POLLING_SLEEP)
1207 rx_timer_interval = MIN_POLLING_SLEEP;
1208 } else {
1209 usleep_range(POLLING_MIN_SLEEP, POLLING_MAX_SLEEP);
1210 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001211 }
1212}
1213
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001214static void bam_mux_tx_notify(struct sps_event_notify *notify)
1215{
1216 struct tx_pkt_info *pkt;
1217
1218 DBG("%s: event %d notified\n", __func__, notify->event_id);
1219
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001220 if (in_global_reset)
1221 return;
1222
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001223 switch (notify->event_id) {
1224 case SPS_EVENT_EOT:
1225 pkt = notify->data.transfer.user;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001226 if (!pkt->is_cmd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001227 dma_unmap_single(NULL, pkt->dma_address,
1228 pkt->skb->len,
1229 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001230 else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001231 dma_unmap_single(NULL, pkt->dma_address,
1232 pkt->len,
1233 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001234 queue_work(bam_mux_tx_workqueue, &pkt->work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001235 break;
1236 default:
1237 pr_err("%s: recieved unexpected event id %d\n", __func__,
1238 notify->event_id);
1239 }
1240}
1241
Jeff Hugo33dbc002011-08-25 15:52:53 -06001242static void bam_mux_rx_notify(struct sps_event_notify *notify)
1243{
Jeff Hugo949080a2011-08-30 11:58:56 -06001244 int ret;
1245 struct sps_connect cur_rx_conn;
Jeff Hugo33dbc002011-08-25 15:52:53 -06001246
1247 DBG("%s: event %d notified\n", __func__, notify->event_id);
1248
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001249 if (in_global_reset)
1250 return;
1251
Jeff Hugo33dbc002011-08-25 15:52:53 -06001252 switch (notify->event_id) {
1253 case SPS_EVENT_EOT:
Jeff Hugo949080a2011-08-30 11:58:56 -06001254 /* attempt to disable interrupts in this pipe */
1255 if (!polling_mode) {
1256 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1257 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001258 pr_err("%s: sps_get_config() failed %d, interrupts"
1259 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001260 break;
1261 }
Jeff Hugoa9d32ba2011-11-21 14:59:48 -07001262 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
Jeff Hugo949080a2011-08-30 11:58:56 -06001263 SPS_O_ACK_TRANSFERS | SPS_O_POLL;
1264 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1265 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001266 pr_err("%s: sps_set_config() failed %d, interrupts"
1267 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001268 break;
1269 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001270 grab_wakelock();
Jeff Hugo949080a2011-08-30 11:58:56 -06001271 polling_mode = 1;
Jeff Hugofff43af92012-03-29 17:54:52 -06001272 /*
1273 * run on core 0 so that netif_rx() in rmnet uses only
1274 * one queue
1275 */
1276 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Jeff Hugo949080a2011-08-30 11:58:56 -06001277 }
Jeff Hugo33dbc002011-08-25 15:52:53 -06001278 break;
1279 default:
1280 pr_err("%s: recieved unexpected event id %d\n", __func__,
1281 notify->event_id);
1282 }
1283}
1284
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001285#ifdef CONFIG_DEBUG_FS
1286
1287static int debug_tbl(char *buf, int max)
1288{
1289 int i = 0;
1290 int j;
1291
1292 for (j = 0; j < BAM_DMUX_NUM_CHANNELS; ++j) {
1293 i += scnprintf(buf + i, max - i,
1294 "ch%02d local open=%s remote open=%s\n",
1295 j, bam_ch_is_local_open(j) ? "Y" : "N",
1296 bam_ch_is_remote_open(j) ? "Y" : "N");
1297 }
1298
1299 return i;
1300}
1301
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001302static int debug_ul_pkt_cnt(char *buf, int max)
1303{
1304 struct list_head *p;
1305 unsigned long flags;
1306 int n = 0;
1307
1308 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
1309 __list_for_each(p, &bam_tx_pool) {
1310 ++n;
1311 }
1312 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
1313
1314 return scnprintf(buf, max, "Number of UL packets in flight: %d\n", n);
1315}
1316
1317static int debug_stats(char *buf, int max)
1318{
1319 int i = 0;
1320
1321 i += scnprintf(buf + i, max - i,
Eric Holmberg9fdef262012-02-14 11:46:05 -07001322 "skb read cnt: %u\n"
1323 "skb write cnt: %u\n"
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001324 "skb copy cnt: %u\n"
1325 "skb copy bytes: %u\n"
Eric Holmberg6074aba2012-01-18 17:59:44 -07001326 "sps tx failures: %u\n"
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001327 "sps tx stalls: %u\n"
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001328 "rx queue len: %d\n"
1329 "a2 ack out cnt: %d\n"
1330 "a2 ack in cnt: %d\n"
1331 "a2 pwr cntl in: %d\n",
Eric Holmberg9fdef262012-02-14 11:46:05 -07001332 bam_dmux_read_cnt,
1333 bam_dmux_write_cnt,
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001334 bam_dmux_write_cpy_cnt,
1335 bam_dmux_write_cpy_bytes,
Eric Holmberg6074aba2012-01-18 17:59:44 -07001336 bam_dmux_tx_sps_failure_cnt,
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001337 bam_dmux_tx_stall_cnt,
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001338 bam_rx_pool_len,
1339 atomic_read(&bam_dmux_ack_out_cnt),
1340 atomic_read(&bam_dmux_ack_in_cnt),
1341 atomic_read(&bam_dmux_a2_pwr_cntl_in_cnt)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001342 );
1343
1344 return i;
1345}
1346
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001347#define DEBUG_BUFMAX 4096
1348static char debug_buffer[DEBUG_BUFMAX];
1349
1350static ssize_t debug_read(struct file *file, char __user *buf,
1351 size_t count, loff_t *ppos)
1352{
1353 int (*fill)(char *buf, int max) = file->private_data;
1354 int bsize = fill(debug_buffer, DEBUG_BUFMAX);
1355 return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
1356}
1357
1358static int debug_open(struct inode *inode, struct file *file)
1359{
1360 file->private_data = inode->i_private;
1361 return 0;
1362}
1363
1364
1365static const struct file_operations debug_ops = {
1366 .read = debug_read,
1367 .open = debug_open,
1368};
1369
1370static void debug_create(const char *name, mode_t mode,
1371 struct dentry *dent,
1372 int (*fill)(char *buf, int max))
1373{
Eric Holmberge4ac80b2012-01-12 09:21:59 -07001374 struct dentry *file;
1375
1376 file = debugfs_create_file(name, mode, dent, fill, &debug_ops);
1377 if (IS_ERR(file))
1378 pr_err("%s: debugfs create failed %d\n", __func__,
1379 (int)PTR_ERR(file));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001380}
1381
1382#endif
1383
Jeff Hugod98b1082011-10-24 10:30:23 -06001384static void notify_all(int event, unsigned long data)
1385{
1386 int i;
Jeff Hugocb798022012-04-09 14:55:40 -06001387 struct list_head *temp;
1388 struct outside_notify_func *func;
Jeff Hugod98b1082011-10-24 10:30:23 -06001389
1390 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
Eric Holmberg454d9da2012-01-12 09:37:14 -07001391 if (bam_ch_is_open(i)) {
Jeff Hugod98b1082011-10-24 10:30:23 -06001392 bam_ch[i].notify(bam_ch[i].priv, event, data);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301393 BAM_DMUX_LOG("%s: cid=%d, event=%d, data=%lu\n",
Eric Holmberg454d9da2012-01-12 09:37:14 -07001394 __func__, i, event, data);
1395 }
Jeff Hugod98b1082011-10-24 10:30:23 -06001396 }
Jeff Hugocb798022012-04-09 14:55:40 -06001397
1398 __list_for_each(temp, &bam_other_notify_funcs) {
1399 func = container_of(temp, struct outside_notify_func,
1400 list_node);
1401 func->notify(func->priv, event, data);
1402 }
Jeff Hugod98b1082011-10-24 10:30:23 -06001403}
1404
1405static void kickoff_ul_wakeup_func(struct work_struct *work)
1406{
1407 read_lock(&ul_wakeup_lock);
1408 if (!bam_is_connected) {
1409 read_unlock(&ul_wakeup_lock);
1410 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -07001411 if (unlikely(in_global_reset == 1))
1412 return;
Jeff Hugod98b1082011-10-24 10:30:23 -06001413 read_lock(&ul_wakeup_lock);
1414 ul_packet_written = 1;
1415 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
1416 }
1417 read_unlock(&ul_wakeup_lock);
1418}
1419
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001420int msm_bam_dmux_kickoff_ul_wakeup(void)
Jeff Hugod98b1082011-10-24 10:30:23 -06001421{
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001422 int is_connected;
1423
1424 read_lock(&ul_wakeup_lock);
1425 ul_packet_written = 1;
1426 is_connected = bam_is_connected;
1427 if (!is_connected)
1428 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1429 read_unlock(&ul_wakeup_lock);
1430
1431 return is_connected;
Jeff Hugod98b1082011-10-24 10:30:23 -06001432}
1433
Eric Holmberg878923a2012-01-10 14:28:19 -07001434static void power_vote(int vote)
1435{
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301436 BAM_DMUX_LOG("%s: curr=%d, vote=%d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -07001437 bam_dmux_uplink_vote, vote);
1438
1439 if (bam_dmux_uplink_vote == vote)
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301440 BAM_DMUX_LOG("%s: warning - duplicate power vote\n", __func__);
Eric Holmberg878923a2012-01-10 14:28:19 -07001441
1442 bam_dmux_uplink_vote = vote;
1443 if (vote)
1444 smsm_change_state(SMSM_APPS_STATE, 0, SMSM_A2_POWER_CONTROL);
1445 else
1446 smsm_change_state(SMSM_APPS_STATE, SMSM_A2_POWER_CONTROL, 0);
1447}
1448
Eric Holmberg454d9da2012-01-12 09:37:14 -07001449/*
1450 * @note: Must be called with ul_wakeup_lock locked.
1451 */
1452static inline void ul_powerdown(void)
1453{
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301454 BAM_DMUX_LOG("%s: powerdown\n", __func__);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001455 verify_tx_queue_is_empty(__func__);
1456
1457 if (a2_pc_disabled) {
1458 wait_for_dfab = 1;
1459 INIT_COMPLETION(dfab_unvote_completion);
1460 release_wakelock();
1461 } else {
1462 wait_for_ack = 1;
1463 INIT_COMPLETION(ul_wakeup_ack_completion);
1464 power_vote(0);
1465 }
1466 bam_is_connected = 0;
1467 notify_all(BAM_DMUX_UL_DISCONNECTED, (unsigned long)(NULL));
1468}
1469
1470static inline void ul_powerdown_finish(void)
1471{
1472 if (a2_pc_disabled && wait_for_dfab) {
1473 unvote_dfab();
1474 complete_all(&dfab_unvote_completion);
1475 wait_for_dfab = 0;
1476 }
1477}
1478
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001479/*
1480 * Votes for UL power and returns current power state.
1481 *
1482 * @returns true if currently connected
1483 */
1484int msm_bam_dmux_ul_power_vote(void)
1485{
1486 int is_connected;
1487
1488 read_lock(&ul_wakeup_lock);
1489 atomic_inc(&ul_ondemand_vote);
1490 is_connected = bam_is_connected;
1491 if (!is_connected)
1492 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1493 read_unlock(&ul_wakeup_lock);
1494
1495 return is_connected;
1496}
1497
1498/*
1499 * Unvotes for UL power.
1500 *
1501 * @returns true if vote count is 0 (UL shutdown possible)
1502 */
1503int msm_bam_dmux_ul_power_unvote(void)
1504{
1505 int vote;
1506
1507 read_lock(&ul_wakeup_lock);
1508 vote = atomic_dec_return(&ul_ondemand_vote);
1509 if (unlikely(vote) < 0)
1510 DMUX_LOG_KERR("%s: invalid power vote %d\n", __func__, vote);
1511 read_unlock(&ul_wakeup_lock);
1512
1513 return vote == 0;
1514}
1515
Jeff Hugocb798022012-04-09 14:55:40 -06001516int msm_bam_dmux_reg_notify(void *priv,
1517 void (*notify)(void *priv, int event_type,
1518 unsigned long data))
1519{
1520 struct outside_notify_func *func;
1521
1522 if (!notify)
1523 return -EINVAL;
1524
1525 func = kmalloc(sizeof(struct outside_notify_func), GFP_KERNEL);
1526 if (!func)
1527 return -ENOMEM;
1528
1529 func->notify = notify;
1530 func->priv = priv;
1531 list_add(&func->list_node, &bam_other_notify_funcs);
1532
1533 return 0;
1534}
1535
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001536static void ul_timeout(struct work_struct *work)
1537{
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001538 unsigned long flags;
1539 int ret;
1540
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001541 if (in_global_reset)
1542 return;
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001543 ret = write_trylock_irqsave(&ul_wakeup_lock, flags);
1544 if (!ret) { /* failed to grab lock, reschedule and bail */
1545 schedule_delayed_work(&ul_timeout_work,
1546 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1547 return;
1548 }
Eric Holmberg454d9da2012-01-12 09:37:14 -07001549 if (bam_is_connected) {
Eric Holmberg6074aba2012-01-18 17:59:44 -07001550 if (!ul_packet_written) {
1551 spin_lock(&bam_tx_pool_spinlock);
1552 if (!list_empty(&bam_tx_pool)) {
1553 struct tx_pkt_info *info;
1554
1555 info = list_first_entry(&bam_tx_pool,
1556 struct tx_pkt_info, list_node);
1557 DMUX_LOG_KERR("%s: UL delayed ts=%u.%09lu\n",
1558 __func__, info->ts_sec, info->ts_nsec);
1559 DBG_INC_TX_STALL_CNT();
1560 ul_packet_written = 1;
1561 }
1562 spin_unlock(&bam_tx_pool_spinlock);
1563 }
1564
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001565 if (ul_packet_written || atomic_read(&ul_ondemand_vote)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301566 BAM_DMUX_LOG("%s: pkt written %d\n",
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001567 __func__, ul_packet_written);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001568 ul_packet_written = 0;
1569 schedule_delayed_work(&ul_timeout_work,
1570 msecs_to_jiffies(UL_TIMEOUT_DELAY));
Eric Holmberg006057d2012-01-11 10:10:42 -07001571 } else {
Eric Holmberg454d9da2012-01-12 09:37:14 -07001572 ul_powerdown();
Eric Holmberg006057d2012-01-11 10:10:42 -07001573 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001574 }
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001575 write_unlock_irqrestore(&ul_wakeup_lock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001576 ul_powerdown_finish();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001577}
Jeff Hugo4838f412012-01-20 11:19:37 -07001578
1579static int ssrestart_check(void)
1580{
Jeff Hugob8156d72013-06-04 12:51:10 -06001581 int ret = 0;
1582
1583 DMUX_LOG_KERR("%s: modem timeout: BAM DMUX disabled for SSR\n",
1584 __func__);
Eric Holmberg90285e22012-02-22 12:33:05 -07001585 in_global_reset = 1;
Jeff Hugob8156d72013-06-04 12:51:10 -06001586 ret = subsystem_restart("modem");
1587 if (ret == -ENODEV)
1588 panic("modem subsystem restart failed\n");
Eric Holmberg90285e22012-02-22 12:33:05 -07001589 return 1;
Jeff Hugo4838f412012-01-20 11:19:37 -07001590}
1591
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001592static void ul_wakeup(void)
1593{
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001594 int ret;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001595 int do_vote_dfab = 0;
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001596
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001597 mutex_lock(&wakeup_lock);
1598 if (bam_is_connected) { /* bam got connected before lock grabbed */
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301599 BAM_DMUX_LOG("%s Already awake\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001600 mutex_unlock(&wakeup_lock);
1601 return;
1602 }
Eric Holmberg878923a2012-01-10 14:28:19 -07001603
Jeff Hugoc2696142012-05-03 11:42:13 -06001604 /*
Jeff Hugof5001732012-08-27 13:19:09 -06001605 * if this gets hit, that means restart_notifier_cb() has started
1606 * but probably not finished, thus we know SSR has happened, but
1607 * haven't been able to send that info to our clients yet.
1608 * in that case, abort the ul_wakeup() so that we don't undo any
1609 * work restart_notifier_cb() has done. The clients will be notified
1610 * shortly. No cleanup necessary (reschedule the wakeup) as our and
1611 * their SSR handling will cover it
1612 */
1613 if (unlikely(in_global_reset == 1)) {
1614 mutex_unlock(&wakeup_lock);
1615 return;
1616 }
1617
1618 /*
Jeff Hugoc2696142012-05-03 11:42:13 -06001619 * if someone is voting for UL before bam is inited (modem up first
1620 * time), set flag for init to kickoff ul wakeup once bam is inited
1621 */
1622 mutex_lock(&delayed_ul_vote_lock);
1623 if (unlikely(!bam_mux_initialized)) {
1624 need_delayed_ul_vote = 1;
1625 mutex_unlock(&delayed_ul_vote_lock);
1626 mutex_unlock(&wakeup_lock);
1627 return;
1628 }
1629 mutex_unlock(&delayed_ul_vote_lock);
1630
Eric Holmberg006057d2012-01-11 10:10:42 -07001631 if (a2_pc_disabled) {
1632 /*
1633 * don't grab the wakelock the first time because it is
1634 * already grabbed when a2 powers on
1635 */
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001636 if (likely(a2_pc_disabled_wakelock_skipped)) {
Eric Holmberg006057d2012-01-11 10:10:42 -07001637 grab_wakelock();
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001638 do_vote_dfab = 1; /* vote must occur after wait */
1639 } else {
Jeff Hugo583a6da2012-02-03 11:37:30 -07001640 a2_pc_disabled_wakelock_skipped = 1;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001641 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001642 if (wait_for_dfab) {
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001643 ret = wait_for_completion_timeout(
Eric Holmberg006057d2012-01-11 10:10:42 -07001644 &dfab_unvote_completion, HZ);
1645 BUG_ON(ret == 0);
1646 }
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001647 if (likely(do_vote_dfab))
1648 vote_dfab();
Eric Holmberg006057d2012-01-11 10:10:42 -07001649 schedule_delayed_work(&ul_timeout_work,
1650 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1651 bam_is_connected = 1;
1652 mutex_unlock(&wakeup_lock);
1653 return;
1654 }
1655
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001656 /*
1657 * must wait for the previous power down request to have been acked
1658 * chances are it already came in and this will just fall through
1659 * instead of waiting
1660 */
1661 if (wait_for_ack) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301662 BAM_DMUX_LOG("%s waiting for previous ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001663 ret = wait_for_completion_timeout(
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001664 &ul_wakeup_ack_completion, HZ);
Eric Holmberg006057d2012-01-11 10:10:42 -07001665 wait_for_ack = 0;
Jeff Hugo4838f412012-01-20 11:19:37 -07001666 if (unlikely(ret == 0) && ssrestart_check()) {
1667 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301668 BAM_DMUX_LOG("%s timeout previous ack\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001669 return;
1670 }
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001671 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001672 INIT_COMPLETION(ul_wakeup_ack_completion);
Eric Holmberg878923a2012-01-10 14:28:19 -07001673 power_vote(1);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301674 BAM_DMUX_LOG("%s waiting for wakeup ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001675 ret = wait_for_completion_timeout(&ul_wakeup_ack_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001676 if (unlikely(ret == 0) && ssrestart_check()) {
1677 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301678 BAM_DMUX_LOG("%s timeout wakeup ack\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001679 return;
1680 }
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301681 BAM_DMUX_LOG("%s waiting completion\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001682 ret = wait_for_completion_timeout(&bam_connection_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001683 if (unlikely(ret == 0) && ssrestart_check()) {
1684 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301685 BAM_DMUX_LOG("%s timeout power on\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001686 return;
1687 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001688
1689 bam_is_connected = 1;
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301690 BAM_DMUX_LOG("%s complete\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001691 schedule_delayed_work(&ul_timeout_work,
1692 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1693 mutex_unlock(&wakeup_lock);
1694}
1695
1696static void reconnect_to_bam(void)
1697{
1698 int i;
1699
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001700 in_global_reset = 0;
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001701 in_ssr = 0;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001702 vote_dfab();
Jeff Hugo18792a32012-06-20 15:25:55 -06001703 if (!power_management_only_mode) {
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001704 if (ssr_skipped_disconnect) {
1705 /* delayed to here to prevent bus stall */
1706 sps_disconnect(bam_tx_pipe);
1707 sps_disconnect(bam_rx_pipe);
1708 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1709 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
1710 }
1711 ssr_skipped_disconnect = 0;
Jeff Hugo18792a32012-06-20 15:25:55 -06001712 i = sps_device_reset(a2_device_handle);
1713 if (i)
1714 pr_err("%s: device reset failed rc = %d\n", __func__,
1715 i);
1716 i = sps_connect(bam_tx_pipe, &tx_connection);
1717 if (i)
1718 pr_err("%s: tx connection failed rc = %d\n", __func__,
1719 i);
1720 i = sps_connect(bam_rx_pipe, &rx_connection);
1721 if (i)
1722 pr_err("%s: rx connection failed rc = %d\n", __func__,
1723 i);
1724 i = sps_register_event(bam_tx_pipe, &tx_register_event);
1725 if (i)
1726 pr_err("%s: tx event reg failed rc = %d\n", __func__,
1727 i);
1728 i = sps_register_event(bam_rx_pipe, &rx_register_event);
1729 if (i)
1730 pr_err("%s: rx event reg failed rc = %d\n", __func__,
1731 i);
1732 }
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001733
1734 bam_connection_is_active = 1;
1735
1736 if (polling_mode)
1737 rx_switch_to_interrupt_mode();
1738
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001739 toggle_apps_ack();
1740 complete_all(&bam_connection_completion);
Jeff Hugo18792a32012-06-20 15:25:55 -06001741 if (!power_management_only_mode)
1742 queue_rx();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001743}
1744
1745static void disconnect_to_bam(void)
1746{
1747 struct list_head *node;
1748 struct rx_pkt_info *info;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001749 unsigned long flags;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001750
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001751 bam_connection_is_active = 0;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001752
1753 /* handle disconnect during active UL */
1754 write_lock_irqsave(&ul_wakeup_lock, flags);
1755 if (bam_is_connected) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301756 BAM_DMUX_LOG("%s: UL active - forcing powerdown\n", __func__);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001757 ul_powerdown();
1758 }
1759 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1760 ul_powerdown_finish();
1761
1762 /* tear down BAM connection */
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001763 INIT_COMPLETION(bam_connection_completion);
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001764
1765 /* in_ssr documentation/assumptions found in restart_notifier_cb */
Jeff Hugo18792a32012-06-20 15:25:55 -06001766 if (!power_management_only_mode) {
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001767 if (likely(!in_ssr)) {
1768 sps_disconnect(bam_tx_pipe);
1769 sps_disconnect(bam_rx_pipe);
1770 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1771 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
1772 sps_device_reset(a2_device_handle);
1773 } else {
1774 ssr_skipped_disconnect = 1;
1775 }
Jeff Hugo18792a32012-06-20 15:25:55 -06001776 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001777 unvote_dfab();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001778
1779 mutex_lock(&bam_rx_pool_mutexlock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001780 while (!list_empty(&bam_rx_pool)) {
1781 node = bam_rx_pool.next;
1782 list_del(node);
1783 info = container_of(node, struct rx_pkt_info, list_node);
1784 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
1785 DMA_FROM_DEVICE);
1786 dev_kfree_skb_any(info->skb);
1787 kfree(info);
1788 }
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001789 bam_rx_pool_len = 0;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001790 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmberg878923a2012-01-10 14:28:19 -07001791
Jeff Hugo0b13a352012-03-17 23:18:30 -06001792 if (disconnect_ack)
1793 toggle_apps_ack();
1794
Eric Holmberg878923a2012-01-10 14:28:19 -07001795 verify_tx_queue_is_empty(__func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001796}
1797
1798static void vote_dfab(void)
1799{
Jeff Hugoca0caa82011-12-05 16:05:23 -07001800 int rc;
1801
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301802 BAM_DMUX_LOG("%s\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001803 mutex_lock(&dfab_status_lock);
1804 if (dfab_is_on) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301805 BAM_DMUX_LOG("%s: dfab is already on\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001806 mutex_unlock(&dfab_status_lock);
1807 return;
1808 }
Jeff Hugod0befde2012-08-09 15:32:49 -06001809 if (dfab_clk) {
1810 rc = clk_prepare_enable(dfab_clk);
1811 if (rc)
1812 DMUX_LOG_KERR("bam_dmux vote for dfab failed rc = %d\n",
1813 rc);
1814 }
1815 if (xo_clk) {
1816 rc = clk_prepare_enable(xo_clk);
1817 if (rc)
1818 DMUX_LOG_KERR("bam_dmux vote for xo failed rc = %d\n",
1819 rc);
1820 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001821 dfab_is_on = 1;
1822 mutex_unlock(&dfab_status_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001823}
1824
1825static void unvote_dfab(void)
1826{
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301827 BAM_DMUX_LOG("%s\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001828 mutex_lock(&dfab_status_lock);
1829 if (!dfab_is_on) {
1830 DMUX_LOG_KERR("%s: dfab is already off\n", __func__);
1831 dump_stack();
1832 mutex_unlock(&dfab_status_lock);
1833 return;
1834 }
Jeff Hugod0befde2012-08-09 15:32:49 -06001835 if (dfab_clk)
1836 clk_disable_unprepare(dfab_clk);
1837 if (xo_clk)
1838 clk_disable_unprepare(xo_clk);
Eric Holmberg006057d2012-01-11 10:10:42 -07001839 dfab_is_on = 0;
1840 mutex_unlock(&dfab_status_lock);
1841}
1842
1843/* reference counting wrapper around wakelock */
1844static void grab_wakelock(void)
1845{
1846 unsigned long flags;
1847
1848 spin_lock_irqsave(&wakelock_reference_lock, flags);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301849 BAM_DMUX_LOG("%s: ref count = %d\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -07001850 wakelock_reference_count);
1851 if (wakelock_reference_count == 0)
1852 wake_lock(&bam_wakelock);
1853 ++wakelock_reference_count;
1854 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1855}
1856
1857static void release_wakelock(void)
1858{
1859 unsigned long flags;
1860
1861 spin_lock_irqsave(&wakelock_reference_lock, flags);
1862 if (wakelock_reference_count == 0) {
1863 DMUX_LOG_KERR("%s: bam_dmux wakelock not locked\n", __func__);
1864 dump_stack();
1865 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1866 return;
1867 }
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301868 BAM_DMUX_LOG("%s: ref count = %d\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -07001869 wakelock_reference_count);
1870 --wakelock_reference_count;
1871 if (wakelock_reference_count == 0)
1872 wake_unlock(&bam_wakelock);
1873 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001874}
1875
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001876static int restart_notifier_cb(struct notifier_block *this,
1877 unsigned long code,
1878 void *data)
1879{
1880 int i;
1881 struct list_head *node;
1882 struct tx_pkt_info *info;
1883 int temp_remote_status;
Jeff Hugo626303bf2011-11-21 11:43:28 -07001884 unsigned long flags;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001885
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001886 /*
1887 * Bam_dmux counts on the fact that the BEFORE_SHUTDOWN level of
1888 * notifications are guarenteed to execute before the AFTER_SHUTDOWN
1889 * level of notifications, and that BEFORE_SHUTDOWN always occurs in
1890 * all SSR events, no matter what triggered the SSR. Also, bam_dmux
1891 * assumes that SMD does its SSR processing in the AFTER_SHUTDOWN level
1892 * thus bam_dmux is guarenteed to detect SSR before SMD, since the
1893 * callbacks for all the drivers within the AFTER_SHUTDOWN level could
1894 * occur in any order. Bam_dmux uses this knowledge to skip accessing
1895 * the bam hardware when disconnect_to_bam() is triggered by SMD's SSR
1896 * processing. We do not wat to access the bam hardware during SSR
1897 * because a watchdog crash from a bus stall would likely occur.
1898 */
1899 if (code == SUBSYS_BEFORE_SHUTDOWN)
1900 in_ssr = 1;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001901 if (code != SUBSYS_AFTER_SHUTDOWN)
1902 return NOTIFY_DONE;
1903
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301904 BAM_DMUX_LOG("%s: begin\n", __func__);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001905 in_global_reset = 1;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001906
1907 /* Handle uplink Powerdown */
1908 write_lock_irqsave(&ul_wakeup_lock, flags);
1909 if (bam_is_connected) {
1910 ul_powerdown();
1911 wait_for_ack = 0;
1912 }
Jeff Hugo4838f412012-01-20 11:19:37 -07001913 /*
1914 * if modem crash during ul_wakeup(), power_vote is 1, needs to be
1915 * reset to 0. harmless if bam_is_connected check above passes
1916 */
1917 power_vote(0);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001918 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1919 ul_powerdown_finish();
Eric Holmberg006057d2012-01-11 10:10:42 -07001920 a2_pc_disabled = 0;
Jeff Hugo583a6da2012-02-03 11:37:30 -07001921 a2_pc_disabled_wakelock_skipped = 0;
Jeff Hugof62029d2012-07-17 13:39:53 -06001922 disconnect_ack = 1;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001923
1924 /* Cleanup Channel States */
Eric Holmberga623da82012-07-12 09:37:09 -06001925 mutex_lock(&bam_pdev_mutexlock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001926 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
1927 temp_remote_status = bam_ch_is_remote_open(i);
1928 bam_ch[i].status &= ~BAM_CH_REMOTE_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001929 bam_ch[i].num_tx_pkts = 0;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001930 if (bam_ch_is_local_open(i))
1931 bam_ch[i].status |= BAM_CH_IN_RESET;
1932 if (temp_remote_status) {
1933 platform_device_unregister(bam_ch[i].pdev);
1934 bam_ch[i].pdev = platform_device_alloc(
1935 bam_ch[i].name, 2);
1936 }
1937 }
Eric Holmberga623da82012-07-12 09:37:09 -06001938 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001939
1940 /* Cleanup pending UL data */
Jeff Hugo626303bf2011-11-21 11:43:28 -07001941 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001942 while (!list_empty(&bam_tx_pool)) {
1943 node = bam_tx_pool.next;
1944 list_del(node);
1945 info = container_of(node, struct tx_pkt_info,
1946 list_node);
1947 if (!info->is_cmd) {
1948 dma_unmap_single(NULL, info->dma_address,
1949 info->skb->len,
1950 DMA_TO_DEVICE);
1951 dev_kfree_skb_any(info->skb);
1952 } else {
1953 dma_unmap_single(NULL, info->dma_address,
1954 info->len,
1955 DMA_TO_DEVICE);
1956 kfree(info->skb);
1957 }
1958 kfree(info);
1959 }
Jeff Hugo626303bf2011-11-21 11:43:28 -07001960 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001961
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301962 BAM_DMUX_LOG("%s: complete\n", __func__);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001963 return NOTIFY_DONE;
1964}
1965
Jeff Hugo9dea05c2011-12-21 12:23:05 -07001966static int bam_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001967{
1968 u32 h;
1969 dma_addr_t dma_addr;
1970 int ret;
1971 void *a2_virt_addr;
Jeff Hugo4b2890d2012-01-16 16:14:21 -07001972 int skip_iounmap = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001973
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001974 vote_dfab();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001975 /* init BAM */
Jeff Hugo3910ee12012-08-21 14:08:20 -06001976 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
1977 a2_phys_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001978 if (!a2_virt_addr) {
1979 pr_err("%s: ioremap failed\n", __func__);
1980 ret = -ENOMEM;
Jeff Hugo994a92d2012-01-05 13:25:21 -07001981 goto ioremap_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001982 }
Jeff Hugo3910ee12012-08-21 14:08:20 -06001983 a2_props.phys_addr = (u32)(a2_phys_base);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001984 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo3910ee12012-08-21 14:08:20 -06001985 a2_props.virt_size = a2_phys_size;
1986 a2_props.irq = a2_bam_irq;
Jeff Hugo927cba62011-11-11 11:49:52 -07001987 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001988 a2_props.num_pipes = A2_NUM_PIPES;
1989 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
Jeff Hugo75913c82011-12-05 15:59:01 -07001990 if (cpu_is_msm9615())
1991 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001992 /* need to free on tear down */
1993 ret = sps_register_bam_device(&a2_props, &h);
1994 if (ret < 0) {
1995 pr_err("%s: register bam error %d\n", __func__, ret);
1996 goto register_bam_failed;
1997 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001998 a2_device_handle = h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001999
2000 bam_tx_pipe = sps_alloc_endpoint();
2001 if (bam_tx_pipe == NULL) {
2002 pr_err("%s: tx alloc endpoint failed\n", __func__);
2003 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002004 goto tx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002005 }
2006 ret = sps_get_config(bam_tx_pipe, &tx_connection);
2007 if (ret) {
2008 pr_err("%s: tx get config failed %d\n", __func__, ret);
2009 goto tx_get_config_failed;
2010 }
2011
2012 tx_connection.source = SPS_DEV_HANDLE_MEM;
2013 tx_connection.src_pipe_index = 0;
2014 tx_connection.destination = h;
2015 tx_connection.dest_pipe_index = 4;
2016 tx_connection.mode = SPS_MODE_DEST;
2017 tx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT;
2018 tx_desc_mem_buf.size = 0x800; /* 2k */
2019 tx_desc_mem_buf.base = dma_alloc_coherent(NULL, tx_desc_mem_buf.size,
2020 &dma_addr, 0);
2021 if (tx_desc_mem_buf.base == NULL) {
2022 pr_err("%s: tx memory alloc failed\n", __func__);
2023 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002024 goto tx_get_config_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002025 }
2026 tx_desc_mem_buf.phys_base = dma_addr;
2027 memset(tx_desc_mem_buf.base, 0x0, tx_desc_mem_buf.size);
2028 tx_connection.desc = tx_desc_mem_buf;
2029 tx_connection.event_thresh = 0x10;
2030
2031 ret = sps_connect(bam_tx_pipe, &tx_connection);
2032 if (ret < 0) {
2033 pr_err("%s: tx connect error %d\n", __func__, ret);
2034 goto tx_connect_failed;
2035 }
2036
2037 bam_rx_pipe = sps_alloc_endpoint();
2038 if (bam_rx_pipe == NULL) {
2039 pr_err("%s: rx alloc endpoint failed\n", __func__);
2040 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002041 goto rx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002042 }
2043 ret = sps_get_config(bam_rx_pipe, &rx_connection);
2044 if (ret) {
2045 pr_err("%s: rx get config failed %d\n", __func__, ret);
2046 goto rx_get_config_failed;
2047 }
2048
2049 rx_connection.source = h;
2050 rx_connection.src_pipe_index = 5;
2051 rx_connection.destination = SPS_DEV_HANDLE_MEM;
2052 rx_connection.dest_pipe_index = 1;
2053 rx_connection.mode = SPS_MODE_SRC;
Jeff Hugo949080a2011-08-30 11:58:56 -06002054 rx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT |
2055 SPS_O_ACK_TRANSFERS;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002056 rx_desc_mem_buf.size = 0x800; /* 2k */
2057 rx_desc_mem_buf.base = dma_alloc_coherent(NULL, rx_desc_mem_buf.size,
2058 &dma_addr, 0);
2059 if (rx_desc_mem_buf.base == NULL) {
2060 pr_err("%s: rx memory alloc failed\n", __func__);
2061 ret = -ENOMEM;
2062 goto rx_mem_failed;
2063 }
2064 rx_desc_mem_buf.phys_base = dma_addr;
2065 memset(rx_desc_mem_buf.base, 0x0, rx_desc_mem_buf.size);
2066 rx_connection.desc = rx_desc_mem_buf;
2067 rx_connection.event_thresh = 0x10;
2068
2069 ret = sps_connect(bam_rx_pipe, &rx_connection);
2070 if (ret < 0) {
2071 pr_err("%s: rx connect error %d\n", __func__, ret);
2072 goto rx_connect_failed;
2073 }
2074
2075 tx_register_event.options = SPS_O_EOT;
2076 tx_register_event.mode = SPS_TRIGGER_CALLBACK;
2077 tx_register_event.xfer_done = NULL;
2078 tx_register_event.callback = bam_mux_tx_notify;
2079 tx_register_event.user = NULL;
2080 ret = sps_register_event(bam_tx_pipe, &tx_register_event);
2081 if (ret < 0) {
2082 pr_err("%s: tx register event error %d\n", __func__, ret);
2083 goto rx_event_reg_failed;
2084 }
2085
Jeff Hugo33dbc002011-08-25 15:52:53 -06002086 rx_register_event.options = SPS_O_EOT;
2087 rx_register_event.mode = SPS_TRIGGER_CALLBACK;
2088 rx_register_event.xfer_done = NULL;
2089 rx_register_event.callback = bam_mux_rx_notify;
2090 rx_register_event.user = NULL;
2091 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
2092 if (ret < 0) {
2093 pr_err("%s: tx register event error %d\n", __func__, ret);
2094 goto rx_event_reg_failed;
2095 }
2096
Jeff Hugoc2696142012-05-03 11:42:13 -06002097 mutex_lock(&delayed_ul_vote_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002098 bam_mux_initialized = 1;
Jeff Hugoc2696142012-05-03 11:42:13 -06002099 if (need_delayed_ul_vote) {
2100 need_delayed_ul_vote = 0;
2101 msm_bam_dmux_kickoff_ul_wakeup();
2102 }
2103 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002104 toggle_apps_ack();
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002105 bam_connection_is_active = 1;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002106 complete_all(&bam_connection_completion);
Jeff Hugo2fb555e2012-03-14 16:33:47 -06002107 queue_rx();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002108 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002109
2110rx_event_reg_failed:
2111 sps_disconnect(bam_rx_pipe);
2112rx_connect_failed:
2113 dma_free_coherent(NULL, rx_desc_mem_buf.size, rx_desc_mem_buf.base,
2114 rx_desc_mem_buf.phys_base);
2115rx_mem_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002116rx_get_config_failed:
2117 sps_free_endpoint(bam_rx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002118rx_alloc_endpoint_failed:
2119 sps_disconnect(bam_tx_pipe);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002120tx_connect_failed:
2121 dma_free_coherent(NULL, tx_desc_mem_buf.size, tx_desc_mem_buf.base,
2122 tx_desc_mem_buf.phys_base);
2123tx_get_config_failed:
2124 sps_free_endpoint(bam_tx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002125tx_alloc_endpoint_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002126 sps_deregister_bam_device(h);
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002127 /*
2128 * sps_deregister_bam_device() calls iounmap. calling iounmap on the
2129 * same handle below will cause a crash, so skip it if we've freed
2130 * the handle here.
2131 */
2132 skip_iounmap = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002133register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002134 if (!skip_iounmap)
2135 iounmap(a2_virt_addr);
Jeff Hugo994a92d2012-01-05 13:25:21 -07002136ioremap_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002137 /*destroy_workqueue(bam_mux_workqueue);*/
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002138 return ret;
2139}
2140
2141static int bam_init_fallback(void)
2142{
2143 u32 h;
2144 int ret;
2145 void *a2_virt_addr;
2146
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002147 /* init BAM */
Jeff Hugo3910ee12012-08-21 14:08:20 -06002148 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
2149 a2_phys_size);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002150 if (!a2_virt_addr) {
2151 pr_err("%s: ioremap failed\n", __func__);
2152 ret = -ENOMEM;
2153 goto ioremap_failed;
2154 }
Jeff Hugo3910ee12012-08-21 14:08:20 -06002155 a2_props.phys_addr = (u32)(a2_phys_base);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002156 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo3910ee12012-08-21 14:08:20 -06002157 a2_props.virt_size = a2_phys_size;
2158 a2_props.irq = a2_bam_irq;
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002159 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
2160 a2_props.num_pipes = A2_NUM_PIPES;
2161 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
2162 if (cpu_is_msm9615())
2163 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
2164 ret = sps_register_bam_device(&a2_props, &h);
2165 if (ret < 0) {
2166 pr_err("%s: register bam error %d\n", __func__, ret);
2167 goto register_bam_failed;
2168 }
2169 a2_device_handle = h;
Jeff Hugoc2696142012-05-03 11:42:13 -06002170
2171 mutex_lock(&delayed_ul_vote_lock);
2172 bam_mux_initialized = 1;
2173 if (need_delayed_ul_vote) {
2174 need_delayed_ul_vote = 0;
2175 msm_bam_dmux_kickoff_ul_wakeup();
2176 }
2177 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugo2bec9772012-04-05 12:25:16 -06002178 toggle_apps_ack();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002179
Jeff Hugo18792a32012-06-20 15:25:55 -06002180 power_management_only_mode = 1;
2181 bam_connection_is_active = 1;
2182 complete_all(&bam_connection_completion);
2183
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002184 return 0;
2185
2186register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002187 iounmap(a2_virt_addr);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002188ioremap_failed:
2189 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002190}
Jeff Hugoade1f842011-08-03 15:53:59 -06002191
Jeff Hugoa670b762012-03-15 15:58:28 -06002192static void msm9615_bam_init(void)
Eric Holmberg604ab252012-01-15 00:01:18 -07002193{
2194 int ret = 0;
2195
2196 ret = bam_init();
2197 if (ret) {
2198 ret = bam_init_fallback();
2199 if (ret)
2200 pr_err("%s: bam init fallback failed: %d",
2201 __func__, ret);
2202 }
2203}
2204
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002205static void toggle_apps_ack(void)
2206{
2207 static unsigned int clear_bit; /* 0 = set the bit, else clear bit */
Eric Holmberg878923a2012-01-10 14:28:19 -07002208
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302209 BAM_DMUX_LOG("%s: apps ack %d->%d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -07002210 clear_bit & 0x1, ~clear_bit & 0x1);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002211 smsm_change_state(SMSM_APPS_STATE,
2212 clear_bit & SMSM_A2_POWER_CONTROL_ACK,
2213 ~clear_bit & SMSM_A2_POWER_CONTROL_ACK);
2214 clear_bit = ~clear_bit;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002215 DBG_INC_ACK_OUT_CNT();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002216}
2217
Jeff Hugoade1f842011-08-03 15:53:59 -06002218static void bam_dmux_smsm_cb(void *priv, uint32_t old_state, uint32_t new_state)
2219{
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002220 static int last_processed_state;
2221
2222 mutex_lock(&smsm_cb_lock);
Eric Holmberg878923a2012-01-10 14:28:19 -07002223 bam_dmux_power_state = new_state & SMSM_A2_POWER_CONTROL ? 1 : 0;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002224 DBG_INC_A2_POWER_CONTROL_IN_CNT();
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302225 BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
Eric Holmberg878923a2012-01-10 14:28:19 -07002226 new_state);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002227 if (last_processed_state == (new_state & SMSM_A2_POWER_CONTROL)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302228 BAM_DMUX_LOG("%s: already processed this state\n", __func__);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002229 mutex_unlock(&smsm_cb_lock);
2230 return;
2231 }
2232
2233 last_processed_state = new_state & SMSM_A2_POWER_CONTROL;
Eric Holmberg878923a2012-01-10 14:28:19 -07002234
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002235 if (bam_mux_initialized && new_state & SMSM_A2_POWER_CONTROL) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302236 BAM_DMUX_LOG("%s: reconnect\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002237 grab_wakelock();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002238 reconnect_to_bam();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002239 } else if (bam_mux_initialized &&
2240 !(new_state & SMSM_A2_POWER_CONTROL)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302241 BAM_DMUX_LOG("%s: disconnect\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002242 disconnect_to_bam();
Eric Holmberg006057d2012-01-11 10:10:42 -07002243 release_wakelock();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002244 } else if (new_state & SMSM_A2_POWER_CONTROL) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302245 BAM_DMUX_LOG("%s: init\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002246 grab_wakelock();
Jeff Hugoa670b762012-03-15 15:58:28 -06002247 if (cpu_is_msm9615())
2248 msm9615_bam_init();
2249 else
Eric Holmberg604ab252012-01-15 00:01:18 -07002250 bam_init();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002251 } else {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302252 BAM_DMUX_LOG("%s: bad state change\n", __func__);
Jeff Hugoade1f842011-08-03 15:53:59 -06002253 pr_err("%s: unsupported state change\n", __func__);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002254 }
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002255 mutex_unlock(&smsm_cb_lock);
Jeff Hugoade1f842011-08-03 15:53:59 -06002256
2257}
2258
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002259static void bam_dmux_smsm_ack_cb(void *priv, uint32_t old_state,
2260 uint32_t new_state)
2261{
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002262 DBG_INC_ACK_IN_CNT();
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302263 BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
Eric Holmberg878923a2012-01-10 14:28:19 -07002264 new_state);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002265 complete_all(&ul_wakeup_ack_completion);
2266}
2267
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002268static int bam_dmux_probe(struct platform_device *pdev)
2269{
2270 int rc;
Jeff Hugo3910ee12012-08-21 14:08:20 -06002271 struct resource *r;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002272
2273 DBG("%s probe called\n", __func__);
2274 if (bam_mux_initialized)
2275 return 0;
2276
Jeff Hugo3910ee12012-08-21 14:08:20 -06002277 if (pdev->dev.of_node) {
2278 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2279 if (!r) {
2280 pr_err("%s: reg field missing\n", __func__);
2281 return -ENODEV;
2282 }
2283 a2_phys_base = (void *)(r->start);
2284 a2_phys_size = (uint32_t)(resource_size(r));
2285 a2_bam_irq = platform_get_irq(pdev, 0);
2286 if (a2_bam_irq == -ENXIO) {
2287 pr_err("%s: irq field missing\n", __func__);
2288 return -ENODEV;
2289 }
2290 DBG("%s: base:%p size:%x irq:%d\n", __func__,
2291 a2_phys_base,
2292 a2_phys_size,
2293 a2_bam_irq);
2294 } else { /* fallback to default init data */
2295 a2_phys_base = (void *)(A2_PHYS_BASE);
2296 a2_phys_size = A2_PHYS_SIZE;
2297 a2_bam_irq = A2_BAM_IRQ;
2298 }
2299
Stephen Boyd69d35e32012-02-14 15:33:30 -08002300 xo_clk = clk_get(&pdev->dev, "xo");
2301 if (IS_ERR(xo_clk)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302302 BAM_DMUX_LOG("%s: did not get xo clock\n", __func__);
Jeff Hugod0befde2012-08-09 15:32:49 -06002303 xo_clk = NULL;
Stephen Boyd69d35e32012-02-14 15:33:30 -08002304 }
Stephen Boyd1c51a492011-10-26 12:11:47 -07002305 dfab_clk = clk_get(&pdev->dev, "bus_clk");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002306 if (IS_ERR(dfab_clk)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302307 BAM_DMUX_LOG("%s: did not get dfab clock\n", __func__);
Jeff Hugod0befde2012-08-09 15:32:49 -06002308 dfab_clk = NULL;
2309 } else {
2310 rc = clk_set_rate(dfab_clk, 64000000);
2311 if (rc)
2312 pr_err("%s: unable to set dfab clock rate\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002313 }
2314
Jeff Hugofff43af92012-03-29 17:54:52 -06002315 /*
2316 * setup the workqueue so that it can be pinned to core 0 and not
2317 * block the watchdog pet function, so that netif_rx() in rmnet
2318 * only uses one queue.
2319 */
2320 bam_mux_rx_workqueue = alloc_workqueue("bam_dmux_rx",
2321 WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002322 if (!bam_mux_rx_workqueue)
2323 return -ENOMEM;
2324
2325 bam_mux_tx_workqueue = create_singlethread_workqueue("bam_dmux_tx");
2326 if (!bam_mux_tx_workqueue) {
2327 destroy_workqueue(bam_mux_rx_workqueue);
2328 return -ENOMEM;
2329 }
2330
Jeff Hugo7960abd2011-08-02 15:39:38 -06002331 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002332 spin_lock_init(&bam_ch[rc].lock);
Jeff Hugo7960abd2011-08-02 15:39:38 -06002333 scnprintf(bam_ch[rc].name, BAM_DMUX_CH_NAME_MAX_LEN,
2334 "bam_dmux_ch_%d", rc);
2335 /* bus 2, ie a2 stream 2 */
2336 bam_ch[rc].pdev = platform_device_alloc(bam_ch[rc].name, 2);
2337 if (!bam_ch[rc].pdev) {
2338 pr_err("%s: platform device alloc failed\n", __func__);
2339 destroy_workqueue(bam_mux_rx_workqueue);
2340 destroy_workqueue(bam_mux_tx_workqueue);
2341 return -ENOMEM;
2342 }
2343 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002344
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002345 init_completion(&ul_wakeup_ack_completion);
2346 init_completion(&bam_connection_completion);
Eric Holmberg006057d2012-01-11 10:10:42 -07002347 init_completion(&dfab_unvote_completion);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002348 INIT_DELAYED_WORK(&ul_timeout_work, ul_timeout);
Jeff Hugo988e7ba2012-10-03 15:53:54 -06002349 INIT_DELAYED_WORK(&queue_rx_work, queue_rx_work_func);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002350 wake_lock_init(&bam_wakelock, WAKE_LOCK_SUSPEND, "bam_dmux_wakelock");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002351
Jeff Hugoade1f842011-08-03 15:53:59 -06002352 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL,
2353 bam_dmux_smsm_cb, NULL);
2354
2355 if (rc) {
2356 destroy_workqueue(bam_mux_rx_workqueue);
2357 destroy_workqueue(bam_mux_tx_workqueue);
2358 pr_err("%s: smsm cb register failed, rc: %d\n", __func__, rc);
2359 return -ENOMEM;
2360 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002361
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002362 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL_ACK,
2363 bam_dmux_smsm_ack_cb, NULL);
2364
2365 if (rc) {
2366 destroy_workqueue(bam_mux_rx_workqueue);
2367 destroy_workqueue(bam_mux_tx_workqueue);
2368 smsm_state_cb_deregister(SMSM_MODEM_STATE,
2369 SMSM_A2_POWER_CONTROL,
2370 bam_dmux_smsm_cb, NULL);
2371 pr_err("%s: smsm ack cb register failed, rc: %d\n", __func__,
2372 rc);
2373 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc)
2374 platform_device_put(bam_ch[rc].pdev);
2375 return -ENOMEM;
2376 }
2377
Eric Holmbergfd1e2ae2011-11-15 18:28:17 -07002378 if (smsm_get_state(SMSM_MODEM_STATE) & SMSM_A2_POWER_CONTROL)
2379 bam_dmux_smsm_cb(NULL, 0, smsm_get_state(SMSM_MODEM_STATE));
2380
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002381 return 0;
2382}
2383
Jeff Hugo3910ee12012-08-21 14:08:20 -06002384static struct of_device_id msm_match_table[] = {
2385 {.compatible = "qcom,bam_dmux"},
2386 {},
2387};
2388
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002389static struct platform_driver bam_dmux_driver = {
2390 .probe = bam_dmux_probe,
2391 .driver = {
2392 .name = "BAM_RMNT",
2393 .owner = THIS_MODULE,
Jeff Hugo3910ee12012-08-21 14:08:20 -06002394 .of_match_table = msm_match_table,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002395 },
2396};
2397
2398static int __init bam_dmux_init(void)
2399{
2400#ifdef CONFIG_DEBUG_FS
2401 struct dentry *dent;
2402
2403 dent = debugfs_create_dir("bam_dmux", 0);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002404 if (!IS_ERR(dent)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002405 debug_create("tbl", 0444, dent, debug_tbl);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002406 debug_create("ul_pkt_cnt", 0444, dent, debug_ul_pkt_cnt);
2407 debug_create("stats", 0444, dent, debug_stats);
2408 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002409#endif
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302410
2411 bam_ipc_log_txt = ipc_log_context_create(BAM_IPC_LOG_PAGES, "bam_dmux");
2412 if (!bam_ipc_log_txt) {
2413 pr_err("%s : unable to create IPC Logging Context", __func__);
Eric Holmberg878923a2012-01-10 14:28:19 -07002414 }
2415
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07002416 rx_timer_interval = DEFAULT_POLLING_MIN_SLEEP;
2417
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002418 subsys_notif_register_notifier("modem", &restart_notifier);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002419 return platform_driver_register(&bam_dmux_driver);
2420}
2421
Jeff Hugoade1f842011-08-03 15:53:59 -06002422late_initcall(bam_dmux_init); /* needs to init after SMD */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002423MODULE_DESCRIPTION("MSM BAM DMUX");
2424MODULE_LICENSE("GPL v2");