xref: /freebsd/sys/dev/pwm/pwmbus.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
10af7a9a4SIan Lepore /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
30af7a9a4SIan Lepore  *
40af7a9a4SIan Lepore  * Copyright (c) 2019 Ian Lepore <ian@FreeBSD.org>
50af7a9a4SIan Lepore  *
60af7a9a4SIan Lepore  * Redistribution and use in source and binary forms, with or without
70af7a9a4SIan Lepore  * modification, are permitted provided that the following conditions
80af7a9a4SIan Lepore  * are met:
90af7a9a4SIan Lepore  * 1. Redistributions of source code must retain the above copyright
100af7a9a4SIan Lepore  *    notice, this list of conditions and the following disclaimer.
110af7a9a4SIan Lepore  * 2. Redistributions in binary form must reproduce the above copyright
120af7a9a4SIan Lepore  *    notice, this list of conditions and the following disclaimer in the
130af7a9a4SIan Lepore  *    documentation and/or other materials provided with the distribution.
140af7a9a4SIan Lepore  *
150af7a9a4SIan Lepore  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
160af7a9a4SIan Lepore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
170af7a9a4SIan Lepore  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
180af7a9a4SIan Lepore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
190af7a9a4SIan Lepore  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
200af7a9a4SIan Lepore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
210af7a9a4SIan Lepore  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
220af7a9a4SIan Lepore  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
230af7a9a4SIan Lepore  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
240af7a9a4SIan Lepore  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
250af7a9a4SIan Lepore  * SUCH DAMAGE.
260af7a9a4SIan Lepore  */
270af7a9a4SIan Lepore 
280af7a9a4SIan Lepore #ifndef _PWMBUS_H_
290af7a9a4SIan Lepore #define _PWMBUS_H_
300af7a9a4SIan Lepore 
31b43e2c8bSIan Lepore struct pwmbus_softc {
32b43e2c8bSIan Lepore 	device_t	dev;
33b43e2c8bSIan Lepore 	u_int		nchannels;
34b43e2c8bSIan Lepore };
35b43e2c8bSIan Lepore 
360af7a9a4SIan Lepore struct pwmbus_ivars {
370af7a9a4SIan Lepore 	u_int	pi_channel;
380af7a9a4SIan Lepore };
390af7a9a4SIan Lepore 
400af7a9a4SIan Lepore enum {
410af7a9a4SIan Lepore 	PWMBUS_IVAR_CHANNEL,	/* Channel used by child dev */
420af7a9a4SIan Lepore };
430af7a9a4SIan Lepore 
440af7a9a4SIan Lepore #define PWMBUS_ACCESSOR(A, B, T)					\
450af7a9a4SIan Lepore static inline int							\
460af7a9a4SIan Lepore pwmbus_get_ ## A(device_t dev, T *t)					\
470af7a9a4SIan Lepore {									\
480af7a9a4SIan Lepore 	return BUS_READ_IVAR(device_get_parent(dev), dev,		\
490af7a9a4SIan Lepore 	    PWMBUS_IVAR_ ## B, (uintptr_t *) t);			\
500af7a9a4SIan Lepore }									\
510af7a9a4SIan Lepore static inline int							\
520af7a9a4SIan Lepore pwmbus_set_ ## A(device_t dev, T t)					\
530af7a9a4SIan Lepore {									\
540af7a9a4SIan Lepore 	return BUS_WRITE_IVAR(device_get_parent(dev), dev,		\
550af7a9a4SIan Lepore 	    PWMBUS_IVAR_ ## B, (uintptr_t) t);				\
560af7a9a4SIan Lepore }
570af7a9a4SIan Lepore 
580af7a9a4SIan Lepore PWMBUS_ACCESSOR(channel, CHANNEL, u_int)
590af7a9a4SIan Lepore 
60b43e2c8bSIan Lepore #ifdef FDT
61b43e2c8bSIan Lepore #define	PWMBUS_FDT_PNP_INFO(t)	FDTCOMPAT_PNP_INFO(t, pwmbus)
62b43e2c8bSIan Lepore #else
63b43e2c8bSIan Lepore #define	PWMBUS_FDT_PNP_INFO(t)
64b43e2c8bSIan Lepore #endif
65b43e2c8bSIan Lepore 
660af7a9a4SIan Lepore extern driver_t   pwmbus_driver;
670af7a9a4SIan Lepore extern driver_t   ofw_pwmbus_driver;
680af7a9a4SIan Lepore 
690af7a9a4SIan Lepore #endif /* _PWMBUS_H_ */
70