Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * coupler.h -- SoC Regulator support, coupler API.
4 *
5 * Regulator Coupler Interface.
6 */
7
8#ifndef __LINUX_REGULATOR_COUPLER_H_
9#define __LINUX_REGULATOR_COUPLER_H_
10
11#include <linux/kernel.h>
12#include <linux/suspend.h>
13
14struct regulator_coupler;
15struct regulator_dev;
16
17/**
18 * struct regulator_coupler - customized regulator's coupler
19 *
20 * Regulator's coupler allows to customize coupling algorithm.
21 *
22 * @list: couplers list entry
23 * @attach_regulator: Callback invoked on creation of a coupled regulator,
24 * couples are unresolved at this point. The callee should
25 * check that it could handle the regulator and return 0 on
26 * success, -errno on failure and 1 if given regulator is
27 * not suitable for this coupler (case of having multiple
28 * regulators in a system). Callback shall be implemented.
29 * @detach_regulator: Callback invoked on destruction of a coupled regulator.
30 * This callback is optional and could be NULL.
31 * @balance_voltage: Callback invoked when voltage of a coupled regulator is
32 * changing. Called with all of the coupled rdev's being held
33 * under "consumer lock". The callee should perform voltage
34 * balancing, changing voltage of the coupled regulators as
35 * needed. It's up to the coupler to verify the voltage
36 * before changing it in hardware, i.e. coupler should
37 * check consumer's min/max and etc. This callback is
38 * optional and could be NULL, in which case a generic
39 * voltage balancer will be used.
40 */
41struct regulator_coupler {
42 struct list_head list;
43
44 int (*attach_regulator)(struct regulator_coupler *coupler,
45 struct regulator_dev *rdev);
46 int (*detach_regulator)(struct regulator_coupler *coupler,
47 struct regulator_dev *rdev);
48 int (*balance_voltage)(struct regulator_coupler *coupler,
49 struct regulator_dev *rdev,
50 suspend_state_t state);
51};
52
53#ifdef CONFIG_REGULATOR
54int regulator_coupler_register(struct regulator_coupler *coupler);
55const char *rdev_get_name(struct regulator_dev *rdev);
56int regulator_check_consumers(struct regulator_dev *rdev,
57 int *min_uV, int *max_uV,
58 suspend_state_t state);
59int regulator_check_voltage(struct regulator_dev *rdev,
60 int *min_uV, int *max_uV);
61int regulator_get_voltage_rdev(struct regulator_dev *rdev);
62int regulator_set_voltage_rdev(struct regulator_dev *rdev,
63 int min_uV, int max_uV,
64 suspend_state_t state);
65int regulator_do_balance_voltage(struct regulator_dev *rdev,
66 suspend_state_t state, bool skip_coupled);
67#else
68static inline int regulator_coupler_register(struct regulator_coupler *coupler)
69{
70 return 0;
71}
72static inline const char *rdev_get_name(struct regulator_dev *rdev)
73{
74 return NULL;
75}
76static inline int regulator_check_consumers(struct regulator_dev *rdev,
77 int *min_uV, int *max_uV,
78 suspend_state_t state)
79{
80 return -EINVAL;
81}
82static inline int regulator_check_voltage(struct regulator_dev *rdev,
83 int *min_uV, int *max_uV)
84{
85 return -EINVAL;
86}
87static inline int regulator_get_voltage_rdev(struct regulator_dev *rdev)
88{
89 return -EINVAL;
90}
91static inline int regulator_set_voltage_rdev(struct regulator_dev *rdev,
92 int min_uV, int max_uV,
93 suspend_state_t state)
94{
95 return -EINVAL;
96}
97static inline int regulator_do_balance_voltage(struct regulator_dev *rdev,
98 suspend_state_t state,
99 bool skip_coupled)
100{
101 return -EINVAL;
102}
103#endif
104
105#endif