mq200machdep.c revision 1.2 1 1.2 lukem /* $NetBSD: mq200machdep.c,v 1.2 2003/07/15 02:29:29 lukem 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.2 lukem #include <sys/cdefs.h>
34 1.2 lukem __KERNEL_RCSID(0, "$NetBSD: mq200machdep.c,v 1.2 2003/07/15 02:29:29 lukem Exp $");
35 1.2 lukem
36 1.1 takemura #include <sys/param.h>
37 1.1 takemura #include <sys/kernel.h>
38 1.1 takemura #include <sys/systm.h>
39 1.1 takemura #include <sys/device.h>
40 1.1 takemura #else
41 1.1 takemura #include <stdio.h>
42 1.1 takemura #endif
43 1.1 takemura #include <sys/types.h>
44 1.1 takemura
45 1.1 takemura #include <machine/platid.h>
46 1.1 takemura #include <machine/platid_mask.h>
47 1.1 takemura
48 1.1 takemura #include "opt_mq200.h"
49 1.1 takemura #include "mq200var.h"
50 1.1 takemura #include "mq200reg.h"
51 1.1 takemura #include "mq200priv.h"
52 1.1 takemura
53 1.1 takemura #if MQ200_SETUPREGS
54 1.1 takemura #define OP_(n) (((n) << 2) | 1)
55 1.1 takemura #define OP_END OP_(1)
56 1.1 takemura #define OP_MASK OP_(2)
57 1.1 takemura #define OP_LOADPLLPARAM OP_(3)
58 1.1 takemura #define OP_LOADFROMREG OP_(4)
59 1.1 takemura #define OP_STORETOREG OP_(5)
60 1.1 takemura #define OP_LOADIMM OP_(6)
61 1.1 takemura #define OP_OR OP_(7)
62 1.1 takemura
63 1.1 takemura static void mq200_setupregs(struct mq200_softc *sc, u_int32_t *ops);
64 1.1 takemura
65 1.1 takemura static u_int32_t mcr530_init_ops[] = {
66 1.1 takemura MQ200_PMCR, 0, /* power management control */
67 1.1 takemura MQ200_DCMISCR, MQ200_DCMISC_OSC_ENABLE |
68 1.1 takemura MQ200_DCMISC_FASTPOWSEQ_DISABLE |
69 1.1 takemura MQ200_DCMISC_OSCFREQ_12_25,
70 1.1 takemura OP_END
71 1.1 takemura };
72 1.1 takemura #endif /* MQ200_SETUPREGS */
73 1.1 takemura
74 1.1 takemura static struct mq200_clock_setting mcr530_clocks[] = {
75 1.1 takemura /* CRT: off FP: off */
76 1.1 takemura {
77 1.1 takemura MQ200_CLOCK_PLL1, /* memory clock */
78 1.1 takemura MQ200_CLOCK_PLL1, /* graphics engine clock */
79 1.1 takemura {
80 1.1 takemura 0, /* GC1(CRT) clock */
81 1.1 takemura 0, /* GC2(FP) clock */
82 1.1 takemura },
83 1.1 takemura 30000, /* PLL1 30MHz */
84 1.1 takemura 0, /* PLL2 disable */
85 1.1 takemura 0, /* PLL3 disable */
86 1.1 takemura },
87 1.1 takemura /* CRT: on FP: off */
88 1.1 takemura {
89 1.1 takemura MQ200_CLOCK_PLL1, /* memory clock */
90 1.1 takemura MQ200_CLOCK_PLL2, /* graphics engine clock */
91 1.1 takemura {
92 1.1 takemura MQ200_CLOCK_PLL3, /* GC1(CRT) clock */
93 1.1 takemura 0, /* GC2(FP) clock */
94 1.1 takemura },
95 1.1 takemura 83000, /* PLL1 83MHz */
96 1.1 takemura 30000, /* PLL2 30MHz */
97 1.1 takemura -1, /* PLL3 will be set by GC1 */
98 1.1 takemura },
99 1.1 takemura /* CRT: off FP: on */
100 1.1 takemura {
101 1.1 takemura MQ200_CLOCK_PLL1, /* memory clock */
102 1.1 takemura MQ200_CLOCK_PLL2, /* graphics engine clock */
103 1.1 takemura {
104 1.1 takemura 0, /* GC1(CRT) clock */
105 1.1 takemura MQ200_CLOCK_PLL2, /* GC2(FP) clock */
106 1.1 takemura },
107 1.1 takemura 30000, /* PLL1 30MHz */
108 1.1 takemura 18800, /* PLL2 18.8MHz */
109 1.1 takemura 0, /* PLL3 disable */
110 1.1 takemura },
111 1.1 takemura /* CRT: on FP: on */
112 1.1 takemura {
113 1.1 takemura MQ200_CLOCK_PLL1, /* memory clock */
114 1.1 takemura MQ200_CLOCK_PLL2, /* graphics engine clock */
115 1.1 takemura {
116 1.1 takemura MQ200_CLOCK_PLL3, /* GC1(CRT) clock */
117 1.1 takemura MQ200_CLOCK_PLL2, /* GC2(FP) clock */
118 1.1 takemura },
119 1.1 takemura 83000, /* PLL1 83MHz */
120 1.1 takemura 18800, /* PLL2 18.8MHz */
121 1.1 takemura -1, /* PLL3 will be set by GC1 */
122 1.1 takemura },
123 1.1 takemura };
124 1.1 takemura
125 1.1 takemura static struct mq200_md_param machdep_params[] = {
126 1.1 takemura {
127 1.1 takemura &platid_mask_MACH_NEC_MCR_530,
128 1.1 takemura 640, 240, /* flat panel size */
129 1.1 takemura 12288, /* base clock is 12.288 MHz */
130 1.1 takemura MQ200_MD_HAVECRT | MQ200_MD_HAVEFP,
131 1.1 takemura #if MQ200_SETUPREGS
132 1.1 takemura mcr530_init_ops,
133 1.1 takemura #else
134 1.1 takemura NULL,
135 1.1 takemura #endif /* MQ200_SETUPREGS */
136 1.1 takemura mcr530_clocks,
137 1.1 takemura /* DCMISC */
138 1.1 takemura MQ200_DCMISC_OSC_ENABLE |
139 1.1 takemura MQ200_DCMISC_FASTPOWSEQ_DISABLE |
140 1.1 takemura MQ200_DCMISC_OSCFREQ_12_25,
141 1.1 takemura /* PMC */
142 1.1 takemura 0,
143 1.1 takemura /* MM01 */
144 1.1 takemura MQ200_MM01_DRAM_AUTO_REFRESH_EN |
145 1.1 takemura MQ200_MM01_GE_PB_EN |
146 1.1 takemura MQ200_MM01_CPU_PB_EN |
147 1.1 takemura MQ200_MM01_SLOW_REFRESH_EN |
148 1.1 takemura (0x143e << MQ200_MM01_REFRESH_SHIFT),
149 1.1 takemura },
150 1.1 takemura };
151 1.1 takemura
152 1.1 takemura void
153 1.1 takemura mq200_mdsetup(struct mq200_softc *sc)
154 1.1 takemura {
155 1.1 takemura const struct mq200_md_param *mdp;
156 1.1 takemura
157 1.1 takemura sc->sc_md = NULL;
158 1.1 takemura for (mdp = machdep_params; mdp->md_platform != NULL; mdp++) {
159 1.1 takemura platid_mask_t mask;
160 1.1 takemura mask = PLATID_DEREF(mdp->md_platform);
161 1.1 takemura if (platid_match(&platid, &mask)) {
162 1.1 takemura sc->sc_md = mdp;
163 1.1 takemura break;
164 1.1 takemura }
165 1.1 takemura }
166 1.1 takemura
167 1.1 takemura if (sc->sc_md) {
168 1.1 takemura sc->sc_width[MQ200_GC2] = mdp->md_fp_width;
169 1.1 takemura sc->sc_height[MQ200_GC2] = mdp->md_fp_height;
170 1.1 takemura sc->sc_baseclock = mdp->md_baseclock;
171 1.1 takemura
172 1.1 takemura sc->sc_regctxs[MQ200_I_DCMISC ].val = mdp->md_init_dcmisc;
173 1.1 takemura sc->sc_regctxs[MQ200_I_PMC ].val = mdp->md_init_pmc;
174 1.1 takemura sc->sc_regctxs[MQ200_I_MM01 ].val = mdp->md_init_mm01;
175 1.1 takemura
176 1.1 takemura #if MQ200_SETUPREGS
177 1.1 takemura mq200_setupregs(sc, mdp->md_init_ops);
178 1.1 takemura #endif
179 1.1 takemura }
180 1.1 takemura }
181 1.1 takemura
182 1.1 takemura #if MQ200_SETUPREGS
183 1.1 takemura static void
184 1.1 takemura mq200_setupregs(struct mq200_softc *sc, u_int32_t *ops)
185 1.1 takemura {
186 1.1 takemura u_int32_t reg, mask, accum;
187 1.1 takemura
188 1.1 takemura while (1) {
189 1.1 takemura switch (ops[0] & 0x3) {
190 1.1 takemura case 0:
191 1.1 takemura if (mask == ~0) {
192 1.1 takemura mq200_write(sc, ops[0], ops[1]);
193 1.1 takemura } else {
194 1.1 takemura reg = mq200_read(sc, ops[0]);
195 1.1 takemura reg = (reg & ~mask) | (ops[1] & mask);
196 1.1 takemura mq200_write(sc, ops[0], reg);
197 1.1 takemura }
198 1.1 takemura break;
199 1.1 takemura case 1:
200 1.1 takemura switch (ops[0]) {
201 1.1 takemura case OP_END:
202 1.1 takemura return;
203 1.1 takemura case OP_MASK:
204 1.1 takemura mask = ops[1];
205 1.1 takemura break;
206 1.1 takemura case OP_LOADPLLPARAM:
207 1.1 takemura mq200_pllparam(ops[1], &accum);
208 1.1 takemura break;
209 1.1 takemura case OP_LOADFROMREG:
210 1.1 takemura reg = mq200_read(sc, ops[1]);
211 1.1 takemura accum = (accum & ~mask) | (reg & mask);
212 1.1 takemura break;
213 1.1 takemura case OP_STORETOREG:
214 1.1 takemura if (mask == ~0) {
215 1.1 takemura mq200_write(sc, ops[1], accum);
216 1.1 takemura } else {
217 1.1 takemura reg = mq200_read(sc, ops[1]);
218 1.1 takemura reg = (reg & ~mask) | (accum & mask);
219 1.1 takemura mq200_write(sc, ops[1], reg);
220 1.1 takemura }
221 1.1 takemura break;
222 1.1 takemura case OP_LOADIMM:
223 1.1 takemura accum = (accum & ~mask) | (ops[1] & mask);
224 1.1 takemura break;
225 1.1 takemura case OP_OR:
226 1.1 takemura accum = (accum | ops[1]);
227 1.1 takemura break;
228 1.1 takemura }
229 1.1 takemura break;
230 1.1 takemura }
231 1.1 takemura if (ops[0] != OP_MASK)
232 1.1 takemura mask = ~0;
233 1.1 takemura ops += 2;
234 1.1 takemura }
235 1.1 takemura }
236 1.1 takemura #endif /* MQ200_SETUPREGS */
237