Lines Matching +full:mode +full:- +full:reg

1 // SPDX-License-Identifier: GPL-2.0
9 // Inspired from tps65086-regulator.c
30 * Performance, Active, Low-power, Hibernate.
33 * Each regulator has a register for each power mode. To access a register
34 * for a specific regulator and mode BASE_* and OFFSET_* need to be added.
41 * a low-power state while the PMIC is in Active mode. They are supposed to be
42 * configured at startup and then simply transition to/from a global low-power
45 * This driver keeps the PMIC in Active mode, Low-power state is set for the
46 * regulators by enabling/disabling operating mode (FPWM or Auto PFM).
48 * The PMIC's Low-power and Hibernate modes are used during standby/suspend.
49 * To enter standby/suspend the PMIC will go to Low-power mode. From there, it
75 * enum mcp16502_reg - MCP16502 regulators's registers
77 * @MCP16502_REG_LPM: low power mode state register
79 * @MCP16502_REG_HPM: high-performance mode register
102 static unsigned int mcp16502_of_map_mode(unsigned int mode) in mcp16502_of_map_mode() argument
104 if (mode == REGULATOR_MODE_NORMAL || mode == REGULATOR_MODE_IDLE) in mcp16502_of_map_mode()
105 return mode; in mcp16502_of_map_mode()
146 * struct mcp16502 - PMIC representation
154 * mcp16502_gpio_set_mode() - set the GPIO corresponding value
158 static void mcp16502_gpio_set_mode(struct mcp16502 *mcp, int mode) in mcp16502_gpio_set_mode() argument
160 switch (mode) { in mcp16502_gpio_set_mode()
162 gpiod_set_value(mcp->lpm, 0); in mcp16502_gpio_set_mode()
166 gpiod_set_value(mcp->lpm, 1); in mcp16502_gpio_set_mode()
169 pr_err("%s: %d invalid\n", __func__, mode); in mcp16502_gpio_set_mode()
174 * mcp16502_get_reg() - get the PMIC's state configuration register for opmode
177 * @opmode: the PMIC's operating mode ACTIVE, Low-power, Hibernate
189 return -EINVAL; in mcp16502_get_state_reg()
194 * mcp16502_get_mode() - return the current operating mode of a regulator
197 * use the Active mode registers.
199 * Note: this is different from the PMIC's operatig mode, it is the
200 * MODE bit from the regulator's register.
205 int ret, reg; in mcp16502_get_mode() local
207 reg = mcp16502_get_state_reg(rdev, MCP16502_OPMODE_ACTIVE); in mcp16502_get_mode()
208 if (reg < 0) in mcp16502_get_mode()
209 return reg; in mcp16502_get_mode()
211 ret = regmap_read(rdev->regmap, reg, &val); in mcp16502_get_mode()
226 * _mcp16502_set_mode() - helper for set_mode and set_suspend_mode
228 * @rdev: the regulator for which we are setting the mode
229 * @mode: the regulator's mode (the one from MODE bit)
230 * @opmode: the PMIC's operating mode: Active/Low-power/Hibernate
232 static int _mcp16502_set_mode(struct regulator_dev *rdev, unsigned int mode, in _mcp16502_set_mode() argument
236 int reg; in _mcp16502_set_mode() local
238 reg = mcp16502_get_state_reg(rdev, op_mode); in _mcp16502_set_mode()
239 if (reg < 0) in _mcp16502_set_mode()
240 return reg; in _mcp16502_set_mode()
242 switch (mode) { in _mcp16502_set_mode()
250 return -EINVAL; in _mcp16502_set_mode()
253 reg = regmap_update_bits(rdev->regmap, reg, MCP16502_MODE, val); in _mcp16502_set_mode()
254 return reg; in _mcp16502_set_mode()
258 * mcp16502_set_mode() - regulator_ops set_mode
260 static int mcp16502_set_mode(struct regulator_dev *rdev, unsigned int mode) in mcp16502_set_mode() argument
262 return _mcp16502_set_mode(rdev, mode, MCP16502_OPMODE_ACTIVE); in mcp16502_set_mode()
266 * mcp16502_get_status() - regulator_ops get_status
273 ret = regmap_read(rdev->regmap, MCP16502_STAT_BASE(rdev_get_id(rdev)), in mcp16502_get_status()
297 ret = regmap_read(rdev->regmap, MCP16502_REG_BASE(id, CFG), &val); in mcp16502_set_voltage_time_sel()
302 uV_delta = abs(new_sel * rdev->desc->linear_ranges->step - in mcp16502_set_voltage_time_sel()
303 old_sel * rdev->desc->linear_ranges->step); in mcp16502_set_voltage_time_sel()
320 return -EINVAL; in mcp16502_set_voltage_time_sel()
328 * mcp16502_suspend_get_target_reg() - get the reg of the target suspend PMIC
329 * mode
340 dev_err(&rdev->dev, "invalid suspend target: %d\n", in mcp16502_suspend_get_target_reg()
344 return -EINVAL; in mcp16502_suspend_get_target_reg()
348 * mcp16502_set_suspend_voltage() - regulator_ops set_suspend_voltage
353 int reg = mcp16502_suspend_get_target_reg(rdev); in mcp16502_set_suspend_voltage() local
358 if (reg < 0) in mcp16502_set_suspend_voltage()
359 return reg; in mcp16502_set_suspend_voltage()
361 return regmap_update_bits(rdev->regmap, reg, MCP16502_VSEL, sel); in mcp16502_set_suspend_voltage()
365 * mcp16502_set_suspend_mode() - regulator_ops set_suspend_mode
368 unsigned int mode) in mcp16502_set_suspend_mode() argument
372 return _mcp16502_set_mode(rdev, mode, MCP16502_OPMODE_LPM); in mcp16502_set_suspend_mode()
375 return _mcp16502_set_mode(rdev, mode, MCP16502_OPMODE_HIB); in mcp16502_set_suspend_mode()
377 dev_err(&rdev->dev, "invalid suspend target: %d\n", in mcp16502_set_suspend_mode()
381 return -EINVAL; in mcp16502_set_suspend_mode()
385 * mcp16502_set_suspend_enable() - regulator_ops set_suspend_enable
389 int reg = mcp16502_suspend_get_target_reg(rdev); in mcp16502_set_suspend_enable() local
391 if (reg < 0) in mcp16502_set_suspend_enable()
392 return reg; in mcp16502_set_suspend_enable()
394 return regmap_update_bits(rdev->regmap, reg, MCP16502_EN, MCP16502_EN); in mcp16502_set_suspend_enable()
398 * mcp16502_set_suspend_disable() - regulator_ops set_suspend_disable
402 int reg = mcp16502_suspend_get_target_reg(rdev); in mcp16502_set_suspend_disable() local
404 if (reg < 0) in mcp16502_set_suspend_disable()
405 return reg; in mcp16502_set_suspend_disable()
407 return regmap_update_bits(rdev->regmap, reg, MCP16502_EN, 0); in mcp16502_set_suspend_disable()
513 dev = &client->dev; in mcp16502_probe()
518 return -ENOMEM; in mcp16502_probe()
531 mcp->lpm = devm_gpiod_get_optional(dev, "lpm", GPIOD_OUT_LOW); in mcp16502_probe()
532 if (IS_ERR(mcp->lpm)) { in mcp16502_probe()
533 dev_err(dev, "failed to get lpm pin: %ld\n", PTR_ERR(mcp->lpm)); in mcp16502_probe()
534 return PTR_ERR(mcp->lpm); in mcp16502_probe()
589 .name = "mcp16502-regulator",