Lines Matching +full:regulator +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0+
3 // Regulator driver for DA9055 PMIC
15 #include <linux/regulator/driver.h>
16 #include <linux/regulator/machine.h>
18 #include <linux/regulator/of_regulator.h>
34 /* DA9055 REGULATOR IDs */
72 struct da9055_mode_reg mode; member
84 struct da9055_regulator *regulator = rdev_get_drvdata(rdev); in da9055_buck_get_mode() local
85 struct da9055_regulator_info *info = regulator->info; in da9055_buck_get_mode()
86 int ret, mode = 0; in da9055_buck_get_mode() local
88 ret = da9055_reg_read(regulator->da9055, info->mode.reg); in da9055_buck_get_mode()
92 switch ((ret & info->mode.mask) >> info->mode.shift) { in da9055_buck_get_mode()
94 mode = REGULATOR_MODE_FAST; in da9055_buck_get_mode()
97 mode = REGULATOR_MODE_NORMAL; in da9055_buck_get_mode()
100 mode = REGULATOR_MODE_STANDBY; in da9055_buck_get_mode()
104 return mode; in da9055_buck_get_mode()
108 unsigned int mode) in da9055_buck_set_mode() argument
110 struct da9055_regulator *regulator = rdev_get_drvdata(rdev); in da9055_buck_set_mode() local
111 struct da9055_regulator_info *info = regulator->info; in da9055_buck_set_mode()
114 switch (mode) { in da9055_buck_set_mode()
116 val = DA9055_BUCK_MODE_SYNC << info->mode.shift; in da9055_buck_set_mode()
119 val = DA9055_BUCK_MODE_AUTO << info->mode.shift; in da9055_buck_set_mode()
122 val = DA9055_BUCK_MODE_SLEEP << info->mode.shift; in da9055_buck_set_mode()
126 return da9055_reg_update(regulator->da9055, info->mode.reg, in da9055_buck_set_mode()
127 info->mode.mask, val); in da9055_buck_set_mode()
132 struct da9055_regulator *regulator = rdev_get_drvdata(rdev); in da9055_ldo_get_mode() local
133 struct da9055_regulator_info *info = regulator->info; in da9055_ldo_get_mode()
136 ret = da9055_reg_read(regulator->da9055, info->volt.reg_b); in da9055_ldo_get_mode()
140 if (ret >> info->volt.sl_shift) in da9055_ldo_get_mode()
146 static int da9055_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode) in da9055_ldo_set_mode() argument
148 struct da9055_regulator *regulator = rdev_get_drvdata(rdev); in da9055_ldo_set_mode() local
149 struct da9055_regulator_info *info = regulator->info; in da9055_ldo_set_mode()
150 struct da9055_volt_reg volt = info->volt; in da9055_ldo_set_mode()
153 switch (mode) { in da9055_ldo_set_mode()
163 return da9055_reg_update(regulator->da9055, volt.reg_b, in da9055_ldo_set_mode()
170 struct da9055_regulator *regulator = rdev_get_drvdata(rdev); in da9055_regulator_get_voltage_sel() local
171 struct da9055_regulator_info *info = regulator->info; in da9055_regulator_get_voltage_sel()
172 struct da9055_volt_reg volt = info->volt; in da9055_regulator_get_voltage_sel()
180 ret = da9055_reg_read(regulator->da9055, info->conf.reg); in da9055_regulator_get_voltage_sel()
184 ret &= info->conf.sel_mask; in da9055_regulator_get_voltage_sel()
188 ret = da9055_reg_read(regulator->da9055, volt.reg_a); in da9055_regulator_get_voltage_sel()
190 ret = da9055_reg_read(regulator->da9055, volt.reg_b); in da9055_regulator_get_voltage_sel()
202 struct da9055_regulator *regulator = rdev_get_drvdata(rdev); in da9055_regulator_set_voltage_sel() local
203 struct da9055_regulator_info *info = regulator->info; in da9055_regulator_set_voltage_sel()
207 * Regulator register set A/B is not selected through GPIO therefore in da9055_regulator_set_voltage_sel()
210 if (regulator->reg_rselect == NO_GPIO) { in da9055_regulator_set_voltage_sel()
212 ret = da9055_reg_update(regulator->da9055, info->conf.reg, in da9055_regulator_set_voltage_sel()
213 info->conf.sel_mask, DA9055_SEL_REG_A); in da9055_regulator_set_voltage_sel()
218 return da9055_reg_update(regulator->da9055, info->volt.reg_a, in da9055_regulator_set_voltage_sel()
219 info->volt.v_mask, selector); in da9055_regulator_set_voltage_sel()
223 * Here regulator register set A/B is selected through GPIO. in da9055_regulator_set_voltage_sel()
227 ret = da9055_reg_read(regulator->da9055, info->conf.reg); in da9055_regulator_set_voltage_sel()
231 ret &= info->conf.sel_mask; in da9055_regulator_set_voltage_sel()
235 return da9055_reg_update(regulator->da9055, info->volt.reg_a, in da9055_regulator_set_voltage_sel()
236 info->volt.v_mask, selector); in da9055_regulator_set_voltage_sel()
238 return da9055_reg_update(regulator->da9055, info->volt.reg_b, in da9055_regulator_set_voltage_sel()
239 info->volt.v_mask, selector); in da9055_regulator_set_voltage_sel()
245 struct da9055_regulator *regulator = rdev_get_drvdata(rdev); in da9055_regulator_set_suspend_voltage() local
246 struct da9055_regulator_info *info = regulator->info; in da9055_regulator_set_suspend_voltage()
250 if (regulator->reg_rselect == NO_GPIO) { in da9055_regulator_set_suspend_voltage()
251 ret = da9055_reg_update(regulator->da9055, info->conf.reg, in da9055_regulator_set_suspend_voltage()
252 info->conf.sel_mask, DA9055_SEL_REG_B); in da9055_regulator_set_suspend_voltage()
261 return da9055_reg_update(regulator->da9055, info->volt.reg_b, in da9055_regulator_set_suspend_voltage()
262 info->volt.v_mask, ret); in da9055_regulator_set_suspend_voltage()
267 struct da9055_regulator *regulator = rdev_get_drvdata(rdev); in da9055_suspend_enable() local
268 struct da9055_regulator_info *info = regulator->info; in da9055_suspend_enable()
271 if (regulator->reg_rselect == NO_GPIO) in da9055_suspend_enable()
272 return da9055_reg_update(regulator->da9055, info->conf.reg, in da9055_suspend_enable()
273 info->conf.sel_mask, DA9055_SEL_REG_B); in da9055_suspend_enable()
280 struct da9055_regulator *regulator = rdev_get_drvdata(rdev); in da9055_suspend_disable() local
281 struct da9055_regulator_info *info = regulator->info; in da9055_suspend_disable()
284 if (regulator->reg_rselect == NO_GPIO) in da9055_suspend_disable()
285 return da9055_reg_update(regulator->da9055, info->conf.reg, in da9055_suspend_disable()
286 info->conf.sel_mask, DA9055_SEL_REG_A); in da9055_suspend_disable()
340 .n_voltages = (max - min) / step + 1 + (voffset), \
357 .v_mask = (1 << (vbits)) - 1,\
370 .n_voltages = (max - min) / step + 1 + (voffset), \
391 .v_mask = (1 << (vbits)) - 1,\
393 .mode = {\
412 * Configures regulator to be controlled either through GPIO 1 or 2.
413 * GPIO can control regulator state and/or select the regulator register
416 static int da9055_gpio_init(struct da9055_regulator *regulator, in da9055_gpio_init() argument
420 struct da9055_regulator_info *info = regulator->info; in da9055_gpio_init()
426 if (pdata->gpio_ren && pdata->gpio_ren[id]) { in da9055_gpio_init()
428 int gpio_mux = pdata->gpio_ren[id]; in da9055_gpio_init()
430 config->ena_gpiod = pdata->ena_gpiods[id]; in da9055_gpio_init()
433 * GPI pin is muxed with regulator to control the in da9055_gpio_init()
434 * regulator state. in da9055_gpio_init()
437 ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN, in da9055_gpio_init()
443 * Let the regulator know that its state is controlled in da9055_gpio_init()
446 ret = da9055_reg_update(regulator->da9055, info->conf.reg, in da9055_gpio_init()
448 pdata->reg_ren[id] in da9055_gpio_init()
454 if (pdata->gpio_rsel && pdata->gpio_rsel[id]) { in da9055_gpio_init()
456 int gpio_mux = pdata->gpio_rsel[id]; in da9055_gpio_init()
458 regulator->reg_rselect = pdata->reg_rsel[id]; in da9055_gpio_init()
461 * GPI pin is muxed with regulator to select the in da9055_gpio_init()
462 * regulator register set A/B for voltage ramping. in da9055_gpio_init()
465 ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN, in da9055_gpio_init()
471 * Let the regulator know that its register set A/B in da9055_gpio_init()
474 ret = da9055_reg_update(regulator->da9055, info->conf.reg, in da9055_gpio_init()
476 pdata->reg_rsel[id] in da9055_gpio_init()
486 struct da9055_regulator *regulator = data; in da9055_ldo5_6_oc_irq() local
488 regulator_notifier_call_chain(regulator->rdev, in da9055_ldo5_6_oc_irq()
501 if (info->reg_desc.id == id) in find_regulator_info()
511 struct da9055_regulator *regulator; in da9055_regulator_probe() local
512 struct da9055 *da9055 = dev_get_drvdata(pdev->dev.parent); in da9055_regulator_probe()
513 struct da9055_pdata *pdata = dev_get_platdata(da9055->dev); in da9055_regulator_probe()
516 regulator = devm_kzalloc(&pdev->dev, sizeof(struct da9055_regulator), in da9055_regulator_probe()
518 if (!regulator) in da9055_regulator_probe()
519 return -ENOMEM; in da9055_regulator_probe()
521 regulator->info = find_regulator_info(pdev->id); in da9055_regulator_probe()
522 if (regulator->info == NULL) { in da9055_regulator_probe()
523 dev_err(&pdev->dev, "invalid regulator ID specified\n"); in da9055_regulator_probe()
524 return -EINVAL; in da9055_regulator_probe()
527 regulator->da9055 = da9055; in da9055_regulator_probe()
528 config.dev = da9055->dev; in da9055_regulator_probe()
529 config.driver_data = regulator; in da9055_regulator_probe()
530 config.regmap = da9055->regmap; in da9055_regulator_probe()
533 config.init_data = pdata->regulators[pdev->id]; in da9055_regulator_probe()
535 ret = da9055_gpio_init(regulator, &config, pdata, pdev->id); in da9055_regulator_probe()
539 regulator->rdev = devm_regulator_register(&pdev->dev, in da9055_regulator_probe()
540 &regulator->info->reg_desc, in da9055_regulator_probe()
542 if (IS_ERR(regulator->rdev)) { in da9055_regulator_probe()
543 dev_err(&pdev->dev, "Failed to register regulator %s\n", in da9055_regulator_probe()
544 regulator->info->reg_desc.name); in da9055_regulator_probe()
545 return PTR_ERR(regulator->rdev); in da9055_regulator_probe()
549 if (pdev->id == DA9055_ID_LDO5 || pdev->id == DA9055_ID_LDO6) { in da9055_regulator_probe()
550 irq = platform_get_irq_byname(pdev, "REGULATOR"); in da9055_regulator_probe()
554 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, in da9055_regulator_probe()
559 pdev->name, regulator); in da9055_regulator_probe()
561 if (ret != -EBUSY) { in da9055_regulator_probe()
562 dev_err(&pdev->dev, in da9055_regulator_probe()
563 "Failed to request Regulator IRQ %d: %d\n", in da9055_regulator_probe()
570 platform_set_drvdata(pdev, regulator); in da9055_regulator_probe()
578 .name = "da9055-regulator",
595 MODULE_DESCRIPTION("Power Regulator driver for Dialog DA9055 PMIC");
597 MODULE_ALIAS("platform:da9055-regulator");