blob: 07dacb247dc9804260fa339f7f0141eed26e4c0c [file] [log] [blame]
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -07001/* 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 Kalavalaadc6ce32017-07-17 17:19:11 -070021#include "cam_debug_util.h"
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070022
23static 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 Kalavalaadc6ce32017-07-17 17:19:11 -070029 CAM_ERR(CAM_ICP, "get bps dt prop is failed");
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070030
31 return rc;
32}
33
34static 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
46int 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
63int cam_bps_enable_soc_resources(struct cam_hw_soc_info *soc_info)
64{
65 int rc = 0;
66
Pavan Kumar Chilamkurthi7e7607b2017-06-22 20:02:50 -070067 rc = cam_soc_util_enable_platform_resource(soc_info, true,
68 CAM_TURBO_VOTE, false);
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070069 if (rc)
Lakshmi Narayana Kalavalaadc6ce32017-07-17 17:19:11 -070070 CAM_ERR(CAM_ICP, "enable platform failed");
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070071
72 return rc;
73}
74
75int 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 Kalavalaadc6ce32017-07-17 17:19:11 -070081 CAM_ERR(CAM_ICP, "disable platform failed");
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070082
83 return rc;
84}
Suresh Vankadara6657bc22017-07-31 10:33:04 +053085
86int 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
102rgltr_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
111int 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
127rgltr_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}