Lines Matching +full:regulator +full:- +full:external
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) ST-Ericsson SA 2010
7 * This file is based on drivers/regulator/ab8500.c
9 * AB8500 external regulators
11 * ab8500-ext supports the following regulators:
12 * - VextSupply3
20 #include <linux/regulator/driver.h>
21 #include <linux/regulator/machine.h>
22 #include <linux/regulator/of_regulator.h>
26 /* AB8500 external regulators */
41 REGULATOR_SUPPLY("vinvsim", "sim-detect.0"),
45 * AB8500 external regulators
51 .name = "ab8500-ext-supply1",
62 .name = "ab8500-ext-supply2",
70 .name = "ab8500-ext-supply3",
83 * struct ab8500_ext_regulator_info - ab8500 regulator information
85 * @desc: regulator description
86 * @cfg: regulator configuration (extension of regulator FW configuration)
89 * @update_mask: mask to enable/disable and set mode of regulator
90 * @update_val: bits holding the regulator current mode
95 * @update_val_hw: bits to set regulator pins in HW control
118 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); in ab8500_ext_regulator_enable()
119 return -EINVAL; in ab8500_ext_regulator_enable()
123 * To satisfy both HW high power request and SW request, the regulator in ab8500_ext_regulator_enable()
126 if (info->cfg && info->cfg->hwreq) in ab8500_ext_regulator_enable()
127 regval = info->update_val_hp; in ab8500_ext_regulator_enable()
129 regval = info->update_val; in ab8500_ext_regulator_enable()
131 ret = abx500_mask_and_set_register_interruptible(info->dev, in ab8500_ext_regulator_enable()
132 info->update_bank, info->update_reg, in ab8500_ext_regulator_enable()
133 info->update_mask, regval); in ab8500_ext_regulator_enable()
136 "couldn't set enable bits for regulator\n"); in ab8500_ext_regulator_enable()
141 "%s-enable (bank, reg, mask, value): 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", in ab8500_ext_regulator_enable()
142 info->desc.name, info->update_bank, info->update_reg, in ab8500_ext_regulator_enable()
143 info->update_mask, regval); in ab8500_ext_regulator_enable()
155 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); in ab8500_ext_regulator_disable()
156 return -EINVAL; in ab8500_ext_regulator_disable()
160 * Set the regulator in HW request mode if configured in ab8500_ext_regulator_disable()
162 if (info->cfg && info->cfg->hwreq) in ab8500_ext_regulator_disable()
163 regval = info->update_val_hw; in ab8500_ext_regulator_disable()
167 ret = abx500_mask_and_set_register_interruptible(info->dev, in ab8500_ext_regulator_disable()
168 info->update_bank, info->update_reg, in ab8500_ext_regulator_disable()
169 info->update_mask, regval); in ab8500_ext_regulator_disable()
172 "couldn't set disable bits for regulator\n"); in ab8500_ext_regulator_disable()
176 dev_dbg(rdev_get_dev(rdev), "%s-disable (bank, reg, mask, value):" in ab8500_ext_regulator_disable()
178 info->desc.name, info->update_bank, info->update_reg, in ab8500_ext_regulator_disable()
179 info->update_mask, regval); in ab8500_ext_regulator_disable()
191 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); in ab8500_ext_regulator_is_enabled()
192 return -EINVAL; in ab8500_ext_regulator_is_enabled()
195 ret = abx500_get_register_interruptible(info->dev, in ab8500_ext_regulator_is_enabled()
196 info->update_bank, info->update_reg, ®val); in ab8500_ext_regulator_is_enabled()
199 "couldn't read 0x%x register\n", info->update_reg); in ab8500_ext_regulator_is_enabled()
203 dev_dbg(rdev_get_dev(rdev), "%s-is_enabled (bank, reg, mask, value):" in ab8500_ext_regulator_is_enabled()
205 info->desc.name, info->update_bank, info->update_reg, in ab8500_ext_regulator_is_enabled()
206 info->update_mask, regval); in ab8500_ext_regulator_is_enabled()
208 if (((regval & info->update_mask) == info->update_val_lp) || in ab8500_ext_regulator_is_enabled()
209 ((regval & info->update_mask) == info->update_val_hp)) in ab8500_ext_regulator_is_enabled()
223 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); in ab8500_ext_regulator_set_mode()
224 return -EINVAL; in ab8500_ext_regulator_set_mode()
229 regval = info->update_val_hp; in ab8500_ext_regulator_set_mode()
232 regval = info->update_val_lp; in ab8500_ext_regulator_set_mode()
236 return -EINVAL; in ab8500_ext_regulator_set_mode()
239 /* If regulator is enabled and info->cfg->hwreq is set, the regulator in ab8500_ext_regulator_set_mode()
244 !(info->cfg && info->cfg->hwreq)) { in ab8500_ext_regulator_set_mode()
245 ret = abx500_mask_and_set_register_interruptible(info->dev, in ab8500_ext_regulator_set_mode()
246 info->update_bank, info->update_reg, in ab8500_ext_regulator_set_mode()
247 info->update_mask, regval); in ab8500_ext_regulator_set_mode()
250 "Could not set regulator mode.\n"); in ab8500_ext_regulator_set_mode()
255 "%s-set_mode (bank, reg, mask, value): " in ab8500_ext_regulator_set_mode()
257 info->desc.name, info->update_bank, info->update_reg, in ab8500_ext_regulator_set_mode()
258 info->update_mask, regval); in ab8500_ext_regulator_set_mode()
261 info->update_val = regval; in ab8500_ext_regulator_set_mode()
272 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); in ab8500_ext_regulator_get_mode()
273 return -EINVAL; in ab8500_ext_regulator_get_mode()
276 if (info->update_val == info->update_val_hp) in ab8500_ext_regulator_get_mode()
278 else if (info->update_val == info->update_val_lp) in ab8500_ext_regulator_get_mode()
281 ret = -EINVAL; in ab8500_ext_regulator_get_mode()
289 struct regulation_constraints *regu_constraints = rdev->constraints; in ab8500_ext_set_voltage()
292 dev_err(rdev_get_dev(rdev), "No regulator constraints\n"); in ab8500_ext_set_voltage()
293 return -EINVAL; in ab8500_ext_set_voltage()
296 if (regu_constraints->min_uV == min_uV && in ab8500_ext_set_voltage()
297 regu_constraints->max_uV == max_uV) in ab8500_ext_set_voltage()
303 regu_constraints->min_uV, regu_constraints->max_uV); in ab8500_ext_set_voltage()
305 return -EINVAL; in ab8500_ext_set_voltage()
311 struct regulation_constraints *regu_constraints = rdev->constraints; in ab8500_ext_list_voltage()
314 dev_err(rdev_get_dev(rdev), "regulator constraints null pointer\n"); in ab8500_ext_list_voltage()
315 return -EINVAL; in ab8500_ext_list_voltage()
318 if (regu_constraints->min_uV && regu_constraints->max_uV) { in ab8500_ext_list_voltage()
319 if (regu_constraints->min_uV == regu_constraints->max_uV) in ab8500_ext_list_voltage()
320 return regu_constraints->min_uV; in ab8500_ext_list_voltage()
322 return -EINVAL; in ab8500_ext_list_voltage()
395 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); in ab8500_ext_regulator_probe()
401 dev_err(&pdev->dev, "null mfd parent\n"); in ab8500_ext_regulator_probe()
402 return -EINVAL; in ab8500_ext_regulator_probe()
411 info->update_val = 0x30; in ab8500_ext_regulator_probe()
412 info->update_val_hp = 0x30; in ab8500_ext_regulator_probe()
413 info->update_val_lp = 0x10; in ab8500_ext_regulator_probe()
420 /* assign per-regulator data */ in ab8500_ext_regulator_probe()
422 info->dev = &pdev->dev; in ab8500_ext_regulator_probe()
423 info->cfg = (struct ab8500_ext_regulator_cfg *) in ab8500_ext_regulator_probe()
426 config.dev = &pdev->dev; in ab8500_ext_regulator_probe()
430 /* register regulator with framework */ in ab8500_ext_regulator_probe()
431 rdev = devm_regulator_register(&pdev->dev, &info->desc, in ab8500_ext_regulator_probe()
434 dev_err(&pdev->dev, "failed to register regulator %s\n", in ab8500_ext_regulator_probe()
435 info->desc.name); in ab8500_ext_regulator_probe()
439 dev_dbg(&pdev->dev, "%s-probed\n", info->desc.name); in ab8500_ext_regulator_probe()
448 .name = "ab8500-ext-regulator",
459 pr_err("Failed to register ab8500 ext regulator: %d\n", ret); in ab8500_ext_regulator_init()
473 MODULE_DESCRIPTION("AB8500 external regulator driver");
474 MODULE_ALIAS("platform:ab8500-ext-regulator");