Deleted Added
full compact
acpi_toshiba.c (128036) acpi_toshiba.c (128207)
1/*-
2 * Copyright (c) 2003 Hiroyuki Aizu <aizu@navi.org>
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

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

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
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2003 Hiroyuki Aizu <aizu@navi.org>
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

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

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
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/dev/acpi_support/acpi_toshiba.c 128036 2004-04-08 16:45:12Z njl $");
29__FBSDID("$FreeBSD: head/sys/dev/acpi_support/acpi_toshiba.c 128207 2004-04-14 00:23:58Z njl $");
30
31#include "opt_acpi.h"
32#include <sys/param.h>
33#include <sys/kernel.h>
34#include <sys/bus.h>
35
36#include "acpi.h"
37#include <dev/acpica/acpivar.h>

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

44 * dedicated ACPI methods instead of using this primitive interface.
45 * However, the ACPI methods seem to be incomplete in some areas (for
46 * example they allow setting, but not reading, the LCD brightness
47 * value), so this is still useful.
48 */
49
50#define METHOD_HCI "GHCI"
51#define METHOD_HCI_ENABLE "ENAB"
30
31#include "opt_acpi.h"
32#include <sys/param.h>
33#include <sys/kernel.h>
34#include <sys/bus.h>
35
36#include "acpi.h"
37#include <dev/acpica/acpivar.h>

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

44 * dedicated ACPI methods instead of using this primitive interface.
45 * However, the ACPI methods seem to be incomplete in some areas (for
46 * example they allow setting, but not reading, the LCD brightness
47 * value), so this is still useful.
48 */
49
50#define METHOD_HCI "GHCI"
51#define METHOD_HCI_ENABLE "ENAB"
52#define METHOD_VIDEO "DSSX"
52
53/* Operations */
54#define HCI_SET 0xFF00
55#define HCI_GET 0xFE00
56
57/* Return codes */
58#define HCI_SUCCESS 0x0000
59#define HCI_FAILURE 0x1000

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

