Loading...
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
18struct 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 */
34struct 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
50extern struct class regulator_class;
51
52static 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
58struct regulator_dev *of_find_regulator_by_node(struct device_node *np);
59struct 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
64struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev,
65 int index);
66
67int of_get_n_coupled(struct regulator_dev *rdev);
68
69bool of_check_coupling_data(struct regulator_dev *rdev);
70
71#else
72static inline struct regulator_dev *
73of_find_regulator_by_node(struct device_node *np)
74{
75 return NULL;
76}
77
78static inline struct regulator_init_data *
79regulator_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
87static inline struct regulator_dev *
88of_parse_coupled_regulator(struct regulator_dev *rdev,
89 int index)
90{
91 return NULL;
92}
93
94static inline int of_get_n_coupled(struct regulator_dev *rdev)
95{
96 return 0;
97}
98
99static inline bool of_check_coupling_data(struct regulator_dev *rdev)
100{
101 return false;
102}
103
104#endif
105enum regulator_get_type {
106 NORMAL_GET,
107 EXCLUSIVE_GET,
108 OPTIONAL_GET,
109 MAX_GET_TYPE
110};
111
112struct regulator *_regulator_get(struct device *dev, const char *id,
113 enum regulator_get_type get_type);
114#endif
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#define rdev_crit(rdev, fmt, ...) \
19 pr_crit("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
20#define rdev_err(rdev, fmt, ...) \
21 pr_err("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
22#define rdev_warn(rdev, fmt, ...) \
23 pr_warn("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
24#define rdev_info(rdev, fmt, ...) \
25 pr_info("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
26#define rdev_dbg(rdev, fmt, ...) \
27 pr_debug("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
28
29struct regulator_voltage {
30 int min_uV;
31 int max_uV;
32};
33
34/*
35 * struct regulator
36 *
37 * One for each consumer device.
38 * @voltage - a voltage array for each state of runtime, i.e.:
39 * PM_SUSPEND_ON
40 * PM_SUSPEND_TO_IDLE
41 * PM_SUSPEND_STANDBY
42 * PM_SUSPEND_MEM
43 * PM_SUSPEND_MAX
44 */
45struct regulator {
46 struct device *dev;
47 struct list_head list;
48 unsigned int always_on:1;
49 unsigned int bypass:1;
50 unsigned int device_link:1;
51 int uA_load;
52 unsigned int enable_count;
53 unsigned int deferred_disables;
54 struct regulator_voltage voltage[REGULATOR_STATES_NUM];
55 const char *supply_name;
56 struct device_attribute dev_attr;
57 struct regulator_dev *rdev;
58 struct dentry *debugfs;
59};
60
61extern const struct class regulator_class;
62
63static inline struct regulator_dev *dev_to_rdev(struct device *dev)
64{
65 return container_of(dev, struct regulator_dev, dev);
66}
67
68enum regulator_get_type {
69 NORMAL_GET,
70 EXCLUSIVE_GET,
71 OPTIONAL_GET,
72 MAX_GET_TYPE
73};
74
75#ifdef CONFIG_OF
76struct regulator_dev *of_regulator_dev_lookup(struct device *dev,
77 struct device_node *np,
78 const char *supply);
79struct regulator_init_data *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
84struct regulator *_of_regulator_get(struct device *dev, struct device_node *node,
85 const char *id, enum regulator_get_type get_type);
86
87struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev,
88 int index);
89
90int of_get_n_coupled(struct regulator_dev *rdev);
91
92bool of_check_coupling_data(struct regulator_dev *rdev);
93
94#else
95static inline struct regulator_dev *of_regulator_dev_lookup(struct device *dev,
96 struct device_node *np,
97 const char *supply)
98{
99 return ERR_PTR(-ENODEV);
100}
101
102static inline struct regulator_init_data *
103regulator_of_get_init_data(struct device *dev,
104 const struct regulator_desc *desc,
105 struct regulator_config *config,
106 struct device_node **node)
107{
108 return NULL;
109}
110
111static inline struct regulator_dev *
112of_parse_coupled_regulator(struct regulator_dev *rdev,
113 int index)
114{
115 return NULL;
116}
117
118static inline int of_get_n_coupled(struct regulator_dev *rdev)
119{
120 return 0;
121}
122
123static inline bool of_check_coupling_data(struct regulator_dev *rdev)
124{
125 return false;
126}
127
128#endif
129
130int _regulator_get_common_check(struct device *dev, const char *id,
131 enum regulator_get_type get_type);
132struct regulator *_regulator_get_common(struct regulator_dev *rdev, struct device *dev,
133 const char *id, enum regulator_get_type get_type);
134struct regulator *_regulator_get(struct device *dev, const char *id,
135 enum regulator_get_type get_type);
136int _regulator_bulk_get(struct device *dev, int num_consumers,
137 struct regulator_bulk_data *consumers, enum regulator_get_type get_type);
138#endif