Deleted Added
full compact
acpi_smbat.c (155869) acpi_smbat.c (186026)
1/*-
2 * Copyright (c) 2005 Hans Petter Selasky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2005 Hans Petter Selasky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/acpica/acpi_smbat.c 155869 2006-02-21 03:16:58Z njl $");
28__FBSDID("$FreeBSD: head/sys/dev/acpica/acpi_smbat.c 186026 2008-12-13 06:04:34Z silby $");
29
30#include "opt_acpi.h"
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/module.h>
34#include <sys/bus.h>
35
36#include <contrib/dev/acpica/acpi.h>

--- 19 unchanged lines hidden (view full) ---

56static int acpi_smbat_shutdown(device_t dev);
57static int acpi_smbat_info_expired(struct timespec *lastupdated);
58static void acpi_smbat_info_updated(struct timespec *lastupdated);
59static int acpi_smbat_get_bif(device_t dev, struct acpi_bif *bif);
60static int acpi_smbat_get_bst(device_t dev, struct acpi_bst *bst);
61
62ACPI_SERIAL_DECL(smbat, "ACPI Smart Battery");
63
29
30#include "opt_acpi.h"
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/module.h>
34#include <sys/bus.h>
35
36#include <contrib/dev/acpica/acpi.h>

--- 19 unchanged lines hidden (view full) ---

56static int acpi_smbat_shutdown(device_t dev);
57static int acpi_smbat_info_expired(struct timespec *lastupdated);
58static void acpi_smbat_info_updated(struct timespec *lastupdated);
59static int acpi_smbat_get_bif(device_t dev, struct acpi_bif *bif);
60static int acpi_smbat_get_bst(device_t dev, struct acpi_bst *bst);
61
62ACPI_SERIAL_DECL(smbat, "ACPI Smart Battery");
63
64SYSCTL_DECL(_debug_acpi);
65SYSCTL_NODE(_debug_acpi, OID_AUTO, batt, CTLFLAG_RD, NULL, "Battery debugging");
66
67/* On some laptops with smart batteries, enabling battery monitoring
68 * software causes keystrokes from atkbd to be lost. This has also been
69 * reported on Linux, and is apparently due to the keyboard and I2C line
70 * for the battery being routed through the same chip. Whether that's
71 * accurate or not, adding extra sleeps to the status checking code
72 * causes the problem to go away.
73 *
74 * If you experience that problem, try a value of 10ms and move up
75 * from there.
76 */
77static int batt_sleep_ms;
78SYSCTL_INT(_debug_acpi_batt, OID_AUTO, batt_sleep_ms, CTLFLAG_RW, &batt_sleep_ms, 0,
79 "Sleep during battery status updates to prevent keystroke loss.");
80
64static device_method_t acpi_smbat_methods[] = {
65 /* device interface */
66 DEVMETHOD(device_probe, acpi_smbat_probe),
67 DEVMETHOD(device_attach, acpi_smbat_attach),
68 DEVMETHOD(device_shutdown, acpi_smbat_shutdown),
69
70 /* ACPI battery interface */
71 DEVMETHOD(acpi_batt_get_status, acpi_smbat_get_bst),

--- 99 unchanged lines hidden (view full) ---

171acpi_smbus_read_2(struct acpi_smbat_softc *sc, uint8_t addr, uint8_t cmd,
172 uint16_t *ptr)
173{
174 int error, to;
175 ACPI_INTEGER val;
176
177 ACPI_SERIAL_ASSERT(smbat);
178
81static device_method_t acpi_smbat_methods[] = {
82 /* device interface */
83 DEVMETHOD(device_probe, acpi_smbat_probe),
84 DEVMETHOD(device_attach, acpi_smbat_attach),
85 DEVMETHOD(device_shutdown, acpi_smbat_shutdown),
86
87 /* ACPI battery interface */
88 DEVMETHOD(acpi_batt_get_status, acpi_smbat_get_bst),

--- 99 unchanged lines hidden (view full) ---

188acpi_smbus_read_2(struct acpi_smbat_softc *sc, uint8_t addr, uint8_t cmd,
189 uint16_t *ptr)
190{
191 int error, to;
192 ACPI_INTEGER val;
193
194 ACPI_SERIAL_ASSERT(smbat);
195
196 if (batt_sleep_ms)
197 AcpiOsSleep(batt_sleep_ms);
198
179 val = addr;
180 error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_ADDR,
181 val, 1);
182 if (error)
183 goto out;
184
185 val = cmd;
186 error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_CMD,
187 val, 1);
188 if (error)
189 goto out;
190
191 val = 0x09; /* | 0x80 if PEC */
192 error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_PRTCL,
193 val, 1);
194 if (error)
195 goto out;
196
199 val = addr;
200 error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_ADDR,
201 val, 1);
202 if (error)
203 goto out;
204
205 val = cmd;
206 error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_CMD,
207 val, 1);
208 if (error)
209 goto out;
210
211 val = 0x09; /* | 0x80 if PEC */
212 error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_PRTCL,
213 val, 1);
214 if (error)
215 goto out;
216
217 if (batt_sleep_ms)
218 AcpiOsSleep(batt_sleep_ms);
219
197 for (to = SMBUS_TIMEOUT; to != 0; to--) {
198 error = ACPI_EC_READ(sc->ec_dev, sc->sb_base_addr + SMBUS_PRTCL,
199 &val, 1);
200 if (error)
201 goto out;
202 if (val == 0)
203 break;
204 AcpiOsSleep(10);

--- 29 unchanged lines hidden (view full) ---

234 uint8_t *ptr, uint16_t len)
235{
236 ACPI_INTEGER val;
237 uint8_t to;
238 int error;
239
240 ACPI_SERIAL_ASSERT(smbat);
241
220 for (to = SMBUS_TIMEOUT; to != 0; to--) {
221 error = ACPI_EC_READ(sc->ec_dev, sc->sb_base_addr + SMBUS_PRTCL,
222 &val, 1);
223 if (error)
224 goto out;
225 if (val == 0)
226 break;
227 AcpiOsSleep(10);

--- 29 unchanged lines hidden (view full) ---

257 uint8_t *ptr, uint16_t len)
258{
259 ACPI_INTEGER val;
260 uint8_t to;
261 int error;
262
263 ACPI_SERIAL_ASSERT(smbat);
264
265 if (batt_sleep_ms)
266 AcpiOsSleep(batt_sleep_ms);
267
242 val = addr;
243 error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_ADDR,
244 val, 1);
245 if (error)
246 goto out;
247
248 val = cmd;
249 error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_CMD,
250 val, 1);
251 if (error)
252 goto out;
253
254 val = 0x0B /* | 0x80 if PEC */ ;
255 error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_PRTCL,
256 val, 1);
257 if (error)
258 goto out;
259
268 val = addr;
269 error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_ADDR,
270 val, 1);
271 if (error)
272 goto out;
273
274 val = cmd;
275 error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_CMD,
276 val, 1);
277 if (error)
278 goto out;
279
280 val = 0x0B /* | 0x80 if PEC */ ;
281 error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_PRTCL,
282 val, 1);
283 if (error)
284 goto out;
285
286 if (batt_sleep_ms)
287 AcpiOsSleep(batt_sleep_ms);
288
260 for (to = SMBUS_TIMEOUT; to != 0; to--) {
261 error = ACPI_EC_READ(sc->ec_dev, sc->sb_base_addr + SMBUS_PRTCL,
262 &val, 1);
263 if (error)
264 goto out;
265 if (val == 0)
266 break;
267 AcpiOsSleep(10);

--- 19 unchanged lines hidden (view full) ---

287 if (error)
288 goto out;
289 val = (val & 0x1f) + 1;
290
291 bzero(ptr, len);
292 if (len > val)
293 len = val;
294
289 for (to = SMBUS_TIMEOUT; to != 0; to--) {
290 error = ACPI_EC_READ(sc->ec_dev, sc->sb_base_addr + SMBUS_PRTCL,
291 &val, 1);
292 if (error)
293 goto out;
294 if (val == 0)
295 break;
296 AcpiOsSleep(10);

--- 19 unchanged lines hidden (view full) ---

316 if (error)
317 goto out;
318 val = (val & 0x1f) + 1;
319
320 bzero(ptr, len);
321 if (len > val)
322 len = val;
323
324 if (batt_sleep_ms)
325 AcpiOsSleep(batt_sleep_ms);
326
295 while (len--) {
296 error = ACPI_EC_READ(sc->ec_dev, sc->sb_base_addr + SMBUS_DATA
297 + len, &val, 1);
298 if (error)
299 goto out;
300
301 ptr[len] = val;
327 while (len--) {
328 error = ACPI_EC_READ(sc->ec_dev, sc->sb_base_addr + SMBUS_DATA
329 + len, &val, 1);
330 if (error)
331 goto out;
332
333 ptr[len] = val;
334 if (batt_sleep_ms)
335 AcpiOsSleep(1);
302 }
303
304out:
305 return (error);
306}
307
308static int
309acpi_smbat_get_bst(device_t dev, struct acpi_bst *bst)

--- 148 unchanged lines hidden ---
336 }
337
338out:
339 return (error);
340}
341
342static int
343acpi_smbat_get_bst(device_t dev, struct acpi_bst *bst)

--- 148 unchanged lines hidden ---