Fri Oct 30 22:20:38 2020 UTC ()
c99 struct initializers


(christos)
diff -r1.4 -r1.5 src/sys/arch/arm/xscale/pxa2x0_apm.c
diff -r1.27 -r1.28 src/sys/arch/macppc/dev/apm.c
diff -r1.8 -r1.9 src/sys/arch/mips/ralink/ralink_gpio.c

cvs diff -r1.4 -r1.5 src/sys/arch/arm/xscale/pxa2x0_apm.c (switch to unified diff)

--- src/sys/arch/arm/xscale/pxa2x0_apm.c 2012/11/12 18:00:38 1.4
+++ src/sys/arch/arm/xscale/pxa2x0_apm.c 2020/10/30 22:20:38 1.5
@@ -1,1107 +1,1111 @@ @@ -1,1107 +1,1111 @@
1/* $NetBSD: pxa2x0_apm.c,v 1.4 2012/11/12 18:00:38 skrll Exp $ */ 1/* $NetBSD: pxa2x0_apm.c,v 1.5 2020/10/30 22:20:38 christos Exp $ */
2/* $OpenBSD: pxa2x0_apm.c,v 1.28 2007/03/29 18:42:38 uwe Exp $ */ 2/* $OpenBSD: pxa2x0_apm.c,v 1.28 2007/03/29 18:42:38 uwe Exp $ */
3 3
4/*- 4/*-
5 * Copyright (c) 2001 Alexander Guy. All rights reserved. 5 * Copyright (c) 2001 Alexander Guy. All rights reserved.
6 * Copyright (c) 1998-2001 Michael Shalayeff. All rights reserved. 6 * Copyright (c) 1998-2001 Michael Shalayeff. All rights reserved.
7 * Copyright (c) 1995 John T. Kohl. All rights reserved. 7 * Copyright (c) 1995 John T. Kohl. All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software 17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement: 18 * must display the following acknowledgement:
19 * This product includes software developed by the University of 19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors. 20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors 21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software 22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission. 23 * without specific prior written permission.
24 * 24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * OR SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE. 35 * SUCH DAMAGE.
36 * 36 *
37 */ 37 */
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/systm.h> 40#include <sys/systm.h>
41#include <sys/kernel.h> 41#include <sys/kernel.h>
42#include <sys/kthread.h> 42#include <sys/kthread.h>
43#include <sys/lock.h> 43#include <sys/lock.h>
44#include <sys/mount.h> /* for vfs_syncwait() */ 44#include <sys/mount.h> /* for vfs_syncwait() */
45#include <sys/proc.h> 45#include <sys/proc.h>
46#include <sys/device.h> 46#include <sys/device.h>
47#include <sys/fcntl.h> 47#include <sys/fcntl.h>
48#include <sys/ioctl.h> 48#include <sys/ioctl.h>
49#include <sys/event.h> 49#include <sys/event.h>
50 50
51#include <machine/cpu.h> 51#include <machine/cpu.h>
52#include <machine/apmvar.h> 52#include <machine/apmvar.h>
53 53
54#include <arm/xscale/pxa2x0reg.h> 54#include <arm/xscale/pxa2x0reg.h>
55#include <arm/xscale/pxa2x0var.h> 55#include <arm/xscale/pxa2x0var.h>
56#include <arm/xscale/pxa2x0_apm.h> 56#include <arm/xscale/pxa2x0_apm.h>
57#include <arm/xscale/pxa2x0_gpio.h> 57#include <arm/xscale/pxa2x0_gpio.h>
58 58
59#if defined(APMDEBUG) 59#if defined(APMDEBUG)
60#define DPRINTF(x) printf x 60#define DPRINTF(x) printf x
61#else 61#else
62#define DPRINTF(x) /**/ 62#define DPRINTF(x) /**/
63#endif 63#endif
64 64
65#define APM_LOCK(sc) lockmgr(&(sc)->sc_lock, LK_EXCLUSIVE, NULL) 65#define APM_LOCK(sc) lockmgr(&(sc)->sc_lock, LK_EXCLUSIVE, NULL)
66#define APM_UNLOCK(sc) lockmgr(&(sc)->sc_lock, LK_RELEASE, NULL) 66#define APM_UNLOCK(sc) lockmgr(&(sc)->sc_lock, LK_RELEASE, NULL)
67 67
68#define APMUNIT(dev) (minor(dev)&0xf0) 68#define APMUNIT(dev) (minor(dev)&0xf0)
69#define APMDEV(dev) (minor(dev)&0x0f) 69#define APMDEV(dev) (minor(dev)&0x0f)
70#define APMDEV_NORMAL 0 70#define APMDEV_NORMAL 0
71#define APMDEV_CTL 8 71#define APMDEV_CTL 8
72 72
73int apm_userstandbys; 73int apm_userstandbys;
74int apm_suspends; 74int apm_suspends;
75int apm_battlow; 75int apm_battlow;
76 76
77extern struct cfdriver zapm_cd; 77extern struct cfdriver zapm_cd;
78 78
79/* battery percentage at which we get verbose in our warnings. This 79/* battery percentage at which we get verbose in our warnings. This
80 value can be changed using sysctl(8), value machdep.apmwarn. 80 value can be changed using sysctl(8), value machdep.apmwarn.
81 Setting it to zero kills all warnings */ 81 Setting it to zero kills all warnings */
82int cpu_apmwarn = 10; 82int cpu_apmwarn = 10;
83 83
84void apm_power_print(struct pxa2x0_apm_softc *, struct apm_power_info *); 84void apm_power_print(struct pxa2x0_apm_softc *, struct apm_power_info *);
85void apm_power_info(struct pxa2x0_apm_softc *, struct apm_power_info *); 85void apm_power_info(struct pxa2x0_apm_softc *, struct apm_power_info *);
86void apm_suspend(struct pxa2x0_apm_softc *); 86void apm_suspend(struct pxa2x0_apm_softc *);
87void apm_resume(struct pxa2x0_apm_softc *); 87void apm_resume(struct pxa2x0_apm_softc *);
88int apm_get_event(struct pxa2x0_apm_softc *, u_int *); 88int apm_get_event(struct pxa2x0_apm_softc *, u_int *);
89int apm_handle_event(struct pxa2x0_apm_softc *, u_int); 89int apm_handle_event(struct pxa2x0_apm_softc *, u_int);
90void apm_thread_create(void *); 90void apm_thread_create(void *);
91void apm_thread(void *); 91void apm_thread(void *);
92 92
93#if 0 93#if 0
94extern int perflevel; 94extern int perflevel;
95#endif 95#endif
96 96
97int freq; 97int freq;
98void pxa2x0_setperf(int speed); 98void pxa2x0_setperf(int speed);
99int pxa2x0_cpuspeed(int *speed); 99int pxa2x0_cpuspeed(int *speed);
100 100
101int apm_record_event(struct pxa2x0_apm_softc *, u_int); 101int apm_record_event(struct pxa2x0_apm_softc *, u_int);
102#if 0 102#if 0
103void filt_apmrdetach(struct knote *kn); 103void filt_apmrdetach(struct knote *kn);
104int filt_apmread(struct knote *kn, long hint); 104int filt_apmread(struct knote *kn, long hint);
105int apmkqfilter(dev_t dev, struct knote *kn); 105int apmkqfilter(dev_t dev, struct knote *kn);
106 106
107struct filterops apmread_filtops = 107static const struct filterops apmread_filtops = {
108 { 1, NULL, filt_apmrdetach, filt_apmread}; 108 .f_isfd = 1,
 109 .f_attach = NULL,
 110 .f_detach = filt_apmrdetach,
 111 .f_event = filt_apmread,
 112};
