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
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 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
68#ifdef CONFIG_OF
69struct regulator_dev *of_find_regulator_by_node(struct device_node *np);
70struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
71 const struct regulator_desc *desc,
72 struct regulator_config *config,
73 struct device_node **node);
74
75struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev,
76 int index);
77
78int of_get_n_coupled(struct regulator_dev *rdev);
79
80bool of_check_coupling_data(struct regulator_dev *rdev);
81
82#else
83static inline struct regulator_dev *
84of_find_regulator_by_node(struct device_node *np)
85{
86 return NULL;
87}
88
89static inline struct regulator_init_data *
90regulator_of_get_init_data(struct device *dev,
91 const struct regulator_desc *desc,
92 struct regulator_config *config,
93 struct device_node **node)
94{
95 return NULL;
96}
97
98static inline struct regulator_dev *
99of_parse_coupled_regulator(struct regulator_dev *rdev,
100 int index)
101{
102 return NULL;
103}
104
105static inline int of_get_n_coupled(struct regulator_dev *rdev)
106{
107 return 0;
108}
109
110static inline bool of_check_coupling_data(struct regulator_dev *rdev)
111{
112 return false;
113}
114
115#endif
116enum regulator_get_type {
117 NORMAL_GET,
118 EXCLUSIVE_GET,
119 OPTIONAL_GET,
120 MAX_GET_TYPE
121};
122
123struct regulator *_regulator_get(struct device *dev, const char *id,
124 enum regulator_get_type get_type);
125int _regulator_bulk_get(struct device *dev, int num_consumers,
126 struct regulator_bulk_data *consumers, enum regulator_get_type get_type);
127#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
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 int uA_load;
40 unsigned int enable_count;
41 unsigned int deferred_disables;
42 struct regulator_voltage voltage[REGULATOR_STATES_NUM];
43 const char *supply_name;
44 struct device_attribute dev_attr;
45 struct regulator_dev *rdev;
46 struct dentry *debugfs;
47};
48
49extern struct class regulator_class;
50
51static inline struct regulator_dev *dev_to_rdev(struct device *dev)
52{
53 return container_of(dev, struct regulator_dev, dev);
54}
55
56#ifdef CONFIG_OF
57struct regulator_dev *of_find_regulator_by_node(struct device_node *np);
58struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
59 const struct regulator_desc *desc,
60 struct regulator_config *config,
61 struct device_node **node);
62
63struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev,
64 int index);
65
66int of_get_n_coupled(struct regulator_dev *rdev);
67
68bool of_check_coupling_data(struct regulator_dev *rdev);
69
70#else
71static inline struct regulator_dev *
72of_find_regulator_by_node(struct device_node *np)
73{
74 return NULL;
75}
76
77static inline struct regulator_init_data *
78regulator_of_get_init_data(struct device *dev,
79 const struct regulator_desc *desc,
80 struct regulator_config *config,
81 struct device_node **node)
82{
83 return NULL;
84}
85
86static inline struct regulator_dev *
87of_parse_coupled_regulator(struct regulator_dev *rdev,
88 int index)
89{
90 return NULL;
91}
92
93static inline int of_get_n_coupled(struct regulator_dev *rdev)
94{
95 return 0;
96}
97
98static inline bool of_check_coupling_data(struct regulator_dev *rdev)
99{
100 return false;
101}
102
103#endif
104enum regulator_get_type {
105 NORMAL_GET,
106 EXCLUSIVE_GET,
107 OPTIONAL_GET,
108 MAX_GET_TYPE
109};
110
111struct regulator *_regulator_get(struct device *dev, const char *id,
112 enum regulator_get_type get_type);
113#endif