geodereg.h revision 1.2 1 /* $NetBSD: geodereg.h,v 1.2 2005/09/22 18:57:39 dyoung Exp $ */
2
3 /*-
4 * Copyright (c) 2005 David Young. All rights reserved.
5 *
6 * This code was written by David Young.
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 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by David Young.
19 * 4. The name of David Young may not be used to endorse or promote
20 * products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
27 * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
34 * OF SUCH DAMAGE.
35 */
36
37 /*
38 * Register definitions for the AMD Geode SC1100.
39 */
40
41 #ifndef _I386_PCI_GEODEREG_H_
42 #define _I386_PCI_GEODEREG_H_
43
44 /* Macros for bit twiddling. */
45
46 #ifndef _BIT_TWIDDLE
47 #define _BIT_TWIDDLE
48 /* nth bit, BIT(0) == 0x1. */
49 #define BIT(n) (((n) == 32) ? 0 : ((u_int32_t) 1 << (n)))
50
51 /* bits m through n, m < n. */
52 #define BITS(m, n) ((BIT(MAX((m), (n)) + 1) - 1) ^ (BIT(MIN((m), (n))) - 1))
53
54 /* find least significant bit that is set */
55 #define LOWEST_SET_BIT(x) ((((x) - 1) & (x)) ^ (x))
56
57 /* for x a power of two and p a non-negative integer, is x a greater power than 2**p? */
58 #define GTEQ_POWER(x, p) (((u_long)(x) >> (p)) != 0)
59
60 #define MASK_TO_SHIFT2(m) (GTEQ_POWER(LOWEST_SET_BIT((m)), 1) ? 1 : 0)
61
62 #define MASK_TO_SHIFT4(m) \
63 (GTEQ_POWER(LOWEST_SET_BIT((m)), 2) \
64 ? 2 + MASK_TO_SHIFT2((m) >> 2) \
65 : MASK_TO_SHIFT2((m)))
66
67 #define MASK_TO_SHIFT8(m) \
68 (GTEQ_POWER(LOWEST_SET_BIT((m)), 4) \
69 ? 4 + MASK_TO_SHIFT4((m) >> 4) \
70 : MASK_TO_SHIFT4((m)))
71
72 #define MASK_TO_SHIFT16(m) \
73 (GTEQ_POWER(LOWEST_SET_BIT((m)), 8) \
74 ? 8 + MASK_TO_SHIFT8((m) >> 8) \
75 : MASK_TO_SHIFT8((m)))
76
77 #define MASK_TO_SHIFT(m) \
78 (GTEQ_POWER(LOWEST_SET_BIT((m)), 16) \
79 ? 16 + MASK_TO_SHIFT16((m) >> 16) \
80 : MASK_TO_SHIFT16((m)))
81
82 #define MASK_AND_RSHIFT(x, mask) (((x) & (mask)) >> MASK_TO_SHIFT(mask))
83 #define LSHIFT(x, mask) ((x) << MASK_TO_SHIFT(mask))
84 #define MASK_AND_REPLACE(reg, val, mask) ((reg & ~mask) | LSHIFT(val, mask))
85 #define PRESHIFT(m) MASK_AND_RSHIFT((m), (m))
86
87 #endif /* _BIT_TWIDDLE */
88
89 /* AMD Geode SC1100 X-Bus PCI Configuration Register: General
90 * Configuration Block Scratchpad. Set to 0x00000000 after chip reset.
91 * The BIOS writes the base address of the General Configuration
92 * Block to this register.
93 */
94 #define SC1100_XBUS_CBA_SCRATCHPAD 0x64
95
96 #define SC1100_GCB_SIZE 64
97
98 /* watchdog timeout register, 16 bits. */
99 #define SC1100_GCB_WDTO 0x00
100
101 /* Watchdog configuration register, 16 bits. */
102 #define SC1100_GCB_WDCNFG 0x02
103 #define SC1100_WDCNFG_RESERVED BITS(15,9) /* write as read */
104
105 /* 32kHz clock power-down, 0: clock is enabled, 1: clock is disabled. */
106 #define SC1100_WDCNFG_WD32KPD BIT(8)
107
108 /* Watchdog event type 1, and type 2
109 *
110 * 00: no action (default after POR# is asserted)
111 * 01: interrupt
112 * 10: SMI
113 * 11: system reset
114 */
115 #define SC1100_WDCNFG_WDTYPE2_MASK BITS(7,6)
116 #define SC1100_WDCNFG_WDTYPE1_MASK BITS(5,4)
117
118 #define SC1100_WDCNFG_WDTYPE2_NOACTION LSHIFT(0, SC1100_WDCNFG_WDTYPE2_MASK)
119 #define SC1100_WDCNFG_WDTYPE2_INTERRUPT LSHIFT(1, SC1100_WDCNFG_WDTYPE2_MASK)
120 #define SC1100_WDCNFG_WDTYPE2_SMI LSHIFT(2, SC1100_WDCNFG_WDTYPE2_MASK)
121 #define SC1100_WDCNFG_WDTYPE2_RESET LSHIFT(3, SC1100_WDCNFG_WDTYPE2_MASK)
122
123 #define SC1100_WDCNFG_WDTYPE1_NOACTION LSHIFT(0, SC1100_WDCNFG_WDTYPE1_MASK)
124 #define SC1100_WDCNFG_WDTYPE1_INTERRUPT LSHIFT(1, SC1100_WDCNFG_WDTYPE1_MASK)
125 #define SC1100_WDCNFG_WDTYPE1_SMI LSHIFT(2, SC1100_WDCNFG_WDTYPE1_MASK)
126 #define SC1100_WDCNFG_WDTYPE1_RESET LSHIFT(3, SC1100_WDCNFG_WDTYPE1_MASK)
127
128 /* Watchdog timer prescaler
129 *
130 * The prescaler divisor is 2**WDPRES. 1110 (0xe) and 1111 (0xf) are
131 * reserved values.
132 */
133 #define SC1100_WDCNFG_WDPRES_MASK BITS(3,0)
134 #define SC1100_WDCNFG_WDPRES_MAX 0xd
135
136 /* Watchdog status register, 8 bits. */
137 #define SC1100_GCB_WDSTS 0x04
138 #define SC1100_WDSTS_RESERVED BIT(7,4) /* write as read */
139 /* Set to 1 when watchdog reset is asserted. Read-only. Reset either by
140 * POR# (power-on reset) or by writing 0 to WDOVF.
141 */
142 #define SC1100_WDSTS_WDRST BIT(3)
143 /* Set to 1 when watchdog SMI is asserted. Read-only. Reset either by
144 * POR# (power-on reset) or by writing 0 to WDOVF.
145 */
146 #define SC1100_WDSTS_WDSMI BIT(2)
147 /* Set to 1 when watchdog interrupt is asserted. Read-only. Reset either by
148 * POR# (power-on reset) or by writing 0 to WDOVF.
149 */
150 #define SC1100_WDSTS_WDINT BIT(1)
151 /* Set to 1 when watchdog overflow is asserted. Reset either by
152 * POR# (power-on reset) or by writing 1 to this bit.
153 */
154 #define SC1100_WDSTS_WDOVF BIT(0)
155
156 /*
157 * Helpful constants
158 */
159
160 /* maximum watchdog interval in seconds */
161 #define SC1100_WDIVL_MAX ((1 << SC1100_WDCNFG_WDPRES_MAX) * \
162 UINT16_MAX / SC1100_WDCLK_HZ)
163 /* watchdog clock rate in Hertz */
164 #define SC1100_WDCLK_HZ 32000
165
166 #endif /* _I386_PCI_GEODEREG_H_ */
167