109#endif 113#endif
110 114
111/* 115/*
112 * Flags to control kernel display 116 * Flags to control kernel display
113 * SCFLAG_NOPRINT: do not output APM power messages due to 117 * SCFLAG_NOPRINT: do not output APM power messages due to
114 * a power change event. 118 * a power change event.
115 * 119 *
116 * SCFLAG_PCTPRINT: do not output APM power messages due to 120 * SCFLAG_PCTPRINT: do not output APM power messages due to
117 * to a power change event unless the battery 121 * to a power change event unless the battery
118 * percentage changes. 122 * percentage changes.
119 */ 123 */
120 124
121#define SCFLAG_NOPRINT 0x0008000 125#define SCFLAG_NOPRINT 0x0008000
122#define SCFLAG_PCTPRINT 0x0004000 126#define SCFLAG_PCTPRINT 0x0004000
123#define SCFLAG_PRINT (SCFLAG_NOPRINT|SCFLAG_PCTPRINT) 127#define SCFLAG_PRINT (SCFLAG_NOPRINT|SCFLAG_PCTPRINT)
124 128
125#define SCFLAG_OREAD (1 << 0) 129#define SCFLAG_OREAD (1 << 0)
126#define SCFLAG_OWRITE (1 << 1) 130#define SCFLAG_OWRITE (1 << 1)
127#define SCFLAG_OPEN (SCFLAG_OREAD|SCFLAG_OWRITE) 131#define SCFLAG_OPEN (SCFLAG_OREAD|SCFLAG_OWRITE)
128 132
129/* This structure must be kept in sync with pxa2x0_apm_asm.S. */ 133/* This structure must be kept in sync with pxa2x0_apm_asm.S. */
130struct pxa2x0_memcfg { 134struct pxa2x0_memcfg {
131 /* SDRAM refresh */ 135 /* SDRAM refresh */
132 uint32_t mdrefr_high; /* 0x00 */ 136 uint32_t mdrefr_high; /* 0x00 */
133 uint32_t mdrefr_low; /* 0x04 */ 137 uint32_t mdrefr_low; /* 0x04 */
134 uint32_t mdrefr_low2; /* 0x08 */ 138 uint32_t mdrefr_low2; /* 0x08 */
135 /* Synchronous, static, or VLIO interfaces */ 139 /* Synchronous, static, or VLIO interfaces */
136 uint32_t msc_high[3]; /* 0x0c */ 140 uint32_t msc_high[3]; /* 0x0c */
137 uint32_t msc_low[3]; /* 0x18 */ 141 uint32_t msc_low[3]; /* 0x18 */
138 /* XXX move up */ 142 /* XXX move up */
139 uint32_t mdrefr_91; /* 0x24 */ 143 uint32_t mdrefr_91; /* 0x24 */
140}; 144};
141 145
142/* XXX */ 146/* XXX */
143#define MDREFR_C3000 (MDREFR_K0DB2 | MDREFR_E1PIN | MDREFR_K1RUN | \ 147#define MDREFR_C3000 (MDREFR_K0DB2 | MDREFR_E1PIN | MDREFR_K1RUN | \
144 MDREFR_K1DB2 | MDREFR_K2DB2 | MDREFR_APD) 148 MDREFR_K1DB2 | MDREFR_K2DB2 | MDREFR_APD)
145#define MSC0_HIGH \ 149#define MSC0_HIGH \
146 ( 7 << MSC_RRR_SHIFT << 16) | \ 150 ( 7 << MSC_RRR_SHIFT << 16) | \
147 (15 << MSC_RDN_SHIFT << 16) | \ 151 (15 << MSC_RDN_SHIFT << 16) | \
148 (15 << MSC_RDF_SHIFT << 16) | \ 152 (15 << MSC_RDF_SHIFT << 16) | \
149 (MSC_RT_NONBURST << 16) | \ 153 (MSC_RT_NONBURST << 16) | \
150 ( 2 << MSC_RRR_SHIFT) | \ 154 ( 2 << MSC_RRR_SHIFT) | \
151 (13 << MSC_RDN_SHIFT) | \ 155 (13 << MSC_RDN_SHIFT) | \
152 (13 << MSC_RDF_SHIFT) | \ 156 (13 << MSC_RDF_SHIFT) | \
153 MSC_RBW /* PXA271 */ | \ 157 MSC_RBW /* PXA271 */ | \
154 MSC_RT_NONBURST 158 MSC_RT_NONBURST
155#define MSC1_HIGH \ 159#define MSC1_HIGH \
156 ( 7 << MSC_RRR_SHIFT << 16) | \ 160 ( 7 << MSC_RRR_SHIFT << 16) | \
157 (15 << MSC_RDN_SHIFT << 16) | \ 161 (15 << MSC_RDN_SHIFT << 16) | \
158 (15 << MSC_RDF_SHIFT << 16) | \ 162 (15 << MSC_RDF_SHIFT << 16) | \
159 (MSC_RT_VLIO << 16) | \ 163 (MSC_RT_VLIO << 16) | \
160 ( 3 << MSC_RRR_SHIFT) | \ 164 ( 3 << MSC_RRR_SHIFT) | \
161 ( 4 << MSC_RDN_SHIFT) | \ 165 ( 4 << MSC_RDN_SHIFT) | \
162 (13 << MSC_RDF_SHIFT) | \ 166 (13 << MSC_RDF_SHIFT) | \
163 MSC_RT_VLIO 167 MSC_RT_VLIO
164#define MSC2_HIGH \ 168#define MSC2_HIGH \
165 ( 7 << MSC_RRR_SHIFT << 16) | \ 169 ( 7 << MSC_RRR_SHIFT << 16) | \
166 (15 << MSC_RDN_SHIFT << 16) | \ 170 (15 << MSC_RDN_SHIFT << 16) | \
167 (15 << MSC_RDF_SHIFT << 16) | \ 171 (15 << MSC_RDF_SHIFT << 16) | \
168 (MSC_RT_NONBURST << 16) | \ 172 (MSC_RT_NONBURST << 16) | \
169 ( 3 << MSC_RRR_SHIFT) | \ 173 ( 3 << MSC_RRR_SHIFT) | \
170 ( 4 << MSC_RDN_SHIFT) | \ 174 ( 4 << MSC_RDN_SHIFT) | \
171 (13 << MSC_RDF_SHIFT) | \ 175 (13 << MSC_RDF_SHIFT) | \
172 MSC_RT_VLIO 176 MSC_RT_VLIO
173#define MSC0_LOW \ 177#define MSC0_LOW \
174 ( 7 << MSC_RRR_SHIFT << 16) | \ 178 ( 7 << MSC_RRR_SHIFT << 16) | \
175 (15 << MSC_RDN_SHIFT << 16) | \ 179 (15 << MSC_RDN_SHIFT << 16) | \
176 (15 << MSC_RDF_SHIFT << 16) | \ 180 (15 << MSC_RDF_SHIFT << 16) | \
177 (MSC_RT_NONBURST << 16) | \ 181 (MSC_RT_NONBURST << 16) | \
178 ( 1 << MSC_RRR_SHIFT) | \ 182 ( 1 << MSC_RRR_SHIFT) | \
179 ( 8 << MSC_RDN_SHIFT) | \ 183 ( 8 << MSC_RDN_SHIFT) | \
180 ( 8 << MSC_RDF_SHIFT) | \ 184 ( 8 << MSC_RDF_SHIFT) | \
181 MSC_RBW /* PXA271 */ | \ 185 MSC_RBW /* PXA271 */ | \
182 MSC_RT_NONBURST 186 MSC_RT_NONBURST
183#define MSC1_LOW \ 187#define MSC1_LOW \
184 ( 7 << MSC_RRR_SHIFT << 16) | \ 188 ( 7 << MSC_RRR_SHIFT << 16) | \
185 (15 << MSC_RDN_SHIFT << 16) | \ 189 (15 << MSC_RDN_SHIFT << 16) | \
186 (15 << MSC_RDF_SHIFT << 16) | \ 190 (15 << MSC_RDF_SHIFT << 16) | \
187 (MSC_RT_VLIO << 16) | \ 191 (MSC_RT_VLIO << 16) | \
188 ( 1 << MSC_RRR_SHIFT) | \ 192 ( 1 << MSC_RRR_SHIFT) | \
189 ( 2 << MSC_RDN_SHIFT) | \ 193 ( 2 << MSC_RDN_SHIFT) | \
190 ( 6 << MSC_RDF_SHIFT) | \ 194 ( 6 << MSC_RDF_SHIFT) | \
191 MSC_RT_VLIO 195 MSC_RT_VLIO
192#define MSC2_LOW \ 196#define MSC2_LOW \
193 ( 7 << MSC_RRR_SHIFT << 16) | \ 197 ( 7 << MSC_RRR_SHIFT << 16) | \
194 (15 << MSC_RDN_SHIFT << 16) | \ 198 (15 << MSC_RDN_SHIFT << 16) | \
195 (15 << MSC_RDF_SHIFT << 16) | \ 199 (15 << MSC_RDF_SHIFT << 16) | \
196 (MSC_RT_NONBURST << 16) | \ 200 (MSC_RT_NONBURST << 16) | \
197 ( 1 << MSC_RRR_SHIFT) | \ 201 ( 1 << MSC_RRR_SHIFT) | \
198 ( 2 << MSC_RDN_SHIFT) | \ 202 ( 2 << MSC_RDN_SHIFT) | \
199 ( 6 << MSC_RDF_SHIFT) | \ 203 ( 6 << MSC_RDF_SHIFT) | \
200 MSC_RT_VLIO 204 MSC_RT_VLIO
201struct pxa2x0_memcfg pxa2x0_memcfg = { 205struct pxa2x0_memcfg pxa2x0_memcfg = {
202 (MDREFR_C3000 | 0x030), 206 (MDREFR_C3000 | 0x030),
203 (MDREFR_C3000 | 0x00b), 207 (MDREFR_C3000 | 0x00b),
204 (MDREFR_C3000 | 0x017), 208 (MDREFR_C3000 | 0x017),
205 { MSC0_HIGH, MSC1_HIGH, MSC2_HIGH }, 209 { MSC0_HIGH, MSC1_HIGH, MSC2_HIGH },
206 { MSC1_LOW, MSC1_LOW, MSC2_LOW }, 210 { MSC1_LOW, MSC1_LOW, MSC2_LOW },
207 (MDREFR_C3000 | 0x013) 211 (MDREFR_C3000 | 0x013)
208}; 212};
209 213
210#define PI2C_RETRY_COUNT 10 214#define PI2C_RETRY_COUNT 10
211/* XXX varies depending on voltage regulator IC. */ 215/* XXX varies depending on voltage regulator IC. */
212#define PI2C_VOLTAGE_LOW 0x13 /* 1.00V */ 216#define PI2C_VOLTAGE_LOW 0x13 /* 1.00V */
213#define PI2C_VOLTAGE_HIGH 0x1a /* 1.35V */ 217#define PI2C_VOLTAGE_HIGH 0x1a /* 1.35V */
214 218
215void pxa2x0_pi2c_open(bus_space_tag_t, bus_space_handle_t); 219void pxa2x0_pi2c_open(bus_space_tag_t, bus_space_handle_t);
216void pxa2x0_pi2c_close(bus_space_tag_t, bus_space_handle_t); 220void pxa2x0_pi2c_close(bus_space_tag_t, bus_space_handle_t);
217int pxa2x0_pi2c_read(bus_space_tag_t, bus_space_handle_t, u_char, u_char *); 221int pxa2x0_pi2c_read(bus_space_tag_t, bus_space_handle_t, u_char, u_char *);
218int pxa2x0_pi2c_write(bus_space_tag_t, bus_space_handle_t, u_char, u_char); 222int pxa2x0_pi2c_write(bus_space_tag_t, bus_space_handle_t, u_char, u_char);
219int pxa2x0_pi2c_getvoltage(bus_space_tag_t, bus_space_handle_t, u_char *); 223int pxa2x0_pi2c_getvoltage(bus_space_tag_t, bus_space_handle_t, u_char *);
220int pxa2x0_pi2c_setvoltage(bus_space_tag_t, bus_space_handle_t, u_char); 224int pxa2x0_pi2c_setvoltage(bus_space_tag_t, bus_space_handle_t, u_char);
221#if 0 225#if 0
222void pxa2x0_pi2c_print(struct pxa2x0_apm_softc *); 226void pxa2x0_pi2c_print(struct pxa2x0_apm_softc *);
223#endif 227#endif
224 228
225/* XXX used in pxa2x0_apm_asm.S */ 229/* XXX used in pxa2x0_apm_asm.S */
226bus_space_handle_t pxa2x0_gpio_ioh; 230bus_space_handle_t pxa2x0_gpio_ioh;
227bus_space_handle_t pxa2x0_clkman_ioh; 231bus_space_handle_t pxa2x0_clkman_ioh;
228bus_space_handle_t pxa2x0_memctl_ioh; 232bus_space_handle_t pxa2x0_memctl_ioh;
229 233
230/* pxa2x0_apm_asm.S */ 234/* pxa2x0_apm_asm.S */
231void pxa27x_run_mode(void); 235void pxa27x_run_mode(void);
232void pxa27x_fastbus_run_mode(int, uint32_t); 236void pxa27x_fastbus_run_mode(int, uint32_t);
233void pxa27x_frequency_change(int, int, struct pxa2x0_memcfg *); 237void pxa27x_frequency_change(int, int, struct pxa2x0_memcfg *);
234void pxa2x0_cpu_suspend(void); 238void pxa2x0_cpu_suspend(void);
235void pxa2x0_cpu_resume(void); 239void pxa2x0_cpu_resume(void);
236void pxa27x_cpu_speed_high(void); 240void pxa27x_cpu_speed_high(void);
237void pxa27x_cpu_speed_low(void); 241void pxa27x_cpu_speed_low(void);
238void pxa27x_cpu_speed_91(void); 242void pxa27x_cpu_speed_91(void);
239void pxa27x_cpu_speed_208(void); 243void pxa27x_cpu_speed_208(void);
240 244
241void 245void
242apm_power_print(struct pxa2x0_apm_softc *sc, struct apm_power_info *powerp) 246apm_power_print(struct pxa2x0_apm_softc *sc, struct apm_power_info *powerp)
243{ 247{
244 248
245 if (powerp->battery_life != APM_BATT_LIFE_UNKNOWN) 249 if (powerp->battery_life != APM_BATT_LIFE_UNKNOWN)
246 printf("%s: battery life expectancy %d%%\n", 250 printf("%s: battery life expectancy %d%%\n",
247 device_xname(sc->sc_dev), powerp->battery_life); 251 device_xname(sc->sc_dev), powerp->battery_life);
248 252
249 printf("%s: AC ", device_xname(sc->sc_dev)); 253 printf("%s: AC ", device_xname(sc->sc_dev));
250 switch (powerp->ac_state) { 254 switch (powerp->ac_state) {
251 case APM_AC_OFF: 255 case APM_AC_OFF:
252 printf("off,"); 256 printf("off,");
253 break; 257 break;
254 case APM_AC_ON: 258 case APM_AC_ON:
255 printf("on,"); 259 printf("on,");
256 break; 260 break;
257 case APM_AC_BACKUP: 261 case APM_AC_BACKUP:
258 printf("backup power,"); 262 printf("backup power,");
259 break; 263 break;
260 default: 264 default:
261 case APM_AC_UNKNOWN: 265 case APM_AC_UNKNOWN:
262 printf("unknown,"); 266 printf("unknown,");
263 break; 267 break;
264 } 268 }
265 269
266 printf(" battery is "); 270 printf(" battery is ");
267 switch (powerp->battery_state) { 271 switch (powerp->battery_state) {
268 case APM_BATT_HIGH: 272 case APM_BATT_HIGH:
269 printf("high"); 273 printf("high");
270 break; 274 break;
271 case APM_BATT_LOW: 275 case APM_BATT_LOW:
272 printf("low"); 276 printf("low");
273 break; 277 break;
274 case APM_BATT_CRITICAL: 278 case APM_BATT_CRITICAL:
275 printf("CRITICAL"); 279 printf("CRITICAL");
276 break; 280 break;
277 case APM_BATT_CHARGING: 281 case APM_BATT_CHARGING:
278 printf("charging"); 282 printf("charging");
279 break; 283 break;
280 case APM_BATT_UNKNOWN: 284 case APM_BATT_UNKNOWN:
281 printf("unknown"); 285 printf("unknown");
282 break; 286 break;
283 default: 287 default:
284 printf("undecoded (%x)", powerp->battery_state); 288 printf("undecoded (%x)", powerp->battery_state);
285 break; 289 break;
286 } 290 }
287 291
288 printf("\n"); 292 printf("\n");
289} 293}
290 294
291void 295void
292apm_power_info(struct pxa2x0_apm_softc *sc, 296apm_power_info(struct pxa2x0_apm_softc *sc,
293 struct apm_power_info *power) 297 struct apm_power_info *power)
294{ 298{
295 299
296 power->ac_state = APM_AC_UNKNOWN; 300 power->ac_state = APM_AC_UNKNOWN;
297 power->battery_state = APM_BATT_UNKNOWN; 301 power->battery_state = APM_BATT_UNKNOWN;
298 power->battery_life = 0 /* APM_BATT_LIFE_UNKNOWN */; 302 power->battery_life = 0 /* APM_BATT_LIFE_UNKNOWN */;
299 power->minutes_left = 0; 303 power->minutes_left = 0;
300 304
301 if (sc->sc_power_info != NULL) 305 if (sc->sc_power_info != NULL)
302 sc->sc_power_info(sc, power); 306 sc->sc_power_info(sc, power);
303} 307}
304 308
305void 309void
306apm_suspend(struct pxa2x0_apm_softc *sc) 310apm_suspend(struct pxa2x0_apm_softc *sc)
307{ 311{
308 312
309 resettodr(); 313 resettodr();
310 314
311 dopowerhooks(PWR_SUSPEND); 315 dopowerhooks(PWR_SUSPEND);
312 316
313#if 0 317#if 0
314 if (cold) 318 if (cold)
315 vfs_syncwait(0); 319 vfs_syncwait(0);
316#endif 320#endif
317 321
318 if (sc->sc_suspend == NULL) 322 if (sc->sc_suspend == NULL)
319 pxa2x0_wakeup_config(PXA2X0_WAKEUP_ALL, 1); 323 pxa2x0_wakeup_config(PXA2X0_WAKEUP_ALL, 1);
320 else 324 else
321 sc->sc_suspend(sc); 325 sc->sc_suspend(sc);
322 326
323 pxa2x0_apm_sleep(sc); 327 pxa2x0_apm_sleep(sc);
324} 328}
325 329
326void 330void
327apm_resume(struct pxa2x0_apm_softc *sc) 331apm_resume(struct pxa2x0_apm_softc *sc)
328{ 332{
329 333
330 dopowerhooks(PWR_RESUME); 334 dopowerhooks(PWR_RESUME);
331 335
332 inittodr(0); 336 inittodr(0);
333 337
334 /* 338 /*
335 * Clear the OTG Peripheral hold after running the pxaudc and pxaohci 339 * Clear the OTG Peripheral hold after running the pxaudc and pxaohci
336 * powerhooks to re-enable their operation. See 3.8.1.2 340 * powerhooks to re-enable their operation. See 3.8.1.2
337 */ 341 */
338 /* XXX ifdef NPXAUDC > 0 */ 342 /* XXX ifdef NPXAUDC > 0 */
339 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSSR, PSSR_OTGPH); 343 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSSR, PSSR_OTGPH);
340} 344}
341 345
342#if 0 346#if 0
343int 347int
344apm_get_event(struct pxa2x0_apm_softc *sc, u_int *typep) 348apm_get_event(struct pxa2x0_apm_softc *sc, u_int *typep)
345{ 349{
346 350
347 if (sc->sc_get_event != NULL) 351 if (sc->sc_get_event != NULL)
348 return (sc->sc_get_event(sc, typep)); 352 return (sc->sc_get_event(sc, typep));
349 353
350 *typep = APM_NOEVENT; 354 *typep = APM_NOEVENT;
351 return (1); 355 return (1);
352} 356}
353 357
354int 358int
355apm_handle_event(struct pxa2x0_apm_softc *sc, u_int type) 359apm_handle_event(struct pxa2x0_apm_softc *sc, u_int type)
356{ 360{
357 struct apm_power_info power; 361 struct apm_power_info power;
358 int ret = 0; 362 int ret = 0;
359 363
360 switch (type) { 364 switch (type) {
361 case APM_NOEVENT: 365 case APM_NOEVENT:
362 ret = 1; 366 ret = 1;
363 break; 367 break;
364 case APM_CRIT_SUSPEND_REQ: 368 case APM_CRIT_SUSPEND_REQ:
365 DPRINTF(("suspend required immediately\n")); 369 DPRINTF(("suspend required immediately\n"));
366#if 0 370#if 0
367 /* XXX apmd would make us suspend again after resume. */ 371 /* XXX apmd would make us suspend again after resume. */
368 (void)apm_record_event(sc, type); 372 (void)apm_record_event(sc, type);
369#endif 373#endif
370 /* 374 /*
371 * We ignore APM_CRIT_RESUME and just suspend here as usual 375 * We ignore APM_CRIT_RESUME and just suspend here as usual
372 * to simplify the actual apm_get_event() implementation. 376 * to simplify the actual apm_get_event() implementation.
373 */ 377 */
374 apm_suspends++; 378 apm_suspends++;
375 ret = 1; 379 ret = 1;
376 break; 380 break;
377 case APM_USER_SUSPEND_REQ: 381 case APM_USER_SUSPEND_REQ:
378 case APM_SUSPEND_REQ: 382 case APM_SUSPEND_REQ:
379 DPRINTF(("suspend requested\n")); 383 DPRINTF(("suspend requested\n"));
380 if (apm_record_event(sc, type)) { 384 if (apm_record_event(sc, type)) {
381 DPRINTF(("suspend ourselves\n")); 385 DPRINTF(("suspend ourselves\n"));
382 apm_suspends++; 386 apm_suspends++;
383 } 387 }
384 break; 388 break;
385 case APM_POWER_CHANGE: 389 case APM_POWER_CHANGE:
386 DPRINTF(("power status change\n")); 390 DPRINTF(("power status change\n"));
387 apm_power_info(sc, &power); 391 apm_power_info(sc, &power);
388 if (power.battery_life != APM_BATT_LIFE_UNKNOWN && 392 if (power.battery_life != APM_BATT_LIFE_UNKNOWN &&
389 power.battery_life < cpu_apmwarn && 393 power.battery_life < cpu_apmwarn &&
390 (sc->sc_flags & SCFLAG_PRINT) != SCFLAG_NOPRINT && 394 (sc->sc_flags & SCFLAG_PRINT) != SCFLAG_NOPRINT &&
391 ((sc->sc_flags & SCFLAG_PRINT) != SCFLAG_PCTPRINT || 395 ((sc->sc_flags & SCFLAG_PRINT) != SCFLAG_PCTPRINT ||
392 sc->sc_batt_life != power.battery_life)) { 396 sc->sc_batt_life != power.battery_life)) {
393 sc->sc_batt_life = power.battery_life; 397 sc->sc_batt_life = power.battery_life;
394 apm_power_print(sc, &power); 398 apm_power_print(sc, &power);
395 } 399 }
396 apm_record_event(sc, type); 400 apm_record_event(sc, type);
397 break; 401 break;
398 case APM_BATTERY_LOW: 402 case APM_BATTERY_LOW:
399 DPRINTF(("Battery low!\n")); 403 DPRINTF(("Battery low!\n"));
400 apm_battlow++; 404 apm_battlow++;
401 apm_record_event(sc, type); 405 apm_record_event(sc, type);
402 break; 406 break;
403 default: 407 default:
404 DPRINTF(("apm_handle_event: unsupported event, code %d\n", 408 DPRINTF(("apm_handle_event: unsupported event, code %d\n",
405 type)); 409 type));
406 } 410 }
407 411
408 return (ret); 412 return (ret);
409} 413}
410 414
411void 415void
412apm_thread_create(void *v) 416apm_thread_create(void *v)
413{ 417{
414 struct pxa2x0_apm_softc *sc = v; 418 struct pxa2x0_apm_softc *sc = v;
415 419
416 if (kthread_create(apm_thread, sc, &sc->sc_thread, 420 if (kthread_create(apm_thread, sc, &sc->sc_thread,
417 "%s", device_xname(sc->sc_dev))) { 421 "%s", device_xname(sc->sc_dev))) {
418 /* apm_disconnect(sc); */ 422 /* apm_disconnect(sc); */
419 printf("%s: failed to create kernel thread, disabled", 423 printf("%s: failed to create kernel thread, disabled",
420 device_xname(sc->sc_dev)); 424 device_xname(sc->sc_dev));
421 } 425 }
422} 426}
423 427
424void 428void
425apm_thread(void *v) 429apm_thread(void *v)
426{ 430{
427 struct pxa2x0_apm_softc *sc = v; 431 struct pxa2x0_apm_softc *sc = v;
428 u_int type; 432 u_int type;
429 433
430 for (;;) { 434 for (;;) {
431 APM_LOCK(sc); 435 APM_LOCK(sc);
432 436
433 while (1) { 437 while (1) {
434 if (apm_get_event(sc, &type) != 0) 438 if (apm_get_event(sc, &type) != 0)
435 break; 439 break;
436 if (apm_handle_event(sc, type) != 0) 440 if (apm_handle_event(sc, type) != 0)
437 break; 441 break;
438 } 442 }
439 if (apm_suspends || apm_userstandbys /* || apm_battlow*/) { 443 if (apm_suspends || apm_userstandbys /* || apm_battlow*/) {
440 apm_suspend(sc); 444 apm_suspend(sc);
441 apm_resume(sc); 445 apm_resume(sc);
442 } 446 }
443 apm_battlow = apm_suspends = apm_userstandbys = 0; 447 apm_battlow = apm_suspends = apm_userstandbys = 0;
444 448
445 APM_UNLOCK(sc); 449 APM_UNLOCK(sc);
446 kpause("apmev", false, hz, NULL); 450 kpause("apmev", false, hz, NULL);
447 } 451 }
448} 452}
449 453
450int 454int
451apmopen(dev_t dev, int flag, int mode, struct proc *p) 455apmopen(dev_t dev, int flag, int mode, struct proc *p)
452{ 456{
453 struct pxa2x0_apm_softc *sc; 457 struct pxa2x0_apm_softc *sc;
454 int error = 0; 458 int error = 0;
455 459
456 /* apm0 only */ 460 /* apm0 only */
457 if (!zapm_cd.cd_ndevs || APMUNIT(dev) != 0 || 461 if (!zapm_cd.cd_ndevs || APMUNIT(dev) != 0 ||
458 !(sc = zapm_cd.cd_devs[APMUNIT(dev)])) 462 !(sc = zapm_cd.cd_devs[APMUNIT(dev)]))
459 return (ENXIO); 463 return (ENXIO);
460 464
461 DPRINTF(("apmopen: dev %d pid %d flag %x mode %x\n", 465 DPRINTF(("apmopen: dev %d pid %d flag %x mode %x\n",
462 APMDEV(dev), p->p_pid, flag, mode)); 466 APMDEV(dev), p->p_pid, flag, mode));
463 467
464 switch (APMDEV(dev)) { 468 switch (APMDEV(dev)) {
465 case APMDEV_CTL: 469 case APMDEV_CTL:
466 if (!(flag & FWRITE)) { 470 if (!(flag & FWRITE)) {
467 error = EINVAL; 471 error = EINVAL;
468 break; 472 break;
469 } 473 }
470 if (sc->sc_flags & SCFLAG_OWRITE) { 474 if (sc->sc_flags & SCFLAG_OWRITE) {
471 error = EBUSY; 475 error = EBUSY;
472 break; 476 break;
473 } 477 }
474 sc->sc_flags |= SCFLAG_OWRITE; 478 sc->sc_flags |= SCFLAG_OWRITE;
475 break; 479 break;
476 case APMDEV_NORMAL: 480 case APMDEV_NORMAL:
477 if (!(flag & FREAD) || (flag & FWRITE)) { 481 if (!(flag & FREAD) || (flag & FWRITE)) {
478 error = EINVAL; 482 error = EINVAL;
479 break; 483 break;
480 } 484 }
481 sc->sc_flags |= SCFLAG_OREAD; 485 sc->sc_flags |= SCFLAG_OREAD;
482 break; 486 break;
483 default: 487 default:
484 error = ENXIO; 488 error = ENXIO;
485 break; 489 break;
486 } 490 }
487 return (error); 491 return (error);
488} 492}
489 493
490int 494int
491apmclose(dev_t dev, int flag, int mode, struct proc *p) 495apmclose(dev_t dev, int flag, int mode, struct proc *p)
492{ 496{
493 struct pxa2x0_apm_softc *sc; 497 struct pxa2x0_apm_softc *sc;
494 498
495 /* apm0 only */ 499 /* apm0 only */
496 if (!apm_cd.cd_ndevs || APMUNIT(dev) != 0 || 500 if (!apm_cd.cd_ndevs || APMUNIT(dev) != 0 ||
497 !(sc = apm_cd.cd_devs[APMUNIT(dev)])) 501 !(sc = apm_cd.cd_devs[APMUNIT(dev)]))
498 return (ENXIO); 502 return (ENXIO);
499 503
500 DPRINTF(("apmclose: pid %d flag %x mode %x\n", p->p_pid, flag, mode)); 504 DPRINTF(("apmclose: pid %d flag %x mode %x\n", p->p_pid, flag, mode));
501 505
502 switch (APMDEV(dev)) { 506 switch (APMDEV(dev)) {
503 case APMDEV_CTL: 507 case APMDEV_CTL:
504 sc->sc_flags &= ~SCFLAG_OWRITE; 508 sc->sc_flags &= ~SCFLAG_OWRITE;
505 break; 509 break;
506 case APMDEV_NORMAL: 510 case APMDEV_NORMAL:
507 sc->sc_flags &= ~SCFLAG_OREAD; 511 sc->sc_flags &= ~SCFLAG_OREAD;
508 break; 512 break;
509 } 513 }
510 return (0); 514 return (0);
511} 515}
512 516
513int 517int
514apmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) 518apmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
515{ 519{
516 struct pxa2x0_apm_softc *sc; 520 struct pxa2x0_apm_softc *sc;
517 struct apm_power_info *power; 521 struct apm_power_info *power;
518 int error = 0; 522 int error = 0;
519 523
520 /* apm0 only */ 524 /* apm0 only */
521 if (!apm_cd.cd_ndevs || APMUNIT(dev) != 0 || 525 if (!apm_cd.cd_ndevs || APMUNIT(dev) != 0 ||
522 !(sc = apm_cd.cd_devs[APMUNIT(dev)])) 526 !(sc = apm_cd.cd_devs[APMUNIT(dev)]))
523 return (ENXIO); 527 return (ENXIO);
524 528
525 switch (cmd) { 529 switch (cmd) {
526 /* some ioctl names from linux */ 530 /* some ioctl names from linux */
527 case APM_IOC_STANDBY: 531 case APM_IOC_STANDBY:
528 if ((flag & FWRITE) == 0) 532 if ((flag & FWRITE) == 0)
529 error = EBADF; 533 error = EBADF;
530 else 534 else
531 apm_userstandbys++; 535 apm_userstandbys++;
532 break; 536 break;
533 case APM_IOC_SUSPEND: 537 case APM_IOC_SUSPEND:
534 if ((flag & FWRITE) == 0) 538 if ((flag & FWRITE) == 0)
535 error = EBADF; 539 error = EBADF;
536 else 540 else
537 apm_suspends++; /* XXX */ 541 apm_suspends++; /* XXX */
538 break; 542 break;
539 case APM_IOC_PRN_CTL: 543 case APM_IOC_PRN_CTL:
540 if ((flag & FWRITE) == 0) 544 if ((flag & FWRITE) == 0)
541 error = EBADF; 545 error = EBADF;
542 else { 546 else {
543 int flag = *(int *)data; 547 int flag = *(int *)data;
544 DPRINTF(( "APM_IOC_PRN_CTL: %d\n", flag )); 548 DPRINTF(( "APM_IOC_PRN_CTL: %d\n", flag ));
545 switch (flag) { 549 switch (flag) {
546 case APM_PRINT_ON: /* enable printing */ 550 case APM_PRINT_ON: /* enable printing */
547 sc->sc_flags &= ~SCFLAG_PRINT; 551 sc->sc_flags &= ~SCFLAG_PRINT;
548 break; 552 break;
549 case APM_PRINT_OFF: /* disable printing */ 553 case APM_PRINT_OFF: /* disable printing */
550 sc->sc_flags &= ~SCFLAG_PRINT; 554 sc->sc_flags &= ~SCFLAG_PRINT;
551 sc->sc_flags |= SCFLAG_NOPRINT; 555 sc->sc_flags |= SCFLAG_NOPRINT;
552 break; 556 break;
553 case APM_PRINT_PCT: /* disable some printing */ 557 case APM_PRINT_PCT: /* disable some printing */
554 sc->sc_flags &= ~SCFLAG_PRINT; 558 sc->sc_flags &= ~SCFLAG_PRINT;
555 sc->sc_flags |= SCFLAG_PCTPRINT; 559 sc->sc_flags |= SCFLAG_PCTPRINT;
556 break; 560 break;
557 default: 561 default:
558 error = EINVAL; 562 error = EINVAL;
559 break; 563 break;
560 } 564 }
561 } 565 }
562 break; 566 break;
563 case APM_IOC_DEV_CTL: 567 case APM_IOC_DEV_CTL:
564 if ((flag & FWRITE) == 0) 568 if ((flag & FWRITE) == 0)
565 error = EBADF; 569 error = EBADF;
566 break; 570 break;
567 case APM_IOC_GETPOWER: 571 case APM_IOC_GETPOWER:
568 power = (struct apm_power_info *)data; 572 power = (struct apm_power_info *)data;
569 apm_power_info(sc, power); 573 apm_power_info(sc, power);
570 break; 574 break;
571 575
572 default: 576 default:
573 error = ENOTTY; 577 error = ENOTTY;
574 } 578 }
575 579
576 return (error); 580 return (error);
577} 581}
578 582
579int 583int
580apm_record_event(struct pxa2x0_apm_softc *sc, u_int type) 584apm_record_event(struct pxa2x0_apm_softc *sc, u_int type)
581{ 585{
582 static int apm_evindex; 586 static int apm_evindex;
583 587
584 /* skip if no user waiting */ 588 /* skip if no user waiting */
585 if ((sc->sc_flags & SCFLAG_OPEN) == 0) 589 if ((sc->sc_flags & SCFLAG_OPEN) == 0)
586 return (1); 590 return (1);
587 591
588 apm_evindex++; 592 apm_evindex++;
589 KNOTE(&sc->sc_note, APM_EVENT_COMPOSE(type, apm_evindex)); 593 KNOTE(&sc->sc_note, APM_EVENT_COMPOSE(type, apm_evindex));
590 594
591 return (0); 595 return (0);
592} 596}
593 597
594void 598void
595filt_apmrdetach(struct knote *kn) 599filt_apmrdetach(struct knote *kn)
596{ 600{
597 struct pxa2x0_apm_softc *sc = 601 struct pxa2x0_apm_softc *sc =
598 (struct pxa2x0_apm_softc *)kn->kn_hook; 602 (struct pxa2x0_apm_softc *)kn->kn_hook;
599 603
600 SLIST_REMOVE(&sc->sc_note, kn, knote, kn_selnext); 604 SLIST_REMOVE(&sc->sc_note, kn, knote, kn_selnext);
601} 605}
602 606
603int 607int
604filt_apmread(struct knote *kn, long hint) 608filt_apmread(struct knote *kn, long hint)
605{ 609{
606 /* XXX weird kqueue_scan() semantics */ 610 /* XXX weird kqueue_scan() semantics */
607 if (hint && !kn->kn_data) 611 if (hint && !kn->kn_data)
608 kn->kn_data = (int)hint; 612 kn->kn_data = (int)hint;
609 613
610 return (1); 614 return (1);
611} 615}
612 616
613int 617int
614apmkqfilter(dev_t dev, struct knote *kn) 618apmkqfilter(dev_t dev, struct knote *kn)
615{ 619{
616 struct pxa2x0_apm_softc *sc; 620 struct pxa2x0_apm_softc *sc;
617 621
618 /* apm0 only */ 622 /* apm0 only */
619 if (!apm_cd.cd_ndevs || APMUNIT(dev) != 0 || 623 if (!apm_cd.cd_ndevs || APMUNIT(dev) != 0 ||
620 !(sc = apm_cd.cd_devs[APMUNIT(dev)])) 624 !(sc = apm_cd.cd_devs[APMUNIT(dev)]))
621 return (ENXIO); 625 return (ENXIO);
622 626
623 switch (kn->kn_filter) { 627 switch (kn->kn_filter) {
624 case EVFILT_READ: 628 case EVFILT_READ:
625 kn->kn_fop = &apmread_filtops; 629 kn->kn_fop = &apmread_filtops;
626 break; 630 break;
627 default: 631 default:
628 return (1); 632 return (1);
629 } 633 }
630 634
631 kn->kn_hook = (caddr_t)sc; 635 kn->kn_hook = (caddr_t)sc;
632 SLIST_INSERT_HEAD(&sc->sc_note, kn, kn_selnext); 636 SLIST_INSERT_HEAD(&sc->sc_note, kn, kn_selnext);
633 637
634 return (0); 638 return (0);
635} 639}
636 640
637void 641void
638pxa2x0_apm_attach_sub(struct pxa2x0_apm_softc *sc) 642pxa2x0_apm_attach_sub(struct pxa2x0_apm_softc *sc)
639{ 643{
640 644
641 sc->sc_iot = &pxa2x0_bs_tag; 645 sc->sc_iot = &pxa2x0_bs_tag;
642 646
643 if (bus_space_map(sc->sc_iot, PXA2X0_POWMAN_BASE, 647 if (bus_space_map(sc->sc_iot, PXA2X0_POWMAN_BASE,
644 PXA2X0_POWMAN_SIZE, 0, &sc->sc_pm_ioh)) { 648 PXA2X0_POWMAN_SIZE, 0, &sc->sc_pm_ioh)) {
645 printf("pxa2x0_apm_attach_sub: failed to map POWMAN\n"); 649 printf("pxa2x0_apm_attach_sub: failed to map POWMAN\n");
646 return; 650 return;
647 } 651 }
648 652
649 lockinit(&sc->sc_lock, PWAIT, "apmlk", 0, 0); 653 lockinit(&sc->sc_lock, PWAIT, "apmlk", 0, 0);
650 654
651 kthread_create_deferred(apm_thread_create, sc); 655 kthread_create_deferred(apm_thread_create, sc);
652 656
653 printf("\n"); 657 printf("\n");
654 658
655 if (bus_space_map(sc->sc_iot, PXA2X0_CLKMAN_BASE, PXA2X0_CLKMAN_SIZE, 659 if (bus_space_map(sc->sc_iot, PXA2X0_CLKMAN_BASE, PXA2X0_CLKMAN_SIZE,
656 0, &pxa2x0_clkman_ioh)) { 660 0, &pxa2x0_clkman_ioh)) {
657 printf("%s: failed to map CLKMAN\n", device_xname(sc->sc_dev)); 661 printf("%s: failed to map CLKMAN\n", device_xname(sc->sc_dev));
658 return; 662 return;
659 } 663 }
660 664
661 if (bus_space_map(sc->sc_iot, PXA2X0_MEMCTL_BASE, PXA2X0_MEMCTL_SIZE, 665 if (bus_space_map(sc->sc_iot, PXA2X0_MEMCTL_BASE, PXA2X0_MEMCTL_SIZE,
662 0, &pxa2x0_memctl_ioh)) { 666 0, &pxa2x0_memctl_ioh)) {
663 printf("%s: failed to map MEMCTL\n", device_xname(sc->sc_dev)); 667 printf("%s: failed to map MEMCTL\n", device_xname(sc->sc_dev));
664 return; 668 return;
665 } 669 }
666 sc->sc_memctl_ioh = pxa2x0_memctl_ioh; 670 sc->sc_memctl_ioh = pxa2x0_memctl_ioh;
667 671
668 if (bus_space_map(sc->sc_iot, PXA2X0_GPIO_BASE, PXA2X0_GPIO_SIZE, 672 if (bus_space_map(sc->sc_iot, PXA2X0_GPIO_BASE, PXA2X0_GPIO_SIZE,
669 0, &pxa2x0_gpio_ioh)) { 673 0, &pxa2x0_gpio_ioh)) {
670 printf("%s: can't map GPIO\n", device_xname(sc->sc_dev)); 674 printf("%s: can't map GPIO\n", device_xname(sc->sc_dev));
671 return; 675 return;
672 } 676 }
673 677
674 /* Clear all reset status flags. */ 678 /* Clear all reset status flags. */
675 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_RCSR, 679 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_RCSR,
676 RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR); 680 RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR);
677} 681}
678#endif /* 0 */ 682#endif /* 0 */
679 683
680void 684void
681pxa2x0_wakeup_config(u_int wsrc, int enable) 685pxa2x0_wakeup_config(u_int wsrc, int enable)
682{ 686{
683 struct pxa2x0_apm_softc *sc; 687 struct pxa2x0_apm_softc *sc;
684 uint32_t prer; 688 uint32_t prer;
685 uint32_t pfer; 689 uint32_t pfer;
686 uint32_t pkwr; 690 uint32_t pkwr;
687 691
688 if (zapm_cd.cd_ndevs < 1 || zapm_cd.cd_devs[0] == NULL) 692 if (zapm_cd.cd_ndevs < 1 || zapm_cd.cd_devs[0] == NULL)
689 return; 693 return;
690 sc = device_private(zapm_cd.cd_devs[0]); 694 sc = device_private(zapm_cd.cd_devs[0]);
691 695
692 prer = pfer = pkwr = 0; 696 prer = pfer = pkwr = 0;
693 697
694 if ((wsrc & PXA2X0_WAKEUP_POWERON) != 0) { 698 if ((wsrc & PXA2X0_WAKEUP_POWERON) != 0) {
695 prer |= (1<<0); 699 prer |= (1<<0);
696 pfer |= (1<<0); 700 pfer |= (1<<0);
697 pkwr |= (1<<12); /* XXX */ 701 pkwr |= (1<<12); /* XXX */
698 } 702 }
699 703
700 if ((wsrc & PXA2X0_WAKEUP_GPIORST) != 0) 704 if ((wsrc & PXA2X0_WAKEUP_GPIORST) != 0)
701 pfer |= (1<<1); 705 pfer |= (1<<1);
702 if ((wsrc & PXA2X0_WAKEUP_SD) != 0) 706 if ((wsrc & PXA2X0_WAKEUP_SD) != 0)
703 prer |= (1<<9); 707 prer |= (1<<9);
704 if ((wsrc & PXA2X0_WAKEUP_RC) != 0) 708 if ((wsrc & PXA2X0_WAKEUP_RC) != 0)
705 prer |= (1<<13); 709 prer |= (1<<13);
706 if ((wsrc & PXA2X0_WAKEUP_SYNC) != 0) 710 if ((wsrc & PXA2X0_WAKEUP_SYNC) != 0)
707 pkwr |= (1<<1); 711 pkwr |= (1<<1);
708 if ((wsrc & PXA2X0_WAKEUP_KEYNS0) != 0) 712 if ((wsrc & PXA2X0_WAKEUP_KEYNS0) != 0)
709 prer |= (1<<12); 713 prer |= (1<<12);
710 if ((wsrc & PXA2X0_WAKEUP_KEYNS1) != 0) 714 if ((wsrc & PXA2X0_WAKEUP_KEYNS1) != 0)
711 pkwr |= (1<<2); 715 pkwr |= (1<<2);
712 if ((wsrc & PXA2X0_WAKEUP_KEYNS2) != 0) 716 if ((wsrc & PXA2X0_WAKEUP_KEYNS2) != 0)
713 pkwr |= (1<<9); 717 pkwr |= (1<<9);
714 if ((wsrc & PXA2X0_WAKEUP_KEYNS3) != 0) 718 if ((wsrc & PXA2X0_WAKEUP_KEYNS3) != 0)
715 pkwr |= (1<<3); 719 pkwr |= (1<<3);
716 if ((wsrc & PXA2X0_WAKEUP_KEYNS4) != 0) 720 if ((wsrc & PXA2X0_WAKEUP_KEYNS4) != 0)
717 pkwr |= (1<<4); 721 pkwr |= (1<<4);
718 if ((wsrc & PXA2X0_WAKEUP_KEYNS5) != 0) 722 if ((wsrc & PXA2X0_WAKEUP_KEYNS5) != 0)
719 pkwr |= (1<<6); 723 pkwr |= (1<<6);
720 if ((wsrc & PXA2X0_WAKEUP_KEYNS6) != 0) 724 if ((wsrc & PXA2X0_WAKEUP_KEYNS6) != 0)
721 pkwr |= (1<<7); 725 pkwr |= (1<<7);
722 if ((wsrc & PXA2X0_WAKEUP_CF0) != 0) 726 if ((wsrc & PXA2X0_WAKEUP_CF0) != 0)
723 pkwr |= (1<<11); 727 pkwr |= (1<<11);
724 if ((wsrc & PXA2X0_WAKEUP_CF1) != 0) 728 if ((wsrc & PXA2X0_WAKEUP_CF1) != 0)
725 pkwr |= (1<<10); 729 pkwr |= (1<<10);
726 if ((wsrc & PXA2X0_WAKEUP_USBD) != 0) 730 if ((wsrc & PXA2X0_WAKEUP_USBD) != 0)
727 prer |= (1<<24); 731 prer |= (1<<24);
728 732
729 if ((wsrc & PXA2X0_WAKEUP_LOCKSW) != 0) { 733 if ((wsrc & PXA2X0_WAKEUP_LOCKSW) != 0) {
730 prer |= (1<<15); 734 prer |= (1<<15);
731 pfer |= (1<<15); 735 pfer |= (1<<15);
732 } 736 }
733 737
734 if ((wsrc & PXA2X0_WAKEUP_JACKIN) != 0) { 738 if ((wsrc & PXA2X0_WAKEUP_JACKIN) != 0) {
735 prer |= (1<<23); 739 prer |= (1<<23);
736 pfer |= (1<<23); 740 pfer |= (1<<23);
737 } 741 }
738 742
739 if ((wsrc & PXA2X0_WAKEUP_CHRGFULL) != 0) 743 if ((wsrc & PXA2X0_WAKEUP_CHRGFULL) != 0)
740 pkwr |= (1<<18); 744 pkwr |= (1<<18);
741 if ((wsrc & PXA2X0_WAKEUP_RTC) != 0) 745 if ((wsrc & PXA2X0_WAKEUP_RTC) != 0)
742 prer |= (1<<31); 746 prer |= (1<<31);
743 747
744 if (enable) { 748 if (enable) {
745 sc->sc_wakeon |= wsrc; 749 sc->sc_wakeon |= wsrc;
746 prer |= bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, 750 prer |= bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh,
747 POWMAN_PRER); 751 POWMAN_PRER);
748 pfer |= bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, 752 pfer |= bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh,
749 POWMAN_PFER); 753 POWMAN_PFER);
750 pkwr |= bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, 754 pkwr |= bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh,
751 POWMAN_PKWR); 755 POWMAN_PKWR);
752 } else { 756 } else {
753 sc->sc_wakeon &= ~wsrc; 757 sc->sc_wakeon &= ~wsrc;
754 prer = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, 758 prer = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh,
755 POWMAN_PRER) & ~prer; 759 POWMAN_PRER) & ~prer;
756 pfer = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, 760 pfer = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh,
757 POWMAN_PFER) & ~pfer; 761 POWMAN_PFER) & ~pfer;
758 pkwr = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, 762 pkwr = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh,
759 POWMAN_PKWR) & ~pkwr; 763 POWMAN_PKWR) & ~pkwr;
760 } 764 }
761 765
762 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PKWR, pkwr); 766 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PKWR, pkwr);
763 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PRER, prer); 767 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PRER, prer);
764 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PFER, pfer); 768 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PFER, pfer);
765 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PWER, 769 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PWER,
766 prer | pfer); 770 prer | pfer);
767} 771}
768 772
769u_int 773u_int
770pxa2x0_wakeup_status(void) 774pxa2x0_wakeup_status(void)
771{ 775{
772 struct pxa2x0_apm_softc *sc; 776 struct pxa2x0_apm_softc *sc;
773 uint32_t rv; 777 uint32_t rv;
774 u_int wsrc; 778 u_int wsrc;
775 779
776 if (zapm_cd.cd_ndevs < 1 || zapm_cd.cd_devs[0] == NULL) 780 if (zapm_cd.cd_ndevs < 1 || zapm_cd.cd_devs[0] == NULL)
777 return (0); 781 return (0);
778 782
779 sc = device_private(zapm_cd.cd_devs[0]); 783 sc = device_private(zapm_cd.cd_devs[0]);
780 wsrc = 0; 784 wsrc = 0;
781 785
782 rv = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PEDR); 786 rv = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PEDR);
783 if ((rv & (1<<0)) != 0) 787 if ((rv & (1<<0)) != 0)
784 wsrc |= PXA2X0_WAKEUP_POWERON; 788 wsrc |= PXA2X0_WAKEUP_POWERON;
785 if ((rv & (1<<1)) != 0) 789 if ((rv & (1<<1)) != 0)
786 wsrc |= PXA2X0_WAKEUP_GPIORST; 790 wsrc |= PXA2X0_WAKEUP_GPIORST;
787 if ((rv & (1<<9)) != 0) 791 if ((rv & (1<<9)) != 0)
788 wsrc |= PXA2X0_WAKEUP_SD; 792 wsrc |= PXA2X0_WAKEUP_SD;
789 if ((rv & (1<<12)) != 0) 793 if ((rv & (1<<12)) != 0)
790 wsrc |= PXA2X0_WAKEUP_KEYNS0; 794 wsrc |= PXA2X0_WAKEUP_KEYNS0;
791 if ((rv & (1<<13)) != 0) 795 if ((rv & (1<<13)) != 0)
792 wsrc |= PXA2X0_WAKEUP_RC; 796 wsrc |= PXA2X0_WAKEUP_RC;
793 if ((rv & (1<<15)) != 0) 797 if ((rv & (1<<15)) != 0)
794 wsrc |= PXA2X0_WAKEUP_LOCKSW; 798 wsrc |= PXA2X0_WAKEUP_LOCKSW;
795 if ((rv & (1<<23)) != 0) 799 if ((rv & (1<<23)) != 0)
796 wsrc |= PXA2X0_WAKEUP_JACKIN; 800 wsrc |= PXA2X0_WAKEUP_JACKIN;
797 if ((rv & (1<<24)) != 0) 801 if ((rv & (1<<24)) != 0)
798 wsrc |= PXA2X0_WAKEUP_USBD; 802 wsrc |= PXA2X0_WAKEUP_USBD;
799 if ((rv & (1<<31)) != 0) 803 if ((rv & (1<<31)) != 0)
800 wsrc |= PXA2X0_WAKEUP_RTC; 804 wsrc |= PXA2X0_WAKEUP_RTC;
801 805
802 rv = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PKSR); 806 rv = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PKSR);
803 if ((rv & (1<<1)) != 0) 807 if ((rv & (1<<1)) != 0)
804 wsrc |= PXA2X0_WAKEUP_SYNC; 808 wsrc |= PXA2X0_WAKEUP_SYNC;
805 if ((rv & (1<<2)) != 0) 809 if ((rv & (1<<2)) != 0)
806 wsrc |= PXA2X0_WAKEUP_KEYNS1; 810 wsrc |= PXA2X0_WAKEUP_KEYNS1;
807 if ((rv & (1<<9)) != 0) 811 if ((rv & (1<<9)) != 0)
808 wsrc |= PXA2X0_WAKEUP_KEYNS2; 812 wsrc |= PXA2X0_WAKEUP_KEYNS2;
809 if ((rv & (1<<3)) != 0) 813 if ((rv & (1<<3)) != 0)
810 wsrc |= PXA2X0_WAKEUP_KEYNS3; 814 wsrc |= PXA2X0_WAKEUP_KEYNS3;
811 if ((rv & (1<<4)) != 0) 815 if ((rv & (1<<4)) != 0)
812 wsrc |= PXA2X0_WAKEUP_KEYNS4; 816 wsrc |= PXA2X0_WAKEUP_KEYNS4;
813 if ((rv & (1<<6)) != 0) 817 if ((rv & (1<<6)) != 0)
814 wsrc |= PXA2X0_WAKEUP_KEYNS5; 818 wsrc |= PXA2X0_WAKEUP_KEYNS5;
815 if ((rv & (1<<7)) != 0) 819 if ((rv & (1<<7)) != 0)
816 wsrc |= PXA2X0_WAKEUP_KEYNS6; 820 wsrc |= PXA2X0_WAKEUP_KEYNS6;
817 if ((rv & (1<<10)) != 0) 821 if ((rv & (1<<10)) != 0)
818 wsrc |= PXA2X0_WAKEUP_CF1; 822 wsrc |= PXA2X0_WAKEUP_CF1;
819 if ((rv & (1<<11)) != 0) 823 if ((rv & (1<<11)) != 0)
820 wsrc |= PXA2X0_WAKEUP_CF0; 824 wsrc |= PXA2X0_WAKEUP_CF0;
821 if ((rv & (1<<12)) != 0) 825 if ((rv & (1<<12)) != 0)
822 wsrc |= PXA2X0_WAKEUP_POWERON; 826 wsrc |= PXA2X0_WAKEUP_POWERON;
823 if ((rv & (1<<18)) != 0) 827 if ((rv & (1<<18)) != 0)
824 wsrc |= PXA2X0_WAKEUP_CHRGFULL; 828 wsrc |= PXA2X0_WAKEUP_CHRGFULL;
825 829
826 return (wsrc); 830 return (wsrc);
827} 831}
828 832
829struct pxa2x0_sleep_data { 833struct pxa2x0_sleep_data {
830 /* OS timer registers */ 834 /* OS timer registers */
831 uint32_t sd_osmr0, sd_osmr1, sd_osmr2, sd_osmr3; 835 uint32_t sd_osmr0, sd_osmr1, sd_osmr2, sd_osmr3;
832 uint32_t sd_oscr0; 836 uint32_t sd_oscr0;
833 uint32_t sd_osmr4, sd_osmr5; 837 uint32_t sd_osmr4, sd_osmr5;
834 uint32_t sd_oscr4; 838 uint32_t sd_oscr4;
835 uint32_t sd_omcr4, sd_omcr5; 839 uint32_t sd_omcr4, sd_omcr5;
836 uint32_t sd_oier; 840 uint32_t sd_oier;
837 /* GPIO registers */ 841 /* GPIO registers */
838 uint32_t sd_gpdr0, sd_gpdr1, sd_gpdr2, sd_gpdr3; 842 uint32_t sd_gpdr0, sd_gpdr1, sd_gpdr2, sd_gpdr3;
839 uint32_t sd_grer0, sd_grer1, sd_grer2, sd_grer3; 843 uint32_t sd_grer0, sd_grer1, sd_grer2, sd_grer3;
840 uint32_t sd_gfer0, sd_gfer1, sd_gfer2, sd_gfer3; 844 uint32_t sd_gfer0, sd_gfer1, sd_gfer2, sd_gfer3;
841 uint32_t sd_gafr0_l, sd_gafr1_l, sd_gafr2_l, sd_gafr3_l; 845 uint32_t sd_gafr0_l, sd_gafr1_l, sd_gafr2_l, sd_gafr3_l;
842 uint32_t sd_gafr0_u, sd_gafr1_u, sd_gafr2_u, sd_gafr3_u; 846 uint32_t sd_gafr0_u, sd_gafr1_u, sd_gafr2_u, sd_gafr3_u;
843 uint32_t sd_gplr0, sd_gplr1, sd_gplr2, sd_gplr3; 847 uint32_t sd_gplr0, sd_gplr1, sd_gplr2, sd_gplr3;
844 /* Interrupt controller registers */ 848 /* Interrupt controller registers */
845 uint32_t sd_iclr; 849 uint32_t sd_iclr;
846 uint32_t sd_icmr; 850 uint32_t sd_icmr;
847 uint32_t sd_iccr; 851 uint32_t sd_iccr;
848 /* Memory controller registers */ 852 /* Memory controller registers */
849 uint32_t sd_mecr; 853 uint32_t sd_mecr;
850 uint32_t sd_mcmem0, sd_mcmem1; 854 uint32_t sd_mcmem0, sd_mcmem1;
851 uint32_t sd_mcatt0, sd_mcatt1; 855 uint32_t sd_mcatt0, sd_mcatt1;
852 uint32_t sd_mcio0, sd_mcio1; 856 uint32_t sd_mcio0, sd_mcio1;
853 /* Clocks manager registers */ 857 /* Clocks manager registers */
854 uint32_t sd_cken; 858 uint32_t sd_cken;
855}; 859};
856 860
857void 861void
858pxa2x0_apm_sleep(struct pxa2x0_apm_softc *sc) 862pxa2x0_apm_sleep(struct pxa2x0_apm_softc *sc)
859{ 863{
860 struct pxa2x0_sleep_data sd; 864 struct pxa2x0_sleep_data sd;
861 bus_space_handle_t ost_ioh; 865 bus_space_handle_t ost_ioh;
862 int save; 866 int save;
863 uint32_t rv; 867 uint32_t rv;
864 868
865 ost_ioh = (bus_space_handle_t)0; 869 ost_ioh = (bus_space_handle_t)0;
866 if (bus_space_map(sc->sc_iot, PXA2X0_OST_BASE, PXA2X0_OST_SIZE, 0, 870 if (bus_space_map(sc->sc_iot, PXA2X0_OST_BASE, PXA2X0_OST_SIZE, 0,
867 &ost_ioh)) { 871 &ost_ioh)) {
868 printf("pxa2x0_apm_sleep: can't map OST\n"); 872 printf("pxa2x0_apm_sleep: can't map OST\n");
869 goto out; 873 goto out;
870 } 874 }
871 875
872 save = disable_interrupts(I32_bit|F32_bit); 876 save = disable_interrupts(I32_bit|F32_bit);
873 877
874 sd.sd_oscr0 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSCR0); 878 sd.sd_oscr0 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSCR0);
875 sd.sd_oscr4 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSCR4); 879 sd.sd_oscr4 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSCR4);
876 sd.sd_omcr4 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OMCR4); 880 sd.sd_omcr4 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OMCR4);
877 sd.sd_omcr5 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OMCR5); 881 sd.sd_omcr5 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OMCR5);
878 sd.sd_osmr0 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR0); 882 sd.sd_osmr0 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR0);
879 sd.sd_osmr1 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR1); 883 sd.sd_osmr1 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR1);
880 sd.sd_osmr2 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR2); 884 sd.sd_osmr2 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR2);
881 sd.sd_osmr3 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR3); 885 sd.sd_osmr3 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR3);
882 sd.sd_osmr4 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR4); 886 sd.sd_osmr4 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR4);
883 sd.sd_osmr5 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR5); 887 sd.sd_osmr5 = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OSMR5);
884 sd.sd_oier = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OIER); 888 sd.sd_oier = bus_space_read_4(sc->sc_iot, ost_ioh, OST_OIER);
885 889
886 /* Bring the PXA27x into 416MHz turbo mode. */ 890 /* Bring the PXA27x into 416MHz turbo mode. */
887 if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) == CPU_ID_PXA27X && 891 if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) == CPU_ID_PXA27X &&
888 bus_space_read_4(sc->sc_iot, pxa2x0_clkman_ioh, CLKMAN_CCCR) != 892 bus_space_read_4(sc->sc_iot, pxa2x0_clkman_ioh, CLKMAN_CCCR) !=
889 (CCCR_A | CCCR_TURBO_X2 | CCCR_RUN_X16)) { 893 (CCCR_A | CCCR_TURBO_X2 | CCCR_RUN_X16)) {
890#if 0 894#if 0
891 pxa27x_cpu_speed_high(); 895 pxa27x_cpu_speed_high();
892#else 896#else
893#define CLKCFG_T (1<<0) /* turbo */ 897#define CLKCFG_T (1<<0) /* turbo */
894#define CLKCFG_F (1<<1) /* frequency change */ 898#define CLKCFG_F (1<<1) /* frequency change */
895#define CLKCFG_B (1<<3) /* fast-bus */ 899#define CLKCFG_B (1<<3) /* fast-bus */
896 pxa27x_frequency_change(CCCR_A | CCCR_TURBO_X2 | 900 pxa27x_frequency_change(CCCR_A | CCCR_TURBO_X2 |
897 CCCR_RUN_X16, CLKCFG_B | CLKCFG_F | CLKCFG_T, 901 CCCR_RUN_X16, CLKCFG_B | CLKCFG_F | CLKCFG_T,
898 &pxa2x0_memcfg); 902 &pxa2x0_memcfg);
899#endif 903#endif
900 delay(500000); /* XXX */ 904 delay(500000); /* XXX */
901 } 905 }
902 906
903suspend_again: 907suspend_again:
904 /* Clear wake-up status. */ 908 /* Clear wake-up status. */
905 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PEDR, 909 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PEDR,
906 0xffffffff); 910 0xffffffff);
907 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PKSR, 911 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PKSR,
908 0xffffffff); 912 0xffffffff);
909 913
910 /* XXX control battery charging in sleep mode. */ 914 /* XXX control battery charging in sleep mode. */
911 915
912 /* XXX schedule RTC alarm to check the battery, or schedule 916 /* XXX schedule RTC alarm to check the battery, or schedule
913 XXX wake-up shortly before an already programmed alarm? */ 917 XXX wake-up shortly before an already programmed alarm? */
914 918
915 pxa27x_run_mode(); 919 pxa27x_run_mode();
916#define MDREFR_LOW (MDREFR_C3000 | 0x00b) 920#define MDREFR_LOW (MDREFR_C3000 | 0x00b)
917 pxa27x_fastbus_run_mode(0, MDREFR_LOW); 921 pxa27x_fastbus_run_mode(0, MDREFR_LOW);
918 delay(1); 922 delay(1);
919#if 1 923#if 1
920 pxa27x_cpu_speed_91(); 924 pxa27x_cpu_speed_91();
921#else 925#else
922 pxa27x_frequency_change(CCCR_TURBO_X1 | CCCR_RUN_X7, CLKCFG_F, 926 pxa27x_frequency_change(CCCR_TURBO_X1 | CCCR_RUN_X7, CLKCFG_F,
923 &pxa2x0_memcfg); 927 &pxa2x0_memcfg);
924#endif 928#endif
925 pxa2x0_pi2c_setvoltage(sc->sc_iot, sc->sc_pm_ioh, PI2C_VOLTAGE_LOW); 929 pxa2x0_pi2c_setvoltage(sc->sc_iot, sc->sc_pm_ioh, PI2C_VOLTAGE_LOW);
926 930
927 sd.sd_gpdr0 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR0); 931 sd.sd_gpdr0 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR0);
928 sd.sd_gpdr1 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR1); 932 sd.sd_gpdr1 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR1);
929 sd.sd_gpdr2 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR2); 933 sd.sd_gpdr2 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR2);
930 sd.sd_gpdr3 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR3); 934 sd.sd_gpdr3 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR3);
931 935
932 sd.sd_grer0 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER0); 936 sd.sd_grer0 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER0);
933 sd.sd_grer1 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER1); 937 sd.sd_grer1 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER1);
934 sd.sd_grer2 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER2); 938 sd.sd_grer2 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER2);
935 sd.sd_grer3 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER3); 939 sd.sd_grer3 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER3);
936 940
937 sd.sd_gfer0 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER0); 941 sd.sd_gfer0 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER0);
938 sd.sd_gfer1 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER1); 942 sd.sd_gfer1 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER1);
939 sd.sd_gfer2 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER2); 943 sd.sd_gfer2 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER2);
940 sd.sd_gfer3 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER3); 944 sd.sd_gfer3 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER3);
941 945
942 sd.sd_gafr0_l = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR0_L); 946 sd.sd_gafr0_l = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR0_L);
943 sd.sd_gafr1_l = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR1_L); 947 sd.sd_gafr1_l = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR1_L);
944 sd.sd_gafr2_l = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR2_L); 948 sd.sd_gafr2_l = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR2_L);
945 sd.sd_gafr3_l = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR3_L); 949 sd.sd_gafr3_l = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR3_L);
946 950
947 sd.sd_gafr0_u = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR0_U); 951 sd.sd_gafr0_u = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR0_U);
948 sd.sd_gafr1_u = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR1_U); 952 sd.sd_gafr1_u = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR1_U);
949 sd.sd_gafr2_u = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR2_U); 953 sd.sd_gafr2_u = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR2_U);
950 sd.sd_gafr3_u = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR3_U); 954 sd.sd_gafr3_u = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR3_U);
951 955
952 sd.sd_gplr0 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPLR0); 956 sd.sd_gplr0 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPLR0);
953 sd.sd_gplr1 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPLR1); 957 sd.sd_gplr1 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPLR1);
954 sd.sd_gplr2 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPLR2); 958 sd.sd_gplr2 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPLR2);
955 sd.sd_gplr3 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPLR3); 959 sd.sd_gplr3 = bus_space_read_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPLR3);
956 960
957 sd.sd_iclr = read_icu(INTCTL_ICLR); 961 sd.sd_iclr = read_icu(INTCTL_ICLR);
958 sd.sd_icmr = read_icu(INTCTL_ICMR); 962 sd.sd_icmr = read_icu(INTCTL_ICMR);
959 sd.sd_iccr = read_icu(INTCTL_ICCR); 963 sd.sd_iccr = read_icu(INTCTL_ICCR);
960 write_icu(INTCTL_ICMR, 0); 964 write_icu(INTCTL_ICMR, 0);
961 965
962 sd.sd_mecr = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh, 966 sd.sd_mecr = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh,
963 MEMCTL_MECR); 967 MEMCTL_MECR);
964 sd.sd_mcmem0 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh, 968 sd.sd_mcmem0 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh,
965 MEMCTL_MCMEM(0)); 969 MEMCTL_MCMEM(0));
966 sd.sd_mcmem1 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh, 970 sd.sd_mcmem1 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh,
967 MEMCTL_MCMEM(1)); 971 MEMCTL_MCMEM(1));
968 sd.sd_mcatt0 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh, 972 sd.sd_mcatt0 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh,
969 MEMCTL_MCATT(0)); 973 MEMCTL_MCATT(0));
970 sd.sd_mcatt1 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh, 974 sd.sd_mcatt1 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh,
971 MEMCTL_MCATT(1)); 975 MEMCTL_MCATT(1));
972 sd.sd_mcio0 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh, 976 sd.sd_mcio0 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh,
973 MEMCTL_MCIO(0)); 977 MEMCTL_MCIO(0));
974 sd.sd_mcio1 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh, 978 sd.sd_mcio1 = bus_space_read_4(sc->sc_iot, pxa2x0_memctl_ioh,
975 MEMCTL_MCIO(1)); 979 MEMCTL_MCIO(1));
976 980
977 sd.sd_cken = bus_space_read_4(sc->sc_iot, pxa2x0_clkman_ioh, 981 sd.sd_cken = bus_space_read_4(sc->sc_iot, pxa2x0_clkman_ioh,
978 CLKMAN_CKEN); 982 CLKMAN_CKEN);
979 983
980 /* 984 /*
981 * Stop clocks to all units except to the memory controller, and 985 * Stop clocks to all units except to the memory controller, and
982 * to the keypad controller if it is enabled as a wake-up source. 986 * to the keypad controller if it is enabled as a wake-up source.
983 */ 987 */
984 rv = CKEN_MEM; 988 rv = CKEN_MEM;
985 if ((sc->sc_wakeon & PXA2X0_WAKEUP_KEYNS_ALL) != 0) 989 if ((sc->sc_wakeon & PXA2X0_WAKEUP_KEYNS_ALL) != 0)
986 rv |= CKEN_KEY; 990 rv |= CKEN_KEY;
987 bus_space_write_4(sc->sc_iot, pxa2x0_clkman_ioh, CLKMAN_CKEN, rv); 991 bus_space_write_4(sc->sc_iot, pxa2x0_clkman_ioh, CLKMAN_CKEN, rv);
988 992
989 /* Disable nRESET_OUT. */ 993 /* Disable nRESET_OUT. */
990 rv = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSLR); 994 rv = bus_space_read_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSLR);
991#define PSLR_SL_ROD (1<<20) 995#define PSLR_SL_ROD (1<<20)
992 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSLR, 996 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSLR,
993 rv | PSLR_SL_ROD); 997 rv | PSLR_SL_ROD);
994 998
995 /* Clear all reset status flags. */ 999 /* Clear all reset status flags. */
996 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_RCSR, 1000 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_RCSR,
997 RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR); 1001 RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR);
998 1002
999 /* Stop 3/13MHz oscillator; do not float PCMCIA and chip-selects. */ 1003 /* Stop 3/13MHz oscillator; do not float PCMCIA and chip-selects. */
1000 rv = PCFR_OPDE; 1004 rv = PCFR_OPDE;
1001 if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) == CPU_ID_PXA27X) 1005 if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) == CPU_ID_PXA27X)
1002 /* Enable nRESET_GPIO as a GPIO reset input. */ 1006 /* Enable nRESET_GPIO as a GPIO reset input. */
1003 rv |= PCFR_GPR_EN; 1007 rv |= PCFR_GPR_EN;
1004 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PCFR, rv); 1008 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PCFR, rv);
1005 1009
1006 /* XXX C3000 */ 1010 /* XXX C3000 */
1007#define GPIO_G0_STROBE_BIT 0x0f800000 1011#define GPIO_G0_STROBE_BIT 0x0f800000
1008#define GPIO_G1_STROBE_BIT 0x00100000 1012#define GPIO_G1_STROBE_BIT 0x00100000
1009#define GPIO_G2_STROBE_BIT 0x01000000 1013#define GPIO_G2_STROBE_BIT 0x01000000
1010#define GPIO_G3_STROBE_BIT 0x00041880 1014#define GPIO_G3_STROBE_BIT 0x00041880
1011#define GPIO_KEY_STROBE0 88 1015#define GPIO_KEY_STROBE0 88
1012 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR0, 1016 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR0,
1013 0x00144018); 1017 0x00144018);
1014 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR1, 1018 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR1,
1015 0x00ef0000); 1019 0x00ef0000);
1016 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR2, 1020 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR2,
1017 0x0121c000); 1021 0x0121c000);
1018 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR3, 1022 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR3,
1019 0x00600000); 1023 0x00600000);
1020 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR0, 1024 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR0,
1021 0x00144018 & ~GPIO_G0_STROBE_BIT); 1025 0x00144018 & ~GPIO_G0_STROBE_BIT);
1022 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR1, 1026 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR1,
1023 0x00ef0000 & ~GPIO_G1_STROBE_BIT); 1027 0x00ef0000 & ~GPIO_G1_STROBE_BIT);
1024 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR2, 1028 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR2,
1025 0x0121c000 & ~GPIO_G2_STROBE_BIT); 1029 0x0121c000 & ~GPIO_G2_STROBE_BIT);
1026 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR3, 1030 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR3,
1027 0x00600000 & ~GPIO_G3_STROBE_BIT); 1031 0x00600000 & ~GPIO_G3_STROBE_BIT);
1028 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR2, 1032 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PGSR2,
1029 (0x0121c000 & ~GPIO_G2_STROBE_BIT) | 1033 (0x0121c000 & ~GPIO_G2_STROBE_BIT) |
1030 GPIO_BIT(GPIO_KEY_STROBE0)); 1034 GPIO_BIT(GPIO_KEY_STROBE0));
1031 1035
1032 /* C3000 */ 1036 /* C3000 */
1033#define GPIO_EXT_BUS_READY 18 1037#define GPIO_EXT_BUS_READY 18
1034 pxa2x0_gpio_set_function(GPIO_EXT_BUS_READY, GPIO_SET | GPIO_OUT); 1038 pxa2x0_gpio_set_function(GPIO_EXT_BUS_READY, GPIO_SET | GPIO_OUT);
1035 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR0, 0xd01c4418); 1039 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR0, 0xd01c4418);
1036 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR1, 0xfcefbd21); 1040 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR1, 0xfcefbd21);
1037 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR2, 0x13a5ffff); 1041 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR2, 0x13a5ffff);
1038 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR3, 0x01e3e10c); 1042 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR3, 0x01e3e10c);
1039 1043
1040 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSPR, 1044 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSPR,
1041 (uint32_t)&pxa2x0_cpu_resume - 0xc0200000 + 0xa0200000); 1045 (uint32_t)&pxa2x0_cpu_resume - 0xc0200000 + 0xa0200000);
1042 1046
1043 pxa2x0_cpu_suspend(); 1047 pxa2x0_cpu_suspend();
1044 1048
1045 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSPR, 0); 1049 bus_space_write_4(sc->sc_iot, sc->sc_pm_ioh, POWMAN_PSPR, 0);
1046 1050
1047 pxa2x0_clkman_config(CKEN_SSP|CKEN_PWM0|CKEN_PWM1, 1); 1051 pxa2x0_clkman_config(CKEN_SSP|CKEN_PWM0|CKEN_PWM1, 1);
1048 pxa2x0_clkman_config(CKEN_KEY, 0); 1052 pxa2x0_clkman_config(CKEN_KEY, 0);
1049 1053
1050#if 1 1054#if 1
1051 /* Clear all GPIO interrupt sources. */ 1055 /* Clear all GPIO interrupt sources. */
1052 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GEDR0, 0xffffffff); 1056 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GEDR0, 0xffffffff);
1053 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GEDR1, 0xffffffff); 1057 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GEDR1, 0xffffffff);
1054 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GEDR2, 0xffffffff); 1058 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GEDR2, 0xffffffff);
1055#endif 1059#endif
1056 1060
1057 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR0, sd.sd_gpdr0); 1061 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR0, sd.sd_gpdr0);
1058 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR1, sd.sd_gpdr1); 1062 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR1, sd.sd_gpdr1);
1059 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR2, sd.sd_gpdr2); 1063 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR2, sd.sd_gpdr2);
1060 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER0, sd.sd_grer0); 1064 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER0, sd.sd_grer0);
1061 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER1, sd.sd_grer1); 1065 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER1, sd.sd_grer1);
1062 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER2, sd.sd_grer2); 1066 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER2, sd.sd_grer2);
1063 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER0, sd.sd_gfer0); 1067 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER0, sd.sd_gfer0);
1064 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER1, sd.sd_gfer1); 1068 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER1, sd.sd_gfer1);
1065 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER2, sd.sd_gfer2); 1069 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER2, sd.sd_gfer2);
1066 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR0_L, sd.sd_gafr0_l); 1070 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR0_L, sd.sd_gafr0_l);
1067 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR1_L, sd.sd_gafr1_l); 1071 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR1_L, sd.sd_gafr1_l);
1068 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR2_L, sd.sd_gafr2_l); 1072 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR2_L, sd.sd_gafr2_l);
1069 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR0_U, sd.sd_gafr0_u); 1073 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR0_U, sd.sd_gafr0_u);
1070 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR1_U, sd.sd_gafr1_u); 1074 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR1_U, sd.sd_gafr1_u);
1071 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR2_U, sd.sd_gafr2_u); 1075 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR2_U, sd.sd_gafr2_u);
1072 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPSR0, sd.sd_gplr0 & 1076 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPSR0, sd.sd_gplr0 &
1073 sd.sd_gpdr0); 1077 sd.sd_gpdr0);
1074 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPSR1, sd.sd_gplr1 & 1078 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPSR1, sd.sd_gplr1 &
1075 sd.sd_gpdr1); 1079 sd.sd_gpdr1);
1076 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPSR2, sd.sd_gplr2 & 1080 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPSR2, sd.sd_gplr2 &
1077 sd.sd_gpdr2); 1081 sd.sd_gpdr2);
1078 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPCR0, ~sd.sd_gplr0 & 1082 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPCR0, ~sd.sd_gplr0 &
1079 sd.sd_gpdr0); 1083 sd.sd_gpdr0);
1080 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPCR1, ~sd.sd_gplr1 & 1084 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPCR1, ~sd.sd_gplr1 &
1081 sd.sd_gpdr1); 1085 sd.sd_gpdr1);
1082 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPCR2, ~sd.sd_gplr2 & 1086 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPCR2, ~sd.sd_gplr2 &
1083 sd.sd_gpdr2); 1087 sd.sd_gpdr2);
1084 1088
1085 /* PXA27x */ 1089 /* PXA27x */
1086#if 0 1090#if 0
1087 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GEDR3, 0xffffffff); 1091 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GEDR3, 0xffffffff);
1088#endif 1092#endif
1089 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR3, sd.sd_gpdr3); 1093 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPDR3, sd.sd_gpdr3);
1090 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER3, sd.sd_grer3); 1094 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GRER3, sd.sd_grer3);
1091 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER3, sd.sd_gfer3); 1095 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GFER3, sd.sd_gfer3);
1092 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR3_L, sd.sd_gafr3_l); 1096 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR3_L, sd.sd_gafr3_l);
1093 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR3_U, sd.sd_gafr3_u); 1097 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GAFR3_U, sd.sd_gafr3_u);
1094 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPSR3, sd.sd_gplr3 & 1098 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPSR3, sd.sd_gplr3 &
1095 sd.sd_gpdr3); 1099 sd.sd_gpdr3);
1096 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPCR3, ~sd.sd_gplr3 & 1100 bus_space_write_4(sc->sc_iot, pxa2x0_gpio_ioh, GPIO_GPCR3, ~sd.sd_gplr3 &
1097 sd.sd_gpdr3); 1101 sd.sd_gpdr3);
1098 1102
1099 bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MECR, 1103 bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MECR,
1100 sd.sd_mecr); 1104 sd.sd_mecr);
1101 bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MCMEM(0), 1105 bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MCMEM(0),
1102 sd.sd_mcmem0); 1106 sd.sd_mcmem0);
1103 bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MCMEM(1), 1107 bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MCMEM(1),
1104 sd.sd_mcmem1); 1108 sd.sd_mcmem1);
1105 bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MCATT(0), 1109 bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MCATT(0),
1106 sd.sd_mcatt0); 1110 sd.sd_mcatt0);
1107 bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MCATT(1), 1111 bus_space_write_4(sc->sc_iot, pxa2x0_memctl_ioh, MEMCTL_MCATT(1),

cvs diff -r1.27 -r1.28 src/sys/arch/macppc/dev/apm.c (switch to unified diff)

--- src/sys/arch/macppc/dev/apm.c 2014/07/25 08:10:34 1.27
+++ src/sys/arch/macppc/dev/apm.c 2020/10/30 22:20:38 1.28
@@ -1,459 +1,463 @@ @@ -1,459 +1,463 @@
1/* $NetBSD: apm.c,v 1.27 2014/07/25 08:10:34 dholland Exp $ */ 1/* $NetBSD: apm.c,v 1.28 2020/10/30 22:20:38 christos Exp $ */
2/* $OpenBSD: apm.c,v 1.5 2002/06/07 07:13:59 miod Exp $ */ 2/* $OpenBSD: apm.c,v 1.5 2002/06/07 07:13:59 miod Exp $ */
3 3
4/*- 4/*-
5 * Copyright (c) 2001 Alexander Guy. All rights reserved. 5 * Copyright (c) 2001 Alexander Guy. All rights reserved.
6 * Copyright (c) 1998-2001 Michael Shalayeff. All rights reserved. 6 * Copyright (c) 1998-2001 Michael Shalayeff. All rights reserved.
7 * Copyright (c) 1995 John T. Kohl. All rights reserved. 7 * Copyright (c) 1995 John T. Kohl. All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the names of the authors nor the names of contributors 17 * 3. Neither the names of the authors nor the names of contributors
18 * may be used to endorse or promote products derived from this software 18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission. 19 * without specific prior written permission.
20 * 20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * OR SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE. 31 * SUCH DAMAGE.
32 * 32 *
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.27 2014/07/25 08:10:34 dholland Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.28 2020/10/30 22:20:38 christos Exp $");
37 37
38#include "apm.h" 38#include "apm.h"
39 39
40#if NAPM > 1 40#if NAPM > 1
41#error only one APM emulation device may be configured 41#error only one APM emulation device may be configured
42#endif 42#endif
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/systm.h> 45#include <sys/systm.h>
46#include <sys/kernel.h> 46#include <sys/kernel.h>
47#include <sys/proc.h> 47#include <sys/proc.h>
48#include <sys/device.h> 48#include <sys/device.h>
49#include <sys/fcntl.h> 49#include <sys/fcntl.h>
50#include <sys/ioctl.h> 50#include <sys/ioctl.h>
51#include <sys/mutex.h> 51#include <sys/mutex.h>
52#ifdef __OpenBSD__ 52#ifdef __OpenBSD__
53#include <sys/event.h> 53#include <sys/event.h>
54#endif 54#endif
55#ifdef __NetBSD__ 55#ifdef __NetBSD__
56#include <sys/select.h> 56#include <sys/select.h>
57#include <sys/poll.h> 57#include <sys/poll.h>
58#include <sys/conf.h> 58#include <sys/conf.h>
59#endif 59#endif
60 60
61#ifdef __OpenBSD__ 61#ifdef __OpenBSD__
62#include <machine/conf.h> 62#include <machine/conf.h>
63#endif 63#endif
64#include <machine/cpu.h> 64#include <machine/cpu.h>
65#include <machine/apmvar.h> 65#include <machine/apmvar.h>
66 66
67#include <macppc/dev/adbvar.h> 67#include <macppc/dev/adbvar.h>
68#include <macppc/dev/pm_direct.h> 68#include <macppc/dev/pm_direct.h>
69 69
70#if defined(APMDEBUG) 70#if defined(APMDEBUG)
71#define DPRINTF(x) printf x 71#define DPRINTF(x) printf x
72#else 72#else
73#define DPRINTF(x) /**/ 73#define DPRINTF(x) /**/
74#endif 74#endif
75 75
76#define APM_NEVENTS 16 76#define APM_NEVENTS 16
77 77
78struct apm_softc { 78struct apm_softc {
79 struct selinfo sc_rsel; 79 struct selinfo sc_rsel;
80#ifdef __OpenBSD__ 80#ifdef __OpenBSD__
81 struct klist sc_note; 81 struct klist sc_note;
82#endif 82#endif
83 int sc_flags; 83 int sc_flags;
84 int event_count; 84 int event_count;
85 int event_ptr; 85 int event_ptr;
86 kmutex_t sc_lock; 86 kmutex_t sc_lock;
87 struct apm_event_info event_list[APM_NEVENTS]; 87 struct apm_event_info event_list[APM_NEVENTS];
88}; 88};
89 89
90/* 90/*
91 * A brief note on the locking protocol: it's very simple; we 91 * A brief note on the locking protocol: it's very simple; we
92 * assert an exclusive lock any time thread context enters the 92 * assert an exclusive lock any time thread context enters the
93 * APM module. This is both the APM thread itself, as well as 93 * APM module. This is both the APM thread itself, as well as
94 * user context. 94 * user context.
95 */ 95 */
96#ifdef __NetBSD__ 96#ifdef __NetBSD__
97#define APM_LOCK(apmsc) mutex_enter(&(apmsc)->sc_lock) 97#define APM_LOCK(apmsc) mutex_enter(&(apmsc)->sc_lock)
98#define APM_UNLOCK(apmsc) mutex_exit(&(apmsc)->sc_lock) 98#define APM_UNLOCK(apmsc) mutex_exit(&(apmsc)->sc_lock)
99#else 99#else
100#define APM_LOCK(apmsc) 100#define APM_LOCK(apmsc)
101#define APM_UNLOCK(apmsc) 101#define APM_UNLOCK(apmsc)
102#endif 102#endif
103 103
104int apmmatch(device_t, cfdata_t, void *); 104int apmmatch(device_t, cfdata_t, void *);
105void apmattach(device_t, device_t, void *); 105void apmattach(device_t, device_t, void *);
106 106
107#ifdef __NetBSD__ 107#ifdef __NetBSD__
108#if 0 108#if 0
109static int apm_record_event(struct apm_softc *, u_int); 109static int apm_record_event(struct apm_softc *, u_int);
110#endif 110#endif
111#endif 111#endif
112 112
113CFATTACH_DECL_NEW(apm, sizeof(struct apm_softc), 113CFATTACH_DECL_NEW(apm, sizeof(struct apm_softc),
114 apmmatch, apmattach, NULL, NULL); 114 apmmatch, apmattach, NULL, NULL);
115 115
116#ifdef __OpenBSD__ 116#ifdef __OpenBSD__
117struct cfdriver apm_cd = { 117struct cfdriver apm_cd = {
118 NULL, "apm", DV_DULL 118 NULL, "apm", DV_DULL
119}; 119};
120#else 120#else
121extern struct cfdriver apm_cd; 121extern struct cfdriver apm_cd;
122 122
123dev_type_open(apmopen); 123dev_type_open(apmopen);
124dev_type_close(apmclose); 124dev_type_close(apmclose);
125dev_type_ioctl(apmioctl); 125dev_type_ioctl(apmioctl);
126dev_type_poll(apmpoll); 126dev_type_poll(apmpoll);
127dev_type_kqfilter(apmkqfilter); 127dev_type_kqfilter(apmkqfilter);
128 128
129const struct cdevsw apm_cdevsw = { 129const struct cdevsw apm_cdevsw = {
130 .d_open = apmopen, 130 .d_open = apmopen,
131 .d_close = apmclose, 131 .d_close = apmclose,
132 .d_read = noread, 132 .d_read = noread,
133 .d_write = nowrite, 133 .d_write = nowrite,
134 .d_ioctl = apmioctl, 134 .d_ioctl = apmioctl,
135 .d_stop = nostop, 135 .d_stop = nostop,
136 .d_tty = notty, 136 .d_tty = notty,
137 .d_poll = apmpoll, 137 .d_poll = apmpoll,
138 .d_mmap = nommap, 138 .d_mmap = nommap,
139 .d_kqfilter = apmkqfilter, 139 .d_kqfilter = apmkqfilter,
140 .d_discard = nodiscard, 140 .d_discard = nodiscard,
141 .d_flag = 0 141 .d_flag = 0
142}; 142};
143#endif 143#endif
144 144
145int apm_evindex; 145int apm_evindex;
146 146
147#define APMUNIT(dev) (minor(dev)&0xf0) 147#define APMUNIT(dev) (minor(dev)&0xf0)
148#define APMDEV(dev) (minor(dev)&0x0f) 148#define APMDEV(dev) (minor(dev)&0x0f)
149#define APMDEV_NORMAL 0 149#define APMDEV_NORMAL 0
150#define APMDEV_CTL 8 150#define APMDEV_CTL 8
151 151
152/* 152/*
153 * Flags to control kernel display 153 * Flags to control kernel display
154 * SCFLAG_NOPRINT: do not output APM power messages due to 154 * SCFLAG_NOPRINT: do not output APM power messages due to
155 * a power change event. 155 * a power change event.
156 * 156 *
157 * SCFLAG_PCTPRINT: do not output APM power messages due to 157 * SCFLAG_PCTPRINT: do not output APM power messages due to
158 * to a power change event unless the battery 158 * to a power change event unless the battery
159 * percentage changes. 159 * percentage changes.
160 */ 160 */
161 161
162#define SCFLAG_NOPRINT 0x0008000 162#define SCFLAG_NOPRINT 0x0008000
163#define SCFLAG_PCTPRINT 0x0004000 163#define SCFLAG_PCTPRINT 0x0004000
164#define SCFLAG_PRINT (SCFLAG_NOPRINT|SCFLAG_PCTPRINT) 164#define SCFLAG_PRINT (SCFLAG_NOPRINT|SCFLAG_PCTPRINT)
165 165
166#define SCFLAG_OREAD (1 << 0) 166#define SCFLAG_OREAD (1 << 0)
167#define SCFLAG_OWRITE (1 << 1) 167#define SCFLAG_OWRITE (1 << 1)
168#define SCFLAG_OPEN (SCFLAG_OREAD|SCFLAG_OWRITE) 168#define SCFLAG_OPEN (SCFLAG_OREAD|SCFLAG_OWRITE)
169 169
170 170
171int 171int
172apmmatch(device_t parent, cfdata_t match, void *aux) 172apmmatch(device_t parent, cfdata_t match, void *aux)
173{ 173{
174 struct adb_attach_args *aa = (void *)aux;  174 struct adb_attach_args *aa = (void *)aux;
175 if (aa->origaddr != ADBADDR_APM || 175 if (aa->origaddr != ADBADDR_APM ||
176 aa->handler_id != ADBADDR_APM || 176 aa->handler_id != ADBADDR_APM ||
177 aa->adbaddr != ADBADDR_APM) 177 aa->adbaddr != ADBADDR_APM)
178 return 0; 178 return 0;
179 179
180 if (adbHardware != ADB_HW_PMU) 180 if (adbHardware != ADB_HW_PMU)
181 return 0; 181 return 0;
182 182
183 return 1; 183 return 1;
184} 184}
185 185
186void 186void
187apmattach(device_t parent, device_t self, void *aux) 187apmattach(device_t parent, device_t self, void *aux)
188{ 188{
189 struct apm_softc *sc = device_private(self); 189 struct apm_softc *sc = device_private(self);
190 struct pmu_battery_info info; 190 struct pmu_battery_info info;
191 191
192 pm_battery_info(0, &info); 192 pm_battery_info(0, &info);
193 193
194 printf(": battery flags 0x%X, ", info.flags); 194 printf(": battery flags 0x%X, ", info.flags);
195 printf("%d%% charged\n", ((info.cur_charge * 100) / info.max_charge)); 195 printf("%d%% charged\n", ((info.cur_charge * 100) / info.max_charge));
196 196
197 sc->sc_flags = 0; 197 sc->sc_flags = 0;
198 sc->event_ptr = 0; 198 sc->event_ptr = 0;
199 sc->event_count = 0; 199 sc->event_count = 0;
200 mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE); 200 mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
201 selinit(&sc->sc_rsel); 201 selinit(&sc->sc_rsel);
202} 202}
203 203
204int 204int
205apmopen(dev_t dev, int flag, int mode, struct lwp *l) 205apmopen(dev_t dev, int flag, int mode, struct lwp *l)
206{ 206{
207 struct apm_softc *sc; 207 struct apm_softc *sc;
208 int error = 0; 208 int error = 0;
209 209
210 /* apm0 only */ 210 /* apm0 only */
211 sc = device_lookup_private(&apm_cd, APMUNIT(dev)); 211 sc = device_lookup_private(&apm_cd, APMUNIT(dev));
212 if (sc == NULL) 212 if (sc == NULL)
213 return ENXIO; 213 return ENXIO;
214 214
215 DPRINTF(("apmopen: dev %d pid %d flag %x mode %x\n", 215 DPRINTF(("apmopen: dev %d pid %d flag %x mode %x\n",
216 APMDEV(dev), l->l_proc->p_pid, flag, mode)); 216 APMDEV(dev), l->l_proc->p_pid, flag, mode));
217 217
218 APM_LOCK(sc); 218 APM_LOCK(sc);
219 switch (APMDEV(dev)) { 219 switch (APMDEV(dev)) {
220 case APMDEV_CTL: 220 case APMDEV_CTL:
221 if (!(flag & FWRITE)) { 221 if (!(flag & FWRITE)) {
222 error = EINVAL; 222 error = EINVAL;
223 break; 223 break;
224 } 224 }
225 if (sc->sc_flags & SCFLAG_OWRITE) { 225 if (sc->sc_flags & SCFLAG_OWRITE) {
226 error = EBUSY; 226 error = EBUSY;
227 break; 227 break;
228 } 228 }
229 sc->sc_flags |= SCFLAG_OWRITE; 229 sc->sc_flags |= SCFLAG_OWRITE;
230 break; 230 break;
231 case APMDEV_NORMAL: 231 case APMDEV_NORMAL:
232 if (!(flag & FREAD) || (flag & FWRITE)) { 232 if (!(flag & FREAD) || (flag & FWRITE)) {
233 error = EINVAL; 233 error = EINVAL;
234 break; 234 break;
235 } 235 }
236 sc->sc_flags |= SCFLAG_OREAD; 236 sc->sc_flags |= SCFLAG_OREAD;
237 break; 237 break;
238 default: 238 default:
239 error = ENXIO; 239 error = ENXIO;
240 break; 240 break;
241 } 241 }
242 APM_UNLOCK(sc); 242 APM_UNLOCK(sc);
243 return error; 243 return error;
244} 244}
245 245
246int 246int
247apmclose(dev_t dev, int flag, int mode, struct lwp *l) 247apmclose(dev_t dev, int flag, int mode, struct lwp *l)
248{ 248{
249 struct apm_softc *sc; 249 struct apm_softc *sc;
250 250
251 /* apm0 only */ 251 /* apm0 only */
252 sc = device_lookup_private(&apm_cd, APMUNIT(dev)); 252 sc = device_lookup_private(&apm_cd, APMUNIT(dev));
253 if (sc == NULL) 253 if (sc == NULL)
254 return ENXIO; 254 return ENXIO;
255 255
256 DPRINTF(("apmclose: pid %d flag %x mode %x\n", l->l_proc->p_pid, flag, mode)); 256 DPRINTF(("apmclose: pid %d flag %x mode %x\n", l->l_proc->p_pid, flag, mode));
257 257
258 APM_LOCK(sc); 258 APM_LOCK(sc);
259 switch (APMDEV(dev)) { 259 switch (APMDEV(dev)) {
260 case APMDEV_CTL: 260 case APMDEV_CTL:
261 sc->sc_flags &= ~SCFLAG_OWRITE; 261 sc->sc_flags &= ~SCFLAG_OWRITE;
262 break; 262 break;
263 case APMDEV_NORMAL: 263 case APMDEV_NORMAL:
264 sc->sc_flags &= ~SCFLAG_OREAD; 264 sc->sc_flags &= ~SCFLAG_OREAD;
265 break; 265 break;
266 } 266 }
267 APM_UNLOCK(sc); 267 APM_UNLOCK(sc);
268 return 0; 268 return 0;
269} 269}
270 270
271int 271int
272apmioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) 272apmioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
273{ 273{
274 struct apm_softc *sc; 274 struct apm_softc *sc;
275 struct pmu_battery_info batt; 275 struct pmu_battery_info batt;
276 struct apm_power_info *power; 276 struct apm_power_info *power;
277 int error = 0; 277 int error = 0;
278 278
279 /* apm0 only */ 279 /* apm0 only */
280 sc = device_lookup_private(&apm_cd, APMUNIT(dev)); 280 sc = device_lookup_private(&apm_cd, APMUNIT(dev));
281 if (sc == NULL) 281 if (sc == NULL)
282 return ENXIO; 282 return ENXIO;
283 283
284 APM_LOCK(sc); 284 APM_LOCK(sc);
285 switch (cmd) { 285 switch (cmd) {
286 /* some ioctl names from linux */ 286 /* some ioctl names from linux */
287 case APM_IOC_STANDBY: 287 case APM_IOC_STANDBY:
288 if ((flag & FWRITE) == 0) 288 if ((flag & FWRITE) == 0)
289 error = EBADF; 289 error = EBADF;
290 case APM_IOC_SUSPEND: 290 case APM_IOC_SUSPEND:
291 if ((flag & FWRITE) == 0) 291 if ((flag & FWRITE) == 0)
292 error = EBADF;  292 error = EBADF;
293 break; 293 break;
294 case APM_IOC_PRN_CTL: 294 case APM_IOC_PRN_CTL:
295 if ((flag & FWRITE) == 0) 295 if ((flag & FWRITE) == 0)
296 error = EBADF; 296 error = EBADF;
297 else { 297 else {
298 int op = *(int *)data; 298 int op = *(int *)data;
299 DPRINTF(( "APM_IOC_PRN_CTL: %d\n", op )); 299 DPRINTF(( "APM_IOC_PRN_CTL: %d\n", op ));
300 switch (op) { 300 switch (op) {
301 case APM_PRINT_ON: /* enable printing */ 301 case APM_PRINT_ON: /* enable printing */
302 sc->sc_flags &= ~SCFLAG_PRINT; 302 sc->sc_flags &= ~SCFLAG_PRINT;
303 break; 303 break;
304 case APM_PRINT_OFF: /* disable printing */ 304 case APM_PRINT_OFF: /* disable printing */
305 sc->sc_flags &= ~SCFLAG_PRINT; 305 sc->sc_flags &= ~SCFLAG_PRINT;
306 sc->sc_flags |= SCFLAG_NOPRINT; 306 sc->sc_flags |= SCFLAG_NOPRINT;
307 break; 307 break;
308 case APM_PRINT_PCT: /* disable some printing */ 308 case APM_PRINT_PCT: /* disable some printing */
309 sc->sc_flags &= ~SCFLAG_PRINT; 309 sc->sc_flags &= ~SCFLAG_PRINT;
310 sc->sc_flags |= SCFLAG_PCTPRINT; 310 sc->sc_flags |= SCFLAG_PCTPRINT;
311 break; 311 break;
312 default: 312 default:
313 error = EINVAL; 313 error = EINVAL;
314 break; 314 break;
315 } 315 }
316 } 316 }
317 break; 317 break;
318 case APM_IOC_DEV_CTL: 318 case APM_IOC_DEV_CTL:
319 if ((flag & FWRITE) == 0) 319 if ((flag & FWRITE) == 0)
320 error = EBADF; 320 error = EBADF;
321 break; 321 break;
322 case APM_IOC_GETPOWER: 322 case APM_IOC_GETPOWER:
323 power = (struct apm_power_info *)data; 323 power = (struct apm_power_info *)data;
324 324
325 pm_battery_info(0, &batt); 325 pm_battery_info(0, &batt);
326 326
327 power->ac_state = ((batt.flags & PMU_PWR_AC_PRESENT) ? 327 power->ac_state = ((batt.flags & PMU_PWR_AC_PRESENT) ?
328 APM_AC_ON : APM_AC_OFF); 328 APM_AC_ON : APM_AC_OFF);
329 power->battery_life = 329 power->battery_life =
330 ((batt.cur_charge * 100) / batt.max_charge); 330 ((batt.cur_charge * 100) / batt.max_charge);
331 331
332 /* 332 /*
333 * If the battery is charging, return the minutes left until 333 * If the battery is charging, return the minutes left until
334 * charging is complete. apmd knows this. 334 * charging is complete. apmd knows this.
335 */ 335 */
336 336
337 if (!(batt.flags & PMU_PWR_BATT_PRESENT)) { 337 if (!(batt.flags & PMU_PWR_BATT_PRESENT)) {
338 power->battery_state = APM_BATT_UNKNOWN; 338 power->battery_state = APM_BATT_UNKNOWN;
339 power->minutes_left = 0; 339 power->minutes_left = 0;
340 power->battery_life = 0; 340 power->battery_life = 0;
341 } else if ((power->ac_state == APM_AC_ON) && 341 } else if ((power->ac_state == APM_AC_ON) &&
342 (batt.draw > 0)) { 342 (batt.draw > 0)) {
343 power->minutes_left = batt.secs_remaining / 60; 343 power->minutes_left = batt.secs_remaining / 60;
344 power->battery_state = APM_BATT_CHARGING; 344 power->battery_state = APM_BATT_CHARGING;
345 } else { 345 } else {
346 power->minutes_left = batt.secs_remaining / 60; 346 power->minutes_left = batt.secs_remaining / 60;
347 347
348 /* XXX - Arbitrary */ 348 /* XXX - Arbitrary */
349 if (power->battery_life > 60) { 349 if (power->battery_life > 60) {
350 power->battery_state = APM_BATT_HIGH; 350 power->battery_state = APM_BATT_HIGH;
351 } else if (power->battery_life < 10) { 351 } else if (power->battery_life < 10) {
352 power->battery_state = APM_BATT_CRITICAL; 352 power->battery_state = APM_BATT_CRITICAL;
353 } else { 353 } else {
354 power->battery_state = APM_BATT_LOW; 354 power->battery_state = APM_BATT_LOW;
355 } 355 }
356 } 356 }
357 357
358 break; 358 break;
359  359
360 default: 360 default:
361 error = ENOTTY; 361 error = ENOTTY;
362 } 362 }
363 APM_UNLOCK(sc); 363 APM_UNLOCK(sc);
364 364
365 return error; 365 return error;
366} 366}
367 367
368#ifdef __NetBSD__ 368#ifdef __NetBSD__
369#if 0 369#if 0
370/* 370/*
371 * return 0 if the user will notice and handle the event, 371 * return 0 if the user will notice and handle the event,
372 * return 1 if the kernel driver should do so. 372 * return 1 if the kernel driver should do so.
373 */ 373 */
374static int 374static int
375apm_record_event(struct apm_softc *sc, u_int event_type) 375apm_record_event(struct apm_softc *sc, u_int event_type)
376{ 376{
377 struct apm_event_info *evp; 377 struct apm_event_info *evp;
378 378
379 if ((sc->sc_flags & SCFLAG_OPEN) == 0) 379 if ((sc->sc_flags & SCFLAG_OPEN) == 0)
380 return 1; /* no user waiting */ 380 return 1; /* no user waiting */
381 if (sc->event_count == APM_NEVENTS) { 381 if (sc->event_count == APM_NEVENTS) {
382 DPRINTF(("apm_record_event: queue full!\n")); 382 DPRINTF(("apm_record_event: queue full!\n"));
383 return 1; /* overflow */ 383 return 1; /* overflow */
384 } 384 }
385 evp = &sc->event_list[sc->event_ptr]; 385 evp = &sc->event_list[sc->event_ptr];
386 sc->event_count++; 386 sc->event_count++;
387 sc->event_ptr++; 387 sc->event_ptr++;
388 sc->event_ptr %= APM_NEVENTS; 388 sc->event_ptr %= APM_NEVENTS;
389 evp->type = event_type; 389 evp->type = event_type;
390 evp->index = ++apm_evindex; 390 evp->index = ++apm_evindex;
391 selnotify(&sc->sc_rsel, 0, 0); 391 selnotify(&sc->sc_rsel, 0, 0);
392 return (sc->sc_flags & SCFLAG_OWRITE) ? 0 : 1; /* user may handle */ 392 return (sc->sc_flags & SCFLAG_OWRITE) ? 0 : 1; /* user may handle */
393} 393}
394#endif 394#endif
395 395
396int 396int
397apmpoll(dev_t dev, int events, struct lwp *l) 397apmpoll(dev_t dev, int events, struct lwp *l)
398{ 398{
399 struct apm_softc *sc = device_lookup_private(&apm_cd,APMUNIT(dev)); 399 struct apm_softc *sc = device_lookup_private(&apm_cd,APMUNIT(dev));
400 int revents = 0; 400 int revents = 0;
401 401
402 APM_LOCK(sc); 402 APM_LOCK(sc);
403 if (events & (POLLIN | POLLRDNORM)) { 403 if (events & (POLLIN | POLLRDNORM)) {
404 if (sc->event_count) 404 if (sc->event_count)
405 revents |= events & (POLLIN | POLLRDNORM); 405 revents |= events & (POLLIN | POLLRDNORM);
406 else 406 else
407 selrecord(l, &sc->sc_rsel); 407 selrecord(l, &sc->sc_rsel);
408 } 408 }
409 APM_UNLOCK(sc); 409 APM_UNLOCK(sc);
410 410
411 return (revents); 411 return (revents);
412} 412}
413#endif 413#endif
414 414
415static void 415static void
416filt_apmrdetach(struct knote *kn) 416filt_apmrdetach(struct knote *kn)
417{ 417{
418 struct apm_softc *sc = (struct apm_softc *)kn->kn_hook; 418 struct apm_softc *sc = (struct apm_softc *)kn->kn_hook;
419 419
420 APM_LOCK(sc); 420 APM_LOCK(sc);
421 SLIST_REMOVE(&sc->sc_rsel.sel_klist, kn, knote, kn_selnext); 421 SLIST_REMOVE(&sc->sc_rsel.sel_klist, kn, knote, kn_selnext);
422 APM_UNLOCK(sc); 422 APM_UNLOCK(sc);
423} 423}
424 424
425static int 425static int
426filt_apmread(struct knote *kn, long hint) 426filt_apmread(struct knote *kn, long hint)
427{ 427{
428 struct apm_softc *sc = kn->kn_hook; 428 struct apm_softc *sc = kn->kn_hook;
429 429
430 kn->kn_data = sc->event_count; 430 kn->kn_data = sc->event_count;
431 return (kn->kn_data > 0); 431 return (kn->kn_data > 0);
432} 432}
433 433
434static struct filterops apmread_filtops = 434static struct filterops apmread_filtops = {
435 { 1, NULL, filt_apmrdetach, filt_apmread}; 435 .f_isfd = 1,
 436 .f_attach = NULL,
 437 .f_detach = filt_apmrdetach,
 438 .f_event = filt_apmread,
 439};
