1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* Copyright (C) 2018 ROHM Semiconductors */
3 
4 #ifndef __LINUX_MFD_ROHM_H__
5 #define __LINUX_MFD_ROHM_H__
6 
7 #include <linux/regmap.h>
8 #include <linux/regulator/driver.h>
9 
10 enum rohm_chip_type {
11 	ROHM_CHIP_TYPE_BD9571,
12 	ROHM_CHIP_TYPE_BD9573,
13 	ROHM_CHIP_TYPE_BD9574,
14 	ROHM_CHIP_TYPE_BD9576,
15 	ROHM_CHIP_TYPE_BD71815,
16 	ROHM_CHIP_TYPE_BD71828,
17 	ROHM_CHIP_TYPE_BD71837,
18 	ROHM_CHIP_TYPE_BD71847,
19 	ROHM_CHIP_TYPE_AMOUNT
20 };
21 
22 struct rohm_regmap_dev {
23 	struct device *dev;
24 	struct regmap *regmap;
25 };
26 
27 #define ROHM_DVS_LEVEL_RUN		BIT(0)
28 #define ROHM_DVS_LEVEL_IDLE		BIT(1)
29 #define ROHM_DVS_LEVEL_SUSPEND		BIT(2)
30 #define ROHM_DVS_LEVEL_LPSR		BIT(3)
31 #define ROHM_DVS_LEVEL_SNVS		BIT(4)
32 #define ROHM_DVS_LEVEL_VALID_AMOUNT	5
33 #define ROHM_DVS_LEVEL_UNKNOWN		0
34 
35 /**
36  * struct rohm_dvs_config - dynamic voltage scaling register descriptions
37  *
38  * @level_map:		bitmap representing supported run-levels for this
39  *			regulator
40  * @run_reg:		register address for regulator config at 'run' state
41  * @run_mask:		value mask for regulator voltages at 'run' state
42  * @run_on_mask:	enable mask for regulator at 'run' state
43  * @idle_reg:		register address for regulator config at 'idle' state
44  * @idle_mask:		value mask for regulator voltages at 'idle' state
45  * @idle_on_mask:	enable mask for regulator at 'idle' state
46  * @suspend_reg:	register address for regulator config at 'suspend' state
47  * @suspend_mask:	value mask for regulator voltages at 'suspend' state
48  * @suspend_on_mask:	enable mask for regulator at 'suspend' state
49  * @lpsr_reg:		register address for regulator config at 'lpsr' state
50  * @lpsr_mask:		value mask for regulator voltages at 'lpsr' state
51  * @lpsr_on_mask:	enable mask for regulator at 'lpsr' state
52  *
53  * Description of ROHM PMICs voltage configuration registers for different
54  * system states. This is used to correctly configure the PMIC at startup
55  * based on values read from DT.
56  */
57 struct rohm_dvs_config {
58 	uint64_t level_map;
59 	unsigned int run_reg;
60 	unsigned int run_mask;
61 	unsigned int run_on_mask;
62 	unsigned int idle_reg;
63 	unsigned int idle_mask;
64 	unsigned int idle_on_mask;
65 	unsigned int suspend_reg;
66 	unsigned int suspend_mask;
67 	unsigned int suspend_on_mask;
68 	unsigned int lpsr_reg;
69 	unsigned int lpsr_mask;
70 	unsigned int lpsr_on_mask;
71 	unsigned int snvs_reg;
72 	unsigned int snvs_mask;
73 	unsigned int snvs_on_mask;
74 };
75 
76 #if IS_ENABLED(CONFIG_REGULATOR_ROHM)
77 int rohm_regulator_set_dvs_levels(const struct rohm_dvs_config *dvs,
78 				  struct device_node *np,
79 				  const struct regulator_desc *desc,
80 				  struct regmap *regmap);
81 
82 int rohm_regulator_set_voltage_sel_restricted(struct regulator_dev *rdev,
83 					      unsigned int sel);
84 #endif
85 
86 #endif
87