115#define HCI_REG_CX 2 /* Argument (in or out) */
116#define HCI_REG_DX 3 /* Unused? */
117#define HCI_REG_SI 4 /* Unused? */
118#define HCI_REG_DI 5 /* Unused? */
119
120struct acpi_toshiba_softc {
121 device_t dev;
122 ACPI_HANDLE handle;
53
54/* Operations */
55#define HCI_SET 0xFF00
56#define HCI_GET 0xFE00
57
58/* Return codes */
59#define HCI_SUCCESS 0x0000
60#define HCI_FAILURE 0x1000

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

116#define HCI_REG_CX 2 /* Argument (in or out) */
117#define HCI_REG_DX 3 /* Unused? */
118#define HCI_REG_SI 4 /* Unused? */
119#define HCI_REG_DI 5 /* Unused? */
120
121struct acpi_toshiba_softc {
122 device_t dev;
123 ACPI_HANDLE handle;
124 ACPI_HANDLE video_handle;
123 struct sysctl_ctx_list sysctl_ctx;
124 struct sysctl_oid *sysctl_tree;
125};
126
127/* Prototype for HCI functions for getting/setting a value. */
128typedef int hci_fn_t(ACPI_HANDLE, int, UINT32 *);
129
130static int acpi_toshiba_probe(device_t dev);
131static int acpi_toshiba_attach(device_t dev);
132static int acpi_toshiba_detach(device_t dev);
133static int acpi_toshiba_sysctl(SYSCTL_HANDLER_ARGS);
134static hci_fn_t hci_force_fan;
135static hci_fn_t hci_video_output;
136static hci_fn_t hci_lcd_brightness;
137static hci_fn_t hci_lcd_backlight;
138static hci_fn_t hci_cpu_speed;
139static int hci_call(ACPI_HANDLE h, int op, int function, UINT32 *arg);
125 struct sysctl_ctx_list sysctl_ctx;
126 struct sysctl_oid *sysctl_tree;
127};
128
129/* Prototype for HCI functions for getting/setting a value. */
130typedef int hci_fn_t(ACPI_HANDLE, int, UINT32 *);
131
132static int acpi_toshiba_probe(device_t dev);
133static int acpi_toshiba_attach(device_t dev);
134static int acpi_toshiba_detach(device_t dev);
135static int acpi_toshiba_sysctl(SYSCTL_HANDLER_ARGS);
136static hci_fn_t hci_force_fan;
137static hci_fn_t hci_video_output;
138static hci_fn_t hci_lcd_brightness;
139static hci_fn_t hci_lcd_backlight;
140static hci_fn_t hci_cpu_speed;
141static int hci_call(ACPI_HANDLE h, int op, int function, UINT32 *arg);
140static void hci_key_action(ACPI_HANDLE h, UINT32 key);
142static void hci_key_action(struct acpi_toshiba_softc *sc, ACPI_HANDLE h,
143 UINT32 key);
141static void acpi_toshiba_notify(ACPI_HANDLE h, UINT32 notify,
144static void acpi_toshiba_notify(ACPI_HANDLE h, UINT32 notify,
142 void *context);
145 void *context);
146static int acpi_toshiba_video_probe(device_t dev);
147static int acpi_toshiba_video_attach(device_t dev);
143
144/* Table of sysctl names and HCI functions to call. */
145static struct {
146 char *name;
147 hci_fn_t *handler;
148} sysctl_table[] = {
149 /* name, handler */
150 {"force_fan", hci_force_fan},

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

166static driver_t acpi_toshiba_driver = {
167 "acpi_toshiba",
168 acpi_toshiba_methods,
169 sizeof(struct acpi_toshiba_softc),
170};
171
172static devclass_t acpi_toshiba_devclass;
173DRIVER_MODULE(acpi_toshiba, acpi, acpi_toshiba_driver, acpi_toshiba_devclass,
148
149/* Table of sysctl names and HCI functions to call. */
150static struct {
151 char *name;
152 hci_fn_t *handler;
153} sysctl_table[] = {
154 /* name, handler */
155 {"force_fan", hci_force_fan},

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

171static driver_t acpi_toshiba_driver = {
172 "acpi_toshiba",
173 acpi_toshiba_methods,
174 sizeof(struct acpi_toshiba_softc),
175};
176
177static devclass_t acpi_toshiba_devclass;
178DRIVER_MODULE(acpi_toshiba, acpi, acpi_toshiba_driver, acpi_toshiba_devclass,
174 0, 0);
179 0, 0);
175MODULE_DEPEND(acpi_toshiba, acpi, 1, 1, 1);
176
180MODULE_DEPEND(acpi_toshiba, acpi, 1, 1, 1);
181
182static device_method_t acpi_toshiba_video_methods[] = {
183 DEVMETHOD(device_probe, acpi_toshiba_video_probe),
184 DEVMETHOD(device_attach, acpi_toshiba_video_attach),
185
186 {0, 0}
187};
188
189static driver_t acpi_toshiba_video_driver = {
190 "acpi_toshiba_video",
191 acpi_toshiba_video_methods,
192 0,
193};
194
195static devclass_t acpi_toshiba_video_devclass;
196DRIVER_MODULE(acpi_toshiba_video, acpi, acpi_toshiba_video_driver,
197 acpi_toshiba_video_devclass, 0, 0);
198MODULE_DEPEND(acpi_toshiba_video, acpi, 1, 1, 1);
199
177static int enable_fn_keys = 1;
178TUNABLE_INT("hw.acpi.toshiba.enable_fn_keys", &enable_fn_keys);
179
180/*
181 * HID Model
182 * -------------------------------------
183 * TOS6200 Libretto L Series
184 * Dynabook Satellite 2455

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

301 *state >>= HCI_FAN_SHIFT;
302 return (ret);
303}
304
305static int
306hci_video_output(ACPI_HANDLE h, int op, UINT32 *video_output)
307{
308 int ret;
200static int enable_fn_keys = 1;
201TUNABLE_INT("hw.acpi.toshiba.enable_fn_keys", &enable_fn_keys);
202
203/*
204 * HID Model
205 * -------------------------------------
206 * TOS6200 Libretto L Series
207 * Dynabook Satellite 2455

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

324 *state >>= HCI_FAN_SHIFT;
325 return (ret);
326}
327
328static int
329hci_video_output(ACPI_HANDLE h, int op, UINT32 *video_output)
330{
331 int ret;
332 ACPI_STATUS status;
309
310 if (op == HCI_SET) {
311 if (*video_output < 1 || *video_output > 7)
312 return (EINVAL);
333
334 if (op == HCI_SET) {
335 if (*video_output < 1 || *video_output > 7)
336 return (EINVAL);
337 if (h == NULL)
338 return (ENXIO);
313 *video_output |= HCI_VIDEO_OUTPUT_FLAG;
339 *video_output |= HCI_VIDEO_OUTPUT_FLAG;
340 status = acpi_SetInteger(h, "DSSX", *video_output);
341 if (ACPI_SUCCESS(status))
342 ret = 0;
343 else
344 ret = ENXIO;
345 } else {
346 ret = hci_call(h, op, HCI_REG_VIDEO_OUTPUT, video_output);
347 if (ret == 0)
348 *video_output &= 0xff;
314 }
349 }
315 ret = hci_call(h, op, HCI_REG_VIDEO_OUTPUT, video_output);
316 if (ret == 0 && op == HCI_GET)
317 *video_output &= 0xff;
350
318 return (ret);
319}
320
321static int
322hci_lcd_brightness(ACPI_HANDLE h, int op, UINT32 *brightness)
323{
324 int ret;
325

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

414 return (status);
415}
416
417/*
418 * Perform a few actions based on the keypress. Users can extend this
419 * functionality by reading the keystrokes we send to devd(8).
420 */
421static void
351 return (ret);
352}
353
354static int
355hci_lcd_brightness(ACPI_HANDLE h, int op, UINT32 *brightness)
356{
357 int ret;
358

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

447 return (status);
448}
449
450/*
451 * Perform a few actions based on the keypress. Users can extend this
452 * functionality by reading the keystrokes we send to devd(8).
453 */
454static void
422hci_key_action(ACPI_HANDLE h, UINT32 key)
455hci_key_action(struct acpi_toshiba_softc *sc, ACPI_HANDLE h, UINT32 key)
423{
424 UINT32 arg;
425
426 switch (key) {
427 case FN_F6_RELEASE:
428 /* Decrease LCD brightness. */
429 hci_lcd_brightness(h, HCI_GET, &arg);
430 if (arg-- == 0)

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

439 arg = 7;
440 else
441 hci_lcd_brightness(h, HCI_SET, &arg);
442 break;
443 case FN_F5_RELEASE:
444 /* Cycle through video outputs. */
445 hci_video_output(h, HCI_GET, &arg);
446 arg = (arg + 1) % 7;
456{
457 UINT32 arg;
458
459 switch (key) {
460 case FN_F6_RELEASE:
461 /* Decrease LCD brightness. */
462 hci_lcd_brightness(h, HCI_GET, &arg);
463 if (arg-- == 0)

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

472 arg = 7;
473 else
474 hci_lcd_brightness(h, HCI_SET, &arg);
475 break;
476 case FN_F5_RELEASE:
477 /* Cycle through video outputs. */
478 hci_video_output(h, HCI_GET, &arg);
479 arg = (arg + 1) % 7;
447 hci_video_output(h, HCI_SET, &arg);
480 hci_video_output(sc->video_handle, HCI_SET, &arg);
448 break;
449 case FN_F8_RELEASE:
450 /* Toggle LCD backlight. */
451 hci_lcd_backlight(h, HCI_GET, &arg);
452 arg = (arg != 0) ? 0 : 1;
453 hci_lcd_backlight(h, HCI_SET, &arg);
454 break;
455 case FN_ESC_RELEASE:

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

466{
467 struct acpi_toshiba_softc *sc;
468 UINT32 key;
469
470 sc = (struct acpi_toshiba_softc *)context;
471
472 if (notify == 0x80) {
473 while (hci_call(h, HCI_GET, HCI_REG_SYSTEM_EVENT, &key) == 0) {
481 break;
482 case FN_F8_RELEASE:
483 /* Toggle LCD backlight. */
484 hci_lcd_backlight(h, HCI_GET, &arg);
485 arg = (arg != 0) ? 0 : 1;
486 hci_lcd_backlight(h, HCI_SET, &arg);
487 break;
488 case FN_ESC_RELEASE:

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

499{
500 struct acpi_toshiba_softc *sc;
501 UINT32 key;
502
503 sc = (struct acpi_toshiba_softc *)context;
504
505 if (notify == 0x80) {
506 while (hci_call(h, HCI_GET, HCI_REG_SYSTEM_EVENT, &key) == 0) {
474 hci_key_action(h, key);
507 hci_key_action(sc, h, key);
475 acpi_UserNotify("TOSHIBA", h, (uint8_t)key);
476 }
508 acpi_UserNotify("TOSHIBA", h, (uint8_t)key);
509 }
477 } else {
510 } else
478 device_printf(sc->dev, "unknown notify: 0x%x\n", notify);
511 device_printf(sc->dev, "unknown notify: 0x%x\n", notify);
512}
513
514/*
515 * Toshiba video pseudo-device to provide the DSSX method.
516 *
517 * HID Model
518 * -------------------------------------
519 * TOS6201 Libretto L Series
520 */
521static int
522acpi_toshiba_video_probe(device_t dev)
523{
524 int ret = ENXIO;
525
526 if (!acpi_disabled("toshiba") &&
527 acpi_get_type(dev) == ACPI_TYPE_DEVICE &&
528 device_get_unit(dev) == 0 &&
529 acpi_MatchHid(dev, "TOS6201")) {
530 device_quiet(dev);
531 device_set_desc(dev, "Toshiba Video");
532 ret = 0;
479 }
533 }
534
535 return (ret);
480}
536}
537
538static int
539acpi_toshiba_video_attach(device_t dev)
540{
541 struct acpi_toshiba_softc *sc;
542
543 sc = devclass_get_softc(acpi_toshiba_devclass, 0);
544 if (sc == NULL)
545 return (ENXIO);
546 sc->video_handle = acpi_get_handle(dev);
547 return (0);
548}