436 440
437int 441int
438apmkqfilter(dev_t dev, struct knote *kn) 442apmkqfilter(dev_t dev, struct knote *kn)
439{ 443{
440 struct apm_softc *sc = device_lookup_private(&apm_cd,APMUNIT(dev)); 444 struct apm_softc *sc = device_lookup_private(&apm_cd,APMUNIT(dev));
441 struct klist *klist; 445 struct klist *klist;
442 446
443 switch (kn->kn_filter) { 447 switch (kn->kn_filter) {
444 case EVFILT_READ: 448 case EVFILT_READ:
445 klist = &sc->sc_rsel.sel_klist; 449 klist = &sc->sc_rsel.sel_klist;
446 kn->kn_fop = &apmread_filtops; 450 kn->kn_fop = &apmread_filtops;
447 break; 451 break;
448 default: 452 default:
449 return (1); 453 return (1);
450 } 454 }
451 455
452 kn->kn_hook = sc; 456 kn->kn_hook = sc;
453 457
454 APM_LOCK(sc); 458 APM_LOCK(sc);
455 SLIST_INSERT_HEAD(klist, kn, kn_selnext); 459 SLIST_INSERT_HEAD(klist, kn, kn_selnext);
456 APM_UNLOCK(sc); 460 APM_UNLOCK(sc);
457 461
458 return (0); 462 return (0);
459} 463}

cvs diff -r1.8 -r1.9 src/sys/arch/mips/ralink/ralink_gpio.c (switch to unified diff)

--- src/sys/arch/mips/ralink/ralink_gpio.c 2020/03/10 11:07:39 1.8
+++ src/sys/arch/mips/ralink/ralink_gpio.c 2020/10/30 22:20:38 1.9