blob: 49176b587082cde152060065802bc4e77de07fad [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 "ipe_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
Suresh Vankadara6657bc22017-07-31 10:33:04 +053023
24int 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
40rgltr_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
49int 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
65rgltr_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 Kalavala85c40352017-05-15 16:19:13 -070074static 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 Kalavalaadc6ce32017-07-17 17:19:11 -070080 CAM_ERR(CAM_ICP, "get ipe dt prop is failed");
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070081
82 return rc;
83}
84
85static 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
97int 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
114int cam_ipe_enable_soc_resources(struct cam_hw_soc_info *soc_info)
115{
116 int rc = 0;
117
Pavan Kumar Chilamkurthi7e7607b2017-06-22 20:02:50 -0700118 rc = cam_soc_util_enable_platform_resource(soc_info, true,
119 CAM_TURBO_VOTE, false);
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700120 if (rc) {
Lakshmi Narayana Kalavalaadc6ce32017-07-17 17:19:11 -0700121 CAM_ERR(CAM_ICP, "enable platform failed");
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700122 return rc;
123 }
124
125 return rc;
126}
127
128int 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 Kalavalaadc6ce32017-07-17 17:19:11 -0700134 CAM_ERR(CAM_ICP, "enable platform failed");
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700135
136 return rc;
137}
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530138
139int cam_ipe_update_clk_rate(struct cam_hw_soc_info *soc_info,
140 uint32_t clk_rate)
141{
142 if (!soc_info)
143 return -EINVAL;
144
145 return cam_soc_util_set_clk_rate(soc_info->clk[soc_info->src_clk_idx],
146 soc_info->clk_name[soc_info->src_clk_idx], clk_rate);
147}