acpi_sony.c revision 193530
1137593Simp/*-
2137593Simp * Copyright (c) 2004 Takanori Watanabe
3137593Simp * All rights reserved.
4137593Simp *
5137593Simp * Redistribution and use in source and binary forms, with or without
6137593Simp * modification, are permitted provided that the following conditions
7137593Simp * are met:
8137593Simp * 1. Redistributions of source code must retain the above copyright
9137593Simp *    notice, this list of conditions and the following disclaimer.
10137593Simp * 2. Redistributions in binary form must reproduce the above copyright
11137593Simp *    notice, this list of conditions and the following disclaimer in the
12137593Simp *    documentation and/or other materials provided with the distribution.
13137593Simp *
14137593Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15137593Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16137593Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17137593Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18137593Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19137593Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20137593Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21137593Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22137593Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23137593Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24137593Simp * SUCH DAMAGE.
25137593Simp */
26137593Simp
27143002Sobrien#include <sys/cdefs.h>
28143002Sobrien__FBSDID("$FreeBSD: head/sys/dev/acpi_support/acpi_sony.c 193530 2009-06-05 18:44:36Z jkim $");
29143002Sobrien
30137593Simp#include "opt_acpi.h"
31137593Simp#include <sys/param.h>
32137593Simp#include <sys/kernel.h>
33137593Simp#include <sys/bus.h>
34193530Sjkim
35193530Sjkim#include <contrib/dev/acpica/include/acpi.h>
36193530Sjkim
37137593Simp#include "acpi_if.h"
38137593Simp#include <sys/module.h>
39137593Simp#include <dev/acpica/acpivar.h>
40137593Simp#include <sys/sysctl.h>
41138825Snjl
42138825Snjl#define _COMPONENT	ACPI_OEM
43138825SnjlACPI_MODULE_NAME("Sony")
44138825Snjl
45138197Simp#define ACPI_SONY_GET_BRIGHTNESS "GBRT"
46138197Simp#define ACPI_SONY_SET_BRIGHTNESS "SBRT"
47138197Simp#define ACPI_SONY_GET_PID "GPID"
48138825Snjl
49137593Simp/*
50137593Simp * SNY5001
51137593Simp *  [GS]BRT [GS]PBR [GS]CTR [GS]PCR [GS]CMI [CDPW GCDP]? GWDP PWAK PWRN
52137593Simp *
53137593Simp */
54137593Simp
55138197Simpstruct acpi_sony_softc {
56137714Simp	int pid;
57137593Simp};
58138197Simpstatic struct acpi_sony_name_list
59137593Simp{
60137714Simp	char *nodename;
61137714Simp	char *getmethod;
62137714Simp	char *setmethod;
63137714Simp	char *comment;
64138197Simp} acpi_sony_oids[] = {
65137714Simp	{ "brightness", "GBRT", "SBRT", "Display Brightness"},
66137714Simp	{ "ctr", "GCTR", "SCTR", "??"},
67137714Simp	{ "pcr", "GPCR", "SPCR", "???"},
68137593Simp#if 0
69137714Simp	{ "cmi", "GCMI", "SCMI", "????"},
70137593Simp#endif
71137714Simp	{ "wdp", "GWDP", NULL, "?????"},
72163856Skevlo	{ "cdp", "GCDP", "CDPW", "CD Power"},  /*shares [\GL03]&0x8 flag*/
73179137Skevlo	{ "azp", "GAZP", "AZPW", "Audio Power"},
74163856Skevlo	{ NULL, NULL, NULL }
75137593Simp};
76137593Simp
77138197Simpstatic int	acpi_sony_probe(device_t dev);
78138197Simpstatic int	acpi_sony_attach(device_t dev);
79138197Simpstatic int 	acpi_sony_detach(device_t dev);
80138197Simpstatic int	sysctl_acpi_sony_gen_handler(SYSCTL_HANDLER_ARGS);
81137593Simp
82138197Simpstatic device_method_t acpi_sony_methods[] = {
83137593Simp	/* Device interface */
84138197Simp	DEVMETHOD(device_probe, acpi_sony_probe),
85138197Simp	DEVMETHOD(device_attach, acpi_sony_attach),
86138197Simp	DEVMETHOD(device_detach, acpi_sony_detach),
87137593Simp
88137593Simp	{0, 0}
89137593Simp};
90137593Simp
91138197Simpstatic driver_t	acpi_sony_driver = {
92138197Simp	"acpi_sony",
93138197Simp	acpi_sony_methods,
94138197Simp	sizeof(struct acpi_sony_softc),
95137593Simp};
96137593Simp
97138197Simpstatic devclass_t acpi_sony_devclass;
98137593Simp
99138197SimpDRIVER_MODULE(acpi_sony, acpi, acpi_sony_driver, acpi_sony_devclass,
100137593Simp	      0, 0);
101138197SimpMODULE_DEPEND(acpi_sony, acpi, 1, 1, 1);
102137593Simpstatic char    *sny_id[] = {"SNY5001", NULL};
103137593Simp
104137593Simpstatic int
105138197Simpacpi_sony_probe(device_t dev)
106137593Simp{
107192030Sbrueffer	int ret = ENXIO;
108137593Simp
109137593Simp	if (ACPI_ID_PROBE(device_get_parent(dev), dev, sny_id)) {
110137593Simp		device_set_desc(dev, "Sony notebook controller");
111137593Simp		ret = 0;
112137593Simp	}
113137593Simp	return (ret);
114137593Simp}
115137593Simp
116137593Simpstatic int
117138197Simpacpi_sony_attach(device_t dev)
118137593Simp{
119138197Simp	struct acpi_sony_softc *sc;
120137593Simp	int i;
121137593Simp
122137593Simp	sc = device_get_softc(dev);
123138197Simp	acpi_GetInteger(acpi_get_handle(dev), ACPI_SONY_GET_PID, &sc->pid);
124137593Simp	device_printf(dev, "PID %x\n", sc->pid);
125138197Simp	for (i = 0 ; acpi_sony_oids[i].nodename != NULL; i++){
126137593Simp		SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
127137681Simp		    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
128138197Simp		    i, acpi_sony_oids[i].nodename , CTLTYPE_INT |
129138197Simp		    ((acpi_sony_oids[i].setmethod)? CTLFLAG_RW: CTLFLAG_RD),
130138197Simp		    dev, i, sysctl_acpi_sony_gen_handler, "I",
131138197Simp		    acpi_sony_oids[i].comment);
132137593Simp	}
133137714Simp	return (0);
134137593Simp}
135137593Simp
136137593Simpstatic int
137138197Simpacpi_sony_detach(device_t dev)
138137593Simp{
139137745Simp	return (0);
140137593Simp}
141137714Simp
142137593Simp#if 0
143137593Simpstatic int
144138197Simpacpi_sony_suspend(device_t dev)
145137593Simp{
146138197Simp	struct acpi_sony_softc *sc = device_get_softc(dev);
147137714Simp	return (0);
148137593Simp}
149137593Simp
150137593Simpstatic int
151138197Simpacpi_sony_resume(device_t dev)
152137593Simp{
153137593Simp	return (0);
154137593Simp}
155137593Simp#endif
156137593Simp
157137593Simpstatic int
158138197Simpsysctl_acpi_sony_gen_handler(SYSCTL_HANDLER_ARGS)
159137593Simp{
160137593Simp	device_t	dev = arg1;
161137593Simp	int 	function = oidp->oid_arg2;
162137593Simp	int		error = 0, val;
163137593Simp
164137714Simp	acpi_GetInteger(acpi_get_handle(dev),
165138197Simp	    acpi_sony_oids[function].getmethod, &val);
166137593Simp	error = sysctl_handle_int(oidp, &val, 0, req);
167138197Simp	if (error || !req->newptr || !acpi_sony_oids[function].setmethod)
168137714Simp		return (error);
169137714Simp	acpi_SetInteger(acpi_get_handle(dev),
170138197Simp	    acpi_sony_oids[function].setmethod, val);
171137714Simp	return (0);
172137593Simp}
173