Add acpi_{fujitsu, hp, panasonic, sony} modules.
[dragonfly.git] / sys / dev / acpica5 / acpi_sony / acpi_sony.c
blob5b13c8e7dfdc91e79259d7894014f9bb9f957c96
1 /*-
2 * Copyright (c) 2004 Takanori Watanabe
3 * All rights reserved.
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
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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 * $FreeBSD: src/sys/dev/acpi_support/acpi_sony.c,v 1.13 2009/06/05 18:44:36 jkim
28 #include <sys/cdefs.h>
30 #include "opt_acpi.h"
31 #include <sys/param.h>
32 #include <sys/kernel.h>
33 #include <sys/bus.h>
35 #include "acpi.h"
37 #include "acpi_if.h"
38 #include <sys/module.h>
39 #include <dev/acpica5/acpivar.h>
40 #include <sys/sysctl.h>
42 #define _COMPONENT ACPI_OEM
43 ACPI_MODULE_NAME("Sony")
45 #define ACPI_SONY_GET_BRIGHTNESS "GBRT"
46 #define ACPI_SONY_SET_BRIGHTNESS "SBRT"
47 #define ACPI_SONY_GET_PID "GPID"
50 * SNY5001
51 * [GS]BRT [GS]PBR [GS]CTR [GS]PCR [GS]CMI [CDPW GCDP]? GWDP PWAK PWRN
55 struct acpi_sony_softc {
56 int pid;
57 struct sysctl_ctx_list sysctl_ctx;
58 struct sysctl_oid *sysctl_tree;
60 static struct acpi_sony_name_list
62 char *nodename;
63 char *getmethod;
64 char *setmethod;
65 char *comment;
66 } acpi_sony_oids[] = {
67 { "brightness", "GBRT", "SBRT", "Display Brightness"},
68 { "ctr", "GCTR", "SCTR", "??"},
69 { "pcr", "GPCR", "SPCR", "???"},
70 #if 0
71 { "cmi", "GCMI", "SCMI", "????"},
72 #endif
73 { "wdp", "GWDP", NULL, "?????"},
74 { "cdp", "GCDP", "CDPW", "CD Power"}, /*shares [\GL03]&0x8 flag*/
75 { "azp", "GAZP", "AZPW", "Audio Power"},
76 { NULL, NULL, NULL }
79 static int acpi_sony_probe(device_t dev);
80 static int acpi_sony_attach(device_t dev);
81 static int acpi_sony_detach(device_t dev);
82 static int sysctl_acpi_sony_gen_handler(SYSCTL_HANDLER_ARGS);
84 static device_method_t acpi_sony_methods[] = {
85 /* Device interface */
86 DEVMETHOD(device_probe, acpi_sony_probe),
87 DEVMETHOD(device_attach, acpi_sony_attach),
88 DEVMETHOD(device_detach, acpi_sony_detach),
90 {0, 0}
93 static driver_t acpi_sony_driver = {
94 "acpi_sony",
95 acpi_sony_methods,
96 sizeof(struct acpi_sony_softc),
99 static devclass_t acpi_sony_devclass;
101 DRIVER_MODULE(acpi_sony, acpi, acpi_sony_driver, acpi_sony_devclass,
102 0, 0);
103 MODULE_DEPEND(acpi_sony, acpi, 1, 1, 1);
104 static char *sny_id[] = {"SNY5001", NULL};
106 static int
107 acpi_sony_probe(device_t dev)
109 int ret = ENXIO;
111 if (ACPI_ID_PROBE(device_get_parent(dev), dev, sny_id)) {
112 device_set_desc(dev, "Sony notebook controller");
113 ret = 0;
115 return (ret);
118 static int
119 acpi_sony_attach(device_t dev)
121 struct acpi_sony_softc *sc;
122 struct acpi_softc *acpi_sc;
123 int i;
125 sc = device_get_softc(dev);
126 acpi_sc = acpi_device_get_parent_softc(dev);
127 acpi_GetInteger(acpi_get_handle(dev), ACPI_SONY_GET_PID, &sc->pid);
128 device_printf(dev, "PID %x\n", sc->pid);
129 sysctl_ctx_init(&sc->sysctl_ctx);
130 sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
131 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree), OID_AUTO,
132 "sony", CTLFLAG_RD, 0, "");
133 for (i = 0 ; acpi_sony_oids[i].nodename != NULL; i++){
134 SYSCTL_ADD_PROC(&sc->sysctl_ctx,
135 SYSCTL_CHILDREN(sc->sysctl_tree),
136 i, acpi_sony_oids[i].nodename , CTLTYPE_INT |
137 ((acpi_sony_oids[i].setmethod)? CTLFLAG_RW: CTLFLAG_RD),
138 dev, i, sysctl_acpi_sony_gen_handler, "I",
139 acpi_sony_oids[i].comment);
141 return (0);
144 static int
145 acpi_sony_detach(device_t dev)
147 return (0);
150 #if 0
151 static int
152 acpi_sony_suspend(device_t dev)
154 struct acpi_sony_softc *sc = device_get_softc(dev);
155 return (0);
158 static int
159 acpi_sony_resume(device_t dev)
161 return (0);
163 #endif
165 static int
166 sysctl_acpi_sony_gen_handler(SYSCTL_HANDLER_ARGS)
168 device_t dev = arg1;
169 int function = oidp->oid_arg2;
170 int error = 0, val;
172 acpi_GetInteger(acpi_get_handle(dev),
173 acpi_sony_oids[function].getmethod, &val);
174 error = sysctl_handle_int(oidp, &val, 0, req);
175 if (error || !req->newptr || !acpi_sony_oids[function].setmethod)
176 return (error);
177 acpi_SetInteger(acpi_get_handle(dev),
178 acpi_sony_oids[function].setmethod, val);
179 return (0);