]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/extres/regulator/regulator.h
Import to 0.6.1
[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
73 /*
74  * Shorthands for constructing method tables.
75  */
76 #define REGNODEMETHOD           KOBJMETHOD
77 #define REGNODEMETHOD_END       KOBJMETHOD_END
78 #define regnode_method_t        kobj_method_t
79 #define regnode_class_t         kobj_class_t
80 DECLARE_CLASS(regnode_class);
81
82 /* Providers interface. */
83 struct regnode *regnode_create(device_t pdev, regnode_class_t regnode_class,
84     struct regnode_init_def *def);
85 struct regnode *regnode_register(struct regnode *regnode);
86 const char *regnode_get_name(struct regnode *regnode);
87 const char *regnode_get_parent_name(struct regnode *regnode);
88 struct regnode *regnode_get_parent(struct regnode *regnode);
89 int regnode_get_flags(struct regnode *regnode);
90 void *regnode_get_softc(struct regnode *regnode);
91 device_t regnode_get_device(struct regnode *regnode);
92 struct regnode_std_param *regnode_get_stdparam(struct regnode *regnode);
93 void regnode_topo_unlock(void);
94 void regnode_topo_xlock(void);
95 void regnode_topo_slock(void);
96
97 int regnode_enable(struct regnode *regnode);
98 int regnode_disable(struct regnode *regnode);
99 int regnode_stop(struct regnode *regnode, int depth);
100 int regnode_status(struct regnode *regnode, int *status);
101 int regnode_get_voltage(struct regnode *regnode, int *uvolt);
102 int regnode_set_voltage(struct regnode *regnode, int min_uvolt, int max_uvolt);
103 #ifdef FDT
104 phandle_t regnode_get_ofw_node(struct regnode *regnode);
105 #endif
106
107 /* Consumers interface. */
108 int regulator_get_by_name(device_t cdev, const char *name,
109      regulator_t *regulator);
110 int regulator_get_by_id(device_t cdev, device_t pdev, intptr_t id,
111     regulator_t *regulator);
112 int regulator_release(regulator_t regulator);
113 const char *regulator_get_name(regulator_t regulator);
114 int regulator_enable(regulator_t reg);
115 int regulator_disable(regulator_t reg);
116 int regulator_stop(regulator_t reg);
117 int regulator_status(regulator_t reg, int *status);
118 int regulator_get_voltage(regulator_t reg, int *uvolt);
119 int regulator_set_voltage(regulator_t reg, int min_uvolt, int max_uvolt);
120
121 #ifdef FDT
122 int regulator_get_by_ofw_property(device_t dev, char *name,  regulator_t *reg);
123 int regulator_parse_ofw_stdparam(device_t dev, phandle_t node,
124     struct regnode_init_def *def);
125 #endif
126
127 #endif /* _DEV_EXTRES_REGULATOR_H_ */