2 * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
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.
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.
16 static int dsi_pll_enable(struct msm_dsi_pll
*pll
)
21 * Certain PLLs do not allow VCO rate update when it is on.
22 * Keep track of their status to turn on/off after set rate success.
24 if (unlikely(pll
->pll_on
))
27 /* Try all enable sequences until one succeeds */
28 for (i
= 0; i
< pll
->en_seq_cnt
; i
++) {
29 ret
= pll
->enable_seqs
[i
](pll
);
30 DBG("DSI PLL %s after sequence #%d",
31 ret
? "unlocked" : "locked", i
+ 1);
37 DRM_ERROR("DSI PLL failed to lock\n");
46 static void dsi_pll_disable(struct msm_dsi_pll
*pll
)
48 if (unlikely(!pll
->pll_on
))
51 pll
->disable_seq(pll
);
57 * DSI PLL Helper functions
59 long msm_dsi_pll_helper_clk_round_rate(struct clk_hw
*hw
,
60 unsigned long rate
, unsigned long *parent_rate
)
62 struct msm_dsi_pll
*pll
= hw_clk_to_pll(hw
);
64 if (rate
< pll
->min_rate
)
66 else if (rate
> pll
->max_rate
)
72 int msm_dsi_pll_helper_clk_prepare(struct clk_hw
*hw
)
74 struct msm_dsi_pll
*pll
= hw_clk_to_pll(hw
);
78 * Certain PLLs need to update the same VCO rate and registers
79 * after resume in suspend/resume scenario.
81 if (pll
->restore_state
) {
82 ret
= pll
->restore_state(pll
);
87 ret
= dsi_pll_enable(pll
);
93 void msm_dsi_pll_helper_clk_unprepare(struct clk_hw
*hw
)
95 struct msm_dsi_pll
*pll
= hw_clk_to_pll(hw
);
100 dsi_pll_disable(pll
);
103 void msm_dsi_pll_helper_unregister_clks(struct platform_device
*pdev
,
104 struct clk
**clks
, u32 num_clks
)
106 of_clk_del_provider(pdev
->dev
.of_node
);
108 if (!num_clks
|| !clks
)
112 clk_unregister(clks
[--num_clks
]);
113 clks
[num_clks
] = NULL
;
120 int msm_dsi_pll_get_clk_provider(struct msm_dsi_pll
*pll
,
121 struct clk
**byte_clk_provider
, struct clk
**pixel_clk_provider
)
123 if (pll
->get_provider
)
124 return pll
->get_provider(pll
,
131 void msm_dsi_pll_destroy(struct msm_dsi_pll
*pll
)
137 struct msm_dsi_pll
*msm_dsi_pll_init(struct platform_device
*pdev
,
138 enum msm_dsi_phy_type type
, int id
)
140 struct device
*dev
= &pdev
->dev
;
141 struct msm_dsi_pll
*pll
;
144 case MSM_DSI_PHY_28NM_HPM
:
145 case MSM_DSI_PHY_28NM_LP
:
146 pll
= msm_dsi_pll_28nm_init(pdev
, type
, id
);
149 pll
= ERR_PTR(-ENXIO
);
154 dev_err(dev
, "%s: failed to init DSI PLL\n", __func__
);
160 DBG("DSI:%d PLL registered", id
);