Source
x
// SPDX-License-Identifier: GPL-2.0+
//
// max77693.c - Regulator driver for the Maxim 77693 and 77843
//
// Copyright (C) 2013-2015 Samsung Electronics
// Jonghwa Lee <jonghwa3.lee@samsung.com>
// Krzysztof Kozlowski <krzk@kernel.org>
//
// This driver is based on max77686.c
/*
* ID for MAX77843 regulators.
* There is no need for such for MAX77693.
*/
enum max77843_regulator_type {
MAX77843_SAFEOUT1 = 0,
MAX77843_SAFEOUT2,
MAX77843_CHARGER,
MAX77843_NUM,
};
/* Register differences between chargers: MAX77693 and MAX77843 */
struct chg_reg_data {
unsigned int linear_reg;
unsigned int linear_mask;
unsigned int uA_step;
unsigned int min_sel;
};
/*
* MAX77693 CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA
* 0x00, 0x01, 0x2, 0x03 = 60 mA
* 0x04 ~ 0x7E = (60 + (X - 3) * 20) mA
* Actually for MAX77693 the driver manipulates the maximum input current,
* not the fast charge current (output). This should be fixed.
*
* On MAX77843 the calculation formula is the same (except values).
* Fortunately it properly manipulates the fast charge current.
*/
static int max77693_chg_get_current_limit(struct regulator_dev *rdev)
{
const struct chg_reg_data *reg_data = rdev_get_drvdata(rdev);
unsigned int chg_min_uA = rdev->constraints->min_uA;
unsigned int chg_max_uA = rdev->constraints->max_uA;
unsigned int reg, sel;
unsigned int val;
int ret;
ret = regmap_read(rdev->regmap, reg_data->linear_reg, ®);
if (ret < 0)
return ret;
sel = reg & reg_data->linear_mask;
/* the first four codes for charger current are all 60mA */
if (sel <= reg_data->min_sel)
sel = 0;
else
sel -= reg_data->min_sel;
val = chg_min_uA + reg_data->uA_step * sel;
if (val > chg_max_uA)
return -EINVAL;
return val;
}
static int max77693_chg_set_current_limit(struct regulator_dev *rdev,
int min_uA, int max_uA)
{
const struct chg_reg_data *reg_data = rdev_get_drvdata(rdev);
unsigned int chg_min_uA = rdev->constraints->min_uA;
int sel = 0;
while (chg_min_uA + reg_data->uA_step * sel < min_uA)
sel++;