xref: /freebsd/sys/dev/acpi_support/acpi_sony.c (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*-
2  * Copyright (c) 2004 Takanori Watanabe
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
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.
13  *
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  */
26 
27 #include <sys/cdefs.h>
28 #include "opt_acpi.h"
29 #include <sys/param.h>
30 #include <sys/kernel.h>
31 #include <sys/bus.h>
32 
33 #include <contrib/dev/acpica/include/acpi.h>
34 
35 #include "acpi_if.h"
36 #include <sys/module.h>
37 #include <dev/acpica/acpivar.h>
38 #include <sys/sysctl.h>
39 
40 #define _COMPONENT	ACPI_OEM
41 ACPI_MODULE_NAME("Sony")
42 
43 #define ACPI_SONY_GET_PID "GPID"
44 
45 /*
46  * SNY5001
47  *   This is the ACPI handle for the "Sony Notebook Control" driver under
48  *   Windows.
49  *   It provides several methods within the ACPI namespace, including:
50  *  [GS]BRT [GS]PBR [GS]CTR [GS]PCR [GS]CMI [CDPW GCDP]? GWDP PWAK PWRN
51  *
52  * SNY6001
53  *   This is the ACPI handle for the "Sony Programmable I/O" driver under
54  *   Windows.
55  *   It is not yet supported by this driver, but provides control over the
56  *   power to the bluetooth, built-in camera and HSDPA modem devices in some
57  *   laptops, and also allows some control of the fan speed.
58  */
59 
60 struct acpi_sony_softc {
61 	int pid;
62 };
63 static struct acpi_sony_name_list
64 {
65 	char *nodename;
66 	char *getmethod;
67 	char *setmethod;
68 	char *comment;
69 } acpi_sony_oids[] = {
70 	{ "brightness", "GBRT", "SBRT", "Display Brightness"},
71 	{ "brightness_default", "GPBR", "SPBR", "Default Display Brightness"},
72 	{ "contrast", "GCTR", "SCTR", "Display Contrast"},
73 	{ "bass_gain", "GMGB", "SMGB", "Multimedia Bass Gain"},
74 	{ "pcr", "GPCR", "SPCR", "???"},
75 #if 0
76 	{ "cmi", "GCMI", "SCMI", "???"},
77 #endif
78 	{ "wdp", "GWDP", NULL, "???"},
79 	{ "cdp", "GCDP", "CDPW", "CD Power"},  /*shares [\GL03]&0x8 flag*/
80 	{ "azp", "GAZP", "AZPW", "Audio Power"},
81 	{ "lnp", "GLNP", "LNPW", "LAN Power"},
82 	{ NULL, NULL, NULL }
83 };
84 
85 static int	acpi_sony_probe(device_t dev);
86 static int	acpi_sony_attach(device_t dev);
87 static int 	acpi_sony_detach(device_t dev);
88 static int	sysctl_acpi_sony_gen_handler(SYSCTL_HANDLER_ARGS);
89 
90 static device_method_t acpi_sony_methods[] = {
91 	/* Device interface */
92 	DEVMETHOD(device_probe, acpi_sony_probe),
93 	DEVMETHOD(device_attach, acpi_sony_attach),
94 	DEVMETHOD(device_detach, acpi_sony_detach),
95 
96 	DEVMETHOD_END
97 };
98 
99 static driver_t	acpi_sony_driver = {
100 	"acpi_sony",
101 	acpi_sony_methods,
102 	sizeof(struct acpi_sony_softc),
103 };
104 
105 DRIVER_MODULE(acpi_sony, acpi, acpi_sony_driver, 0, 0);
106 MODULE_DEPEND(acpi_sony, acpi, 1, 1, 1);
107 static char    *sny_id[] = {"SNY5001", NULL};
108 
109 static int
110 acpi_sony_probe(device_t dev)
111 {
112 	int ret;
113 
114 	ret = ACPI_ID_PROBE(device_get_parent(dev), dev, sny_id, NULL);
115 	if (ret <= 0) {
116 		device_set_desc(dev, "Sony notebook controller");
117 	}
118 	return (ret);
119 }
120 
121 static int
122 acpi_sony_attach(device_t dev)
123 {
124 	struct acpi_sony_softc *sc;
125 	int i;
126 
127 	sc = device_get_softc(dev);
128 	acpi_GetInteger(acpi_get_handle(dev), ACPI_SONY_GET_PID, &sc->pid);
129 	device_printf(dev, "PID %x\n", sc->pid);
130 	for (i = 0 ; acpi_sony_oids[i].nodename != NULL; i++) {
131 		if (acpi_sony_oids[i].setmethod != NULL) {
132 			SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
133 			    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
134 			    i, acpi_sony_oids[i].nodename ,
135 			    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
136 			    dev, i, sysctl_acpi_sony_gen_handler, "I",
137 			    acpi_sony_oids[i].comment);
138 		} else {
139 			SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
140 			    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
141 			    i, acpi_sony_oids[i].nodename ,
142 			    CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
143 			    dev, i, sysctl_acpi_sony_gen_handler, "I",
144 			    acpi_sony_oids[i].comment);
145 		}
146 	}
147 	return (0);
148 }
149 
150 static int
151 acpi_sony_detach(device_t dev)
152 {
153 	return (0);
154 }
155 
156 #if 0
157 static int
158 acpi_sony_suspend(device_t dev)
159 {
160 	struct acpi_sony_softc *sc = device_get_softc(dev);
161 	return (0);
162 }
163 
164 static int
165 acpi_sony_resume(device_t dev)
166 {
167 	return (0);
168 }
169 #endif
170 
171 static int
172 sysctl_acpi_sony_gen_handler(SYSCTL_HANDLER_ARGS)
173 {
174 	device_t	dev = arg1;
175 	int 	function = oidp->oid_arg2;
176 	int		error = 0, val;
177 
178 	acpi_GetInteger(acpi_get_handle(dev),
179 	    acpi_sony_oids[function].getmethod, &val);
180 	error = sysctl_handle_int(oidp, &val, 0, req);
181 	if (error || !req->newptr || !acpi_sony_oids[function].setmethod)
182 		return (error);
183 	acpi_SetInteger(acpi_get_handle(dev),
184 	    acpi_sony_oids[function].setmethod, val);
185 	return (0);
186 }
187