xref: /netbsd-src/sys/external/bsd/drm2/include/linux/regulator/consumer.h (revision d320d609f9b889775058c531a99b0e64b3387265)
1*d320d609Smaya /*	$NetBSD: consumer.h,v 1.5 2018/11/19 10:48:59 maya Exp $	*/
21ae84735Sriastradh 
31ae84735Sriastradh /*-
41ae84735Sriastradh  * Copyright (c) 2018 The NetBSD Foundation, Inc.
51ae84735Sriastradh  * All rights reserved.
61ae84735Sriastradh  *
71ae84735Sriastradh  * This code is derived from software contributed to The NetBSD Foundation
81ae84735Sriastradh  * by Taylor R. Campbell.
91ae84735Sriastradh  *
101ae84735Sriastradh  * Redistribution and use in source and binary forms, with or without
111ae84735Sriastradh  * modification, are permitted provided that the following conditions
121ae84735Sriastradh  * are met:
131ae84735Sriastradh  * 1. Redistributions of source code must retain the above copyright
141ae84735Sriastradh  *    notice, this list of conditions and the following disclaimer.
151ae84735Sriastradh  * 2. Redistributions in binary form must reproduce the above copyright
161ae84735Sriastradh  *    notice, this list of conditions and the following disclaimer in the
171ae84735Sriastradh  *    documentation and/or other materials provided with the distribution.
181ae84735Sriastradh  *
191ae84735Sriastradh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201ae84735Sriastradh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211ae84735Sriastradh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221ae84735Sriastradh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231ae84735Sriastradh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241ae84735Sriastradh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251ae84735Sriastradh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261ae84735Sriastradh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271ae84735Sriastradh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281ae84735Sriastradh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291ae84735Sriastradh  * POSSIBILITY OF SUCH DAMAGE.
301ae84735Sriastradh  */
311ae84735Sriastradh 
321ae84735Sriastradh #ifndef	_LINUX_REGULATOR_CONSUMER_H_
331ae84735Sriastradh #define	_LINUX_REGULATOR_CONSUMER_H_
341ae84735Sriastradh 
35102da224Sriastradh #ifdef _KERNEL_OPT
365fd863fbSriastradh #include "opt_fdt.h"
37102da224Sriastradh #endif
385fd863fbSriastradh 
395fd863fbSriastradh #ifdef FDT
405fd863fbSriastradh 
41*d320d609Smaya #include <machine/limits.h>
429abf277cSriastradh #include <dev/fdt/fdtvar.h>
439abf277cSriastradh 
445fd863fbSriastradh struct regulator {
455fd863fbSriastradh 	struct fdtbus_regulator	regulator;
465fd863fbSriastradh };
475fd863fbSriastradh 
485fd863fbSriastradh static inline int
regulator_get_voltage(struct regulator * reg)495fd863fbSriastradh regulator_get_voltage(struct regulator *reg)
505fd863fbSriastradh {
515fd863fbSriastradh 	unsigned uvolt;
525fd863fbSriastradh 	int error;
535fd863fbSriastradh 
545fd863fbSriastradh 	error = fdtbus_regulator_get_voltage(&reg->regulator, &uvolt);
555fd863fbSriastradh 	if (error) {
565fd863fbSriastradh 		/* XXX errno NetBSD->Linux */
575fd863fbSriastradh 		KASSERTMSG(error > 0, "negative error: %d", error);
585fd863fbSriastradh 		return -error;
595fd863fbSriastradh 	}
605fd863fbSriastradh 
615fd863fbSriastradh 	KASSERTMSG(uvolt <= INT_MAX, "high voltage: %u uV", uvolt);
629abf277cSriastradh 	return (int)uvolt;
635fd863fbSriastradh }
645fd863fbSriastradh 
655fd863fbSriastradh static inline int
regulator_set_voltage(struct regulator * reg,int min_uvolt,int max_uvolt)665fd863fbSriastradh regulator_set_voltage(struct regulator *reg, int min_uvolt, int max_uvolt)
675fd863fbSriastradh {
685fd863fbSriastradh 
695fd863fbSriastradh 	if (min_uvolt < 0 || max_uvolt < 0)
705fd863fbSriastradh 		return -EINVAL;
715fd863fbSriastradh 
725fd863fbSriastradh 	/* XXX errno NetBSD->Linux */
735fd863fbSriastradh 	return -fdtbus_regulator_set_voltage(&reg->regulator, min_uvolt,
745fd863fbSriastradh 	    max_uvolt);
755fd863fbSriastradh }
765fd863fbSriastradh 
775fd863fbSriastradh #else
785fd863fbSriastradh 
795fd863fbSriastradh struct regulator;
805fd863fbSriastradh 
815fd863fbSriastradh static inline int
regulator_get_voltage(struct regulator * reg)825fd863fbSriastradh regulator_get_voltage(struct regulator *reg)
835fd863fbSriastradh {
845fd863fbSriastradh 	panic("no voltage regulators here");
855fd863fbSriastradh }
865fd863fbSriastradh 
875fd863fbSriastradh static inline int
regulator_set_voltage(struct regulator * reg,int min_uvolt,int max_uvolt)885fd863fbSriastradh regulator_set_voltage(struct regulator *reg, int min_uvolt, int max_uvolt)
895fd863fbSriastradh {
905fd863fbSriastradh 	panic("no voltage regulators here");
915fd863fbSriastradh }
925fd863fbSriastradh 
935fd863fbSriastradh 
945fd863fbSriastradh #endif
955fd863fbSriastradh 
961ae84735Sriastradh #endif	/* _LINUX_REGULATOR_CONSUMER_H_ */
97