summaryrefslogtreecommitdiff
path: root/drivers/regulator/internal.h
blob: fb4433068d2980458f2779fb344f95079edefd81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * internal.h  --  Voltage/Current Regulator framework internal code
 *
 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
 * Copyright 2008 SlimLogic Ltd.
 *
 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
 */

#ifndef __REGULATOR_INTERNAL_H
#define __REGULATOR_INTERNAL_H

#include <linux/suspend.h>

#define REGULATOR_STATES_NUM	(PM_SUSPEND_MAX + 1)

#define rdev_crit(rdev, fmt, ...)					\
	pr_crit("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
#define rdev_err(rdev, fmt, ...)					\
	pr_err("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
#define rdev_warn(rdev, fmt, ...)					\
	pr_warn("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
#define rdev_info(rdev, fmt, ...)					\
	pr_info("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
#define rdev_dbg(rdev, fmt, ...)					\
	pr_debug("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)

struct regulator_voltage {
	int min_uV;
	int max_uV;
};

/*
 * struct regulator
 *
 * One for each consumer device.
 * @voltage - a voltage array for each state of runtime, i.e.:
 *            PM_SUSPEND_ON
 *            PM_SUSPEND_TO_IDLE
 *            PM_SUSPEND_STANDBY
 *            PM_SUSPEND_MEM
 *            PM_SUSPEND_MAX
 */
struct regulator {
	struct device *dev;
	struct list_head list;
	unsigned int always_on:1;
	unsigned int bypass:1;
	unsigned int device_link:1;
	int uA_load;
	unsigned int enable_count;
	unsigned int deferred_disables;
	struct regulator_voltage voltage[REGULATOR_STATES_NUM];
	const char *supply_name;
	struct device_attribute dev_attr;
	struct regulator_dev *rdev;
	struct dentry *debugfs;
};

extern struct class regulator_class;

static inline struct regulator_dev *dev_to_rdev(struct device *dev)
{
	return container_of(dev, struct regulator_dev, dev);
}

#ifdef CONFIG_OF
struct regulator_dev *of_find_regulator_by_node(struct device_node *np);
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);

struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev,
						 int index);

int of_get_n_coupled(struct regulator_dev *rdev);

bool of_check_coupling_data(struct regulator_dev *rdev);

#else
static inline struct regulator_dev *
of_find_regulator_by_node(struct device_node *np)
{
	return NULL;
}

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)
{
	return NULL;
}

static inline struct regulator_dev *
of_parse_coupled_regulator(struct regulator_dev *rdev,
			   int index)
{
	return NULL;
}

static inline int of_get_n_coupled(struct regulator_dev *rdev)
{
	return 0;
}

static inline bool of_check_coupling_data(struct regulator_dev *rdev)
{
	return false;
}

#endif
enum regulator_get_type {
	NORMAL_GET,
	EXCLUSIVE_GET,
	OPTIONAL_GET,
	MAX_GET_TYPE
};

struct regulator *_regulator_get(struct device *dev, const char *id,
				 enum regulator_get_type get_type);
int _regulator_bulk_get(struct device *dev, int num_consumers,
			struct regulator_bulk_data *consumers, enum regulator_get_type get_type);
#endif