Home | History | Annotate | Line # | Download | only in regulator
consumer.h revision 1.4.2.2
      1 /*	$NetBSD: consumer.h,v 1.4.2.2 2018/09/06 06:56:36 pgoyette 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 <dev/fdt/fdtvar.h>
     42 
     43 struct regulator {
     44 	struct fdtbus_regulator	regulator;
     45 };
     46 
     47 static inline int
     48 regulator_get_voltage(struct regulator *reg)
     49 {
     50 	unsigned uvolt;
     51 	int error;
     52 
     53 	error = fdtbus_regulator_get_voltage(&reg->regulator, &uvolt);
     54 	if (error) {
     55 		/* XXX errno NetBSD->Linux */
     56 		KASSERTMSG(error > 0, "negative error: %d", error);
     57 		return -error;
     58 	}
     59 
     60 	KASSERTMSG(uvolt <= INT_MAX, "high voltage: %u uV", uvolt);
     61 	return (int)uvolt;
     62 }
     63 
     64 static inline int
     65 regulator_set_voltage(struct regulator *reg, int min_uvolt, int max_uvolt)
     66 {
     67 
     68 	if (min_uvolt < 0 || max_uvolt < 0)
     69 		return -EINVAL;
     70 
     71 	/* XXX errno NetBSD->Linux */
     72 	return -fdtbus_regulator_set_voltage(&reg->regulator, min_uvolt,
     73 	    max_uvolt);
     74 }
     75 
     76 #else
     77 
     78 struct regulator;
     79 
     80 static inline int
     81 regulator_get_voltage(struct regulator *reg)
     82 {
     83 	panic("no voltage regulators here");
     84 }
     85 
     86 static inline int
     87 regulator_set_voltage(struct regulator *reg, int min_uvolt, int max_uvolt)
     88 {
     89 	panic("no voltage regulators here");
     90 }
     91 
     92 
     93 #endif
     94 
     95 #endif	/* _LINUX_REGULATOR_CONSUMER_H_ */
     96