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