Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 2 | * |
| 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 Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 12 | #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 Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 35 | #define LADDR_RETRY 5 |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 36 | |
| 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 */ |
| 41 | enum 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 | |
| 54 | enum 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 | |
| 60 | enum 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 | |
| 71 | enum 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 Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 81 | enum ngd_status { |
| 82 | NGD_LADDR = 1 << 1, |
| 83 | }; |
| 84 | |
| 85 | static int ngd_slim_runtime_resume(struct device *device); |
| 86 | |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 87 | static 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 Dharia | 2b8a4b5 | 2013-05-15 20:01:45 -0600 | [diff] [blame] | 92 | u32 pstat; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 93 | |
| 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 Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 132 | if (dev->use_rx_msgqs == MSM_MSGQ_ENABLED) |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 133 | 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 Dharia | 2b8a4b5 | 2013-05-15 20:01:45 -0600 | [diff] [blame] | 151 | |
| 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 Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 155 | return IRQ_HANDLED; |
| 156 | } |
| 157 | |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 158 | static 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 Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 162 | struct msm_slim_ctrl *dev = |
| 163 | container_of(qmi, struct msm_slim_ctrl, qmi); |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 164 | pr_info("Slimbus QMI NGD CB received event:%ld", code); |
| 165 | switch (code) { |
| 166 | case QMI_SERVER_ARRIVE: |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 167 | schedule_work(&qmi->ssr_up); |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 168 | break; |
| 169 | case QMI_SERVER_EXIT: |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 170 | 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 Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 176 | break; |
| 177 | default: |
| 178 | break; |
| 179 | } |
| 180 | return 0; |
| 181 | } |
| 182 | |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 183 | static 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 Dharia | d295935 | 2012-12-01 15:43:01 -0700 | [diff] [blame] | 187 | mutex_lock(&ctrl->m_ctrl); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 188 | 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 Dharia | d295935 | 2012-12-01 15:43:01 -0700 | [diff] [blame] | 193 | if (!ctrl->txnt) { |
| 194 | mutex_unlock(&ctrl->m_ctrl); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 195 | return -ENOMEM; |
Sagar Dharia | d295935 | 2012-12-01 15:43:01 -0700 | [diff] [blame] | 196 | } |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 197 | 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 Dharia | d295935 | 2012-12-01 15:43:01 -0700 | [diff] [blame] | 208 | mutex_unlock(&ctrl->m_ctrl); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 209 | 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 Dharia | d295935 | 2012-12-01 15:43:01 -0700 | [diff] [blame] | 216 | mutex_unlock(&ctrl->m_ctrl); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 217 | return 0; |
| 218 | } |
| 219 | static 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 Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 228 | u8 la = txn->la; |
Sagar Dharia | 8e554ed | 2013-07-19 15:48:15 -0600 | [diff] [blame] | 229 | u8 txn_mt; |
| 230 | u16 txn_mc = txn->mc; |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 231 | u8 wbuf[SLIM_MSGQ_BUF_LEN]; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 232 | |
Sagar Dharia | a139828 | 2013-01-22 13:26:20 -0700 | [diff] [blame] | 233 | 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 Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 244 | 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 Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 252 | } |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 253 | else if (txn->mc & SLIM_MSG_CLK_PAUSE_SEQ_FLG) |
| 254 | return 0; |
| 255 | |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 256 | 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 Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 261 | /* 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 |
| 271 | * MSM_CTRL_AWAKE), will need that lock |
| 272 | */ |
| 273 | if ((txn->mt == SLIM_MSG_MT_CORE) && |
| 274 | ((mc >= SLIM_MSG_MC_CONNECT_SOURCE && |
| 275 | mc <= SLIM_MSG_MC_CHANGE_CONTENT) || |
| 276 | (mc >= SLIM_MSG_MC_BEGIN_RECONFIGURATION && |
| 277 | mc <= SLIM_MSG_MC_RECONFIGURE_NOW))) |
| 278 | return -EREMOTEIO; |
| 279 | if ((txn->mt == SLIM_MSG_MT_DEST_REFERRED_USER) && |
| 280 | ((mc >= SLIM_USR_MC_DEFINE_CHAN && |
| 281 | mc <= SLIM_USR_MC_DISCONNECT_PORT))) |
| 282 | return -EREMOTEIO; |
| 283 | timeout = wait_for_completion_timeout(&dev->ctrl_up, |
| 284 | HZ); |
| 285 | if (!timeout) |
| 286 | return -ETIMEDOUT; |
| 287 | } |
| 288 | msm_slim_get_ctrl(dev); |
| 289 | } |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 290 | mutex_lock(&dev->tx_lock); |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 291 | |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 292 | if (txn->mc != SLIM_USR_MC_REPORT_SATELLITE && |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 293 | (dev->state != MSM_CTRL_AWAKE)) { |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 294 | dev_err(dev->dev, "controller not ready"); |
| 295 | mutex_unlock(&dev->tx_lock); |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 296 | msm_slim_put_ctrl(dev); |
| 297 | return -EREMOTEIO; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 298 | } |
| 299 | if (txn->mt == SLIM_MSG_MT_CORE && |
| 300 | (txn->mc == SLIM_MSG_MC_CONNECT_SOURCE || |
| 301 | txn->mc == SLIM_MSG_MC_CONNECT_SINK || |
| 302 | txn->mc == SLIM_MSG_MC_DISCONNECT_PORT)) { |
| 303 | int i = 0; |
| 304 | txn->mt = SLIM_MSG_MT_DEST_REFERRED_USER; |
| 305 | if (txn->mc == SLIM_MSG_MC_CONNECT_SOURCE) |
| 306 | txn->mc = SLIM_USR_MC_CONNECT_SRC; |
| 307 | else if (txn->mc == SLIM_MSG_MC_CONNECT_SINK) |
| 308 | txn->mc = SLIM_USR_MC_CONNECT_SINK; |
| 309 | else if (txn->mc == SLIM_MSG_MC_DISCONNECT_PORT) |
| 310 | txn->mc = SLIM_USR_MC_DISCONNECT_PORT; |
Sagar Dharia | a3c6a38 | 2013-06-21 12:18:20 -0600 | [diff] [blame] | 311 | if (txn->la == SLIM_LA_MGR) { |
| 312 | if (dev->pgdla == SLIM_LA_MGR) { |
| 313 | u8 ea[] = {0, QC_DEVID_PGD, 0, 0, QC_MFGID_MSB, |
| 314 | QC_MFGID_LSB}; |
| 315 | ea[2] = (u8)(dev->pdata.eapc & 0xFF); |
| 316 | ea[3] = (u8)((dev->pdata.eapc & 0xFF00) >> 8); |
| 317 | mutex_unlock(&dev->tx_lock); |
| 318 | ret = dev->ctrl.get_laddr(&dev->ctrl, ea, 6, |
| 319 | &dev->pgdla); |
| 320 | pr_debug("SLIM PGD LA:0x%x, ret:%d", dev->pgdla, |
| 321 | ret); |
| 322 | if (ret) { |
| 323 | pr_err("Incorrect SLIM-PGD EAPC:0x%x", |
| 324 | dev->pdata.eapc); |
| 325 | return ret; |
| 326 | } |
| 327 | mutex_lock(&dev->tx_lock); |
| 328 | } |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 329 | txn->la = dev->pgdla; |
Sagar Dharia | a3c6a38 | 2013-06-21 12:18:20 -0600 | [diff] [blame] | 330 | } |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 331 | wbuf[i++] = txn->la; |
| 332 | la = SLIM_LA_MGR; |
| 333 | wbuf[i++] = txn->wbuf[0]; |
| 334 | if (txn->mc != SLIM_USR_MC_DISCONNECT_PORT) |
| 335 | wbuf[i++] = txn->wbuf[1]; |
| 336 | ret = ngd_get_tid(ctrl, txn, &wbuf[i++], &done); |
| 337 | if (ret) { |
| 338 | pr_err("TID for connect/disconnect fail:%d", ret); |
| 339 | goto ngd_xfer_err; |
| 340 | } |
| 341 | txn->len = i; |
| 342 | txn->wbuf = wbuf; |
| 343 | txn->rl = txn->len + 4; |
| 344 | } |
| 345 | txn->rl--; |
| 346 | pbuf = msm_get_msg_buf(dev, txn->rl); |
| 347 | if (!pbuf) { |
| 348 | dev_err(dev->dev, "Message buffer unavailable"); |
| 349 | ret = -ENOMEM; |
| 350 | goto ngd_xfer_err; |
| 351 | } |
| 352 | dev->err = 0; |
| 353 | |
| 354 | if (txn->dt == SLIM_MSG_DEST_ENUMADDR) { |
| 355 | ret = -EPROTONOSUPPORT; |
| 356 | goto ngd_xfer_err; |
| 357 | } |
| 358 | if (txn->dt == SLIM_MSG_DEST_LOGICALADDR) |
| 359 | *pbuf = SLIM_MSG_ASM_FIRST_WORD(txn->rl, txn->mt, txn->mc, 0, |
| 360 | la); |
| 361 | else |
| 362 | *pbuf = SLIM_MSG_ASM_FIRST_WORD(txn->rl, txn->mt, txn->mc, 1, |
| 363 | la); |
| 364 | if (txn->dt == SLIM_MSG_DEST_LOGICALADDR) |
| 365 | puc = ((u8 *)pbuf) + 3; |
| 366 | else |
| 367 | puc = ((u8 *)pbuf) + 2; |
| 368 | if (txn->rbuf) |
| 369 | *(puc++) = txn->tid; |
| 370 | if ((txn->mt == SLIM_MSG_MT_CORE) && |
| 371 | ((txn->mc >= SLIM_MSG_MC_REQUEST_INFORMATION && |
| 372 | txn->mc <= SLIM_MSG_MC_REPORT_INFORMATION) || |
| 373 | (txn->mc >= SLIM_MSG_MC_REQUEST_VALUE && |
| 374 | txn->mc <= SLIM_MSG_MC_CHANGE_VALUE))) { |
| 375 | *(puc++) = (txn->ec & 0xFF); |
| 376 | *(puc++) = (txn->ec >> 8)&0xFF; |
| 377 | } |
| 378 | if (txn->wbuf) |
| 379 | memcpy(puc, txn->wbuf, txn->len); |
| 380 | if (txn->mt == SLIM_MSG_MT_DEST_REFERRED_USER && |
| 381 | (txn->mc == SLIM_USR_MC_CONNECT_SRC || |
| 382 | txn->mc == SLIM_USR_MC_CONNECT_SINK || |
| 383 | txn->mc == SLIM_USR_MC_DISCONNECT_PORT) && txn->wbuf && |
| 384 | wbuf[0] == dev->pgdla) { |
Sagar Dharia | 2d74c14 | 2013-05-17 02:24:06 -0600 | [diff] [blame] | 385 | if (txn->mc != SLIM_USR_MC_DISCONNECT_PORT) |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 386 | dev->err = msm_slim_connect_pipe_port(dev, wbuf[1]); |
| 387 | else { |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 388 | /* |
| 389 | * Remove channel disconnects master-side ports from |
| 390 | * channel. No need to send that again on the bus |
Sagar Dharia | 2d74c14 | 2013-05-17 02:24:06 -0600 | [diff] [blame] | 391 | * Only disable port |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 392 | */ |
Sagar Dharia | 2d74c14 | 2013-05-17 02:24:06 -0600 | [diff] [blame] | 393 | writel_relaxed(0, PGD_PORT(PGD_PORT_CFGn, |
| 394 | (wbuf[1] + dev->port_b), dev->ver)); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 395 | mutex_unlock(&dev->tx_lock); |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 396 | msm_slim_put_ctrl(dev); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 397 | return 0; |
| 398 | } |
| 399 | if (dev->err) { |
| 400 | dev_err(dev->dev, "pipe-port connect err:%d", dev->err); |
| 401 | goto ngd_xfer_err; |
| 402 | } |
Sagar Dharia | a3c6a38 | 2013-06-21 12:18:20 -0600 | [diff] [blame] | 403 | /* Add port-base to port number if this is manager side port */ |
| 404 | puc[1] += dev->port_b; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 405 | } |
| 406 | dev->err = 0; |
Sagar Dharia | 8e554ed | 2013-07-19 15:48:15 -0600 | [diff] [blame] | 407 | /* |
| 408 | * If it's a read txn, it may be freed if a response is received by |
| 409 | * received thread before reaching end of this function. |
| 410 | * mc, mt may have changed to convert standard slimbus code/type to |
| 411 | * satellite user-defined message. Reinitialize again |
| 412 | */ |
| 413 | txn_mc = txn->mc; |
| 414 | txn_mt = txn->mt; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 415 | dev->wr_comp = &tx_sent; |
| 416 | ret = msm_send_msg_buf(dev, pbuf, txn->rl, |
| 417 | NGD_BASE(dev->ctrl.nr, dev->ver) + NGD_TX_MSG); |
| 418 | if (!ret) { |
| 419 | int timeout = wait_for_completion_timeout(&tx_sent, HZ); |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 420 | if (!timeout) { |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 421 | ret = -ETIMEDOUT; |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 422 | /* |
| 423 | * disconnect/recoonect pipe so that subsequent |
| 424 | * transactions don't timeout due to unavailable |
| 425 | * descriptors |
| 426 | */ |
| 427 | msm_slim_disconnect_endp(dev, &dev->tx_msgq, |
| 428 | &dev->use_tx_msgqs); |
| 429 | msm_slim_connect_endp(dev, &dev->tx_msgq, NULL); |
| 430 | } else { |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 431 | ret = dev->err; |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 432 | } |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 433 | } |
| 434 | dev->wr_comp = NULL; |
| 435 | if (ret) { |
| 436 | u32 conf, stat, rx_msgq, int_stat, int_en, int_clr; |
| 437 | void __iomem *ngd = dev->base + NGD_BASE(dev->ctrl.nr, |
| 438 | dev->ver); |
| 439 | dev_err(dev->dev, "TX failed :MC:0x%x,mt:0x%x, ret:%d, ver:%d", |
Sagar Dharia | 8e554ed | 2013-07-19 15:48:15 -0600 | [diff] [blame] | 440 | txn_mc, txn_mt, ret, dev->ver); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 441 | conf = readl_relaxed(ngd); |
| 442 | stat = readl_relaxed(ngd + NGD_STATUS); |
| 443 | rx_msgq = readl_relaxed(ngd + NGD_RX_MSGQ_CFG); |
| 444 | int_stat = readl_relaxed(ngd + NGD_INT_STAT); |
| 445 | int_en = readl_relaxed(ngd + NGD_INT_EN); |
| 446 | int_clr = readl_relaxed(ngd + NGD_INT_CLR); |
| 447 | |
| 448 | pr_err("conf:0x%x,stat:0x%x,rxmsgq:0x%x", conf, stat, rx_msgq); |
| 449 | pr_err("int_stat:0x%x,int_en:0x%x,int_cll:0x%x", int_stat, |
| 450 | int_en, int_clr); |
Sagar Dharia | 8e554ed | 2013-07-19 15:48:15 -0600 | [diff] [blame] | 451 | } else if (txn_mt == SLIM_MSG_MT_DEST_REFERRED_USER && |
| 452 | (txn_mc == SLIM_USR_MC_CONNECT_SRC || |
| 453 | txn_mc == SLIM_USR_MC_CONNECT_SINK || |
| 454 | txn_mc == SLIM_USR_MC_DISCONNECT_PORT)) { |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 455 | int timeout; |
| 456 | mutex_unlock(&dev->tx_lock); |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 457 | msm_slim_put_ctrl(dev); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 458 | timeout = wait_for_completion_timeout(txn->comp, HZ); |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 459 | if (!timeout) |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 460 | ret = -ETIMEDOUT; |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 461 | else |
| 462 | ret = txn->ec; |
| 463 | if (ret) { |
| 464 | pr_err("connect/disconnect:0x%x,tid:%d err:%d", txn->mc, |
| 465 | txn->tid, ret); |
Sagar Dharia | d295935 | 2012-12-01 15:43:01 -0700 | [diff] [blame] | 466 | mutex_lock(&ctrl->m_ctrl); |
| 467 | ctrl->txnt[txn->tid] = NULL; |
| 468 | mutex_unlock(&ctrl->m_ctrl); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 469 | } |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 470 | return ret ? ret : dev->err; |
| 471 | } |
| 472 | ngd_xfer_err: |
| 473 | mutex_unlock(&dev->tx_lock); |
Sagar Dharia | 8e554ed | 2013-07-19 15:48:15 -0600 | [diff] [blame] | 474 | if (txn_mc != SLIM_USR_MC_REPORT_SATELLITE) |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 475 | msm_slim_put_ctrl(dev); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 476 | return ret ? ret : dev->err; |
| 477 | } |
| 478 | |
| 479 | static int ngd_xferandwait_ack(struct slim_controller *ctrl, |
| 480 | struct slim_msg_txn *txn) |
| 481 | { |
| 482 | int ret = ngd_xfer_msg(ctrl, txn); |
| 483 | if (!ret) { |
| 484 | int timeout; |
| 485 | timeout = wait_for_completion_timeout(txn->comp, HZ); |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 486 | if (!timeout) |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 487 | ret = -ETIMEDOUT; |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 488 | else |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 489 | ret = txn->ec; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 490 | } |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 491 | if (ret) { |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 492 | pr_err("master msg:0x%x,tid:%d ret:%d", txn->mc, |
| 493 | txn->tid, ret); |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 494 | mutex_lock(&ctrl->m_ctrl); |
| 495 | ctrl->txnt[txn->tid] = NULL; |
| 496 | mutex_unlock(&ctrl->m_ctrl); |
| 497 | } |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 498 | |
| 499 | return ret; |
| 500 | } |
| 501 | |
| 502 | static int ngd_allocbw(struct slim_device *sb, int *subfrmc, int *clkgear) |
| 503 | { |
| 504 | int ret; |
| 505 | struct slim_pending_ch *pch; |
| 506 | struct slim_msg_txn txn; |
| 507 | struct slim_controller *ctrl = sb->ctrl; |
| 508 | DECLARE_COMPLETION_ONSTACK(done); |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 509 | u8 wbuf[SLIM_MSGQ_BUF_LEN]; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 510 | |
Sagar Dharia | 5ee34ae | 2013-04-26 18:05:37 -0600 | [diff] [blame] | 511 | *clkgear = ctrl->clkgear; |
| 512 | *subfrmc = 0; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 513 | txn.mt = SLIM_MSG_MT_DEST_REFERRED_USER; |
| 514 | txn.dt = SLIM_MSG_DEST_LOGICALADDR; |
| 515 | txn.la = SLIM_LA_MGR; |
| 516 | txn.len = 0; |
| 517 | txn.ec = 0; |
| 518 | txn.wbuf = wbuf; |
| 519 | txn.rbuf = NULL; |
| 520 | |
Sagar Dharia | 5ee34ae | 2013-04-26 18:05:37 -0600 | [diff] [blame] | 521 | if (ctrl->sched.msgsl != ctrl->sched.pending_msgsl) { |
| 522 | pr_debug("slim reserve BW for messaging: req: %d", |
| 523 | ctrl->sched.pending_msgsl); |
| 524 | txn.mc = SLIM_USR_MC_REQ_BW; |
| 525 | wbuf[txn.len++] = ((sb->laddr & 0x1f) | |
| 526 | ((u8)(ctrl->sched.pending_msgsl & 0x7) << 5)); |
| 527 | wbuf[txn.len++] = (u8)(ctrl->sched.pending_msgsl >> 3); |
| 528 | ret = ngd_get_tid(ctrl, &txn, &wbuf[txn.len++], &done); |
| 529 | if (ret) |
| 530 | return ret; |
| 531 | txn.rl = txn.len + 4; |
| 532 | ret = ngd_xferandwait_ack(ctrl, &txn); |
| 533 | if (ret) |
| 534 | return ret; |
| 535 | |
| 536 | txn.mc = SLIM_USR_MC_RECONFIG_NOW; |
| 537 | txn.len = 2; |
| 538 | wbuf[1] = sb->laddr; |
| 539 | txn.rl = txn.len + 4; |
| 540 | ret = ngd_get_tid(ctrl, &txn, &wbuf[0], &done); |
| 541 | if (ret) |
| 542 | return ret; |
| 543 | ret = ngd_xferandwait_ack(ctrl, &txn); |
| 544 | if (ret) |
| 545 | return ret; |
| 546 | |
| 547 | txn.len = 0; |
| 548 | } |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 549 | list_for_each_entry(pch, &sb->mark_define, pending) { |
| 550 | struct slim_ich *slc; |
| 551 | slc = &ctrl->chans[pch->chan]; |
| 552 | if (!slc) { |
| 553 | pr_err("no channel in define?"); |
| 554 | return -ENXIO; |
| 555 | } |
| 556 | if (txn.len == 0) { |
Sagar Dharia | b47c896 | 2012-10-30 13:44:08 -0600 | [diff] [blame] | 557 | /* Per protocol, only last 5 bits for client no. */ |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 558 | wbuf[txn.len++] = (u8) (slc->prop.dataf << 5) | |
Sagar Dharia | b47c896 | 2012-10-30 13:44:08 -0600 | [diff] [blame] | 559 | (sb->laddr & 0x1f); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 560 | wbuf[txn.len] = slc->seglen; |
| 561 | if (slc->coeff == SLIM_COEFF_3) |
| 562 | wbuf[txn.len] |= 1 << 5; |
| 563 | wbuf[txn.len++] |= slc->prop.auxf << 6; |
| 564 | wbuf[txn.len++] = slc->rootexp << 4 | slc->prop.prot; |
| 565 | wbuf[txn.len++] = slc->prrate; |
| 566 | ret = ngd_get_tid(ctrl, &txn, &wbuf[txn.len++], &done); |
| 567 | if (ret) { |
| 568 | pr_err("no tid for channel define?"); |
| 569 | return -ENXIO; |
| 570 | } |
| 571 | } |
| 572 | wbuf[txn.len++] = slc->chan; |
Sagar Dharia | b47c896 | 2012-10-30 13:44:08 -0600 | [diff] [blame] | 573 | pr_debug("slim define chan:%d, tid:0x%x", slc->chan, txn.tid); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 574 | } |
| 575 | if (txn.len) { |
| 576 | txn.mc = SLIM_USR_MC_DEF_ACT_CHAN; |
| 577 | txn.rl = txn.len + 4; |
| 578 | ret = ngd_xferandwait_ack(ctrl, &txn); |
| 579 | if (ret) |
| 580 | return ret; |
| 581 | |
| 582 | txn.mc = SLIM_USR_MC_RECONFIG_NOW; |
| 583 | txn.len = 2; |
| 584 | wbuf[1] = sb->laddr; |
| 585 | txn.rl = txn.len + 4; |
| 586 | ret = ngd_get_tid(ctrl, &txn, &wbuf[0], &done); |
| 587 | if (ret) |
| 588 | return ret; |
| 589 | ret = ngd_xferandwait_ack(ctrl, &txn); |
| 590 | if (ret) |
| 591 | return ret; |
| 592 | } |
| 593 | txn.len = 0; |
| 594 | list_for_each_entry(pch, &sb->mark_removal, pending) { |
| 595 | struct slim_ich *slc; |
| 596 | slc = &ctrl->chans[pch->chan]; |
| 597 | if (!slc) { |
| 598 | pr_err("no channel in removal?"); |
| 599 | return -ENXIO; |
| 600 | } |
| 601 | if (txn.len == 0) { |
Sagar Dharia | b47c896 | 2012-10-30 13:44:08 -0600 | [diff] [blame] | 602 | /* Per protocol, only last 5 bits for client no. */ |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 603 | wbuf[txn.len++] = (u8) (SLIM_CH_REMOVE << 6) | |
Sagar Dharia | b47c896 | 2012-10-30 13:44:08 -0600 | [diff] [blame] | 604 | (sb->laddr & 0x1f); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 605 | ret = ngd_get_tid(ctrl, &txn, &wbuf[txn.len++], &done); |
| 606 | if (ret) { |
| 607 | pr_err("no tid for channel define?"); |
| 608 | return -ENXIO; |
| 609 | } |
| 610 | } |
| 611 | wbuf[txn.len++] = slc->chan; |
Sagar Dharia | b47c896 | 2012-10-30 13:44:08 -0600 | [diff] [blame] | 612 | pr_debug("slim remove chan:%d, tid:0x%x", slc->chan, txn.tid); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 613 | } |
| 614 | if (txn.len) { |
| 615 | txn.mc = SLIM_USR_MC_CHAN_CTRL; |
| 616 | txn.rl = txn.len + 4; |
| 617 | ret = ngd_xferandwait_ack(ctrl, &txn); |
| 618 | if (ret) |
| 619 | return ret; |
| 620 | |
| 621 | txn.mc = SLIM_USR_MC_RECONFIG_NOW; |
| 622 | txn.len = 2; |
| 623 | wbuf[1] = sb->laddr; |
| 624 | txn.rl = txn.len + 4; |
| 625 | ret = ngd_get_tid(ctrl, &txn, &wbuf[0], &done); |
| 626 | if (ret) |
| 627 | return ret; |
| 628 | ret = ngd_xferandwait_ack(ctrl, &txn); |
| 629 | if (ret) |
| 630 | return ret; |
| 631 | txn.len = 0; |
| 632 | } |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 633 | return 0; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | static int ngd_set_laddr(struct slim_controller *ctrl, const u8 *ea, |
| 637 | u8 elen, u8 laddr) |
| 638 | { |
| 639 | return 0; |
| 640 | } |
| 641 | |
| 642 | static int ngd_get_laddr(struct slim_controller *ctrl, const u8 *ea, |
| 643 | u8 elen, u8 *laddr) |
| 644 | { |
| 645 | int ret; |
| 646 | u8 wbuf[10]; |
| 647 | struct slim_msg_txn txn; |
| 648 | DECLARE_COMPLETION_ONSTACK(done); |
| 649 | txn.mt = SLIM_MSG_MT_DEST_REFERRED_USER; |
| 650 | txn.dt = SLIM_MSG_DEST_LOGICALADDR; |
| 651 | txn.la = SLIM_LA_MGR; |
| 652 | txn.ec = 0; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 653 | ret = ngd_get_tid(ctrl, &txn, &wbuf[0], &done); |
| 654 | if (ret) { |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 655 | return ret; |
| 656 | } |
| 657 | memcpy(&wbuf[1], ea, elen); |
| 658 | txn.mc = SLIM_USR_MC_ADDR_QUERY; |
| 659 | txn.rl = 11; |
| 660 | txn.len = 7; |
| 661 | txn.wbuf = wbuf; |
| 662 | txn.rbuf = NULL; |
| 663 | ret = ngd_xferandwait_ack(ctrl, &txn); |
| 664 | if (!ret && txn.la == 0xFF) |
| 665 | ret = -ENXIO; |
| 666 | else if (!ret) |
| 667 | *laddr = txn.la; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 668 | return ret; |
| 669 | } |
| 670 | |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 671 | static void ngd_slim_setup_msg_path(struct msm_slim_ctrl *dev) |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 672 | { |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 673 | if (dev->state == MSM_CTRL_DOWN) { |
| 674 | msm_slim_sps_init(dev, dev->bam_mem, |
| 675 | NGD_BASE(dev->ctrl.nr, |
| 676 | dev->ver) + NGD_STATUS, true); |
| 677 | } else { |
| 678 | if (dev->use_rx_msgqs == MSM_MSGQ_DISABLED) |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 679 | goto setup_tx_msg_path; |
| 680 | msm_slim_connect_endp(dev, &dev->rx_msgq, |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 681 | &dev->rx_msgq_notify); |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 682 | |
| 683 | setup_tx_msg_path: |
| 684 | if (dev->use_tx_msgqs == MSM_MSGQ_DISABLED) |
| 685 | return; |
| 686 | msm_slim_connect_endp(dev, &dev->tx_msgq, |
| 687 | NULL); |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 688 | } |
| 689 | } |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 690 | |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 691 | static void ngd_slim_rx(struct msm_slim_ctrl *dev, u8 *buf) |
| 692 | { |
| 693 | u8 mc, mt, len; |
| 694 | int ret; |
| 695 | u32 msgq_en = 1; |
| 696 | |
| 697 | len = buf[0] & 0x1F; |
| 698 | mt = (buf[0] >> 5) & 0x7; |
| 699 | mc = buf[1]; |
| 700 | if (mc == SLIM_USR_MC_MASTER_CAPABILITY && |
| 701 | mt == SLIM_MSG_MT_SRC_REFERRED_USER) { |
| 702 | struct slim_msg_txn txn; |
Sagar Dharia | 0a69333 | 2013-04-15 17:59:03 -0600 | [diff] [blame] | 703 | int retries = 0; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 704 | u8 wbuf[8]; |
| 705 | txn.dt = SLIM_MSG_DEST_LOGICALADDR; |
| 706 | txn.ec = 0; |
| 707 | txn.rbuf = NULL; |
| 708 | txn.mc = SLIM_USR_MC_REPORT_SATELLITE; |
| 709 | txn.mt = SLIM_MSG_MT_SRC_REFERRED_USER; |
| 710 | txn.la = SLIM_LA_MGR; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 711 | wbuf[0] = SAT_MAGIC_LSB; |
| 712 | wbuf[1] = SAT_MAGIC_MSB; |
| 713 | wbuf[2] = SAT_MSG_VER; |
| 714 | wbuf[3] = SAT_MSG_PROT; |
| 715 | txn.wbuf = wbuf; |
| 716 | txn.len = 4; |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 717 | pr_info("SLIM SAT: Received master capability"); |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 718 | if (dev->state >= MSM_CTRL_ASLEEP) { |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 719 | ngd_slim_setup_msg_path(dev); |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 720 | if (dev->use_rx_msgqs == MSM_MSGQ_ENABLED) |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 721 | msgq_en |= NGD_CFG_RX_MSGQ_EN; |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 722 | if (dev->use_tx_msgqs == MSM_MSGQ_ENABLED) |
| 723 | msgq_en |= NGD_CFG_TX_MSGQ_EN; |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 724 | writel_relaxed(msgq_en, dev->base + |
| 725 | NGD_BASE(dev->ctrl.nr, dev->ver)); |
| 726 | /* make sure NGD MSG-Q config goes through */ |
| 727 | mb(); |
| 728 | } |
Sagar Dharia | 0a69333 | 2013-04-15 17:59:03 -0600 | [diff] [blame] | 729 | capability_retry: |
| 730 | txn.rl = 8; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 731 | ret = ngd_xfer_msg(&dev->ctrl, &txn); |
| 732 | if (!ret) { |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 733 | enum msm_ctrl_state prev_state = dev->state; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 734 | dev->state = MSM_CTRL_AWAKE; |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 735 | if (prev_state >= MSM_CTRL_ASLEEP) |
| 736 | complete(&dev->reconf); |
| 737 | else |
| 738 | pr_err("SLIM: unexpected capability, state:%d", |
| 739 | prev_state); |
| 740 | /* ADSP SSR, send device_up notifications */ |
| 741 | if (prev_state == MSM_CTRL_DOWN) |
| 742 | schedule_work(&dev->slave_notify); |
Sagar Dharia | 0a69333 | 2013-04-15 17:59:03 -0600 | [diff] [blame] | 743 | } else if (ret == -EIO) { |
| 744 | pr_info("capability message NACKed, retrying"); |
| 745 | if (retries < INIT_MX_RETRIES) { |
| 746 | msleep(DEF_RETRY_MS); |
| 747 | retries++; |
| 748 | goto capability_retry; |
| 749 | } |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | if (mc == SLIM_MSG_MC_REPLY_INFORMATION || |
| 753 | mc == SLIM_MSG_MC_REPLY_VALUE) { |
| 754 | u8 tid = buf[3]; |
| 755 | dev_dbg(dev->dev, "tid:%d, len:%d\n", tid, len); |
| 756 | slim_msg_response(&dev->ctrl, &buf[4], tid, |
| 757 | len - 4); |
| 758 | pm_runtime_mark_last_busy(dev->dev); |
| 759 | } |
| 760 | if (mc == SLIM_USR_MC_ADDR_REPLY && |
| 761 | mt == SLIM_MSG_MT_SRC_REFERRED_USER) { |
Sagar Dharia | d295935 | 2012-12-01 15:43:01 -0700 | [diff] [blame] | 762 | struct slim_msg_txn *txn; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 763 | u8 failed_ea[6] = {0, 0, 0, 0, 0, 0}; |
Sagar Dharia | d295935 | 2012-12-01 15:43:01 -0700 | [diff] [blame] | 764 | mutex_lock(&dev->ctrl.m_ctrl); |
| 765 | txn = dev->ctrl.txnt[buf[3]]; |
| 766 | if (!txn) { |
| 767 | pr_err("LADDR response after timeout, tid:0x%x", |
| 768 | buf[3]); |
| 769 | mutex_unlock(&dev->ctrl.m_ctrl); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 770 | return; |
Sagar Dharia | d295935 | 2012-12-01 15:43:01 -0700 | [diff] [blame] | 771 | } |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 772 | if (memcmp(&buf[4], failed_ea, 6)) |
| 773 | txn->la = buf[10]; |
| 774 | dev->ctrl.txnt[buf[3]] = NULL; |
Sagar Dharia | d295935 | 2012-12-01 15:43:01 -0700 | [diff] [blame] | 775 | mutex_unlock(&dev->ctrl.m_ctrl); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 776 | complete(txn->comp); |
| 777 | } |
| 778 | if (mc == SLIM_USR_MC_GENERIC_ACK && |
| 779 | mt == SLIM_MSG_MT_SRC_REFERRED_USER) { |
Sagar Dharia | d295935 | 2012-12-01 15:43:01 -0700 | [diff] [blame] | 780 | struct slim_msg_txn *txn; |
| 781 | mutex_lock(&dev->ctrl.m_ctrl); |
| 782 | txn = dev->ctrl.txnt[buf[3]]; |
| 783 | if (!txn) { |
| 784 | pr_err("ACK received after timeout, tid:0x%x", |
| 785 | buf[3]); |
| 786 | mutex_unlock(&dev->ctrl.m_ctrl); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 787 | return; |
Sagar Dharia | d295935 | 2012-12-01 15:43:01 -0700 | [diff] [blame] | 788 | } |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 789 | dev_dbg(dev->dev, "got response:tid:%d, response:0x%x", |
| 790 | (int)buf[3], buf[4]); |
| 791 | if (!(buf[4] & MSM_SAT_SUCCSS)) { |
| 792 | dev_err(dev->dev, "TID:%d, NACK code:0x%x", (int)buf[3], |
| 793 | buf[4]); |
| 794 | txn->ec = -EIO; |
| 795 | } |
| 796 | dev->ctrl.txnt[buf[3]] = NULL; |
Sagar Dharia | d295935 | 2012-12-01 15:43:01 -0700 | [diff] [blame] | 797 | mutex_unlock(&dev->ctrl.m_ctrl); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 798 | complete(txn->comp); |
| 799 | } |
| 800 | } |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 801 | |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 802 | static int ngd_slim_power_up(struct msm_slim_ctrl *dev) |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 803 | { |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 804 | void __iomem *ngd; |
| 805 | int timeout, ret; |
| 806 | enum msm_ctrl_state cur_state = dev->state; |
| 807 | u32 laddr; |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 808 | u32 ngd_int = (NGD_INT_TX_NACKED_2 | |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 809 | NGD_INT_MSG_BUF_CONTE | NGD_INT_MSG_TX_INVAL | |
| 810 | NGD_INT_IE_VE_CHG | NGD_INT_DEV_ERR | |
| 811 | NGD_INT_TX_MSG_SENT | NGD_INT_RX_MSG_RCVD); |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 812 | |
| 813 | if (cur_state == MSM_CTRL_DOWN) { |
| 814 | int timeout = wait_for_completion_timeout(&dev->qmi.qmi_comp, |
| 815 | HZ); |
| 816 | if (!timeout) |
| 817 | pr_err("slimbus QMI init timed out"); |
| 818 | } |
| 819 | |
| 820 | ret = msm_slim_qmi_power_request(dev, true); |
| 821 | if (ret) { |
| 822 | pr_err("SLIM QMI power request failed:%d", ret); |
| 823 | return ret; |
| 824 | } |
| 825 | if (!dev->ver) { |
| 826 | dev->ver = readl_relaxed(dev->base); |
| 827 | /* Version info in 16 MSbits */ |
| 828 | dev->ver >>= 16; |
| 829 | } |
| 830 | ngd = dev->base + NGD_BASE(dev->ctrl.nr, dev->ver); |
| 831 | laddr = readl_relaxed(ngd + NGD_STATUS); |
| 832 | if (laddr & NGD_LADDR) { |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 833 | /* |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 834 | * ADSP power collapse case, where HW wasn't reset. |
| 835 | * Reconnect BAM pipes if disconnected |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 836 | */ |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 837 | ngd_slim_setup_msg_path(dev); |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 838 | return 0; |
| 839 | } else if (cur_state != MSM_CTRL_DOWN) { |
| 840 | pr_info("ADSP P.C. CTRL state:%d NGD not enumerated:0x%x", |
| 841 | dev->state, laddr); |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 842 | } |
Sagar Dharia | da48bd6 | 2013-03-21 18:02:40 -0600 | [diff] [blame] | 843 | /* ADSP SSR scenario, need to disconnect pipe before connecting */ |
| 844 | if (dev->use_rx_msgqs == MSM_MSGQ_DOWN) { |
| 845 | struct msm_slim_endp *endpoint = &dev->rx_msgq; |
| 846 | sps_disconnect(endpoint->sps); |
| 847 | sps_free_endpoint(endpoint->sps); |
| 848 | dev->use_rx_msgqs = MSM_MSGQ_RESET; |
| 849 | } |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 850 | if (dev->use_tx_msgqs == MSM_MSGQ_DOWN) { |
| 851 | struct msm_slim_endp *endpoint = &dev->tx_msgq; |
| 852 | sps_disconnect(endpoint->sps); |
| 853 | sps_free_endpoint(endpoint->sps); |
| 854 | dev->use_tx_msgqs = MSM_MSGQ_RESET; |
| 855 | } |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 856 | /* |
| 857 | * ADSP power collapse case (OR SSR), where HW was reset |
| 858 | * BAM programming will happen when capability message is received |
| 859 | */ |
| 860 | writel_relaxed(ngd_int, dev->base + NGD_INT_EN + |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 861 | NGD_BASE(dev->ctrl.nr, dev->ver)); |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 862 | /* |
| 863 | * Enable NGD. Configure NGD in register acc. mode until master |
| 864 | * announcement is received |
| 865 | */ |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 866 | writel_relaxed(1, dev->base + NGD_BASE(dev->ctrl.nr, dev->ver)); |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 867 | /* make sure NGD enabling goes through */ |
| 868 | mb(); |
| 869 | |
| 870 | timeout = wait_for_completion_timeout(&dev->reconf, HZ); |
| 871 | if (!timeout) { |
| 872 | pr_err("failed to received master capability"); |
| 873 | return -ETIMEDOUT; |
| 874 | } |
| 875 | if (cur_state == MSM_CTRL_DOWN) |
| 876 | complete(&dev->ctrl_up); |
| 877 | return 0; |
| 878 | } |
| 879 | |
| 880 | static int ngd_slim_enable(struct msm_slim_ctrl *dev, bool enable) |
| 881 | { |
| 882 | int ret = 0; |
| 883 | if (enable) { |
| 884 | ret = msm_slim_qmi_init(dev, false); |
| 885 | /* controller state should be in sync with framework state */ |
| 886 | if (!ret) { |
| 887 | ret = slim_ctrl_clk_pause(&dev->ctrl, false, |
| 888 | SLIM_CLK_UNSPECIFIED); |
| 889 | complete(&dev->qmi.qmi_comp); |
| 890 | /* |
| 891 | * Power-up won't be called if clock pause failed. |
| 892 | * This can happen if ADSP SSR happened when audio |
| 893 | * session is in progress. Framework will think that |
| 894 | * clock pause failed so no need to wakeup controller. |
| 895 | * Call power-up explicitly in that case, since slimbus |
| 896 | * HW needs to be powered-on to be in sync with |
| 897 | * framework state |
| 898 | */ |
| 899 | if (ret) |
| 900 | ngd_slim_power_up(dev); |
| 901 | if (!pm_runtime_enabled(dev->dev) || |
| 902 | !pm_runtime_suspended(dev->dev)) |
| 903 | ngd_slim_runtime_resume(dev->dev); |
| 904 | else |
| 905 | pm_runtime_resume(dev->dev); |
| 906 | pm_runtime_mark_last_busy(dev->dev); |
| 907 | pm_runtime_put(dev->dev); |
| 908 | } else |
| 909 | dev_err(dev->dev, "qmi init fail, ret:%d, state:%d", |
| 910 | ret, dev->state); |
| 911 | } else { |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 912 | msm_slim_qmi_exit(dev); |
| 913 | } |
| 914 | |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 915 | return ret; |
| 916 | } |
| 917 | |
| 918 | static int ngd_clk_pause_wakeup(struct slim_controller *ctrl) |
| 919 | { |
| 920 | struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl); |
| 921 | return ngd_slim_power_up(dev); |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 922 | } |
| 923 | |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 924 | static int ngd_slim_rx_msgq_thread(void *data) |
| 925 | { |
| 926 | struct msm_slim_ctrl *dev = (struct msm_slim_ctrl *)data; |
| 927 | struct completion *notify = &dev->rx_msgq_notify; |
| 928 | int ret = 0, index = 0; |
| 929 | u32 mc = 0; |
| 930 | u32 mt = 0; |
| 931 | u32 buffer[10]; |
| 932 | u8 msg_len = 0; |
| 933 | |
| 934 | while (!kthread_should_stop()) { |
| 935 | set_current_state(TASK_INTERRUPTIBLE); |
| 936 | ret = wait_for_completion_interruptible(notify); |
| 937 | if (ret) { |
| 938 | dev_err(dev->dev, "rx thread wait err:%d", ret); |
| 939 | continue; |
| 940 | } |
| 941 | /* 1 irq notification per message */ |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 942 | if (dev->use_rx_msgqs != MSM_MSGQ_ENABLED) { |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 943 | msm_slim_rx_dequeue(dev, (u8 *)buffer); |
| 944 | ngd_slim_rx(dev, (u8 *)buffer); |
| 945 | continue; |
| 946 | } |
| 947 | ret = msm_slim_rx_msgq_get(dev, buffer, index); |
| 948 | if (ret) { |
| 949 | dev_err(dev->dev, "rx_msgq_get() failed 0x%x\n", ret); |
| 950 | continue; |
| 951 | } |
| 952 | |
| 953 | /* Wait for complete message */ |
| 954 | if (index++ == 0) { |
| 955 | msg_len = *buffer & 0x1F; |
| 956 | mt = (buffer[0] >> 5) & 0x7; |
| 957 | mc = (buffer[0] >> 8) & 0xff; |
| 958 | dev_dbg(dev->dev, "MC: %x, MT: %x\n", mc, mt); |
| 959 | } |
| 960 | if ((index * 4) >= msg_len) { |
| 961 | index = 0; |
| 962 | ngd_slim_rx(dev, (u8 *)buffer); |
| 963 | } else |
| 964 | continue; |
| 965 | } |
| 966 | return 0; |
| 967 | } |
| 968 | |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 969 | static void ngd_laddr_lookup(struct work_struct *work) |
| 970 | { |
| 971 | struct msm_slim_ctrl *dev = |
| 972 | container_of(work, struct msm_slim_ctrl, slave_notify); |
| 973 | struct slim_controller *ctrl = &dev->ctrl; |
| 974 | struct slim_device *sbdev; |
| 975 | int i; |
| 976 | mutex_lock(&ctrl->m_ctrl); |
| 977 | list_for_each_entry(sbdev, &ctrl->devs, dev_list) { |
| 978 | int ret = 0; |
| 979 | mutex_unlock(&ctrl->m_ctrl); |
| 980 | for (i = 0; i < LADDR_RETRY; i++) { |
| 981 | ret = slim_get_logical_addr(sbdev, sbdev->e_addr, |
| 982 | 6, &sbdev->laddr); |
| 983 | if (!ret) |
| 984 | break; |
| 985 | else /* time for ADSP to assign LA */ |
| 986 | msleep(20); |
| 987 | } |
| 988 | mutex_lock(&ctrl->m_ctrl); |
| 989 | } |
| 990 | mutex_unlock(&ctrl->m_ctrl); |
| 991 | } |
| 992 | |
| 993 | static void ngd_adsp_down(struct work_struct *work) |
| 994 | { |
| 995 | struct msm_slim_qmi *qmi = |
| 996 | container_of(work, struct msm_slim_qmi, ssr_down); |
| 997 | struct msm_slim_ctrl *dev = |
| 998 | container_of(qmi, struct msm_slim_ctrl, qmi); |
| 999 | struct slim_controller *ctrl = &dev->ctrl; |
| 1000 | struct slim_device *sbdev; |
| 1001 | int i; |
| 1002 | |
| 1003 | ngd_slim_enable(dev, false); |
| 1004 | /* disconnect BAM pipes */ |
Sagar Dharia | da48bd6 | 2013-03-21 18:02:40 -0600 | [diff] [blame] | 1005 | if (dev->use_rx_msgqs == MSM_MSGQ_ENABLED) |
| 1006 | dev->use_rx_msgqs = MSM_MSGQ_DOWN; |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 1007 | if (dev->use_tx_msgqs == MSM_MSGQ_ENABLED) |
| 1008 | dev->use_tx_msgqs = MSM_MSGQ_DOWN; |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 1009 | msm_slim_sps_exit(dev, false); |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 1010 | mutex_lock(&ctrl->m_ctrl); |
| 1011 | /* device up should be called again after SSR */ |
| 1012 | list_for_each_entry(sbdev, &ctrl->devs, dev_list) |
| 1013 | sbdev->notified = false; |
| 1014 | /* invalidate logical addresses */ |
| 1015 | for (i = 0; i < ctrl->num_dev; i++) |
| 1016 | ctrl->addrt[i].valid = false; |
| 1017 | mutex_unlock(&ctrl->m_ctrl); |
| 1018 | pr_info("SLIM ADSP SSR (DOWN) done"); |
| 1019 | } |
| 1020 | |
| 1021 | static void ngd_adsp_up(struct work_struct *work) |
| 1022 | { |
| 1023 | struct msm_slim_qmi *qmi = |
| 1024 | container_of(work, struct msm_slim_qmi, ssr_up); |
| 1025 | struct msm_slim_ctrl *dev = |
| 1026 | container_of(qmi, struct msm_slim_ctrl, qmi); |
| 1027 | ngd_slim_enable(dev, true); |
| 1028 | } |
| 1029 | |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1030 | static int __devinit ngd_slim_probe(struct platform_device *pdev) |
| 1031 | { |
| 1032 | struct msm_slim_ctrl *dev; |
| 1033 | int ret; |
| 1034 | struct resource *bam_mem; |
| 1035 | struct resource *slim_mem; |
| 1036 | struct resource *irq, *bam_irq; |
| 1037 | enum apr_subsys_state q6_state; |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 1038 | bool rxreg_access = false; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1039 | |
| 1040 | q6_state = apr_get_q6_state(); |
| 1041 | if (q6_state == APR_SUBSYS_DOWN) { |
| 1042 | dev_dbg(&pdev->dev, "defering %s, adsp_state %d\n", __func__, |
| 1043 | q6_state); |
| 1044 | return -EPROBE_DEFER; |
| 1045 | } else |
| 1046 | dev_dbg(&pdev->dev, "adsp is ready\n"); |
| 1047 | |
| 1048 | slim_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 1049 | "slimbus_physical"); |
| 1050 | if (!slim_mem) { |
| 1051 | dev_err(&pdev->dev, "no slimbus physical memory resource\n"); |
| 1052 | return -ENODEV; |
| 1053 | } |
| 1054 | bam_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 1055 | "slimbus_bam_physical"); |
| 1056 | if (!bam_mem) { |
| 1057 | dev_err(&pdev->dev, "no slimbus BAM memory resource\n"); |
| 1058 | return -ENODEV; |
| 1059 | } |
| 1060 | irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, |
| 1061 | "slimbus_irq"); |
| 1062 | if (!irq) { |
| 1063 | dev_err(&pdev->dev, "no slimbus IRQ resource\n"); |
| 1064 | return -ENODEV; |
| 1065 | } |
| 1066 | bam_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, |
| 1067 | "slimbus_bam_irq"); |
| 1068 | if (!bam_irq) { |
| 1069 | dev_err(&pdev->dev, "no slimbus BAM IRQ resource\n"); |
| 1070 | return -ENODEV; |
| 1071 | } |
| 1072 | |
| 1073 | dev = kzalloc(sizeof(struct msm_slim_ctrl), GFP_KERNEL); |
| 1074 | if (IS_ERR(dev)) { |
| 1075 | dev_err(&pdev->dev, "no memory for MSM slimbus controller\n"); |
| 1076 | return PTR_ERR(dev); |
| 1077 | } |
| 1078 | dev->dev = &pdev->dev; |
| 1079 | platform_set_drvdata(pdev, dev); |
| 1080 | slim_set_ctrldata(&dev->ctrl, dev); |
| 1081 | dev->base = ioremap(slim_mem->start, resource_size(slim_mem)); |
| 1082 | if (!dev->base) { |
| 1083 | dev_err(&pdev->dev, "IOremap failed\n"); |
| 1084 | ret = -ENOMEM; |
| 1085 | goto err_ioremap_failed; |
| 1086 | } |
| 1087 | dev->bam.base = ioremap(bam_mem->start, resource_size(bam_mem)); |
| 1088 | if (!dev->bam.base) { |
| 1089 | dev_err(&pdev->dev, "BAM IOremap failed\n"); |
| 1090 | ret = -ENOMEM; |
| 1091 | goto err_ioremap_bam_failed; |
| 1092 | } |
| 1093 | if (pdev->dev.of_node) { |
| 1094 | |
| 1095 | ret = of_property_read_u32(pdev->dev.of_node, "cell-index", |
| 1096 | &dev->ctrl.nr); |
| 1097 | if (ret) { |
| 1098 | dev_err(&pdev->dev, "Cell index not specified:%d", ret); |
| 1099 | goto err_ctrl_failed; |
| 1100 | } |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 1101 | rxreg_access = of_property_read_bool(pdev->dev.of_node, |
| 1102 | "qcom,rxreg-access"); |
Sagar Dharia | a3c6a38 | 2013-06-21 12:18:20 -0600 | [diff] [blame] | 1103 | of_property_read_u32(pdev->dev.of_node, "qcom,apps-ch-pipes", |
| 1104 | &dev->pdata.apps_pipes); |
| 1105 | of_property_read_u32(pdev->dev.of_node, "qcom,ea-pc", |
| 1106 | &dev->pdata.eapc); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1107 | } else { |
| 1108 | dev->ctrl.nr = pdev->id; |
| 1109 | } |
Sagar Dharia | a3c6a38 | 2013-06-21 12:18:20 -0600 | [diff] [blame] | 1110 | /* |
| 1111 | * Keep PGD's logical address as manager's. Query it when first data |
| 1112 | * channel request comes in |
| 1113 | */ |
| 1114 | dev->pgdla = SLIM_LA_MGR; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1115 | dev->ctrl.nchans = MSM_SLIM_NCHANS; |
| 1116 | dev->ctrl.nports = MSM_SLIM_NPORTS; |
| 1117 | dev->framer.rootfreq = SLIM_ROOT_FREQ >> 3; |
| 1118 | dev->framer.superfreq = |
| 1119 | dev->framer.rootfreq / SLIM_CL_PER_SUPERFRAME_DIV8; |
| 1120 | dev->ctrl.a_framer = &dev->framer; |
| 1121 | dev->ctrl.clkgear = SLIM_MAX_CLK_GEAR; |
| 1122 | dev->ctrl.set_laddr = ngd_set_laddr; |
| 1123 | dev->ctrl.get_laddr = ngd_get_laddr; |
| 1124 | dev->ctrl.allocbw = ngd_allocbw; |
| 1125 | dev->ctrl.xfer_msg = ngd_xfer_msg; |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 1126 | dev->ctrl.wakeup = ngd_clk_pause_wakeup; |
Sagar Dharia | 100e721 | 2013-05-17 18:20:57 -0600 | [diff] [blame] | 1127 | dev->ctrl.alloc_port = msm_alloc_port; |
| 1128 | dev->ctrl.dealloc_port = msm_dealloc_port; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1129 | dev->ctrl.port_xfer = msm_slim_port_xfer; |
| 1130 | dev->ctrl.port_xfer_status = msm_slim_port_xfer_status; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1131 | dev->bam_mem = bam_mem; |
| 1132 | |
| 1133 | init_completion(&dev->reconf); |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 1134 | init_completion(&dev->ctrl_up); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1135 | mutex_init(&dev->tx_lock); |
| 1136 | spin_lock_init(&dev->rx_lock); |
| 1137 | dev->ee = 1; |
| 1138 | dev->irq = irq->start; |
| 1139 | dev->bam.irq = bam_irq->start; |
| 1140 | |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 1141 | if (rxreg_access) |
| 1142 | dev->use_rx_msgqs = MSM_MSGQ_DISABLED; |
| 1143 | else |
| 1144 | dev->use_rx_msgqs = MSM_MSGQ_RESET; |
Sagar Dharia | 5c8ad19 | 2013-05-31 11:39:05 -0600 | [diff] [blame] | 1145 | |
| 1146 | /* Enable TX message queues by default as recommended by HW */ |
| 1147 | dev->use_tx_msgqs = MSM_MSGQ_RESET; |
| 1148 | |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1149 | init_completion(&dev->rx_msgq_notify); |
| 1150 | |
| 1151 | /* Register with framework */ |
| 1152 | ret = slim_add_numbered_controller(&dev->ctrl); |
| 1153 | if (ret) { |
| 1154 | dev_err(dev->dev, "error adding controller\n"); |
| 1155 | goto err_ctrl_failed; |
| 1156 | } |
| 1157 | |
| 1158 | dev->ctrl.dev.parent = &pdev->dev; |
| 1159 | dev->ctrl.dev.of_node = pdev->dev.of_node; |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 1160 | dev->state = MSM_CTRL_DOWN; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1161 | |
| 1162 | ret = request_irq(dev->irq, ngd_slim_interrupt, |
| 1163 | IRQF_TRIGGER_HIGH, "ngd_slim_irq", dev); |
| 1164 | |
| 1165 | if (ret) { |
| 1166 | dev_err(&pdev->dev, "request IRQ failed\n"); |
| 1167 | goto err_request_irq_failed; |
| 1168 | } |
| 1169 | |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 1170 | init_completion(&dev->qmi.qmi_comp); |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 1171 | pm_runtime_use_autosuspend(dev->dev); |
| 1172 | pm_runtime_set_autosuspend_delay(dev->dev, MSM_SLIM_AUTOSUSPEND); |
| 1173 | pm_runtime_set_suspended(dev->dev); |
| 1174 | pm_runtime_enable(dev->dev); |
| 1175 | |
| 1176 | INIT_WORK(&dev->slave_notify, ngd_laddr_lookup); |
| 1177 | INIT_WORK(&dev->qmi.ssr_down, ngd_adsp_down); |
| 1178 | INIT_WORK(&dev->qmi.ssr_up, ngd_adsp_up); |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 1179 | dev->qmi.nb.notifier_call = ngd_qmi_available; |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 1180 | pm_runtime_get_noresume(dev->dev); |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 1181 | ret = qmi_svc_event_notifier_register(SLIMBUS_QMI_SVC_ID, |
| 1182 | SLIMBUS_QMI_INS_ID, &dev->qmi.nb); |
| 1183 | if (ret) { |
| 1184 | pr_err("Slimbus QMI service registration failed:%d", ret); |
| 1185 | goto qmi_register_failed; |
| 1186 | } |
| 1187 | |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 1188 | |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1189 | /* Fire up the Rx message queue thread */ |
| 1190 | dev->rx_msgq_thread = kthread_run(ngd_slim_rx_msgq_thread, dev, |
| 1191 | NGD_SLIM_NAME "_ngd_msgq_thread"); |
| 1192 | if (IS_ERR(dev->rx_msgq_thread)) { |
| 1193 | ret = PTR_ERR(dev->rx_msgq_thread); |
| 1194 | dev_err(dev->dev, "Failed to start Rx message queue thread\n"); |
| 1195 | goto err_thread_create_failed; |
| 1196 | } |
| 1197 | |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1198 | if (pdev->dev.of_node) |
| 1199 | of_register_slim_devices(&dev->ctrl); |
| 1200 | |
| 1201 | /* Add devices registered with board-info now that controller is up */ |
| 1202 | slim_ctrl_add_boarddevs(&dev->ctrl); |
| 1203 | |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1204 | dev_dbg(dev->dev, "NGD SB controller is up!\n"); |
| 1205 | return 0; |
| 1206 | |
| 1207 | err_thread_create_failed: |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 1208 | qmi_svc_event_notifier_unregister(SLIMBUS_QMI_SVC_ID, |
| 1209 | SLIMBUS_QMI_INS_ID, &dev->qmi.nb); |
| 1210 | qmi_register_failed: |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1211 | free_irq(dev->irq, dev); |
| 1212 | err_request_irq_failed: |
| 1213 | slim_del_controller(&dev->ctrl); |
| 1214 | err_ctrl_failed: |
| 1215 | iounmap(dev->bam.base); |
| 1216 | err_ioremap_bam_failed: |
| 1217 | iounmap(dev->base); |
| 1218 | err_ioremap_failed: |
| 1219 | kfree(dev); |
| 1220 | return ret; |
| 1221 | } |
| 1222 | |
| 1223 | static int __devexit ngd_slim_remove(struct platform_device *pdev) |
| 1224 | { |
| 1225 | struct msm_slim_ctrl *dev = platform_get_drvdata(pdev); |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 1226 | ngd_slim_enable(dev, false); |
| 1227 | qmi_svc_event_notifier_unregister(SLIMBUS_QMI_SVC_ID, |
| 1228 | SLIMBUS_QMI_INS_ID, &dev->qmi.nb); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1229 | pm_runtime_disable(&pdev->dev); |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1230 | free_irq(dev->irq, dev); |
| 1231 | slim_del_controller(&dev->ctrl); |
| 1232 | kthread_stop(dev->rx_msgq_thread); |
| 1233 | iounmap(dev->bam.base); |
| 1234 | iounmap(dev->base); |
| 1235 | kfree(dev); |
| 1236 | return 0; |
| 1237 | } |
| 1238 | |
| 1239 | #ifdef CONFIG_PM_RUNTIME |
| 1240 | static int ngd_slim_runtime_idle(struct device *device) |
| 1241 | { |
| 1242 | dev_dbg(device, "pm_runtime: idle...\n"); |
| 1243 | pm_request_autosuspend(device); |
| 1244 | return -EAGAIN; |
| 1245 | } |
| 1246 | #endif |
| 1247 | |
| 1248 | /* |
| 1249 | * If PM_RUNTIME is not defined, these 2 functions become helper |
| 1250 | * functions to be called from system suspend/resume. So they are not |
| 1251 | * inside ifdef CONFIG_PM_RUNTIME |
| 1252 | */ |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1253 | static int ngd_slim_runtime_resume(struct device *device) |
| 1254 | { |
| 1255 | struct platform_device *pdev = to_platform_device(device); |
| 1256 | struct msm_slim_ctrl *dev = platform_get_drvdata(pdev); |
| 1257 | int ret = 0; |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 1258 | if (dev->state >= MSM_CTRL_ASLEEP) |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1259 | ret = slim_ctrl_clk_pause(&dev->ctrl, true, 0); |
| 1260 | if (ret) { |
| 1261 | dev_err(device, "clk pause not exited:%d", ret); |
| 1262 | dev->state = MSM_CTRL_ASLEEP; |
| 1263 | } else { |
| 1264 | dev->state = MSM_CTRL_AWAKE; |
| 1265 | } |
| 1266 | return ret; |
| 1267 | } |
| 1268 | |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 1269 | #ifdef CONFIG_PM_SLEEP |
| 1270 | static int ngd_slim_runtime_suspend(struct device *device) |
| 1271 | { |
| 1272 | struct platform_device *pdev = to_platform_device(device); |
| 1273 | struct msm_slim_ctrl *dev = platform_get_drvdata(pdev); |
| 1274 | int ret = 0; |
| 1275 | dev->state = MSM_CTRL_SLEEPING; |
| 1276 | ret = slim_ctrl_clk_pause(&dev->ctrl, false, SLIM_CLK_UNSPECIFIED); |
| 1277 | if (ret) { |
| 1278 | if (ret != -EBUSY) |
| 1279 | dev_err(device, "clk pause not entered:%d", ret); |
| 1280 | dev->state = MSM_CTRL_AWAKE; |
| 1281 | } else { |
| 1282 | dev->state = MSM_CTRL_ASLEEP; |
| 1283 | } |
| 1284 | return ret; |
| 1285 | } |
| 1286 | |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1287 | static int ngd_slim_suspend(struct device *dev) |
| 1288 | { |
| 1289 | int ret = -EBUSY; |
| 1290 | if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) { |
| 1291 | dev_dbg(dev, "system suspend"); |
| 1292 | ret = ngd_slim_runtime_suspend(dev); |
Sagar Dharia | a139828 | 2013-01-22 13:26:20 -0700 | [diff] [blame] | 1293 | /* |
| 1294 | * If runtime-PM still thinks it's active, then make sure its |
| 1295 | * status is in sync with HW status. |
| 1296 | * Since this suspend calls QMI api, it results in holding a |
| 1297 | * wakelock. That results in failure of first suspend. |
| 1298 | * Subsequent suspend should not call low-power transition |
| 1299 | * again since the HW is already in suspended state. |
| 1300 | */ |
| 1301 | if (!ret) { |
| 1302 | pm_runtime_disable(dev); |
| 1303 | pm_runtime_set_suspended(dev); |
| 1304 | pm_runtime_enable(dev); |
| 1305 | } |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1306 | } |
| 1307 | if (ret == -EBUSY) { |
| 1308 | /* |
| 1309 | * There is a possibility that some audio stream is active |
| 1310 | * during suspend. We dont want to return suspend failure in |
| 1311 | * that case so that display and relevant components can still |
| 1312 | * go to suspend. |
| 1313 | * If there is some other error, then it should be passed-on |
| 1314 | * to system level suspend |
| 1315 | */ |
| 1316 | ret = 0; |
| 1317 | } |
| 1318 | return ret; |
| 1319 | } |
| 1320 | |
| 1321 | static int ngd_slim_resume(struct device *dev) |
| 1322 | { |
Sagar Dharia | a139828 | 2013-01-22 13:26:20 -0700 | [diff] [blame] | 1323 | /* |
| 1324 | * Rely on runtime-PM to call resume in case it is enabled. |
| 1325 | * Even if it's not enabled, rely on 1st client transaction to do |
| 1326 | * clock/power on |
| 1327 | */ |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 1328 | return 0; |
| 1329 | } |
| 1330 | #endif /* CONFIG_PM_SLEEP */ |
| 1331 | |
| 1332 | static const struct dev_pm_ops ngd_slim_dev_pm_ops = { |
| 1333 | SET_SYSTEM_SLEEP_PM_OPS( |
| 1334 | ngd_slim_suspend, |
| 1335 | ngd_slim_resume |
| 1336 | ) |
| 1337 | SET_RUNTIME_PM_OPS( |
| 1338 | ngd_slim_runtime_suspend, |
| 1339 | ngd_slim_runtime_resume, |
| 1340 | ngd_slim_runtime_idle |
| 1341 | ) |
| 1342 | }; |
| 1343 | |
| 1344 | static struct of_device_id ngd_slim_dt_match[] = { |
| 1345 | { |
| 1346 | .compatible = "qcom,slim-ngd", |
| 1347 | }, |
| 1348 | {} |
| 1349 | }; |
| 1350 | |
| 1351 | static struct platform_driver ngd_slim_driver = { |
| 1352 | .probe = ngd_slim_probe, |
| 1353 | .remove = ngd_slim_remove, |
| 1354 | .driver = { |
| 1355 | .name = NGD_SLIM_NAME, |
| 1356 | .owner = THIS_MODULE, |
| 1357 | .pm = &ngd_slim_dev_pm_ops, |
| 1358 | .of_match_table = ngd_slim_dt_match, |
| 1359 | }, |
| 1360 | }; |
| 1361 | |
| 1362 | static int ngd_slim_init(void) |
| 1363 | { |
| 1364 | return platform_driver_register(&ngd_slim_driver); |
| 1365 | } |
| 1366 | late_initcall(ngd_slim_init); |
| 1367 | |
| 1368 | static void ngd_slim_exit(void) |
| 1369 | { |
| 1370 | platform_driver_unregister(&ngd_slim_driver); |
| 1371 | } |
| 1372 | module_exit(ngd_slim_exit); |
| 1373 | |
| 1374 | MODULE_LICENSE("GPL v2"); |
| 1375 | MODULE_DESCRIPTION("MSM Slimbus controller"); |
| 1376 | MODULE_ALIAS("platform:msm-slim-ngd"); |