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 | |
| 13 | #include <linux/io.h> |
| 14 | #include <linux/of.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/dma-buf.h> |
| 17 | #include <media/cam_defs.h> |
| 18 | #include <media/cam_icp.h> |
| 19 | #include "ipe_soc.h" |
| 20 | #include "cam_soc_util.h" |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 21 | #include "cam_debug_util.h" |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 22 | |
Suresh Vankadara | 6657bc2 | 2017-07-31 10:33:04 +0530 | [diff] [blame] | 23 | |
| 24 | int cam_ipe_transfer_gdsc_control(struct cam_hw_soc_info *soc_info) |
| 25 | { |
| 26 | int i; |
| 27 | int rc; |
| 28 | |
| 29 | for (i = 0; i < soc_info->num_rgltr; i++) { |
| 30 | rc = regulator_set_mode(soc_info->rgltr[i], |
| 31 | REGULATOR_MODE_FAST); |
| 32 | if (rc) { |
| 33 | CAM_ERR(CAM_ICP, "Regulator set mode %s failed", |
| 34 | soc_info->rgltr_name[i]); |
| 35 | goto rgltr_set_mode_failed; |
| 36 | } |
| 37 | } |
| 38 | return 0; |
| 39 | |
| 40 | rgltr_set_mode_failed: |
| 41 | for (i = i - 1; i >= 0; i--) |
| 42 | if (soc_info->rgltr[i]) |
| 43 | regulator_set_mode(soc_info->rgltr[i], |
| 44 | REGULATOR_MODE_NORMAL); |
| 45 | |
| 46 | return rc; |
| 47 | } |
| 48 | |
| 49 | int cam_ipe_get_gdsc_control(struct cam_hw_soc_info *soc_info) |
| 50 | { |
| 51 | int i; |
| 52 | int rc; |
| 53 | |
| 54 | for (i = 0; i < soc_info->num_rgltr; i++) { |
| 55 | rc = regulator_set_mode(soc_info->rgltr[i], |
| 56 | REGULATOR_MODE_NORMAL); |
| 57 | if (rc) { |
| 58 | CAM_ERR(CAM_ICP, "Regulator set mode %s failed", |
| 59 | soc_info->rgltr_name[i]); |
| 60 | goto rgltr_set_mode_failed; |
| 61 | } |
| 62 | } |
| 63 | return 0; |
| 64 | |
| 65 | rgltr_set_mode_failed: |
| 66 | for (i = i - 1; i >= 0; i--) |
| 67 | if (soc_info->rgltr[i]) |
| 68 | regulator_set_mode(soc_info->rgltr[i], |
| 69 | REGULATOR_MODE_FAST); |
| 70 | |
| 71 | return rc; |
| 72 | } |
| 73 | |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 74 | static int cam_ipe_get_dt_properties(struct cam_hw_soc_info *soc_info) |
| 75 | { |
| 76 | int rc = 0; |
| 77 | |
| 78 | rc = cam_soc_util_get_dt_properties(soc_info); |
| 79 | if (rc < 0) |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 80 | CAM_ERR(CAM_ICP, "get ipe dt prop is failed"); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 81 | |
| 82 | return rc; |
| 83 | } |
| 84 | |
| 85 | static int cam_ipe_request_platform_resource( |
| 86 | struct cam_hw_soc_info *soc_info, |
| 87 | irq_handler_t ipe_irq_handler, void *irq_data) |
| 88 | { |
| 89 | int rc = 0; |
| 90 | |
| 91 | rc = cam_soc_util_request_platform_resource(soc_info, ipe_irq_handler, |
| 92 | irq_data); |
| 93 | |
| 94 | return rc; |
| 95 | } |
| 96 | |
| 97 | int cam_ipe_init_soc_resources(struct cam_hw_soc_info *soc_info, |
| 98 | irq_handler_t ipe_irq_handler, void *irq_data) |
| 99 | { |
| 100 | int rc = 0; |
| 101 | |
| 102 | rc = cam_ipe_get_dt_properties(soc_info); |
| 103 | if (rc < 0) |
| 104 | return rc; |
| 105 | |
| 106 | rc = cam_ipe_request_platform_resource(soc_info, ipe_irq_handler, |
| 107 | irq_data); |
| 108 | if (rc < 0) |
| 109 | return rc; |
| 110 | |
| 111 | return rc; |
| 112 | } |
| 113 | |
| 114 | int cam_ipe_enable_soc_resources(struct cam_hw_soc_info *soc_info) |
| 115 | { |
| 116 | int rc = 0; |
| 117 | |
Pavan Kumar Chilamkurthi | 7e7607b | 2017-06-22 20:02:50 -0700 | [diff] [blame] | 118 | rc = cam_soc_util_enable_platform_resource(soc_info, true, |
| 119 | CAM_TURBO_VOTE, false); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 120 | if (rc) { |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 121 | CAM_ERR(CAM_ICP, "enable platform failed"); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 122 | return rc; |
| 123 | } |
| 124 | |
| 125 | return rc; |
| 126 | } |
| 127 | |
| 128 | int cam_ipe_disable_soc_resources(struct cam_hw_soc_info *soc_info) |
| 129 | { |
| 130 | int rc = 0; |
| 131 | |
| 132 | rc = cam_soc_util_disable_platform_resource(soc_info, true, false); |
| 133 | if (rc) |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 134 | CAM_ERR(CAM_ICP, "enable platform failed"); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 135 | |
| 136 | return rc; |
| 137 | } |