Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) // max77693.c - Regulator driver for the Maxim 77693 and 77843
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) // Copyright (C) 2013-2015 Samsung Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) // Jonghwa Lee <jonghwa3.lee@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) // Krzysztof Kozlowski <krzk@kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) // This driver is based on max77686.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/regulator/machine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/mfd/max77693.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/mfd/max77693-common.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/mfd/max77693-private.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/mfd/max77843-private.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/regulator/of_regulator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * ID for MAX77843 regulators.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * There is no need for such for MAX77693.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) enum max77843_regulator_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	MAX77843_SAFEOUT1 = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	MAX77843_SAFEOUT2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	MAX77843_CHARGER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	MAX77843_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /* Register differences between chargers: MAX77693 and MAX77843 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) struct chg_reg_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	unsigned int linear_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	unsigned int linear_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	unsigned int uA_step;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	unsigned int min_sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * MAX77693 CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * 0x00, 0x01, 0x2, 0x03	= 60 mA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * 0x04 ~ 0x7E			= (60 + (X - 3) * 20) mA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * Actually for MAX77693 the driver manipulates the maximum input current,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * not the fast charge current (output). This should be fixed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * On MAX77843 the calculation formula is the same (except values).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * Fortunately it properly manipulates the fast charge current.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static int max77693_chg_get_current_limit(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	const struct chg_reg_data *reg_data = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	unsigned int chg_min_uA = rdev->constraints->min_uA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	unsigned int chg_max_uA = rdev->constraints->max_uA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	unsigned int reg, sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	ret = regmap_read(rdev->regmap, reg_data->linear_reg, &reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	sel = reg & reg_data->linear_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	/* the first four codes for charger current are all 60mA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (sel <= reg_data->min_sel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		sel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		sel -= reg_data->min_sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	val = chg_min_uA + reg_data->uA_step * sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (val > chg_max_uA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static int max77693_chg_set_current_limit(struct regulator_dev *rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 						int min_uA, int max_uA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	const struct chg_reg_data *reg_data = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	unsigned int chg_min_uA = rdev->constraints->min_uA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	int sel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	while (chg_min_uA + reg_data->uA_step * sel < min_uA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		sel++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (chg_min_uA + reg_data->uA_step * sel > max_uA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	/* the first four codes for charger current are all 60mA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	sel += reg_data->min_sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return regmap_write(rdev->regmap, reg_data->linear_reg, sel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /* end of CHARGER regulator ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /* Returns regmap suitable for given regulator on chosen device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static struct regmap *max77693_get_regmap(enum max77693_types type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 					  struct max77693_dev *max77693,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 					  int reg_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (type == TYPE_MAX77693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		return max77693->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	/* Else: TYPE_MAX77843 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	switch (reg_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	case MAX77843_SAFEOUT1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	case MAX77843_SAFEOUT2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return max77693->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	case MAX77843_CHARGER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		return max77693->regmap_chg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		return max77693->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static const unsigned int max77693_safeout_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	4850000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	4900000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	4950000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	3300000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static const struct regulator_ops max77693_safeout_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	.list_voltage		= regulator_list_voltage_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	.is_enabled		= regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	.enable			= regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	.disable		= regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static const struct regulator_ops max77693_charger_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	.is_enabled		= regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	.enable			= regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	.disable		= regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	.get_current_limit	= max77693_chg_get_current_limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	.set_current_limit	= max77693_chg_set_current_limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #define max77693_regulator_desc_esafeout(_num)	{		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	.name		= "ESAFEOUT"#_num,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	.id		= MAX77693_ESAFEOUT##_num,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	.of_match	= of_match_ptr("ESAFEOUT"#_num),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	.regulators_node	= of_match_ptr("regulators"),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	.n_voltages	= 4,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	.ops		= &max77693_safeout_ops,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	.type		= REGULATOR_VOLTAGE,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	.owner		= THIS_MODULE,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	.volt_table	= max77693_safeout_table,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	.vsel_reg	= MAX77693_CHG_REG_SAFEOUT_CTRL,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	.vsel_mask	= SAFEOUT_CTRL_SAFEOUT##_num##_MASK,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	.enable_reg	= MAX77693_CHG_REG_SAFEOUT_CTRL,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	.enable_mask	= SAFEOUT_CTRL_ENSAFEOUT##_num##_MASK ,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static const struct regulator_desc max77693_supported_regulators[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	max77693_regulator_desc_esafeout(1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	max77693_regulator_desc_esafeout(2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		.name = "CHARGER",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		.id = MAX77693_CHARGER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		.of_match = of_match_ptr("CHARGER"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		.regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		.ops = &max77693_charger_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		.type = REGULATOR_CURRENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		.enable_reg = MAX77693_CHG_REG_CHG_CNFG_00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		.enable_mask = CHG_CNFG_00_CHG_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 				CHG_CNFG_00_BUCK_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		.enable_val = CHG_CNFG_00_CHG_MASK | CHG_CNFG_00_BUCK_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static const struct chg_reg_data max77693_chg_reg_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	.linear_reg	= MAX77693_CHG_REG_CHG_CNFG_09,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	.linear_mask	= CHG_CNFG_09_CHGIN_ILIM_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	.uA_step	= 20000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	.min_sel	= 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #define	max77843_regulator_desc_esafeout(num)	{			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	.name		= "SAFEOUT" # num,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	.id		= MAX77843_SAFEOUT ## num,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	.ops		= &max77693_safeout_ops,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	.of_match	= of_match_ptr("SAFEOUT" # num),		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	.regulators_node = of_match_ptr("regulators"),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	.type		= REGULATOR_VOLTAGE,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	.owner		= THIS_MODULE,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	.n_voltages	= ARRAY_SIZE(max77693_safeout_table),		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	.volt_table	= max77693_safeout_table,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	.enable_reg	= MAX77843_SYS_REG_SAFEOUTCTRL,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	.enable_mask	= MAX77843_REG_SAFEOUTCTRL_ENSAFEOUT ## num,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	.vsel_reg	= MAX77843_SYS_REG_SAFEOUTCTRL,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	.vsel_mask	= MAX77843_REG_SAFEOUTCTRL_SAFEOUT ## num ## _MASK, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static const struct regulator_desc max77843_supported_regulators[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	[MAX77843_SAFEOUT1] = max77843_regulator_desc_esafeout(1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	[MAX77843_SAFEOUT2] = max77843_regulator_desc_esafeout(2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	[MAX77843_CHARGER] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		.name		= "CHARGER",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		.id		= MAX77843_CHARGER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		.ops		= &max77693_charger_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		.of_match	= of_match_ptr("CHARGER"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		.regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		.type		= REGULATOR_CURRENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		.enable_reg	= MAX77843_CHG_REG_CHG_CNFG_00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		.enable_mask	= MAX77843_CHG_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		.enable_val	= MAX77843_CHG_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static const struct chg_reg_data max77843_chg_reg_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	.linear_reg	= MAX77843_CHG_REG_CHG_CNFG_02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	.linear_mask	= MAX77843_CHG_FAST_CHG_CURRENT_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	.uA_step	= MAX77843_CHG_FAST_CHG_CURRENT_STEP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	.min_sel	= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static int max77693_pmic_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	enum max77693_types type = platform_get_device_id(pdev)->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	const struct regulator_desc *regulators;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	unsigned int regulators_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct regulator_config config = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	config.dev = iodev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	case TYPE_MAX77693:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		regulators = max77693_supported_regulators;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		regulators_size = ARRAY_SIZE(max77693_supported_regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		config.driver_data = (void *)&max77693_chg_reg_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	case TYPE_MAX77843:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		regulators = max77843_supported_regulators;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		regulators_size = ARRAY_SIZE(max77843_supported_regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		config.driver_data = (void *)&max77843_chg_reg_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		dev_err(&pdev->dev, "Unsupported device type: %u\n", type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	for (i = 0; i < regulators_size; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		config.regmap = max77693_get_regmap(type, iodev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 						    regulators[i].id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		rdev = devm_regulator_register(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 						&regulators[i], &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		if (IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 				"Failed to initialize regulator-%d\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			return PTR_ERR(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static const struct platform_device_id max77693_pmic_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	{ "max77693-pmic", TYPE_MAX77693 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	{ "max77843-regulator", TYPE_MAX77843 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) MODULE_DEVICE_TABLE(platform, max77693_pmic_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static struct platform_driver max77693_pmic_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		   .name = "max77693-pmic",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		   },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	.probe = max77693_pmic_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	.id_table = max77693_pmic_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static int __init max77693_pmic_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	return platform_driver_register(&max77693_pmic_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) subsys_initcall(max77693_pmic_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static void __exit max77693_pmic_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	platform_driver_unregister(&max77693_pmic_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) module_exit(max77693_pmic_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) MODULE_DESCRIPTION("MAXIM 77693/77843 regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) MODULE_AUTHOR("Jonghwa Lee <jonghwa3.lee@samsung.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) MODULE_AUTHOR("Krzysztof Kozlowski <krzk@kernel.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) MODULE_LICENSE("GPL");