pciide_opti_reg.h revision 1.2.8.2 1 1.2.8.2 bouyer /* $NetBSD: pciide_opti_reg.h,v 1.2.8.2 2000/11/20 11:42:35 bouyer Exp $ */
2 1.2.8.2 bouyer
3 1.2.8.2 bouyer /*-
4 1.2.8.2 bouyer * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.2.8.2 bouyer * All rights reserved.
6 1.2.8.2 bouyer *
7 1.2.8.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.2.8.2 bouyer * by Steve C. Woodford.
9 1.2.8.2 bouyer *
10 1.2.8.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.2.8.2 bouyer * modification, are permitted provided that the following conditions
12 1.2.8.2 bouyer * are met:
13 1.2.8.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.2.8.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.2.8.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.8.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.2.8.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.2.8.2 bouyer * 3. All advertising materials mentioning features or use of this software
19 1.2.8.2 bouyer * must display the following acknowledgement:
20 1.2.8.2 bouyer * This product includes software developed by the NetBSD
21 1.2.8.2 bouyer * Foundation, Inc. and its contributors.
22 1.2.8.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.8.2 bouyer * contributors may be used to endorse or promote products derived
24 1.2.8.2 bouyer * from this software without specific prior written permission.
25 1.2.8.2 bouyer *
26 1.2.8.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.8.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.8.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.8.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.8.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.8.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.8.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.8.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.8.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.8.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.8.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
37 1.2.8.2 bouyer */
38 1.2.8.2 bouyer
39 1.2.8.2 bouyer /*
40 1.2.8.2 bouyer * Register definitions for OPTi PCIIDE controllers based on
41 1.2.8.2 bouyer * their 82c621 chip.
42 1.2.8.2 bouyer */
43 1.2.8.2 bouyer
44 1.2.8.2 bouyer /* IDE Initialization Control Register */
45 1.2.8.2 bouyer #define OPTI_REG_INIT_CONTROL 0x40
46 1.2.8.2 bouyer #define OPTI_INIT_CONTROL_MODE_PIO_0 0
47 1.2.8.2 bouyer #define OPTI_INIT_CONTROL_MODE_PIO_1 2
48 1.2.8.2 bouyer #define OPTI_INIT_CONTROL_MODE_PIO_2 1
49 1.2.8.2 bouyer #define OPTI_INIT_CONTROL_MODE_PIO_3 3
50 1.2.8.2 bouyer #define OPTI_INIT_CONTROL_ADDR_RELOC (1u << 2)
51 1.2.8.2 bouyer #define OPTI_INIT_CONTROL_CH2_ENABLE 0
52 1.2.8.2 bouyer #define OPTI_INIT_CONTROL_CH2_DISABLE (1u << 3)
53 1.2.8.2 bouyer #define OPTI_INIT_CONTROL_FIFO_16 0
54 1.2.8.2 bouyer #define OPTI_INIT_CONTROL_FIFO_32 (1u << 5)
55 1.2.8.2 bouyer #define OPTI_INIT_CONTROL_FIFO_REQ_32 0
56 1.2.8.2 bouyer #define OPTI_INIT_CONTROL_FIFO_REQ_30 (1u << 6)
57 1.2.8.2 bouyer #define OPTI_INIT_CONTROL_FIFO_REQ_28 (2u << 6)
58 1.2.8.2 bouyer #define OPTI_INIT_CONTROL_FIFO_REQ_26 (3u << 6)
59 1.2.8.2 bouyer
60 1.2.8.2 bouyer /* IDE Enhanced Features Register */
61 1.2.8.2 bouyer #define OPTI_REG_ENH_FEAT 0x42
62 1.2.8.2 bouyer #define OPTI_ENH_FEAT_X111_ENABLE (1u << 1)
63 1.2.8.2 bouyer #define OPTI_ENH_FEAT_CONCURRENT_MAST (1u << 2)
64 1.2.8.2 bouyer #define OPTI_ENH_FEAT_PCI_INVALIDATE (1u << 3)
65 1.2.8.2 bouyer #define OPTI_ENH_FEAT_IDE_CONCUR (1u << 4)
66 1.2.8.2 bouyer #define OPTI_ENH_FEAT_SLAVE_FIFO_ISA (1u << 5)
67 1.2.8.2 bouyer
68 1.2.8.2 bouyer /* IDE Enhanced Mode Register */
69 1.2.8.2 bouyer #define OPTI_REG_ENH_MODE 0x43
70 1.2.8.2 bouyer #define OPTI_ENH_MODE_MASK(c,d) (3u << (((c) * 4) + ((d) * 2)))
71 1.2.8.2 bouyer #define OPTI_ENH_MODE_USE_TIMING(c,d) 0
72 1.2.8.2 bouyer #define OPTI_ENH_MODE(c,d,m) ((m) << (((c) * 4) + ((d) * 2)))
73 1.2.8.2 bouyer
74 1.2.8.2 bouyer /* Timing registers */
75 1.2.8.2 bouyer #define OPTI_REG_READ_CYCLE_TIMING 0x00
76 1.2.8.2 bouyer #define OPTI_REG_WRITE_CYCLE_TIMING 0x01
77 1.2.8.2 bouyer #define OPTI_RECOVERY_TIME_SHIFT 0
78 1.2.8.2 bouyer #define OPTI_PULSE_WIDTH_SHIFT 4
79 1.2.8.2 bouyer
80 1.2.8.2 bouyer /*
81 1.2.8.2 bouyer * Control register.
82 1.2.8.2 bouyer */
83 1.2.8.2 bouyer #define OPTI_REG_CONTROL 0x03
84 1.2.8.2 bouyer #define OPTI_CONTROL_DISABLE 0x11
85 1.2.8.2 bouyer #define OPTI_CONTROL_ENABLE 0x95
86 1.2.8.2 bouyer
87 1.2.8.2 bouyer /* Strap register */
88 1.2.8.2 bouyer #define OPTI_REG_STRAP 0x05
89 1.2.8.2 bouyer #define OPTI_STRAP_PCI_SPEED_MASK 0x1u
90 1.2.8.2 bouyer #define OPTI_STRAP_PCI_33 0
91 1.2.8.2 bouyer #define OPTI_STRAP_PCI_25 1
92 1.2.8.2 bouyer
93 1.2.8.2 bouyer /* Miscellaneous register */
94 1.2.8.2 bouyer #define OPTI_REG_MISC 0x06
95 1.2.8.2 bouyer #define OPTI_MISC_INDEX(d) ((unsigned)(d))
96 1.2.8.2 bouyer #define OPTI_MISC_INDEX_MASK 0x01u
97 1.2.8.2 bouyer #define OPTI_MISC_DELAY_MASK 0x07u
98 1.2.8.2 bouyer #define OPTI_MISC_DELAY_SHIFT 1
99 1.2.8.2 bouyer #define OPTI_MISC_ADDR_SETUP_MASK 0x3u
100 1.2.8.2 bouyer #define OPTI_MISC_ADDR_SETUP_SHIFT 4
101 1.2.8.2 bouyer #define OPTI_MISC_READ_PREFETCH_ENABLE (1u << 6)
102 1.2.8.2 bouyer #define OPTI_MISC_ADDR_SETUP_MASK 0x3u
103 1.2.8.2 bouyer #define OPTI_MISC_WRITE_MASK 0x7fu
104 1.2.8.2 bouyer
105 1.2.8.2 bouyer
106 1.2.8.2 bouyer /*
107 1.2.8.2 bouyer * Inline functions for accessing the timing registers of the
108 1.2.8.2 bouyer * OPTi controller.
109 1.2.8.2 bouyer *
110 1.2.8.2 bouyer * These *MUST* disable interrupts as they need atomic access to
111 1.2.8.2 bouyer * certain magic registers. Failure to adhere to this *will*
112 1.2.8.2 bouyer * break things in subtle ways if the wdc registers are accessed
113 1.2.8.2 bouyer * by an interrupt routine while this magic sequence is executing.
114 1.2.8.2 bouyer */
115 1.2.8.2 bouyer static __inline__ u_int8_t
116 1.2.8.2 bouyer opti_read_config(struct channel_softc *chp, int reg)
117 1.2.8.2 bouyer {
118 1.2.8.2 bouyer u_int8_t rv;
119 1.2.8.2 bouyer int s = splhigh();
120 1.2.8.2 bouyer
121 1.2.8.2 bouyer /* Two consecutive 16-bit reads from register #1 (0x1f1/0x171) */
122 1.2.8.2 bouyer (void) bus_space_read_2(chp->cmd_iot, chp->cmd_ioh, wd_features);
123 1.2.8.2 bouyer (void) bus_space_read_2(chp->cmd_iot, chp->cmd_ioh, wd_features);
124 1.2.8.2 bouyer
125 1.2.8.2 bouyer /* Followed by an 8-bit write of 0x3 to register #2 */
126 1.2.8.2 bouyer bus_space_write_1(chp->cmd_iot, chp->cmd_ioh, wd_seccnt, 0x03u);
127 1.2.8.2 bouyer
128 1.2.8.2 bouyer /* Now we can read the required register */
129 1.2.8.2 bouyer rv = bus_space_read_1(chp->cmd_iot, chp->cmd_ioh, reg);
130 1.2.8.2 bouyer
131 1.2.8.2 bouyer /* Restore the real registers */
132 1.2.8.2 bouyer bus_space_write_1(chp->cmd_iot, chp->cmd_ioh, wd_seccnt, 0x83u);
133 1.2.8.2 bouyer
134 1.2.8.2 bouyer splx(s);
135 1.2.8.2 bouyer
136 1.2.8.2 bouyer return rv;
137 1.2.8.2 bouyer }
138 1.2.8.2 bouyer
139 1.2.8.2 bouyer static __inline__ void
140 1.2.8.2 bouyer opti_write_config(struct channel_softc *chp, int reg, u_int8_t val)
141 1.2.8.2 bouyer {
142 1.2.8.2 bouyer int s = splhigh();
143 1.2.8.2 bouyer
144 1.2.8.2 bouyer /* Two consecutive 16-bit reads from register #1 (0x1f1/0x171) */
145 1.2.8.2 bouyer (void) bus_space_read_2(chp->cmd_iot, chp->cmd_ioh, wd_features);
146 1.2.8.2 bouyer (void) bus_space_read_2(chp->cmd_iot, chp->cmd_ioh, wd_features);
147 1.2.8.2 bouyer
148 1.2.8.2 bouyer /* Followed by an 8-bit write of 0x3 to register #2 */
149 1.2.8.2 bouyer bus_space_write_1(chp->cmd_iot, chp->cmd_ioh, wd_seccnt, 0x03u);
150 1.2.8.2 bouyer
151 1.2.8.2 bouyer /* Now we can write the required register */
152 1.2.8.2 bouyer bus_space_write_1(chp->cmd_iot, chp->cmd_ioh, reg, val);
153 1.2.8.2 bouyer
154 1.2.8.2 bouyer /* Restore the real registers */
155 1.2.8.2 bouyer bus_space_write_1(chp->cmd_iot, chp->cmd_ioh, wd_seccnt, 0x83u);
156 1.2.8.2 bouyer
157 1.2.8.2 bouyer splx(s);
158 1.2.8.2 bouyer }
159 1.2.8.2 bouyer
160 1.2.8.2 bouyer /*
161 1.2.8.2 bouyer * These are the timing register values for the various IDE modes
162 1.2.8.2 bouyer * supported by the OPTi chip. The first index of the two-dimensional
163 1.2.8.2 bouyer * arrays is used for a 33MHz PCIbus, the second for a 25MHz PCIbus.
164 1.2.8.2 bouyer */
165 1.2.8.2 bouyer static u_int8_t opti_tim_cp[2][8] = { /* Command Pulse */
166 1.2.8.2 bouyer {5, 4, 3, 2, 2, 7, 2, 2},
167 1.2.8.2 bouyer {4, 3, 2, 2, 1, 5, 2, 1}
168 1.2.8.2 bouyer };
169 1.2.8.2 bouyer
170 1.2.8.2 bouyer static u_int8_t opti_tim_rt[2][8] = { /* Recovery Time */
171 1.2.8.2 bouyer {9, 4, 0, 0, 0, 6, 0, 0},
172 1.2.8.2 bouyer {6, 2, 0, 0, 0, 4, 0, 0}
173 1.2.8.2 bouyer };
174 1.2.8.2 bouyer
175 1.2.8.2 bouyer static u_int8_t opti_tim_as[2][8] = { /* Address Setup */
176 1.2.8.2 bouyer {2, 1, 1, 1, 0, 0, 0, 0},
177 1.2.8.2 bouyer {1, 1, 0, 0, 0, 0, 0, 0}
178 1.2.8.2 bouyer };
179 1.2.8.2 bouyer
180 1.2.8.2 bouyer static u_int8_t opti_tim_em[8] = { /* Enhanced Mode */
181 1.2.8.2 bouyer 0, 0, 0, 1, 2, 0, 1 ,2
182 1.2.8.2 bouyer };
183