mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2025-04-22 10:17:42 +07:00
regulator: max77686: Add GPIO control
Add enable control over GPIO for regulators supporting this: LDO20, LDO21, LDO22, buck8 and buck9. This is needed for proper (and full) configuration of the Maxim 77686 PMIC without creating redundant 'regulator-fixed' entries. Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
bfa21a0dfe
commit
3307e9025d
@ -26,6 +26,7 @@
|
|||||||
#include <linux/bug.h>
|
#include <linux/bug.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/gpio.h>
|
#include <linux/gpio.h>
|
||||||
|
#include <linux/of_gpio.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/regulator/driver.h>
|
#include <linux/regulator/driver.h>
|
||||||
@ -45,6 +46,11 @@
|
|||||||
#define MAX77686_DVS_MINUV 600000
|
#define MAX77686_DVS_MINUV 600000
|
||||||
#define MAX77686_DVS_UVSTEP 12500
|
#define MAX77686_DVS_UVSTEP 12500
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Value for configuring buck[89] and LDO{20,21,22} as GPIO control.
|
||||||
|
* It is the same as 'off' for other regulators.
|
||||||
|
*/
|
||||||
|
#define MAX77686_GPIO_CONTROL 0x0
|
||||||
/*
|
/*
|
||||||
* Values used for configuring LDOs and bucks.
|
* Values used for configuring LDOs and bucks.
|
||||||
* Forcing low power mode: LDO1, 3-5, 9, 13, 17-26
|
* Forcing low power mode: LDO1, 3-5, 9, 13, 17-26
|
||||||
@ -82,6 +88,8 @@ enum max77686_ramp_rate {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct max77686_data {
|
struct max77686_data {
|
||||||
|
u64 gpio_enabled:MAX77686_REGULATORS;
|
||||||
|
|
||||||
/* Array indexed by regulator id */
|
/* Array indexed by regulator id */
|
||||||
unsigned int opmode[MAX77686_REGULATORS];
|
unsigned int opmode[MAX77686_REGULATORS];
|
||||||
};
|
};
|
||||||
@ -100,6 +108,26 @@ static unsigned int max77686_get_opmode_shift(int id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When regulator is configured for GPIO control then it
|
||||||
|
* replaces "normal" mode. Any change from low power mode to normal
|
||||||
|
* should actually change to GPIO control.
|
||||||
|
* Map normal mode to proper value for such regulators.
|
||||||
|
*/
|
||||||
|
static unsigned int max77686_map_normal_mode(struct max77686_data *max77686,
|
||||||
|
int id)
|
||||||
|
{
|
||||||
|
switch (id) {
|
||||||
|
case MAX77686_BUCK8:
|
||||||
|
case MAX77686_BUCK9:
|
||||||
|
case MAX77686_LDO20 ... MAX77686_LDO22:
|
||||||
|
if (max77686->gpio_enabled & (1 << id))
|
||||||
|
return MAX77686_GPIO_CONTROL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MAX77686_NORMAL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */
|
/* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */
|
||||||
static int max77686_set_suspend_disable(struct regulator_dev *rdev)
|
static int max77686_set_suspend_disable(struct regulator_dev *rdev)
|
||||||
{
|
{
|
||||||
@ -136,7 +164,7 @@ static int max77686_set_suspend_mode(struct regulator_dev *rdev,
|
|||||||
val = MAX77686_LDO_LOWPOWER_PWRREQ;
|
val = MAX77686_LDO_LOWPOWER_PWRREQ;
|
||||||
break;
|
break;
|
||||||
case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
|
case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
|
||||||
val = MAX77686_NORMAL;
|
val = max77686_map_normal_mode(max77686, id);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
|
pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
|
||||||
@ -160,7 +188,7 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
|
|||||||
{
|
{
|
||||||
unsigned int val;
|
unsigned int val;
|
||||||
struct max77686_data *max77686 = rdev_get_drvdata(rdev);
|
struct max77686_data *max77686 = rdev_get_drvdata(rdev);
|
||||||
int ret;
|
int ret, id = rdev_get_id(rdev);
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case REGULATOR_MODE_STANDBY: /* switch off */
|
case REGULATOR_MODE_STANDBY: /* switch off */
|
||||||
@ -170,7 +198,7 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
|
|||||||
val = MAX77686_LDO_LOWPOWER_PWRREQ;
|
val = MAX77686_LDO_LOWPOWER_PWRREQ;
|
||||||
break;
|
break;
|
||||||
case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
|
case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
|
||||||
val = MAX77686_NORMAL;
|
val = max77686_map_normal_mode(max77686, id);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
|
pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
|
||||||
@ -184,7 +212,7 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
max77686->opmode[rdev_get_id(rdev)] = val;
|
max77686->opmode[id] = val;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +225,7 @@ static int max77686_enable(struct regulator_dev *rdev)
|
|||||||
shift = max77686_get_opmode_shift(id);
|
shift = max77686_get_opmode_shift(id);
|
||||||
|
|
||||||
if (max77686->opmode[id] == MAX77686_OFF_PWRREQ)
|
if (max77686->opmode[id] == MAX77686_OFF_PWRREQ)
|
||||||
max77686->opmode[id] = MAX77686_NORMAL;
|
max77686->opmode[id] = max77686_map_normal_mode(max77686, id);
|
||||||
|
|
||||||
return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
|
return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
|
||||||
rdev->desc->enable_mask,
|
rdev->desc->enable_mask,
|
||||||
@ -229,6 +257,36 @@ static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
|
|||||||
MAX77686_RAMP_RATE_MASK, ramp_value << 6);
|
MAX77686_RAMP_RATE_MASK, ramp_value << 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int max77686_of_parse_cb(struct device_node *np,
|
||||||
|
const struct regulator_desc *desc,
|
||||||
|
struct regulator_config *config)
|
||||||
|
{
|
||||||
|
struct max77686_data *max77686 = config->driver_data;
|
||||||
|
|
||||||
|
switch (desc->id) {
|
||||||
|
case MAX77686_BUCK8:
|
||||||
|
case MAX77686_BUCK9:
|
||||||
|
case MAX77686_LDO20 ... MAX77686_LDO22:
|
||||||
|
config->ena_gpio = of_get_named_gpio(np,
|
||||||
|
"maxim,ena-gpios", 0);
|
||||||
|
config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
|
||||||
|
config->ena_gpio_initialized = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gpio_is_valid(config->ena_gpio)) {
|
||||||
|
max77686->gpio_enabled |= (1 << desc->id);
|
||||||
|
|
||||||
|
return regmap_update_bits(config->regmap, desc->enable_reg,
|
||||||
|
desc->enable_mask,
|
||||||
|
MAX77686_GPIO_CONTROL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static struct regulator_ops max77686_ops = {
|
static struct regulator_ops max77686_ops = {
|
||||||
.list_voltage = regulator_list_voltage_linear,
|
.list_voltage = regulator_list_voltage_linear,
|
||||||
.map_voltage = regulator_map_voltage_linear,
|
.map_voltage = regulator_map_voltage_linear,
|
||||||
@ -283,6 +341,7 @@ static struct regulator_ops max77686_buck_dvs_ops = {
|
|||||||
.name = "LDO"#num, \
|
.name = "LDO"#num, \
|
||||||
.of_match = of_match_ptr("LDO"#num), \
|
.of_match = of_match_ptr("LDO"#num), \
|
||||||
.regulators_node = of_match_ptr("voltage-regulators"), \
|
.regulators_node = of_match_ptr("voltage-regulators"), \
|
||||||
|
.of_parse_cb = max77686_of_parse_cb, \
|
||||||
.id = MAX77686_LDO##num, \
|
.id = MAX77686_LDO##num, \
|
||||||
.ops = &max77686_ops, \
|
.ops = &max77686_ops, \
|
||||||
.type = REGULATOR_VOLTAGE, \
|
.type = REGULATOR_VOLTAGE, \
|
||||||
@ -355,6 +414,7 @@ static struct regulator_ops max77686_buck_dvs_ops = {
|
|||||||
.name = "BUCK"#num, \
|
.name = "BUCK"#num, \
|
||||||
.of_match = of_match_ptr("BUCK"#num), \
|
.of_match = of_match_ptr("BUCK"#num), \
|
||||||
.regulators_node = of_match_ptr("voltage-regulators"), \
|
.regulators_node = of_match_ptr("voltage-regulators"), \
|
||||||
|
.of_parse_cb = max77686_of_parse_cb, \
|
||||||
.id = MAX77686_BUCK##num, \
|
.id = MAX77686_BUCK##num, \
|
||||||
.ops = &max77686_ops, \
|
.ops = &max77686_ops, \
|
||||||
.type = REGULATOR_VOLTAGE, \
|
.type = REGULATOR_VOLTAGE, \
|
||||||
|
Loading…
Reference in New Issue
Block a user