Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Sagar Dharia | 2754ab4 | 2012-08-21 18:07:39 -0600 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef _SLIM_MSM_H |
| 14 | #define _SLIM_MSM_H |
Kenneth Heitke | ae62604 | 2012-11-05 21:01:44 -0700 | [diff] [blame] | 15 | |
| 16 | #include <linux/kthread.h> |
| 17 | #include <mach/msm_qmi_interface.h> |
| 18 | |
Sagar Dharia | 2754ab4 | 2012-08-21 18:07:39 -0600 | [diff] [blame] | 19 | /* Per spec.max 40 bytes per received message */ |
| 20 | #define SLIM_RX_MSGQ_BUF_LEN 40 |
| 21 | |
| 22 | #define SLIM_USR_MC_GENERIC_ACK 0x25 |
| 23 | #define SLIM_USR_MC_MASTER_CAPABILITY 0x0 |
| 24 | #define SLIM_USR_MC_REPORT_SATELLITE 0x1 |
| 25 | #define SLIM_USR_MC_ADDR_QUERY 0xD |
| 26 | #define SLIM_USR_MC_ADDR_REPLY 0xE |
| 27 | #define SLIM_USR_MC_DEFINE_CHAN 0x20 |
| 28 | #define SLIM_USR_MC_DEF_ACT_CHAN 0x21 |
| 29 | #define SLIM_USR_MC_CHAN_CTRL 0x23 |
| 30 | #define SLIM_USR_MC_RECONFIG_NOW 0x24 |
| 31 | #define SLIM_USR_MC_REQ_BW 0x28 |
| 32 | #define SLIM_USR_MC_CONNECT_SRC 0x2C |
| 33 | #define SLIM_USR_MC_CONNECT_SINK 0x2D |
| 34 | #define SLIM_USR_MC_DISCONNECT_PORT 0x2E |
| 35 | |
| 36 | #define MSM_SLIM_AUTOSUSPEND MSEC_PER_SEC |
| 37 | |
| 38 | /* |
| 39 | * Messages that can be received simultaneously: |
| 40 | * Client reads, LPASS master responses, announcement messages |
| 41 | * Receive upto 10 messages simultaneously. |
| 42 | */ |
| 43 | #define MSM_SLIM_DESC_NUM 32 |
| 44 | |
| 45 | /* MSM Slimbus peripheral settings */ |
| 46 | #define MSM_SLIM_PERF_SUMM_THRESHOLD 0x8000 |
| 47 | #define MSM_SLIM_NPORTS 24 |
| 48 | #define MSM_SLIM_NCHANS 32 |
| 49 | |
| 50 | #define SLIM_MSG_ASM_FIRST_WORD(l, mt, mc, dt, ad) \ |
| 51 | ((l) | ((mt) << 5) | ((mc) << 8) | ((dt) << 15) | ((ad) << 16)) |
| 52 | |
| 53 | #define MSM_CONCUR_MSG 8 |
| 54 | #define SAT_CONCUR_MSG 8 |
| 55 | #define DEF_WATERMARK (8 << 1) |
| 56 | #define DEF_ALIGN 0 |
| 57 | #define DEF_PACK (1 << 6) |
| 58 | #define ENABLE_PORT 1 |
| 59 | |
| 60 | #define DEF_BLKSZ 0 |
| 61 | #define DEF_TRANSZ 0 |
| 62 | |
| 63 | #define SAT_MAGIC_LSB 0xD9 |
| 64 | #define SAT_MAGIC_MSB 0xC5 |
| 65 | #define SAT_MSG_VER 0x1 |
| 66 | #define SAT_MSG_PROT 0x1 |
| 67 | #define MSM_SAT_SUCCSS 0x20 |
| 68 | #define MSM_MAX_NSATS 2 |
| 69 | #define MSM_MAX_SATCH 32 |
| 70 | |
Kenneth Heitke | ae62604 | 2012-11-05 21:01:44 -0700 | [diff] [blame] | 71 | /* Slimbus QMI service */ |
| 72 | #define SLIMBUS_QMI_SVC_ID 0x0301 |
| 73 | #define SLIMBUS_QMI_INS_ID 1 |
| 74 | |
Sagar Dharia | 2754ab4 | 2012-08-21 18:07:39 -0600 | [diff] [blame] | 75 | #define PGD_THIS_EE(r, v) ((v) ? PGD_THIS_EE_V2(r) : PGD_THIS_EE_V1(r)) |
| 76 | #define PGD_PORT(r, p, v) ((v) ? PGD_PORT_V2(r, p) : PGD_PORT_V1(r, p)) |
| 77 | #define CFG_PORT(r, v) ((v) ? CFG_PORT_V2(r) : CFG_PORT_V1(r)) |
| 78 | |
| 79 | #define PGD_THIS_EE_V2(r) (dev->base + (r ## _V2) + (dev->ee * 0x1000)) |
| 80 | #define PGD_PORT_V2(r, p) (dev->base + (r ## _V2) + ((p) * 0x1000)) |
| 81 | #define CFG_PORT_V2(r) ((r ## _V2)) |
| 82 | /* Component registers */ |
| 83 | enum comp_reg_v2 { |
| 84 | COMP_CFG_V2 = 4, |
| 85 | COMP_TRUST_CFG_V2 = 0x3000, |
| 86 | }; |
| 87 | |
| 88 | /* Manager PGD registers */ |
| 89 | enum pgd_reg_v2 { |
| 90 | PGD_CFG_V2 = 0x800, |
| 91 | PGD_STAT_V2 = 0x804, |
| 92 | PGD_INT_EN_V2 = 0x810, |
| 93 | PGD_INT_STAT_V2 = 0x814, |
| 94 | PGD_INT_CLR_V2 = 0x818, |
| 95 | PGD_OWN_EEn_V2 = 0x300C, |
| 96 | PGD_PORT_INT_EN_EEn_V2 = 0x5000, |
| 97 | PGD_PORT_INT_ST_EEn_V2 = 0x5004, |
| 98 | PGD_PORT_INT_CL_EEn_V2 = 0x5008, |
| 99 | PGD_PORT_CFGn_V2 = 0x14000, |
| 100 | PGD_PORT_STATn_V2 = 0x14004, |
| 101 | PGD_PORT_PARAMn_V2 = 0x14008, |
| 102 | PGD_PORT_BLKn_V2 = 0x1400C, |
| 103 | PGD_PORT_TRANn_V2 = 0x14010, |
| 104 | PGD_PORT_MCHANn_V2 = 0x14014, |
| 105 | PGD_PORT_PSHPLLn_V2 = 0x14018, |
| 106 | PGD_PORT_PC_CFGn_V2 = 0x8000, |
| 107 | PGD_PORT_PC_VALn_V2 = 0x8004, |
| 108 | PGD_PORT_PC_VFR_TSn_V2 = 0x8008, |
| 109 | PGD_PORT_PC_VFR_STn_V2 = 0x800C, |
| 110 | PGD_PORT_PC_VFR_CLn_V2 = 0x8010, |
| 111 | PGD_IE_STAT_V2 = 0x820, |
| 112 | PGD_VE_STAT_V2 = 0x830, |
| 113 | }; |
| 114 | |
| 115 | #define PGD_THIS_EE_V1(r) (dev->base + (r ## _V1) + (dev->ee * 16)) |
| 116 | #define PGD_PORT_V1(r, p) (dev->base + (r ## _V1) + ((p) * 32)) |
| 117 | #define CFG_PORT_V1(r) ((r ## _V1)) |
| 118 | /* Component registers */ |
| 119 | enum comp_reg_v1 { |
| 120 | COMP_CFG_V1 = 0, |
| 121 | COMP_TRUST_CFG_V1 = 0x14, |
| 122 | }; |
| 123 | |
| 124 | /* Manager PGD registers */ |
| 125 | enum pgd_reg_v1 { |
| 126 | PGD_CFG_V1 = 0x1000, |
| 127 | PGD_STAT_V1 = 0x1004, |
| 128 | PGD_INT_EN_V1 = 0x1010, |
| 129 | PGD_INT_STAT_V1 = 0x1014, |
| 130 | PGD_INT_CLR_V1 = 0x1018, |
| 131 | PGD_OWN_EEn_V1 = 0x1020, |
| 132 | PGD_PORT_INT_EN_EEn_V1 = 0x1030, |
| 133 | PGD_PORT_INT_ST_EEn_V1 = 0x1034, |
| 134 | PGD_PORT_INT_CL_EEn_V1 = 0x1038, |
| 135 | PGD_PORT_CFGn_V1 = 0x1080, |
| 136 | PGD_PORT_STATn_V1 = 0x1084, |
| 137 | PGD_PORT_PARAMn_V1 = 0x1088, |
| 138 | PGD_PORT_BLKn_V1 = 0x108C, |
| 139 | PGD_PORT_TRANn_V1 = 0x1090, |
| 140 | PGD_PORT_MCHANn_V1 = 0x1094, |
| 141 | PGD_PORT_PSHPLLn_V1 = 0x1098, |
| 142 | PGD_PORT_PC_CFGn_V1 = 0x1600, |
| 143 | PGD_PORT_PC_VALn_V1 = 0x1604, |
| 144 | PGD_PORT_PC_VFR_TSn_V1 = 0x1608, |
| 145 | PGD_PORT_PC_VFR_STn_V1 = 0x160C, |
| 146 | PGD_PORT_PC_VFR_CLn_V1 = 0x1610, |
| 147 | PGD_IE_STAT_V1 = 0x1700, |
| 148 | PGD_VE_STAT_V1 = 0x1710, |
| 149 | }; |
| 150 | |
| 151 | enum msm_ctrl_state { |
| 152 | MSM_CTRL_AWAKE, |
| 153 | MSM_CTRL_SLEEPING, |
| 154 | MSM_CTRL_ASLEEP, |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 155 | MSM_CTRL_DOWN, |
Sagar Dharia | 2754ab4 | 2012-08-21 18:07:39 -0600 | [diff] [blame] | 156 | }; |
| 157 | |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 158 | enum msm_slim_msgq { |
| 159 | MSM_MSGQ_DISABLED, |
| 160 | MSM_MSGQ_RESET, |
| 161 | MSM_MSGQ_ENABLED, |
| 162 | }; |
| 163 | |
Sagar Dharia | 2754ab4 | 2012-08-21 18:07:39 -0600 | [diff] [blame] | 164 | struct msm_slim_sps_bam { |
| 165 | u32 hdl; |
| 166 | void __iomem *base; |
| 167 | int irq; |
| 168 | }; |
| 169 | |
| 170 | struct msm_slim_endp { |
| 171 | struct sps_pipe *sps; |
| 172 | struct sps_connect config; |
| 173 | struct sps_register_event event; |
| 174 | struct sps_mem_buffer buf; |
| 175 | struct completion *xcomp; |
| 176 | bool connected; |
| 177 | }; |
| 178 | |
Kenneth Heitke | ae62604 | 2012-11-05 21:01:44 -0700 | [diff] [blame] | 179 | struct msm_slim_qmi { |
| 180 | struct qmi_handle *handle; |
| 181 | struct task_struct *task; |
| 182 | struct kthread_work kwork; |
| 183 | struct kthread_worker kworker; |
Sagar Dharia | cc1001e | 2012-11-06 13:56:42 -0700 | [diff] [blame] | 184 | struct completion qmi_comp; |
| 185 | struct notifier_block nb; |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 186 | struct work_struct ssr_down; |
| 187 | struct work_struct ssr_up; |
Kenneth Heitke | ae62604 | 2012-11-05 21:01:44 -0700 | [diff] [blame] | 188 | }; |
| 189 | |
Sagar Dharia | 2754ab4 | 2012-08-21 18:07:39 -0600 | [diff] [blame] | 190 | struct msm_slim_ctrl { |
| 191 | struct slim_controller ctrl; |
| 192 | struct slim_framer framer; |
| 193 | struct device *dev; |
| 194 | void __iomem *base; |
| 195 | struct resource *slew_mem; |
Sagar Dharia | 71fcea5 | 2012-09-12 23:21:57 -0600 | [diff] [blame] | 196 | struct resource *bam_mem; |
Sagar Dharia | 2754ab4 | 2012-08-21 18:07:39 -0600 | [diff] [blame] | 197 | u32 curr_bw; |
| 198 | u8 msg_cnt; |
| 199 | u32 tx_buf[10]; |
| 200 | u8 rx_msgs[MSM_CONCUR_MSG][SLIM_RX_MSGQ_BUF_LEN]; |
| 201 | spinlock_t rx_lock; |
| 202 | int head; |
| 203 | int tail; |
| 204 | int irq; |
| 205 | int err; |
| 206 | int ee; |
| 207 | struct completion *wr_comp; |
| 208 | struct msm_slim_sat *satd[MSM_MAX_NSATS]; |
| 209 | struct msm_slim_endp pipes[7]; |
| 210 | struct msm_slim_sps_bam bam; |
| 211 | struct msm_slim_endp rx_msgq; |
| 212 | struct completion rx_msgq_notify; |
| 213 | struct task_struct *rx_msgq_thread; |
| 214 | struct clk *rclk; |
| 215 | struct clk *hclk; |
| 216 | struct mutex tx_lock; |
| 217 | u8 pgdla; |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 218 | enum msm_slim_msgq use_rx_msgqs; |
Sagar Dharia | 2754ab4 | 2012-08-21 18:07:39 -0600 | [diff] [blame] | 219 | int pipe_b; |
| 220 | struct completion reconf; |
| 221 | bool reconf_busy; |
| 222 | bool chan_active; |
| 223 | enum msm_ctrl_state state; |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 224 | struct completion ctrl_up; |
Sagar Dharia | 2754ab4 | 2012-08-21 18:07:39 -0600 | [diff] [blame] | 225 | int nsats; |
| 226 | u32 ver; |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 227 | struct work_struct slave_notify; |
Kenneth Heitke | ae62604 | 2012-11-05 21:01:44 -0700 | [diff] [blame] | 228 | struct msm_slim_qmi qmi; |
Sagar Dharia | 2754ab4 | 2012-08-21 18:07:39 -0600 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | struct msm_sat_chan { |
| 232 | u8 chan; |
| 233 | u16 chanh; |
| 234 | int req_rem; |
| 235 | int req_def; |
| 236 | bool reconf; |
| 237 | }; |
| 238 | |
| 239 | struct msm_slim_sat { |
| 240 | struct slim_device satcl; |
| 241 | struct msm_slim_ctrl *dev; |
| 242 | struct workqueue_struct *wq; |
| 243 | struct work_struct wd; |
| 244 | u8 sat_msgs[SAT_CONCUR_MSG][40]; |
| 245 | struct msm_sat_chan *satch; |
| 246 | u8 nsatch; |
| 247 | bool sent_capability; |
| 248 | bool pending_reconf; |
| 249 | bool pending_capability; |
| 250 | int shead; |
| 251 | int stail; |
| 252 | spinlock_t lock; |
| 253 | }; |
| 254 | |
| 255 | enum rsc_grp { |
| 256 | EE_MGR_RSC_GRP = 1 << 10, |
| 257 | EE_NGD_2 = 2 << 6, |
| 258 | EE_NGD_1 = 0, |
| 259 | }; |
| 260 | |
| 261 | |
| 262 | int msm_slim_rx_enqueue(struct msm_slim_ctrl *dev, u32 *buf, u8 len); |
| 263 | int msm_slim_rx_dequeue(struct msm_slim_ctrl *dev, u8 *buf); |
| 264 | int msm_slim_get_ctrl(struct msm_slim_ctrl *dev); |
| 265 | void msm_slim_put_ctrl(struct msm_slim_ctrl *dev); |
| 266 | int msm_slim_init_endpoint(struct msm_slim_ctrl *dev, struct msm_slim_endp *ep); |
| 267 | void msm_slim_free_endpoint(struct msm_slim_endp *ep); |
| 268 | void msm_hw_set_port(struct msm_slim_ctrl *dev, u8 pn); |
| 269 | int msm_slim_connect_pipe_port(struct msm_slim_ctrl *dev, u8 pn); |
| 270 | int msm_config_port(struct slim_controller *ctrl, u8 pn); |
| 271 | enum slim_port_err msm_slim_port_xfer_status(struct slim_controller *ctr, |
| 272 | u8 pn, u8 **done_buf, u32 *done_len); |
| 273 | int msm_slim_port_xfer(struct slim_controller *ctrl, u8 pn, u8 *iobuf, |
| 274 | u32 len, struct completion *comp); |
| 275 | int msm_send_msg_buf(struct msm_slim_ctrl *dev, u32 *buf, u8 len, u32 tx_reg); |
| 276 | u32 *msm_get_msg_buf(struct msm_slim_ctrl *dev, int len); |
| 277 | int msm_slim_rx_msgq_get(struct msm_slim_ctrl *dev, u32 *data, int offset); |
| 278 | int msm_slim_sps_init(struct msm_slim_ctrl *dev, struct resource *bam_mem, |
Sagar Dharia | 60f59a7 | 2012-10-17 12:42:03 -0600 | [diff] [blame] | 279 | u32 pipe_reg, bool remote); |
Sagar Dharia | 33beca0 | 2012-10-22 16:21:46 -0600 | [diff] [blame] | 280 | void msm_slim_sps_exit(struct msm_slim_ctrl *dev, bool dereg); |
Kenneth Heitke | ae62604 | 2012-11-05 21:01:44 -0700 | [diff] [blame] | 281 | |
Sagar Dharia | 24419e3 | 2013-01-14 17:56:32 -0700 | [diff] [blame] | 282 | int msm_slim_connect_endp(struct msm_slim_ctrl *dev, |
| 283 | struct msm_slim_endp *endpoint, |
| 284 | struct completion *notify); |
Kenneth Heitke | ae62604 | 2012-11-05 21:01:44 -0700 | [diff] [blame] | 285 | void msm_slim_qmi_exit(struct msm_slim_ctrl *dev); |
| 286 | int msm_slim_qmi_init(struct msm_slim_ctrl *dev, bool apps_is_master); |
| 287 | int msm_slim_qmi_power_request(struct msm_slim_ctrl *dev, bool active); |
Sagar Dharia | 2754ab4 | 2012-08-21 18:07:39 -0600 | [diff] [blame] | 288 | #endif |