blob: dc728eb25e682a559b19ed58d3171db61227af2a [file] [log] [blame]
Sagar Dharia32379162013-12-12 00:46:37 -07001/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
Sagar Dharia71fcea52012-09-12 23:21:57 -06002 *
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 */
Sagar Dharia71fcea52012-09-12 23:21:57 -060012#include <linux/irq.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/slab.h>
16#include <linux/io.h>
17#include <linux/interrupt.h>
18#include <linux/platform_device.h>
19#include <linux/dma-mapping.h>
20#include <linux/slimbus/slimbus.h>
21#include <linux/delay.h>
22#include <linux/kthread.h>
23#include <linux/clk.h>
24#include <linux/pm_runtime.h>
25#include <linux/of.h>
26#include <linux/of_slimbus.h>
27#include <linux/timer.h>
28#include <mach/sps.h>
29#include "slim-msm.h"
30#include <mach/qdsp6v2/apr.h>
31
32#define NGD_SLIM_NAME "ngd_msm_ctrl"
33#define SLIM_LA_MGR 0xFF
34#define SLIM_ROOT_FREQ 24576000
Sagar Dharia33beca02012-10-22 16:21:46 -060035#define LADDR_RETRY 5
Sagar Dharia71fcea52012-09-12 23:21:57 -060036
37#define NGD_BASE_V1(r) (((r) % 2) ? 0x800 : 0xA00)
38#define NGD_BASE_V2(r) (((r) % 2) ? 0x1000 : 0x2000)
39#define NGD_BASE(r, v) ((v) ? NGD_BASE_V2(r) : NGD_BASE_V1(r))
40/* NGD (Non-ported Generic Device) registers */
41enum ngd_reg {
42 NGD_CFG = 0x0,
43 NGD_STATUS = 0x4,
44 NGD_RX_MSGQ_CFG = 0x8,
45 NGD_INT_EN = 0x10,
46 NGD_INT_STAT = 0x14,
47 NGD_INT_CLR = 0x18,
48 NGD_TX_MSG = 0x30,
49 NGD_RX_MSG = 0x70,
50 NGD_IE_STAT = 0xF0,
51 NGD_VE_STAT = 0x100,
52};
53
54enum ngd_msg_cfg {
55 NGD_CFG_ENABLE = 1,
56 NGD_CFG_RX_MSGQ_EN = 1 << 1,
57 NGD_CFG_TX_MSGQ_EN = 1 << 2,
58};
59
60enum ngd_intr {
61 NGD_INT_RECFG_DONE = 1 << 24,
62 NGD_INT_TX_NACKED_2 = 1 << 25,
63 NGD_INT_MSG_BUF_CONTE = 1 << 26,
64 NGD_INT_MSG_TX_INVAL = 1 << 27,
65 NGD_INT_IE_VE_CHG = 1 << 28,
66 NGD_INT_DEV_ERR = 1 << 29,
67 NGD_INT_RX_MSG_RCVD = 1 << 30,
68 NGD_INT_TX_MSG_SENT = 1 << 31,
69};
70
71enum ngd_offsets {
72 NGD_NACKED_MC = 0x7F00000,
73 NGD_ACKED_MC = 0xFE000,
74 NGD_ERROR = 0x1800,
75 NGD_MSGQ_SUPPORT = 0x400,
76 NGD_RX_MSGQ_TIME_OUT = 0x16,
77 NGD_ENUMERATED = 0x1,
78 NGD_TX_BUSY = 0x0,
79};
80
Sagar Dharia33beca02012-10-22 16:21:46 -060081enum ngd_status {
82 NGD_LADDR = 1 << 1,
83};
84
85static int ngd_slim_runtime_resume(struct device *device);
86
Sagar Dharia71fcea52012-09-12 23:21:57 -060087static irqreturn_t ngd_slim_interrupt(int irq, void *d)
88{
89 struct msm_slim_ctrl *dev = (struct msm_slim_ctrl *)d;
90 void __iomem *ngd = dev->base + NGD_BASE(dev->ctrl.nr, dev->ver);
91 u32 stat = readl_relaxed(ngd + NGD_INT_STAT);
Sagar Dharia2b8a4b52013-05-15 20:01:45 -060092 u32 pstat;
Sagar Dharia71fcea52012-09-12 23:21:57 -060093
94 if (stat & NGD_INT_TX_MSG_SENT) {
95 writel_relaxed(NGD_INT_TX_MSG_SENT, ngd + NGD_INT_CLR);
96 /* Make sure interrupt is cleared */
97 mb();
98 if (dev->wr_comp)
99 complete(dev->wr_comp);
100 } else if ((stat & NGD_INT_MSG_BUF_CONTE) ||
101 (stat & NGD_INT_MSG_TX_INVAL) || (stat & NGD_INT_DEV_ERR) ||
102 (stat & NGD_INT_TX_NACKED_2)) {
103 dev_err(dev->dev, "NGD interrupt error:0x%x", stat);
104 writel_relaxed(stat, ngd + NGD_INT_CLR);
105 /* Guarantee that error interrupts are cleared */
106 mb();
107 if (((stat & NGD_INT_TX_NACKED_2) ||
108 (stat & NGD_INT_MSG_TX_INVAL))) {
109 dev->err = -EIO;
110 if (dev->wr_comp)
111 complete(dev->wr_comp);
112 }
113 }
114 if (stat & NGD_INT_RX_MSG_RCVD) {
115 u32 rx_buf[10];
116 u8 len, i;
117 rx_buf[0] = readl_relaxed(ngd + NGD_RX_MSG);
118 len = rx_buf[0] & 0x1F;
119 for (i = 1; i < ((len + 3) >> 2); i++) {
120 rx_buf[i] = readl_relaxed(ngd + NGD_RX_MSG +
121 (4 * i));
122 dev_dbg(dev->dev, "REG-RX data: %x\n", rx_buf[i]);
123 }
124 msm_slim_rx_enqueue(dev, rx_buf, len);
125 writel_relaxed(NGD_INT_RX_MSG_RCVD,
126 ngd + NGD_INT_CLR);
127 /*
128 * Guarantee that CLR bit write goes through before
129 * queuing work
130 */
131 mb();
Sagar Dharia24419e32013-01-14 17:56:32 -0700132 if (dev->use_rx_msgqs == MSM_MSGQ_ENABLED)
Sagar Dharia71fcea52012-09-12 23:21:57 -0600133 dev_err(dev->dev,
134 "direct message received even with RX MSGQs");
135 else
136 complete(&dev->rx_msgq_notify);
137 }
138 if (stat & NGD_INT_RECFG_DONE) {
139 writel_relaxed(NGD_INT_RECFG_DONE, ngd + NGD_INT_CLR);
140 /* Guarantee RECONFIG DONE interrupt is cleared */
141 mb();
142 /* In satellite mode, just log the reconfig done IRQ */
143 dev_dbg(dev->dev, "reconfig done IRQ for NGD");
144 }
145 if (stat & NGD_INT_IE_VE_CHG) {
146 writel_relaxed(NGD_INT_IE_VE_CHG, ngd + NGD_INT_CLR);
147 /* Guarantee IE VE change interrupt is cleared */
148 mb();
149 dev_err(dev->dev, "NGD IE VE change");
150 }
Sagar Dharia2b8a4b52013-05-15 20:01:45 -0600151
152 pstat = readl_relaxed(PGD_THIS_EE(PGD_PORT_INT_ST_EEn, dev->ver));
153 if (pstat != 0)
154 return msm_slim_port_irq_handler(dev, pstat);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600155 return IRQ_HANDLED;
156}
157
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700158static int ngd_qmi_available(struct notifier_block *n, unsigned long code,
159 void *_cmd)
160{
161 struct msm_slim_qmi *qmi = container_of(n, struct msm_slim_qmi, nb);
Sagar Dharia33beca02012-10-22 16:21:46 -0600162 struct msm_slim_ctrl *dev =
163 container_of(qmi, struct msm_slim_ctrl, qmi);
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700164 pr_info("Slimbus QMI NGD CB received event:%ld", code);
165 switch (code) {
166 case QMI_SERVER_ARRIVE:
Sagar Dharia33beca02012-10-22 16:21:46 -0600167 schedule_work(&qmi->ssr_up);
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700168 break;
169 case QMI_SERVER_EXIT:
Sagar Dharia33beca02012-10-22 16:21:46 -0600170 dev->state = MSM_CTRL_DOWN;
171 /* make sure autosuspend is not called until ADSP comes up*/
172 pm_runtime_get_noresume(dev->dev);
173 /* Reset ctrl_up completion */
174 init_completion(&dev->ctrl_up);
175 schedule_work(&qmi->ssr_down);
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700176 break;
177 default:
178 break;
179 }
180 return 0;
181}
182
Sagar Dharia71fcea52012-09-12 23:21:57 -0600183static int ngd_get_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn,
184 u8 *tid, struct completion *done)
185{
186 struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl);
Sagar Dhariad2959352012-12-01 15:43:01 -0700187 mutex_lock(&ctrl->m_ctrl);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600188 if (ctrl->last_tid <= 255) {
189 ctrl->txnt = krealloc(ctrl->txnt,
190 (ctrl->last_tid + 1) *
191 sizeof(struct slim_msg_txn *),
192 GFP_KERNEL);
Sagar Dhariad2959352012-12-01 15:43:01 -0700193 if (!ctrl->txnt) {
194 mutex_unlock(&ctrl->m_ctrl);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600195 return -ENOMEM;
Sagar Dhariad2959352012-12-01 15:43:01 -0700196 }
Sagar Dharia71fcea52012-09-12 23:21:57 -0600197 dev->msg_cnt = ctrl->last_tid;
198 ctrl->last_tid++;
199 } else {
200 int i;
201 for (i = 0; i < 256; i++) {
202 dev->msg_cnt = ((dev->msg_cnt + 1) & 0xFF);
203 if (ctrl->txnt[dev->msg_cnt] == NULL)
204 break;
205 }
206 if (i >= 256) {
207 dev_err(&ctrl->dev, "out of TID");
Sagar Dhariad2959352012-12-01 15:43:01 -0700208 mutex_unlock(&ctrl->m_ctrl);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600209 return -ENOMEM;
210 }
211 }
212 ctrl->txnt[dev->msg_cnt] = txn;
213 txn->tid = dev->msg_cnt;
214 txn->comp = done;
215 *tid = dev->msg_cnt;
Sagar Dhariad2959352012-12-01 15:43:01 -0700216 mutex_unlock(&ctrl->m_ctrl);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600217 return 0;
218}
219static int ngd_xfer_msg(struct slim_controller *ctrl, struct slim_msg_txn *txn)
220{
221 DECLARE_COMPLETION_ONSTACK(done);
222 DECLARE_COMPLETION_ONSTACK(tx_sent);
223
224 struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl);
225 u32 *pbuf;
226 u8 *puc;
227 int ret = 0;
Sagar Dharia71fcea52012-09-12 23:21:57 -0600228 u8 la = txn->la;
Sagar Dharia8e554ed2013-07-19 15:48:15 -0600229 u8 txn_mt;
230 u16 txn_mc = txn->mc;
Sagar Dharia5c8ad192013-05-31 11:39:05 -0600231 u8 wbuf[SLIM_MSGQ_BUF_LEN];
Sagar Dharia71fcea52012-09-12 23:21:57 -0600232
Sagar Dhariaa1398282013-01-22 13:26:20 -0700233 if (!pm_runtime_enabled(dev->dev) && dev->state == MSM_CTRL_ASLEEP &&
234 txn->mc != SLIM_USR_MC_REPORT_SATELLITE) {
235 /*
236 * Counter-part of system-suspend when runtime-pm is not enabled
237 * This way, resume can be left empty and device will be put in
238 * active mode only if client requests anything on the bus
239 * If the state was DOWN, SSR UP notification will take
240 * care of putting the device in active state.
241 */
242 ngd_slim_runtime_resume(dev->dev);
243 }
Sagar Dharia5c8ad192013-05-31 11:39:05 -0600244 if ((txn->mc == (SLIM_MSG_CLK_PAUSE_SEQ_FLG |
245 SLIM_MSG_MC_RECONFIGURE_NOW)) &&
246 dev->state <= MSM_CTRL_SLEEPING) {
247 msm_slim_disconnect_endp(dev, &dev->rx_msgq,
248 &dev->use_rx_msgqs);
249 msm_slim_disconnect_endp(dev, &dev->tx_msgq,
250 &dev->use_tx_msgqs);
251 return msm_slim_qmi_power_request(dev, false);
Sagar Dharia24419e32013-01-14 17:56:32 -0700252 }
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700253 else if (txn->mc & SLIM_MSG_CLK_PAUSE_SEQ_FLG)
254 return 0;
255
Sagar Dharia71fcea52012-09-12 23:21:57 -0600256 if (txn->mt == SLIM_MSG_MT_CORE &&
257 (txn->mc >= SLIM_MSG_MC_BEGIN_RECONFIGURATION &&
258 txn->mc <= SLIM_MSG_MC_RECONFIGURE_NOW)) {
259 return 0;
260 }
Sagar Dharia33beca02012-10-22 16:21:46 -0600261 /* If txn is tried when controller is down, wait for ADSP to boot */
262 if (txn->mc != SLIM_USR_MC_REPORT_SATELLITE) {
263 if (dev->state == MSM_CTRL_DOWN) {
264 u8 mc = (u8)txn->mc;
265 int timeout;
266 dev_err(dev->dev, "ADSP slimbus not up yet");
267 /*
268 * Messages related to data channel management can't
269 * wait since they are holding reconfiguration lock.
270 * clk_pause in resume (which can change state back to
Sagar Dharia32379162013-12-12 00:46:37 -0700271 * MSM_CTRL_AWAKE), will need that lock.
272 * Port disconnection, channel removal calls should pass
273 * through since there is no activity on the bus and
274 * those calls are triggered by clients due to
275 * device_down callback in that situation.
276 * Returning 0 on the disconnections and
277 * removals will ensure consistent state of channels,
278 * ports with the HW
Sagar Dharia33beca02012-10-22 16:21:46 -0600279 */
Sagar Dharia32379162013-12-12 00:46:37 -0700280 if ((txn->mt == SLIM_MSG_MT_DEST_REFERRED_USER) &&
281 ((mc == SLIM_USR_MC_CHAN_CTRL ||
282 mc == SLIM_USR_MC_DISCONNECT_PORT ||
283 mc == SLIM_USR_MC_RECONFIG_NOW)))
284 return 0;
285 if ((txn->mt == SLIM_MSG_MT_CORE) &&
286 ((mc == SLIM_MSG_MC_DISCONNECT_PORT ||
287 mc == SLIM_MSG_MC_NEXT_REMOVE_CHANNEL ||
288 mc == SLIM_USR_MC_RECONFIG_NOW)))
289 return 0;
Sagar Dharia33beca02012-10-22 16:21:46 -0600290 if ((txn->mt == SLIM_MSG_MT_CORE) &&
291 ((mc >= SLIM_MSG_MC_CONNECT_SOURCE &&
292 mc <= SLIM_MSG_MC_CHANGE_CONTENT) ||
293 (mc >= SLIM_MSG_MC_BEGIN_RECONFIGURATION &&
294 mc <= SLIM_MSG_MC_RECONFIGURE_NOW)))
295 return -EREMOTEIO;
296 if ((txn->mt == SLIM_MSG_MT_DEST_REFERRED_USER) &&
297 ((mc >= SLIM_USR_MC_DEFINE_CHAN &&
Sagar Dharia32379162013-12-12 00:46:37 -0700298 mc < SLIM_USR_MC_DISCONNECT_PORT)))
Sagar Dharia33beca02012-10-22 16:21:46 -0600299 return -EREMOTEIO;
300 timeout = wait_for_completion_timeout(&dev->ctrl_up,
301 HZ);
302 if (!timeout)
303 return -ETIMEDOUT;
304 }
305 msm_slim_get_ctrl(dev);
306 }
Sagar Dharia71fcea52012-09-12 23:21:57 -0600307 mutex_lock(&dev->tx_lock);
Sagar Dharia33beca02012-10-22 16:21:46 -0600308
Sagar Dharia71fcea52012-09-12 23:21:57 -0600309 if (txn->mc != SLIM_USR_MC_REPORT_SATELLITE &&
Sagar Dharia33beca02012-10-22 16:21:46 -0600310 (dev->state != MSM_CTRL_AWAKE)) {
Sagar Dharia71fcea52012-09-12 23:21:57 -0600311 dev_err(dev->dev, "controller not ready");
312 mutex_unlock(&dev->tx_lock);
Sagar Dharia33beca02012-10-22 16:21:46 -0600313 msm_slim_put_ctrl(dev);
314 return -EREMOTEIO;
Sagar Dharia71fcea52012-09-12 23:21:57 -0600315 }
316 if (txn->mt == SLIM_MSG_MT_CORE &&
317 (txn->mc == SLIM_MSG_MC_CONNECT_SOURCE ||
318 txn->mc == SLIM_MSG_MC_CONNECT_SINK ||
319 txn->mc == SLIM_MSG_MC_DISCONNECT_PORT)) {
320 int i = 0;
321 txn->mt = SLIM_MSG_MT_DEST_REFERRED_USER;
322 if (txn->mc == SLIM_MSG_MC_CONNECT_SOURCE)
323 txn->mc = SLIM_USR_MC_CONNECT_SRC;
324 else if (txn->mc == SLIM_MSG_MC_CONNECT_SINK)
325 txn->mc = SLIM_USR_MC_CONNECT_SINK;
326 else if (txn->mc == SLIM_MSG_MC_DISCONNECT_PORT)
327 txn->mc = SLIM_USR_MC_DISCONNECT_PORT;
Sagar Dhariaa3c6a382013-06-21 12:18:20 -0600328 if (txn->la == SLIM_LA_MGR) {
329 if (dev->pgdla == SLIM_LA_MGR) {
330 u8 ea[] = {0, QC_DEVID_PGD, 0, 0, QC_MFGID_MSB,
331 QC_MFGID_LSB};
332 ea[2] = (u8)(dev->pdata.eapc & 0xFF);
333 ea[3] = (u8)((dev->pdata.eapc & 0xFF00) >> 8);
334 mutex_unlock(&dev->tx_lock);
335 ret = dev->ctrl.get_laddr(&dev->ctrl, ea, 6,
336 &dev->pgdla);
337 pr_debug("SLIM PGD LA:0x%x, ret:%d", dev->pgdla,
338 ret);
339 if (ret) {
340 pr_err("Incorrect SLIM-PGD EAPC:0x%x",
341 dev->pdata.eapc);
342 return ret;
343 }
344 mutex_lock(&dev->tx_lock);
345 }
Sagar Dharia71fcea52012-09-12 23:21:57 -0600346 txn->la = dev->pgdla;
Sagar Dhariaa3c6a382013-06-21 12:18:20 -0600347 }
Sagar Dharia71fcea52012-09-12 23:21:57 -0600348 wbuf[i++] = txn->la;
349 la = SLIM_LA_MGR;
350 wbuf[i++] = txn->wbuf[0];
351 if (txn->mc != SLIM_USR_MC_DISCONNECT_PORT)
352 wbuf[i++] = txn->wbuf[1];
353 ret = ngd_get_tid(ctrl, txn, &wbuf[i++], &done);
354 if (ret) {
355 pr_err("TID for connect/disconnect fail:%d", ret);
356 goto ngd_xfer_err;
357 }
358 txn->len = i;
359 txn->wbuf = wbuf;
360 txn->rl = txn->len + 4;
361 }
362 txn->rl--;
363 pbuf = msm_get_msg_buf(dev, txn->rl);
364 if (!pbuf) {
365 dev_err(dev->dev, "Message buffer unavailable");
366 ret = -ENOMEM;
367 goto ngd_xfer_err;
368 }
369 dev->err = 0;
370
371 if (txn->dt == SLIM_MSG_DEST_ENUMADDR) {
372 ret = -EPROTONOSUPPORT;
373 goto ngd_xfer_err;
374 }
375 if (txn->dt == SLIM_MSG_DEST_LOGICALADDR)
376 *pbuf = SLIM_MSG_ASM_FIRST_WORD(txn->rl, txn->mt, txn->mc, 0,
377 la);
378 else
379 *pbuf = SLIM_MSG_ASM_FIRST_WORD(txn->rl, txn->mt, txn->mc, 1,
380 la);
381 if (txn->dt == SLIM_MSG_DEST_LOGICALADDR)
382 puc = ((u8 *)pbuf) + 3;
383 else
384 puc = ((u8 *)pbuf) + 2;
385 if (txn->rbuf)
386 *(puc++) = txn->tid;
387 if ((txn->mt == SLIM_MSG_MT_CORE) &&
388 ((txn->mc >= SLIM_MSG_MC_REQUEST_INFORMATION &&
389 txn->mc <= SLIM_MSG_MC_REPORT_INFORMATION) ||
390 (txn->mc >= SLIM_MSG_MC_REQUEST_VALUE &&
391 txn->mc <= SLIM_MSG_MC_CHANGE_VALUE))) {
392 *(puc++) = (txn->ec & 0xFF);
393 *(puc++) = (txn->ec >> 8)&0xFF;
394 }
395 if (txn->wbuf)
396 memcpy(puc, txn->wbuf, txn->len);
397 if (txn->mt == SLIM_MSG_MT_DEST_REFERRED_USER &&
398 (txn->mc == SLIM_USR_MC_CONNECT_SRC ||
399 txn->mc == SLIM_USR_MC_CONNECT_SINK ||
400 txn->mc == SLIM_USR_MC_DISCONNECT_PORT) && txn->wbuf &&
401 wbuf[0] == dev->pgdla) {
Sagar Dharia2d74c142013-05-17 02:24:06 -0600402 if (txn->mc != SLIM_USR_MC_DISCONNECT_PORT)
Sagar Dharia71fcea52012-09-12 23:21:57 -0600403 dev->err = msm_slim_connect_pipe_port(dev, wbuf[1]);
404 else {
Sagar Dharia71fcea52012-09-12 23:21:57 -0600405 /*
406 * Remove channel disconnects master-side ports from
407 * channel. No need to send that again on the bus
Sagar Dharia2d74c142013-05-17 02:24:06 -0600408 * Only disable port
Sagar Dharia71fcea52012-09-12 23:21:57 -0600409 */
Sagar Dharia2d74c142013-05-17 02:24:06 -0600410 writel_relaxed(0, PGD_PORT(PGD_PORT_CFGn,
411 (wbuf[1] + dev->port_b), dev->ver));
Sagar Dharia71fcea52012-09-12 23:21:57 -0600412 mutex_unlock(&dev->tx_lock);
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700413 msm_slim_put_ctrl(dev);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600414 return 0;
415 }
416 if (dev->err) {
417 dev_err(dev->dev, "pipe-port connect err:%d", dev->err);
418 goto ngd_xfer_err;
419 }
Sagar Dhariaa3c6a382013-06-21 12:18:20 -0600420 /* Add port-base to port number if this is manager side port */
421 puc[1] += dev->port_b;
Sagar Dharia71fcea52012-09-12 23:21:57 -0600422 }
423 dev->err = 0;
Sagar Dharia8e554ed2013-07-19 15:48:15 -0600424 /*
425 * If it's a read txn, it may be freed if a response is received by
426 * received thread before reaching end of this function.
427 * mc, mt may have changed to convert standard slimbus code/type to
428 * satellite user-defined message. Reinitialize again
429 */
430 txn_mc = txn->mc;
431 txn_mt = txn->mt;
Sagar Dharia71fcea52012-09-12 23:21:57 -0600432 dev->wr_comp = &tx_sent;
433 ret = msm_send_msg_buf(dev, pbuf, txn->rl,
434 NGD_BASE(dev->ctrl.nr, dev->ver) + NGD_TX_MSG);
435 if (!ret) {
436 int timeout = wait_for_completion_timeout(&tx_sent, HZ);
Sagar Dharia5c8ad192013-05-31 11:39:05 -0600437 if (!timeout) {
Sagar Dharia71fcea52012-09-12 23:21:57 -0600438 ret = -ETIMEDOUT;
Sagar Dharia5c8ad192013-05-31 11:39:05 -0600439 /*
440 * disconnect/recoonect pipe so that subsequent
441 * transactions don't timeout due to unavailable
442 * descriptors
443 */
444 msm_slim_disconnect_endp(dev, &dev->tx_msgq,
445 &dev->use_tx_msgqs);
446 msm_slim_connect_endp(dev, &dev->tx_msgq, NULL);
447 } else {
Sagar Dharia71fcea52012-09-12 23:21:57 -0600448 ret = dev->err;
Sagar Dharia5c8ad192013-05-31 11:39:05 -0600449 }
Sagar Dharia71fcea52012-09-12 23:21:57 -0600450 }
451 dev->wr_comp = NULL;
452 if (ret) {
453 u32 conf, stat, rx_msgq, int_stat, int_en, int_clr;
454 void __iomem *ngd = dev->base + NGD_BASE(dev->ctrl.nr,
455 dev->ver);
456 dev_err(dev->dev, "TX failed :MC:0x%x,mt:0x%x, ret:%d, ver:%d",
Sagar Dharia8e554ed2013-07-19 15:48:15 -0600457 txn_mc, txn_mt, ret, dev->ver);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600458 conf = readl_relaxed(ngd);
459 stat = readl_relaxed(ngd + NGD_STATUS);
460 rx_msgq = readl_relaxed(ngd + NGD_RX_MSGQ_CFG);
461 int_stat = readl_relaxed(ngd + NGD_INT_STAT);
462 int_en = readl_relaxed(ngd + NGD_INT_EN);
463 int_clr = readl_relaxed(ngd + NGD_INT_CLR);
464
465 pr_err("conf:0x%x,stat:0x%x,rxmsgq:0x%x", conf, stat, rx_msgq);
466 pr_err("int_stat:0x%x,int_en:0x%x,int_cll:0x%x", int_stat,
467 int_en, int_clr);
Sagar Dharia8e554ed2013-07-19 15:48:15 -0600468 } else if (txn_mt == SLIM_MSG_MT_DEST_REFERRED_USER &&
469 (txn_mc == SLIM_USR_MC_CONNECT_SRC ||
470 txn_mc == SLIM_USR_MC_CONNECT_SINK ||
471 txn_mc == SLIM_USR_MC_DISCONNECT_PORT)) {
Sagar Dharia71fcea52012-09-12 23:21:57 -0600472 int timeout;
473 mutex_unlock(&dev->tx_lock);
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700474 msm_slim_put_ctrl(dev);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600475 timeout = wait_for_completion_timeout(txn->comp, HZ);
Sagar Dharia33beca02012-10-22 16:21:46 -0600476 if (!timeout)
Sagar Dharia71fcea52012-09-12 23:21:57 -0600477 ret = -ETIMEDOUT;
Sagar Dharia33beca02012-10-22 16:21:46 -0600478 else
479 ret = txn->ec;
480 if (ret) {
481 pr_err("connect/disconnect:0x%x,tid:%d err:%d", txn->mc,
482 txn->tid, ret);
Sagar Dhariad2959352012-12-01 15:43:01 -0700483 mutex_lock(&ctrl->m_ctrl);
484 ctrl->txnt[txn->tid] = NULL;
485 mutex_unlock(&ctrl->m_ctrl);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600486 }
Sagar Dharia71fcea52012-09-12 23:21:57 -0600487 return ret ? ret : dev->err;
488 }
489ngd_xfer_err:
490 mutex_unlock(&dev->tx_lock);
Sagar Dharia8e554ed2013-07-19 15:48:15 -0600491 if (txn_mc != SLIM_USR_MC_REPORT_SATELLITE)
Sagar Dharia33beca02012-10-22 16:21:46 -0600492 msm_slim_put_ctrl(dev);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600493 return ret ? ret : dev->err;
494}
495
496static int ngd_xferandwait_ack(struct slim_controller *ctrl,
497 struct slim_msg_txn *txn)
498{
499 int ret = ngd_xfer_msg(ctrl, txn);
500 if (!ret) {
501 int timeout;
502 timeout = wait_for_completion_timeout(txn->comp, HZ);
Sagar Dharia33beca02012-10-22 16:21:46 -0600503 if (!timeout)
Sagar Dharia71fcea52012-09-12 23:21:57 -0600504 ret = -ETIMEDOUT;
Sagar Dharia33beca02012-10-22 16:21:46 -0600505 else
Sagar Dharia71fcea52012-09-12 23:21:57 -0600506 ret = txn->ec;
Sagar Dharia71fcea52012-09-12 23:21:57 -0600507 }
Sagar Dharia33beca02012-10-22 16:21:46 -0600508 if (ret) {
Sagar Dharia71fcea52012-09-12 23:21:57 -0600509 pr_err("master msg:0x%x,tid:%d ret:%d", txn->mc,
510 txn->tid, ret);
Sagar Dharia33beca02012-10-22 16:21:46 -0600511 mutex_lock(&ctrl->m_ctrl);
512 ctrl->txnt[txn->tid] = NULL;
513 mutex_unlock(&ctrl->m_ctrl);
514 }
Sagar Dharia71fcea52012-09-12 23:21:57 -0600515
516 return ret;
517}
518
519static int ngd_allocbw(struct slim_device *sb, int *subfrmc, int *clkgear)
520{
521 int ret;
522 struct slim_pending_ch *pch;
523 struct slim_msg_txn txn;
524 struct slim_controller *ctrl = sb->ctrl;
525 DECLARE_COMPLETION_ONSTACK(done);
Sagar Dharia5c8ad192013-05-31 11:39:05 -0600526 u8 wbuf[SLIM_MSGQ_BUF_LEN];
Sagar Dharia71fcea52012-09-12 23:21:57 -0600527
Sagar Dharia5ee34ae2013-04-26 18:05:37 -0600528 *clkgear = ctrl->clkgear;
529 *subfrmc = 0;
Sagar Dharia71fcea52012-09-12 23:21:57 -0600530 txn.mt = SLIM_MSG_MT_DEST_REFERRED_USER;
531 txn.dt = SLIM_MSG_DEST_LOGICALADDR;
532 txn.la = SLIM_LA_MGR;
533 txn.len = 0;
534 txn.ec = 0;
535 txn.wbuf = wbuf;
536 txn.rbuf = NULL;
537
Sagar Dharia5ee34ae2013-04-26 18:05:37 -0600538 if (ctrl->sched.msgsl != ctrl->sched.pending_msgsl) {
539 pr_debug("slim reserve BW for messaging: req: %d",
540 ctrl->sched.pending_msgsl);
541 txn.mc = SLIM_USR_MC_REQ_BW;
542 wbuf[txn.len++] = ((sb->laddr & 0x1f) |
543 ((u8)(ctrl->sched.pending_msgsl & 0x7) << 5));
544 wbuf[txn.len++] = (u8)(ctrl->sched.pending_msgsl >> 3);
545 ret = ngd_get_tid(ctrl, &txn, &wbuf[txn.len++], &done);
546 if (ret)
547 return ret;
548 txn.rl = txn.len + 4;
549 ret = ngd_xferandwait_ack(ctrl, &txn);
550 if (ret)
551 return ret;
552
553 txn.mc = SLIM_USR_MC_RECONFIG_NOW;
554 txn.len = 2;
555 wbuf[1] = sb->laddr;
556 txn.rl = txn.len + 4;
557 ret = ngd_get_tid(ctrl, &txn, &wbuf[0], &done);
558 if (ret)
559 return ret;
560 ret = ngd_xferandwait_ack(ctrl, &txn);
561 if (ret)
562 return ret;
563
564 txn.len = 0;
565 }
Sagar Dharia71fcea52012-09-12 23:21:57 -0600566 list_for_each_entry(pch, &sb->mark_define, pending) {
567 struct slim_ich *slc;
568 slc = &ctrl->chans[pch->chan];
569 if (!slc) {
570 pr_err("no channel in define?");
571 return -ENXIO;
572 }
573 if (txn.len == 0) {
Sagar Dhariab47c8962012-10-30 13:44:08 -0600574 /* Per protocol, only last 5 bits for client no. */
Sagar Dharia71fcea52012-09-12 23:21:57 -0600575 wbuf[txn.len++] = (u8) (slc->prop.dataf << 5) |
Sagar Dhariab47c8962012-10-30 13:44:08 -0600576 (sb->laddr & 0x1f);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600577 wbuf[txn.len] = slc->seglen;
578 if (slc->coeff == SLIM_COEFF_3)
579 wbuf[txn.len] |= 1 << 5;
580 wbuf[txn.len++] |= slc->prop.auxf << 6;
581 wbuf[txn.len++] = slc->rootexp << 4 | slc->prop.prot;
582 wbuf[txn.len++] = slc->prrate;
583 ret = ngd_get_tid(ctrl, &txn, &wbuf[txn.len++], &done);
584 if (ret) {
585 pr_err("no tid for channel define?");
586 return -ENXIO;
587 }
588 }
589 wbuf[txn.len++] = slc->chan;
Sagar Dhariab47c8962012-10-30 13:44:08 -0600590 pr_debug("slim define chan:%d, tid:0x%x", slc->chan, txn.tid);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600591 }
592 if (txn.len) {
593 txn.mc = SLIM_USR_MC_DEF_ACT_CHAN;
594 txn.rl = txn.len + 4;
595 ret = ngd_xferandwait_ack(ctrl, &txn);
596 if (ret)
597 return ret;
598
599 txn.mc = SLIM_USR_MC_RECONFIG_NOW;
600 txn.len = 2;
601 wbuf[1] = sb->laddr;
602 txn.rl = txn.len + 4;
603 ret = ngd_get_tid(ctrl, &txn, &wbuf[0], &done);
604 if (ret)
605 return ret;
606 ret = ngd_xferandwait_ack(ctrl, &txn);
607 if (ret)
608 return ret;
609 }
610 txn.len = 0;
611 list_for_each_entry(pch, &sb->mark_removal, pending) {
612 struct slim_ich *slc;
613 slc = &ctrl->chans[pch->chan];
614 if (!slc) {
615 pr_err("no channel in removal?");
616 return -ENXIO;
617 }
618 if (txn.len == 0) {
Sagar Dhariab47c8962012-10-30 13:44:08 -0600619 /* Per protocol, only last 5 bits for client no. */
Sagar Dharia71fcea52012-09-12 23:21:57 -0600620 wbuf[txn.len++] = (u8) (SLIM_CH_REMOVE << 6) |
Sagar Dhariab47c8962012-10-30 13:44:08 -0600621 (sb->laddr & 0x1f);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600622 ret = ngd_get_tid(ctrl, &txn, &wbuf[txn.len++], &done);
623 if (ret) {
624 pr_err("no tid for channel define?");
625 return -ENXIO;
626 }
627 }
628 wbuf[txn.len++] = slc->chan;
Sagar Dhariab47c8962012-10-30 13:44:08 -0600629 pr_debug("slim remove chan:%d, tid:0x%x", slc->chan, txn.tid);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600630 }
631 if (txn.len) {
632 txn.mc = SLIM_USR_MC_CHAN_CTRL;
633 txn.rl = txn.len + 4;
634 ret = ngd_xferandwait_ack(ctrl, &txn);
635 if (ret)
636 return ret;
637
638 txn.mc = SLIM_USR_MC_RECONFIG_NOW;
639 txn.len = 2;
640 wbuf[1] = sb->laddr;
641 txn.rl = txn.len + 4;
642 ret = ngd_get_tid(ctrl, &txn, &wbuf[0], &done);
643 if (ret)
644 return ret;
645 ret = ngd_xferandwait_ack(ctrl, &txn);
646 if (ret)
647 return ret;
648 txn.len = 0;
649 }
Sagar Dharia24419e32013-01-14 17:56:32 -0700650 return 0;
Sagar Dharia71fcea52012-09-12 23:21:57 -0600651}
652
653static int ngd_set_laddr(struct slim_controller *ctrl, const u8 *ea,
654 u8 elen, u8 laddr)
655{
656 return 0;
657}
658
659static int ngd_get_laddr(struct slim_controller *ctrl, const u8 *ea,
660 u8 elen, u8 *laddr)
661{
662 int ret;
663 u8 wbuf[10];
664 struct slim_msg_txn txn;
665 DECLARE_COMPLETION_ONSTACK(done);
666 txn.mt = SLIM_MSG_MT_DEST_REFERRED_USER;
667 txn.dt = SLIM_MSG_DEST_LOGICALADDR;
668 txn.la = SLIM_LA_MGR;
669 txn.ec = 0;
Sagar Dharia71fcea52012-09-12 23:21:57 -0600670 ret = ngd_get_tid(ctrl, &txn, &wbuf[0], &done);
671 if (ret) {
Sagar Dharia71fcea52012-09-12 23:21:57 -0600672 return ret;
673 }
674 memcpy(&wbuf[1], ea, elen);
675 txn.mc = SLIM_USR_MC_ADDR_QUERY;
676 txn.rl = 11;
677 txn.len = 7;
678 txn.wbuf = wbuf;
679 txn.rbuf = NULL;
680 ret = ngd_xferandwait_ack(ctrl, &txn);
681 if (!ret && txn.la == 0xFF)
682 ret = -ENXIO;
683 else if (!ret)
684 *laddr = txn.la;
Sagar Dharia71fcea52012-09-12 23:21:57 -0600685 return ret;
686}
687
Sagar Dharia5c8ad192013-05-31 11:39:05 -0600688static void ngd_slim_setup_msg_path(struct msm_slim_ctrl *dev)
Sagar Dharia24419e32013-01-14 17:56:32 -0700689{
Sagar Dharia24419e32013-01-14 17:56:32 -0700690 if (dev->state == MSM_CTRL_DOWN) {
691 msm_slim_sps_init(dev, dev->bam_mem,
692 NGD_BASE(dev->ctrl.nr,
693 dev->ver) + NGD_STATUS, true);
694 } else {
695 if (dev->use_rx_msgqs == MSM_MSGQ_DISABLED)
Sagar Dharia5c8ad192013-05-31 11:39:05 -0600696 goto setup_tx_msg_path;
697 msm_slim_connect_endp(dev, &dev->rx_msgq,
Sagar Dharia24419e32013-01-14 17:56:32 -0700698 &dev->rx_msgq_notify);
Sagar Dharia5c8ad192013-05-31 11:39:05 -0600699
700setup_tx_msg_path:
701 if (dev->use_tx_msgqs == MSM_MSGQ_DISABLED)
702 return;
703 msm_slim_connect_endp(dev, &dev->tx_msgq,
704 NULL);
Sagar Dharia24419e32013-01-14 17:56:32 -0700705 }
706}
Sagar Dharia5c8ad192013-05-31 11:39:05 -0600707
Sagar Dharia71fcea52012-09-12 23:21:57 -0600708static void ngd_slim_rx(struct msm_slim_ctrl *dev, u8 *buf)
709{
710 u8 mc, mt, len;
711 int ret;
712 u32 msgq_en = 1;
713
714 len = buf[0] & 0x1F;
715 mt = (buf[0] >> 5) & 0x7;
716 mc = buf[1];
717 if (mc == SLIM_USR_MC_MASTER_CAPABILITY &&
718 mt == SLIM_MSG_MT_SRC_REFERRED_USER) {
719 struct slim_msg_txn txn;
Sagar Dharia0a693332013-04-15 17:59:03 -0600720 int retries = 0;
Sagar Dharia71fcea52012-09-12 23:21:57 -0600721 u8 wbuf[8];
722 txn.dt = SLIM_MSG_DEST_LOGICALADDR;
723 txn.ec = 0;
724 txn.rbuf = NULL;
725 txn.mc = SLIM_USR_MC_REPORT_SATELLITE;
726 txn.mt = SLIM_MSG_MT_SRC_REFERRED_USER;
727 txn.la = SLIM_LA_MGR;
Sagar Dharia71fcea52012-09-12 23:21:57 -0600728 wbuf[0] = SAT_MAGIC_LSB;
729 wbuf[1] = SAT_MAGIC_MSB;
730 wbuf[2] = SAT_MSG_VER;
731 wbuf[3] = SAT_MSG_PROT;
732 txn.wbuf = wbuf;
733 txn.len = 4;
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700734 pr_info("SLIM SAT: Received master capability");
Sagar Dharia24419e32013-01-14 17:56:32 -0700735 if (dev->state >= MSM_CTRL_ASLEEP) {
Sagar Dharia5c8ad192013-05-31 11:39:05 -0600736 ngd_slim_setup_msg_path(dev);
Sagar Dharia24419e32013-01-14 17:56:32 -0700737 if (dev->use_rx_msgqs == MSM_MSGQ_ENABLED)
Sagar Dharia33beca02012-10-22 16:21:46 -0600738 msgq_en |= NGD_CFG_RX_MSGQ_EN;
Sagar Dharia5c8ad192013-05-31 11:39:05 -0600739 if (dev->use_tx_msgqs == MSM_MSGQ_ENABLED)
740 msgq_en |= NGD_CFG_TX_MSGQ_EN;
Sagar Dharia33beca02012-10-22 16:21:46 -0600741 writel_relaxed(msgq_en, dev->base +
742 NGD_BASE(dev->ctrl.nr, dev->ver));
743 /* make sure NGD MSG-Q config goes through */
744 mb();
745 }
Sagar Dharia0a693332013-04-15 17:59:03 -0600746capability_retry:
747 txn.rl = 8;
Sagar Dharia71fcea52012-09-12 23:21:57 -0600748 ret = ngd_xfer_msg(&dev->ctrl, &txn);
749 if (!ret) {
Sagar Dharia33beca02012-10-22 16:21:46 -0600750 enum msm_ctrl_state prev_state = dev->state;
Sagar Dharia71fcea52012-09-12 23:21:57 -0600751 dev->state = MSM_CTRL_AWAKE;
Sagar Dharia33beca02012-10-22 16:21:46 -0600752 if (prev_state >= MSM_CTRL_ASLEEP)
753 complete(&dev->reconf);
754 else
755 pr_err("SLIM: unexpected capability, state:%d",
756 prev_state);
757 /* ADSP SSR, send device_up notifications */
758 if (prev_state == MSM_CTRL_DOWN)
759 schedule_work(&dev->slave_notify);
Sagar Dharia0a693332013-04-15 17:59:03 -0600760 } else if (ret == -EIO) {
761 pr_info("capability message NACKed, retrying");
762 if (retries < INIT_MX_RETRIES) {
763 msleep(DEF_RETRY_MS);
764 retries++;
765 goto capability_retry;
766 }
Sagar Dharia71fcea52012-09-12 23:21:57 -0600767 }
768 }
769 if (mc == SLIM_MSG_MC_REPLY_INFORMATION ||
770 mc == SLIM_MSG_MC_REPLY_VALUE) {
771 u8 tid = buf[3];
772 dev_dbg(dev->dev, "tid:%d, len:%d\n", tid, len);
773 slim_msg_response(&dev->ctrl, &buf[4], tid,
774 len - 4);
775 pm_runtime_mark_last_busy(dev->dev);
776 }
777 if (mc == SLIM_USR_MC_ADDR_REPLY &&
778 mt == SLIM_MSG_MT_SRC_REFERRED_USER) {
Sagar Dhariad2959352012-12-01 15:43:01 -0700779 struct slim_msg_txn *txn;
Sagar Dharia71fcea52012-09-12 23:21:57 -0600780 u8 failed_ea[6] = {0, 0, 0, 0, 0, 0};
Sagar Dhariad2959352012-12-01 15:43:01 -0700781 mutex_lock(&dev->ctrl.m_ctrl);
782 txn = dev->ctrl.txnt[buf[3]];
783 if (!txn) {
784 pr_err("LADDR response after timeout, tid:0x%x",
785 buf[3]);
786 mutex_unlock(&dev->ctrl.m_ctrl);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600787 return;
Sagar Dhariad2959352012-12-01 15:43:01 -0700788 }
Sagar Dharia71fcea52012-09-12 23:21:57 -0600789 if (memcmp(&buf[4], failed_ea, 6))
790 txn->la = buf[10];
791 dev->ctrl.txnt[buf[3]] = NULL;
Sagar Dhariad2959352012-12-01 15:43:01 -0700792 mutex_unlock(&dev->ctrl.m_ctrl);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600793 complete(txn->comp);
794 }
795 if (mc == SLIM_USR_MC_GENERIC_ACK &&
796 mt == SLIM_MSG_MT_SRC_REFERRED_USER) {
Sagar Dhariad2959352012-12-01 15:43:01 -0700797 struct slim_msg_txn *txn;
798 mutex_lock(&dev->ctrl.m_ctrl);
799 txn = dev->ctrl.txnt[buf[3]];
800 if (!txn) {
801 pr_err("ACK received after timeout, tid:0x%x",
802 buf[3]);
803 mutex_unlock(&dev->ctrl.m_ctrl);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600804 return;
Sagar Dhariad2959352012-12-01 15:43:01 -0700805 }
Sagar Dharia71fcea52012-09-12 23:21:57 -0600806 dev_dbg(dev->dev, "got response:tid:%d, response:0x%x",
807 (int)buf[3], buf[4]);
808 if (!(buf[4] & MSM_SAT_SUCCSS)) {
809 dev_err(dev->dev, "TID:%d, NACK code:0x%x", (int)buf[3],
810 buf[4]);
811 txn->ec = -EIO;
812 }
813 dev->ctrl.txnt[buf[3]] = NULL;
Sagar Dhariad2959352012-12-01 15:43:01 -0700814 mutex_unlock(&dev->ctrl.m_ctrl);
Sagar Dharia71fcea52012-09-12 23:21:57 -0600815 complete(txn->comp);
816 }
817}
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700818
Sagar Dharia33beca02012-10-22 16:21:46 -0600819static int ngd_slim_power_up(struct msm_slim_ctrl *dev)
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700820{
Sagar Dharia33beca02012-10-22 16:21:46 -0600821 void __iomem *ngd;
822 int timeout, ret;
823 enum msm_ctrl_state cur_state = dev->state;
824 u32 laddr;
Sagar Dharia24419e32013-01-14 17:56:32 -0700825 u32 ngd_int = (NGD_INT_TX_NACKED_2 |
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700826 NGD_INT_MSG_BUF_CONTE | NGD_INT_MSG_TX_INVAL |
827 NGD_INT_IE_VE_CHG | NGD_INT_DEV_ERR |
828 NGD_INT_TX_MSG_SENT | NGD_INT_RX_MSG_RCVD);
Sagar Dharia33beca02012-10-22 16:21:46 -0600829
830 if (cur_state == MSM_CTRL_DOWN) {
831 int timeout = wait_for_completion_timeout(&dev->qmi.qmi_comp,
832 HZ);
833 if (!timeout)
834 pr_err("slimbus QMI init timed out");
835 }
836
837 ret = msm_slim_qmi_power_request(dev, true);
838 if (ret) {
839 pr_err("SLIM QMI power request failed:%d", ret);
840 return ret;
841 }
842 if (!dev->ver) {
843 dev->ver = readl_relaxed(dev->base);
844 /* Version info in 16 MSbits */
845 dev->ver >>= 16;
846 }
847 ngd = dev->base + NGD_BASE(dev->ctrl.nr, dev->ver);
848 laddr = readl_relaxed(ngd + NGD_STATUS);
849 if (laddr & NGD_LADDR) {
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700850 /*
Sagar Dharia33beca02012-10-22 16:21:46 -0600851 * ADSP power collapse case, where HW wasn't reset.
852 * Reconnect BAM pipes if disconnected
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700853 */
Sagar Dharia5c8ad192013-05-31 11:39:05 -0600854 ngd_slim_setup_msg_path(dev);
Sagar Dharia33beca02012-10-22 16:21:46 -0600855 return 0;
856 } else if (cur_state != MSM_CTRL_DOWN) {
857 pr_info("ADSP P.C. CTRL state:%d NGD not enumerated:0x%x",
858 dev->state, laddr);
Sagar Dharia33beca02012-10-22 16:21:46 -0600859 }
Sagar Dhariada48bd62013-03-21 18:02:40 -0600860 /* ADSP SSR scenario, need to disconnect pipe before connecting */
861 if (dev->use_rx_msgqs == MSM_MSGQ_DOWN) {
862 struct msm_slim_endp *endpoint = &dev->rx_msgq;
863 sps_disconnect(endpoint->sps);
864 sps_free_endpoint(endpoint->sps);
865 dev->use_rx_msgqs = MSM_MSGQ_RESET;
866 }
Sagar Dharia5c8ad192013-05-31 11:39:05 -0600867 if (dev->use_tx_msgqs == MSM_MSGQ_DOWN) {
868 struct msm_slim_endp *endpoint = &dev->tx_msgq;
869 sps_disconnect(endpoint->sps);
870 sps_free_endpoint(endpoint->sps);
871 dev->use_tx_msgqs = MSM_MSGQ_RESET;
872 }
Sagar Dharia33beca02012-10-22 16:21:46 -0600873 /*
874 * ADSP power collapse case (OR SSR), where HW was reset
875 * BAM programming will happen when capability message is received
876 */
877 writel_relaxed(ngd_int, dev->base + NGD_INT_EN +
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700878 NGD_BASE(dev->ctrl.nr, dev->ver));
Sagar Dharia33beca02012-10-22 16:21:46 -0600879 /*
880 * Enable NGD. Configure NGD in register acc. mode until master
881 * announcement is received
882 */
Sagar Dharia24419e32013-01-14 17:56:32 -0700883 writel_relaxed(1, dev->base + NGD_BASE(dev->ctrl.nr, dev->ver));
Sagar Dharia33beca02012-10-22 16:21:46 -0600884 /* make sure NGD enabling goes through */
885 mb();
886
887 timeout = wait_for_completion_timeout(&dev->reconf, HZ);
888 if (!timeout) {
889 pr_err("failed to received master capability");
890 return -ETIMEDOUT;
891 }
892 if (cur_state == MSM_CTRL_DOWN)
893 complete(&dev->ctrl_up);
894 return 0;
895}
896
897static int ngd_slim_enable(struct msm_slim_ctrl *dev, bool enable)
898{
899 int ret = 0;
900 if (enable) {
901 ret = msm_slim_qmi_init(dev, false);
902 /* controller state should be in sync with framework state */
903 if (!ret) {
904 ret = slim_ctrl_clk_pause(&dev->ctrl, false,
905 SLIM_CLK_UNSPECIFIED);
906 complete(&dev->qmi.qmi_comp);
907 /*
908 * Power-up won't be called if clock pause failed.
909 * This can happen if ADSP SSR happened when audio
910 * session is in progress. Framework will think that
911 * clock pause failed so no need to wakeup controller.
912 * Call power-up explicitly in that case, since slimbus
913 * HW needs to be powered-on to be in sync with
914 * framework state
915 */
916 if (ret)
917 ngd_slim_power_up(dev);
918 if (!pm_runtime_enabled(dev->dev) ||
919 !pm_runtime_suspended(dev->dev))
920 ngd_slim_runtime_resume(dev->dev);
921 else
922 pm_runtime_resume(dev->dev);
923 pm_runtime_mark_last_busy(dev->dev);
924 pm_runtime_put(dev->dev);
925 } else
926 dev_err(dev->dev, "qmi init fail, ret:%d, state:%d",
927 ret, dev->state);
928 } else {
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700929 msm_slim_qmi_exit(dev);
930 }
931
Sagar Dharia33beca02012-10-22 16:21:46 -0600932 return ret;
933}
934
935static int ngd_clk_pause_wakeup(struct slim_controller *ctrl)
936{
937 struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl);
938 return ngd_slim_power_up(dev);
Sagar Dhariacc1001e2012-11-06 13:56:42 -0700939}
940
Sagar Dharia71fcea52012-09-12 23:21:57 -0600941static int ngd_slim_rx_msgq_thread(void *data)
942{
943 struct msm_slim_ctrl *dev = (struct msm_slim_ctrl *)data;
944 struct completion *notify = &dev->rx_msgq_notify;
945 int ret = 0, index = 0;
946 u32 mc = 0;
947 u32 mt = 0;
948 u32 buffer[10];
949 u8 msg_len = 0;
950
951 while (!kthread_should_stop()) {
952 set_current_state(TASK_INTERRUPTIBLE);
953 ret = wait_for_completion_interruptible(notify);
954 if (ret) {
955 dev_err(dev->dev, "rx thread wait err:%d", ret);
956 continue;
957 }
958 /* 1 irq notification per message */
Sagar Dharia24419e32013-01-14 17:56:32 -0700959 if (dev->use_rx_msgqs != MSM_MSGQ_ENABLED) {
Sagar Dharia71fcea52012-09-12 23:21:57 -0600960 msm_slim_rx_dequeue(dev, (u8 *)buffer);
961 ngd_slim_rx(dev, (u8 *)buffer);
962 continue;
963 }
964 ret = msm_slim_rx_msgq_get(dev, buffer, index);
965 if (ret) {
966 dev_err(dev->dev, "rx_msgq_get() failed 0x%x\n", ret);
967 continue;
968 }
969
970 /* Wait for complete message */
971 if (index++ == 0) {
972 msg_len = *buffer & 0x1F;
973 mt = (buffer[0] >> 5) & 0x7;
974 mc = (buffer[0] >> 8) & 0xff;
975 dev_dbg(dev->dev, "MC: %x, MT: %x\n", mc, mt);
976 }
977 if ((index * 4) >= msg_len) {
978 index = 0;
979 ngd_slim_rx(dev, (u8 *)buffer);
980 } else
981 continue;
982 }
983 return 0;
984}
985
Sagar Dharia33beca02012-10-22 16:21:46 -0600986static void ngd_laddr_lookup(struct work_struct *work)
987{
988 struct msm_slim_ctrl *dev =
989 container_of(work, struct msm_slim_ctrl, slave_notify);
990 struct slim_controller *ctrl = &dev->ctrl;
991 struct slim_device *sbdev;
992 int i;
Sagar Dharia722f9e22013-12-11 23:59:22 -0700993 slim_framer_booted(ctrl);
Sagar Dharia33beca02012-10-22 16:21:46 -0600994 mutex_lock(&ctrl->m_ctrl);
995 list_for_each_entry(sbdev, &ctrl->devs, dev_list) {
996 int ret = 0;
997 mutex_unlock(&ctrl->m_ctrl);
998 for (i = 0; i < LADDR_RETRY; i++) {
999 ret = slim_get_logical_addr(sbdev, sbdev->e_addr,
1000 6, &sbdev->laddr);
1001 if (!ret)
1002 break;
1003 else /* time for ADSP to assign LA */
1004 msleep(20);
1005 }
1006 mutex_lock(&ctrl->m_ctrl);
1007 }
1008 mutex_unlock(&ctrl->m_ctrl);
1009}
1010
1011static void ngd_adsp_down(struct work_struct *work)
1012{
1013 struct msm_slim_qmi *qmi =
1014 container_of(work, struct msm_slim_qmi, ssr_down);
1015 struct msm_slim_ctrl *dev =
1016 container_of(qmi, struct msm_slim_ctrl, qmi);
1017 struct slim_controller *ctrl = &dev->ctrl;
1018 struct slim_device *sbdev;
Sagar Dharia33beca02012-10-22 16:21:46 -06001019
1020 ngd_slim_enable(dev, false);
1021 /* disconnect BAM pipes */
Sagar Dhariada48bd62013-03-21 18:02:40 -06001022 if (dev->use_rx_msgqs == MSM_MSGQ_ENABLED)
1023 dev->use_rx_msgqs = MSM_MSGQ_DOWN;
Sagar Dharia5c8ad192013-05-31 11:39:05 -06001024 if (dev->use_tx_msgqs == MSM_MSGQ_ENABLED)
1025 dev->use_tx_msgqs = MSM_MSGQ_DOWN;
Sagar Dharia33beca02012-10-22 16:21:46 -06001026 msm_slim_sps_exit(dev, false);
Sagar Dharia33beca02012-10-22 16:21:46 -06001027 /* device up should be called again after SSR */
1028 list_for_each_entry(sbdev, &ctrl->devs, dev_list)
Sagar Dhariaf68d71f2013-07-31 17:43:46 -06001029 slim_report_absent(sbdev);
Sagar Dharia33beca02012-10-22 16:21:46 -06001030 pr_info("SLIM ADSP SSR (DOWN) done");
1031}
1032
1033static void ngd_adsp_up(struct work_struct *work)
1034{
1035 struct msm_slim_qmi *qmi =
1036 container_of(work, struct msm_slim_qmi, ssr_up);
1037 struct msm_slim_ctrl *dev =
1038 container_of(qmi, struct msm_slim_ctrl, qmi);
1039 ngd_slim_enable(dev, true);
1040}
1041
Sagar Dharia71fcea52012-09-12 23:21:57 -06001042static int __devinit ngd_slim_probe(struct platform_device *pdev)
1043{
1044 struct msm_slim_ctrl *dev;
1045 int ret;
1046 struct resource *bam_mem;
1047 struct resource *slim_mem;
1048 struct resource *irq, *bam_irq;
1049 enum apr_subsys_state q6_state;
Sagar Dharia24419e32013-01-14 17:56:32 -07001050 bool rxreg_access = false;
Sagar Dharia71fcea52012-09-12 23:21:57 -06001051
1052 q6_state = apr_get_q6_state();
1053 if (q6_state == APR_SUBSYS_DOWN) {
1054 dev_dbg(&pdev->dev, "defering %s, adsp_state %d\n", __func__,
1055 q6_state);
1056 return -EPROBE_DEFER;
1057 } else
1058 dev_dbg(&pdev->dev, "adsp is ready\n");
1059
1060 slim_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1061 "slimbus_physical");
1062 if (!slim_mem) {
1063 dev_err(&pdev->dev, "no slimbus physical memory resource\n");
1064 return -ENODEV;
1065 }
1066 bam_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1067 "slimbus_bam_physical");
1068 if (!bam_mem) {
1069 dev_err(&pdev->dev, "no slimbus BAM memory resource\n");
1070 return -ENODEV;
1071 }
1072 irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
1073 "slimbus_irq");
1074 if (!irq) {
1075 dev_err(&pdev->dev, "no slimbus IRQ resource\n");
1076 return -ENODEV;
1077 }
1078 bam_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
1079 "slimbus_bam_irq");
1080 if (!bam_irq) {
1081 dev_err(&pdev->dev, "no slimbus BAM IRQ resource\n");
1082 return -ENODEV;
1083 }
1084
1085 dev = kzalloc(sizeof(struct msm_slim_ctrl), GFP_KERNEL);
Kiran Gunda318cac42013-10-21 17:00:15 +05301086 if (IS_ERR_OR_NULL(dev)) {
Sagar Dharia71fcea52012-09-12 23:21:57 -06001087 dev_err(&pdev->dev, "no memory for MSM slimbus controller\n");
1088 return PTR_ERR(dev);
1089 }
1090 dev->dev = &pdev->dev;
1091 platform_set_drvdata(pdev, dev);
1092 slim_set_ctrldata(&dev->ctrl, dev);
1093 dev->base = ioremap(slim_mem->start, resource_size(slim_mem));
1094 if (!dev->base) {
1095 dev_err(&pdev->dev, "IOremap failed\n");
1096 ret = -ENOMEM;
1097 goto err_ioremap_failed;
1098 }
1099 dev->bam.base = ioremap(bam_mem->start, resource_size(bam_mem));
1100 if (!dev->bam.base) {
1101 dev_err(&pdev->dev, "BAM IOremap failed\n");
1102 ret = -ENOMEM;
1103 goto err_ioremap_bam_failed;
1104 }
1105 if (pdev->dev.of_node) {
1106
1107 ret = of_property_read_u32(pdev->dev.of_node, "cell-index",
1108 &dev->ctrl.nr);
1109 if (ret) {
1110 dev_err(&pdev->dev, "Cell index not specified:%d", ret);
1111 goto err_ctrl_failed;
1112 }
Sagar Dharia24419e32013-01-14 17:56:32 -07001113 rxreg_access = of_property_read_bool(pdev->dev.of_node,
1114 "qcom,rxreg-access");
Sagar Dhariaa3c6a382013-06-21 12:18:20 -06001115 of_property_read_u32(pdev->dev.of_node, "qcom,apps-ch-pipes",
1116 &dev->pdata.apps_pipes);
1117 of_property_read_u32(pdev->dev.of_node, "qcom,ea-pc",
1118 &dev->pdata.eapc);
Sagar Dharia71fcea52012-09-12 23:21:57 -06001119 } else {
1120 dev->ctrl.nr = pdev->id;
1121 }
Sagar Dhariaa3c6a382013-06-21 12:18:20 -06001122 /*
1123 * Keep PGD's logical address as manager's. Query it when first data
1124 * channel request comes in
1125 */
1126 dev->pgdla = SLIM_LA_MGR;
Sagar Dharia71fcea52012-09-12 23:21:57 -06001127 dev->ctrl.nchans = MSM_SLIM_NCHANS;
1128 dev->ctrl.nports = MSM_SLIM_NPORTS;
1129 dev->framer.rootfreq = SLIM_ROOT_FREQ >> 3;
1130 dev->framer.superfreq =
1131 dev->framer.rootfreq / SLIM_CL_PER_SUPERFRAME_DIV8;
1132 dev->ctrl.a_framer = &dev->framer;
1133 dev->ctrl.clkgear = SLIM_MAX_CLK_GEAR;
1134 dev->ctrl.set_laddr = ngd_set_laddr;
1135 dev->ctrl.get_laddr = ngd_get_laddr;
1136 dev->ctrl.allocbw = ngd_allocbw;
1137 dev->ctrl.xfer_msg = ngd_xfer_msg;
Sagar Dhariacc1001e2012-11-06 13:56:42 -07001138 dev->ctrl.wakeup = ngd_clk_pause_wakeup;
Sagar Dharia100e7212013-05-17 18:20:57 -06001139 dev->ctrl.alloc_port = msm_alloc_port;
1140 dev->ctrl.dealloc_port = msm_dealloc_port;
Sagar Dharia71fcea52012-09-12 23:21:57 -06001141 dev->ctrl.port_xfer = msm_slim_port_xfer;
1142 dev->ctrl.port_xfer_status = msm_slim_port_xfer_status;
Sagar Dharia71fcea52012-09-12 23:21:57 -06001143 dev->bam_mem = bam_mem;
1144
1145 init_completion(&dev->reconf);
Sagar Dharia33beca02012-10-22 16:21:46 -06001146 init_completion(&dev->ctrl_up);
Sagar Dharia71fcea52012-09-12 23:21:57 -06001147 mutex_init(&dev->tx_lock);
1148 spin_lock_init(&dev->rx_lock);
1149 dev->ee = 1;
1150 dev->irq = irq->start;
1151 dev->bam.irq = bam_irq->start;
1152
Sagar Dharia24419e32013-01-14 17:56:32 -07001153 if (rxreg_access)
1154 dev->use_rx_msgqs = MSM_MSGQ_DISABLED;
1155 else
1156 dev->use_rx_msgqs = MSM_MSGQ_RESET;
Sagar Dharia5c8ad192013-05-31 11:39:05 -06001157
1158 /* Enable TX message queues by default as recommended by HW */
1159 dev->use_tx_msgqs = MSM_MSGQ_RESET;
1160
Sagar Dharia71fcea52012-09-12 23:21:57 -06001161 init_completion(&dev->rx_msgq_notify);
1162
1163 /* Register with framework */
1164 ret = slim_add_numbered_controller(&dev->ctrl);
1165 if (ret) {
1166 dev_err(dev->dev, "error adding controller\n");
1167 goto err_ctrl_failed;
1168 }
1169
1170 dev->ctrl.dev.parent = &pdev->dev;
1171 dev->ctrl.dev.of_node = pdev->dev.of_node;
Sagar Dharia33beca02012-10-22 16:21:46 -06001172 dev->state = MSM_CTRL_DOWN;
Sagar Dharia71fcea52012-09-12 23:21:57 -06001173
1174 ret = request_irq(dev->irq, ngd_slim_interrupt,
1175 IRQF_TRIGGER_HIGH, "ngd_slim_irq", dev);
1176
1177 if (ret) {
1178 dev_err(&pdev->dev, "request IRQ failed\n");
1179 goto err_request_irq_failed;
1180 }
1181
Sagar Dhariacc1001e2012-11-06 13:56:42 -07001182 init_completion(&dev->qmi.qmi_comp);
Sagar Dharia33beca02012-10-22 16:21:46 -06001183 pm_runtime_use_autosuspend(dev->dev);
1184 pm_runtime_set_autosuspend_delay(dev->dev, MSM_SLIM_AUTOSUSPEND);
1185 pm_runtime_set_suspended(dev->dev);
1186 pm_runtime_enable(dev->dev);
1187
1188 INIT_WORK(&dev->slave_notify, ngd_laddr_lookup);
1189 INIT_WORK(&dev->qmi.ssr_down, ngd_adsp_down);
1190 INIT_WORK(&dev->qmi.ssr_up, ngd_adsp_up);
Sagar Dhariacc1001e2012-11-06 13:56:42 -07001191 dev->qmi.nb.notifier_call = ngd_qmi_available;
Sagar Dharia33beca02012-10-22 16:21:46 -06001192 pm_runtime_get_noresume(dev->dev);
Sagar Dhariacc1001e2012-11-06 13:56:42 -07001193 ret = qmi_svc_event_notifier_register(SLIMBUS_QMI_SVC_ID,
1194 SLIMBUS_QMI_INS_ID, &dev->qmi.nb);
1195 if (ret) {
1196 pr_err("Slimbus QMI service registration failed:%d", ret);
1197 goto qmi_register_failed;
1198 }
1199
Sagar Dharia33beca02012-10-22 16:21:46 -06001200
Sagar Dharia71fcea52012-09-12 23:21:57 -06001201 /* Fire up the Rx message queue thread */
1202 dev->rx_msgq_thread = kthread_run(ngd_slim_rx_msgq_thread, dev,
1203 NGD_SLIM_NAME "_ngd_msgq_thread");
1204 if (IS_ERR(dev->rx_msgq_thread)) {
1205 ret = PTR_ERR(dev->rx_msgq_thread);
1206 dev_err(dev->dev, "Failed to start Rx message queue thread\n");
1207 goto err_thread_create_failed;
1208 }
1209
Sagar Dharia71fcea52012-09-12 23:21:57 -06001210 if (pdev->dev.of_node)
1211 of_register_slim_devices(&dev->ctrl);
1212
1213 /* Add devices registered with board-info now that controller is up */
1214 slim_ctrl_add_boarddevs(&dev->ctrl);
1215
Sagar Dharia71fcea52012-09-12 23:21:57 -06001216 dev_dbg(dev->dev, "NGD SB controller is up!\n");
1217 return 0;
1218
1219err_thread_create_failed:
Sagar Dhariacc1001e2012-11-06 13:56:42 -07001220 qmi_svc_event_notifier_unregister(SLIMBUS_QMI_SVC_ID,
1221 SLIMBUS_QMI_INS_ID, &dev->qmi.nb);
1222qmi_register_failed:
Sagar Dharia71fcea52012-09-12 23:21:57 -06001223 free_irq(dev->irq, dev);
1224err_request_irq_failed:
1225 slim_del_controller(&dev->ctrl);
1226err_ctrl_failed:
1227 iounmap(dev->bam.base);
1228err_ioremap_bam_failed:
1229 iounmap(dev->base);
1230err_ioremap_failed:
1231 kfree(dev);
1232 return ret;
1233}
1234
1235static int __devexit ngd_slim_remove(struct platform_device *pdev)
1236{
1237 struct msm_slim_ctrl *dev = platform_get_drvdata(pdev);
Sagar Dhariacc1001e2012-11-06 13:56:42 -07001238 ngd_slim_enable(dev, false);
1239 qmi_svc_event_notifier_unregister(SLIMBUS_QMI_SVC_ID,
1240 SLIMBUS_QMI_INS_ID, &dev->qmi.nb);
Sagar Dharia71fcea52012-09-12 23:21:57 -06001241 pm_runtime_disable(&pdev->dev);
Sagar Dharia71fcea52012-09-12 23:21:57 -06001242 free_irq(dev->irq, dev);
1243 slim_del_controller(&dev->ctrl);
1244 kthread_stop(dev->rx_msgq_thread);
1245 iounmap(dev->bam.base);
1246 iounmap(dev->base);
1247 kfree(dev);
1248 return 0;
1249}
1250
1251#ifdef CONFIG_PM_RUNTIME
1252static int ngd_slim_runtime_idle(struct device *device)
1253{
1254 dev_dbg(device, "pm_runtime: idle...\n");
1255 pm_request_autosuspend(device);
1256 return -EAGAIN;
1257}
1258#endif
1259
1260/*
1261 * If PM_RUNTIME is not defined, these 2 functions become helper
1262 * functions to be called from system suspend/resume. So they are not
1263 * inside ifdef CONFIG_PM_RUNTIME
1264 */
Sagar Dharia71fcea52012-09-12 23:21:57 -06001265static int ngd_slim_runtime_resume(struct device *device)
1266{
1267 struct platform_device *pdev = to_platform_device(device);
1268 struct msm_slim_ctrl *dev = platform_get_drvdata(pdev);
1269 int ret = 0;
Sagar Dharia33beca02012-10-22 16:21:46 -06001270 if (dev->state >= MSM_CTRL_ASLEEP)
Sagar Dharia71fcea52012-09-12 23:21:57 -06001271 ret = slim_ctrl_clk_pause(&dev->ctrl, true, 0);
1272 if (ret) {
1273 dev_err(device, "clk pause not exited:%d", ret);
1274 dev->state = MSM_CTRL_ASLEEP;
1275 } else {
1276 dev->state = MSM_CTRL_AWAKE;
1277 }
1278 return ret;
1279}
1280
Sagar Dharia33beca02012-10-22 16:21:46 -06001281#ifdef CONFIG_PM_SLEEP
1282static int ngd_slim_runtime_suspend(struct device *device)
1283{
1284 struct platform_device *pdev = to_platform_device(device);
1285 struct msm_slim_ctrl *dev = platform_get_drvdata(pdev);
1286 int ret = 0;
1287 dev->state = MSM_CTRL_SLEEPING;
1288 ret = slim_ctrl_clk_pause(&dev->ctrl, false, SLIM_CLK_UNSPECIFIED);
1289 if (ret) {
1290 if (ret != -EBUSY)
1291 dev_err(device, "clk pause not entered:%d", ret);
1292 dev->state = MSM_CTRL_AWAKE;
1293 } else {
1294 dev->state = MSM_CTRL_ASLEEP;
1295 }
1296 return ret;
1297}
1298
Sagar Dharia71fcea52012-09-12 23:21:57 -06001299static int ngd_slim_suspend(struct device *dev)
1300{
1301 int ret = -EBUSY;
1302 if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) {
1303 dev_dbg(dev, "system suspend");
1304 ret = ngd_slim_runtime_suspend(dev);
Sagar Dhariaa1398282013-01-22 13:26:20 -07001305 /*
1306 * If runtime-PM still thinks it's active, then make sure its
1307 * status is in sync with HW status.
1308 * Since this suspend calls QMI api, it results in holding a
1309 * wakelock. That results in failure of first suspend.
1310 * Subsequent suspend should not call low-power transition
1311 * again since the HW is already in suspended state.
1312 */
1313 if (!ret) {
1314 pm_runtime_disable(dev);
1315 pm_runtime_set_suspended(dev);
1316 pm_runtime_enable(dev);
1317 }
Sagar Dharia71fcea52012-09-12 23:21:57 -06001318 }
1319 if (ret == -EBUSY) {
1320 /*
1321 * There is a possibility that some audio stream is active
1322 * during suspend. We dont want to return suspend failure in
1323 * that case so that display and relevant components can still
1324 * go to suspend.
1325 * If there is some other error, then it should be passed-on
1326 * to system level suspend
1327 */
1328 ret = 0;
1329 }
1330 return ret;
1331}
1332
1333static int ngd_slim_resume(struct device *dev)
1334{
Sagar Dhariaa1398282013-01-22 13:26:20 -07001335 /*
1336 * Rely on runtime-PM to call resume in case it is enabled.
1337 * Even if it's not enabled, rely on 1st client transaction to do
1338 * clock/power on
1339 */
Sagar Dharia71fcea52012-09-12 23:21:57 -06001340 return 0;
1341}
1342#endif /* CONFIG_PM_SLEEP */
1343
1344static const struct dev_pm_ops ngd_slim_dev_pm_ops = {
1345 SET_SYSTEM_SLEEP_PM_OPS(
1346 ngd_slim_suspend,
1347 ngd_slim_resume
1348 )
1349 SET_RUNTIME_PM_OPS(
1350 ngd_slim_runtime_suspend,
1351 ngd_slim_runtime_resume,
1352 ngd_slim_runtime_idle
1353 )
1354};
1355
1356static struct of_device_id ngd_slim_dt_match[] = {
1357 {
1358 .compatible = "qcom,slim-ngd",
1359 },
1360 {}
1361};
1362
1363static struct platform_driver ngd_slim_driver = {
1364 .probe = ngd_slim_probe,
1365 .remove = ngd_slim_remove,
1366 .driver = {
1367 .name = NGD_SLIM_NAME,
1368 .owner = THIS_MODULE,
1369 .pm = &ngd_slim_dev_pm_ops,
1370 .of_match_table = ngd_slim_dt_match,
1371 },
1372};
1373
1374static int ngd_slim_init(void)
1375{
1376 return platform_driver_register(&ngd_slim_driver);
1377}
1378late_initcall(ngd_slim_init);
1379
1380static void ngd_slim_exit(void)
1381{
1382 platform_driver_unregister(&ngd_slim_driver);
1383}
1384module_exit(ngd_slim_exit);
1385
1386MODULE_LICENSE("GPL v2");
1387MODULE_DESCRIPTION("MSM Slimbus controller");
1388MODULE_ALIAS("platform:msm-slim-ngd");