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