1 1.6 garbled /* $NetBSD: mq200machdep.c,v 1.6 2007/10/17 19:54:28 garbled 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.6 garbled __KERNEL_RCSID(0, "$NetBSD: mq200machdep.c,v 1.6 2007/10/17 19:54:28 garbled 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.3 imp 640, 240, /* flat panel size */ 129 1.3 imp 12288, /* base clock is 12.288 MHz */ 130 1.3 imp MQ200_MD_HAVECRT | MQ200_MD_HAVEFP, 131 1.3 imp #if MQ200_SETUPREGS 132 1.3 imp mcr530_init_ops, 133 1.3 imp #else 134 1.3 imp NULL, 135 1.3 imp #endif /* MQ200_SETUPREGS */ 136 1.3 imp mcr530_clocks, 137 1.3 imp /* DCMISC */ 138 1.3 imp MQ200_DCMISC_OSC_ENABLE | 139 1.3 imp MQ200_DCMISC_FASTPOWSEQ_DISABLE | 140 1.3 imp MQ200_DCMISC_OSCFREQ_12_25, 141 1.3 imp /* PMC */ 142 1.3 imp 0, 143 1.3 imp /* MM01 */ 144 1.3 imp MQ200_MM01_DRAM_AUTO_REFRESH_EN | 145 1.3 imp MQ200_MM01_GE_PB_EN | 146 1.3 imp MQ200_MM01_CPU_PB_EN | 147 1.3 imp MQ200_MM01_SLOW_REFRESH_EN | 148 1.3 imp (0x143e << MQ200_MM01_REFRESH_SHIFT), 149 1.3 imp }, 150 1.3 imp { 151 1.3 imp &platid_mask_MACH_NEC_MCR_530A, 152 1.1 takemura 640, 240, /* flat panel size */ 153 1.1 takemura 12288, /* base clock is 12.288 MHz */ 154 1.1 takemura MQ200_MD_HAVECRT | MQ200_MD_HAVEFP, 155 1.1 takemura #if MQ200_SETUPREGS 156 1.1 takemura mcr530_init_ops, 157 1.1 takemura #else 158 1.1 takemura NULL, 159 1.1 takemura #endif /* MQ200_SETUPREGS */ 160 1.1 takemura mcr530_clocks, 161 1.1 takemura /* DCMISC */ 162 1.1 takemura MQ200_DCMISC_OSC_ENABLE | 163 1.1 takemura MQ200_DCMISC_FASTPOWSEQ_DISABLE | 164 1.1 takemura MQ200_DCMISC_OSCFREQ_12_25, 165 1.1 takemura /* PMC */ 166 1.1 takemura 0, 167 1.1 takemura /* MM01 */ 168 1.1 takemura MQ200_MM01_DRAM_AUTO_REFRESH_EN | 169 1.1 takemura MQ200_MM01_GE_PB_EN | 170 1.1 takemura MQ200_MM01_CPU_PB_EN | 171 1.1 takemura MQ200_MM01_SLOW_REFRESH_EN | 172 1.1 takemura (0x143e << MQ200_MM01_REFRESH_SHIFT), 173 1.1 takemura }, 174 1.5 kiyohara { 175 1.5 kiyohara NULL /* md_platform */ 176 1.5 kiyohara } 177 1.1 takemura }; 178 1.1 takemura 179 1.1 takemura void 180 1.1 takemura mq200_mdsetup(struct mq200_softc *sc) 181 1.1 takemura { 182 1.1 takemura const struct mq200_md_param *mdp; 183 1.1 takemura 184 1.1 takemura sc->sc_md = NULL; 185 1.1 takemura for (mdp = machdep_params; mdp->md_platform != NULL; mdp++) { 186 1.1 takemura platid_mask_t mask; 187 1.1 takemura mask = PLATID_DEREF(mdp->md_platform); 188 1.1 takemura if (platid_match(&platid, &mask)) { 189 1.1 takemura sc->sc_md = mdp; 190 1.1 takemura break; 191 1.1 takemura } 192 1.1 takemura } 193 1.1 takemura 194 1.1 takemura if (sc->sc_md) { 195 1.1 takemura sc->sc_width[MQ200_GC2] = mdp->md_fp_width; 196 1.1 takemura sc->sc_height[MQ200_GC2] = mdp->md_fp_height; 197 1.1 takemura sc->sc_baseclock = mdp->md_baseclock; 198 1.1 takemura 199 1.1 takemura sc->sc_regctxs[MQ200_I_DCMISC ].val = mdp->md_init_dcmisc; 200 1.1 takemura sc->sc_regctxs[MQ200_I_PMC ].val = mdp->md_init_pmc; 201 1.1 takemura sc->sc_regctxs[MQ200_I_MM01 ].val = mdp->md_init_mm01; 202 1.1 takemura 203 1.1 takemura #if MQ200_SETUPREGS 204 1.1 takemura mq200_setupregs(sc, mdp->md_init_ops); 205 1.1 takemura #endif 206 1.1 takemura } 207 1.1 takemura } 208 1.1 takemura 209 1.1 takemura #if MQ200_SETUPREGS 210 1.1 takemura static void 211 1.1 takemura mq200_setupregs(struct mq200_softc *sc, u_int32_t *ops) 212 1.1 takemura { 213 1.1 takemura u_int32_t reg, mask, accum; 214 1.1 takemura 215 1.1 takemura while (1) { 216 1.1 takemura switch (ops[0] & 0x3) { 217 1.1 takemura case 0: 218 1.1 takemura if (mask == ~0) { 219 1.1 takemura mq200_write(sc, ops[0], ops[1]); 220 1.1 takemura } else { 221 1.1 takemura reg = mq200_read(sc, ops[0]); 222 1.1 takemura reg = (reg & ~mask) | (ops[1] & mask); 223 1.1 takemura mq200_write(sc, ops[0], reg); 224 1.1 takemura } 225 1.1 takemura break; 226 1.1 takemura case 1: 227 1.1 takemura switch (ops[0]) { 228 1.1 takemura case OP_END: 229 1.1 takemura return; 230 1.1 takemura case OP_MASK: 231 1.1 takemura mask = ops[1]; 232 1.1 takemura break; 233 1.1 takemura case OP_LOADPLLPARAM: 234 1.1 takemura mq200_pllparam(ops[1], &accum); 235 1.1 takemura break; 236 1.1 takemura case OP_LOADFROMREG: 237 1.1 takemura reg = mq200_read(sc, ops[1]); 238 1.1 takemura accum = (accum & ~mask) | (reg & mask); 239 1.1 takemura break; 240 1.1 takemura case OP_STORETOREG: 241 1.1 takemura if (mask == ~0) { 242 1.1 takemura mq200_write(sc, ops[1], accum); 243 1.1 takemura } else { 244 1.1 takemura reg = mq200_read(sc, ops[1]); 245 1.1 takemura reg = (reg & ~mask) | (accum & mask); 246 1.1 takemura mq200_write(sc, ops[1], reg); 247 1.1 takemura } 248 1.1 takemura break; 249 1.1 takemura case OP_LOADIMM: 250 1.1 takemura accum = (accum & ~mask) | (ops[1] & mask); 251 1.1 takemura break; 252 1.1 takemura case OP_OR: 253 1.1 takemura accum = (accum | ops[1]); 254 1.1 takemura break; 255 1.1 takemura } 256 1.1 takemura break; 257 1.1 takemura } 258 1.1 takemura if (ops[0] != OP_MASK) 259 1.1 takemura mask = ~0; 260 1.1 takemura ops += 2; 261 1.1 takemura } 262 1.1 takemura } 263 1.1 takemura #endif /* MQ200_SETUPREGS */ 264