acpi_sony.c revision 137715
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 *	$FreeBSD: head/sys/dev/acpi_support/acpi_sony.c 137714 2004-11-15 05:12:17Z imp $
27 */
28
29#include "opt_acpi.h"
30#include <sys/param.h>
31#include <sys/kernel.h>
32#include <sys/bus.h>
33#include "acpi.h"
34#include "acpi_if.h"
35#include <sys/module.h>
36#include <dev/acpica/acpivar.h>
37#include <sys/sysctl.h>
38#define ACPI_SNC_GET_BRIGHTNESS "GBRT"
39#define ACPI_SNC_SET_BRIGHTNESS "SBRT"
40#define ACPI_SNC_GET_PID "GPID"
41/*
42 * SNY5001
43 *  [GS]BRT [GS]PBR [GS]CTR [GS]PCR [GS]CMI [CDPW GCDP]? GWDP PWAK PWRN
44 *
45 */
46
47struct acpi_snc_softc {
48	int pid;
49};
50static struct acpi_snc_name_list
51{
52	char *nodename;
53	char *getmethod;
54	char *setmethod;
55	char *comment;
56} acpi_snc_oids[] = {
57	{ "brightness", "GBRT", "SBRT", "Display Brightness"},
58	{ "ctr", "GCTR", "SCTR", "??"},
59	{ "pcr", "GPCR", "SPCR", "???"},
60#if 0
61	{ "cmi", "GCMI", "SCMI", "????"},
62#endif
63	{ "wdp", "GWDP", NULL, "?????"},
64	{ "cdp", "GCDP", "CDPW", "??????"},  /*shares [\GL03]&0x8 flag*/
65	{NULL, NULL,NULL}
66};
67
68static int	acpi_snc_probe(device_t dev);
69static int	acpi_snc_attach(device_t dev);
70static int 	acpi_snc_detach(device_t dev);
71static int	sysctl_acpi_snc_gen_handler(SYSCTL_HANDLER_ARGS);
72
73static device_method_t acpi_snc_methods[] = {
74	/* Device interface */
75	DEVMETHOD(device_probe, acpi_snc_probe),
76	DEVMETHOD(device_attach, acpi_snc_attach),
77	DEVMETHOD(device_detach, acpi_snc_detach),
78
79	{0, 0}
80};
81
82static driver_t	acpi_snc_driver = {
83	"acpi_snc",
84	acpi_snc_methods,
85	sizeof(struct acpi_snc_softc),
86};
87
88static devclass_t acpi_snc_devclass;
89
90DRIVER_MODULE(acpi_snc, acpi, acpi_snc_driver, acpi_snc_devclass,
91	      0, 0);
92MODULE_DEPEND(acpi_snc, acpi, 1, 1, 1);
93static char    *sny_id[] = {"SNY5001", NULL};
94
95static int
96acpi_snc_probe(device_t dev)
97{
98	struct acpi_snc_softc *sc;
99	int		ret = ENXIO;
100
101	sc = device_get_softc(dev);
102
103	if (ACPI_ID_PROBE(device_get_parent(dev), dev, sny_id)) {
104		device_set_desc(dev, "Sony notebook controller");
105		ret = 0;
106	}
107	return (ret);
108}
109
110static int
111acpi_snc_attach(device_t dev)
112{
113	struct acpi_snc_softc *sc;
114	int i;
115
116	sc = device_get_softc(dev);
117	acpi_GetInteger(acpi_get_handle(dev), ACPI_SNC_GET_PID, &sc->pid);
118	device_printf(dev, "PID %x\n", sc->pid);
119	for (i = 0 ; acpi_snc_oids[i].nodename != NULL; i++){
120		SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
121		    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
122		    i, acpi_snc_oids[i].nodename , CTLTYPE_INT |
123		    ((acpi_snc_oids[i].setmethod)? CTLFLAG_RW: CTLFLAG_RD),
124		    dev, i, sysctl_acpi_snc_gen_handler, "I",
125		    acpi_snc_oids[i].comment);
126	}
127	return (0);
128}
129
130static int
131acpi_snc_detach(device_t dev)
132{
133	return_VALUE(0);
134}
135
136#if 0
137static int
138acpi_snc_suspend(device_t dev)
139{
140	struct acpi_snc_softc *sc = device_get_softc(dev);
141	return (0);
142}
143
144static int
145acpi_snc_resume(device_t dev)
146{
147	return (0);
148}
149#endif
150
151static int
152sysctl_acpi_snc_gen_handler(SYSCTL_HANDLER_ARGS)
153{
154	device_t	dev = arg1;
155	int 	function = oidp->oid_arg2;
156	int		error = 0, val;
157
158	acpi_GetInteger(acpi_get_handle(dev),
159	    acpi_snc_oids[function].getmethod, &val);
160	error = sysctl_handle_int(oidp, &val, 0, req);
161	if (error || !req->newptr || !acpi_snc_oids[function].setmethod)
162		return (error);
163	acpi_SetInteger(acpi_get_handle(dev),
164	    acpi_snc_oids[function].setmethod, val);
165	return (0);
166}
167