xref: /openbsd/sys/arch/sh/include/devreg.h (revision d874cce4)
1 /*	$OpenBSD: devreg.h,v 1.3 2008/06/26 05:42:12 ray Exp $	*/
2 /*	$NetBSD: devreg.h,v 1.5 2006/01/21 04:57:07 uwe Exp $	*/
3 
4 /*-
5  * Copyright (c) 2002 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef _SH_DEVREG_H_
31 #define	_SH_DEVREG_H_
32 /*
33  * SH embedded device register defines.
34  */
35 
36 /*
37  * Access method
38  */
39 #define	_reg_read_1(a)		(*(volatile uint8_t *)((vaddr_t)(a)))
40 #define	_reg_read_2(a)		(*(volatile uint16_t *)((vaddr_t)(a)))
41 #define	_reg_read_4(a)		(*(volatile uint32_t *)((vaddr_t)(a)))
42 #define	_reg_write_1(a, v)						\
43 	(*(volatile uint8_t *)(a)  = (uint8_t)(v))
44 #define	_reg_write_2(a, v)						\
45 	(*(volatile uint16_t *)(a) = (uint16_t)(v))
46 #define	_reg_write_4(a, v)						\
47 	(*(volatile uint32_t *)(a) = (uint32_t)(v))
48 #define	_reg_bset_1(a, v)						\
49 	(*(volatile uint8_t *)(a)  |= (uint8_t)(v))
50 #define	_reg_bset_2(a, v)						\
51 	(*(volatile uint16_t *)(a) |= (uint16_t)(v))
52 #define	_reg_bset_4(a, v)						\
53 	(*(volatile uint32_t *)(a) |= (uint32_t)(v))
54 #define	_reg_bclr_1(a, v)						\
55 	(*(volatile uint8_t *)(a)  &= ~(uint8_t)(v))
56 #define	_reg_bclr_2(a, v)						\
57 	(*(volatile uint16_t *)(a) &= ~(uint16_t)(v))
58 #define	_reg_bclr_4(a, v)						\
59 	(*(volatile uint32_t *)(a) &= ~(uint32_t)(v))
60 
61 /*
62  * Register address.
63  */
64 #if defined(SH3) && defined(SH4)
65 #define	SH_(x)		__sh_ ## x
66 #elif defined(SH3)
67 #define	SH_(x)		SH3_ ## x
68 #elif defined(SH4)
69 #define	SH_(x)		SH4_ ## x
70 #endif
71 
72 #ifndef _LOCORE
73 /* Initialize register address for SH3 && SH4 kernel. */
74 void sh_devreg_init(void);
75 #endif
76 #endif /* !_SH_DEVREG_H_ */
77