Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2017, The Linux Foundation. All rights reserved. |
| 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 | |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 13 | #include <linux/of.h> |
| 14 | #include <linux/debugfs.h> |
| 15 | #include <linux/videodev2.h> |
| 16 | #include <linux/uaccess.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/firmware.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/timer.h> |
| 21 | #include "cam_io_util.h" |
| 22 | #include "cam_hw.h" |
| 23 | #include "cam_hw_intf.h" |
| 24 | #include "bps_core.h" |
| 25 | #include "bps_soc.h" |
| 26 | #include "cam_soc_util.h" |
| 27 | #include "cam_io_util.h" |
| 28 | #include "cam_bps_hw_intf.h" |
| 29 | #include "cam_icp_hw_intf.h" |
| 30 | #include "cam_icp_hw_mgr_intf.h" |
| 31 | #include "cam_cpas_api.h" |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 32 | #include "cam_debug_util.h" |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 33 | |
| 34 | static int cam_bps_cpas_vote(struct cam_bps_device_core_info *core_info, |
| 35 | struct cam_icp_cpas_vote *cpas_vote) |
| 36 | { |
| 37 | int rc = 0; |
| 38 | |
| 39 | if (cpas_vote->ahb_vote_valid) |
| 40 | rc = cam_cpas_update_ahb_vote(core_info->cpas_handle, |
| 41 | &cpas_vote->ahb_vote); |
| 42 | if (cpas_vote->axi_vote_valid) |
| 43 | rc = cam_cpas_update_axi_vote(core_info->cpas_handle, |
| 44 | &cpas_vote->axi_vote); |
| 45 | |
| 46 | if (rc < 0) |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 47 | CAM_ERR(CAM_ICP, "cpas vote is failed: %d", rc); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 48 | |
| 49 | return rc; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | int cam_bps_init_hw(void *device_priv, |
| 54 | void *init_hw_args, uint32_t arg_size) |
| 55 | { |
| 56 | struct cam_hw_info *bps_dev = device_priv; |
| 57 | struct cam_hw_soc_info *soc_info = NULL; |
| 58 | struct cam_bps_device_core_info *core_info = NULL; |
| 59 | struct cam_icp_cpas_vote cpas_vote; |
| 60 | int rc = 0; |
| 61 | |
| 62 | if (!device_priv) { |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 63 | CAM_ERR(CAM_ICP, "Invalid cam_dev_info"); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 64 | return -EINVAL; |
| 65 | } |
| 66 | |
| 67 | soc_info = &bps_dev->soc_info; |
| 68 | core_info = (struct cam_bps_device_core_info *)bps_dev->core_info; |
| 69 | |
| 70 | if ((!soc_info) || (!core_info)) { |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 71 | CAM_ERR(CAM_ICP, "soc_info = %pK core_info = %pK", |
| 72 | soc_info, core_info); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 73 | return -EINVAL; |
| 74 | } |
| 75 | |
| 76 | cpas_vote.ahb_vote.type = CAM_VOTE_ABSOLUTE; |
Pavan Kumar Chilamkurthi | 7e7607b | 2017-06-22 20:02:50 -0700 | [diff] [blame] | 77 | cpas_vote.ahb_vote.vote.level = CAM_SVS_VOTE; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 78 | cpas_vote.axi_vote.compressed_bw = ICP_TURBO_VOTE; |
| 79 | cpas_vote.axi_vote.uncompressed_bw = ICP_TURBO_VOTE; |
| 80 | |
| 81 | rc = cam_cpas_start(core_info->cpas_handle, |
| 82 | &cpas_vote.ahb_vote, &cpas_vote.axi_vote); |
Lakshmi Narayana Kalavala | c2fac45 | 2017-06-12 12:38:07 -0700 | [diff] [blame] | 83 | if (rc) { |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 84 | CAM_ERR(CAM_ICP, "cpass start failed: %d", rc); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 85 | return rc; |
| 86 | } |
Lakshmi Narayana Kalavala | c2fac45 | 2017-06-12 12:38:07 -0700 | [diff] [blame] | 87 | core_info->cpas_start = true; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 88 | |
| 89 | rc = cam_bps_enable_soc_resources(soc_info); |
Lakshmi Narayana Kalavala | c2fac45 | 2017-06-12 12:38:07 -0700 | [diff] [blame] | 90 | if (rc) { |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 91 | CAM_ERR(CAM_ICP, "soc enable is failed: %d", rc); |
Lakshmi Narayana Kalavala | c2fac45 | 2017-06-12 12:38:07 -0700 | [diff] [blame] | 92 | if (cam_cpas_stop(core_info->cpas_handle)) |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 93 | CAM_ERR(CAM_ICP, "cpas stop is failed"); |
Lakshmi Narayana Kalavala | c2fac45 | 2017-06-12 12:38:07 -0700 | [diff] [blame] | 94 | else |
| 95 | core_info->cpas_start = false; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | return rc; |
| 99 | } |
| 100 | |
| 101 | int cam_bps_deinit_hw(void *device_priv, |
| 102 | void *init_hw_args, uint32_t arg_size) |
| 103 | { |
| 104 | struct cam_hw_info *bps_dev = device_priv; |
| 105 | struct cam_hw_soc_info *soc_info = NULL; |
| 106 | struct cam_bps_device_core_info *core_info = NULL; |
| 107 | int rc = 0; |
| 108 | |
| 109 | if (!device_priv) { |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 110 | CAM_ERR(CAM_ICP, "Invalid cam_dev_info"); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 111 | return -EINVAL; |
| 112 | } |
| 113 | |
| 114 | soc_info = &bps_dev->soc_info; |
| 115 | core_info = (struct cam_bps_device_core_info *)bps_dev->core_info; |
| 116 | if ((!soc_info) || (!core_info)) { |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 117 | CAM_ERR(CAM_ICP, "soc_info = %pK core_info = %pK", |
| 118 | soc_info, core_info); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 119 | return -EINVAL; |
| 120 | } |
| 121 | |
| 122 | rc = cam_bps_disable_soc_resources(soc_info); |
Lakshmi Narayana Kalavala | c2fac45 | 2017-06-12 12:38:07 -0700 | [diff] [blame] | 123 | if (rc) |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 124 | CAM_ERR(CAM_ICP, "soc disable is failed: %d", rc); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 125 | |
Lakshmi Narayana Kalavala | c2fac45 | 2017-06-12 12:38:07 -0700 | [diff] [blame] | 126 | if (core_info->cpas_start) { |
| 127 | if (cam_cpas_stop(core_info->cpas_handle)) |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 128 | CAM_ERR(CAM_ICP, "cpas stop is failed"); |
Lakshmi Narayana Kalavala | c2fac45 | 2017-06-12 12:38:07 -0700 | [diff] [blame] | 129 | else |
| 130 | core_info->cpas_start = false; |
| 131 | } |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 132 | |
| 133 | return rc; |
| 134 | } |
| 135 | |
Suresh Vankadara | 6657bc2 | 2017-07-31 10:33:04 +0530 | [diff] [blame] | 136 | static int cam_bps_handle_pc(struct cam_hw_info *bps_dev) |
| 137 | { |
| 138 | struct cam_hw_soc_info *soc_info = NULL; |
| 139 | struct cam_bps_device_core_info *core_info = NULL; |
| 140 | struct cam_bps_device_hw_info *hw_info = NULL; |
| 141 | int pwr_ctrl; |
| 142 | int pwr_status; |
| 143 | |
| 144 | soc_info = &bps_dev->soc_info; |
| 145 | core_info = (struct cam_bps_device_core_info *)bps_dev->core_info; |
| 146 | hw_info = core_info->bps_hw_info; |
| 147 | |
| 148 | cam_cpas_reg_read(core_info->cpas_handle, |
| 149 | CAM_CPAS_REG_CPASTOP, hw_info->pwr_ctrl, |
| 150 | true, &pwr_ctrl); |
| 151 | if (!(pwr_ctrl & BPS_COLLAPSE_MASK)) { |
| 152 | cam_cpas_reg_read(core_info->cpas_handle, |
| 153 | CAM_CPAS_REG_CPASTOP, hw_info->pwr_status, |
| 154 | true, &pwr_status); |
| 155 | |
| 156 | cam_cpas_reg_write(core_info->cpas_handle, |
| 157 | CAM_CPAS_REG_CPASTOP, |
| 158 | hw_info->pwr_ctrl, true, 0x1); |
| 159 | |
| 160 | if ((pwr_status >> BPS_PWR_ON_MASK)) |
| 161 | return -EINVAL; |
| 162 | } |
| 163 | cam_bps_get_gdsc_control(soc_info); |
| 164 | cam_cpas_reg_read(core_info->cpas_handle, |
| 165 | CAM_CPAS_REG_CPASTOP, hw_info->pwr_ctrl, true, |
| 166 | &pwr_ctrl); |
| 167 | cam_cpas_reg_read(core_info->cpas_handle, |
| 168 | CAM_CPAS_REG_CPASTOP, hw_info->pwr_status, |
| 169 | true, &pwr_status); |
| 170 | CAM_DBG(CAM_ICP, "pwr_ctrl = %x pwr_status = %x", |
| 171 | pwr_ctrl, pwr_status); |
| 172 | |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | static int cam_bps_handle_resume(struct cam_hw_info *bps_dev) |
| 177 | { |
| 178 | struct cam_hw_soc_info *soc_info = NULL; |
| 179 | struct cam_bps_device_core_info *core_info = NULL; |
| 180 | struct cam_bps_device_hw_info *hw_info = NULL; |
| 181 | int pwr_ctrl; |
| 182 | int pwr_status; |
| 183 | int rc = 0; |
| 184 | |
| 185 | soc_info = &bps_dev->soc_info; |
| 186 | core_info = (struct cam_bps_device_core_info *)bps_dev->core_info; |
| 187 | hw_info = core_info->bps_hw_info; |
| 188 | |
| 189 | cam_cpas_reg_read(core_info->cpas_handle, |
| 190 | CAM_CPAS_REG_CPASTOP, hw_info->pwr_ctrl, true, &pwr_ctrl); |
| 191 | if (pwr_ctrl & BPS_COLLAPSE_MASK) { |
| 192 | CAM_ERR(CAM_ICP, "BPS: resume failed : %d", pwr_ctrl); |
| 193 | return -EINVAL; |
| 194 | } |
| 195 | |
| 196 | rc = cam_bps_transfer_gdsc_control(soc_info); |
| 197 | cam_cpas_reg_read(core_info->cpas_handle, |
| 198 | CAM_CPAS_REG_CPASTOP, hw_info->pwr_ctrl, true, &pwr_ctrl); |
| 199 | cam_cpas_reg_read(core_info->cpas_handle, |
| 200 | CAM_CPAS_REG_CPASTOP, hw_info->pwr_status, true, &pwr_status); |
| 201 | CAM_DBG(CAM_ICP, "pwr_ctrl = %x pwr_status = %x", |
| 202 | pwr_ctrl, pwr_status); |
| 203 | |
| 204 | return rc; |
| 205 | } |
| 206 | |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 207 | int cam_bps_process_cmd(void *device_priv, uint32_t cmd_type, |
| 208 | void *cmd_args, uint32_t arg_size) |
| 209 | { |
| 210 | struct cam_hw_info *bps_dev = device_priv; |
| 211 | struct cam_hw_soc_info *soc_info = NULL; |
| 212 | struct cam_bps_device_core_info *core_info = NULL; |
| 213 | struct cam_bps_device_hw_info *hw_info = NULL; |
| 214 | int rc = 0; |
| 215 | |
| 216 | if (!device_priv) { |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 217 | CAM_ERR(CAM_ICP, "Invalid arguments"); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 218 | return -EINVAL; |
| 219 | } |
| 220 | |
| 221 | if (cmd_type >= CAM_ICP_BPS_CMD_MAX) { |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 222 | CAM_ERR(CAM_ICP, "Invalid command : %x", cmd_type); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 223 | return -EINVAL; |
| 224 | } |
| 225 | |
| 226 | soc_info = &bps_dev->soc_info; |
| 227 | core_info = (struct cam_bps_device_core_info *)bps_dev->core_info; |
| 228 | hw_info = core_info->bps_hw_info; |
| 229 | |
| 230 | switch (cmd_type) { |
| 231 | case CAM_ICP_BPS_CMD_VOTE_CPAS: { |
| 232 | struct cam_icp_cpas_vote *cpas_vote = cmd_args; |
| 233 | |
| 234 | if (!cmd_args) { |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 235 | CAM_ERR(CAM_ICP, "cmd args NULL"); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 236 | return -EINVAL; |
| 237 | } |
| 238 | |
| 239 | cam_bps_cpas_vote(core_info, cpas_vote); |
| 240 | break; |
| 241 | } |
| 242 | |
| 243 | case CAM_ICP_BPS_CMD_CPAS_START: { |
| 244 | struct cam_icp_cpas_vote *cpas_vote = cmd_args; |
| 245 | |
| 246 | if (!cmd_args) { |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 247 | CAM_ERR(CAM_ICP, "cmd args NULL"); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 248 | return -EINVAL; |
| 249 | } |
| 250 | |
Lakshmi Narayana Kalavala | c2fac45 | 2017-06-12 12:38:07 -0700 | [diff] [blame] | 251 | if (!core_info->cpas_start) { |
| 252 | rc = cam_cpas_start(core_info->cpas_handle, |
| 253 | &cpas_vote->ahb_vote, |
| 254 | &cpas_vote->axi_vote); |
| 255 | core_info->cpas_start = true; |
| 256 | } |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 257 | break; |
| 258 | } |
| 259 | |
| 260 | case CAM_ICP_BPS_CMD_CPAS_STOP: |
Lakshmi Narayana Kalavala | c2fac45 | 2017-06-12 12:38:07 -0700 | [diff] [blame] | 261 | if (core_info->cpas_start) { |
| 262 | cam_cpas_stop(core_info->cpas_handle); |
| 263 | core_info->cpas_start = false; |
| 264 | } |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 265 | break; |
Suresh Vankadara | 6657bc2 | 2017-07-31 10:33:04 +0530 | [diff] [blame] | 266 | case CAM_ICP_BPS_CMD_POWER_COLLAPSE: |
| 267 | rc = cam_bps_handle_pc(bps_dev); |
| 268 | break; |
| 269 | case CAM_ICP_BPS_CMD_POWER_RESUME: |
| 270 | rc = cam_bps_handle_resume(bps_dev); |
| 271 | break; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 272 | default: |
| 273 | break; |
| 274 | } |
| 275 | return rc; |
| 276 | } |
| 277 | |
| 278 | irqreturn_t cam_bps_irq(int irq_num, void *data) |
| 279 | { |
| 280 | return IRQ_HANDLED; |
| 281 | } |