xref: /netbsd-src/sys/external/bsd/drm2/include/linux/regulator/consumer.h (revision d320d609f9b889775058c531a99b0e64b3387265)
1 /*	$NetBSD: consumer.h,v 1.5 2018/11/19 10:48:59 maya Exp $	*/
2 
3 /*-
4  * Copyright (c) 2018 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Taylor R. Campbell.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef	_LINUX_REGULATOR_CONSUMER_H_
33 #define	_LINUX_REGULATOR_CONSUMER_H_
34 
35 #ifdef _KERNEL_OPT
36 #include "opt_fdt.h"
37 #endif
38 
39 #ifdef FDT
40 
41 #include <machine/limits.h>
42 #include <dev/fdt/fdtvar.h>
43 
44 struct regulator {
45 	struct fdtbus_regulator	regulator;
46 };
47 
48 static inline int
regulator_get_voltage(struct regulator * reg)49 regulator_get_voltage(struct regulator *reg)
50 {
51 	unsigned uvolt;
52 	int error;
53 
54 	error = fdtbus_regulator_get_voltage(&reg->regulator, &uvolt);
55 	if (error) {
56 		/* XXX errno NetBSD->Linux */
57 		KASSERTMSG(error > 0, "negative error: %d", error);
58 		return -error;
59 	}
60 
61 	KASSERTMSG(uvolt <= INT_MAX, "high voltage: %u uV", uvolt);
62 	return (int)uvolt;
63 }
64 
65 static inline int
regulator_set_voltage(struct regulator * reg,int min_uvolt,int max_uvolt)66 regulator_set_voltage(struct regulator *reg, int min_uvolt, int max_uvolt)
67 {
68 
69 	if (min_uvolt < 0 || max_uvolt < 0)
70 		return -EINVAL;
71 
72 	/* XXX errno NetBSD->Linux */
73 	return -fdtbus_regulator_set_voltage(&reg->regulator, min_uvolt,
74 	    max_uvolt);
75 }
76 
77 #else
78 
79 struct regulator;
80 
81 static inline int
regulator_get_voltage(struct regulator * reg)82 regulator_get_voltage(struct regulator *reg)
83 {
84 	panic("no voltage regulators here");
85 }
86 
87 static inline int
regulator_set_voltage(struct regulator * reg,int min_uvolt,int max_uvolt)88 regulator_set_voltage(struct regulator *reg, int min_uvolt, int max_uvolt)
89 {
90 	panic("no voltage regulators here");
91 }
92 
93 
94 #endif
95 
96 #endif	/* _LINUX_REGULATOR_CONSUMER_H_ */
97