blob: 27491559e57622339ca885c3e4c93e40a2d90184 [file] [log] [blame]
Sachin Bhayareeeb88892018-01-02 16:36:01 +05301/* Copyright (c) 2012-2015, 2017-2018, 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/clk.h>
14#include <linux/err.h>
15#include <linux/io.h>
16#include <linux/delay.h>
17#include <linux/mdss_io_util.h>
18
19#define MAX_I2C_CMDS 16
Sachin Bhayare5076e252018-01-18 14:56:45 +053020void mdss_reg_w(struct mdss_io_data *io, u32 offset, u32 value, u32 debug)
Sachin Bhayareeeb88892018-01-02 16:36:01 +053021{
22 u32 in_val;
23
24 if (!io || !io->base) {
25 DEV_ERR("%pS->%s: invalid input\n",
26 __builtin_return_address(0), __func__);
27 return;
28 }
29
30 if (offset > io->len) {
31 DEV_ERR("%pS->%s: offset out of range\n",
32 __builtin_return_address(0), __func__);
33 return;
34 }
35
36 writel_relaxed(value, io->base + offset);
37 if (debug) {
38 in_val = readl_relaxed(io->base + offset);
39 DEV_DBG("[%08x] => %08x [%08x]\n",
40 (u32)(unsigned long)(io->base + offset),
41
42 value, in_val);
43 }
Sachin Bhayare5076e252018-01-18 14:56:45 +053044} /* mdss_reg_w */
45EXPORT_SYMBOL(mdss_reg_w);
Sachin Bhayareeeb88892018-01-02 16:36:01 +053046
Sachin Bhayare5076e252018-01-18 14:56:45 +053047u32 mdss_reg_r(struct mdss_io_data *io, u32 offset, u32 debug)
Sachin Bhayareeeb88892018-01-02 16:36:01 +053048{
49 u32 value;
50
51 if (!io || !io->base) {
52 DEV_ERR("%pS->%s: invalid input\n",
53 __builtin_return_address(0), __func__);
54 return -EINVAL;
55 }
56
57 if (offset > io->len) {
58 DEV_ERR("%pS->%s: offset out of range\n",
59 __builtin_return_address(0), __func__);
60 return -EINVAL;
61 }
62
63 value = readl_relaxed(io->base + offset);
64 if (debug)
65 DEV_DBG("[%08x] <= %08x\n",
66 (u32)(unsigned long)(io->base + offset), value);
67
68 return value;
Sachin Bhayare5076e252018-01-18 14:56:45 +053069} /* mdss_reg_r */
70EXPORT_SYMBOL(mdss_reg_r);
Sachin Bhayareeeb88892018-01-02 16:36:01 +053071
Sachin Bhayare5076e252018-01-18 14:56:45 +053072void mdss_reg_dump(void __iomem *base, u32 length, const char *prefix,
Sachin Bhayareeeb88892018-01-02 16:36:01 +053073 u32 debug)
74{
75 if (debug)
76 print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET, 32, 4,
77 (void *)base, length, false);
Sachin Bhayare5076e252018-01-18 14:56:45 +053078} /* mdss_reg_dump */
79EXPORT_SYMBOL(mdss_reg_dump);
Sachin Bhayareeeb88892018-01-02 16:36:01 +053080
Sachin Bhayare5076e252018-01-18 14:56:45 +053081static struct resource *msm_mdss_get_res_byname(struct platform_device *pdev,
Sachin Bhayareeeb88892018-01-02 16:36:01 +053082 unsigned int type, const char *name)
83{
84 struct resource *res = NULL;
85
86 res = platform_get_resource_byname(pdev, type, name);
87 if (!res)
88 DEV_ERR("%s: '%s' resource not found\n", __func__, name);
89
90 return res;
Sachin Bhayare5076e252018-01-18 14:56:45 +053091} /* msm_mdss_get_res_byname */
92EXPORT_SYMBOL(msm_mdss_get_res_byname);
Sachin Bhayareeeb88892018-01-02 16:36:01 +053093
Sachin Bhayare5076e252018-01-18 14:56:45 +053094int msm_mdss_ioremap_byname(struct platform_device *pdev,
95 struct mdss_io_data *io_data, const char *name)
Sachin Bhayareeeb88892018-01-02 16:36:01 +053096{
97 struct resource *res = NULL;
98
99 if (!pdev || !io_data) {
100 DEV_ERR("%pS->%s: invalid input\n",
101 __builtin_return_address(0), __func__);
102 return -EINVAL;
103 }
104
Sachin Bhayare5076e252018-01-18 14:56:45 +0530105 res = msm_mdss_get_res_byname(pdev, IORESOURCE_MEM, name);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530106 if (!res) {
Sachin Bhayare5076e252018-01-18 14:56:45 +0530107 DEV_ERR("%pS->%s: '%s' msm_mdss_get_res_byname failed\n",
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530108 __builtin_return_address(0), __func__, name);
109 return -ENODEV;
110 }
111
112 io_data->len = (u32)resource_size(res);
113 io_data->base = ioremap(res->start, io_data->len);
114 if (!io_data->base) {
115 DEV_ERR("%pS->%s: '%s' ioremap failed\n",
116 __builtin_return_address(0), __func__, name);
117 return -EIO;
118 }
119
120 return 0;
Sachin Bhayare5076e252018-01-18 14:56:45 +0530121} /* msm_mdss_ioremap_byname */
122EXPORT_SYMBOL(msm_mdss_ioremap_byname);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530123
Sachin Bhayare5076e252018-01-18 14:56:45 +0530124void msm_mdss_iounmap(struct mdss_io_data *io_data)
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530125{
126 if (!io_data) {
127 DEV_ERR("%pS->%s: invalid input\n",
128 __builtin_return_address(0), __func__);
129 return;
130 }
131
132 if (io_data->base) {
133 iounmap(io_data->base);
134 io_data->base = NULL;
135 }
136 io_data->len = 0;
Sachin Bhayare5076e252018-01-18 14:56:45 +0530137} /* msm_mdss_iounmap */
138EXPORT_SYMBOL(msm_mdss_iounmap);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530139
Sachin Bhayare5076e252018-01-18 14:56:45 +0530140int msm_mdss_config_vreg(struct device *dev, struct mdss_vreg *in_vreg,
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530141 int num_vreg, int config)
142{
143 int i = 0, rc = 0;
Sachin Bhayare5076e252018-01-18 14:56:45 +0530144 struct mdss_vreg *curr_vreg = NULL;
145 enum mdss_vreg_type type;
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530146
147 if (!in_vreg || !num_vreg)
148 return rc;
149
150 if (config) {
151 for (i = 0; i < num_vreg; i++) {
152 curr_vreg = &in_vreg[i];
153 curr_vreg->vreg = regulator_get(dev,
154 curr_vreg->vreg_name);
155 rc = PTR_RET(curr_vreg->vreg);
156 if (rc) {
157 DEV_ERR("%pS->%s: %s get failed. rc=%d\n",
158 __builtin_return_address(0), __func__,
159 curr_vreg->vreg_name, rc);
160 curr_vreg->vreg = NULL;
161 goto vreg_get_fail;
162 }
163 type = (regulator_count_voltages(curr_vreg->vreg) > 0)
164 ? DSS_REG_LDO : DSS_REG_VS;
165 if (type == DSS_REG_LDO) {
166 rc = regulator_set_voltage(
167 curr_vreg->vreg,
168 curr_vreg->min_voltage,
169 curr_vreg->max_voltage);
170 if (rc < 0) {
171 DEV_ERR("%pS->%s: %s set vltg fail\n",
172 __builtin_return_address(0),
173 __func__,
174 curr_vreg->vreg_name);
175 goto vreg_set_voltage_fail;
176 }
177 }
178 }
179 } else {
180 for (i = num_vreg-1; i >= 0; i--) {
181 curr_vreg = &in_vreg[i];
182 if (curr_vreg->vreg) {
183 type = (regulator_count_voltages(
184 curr_vreg->vreg) > 0)
185 ? DSS_REG_LDO : DSS_REG_VS;
186 if (type == DSS_REG_LDO) {
187 regulator_set_voltage(curr_vreg->vreg,
188 0, curr_vreg->max_voltage);
189 }
190 regulator_put(curr_vreg->vreg);
191 curr_vreg->vreg = NULL;
192 }
193 }
194 }
195 return 0;
196
197vreg_unconfig:
198if (type == DSS_REG_LDO)
Sachin Bhayare3d3767e2018-01-02 21:10:57 +0530199 regulator_set_load(curr_vreg->vreg, 0);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530200
201vreg_set_voltage_fail:
202 regulator_put(curr_vreg->vreg);
203 curr_vreg->vreg = NULL;
204
205vreg_get_fail:
206 for (i--; i >= 0; i--) {
207 curr_vreg = &in_vreg[i];
208 type = (regulator_count_voltages(curr_vreg->vreg) > 0)
209 ? DSS_REG_LDO : DSS_REG_VS;
210 goto vreg_unconfig;
211 }
212 return rc;
Sachin Bhayare5076e252018-01-18 14:56:45 +0530213} /* msm_mdss_config_vreg */
214EXPORT_SYMBOL(msm_mdss_config_vreg);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530215
Sachin Bhayare5076e252018-01-18 14:56:45 +0530216int msm_mdss_config_vreg_opt_mode(struct mdss_vreg *in_vreg, int num_vreg,
217 enum mdss_vreg_mode mode)
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530218{
219 int i = 0, rc = 0;
220
221 if (mode >= DSS_REG_MODE_MAX) {
222 pr_err("%pS->%s: invalid mode %d\n",
223 __builtin_return_address(0), __func__, mode);
224 rc = -EINVAL;
225 goto error;
226 }
227
228 for (i = 0; i < num_vreg; i++) {
229 rc = PTR_RET(in_vreg[i].vreg);
230 if (rc) {
231 DEV_ERR("%pS->%s: %s regulator error. rc=%d\n",
232 __builtin_return_address(0), __func__,
233 in_vreg[i].vreg_name, rc);
234 goto error;
235 }
236
237 DEV_DBG("%s: Setting optimum mode %d for %s (load=%d)\n",
238 __func__, mode, in_vreg[i].vreg_name,
239 in_vreg[i].load[mode]);
Sachin Bhayare3d3767e2018-01-02 21:10:57 +0530240 rc = regulator_set_load(in_vreg[i].vreg,
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530241 in_vreg[i].load[mode]);
242 if (rc < 0) {
243 DEV_ERR("%pS->%s: %s set opt mode failed. rc=%d\n",
244 __builtin_return_address(0), __func__,
245 in_vreg[i].vreg_name, rc);
246 goto error;
247 } else {
248 /*
Sachin Bhayare3d3767e2018-01-02 21:10:57 +0530249 * regulator_set_load can return non-zero
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530250 * value for success. However, this API is expected
251 * to return 0 for success.
252 */
253 rc = 0;
254 }
255 }
256
257error:
258 return rc;
259}
Sachin Bhayare5076e252018-01-18 14:56:45 +0530260EXPORT_SYMBOL(msm_mdss_config_vreg_opt_mode);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530261
Sachin Bhayare5076e252018-01-18 14:56:45 +0530262int msm_mdss_enable_vreg(struct mdss_vreg *in_vreg, int num_vreg, int enable)
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530263{
264 int i = 0, rc = 0;
265 bool need_sleep;
266
267 if (enable) {
268 for (i = 0; i < num_vreg; i++) {
269 rc = PTR_RET(in_vreg[i].vreg);
270 if (rc) {
271 DEV_ERR("%pS->%s: %s regulator error. rc=%d\n",
272 __builtin_return_address(0), __func__,
273 in_vreg[i].vreg_name, rc);
274 goto vreg_set_opt_mode_fail;
275 }
276 need_sleep = !regulator_is_enabled(in_vreg[i].vreg);
277 if (in_vreg[i].pre_on_sleep && need_sleep)
Vishnuvardhan Prodduturicc3789e2018-05-09 17:58:00 +0530278 usleep_range((in_vreg[i].pre_on_sleep * 1000),
279 (in_vreg[i].pre_on_sleep * 1000) + 10);
Sachin Bhayare3d3767e2018-01-02 21:10:57 +0530280 rc = regulator_set_load(in_vreg[i].vreg,
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530281 in_vreg[i].load[DSS_REG_MODE_ENABLE]);
282 if (rc < 0) {
283 DEV_ERR("%pS->%s: %s set opt m fail\n",
284 __builtin_return_address(0), __func__,
285 in_vreg[i].vreg_name);
286 goto vreg_set_opt_mode_fail;
287 }
288 rc = regulator_enable(in_vreg[i].vreg);
jialongjhan7dfbf872020-04-21 20:24:23 +0800289
290 //[Arima][8901][Jialongjhan]Modify Power on/off sequence 20191104 Start
291 if(!strcmp(in_vreg[i].vreg_name,"vddio")){
292 msleep(10);
293 }
294 //[Arima][8901][Jialongjhan]Modify Power on/off sequence 20191104 End
295
296
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530297 if (in_vreg[i].post_on_sleep && need_sleep)
Vishnuvardhan Prodduturicc3789e2018-05-09 17:58:00 +0530298 usleep_range((in_vreg[i].post_on_sleep * 1000),
299 (in_vreg[i].post_on_sleep * 1000) + 10);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530300 if (rc < 0) {
301 DEV_ERR("%pS->%s: %s enable failed\n",
302 __builtin_return_address(0), __func__,
303 in_vreg[i].vreg_name);
304 goto disable_vreg;
305 }
306 }
307 } else {
308 for (i = num_vreg-1; i >= 0; i--) {
309 if (in_vreg[i].pre_off_sleep)
Vishnuvardhan Prodduturicc3789e2018-05-09 17:58:00 +0530310 usleep_range((in_vreg[i].pre_off_sleep * 1000),
311 (in_vreg[i].pre_off_sleep * 1000) + 10);
Sachin Bhayare3d3767e2018-01-02 21:10:57 +0530312 regulator_set_load(in_vreg[i].vreg,
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530313 in_vreg[i].load[DSS_REG_MODE_DISABLE]);
314
jialongjhan7dfbf872020-04-21 20:24:23 +0800315 //[Arima][8901][Jialongjhan]Modify Power on/off sequence 20191104 Start
316 if(!strcmp(in_vreg[i].vreg_name,"vddio")){
317 msleep(10);
318 }
319 //[Arima][8901][Jialongjhan]Modify Power on/off sequence 20191104 End
320
321
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530322 if (regulator_is_enabled(in_vreg[i].vreg))
323 regulator_disable(in_vreg[i].vreg);
324
325 if (in_vreg[i].post_off_sleep)
Vishnuvardhan Prodduturicc3789e2018-05-09 17:58:00 +0530326 usleep_range((in_vreg[i].post_off_sleep * 1000),
327 (in_vreg[i].post_off_sleep * 1000) + 10);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530328 }
329 }
330 return rc;
331
332disable_vreg:
Sachin Bhayare3d3767e2018-01-02 21:10:57 +0530333 regulator_set_load(in_vreg[i].vreg,
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530334 in_vreg[i].load[DSS_REG_MODE_DISABLE]);
335
336vreg_set_opt_mode_fail:
337 for (i--; i >= 0; i--) {
338 if (in_vreg[i].pre_off_sleep)
Vishnuvardhan Prodduturicc3789e2018-05-09 17:58:00 +0530339 usleep_range((in_vreg[i].pre_off_sleep * 1000),
340 (in_vreg[i].pre_off_sleep * 1000) + 10);
Sachin Bhayare3d3767e2018-01-02 21:10:57 +0530341 regulator_set_load(in_vreg[i].vreg,
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530342 in_vreg[i].load[DSS_REG_MODE_DISABLE]);
343 regulator_disable(in_vreg[i].vreg);
344 if (in_vreg[i].post_off_sleep)
Vishnuvardhan Prodduturicc3789e2018-05-09 17:58:00 +0530345 usleep_range((in_vreg[i].post_off_sleep * 1000),
346 (in_vreg[i].post_off_sleep * 1000) + 10);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530347 }
348
349 return rc;
Sachin Bhayare5076e252018-01-18 14:56:45 +0530350} /* msm_mdss_enable_vreg */
351EXPORT_SYMBOL(msm_mdss_enable_vreg);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530352
Sachin Bhayare5076e252018-01-18 14:56:45 +0530353int msm_mdss_enable_gpio(struct mdss_gpio *in_gpio, int num_gpio, int enable)
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530354{
355 int i = 0, rc = 0;
356
357 if (enable) {
358 for (i = 0; i < num_gpio; i++) {
359 DEV_DBG("%pS->%s: %s enable\n",
360 __builtin_return_address(0), __func__,
361 in_gpio[i].gpio_name);
362
363 rc = gpio_request(in_gpio[i].gpio,
364 in_gpio[i].gpio_name);
365 if (rc < 0) {
366 DEV_ERR("%pS->%s: %s enable failed\n",
367 __builtin_return_address(0), __func__,
368 in_gpio[i].gpio_name);
369 goto disable_gpio;
370 }
371 gpio_set_value(in_gpio[i].gpio, in_gpio[i].value);
372 }
373 } else {
374 for (i = num_gpio-1; i >= 0; i--) {
375 DEV_DBG("%pS->%s: %s disable\n",
376 __builtin_return_address(0), __func__,
377 in_gpio[i].gpio_name);
378 if (in_gpio[i].gpio)
379 gpio_free(in_gpio[i].gpio);
380 }
381 }
382 return rc;
383
384disable_gpio:
385 for (i--; i >= 0; i--)
386 if (in_gpio[i].gpio)
387 gpio_free(in_gpio[i].gpio);
388
389 return rc;
Sachin Bhayare5076e252018-01-18 14:56:45 +0530390} /* msm_mdss_enable_gpio */
391EXPORT_SYMBOL(msm_mdss_enable_gpio);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530392
Sachin Bhayare5076e252018-01-18 14:56:45 +0530393void msm_mdss_put_clk(struct mdss_clk *clk_arry, int num_clk)
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530394{
395 int i;
396
397 for (i = num_clk - 1; i >= 0; i--) {
398 if (clk_arry[i].clk)
399 clk_put(clk_arry[i].clk);
400 clk_arry[i].clk = NULL;
401 }
Sachin Bhayare5076e252018-01-18 14:56:45 +0530402} /* msm_mdss_put_clk */
403EXPORT_SYMBOL(msm_mdss_put_clk);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530404
Sachin Bhayare5076e252018-01-18 14:56:45 +0530405int msm_mdss_get_clk(struct device *dev, struct mdss_clk *clk_arry, int num_clk)
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530406{
407 int i, rc = 0;
408
409 for (i = 0; i < num_clk; i++) {
410 clk_arry[i].clk = clk_get(dev, clk_arry[i].clk_name);
411 rc = PTR_RET(clk_arry[i].clk);
412 if (rc) {
413 DEV_ERR("%pS->%s: '%s' get failed. rc=%d\n",
414 __builtin_return_address(0), __func__,
415 clk_arry[i].clk_name, rc);
416 goto error;
417 }
418 }
419
420 return rc;
421
422error:
Sachin Bhayare5076e252018-01-18 14:56:45 +0530423 msm_mdss_put_clk(clk_arry, num_clk);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530424
425 return rc;
Sachin Bhayare5076e252018-01-18 14:56:45 +0530426} /* msm_mdss_get_clk */
427EXPORT_SYMBOL(msm_mdss_get_clk);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530428
Sachin Bhayare5076e252018-01-18 14:56:45 +0530429int msm_mdss_clk_set_rate(struct mdss_clk *clk_arry, int num_clk)
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530430{
431 int i, rc = 0;
432
433 for (i = 0; i < num_clk; i++) {
434 if (clk_arry[i].clk) {
435 if (clk_arry[i].type != DSS_CLK_AHB) {
436 DEV_DBG("%pS->%s: '%s' rate %ld\n",
437 __builtin_return_address(0), __func__,
438 clk_arry[i].clk_name,
439 clk_arry[i].rate);
440 rc = clk_set_rate(clk_arry[i].clk,
441 clk_arry[i].rate);
442 if (rc) {
443 DEV_ERR("%pS->%s: %s failed. rc=%d\n",
444 __builtin_return_address(0),
445 __func__,
446 clk_arry[i].clk_name, rc);
447 break;
448 }
449 }
450 } else {
451 DEV_ERR("%pS->%s: '%s' is not available\n",
452 __builtin_return_address(0), __func__,
453 clk_arry[i].clk_name);
454 rc = -EPERM;
455 break;
456 }
457 }
458
459 return rc;
Sachin Bhayare5076e252018-01-18 14:56:45 +0530460} /* msm_mdss_clk_set_rate */
461EXPORT_SYMBOL(msm_mdss_clk_set_rate);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530462
Sachin Bhayare5076e252018-01-18 14:56:45 +0530463int msm_mdss_enable_clk(struct mdss_clk *clk_arry, int num_clk, int enable)
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530464{
465 int i, rc = 0;
466
467 if (enable) {
468 for (i = 0; i < num_clk; i++) {
469 DEV_DBG("%pS->%s: enable '%s'\n",
470 __builtin_return_address(0), __func__,
471 clk_arry[i].clk_name);
472 if (clk_arry[i].clk) {
473 rc = clk_prepare_enable(clk_arry[i].clk);
474 if (rc)
475 DEV_ERR("%pS->%s: %s en fail. rc=%d\n",
476 __builtin_return_address(0),
477 __func__,
478 clk_arry[i].clk_name, rc);
479 } else {
480 DEV_ERR("%pS->%s: '%s' is not available\n",
481 __builtin_return_address(0), __func__,
482 clk_arry[i].clk_name);
483 rc = -EPERM;
484 }
485
486 if (rc) {
Sachin Bhayare5076e252018-01-18 14:56:45 +0530487 msm_mdss_enable_clk(&clk_arry[i],
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530488 i, false);
489 break;
490 }
491 }
492 } else {
493 for (i = num_clk - 1; i >= 0; i--) {
494 DEV_DBG("%pS->%s: disable '%s'\n",
495 __builtin_return_address(0), __func__,
496 clk_arry[i].clk_name);
497
498 if (clk_arry[i].clk)
499 clk_disable_unprepare(clk_arry[i].clk);
500 else
501 DEV_ERR("%pS->%s: '%s' is not available\n",
502 __builtin_return_address(0), __func__,
503 clk_arry[i].clk_name);
504 }
505 }
506
507 return rc;
Sachin Bhayare5076e252018-01-18 14:56:45 +0530508} /* msm_mdss_enable_clk */
509EXPORT_SYMBOL(msm_mdss_enable_clk);
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530510
511
512int mdss_i2c_byte_read(struct i2c_client *client, uint8_t slave_addr,
513 uint8_t reg_offset, uint8_t *read_buf)
514{
515 struct i2c_msg msgs[2];
516 int ret = -1;
517
518 pr_debug("%s: reading from slave_addr=[%x] and offset=[%x]\n",
519 __func__, slave_addr, reg_offset);
520
521 msgs[0].addr = slave_addr >> 1;
522 msgs[0].flags = 0;
523 msgs[0].buf = &reg_offset;
524 msgs[0].len = 1;
525
526 msgs[1].addr = slave_addr >> 1;
527 msgs[1].flags = I2C_M_RD;
528 msgs[1].buf = read_buf;
529 msgs[1].len = 1;
530
531 ret = i2c_transfer(client->adapter, msgs, 2);
532 if (ret < 1) {
533 pr_err("%s: I2C READ FAILED=[%d]\n", __func__, ret);
534 return -EACCES;
535 }
536 pr_debug("%s: i2c buf is [%x]\n", __func__, *read_buf);
537 return 0;
538}
539EXPORT_SYMBOL(mdss_i2c_byte_read);
540
541int mdss_i2c_byte_write(struct i2c_client *client, uint8_t slave_addr,
542 uint8_t reg_offset, uint8_t *value)
543{
544 struct i2c_msg msgs[1];
545 uint8_t data[2];
546 int status = -EACCES;
547
548 pr_debug("%s: writing from slave_addr=[%x] and offset=[%x]\n",
549 __func__, slave_addr, reg_offset);
550
551 data[0] = reg_offset;
552 data[1] = *value;
553
554 msgs[0].addr = slave_addr >> 1;
555 msgs[0].flags = 0;
556 msgs[0].len = 2;
557 msgs[0].buf = data;
558
559 status = i2c_transfer(client->adapter, msgs, 1);
560 if (status < 1) {
561 pr_err("I2C WRITE FAILED=[%d]\n", status);
562 return -EACCES;
563 }
564 pr_debug("%s: I2C write status=%x\n", __func__, status);
565 return status;
566}
567EXPORT_SYMBOL(mdss_i2c_byte_write);