#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
#define TPS65132_REG_VPOS 0x00
#define TPS65132_REG_VNEG 0x01
#define TPS65132_REG_APPS_DISP_DISN 0x03
#define TPS65132_REG_CONTROL 0x0FF
#define TPS65132_VOUT_MASK 0x1F
#define TPS65132_VOUT_N_VOLTAGE 0x15
#define TPS65132_VOUT_VMIN 4000000
#define TPS65132_VOUT_VMAX 6000000
#define TPS65132_VOUT_STEP 100000
#define TPS65132_REG_APPS_DIS_VPOS BIT(0)
#define TPS65132_REG_APPS_DIS_VNEG BIT(1)
#define TPS65132_REGULATOR_ID_VPOS 0
#define TPS65132_REGULATOR_ID_VNEG 1
#define TPS65132_MAX_REGULATORS 2
#define TPS65132_ACT_DIS_TIME_SLACK 1000
struct tps65132_reg_pdata {
struct gpio_desc *en_gpiod;
struct gpio_desc *act_dis_gpiod;
unsigned int act_dis_time_us;
struct tps65132_regulator {
struct regulator_desc *rdesc[TPS65132_MAX_REGULATORS];
struct tps65132_reg_pdata reg_pdata[TPS65132_MAX_REGULATORS];
struct regulator_dev *rdev[TPS65132_MAX_REGULATORS];
static int tps65132_regulator_enable(struct regulator_dev *rdev)
struct tps65132_regulator *tps = rdev_get_drvdata(rdev);
int id = rdev_get_id(rdev);
struct tps65132_reg_pdata *rpdata = &tps->reg_pdata[id];
if (!IS_ERR(rpdata->en_gpiod)) {
gpiod_set_value_cansleep(rpdata->en_gpiod, 1);
rpdata->ena_gpio_state = 1;
if (rdev->constraints->active_discharge ==
REGULATOR_ACTIVE_DISCHARGE_DISABLE) {
ret = regulator_set_active_discharge_regmap(rdev, false);
dev_err(tps->dev, "Failed to disable active discharge: %d\n",
static int tps65132_regulator_disable(struct regulator_dev *rdev)
struct tps65132_regulator *tps = rdev_get_drvdata(rdev);