Lines Matching +full:power +full:- +full:mode +full:- +full:hysteretic
1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
16 #include <dt-bindings/mfd/qcom-rpm.h>
32 struct request_member fm; /* force mode */
33 struct request_member pm; /* power mode */
45 (((reg)->parts->fm.mask >> (reg)->parts->fm.shift) == 3)
193 if (WARN_ON((value << req->shift) & ~req->mask)) in rpm_reg_write()
194 return -EINVAL; in rpm_reg_write()
196 vreg->val[req->word] &= ~req->mask; in rpm_reg_write()
197 vreg->val[req->word] |= value << req->shift; in rpm_reg_write()
199 return qcom_rpm_write(vreg->rpm, in rpm_reg_write()
201 vreg->resource, in rpm_reg_write()
202 vreg->val, in rpm_reg_write()
203 vreg->parts->request_len); in rpm_reg_write()
210 const struct rpm_reg_parts *parts = vreg->parts; in rpm_reg_set_mV_sel()
211 const struct request_member *req = &parts->mV; in rpm_reg_set_mV_sel()
215 if (req->mask == 0) in rpm_reg_set_mV_sel()
216 return -EINVAL; in rpm_reg_set_mV_sel()
222 mutex_lock(&vreg->lock); in rpm_reg_set_mV_sel()
223 if (vreg->is_enabled) in rpm_reg_set_mV_sel()
227 vreg->uV = uV; in rpm_reg_set_mV_sel()
228 mutex_unlock(&vreg->lock); in rpm_reg_set_mV_sel()
237 const struct rpm_reg_parts *parts = vreg->parts; in rpm_reg_set_uV_sel()
238 const struct request_member *req = &parts->uV; in rpm_reg_set_uV_sel()
242 if (req->mask == 0) in rpm_reg_set_uV_sel()
243 return -EINVAL; in rpm_reg_set_uV_sel()
249 mutex_lock(&vreg->lock); in rpm_reg_set_uV_sel()
250 if (vreg->is_enabled) in rpm_reg_set_uV_sel()
254 vreg->uV = uV; in rpm_reg_set_uV_sel()
255 mutex_unlock(&vreg->lock); in rpm_reg_set_uV_sel()
264 return vreg->uV; in rpm_reg_get_voltage()
270 const struct rpm_reg_parts *parts = vreg->parts; in rpm_reg_mV_enable()
271 const struct request_member *req = &parts->mV; in rpm_reg_mV_enable()
274 if (req->mask == 0) in rpm_reg_mV_enable()
275 return -EINVAL; in rpm_reg_mV_enable()
277 mutex_lock(&vreg->lock); in rpm_reg_mV_enable()
278 ret = rpm_reg_write(vreg, req, vreg->uV / 1000); in rpm_reg_mV_enable()
280 vreg->is_enabled = 1; in rpm_reg_mV_enable()
281 mutex_unlock(&vreg->lock); in rpm_reg_mV_enable()
289 const struct rpm_reg_parts *parts = vreg->parts; in rpm_reg_uV_enable()
290 const struct request_member *req = &parts->uV; in rpm_reg_uV_enable()
293 if (req->mask == 0) in rpm_reg_uV_enable()
294 return -EINVAL; in rpm_reg_uV_enable()
296 mutex_lock(&vreg->lock); in rpm_reg_uV_enable()
297 ret = rpm_reg_write(vreg, req, vreg->uV); in rpm_reg_uV_enable()
299 vreg->is_enabled = 1; in rpm_reg_uV_enable()
300 mutex_unlock(&vreg->lock); in rpm_reg_uV_enable()
308 const struct rpm_reg_parts *parts = vreg->parts; in rpm_reg_switch_enable()
309 const struct request_member *req = &parts->enable_state; in rpm_reg_switch_enable()
312 if (req->mask == 0) in rpm_reg_switch_enable()
313 return -EINVAL; in rpm_reg_switch_enable()
315 mutex_lock(&vreg->lock); in rpm_reg_switch_enable()
318 vreg->is_enabled = 1; in rpm_reg_switch_enable()
319 mutex_unlock(&vreg->lock); in rpm_reg_switch_enable()
327 const struct rpm_reg_parts *parts = vreg->parts; in rpm_reg_mV_disable()
328 const struct request_member *req = &parts->mV; in rpm_reg_mV_disable()
331 if (req->mask == 0) in rpm_reg_mV_disable()
332 return -EINVAL; in rpm_reg_mV_disable()
334 mutex_lock(&vreg->lock); in rpm_reg_mV_disable()
337 vreg->is_enabled = 0; in rpm_reg_mV_disable()
338 mutex_unlock(&vreg->lock); in rpm_reg_mV_disable()
346 const struct rpm_reg_parts *parts = vreg->parts; in rpm_reg_uV_disable()
347 const struct request_member *req = &parts->uV; in rpm_reg_uV_disable()
350 if (req->mask == 0) in rpm_reg_uV_disable()
351 return -EINVAL; in rpm_reg_uV_disable()
353 mutex_lock(&vreg->lock); in rpm_reg_uV_disable()
356 vreg->is_enabled = 0; in rpm_reg_uV_disable()
357 mutex_unlock(&vreg->lock); in rpm_reg_uV_disable()
365 const struct rpm_reg_parts *parts = vreg->parts; in rpm_reg_switch_disable()
366 const struct request_member *req = &parts->enable_state; in rpm_reg_switch_disable()
369 if (req->mask == 0) in rpm_reg_switch_disable()
370 return -EINVAL; in rpm_reg_switch_disable()
372 mutex_lock(&vreg->lock); in rpm_reg_switch_disable()
375 vreg->is_enabled = 0; in rpm_reg_switch_disable()
376 mutex_unlock(&vreg->lock); in rpm_reg_switch_disable()
385 return vreg->is_enabled; in rpm_reg_is_enabled()
391 const struct rpm_reg_parts *parts = vreg->parts; in rpm_reg_set_load()
392 const struct request_member *req = &parts->ia; in rpm_reg_set_load()
394 int max_mA = req->mask >> req->shift; in rpm_reg_set_load()
397 if (req->mask == 0) in rpm_reg_set_load()
398 return -EINVAL; in rpm_reg_set_load()
403 mutex_lock(&vreg->lock); in rpm_reg_set_load()
405 mutex_unlock(&vreg->lock); in rpm_reg_set_load()
634 if (req->mask == 0 || (value << req->shift) & ~req->mask) in rpm_reg_set()
635 return -EINVAL; in rpm_reg_set()
637 vreg->val[req->word] &= ~req->mask; in rpm_reg_set()
638 vreg->val[req->word] |= value << req->shift; in rpm_reg_set()
658 key = "qcom,switch-mode-frequency"; in rpm_reg_of_parse_freq()
662 return -EINVAL; in rpm_reg_of_parse_freq()
667 rpm_reg_set(vreg, &vreg->parts->freq, i + 1); in rpm_reg_of_parse_freq()
673 return -EINVAL; in rpm_reg_of_parse_freq()
680 struct qcom_rpm_reg *vreg = config->driver_data; in rpm_reg_of_parse()
681 struct device *dev = config->dev; in rpm_reg_of_parse()
688 key = "bias-pull-down"; in rpm_reg_of_parse()
690 ret = rpm_reg_set(vreg, &vreg->parts->pd, 1); in rpm_reg_of_parse()
697 if (vreg->parts->freq.mask) { in rpm_reg_of_parse()
703 if (vreg->parts->pm.mask) { in rpm_reg_of_parse()
704 key = "qcom,power-mode-hysteretic"; in rpm_reg_of_parse()
707 ret = rpm_reg_set(vreg, &vreg->parts->pm, pwm); in rpm_reg_of_parse()
709 dev_err(dev, "failed to set power mode\n"); in rpm_reg_of_parse()
714 if (vreg->parts->fm.mask) { in rpm_reg_of_parse()
715 force_mode = -1; in rpm_reg_of_parse()
717 key = "qcom,force-mode"; in rpm_reg_of_parse()
719 if (ret == -EINVAL) { in rpm_reg_of_parse()
727 * If force-mode is encoded as 2 bits then the in rpm_reg_of_parse()
747 if (vreg->supports_force_mode_auto) in rpm_reg_of_parse()
751 if (vreg->supports_force_mode_bypass) in rpm_reg_of_parse()
756 if (force_mode == -1) { in rpm_reg_of_parse()
757 dev_err(dev, "invalid force mode\n"); in rpm_reg_of_parse()
758 return -EINVAL; in rpm_reg_of_parse()
761 ret = rpm_reg_set(vreg, &vreg->parts->fm, force_mode); in rpm_reg_of_parse()
763 dev_err(dev, "failed to set force mode\n"); in rpm_reg_of_parse()
912 { "usb-switch", QCOM_RPM_USB_OTG_SWITCH, &pm8921_switch, "vin_5vs" },
913 { "hdmi-switch", QCOM_RPM_HDMI_SWITCH, &pm8921_switch, "vin_5vs" },
927 { .compatible = "qcom,rpm-pm8018-regulators",
929 { .compatible = "qcom,rpm-pm8058-regulators", .data = &rpm_pm8058_regulators },
930 { .compatible = "qcom,rpm-pm8901-regulators", .data = &rpm_pm8901_regulators },
931 { .compatible = "qcom,rpm-pm8921-regulators", .data = &rpm_pm8921_regulators },
932 { .compatible = "qcom,rpm-smb208-regulators", .data = &rpm_smb208_regulators },
945 rpm = dev_get_drvdata(pdev->dev.parent); in rpm_reg_probe()
947 dev_err(&pdev->dev, "unable to retrieve handle to rpm\n"); in rpm_reg_probe()
948 return -ENODEV; in rpm_reg_probe()
951 reg = device_get_match_data(&pdev->dev); in rpm_reg_probe()
953 dev_err(&pdev->dev, "failed to match device\n"); in rpm_reg_probe()
954 return -ENODEV; in rpm_reg_probe()
957 for (; reg->name; reg++) { in rpm_reg_probe()
958 vreg = devm_kmemdup(&pdev->dev, reg->template, sizeof(*vreg), GFP_KERNEL); in rpm_reg_probe()
960 return -ENOMEM; in rpm_reg_probe()
962 mutex_init(&vreg->lock); in rpm_reg_probe()
964 vreg->dev = &pdev->dev; in rpm_reg_probe()
965 vreg->resource = reg->resource; in rpm_reg_probe()
966 vreg->rpm = rpm; in rpm_reg_probe()
968 vreg->desc.id = -1; in rpm_reg_probe()
969 vreg->desc.owner = THIS_MODULE; in rpm_reg_probe()
970 vreg->desc.type = REGULATOR_VOLTAGE; in rpm_reg_probe()
971 vreg->desc.name = reg->name; in rpm_reg_probe()
972 vreg->desc.supply_name = reg->supply; in rpm_reg_probe()
973 vreg->desc.of_match = reg->name; in rpm_reg_probe()
974 vreg->desc.of_parse_cb = rpm_reg_of_parse; in rpm_reg_probe()
976 config.dev = &pdev->dev; in rpm_reg_probe()
978 rdev = devm_regulator_register(&pdev->dev, &vreg->desc, &config); in rpm_reg_probe()
980 dev_err(&pdev->dev, "failed to register %s\n", reg->name); in rpm_reg_probe()