mq200machdep.c revision 1.1 1 1.1 takemura /* $NetBSD: mq200machdep.c,v 1.1 2001/03/25 13:06:53 takemura Exp $ */
2 1.1 takemura
3 1.1 takemura /*-
4 1.1 takemura * Copyright (c) 2001 TAKEMURA Shin
5 1.1 takemura * All rights reserved.
6 1.1 takemura *
7 1.1 takemura * Redistribution and use in source and binary forms, with or without
8 1.1 takemura * modification, are permitted provided that the following conditions
9 1.1 takemura * are met:
10 1.1 takemura * 1. Redistributions of source code must retain the above copyright
11 1.1 takemura * notice, this list of conditions and the following disclaimer.
12 1.1 takemura * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 takemura * notice, this list of conditions and the following disclaimer in the
14 1.1 takemura * documentation and/or other materials provided with the distribution.
15 1.1 takemura * 3. The name of the author may not be used to endorse or promote products
16 1.1 takemura * derived from this software without specific prior written permission.
17 1.1 takemura *
18 1.1 takemura * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 1.1 takemura * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 1.1 takemura * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 1.1 takemura * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 1.1 takemura * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 1.1 takemura * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 1.1 takemura * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 1.1 takemura * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 1.1 takemura * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.1 takemura * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.1 takemura * SUCH DAMAGE.
29 1.1 takemura *
30 1.1 takemura */
31 1.1 takemura
32 1.1 takemura #ifdef _KERNEL
33 1.1 takemura #include <sys/param.h>
34 1.1 takemura #include <sys/kernel.h>
35 1.1 takemura #include <sys/systm.h>
36 1.1 takemura #include <sys/device.h>
37 1.1 takemura #else
38 1.1 takemura #include <stdio.h>
39 1.1 takemura #endif
40 1.1 takemura #include <sys/types.h>
41 1.1 takemura
42 1.1 takemura #include <machine/platid.h>
43 1.1 takemura #include <machine/platid_mask.h>
44 1.1 takemura
45 1.1 takemura #include "opt_mq200.h"
46 1.1 takemura #include "mq200var.h"
47 1.1 takemura #include "mq200reg.h"
48 1.1 takemura #include "mq200priv.h"
49 1.1 takemura
50 1.1 takemura #if MQ200_SETUPREGS
51 1.1 takemura #define OP_(n) (((n) << 2) | 1)
52 1.1 takemura #define OP_END OP_(1)
53 1.1 takemura #define OP_MASK OP_(2)
54 1.1 takemura #define OP_LOADPLLPARAM OP_(3)
55 1.1 takemura #define OP_LOADFROMREG OP_(4)
56 1.1 takemura #define OP_STORETOREG OP_(5)
57 1.1 takemura #define OP_LOADIMM OP_(6)
58 1.1 takemura #define OP_OR OP_(7)
59 1.1 takemura
60 1.1 takemura static void mq200_setupregs(struct mq200_softc *sc, u_int32_t *ops);
61 1.1 takemura
62 1.1 takemura static u_int32_t mcr530_init_ops[] = {
63 1.1 takemura MQ200_PMCR, 0, /* power management control */
64 1.1 takemura MQ200_DCMISCR, MQ200_DCMISC_OSC_ENABLE |
65 1.1 takemura MQ200_DCMISC_FASTPOWSEQ_DISABLE |
66 1.1 takemura MQ200_DCMISC_OSCFREQ_12_25,
67 1.1 takemura OP_END
68 1.1 takemura };
69 1.1 takemura #endif /* MQ200_SETUPREGS */
70 1.1 takemura
71 1.1 takemura static struct mq200_clock_setting mcr530_clocks[] = {
72 1.1 takemura /* CRT: off FP: off */
73 1.1 takemura {
74 1.1 takemura MQ200_CLOCK_PLL1, /* memory clock */
75 1.1 takemura MQ200_CLOCK_PLL1, /* graphics engine clock */
76 1.1 takemura {
77 1.1 takemura 0, /* GC1(CRT) clock */
78 1.1 takemura 0, /* GC2(FP) clock */
79 1.1 takemura },
80 1.1 takemura 30000, /* PLL1 30MHz */
81 1.1 takemura 0, /* PLL2 disable */
82 1.1 takemura 0, /* PLL3 disable */
83 1.1 takemura },
84 1.1 takemura /* CRT: on FP: off */
85 1.1 takemura {
86 1.1 takemura MQ200_CLOCK_PLL1, /* memory clock */
87 1.1 takemura MQ200_CLOCK_PLL2, /* graphics engine clock */
88 1.1 takemura {
89 1.1 takemura MQ200_CLOCK_PLL3, /* GC1(CRT) clock */
90 1.1 takemura 0, /* GC2(FP) clock */
91 1.1 takemura },
92 1.1 takemura 83000, /* PLL1 83MHz */
93 1.1 takemura 30000, /* PLL2 30MHz */
94 1.1 takemura -1, /* PLL3 will be set by GC1 */
95 1.1 takemura },
96 1.1 takemura /* CRT: off FP: on */
97 1.1 takemura {
98 1.1 takemura MQ200_CLOCK_PLL1, /* memory clock */
99 1.1 takemura MQ200_CLOCK_PLL2, /* graphics engine clock */
100 1.1 takemura {
101 1.1 takemura 0, /* GC1(CRT) clock */
102 1.1 takemura MQ200_CLOCK_PLL2, /* GC2(FP) clock */
103 1.1 takemura },
104 1.1 takemura 30000, /* PLL1 30MHz */
105 1.1 takemura 18800, /* PLL2 18.8MHz */
106 1.1 takemura 0, /* PLL3 disable */
107 1.1 takemura },
108 1.1 takemura /* CRT: on FP: on */
109 1.1 takemura {
110 1.1 takemura MQ200_CLOCK_PLL1, /* memory clock */
111 1.1 takemura MQ200_CLOCK_PLL2, /* graphics engine clock */
112 1.1 takemura {
113 1.1 takemura MQ200_CLOCK_PLL3, /* GC1(CRT) clock */
114 1.1 takemura MQ200_CLOCK_PLL2, /* GC2(FP) clock */
115 1.1 takemura },
116 1.1 takemura 83000, /* PLL1 83MHz */
117 1.1 takemura 18800, /* PLL2 18.8MHz */
118 1.1 takemura -1, /* PLL3 will be set by GC1 */
119 1.1 takemura },
120 1.1 takemura };
121 1.1 takemura
122 1.1 takemura static struct mq200_md_param machdep_params[] = {
123 1.1 takemura {
124 1.1 takemura &platid_mask_MACH_NEC_MCR_530,
125 1.1 takemura 640, 240, /* flat panel size */
126 1.1 takemura 12288, /* base clock is 12.288 MHz */
127 1.1 takemura MQ200_MD_HAVECRT | MQ200_MD_HAVEFP,
128 1.1 takemura #if MQ200_SETUPREGS
129 1.1 takemura mcr530_init_ops,
130 1.1 takemura #else
131 1.1 takemura NULL,
132 1.1 takemura #endif /* MQ200_SETUPREGS */
133 1.1 takemura mcr530_clocks,
134 1.1 takemura /* DCMISC */
135 1.1 takemura MQ200_DCMISC_OSC_ENABLE |
136 1.1 takemura MQ200_DCMISC_FASTPOWSEQ_DISABLE |
137 1.1 takemura MQ200_DCMISC_OSCFREQ_12_25,
138 1.1 takemura /* PMC */
139 1.1 takemura 0,
140 1.1 takemura /* MM01 */
141 1.1 takemura MQ200_MM01_DRAM_AUTO_REFRESH_EN |
142 1.1 takemura MQ200_MM01_GE_PB_EN |
143 1.1 takemura MQ200_MM01_CPU_PB_EN |
144 1.1 takemura MQ200_MM01_SLOW_REFRESH_EN |
145 1.1 takemura (0x143e << MQ200_MM01_REFRESH_SHIFT),
146 1.1 takemura },
147 1.1 takemura };
148 1.1 takemura
149 1.1 takemura void
150 1.1 takemura mq200_mdsetup(struct mq200_softc *sc)
151 1.1 takemura {
152 1.1 takemura const struct mq200_md_param *mdp;
153 1.1 takemura
154 1.1 takemura sc->sc_md = NULL;
155 1.1 takemura for (mdp = machdep_params; mdp->md_platform != NULL; mdp++) {
156 1.1 takemura platid_mask_t mask;
157 1.1 takemura mask = PLATID_DEREF(mdp->md_platform);
158 1.1 takemura if (platid_match(&platid, &mask)) {
159 1.1 takemura sc->sc_md = mdp;
160 1.1 takemura break;
161 1.1 takemura }
162 1.1 takemura }
163 1.1 takemura
164 1.1 takemura if (sc->sc_md) {
165 1.1 takemura sc->sc_width[MQ200_GC2] = mdp->md_fp_width;
166 1.1 takemura sc->sc_height[MQ200_GC2] = mdp->md_fp_height;
167 1.1 takemura sc->sc_baseclock = mdp->md_baseclock;
168 1.1 takemura
169 1.1 takemura sc->sc_regctxs[MQ200_I_DCMISC ].val = mdp->md_init_dcmisc;
170 1.1 takemura sc->sc_regctxs[MQ200_I_PMC ].val = mdp->md_init_pmc;
171 1.1 takemura sc->sc_regctxs[MQ200_I_MM01 ].val = mdp->md_init_mm01;
172 1.1 takemura
173 1.1 takemura #if MQ200_SETUPREGS
174 1.1 takemura mq200_setupregs(sc, mdp->md_init_ops);
175 1.1 takemura #endif
176 1.1 takemura }
177 1.1 takemura }
178 1.1 takemura
179 1.1 takemura #if MQ200_SETUPREGS
180 1.1 takemura static void
181 1.1 takemura mq200_setupregs(struct mq200_softc *sc, u_int32_t *ops)
182 1.1 takemura {
183 1.1 takemura u_int32_t reg, mask, accum;
184 1.1 takemura
185 1.1 takemura while (1) {
186 1.1 takemura switch (ops[0] & 0x3) {
187 1.1 takemura case 0:
188 1.1 takemura if (mask == ~0) {
189 1.1 takemura mq200_write(sc, ops[0], ops[1]);
190 1.1 takemura } else {
191 1.1 takemura reg = mq200_read(sc, ops[0]);
192 1.1 takemura reg = (reg & ~mask) | (ops[1] & mask);
193 1.1 takemura mq200_write(sc, ops[0], reg);
194 1.1 takemura }
195 1.1 takemura break;
196 1.1 takemura case 1:
197 1.1 takemura switch (ops[0]) {
198 1.1 takemura case OP_END:
199 1.1 takemura return;
200 1.1 takemura case OP_MASK:
201 1.1 takemura mask = ops[1];
202 1.1 takemura break;
203 1.1 takemura case OP_LOADPLLPARAM:
204 1.1 takemura mq200_pllparam(ops[1], &accum);
205 1.1 takemura break;
206 1.1 takemura case OP_LOADFROMREG:
207 1.1 takemura reg = mq200_read(sc, ops[1]);
208 1.1 takemura accum = (accum & ~mask) | (reg & mask);
209 1.1 takemura break;
210 1.1 takemura case OP_STORETOREG:
211 1.1 takemura if (mask == ~0) {
212 1.1 takemura mq200_write(sc, ops[1], accum);
213 1.1 takemura } else {
214 1.1 takemura reg = mq200_read(sc, ops[1]);
215 1.1 takemura reg = (reg & ~mask) | (accum & mask);
216 1.1 takemura mq200_write(sc, ops[1], reg);
217 1.1 takemura }
218 1.1 takemura break;
219 1.1 takemura case OP_LOADIMM:
220 1.1 takemura accum = (accum & ~mask) | (ops[1] & mask);
221 1.1 takemura break;
222 1.1 takemura case OP_OR:
223 1.1 takemura accum = (accum | ops[1]);
224 1.1 takemura break;
225 1.1 takemura }
226 1.1 takemura break;
227 1.1 takemura }
228 1.1 takemura if (ops[0] != OP_MASK)
229 1.1 takemura mask = ~0;
230 1.1 takemura ops += 2;
231 1.1 takemura }
232 1.1 takemura }
233 1.1 takemura #endif /* MQ200_SETUPREGS */
234