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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * drivers/regulator/ab3100.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2008-2009 ST-Ericsson AB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Low-level control of the AB3100 IC Low Dropout (LDO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * regulators, external regulator and buck converter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Author: Mattias Wallin <mattias.wallin@stericsson.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Author: Linus Walleij <linus.walleij@stericsson.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/mfd/ab3100.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/mfd/abx500.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/regulator/of_regulator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /* LDO registers and some handy masking definitions for AB3100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define AB3100_LDO_A		0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define AB3100_LDO_C		0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define AB3100_LDO_D		0x42
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define AB3100_LDO_E		0x43
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define AB3100_LDO_E_SLEEP	0x44
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define AB3100_LDO_F		0x45
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define AB3100_LDO_G		0x46
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define AB3100_LDO_H		0x47
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define AB3100_LDO_H_SLEEP_MODE	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define AB3100_LDO_H_SLEEP_EN	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define AB3100_LDO_ON		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define AB3100_LDO_H_VSEL_AC	5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define AB3100_LDO_K		0x48
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define AB3100_LDO_EXT		0x49
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define AB3100_BUCK		0x4A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define AB3100_BUCK_SLEEP	0x4B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define AB3100_REG_ON_MASK	0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * struct ab3100_regulator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * A struct passed around the individual regulator functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * @platform_device: platform device holding this regulator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * @dev: handle to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * @plfdata: AB3100 platform data passed in at probe time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * @regreg: regulator register number in the AB3100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) struct ab3100_regulator {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct ab3100_platform_data *plfdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	u8 regreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) /* The order in which registers are initialized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static const u8 ab3100_reg_init_order[AB3100_NUM_REGULATORS+2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	AB3100_LDO_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	AB3100_LDO_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	AB3100_LDO_E,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	AB3100_LDO_E_SLEEP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	AB3100_LDO_F,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	AB3100_LDO_G,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	AB3100_LDO_H,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	AB3100_LDO_K,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	AB3100_LDO_EXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	AB3100_BUCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	AB3100_BUCK_SLEEP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	AB3100_LDO_D,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) /* Preset (hardware defined) voltages for these regulators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define LDO_A_VOLTAGE 2750000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) #define LDO_C_VOLTAGE 2650000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define LDO_D_VOLTAGE 2650000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static const unsigned int ldo_e_buck_typ_voltages[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	1800000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	1400000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	1300000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	1200000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	1100000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	1050000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	900000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static const unsigned int ldo_f_typ_voltages[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	1800000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	1400000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	1300000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	1200000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	1100000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	1050000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	2500000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	2650000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static const unsigned int ldo_g_typ_voltages[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	2850000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	2750000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	1800000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	1500000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static const unsigned int ldo_h_typ_voltages[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	2750000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	1800000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	1500000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	1200000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static const unsigned int ldo_k_typ_voltages[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	2750000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	1800000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* The regulator devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static struct ab3100_regulator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ab3100_regulators[AB3100_NUM_REGULATORS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		.regreg = AB3100_LDO_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		.regreg = AB3100_LDO_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		.regreg = AB3100_LDO_D,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		.regreg = AB3100_LDO_E,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		.regreg = AB3100_LDO_F,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		.regreg = AB3100_LDO_G,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		.regreg = AB3100_LDO_H,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		.regreg = AB3100_LDO_K,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		.regreg = AB3100_LDO_EXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		/* No voltages for the external regulator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		.regreg = AB3100_BUCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  * General functions for enable, disable and is_enabled used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * LDO: A,C,E,F,G,H,K,EXT and BUCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int ab3100_enable_regulator(struct regulator_dev *reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	u8 regval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	err = abx500_get_register_interruptible(abreg->dev, 0, abreg->regreg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 						&regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		dev_warn(&reg->dev, "failed to get regid %d value\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			 abreg->regreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	/* The regulator is already on, no reason to go further */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (regval & AB3100_REG_ON_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	regval |= AB3100_REG_ON_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	err = abx500_set_register_interruptible(abreg->dev, 0, abreg->regreg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 						regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		dev_warn(&reg->dev, "failed to set regid %d value\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			 abreg->regreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static int ab3100_disable_regulator(struct regulator_dev *reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	u8 regval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	 * LDO D is a special regulator. When it is disabled, the entire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	 * system is shut down. So this is handled specially.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	pr_info("Called ab3100_disable_regulator\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (abreg->regreg == AB3100_LDO_D) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		dev_info(&reg->dev, "disabling LDO D - shut down system\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		/* Setting LDO D to 0x00 cuts the power to the SoC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		return abx500_set_register_interruptible(abreg->dev, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 							 AB3100_LDO_D, 0x00U);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	 * All other regulators are handled here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	err = abx500_get_register_interruptible(abreg->dev, 0, abreg->regreg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 						&regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		dev_err(&reg->dev, "unable to get register 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			abreg->regreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	regval &= ~AB3100_REG_ON_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	return abx500_set_register_interruptible(abreg->dev, 0, abreg->regreg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 						 regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static int ab3100_is_enabled_regulator(struct regulator_dev *reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	u8 regval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	err = abx500_get_register_interruptible(abreg->dev, 0, abreg->regreg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 						&regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		dev_err(&reg->dev, "unable to get register 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			abreg->regreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	return regval & AB3100_REG_ON_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static int ab3100_get_voltage_regulator(struct regulator_dev *reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	u8 regval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	 * For variable types, read out setting and index into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	 * supplied voltage list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	err = abx500_get_register_interruptible(abreg->dev, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 						abreg->regreg, &regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		dev_warn(&reg->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			 "failed to get regulator value in register %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			 abreg->regreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	/* The 3 highest bits index voltages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	regval &= 0xE0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	regval >>= 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (regval >= reg->desc->n_voltages) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		dev_err(&reg->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			"regulator register %02x contains an illegal voltage setting\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			abreg->regreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		return -EINVAL;
^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) 	return reg->desc->volt_table[regval];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static int ab3100_set_voltage_regulator_sel(struct regulator_dev *reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 					    unsigned selector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	u8 regval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	err = abx500_get_register_interruptible(abreg->dev, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 						abreg->regreg, &regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		dev_warn(&reg->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			 "failed to get regulator register %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			 abreg->regreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	/* The highest three bits control the variable regulators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	regval &= ~0xE0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	regval |= (selector << 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	err = abx500_set_register_interruptible(abreg->dev, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 						abreg->regreg, regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		dev_warn(&reg->dev, "failed to set regulator register %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			abreg->regreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static int ab3100_set_suspend_voltage_regulator(struct regulator_dev *reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 						int uV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	u8 regval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	int bestindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	u8 targetreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	if (abreg->regreg == AB3100_LDO_E)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		targetreg = AB3100_LDO_E_SLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	else if (abreg->regreg == AB3100_BUCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		targetreg = AB3100_BUCK_SLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	/* LDO E and BUCK have special suspend voltages you can set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	bestindex = regulator_map_voltage_iterate(reg, uV, uV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	err = abx500_get_register_interruptible(abreg->dev, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 						targetreg, &regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		dev_warn(&reg->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			 "failed to get regulator register %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			 targetreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	/* The highest three bits control the variable regulators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	regval &= ~0xE0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	regval |= (bestindex << 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	err = abx500_set_register_interruptible(abreg->dev, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 						targetreg, regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		dev_warn(&reg->dev, "failed to set regulator register %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			abreg->regreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)  * The external regulator can just define a fixed voltage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static int ab3100_get_voltage_regulator_external(struct regulator_dev *reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	if (abreg->plfdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		return abreg->plfdata->external_voltage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		/* TODO: encode external voltage into device tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static const struct regulator_ops regulator_ops_fixed = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	.enable      = ab3100_enable_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	.disable     = ab3100_disable_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	.is_enabled  = ab3100_is_enabled_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) static const struct regulator_ops regulator_ops_variable = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	.enable      = ab3100_enable_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	.disable     = ab3100_disable_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	.is_enabled  = ab3100_is_enabled_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	.get_voltage = ab3100_get_voltage_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	.set_voltage_sel = ab3100_set_voltage_regulator_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	.list_voltage = regulator_list_voltage_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) static const struct regulator_ops regulator_ops_variable_sleepable = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	.enable      = ab3100_enable_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	.disable     = ab3100_disable_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	.is_enabled  = ab3100_is_enabled_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	.get_voltage = ab3100_get_voltage_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	.set_voltage_sel = ab3100_set_voltage_regulator_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	.set_suspend_voltage = ab3100_set_suspend_voltage_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	.list_voltage = regulator_list_voltage_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)  * LDO EXT is an external regulator so it is really
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)  * not possible to set any voltage locally here, AB3100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)  * is an on/off switch plain an simple. The external
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)  * voltage is defined in the board set-up if any.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static const struct regulator_ops regulator_ops_external = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	.enable      = ab3100_enable_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	.disable     = ab3100_disable_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	.is_enabled  = ab3100_is_enabled_regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	.get_voltage = ab3100_get_voltage_regulator_external,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static const struct regulator_desc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		.name = "LDO_A",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		.id   = AB3100_LDO_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		.ops  = &regulator_ops_fixed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		.n_voltages = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		.fixed_uV = LDO_A_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		.enable_time = 200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		.name = "LDO_C",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		.id   = AB3100_LDO_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		.ops  = &regulator_ops_fixed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		.n_voltages = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		.fixed_uV = LDO_C_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		.enable_time = 200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		.name = "LDO_D",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		.id   = AB3100_LDO_D,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		.ops  = &regulator_ops_fixed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		.n_voltages = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		.fixed_uV = LDO_D_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		.enable_time = 200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		.name = "LDO_E",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		.id   = AB3100_LDO_E,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		.ops  = &regulator_ops_variable_sleepable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		.n_voltages = ARRAY_SIZE(ldo_e_buck_typ_voltages),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		.volt_table = ldo_e_buck_typ_voltages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		.enable_time = 200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		.name = "LDO_F",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		.id   = AB3100_LDO_F,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		.ops  = &regulator_ops_variable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		.n_voltages = ARRAY_SIZE(ldo_f_typ_voltages),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		.volt_table = ldo_f_typ_voltages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		.enable_time = 600,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		.name = "LDO_G",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		.id   = AB3100_LDO_G,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		.ops  = &regulator_ops_variable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		.n_voltages = ARRAY_SIZE(ldo_g_typ_voltages),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		.volt_table = ldo_g_typ_voltages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		.enable_time = 400,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		.name = "LDO_H",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		.id   = AB3100_LDO_H,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		.ops  = &regulator_ops_variable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		.n_voltages = ARRAY_SIZE(ldo_h_typ_voltages),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		.volt_table = ldo_h_typ_voltages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		.enable_time = 200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		.name = "LDO_K",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		.id   = AB3100_LDO_K,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		.ops  = &regulator_ops_variable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		.n_voltages = ARRAY_SIZE(ldo_k_typ_voltages),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		.volt_table = ldo_k_typ_voltages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		.enable_time = 200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		.name = "LDO_EXT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		.id   = AB3100_LDO_EXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		.ops  = &regulator_ops_external,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		.name = "BUCK",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		.id   = AB3100_BUCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		.ops  = &regulator_ops_variable_sleepable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		.n_voltages = ARRAY_SIZE(ldo_e_buck_typ_voltages),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		.volt_table = ldo_e_buck_typ_voltages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		.enable_time = 1000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) static int ab3100_regulator_register(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 				     struct ab3100_platform_data *plfdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 				     struct regulator_init_data *init_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 				     struct device_node *np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 				     unsigned long id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	const struct regulator_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	struct ab3100_regulator *reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	struct regulator_config config = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		desc = &ab3100_regulator_desc[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		if (desc->id == id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	if (desc->id != id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	/* Same index used for this array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	reg = &ab3100_regulators[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	 * Initialize per-regulator struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	 * Inherit platform data, this comes down from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	 * i2c boarddata, from the machine. So if you want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	 * see what it looks like for a certain machine, go
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	 * into the machine I2C setup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	reg->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	if (plfdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		reg->plfdata = plfdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		config.init_data = &plfdata->reg_constraints[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	} else if (np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		config.of_node = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		config.init_data = init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	config.dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	config.driver_data = reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	rdev = devm_regulator_register(&pdev->dev, desc, &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	if (IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		err = PTR_ERR(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 			"%s: failed to register regulator %s err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 			__func__, desc->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 			err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) static struct of_regulator_match ab3100_regulator_matches[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	{ .name = "ab3100_ldo_a", .driver_data = (void *) AB3100_LDO_A, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	{ .name = "ab3100_ldo_c", .driver_data = (void *) AB3100_LDO_C, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	{ .name = "ab3100_ldo_d", .driver_data = (void *) AB3100_LDO_D, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	{ .name = "ab3100_ldo_e", .driver_data = (void *) AB3100_LDO_E, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	{ .name = "ab3100_ldo_f", .driver_data = (void *) AB3100_LDO_F },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	{ .name = "ab3100_ldo_g", .driver_data = (void *) AB3100_LDO_G },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	{ .name = "ab3100_ldo_h", .driver_data = (void *) AB3100_LDO_H },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	{ .name = "ab3100_ldo_k", .driver_data = (void *) AB3100_LDO_K },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	{ .name = "ab3100_ext", .driver_data = (void *) AB3100_LDO_EXT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	{ .name = "ab3100_buck", .driver_data = (void *) AB3100_BUCK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)  * Initial settings of ab3100 registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)  * Common for below LDO regulator settings are that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)  * bit 7-5 controls voltage. Bit 4 turns regulator ON(1) or OFF(0).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)  * Bit 3-2 controls sleep enable and bit 1-0 controls sleep mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) /* LDO_A 0x16: 2.75V, ON, SLEEP_A, SLEEP OFF GND */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) #define LDO_A_SETTING		0x16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) /* LDO_C 0x10: 2.65V, ON, SLEEP_A or B, SLEEP full power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) #define LDO_C_SETTING		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) /* LDO_D 0x10: 2.65V, ON, sleep mode not used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) #define LDO_D_SETTING		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) /* LDO_E 0x10: 1.8V, ON, SLEEP_A or B, SLEEP full power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) #define LDO_E_SETTING		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) /* LDO_E SLEEP 0x00: 1.8V, not used, SLEEP_A or B, not used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) #define LDO_E_SLEEP_SETTING	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) /* LDO_F 0xD0: 2.5V, ON, SLEEP_A or B, SLEEP full power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) #define LDO_F_SETTING		0xD0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) /* LDO_G 0x00: 2.85V, OFF, SLEEP_A or B, SLEEP full power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) #define LDO_G_SETTING		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) /* LDO_H 0x18: 2.75V, ON, SLEEP_B, SLEEP full power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) #define LDO_H_SETTING		0x18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) /* LDO_K 0x00: 2.75V, OFF, SLEEP_A or B, SLEEP full power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) #define LDO_K_SETTING		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) /* LDO_EXT 0x00: Voltage not set, OFF, not used, not used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) #define LDO_EXT_SETTING		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) /* BUCK 0x7D: 1.2V, ON, SLEEP_A and B, SLEEP low power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) #define BUCK_SETTING	0x7D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) /* BUCK SLEEP 0xAC: 1.05V, Not used, SLEEP_A and B, Not used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) #define BUCK_SLEEP_SETTING	0xAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) static const u8 ab3100_reg_initvals[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	LDO_A_SETTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	LDO_C_SETTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	LDO_E_SETTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	LDO_E_SLEEP_SETTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	LDO_F_SETTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	LDO_G_SETTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	LDO_H_SETTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	LDO_K_SETTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	LDO_EXT_SETTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	BUCK_SETTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	BUCK_SLEEP_SETTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	LDO_D_SETTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	 * Set up the regulator registers, as was previously done with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	 * platform data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	/* Set up regulators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		err = abx500_set_register_interruptible(&pdev->dev, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 					ab3100_reg_init_order[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 					ab3100_reg_initvals[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 			dev_err(&pdev->dev, "regulator initialization failed with error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 				err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	for (i = 0; i < ARRAY_SIZE(ab3100_regulator_matches); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 		err = ab3100_regulator_register(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 			pdev, NULL, ab3100_regulator_matches[i].init_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 			ab3100_regulator_matches[i].of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 			(unsigned long)ab3100_regulator_matches[i].driver_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) static int ab3100_regulators_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	struct ab3100_platform_data *plfdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	u8 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	/* Check chip state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	err = abx500_get_register_interruptible(&pdev->dev, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 						AB3100_LDO_D, &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 		dev_err(&pdev->dev, "could not read initial status of LDO_D\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	if (data & 0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 		dev_notice(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 			   "chip is already in active mode (Warm start)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		dev_notice(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 			   "chip is in inactive mode (Cold start)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	if (np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		err = of_regulator_match(&pdev->dev, np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 					 ab3100_regulator_matches,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 					 ARRAY_SIZE(ab3100_regulator_matches));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 		if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 			dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 				"Error parsing regulator init data: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 		return ab3100_regulator_of_probe(pdev, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	/* Set up regulators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 		err = abx500_set_register_interruptible(&pdev->dev, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 					ab3100_reg_init_order[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 					plfdata->reg_initvals[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 			dev_err(&pdev->dev, "regulator initialization failed with error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 				err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	/* Register the regulators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 		const struct regulator_desc *desc = &ab3100_regulator_desc[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		err = ab3100_regulator_register(pdev, plfdata, NULL, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 						desc->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) static struct platform_driver ab3100_regulators_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 		.name  = "ab3100-regulators",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	.probe = ab3100_regulators_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) static __init int ab3100_regulators_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	return platform_driver_register(&ab3100_regulators_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) static __exit void ab3100_regulators_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	platform_driver_unregister(&ab3100_regulators_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) subsys_initcall(ab3100_regulators_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) module_exit(ab3100_regulators_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) MODULE_DESCRIPTION("AB3100 Regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) MODULE_ALIAS("platform:ab3100-regulators");