Lines Matching +full:no +full:- +full:mmc
1 // SPDX-License-Identifier: GPL-2.0
3 * Helper functions for MMC regulators.
11 #include <linux/mmc/host.h>
19 * mmc_ocrbitnum_to_vdd - Convert a OCR bit number to its voltage
32 return -EINVAL; in mmc_ocrbitnum_to_vdd()
40 tmp = vdd_bit - ilog2(MMC_VDD_165_195); in mmc_ocrbitnum_to_vdd()
53 * mmc_regulator_get_ocrmask - return mask of supported voltages
57 * can be provided to MMC/SD/SDIO devices using the specified voltage
59 * MMC host adapter.
95 * mmc_regulator_set_ocr - set regulator to match host->ios voltage
96 * @mmc: the host to regulate
98 * @vdd_bit: zero for power off, else a bit number (host->ios.vdd)
102 * MMC host drivers may use this to enable or disable a regulator using
106 int mmc_regulator_set_ocr(struct mmc_host *mmc, in mmc_regulator_set_ocr() argument
120 if (result == 0 && !mmc->regulator_enabled) { in mmc_regulator_set_ocr()
123 mmc->regulator_enabled = true; in mmc_regulator_set_ocr()
125 } else if (mmc->regulator_enabled) { in mmc_regulator_set_ocr()
128 mmc->regulator_enabled = false; in mmc_regulator_set_ocr()
132 dev_err(mmc_dev(mmc), in mmc_regulator_set_ocr()
149 return -EINVAL; in mmc_regulator_set_voltage_if_supported()
152 * The voltage is already set, no need to switch. in mmc_regulator_set_voltage_if_supported()
153 * Return 1 to indicate that no switch happened. in mmc_regulator_set_voltage_if_supported()
164 * mmc_regulator_set_vqmmc - Set VQMMC as per the ios
165 * @mmc: the host to regulate
172 * If this is not possible we'll try the full 2.7-3.6V of the spec.
182 int mmc_regulator_set_vqmmc(struct mmc_host *mmc, struct mmc_ios *ios) in mmc_regulator_set_vqmmc() argument
184 struct device *dev = mmc_dev(mmc); in mmc_regulator_set_vqmmc()
187 /* If no vqmmc supply then we can't change the voltage */ in mmc_regulator_set_vqmmc()
188 if (IS_ERR(mmc->supply.vqmmc)) in mmc_regulator_set_vqmmc()
189 return -EINVAL; in mmc_regulator_set_vqmmc()
191 switch (ios->signal_voltage) { in mmc_regulator_set_vqmmc()
193 return mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, in mmc_regulator_set_vqmmc()
196 return mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, in mmc_regulator_set_vqmmc()
199 ret = mmc_ocrbitnum_to_vdd(mmc->ios.vdd, &volt, &max_uV); in mmc_regulator_set_vqmmc()
203 dev_dbg(dev, "%s: found vmmc voltage range of %d-%duV\n", in mmc_regulator_set_vqmmc()
206 min_uV = max(volt - 300000, 2700000); in mmc_regulator_set_vqmmc()
216 ret = mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, in mmc_regulator_set_vqmmc()
221 return mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, in mmc_regulator_set_vqmmc()
224 return -EINVAL; in mmc_regulator_set_vqmmc()
239 * mmc_regulator_get_supply - try to get VMMC and VQMMC regulators for a host
240 * @mmc: the host to regulate
243 * or -EPROBE_DEFER. 0 means no critical error but it does not mean all
248 int mmc_regulator_get_supply(struct mmc_host *mmc) in mmc_regulator_get_supply() argument
250 struct device *dev = mmc_dev(mmc); in mmc_regulator_get_supply()
253 mmc->supply.vmmc = devm_regulator_get_optional(dev, "vmmc"); in mmc_regulator_get_supply()
254 mmc->supply.vqmmc = devm_regulator_get_optional(dev, "vqmmc"); in mmc_regulator_get_supply()
256 if (IS_ERR(mmc->supply.vmmc)) { in mmc_regulator_get_supply()
257 if (PTR_ERR(mmc->supply.vmmc) == -EPROBE_DEFER) in mmc_regulator_get_supply()
258 return dev_err_probe(dev, -EPROBE_DEFER, in mmc_regulator_get_supply()
261 dev_dbg(dev, "No vmmc regulator found\n"); in mmc_regulator_get_supply()
263 ret = mmc_regulator_get_ocrmask(mmc->supply.vmmc); in mmc_regulator_get_supply()
265 mmc->ocr_avail = ret; in mmc_regulator_get_supply()
270 if (IS_ERR(mmc->supply.vqmmc)) { in mmc_regulator_get_supply()
271 if (PTR_ERR(mmc->supply.vqmmc) == -EPROBE_DEFER) in mmc_regulator_get_supply()
272 return dev_err_probe(dev, -EPROBE_DEFER, in mmc_regulator_get_supply()
275 dev_dbg(dev, "No vqmmc regulator found\n"); in mmc_regulator_get_supply()
283 * mmc_regulator_enable_vqmmc - enable VQMMC regulator for a host
284 * @mmc: the host to regulate
290 int mmc_regulator_enable_vqmmc(struct mmc_host *mmc) in mmc_regulator_enable_vqmmc() argument
294 if (!IS_ERR(mmc->supply.vqmmc) && !mmc->vqmmc_enabled) { in mmc_regulator_enable_vqmmc()
295 ret = regulator_enable(mmc->supply.vqmmc); in mmc_regulator_enable_vqmmc()
297 dev_err(mmc_dev(mmc), "enabling vqmmc regulator failed\n"); in mmc_regulator_enable_vqmmc()
299 mmc->vqmmc_enabled = true; in mmc_regulator_enable_vqmmc()
307 * mmc_regulator_disable_vqmmc - disable VQMMC regulator for a host
308 * @mmc: the host to regulate
314 void mmc_regulator_disable_vqmmc(struct mmc_host *mmc) in mmc_regulator_disable_vqmmc() argument
316 if (!IS_ERR(mmc->supply.vqmmc) && mmc->vqmmc_enabled) { in mmc_regulator_disable_vqmmc()
317 regulator_disable(mmc->supply.vqmmc); in mmc_regulator_disable_vqmmc()
318 mmc->vqmmc_enabled = false; in mmc_regulator_disable_vqmmc()