xref: /netbsd-src/sys/dev/fdt/syscon.h (revision a319d981354fb3b19992225d60831cb4b4002029)
1*a319d981Sskrll /* $NetBSD: syscon.h,v 1.2 2020/12/11 09:40:28 skrll Exp $ */
25b0333ebSjmcneill 
35b0333ebSjmcneill /*-
45b0333ebSjmcneill  * Copyright (c) 2018 Jared McNeill <jmcneill@invisible.ca>
55b0333ebSjmcneill  * All rights reserved.
65b0333ebSjmcneill  *
75b0333ebSjmcneill  * Redistribution and use in source and binary forms, with or without
85b0333ebSjmcneill  * modification, are permitted provided that the following conditions
95b0333ebSjmcneill  * are met:
105b0333ebSjmcneill  * 1. Redistributions of source code must retain the above copyright
115b0333ebSjmcneill  *    notice, this list of conditions and the following disclaimer.
125b0333ebSjmcneill  * 2. Redistributions in binary form must reproduce the above copyright
135b0333ebSjmcneill  *    notice, this list of conditions and the following disclaimer in the
145b0333ebSjmcneill  *    documentation and/or other materials provided with the distribution.
155b0333ebSjmcneill  *
165b0333ebSjmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
175b0333ebSjmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
185b0333ebSjmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
195b0333ebSjmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
205b0333ebSjmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
215b0333ebSjmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
225b0333ebSjmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
235b0333ebSjmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
245b0333ebSjmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
255b0333ebSjmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
265b0333ebSjmcneill  * SUCH DAMAGE.
275b0333ebSjmcneill  */
285b0333ebSjmcneill 
29*a319d981Sskrll #ifndef _DEV_FDT_SYSCON_H_
30*a319d981Sskrll #define _DEV_FDT_SYSCON_H_
315b0333ebSjmcneill 
325b0333ebSjmcneill struct syscon {
335b0333ebSjmcneill 	void		*priv;
345b0333ebSjmcneill 
355b0333ebSjmcneill 	void		(*lock)(void *);
365b0333ebSjmcneill 	void		(*unlock)(void *);
375b0333ebSjmcneill 	uint32_t	(*read_4)(void *, bus_size_t);
385b0333ebSjmcneill 	void		(*write_4)(void *, bus_size_t, uint32_t);
395b0333ebSjmcneill };
405b0333ebSjmcneill 
415b0333ebSjmcneill #define	syscon_lock(_syscon)					\
425b0333ebSjmcneill 	(_syscon)->lock((_syscon)->priv)
435b0333ebSjmcneill 
445b0333ebSjmcneill #define	syscon_unlock(_syscon)					\
455b0333ebSjmcneill 	(_syscon)->unlock((_syscon)->priv)
465b0333ebSjmcneill 
475b0333ebSjmcneill #define	syscon_read_4(_syscon, _reg)				\
485b0333ebSjmcneill 	(_syscon)->read_4((_syscon)->priv, (_reg))
495b0333ebSjmcneill 
505b0333ebSjmcneill #define	syscon_write_4(_syscon, _reg, _val)			\
515b0333ebSjmcneill 	(_syscon)->write_4((_syscon)->priv, (_reg), (_val))
525b0333ebSjmcneill 
535b0333ebSjmcneill 
54*a319d981Sskrll #endif /* _DEV_FDT_SYSCON_H_ */
55