Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [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 | */ |
| 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> |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 24 | #include <linux/pm_runtime.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 25 | #include <mach/sps.h> |
| 26 | |
| 27 | /* Per spec.max 40 bytes per received message */ |
| 28 | #define SLIM_RX_MSGQ_BUF_LEN 40 |
| 29 | |
| 30 | #define SLIM_USR_MC_GENERIC_ACK 0x25 |
| 31 | #define SLIM_USR_MC_MASTER_CAPABILITY 0x0 |
| 32 | #define SLIM_USR_MC_REPORT_SATELLITE 0x1 |
| 33 | #define SLIM_USR_MC_ADDR_QUERY 0xD |
| 34 | #define SLIM_USR_MC_ADDR_REPLY 0xE |
| 35 | #define SLIM_USR_MC_DEFINE_CHAN 0x20 |
| 36 | #define SLIM_USR_MC_DEF_ACT_CHAN 0x21 |
| 37 | #define SLIM_USR_MC_CHAN_CTRL 0x23 |
| 38 | #define SLIM_USR_MC_RECONFIG_NOW 0x24 |
| 39 | #define SLIM_USR_MC_REQ_BW 0x28 |
| 40 | #define SLIM_USR_MC_CONNECT_SRC 0x2C |
| 41 | #define SLIM_USR_MC_CONNECT_SINK 0x2D |
| 42 | #define SLIM_USR_MC_DISCONNECT_PORT 0x2E |
| 43 | |
| 44 | /* MSM Slimbus peripheral settings */ |
| 45 | #define MSM_SLIM_PERF_SUMM_THRESHOLD 0x8000 |
| 46 | #define MSM_SLIM_NCHANS 32 |
| 47 | #define MSM_SLIM_NPORTS 24 |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 48 | #define MSM_SLIM_AUTOSUSPEND MSEC_PER_SEC |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | * Need enough descriptors to receive present messages from slaves |
| 52 | * if received simultaneously. Present message needs 3 descriptors |
| 53 | * and this size will ensure around 10 simultaneous reports. |
| 54 | */ |
| 55 | #define MSM_SLIM_DESC_NUM 32 |
| 56 | |
| 57 | #define SLIM_MSG_ASM_FIRST_WORD(l, mt, mc, dt, ad) \ |
| 58 | ((l) | ((mt) << 5) | ((mc) << 8) | ((dt) << 15) | ((ad) << 16)) |
| 59 | |
| 60 | #define MSM_SLIM_NAME "msm_slim_ctrl" |
| 61 | #define SLIM_ROOT_FREQ 24576000 |
| 62 | |
| 63 | #define MSM_CONCUR_MSG 8 |
| 64 | #define SAT_CONCUR_MSG 8 |
| 65 | #define DEF_WATERMARK (8 << 1) |
| 66 | #define DEF_ALIGN 0 |
| 67 | #define DEF_PACK (1 << 6) |
| 68 | #define ENABLE_PORT 1 |
| 69 | |
| 70 | #define DEF_BLKSZ 0 |
| 71 | #define DEF_TRANSZ 0 |
| 72 | |
| 73 | #define SAT_MAGIC_LSB 0xD9 |
| 74 | #define SAT_MAGIC_MSB 0xC5 |
| 75 | #define SAT_MSG_VER 0x1 |
| 76 | #define SAT_MSG_PROT 0x1 |
| 77 | #define MSM_SAT_SUCCSS 0x20 |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 78 | #define MSM_MAX_NSATS 2 |
Sagar Dharia | 0ffdca1 | 2011-09-25 18:55:53 -0600 | [diff] [blame] | 79 | #define MSM_MAX_SATCH 32 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 80 | |
| 81 | #define QC_MFGID_LSB 0x2 |
| 82 | #define QC_MFGID_MSB 0x17 |
| 83 | #define QC_CHIPID_SL 0x10 |
| 84 | #define QC_DEVID_SAT1 0x3 |
| 85 | #define QC_DEVID_SAT2 0x4 |
| 86 | #define QC_DEVID_PGD 0x5 |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 87 | #define QC_MSM_DEVS 5 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 88 | |
| 89 | /* Component registers */ |
| 90 | enum comp_reg { |
| 91 | COMP_CFG = 0, |
| 92 | COMP_TRUST_CFG = 0x14, |
| 93 | }; |
| 94 | |
| 95 | /* Manager registers */ |
| 96 | enum mgr_reg { |
| 97 | MGR_CFG = 0x200, |
| 98 | MGR_STATUS = 0x204, |
| 99 | MGR_RX_MSGQ_CFG = 0x208, |
| 100 | MGR_INT_EN = 0x210, |
| 101 | MGR_INT_STAT = 0x214, |
| 102 | MGR_INT_CLR = 0x218, |
| 103 | MGR_TX_MSG = 0x230, |
| 104 | MGR_RX_MSG = 0x270, |
| 105 | MGR_VE_STAT = 0x300, |
| 106 | }; |
| 107 | |
| 108 | enum msg_cfg { |
| 109 | MGR_CFG_ENABLE = 1, |
| 110 | MGR_CFG_RX_MSGQ_EN = 1 << 1, |
| 111 | MGR_CFG_TX_MSGQ_EN_HIGH = 1 << 2, |
| 112 | MGR_CFG_TX_MSGQ_EN_LOW = 1 << 3, |
| 113 | }; |
| 114 | /* Message queue types */ |
| 115 | enum msm_slim_msgq_type { |
| 116 | MSGQ_RX = 0, |
| 117 | MSGQ_TX_LOW = 1, |
| 118 | MSGQ_TX_HIGH = 2, |
| 119 | }; |
| 120 | /* Framer registers */ |
| 121 | enum frm_reg { |
| 122 | FRM_CFG = 0x400, |
| 123 | FRM_STAT = 0x404, |
| 124 | FRM_INT_EN = 0x410, |
| 125 | FRM_INT_STAT = 0x414, |
| 126 | FRM_INT_CLR = 0x418, |
| 127 | FRM_WAKEUP = 0x41C, |
| 128 | FRM_CLKCTL_DONE = 0x420, |
| 129 | FRM_IE_STAT = 0x430, |
| 130 | FRM_VE_STAT = 0x440, |
| 131 | }; |
| 132 | |
| 133 | /* Interface registers */ |
| 134 | enum intf_reg { |
| 135 | INTF_CFG = 0x600, |
| 136 | INTF_STAT = 0x604, |
| 137 | INTF_INT_EN = 0x610, |
| 138 | INTF_INT_STAT = 0x614, |
| 139 | INTF_INT_CLR = 0x618, |
| 140 | INTF_IE_STAT = 0x630, |
| 141 | INTF_VE_STAT = 0x640, |
| 142 | }; |
| 143 | |
| 144 | /* Manager PGD registers */ |
| 145 | enum pgd_reg { |
| 146 | PGD_CFG = 0x1000, |
| 147 | PGD_STAT = 0x1004, |
| 148 | PGD_INT_EN = 0x1010, |
| 149 | PGD_INT_STAT = 0x1014, |
| 150 | PGD_INT_CLR = 0x1018, |
| 151 | PGD_OWN_EEn = 0x1020, |
| 152 | PGD_PORT_INT_EN_EEn = 0x1030, |
| 153 | PGD_PORT_INT_ST_EEn = 0x1034, |
| 154 | PGD_PORT_INT_CL_EEn = 0x1038, |
| 155 | PGD_PORT_CFGn = 0x1080, |
| 156 | PGD_PORT_STATn = 0x1084, |
| 157 | PGD_PORT_PARAMn = 0x1088, |
| 158 | PGD_PORT_BLKn = 0x108C, |
| 159 | PGD_PORT_TRANn = 0x1090, |
| 160 | PGD_PORT_MCHANn = 0x1094, |
| 161 | PGD_PORT_PSHPLLn = 0x1098, |
| 162 | PGD_PORT_PC_CFGn = 0x1600, |
| 163 | PGD_PORT_PC_VALn = 0x1604, |
| 164 | PGD_PORT_PC_VFR_TSn = 0x1608, |
| 165 | PGD_PORT_PC_VFR_STn = 0x160C, |
| 166 | PGD_PORT_PC_VFR_CLn = 0x1610, |
| 167 | PGD_IE_STAT = 0x1700, |
| 168 | PGD_VE_STAT = 0x1710, |
| 169 | }; |
| 170 | |
| 171 | enum rsc_grp { |
| 172 | EE_MGR_RSC_GRP = 1 << 10, |
| 173 | EE_NGD_2 = 2 << 6, |
| 174 | EE_NGD_1 = 0, |
| 175 | }; |
| 176 | |
| 177 | enum mgr_intr { |
| 178 | MGR_INT_RECFG_DONE = 1 << 24, |
| 179 | MGR_INT_TX_NACKED_2 = 1 << 25, |
| 180 | MGR_INT_MSG_BUF_CONTE = 1 << 26, |
| 181 | MGR_INT_RX_MSG_RCVD = 1 << 30, |
| 182 | MGR_INT_TX_MSG_SENT = 1 << 31, |
| 183 | }; |
| 184 | |
| 185 | enum frm_cfg { |
| 186 | FRM_ACTIVE = 1, |
| 187 | CLK_GEAR = 7, |
| 188 | ROOT_FREQ = 11, |
| 189 | REF_CLK_GEAR = 15, |
| 190 | }; |
| 191 | |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 192 | enum msm_ctrl_state { |
| 193 | MSM_CTRL_AWAKE, |
| 194 | MSM_CTRL_SLEEPING, |
| 195 | MSM_CTRL_ASLEEP, |
| 196 | }; |
| 197 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 198 | struct msm_slim_sps_bam { |
| 199 | u32 hdl; |
| 200 | void __iomem *base; |
| 201 | int irq; |
| 202 | }; |
| 203 | |
| 204 | struct msm_slim_endp { |
| 205 | struct sps_pipe *sps; |
| 206 | struct sps_connect config; |
| 207 | struct sps_register_event event; |
| 208 | struct sps_mem_buffer buf; |
| 209 | struct completion *xcomp; |
| 210 | bool connected; |
| 211 | }; |
| 212 | |
| 213 | struct msm_slim_ctrl { |
| 214 | struct slim_controller ctrl; |
| 215 | struct slim_framer framer; |
| 216 | struct device *dev; |
| 217 | void __iomem *base; |
Sagar Dharia | cc96945 | 2011-09-19 10:34:30 -0600 | [diff] [blame] | 218 | struct resource *slew_mem; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 219 | u32 curr_bw; |
| 220 | u8 msg_cnt; |
| 221 | u32 tx_buf[10]; |
| 222 | u8 rx_msgs[MSM_CONCUR_MSG][SLIM_RX_MSGQ_BUF_LEN]; |
| 223 | spinlock_t rx_lock; |
| 224 | int head; |
| 225 | int tail; |
| 226 | int irq; |
| 227 | int err; |
| 228 | int ee; |
| 229 | struct completion *wr_comp; |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 230 | struct msm_slim_sat *satd[MSM_MAX_NSATS]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 231 | struct msm_slim_endp pipes[7]; |
| 232 | struct msm_slim_sps_bam bam; |
| 233 | struct msm_slim_endp rx_msgq; |
| 234 | struct completion rx_msgq_notify; |
| 235 | struct task_struct *rx_msgq_thread; |
| 236 | struct clk *rclk; |
| 237 | struct mutex tx_lock; |
| 238 | u8 pgdla; |
| 239 | bool use_rx_msgqs; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 240 | int pipe_b; |
| 241 | struct completion reconf; |
| 242 | bool reconf_busy; |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 243 | bool chan_active; |
| 244 | enum msm_ctrl_state state; |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 245 | int nsats; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 246 | }; |
| 247 | |
Sagar Dharia | 0ffdca1 | 2011-09-25 18:55:53 -0600 | [diff] [blame] | 248 | struct msm_sat_chan { |
| 249 | u8 chan; |
| 250 | u16 chanh; |
| 251 | int req_rem; |
| 252 | int req_def; |
| 253 | }; |
| 254 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 255 | struct msm_slim_sat { |
| 256 | struct slim_device satcl; |
| 257 | struct msm_slim_ctrl *dev; |
| 258 | struct workqueue_struct *wq; |
| 259 | struct work_struct wd; |
| 260 | u8 sat_msgs[SAT_CONCUR_MSG][40]; |
Sagar Dharia | 0ffdca1 | 2011-09-25 18:55:53 -0600 | [diff] [blame] | 261 | struct msm_sat_chan *satch; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 262 | u8 nsatch; |
| 263 | bool sent_capability; |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 264 | bool pending_reconf; |
| 265 | bool pending_capability; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 266 | int shead; |
| 267 | int stail; |
| 268 | spinlock_t lock; |
| 269 | }; |
| 270 | |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 271 | static struct msm_slim_sat *msm_slim_alloc_sat(struct msm_slim_ctrl *dev); |
| 272 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 273 | static int msm_slim_rx_enqueue(struct msm_slim_ctrl *dev, u32 *buf, u8 len) |
| 274 | { |
| 275 | spin_lock(&dev->rx_lock); |
| 276 | if ((dev->tail + 1) % MSM_CONCUR_MSG == dev->head) { |
| 277 | spin_unlock(&dev->rx_lock); |
| 278 | dev_err(dev->dev, "RX QUEUE full!"); |
| 279 | return -EXFULL; |
| 280 | } |
| 281 | memcpy((u8 *)dev->rx_msgs[dev->tail], (u8 *)buf, len); |
| 282 | dev->tail = (dev->tail + 1) % MSM_CONCUR_MSG; |
| 283 | spin_unlock(&dev->rx_lock); |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | static int msm_slim_rx_dequeue(struct msm_slim_ctrl *dev, u8 *buf) |
| 288 | { |
| 289 | unsigned long flags; |
| 290 | spin_lock_irqsave(&dev->rx_lock, flags); |
| 291 | if (dev->tail == dev->head) { |
| 292 | spin_unlock_irqrestore(&dev->rx_lock, flags); |
| 293 | return -ENODATA; |
| 294 | } |
| 295 | memcpy(buf, (u8 *)dev->rx_msgs[dev->head], 40); |
| 296 | dev->head = (dev->head + 1) % MSM_CONCUR_MSG; |
| 297 | spin_unlock_irqrestore(&dev->rx_lock, flags); |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | static int msm_sat_enqueue(struct msm_slim_sat *sat, u32 *buf, u8 len) |
| 302 | { |
| 303 | struct msm_slim_ctrl *dev = sat->dev; |
| 304 | spin_lock(&sat->lock); |
| 305 | if ((sat->stail + 1) % SAT_CONCUR_MSG == sat->shead) { |
| 306 | spin_unlock(&sat->lock); |
| 307 | dev_err(dev->dev, "SAT QUEUE full!"); |
| 308 | return -EXFULL; |
| 309 | } |
| 310 | memcpy(sat->sat_msgs[sat->stail], (u8 *)buf, len); |
| 311 | sat->stail = (sat->stail + 1) % SAT_CONCUR_MSG; |
| 312 | spin_unlock(&sat->lock); |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static int msm_sat_dequeue(struct msm_slim_sat *sat, u8 *buf) |
| 317 | { |
| 318 | unsigned long flags; |
| 319 | spin_lock_irqsave(&sat->lock, flags); |
| 320 | if (sat->stail == sat->shead) { |
| 321 | spin_unlock_irqrestore(&sat->lock, flags); |
| 322 | return -ENODATA; |
| 323 | } |
| 324 | memcpy(buf, sat->sat_msgs[sat->shead], 40); |
| 325 | sat->shead = (sat->shead + 1) % SAT_CONCUR_MSG; |
| 326 | spin_unlock_irqrestore(&sat->lock, flags); |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | static void msm_get_eaddr(u8 *e_addr, u32 *buffer) |
| 331 | { |
| 332 | e_addr[0] = (buffer[1] >> 24) & 0xff; |
| 333 | e_addr[1] = (buffer[1] >> 16) & 0xff; |
| 334 | e_addr[2] = (buffer[1] >> 8) & 0xff; |
| 335 | e_addr[3] = buffer[1] & 0xff; |
| 336 | e_addr[4] = (buffer[0] >> 24) & 0xff; |
| 337 | e_addr[5] = (buffer[0] >> 16) & 0xff; |
| 338 | } |
| 339 | |
| 340 | static bool msm_is_sat_dev(u8 *e_addr) |
| 341 | { |
| 342 | if (e_addr[5] == QC_MFGID_LSB && e_addr[4] == QC_MFGID_MSB && |
| 343 | e_addr[2] != QC_CHIPID_SL && |
| 344 | (e_addr[1] == QC_DEVID_SAT1 || e_addr[1] == QC_DEVID_SAT2)) |
| 345 | return true; |
| 346 | return false; |
| 347 | } |
| 348 | |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 349 | static int msm_slim_get_ctrl(struct msm_slim_ctrl *dev) |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 350 | { |
Sagar Dharia | 45e7791 | 2012-01-10 09:55:18 -0700 | [diff] [blame] | 351 | #ifdef CONFIG_PM_RUNTIME |
| 352 | int ref = 0; |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 353 | int ret = pm_runtime_get_sync(dev->dev); |
| 354 | if (ret >= 0) { |
| 355 | ref = atomic_read(&dev->dev->power.usage_count); |
| 356 | if (ref <= 0) { |
| 357 | dev_err(dev->dev, "reference count -ve:%d", ref); |
| 358 | ret = -ENODEV; |
| 359 | } |
| 360 | } |
| 361 | return ret; |
Sagar Dharia | 45e7791 | 2012-01-10 09:55:18 -0700 | [diff] [blame] | 362 | #else |
| 363 | return -ENODEV; |
| 364 | #endif |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 365 | } |
| 366 | static void msm_slim_put_ctrl(struct msm_slim_ctrl *dev) |
| 367 | { |
Sagar Dharia | 45e7791 | 2012-01-10 09:55:18 -0700 | [diff] [blame] | 368 | #ifdef CONFIG_PM_RUNTIME |
Sagar Dharia | 38fd187 | 2012-02-06 18:36:38 -0700 | [diff] [blame] | 369 | int ref; |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 370 | pm_runtime_mark_last_busy(dev->dev); |
Sagar Dharia | 38fd187 | 2012-02-06 18:36:38 -0700 | [diff] [blame] | 371 | ref = atomic_read(&dev->dev->power.usage_count); |
| 372 | if (ref <= 0) |
| 373 | dev_err(dev->dev, "reference count mismatch:%d", ref); |
| 374 | else |
| 375 | pm_runtime_put(dev->dev); |
Sagar Dharia | 45e7791 | 2012-01-10 09:55:18 -0700 | [diff] [blame] | 376 | #endif |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 377 | } |
| 378 | |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 379 | static struct msm_slim_sat *addr_to_sat(struct msm_slim_ctrl *dev, u8 laddr) |
| 380 | { |
| 381 | struct msm_slim_sat *sat = NULL; |
| 382 | int i = 0; |
| 383 | while (!sat && i < dev->nsats) { |
| 384 | if (laddr == dev->satd[i]->satcl.laddr) |
| 385 | sat = dev->satd[i]; |
| 386 | i++; |
| 387 | } |
| 388 | return sat; |
| 389 | } |
| 390 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 391 | static irqreturn_t msm_slim_interrupt(int irq, void *d) |
| 392 | { |
| 393 | struct msm_slim_ctrl *dev = d; |
| 394 | u32 pstat; |
| 395 | u32 stat = readl_relaxed(dev->base + MGR_INT_STAT); |
| 396 | |
| 397 | if (stat & MGR_INT_TX_MSG_SENT || stat & MGR_INT_TX_NACKED_2) { |
| 398 | if (stat & MGR_INT_TX_MSG_SENT) |
| 399 | writel_relaxed(MGR_INT_TX_MSG_SENT, |
| 400 | dev->base + MGR_INT_CLR); |
| 401 | else { |
| 402 | writel_relaxed(MGR_INT_TX_NACKED_2, |
| 403 | dev->base + MGR_INT_CLR); |
| 404 | dev->err = -EIO; |
| 405 | } |
| 406 | /* |
| 407 | * Guarantee that interrupt clear bit write goes through before |
| 408 | * signalling completion/exiting ISR |
| 409 | */ |
| 410 | mb(); |
| 411 | if (dev->wr_comp) |
| 412 | complete(dev->wr_comp); |
| 413 | } |
| 414 | if (stat & MGR_INT_RX_MSG_RCVD) { |
| 415 | u32 rx_buf[10]; |
| 416 | u32 mc, mt; |
| 417 | u8 len, i; |
| 418 | rx_buf[0] = readl_relaxed(dev->base + MGR_RX_MSG); |
| 419 | len = rx_buf[0] & 0x1F; |
| 420 | for (i = 1; i < ((len + 3) >> 2); i++) { |
| 421 | rx_buf[i] = readl_relaxed(dev->base + MGR_RX_MSG + |
| 422 | (4 * i)); |
| 423 | dev_dbg(dev->dev, "reading data: %x\n", rx_buf[i]); |
| 424 | } |
| 425 | mt = (rx_buf[0] >> 5) & 0x7; |
| 426 | mc = (rx_buf[0] >> 8) & 0xff; |
| 427 | dev_dbg(dev->dev, "MC: %x, MT: %x\n", mc, mt); |
| 428 | if (mt == SLIM_MSG_MT_DEST_REFERRED_USER || |
| 429 | mt == SLIM_MSG_MT_SRC_REFERRED_USER) { |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 430 | u8 laddr = (u8)((rx_buf[0] >> 16) & 0xFF); |
| 431 | struct msm_slim_sat *sat = addr_to_sat(dev, laddr); |
| 432 | if (sat) |
| 433 | msm_sat_enqueue(sat, rx_buf, len); |
| 434 | else |
| 435 | dev_err(dev->dev, "unknown sat:%d message", |
| 436 | laddr); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 437 | writel_relaxed(MGR_INT_RX_MSG_RCVD, |
| 438 | dev->base + MGR_INT_CLR); |
| 439 | /* |
| 440 | * Guarantee that CLR bit write goes through before |
| 441 | * queuing work |
| 442 | */ |
| 443 | mb(); |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 444 | if (sat) |
| 445 | queue_work(sat->wq, &sat->wd); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 446 | } else if (mt == SLIM_MSG_MT_CORE && |
| 447 | mc == SLIM_MSG_MC_REPORT_PRESENT) { |
| 448 | u8 e_addr[6]; |
| 449 | msm_get_eaddr(e_addr, rx_buf); |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 450 | msm_slim_rx_enqueue(dev, rx_buf, len); |
| 451 | writel_relaxed(MGR_INT_RX_MSG_RCVD, dev->base + |
| 452 | MGR_INT_CLR); |
| 453 | /* |
| 454 | * Guarantee that CLR bit write goes through |
| 455 | * before signalling completion |
| 456 | */ |
| 457 | mb(); |
| 458 | complete(&dev->rx_msgq_notify); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 459 | } else if (mc == SLIM_MSG_MC_REPLY_INFORMATION || |
| 460 | mc == SLIM_MSG_MC_REPLY_VALUE) { |
| 461 | msm_slim_rx_enqueue(dev, rx_buf, len); |
| 462 | writel_relaxed(MGR_INT_RX_MSG_RCVD, dev->base + |
| 463 | MGR_INT_CLR); |
| 464 | /* |
| 465 | * Guarantee that CLR bit write goes through |
| 466 | * before signalling completion |
| 467 | */ |
| 468 | mb(); |
| 469 | complete(&dev->rx_msgq_notify); |
Sagar Dharia | 144e5e0 | 2011-08-08 17:30:11 -0600 | [diff] [blame] | 470 | } else if (mc == SLIM_MSG_MC_REPORT_INFORMATION) { |
| 471 | u8 *buf = (u8 *)rx_buf; |
| 472 | u8 l_addr = buf[2]; |
| 473 | u16 ele = (u16)buf[4] << 4; |
| 474 | ele |= ((buf[3] & 0xf0) >> 4); |
| 475 | dev_err(dev->dev, "Slim-dev:%d report inf element:0x%x", |
| 476 | l_addr, ele); |
| 477 | for (i = 0; i < len - 5; i++) |
| 478 | dev_err(dev->dev, "offset:0x%x:bit mask:%x", |
| 479 | i, buf[i+5]); |
| 480 | writel_relaxed(MGR_INT_RX_MSG_RCVD, dev->base + |
| 481 | MGR_INT_CLR); |
| 482 | /* |
| 483 | * Guarantee that CLR bit write goes through |
| 484 | * before exiting |
| 485 | */ |
| 486 | mb(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 487 | } else { |
| 488 | dev_err(dev->dev, "Unexpected MC,%x MT:%x, len:%d", |
| 489 | mc, mt, len); |
| 490 | for (i = 0; i < ((len + 3) >> 2); i++) |
| 491 | dev_err(dev->dev, "error msg: %x", rx_buf[i]); |
| 492 | writel_relaxed(MGR_INT_RX_MSG_RCVD, dev->base + |
| 493 | MGR_INT_CLR); |
| 494 | /* |
| 495 | * Guarantee that CLR bit write goes through |
| 496 | * before exiting |
| 497 | */ |
| 498 | mb(); |
| 499 | } |
| 500 | } |
| 501 | if (stat & MGR_INT_RECFG_DONE) { |
| 502 | writel_relaxed(MGR_INT_RECFG_DONE, dev->base + MGR_INT_CLR); |
| 503 | /* |
| 504 | * Guarantee that CLR bit write goes through |
| 505 | * before exiting ISR |
| 506 | */ |
| 507 | mb(); |
| 508 | complete(&dev->reconf); |
| 509 | } |
| 510 | pstat = readl_relaxed(dev->base + PGD_PORT_INT_ST_EEn + (16 * dev->ee)); |
| 511 | if (pstat != 0) { |
| 512 | int i = 0; |
| 513 | for (i = dev->pipe_b; i < MSM_SLIM_NPORTS; i++) { |
| 514 | if (pstat & 1 << i) { |
| 515 | u32 val = readl_relaxed(dev->base + |
| 516 | PGD_PORT_STATn + (i * 32)); |
| 517 | if (val & (1 << 19)) { |
| 518 | dev->ctrl.ports[i].err = |
| 519 | SLIM_P_DISCONNECT; |
| 520 | dev->pipes[i-dev->pipe_b].connected = |
| 521 | false; |
| 522 | /* |
| 523 | * SPS will call completion since |
| 524 | * ERROR flags are registered |
| 525 | */ |
| 526 | } else if (val & (1 << 2)) |
| 527 | dev->ctrl.ports[i].err = |
| 528 | SLIM_P_OVERFLOW; |
| 529 | else if (val & (1 << 3)) |
| 530 | dev->ctrl.ports[i].err = |
| 531 | SLIM_P_UNDERFLOW; |
| 532 | } |
| 533 | writel_relaxed(1, dev->base + PGD_PORT_INT_CL_EEn + |
| 534 | (dev->ee * 16)); |
| 535 | } |
| 536 | /* |
| 537 | * Guarantee that port interrupt bit(s) clearing writes go |
| 538 | * through before exiting ISR |
| 539 | */ |
| 540 | mb(); |
| 541 | } |
| 542 | |
| 543 | return IRQ_HANDLED; |
| 544 | } |
| 545 | |
| 546 | static int |
| 547 | msm_slim_init_endpoint(struct msm_slim_ctrl *dev, struct msm_slim_endp *ep) |
| 548 | { |
| 549 | int ret; |
| 550 | struct sps_pipe *endpoint; |
| 551 | struct sps_connect *config = &ep->config; |
| 552 | |
| 553 | /* Allocate the endpoint */ |
| 554 | endpoint = sps_alloc_endpoint(); |
| 555 | if (!endpoint) { |
| 556 | dev_err(dev->dev, "sps_alloc_endpoint failed\n"); |
| 557 | return -ENOMEM; |
| 558 | } |
| 559 | |
| 560 | /* Get default connection configuration for an endpoint */ |
| 561 | ret = sps_get_config(endpoint, config); |
| 562 | if (ret) { |
| 563 | dev_err(dev->dev, "sps_get_config failed 0x%x\n", ret); |
| 564 | goto sps_config_failed; |
| 565 | } |
| 566 | |
| 567 | ep->sps = endpoint; |
| 568 | return 0; |
| 569 | |
| 570 | sps_config_failed: |
| 571 | sps_free_endpoint(endpoint); |
| 572 | return ret; |
| 573 | } |
| 574 | |
| 575 | static void |
| 576 | msm_slim_free_endpoint(struct msm_slim_endp *ep) |
| 577 | { |
| 578 | sps_free_endpoint(ep->sps); |
| 579 | ep->sps = NULL; |
| 580 | } |
| 581 | |
| 582 | static int msm_slim_sps_mem_alloc( |
| 583 | struct msm_slim_ctrl *dev, struct sps_mem_buffer *mem, u32 len) |
| 584 | { |
| 585 | dma_addr_t phys; |
| 586 | |
| 587 | mem->size = len; |
| 588 | mem->min_size = 0; |
| 589 | mem->base = dma_alloc_coherent(dev->dev, mem->size, &phys, GFP_KERNEL); |
| 590 | |
| 591 | if (!mem->base) { |
| 592 | dev_err(dev->dev, "dma_alloc_coherent(%d) failed\n", len); |
| 593 | return -ENOMEM; |
| 594 | } |
| 595 | |
| 596 | mem->phys_base = phys; |
| 597 | memset(mem->base, 0x00, mem->size); |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | static void |
| 602 | msm_slim_sps_mem_free(struct msm_slim_ctrl *dev, struct sps_mem_buffer *mem) |
| 603 | { |
| 604 | dma_free_coherent(dev->dev, mem->size, mem->base, mem->phys_base); |
| 605 | mem->size = 0; |
| 606 | mem->base = NULL; |
| 607 | mem->phys_base = 0; |
| 608 | } |
| 609 | |
| 610 | static void msm_hw_set_port(struct msm_slim_ctrl *dev, u8 pn) |
| 611 | { |
| 612 | u32 set_cfg = DEF_WATERMARK | DEF_ALIGN | DEF_PACK | ENABLE_PORT; |
| 613 | u32 int_port = readl_relaxed(dev->base + PGD_PORT_INT_EN_EEn + |
| 614 | (dev->ee * 16)); |
| 615 | writel_relaxed(set_cfg, dev->base + PGD_PORT_CFGn + (pn * 32)); |
| 616 | writel_relaxed(DEF_BLKSZ, dev->base + PGD_PORT_BLKn + (pn * 32)); |
| 617 | writel_relaxed(DEF_TRANSZ, dev->base + PGD_PORT_TRANn + (pn * 32)); |
| 618 | writel_relaxed((int_port | 1 << pn) , dev->base + PGD_PORT_INT_EN_EEn + |
| 619 | (dev->ee * 16)); |
| 620 | /* Make sure that port registers are updated before returning */ |
| 621 | mb(); |
| 622 | } |
| 623 | |
| 624 | static int msm_slim_connect_pipe_port(struct msm_slim_ctrl *dev, u8 pn) |
| 625 | { |
| 626 | struct msm_slim_endp *endpoint = &dev->pipes[pn]; |
| 627 | struct sps_connect *cfg = &endpoint->config; |
| 628 | u32 stat; |
| 629 | int ret = sps_get_config(dev->pipes[pn].sps, cfg); |
| 630 | if (ret) { |
| 631 | dev_err(dev->dev, "sps pipe-port get config error%x\n", ret); |
| 632 | return ret; |
| 633 | } |
| 634 | cfg->options = SPS_O_DESC_DONE | SPS_O_ERROR | |
| 635 | SPS_O_ACK_TRANSFERS | SPS_O_AUTO_ENABLE; |
| 636 | |
| 637 | if (dev->pipes[pn].connected) { |
| 638 | ret = sps_set_config(dev->pipes[pn].sps, cfg); |
| 639 | if (ret) { |
| 640 | dev_err(dev->dev, "sps pipe-port set config erro:%x\n", |
| 641 | ret); |
| 642 | return ret; |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | stat = readl_relaxed(dev->base + PGD_PORT_STATn + |
| 647 | (32 * (pn + dev->pipe_b))); |
| 648 | if (dev->ctrl.ports[pn].flow == SLIM_SRC) { |
| 649 | cfg->destination = dev->bam.hdl; |
| 650 | cfg->source = SPS_DEV_HANDLE_MEM; |
| 651 | cfg->dest_pipe_index = ((stat & (0xFF << 4)) >> 4); |
| 652 | cfg->src_pipe_index = 0; |
| 653 | dev_dbg(dev->dev, "flow src:pipe num:%d", |
| 654 | cfg->dest_pipe_index); |
| 655 | cfg->mode = SPS_MODE_DEST; |
| 656 | } else { |
| 657 | cfg->source = dev->bam.hdl; |
| 658 | cfg->destination = SPS_DEV_HANDLE_MEM; |
| 659 | cfg->src_pipe_index = ((stat & (0xFF << 4)) >> 4); |
| 660 | cfg->dest_pipe_index = 0; |
| 661 | dev_dbg(dev->dev, "flow dest:pipe num:%d", |
| 662 | cfg->src_pipe_index); |
| 663 | cfg->mode = SPS_MODE_SRC; |
| 664 | } |
| 665 | /* Space for desciptor FIFOs */ |
| 666 | cfg->desc.size = MSM_SLIM_DESC_NUM * sizeof(struct sps_iovec); |
| 667 | cfg->config = SPS_CONFIG_DEFAULT; |
| 668 | ret = sps_connect(dev->pipes[pn].sps, cfg); |
| 669 | if (!ret) { |
| 670 | dev->pipes[pn].connected = true; |
| 671 | msm_hw_set_port(dev, pn + dev->pipe_b); |
| 672 | } |
| 673 | return ret; |
| 674 | } |
| 675 | |
| 676 | static u32 *msm_get_msg_buf(struct slim_controller *ctrl, int len) |
| 677 | { |
| 678 | struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl); |
| 679 | /* |
| 680 | * Currently we block a transaction until the current one completes. |
| 681 | * In case we need multiple transactions, use message Q |
| 682 | */ |
| 683 | return dev->tx_buf; |
| 684 | } |
| 685 | |
| 686 | static int msm_send_msg_buf(struct slim_controller *ctrl, u32 *buf, u8 len) |
| 687 | { |
| 688 | int i; |
| 689 | struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl); |
| 690 | for (i = 0; i < (len + 3) >> 2; i++) { |
| 691 | dev_dbg(dev->dev, "TX data:0x%x\n", buf[i]); |
| 692 | writel_relaxed(buf[i], dev->base + MGR_TX_MSG + (i * 4)); |
| 693 | } |
| 694 | /* Guarantee that message is sent before returning */ |
| 695 | mb(); |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | static int msm_xfer_msg(struct slim_controller *ctrl, struct slim_msg_txn *txn) |
| 700 | { |
| 701 | DECLARE_COMPLETION_ONSTACK(done); |
| 702 | struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl); |
| 703 | u32 *pbuf; |
| 704 | u8 *puc; |
| 705 | int timeout; |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 706 | int msgv = -1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 707 | u8 la = txn->la; |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 708 | u8 mc = (u8)(txn->mc & 0xFF); |
| 709 | /* |
| 710 | * Voting for runtime PM: Slimbus has 2 possible use cases: |
| 711 | * 1. messaging |
| 712 | * 2. Data channels |
| 713 | * Messaging case goes through messaging slots and data channels |
| 714 | * use their own slots |
| 715 | * This "get" votes for messaging bandwidth |
| 716 | */ |
| 717 | if (!(txn->mc & SLIM_MSG_CLK_PAUSE_SEQ_FLG)) |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 718 | msgv = msm_slim_get_ctrl(dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 719 | mutex_lock(&dev->tx_lock); |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 720 | if (dev->state == MSM_CTRL_ASLEEP || |
| 721 | ((!(txn->mc & SLIM_MSG_CLK_PAUSE_SEQ_FLG)) && |
| 722 | dev->state == MSM_CTRL_SLEEPING)) { |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 723 | dev_err(dev->dev, "runtime or system PM suspended state"); |
| 724 | mutex_unlock(&dev->tx_lock); |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 725 | if (msgv >= 0) |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 726 | msm_slim_put_ctrl(dev); |
| 727 | return -EBUSY; |
| 728 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 729 | if (txn->mt == SLIM_MSG_MT_CORE && |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 730 | mc == SLIM_MSG_MC_BEGIN_RECONFIGURATION) { |
| 731 | if (dev->reconf_busy) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 732 | wait_for_completion(&dev->reconf); |
| 733 | dev->reconf_busy = false; |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 734 | } |
| 735 | /* This "get" votes for data channels */ |
| 736 | if (dev->ctrl.sched.usedslots != 0 && |
| 737 | !dev->chan_active) { |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 738 | int chv = msm_slim_get_ctrl(dev); |
| 739 | if (chv >= 0) |
| 740 | dev->chan_active = true; |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 741 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 742 | } |
| 743 | txn->rl--; |
| 744 | pbuf = msm_get_msg_buf(ctrl, txn->rl); |
| 745 | dev->wr_comp = NULL; |
| 746 | dev->err = 0; |
| 747 | |
| 748 | if (txn->dt == SLIM_MSG_DEST_ENUMADDR) { |
| 749 | mutex_unlock(&dev->tx_lock); |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 750 | if (msgv >= 0) |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 751 | msm_slim_put_ctrl(dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 752 | return -EPROTONOSUPPORT; |
| 753 | } |
| 754 | if (txn->mt == SLIM_MSG_MT_CORE && txn->la == 0xFF && |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 755 | (mc == SLIM_MSG_MC_CONNECT_SOURCE || |
| 756 | mc == SLIM_MSG_MC_CONNECT_SINK || |
| 757 | mc == SLIM_MSG_MC_DISCONNECT_PORT)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 758 | la = dev->pgdla; |
| 759 | if (txn->dt == SLIM_MSG_DEST_LOGICALADDR) |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 760 | *pbuf = SLIM_MSG_ASM_FIRST_WORD(txn->rl, txn->mt, mc, 0, la); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 761 | else |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 762 | *pbuf = SLIM_MSG_ASM_FIRST_WORD(txn->rl, txn->mt, mc, 1, la); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 763 | if (txn->dt == SLIM_MSG_DEST_LOGICALADDR) |
| 764 | puc = ((u8 *)pbuf) + 3; |
| 765 | else |
| 766 | puc = ((u8 *)pbuf) + 2; |
| 767 | if (txn->rbuf) |
| 768 | *(puc++) = txn->tid; |
| 769 | if ((txn->mt == SLIM_MSG_MT_CORE) && |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 770 | ((mc >= SLIM_MSG_MC_REQUEST_INFORMATION && |
| 771 | mc <= SLIM_MSG_MC_REPORT_INFORMATION) || |
| 772 | (mc >= SLIM_MSG_MC_REQUEST_VALUE && |
| 773 | mc <= SLIM_MSG_MC_CHANGE_VALUE))) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 774 | *(puc++) = (txn->ec & 0xFF); |
| 775 | *(puc++) = (txn->ec >> 8)&0xFF; |
| 776 | } |
| 777 | if (txn->wbuf) |
| 778 | memcpy(puc, txn->wbuf, txn->len); |
| 779 | if (txn->mt == SLIM_MSG_MT_CORE && txn->la == 0xFF && |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 780 | (mc == SLIM_MSG_MC_CONNECT_SOURCE || |
| 781 | mc == SLIM_MSG_MC_CONNECT_SINK || |
| 782 | mc == SLIM_MSG_MC_DISCONNECT_PORT)) { |
| 783 | if (mc != SLIM_MSG_MC_DISCONNECT_PORT) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 784 | dev->err = msm_slim_connect_pipe_port(dev, *puc); |
| 785 | else { |
| 786 | struct msm_slim_endp *endpoint = &dev->pipes[*puc]; |
| 787 | struct sps_register_event sps_event; |
| 788 | memset(&sps_event, 0, sizeof(sps_event)); |
| 789 | sps_register_event(endpoint->sps, &sps_event); |
| 790 | sps_disconnect(endpoint->sps); |
| 791 | /* |
| 792 | * Remove channel disconnects master-side ports from |
| 793 | * channel. No need to send that again on the bus |
| 794 | */ |
| 795 | dev->pipes[*puc].connected = false; |
| 796 | mutex_unlock(&dev->tx_lock); |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 797 | if (msgv >= 0) |
| 798 | msm_slim_put_ctrl(dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 799 | return 0; |
| 800 | } |
| 801 | if (dev->err) { |
| 802 | dev_err(dev->dev, "pipe-port connect err:%d", dev->err); |
| 803 | mutex_unlock(&dev->tx_lock); |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 804 | if (msgv >= 0) |
| 805 | msm_slim_put_ctrl(dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 806 | return dev->err; |
| 807 | } |
| 808 | *(puc) = *(puc) + dev->pipe_b; |
| 809 | } |
| 810 | if (txn->mt == SLIM_MSG_MT_CORE && |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 811 | mc == SLIM_MSG_MC_BEGIN_RECONFIGURATION) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 812 | dev->reconf_busy = true; |
| 813 | dev->wr_comp = &done; |
| 814 | msm_send_msg_buf(ctrl, pbuf, txn->rl); |
| 815 | timeout = wait_for_completion_timeout(&done, HZ); |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 816 | |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 817 | if (mc == SLIM_MSG_MC_RECONFIGURE_NOW) { |
| 818 | if ((txn->mc == (SLIM_MSG_MC_RECONFIGURE_NOW | |
| 819 | SLIM_MSG_CLK_PAUSE_SEQ_FLG)) && |
| 820 | timeout) { |
| 821 | timeout = wait_for_completion_timeout(&dev->reconf, HZ); |
| 822 | dev->reconf_busy = false; |
| 823 | if (timeout) { |
| 824 | clk_disable(dev->rclk); |
| 825 | disable_irq(dev->irq); |
| 826 | } |
| 827 | } |
| 828 | if ((txn->mc == (SLIM_MSG_MC_RECONFIGURE_NOW | |
| 829 | SLIM_MSG_CLK_PAUSE_SEQ_FLG)) && |
| 830 | !timeout) { |
| 831 | dev->reconf_busy = false; |
| 832 | dev_err(dev->dev, "clock pause failed"); |
| 833 | mutex_unlock(&dev->tx_lock); |
| 834 | return -ETIMEDOUT; |
| 835 | } |
| 836 | if (txn->mt == SLIM_MSG_MT_CORE && |
| 837 | txn->mc == SLIM_MSG_MC_RECONFIGURE_NOW) { |
| 838 | if (dev->ctrl.sched.usedslots == 0 && |
| 839 | dev->chan_active) { |
| 840 | dev->chan_active = false; |
| 841 | msm_slim_put_ctrl(dev); |
| 842 | } |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 843 | } |
| 844 | } |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 845 | mutex_unlock(&dev->tx_lock); |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 846 | if (msgv >= 0) |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 847 | msm_slim_put_ctrl(dev); |
| 848 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 849 | if (!timeout) |
| 850 | dev_err(dev->dev, "TX timed out:MC:0x%x,mt:0x%x", txn->mc, |
| 851 | txn->mt); |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 852 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 853 | return timeout ? dev->err : -ETIMEDOUT; |
| 854 | } |
| 855 | |
| 856 | static int msm_set_laddr(struct slim_controller *ctrl, const u8 *ea, |
| 857 | u8 elen, u8 laddr) |
| 858 | { |
| 859 | struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl); |
| 860 | DECLARE_COMPLETION_ONSTACK(done); |
| 861 | int timeout; |
| 862 | u32 *buf; |
| 863 | mutex_lock(&dev->tx_lock); |
| 864 | buf = msm_get_msg_buf(ctrl, 9); |
| 865 | buf[0] = SLIM_MSG_ASM_FIRST_WORD(9, SLIM_MSG_MT_CORE, |
| 866 | SLIM_MSG_MC_ASSIGN_LOGICAL_ADDRESS, |
| 867 | SLIM_MSG_DEST_LOGICALADDR, |
| 868 | ea[5] | ea[4] << 8); |
| 869 | buf[1] = ea[3] | (ea[2] << 8) | (ea[1] << 16) | (ea[0] << 24); |
| 870 | buf[2] = laddr; |
| 871 | |
| 872 | dev->wr_comp = &done; |
| 873 | msm_send_msg_buf(ctrl, buf, 9); |
| 874 | timeout = wait_for_completion_timeout(&done, HZ); |
| 875 | mutex_unlock(&dev->tx_lock); |
| 876 | return timeout ? dev->err : -ETIMEDOUT; |
| 877 | } |
| 878 | |
Sagar Dharia | 144e5e0 | 2011-08-08 17:30:11 -0600 | [diff] [blame] | 879 | static int msm_clk_pause_wakeup(struct slim_controller *ctrl) |
| 880 | { |
| 881 | struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl); |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 882 | enable_irq(dev->irq); |
Sagar Dharia | 144e5e0 | 2011-08-08 17:30:11 -0600 | [diff] [blame] | 883 | clk_enable(dev->rclk); |
| 884 | writel_relaxed(1, dev->base + FRM_WAKEUP); |
| 885 | /* Make sure framer wakeup write goes through before exiting function */ |
| 886 | mb(); |
| 887 | /* |
| 888 | * Workaround: Currently, slave is reporting lost-sync messages |
| 889 | * after slimbus comes out of clock pause. |
| 890 | * Transaction with slave fail before slave reports that message |
| 891 | * Give some time for that report to come |
| 892 | * Slimbus wakes up in clock gear 10 at 24.576MHz. With each superframe |
| 893 | * being 250 usecs, we wait for 20 superframes here to ensure |
| 894 | * we get the message |
| 895 | */ |
| 896 | usleep_range(5000, 5000); |
| 897 | return 0; |
| 898 | } |
| 899 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 900 | static int msm_config_port(struct slim_controller *ctrl, u8 pn) |
| 901 | { |
| 902 | struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl); |
| 903 | struct msm_slim_endp *endpoint; |
| 904 | int ret = 0; |
| 905 | if (ctrl->ports[pn].req == SLIM_REQ_HALF_DUP || |
| 906 | ctrl->ports[pn].req == SLIM_REQ_MULTI_CH) |
| 907 | return -EPROTONOSUPPORT; |
| 908 | if (pn >= (MSM_SLIM_NPORTS - dev->pipe_b)) |
| 909 | return -ENODEV; |
| 910 | |
| 911 | endpoint = &dev->pipes[pn]; |
| 912 | ret = msm_slim_init_endpoint(dev, endpoint); |
| 913 | dev_dbg(dev->dev, "sps register bam error code:%x\n", ret); |
| 914 | return ret; |
| 915 | } |
| 916 | |
| 917 | static enum slim_port_err msm_slim_port_xfer_status(struct slim_controller *ctr, |
| 918 | u8 pn, u8 **done_buf, u32 *done_len) |
| 919 | { |
| 920 | struct msm_slim_ctrl *dev = slim_get_ctrldata(ctr); |
| 921 | struct sps_iovec sio; |
| 922 | int ret; |
| 923 | if (done_len) |
| 924 | *done_len = 0; |
| 925 | if (done_buf) |
| 926 | *done_buf = NULL; |
| 927 | if (!dev->pipes[pn].connected) |
| 928 | return SLIM_P_DISCONNECT; |
| 929 | ret = sps_get_iovec(dev->pipes[pn].sps, &sio); |
| 930 | if (!ret) { |
| 931 | if (done_len) |
| 932 | *done_len = sio.size; |
| 933 | if (done_buf) |
| 934 | *done_buf = (u8 *)sio.addr; |
| 935 | } |
| 936 | dev_dbg(dev->dev, "get iovec returned %d\n", ret); |
| 937 | return SLIM_P_INPROGRESS; |
| 938 | } |
| 939 | |
| 940 | static int msm_slim_port_xfer(struct slim_controller *ctrl, u8 pn, u8 *iobuf, |
| 941 | u32 len, struct completion *comp) |
| 942 | { |
| 943 | struct sps_register_event sreg; |
| 944 | int ret; |
| 945 | struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl); |
Sagar Dharia | e77961f | 2011-09-27 14:03:50 -0600 | [diff] [blame] | 946 | if (pn >= 7) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 947 | return -ENODEV; |
| 948 | |
| 949 | |
| 950 | ctrl->ports[pn].xcomp = comp; |
| 951 | sreg.options = (SPS_EVENT_DESC_DONE|SPS_EVENT_ERROR); |
| 952 | sreg.mode = SPS_TRIGGER_WAIT; |
| 953 | sreg.xfer_done = comp; |
| 954 | sreg.callback = NULL; |
| 955 | sreg.user = &ctrl->ports[pn]; |
| 956 | ret = sps_register_event(dev->pipes[pn].sps, &sreg); |
| 957 | if (ret) { |
| 958 | dev_dbg(dev->dev, "sps register event error:%x\n", ret); |
| 959 | return ret; |
| 960 | } |
| 961 | ret = sps_transfer_one(dev->pipes[pn].sps, (u32)iobuf, len, NULL, |
| 962 | SPS_IOVEC_FLAG_INT); |
| 963 | dev_dbg(dev->dev, "sps submit xfer error code:%x\n", ret); |
| 964 | |
| 965 | return ret; |
| 966 | } |
| 967 | |
| 968 | static int msm_sat_define_ch(struct msm_slim_sat *sat, u8 *buf, u8 len, u8 mc) |
| 969 | { |
| 970 | struct msm_slim_ctrl *dev = sat->dev; |
| 971 | enum slim_ch_control oper; |
| 972 | int i; |
| 973 | int ret = 0; |
| 974 | if (mc == SLIM_USR_MC_CHAN_CTRL) { |
Sagar Dharia | 0ffdca1 | 2011-09-25 18:55:53 -0600 | [diff] [blame] | 975 | for (i = 0; i < sat->nsatch; i++) { |
| 976 | if (buf[5] == sat->satch[i].chan) |
| 977 | break; |
| 978 | } |
| 979 | if (i >= sat->nsatch) |
| 980 | return -ENOTCONN; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 981 | oper = ((buf[3] & 0xC0) >> 6); |
| 982 | /* part of grp. activating/removing 1 will take care of rest */ |
Sagar Dharia | 0ffdca1 | 2011-09-25 18:55:53 -0600 | [diff] [blame] | 983 | ret = slim_control_ch(&sat->satcl, sat->satch[i].chanh, oper, |
| 984 | false); |
| 985 | if (!ret) { |
| 986 | for (i = 5; i < len; i++) { |
| 987 | int j; |
| 988 | for (j = 0; j < sat->nsatch; j++) { |
| 989 | if (buf[i] == sat->satch[j].chan) { |
| 990 | if (oper == SLIM_CH_REMOVE) |
| 991 | sat->satch[j].req_rem++; |
| 992 | else |
| 993 | sat->satch[j].req_def++; |
| 994 | break; |
| 995 | } |
| 996 | } |
| 997 | } |
| 998 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 999 | } else { |
| 1000 | u16 chh[40]; |
| 1001 | struct slim_ch prop; |
| 1002 | u32 exp; |
| 1003 | u8 coeff, cc; |
| 1004 | u8 prrate = buf[6]; |
Sagar Dharia | 0ffdca1 | 2011-09-25 18:55:53 -0600 | [diff] [blame] | 1005 | if (len <= 8) |
| 1006 | return -EINVAL; |
| 1007 | for (i = 8; i < len; i++) { |
| 1008 | int j = 0; |
| 1009 | for (j = 0; j < sat->nsatch; j++) { |
| 1010 | if (sat->satch[j].chan == buf[i]) { |
| 1011 | chh[i - 8] = sat->satch[j].chanh; |
| 1012 | break; |
| 1013 | } |
| 1014 | } |
| 1015 | if (j < sat->nsatch) { |
| 1016 | u16 dummy; |
| 1017 | ret = slim_query_ch(&sat->satcl, buf[i], |
| 1018 | &dummy); |
| 1019 | if (ret) |
| 1020 | return ret; |
| 1021 | if (mc == SLIM_USR_MC_DEF_ACT_CHAN) |
| 1022 | sat->satch[j].req_def++; |
| 1023 | continue; |
| 1024 | } |
| 1025 | if (sat->nsatch >= MSM_MAX_SATCH) |
| 1026 | return -EXFULL; |
| 1027 | ret = slim_query_ch(&sat->satcl, buf[i], &chh[i - 8]); |
| 1028 | if (ret) |
| 1029 | return ret; |
| 1030 | sat->satch[j].chan = buf[i]; |
| 1031 | sat->satch[j].chanh = chh[i - 8]; |
| 1032 | if (mc == SLIM_USR_MC_DEF_ACT_CHAN) |
| 1033 | sat->satch[j].req_def++; |
| 1034 | sat->nsatch++; |
| 1035 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1036 | prop.dataf = (enum slim_ch_dataf)((buf[3] & 0xE0) >> 5); |
| 1037 | prop.auxf = (enum slim_ch_auxf)((buf[4] & 0xC0) >> 5); |
| 1038 | prop.baser = SLIM_RATE_4000HZ; |
| 1039 | if (prrate & 0x8) |
| 1040 | prop.baser = SLIM_RATE_11025HZ; |
| 1041 | else |
| 1042 | prop.baser = SLIM_RATE_4000HZ; |
| 1043 | prop.prot = (enum slim_ch_proto)(buf[5] & 0x0F); |
| 1044 | prop.sampleszbits = (buf[4] & 0x1F)*SLIM_CL_PER_SL; |
| 1045 | exp = (u32)((buf[5] & 0xF0) >> 4); |
| 1046 | coeff = (buf[4] & 0x20) >> 5; |
| 1047 | cc = (coeff ? 3 : 1); |
| 1048 | prop.ratem = cc * (1 << exp); |
| 1049 | if (i > 9) |
| 1050 | ret = slim_define_ch(&sat->satcl, &prop, chh, len - 8, |
Sagar Dharia | 0ffdca1 | 2011-09-25 18:55:53 -0600 | [diff] [blame] | 1051 | true, &chh[0]); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1052 | else |
| 1053 | ret = slim_define_ch(&sat->satcl, &prop, |
Sagar Dharia | 0ffdca1 | 2011-09-25 18:55:53 -0600 | [diff] [blame] | 1054 | &chh[0], 1, false, NULL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1055 | dev_dbg(dev->dev, "define sat grp returned:%d", ret); |
Sagar Dharia | 0ffdca1 | 2011-09-25 18:55:53 -0600 | [diff] [blame] | 1056 | if (ret) |
| 1057 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1058 | |
| 1059 | /* part of group so activating 1 will take care of rest */ |
| 1060 | if (mc == SLIM_USR_MC_DEF_ACT_CHAN) |
| 1061 | ret = slim_control_ch(&sat->satcl, |
Sagar Dharia | 0ffdca1 | 2011-09-25 18:55:53 -0600 | [diff] [blame] | 1062 | chh[0], |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1063 | SLIM_CH_ACTIVATE, false); |
| 1064 | } |
| 1065 | return ret; |
| 1066 | } |
| 1067 | |
| 1068 | static void msm_slim_rxwq(struct msm_slim_ctrl *dev) |
| 1069 | { |
| 1070 | u8 buf[40]; |
| 1071 | u8 mc, mt, len; |
| 1072 | int i, ret; |
| 1073 | if ((msm_slim_rx_dequeue(dev, (u8 *)buf)) != -ENODATA) { |
| 1074 | len = buf[0] & 0x1F; |
| 1075 | mt = (buf[0] >> 5) & 0x7; |
| 1076 | mc = buf[1]; |
| 1077 | if (mt == SLIM_MSG_MT_CORE && |
| 1078 | mc == SLIM_MSG_MC_REPORT_PRESENT) { |
| 1079 | u8 laddr; |
| 1080 | u8 e_addr[6]; |
| 1081 | for (i = 0; i < 6; i++) |
| 1082 | e_addr[i] = buf[7-i]; |
| 1083 | |
| 1084 | ret = slim_assign_laddr(&dev->ctrl, e_addr, 6, &laddr); |
| 1085 | /* Is this Qualcomm ported generic device? */ |
| 1086 | if (!ret && e_addr[5] == QC_MFGID_LSB && |
| 1087 | e_addr[4] == QC_MFGID_MSB && |
| 1088 | e_addr[1] == QC_DEVID_PGD && |
| 1089 | e_addr[2] != QC_CHIPID_SL) |
| 1090 | dev->pgdla = laddr; |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1091 | if (!ret && !pm_runtime_enabled(dev->dev) && |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 1092 | laddr == (QC_MSM_DEVS - 1)) |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1093 | pm_runtime_enable(dev->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1094 | |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 1095 | if (!ret && msm_is_sat_dev(e_addr)) { |
| 1096 | struct msm_slim_sat *sat = addr_to_sat(dev, |
| 1097 | laddr); |
| 1098 | if (!sat) |
| 1099 | sat = msm_slim_alloc_sat(dev); |
| 1100 | if (!sat) |
| 1101 | return; |
| 1102 | |
| 1103 | sat->satcl.laddr = laddr; |
| 1104 | msm_sat_enqueue(sat, (u32 *)buf, len); |
| 1105 | queue_work(sat->wq, &sat->wd); |
| 1106 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1107 | } else if (mc == SLIM_MSG_MC_REPLY_INFORMATION || |
| 1108 | mc == SLIM_MSG_MC_REPLY_VALUE) { |
| 1109 | u8 tid = buf[3]; |
| 1110 | dev_dbg(dev->dev, "tid:%d, len:%d\n", tid, len - 4); |
| 1111 | slim_msg_response(&dev->ctrl, &buf[4], tid, |
| 1112 | len - 4); |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 1113 | pm_runtime_mark_last_busy(dev->dev); |
Sagar Dharia | 144e5e0 | 2011-08-08 17:30:11 -0600 | [diff] [blame] | 1114 | } else if (mc == SLIM_MSG_MC_REPORT_INFORMATION) { |
| 1115 | u8 l_addr = buf[2]; |
| 1116 | u16 ele = (u16)buf[4] << 4; |
| 1117 | ele |= ((buf[3] & 0xf0) >> 4); |
| 1118 | dev_err(dev->dev, "Slim-dev:%d report inf element:0x%x", |
| 1119 | l_addr, ele); |
| 1120 | for (i = 0; i < len - 5; i++) |
| 1121 | dev_err(dev->dev, "offset:0x%x:bit mask:%x", |
| 1122 | i, buf[i+5]); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1123 | } else { |
| 1124 | dev_err(dev->dev, "unexpected message:mc:%x, mt:%x", |
| 1125 | mc, mt); |
| 1126 | for (i = 0; i < len; i++) |
| 1127 | dev_err(dev->dev, "error msg: %x", buf[i]); |
| 1128 | |
| 1129 | } |
| 1130 | } else |
| 1131 | dev_err(dev->dev, "rxwq called and no dequeue"); |
| 1132 | } |
| 1133 | |
| 1134 | static void slim_sat_rxprocess(struct work_struct *work) |
| 1135 | { |
| 1136 | struct msm_slim_sat *sat = container_of(work, struct msm_slim_sat, wd); |
| 1137 | struct msm_slim_ctrl *dev = sat->dev; |
| 1138 | u8 buf[40]; |
| 1139 | |
| 1140 | while ((msm_sat_dequeue(sat, buf)) != -ENODATA) { |
| 1141 | struct slim_msg_txn txn; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1142 | u8 len, mc, mt; |
| 1143 | u32 bw_sl; |
| 1144 | int ret = 0; |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 1145 | int satv = -1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1146 | bool gen_ack = false; |
| 1147 | u8 tid; |
| 1148 | u8 wbuf[8]; |
Sagar Dharia | 0ffdca1 | 2011-09-25 18:55:53 -0600 | [diff] [blame] | 1149 | int i; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1150 | txn.mt = SLIM_MSG_MT_SRC_REFERRED_USER; |
| 1151 | txn.dt = SLIM_MSG_DEST_LOGICALADDR; |
| 1152 | txn.ec = 0; |
| 1153 | txn.rbuf = NULL; |
| 1154 | txn.la = sat->satcl.laddr; |
| 1155 | /* satellite handling */ |
| 1156 | len = buf[0] & 0x1F; |
| 1157 | mc = buf[1]; |
| 1158 | mt = (buf[0] >> 5) & 0x7; |
| 1159 | |
| 1160 | if (mt == SLIM_MSG_MT_CORE && |
| 1161 | mc == SLIM_MSG_MC_REPORT_PRESENT) { |
| 1162 | u8 laddr; |
| 1163 | u8 e_addr[6]; |
| 1164 | for (i = 0; i < 6; i++) |
| 1165 | e_addr[i] = buf[7-i]; |
| 1166 | |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1167 | if (pm_runtime_enabled(dev->dev)) { |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 1168 | satv = msm_slim_get_ctrl(dev); |
| 1169 | if (satv >= 0) |
| 1170 | sat->pending_capability = true; |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1171 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1172 | slim_assign_laddr(&dev->ctrl, e_addr, 6, &laddr); |
| 1173 | sat->satcl.laddr = laddr; |
Sagar Dharia | 69bf557 | 2012-02-21 14:45:35 -0700 | [diff] [blame^] | 1174 | /* |
| 1175 | * Since capability message is already sent, present |
| 1176 | * message will indicate subsystem hosting this |
| 1177 | * satellite has restarted. |
| 1178 | * Remove all active channels of this satellite |
| 1179 | * when this is detected |
| 1180 | */ |
| 1181 | if (sat->sent_capability) { |
| 1182 | for (i = 0; i < sat->nsatch; i++) { |
| 1183 | enum slim_ch_state chs = |
| 1184 | slim_get_ch_state(&sat->satcl, |
| 1185 | sat->satch[i].chanh); |
| 1186 | pr_err("Slim-SSR, sat:%d, rm chan:%d", |
| 1187 | laddr, |
| 1188 | sat->satch[i].chan); |
| 1189 | if (chs == SLIM_CH_ACTIVE) |
| 1190 | slim_control_ch(&sat->satcl, |
| 1191 | sat->satch[i].chanh, |
| 1192 | SLIM_CH_REMOVE, true); |
| 1193 | } |
| 1194 | } |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1195 | } else if (mt != SLIM_MSG_MT_CORE && |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 1196 | mc != SLIM_MSG_MC_REPORT_PRESENT) { |
| 1197 | satv = msm_slim_get_ctrl(dev); |
| 1198 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1199 | switch (mc) { |
| 1200 | case SLIM_MSG_MC_REPORT_PRESENT: |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1201 | /* Remove runtime_pm vote once satellite acks */ |
| 1202 | if (mt != SLIM_MSG_MT_CORE) { |
| 1203 | if (pm_runtime_enabled(dev->dev) && |
| 1204 | sat->pending_capability) { |
| 1205 | msm_slim_put_ctrl(dev); |
| 1206 | sat->pending_capability = false; |
| 1207 | } |
| 1208 | continue; |
| 1209 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1210 | /* send a Manager capability msg */ |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 1211 | if (sat->sent_capability) { |
| 1212 | if (mt == SLIM_MSG_MT_CORE) |
| 1213 | goto send_capability; |
| 1214 | else |
| 1215 | continue; |
| 1216 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1217 | ret = slim_add_device(&dev->ctrl, &sat->satcl); |
| 1218 | if (ret) { |
| 1219 | dev_err(dev->dev, |
| 1220 | "Satellite-init failed"); |
| 1221 | continue; |
| 1222 | } |
Sagar Dharia | 0ffdca1 | 2011-09-25 18:55:53 -0600 | [diff] [blame] | 1223 | /* Satellite-channels */ |
| 1224 | sat->satch = kzalloc(MSM_MAX_SATCH * |
| 1225 | sizeof(struct msm_sat_chan), |
| 1226 | GFP_KERNEL); |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 1227 | send_capability: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1228 | txn.mc = SLIM_USR_MC_MASTER_CAPABILITY; |
| 1229 | txn.mt = SLIM_MSG_MT_SRC_REFERRED_USER; |
| 1230 | txn.la = sat->satcl.laddr; |
| 1231 | txn.rl = 8; |
| 1232 | wbuf[0] = SAT_MAGIC_LSB; |
| 1233 | wbuf[1] = SAT_MAGIC_MSB; |
| 1234 | wbuf[2] = SAT_MSG_VER; |
| 1235 | wbuf[3] = SAT_MSG_PROT; |
| 1236 | txn.wbuf = wbuf; |
| 1237 | txn.len = 4; |
| 1238 | sat->sent_capability = true; |
| 1239 | msm_xfer_msg(&dev->ctrl, &txn); |
| 1240 | break; |
| 1241 | case SLIM_USR_MC_ADDR_QUERY: |
| 1242 | memcpy(&wbuf[1], &buf[4], 6); |
| 1243 | ret = slim_get_logical_addr(&sat->satcl, |
| 1244 | &wbuf[1], 6, &wbuf[7]); |
| 1245 | if (ret) |
| 1246 | memset(&wbuf[1], 0, 6); |
| 1247 | wbuf[0] = buf[3]; |
| 1248 | txn.mc = SLIM_USR_MC_ADDR_REPLY; |
| 1249 | txn.rl = 12; |
| 1250 | txn.len = 8; |
| 1251 | txn.wbuf = wbuf; |
| 1252 | msm_xfer_msg(&dev->ctrl, &txn); |
| 1253 | break; |
| 1254 | case SLIM_USR_MC_DEFINE_CHAN: |
| 1255 | case SLIM_USR_MC_DEF_ACT_CHAN: |
| 1256 | case SLIM_USR_MC_CHAN_CTRL: |
| 1257 | if (mc != SLIM_USR_MC_CHAN_CTRL) |
| 1258 | tid = buf[7]; |
| 1259 | else |
| 1260 | tid = buf[4]; |
| 1261 | gen_ack = true; |
| 1262 | ret = msm_sat_define_ch(sat, buf, len, mc); |
| 1263 | if (ret) { |
| 1264 | dev_err(dev->dev, |
| 1265 | "SAT define_ch returned:%d", |
| 1266 | ret); |
| 1267 | } |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1268 | if (!sat->pending_reconf) { |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 1269 | int chv = msm_slim_get_ctrl(dev); |
| 1270 | if (chv >= 0) |
| 1271 | sat->pending_reconf = true; |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1272 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1273 | break; |
| 1274 | case SLIM_USR_MC_RECONFIG_NOW: |
| 1275 | tid = buf[3]; |
| 1276 | gen_ack = true; |
| 1277 | ret = slim_reconfigure_now(&sat->satcl); |
Sagar Dharia | 0ffdca1 | 2011-09-25 18:55:53 -0600 | [diff] [blame] | 1278 | for (i = 0; i < sat->nsatch; i++) { |
| 1279 | struct msm_sat_chan *sch = &sat->satch[i]; |
| 1280 | if (sch->req_rem) { |
| 1281 | if (!ret) |
| 1282 | slim_dealloc_ch(&sat->satcl, |
| 1283 | sch->chanh); |
| 1284 | sch->req_rem--; |
| 1285 | } else if (sch->req_def) { |
| 1286 | if (ret) |
| 1287 | slim_dealloc_ch(&sat->satcl, |
| 1288 | sch->chanh); |
| 1289 | sch->req_def--; |
| 1290 | } |
| 1291 | } |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1292 | if (sat->pending_reconf) { |
| 1293 | msm_slim_put_ctrl(dev); |
| 1294 | sat->pending_reconf = false; |
| 1295 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1296 | break; |
| 1297 | case SLIM_USR_MC_REQ_BW: |
| 1298 | /* what we get is in SLOTS */ |
| 1299 | bw_sl = (u32)buf[4] << 3 | |
| 1300 | ((buf[3] & 0xE0) >> 5); |
| 1301 | sat->satcl.pending_msgsl = bw_sl; |
| 1302 | tid = buf[5]; |
| 1303 | gen_ack = true; |
| 1304 | break; |
| 1305 | case SLIM_USR_MC_CONNECT_SRC: |
| 1306 | case SLIM_USR_MC_CONNECT_SINK: |
| 1307 | if (mc == SLIM_USR_MC_CONNECT_SRC) |
| 1308 | txn.mc = SLIM_MSG_MC_CONNECT_SOURCE; |
| 1309 | else |
| 1310 | txn.mc = SLIM_MSG_MC_CONNECT_SINK; |
| 1311 | wbuf[0] = buf[4] & 0x1F; |
| 1312 | wbuf[1] = buf[5]; |
| 1313 | tid = buf[6]; |
| 1314 | txn.la = buf[3]; |
| 1315 | txn.mt = SLIM_MSG_MT_CORE; |
| 1316 | txn.rl = 6; |
| 1317 | txn.len = 2; |
| 1318 | txn.wbuf = wbuf; |
| 1319 | gen_ack = true; |
| 1320 | ret = msm_xfer_msg(&dev->ctrl, &txn); |
| 1321 | break; |
| 1322 | case SLIM_USR_MC_DISCONNECT_PORT: |
| 1323 | txn.mc = SLIM_MSG_MC_DISCONNECT_PORT; |
| 1324 | wbuf[0] = buf[4] & 0x1F; |
| 1325 | tid = buf[5]; |
| 1326 | txn.la = buf[3]; |
| 1327 | txn.rl = 5; |
| 1328 | txn.len = 1; |
| 1329 | txn.mt = SLIM_MSG_MT_CORE; |
| 1330 | txn.wbuf = wbuf; |
| 1331 | gen_ack = true; |
| 1332 | ret = msm_xfer_msg(&dev->ctrl, &txn); |
| 1333 | default: |
| 1334 | break; |
| 1335 | } |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1336 | if (!gen_ack) { |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 1337 | if (mc != SLIM_MSG_MC_REPORT_PRESENT && satv >= 0) |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1338 | msm_slim_put_ctrl(dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1339 | continue; |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1340 | } |
| 1341 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1342 | wbuf[0] = tid; |
| 1343 | if (!ret) |
| 1344 | wbuf[1] = MSM_SAT_SUCCSS; |
| 1345 | else |
| 1346 | wbuf[1] = 0; |
| 1347 | txn.mc = SLIM_USR_MC_GENERIC_ACK; |
| 1348 | txn.la = sat->satcl.laddr; |
| 1349 | txn.rl = 6; |
| 1350 | txn.len = 2; |
| 1351 | txn.wbuf = wbuf; |
| 1352 | txn.mt = SLIM_MSG_MT_SRC_REFERRED_USER; |
| 1353 | msm_xfer_msg(&dev->ctrl, &txn); |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 1354 | if (satv >= 0) |
| 1355 | msm_slim_put_ctrl(dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1356 | } |
| 1357 | } |
| 1358 | |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 1359 | static struct msm_slim_sat *msm_slim_alloc_sat(struct msm_slim_ctrl *dev) |
| 1360 | { |
| 1361 | struct msm_slim_sat *sat; |
| 1362 | char *name; |
| 1363 | if (dev->nsats >= MSM_MAX_NSATS) |
| 1364 | return NULL; |
| 1365 | |
| 1366 | sat = kzalloc(sizeof(struct msm_slim_sat), GFP_KERNEL); |
| 1367 | if (!sat) { |
| 1368 | dev_err(dev->dev, "no memory for satellite"); |
| 1369 | return NULL; |
| 1370 | } |
| 1371 | name = kzalloc(SLIMBUS_NAME_SIZE, GFP_KERNEL); |
| 1372 | if (!name) { |
| 1373 | dev_err(dev->dev, "no memory for satellite name"); |
| 1374 | kfree(sat); |
| 1375 | return NULL; |
| 1376 | } |
| 1377 | dev->satd[dev->nsats] = sat; |
| 1378 | sat->dev = dev; |
| 1379 | snprintf(name, SLIMBUS_NAME_SIZE, "msm_sat%d", dev->nsats); |
| 1380 | sat->satcl.name = name; |
| 1381 | spin_lock_init(&sat->lock); |
| 1382 | INIT_WORK(&sat->wd, slim_sat_rxprocess); |
| 1383 | sat->wq = create_singlethread_workqueue(sat->satcl.name); |
| 1384 | if (!sat->wq) { |
| 1385 | kfree(name); |
| 1386 | kfree(sat); |
| 1387 | return NULL; |
| 1388 | } |
| 1389 | /* |
| 1390 | * Both sats will be allocated from RX thread and RX thread will |
| 1391 | * process messages sequentially. No synchronization necessary |
| 1392 | */ |
| 1393 | dev->nsats++; |
| 1394 | return sat; |
| 1395 | } |
| 1396 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1397 | static void |
| 1398 | msm_slim_rx_msgq_event(struct msm_slim_ctrl *dev, struct sps_event_notify *ev) |
| 1399 | { |
| 1400 | u32 *buf = ev->data.transfer.user; |
| 1401 | struct sps_iovec *iovec = &ev->data.transfer.iovec; |
| 1402 | |
| 1403 | /* |
| 1404 | * Note the virtual address needs to be offset by the same index |
| 1405 | * as the physical address or just pass in the actual virtual address |
| 1406 | * if the sps_mem_buffer is not needed. Note that if completion is |
| 1407 | * used, the virtual address won't be available and will need to be |
| 1408 | * calculated based on the offset of the physical address |
| 1409 | */ |
| 1410 | if (ev->event_id == SPS_EVENT_DESC_DONE) { |
| 1411 | |
| 1412 | pr_debug("buf = 0x%p, data = 0x%x\n", buf, *buf); |
| 1413 | |
| 1414 | pr_debug("iovec = (0x%x 0x%x 0x%x)\n", |
| 1415 | iovec->addr, iovec->size, iovec->flags); |
| 1416 | |
| 1417 | } else { |
| 1418 | dev_err(dev->dev, "%s: unknown event %d\n", |
| 1419 | __func__, ev->event_id); |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | static void msm_slim_rx_msgq_cb(struct sps_event_notify *notify) |
| 1424 | { |
| 1425 | struct msm_slim_ctrl *dev = (struct msm_slim_ctrl *)notify->user; |
| 1426 | msm_slim_rx_msgq_event(dev, notify); |
| 1427 | } |
| 1428 | |
| 1429 | /* Queue up Rx message buffer */ |
| 1430 | static inline int |
| 1431 | msm_slim_post_rx_msgq(struct msm_slim_ctrl *dev, int ix) |
| 1432 | { |
| 1433 | int ret; |
| 1434 | u32 flags = SPS_IOVEC_FLAG_INT; |
| 1435 | struct msm_slim_endp *endpoint = &dev->rx_msgq; |
| 1436 | struct sps_mem_buffer *mem = &endpoint->buf; |
| 1437 | struct sps_pipe *pipe = endpoint->sps; |
| 1438 | |
| 1439 | /* Rx message queue buffers are 4 bytes in length */ |
| 1440 | u8 *virt_addr = mem->base + (4 * ix); |
| 1441 | u32 phys_addr = mem->phys_base + (4 * ix); |
| 1442 | |
| 1443 | pr_debug("index:%d, phys:0x%x, virt:0x%p\n", ix, phys_addr, virt_addr); |
| 1444 | |
| 1445 | ret = sps_transfer_one(pipe, phys_addr, 4, virt_addr, flags); |
| 1446 | if (ret) |
| 1447 | dev_err(dev->dev, "transfer_one() failed 0x%x, %d\n", ret, ix); |
| 1448 | |
| 1449 | return ret; |
| 1450 | } |
| 1451 | |
| 1452 | static inline int |
| 1453 | msm_slim_rx_msgq_get(struct msm_slim_ctrl *dev, u32 *data, int offset) |
| 1454 | { |
| 1455 | struct msm_slim_endp *endpoint = &dev->rx_msgq; |
| 1456 | struct sps_mem_buffer *mem = &endpoint->buf; |
| 1457 | struct sps_pipe *pipe = endpoint->sps; |
| 1458 | struct sps_iovec iovec; |
| 1459 | int index; |
| 1460 | int ret; |
| 1461 | |
| 1462 | ret = sps_get_iovec(pipe, &iovec); |
| 1463 | if (ret) { |
| 1464 | dev_err(dev->dev, "sps_get_iovec() failed 0x%x\n", ret); |
| 1465 | goto err_exit; |
| 1466 | } |
| 1467 | |
| 1468 | pr_debug("iovec = (0x%x 0x%x 0x%x)\n", |
| 1469 | iovec.addr, iovec.size, iovec.flags); |
| 1470 | BUG_ON(iovec.addr < mem->phys_base); |
| 1471 | BUG_ON(iovec.addr >= mem->phys_base + mem->size); |
| 1472 | |
| 1473 | /* Calculate buffer index */ |
| 1474 | index = (iovec.addr - mem->phys_base) / 4; |
| 1475 | *(data + offset) = *((u32 *)mem->base + index); |
| 1476 | |
| 1477 | pr_debug("buf = 0x%p, data = 0x%x\n", (u32 *)mem->base + index, *data); |
| 1478 | |
| 1479 | /* Add buffer back to the queue */ |
| 1480 | (void)msm_slim_post_rx_msgq(dev, index); |
| 1481 | |
| 1482 | err_exit: |
| 1483 | return ret; |
| 1484 | } |
| 1485 | |
| 1486 | static int msm_slim_rx_msgq_thread(void *data) |
| 1487 | { |
| 1488 | struct msm_slim_ctrl *dev = (struct msm_slim_ctrl *)data; |
| 1489 | struct completion *notify = &dev->rx_msgq_notify; |
| 1490 | struct msm_slim_sat *sat = NULL; |
| 1491 | u32 mc = 0; |
| 1492 | u32 mt = 0; |
| 1493 | u32 buffer[10]; |
| 1494 | int index = 0; |
| 1495 | u8 msg_len = 0; |
| 1496 | int ret; |
| 1497 | |
| 1498 | dev_dbg(dev->dev, "rx thread started"); |
| 1499 | |
| 1500 | while (!kthread_should_stop()) { |
| 1501 | set_current_state(TASK_INTERRUPTIBLE); |
| 1502 | ret = wait_for_completion_interruptible(notify); |
| 1503 | |
| 1504 | if (ret) |
| 1505 | dev_err(dev->dev, "rx thread wait error:%d", ret); |
| 1506 | |
| 1507 | /* 1 irq notification per message */ |
| 1508 | if (!dev->use_rx_msgqs) { |
| 1509 | msm_slim_rxwq(dev); |
| 1510 | continue; |
| 1511 | } |
| 1512 | |
| 1513 | ret = msm_slim_rx_msgq_get(dev, buffer, index); |
| 1514 | if (ret) { |
| 1515 | dev_err(dev->dev, "rx_msgq_get() failed 0x%x\n", ret); |
| 1516 | continue; |
| 1517 | } |
| 1518 | |
| 1519 | pr_debug("message[%d] = 0x%x\n", index, *buffer); |
| 1520 | |
| 1521 | /* Decide if we use generic RX or satellite RX */ |
| 1522 | if (index++ == 0) { |
| 1523 | msg_len = *buffer & 0x1F; |
| 1524 | pr_debug("Start of new message, len = %d\n", msg_len); |
| 1525 | mt = (buffer[0] >> 5) & 0x7; |
| 1526 | mc = (buffer[0] >> 8) & 0xff; |
| 1527 | dev_dbg(dev->dev, "MC: %x, MT: %x\n", mc, mt); |
| 1528 | if (mt == SLIM_MSG_MT_DEST_REFERRED_USER || |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 1529 | mt == SLIM_MSG_MT_SRC_REFERRED_USER) { |
| 1530 | u8 laddr; |
| 1531 | laddr = (u8)((buffer[0] >> 16) & 0xff); |
| 1532 | sat = addr_to_sat(dev, laddr); |
| 1533 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1534 | } else if ((index * 4) >= msg_len) { |
| 1535 | index = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1536 | if (sat) { |
| 1537 | msm_sat_enqueue(sat, buffer, msg_len); |
| 1538 | queue_work(sat->wq, &sat->wd); |
| 1539 | sat = NULL; |
| 1540 | } else { |
| 1541 | msm_slim_rx_enqueue(dev, buffer, msg_len); |
| 1542 | msm_slim_rxwq(dev); |
| 1543 | } |
| 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | return 0; |
| 1548 | } |
| 1549 | |
| 1550 | static int __devinit msm_slim_init_rx_msgq(struct msm_slim_ctrl *dev) |
| 1551 | { |
| 1552 | int i, ret; |
| 1553 | u32 pipe_offset; |
| 1554 | struct msm_slim_endp *endpoint = &dev->rx_msgq; |
| 1555 | struct sps_connect *config = &endpoint->config; |
| 1556 | struct sps_mem_buffer *descr = &config->desc; |
| 1557 | struct sps_mem_buffer *mem = &endpoint->buf; |
| 1558 | struct completion *notify = &dev->rx_msgq_notify; |
| 1559 | |
| 1560 | struct sps_register_event sps_error_event; /* SPS_ERROR */ |
| 1561 | struct sps_register_event sps_descr_event; /* DESCR_DONE */ |
| 1562 | |
| 1563 | /* Allocate the endpoint */ |
| 1564 | ret = msm_slim_init_endpoint(dev, endpoint); |
| 1565 | if (ret) { |
| 1566 | dev_err(dev->dev, "init_endpoint failed 0x%x\n", ret); |
| 1567 | goto sps_init_endpoint_failed; |
| 1568 | } |
| 1569 | |
| 1570 | /* Get the pipe indices for the message queues */ |
| 1571 | pipe_offset = (readl_relaxed(dev->base + MGR_STATUS) & 0xfc) >> 2; |
| 1572 | dev_dbg(dev->dev, "Message queue pipe offset %d\n", pipe_offset); |
| 1573 | |
| 1574 | config->mode = SPS_MODE_SRC; |
| 1575 | config->source = dev->bam.hdl; |
| 1576 | config->destination = SPS_DEV_HANDLE_MEM; |
| 1577 | config->src_pipe_index = pipe_offset; |
| 1578 | config->options = SPS_O_DESC_DONE | SPS_O_ERROR | |
| 1579 | SPS_O_ACK_TRANSFERS | SPS_O_AUTO_ENABLE; |
| 1580 | |
| 1581 | /* Allocate memory for the FIFO descriptors */ |
| 1582 | ret = msm_slim_sps_mem_alloc(dev, descr, |
| 1583 | MSM_SLIM_DESC_NUM * sizeof(struct sps_iovec)); |
| 1584 | if (ret) { |
| 1585 | dev_err(dev->dev, "unable to allocate SPS descriptors\n"); |
| 1586 | goto alloc_descr_failed; |
| 1587 | } |
| 1588 | |
| 1589 | ret = sps_connect(endpoint->sps, config); |
| 1590 | if (ret) { |
| 1591 | dev_err(dev->dev, "sps_connect failed 0x%x\n", ret); |
| 1592 | goto sps_connect_failed; |
| 1593 | } |
| 1594 | |
| 1595 | /* Register completion for DESC_DONE */ |
| 1596 | init_completion(notify); |
| 1597 | memset(&sps_descr_event, 0x00, sizeof(sps_descr_event)); |
| 1598 | |
| 1599 | sps_descr_event.mode = SPS_TRIGGER_CALLBACK; |
| 1600 | sps_descr_event.options = SPS_O_DESC_DONE; |
| 1601 | sps_descr_event.user = (void *)dev; |
| 1602 | sps_descr_event.xfer_done = notify; |
| 1603 | |
| 1604 | ret = sps_register_event(endpoint->sps, &sps_descr_event); |
| 1605 | if (ret) { |
| 1606 | dev_err(dev->dev, "sps_connect() failed 0x%x\n", ret); |
| 1607 | goto sps_reg_event_failed; |
| 1608 | } |
| 1609 | |
| 1610 | /* Register callback for errors */ |
| 1611 | memset(&sps_error_event, 0x00, sizeof(sps_error_event)); |
| 1612 | sps_error_event.mode = SPS_TRIGGER_CALLBACK; |
| 1613 | sps_error_event.options = SPS_O_ERROR; |
| 1614 | sps_error_event.user = (void *)dev; |
| 1615 | sps_error_event.callback = msm_slim_rx_msgq_cb; |
| 1616 | |
| 1617 | ret = sps_register_event(endpoint->sps, &sps_error_event); |
| 1618 | if (ret) { |
| 1619 | dev_err(dev->dev, "sps_connect() failed 0x%x\n", ret); |
| 1620 | goto sps_reg_event_failed; |
| 1621 | } |
| 1622 | |
| 1623 | /* Allocate memory for the message buffer(s), N descrs, 4-byte mesg */ |
| 1624 | ret = msm_slim_sps_mem_alloc(dev, mem, MSM_SLIM_DESC_NUM * 4); |
| 1625 | if (ret) { |
| 1626 | dev_err(dev->dev, "dma_alloc_coherent failed\n"); |
| 1627 | goto alloc_buffer_failed; |
| 1628 | } |
| 1629 | |
| 1630 | /* |
| 1631 | * Call transfer_one for each 4-byte buffer |
| 1632 | * Use (buf->size/4) - 1 for the number of buffer to post |
| 1633 | */ |
| 1634 | |
| 1635 | /* Setup the transfer */ |
| 1636 | for (i = 0; i < (MSM_SLIM_DESC_NUM - 1); i++) { |
| 1637 | ret = msm_slim_post_rx_msgq(dev, i); |
| 1638 | if (ret) { |
| 1639 | dev_err(dev->dev, "post_rx_msgq() failed 0x%x\n", ret); |
| 1640 | goto sps_transfer_failed; |
| 1641 | } |
| 1642 | } |
| 1643 | |
| 1644 | /* Fire up the Rx message queue thread */ |
| 1645 | dev->rx_msgq_thread = kthread_run(msm_slim_rx_msgq_thread, dev, |
| 1646 | MSM_SLIM_NAME "_rx_msgq_thread"); |
| 1647 | if (!dev->rx_msgq_thread) { |
| 1648 | dev_err(dev->dev, "Failed to start Rx message queue thread\n"); |
| 1649 | ret = -EIO; |
| 1650 | } else |
| 1651 | return 0; |
| 1652 | |
| 1653 | sps_transfer_failed: |
| 1654 | msm_slim_sps_mem_free(dev, mem); |
| 1655 | alloc_buffer_failed: |
| 1656 | memset(&sps_error_event, 0x00, sizeof(sps_error_event)); |
| 1657 | sps_register_event(endpoint->sps, &sps_error_event); |
| 1658 | sps_reg_event_failed: |
| 1659 | sps_disconnect(endpoint->sps); |
| 1660 | sps_connect_failed: |
| 1661 | msm_slim_sps_mem_free(dev, descr); |
| 1662 | alloc_descr_failed: |
| 1663 | msm_slim_free_endpoint(endpoint); |
| 1664 | sps_init_endpoint_failed: |
| 1665 | return ret; |
| 1666 | } |
| 1667 | |
| 1668 | /* Registers BAM h/w resource with SPS driver and initializes msgq endpoints */ |
| 1669 | static int __devinit |
| 1670 | msm_slim_sps_init(struct msm_slim_ctrl *dev, struct resource *bam_mem) |
| 1671 | { |
| 1672 | int i, ret; |
| 1673 | u32 bam_handle; |
| 1674 | struct sps_bam_props bam_props = {0}; |
| 1675 | |
| 1676 | static struct sps_bam_sec_config_props sec_props = { |
| 1677 | .ees = { |
| 1678 | [0] = { /* LPASS */ |
| 1679 | .vmid = 0, |
| 1680 | .pipe_mask = 0xFFFF98, |
| 1681 | }, |
| 1682 | [1] = { /* Krait Apps */ |
| 1683 | .vmid = 1, |
| 1684 | .pipe_mask = 0x3F000007, |
| 1685 | }, |
| 1686 | [2] = { /* Modem */ |
| 1687 | .vmid = 2, |
| 1688 | .pipe_mask = 0x00000060, |
| 1689 | }, |
| 1690 | }, |
| 1691 | }; |
| 1692 | |
| 1693 | bam_props.ee = dev->ee; |
| 1694 | bam_props.virt_addr = dev->bam.base; |
| 1695 | bam_props.phys_addr = bam_mem->start; |
| 1696 | bam_props.irq = dev->bam.irq; |
| 1697 | bam_props.manage = SPS_BAM_MGR_LOCAL; |
| 1698 | bam_props.summing_threshold = MSM_SLIM_PERF_SUMM_THRESHOLD; |
| 1699 | |
| 1700 | bam_props.sec_config = SPS_BAM_SEC_DO_CONFIG; |
| 1701 | bam_props.p_sec_config_props = &sec_props; |
| 1702 | |
| 1703 | bam_props.options = SPS_O_DESC_DONE | SPS_O_ERROR | |
| 1704 | SPS_O_ACK_TRANSFERS | SPS_O_AUTO_ENABLE; |
| 1705 | |
| 1706 | /* First 7 bits are for message Qs */ |
| 1707 | for (i = 7; i < 32; i++) { |
| 1708 | /* Check what pipes are owned by Apps. */ |
| 1709 | if ((sec_props.ees[dev->ee].pipe_mask >> i) & 0x1) |
| 1710 | break; |
| 1711 | } |
| 1712 | dev->pipe_b = i - 7; |
| 1713 | |
| 1714 | /* Register the BAM device with the SPS driver */ |
| 1715 | ret = sps_register_bam_device(&bam_props, &bam_handle); |
| 1716 | if (ret) { |
| 1717 | dev_err(dev->dev, "sps_register_bam_device failed 0x%x\n", ret); |
| 1718 | return ret; |
| 1719 | } |
| 1720 | dev->bam.hdl = bam_handle; |
| 1721 | dev_dbg(dev->dev, "SLIM BAM registered, handle = 0x%x\n", bam_handle); |
| 1722 | |
| 1723 | ret = msm_slim_init_rx_msgq(dev); |
| 1724 | if (ret) { |
| 1725 | dev_err(dev->dev, "msm_slim_init_rx_msgq failed 0x%x\n", ret); |
| 1726 | goto rx_msgq_init_failed; |
| 1727 | } |
| 1728 | |
| 1729 | return 0; |
| 1730 | rx_msgq_init_failed: |
| 1731 | sps_deregister_bam_device(bam_handle); |
| 1732 | dev->bam.hdl = 0L; |
| 1733 | return ret; |
| 1734 | } |
| 1735 | |
| 1736 | static void msm_slim_sps_exit(struct msm_slim_ctrl *dev) |
| 1737 | { |
| 1738 | if (dev->use_rx_msgqs) { |
| 1739 | struct msm_slim_endp *endpoint = &dev->rx_msgq; |
| 1740 | struct sps_connect *config = &endpoint->config; |
| 1741 | struct sps_mem_buffer *descr = &config->desc; |
| 1742 | struct sps_mem_buffer *mem = &endpoint->buf; |
| 1743 | struct sps_register_event sps_event; |
| 1744 | memset(&sps_event, 0x00, sizeof(sps_event)); |
| 1745 | msm_slim_sps_mem_free(dev, mem); |
| 1746 | sps_register_event(endpoint->sps, &sps_event); |
| 1747 | sps_disconnect(endpoint->sps); |
| 1748 | msm_slim_sps_mem_free(dev, descr); |
| 1749 | msm_slim_free_endpoint(endpoint); |
| 1750 | } |
| 1751 | sps_deregister_bam_device(dev->bam.hdl); |
| 1752 | } |
| 1753 | |
Sagar Dharia | cc96945 | 2011-09-19 10:34:30 -0600 | [diff] [blame] | 1754 | static void msm_slim_prg_slew(struct platform_device *pdev, |
| 1755 | struct msm_slim_ctrl *dev) |
| 1756 | { |
| 1757 | struct resource *slew_io; |
| 1758 | void __iomem *slew_reg; |
| 1759 | /* SLEW RATE register for this slimbus */ |
| 1760 | dev->slew_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 1761 | "slimbus_slew_reg"); |
| 1762 | if (!dev->slew_mem) { |
| 1763 | dev_dbg(&pdev->dev, "no slimbus slew resource\n"); |
| 1764 | return; |
| 1765 | } |
| 1766 | slew_io = request_mem_region(dev->slew_mem->start, |
| 1767 | resource_size(dev->slew_mem), pdev->name); |
| 1768 | if (!slew_io) { |
| 1769 | dev_dbg(&pdev->dev, "slimbus-slew mem claimed\n"); |
| 1770 | dev->slew_mem = NULL; |
| 1771 | return; |
| 1772 | } |
| 1773 | |
| 1774 | slew_reg = ioremap(dev->slew_mem->start, resource_size(dev->slew_mem)); |
| 1775 | if (!slew_reg) { |
| 1776 | dev_dbg(dev->dev, "slew register mapping failed"); |
| 1777 | release_mem_region(dev->slew_mem->start, |
| 1778 | resource_size(dev->slew_mem)); |
| 1779 | dev->slew_mem = NULL; |
| 1780 | return; |
| 1781 | } |
| 1782 | writel_relaxed(1, slew_reg); |
| 1783 | /* Make sure slimbus-slew rate enabling goes through */ |
| 1784 | wmb(); |
| 1785 | iounmap(slew_reg); |
| 1786 | } |
| 1787 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1788 | static int __devinit msm_slim_probe(struct platform_device *pdev) |
| 1789 | { |
| 1790 | struct msm_slim_ctrl *dev; |
| 1791 | int ret; |
| 1792 | struct resource *bam_mem, *bam_io; |
| 1793 | struct resource *slim_mem, *slim_io; |
| 1794 | struct resource *irq, *bam_irq; |
| 1795 | slim_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 1796 | "slimbus_physical"); |
| 1797 | if (!slim_mem) { |
| 1798 | dev_err(&pdev->dev, "no slimbus physical memory resource\n"); |
| 1799 | return -ENODEV; |
| 1800 | } |
| 1801 | slim_io = request_mem_region(slim_mem->start, resource_size(slim_mem), |
| 1802 | pdev->name); |
| 1803 | if (!slim_io) { |
| 1804 | dev_err(&pdev->dev, "slimbus memory already claimed\n"); |
| 1805 | return -EBUSY; |
| 1806 | } |
| 1807 | |
| 1808 | bam_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 1809 | "slimbus_bam_physical"); |
| 1810 | if (!bam_mem) { |
| 1811 | dev_err(&pdev->dev, "no slimbus BAM memory resource\n"); |
| 1812 | ret = -ENODEV; |
| 1813 | goto err_get_res_bam_failed; |
| 1814 | } |
| 1815 | bam_io = request_mem_region(bam_mem->start, resource_size(bam_mem), |
| 1816 | pdev->name); |
| 1817 | if (!bam_io) { |
| 1818 | release_mem_region(slim_mem->start, resource_size(slim_mem)); |
| 1819 | dev_err(&pdev->dev, "slimbus BAM memory already claimed\n"); |
| 1820 | ret = -EBUSY; |
| 1821 | goto err_get_res_bam_failed; |
| 1822 | } |
| 1823 | irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, |
| 1824 | "slimbus_irq"); |
| 1825 | if (!irq) { |
| 1826 | dev_err(&pdev->dev, "no slimbus IRQ resource\n"); |
| 1827 | ret = -ENODEV; |
| 1828 | goto err_get_res_failed; |
| 1829 | } |
| 1830 | bam_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, |
| 1831 | "slimbus_bam_irq"); |
| 1832 | if (!bam_irq) { |
| 1833 | dev_err(&pdev->dev, "no slimbus BAM IRQ resource\n"); |
| 1834 | ret = -ENODEV; |
| 1835 | goto err_get_res_failed; |
| 1836 | } |
| 1837 | |
| 1838 | dev = kzalloc(sizeof(struct msm_slim_ctrl), GFP_KERNEL); |
| 1839 | if (!dev) { |
| 1840 | dev_err(&pdev->dev, "no memory for MSM slimbus controller\n"); |
| 1841 | ret = -ENOMEM; |
| 1842 | goto err_get_res_failed; |
| 1843 | } |
| 1844 | dev->dev = &pdev->dev; |
| 1845 | platform_set_drvdata(pdev, dev); |
| 1846 | slim_set_ctrldata(&dev->ctrl, dev); |
| 1847 | dev->base = ioremap(slim_mem->start, resource_size(slim_mem)); |
| 1848 | if (!dev->base) { |
| 1849 | dev_err(&pdev->dev, "IOremap failed\n"); |
| 1850 | ret = -ENOMEM; |
| 1851 | goto err_ioremap_failed; |
| 1852 | } |
| 1853 | dev->bam.base = ioremap(bam_mem->start, resource_size(bam_mem)); |
| 1854 | if (!dev->bam.base) { |
| 1855 | dev_err(&pdev->dev, "BAM IOremap failed\n"); |
| 1856 | ret = -ENOMEM; |
| 1857 | goto err_ioremap_bam_failed; |
| 1858 | } |
| 1859 | dev->ctrl.nr = pdev->id; |
| 1860 | dev->ctrl.nchans = MSM_SLIM_NCHANS; |
| 1861 | dev->ctrl.nports = MSM_SLIM_NPORTS; |
| 1862 | dev->ctrl.set_laddr = msm_set_laddr; |
| 1863 | dev->ctrl.xfer_msg = msm_xfer_msg; |
Sagar Dharia | 144e5e0 | 2011-08-08 17:30:11 -0600 | [diff] [blame] | 1864 | dev->ctrl.wakeup = msm_clk_pause_wakeup; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1865 | dev->ctrl.config_port = msm_config_port; |
| 1866 | dev->ctrl.port_xfer = msm_slim_port_xfer; |
| 1867 | dev->ctrl.port_xfer_status = msm_slim_port_xfer_status; |
| 1868 | /* Reserve some messaging BW for satellite-apps driver communication */ |
| 1869 | dev->ctrl.sched.pending_msgsl = 30; |
| 1870 | |
| 1871 | init_completion(&dev->reconf); |
| 1872 | mutex_init(&dev->tx_lock); |
| 1873 | spin_lock_init(&dev->rx_lock); |
| 1874 | dev->ee = 1; |
| 1875 | dev->use_rx_msgqs = 1; |
| 1876 | dev->irq = irq->start; |
| 1877 | dev->bam.irq = bam_irq->start; |
| 1878 | |
| 1879 | ret = msm_slim_sps_init(dev, bam_mem); |
| 1880 | if (ret != 0) { |
| 1881 | dev_err(dev->dev, "error SPS init\n"); |
| 1882 | goto err_sps_init_failed; |
| 1883 | } |
| 1884 | |
| 1885 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1886 | dev->framer.rootfreq = SLIM_ROOT_FREQ >> 3; |
| 1887 | dev->framer.superfreq = |
| 1888 | dev->framer.rootfreq / SLIM_CL_PER_SUPERFRAME_DIV8; |
| 1889 | dev->ctrl.a_framer = &dev->framer; |
| 1890 | dev->ctrl.clkgear = SLIM_MAX_CLK_GEAR; |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1891 | dev->ctrl.dev.parent = &pdev->dev; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1892 | |
| 1893 | ret = request_irq(dev->irq, msm_slim_interrupt, IRQF_TRIGGER_HIGH, |
| 1894 | "msm_slim_irq", dev); |
| 1895 | if (ret) { |
| 1896 | dev_err(&pdev->dev, "request IRQ failed\n"); |
| 1897 | goto err_request_irq_failed; |
| 1898 | } |
| 1899 | |
Sagar Dharia | cc96945 | 2011-09-19 10:34:30 -0600 | [diff] [blame] | 1900 | msm_slim_prg_slew(pdev, dev); |
Sagar Dharia | b1c0acf | 2012-02-06 18:16:58 -0700 | [diff] [blame] | 1901 | |
| 1902 | /* Register with framework before enabling frame, clock */ |
| 1903 | ret = slim_add_numbered_controller(&dev->ctrl); |
| 1904 | if (ret) { |
| 1905 | dev_err(dev->dev, "error adding controller\n"); |
| 1906 | goto err_ctrl_failed; |
| 1907 | } |
| 1908 | |
| 1909 | |
Tianyi Gou | 44a81b0 | 2012-02-06 17:49:07 -0800 | [diff] [blame] | 1910 | dev->rclk = clk_get(dev->dev, "core_clk"); |
Sagar Dharia | b1c0acf | 2012-02-06 18:16:58 -0700 | [diff] [blame] | 1911 | if (!dev->rclk) { |
| 1912 | dev_err(dev->dev, "slimbus clock not found"); |
| 1913 | goto err_clk_get_failed; |
| 1914 | } |
Sagar Dharia | cc96945 | 2011-09-19 10:34:30 -0600 | [diff] [blame] | 1915 | clk_set_rate(dev->rclk, SLIM_ROOT_FREQ); |
| 1916 | clk_enable(dev->rclk); |
| 1917 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1918 | /* Component register initialization */ |
| 1919 | writel_relaxed(1, dev->base + COMP_CFG); |
| 1920 | writel_relaxed((EE_MGR_RSC_GRP | EE_NGD_2 | EE_NGD_1), |
| 1921 | dev->base + COMP_TRUST_CFG); |
| 1922 | |
| 1923 | /* |
| 1924 | * Manager register initialization |
| 1925 | * If RX msg Q is used, disable RX_MSG_RCVD interrupt |
| 1926 | */ |
| 1927 | if (dev->use_rx_msgqs) |
| 1928 | writel_relaxed((MGR_INT_RECFG_DONE | MGR_INT_TX_NACKED_2 | |
| 1929 | MGR_INT_MSG_BUF_CONTE | /* MGR_INT_RX_MSG_RCVD | */ |
| 1930 | MGR_INT_TX_MSG_SENT), dev->base + MGR_INT_EN); |
| 1931 | else |
| 1932 | writel_relaxed((MGR_INT_RECFG_DONE | MGR_INT_TX_NACKED_2 | |
| 1933 | MGR_INT_MSG_BUF_CONTE | MGR_INT_RX_MSG_RCVD | |
| 1934 | MGR_INT_TX_MSG_SENT), dev->base + MGR_INT_EN); |
| 1935 | writel_relaxed(1, dev->base + MGR_CFG); |
| 1936 | /* |
| 1937 | * Framer registers are beyond 1K memory region after Manager and/or |
| 1938 | * component registers. Make sure those writes are ordered |
| 1939 | * before framer register writes |
| 1940 | */ |
| 1941 | wmb(); |
| 1942 | |
| 1943 | /* Framer register initialization */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1944 | writel_relaxed((0xA << REF_CLK_GEAR) | (0xA << CLK_GEAR) | |
| 1945 | (1 << ROOT_FREQ) | (1 << FRM_ACTIVE) | 1, |
| 1946 | dev->base + FRM_CFG); |
| 1947 | /* |
| 1948 | * Make sure that framer wake-up and enabling writes go through |
| 1949 | * before any other component is enabled. Framer is responsible for |
| 1950 | * clocking the bus and enabling framer first will ensure that other |
| 1951 | * devices can report presence when they are enabled |
| 1952 | */ |
| 1953 | mb(); |
| 1954 | |
| 1955 | /* Enable RX msg Q */ |
| 1956 | if (dev->use_rx_msgqs) |
| 1957 | writel_relaxed(MGR_CFG_ENABLE | MGR_CFG_RX_MSGQ_EN, |
| 1958 | dev->base + MGR_CFG); |
| 1959 | else |
| 1960 | writel_relaxed(MGR_CFG_ENABLE, dev->base + MGR_CFG); |
| 1961 | /* |
| 1962 | * Make sure that manager-enable is written through before interface |
| 1963 | * device is enabled |
| 1964 | */ |
| 1965 | mb(); |
| 1966 | writel_relaxed(1, dev->base + INTF_CFG); |
| 1967 | /* |
| 1968 | * Make sure that interface-enable is written through before enabling |
| 1969 | * ported generic device inside MSM manager |
| 1970 | */ |
| 1971 | mb(); |
| 1972 | writel_relaxed(1, dev->base + PGD_CFG); |
| 1973 | writel_relaxed(0x3F<<17, dev->base + (PGD_OWN_EEn + (4 * dev->ee))); |
| 1974 | /* |
| 1975 | * Make sure that ported generic device is enabled and port-EE settings |
| 1976 | * are written through before finally enabling the component |
| 1977 | */ |
| 1978 | mb(); |
| 1979 | |
| 1980 | writel_relaxed(1, dev->base + COMP_CFG); |
| 1981 | /* |
| 1982 | * Make sure that all writes have gone through before exiting this |
| 1983 | * function |
| 1984 | */ |
| 1985 | mb(); |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1986 | pm_runtime_use_autosuspend(&pdev->dev); |
| 1987 | pm_runtime_set_autosuspend_delay(&pdev->dev, MSM_SLIM_AUTOSUSPEND); |
| 1988 | pm_runtime_set_active(&pdev->dev); |
| 1989 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1990 | dev_dbg(dev->dev, "MSM SB controller is up!\n"); |
| 1991 | return 0; |
| 1992 | |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1993 | err_ctrl_failed: |
| 1994 | writel_relaxed(0, dev->base + COMP_CFG); |
Sagar Dharia | b1c0acf | 2012-02-06 18:16:58 -0700 | [diff] [blame] | 1995 | err_clk_get_failed: |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 1996 | kfree(dev->satd); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1997 | err_request_irq_failed: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1998 | msm_slim_sps_exit(dev); |
| 1999 | err_sps_init_failed: |
| 2000 | iounmap(dev->bam.base); |
| 2001 | err_ioremap_bam_failed: |
| 2002 | iounmap(dev->base); |
| 2003 | err_ioremap_failed: |
| 2004 | kfree(dev); |
| 2005 | err_get_res_failed: |
| 2006 | release_mem_region(bam_mem->start, resource_size(bam_mem)); |
| 2007 | err_get_res_bam_failed: |
| 2008 | release_mem_region(slim_mem->start, resource_size(slim_mem)); |
| 2009 | return ret; |
| 2010 | } |
| 2011 | |
| 2012 | static int __devexit msm_slim_remove(struct platform_device *pdev) |
| 2013 | { |
| 2014 | struct msm_slim_ctrl *dev = platform_get_drvdata(pdev); |
| 2015 | struct resource *bam_mem; |
| 2016 | struct resource *slim_mem; |
Sagar Dharia | cc96945 | 2011-09-19 10:34:30 -0600 | [diff] [blame] | 2017 | struct resource *slew_mem = dev->slew_mem; |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 2018 | int i; |
| 2019 | for (i = 0; i < dev->nsats; i++) { |
| 2020 | struct msm_slim_sat *sat = dev->satd[i]; |
Sagar Dharia | 0ffdca1 | 2011-09-25 18:55:53 -0600 | [diff] [blame] | 2021 | int j; |
| 2022 | for (j = 0; j < sat->nsatch; j++) |
| 2023 | slim_dealloc_ch(&sat->satcl, sat->satch[j].chanh); |
Sagar Dharia | 790cfd0 | 2011-09-25 17:56:24 -0600 | [diff] [blame] | 2024 | slim_remove_device(&sat->satcl); |
| 2025 | kfree(sat->satch); |
| 2026 | destroy_workqueue(sat->wq); |
| 2027 | kfree(sat->satcl.name); |
| 2028 | kfree(sat); |
| 2029 | } |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2030 | pm_runtime_disable(&pdev->dev); |
| 2031 | pm_runtime_set_suspended(&pdev->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2032 | free_irq(dev->irq, dev); |
| 2033 | slim_del_controller(&dev->ctrl); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2034 | clk_put(dev->rclk); |
| 2035 | msm_slim_sps_exit(dev); |
| 2036 | kthread_stop(dev->rx_msgq_thread); |
| 2037 | iounmap(dev->bam.base); |
| 2038 | iounmap(dev->base); |
| 2039 | kfree(dev); |
| 2040 | bam_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 2041 | "slimbus_bam_physical"); |
Sagar Dharia | e77961f | 2011-09-27 14:03:50 -0600 | [diff] [blame] | 2042 | if (bam_mem) |
| 2043 | release_mem_region(bam_mem->start, resource_size(bam_mem)); |
Sagar Dharia | cc96945 | 2011-09-19 10:34:30 -0600 | [diff] [blame] | 2044 | if (slew_mem) |
| 2045 | release_mem_region(slew_mem->start, resource_size(slew_mem)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2046 | slim_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 2047 | "slimbus_physical"); |
Sagar Dharia | e77961f | 2011-09-27 14:03:50 -0600 | [diff] [blame] | 2048 | if (slim_mem) |
| 2049 | release_mem_region(slim_mem->start, resource_size(slim_mem)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2050 | return 0; |
| 2051 | } |
| 2052 | |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2053 | #ifdef CONFIG_PM_RUNTIME |
| 2054 | static int msm_slim_runtime_idle(struct device *device) |
| 2055 | { |
| 2056 | dev_dbg(device, "pm_runtime: idle...\n"); |
| 2057 | pm_request_autosuspend(device); |
| 2058 | return -EAGAIN; |
| 2059 | } |
| 2060 | #endif |
| 2061 | |
| 2062 | /* |
| 2063 | * If PM_RUNTIME is not defined, these 2 functions become helper |
| 2064 | * functions to be called from system suspend/resume. So they are not |
| 2065 | * inside ifdef CONFIG_PM_RUNTIME |
| 2066 | */ |
Sagar Dharia | 45e7791 | 2012-01-10 09:55:18 -0700 | [diff] [blame] | 2067 | #ifdef CONFIG_PM_SLEEP |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2068 | static int msm_slim_runtime_suspend(struct device *device) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2069 | { |
| 2070 | struct platform_device *pdev = to_platform_device(device); |
| 2071 | struct msm_slim_ctrl *dev = platform_get_drvdata(pdev); |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2072 | int ret; |
| 2073 | dev_dbg(device, "pm_runtime: suspending...\n"); |
| 2074 | dev->state = MSM_CTRL_SLEEPING; |
| 2075 | ret = slim_ctrl_clk_pause(&dev->ctrl, false, SLIM_CLK_UNSPECIFIED); |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 2076 | if (ret) { |
| 2077 | dev_err(device, "clk pause not entered:%d", ret); |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2078 | dev->state = MSM_CTRL_AWAKE; |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 2079 | } else { |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2080 | dev->state = MSM_CTRL_ASLEEP; |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 2081 | } |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2082 | return ret; |
| 2083 | } |
| 2084 | |
| 2085 | static int msm_slim_runtime_resume(struct device *device) |
| 2086 | { |
| 2087 | struct platform_device *pdev = to_platform_device(device); |
| 2088 | struct msm_slim_ctrl *dev = platform_get_drvdata(pdev); |
| 2089 | int ret = 0; |
| 2090 | dev_dbg(device, "pm_runtime: resuming...\n"); |
| 2091 | if (dev->state == MSM_CTRL_ASLEEP) |
| 2092 | ret = slim_ctrl_clk_pause(&dev->ctrl, true, 0); |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 2093 | if (ret) { |
| 2094 | dev_err(device, "clk pause not exited:%d", ret); |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2095 | dev->state = MSM_CTRL_ASLEEP; |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 2096 | } else { |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2097 | dev->state = MSM_CTRL_AWAKE; |
Sagar Dharia | d3ef30a | 2011-12-09 14:30:45 -0700 | [diff] [blame] | 2098 | } |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2099 | return ret; |
| 2100 | } |
| 2101 | |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2102 | static int msm_slim_suspend(struct device *dev) |
| 2103 | { |
| 2104 | int ret = 0; |
| 2105 | if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) { |
| 2106 | dev_dbg(dev, "system suspend"); |
| 2107 | ret = msm_slim_runtime_suspend(dev); |
Sagar Dharia | 6b559e0 | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2108 | } |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2109 | if (ret == -EBUSY) { |
Sagar Dharia | 144e5e0 | 2011-08-08 17:30:11 -0600 | [diff] [blame] | 2110 | /* |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2111 | * If the clock pause failed due to active channels, there is |
| 2112 | * a possibility that some audio stream is active during suspend |
| 2113 | * We dont want to return suspend failure in that case so that |
| 2114 | * display and relevant components can still go to suspend. |
| 2115 | * If there is some other error, then it should be passed-on |
| 2116 | * to system level suspend |
| 2117 | */ |
Sagar Dharia | 144e5e0 | 2011-08-08 17:30:11 -0600 | [diff] [blame] | 2118 | ret = 0; |
| 2119 | } |
| 2120 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2121 | } |
| 2122 | |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2123 | static int msm_slim_resume(struct device *dev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2124 | { |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2125 | /* If runtime_pm is enabled, this resume shouldn't do anything */ |
| 2126 | if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) { |
| 2127 | int ret; |
| 2128 | dev_dbg(dev, "system resume"); |
| 2129 | ret = msm_slim_runtime_resume(dev); |
| 2130 | if (!ret) { |
| 2131 | pm_runtime_mark_last_busy(dev); |
| 2132 | pm_request_autosuspend(dev); |
| 2133 | } |
| 2134 | return ret; |
| 2135 | |
Sagar Dharia | 144e5e0 | 2011-08-08 17:30:11 -0600 | [diff] [blame] | 2136 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2137 | return 0; |
| 2138 | } |
Sagar Dharia | 45ee38a | 2011-08-03 17:01:31 -0600 | [diff] [blame] | 2139 | #endif /* CONFIG_PM_SLEEP */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2140 | |
| 2141 | static const struct dev_pm_ops msm_slim_dev_pm_ops = { |
| 2142 | SET_SYSTEM_SLEEP_PM_OPS( |
| 2143 | msm_slim_suspend, |
| 2144 | msm_slim_resume |
| 2145 | ) |
| 2146 | SET_RUNTIME_PM_OPS( |
| 2147 | msm_slim_runtime_suspend, |
| 2148 | msm_slim_runtime_resume, |
| 2149 | msm_slim_runtime_idle |
| 2150 | ) |
| 2151 | }; |
| 2152 | |
| 2153 | static struct platform_driver msm_slim_driver = { |
| 2154 | .probe = msm_slim_probe, |
| 2155 | .remove = msm_slim_remove, |
| 2156 | .driver = { |
| 2157 | .name = MSM_SLIM_NAME, |
| 2158 | .owner = THIS_MODULE, |
| 2159 | .pm = &msm_slim_dev_pm_ops, |
| 2160 | }, |
| 2161 | }; |
| 2162 | |
| 2163 | static int msm_slim_init(void) |
| 2164 | { |
| 2165 | return platform_driver_register(&msm_slim_driver); |
| 2166 | } |
| 2167 | subsys_initcall(msm_slim_init); |
| 2168 | |
| 2169 | static void msm_slim_exit(void) |
| 2170 | { |
| 2171 | platform_driver_unregister(&msm_slim_driver); |
| 2172 | } |
| 2173 | module_exit(msm_slim_exit); |
| 2174 | |
| 2175 | MODULE_LICENSE("GPL v2"); |
| 2176 | MODULE_VERSION("0.1"); |
| 2177 | MODULE_DESCRIPTION("MSM Slimbus controller"); |
| 2178 | MODULE_ALIAS("platform:msm-slim"); |