Lines Matching full:drv

39 static int mtk_ccifreq_set_voltage(struct mtk_ccifreq_drv *drv, int new_voltage)  in mtk_ccifreq_set_voltage()  argument
41 const struct mtk_ccifreq_platform_data *soc_data = drv->soc_data; in mtk_ccifreq_set_voltage()
42 struct device *dev = drv->dev; in mtk_ccifreq_set_voltage()
44 int retry_max = drv->vtrack_max; in mtk_ccifreq_set_voltage()
46 if (!drv->sram_reg) { in mtk_ccifreq_set_voltage()
47 ret = regulator_set_voltage(drv->proc_reg, new_voltage, in mtk_ccifreq_set_voltage()
48 drv->soc_data->proc_max_volt); in mtk_ccifreq_set_voltage()
52 pre_voltage = regulator_get_voltage(drv->proc_reg); in mtk_ccifreq_set_voltage()
58 pre_vsram = regulator_get_voltage(drv->sram_reg); in mtk_ccifreq_set_voltage()
71 ret = regulator_set_voltage(drv->sram_reg, vsram, in mtk_ccifreq_set_voltage()
82 ret = regulator_set_voltage(drv->proc_reg, voltage, in mtk_ccifreq_set_voltage()
85 regulator_set_voltage(drv->sram_reg, pre_vsram, in mtk_ccifreq_set_voltage()
92 ret = regulator_set_voltage(drv->proc_reg, voltage, in mtk_ccifreq_set_voltage()
103 ret = regulator_set_voltage(drv->sram_reg, vsram, in mtk_ccifreq_set_voltage()
106 regulator_set_voltage(drv->proc_reg, pre_voltage, in mtk_ccifreq_set_voltage()
128 struct mtk_ccifreq_drv *drv = dev_get_drvdata(dev); in mtk_ccifreq_target() local
134 if (!drv) in mtk_ccifreq_target()
137 if (drv->pre_freq == *freq) in mtk_ccifreq_target()
140 mutex_lock(&drv->reg_lock); in mtk_ccifreq_target()
142 inter_voltage = drv->inter_voltage; in mtk_ccifreq_target()
143 cci_pll = clk_get_parent(drv->cci_clk); in mtk_ccifreq_target()
156 pre_voltage = regulator_get_voltage(drv->proc_reg); in mtk_ccifreq_target()
166 ret = mtk_ccifreq_set_voltage(drv, target_voltage); in mtk_ccifreq_target()
174 ret = clk_set_parent(drv->cci_clk, drv->inter_clk); in mtk_ccifreq_target()
184 clk_set_parent(drv->cci_clk, cci_pll); in mtk_ccifreq_target()
189 ret = clk_set_parent(drv->cci_clk, cci_pll); in mtk_ccifreq_target()
192 mtk_ccifreq_set_voltage(drv, inter_voltage); in mtk_ccifreq_target()
201 ret = mtk_ccifreq_set_voltage(drv, voltage); in mtk_ccifreq_target()
208 drv->pre_freq = *freq; in mtk_ccifreq_target()
209 mutex_unlock(&drv->reg_lock); in mtk_ccifreq_target()
214 mtk_ccifreq_set_voltage(drv, pre_voltage); in mtk_ccifreq_target()
217 mutex_unlock(&drv->reg_lock); in mtk_ccifreq_target()
225 struct mtk_ccifreq_drv *drv; in mtk_ccifreq_opp_notifier() local
228 drv = container_of(nb, struct mtk_ccifreq_drv, opp_nb); in mtk_ccifreq_opp_notifier()
231 mutex_lock(&drv->reg_lock); in mtk_ccifreq_opp_notifier()
235 if (freq == drv->pre_freq) { in mtk_ccifreq_opp_notifier()
237 mtk_ccifreq_set_voltage(drv, volt); in mtk_ccifreq_opp_notifier()
239 mutex_unlock(&drv->reg_lock); in mtk_ccifreq_opp_notifier()
252 struct mtk_ccifreq_drv *drv; in mtk_ccifreq_probe() local
258 drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); in mtk_ccifreq_probe()
259 if (!drv) in mtk_ccifreq_probe()
262 drv->dev = dev; in mtk_ccifreq_probe()
263 drv->soc_data = (const struct mtk_ccifreq_platform_data *) in mtk_ccifreq_probe()
265 mutex_init(&drv->reg_lock); in mtk_ccifreq_probe()
266 platform_set_drvdata(pdev, drv); in mtk_ccifreq_probe()
268 drv->cci_clk = devm_clk_get(dev, "cci"); in mtk_ccifreq_probe()
269 if (IS_ERR(drv->cci_clk)) { in mtk_ccifreq_probe()
270 ret = PTR_ERR(drv->cci_clk); in mtk_ccifreq_probe()
274 drv->inter_clk = devm_clk_get(dev, "intermediate"); in mtk_ccifreq_probe()
275 if (IS_ERR(drv->inter_clk)) { in mtk_ccifreq_probe()
276 ret = PTR_ERR(drv->inter_clk); in mtk_ccifreq_probe()
281 drv->proc_reg = devm_regulator_get_optional(dev, "proc"); in mtk_ccifreq_probe()
282 if (IS_ERR(drv->proc_reg)) { in mtk_ccifreq_probe()
283 ret = PTR_ERR(drv->proc_reg); in mtk_ccifreq_probe()
288 ret = regulator_enable(drv->proc_reg); in mtk_ccifreq_probe()
294 drv->sram_reg = devm_regulator_get_optional(dev, "sram"); in mtk_ccifreq_probe()
295 if (IS_ERR(drv->sram_reg)) { in mtk_ccifreq_probe()
296 ret = PTR_ERR(drv->sram_reg); in mtk_ccifreq_probe()
300 drv->sram_reg = NULL; in mtk_ccifreq_probe()
302 ret = regulator_enable(drv->sram_reg); in mtk_ccifreq_probe()
314 drv->vtrack_max = 3 * DIV_ROUND_UP(max(drv->soc_data->sram_max_volt, in mtk_ccifreq_probe()
315 drv->soc_data->proc_max_volt), in mtk_ccifreq_probe()
316 drv->soc_data->min_volt_shift); in mtk_ccifreq_probe()
318 ret = clk_prepare_enable(drv->cci_clk); in mtk_ccifreq_probe()
328 rate = clk_get_rate(drv->inter_clk); in mtk_ccifreq_probe()
335 drv->inter_voltage = dev_pm_opp_get_voltage(opp); in mtk_ccifreq_probe()
339 opp = dev_pm_opp_find_freq_floor(drv->dev, &rate); in mtk_ccifreq_probe()
348 ret = mtk_ccifreq_set_voltage(drv, opp_volt); in mtk_ccifreq_probe()
362 drv->devfreq = devm_devfreq_add_device(dev, &mtk_ccifreq_profile, in mtk_ccifreq_probe()
365 if (IS_ERR(drv->devfreq)) { in mtk_ccifreq_probe()
368 PTR_ERR(drv->devfreq)); in mtk_ccifreq_probe()
372 drv->opp_nb.notifier_call = mtk_ccifreq_opp_notifier; in mtk_ccifreq_probe()
373 ret = dev_pm_opp_register_notifier(dev, &drv->opp_nb); in mtk_ccifreq_probe()
384 clk_disable_unprepare(drv->cci_clk); in mtk_ccifreq_probe()
387 if (regulator_is_enabled(drv->proc_reg)) in mtk_ccifreq_probe()
388 regulator_disable(drv->proc_reg); in mtk_ccifreq_probe()
389 if (drv->sram_reg && regulator_is_enabled(drv->sram_reg)) in mtk_ccifreq_probe()
390 regulator_disable(drv->sram_reg); in mtk_ccifreq_probe()
398 struct mtk_ccifreq_drv *drv; in mtk_ccifreq_remove() local
400 drv = platform_get_drvdata(pdev); in mtk_ccifreq_remove()
402 dev_pm_opp_unregister_notifier(dev, &drv->opp_nb); in mtk_ccifreq_remove()
404 clk_disable_unprepare(drv->cci_clk); in mtk_ccifreq_remove()
405 regulator_disable(drv->proc_reg); in mtk_ccifreq_remove()
406 if (drv->sram_reg) in mtk_ccifreq_remove()
407 regulator_disable(drv->sram_reg); in mtk_ccifreq_remove()