1 1.9 andvar /* $NetBSD: pxa2x0_apm.c,v 1.9 2022/10/31 21:22:05 andvar Exp $ */ 2 1.1 ober /* $OpenBSD: pxa2x0_apm.c,v 1.28 2007/03/29 18:42:38 uwe Exp $ */ 3 1.1 ober 4 1.1 ober /*- 5 1.1 ober * Copyright (c) 2001 Alexander Guy. All rights reserved. 6 1.1 ober * Copyright (c) 1998-2001 Michael Shalayeff. All rights reserved. 7 1.1 ober * Copyright (c) 1995 John T. Kohl. All rights reserved. 8 1.1 ober * 9 1.1 ober * Redistribution and use in source and binary forms, with or without 10 1.1 ober * modification, are permitted provided that the following conditions 11 1.1 ober * are met: 12 1.1 ober * 1. Redistributions of source code must retain the above copyright 13 1.1 ober * notice, this list of conditions and the following disclaimer. 14 1.1 ober * 2. Redistributions in binary form must reproduce the above copyright 15 1.1 ober * notice, this list of conditions and the following disclaimer in the 16 1.1 ober * documentation and/or other materials provided with the distribution. 17 1.1 ober * 3. All advertising materials mentioning features or use of this software 18 1.1 ober * must display the following acknowledgement: 19 1.1 ober * This product includes software developed by the University of 20 1.1 ober * California, Berkeley and its contributors. 21 1.1 ober * 4. Neither the name of the University nor the names of its contributors 22 1.1 ober * may be used to endorse or promote products derived from this software 23 1.1 ober * without specific prior written permission. 24 1.1 ober * 25 1.1 ober * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 1.1 ober * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 1.1 ober * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 1.1 ober * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 1.1 ober * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 1.1 ober * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 1.1 ober * OR SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 1.1 ober * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 1.1 ober * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 1.1 ober * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 1.1 ober * SUCH DAMAGE. 36 1.1 ober * 37 1.1 ober */ 38 1.1 ober 39 1.1 ober #include <sys/param.h> 40 1.1 ober #include <sys/systm.h> 41 1.1 ober #include <sys/kernel.h> 42 1.1 ober #include <sys/kthread.h> 43 1.1 ober #include <sys/lock.h> 44 1.1 ober #include <sys/mount.h> /* for vfs_syncwait() */ 45 1.1 ober #include <sys/proc.h> 46 1.1 ober #include <sys/device.h> 47 1.1 ober #include <sys/fcntl.h> 48 1.1 ober #include <sys/ioctl.h> 49 1.1 ober #include <sys/event.h> 50 1.1 ober 51 1.1 ober #include <machine/cpu.h> 52 1.1 ober #include <machine/apmvar.h> 53 1.1 ober 54 1.1 ober #include <arm/xscale/pxa2x0reg.h> 55 1.1 ober #include <arm/xscale/pxa2x0var.h> 56 1.1 ober #include <arm/xscale/pxa2x0_apm.h> 57 1.1 ober #include <arm/xscale/pxa2x0_gpio.h> 58 1.1 ober 59 1.1 ober #if defined(APMDEBUG) 60 1.1 ober #define DPRINTF(x) printf x 61 1.1 ober #else 62 1.1 ober #define DPRINTF(x) /**/ 63 1.1 ober #endif 64 1.1 ober 65 1.1 ober #define APM_LOCK(sc) lockmgr(&(sc)->sc_lock, LK_EXCLUSIVE, NULL) 66 1.1 ober #define APM_UNLOCK(sc) lockmgr(&(sc)->sc_lock, LK_RELEASE, NULL) 67 1.1 ober 68 1.1 ober #define APMUNIT(dev) (minor(dev)&0xf0) 69 1.1 ober #define APMDEV(dev) (minor(dev)&0x0f) 70 1.1 ober #define APMDEV_NORMAL 0 71 1.1 ober #define APMDEV_CTL 8 72 1.1 ober 73 1.1 ober int apm_userstandbys; 74 1.1 ober int apm_suspends; 75 1.1 ober int apm_battlow; 76 1.1 ober 77 1.1 ober extern struct cfdriver zapm_cd; 78 1.1 ober 79 1.1 ober /* battery percentage at which we get verbose in our warnings. This 80 1.1 ober value can be changed using sysctl(8), value machdep.apmwarn. 81 1.1 ober Setting it to zero kills all warnings */ 82 1.1 ober int cpu_apmwarn = 10; 83 1.1 ober 84 1.1 ober void apm_power_print(struct pxa2x0_apm_softc *, struct apm_power_info *); 85 1.1 ober void apm_power_info(struct pxa2x0_apm_softc *, struct apm_power_info *); 86 1.1 ober void apm_suspend(struct pxa2x0_apm_softc *); 87 1.1 ober void apm_resume(struct pxa2x0_apm_softc *); 88 1.1 ober int apm_get_event(struct pxa2x0_apm_softc *, u_int *); 89 1.1 ober int apm_handle_event(struct pxa2x0_apm_softc *, u_int); 90 1.1 ober void apm_thread_create(void *); 91 1.1 ober void apm_thread(void *); 92 1.1 ober 93 1.1 ober #if 0 94 1.1 ober extern int perflevel; 95 1.1 ober #endif 96 1.1 ober 97 1.1 ober int freq; 98 1.1 ober void pxa2x0_setperf(int speed); 99 1.1 ober int pxa2x0_cpuspeed(int *speed); 100 1.1 ober 101 1.1 ober int apm_record_event(struct pxa2x0_apm_softc *, u_int); 102 1.1 ober #if 0 103 1.1 ober void filt_apmrdetach(struct knote *kn); 104 1.1 ober int filt_apmread(struct knote *kn, long hint); 105 1.1 ober int apmkqfilter(dev_t dev, struct knote *kn); 106 1.1 ober 107 1.5 christos static const struct filterops apmread_filtops = { 108 1.6 thorpej .f_flags = FILTEROP_ISFD, 109 1.5 christos .f_attach = NULL, 110 1.5 christos .f_detach = filt_apmrdetach, 111 1.5 christos .f_event = filt_apmread, 112 1.5 christos }; 113 1.1 ober #endif 114 1.1 ober 115 1.1 ober /* 116 1.1 ober * Flags to control kernel display 117 1.1 ober * SCFLAG_NOPRINT: do not output APM power messages due to 118 1.1 ober * a power change event. 119 1.1 ober * 120 1.1 ober * SCFLAG_PCTPRINT: do not output APM power messages due to 121 1.1 ober * to a power change event unless the battery 122 1.1 ober * percentage changes. 123 1.1 ober */ 124 1.1 ober 125 1.1 ober #define SCFLAG_NOPRINT 0x0008000 126 1.1 ober #define SCFLAG_PCTPRINT 0x0004000 127 1.1 ober #define SCFLAG_PRINT (SCFLAG_NOPRINT|SCFLAG_PCTPRINT) 128 1.1 ober 129 1.1 ober #define SCFLAG_OREAD (1 << 0) 130 1.1 ober #define SCFLAG_OWRITE (1 << 1) 131 1.1 ober #define SCFLAG_OPEN (SCFLAG_OREAD|SCFLAG_OWRITE) 132 1.1 ober 133 1.1 ober /* This structure must be kept in sync with pxa2x0_apm_asm.S. */ 134 1.1 ober struct pxa2x0_memcfg { 135 1.1 ober /* SDRAM refresh */ 136 1.4 skrll uint32_t mdrefr_high; /* 0x00 */ 137 1.4 skrll uint32_t mdrefr_low; /* 0x04 */ 138 1.4 skrll uint32_t mdrefr_low2; /* 0x08 */ 139 1.1 ober /* Synchronous, static, or VLIO interfaces */ 140 1.4 skrll uint32_t msc_high[3]; /* 0x0c */ 141 1.4 skrll uint32_t msc_low[3]; /* 0x18 */ 142 1.1 ober /* XXX move up */ 143 1.4 skrll uint32_t mdrefr_91; /* 0x24 */ 144 1.1 ober }; 145 1.1 ober 146 1.1 ober /* XXX */ 147 1.1 ober #define MDREFR_C3000 (MDREFR_K0DB2 | MDREFR_E1PIN | MDREFR_K1RUN | \ 148 1.1 ober MDREFR_K1DB2 | MDREFR_K2DB2 | MDREFR_APD) 149 1.1 ober #define MSC0_HIGH \ 150 1.1 ober ( 7 << MSC_RRR_SHIFT << 16) | \ 151 1.1 ober (15 << MSC_RDN_SHIFT << 16) | \ 152 1.1 ober (15 << MSC_RDF_SHIFT << 16) | \ 153 1.1 ober (MSC_RT_NONBURST << 16) | \ 154 1.1 ober ( 2 << MSC_RRR_SHIFT) | \ 155 1.1 ober (13 << MSC_RDN_SHIFT) | \ 156 1.1 ober (13 << MSC_RDF_SHIFT) | \ 157 1.1 ober MSC_RBW /* PXA271 */ | \ 158 1.1 ober MSC_RT_NONBURST 159 1.1 ober #define MSC1_HIGH \ 160 1.1 ober ( 7 << MSC_RRR_SHIFT << 16) | \ 161 1.1 ober (15 << MSC_RDN_SHIFT << 16) | \ 162 1.1 ober (15 << MSC_RDF_SHIFT << 16) | \ 163 1.1 ober (MSC_RT_VLIO << 16) | \ 164 1.1 ober ( 3 << MSC_RRR_SHIFT) | \ 165 1.1 ober ( 4 << MSC_RDN_SHIFT) | \ 166 1.1 ober (13 << MSC_RDF_SHIFT) | \ 167 1.1 ober MSC_RT_VLIO 168 1.1 ober #define MSC2_HIGH \ 169 1.1 ober ( 7 << MSC_RRR_SHIFT << 16) | \ 170 1.1 ober (15 << MSC_RDN_SHIFT << 16) | \ 171 1.1 ober (15 << MSC_RDF_SHIFT << 16) | \ 172 1.1 ober (MSC_RT_NONBURST << 16) | \ 173 1.1 ober ( 3 << MSC_RRR_SHIFT) | \ 174 1.1 ober ( 4 << MSC_RDN_SHIFT) | \ 175 1.1 ober (13 << MSC_RDF_SHIFT) | \ 176 1.1 ober MSC_RT_VLIO 177 1.1 ober #define MSC0_LOW \ 178 1.1 ober ( 7 << MSC_RRR_SHIFT << 16) | \ 179 1.1 ober (15 << MSC_RDN_SHIFT << 16) | \ 180 1.1 ober (15 << MSC_RDF_SHIFT << 16) | \ 181 1.1 ober (MSC_RT_NONBURST << 16) | \ 182 1.1 ober ( 1 << MSC_RRR_SHIFT) | \ 183 1.1 ober ( 8 << MSC_RDN_SHIFT) | \ 184 1.1 ober ( 8 << MSC_RDF_SHIFT) | \ 185 1.1 ober MSC_RBW /* PXA271 */ | \ 186 1.1 ober MSC_RT_NONBURST 187 1.1 ober #define MSC1_LOW \ 188 1.1 ober ( 7 << MSC_RRR_SHIFT << 16) | \ 189 1.1 ober (15 << MSC_RDN_SHIFT << 16) | \ 190 1.1 ober (15 << MSC_RDF_SHIFT << 16) | \ 191 1.1 ober (MSC_RT_VLIO << 16) | \ 192 1.1 ober ( 1 << MSC_RRR_SHIFT) | \ 193 1.1 ober ( 2 << MSC_RDN_SHIFT) | \ 194 1.1 ober ( 6 << MSC_RDF_SHIFT) | \ 195 1.1 ober MSC_RT_VLIO 196 1.1 ober #define MSC2_LOW \ 197 1.1 ober ( 7 << MSC_RRR_SHIFT << 16) | \ 198 1.1 ober (15 << MSC_RDN_SHIFT << 16) | \ 199 1.1 ober (15 << MSC_RDF_SHIFT << 16) | \ 200 1.1 ober (MSC_RT_NONBURST << 16) | \ 201 1.1 ober ( 1 << MSC_RRR_SHIFT) | \ 202 1.1 ober ( 2 << MSC_RDN_SHIFT) | \ 203 1.1 ober ( 6 << MSC_RDF_SHIFT) | \ 204 1.1 ober MSC_RT_VLIO 205 1.1 ober struct pxa2x0_memcfg pxa2x0_memcfg = { 206 1.1 ober (MDREFR_C3000 | 0x030), 207 1.1 ober (MDREFR_C3000 | 0x00b), 208 1.1 ober (MDREFR_C3000 | 0x017), 209 1.1 ober { MSC0_HIGH, MSC1_HIGH, MSC2_HIGH }, 210 1.1 ober { MSC1_LOW, MSC1_LOW, MSC2_LOW }, 211 1.1 ober (MDREFR_C3000 | 0x013) 212 1.1 ober }; 213 1.1 ober 214 1.1 ober #define PI2C_RETRY_COUNT 10 215 1.1 ober /* XXX varies depending on voltage regulator IC. */ 216 1.1 ober #define PI2C_VOLTAGE_LOW 0x13 /* 1.00V */ 217 1.1 ober #define PI2C_VOLTAGE_HIGH 0x1a /* 1.35V */ 218 1.1 ober 219 1.1 ober void pxa2x0_pi2c_open(bus_space_tag_t, bus_space_handle_t); 220 1.1 ober void pxa2x0_pi2c_close(bus_space_tag_t, bus_space_handle_t); 221 1.1 ober int pxa2x0_pi2c_read(bus_space_tag_t, bus_space_handle_t, u_char, u_char *); 222 1.1 ober int pxa2x0_pi2c_write(bus_space_tag_t, bus_space_handle_t, u_char, u_char); 223 1.1 ober int pxa2x0_pi2c_getvoltage(bus_space_tag_t, bus_space_handle_t, u_char *); 224 1.1 ober int pxa2x0_pi2c_setvoltage(bus_space_tag_t, bus_space_handle_t, u_char); 225 1.1 ober #if 0 226 1.1 ober void pxa2x0_pi2c_print(struct pxa2x0_apm_softc *); 227 1.1 ober #endif 228 1.1 ober 229 1.1 ober /* XXX used in pxa2x0_apm_asm.S */ 230 1.1 ober bus_space_handle_t pxa2x0_gpio_ioh; 231 1.1 ober bus_space_handle_t pxa2x0_clkman_ioh; 232 1.1 ober bus_space_handle_t pxa2x0_memctl_ioh; 233 1.1 ober 234 1.1 ober /* pxa2x0_apm_asm.S */ 235 1.1 ober void pxa27x_run_mode(void); 236 1.4 skrll void pxa27x_fastbus_run_mode(int, uint32_t); 237 1.1 ober void pxa27x_frequency_change(int, int, struct pxa2x0_memcfg *); 238 1.1 ober void pxa2x0_cpu_suspend(void); 239 1.1 ober void pxa2x0_cpu_resume(void); 240 1.1 ober void pxa27x_cpu_speed_high(void); 241 1.1 ober void pxa27x_cpu_speed_low(void); 242 1.1 ober void pxa27x_cpu_speed_91(void); 243 1.1 ober void pxa27x_cpu_speed_208(void); 244 1.1 ober 245 1.1 ober void 246 1.1 ober apm_power_print(struct pxa2x0_apm_softc *sc, struct apm_power_info *powerp) 247 1.1 ober { 248 1.1 ober 249 1.1 ober if (powerp->battery_life != APM_BATT_LIFE_UNKNOWN) 250 1.1 ober printf("%s: battery life expectancy %d%%\n", 251 1.3 chs device_xname(sc->sc_dev), powerp->battery_life); 252 1.1 ober 253 1.3 chs printf("%s: AC ", device_xname(sc->sc_dev)); 254 1.1 ober switch (powerp->ac_state) { 255 1.1 ober case APM_AC_OFF: 256 1.1 ober printf("off,"); 257 1.1 ober break; 258 1.1 ober case APM_AC_ON: 259 1.1 ober printf("on,"); 260 1.1 ober break; 261 1.1 ober case APM_AC_BACKUP: 262 1.1 ober printf("backup power,"); 263 1.1 ober break; 264 1.1 ober default: 265 1.1 ober case APM_AC_UNKNOWN: 266 1.1 ober printf("unknown,"); 267 1.1 ober break; 268 1.1 ober } 269 1.1 ober 270 1.1 ober printf(" battery is "); 271 1.1 ober switch (powerp->battery_state) { 272 1.1 ober case APM_BATT_HIGH: 273 1.1 ober printf("high"); 274 1.1 ober break; 275 1.1 ober case APM_BATT_LOW: 276 1.1 ober printf("low"); 277 1.1 ober break; 278 1.1 ober case APM_BATT_CRITICAL: 279 1.1 ober printf("CRITICAL"); 280 1.1 ober break; 281 1.1 ober case APM_BATT_CHARGING: 282 1.1 ober printf("charging"); 283 1.1 ober break; 284 1.1 ober case APM_BATT_UNKNOWN: 285 1.1 ober printf("unknown"); 286 1.1 ober break; 287 1.1 ober default: 288 1.1 ober printf("undecoded (%x)", powerp->battery_state); 289 1.1 ober break; 290 1.1 ober } 291 1.1 ober 292 1.1 ober printf("\n"); 293 1.1 ober } 294 1.1 ober 295 1.1 ober void 296 1.1 ober apm_power_info(struct pxa2x0_apm_softc *sc, 297 1.1 ober struct apm_power_info *power) 298 1.1 ober { 299 1.1 ober 300 1.1 ober power->ac_state = APM_AC_UNKNOWN; 301 1.1 ober power->battery_state = APM_BATT_UNKNOWN; 302 1.1 ober power->battery_life = 0 /* APM_BATT_LIFE_UNKNOWN */; 303 1.1 ober power->minutes_left = 0; 304 1.1 ober 305 1.1 ober if (sc->sc_power_info != NULL) 306 1.1 ober sc->sc_power_info(sc, power); 307 1.1 ober } 308 1.1 ober 309 1.1 ober void 310 1.1 ober apm_suspend(struct pxa2x0_apm_softc *sc) 311 1.1 ober { 312 1.1 ober 313 1.1 ober resettodr(); 314 1.1 ober 315 1.1 ober dopowerhooks(PWR_SUSPEND); 316 1.1 ober 317 1.1 ober #if 0 318 1.1 ober if (cold) 319 1.1 ober vfs_syncwait(0); 320 1.1 ober #endif 321 1.1 ober 322 1.1 ober if (sc->sc_suspend == NULL) 323 1.1 ober pxa2x0_wakeup_config(PXA2X0_WAKEUP_ALL, 1); 324 1.1 ober else 325 1.1 ober sc->sc_suspend(sc); 326 1.1 ober 327 1.1 ober pxa2x0_apm_sleep(sc); 328 1.1 ober } 329 1.1 ober 330 1.1 ober void 331 1.1 ober apm_resume(struct pxa2x0_apm_softc *sc) 332 1.1 ober { 333 1.1 ober 334 1.1 ober dopowerhooks(PWR_RESUME); 335 1.1 ober 336 1.1 ober inittodr(0); 337 1.1 ober 338 1.1 ober /* 339 1.1 ober * Clear the OTG Peripheral hold after running the pxaudc and pxaohci 340 1.1 ober * powerhooks to re-enable their operation. See 3.8.1.2 341 1.1 ober */ 342 1.1 ober /* XXX ifdef NPXAUDC > 0 */ 343 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSSR, PSSR_OTGPH); 344 1.1 ober } 345 1.1 ober 346 1.1 ober #if 0 347 1.1 ober int 348 1.1 ober apm_get_event(struct pxa2x0_apm_softc *sc, u_int *typep) 349 1.1 ober { 350 1.1 ober 351 1.1 ober if (sc->sc_get_event != NULL) 352 1.1 ober return (sc->sc_get_event(sc, typep)); 353 1.1 ober 354 1.1 ober *typep = APM_NOEVENT; 355 1.1 ober return (1); 356 1.1 ober } 357 1.1 ober 358 1.1 ober int 359 1.1 ober apm_handle_event(struct pxa2x0_apm_softc *sc, u_int type) 360 1.1 ober { 361 1.1 ober struct apm_power_info power; 362 1.1 ober int ret = 0; 363 1.1 ober 364 1.1 ober switch (type) { 365 1.1 ober case APM_NOEVENT: 366 1.1 ober ret = 1; 367 1.1 ober break; 368 1.1 ober case APM_CRIT_SUSPEND_REQ: 369 1.1 ober DPRINTF(("suspend required immediately\n")); 370 1.1 ober #if 0 371 1.1 ober /* XXX apmd would make us suspend again after resume. */ 372 1.1 ober (void)apm_record_event(sc, type); 373 1.1 ober #endif 374 1.1 ober /* 375 1.1 ober * We ignore APM_CRIT_RESUME and just suspend here as usual 376 1.1 ober * to simplify the actual apm_get_event() implementation. 377 1.1 ober */ 378 1.1 ober apm_suspends++; 379 1.1 ober ret = 1; 380 1.1 ober break; 381 1.1 ober case APM_USER_SUSPEND_REQ: 382 1.1 ober case APM_SUSPEND_REQ: 383 1.1 ober DPRINTF(("suspend requested\n")); 384 1.1 ober if (apm_record_event(sc, type)) { 385 1.1 ober DPRINTF(("suspend ourselves\n")); 386 1.1 ober apm_suspends++; 387 1.1 ober } 388 1.1 ober break; 389 1.1 ober case APM_POWER_CHANGE: 390 1.1 ober DPRINTF(("power status change\n")); 391 1.1 ober apm_power_info(sc, &power); 392 1.1 ober if (power.battery_life != APM_BATT_LIFE_UNKNOWN && 393 1.1 ober power.battery_life < cpu_apmwarn && 394 1.1 ober (sc->sc_flags & SCFLAG_PRINT) != SCFLAG_NOPRINT && 395 1.1 ober ((sc->sc_flags & SCFLAG_PRINT) != SCFLAG_PCTPRINT || 396 1.1 ober sc->sc_batt_life != power.battery_life)) { 397 1.1 ober sc->sc_batt_life = power.battery_life; 398 1.1 ober apm_power_print(sc, &power); 399 1.1 ober } 400 1.1 ober apm_record_event(sc, type); 401 1.1 ober break; 402 1.1 ober case APM_BATTERY_LOW: 403 1.1 ober DPRINTF(("Battery low!\n")); 404 1.1 ober apm_battlow++; 405 1.1 ober apm_record_event(sc, type); 406 1.1 ober break; 407 1.1 ober default: 408 1.1 ober DPRINTF(("apm_handle_event: unsupported event, code %d\n", 409 1.1 ober type)); 410 1.1 ober } 411 1.1 ober 412 1.1 ober return (ret); 413 1.1 ober } 414 1.1 ober 415 1.1 ober void 416 1.1 ober apm_thread_create(void *v) 417 1.1 ober { 418 1.1 ober struct pxa2x0_apm_softc *sc = v; 419 1.1 ober 420 1.1 ober if (kthread_create(apm_thread, sc, &sc->sc_thread, 421 1.3 chs "%s", device_xname(sc->sc_dev))) { 422 1.1 ober /* apm_disconnect(sc); */ 423 1.1 ober printf("%s: failed to create kernel thread, disabled", 424 1.3 chs device_xname(sc->sc_dev)); 425 1.1 ober } 426 1.1 ober } 427 1.1 ober 428 1.1 ober void 429 1.1 ober apm_thread(void *v) 430 1.1 ober { 431 1.1 ober struct pxa2x0_apm_softc *sc = v; 432 1.1 ober u_int type; 433 1.1 ober 434 1.1 ober for (;;) { 435 1.1 ober APM_LOCK(sc); 436 1.1 ober 437 1.1 ober while (1) { 438 1.1 ober if (apm_get_event(sc, &type) != 0) 439 1.1 ober break; 440 1.1 ober if (apm_handle_event(sc, type) != 0) 441 1.1 ober break; 442 1.1 ober } 443 1.1 ober if (apm_suspends || apm_userstandbys /* || apm_battlow*/) { 444 1.1 ober apm_suspend(sc); 445 1.1 ober apm_resume(sc); 446 1.1 ober } 447 1.1 ober apm_battlow = apm_suspends = apm_userstandbys = 0; 448 1.1 ober 449 1.1 ober APM_UNLOCK(sc); 450 1.2 pooka kpause("apmev", false, hz, NULL); 451 1.1 ober } 452 1.1 ober } 453 1.1 ober 454 1.1 ober int 455 1.1 ober apmopen(dev_t dev, int flag, int mode, struct proc *p) 456 1.1 ober { 457 1.1 ober struct pxa2x0_apm_softc *sc; 458 1.1 ober int error = 0; 459 1.1 ober 460 1.1 ober /* apm0 only */ 461 1.1 ober if (!zapm_cd.cd_ndevs || APMUNIT(dev) != 0 || 462 1.1 ober !(sc = zapm_cd.cd_devs[APMUNIT(dev)])) 463 1.1 ober return (ENXIO); 464 1.1 ober 465 1.1 ober DPRINTF(("apmopen: dev %d pid %d flag %x mode %x\n", 466 1.1 ober APMDEV(dev), p->p_pid, flag, mode)); 467 1.1 ober 468 1.1 ober switch (APMDEV(dev)) { 469 1.1 ober case APMDEV_CTL: 470 1.1 ober if (!(flag & FWRITE)) { 471 1.1 ober error = EINVAL; 472 1.1 ober break; 473 1.1 ober } 474 1.1 ober if (sc->sc_flags & SCFLAG_OWRITE) { 475 1.1 ober error = EBUSY; 476 1.1 ober break; 477 1.1 ober } 478 1.1 ober sc->sc_flags |= SCFLAG_OWRITE; 479 1.1 ober break; 480 1.1 ober case APMDEV_NORMAL: 481 1.1 ober if (!(flag & FREAD) || (flag & FWRITE)) { 482 1.1 ober error = EINVAL; 483 1.1 ober break; 484 1.1 ober } 485 1.1 ober sc->sc_flags |= SCFLAG_OREAD; 486 1.1 ober break; 487 1.1 ober default: 488 1.1 ober error = ENXIO; 489 1.1 ober break; 490 1.1 ober } 491 1.1 ober return (error); 492 1.1 ober } 493 1.1 ober 494 1.1 ober int 495 1.1 ober apmclose(dev_t dev, int flag, int mode, struct proc *p) 496 1.1 ober { 497 1.1 ober struct pxa2x0_apm_softc *sc; 498 1.1 ober 499 1.1 ober /* apm0 only */ 500 1.1 ober if (!apm_cd.cd_ndevs || APMUNIT(dev) != 0 || 501 1.1 ober !(sc = apm_cd.cd_devs[APMUNIT(dev)])) 502 1.1 ober return (ENXIO); 503 1.1 ober 504 1.1 ober DPRINTF(("apmclose: pid %d flag %x mode %x\n", p->p_pid, flag, mode)); 505 1.1 ober 506 1.1 ober switch (APMDEV(dev)) { 507 1.1 ober case APMDEV_CTL: 508 1.1 ober sc->sc_flags &= ~SCFLAG_OWRITE; 509 1.1 ober break; 510 1.1 ober case APMDEV_NORMAL: 511 1.1 ober sc->sc_flags &= ~SCFLAG_OREAD; 512 1.1 ober break; 513 1.1 ober } 514 1.1 ober return (0); 515 1.1 ober } 516 1.1 ober 517 1.1 ober int 518 1.1 ober apmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) 519 1.1 ober { 520 1.1 ober struct pxa2x0_apm_softc *sc; 521 1.1 ober struct apm_power_info *power; 522 1.1 ober int error = 0; 523 1.1 ober 524 1.1 ober /* apm0 only */ 525 1.1 ober if (!apm_cd.cd_ndevs || APMUNIT(dev) != 0 || 526 1.1 ober !(sc = apm_cd.cd_devs[APMUNIT(dev)])) 527 1.1 ober return (ENXIO); 528 1.1 ober 529 1.1 ober switch (cmd) { 530 1.1 ober /* some ioctl names from linux */ 531 1.1 ober case APM_IOC_STANDBY: 532 1.1 ober if ((flag & FWRITE) == 0) 533 1.1 ober error = EBADF; 534 1.1 ober else 535 1.1 ober apm_userstandbys++; 536 1.1 ober break; 537 1.1 ober case APM_IOC_SUSPEND: 538 1.1 ober if ((flag & FWRITE) == 0) 539 1.1 ober error = EBADF; 540 1.1 ober else 541 1.1 ober apm_suspends++; /* XXX */ 542 1.1 ober break; 543 1.1 ober case APM_IOC_PRN_CTL: 544 1.1 ober if ((flag & FWRITE) == 0) 545 1.1 ober error = EBADF; 546 1.1 ober else { 547 1.1 ober int flag = *(int *)data; 548 1.1 ober DPRINTF(( "APM_IOC_PRN_CTL: %d\n", flag )); 549 1.1 ober switch (flag) { 550 1.1 ober case APM_PRINT_ON: /* enable printing */ 551 1.1 ober sc->sc_flags &= ~SCFLAG_PRINT; 552 1.1 ober break; 553 1.1 ober case APM_PRINT_OFF: /* disable printing */ 554 1.1 ober sc->sc_flags &= ~SCFLAG_PRINT; 555 1.1 ober sc->sc_flags |= SCFLAG_NOPRINT; 556 1.1 ober break; 557 1.1 ober case APM_PRINT_PCT: /* disable some printing */ 558 1.1 ober sc->sc_flags &= ~SCFLAG_PRINT; 559 1.1 ober sc->sc_flags |= SCFLAG_PCTPRINT; 560 1.1 ober break; 561 1.1 ober default: 562 1.1 ober error = EINVAL; 563 1.1 ober break; 564 1.1 ober } 565 1.1 ober } 566 1.1 ober break; 567 1.1 ober case APM_IOC_DEV_CTL: 568 1.1 ober if ((flag & FWRITE) == 0) 569 1.1 ober error = EBADF; 570 1.1 ober break; 571 1.1 ober case APM_IOC_GETPOWER: 572 1.1 ober power = (struct apm_power_info *)data; 573 1.1 ober apm_power_info(sc, power); 574 1.1 ober break; 575 1.1 ober 576 1.1 ober default: 577 1.1 ober error = ENOTTY; 578 1.1 ober } 579 1.1 ober 580 1.1 ober return (error); 581 1.1 ober } 582 1.1 ober 583 1.1 ober int 584 1.1 ober apm_record_event(struct pxa2x0_apm_softc *sc, u_int type) 585 1.1 ober { 586 1.1 ober static int apm_evindex; 587 1.1 ober 588 1.1 ober /* skip if no user waiting */ 589 1.1 ober if ((sc->sc_flags & SCFLAG_OPEN) == 0) 590 1.1 ober return (1); 591 1.1 ober 592 1.1 ober apm_evindex++; 593 1.1 ober KNOTE(&sc->sc_note, APM_EVENT_COMPOSE(type, apm_evindex)); 594 1.1 ober 595 1.1 ober return (0); 596 1.1 ober } 597 1.1 ober 598 1.1 ober void 599 1.1 ober filt_apmrdetach(struct knote *kn) 600 1.1 ober { 601 1.1 ober struct pxa2x0_apm_softc *sc = 602 1.1 ober (struct pxa2x0_apm_softc *)kn->kn_hook; 603 1.1 ober 604 1.8 thorpej klist_remove(&sc->sc_note, kn); 605 1.1 ober } 606 1.1 ober 607 1.1 ober int 608 1.1 ober filt_apmread(struct knote *kn, long hint) 609 1.1 ober { 610 1.1 ober /* XXX weird kqueue_scan() semantics */ 611 1.1 ober if (hint && !kn->kn_data) 612 1.1 ober kn->kn_data = (int)hint; 613 1.1 ober 614 1.1 ober return (1); 615 1.1 ober } 616 1.1 ober 617 1.1 ober int 618 1.1 ober apmkqfilter(dev_t dev, struct knote *kn) 619 1.1 ober { 620 1.1 ober struct pxa2x0_apm_softc *sc; 621 1.1 ober 622 1.1 ober /* apm0 only */ 623 1.1 ober if (!apm_cd.cd_ndevs || APMUNIT(dev) != 0 || 624 1.1 ober !(sc = apm_cd.cd_devs[APMUNIT(dev)])) 625 1.1 ober return (ENXIO); 626 1.1 ober 627 1.1 ober switch (kn->kn_filter) { 628 1.1 ober case EVFILT_READ: 629 1.1 ober kn->kn_fop = &apmread_filtops; 630 1.1 ober break; 631 1.1 ober default: 632 1.7 thorpej return (EINVAL); 633 1.1 ober } 634 1.1 ober 635 1.1 ober kn->kn_hook = (caddr_t)sc; 636 1.8 thorpej klist_insert(&sc->sc_note, kn); 637 1.1 ober 638 1.1 ober return (0); 639 1.1 ober } 640 1.1 ober 641 1.1 ober void 642 1.1 ober pxa2x0_apm_attach_sub(struct pxa2x0_apm_softc *sc) 643 1.1 ober { 644 1.1 ober 645 1.1 ober sc->sc_iot = &pxa2x0_bs_tag; 646 1.1 ober 647 1.1 ober if (bus_space_map(sc->sc_iot, PXA2X0_POWMAN_BASE, 648 1.1 ober PXA2X0_POWMAN_SIZE, 0, &sc->sc_pm_ioh)) { 649 1.1 ober printf("pxa2x0_apm_attach_sub: failed to map POWMAN\n"); 650 1.1 ober return; 651 1.1 ober } 652 1.1 ober 653 1.1 ober lockinit(&sc->sc_lock, PWAIT, "apmlk", 0, 0); 654 1.8 thorpej klist_init(&sc->sc_note); 655 1.1 ober 656 1.1 ober kthread_create_deferred(apm_thread_create, sc); 657 1.1 ober 658 1.1 ober printf("\n"); 659 1.1 ober 660 1.1 ober if (bus_space_map(sc->sc_iot, PXA2X0_CLKMAN_BASE, PXA2X0_CLKMAN_SIZE, 661 1.1 ober 0, &pxa2x0_clkman_ioh)) { 662 1.3 chs printf("%s: failed to map CLKMAN\n", device_xname(sc->sc_dev)); 663 1.1 ober return; 664 1.1 ober } 665 1.1 ober 666 1.1 ober if (bus_space_map(sc->sc_iot, PXA2X0_MEMCTL_BASE, PXA2X0_MEMCTL_SIZE, 667 1.1 ober 0, &pxa2x0_memctl_ioh)) { 668 1.3 chs printf("%s: failed to map MEMCTL\n", device_xname(sc->sc_dev)); 669 1.1 ober return; 670 1.1 ober } 671 1.1 ober sc->sc_memctl_ioh = pxa2x0_memctl_ioh; 672 1.1 ober 673 1.1 ober if (bus_space_map(sc->sc_iot, PXA2X0_GPIO_BASE, PXA2X0_GPIO_SIZE, 674 1.1 ober 0, &pxa2x0_gpio_ioh)) { 675 1.3 chs printf("%s: can't map GPIO\n", device_xname(sc->sc_dev)); 676 1.1 ober return; 677 1.1 ober } 678 1.1 ober 679 1.1 ober /* Clear all reset status flags. */ 680 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_RCSR, 681 1.1 ober RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR); 682 1.1 ober } 683 1.1 ober #endif /* 0 */ 684 1.1 ober 685 1.1 ober void 686 1.1 ober pxa2x0_wakeup_config(u_int wsrc, int enable) 687 1.1 ober { 688 1.1 ober struct pxa2x0_apm_softc *sc; 689 1.4 skrll uint32_t prer; 690 1.4 skrll uint32_t pfer; 691 1.4 skrll uint32_t pkwr; 692 1.1 ober 693 1.1 ober if (zapm_cd.cd_ndevs < 1 || zapm_cd.cd_devs[0] == NULL) 694 1.1 ober return; 695 1.1 ober sc = device_private(zapm_cd.cd_devs[0]); 696 1.1 ober 697 1.1 ober prer = pfer = pkwr = 0; 698 1.1 ober 699 1.1 ober if ((wsrc & PXA2X0_WAKEUP_POWERON) != 0) { 700 1.1 ober prer |= (1<<0); 701 1.1 ober pfer |= (1<<0); 702 1.1 ober pkwr |= (1<<12); /* XXX */ 703 1.1 ober } 704 1.1 ober 705 1.1 ober if ((wsrc & PXA2X0_WAKEUP_GPIORST) != 0) 706 1.1 ober pfer |= (1<<1); 707 1.1 ober if ((wsrc & PXA2X0_WAKEUP_SD) != 0) 708 1.1 ober prer |= (1<<9); 709 1.1 ober if ((wsrc & PXA2X0_WAKEUP_RC) != 0) 710 1.1 ober prer |= (1<<13); 711 1.1 ober if ((wsrc & PXA2X0_WAKEUP_SYNC) != 0) 712 1.1 ober pkwr |= (1<<1); 713 1.1 ober if ((wsrc & PXA2X0_WAKEUP_KEYNS0) != 0) 714 1.1 ober prer |= (1<<12); 715 1.1 ober if ((wsrc & PXA2X0_WAKEUP_KEYNS1) != 0) 716 1.1 ober pkwr |= (1<<2); 717 1.1 ober if ((wsrc & PXA2X0_WAKEUP_KEYNS2) != 0) 718 1.1 ober pkwr |= (1<<9); 719 1.1 ober if ((wsrc & PXA2X0_WAKEUP_KEYNS3) != 0) 720 1.1 ober pkwr |= (1<<3); 721 1.1 ober if ((wsrc & PXA2X0_WAKEUP_KEYNS4) != 0) 722 1.1 ober pkwr |= (1<<4); 723 1.1 ober if ((wsrc & PXA2X0_WAKEUP_KEYNS5) != 0) 724 1.1 ober pkwr |= (1<<6); 725 1.1 ober if ((wsrc & PXA2X0_WAKEUP_KEYNS6) != 0) 726 1.1 ober pkwr |= (1<<7); 727 1.1 ober if ((wsrc & PXA2X0_WAKEUP_CF0) != 0) 728 1.1 ober pkwr |= (1<<11); 729 1.1 ober if ((wsrc & PXA2X0_WAKEUP_CF1) != 0) 730 1.1 ober pkwr |= (1<<10); 731 1.1 ober if ((wsrc & PXA2X0_WAKEUP_USBD) != 0) 732 1.1 ober prer |= (1<<24); 733 1.1 ober 734 1.1 ober if ((wsrc & PXA2X0_WAKEUP_LOCKSW) != 0) { 735 1.1 ober prer |= (1<<15); 736 1.1 ober pfer |= (1<<15); 737 1.1 ober } 738 1.1 ober 739 1.1 ober if ((wsrc & PXA2X0_WAKEUP_JACKIN) != 0) { 740 1.1 ober prer |= (1<<23); 741 1.1 ober pfer |= (1<<23); 742 1.1 ober } 743 1.1 ober 744 1.1 ober if ((wsrc & PXA2X0_WAKEUP_CHRGFULL) != 0) 745 1.1 ober pkwr |= (1<<18); 746 1.1 ober if ((wsrc & PXA2X0_WAKEUP_RTC) != 0) 747 1.1 ober prer |= (1<<31); 748 1.1 ober 749 1.1 ober if (enable) { 750 1.1 ober sc->sc_wakeon |= wsrc; 751 1.1 ober prer |= bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, 752 1.1 ober POWMAN_PRER); 753 1.1 ober pfer |= bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, 754 1.1 ober POWMAN_PFER); 755 1.1 ober pkwr |= bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, 756 1.1 ober POWMAN_PKWR); 757 1.1 ober } else { 758 1.1 ober sc->sc_wakeon &= ~wsrc; 759 1.1 ober prer = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, 760 1.1 ober POWMAN_PRER) & ~prer; 761 1.1 ober pfer = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, 762 1.1 ober POWMAN_PFER) & ~pfer; 763 1.1 ober pkwr = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, 764 1.1 ober POWMAN_PKWR) & ~pkwr; 765 1.1 ober } 766 1.1 ober 767 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PKWR, pkwr); 768 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PRER, prer); 769 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PFER, pfer); 770 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PWER, 771 1.1 ober prer | pfer); 772 1.1 ober } 773 1.1 ober 774 1.1 ober u_int 775 1.1 ober pxa2x0_wakeup_status(void) 776 1.1 ober { 777 1.1 ober struct pxa2x0_apm_softc *sc; 778 1.4 skrll uint32_t rv; 779 1.1 ober u_int wsrc; 780 1.1 ober 781 1.1 ober if (zapm_cd.cd_ndevs < 1 || zapm_cd.cd_devs[0] == NULL) 782 1.1 ober return (0); 783 1.1 ober 784 1.1 ober sc = device_private(zapm_cd.cd_devs[0]); 785 1.1 ober wsrc = 0; 786 1.1 ober 787 1.1 ober rv = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PEDR); 788 1.1 ober if ((rv & (1<<0)) != 0) 789 1.1 ober wsrc |= PXA2X0_WAKEUP_POWERON; 790 1.1 ober if ((rv & (1<<1)) != 0) 791 1.1 ober wsrc |= PXA2X0_WAKEUP_GPIORST; 792 1.1 ober if ((rv & (1<<9)) != 0) 793 1.1 ober wsrc |= PXA2X0_WAKEUP_SD; 794 1.1 ober if ((rv & (1<<12)) != 0) 795 1.1 ober wsrc |= PXA2X0_WAKEUP_KEYNS0; 796 1.1 ober if ((rv & (1<<13)) != 0) 797 1.1 ober wsrc |= PXA2X0_WAKEUP_RC; 798 1.1 ober if ((rv & (1<<15)) != 0) 799 1.1 ober wsrc |= PXA2X0_WAKEUP_LOCKSW; 800 1.1 ober if ((rv & (1<<23)) != 0) 801 1.1 ober wsrc |= PXA2X0_WAKEUP_JACKIN; 802 1.1 ober if ((rv & (1<<24)) != 0) 803 1.1 ober wsrc |= PXA2X0_WAKEUP_USBD; 804 1.1 ober if ((rv & (1<<31)) != 0) 805 1.1 ober wsrc |= PXA2X0_WAKEUP_RTC; 806 1.1 ober 807 1.1 ober rv = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PKSR); 808 1.1 ober if ((rv & (1<<1)) != 0) 809 1.1 ober wsrc |= PXA2X0_WAKEUP_SYNC; 810 1.1 ober if ((rv & (1<<2)) != 0) 811 1.1 ober wsrc |= PXA2X0_WAKEUP_KEYNS1; 812 1.1 ober if ((rv & (1<<9)) != 0) 813 1.1 ober wsrc |= PXA2X0_WAKEUP_KEYNS2; 814 1.1 ober if ((rv & (1<<3)) != 0) 815 1.1 ober wsrc |= PXA2X0_WAKEUP_KEYNS3; 816 1.1 ober if ((rv & (1<<4)) != 0) 817 1.1 ober wsrc |= PXA2X0_WAKEUP_KEYNS4; 818 1.1 ober if ((rv & (1<<6)) != 0) 819 1.1 ober wsrc |= PXA2X0_WAKEUP_KEYNS5; 820 1.1 ober if ((rv & (1<<7)) != 0) 821 1.1 ober wsrc |= PXA2X0_WAKEUP_KEYNS6; 822 1.1 ober if ((rv & (1<<10)) != 0) 823 1.1 ober wsrc |= PXA2X0_WAKEUP_CF1; 824 1.1 ober if ((rv & (1<<11)) != 0) 825 1.1 ober wsrc |= PXA2X0_WAKEUP_CF0; 826 1.1 ober if ((rv & (1<<12)) != 0) 827 1.1 ober wsrc |= PXA2X0_WAKEUP_POWERON; 828 1.1 ober if ((rv & (1<<18)) != 0) 829 1.1 ober wsrc |= PXA2X0_WAKEUP_CHRGFULL; 830 1.1 ober 831 1.1 ober return (wsrc); 832 1.1 ober } 833 1.1 ober 834 1.1 ober struct pxa2x0_sleep_data { 835 1.1 ober /* OS timer registers */ 836 1.4 skrll uint32_t sd_osmr0, sd_osmr1, sd_osmr2, sd_osmr3; 837 1.4 skrll uint32_t sd_oscr0; 838 1.4 skrll uint32_t sd_osmr4, sd_osmr5; 839 1.4 skrll uint32_t sd_oscr4; 840 1.4 skrll uint32_t sd_omcr4, sd_omcr5; 841 1.4 skrll uint32_t sd_oier; 842 1.1 ober /* GPIO registers */ 843 1.4 skrll uint32_t sd_gpdr0, sd_gpdr1, sd_gpdr2, sd_gpdr3; 844 1.4 skrll uint32_t sd_grer0, sd_grer1, sd_grer2, sd_grer3; 845 1.4 skrll uint32_t sd_gfer0, sd_gfer1, sd_gfer2, sd_gfer3; 846 1.4 skrll uint32_t sd_gafr0_l, sd_gafr1_l, sd_gafr2_l, sd_gafr3_l; 847 1.4 skrll uint32_t sd_gafr0_u, sd_gafr1_u, sd_gafr2_u, sd_gafr3_u; 848 1.4 skrll uint32_t sd_gplr0, sd_gplr1, sd_gplr2, sd_gplr3; 849 1.1 ober /* Interrupt controller registers */ 850 1.4 skrll uint32_t sd_iclr; 851 1.4 skrll uint32_t sd_icmr; 852 1.4 skrll uint32_t sd_iccr; 853 1.1 ober /* Memory controller registers */ 854 1.4 skrll uint32_t sd_mecr; 855 1.4 skrll uint32_t sd_mcmem0, sd_mcmem1; 856 1.4 skrll uint32_t sd_mcatt0, sd_mcatt1; 857 1.4 skrll uint32_t sd_mcio0, sd_mcio1; 858 1.1 ober /* Clocks manager registers */ 859 1.4 skrll uint32_t sd_cken; 860 1.1 ober }; 861 1.1 ober 862 1.1 ober void 863 1.1 ober pxa2x0_apm_sleep(struct pxa2x0_apm_softc *sc) 864 1.1 ober { 865 1.1 ober struct pxa2x0_sleep_data sd; 866 1.1 ober bus_space_handle_t ost_ioh; 867 1.1 ober int save; 868 1.4 skrll uint32_t rv; 869 1.1 ober 870 1.1 ober ost_ioh = (bus_space_handle_t)0; 871 1.1 ober if (bus_space_map(sc->sc_iot, PXA2X0_OST_BASE, PXA2X0_OST_SIZE, 0, 872 1.1 ober &ost_ioh)) { 873 1.1 ober printf("pxa2x0_apm_sleep: can't map OST\n"); 874 1.1 ober goto out; 875 1.1 ober } 876 1.1 ober 877 1.1 ober save = disable_interrupts(I32_bit|F32_bit); 878 1.1 ober 879 1.1 ober sd.sd_oscr0 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSCR0); 880 1.1 ober sd.sd_oscr4 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSCR4); 881 1.1 ober sd.sd_omcr4 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OMCR4); 882 1.1 ober sd.sd_omcr5 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OMCR5); 883 1.1 ober sd.sd_osmr0 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR0); 884 1.1 ober sd.sd_osmr1 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR1); 885 1.1 ober sd.sd_osmr2 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR2); 886 1.1 ober sd.sd_osmr3 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR3); 887 1.1 ober sd.sd_osmr4 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR4); 888 1.1 ober sd.sd_osmr5 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR5); 889 1.1 ober sd.sd_oier = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OIER); 890 1.1 ober 891 1.1 ober /* Bring the PXA27x into 416MHz turbo mode. */ 892 1.1 ober if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) == CPU_ID_PXA27X && 893 1.1 ober bus_space_read_4(sc->sc_iot, pxa2x0_clkman_ioh, CLKMAN_CCCR) != 894 1.1 ober (CCCR_A | CCCR_TURBO_X2 | CCCR_RUN_X16)) { 895 1.1 ober #if 0 896 1.1 ober pxa27x_cpu_speed_high(); 897 1.1 ober #else 898 1.1 ober #define CLKCFG_T (1<<0) /* turbo */ 899 1.1 ober #define CLKCFG_F (1<<1) /* frequency change */ 900 1.1 ober #define CLKCFG_B (1<<3) /* fast-bus */ 901 1.1 ober pxa27x_frequency_change(CCCR_A | CCCR_TURBO_X2 | 902 1.1 ober CCCR_RUN_X16, CLKCFG_B | CLKCFG_F | CLKCFG_T, 903 1.1 ober &pxa2x0_memcfg); 904 1.1 ober #endif 905 1.1 ober delay(500000); /* XXX */ 906 1.1 ober } 907 1.1 ober 908 1.1 ober suspend_again: 909 1.1 ober /* Clear wake-up status. */ 910 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PEDR, 911 1.1 ober 0xffffffff); 912 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PKSR, 913 1.1 ober 0xffffffff); 914 1.1 ober 915 1.1 ober /* XXX control battery charging in sleep mode. */ 916 1.1 ober 917 1.1 ober /* XXX schedule RTC alarm to check the battery, or schedule 918 1.1 ober XXX wake-up shortly before an already programmed alarm? */ 919 1.1 ober 920 1.1 ober pxa27x_run_mode(); 921 1.1 ober #define MDREFR_LOW (MDREFR_C3000 | 0x00b) 922 1.1 ober pxa27x_fastbus_run_mode(0, MDREFR_LOW); 923 1.1 ober delay(1); 924 1.1 ober #if 1 925 1.1 ober pxa27x_cpu_speed_91(); 926 1.1 ober #else 927 1.1 ober pxa27x_frequency_change(CCCR_TURBO_X1 | CCCR_RUN_X7, CLKCFG_F, 928 1.1 ober &pxa2x0_memcfg); 929 1.1 ober #endif 930 1.1 ober pxa2x0_pi2c_setvoltage(sc->sc_iot, sc->sc_pm_ioh, PI2C_VOLTAGE_LOW); 931 1.1 ober 932 1.1 ober sd.sd_gpdr0 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR0); 933 1.1 ober sd.sd_gpdr1 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR1); 934 1.1 ober sd.sd_gpdr2 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR2); 935 1.1 ober sd.sd_gpdr3 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR3); 936 1.1 ober 937 1.1 ober sd.sd_grer0 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER0); 938 1.1 ober sd.sd_grer1 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER1); 939 1.1 ober sd.sd_grer2 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER2); 940 1.1 ober sd.sd_grer3 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER3); 941 1.1 ober 942 1.1 ober sd.sd_gfer0 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER0); 943 1.1 ober sd.sd_gfer1 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER1); 944 1.1 ober sd.sd_gfer2 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER2); 945 1.1 ober sd.sd_gfer3 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER3); 946 1.1 ober 947 1.1 ober sd.sd_gafr0_l = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR0_L); 948 1.1 ober sd.sd_gafr1_l = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR1_L); 949 1.1 ober sd.sd_gafr2_l = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR2_L); 950 1.1 ober sd.sd_gafr3_l = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR3_L); 951 1.1 ober 952 1.1 ober sd.sd_gafr0_u = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR0_U); 953 1.1 ober sd.sd_gafr1_u = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR1_U); 954 1.1 ober sd.sd_gafr2_u = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR2_U); 955 1.1 ober sd.sd_gafr3_u = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR3_U); 956 1.1 ober 957 1.1 ober sd.sd_gplr0 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPLR0); 958 1.1 ober sd.sd_gplr1 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPLR1); 959 1.1 ober sd.sd_gplr2 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPLR2); 960 1.1 ober sd.sd_gplr3 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPLR3); 961 1.1 ober 962 1.1 ober sd.sd_iclr = read_icu(INTCTL_ICLR); 963 1.1 ober sd.sd_icmr = read_icu(INTCTL_ICMR); 964 1.1 ober sd.sd_iccr = read_icu(INTCTL_ICCR); 965 1.1 ober write_icu(INTCTL_ICMR, 0); 966 1.1 ober 967 1.1 ober sd.sd_mecr = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh, 968 1.1 ober MEMCTL_MECR); 969 1.1 ober sd.sd_mcmem0 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh, 970 1.1 ober MEMCTL_MCMEM(0)); 971 1.1 ober sd.sd_mcmem1 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh, 972 1.1 ober MEMCTL_MCMEM(1)); 973 1.1 ober sd.sd_mcatt0 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh, 974 1.1 ober MEMCTL_MCATT(0)); 975 1.1 ober sd.sd_mcatt1 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh, 976 1.1 ober MEMCTL_MCATT(1)); 977 1.1 ober sd.sd_mcio0 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh, 978 1.1 ober MEMCTL_MCIO(0)); 979 1.1 ober sd.sd_mcio1 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh, 980 1.1 ober MEMCTL_MCIO(1)); 981 1.1 ober 982 1.1 ober sd.sd_cken = bus_space_read_4(sc->sc_iot, pxa2x0_clkman_ioh, 983 1.1 ober CLKMAN_CKEN); 984 1.1 ober 985 1.1 ober /* 986 1.1 ober * Stop clocks to all units except to the memory controller, and 987 1.1 ober * to the keypad controller if it is enabled as a wake-up source. 988 1.1 ober */ 989 1.1 ober rv = CKEN_MEM; 990 1.1 ober if ((sc->sc_wakeon & PXA2X0_WAKEUP_KEYNS_ALL) != 0) 991 1.1 ober rv |= CKEN_KEY; 992 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_clkman_ioh, CLKMAN_CKEN, rv); 993 1.1 ober 994 1.1 ober /* Disable nRESET_OUT. */ 995 1.1 ober rv = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSLR); 996 1.1 ober #define PSLR_SL_ROD (1<<20) 997 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSLR, 998 1.1 ober rv | PSLR_SL_ROD); 999 1.1 ober 1000 1.1 ober /* Clear all reset status flags. */ 1001 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_RCSR, 1002 1.1 ober RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR); 1003 1.1 ober 1004 1.1 ober /* Stop 3/13MHz oscillator; do not float PCMCIA and chip-selects. */ 1005 1.1 ober rv = PCFR_OPDE; 1006 1.1 ober if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) == CPU_ID_PXA27X) 1007 1.1 ober /* Enable nRESET_GPIO as a GPIO reset input. */ 1008 1.1 ober rv |= PCFR_GPR_EN; 1009 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PCFR, rv); 1010 1.1 ober 1011 1.1 ober /* XXX C3000 */ 1012 1.1 ober #define GPIO_G0_STROBE_BIT 0x0f800000 1013 1.1 ober #define GPIO_G1_STROBE_BIT 0x00100000 1014 1.1 ober #define GPIO_G2_STROBE_BIT 0x01000000 1015 1.1 ober #define GPIO_G3_STROBE_BIT 0x00041880 1016 1.1 ober #define GPIO_KEY_STROBE0 88 1017 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR0, 1018 1.1 ober 0x00144018); 1019 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR1, 1020 1.1 ober 0x00ef0000); 1021 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR2, 1022 1.1 ober 0x0121c000); 1023 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR3, 1024 1.1 ober 0x00600000); 1025 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR0, 1026 1.1 ober 0x00144018 & ~GPIO_G0_STROBE_BIT); 1027 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR1, 1028 1.1 ober 0x00ef0000 & ~GPIO_G1_STROBE_BIT); 1029 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR2, 1030 1.1 ober 0x0121c000 & ~GPIO_G2_STROBE_BIT); 1031 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR3, 1032 1.1 ober 0x00600000 & ~GPIO_G3_STROBE_BIT); 1033 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR2, 1034 1.1 ober (0x0121c000 & ~GPIO_G2_STROBE_BIT) | 1035 1.1 ober GPIO_BIT(GPIO_KEY_STROBE0)); 1036 1.1 ober 1037 1.1 ober /* C3000 */ 1038 1.1 ober #define GPIO_EXT_BUS_READY 18 1039 1.1 ober pxa2x0_gpio_set_function(GPIO_EXT_BUS_READY, GPIO_SET | GPIO_OUT); 1040 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR0, 0xd01c4418); 1041 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR1, 0xfcefbd21); 1042 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR2, 0x13a5ffff); 1043 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR3, 0x01e3e10c); 1044 1.1 ober 1045 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSPR, 1046 1.4 skrll (uint32_t)&pxa2x0_cpu_resume - 0xc0200000 + 0xa0200000); 1047 1.1 ober 1048 1.1 ober pxa2x0_cpu_suspend(); 1049 1.1 ober 1050 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSPR, 0); 1051 1.1 ober 1052 1.1 ober pxa2x0_clkman_config(CKEN_SSP|CKEN_PWM0|CKEN_PWM1, 1); 1053 1.1 ober pxa2x0_clkman_config(CKEN_KEY, 0); 1054 1.1 ober 1055 1.1 ober #if 1 1056 1.1 ober /* Clear all GPIO interrupt sources. */ 1057 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GEDR0, 0xffffffff); 1058 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GEDR1, 0xffffffff); 1059 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GEDR2, 0xffffffff); 1060 1.1 ober #endif 1061 1.1 ober 1062 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR0, sd.sd_gpdr0); 1063 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR1, sd.sd_gpdr1); 1064 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR2, sd.sd_gpdr2); 1065 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER0, sd.sd_grer0); 1066 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER1, sd.sd_grer1); 1067 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER2, sd.sd_grer2); 1068 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER0, sd.sd_gfer0); 1069 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER1, sd.sd_gfer1); 1070 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER2, sd.sd_gfer2); 1071 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR0_L, sd.sd_gafr0_l); 1072 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR1_L, sd.sd_gafr1_l); 1073 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR2_L, sd.sd_gafr2_l); 1074 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR0_U, sd.sd_gafr0_u); 1075 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR1_U, sd.sd_gafr1_u); 1076 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR2_U, sd.sd_gafr2_u); 1077 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPSR0, sd.sd_gplr0 & 1078 1.1 ober sd.sd_gpdr0); 1079 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPSR1, sd.sd_gplr1 & 1080 1.1 ober sd.sd_gpdr1); 1081 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPSR2, sd.sd_gplr2 & 1082 1.1 ober sd.sd_gpdr2); 1083 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPCR0, ~sd.sd_gplr0 & 1084 1.1 ober sd.sd_gpdr0); 1085 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPCR1, ~sd.sd_gplr1 & 1086 1.1 ober sd.sd_gpdr1); 1087 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPCR2, ~sd.sd_gplr2 & 1088 1.1 ober sd.sd_gpdr2); 1089 1.1 ober 1090 1.1 ober /* PXA27x */ 1091 1.1 ober #if 0 1092 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GEDR3, 0xffffffff); 1093 1.1 ober #endif 1094 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR3, sd.sd_gpdr3); 1095 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER3, sd.sd_grer3); 1096 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER3, sd.sd_gfer3); 1097 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR3_L, sd.sd_gafr3_l); 1098 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR3_U, sd.sd_gafr3_u); 1099 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPSR3, sd.sd_gplr3 & 1100 1.1 ober sd.sd_gpdr3); 1101 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPCR3, ~sd.sd_gplr3 & 1102 1.1 ober sd.sd_gpdr3); 1103 1.1 ober 1104 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MECR, 1105 1.1 ober sd.sd_mecr); 1106 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MCMEM(0), 1107 1.1 ober sd.sd_mcmem0); 1108 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MCMEM(1), 1109 1.1 ober sd.sd_mcmem1); 1110 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MCATT(0), 1111 1.1 ober sd.sd_mcatt0); 1112 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MCATT(1), 1113 1.1 ober sd.sd_mcatt1); 1114 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MCIO(0), 1115 1.1 ober sd.sd_mcio0); 1116 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MCIO(1), 1117 1.1 ober sd.sd_mcio1); 1118 1.1 ober 1119 1.1 ober bus_space_write_4(sc->sc_iot, pxa2x0_clkman_ioh, CLKMAN_CKEN, 1120 1.1 ober sd.sd_cken); 1121 1.1 ober 1122 1.1 ober write_icu(INTCTL_ICLR, sd.sd_iclr); 1123 1.1 ober write_icu(INTCTL_ICCR, sd.sd_iccr); 1124 1.1 ober write_icu(INTCTL_ICMR, sd.sd_icmr); 1125 1.1 ober 1126 1.1 ober if ((read_icu(INTCTL_ICIP) & 0x1) != 0) 1127 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PEDR, 0x1); 1128 1.1 ober 1129 1.1 ober bus_space_write_4(sc->sc_iot, ost_ioh, OST_OSMR0, sd.sd_osmr0); 1130 1.1 ober bus_space_write_4(sc->sc_iot, ost_ioh, OST_OSMR1, sd.sd_osmr1); 1131 1.1 ober bus_space_write_4(sc->sc_iot, ost_ioh, OST_OSMR2, sd.sd_osmr2); 1132 1.1 ober bus_space_write_4(sc->sc_iot, ost_ioh, OST_OSMR3, sd.sd_osmr3); 1133 1.1 ober bus_space_write_4(sc->sc_iot, ost_ioh, OST_OSMR4, sd.sd_osmr4); 1134 1.1 ober bus_space_write_4(sc->sc_iot, ost_ioh, OST_OSMR5, sd.sd_osmr5); 1135 1.1 ober bus_space_write_4(sc->sc_iot, ost_ioh, OST_OMCR4, sd.sd_omcr4); 1136 1.1 ober bus_space_write_4(sc->sc_iot, ost_ioh, OST_OMCR5, sd.sd_omcr5); 1137 1.1 ober bus_space_write_4(sc->sc_iot, ost_ioh, OST_OSCR0, sd.sd_oscr0); 1138 1.1 ober bus_space_write_4(sc->sc_iot, ost_ioh, OST_OSCR4, sd.sd_oscr4); 1139 1.1 ober bus_space_write_4(sc->sc_iot, ost_ioh, OST_OIER, sd.sd_oier); 1140 1.1 ober 1141 1.1 ober pxa2x0_pi2c_setvoltage(sc->sc_iot, sc->sc_pm_ioh, PI2C_VOLTAGE_HIGH); 1142 1.1 ober 1143 1.1 ober /* Change to 208MHz run mode with fast-bus still disabled. */ 1144 1.1 ober pxa27x_frequency_change(CCCR_A | CCCR_TURBO_X2 | CCCR_RUN_X16, 1145 1.1 ober CLKCFG_F, &pxa2x0_memcfg); 1146 1.1 ober delay(1); /* XXX is the delay long enough, and necessary at all? */ 1147 1.1 ober pxa27x_fastbus_run_mode(1, pxa2x0_memcfg.mdrefr_high); 1148 1.1 ober 1149 1.1 ober /* Change to 416MHz turbo mode with fast-bus enabled. */ 1150 1.1 ober pxa27x_frequency_change(CCCR_A | CCCR_TURBO_X2 | CCCR_RUN_X16, 1151 1.1 ober CLKCFG_B | CLKCFG_F | CLKCFG_T, &pxa2x0_memcfg); 1152 1.1 ober 1153 1.1 ober if (sc->sc_resume != NULL) { 1154 1.1 ober if (!sc->sc_resume(sc)) 1155 1.1 ober goto suspend_again; 1156 1.1 ober } 1157 1.1 ober 1158 1.1 ober /* 1159 1.1 ober * Allow immediate entry into deep-sleep mode if power fails. 1160 1.1 ober * Resume from immediate deep-sleep is not implemented yet. 1161 1.1 ober */ 1162 1.1 ober bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PMCR, 0); 1163 1.1 ober 1164 1.1 ober 1165 1.1 ober restore_interrupts(save); 1166 1.1 ober 1167 1.1 ober #if 0 1168 1.1 ober pxa2x0_setperf(perflevel); 1169 1.1 ober #endif 1170 1.1 ober 1171 1.1 ober out: 1172 1.1 ober if (ost_ioh != (bus_space_handle_t)0) 1173 1.1 ober bus_space_unmap(sc->sc_iot, ost_ioh, PXA2X0_OST_SIZE); 1174 1.1 ober } 1175 1.1 ober 1176 1.1 ober void 1177 1.1 ober pxa2x0_pi2c_open(bus_space_tag_t iot, bus_space_handle_t ioh) 1178 1.1 ober { 1179 1.4 skrll uint32_t rv; 1180 1.1 ober 1181 1.1 ober /* Enable the I2C unit, and disable automatic voltage change. */ 1182 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PCFR); 1183 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PCFR, rv | PCFR_PI2C_EN); 1184 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PCFR); 1185 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PCFR, rv & ~PCFR_FVC); 1186 1.1 ober delay(1); 1187 1.1 ober 1188 1.1 ober /* Enable the clock to the power manager I2C unit. */ 1189 1.1 ober pxa2x0_clkman_config(CKEN_PI2C, 1); 1190 1.1 ober delay(1); 1191 1.1 ober } 1192 1.1 ober 1193 1.1 ober void 1194 1.1 ober pxa2x0_pi2c_close(bus_space_tag_t iot, bus_space_handle_t ioh) 1195 1.1 ober { 1196 1.4 skrll uint32_t rv; 1197 1.1 ober 1198 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, PICR_UR); 1199 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PISAR, 0); 1200 1.1 ober delay(1); 1201 1.1 ober 1202 1.1 ober /* Disable the clock to the power manager I2C unit. */ 1203 1.1 ober pxa2x0_clkman_config(CKEN_PI2C, 0); 1204 1.1 ober delay(1); 1205 1.1 ober 1206 1.1 ober /* Disable the I2C unit, and disable automatic voltage change. */ 1207 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PCFR); 1208 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PCFR, 1209 1.1 ober rv & ~(PCFR_PI2C_EN | PCFR_FVC)); 1210 1.1 ober delay(1); 1211 1.1 ober } 1212 1.1 ober 1213 1.1 ober int 1214 1.1 ober pxa2x0_pi2c_read(bus_space_tag_t iot, bus_space_handle_t ioh, 1215 1.1 ober u_char slave, u_char *valuep) 1216 1.1 ober { 1217 1.4 skrll uint32_t rv; 1218 1.1 ober int timeout; 1219 1.1 ober int tries = PI2C_RETRY_COUNT; 1220 1.1 ober 1221 1.1 ober retry: 1222 1.1 ober 1223 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, PICR_UR); 1224 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PISAR, 0x00); 1225 1.1 ober delay(1); 1226 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, PICR_IUE | PICR_SCLE); 1227 1.1 ober 1228 1.1 ober /* Write slave device address. */ 1229 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PIDBR, (slave<<1) | 0x1); 1230 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PICR); 1231 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, rv | PICR_START); 1232 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PICR); 1233 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, rv & ~PICR_STOP); 1234 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PICR); 1235 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, rv | PICR_TB); 1236 1.1 ober 1237 1.1 ober timeout = 10000; 1238 1.1 ober while ((bus_space_read_4(iot, ioh, POWMAN_PISR) & PISR_ITE) == 0) { 1239 1.1 ober if (timeout-- == 0) { 1240 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PISR, PISR_ITE); 1241 1.1 ober goto err; 1242 1.1 ober } 1243 1.1 ober delay(1); 1244 1.1 ober } 1245 1.1 ober 1246 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PISR, PISR_ITE); 1247 1.1 ober 1248 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PICR); 1249 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, rv & ~PICR_START); 1250 1.1 ober 1251 1.1 ober /* Read data value. */ 1252 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PICR); 1253 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, rv | 1254 1.1 ober (PICR_STOP | PICR_ACKNAK)); 1255 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PICR); 1256 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, rv | PICR_TB); 1257 1.1 ober 1258 1.1 ober timeout = 10000; 1259 1.1 ober while ((bus_space_read_4(iot, ioh, POWMAN_PISR) & PISR_IRF) == 0) { 1260 1.1 ober if (timeout-- == 0) { 1261 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PISR, PISR_IRF); 1262 1.1 ober goto err; 1263 1.1 ober } 1264 1.1 ober delay(1); 1265 1.1 ober } 1266 1.1 ober 1267 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PISR, PISR_IRF); 1268 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PIDBR); 1269 1.1 ober *valuep = (u_char)rv; 1270 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PICR); 1271 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, rv & 1272 1.1 ober ~(PICR_STOP | PICR_ACKNAK)); 1273 1.1 ober 1274 1.1 ober return (0); 1275 1.1 ober err: 1276 1.1 ober if (tries-- >= 0) 1277 1.1 ober goto retry; 1278 1.1 ober 1279 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, PICR_UR); 1280 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PISAR, 0x00); 1281 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, PICR_IUE | PICR_SCLE); 1282 1.1 ober 1283 1.1 ober return (-EIO); 1284 1.1 ober } 1285 1.1 ober 1286 1.1 ober int 1287 1.1 ober pxa2x0_pi2c_write(bus_space_tag_t iot, bus_space_handle_t ioh, 1288 1.1 ober u_char slave, u_char value) 1289 1.1 ober { 1290 1.4 skrll uint32_t rv; 1291 1.1 ober int timeout; 1292 1.1 ober int tries = PI2C_RETRY_COUNT; 1293 1.1 ober 1294 1.1 ober retry: 1295 1.1 ober 1296 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, PICR_UR); 1297 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PISAR, 0x00); 1298 1.1 ober delay(1); 1299 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, PICR_IUE | PICR_SCLE); 1300 1.1 ober 1301 1.1 ober /* Write slave device address. */ 1302 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PIDBR, (slave<<1)); 1303 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PICR); 1304 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, rv | PICR_START); 1305 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PICR); 1306 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, rv & ~PICR_STOP); 1307 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PICR); 1308 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, rv | PICR_TB); 1309 1.1 ober 1310 1.1 ober timeout = 10000; 1311 1.1 ober while ((bus_space_read_4(iot, ioh, POWMAN_PISR) & PISR_ITE) == 0) { 1312 1.1 ober if (timeout-- == 0) { 1313 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PISR, PISR_ITE); 1314 1.1 ober goto err; 1315 1.1 ober } 1316 1.1 ober delay(1); 1317 1.1 ober } 1318 1.1 ober if ((bus_space_read_4(iot, ioh, POWMAN_PISR) & PISR_ACKNAK) != 0) 1319 1.1 ober goto err; 1320 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PISR, PISR_ITE); 1321 1.1 ober 1322 1.1 ober /* Write data. */ 1323 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PICR); 1324 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, rv & ~PICR_START); 1325 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PICR); 1326 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, rv | PICR_STOP); 1327 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PIDBR, value); 1328 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PICR); 1329 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, rv | PICR_TB); 1330 1.1 ober 1331 1.1 ober timeout = 10000; 1332 1.1 ober while ((bus_space_read_4(iot, ioh, POWMAN_PISR) & PISR_ITE) == 0) { 1333 1.1 ober if (timeout-- == 0) { 1334 1.1 ober #if 0 1335 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PISR, PISR_ITE); 1336 1.1 ober #endif 1337 1.1 ober goto err; 1338 1.1 ober } 1339 1.1 ober delay(1); 1340 1.1 ober } 1341 1.1 ober if ((bus_space_read_4(iot, ioh, POWMAN_PISR) & PISR_ACKNAK) != 0) 1342 1.1 ober goto err; 1343 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PISR, PISR_ITE); 1344 1.1 ober 1345 1.1 ober rv = bus_space_read_4(iot, ioh, POWMAN_PICR); 1346 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, rv & ~PICR_STOP); 1347 1.1 ober 1348 1.1 ober return (0); 1349 1.1 ober err: 1350 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PISR, PISR_ITE); 1351 1.1 ober if (tries-- >= 0) 1352 1.1 ober goto retry; 1353 1.1 ober 1354 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, PICR_UR); 1355 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PISAR, 0x00); 1356 1.1 ober bus_space_write_4(iot, ioh, POWMAN_PICR, PICR_IUE | PICR_SCLE); 1357 1.1 ober 1358 1.1 ober return (-EIO); 1359 1.1 ober } 1360 1.1 ober 1361 1.1 ober int 1362 1.1 ober pxa2x0_pi2c_getvoltage(bus_space_tag_t iot, bus_space_handle_t ioh, 1363 1.1 ober u_char *valuep) 1364 1.1 ober { 1365 1.1 ober int res; 1366 1.1 ober 1367 1.1 ober pxa2x0_pi2c_open(iot, ioh); 1368 1.1 ober res = pxa2x0_pi2c_read(iot, ioh, 0x0c, valuep); 1369 1.1 ober pxa2x0_pi2c_close(iot, ioh); 1370 1.1 ober return (res); 1371 1.1 ober } 1372 1.1 ober 1373 1.1 ober int 1374 1.1 ober pxa2x0_pi2c_setvoltage(bus_space_tag_t iot, bus_space_handle_t ioh, 1375 1.1 ober u_char value) 1376 1.1 ober { 1377 1.1 ober int res; 1378 1.1 ober 1379 1.1 ober pxa2x0_pi2c_open(iot, ioh); 1380 1.1 ober res = pxa2x0_pi2c_write(iot, ioh, 0x0c, value); 1381 1.1 ober pxa2x0_pi2c_close(iot, ioh); 1382 1.1 ober return (res); 1383 1.1 ober } 1384 1.1 ober 1385 1.1 ober #if 0 1386 1.1 ober void 1387 1.1 ober pxa2x0_pi2c_print(struct pxa2x0_apm_softc *sc) 1388 1.1 ober { 1389 1.1 ober u_char value = 0; 1390 1.1 ober 1391 1.1 ober (void)pxa2x0_pi2c_getvoltage(sc->sc_iot, sc->sc_pm_ioh, &value); 1392 1.1 ober printf("xscale core voltage: %s\n", value == PI2C_VOLTAGE_HIGH ? 1393 1.1 ober "high" : (value == PI2C_VOLTAGE_LOW ? "low" : "unknown")); 1394 1.1 ober } 1395 1.1 ober #endif 1396 1.1 ober 1397 1.1 ober struct { 1398 1.1 ober int maxspeed; 1399 1.1 ober int numspeeds; 1400 1.1 ober int hz [6]; 1401 1.9 andvar int rate [6]; /* could this be simplified by not having 100% in table? */ 1402 1.1 ober } 1403 1.1 ober speedtables[] = { 1404 1.1 ober { 91, 1, { 91 }, { 100 }}, 1405 1.1 ober { 208, 2, { 91, 208}, {50, 100}}, 1406 1.1 ober { 416, 3, { 91, 208, 416}, {25, 50, 100}}, 1407 1.1 ober { 520, 4, { 91, 208, 416, 520}, {18, 40 ,80, 100}}, 1408 1.1 ober { 624, 5, { 91, 208, 416, 520, 624}, {15, 34, 67, 82, 100}}, 1409 1.1 ober { 0 } 1410 1.1 ober }; 1411 1.1 ober int xscale_maxspeed = 416; /* XXX */ 1412 1.1 ober 1413 1.1 ober int speed_to_freq(int speed); 1414 1.1 ober 1415 1.1 ober int 1416 1.1 ober speed_to_freq(int speed) 1417 1.1 ober { 1418 1.1 ober int i, j; 1419 1.1 ober int newspeed = 0; 1420 1.1 ober int numspeeds; 1421 1.1 ober for (i = 0; speedtables[i].maxspeed != 0; i++) { 1422 1.1 ober if (speedtables[i].maxspeed != xscale_maxspeed) 1423 1.1 ober continue; 1424 1.1 ober 1425 1.1 ober if (speed <= speedtables[i].rate[0]) { 1426 1.1 ober return speedtables[i].hz[0]; 1427 1.1 ober 1428 1.1 ober } 1429 1.1 ober numspeeds = speedtables[i].numspeeds; 1430 1.1 ober if (speed == speedtables[i].rate[numspeeds-1]) { 1431 1.1 ober return speedtables[i].hz[numspeeds-1]; 1432 1.1 ober } 1433 1.1 ober for (j = 1; j < numspeeds; j++) { 1434 1.1 ober if (speed < speedtables[i].rate[j]) { 1435 1.1 ober return speedtables[i].hz[j-1]; 1436 1.1 ober } 1437 1.1 ober } 1438 1.1 ober } 1439 1.1 ober return newspeed; 1440 1.1 ober } 1441 1.1 ober 1442 1.1 ober 1443 1.1 ober void 1444 1.1 ober pxa2x0_setperf(int speed) 1445 1.1 ober { 1446 1.1 ober struct pxa2x0_apm_softc *sc; 1447 1.1 ober int s; 1448 1.1 ober int newfreq; 1449 1.1 ober 1450 1.1 ober sc = device_private(zapm_cd.cd_devs[0]); 1451 1.1 ober 1452 1.1 ober newfreq = speed_to_freq(speed); 1453 1.1 ober 1454 1.1 ober if (newfreq == 0) { 1455 1.1 ober printf("bogus new frequency 0 for rate %d maxclock %d\n", 1456 1.1 ober speed, xscale_maxspeed); 1457 1.1 ober } 1458 1.1 ober 1459 1.1 ober DPRINTF(("setperf speed %d newfreq %d, maxfreq %d\n", 1460 1.1 ober speed, newfreq, xscale_maxspeed)); 1461 1.1 ober 1462 1.1 ober s = disable_interrupts(I32_bit|F32_bit); 1463 1.1 ober 1464 1.1 ober if (newfreq == 91) { 1465 1.1 ober if (freq > 91) { 1466 1.1 ober pxa27x_run_mode(); 1467 1.1 ober pxa27x_fastbus_run_mode(0, MDREFR_LOW); 1468 1.1 ober pxa27x_cpu_speed_91(); 1469 1.1 ober pxa2x0_pi2c_setvoltage(sc->sc_iot, sc->sc_pm_ioh, 1470 1.1 ober PI2C_VOLTAGE_LOW); 1471 1.1 ober freq = 91; 1472 1.1 ober } 1473 1.1 ober } else if (newfreq == 208) { 1474 1.1 ober if (freq < 208) 1475 1.1 ober pxa2x0_pi2c_setvoltage(sc->sc_iot, sc->sc_pm_ioh, 1476 1.1 ober PI2C_VOLTAGE_HIGH); 1477 1.1 ober if (freq != 208) { 1478 1.1 ober pxa27x_frequency_change(CCCR_A | CCCR_TURBO_X2 | 1479 1.1 ober CCCR_RUN_X16, CLKCFG_F, &pxa2x0_memcfg); 1480 1.1 ober pxa27x_fastbus_run_mode(1, pxa2x0_memcfg.mdrefr_high); 1481 1.1 ober freq = 208; 1482 1.1 ober } 1483 1.1 ober } else if (newfreq == 416) { 1484 1.1 ober if (freq < 208) { 1485 1.1 ober pxa2x0_pi2c_setvoltage(sc->sc_iot, sc->sc_pm_ioh, 1486 1.1 ober PI2C_VOLTAGE_HIGH); 1487 1.1 ober pxa27x_frequency_change(CCCR_A | CCCR_TURBO_X2 | 1488 1.1 ober CCCR_RUN_X16, CLKCFG_F, &pxa2x0_memcfg); 1489 1.1 ober pxa27x_fastbus_run_mode(1, pxa2x0_memcfg.mdrefr_high); 1490 1.1 ober } 1491 1.1 ober if (freq != 416) { 1492 1.1 ober pxa27x_frequency_change(CCCR_A | CCCR_TURBO_X2 | 1493 1.1 ober CCCR_RUN_X16, CLKCFG_B | CLKCFG_F | CLKCFG_T, 1494 1.1 ober &pxa2x0_memcfg); 1495 1.1 ober freq = 416; 1496 1.1 ober } 1497 1.1 ober } else if (newfreq == 520) { 1498 1.1 ober if (freq < 208) { 1499 1.1 ober pxa2x0_pi2c_setvoltage(sc->sc_iot, sc->sc_pm_ioh, 1500 1.1 ober PI2C_VOLTAGE_HIGH); 1501 1.1 ober pxa27x_frequency_change(CCCR_A | CCCR_TURBO_X2 | 1502 1.1 ober CCCR_RUN_X16, CLKCFG_F, &pxa2x0_memcfg); 1503 1.1 ober pxa27x_fastbus_run_mode(1, pxa2x0_memcfg.mdrefr_high); 1504 1.1 ober } 1505 1.1 ober if (freq != 520) { 1506 1.1 ober pxa27x_frequency_change(CCCR_A | CCCR_TURBO_X25 | 1507 1.1 ober CCCR_RUN_X16, CLKCFG_B | CLKCFG_F | CLKCFG_T, 1508 1.1 ober &pxa2x0_memcfg); 1509 1.1 ober freq = 520; 1510 1.1 ober } 1511 1.1 ober } else if (newfreq == 624) { 1512 1.1 ober if (freq < 208) { 1513 1.1 ober pxa2x0_pi2c_setvoltage(sc->sc_iot, sc->sc_pm_ioh, 1514 1.1 ober PI2C_VOLTAGE_HIGH); 1515 1.1 ober pxa27x_frequency_change(CCCR_A | CCCR_TURBO_X2 | 1516 1.1 ober CCCR_RUN_X16, CLKCFG_F, &pxa2x0_memcfg); 1517 1.1 ober pxa27x_fastbus_run_mode(1, pxa2x0_memcfg.mdrefr_high); 1518 1.1 ober } 1519 1.1 ober if (freq != 624) { 1520 1.1 ober pxa27x_frequency_change(CCCR_A | CCCR_TURBO_X3 | 1521 1.1 ober CCCR_RUN_X16, CLKCFG_B | CLKCFG_F | CLKCFG_T, 1522 1.1 ober &pxa2x0_memcfg); 1523 1.1 ober freq = 624; 1524 1.1 ober } 1525 1.1 ober } 1526 1.1 ober 1527 1.1 ober restore_interrupts(s); 1528 1.1 ober } 1529 1.1 ober 1530 1.1 ober int 1531 1.1 ober pxa2x0_cpuspeed(int *freqp) 1532 1.1 ober { 1533 1.1 ober *freqp = freq; 1534 1.1 ober return 0; 1535 1.1 ober } 1536 1.1 ober 1537 1.1 ober void pxa2x0_maxspeed(int *speedp); 1538 1.1 ober 1539 1.1 ober void 1540 1.1 ober pxa2x0_maxspeed(int *speedp) 1541 1.1 ober { 1542 1.1 ober /* XXX assumes a pxa270 */ 1543 1.1 ober 1544 1.1 ober if (*speedp < 207) { 1545 1.1 ober *speedp = 91; 1546 1.1 ober } else if (*speedp < 415) { 1547 1.1 ober *speedp = 208; 1548 1.1 ober } else if (*speedp < 519) { 1549 1.1 ober *speedp = 416; 1550 1.1 ober } else if (*speedp < 624) { 1551 1.1 ober *speedp = 520; 1552 1.1 ober #if 0 1553 1.1 ober } else if (*speedp < 651) { 1554 1.1 ober *speedp = 624; 1555 1.1 ober #endif 1556 1.1 ober } else { 1557 1.1 ober *speedp = 520; /* hope this is safe. */ 1558 1.1 ober } 1559 1.1 ober xscale_maxspeed = *speedp; 1560 1.1 ober #if 0 1561 1.1 ober pxa2x0_setperf(perflevel); 1562 1.1 ober #endif 1563 1.1 ober } 1564