Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  3 *
  4 * This program is free software; you can redistribute it and/or modify
  5 * it under the terms of the GNU General Public License version 2 and
  6 * only version 2 as published by the Free Software Foundation.
  7 *
  8 * This program is distributed in the hope that it will be useful,
  9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 11 * GNU General Public License for more details.
 12 */
 13
 14#include <linux/platform_device.h>
 15
 16#include "dsi_phy.h"
 17
 18#define S_DIV_ROUND_UP(n, d)	\
 19	(((n) >= 0) ? (((n) + (d) - 1) / (d)) : (((n) - (d) + 1) / (d)))
 20
 21static inline s32 linear_inter(s32 tmax, s32 tmin, s32 percent,
 22				s32 min_result, bool even)
 23{
 24	s32 v;
 25
 26	v = (tmax - tmin) * percent;
 27	v = S_DIV_ROUND_UP(v, 100) + tmin;
 28	if (even && (v & 0x1))
 29		return max_t(s32, min_result, v - 1);
 30	else
 31		return max_t(s32, min_result, v);
 32}
 33
 34static void dsi_dphy_timing_calc_clk_zero(struct msm_dsi_dphy_timing *timing,
 35					s32 ui, s32 coeff, s32 pcnt)
 36{
 37	s32 tmax, tmin, clk_z;
 38	s32 temp;
 39
 40	/* reset */
 41	temp = 300 * coeff - ((timing->clk_prepare >> 1) + 1) * 2 * ui;
 42	tmin = S_DIV_ROUND_UP(temp, ui) - 2;
 43	if (tmin > 255) {
 44		tmax = 511;
 45		clk_z = linear_inter(2 * tmin, tmin, pcnt, 0, true);
 46	} else {
 47		tmax = 255;
 48		clk_z = linear_inter(tmax, tmin, pcnt, 0, true);
 49	}
 50
 51	/* adjust */
 52	temp = (timing->hs_rqst + timing->clk_prepare + clk_z) & 0x7;
 53	timing->clk_zero = clk_z + 8 - temp;
 54}
 55
 56int msm_dsi_dphy_timing_calc(struct msm_dsi_dphy_timing *timing,
 57	const unsigned long bit_rate, const unsigned long esc_rate)
 58{
 
 
 59	s32 ui, lpx;
 60	s32 tmax, tmin;
 61	s32 pcnt0 = 10;
 62	s32 pcnt1 = (bit_rate > 1200000000) ? 15 : 10;
 63	s32 pcnt2 = 10;
 64	s32 pcnt3 = (bit_rate > 180000000) ? 10 : 40;
 65	s32 coeff = 1000; /* Precision, should avoid overflow */
 66	s32 temp;
 67
 68	if (!bit_rate || !esc_rate)
 69		return -EINVAL;
 70
 71	ui = mult_frac(NSEC_PER_MSEC, coeff, bit_rate / 1000);
 72	lpx = mult_frac(NSEC_PER_MSEC, coeff, esc_rate / 1000);
 73
 74	tmax = S_DIV_ROUND_UP(95 * coeff, ui) - 2;
 75	tmin = S_DIV_ROUND_UP(38 * coeff, ui) - 2;
 76	timing->clk_prepare = linear_inter(tmax, tmin, pcnt0, 0, true);
 77
 78	temp = lpx / ui;
 79	if (temp & 0x1)
 80		timing->hs_rqst = temp;
 81	else
 82		timing->hs_rqst = max_t(s32, 0, temp - 2);
 83
 84	/* Calculate clk_zero after clk_prepare and hs_rqst */
 85	dsi_dphy_timing_calc_clk_zero(timing, ui, coeff, pcnt2);
 86
 87	temp = 105 * coeff + 12 * ui - 20 * coeff;
 88	tmax = S_DIV_ROUND_UP(temp, ui) - 2;
 89	tmin = S_DIV_ROUND_UP(60 * coeff, ui) - 2;
 90	timing->clk_trail = linear_inter(tmax, tmin, pcnt3, 0, true);
 91
 92	temp = 85 * coeff + 6 * ui;
 93	tmax = S_DIV_ROUND_UP(temp, ui) - 2;
 94	temp = 40 * coeff + 4 * ui;
 95	tmin = S_DIV_ROUND_UP(temp, ui) - 2;
 96	timing->hs_prepare = linear_inter(tmax, tmin, pcnt1, 0, true);
 97
 98	tmax = 255;
 99	temp = ((timing->hs_prepare >> 1) + 1) * 2 * ui + 2 * ui;
100	temp = 145 * coeff + 10 * ui - temp;
101	tmin = S_DIV_ROUND_UP(temp, ui) - 2;
102	timing->hs_zero = linear_inter(tmax, tmin, pcnt2, 24, true);
103
104	temp = 105 * coeff + 12 * ui - 20 * coeff;
105	tmax = S_DIV_ROUND_UP(temp, ui) - 2;
106	temp = 60 * coeff + 4 * ui;
107	tmin = DIV_ROUND_UP(temp, ui) - 2;
108	timing->hs_trail = linear_inter(tmax, tmin, pcnt3, 0, true);
109
110	tmax = 255;
111	tmin = S_DIV_ROUND_UP(100 * coeff, ui) - 2;
112	timing->hs_exit = linear_inter(tmax, tmin, pcnt2, 0, true);
113
114	tmax = 63;
115	temp = ((timing->hs_exit >> 1) + 1) * 2 * ui;
116	temp = 60 * coeff + 52 * ui - 24 * ui - temp;
117	tmin = S_DIV_ROUND_UP(temp, 8 * ui) - 1;
118	timing->clk_post = linear_inter(tmax, tmin, pcnt2, 0, false);
119
120	tmax = 63;
121	temp = ((timing->clk_prepare >> 1) + 1) * 2 * ui;
122	temp += ((timing->clk_zero >> 1) + 1) * 2 * ui;
123	temp += 8 * ui + lpx;
124	tmin = S_DIV_ROUND_UP(temp, 8 * ui) - 1;
125	if (tmin > tmax) {
126		temp = linear_inter(2 * tmax, tmin, pcnt2, 0, false);
127		timing->clk_pre = temp >> 1;
 
128	} else {
129		timing->clk_pre = linear_inter(tmax, tmin, pcnt2, 0, false);
 
 
130	}
131
132	timing->ta_go = 3;
133	timing->ta_sure = 0;
134	timing->ta_get = 4;
135
136	DBG("PHY timings: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d",
137		timing->clk_pre, timing->clk_post, timing->clk_zero,
 
138		timing->clk_trail, timing->clk_prepare, timing->hs_exit,
139		timing->hs_zero, timing->hs_prepare, timing->hs_trail,
140		timing->hs_rqst);
141
142	return 0;
143}
144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145void msm_dsi_phy_set_src_pll(struct msm_dsi_phy *phy, int pll_id, u32 reg,
146				u32 bit_mask)
147{
148	int phy_id = phy->id;
149	u32 val;
150
151	if ((phy_id >= DSI_MAX) || (pll_id >= DSI_MAX))
152		return;
153
154	val = dsi_phy_read(phy->base + reg);
155
156	if (phy->cfg->src_pll_truthtable[phy_id][pll_id])
157		dsi_phy_write(phy->base + reg, val | bit_mask);
158	else
159		dsi_phy_write(phy->base + reg, val & (~bit_mask));
160}
161
162static int dsi_phy_regulator_init(struct msm_dsi_phy *phy)
163{
164	struct regulator_bulk_data *s = phy->supplies;
165	const struct dsi_reg_entry *regs = phy->cfg->reg_cfg.regs;
166	struct device *dev = &phy->pdev->dev;
167	int num = phy->cfg->reg_cfg.num;
168	int i, ret;
169
170	for (i = 0; i < num; i++)
171		s[i].supply = regs[i].name;
172
173	ret = devm_regulator_bulk_get(dev, num, s);
174	if (ret < 0) {
175		dev_err(dev, "%s: failed to init regulator, ret=%d\n",
176						__func__, ret);
177		return ret;
178	}
179
180	for (i = 0; i < num; i++) {
181		if (regulator_can_change_voltage(s[i].consumer)) {
182			ret = regulator_set_voltage(s[i].consumer,
183				regs[i].min_voltage, regs[i].max_voltage);
184			if (ret < 0) {
185				dev_err(dev,
186					"regulator %d set voltage failed, %d\n",
187					i, ret);
188				return ret;
189			}
190		}
 
 
191	}
192
193	return 0;
194}
195
196static void dsi_phy_regulator_disable(struct msm_dsi_phy *phy)
197{
198	struct regulator_bulk_data *s = phy->supplies;
199	const struct dsi_reg_entry *regs = phy->cfg->reg_cfg.regs;
200	int num = phy->cfg->reg_cfg.num;
201	int i;
202
203	DBG("");
204	for (i = num - 1; i >= 0; i--)
205		if (regs[i].disable_load >= 0)
206			regulator_set_load(s[i].consumer, regs[i].disable_load);
207
208	regulator_bulk_disable(num, s);
209}
210
211static int dsi_phy_regulator_enable(struct msm_dsi_phy *phy)
212{
213	struct regulator_bulk_data *s = phy->supplies;
214	const struct dsi_reg_entry *regs = phy->cfg->reg_cfg.regs;
215	struct device *dev = &phy->pdev->dev;
216	int num = phy->cfg->reg_cfg.num;
217	int ret, i;
218
219	DBG("");
220	for (i = 0; i < num; i++) {
221		if (regs[i].enable_load >= 0) {
222			ret = regulator_set_load(s[i].consumer,
223							regs[i].enable_load);
224			if (ret < 0) {
225				dev_err(dev,
226					"regulator %d set op mode failed, %d\n",
227					i, ret);
228				goto fail;
229			}
230		}
231	}
232
233	ret = regulator_bulk_enable(num, s);
234	if (ret < 0) {
235		dev_err(dev, "regulator enable failed, %d\n", ret);
236		goto fail;
237	}
238
239	return 0;
240
241fail:
242	for (i--; i >= 0; i--)
243		regulator_set_load(s[i].consumer, regs[i].disable_load);
244	return ret;
245}
246
247static int dsi_phy_enable_resource(struct msm_dsi_phy *phy)
248{
249	struct device *dev = &phy->pdev->dev;
250	int ret;
251
252	pm_runtime_get_sync(dev);
253
254	ret = clk_prepare_enable(phy->ahb_clk);
255	if (ret) {
256		dev_err(dev, "%s: can't enable ahb clk, %d\n", __func__, ret);
257		pm_runtime_put_sync(dev);
258	}
259
260	return ret;
261}
262
263static void dsi_phy_disable_resource(struct msm_dsi_phy *phy)
264{
265	clk_disable_unprepare(phy->ahb_clk);
266	pm_runtime_put_sync(&phy->pdev->dev);
267}
268
269static const struct of_device_id dsi_phy_dt_match[] = {
270#ifdef CONFIG_DRM_MSM_DSI_28NM_PHY
271	{ .compatible = "qcom,dsi-phy-28nm-hpm",
272	  .data = &dsi_phy_28nm_hpm_cfgs },
273	{ .compatible = "qcom,dsi-phy-28nm-lp",
274	  .data = &dsi_phy_28nm_lp_cfgs },
275#endif
276#ifdef CONFIG_DRM_MSM_DSI_20NM_PHY
277	{ .compatible = "qcom,dsi-phy-20nm",
278	  .data = &dsi_phy_20nm_cfgs },
279#endif
280#ifdef CONFIG_DRM_MSM_DSI_28NM_8960_PHY
281	{ .compatible = "qcom,dsi-phy-28nm-8960",
282	  .data = &dsi_phy_28nm_8960_cfgs },
283#endif
 
 
 
 
 
 
 
 
 
 
284	{}
285};
286
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287static int dsi_phy_driver_probe(struct platform_device *pdev)
288{
289	struct msm_dsi_phy *phy;
290	struct device *dev = &pdev->dev;
291	const struct of_device_id *match;
292	int ret;
293
294	phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
295	if (!phy)
296		return -ENOMEM;
297
298	match = of_match_node(dsi_phy_dt_match, dev->of_node);
299	if (!match)
300		return -ENODEV;
301
302	phy->cfg = match->data;
303	phy->pdev = pdev;
304
305	ret = of_property_read_u32(dev->of_node,
306				"qcom,dsi-phy-index", &phy->id);
307	if (ret) {
308		dev_err(dev, "%s: PHY index not specified, %d\n",
309			__func__, ret);
310		goto fail;
311	}
312
313	phy->regulator_ldo_mode = of_property_read_bool(dev->of_node,
314				"qcom,dsi-phy-regulator-ldo-mode");
315
316	phy->base = msm_ioremap(pdev, "dsi_phy", "DSI_PHY");
317	if (IS_ERR(phy->base)) {
318		dev_err(dev, "%s: failed to map phy base\n", __func__);
319		ret = -ENOMEM;
320		goto fail;
321	}
322
323	phy->reg_base = msm_ioremap(pdev, "dsi_phy_regulator",
324				"DSI_PHY_REG");
325	if (IS_ERR(phy->reg_base)) {
326		dev_err(dev, "%s: failed to map phy regulator base\n",
327			__func__);
328		ret = -ENOMEM;
329		goto fail;
330	}
331
332	ret = dsi_phy_regulator_init(phy);
333	if (ret) {
334		dev_err(dev, "%s: failed to init regulator\n", __func__);
335		goto fail;
336	}
337
338	phy->ahb_clk = devm_clk_get(dev, "iface_clk");
339	if (IS_ERR(phy->ahb_clk)) {
340		dev_err(dev, "%s: Unable to get ahb clk\n", __func__);
341		ret = PTR_ERR(phy->ahb_clk);
342		goto fail;
343	}
344
 
 
 
 
 
 
345	/* PLL init will call into clk_register which requires
346	 * register access, so we need to enable power and ahb clock.
347	 */
348	ret = dsi_phy_enable_resource(phy);
349	if (ret)
350		goto fail;
351
352	phy->pll = msm_dsi_pll_init(pdev, phy->cfg->type, phy->id);
353	if (!phy->pll)
354		dev_info(dev,
355			"%s: pll init failed, need separate pll clk driver\n",
356			__func__);
 
 
357
358	dsi_phy_disable_resource(phy);
359
360	platform_set_drvdata(pdev, phy);
361
362	return 0;
363
364fail:
365	return ret;
366}
367
368static int dsi_phy_driver_remove(struct platform_device *pdev)
369{
370	struct msm_dsi_phy *phy = platform_get_drvdata(pdev);
371
372	if (phy && phy->pll) {
373		msm_dsi_pll_destroy(phy->pll);
374		phy->pll = NULL;
375	}
376
377	platform_set_drvdata(pdev, NULL);
378
379	return 0;
380}
381
382static struct platform_driver dsi_phy_platform_driver = {
383	.probe      = dsi_phy_driver_probe,
384	.remove     = dsi_phy_driver_remove,
385	.driver     = {
386		.name   = "msm_dsi_phy",
387		.of_match_table = dsi_phy_dt_match,
388	},
389};
390
391void __init msm_dsi_phy_driver_register(void)
392{
393	platform_driver_register(&dsi_phy_platform_driver);
394}
395
396void __exit msm_dsi_phy_driver_unregister(void)
397{
398	platform_driver_unregister(&dsi_phy_platform_driver);
399}
400
401int msm_dsi_phy_enable(struct msm_dsi_phy *phy, int src_pll_id,
402	const unsigned long bit_rate, const unsigned long esc_rate)
403{
404	struct device *dev = &phy->pdev->dev;
405	int ret;
406
407	if (!phy || !phy->cfg->ops.enable)
408		return -EINVAL;
409
 
 
 
 
 
 
 
410	ret = dsi_phy_regulator_enable(phy);
411	if (ret) {
412		dev_err(dev, "%s: regulator enable failed, %d\n",
413			__func__, ret);
414		return ret;
415	}
416
417	ret = phy->cfg->ops.enable(phy, src_pll_id, bit_rate, esc_rate);
418	if (ret) {
419		dev_err(dev, "%s: phy enable failed, %d\n", __func__, ret);
420		dsi_phy_regulator_disable(phy);
421		return ret;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422	}
423
424	return 0;
 
 
 
 
 
 
 
 
 
 
425}
426
427void msm_dsi_phy_disable(struct msm_dsi_phy *phy)
428{
429	if (!phy || !phy->cfg->ops.disable)
430		return;
431
 
 
 
 
432	phy->cfg->ops.disable(phy);
433
434	dsi_phy_regulator_disable(phy);
 
435}
436
437void msm_dsi_phy_get_clk_pre_post(struct msm_dsi_phy *phy,
438					u32 *clk_pre, u32 *clk_post)
439{
440	if (!phy)
441		return;
442
443	if (clk_pre)
444		*clk_pre = phy->timing.clk_pre;
445	if (clk_post)
446		*clk_post = phy->timing.clk_post;
447}
448
449struct msm_dsi_pll *msm_dsi_phy_get_pll(struct msm_dsi_phy *phy)
450{
451	if (!phy)
452		return NULL;
453
454	return phy->pll;
455}
456
v5.4
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
 
 
 
 
 
 
 
 
 
  4 */
  5
  6#include <linux/platform_device.h>
  7
  8#include "dsi_phy.h"
  9
 10#define S_DIV_ROUND_UP(n, d)	\
 11	(((n) >= 0) ? (((n) + (d) - 1) / (d)) : (((n) - (d) + 1) / (d)))
 12
 13static inline s32 linear_inter(s32 tmax, s32 tmin, s32 percent,
 14				s32 min_result, bool even)
 15{
 16	s32 v;
 17
 18	v = (tmax - tmin) * percent;
 19	v = S_DIV_ROUND_UP(v, 100) + tmin;
 20	if (even && (v & 0x1))
 21		return max_t(s32, min_result, v - 1);
 22	else
 23		return max_t(s32, min_result, v);
 24}
 25
 26static void dsi_dphy_timing_calc_clk_zero(struct msm_dsi_dphy_timing *timing,
 27					s32 ui, s32 coeff, s32 pcnt)
 28{
 29	s32 tmax, tmin, clk_z;
 30	s32 temp;
 31
 32	/* reset */
 33	temp = 300 * coeff - ((timing->clk_prepare >> 1) + 1) * 2 * ui;
 34	tmin = S_DIV_ROUND_UP(temp, ui) - 2;
 35	if (tmin > 255) {
 36		tmax = 511;
 37		clk_z = linear_inter(2 * tmin, tmin, pcnt, 0, true);
 38	} else {
 39		tmax = 255;
 40		clk_z = linear_inter(tmax, tmin, pcnt, 0, true);
 41	}
 42
 43	/* adjust */
 44	temp = (timing->hs_rqst + timing->clk_prepare + clk_z) & 0x7;
 45	timing->clk_zero = clk_z + 8 - temp;
 46}
 47
 48int msm_dsi_dphy_timing_calc(struct msm_dsi_dphy_timing *timing,
 49			     struct msm_dsi_phy_clk_request *clk_req)
 50{
 51	const unsigned long bit_rate = clk_req->bitclk_rate;
 52	const unsigned long esc_rate = clk_req->escclk_rate;
 53	s32 ui, lpx;
 54	s32 tmax, tmin;
 55	s32 pcnt0 = 10;
 56	s32 pcnt1 = (bit_rate > 1200000000) ? 15 : 10;
 57	s32 pcnt2 = 10;
 58	s32 pcnt3 = (bit_rate > 180000000) ? 10 : 40;
 59	s32 coeff = 1000; /* Precision, should avoid overflow */
 60	s32 temp;
 61
 62	if (!bit_rate || !esc_rate)
 63		return -EINVAL;
 64
 65	ui = mult_frac(NSEC_PER_MSEC, coeff, bit_rate / 1000);
 66	lpx = mult_frac(NSEC_PER_MSEC, coeff, esc_rate / 1000);
 67
 68	tmax = S_DIV_ROUND_UP(95 * coeff, ui) - 2;
 69	tmin = S_DIV_ROUND_UP(38 * coeff, ui) - 2;
 70	timing->clk_prepare = linear_inter(tmax, tmin, pcnt0, 0, true);
 71
 72	temp = lpx / ui;
 73	if (temp & 0x1)
 74		timing->hs_rqst = temp;
 75	else
 76		timing->hs_rqst = max_t(s32, 0, temp - 2);
 77
 78	/* Calculate clk_zero after clk_prepare and hs_rqst */
 79	dsi_dphy_timing_calc_clk_zero(timing, ui, coeff, pcnt2);
 80
 81	temp = 105 * coeff + 12 * ui - 20 * coeff;
 82	tmax = S_DIV_ROUND_UP(temp, ui) - 2;
 83	tmin = S_DIV_ROUND_UP(60 * coeff, ui) - 2;
 84	timing->clk_trail = linear_inter(tmax, tmin, pcnt3, 0, true);
 85
 86	temp = 85 * coeff + 6 * ui;
 87	tmax = S_DIV_ROUND_UP(temp, ui) - 2;
 88	temp = 40 * coeff + 4 * ui;
 89	tmin = S_DIV_ROUND_UP(temp, ui) - 2;
 90	timing->hs_prepare = linear_inter(tmax, tmin, pcnt1, 0, true);
 91
 92	tmax = 255;
 93	temp = ((timing->hs_prepare >> 1) + 1) * 2 * ui + 2 * ui;
 94	temp = 145 * coeff + 10 * ui - temp;
 95	tmin = S_DIV_ROUND_UP(temp, ui) - 2;
 96	timing->hs_zero = linear_inter(tmax, tmin, pcnt2, 24, true);
 97
 98	temp = 105 * coeff + 12 * ui - 20 * coeff;
 99	tmax = S_DIV_ROUND_UP(temp, ui) - 2;
100	temp = 60 * coeff + 4 * ui;
101	tmin = DIV_ROUND_UP(temp, ui) - 2;
102	timing->hs_trail = linear_inter(tmax, tmin, pcnt3, 0, true);
103
104	tmax = 255;
105	tmin = S_DIV_ROUND_UP(100 * coeff, ui) - 2;
106	timing->hs_exit = linear_inter(tmax, tmin, pcnt2, 0, true);
107
108	tmax = 63;
109	temp = ((timing->hs_exit >> 1) + 1) * 2 * ui;
110	temp = 60 * coeff + 52 * ui - 24 * ui - temp;
111	tmin = S_DIV_ROUND_UP(temp, 8 * ui) - 1;
112	timing->shared_timings.clk_post = linear_inter(tmax, tmin, pcnt2, 0,
113						       false);
114	tmax = 63;
115	temp = ((timing->clk_prepare >> 1) + 1) * 2 * ui;
116	temp += ((timing->clk_zero >> 1) + 1) * 2 * ui;
117	temp += 8 * ui + lpx;
118	tmin = S_DIV_ROUND_UP(temp, 8 * ui) - 1;
119	if (tmin > tmax) {
120		temp = linear_inter(2 * tmax, tmin, pcnt2, 0, false);
121		timing->shared_timings.clk_pre = temp >> 1;
122		timing->shared_timings.clk_pre_inc_by_2 = true;
123	} else {
124		timing->shared_timings.clk_pre =
125				linear_inter(tmax, tmin, pcnt2, 0, false);
126		timing->shared_timings.clk_pre_inc_by_2 = false;
127	}
128
129	timing->ta_go = 3;
130	timing->ta_sure = 0;
131	timing->ta_get = 4;
132
133	DBG("PHY timings: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d",
134		timing->shared_timings.clk_pre, timing->shared_timings.clk_post,
135		timing->shared_timings.clk_pre_inc_by_2, timing->clk_zero,
136		timing->clk_trail, timing->clk_prepare, timing->hs_exit,
137		timing->hs_zero, timing->hs_prepare, timing->hs_trail,
138		timing->hs_rqst);
139
140	return 0;
141}
142
143int msm_dsi_dphy_timing_calc_v2(struct msm_dsi_dphy_timing *timing,
144				struct msm_dsi_phy_clk_request *clk_req)
145{
146	const unsigned long bit_rate = clk_req->bitclk_rate;
147	const unsigned long esc_rate = clk_req->escclk_rate;
148	s32 ui, ui_x8, lpx;
149	s32 tmax, tmin;
150	s32 pcnt0 = 50;
151	s32 pcnt1 = 50;
152	s32 pcnt2 = 10;
153	s32 pcnt3 = 30;
154	s32 pcnt4 = 10;
155	s32 pcnt5 = 2;
156	s32 coeff = 1000; /* Precision, should avoid overflow */
157	s32 hb_en, hb_en_ckln, pd_ckln, pd;
158	s32 val, val_ckln;
159	s32 temp;
160
161	if (!bit_rate || !esc_rate)
162		return -EINVAL;
163
164	timing->hs_halfbyte_en = 0;
165	hb_en = 0;
166	timing->hs_halfbyte_en_ckln = 0;
167	hb_en_ckln = 0;
168	timing->hs_prep_dly_ckln = (bit_rate > 100000000) ? 0 : 3;
169	pd_ckln = timing->hs_prep_dly_ckln;
170	timing->hs_prep_dly = (bit_rate > 120000000) ? 0 : 1;
171	pd = timing->hs_prep_dly;
172
173	val = (hb_en << 2) + (pd << 1);
174	val_ckln = (hb_en_ckln << 2) + (pd_ckln << 1);
175
176	ui = mult_frac(NSEC_PER_MSEC, coeff, bit_rate / 1000);
177	ui_x8 = ui << 3;
178	lpx = mult_frac(NSEC_PER_MSEC, coeff, esc_rate / 1000);
179
180	temp = S_DIV_ROUND_UP(38 * coeff - val_ckln * ui, ui_x8);
181	tmin = max_t(s32, temp, 0);
182	temp = (95 * coeff - val_ckln * ui) / ui_x8;
183	tmax = max_t(s32, temp, 0);
184	timing->clk_prepare = linear_inter(tmax, tmin, pcnt0, 0, false);
185
186	temp = 300 * coeff - ((timing->clk_prepare << 3) + val_ckln) * ui;
187	tmin = S_DIV_ROUND_UP(temp - 11 * ui, ui_x8) - 3;
188	tmax = (tmin > 255) ? 511 : 255;
189	timing->clk_zero = linear_inter(tmax, tmin, pcnt5, 0, false);
190
191	tmin = DIV_ROUND_UP(60 * coeff + 3 * ui, ui_x8);
192	temp = 105 * coeff + 12 * ui - 20 * coeff;
193	tmax = (temp + 3 * ui) / ui_x8;
194	timing->clk_trail = linear_inter(tmax, tmin, pcnt3, 0, false);
195
196	temp = S_DIV_ROUND_UP(40 * coeff + 4 * ui - val * ui, ui_x8);
197	tmin = max_t(s32, temp, 0);
198	temp = (85 * coeff + 6 * ui - val * ui) / ui_x8;
199	tmax = max_t(s32, temp, 0);
200	timing->hs_prepare = linear_inter(tmax, tmin, pcnt1, 0, false);
201
202	temp = 145 * coeff + 10 * ui - ((timing->hs_prepare << 3) + val) * ui;
203	tmin = S_DIV_ROUND_UP(temp - 11 * ui, ui_x8) - 3;
204	tmax = 255;
205	timing->hs_zero = linear_inter(tmax, tmin, pcnt4, 0, false);
206
207	tmin = DIV_ROUND_UP(60 * coeff + 4 * ui + 3 * ui, ui_x8);
208	temp = 105 * coeff + 12 * ui - 20 * coeff;
209	tmax = (temp + 3 * ui) / ui_x8;
210	timing->hs_trail = linear_inter(tmax, tmin, pcnt3, 0, false);
211
212	temp = 50 * coeff + ((hb_en << 2) - 8) * ui;
213	timing->hs_rqst = S_DIV_ROUND_UP(temp, ui_x8);
214
215	tmin = DIV_ROUND_UP(100 * coeff, ui_x8) - 1;
216	tmax = 255;
217	timing->hs_exit = linear_inter(tmax, tmin, pcnt2, 0, false);
218
219	temp = 50 * coeff + ((hb_en_ckln << 2) - 8) * ui;
220	timing->hs_rqst_ckln = S_DIV_ROUND_UP(temp, ui_x8);
221
222	temp = 60 * coeff + 52 * ui - 43 * ui;
223	tmin = DIV_ROUND_UP(temp, ui_x8) - 1;
224	tmax = 63;
225	timing->shared_timings.clk_post =
226				linear_inter(tmax, tmin, pcnt2, 0, false);
227
228	temp = 8 * ui + ((timing->clk_prepare << 3) + val_ckln) * ui;
229	temp += (((timing->clk_zero + 3) << 3) + 11 - (pd_ckln << 1)) * ui;
230	temp += hb_en_ckln ? (((timing->hs_rqst_ckln << 3) + 4) * ui) :
231				(((timing->hs_rqst_ckln << 3) + 8) * ui);
232	tmin = S_DIV_ROUND_UP(temp, ui_x8) - 1;
233	tmax = 63;
234	if (tmin > tmax) {
235		temp = linear_inter(tmax << 1, tmin, pcnt2, 0, false);
236		timing->shared_timings.clk_pre = temp >> 1;
237		timing->shared_timings.clk_pre_inc_by_2 = 1;
238	} else {
239		timing->shared_timings.clk_pre =
240				linear_inter(tmax, tmin, pcnt2, 0, false);
241		timing->shared_timings.clk_pre_inc_by_2 = 0;
242	}
243
244	timing->ta_go = 3;
245	timing->ta_sure = 0;
246	timing->ta_get = 4;
247
248	DBG("%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d",
249	    timing->shared_timings.clk_pre, timing->shared_timings.clk_post,
250	    timing->shared_timings.clk_pre_inc_by_2, timing->clk_zero,
251	    timing->clk_trail, timing->clk_prepare, timing->hs_exit,
252	    timing->hs_zero, timing->hs_prepare, timing->hs_trail,
253	    timing->hs_rqst, timing->hs_rqst_ckln, timing->hs_halfbyte_en,
254	    timing->hs_halfbyte_en_ckln, timing->hs_prep_dly,
255	    timing->hs_prep_dly_ckln);
256
257	return 0;
258}
259
260int msm_dsi_dphy_timing_calc_v3(struct msm_dsi_dphy_timing *timing,
261	struct msm_dsi_phy_clk_request *clk_req)
262{
263	const unsigned long bit_rate = clk_req->bitclk_rate;
264	const unsigned long esc_rate = clk_req->escclk_rate;
265	s32 ui, ui_x8, lpx;
266	s32 tmax, tmin;
267	s32 pcnt0 = 50;
268	s32 pcnt1 = 50;
269	s32 pcnt2 = 10;
270	s32 pcnt3 = 30;
271	s32 pcnt4 = 10;
272	s32 pcnt5 = 2;
273	s32 coeff = 1000; /* Precision, should avoid overflow */
274	s32 hb_en, hb_en_ckln;
275	s32 temp;
276
277	if (!bit_rate || !esc_rate)
278		return -EINVAL;
279
280	timing->hs_halfbyte_en = 0;
281	hb_en = 0;
282	timing->hs_halfbyte_en_ckln = 0;
283	hb_en_ckln = 0;
284
285	ui = mult_frac(NSEC_PER_MSEC, coeff, bit_rate / 1000);
286	ui_x8 = ui << 3;
287	lpx = mult_frac(NSEC_PER_MSEC, coeff, esc_rate / 1000);
288
289	temp = S_DIV_ROUND_UP(38 * coeff, ui_x8);
290	tmin = max_t(s32, temp, 0);
291	temp = (95 * coeff) / ui_x8;
292	tmax = max_t(s32, temp, 0);
293	timing->clk_prepare = linear_inter(tmax, tmin, pcnt0, 0, false);
294
295	temp = 300 * coeff - (timing->clk_prepare << 3) * ui;
296	tmin = S_DIV_ROUND_UP(temp, ui_x8) - 1;
297	tmax = (tmin > 255) ? 511 : 255;
298	timing->clk_zero = linear_inter(tmax, tmin, pcnt5, 0, false);
299
300	tmin = DIV_ROUND_UP(60 * coeff + 3 * ui, ui_x8);
301	temp = 105 * coeff + 12 * ui - 20 * coeff;
302	tmax = (temp + 3 * ui) / ui_x8;
303	timing->clk_trail = linear_inter(tmax, tmin, pcnt3, 0, false);
304
305	temp = S_DIV_ROUND_UP(40 * coeff + 4 * ui, ui_x8);
306	tmin = max_t(s32, temp, 0);
307	temp = (85 * coeff + 6 * ui) / ui_x8;
308	tmax = max_t(s32, temp, 0);
309	timing->hs_prepare = linear_inter(tmax, tmin, pcnt1, 0, false);
310
311	temp = 145 * coeff + 10 * ui - (timing->hs_prepare << 3) * ui;
312	tmin = S_DIV_ROUND_UP(temp, ui_x8) - 1;
313	tmax = 255;
314	timing->hs_zero = linear_inter(tmax, tmin, pcnt4, 0, false);
315
316	tmin = DIV_ROUND_UP(60 * coeff + 4 * ui, ui_x8) - 1;
317	temp = 105 * coeff + 12 * ui - 20 * coeff;
318	tmax = (temp / ui_x8) - 1;
319	timing->hs_trail = linear_inter(tmax, tmin, pcnt3, 0, false);
320
321	temp = 50 * coeff + ((hb_en << 2) - 8) * ui;
322	timing->hs_rqst = S_DIV_ROUND_UP(temp, ui_x8);
323
324	tmin = DIV_ROUND_UP(100 * coeff, ui_x8) - 1;
325	tmax = 255;
326	timing->hs_exit = linear_inter(tmax, tmin, pcnt2, 0, false);
327
328	temp = 50 * coeff + ((hb_en_ckln << 2) - 8) * ui;
329	timing->hs_rqst_ckln = S_DIV_ROUND_UP(temp, ui_x8);
330
331	temp = 60 * coeff + 52 * ui - 43 * ui;
332	tmin = DIV_ROUND_UP(temp, ui_x8) - 1;
333	tmax = 63;
334	timing->shared_timings.clk_post =
335		linear_inter(tmax, tmin, pcnt2, 0, false);
336
337	temp = 8 * ui + (timing->clk_prepare << 3) * ui;
338	temp += (((timing->clk_zero + 3) << 3) + 11) * ui;
339	temp += hb_en_ckln ? (((timing->hs_rqst_ckln << 3) + 4) * ui) :
340		(((timing->hs_rqst_ckln << 3) + 8) * ui);
341	tmin = S_DIV_ROUND_UP(temp, ui_x8) - 1;
342	tmax = 63;
343	if (tmin > tmax) {
344		temp = linear_inter(tmax << 1, tmin, pcnt2, 0, false);
345		timing->shared_timings.clk_pre = temp >> 1;
346		timing->shared_timings.clk_pre_inc_by_2 = 1;
347	} else {
348		timing->shared_timings.clk_pre =
349			linear_inter(tmax, tmin, pcnt2, 0, false);
350			timing->shared_timings.clk_pre_inc_by_2 = 0;
351	}
352
353	timing->ta_go = 3;
354	timing->ta_sure = 0;
355	timing->ta_get = 4;
356
357	DBG("%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d",
358		timing->shared_timings.clk_pre, timing->shared_timings.clk_post,
359		timing->shared_timings.clk_pre_inc_by_2, timing->clk_zero,
360		timing->clk_trail, timing->clk_prepare, timing->hs_exit,
361		timing->hs_zero, timing->hs_prepare, timing->hs_trail,
362		timing->hs_rqst, timing->hs_rqst_ckln, timing->hs_halfbyte_en,
363		timing->hs_halfbyte_en_ckln, timing->hs_prep_dly,
364		timing->hs_prep_dly_ckln);
365
366	return 0;
367}
368
369void msm_dsi_phy_set_src_pll(struct msm_dsi_phy *phy, int pll_id, u32 reg,
370				u32 bit_mask)
371{
372	int phy_id = phy->id;
373	u32 val;
374
375	if ((phy_id >= DSI_MAX) || (pll_id >= DSI_MAX))
376		return;
377
378	val = dsi_phy_read(phy->base + reg);
379
380	if (phy->cfg->src_pll_truthtable[phy_id][pll_id])
381		dsi_phy_write(phy->base + reg, val | bit_mask);
382	else
383		dsi_phy_write(phy->base + reg, val & (~bit_mask));
384}
385
386static int dsi_phy_regulator_init(struct msm_dsi_phy *phy)
387{
388	struct regulator_bulk_data *s = phy->supplies;
389	const struct dsi_reg_entry *regs = phy->cfg->reg_cfg.regs;
390	struct device *dev = &phy->pdev->dev;
391	int num = phy->cfg->reg_cfg.num;
392	int i, ret;
393
394	for (i = 0; i < num; i++)
395		s[i].supply = regs[i].name;
396
397	ret = devm_regulator_bulk_get(dev, num, s);
398	if (ret < 0) {
399		if (ret != -EPROBE_DEFER) {
400			DRM_DEV_ERROR(dev,
401				      "%s: failed to init regulator, ret=%d\n",
402				      __func__, ret);
 
 
 
 
 
 
 
 
 
 
 
403		}
404
405		return ret;
406	}
407
408	return 0;
409}
410
411static void dsi_phy_regulator_disable(struct msm_dsi_phy *phy)
412{
413	struct regulator_bulk_data *s = phy->supplies;
414	const struct dsi_reg_entry *regs = phy->cfg->reg_cfg.regs;
415	int num = phy->cfg->reg_cfg.num;
416	int i;
417
418	DBG("");
419	for (i = num - 1; i >= 0; i--)
420		if (regs[i].disable_load >= 0)
421			regulator_set_load(s[i].consumer, regs[i].disable_load);
422
423	regulator_bulk_disable(num, s);
424}
425
426static int dsi_phy_regulator_enable(struct msm_dsi_phy *phy)
427{
428	struct regulator_bulk_data *s = phy->supplies;
429	const struct dsi_reg_entry *regs = phy->cfg->reg_cfg.regs;
430	struct device *dev = &phy->pdev->dev;
431	int num = phy->cfg->reg_cfg.num;
432	int ret, i;
433
434	DBG("");
435	for (i = 0; i < num; i++) {
436		if (regs[i].enable_load >= 0) {
437			ret = regulator_set_load(s[i].consumer,
438							regs[i].enable_load);
439			if (ret < 0) {
440				DRM_DEV_ERROR(dev,
441					"regulator %d set op mode failed, %d\n",
442					i, ret);
443				goto fail;
444			}
445		}
446	}
447
448	ret = regulator_bulk_enable(num, s);
449	if (ret < 0) {
450		DRM_DEV_ERROR(dev, "regulator enable failed, %d\n", ret);
451		goto fail;
452	}
453
454	return 0;
455
456fail:
457	for (i--; i >= 0; i--)
458		regulator_set_load(s[i].consumer, regs[i].disable_load);
459	return ret;
460}
461
462static int dsi_phy_enable_resource(struct msm_dsi_phy *phy)
463{
464	struct device *dev = &phy->pdev->dev;
465	int ret;
466
467	pm_runtime_get_sync(dev);
468
469	ret = clk_prepare_enable(phy->ahb_clk);
470	if (ret) {
471		DRM_DEV_ERROR(dev, "%s: can't enable ahb clk, %d\n", __func__, ret);
472		pm_runtime_put_sync(dev);
473	}
474
475	return ret;
476}
477
478static void dsi_phy_disable_resource(struct msm_dsi_phy *phy)
479{
480	clk_disable_unprepare(phy->ahb_clk);
481	pm_runtime_put_autosuspend(&phy->pdev->dev);
482}
483
484static const struct of_device_id dsi_phy_dt_match[] = {
485#ifdef CONFIG_DRM_MSM_DSI_28NM_PHY
486	{ .compatible = "qcom,dsi-phy-28nm-hpm",
487	  .data = &dsi_phy_28nm_hpm_cfgs },
488	{ .compatible = "qcom,dsi-phy-28nm-lp",
489	  .data = &dsi_phy_28nm_lp_cfgs },
490#endif
491#ifdef CONFIG_DRM_MSM_DSI_20NM_PHY
492	{ .compatible = "qcom,dsi-phy-20nm",
493	  .data = &dsi_phy_20nm_cfgs },
494#endif
495#ifdef CONFIG_DRM_MSM_DSI_28NM_8960_PHY
496	{ .compatible = "qcom,dsi-phy-28nm-8960",
497	  .data = &dsi_phy_28nm_8960_cfgs },
498#endif
499#ifdef CONFIG_DRM_MSM_DSI_14NM_PHY
500	{ .compatible = "qcom,dsi-phy-14nm",
501	  .data = &dsi_phy_14nm_cfgs },
502#endif
503#ifdef CONFIG_DRM_MSM_DSI_10NM_PHY
504	{ .compatible = "qcom,dsi-phy-10nm",
505	  .data = &dsi_phy_10nm_cfgs },
506	{ .compatible = "qcom,dsi-phy-10nm-8998",
507	  .data = &dsi_phy_10nm_8998_cfgs },
508#endif
509	{}
510};
511
512/*
513 * Currently, we only support one SoC for each PHY type. When we have multiple
514 * SoCs for the same PHY, we can try to make the index searching a bit more
515 * clever.
516 */
517static int dsi_phy_get_id(struct msm_dsi_phy *phy)
518{
519	struct platform_device *pdev = phy->pdev;
520	const struct msm_dsi_phy_cfg *cfg = phy->cfg;
521	struct resource *res;
522	int i;
523
524	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dsi_phy");
525	if (!res)
526		return -EINVAL;
527
528	for (i = 0; i < cfg->num_dsi_phy; i++) {
529		if (cfg->io_start[i] == res->start)
530			return i;
531	}
532
533	return -EINVAL;
534}
535
536int msm_dsi_phy_init_common(struct msm_dsi_phy *phy)
537{
538	struct platform_device *pdev = phy->pdev;
539	int ret = 0;
540
541	phy->reg_base = msm_ioremap(pdev, "dsi_phy_regulator",
542				"DSI_PHY_REG");
543	if (IS_ERR(phy->reg_base)) {
544		DRM_DEV_ERROR(&pdev->dev, "%s: failed to map phy regulator base\n",
545			__func__);
546		ret = -ENOMEM;
547		goto fail;
548	}
549
550fail:
551	return ret;
552}
553
554static int dsi_phy_driver_probe(struct platform_device *pdev)
555{
556	struct msm_dsi_phy *phy;
557	struct device *dev = &pdev->dev;
558	const struct of_device_id *match;
559	int ret;
560
561	phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
562	if (!phy)
563		return -ENOMEM;
564
565	match = of_match_node(dsi_phy_dt_match, dev->of_node);
566	if (!match)
567		return -ENODEV;
568
569	phy->cfg = match->data;
570	phy->pdev = pdev;
571
572	phy->id = dsi_phy_get_id(phy);
573	if (phy->id < 0) {
574		ret = phy->id;
575		DRM_DEV_ERROR(dev, "%s: couldn't identify PHY index, %d\n",
576			__func__, ret);
577		goto fail;
578	}
579
580	phy->regulator_ldo_mode = of_property_read_bool(dev->of_node,
581				"qcom,dsi-phy-regulator-ldo-mode");
582
583	phy->base = msm_ioremap(pdev, "dsi_phy", "DSI_PHY");
584	if (IS_ERR(phy->base)) {
585		DRM_DEV_ERROR(dev, "%s: failed to map phy base\n", __func__);
 
 
 
 
 
 
 
 
 
586		ret = -ENOMEM;
587		goto fail;
588	}
589
590	ret = dsi_phy_regulator_init(phy);
591	if (ret)
 
592		goto fail;
 
593
594	phy->ahb_clk = msm_clk_get(pdev, "iface");
595	if (IS_ERR(phy->ahb_clk)) {
596		DRM_DEV_ERROR(dev, "%s: Unable to get ahb clk\n", __func__);
597		ret = PTR_ERR(phy->ahb_clk);
598		goto fail;
599	}
600
601	if (phy->cfg->ops.init) {
602		ret = phy->cfg->ops.init(phy);
603		if (ret)
604			goto fail;
605	}
606
607	/* PLL init will call into clk_register which requires
608	 * register access, so we need to enable power and ahb clock.
609	 */
610	ret = dsi_phy_enable_resource(phy);
611	if (ret)
612		goto fail;
613
614	phy->pll = msm_dsi_pll_init(pdev, phy->cfg->type, phy->id);
615	if (IS_ERR_OR_NULL(phy->pll)) {
616		DRM_DEV_INFO(dev,
617			"%s: pll init failed: %ld, need separate pll clk driver\n",
618			__func__, PTR_ERR(phy->pll));
619		phy->pll = NULL;
620	}
621
622	dsi_phy_disable_resource(phy);
623
624	platform_set_drvdata(pdev, phy);
625
626	return 0;
627
628fail:
629	return ret;
630}
631
632static int dsi_phy_driver_remove(struct platform_device *pdev)
633{
634	struct msm_dsi_phy *phy = platform_get_drvdata(pdev);
635
636	if (phy && phy->pll) {
637		msm_dsi_pll_destroy(phy->pll);
638		phy->pll = NULL;
639	}
640
641	platform_set_drvdata(pdev, NULL);
642
643	return 0;
644}
645
646static struct platform_driver dsi_phy_platform_driver = {
647	.probe      = dsi_phy_driver_probe,
648	.remove     = dsi_phy_driver_remove,
649	.driver     = {
650		.name   = "msm_dsi_phy",
651		.of_match_table = dsi_phy_dt_match,
652	},
653};
654
655void __init msm_dsi_phy_driver_register(void)
656{
657	platform_driver_register(&dsi_phy_platform_driver);
658}
659
660void __exit msm_dsi_phy_driver_unregister(void)
661{
662	platform_driver_unregister(&dsi_phy_platform_driver);
663}
664
665int msm_dsi_phy_enable(struct msm_dsi_phy *phy, int src_pll_id,
666			struct msm_dsi_phy_clk_request *clk_req)
667{
668	struct device *dev = &phy->pdev->dev;
669	int ret;
670
671	if (!phy || !phy->cfg->ops.enable)
672		return -EINVAL;
673
674	ret = dsi_phy_enable_resource(phy);
675	if (ret) {
676		DRM_DEV_ERROR(dev, "%s: resource enable failed, %d\n",
677			__func__, ret);
678		goto res_en_fail;
679	}
680
681	ret = dsi_phy_regulator_enable(phy);
682	if (ret) {
683		DRM_DEV_ERROR(dev, "%s: regulator enable failed, %d\n",
684			__func__, ret);
685		goto reg_en_fail;
686	}
687
688	ret = phy->cfg->ops.enable(phy, src_pll_id, clk_req);
689	if (ret) {
690		DRM_DEV_ERROR(dev, "%s: phy enable failed, %d\n", __func__, ret);
691		goto phy_en_fail;
692	}
693
694	/*
695	 * Resetting DSI PHY silently changes its PLL registers to reset status,
696	 * which will confuse clock driver and result in wrong output rate of
697	 * link clocks. Restore PLL status if its PLL is being used as clock
698	 * source.
699	 */
700	if (phy->usecase != MSM_DSI_PHY_SLAVE) {
701		ret = msm_dsi_pll_restore_state(phy->pll);
702		if (ret) {
703			DRM_DEV_ERROR(dev, "%s: failed to restore pll state, %d\n",
704				__func__, ret);
705			goto pll_restor_fail;
706		}
707	}
708
709	return 0;
710
711pll_restor_fail:
712	if (phy->cfg->ops.disable)
713		phy->cfg->ops.disable(phy);
714phy_en_fail:
715	dsi_phy_regulator_disable(phy);
716reg_en_fail:
717	dsi_phy_disable_resource(phy);
718res_en_fail:
719	return ret;
720}
721
722void msm_dsi_phy_disable(struct msm_dsi_phy *phy)
723{
724	if (!phy || !phy->cfg->ops.disable)
725		return;
726
727	/* Save PLL status if it is a clock source */
728	if (phy->usecase != MSM_DSI_PHY_SLAVE)
729		msm_dsi_pll_save_state(phy->pll);
730
731	phy->cfg->ops.disable(phy);
732
733	dsi_phy_regulator_disable(phy);
734	dsi_phy_disable_resource(phy);
735}
736
737void msm_dsi_phy_get_shared_timings(struct msm_dsi_phy *phy,
738			struct msm_dsi_phy_shared_timings *shared_timings)
739{
740	memcpy(shared_timings, &phy->timing.shared_timings,
741	       sizeof(*shared_timings));
 
 
 
 
 
742}
743
744struct msm_dsi_pll *msm_dsi_phy_get_pll(struct msm_dsi_phy *phy)
745{
746	if (!phy)
747		return NULL;
748
749	return phy->pll;
750}
751
752void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy,
753			     enum msm_dsi_phy_usecase uc)
754{
755	if (phy)
756		phy->usecase = uc;
757}