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