// SPDX-License-Identifier: GPL-2.0+
//
// max8997.c - Regulator driver for the Maxim 8997/8966
//
// Copyright (C) 2011 Samsung Electronics
// MyungJoo Ham <myungjoo.ham@samsung.com>
//
// This driver is based on max8998.c
#include <linux/bug.h>
#include <linux/err.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
#include <linux/mfd/max8997.h>
#include <linux/mfd/max8997-private.h>
#include <linux/regulator/of_regulator.h>
struct max8997_data {
struct device *dev;
struct max8997_dev *iodev;
int num_regulators;
int ramp_delay; /* in mV/us */
bool buck1_gpiodvs;
bool buck2_gpiodvs;
bool buck5_gpiodvs;
u8 buck1_vol[8];
u8 buck2_vol[8];
u8 buck5_vol[8];
int buck125_gpios[3];
int buck125_gpioindex;
bool ignore_gpiodvs_side_effect;
u8 saved_states[MAX8997_REG_MAX];
};
static const unsigned int safeoutvolt[] = {
4850000,
4900000,
4950000,
3300000,
};
static inline void max8997_set_gpio(struct max8997_data *max8997)
{
int set3 = (max8997->buck125_gpioindex) & 0x1;
int set2 = ((max8997->buck125_gpioindex) >> 1) & 0x1;
int set1 = ((max8997->buck125_gpioindex) >> 2) & 0x1;
gpio_set_value(max8997->buck125_gpios[0], set1);
gpio_set_value(max8997->buck125_gpios[1], set2);
gpio_set_value(max8997->buck125_gpios[2], set3);
}
struct voltage_map_desc {
int min;
int max;
int step;
};
/* Voltage maps in uV */
static const struct voltage_map_desc ldo_voltage_map_desc = {
.min = 800000, .max = 3950000, .step = 50000,
}; /* LDO1 ~ 18, 21 all */
static const struct voltage_map_desc buck1245_voltage_map_desc = {
.min = 650000, .max = 2225000, .step = 25000,
}; /* Buck1, 2, 4, 5 */
static const struct voltage_map_desc buck37_voltage_map_desc = {
.min = 750000, .max = 3900000, .step = 50000,
}; /* Buck3, 7 */
/* current map in uA */
static const struct voltage_map_desc charger_current_map_desc = {
.min = 200000, .max = 950000, .step = 50000,
};
static const struct voltage_map_desc topoff_current_map_desc = {
.min = 50000, .max = 200000, .step = 10000,
};
static const struct voltage_map_desc *reg_voltage_map[] = {
[MAX8997_LDO1] = &ldo_voltage_map_desc,
[MAX8997_LDO2] = &ldo_voltage_map_desc,
[MAX8997_LDO3] = &ldo_voltage_map_desc,
[MAX8997_LDO4]