xref: /OK3568_Linux_fs/kernel/drivers/regulator/internal.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * internal.h  --  Voltage/Current Regulator framework internal code
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright 2007, 2008 Wolfson Microelectronics PLC.
6*4882a593Smuzhiyun  * Copyright 2008 SlimLogic Ltd.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Author: Liam Girdwood <lrg@slimlogic.co.uk>
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #ifndef __REGULATOR_INTERNAL_H
12*4882a593Smuzhiyun #define __REGULATOR_INTERNAL_H
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #include <linux/suspend.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #define REGULATOR_STATES_NUM	(PM_SUSPEND_MAX + 1)
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun struct regulator_voltage {
19*4882a593Smuzhiyun 	int min_uV;
20*4882a593Smuzhiyun 	int max_uV;
21*4882a593Smuzhiyun };
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun /*
24*4882a593Smuzhiyun  * struct regulator
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  * One for each consumer device.
27*4882a593Smuzhiyun  * @voltage - a voltage array for each state of runtime, i.e.:
28*4882a593Smuzhiyun  *            PM_SUSPEND_ON
29*4882a593Smuzhiyun  *            PM_SUSPEND_TO_IDLE
30*4882a593Smuzhiyun  *            PM_SUSPEND_STANDBY
31*4882a593Smuzhiyun  *            PM_SUSPEND_MEM
32*4882a593Smuzhiyun  *            PM_SUSPEND_MAX
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun struct regulator {
35*4882a593Smuzhiyun 	struct device *dev;
36*4882a593Smuzhiyun 	struct list_head list;
37*4882a593Smuzhiyun 	unsigned int always_on:1;
38*4882a593Smuzhiyun 	unsigned int bypass:1;
39*4882a593Smuzhiyun 	unsigned int device_link:1;
40*4882a593Smuzhiyun 	int uA_load;
41*4882a593Smuzhiyun 	unsigned int enable_count;
42*4882a593Smuzhiyun 	unsigned int deferred_disables;
43*4882a593Smuzhiyun 	struct regulator_voltage voltage[REGULATOR_STATES_NUM];
44*4882a593Smuzhiyun 	const char *supply_name;
45*4882a593Smuzhiyun 	struct device_attribute dev_attr;
46*4882a593Smuzhiyun 	struct regulator_dev *rdev;
47*4882a593Smuzhiyun 	struct dentry *debugfs;
48*4882a593Smuzhiyun };
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun extern struct class regulator_class;
51*4882a593Smuzhiyun 
dev_to_rdev(struct device * dev)52*4882a593Smuzhiyun static inline struct regulator_dev *dev_to_rdev(struct device *dev)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun 	return container_of(dev, struct regulator_dev, dev);
55*4882a593Smuzhiyun }
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun #ifdef CONFIG_OF
58*4882a593Smuzhiyun struct regulator_dev *of_find_regulator_by_node(struct device_node *np);
59*4882a593Smuzhiyun struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
60*4882a593Smuzhiyun 			         const struct regulator_desc *desc,
61*4882a593Smuzhiyun 				 struct regulator_config *config,
62*4882a593Smuzhiyun 				 struct device_node **node);
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev,
65*4882a593Smuzhiyun 						 int index);
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun int of_get_n_coupled(struct regulator_dev *rdev);
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun bool of_check_coupling_data(struct regulator_dev *rdev);
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun #else
72*4882a593Smuzhiyun static inline struct regulator_dev *
of_find_regulator_by_node(struct device_node * np)73*4882a593Smuzhiyun of_find_regulator_by_node(struct device_node *np)
74*4882a593Smuzhiyun {
75*4882a593Smuzhiyun 	return NULL;
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun static inline struct regulator_init_data *
regulator_of_get_init_data(struct device * dev,const struct regulator_desc * desc,struct regulator_config * config,struct device_node ** node)79*4882a593Smuzhiyun regulator_of_get_init_data(struct device *dev,
80*4882a593Smuzhiyun 			   const struct regulator_desc *desc,
81*4882a593Smuzhiyun 			   struct regulator_config *config,
82*4882a593Smuzhiyun 			   struct device_node **node)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun 	return NULL;
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun static inline struct regulator_dev *
of_parse_coupled_regulator(struct regulator_dev * rdev,int index)88*4882a593Smuzhiyun of_parse_coupled_regulator(struct regulator_dev *rdev,
89*4882a593Smuzhiyun 			   int index)
90*4882a593Smuzhiyun {
91*4882a593Smuzhiyun 	return NULL;
92*4882a593Smuzhiyun }
93*4882a593Smuzhiyun 
of_get_n_coupled(struct regulator_dev * rdev)94*4882a593Smuzhiyun static inline int of_get_n_coupled(struct regulator_dev *rdev)
95*4882a593Smuzhiyun {
96*4882a593Smuzhiyun 	return 0;
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun 
of_check_coupling_data(struct regulator_dev * rdev)99*4882a593Smuzhiyun static inline bool of_check_coupling_data(struct regulator_dev *rdev)
100*4882a593Smuzhiyun {
101*4882a593Smuzhiyun 	return false;
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun #endif
105*4882a593Smuzhiyun enum regulator_get_type {
106*4882a593Smuzhiyun 	NORMAL_GET,
107*4882a593Smuzhiyun 	EXCLUSIVE_GET,
108*4882a593Smuzhiyun 	OPTIONAL_GET,
109*4882a593Smuzhiyun 	MAX_GET_TYPE
110*4882a593Smuzhiyun };
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun struct regulator *_regulator_get(struct device *dev, const char *id,
113*4882a593Smuzhiyun 				 enum regulator_get_type get_type);
114*4882a593Smuzhiyun #endif
115