]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/extres/regulator/regulator.h
MFV r319744,r319745: 8269 dtrace stddev aggregation is normalized incorrectly
[FreeBSD/FreeBSD.git] / sys / dev / extres / regulator / regulator.h
1 /*-
2  * Copyright 2016 Michal Meloun <mmel@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 #ifndef _DEV_EXTRES_REGULATOR_H_
30 #define _DEV_EXTRES_REGULATOR_H_
31 #include "opt_platform.h"
32
33 #include <sys/kobj.h>
34 #ifdef FDT
35 #include <dev/ofw/ofw_bus.h>
36 #endif
37 #include "regnode_if.h"
38
39 #define REGULATOR_FLAGS_STATIC          0x00000001  /* Static strings */
40 #define REGULATOR_FLAGS_NOT_DISABLE     0x00000002  /* Cannot be disabled */
41
42 #define REGULATOR_STATUS_ENABLED        0x00000001
43 #define REGULATOR_STATUS_OVERCURRENT    0x00000002
44
45 typedef struct regulator *regulator_t;
46
47 /* Standard regulator parameters. */
48 struct regnode_std_param {
49         int                     min_uvolt;      /* In uV */
50         int                     max_uvolt;      /* In uV */
51         int                     min_uamp;       /* In uA */
52         int                     max_uamp;       /* In uA */
53         int                     ramp_delay;     /* In uV/usec */
54         int                     enable_delay;   /* In usec */
55         bool                    boot_on;        /* Is enabled on boot */
56         bool                    always_on;      /* Must be enabled */
57         int                     enable_active_high;
58 };
59
60 /* Initialization parameters. */
61 struct regnode_init_def {
62         char                    *name;          /* Regulator name */
63         char                    *parent_name;   /* Name of parent regulator */
64         struct regnode_std_param std_param;     /* Standard parameters */
65         intptr_t                id;             /* Regulator ID */
66         int                     flags;          /* Flags */
67 #ifdef FDT
68          phandle_t              ofw_node;       /* OFW node of regulator */
69 #endif
70 };
71
72 struct regulator_range {
73         int             min_uvolt;
74         int             step_uvolt;
75         uint8_t         min_sel;
76         uint8_t         max_sel;
77 };
78
79 #define REG_RANGE_INIT(_min_sel, _max_sel, _min_uvolt, _step_uvolt) {   \
80         .min_sel        = _min_sel,                                     \
81         .max_sel        = _max_sel,                                     \
82         .min_uvolt      = _min_uvolt,                                   \
83         .step_uvolt     = _step_uvolt,                                  \
84 }
85
86 /*
87  * Shorthands for constructing method tables.
88  */
89 #define REGNODEMETHOD           KOBJMETHOD
90 #define REGNODEMETHOD_END       KOBJMETHOD_END
91 #define regnode_method_t        kobj_method_t
92 #define regnode_class_t         kobj_class_t
93 DECLARE_CLASS(regnode_class);
94
95 /* Providers interface. */
96 struct regnode *regnode_create(device_t pdev, regnode_class_t regnode_class,
97     struct regnode_init_def *def);
98 struct regnode *regnode_register(struct regnode *regnode);
99 const char *regnode_get_name(struct regnode *regnode);
100 const char *regnode_get_parent_name(struct regnode *regnode);
101 struct regnode *regnode_get_parent(struct regnode *regnode);
102 int regnode_get_flags(struct regnode *regnode);
103 void *regnode_get_softc(struct regnode *regnode);
104 device_t regnode_get_device(struct regnode *regnode);
105 struct regnode_std_param *regnode_get_stdparam(struct regnode *regnode);
106 void regnode_topo_unlock(void);
107 void regnode_topo_xlock(void);
108 void regnode_topo_slock(void);
109
110 int regnode_enable(struct regnode *regnode);
111 int regnode_disable(struct regnode *regnode);
112 int regnode_stop(struct regnode *regnode, int depth);
113 int regnode_status(struct regnode *regnode, int *status);
114 int regnode_get_voltage(struct regnode *regnode, int *uvolt);
115 int regnode_set_voltage(struct regnode *regnode, int min_uvolt, int max_uvolt);
116 #ifdef FDT
117 phandle_t regnode_get_ofw_node(struct regnode *regnode);
118 #endif
119
120 /* Consumers interface. */
121 int regulator_get_by_name(device_t cdev, const char *name,
122      regulator_t *regulator);
123 int regulator_get_by_id(device_t cdev, device_t pdev, intptr_t id,
124     regulator_t *regulator);
125 int regulator_release(regulator_t regulator);
126 const char *regulator_get_name(regulator_t regulator);
127 int regulator_enable(regulator_t reg);
128 int regulator_disable(regulator_t reg);
129 int regulator_stop(regulator_t reg);
130 int regulator_status(regulator_t reg, int *status);
131 int regulator_get_voltage(regulator_t reg, int *uvolt);
132 int regulator_set_voltage(regulator_t reg, int min_uvolt, int max_uvolt);
133
134 #ifdef FDT
135 int regulator_get_by_ofw_property(device_t dev, phandle_t node, char *name,
136     regulator_t *reg);
137 int regulator_parse_ofw_stdparam(device_t dev, phandle_t node,
138     struct regnode_init_def *def);
139 #endif
140
141 /* Utility functions */
142 int regulator_range_volt_to_sel8(struct regulator_range *ranges, int nranges,
143     int min_uvolt, int max_uvolt, uint8_t *out_sel);
144 int regulator_range_sel8_to_volt(struct regulator_range *ranges, int nranges,
145    uint8_t sel, int *volt);
146
147 #endif /* _DEV_EXTRES_REGULATOR_H_ */