Remove inclusion of <sys/cdefs.h> from kernel .c files.
[dragonfly.git] / sys / dev / acpica5 / acpi_sony / acpi_sony.c
CommitLineData
b4f6cb38
AP
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.
32af04f7 25 *
b4f6cb38
AP
26 * $FreeBSD: src/sys/dev/acpi_support/acpi_sony.c,v 1.13 2009/06/05 18:44:36 jkim
27 */
28
b4f6cb38
AP
29#include "opt_acpi.h"
30#include <sys/param.h>
31#include <sys/kernel.h>
32#include <sys/bus.h>
33
34#include "acpi.h"
35
36#include "acpi_if.h"
37#include <sys/module.h>
38#include <dev/acpica5/acpivar.h>
39#include <sys/sysctl.h>
40
41#define _COMPONENT ACPI_OEM
42ACPI_MODULE_NAME("Sony")
43
44#define ACPI_SONY_GET_BRIGHTNESS "GBRT"
45#define ACPI_SONY_SET_BRIGHTNESS "SBRT"
46#define ACPI_SONY_GET_PID "GPID"
47
48/*
49 * SNY5001
50 * [GS]BRT [GS]PBR [GS]CTR [GS]PCR [GS]CMI [CDPW GCDP]? GWDP PWAK PWRN
51 *
52 */
53
54struct acpi_sony_softc {
55 int pid;
56 struct sysctl_ctx_list sysctl_ctx;
57 struct sysctl_oid *sysctl_tree;
58};
59static struct acpi_sony_name_list
60{
61 char *nodename;
62 char *getmethod;
63 char *setmethod;
64 char *comment;
65} acpi_sony_oids[] = {
66 { "brightness", "GBRT", "SBRT", "Display Brightness"},
67 { "ctr", "GCTR", "SCTR", "??"},
68 { "pcr", "GPCR", "SPCR", "???"},
69#if 0
70 { "cmi", "GCMI", "SCMI", "????"},
71#endif
72 { "wdp", "GWDP", NULL, "?????"},
73 { "cdp", "GCDP", "CDPW", "CD Power"}, /*shares [\GL03]&0x8 flag*/
74 { "azp", "GAZP", "AZPW", "Audio Power"},
75 { NULL, NULL, NULL }
76};
77
78static int acpi_sony_probe(device_t dev);
79static int acpi_sony_attach(device_t dev);
80static int acpi_sony_detach(device_t dev);
81static int sysctl_acpi_sony_gen_handler(SYSCTL_HANDLER_ARGS);
82
83static device_method_t acpi_sony_methods[] = {
84 /* Device interface */
85 DEVMETHOD(device_probe, acpi_sony_probe),
86 DEVMETHOD(device_attach, acpi_sony_attach),
87 DEVMETHOD(device_detach, acpi_sony_detach),
88
89 {0, 0}
90};
91
92static driver_t acpi_sony_driver = {
93 "acpi_sony",
94 acpi_sony_methods,
95 sizeof(struct acpi_sony_softc),
96};
97
98static devclass_t acpi_sony_devclass;
99
100DRIVER_MODULE(acpi_sony, acpi, acpi_sony_driver, acpi_sony_devclass,
101 0, 0);
102MODULE_DEPEND(acpi_sony, acpi, 1, 1, 1);
103static char *sny_id[] = {"SNY5001", NULL};
104
105static int
106acpi_sony_probe(device_t dev)
107{
108 int ret = ENXIO;
109
110 if (ACPI_ID_PROBE(device_get_parent(dev), dev, sny_id)) {
111 device_set_desc(dev, "Sony notebook controller");
112 ret = 0;
113 }
114 return (ret);
115}
116
117static int
118acpi_sony_attach(device_t dev)
119{
120 struct acpi_sony_softc *sc;
121 struct acpi_softc *acpi_sc;
122 int i;
123
124 sc = device_get_softc(dev);
125 acpi_sc = acpi_device_get_parent_softc(dev);
126 acpi_GetInteger(acpi_get_handle(dev), ACPI_SONY_GET_PID, &sc->pid);
127 device_printf(dev, "PID %x\n", sc->pid);
128 sysctl_ctx_init(&sc->sysctl_ctx);
129 sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
130 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree), OID_AUTO,
131 "sony", CTLFLAG_RD, 0, "");
132 for (i = 0 ; acpi_sony_oids[i].nodename != NULL; i++){
133 SYSCTL_ADD_PROC(&sc->sysctl_ctx,
134 SYSCTL_CHILDREN(sc->sysctl_tree),
135 i, acpi_sony_oids[i].nodename , CTLTYPE_INT |
136 ((acpi_sony_oids[i].setmethod)? CTLFLAG_RW: CTLFLAG_RD),
137 dev, i, sysctl_acpi_sony_gen_handler, "I",
138 acpi_sony_oids[i].comment);
139 }
140 return (0);
141}
142
143static int
144acpi_sony_detach(device_t dev)
145{
146 return (0);
147}
148
149#if 0
150static int
151acpi_sony_suspend(device_t dev)
152{
153 struct acpi_sony_softc *sc = device_get_softc(dev);
154 return (0);
155}
156
157static int
158acpi_sony_resume(device_t dev)
159{
160 return (0);
161}
162#endif
163
164static int
165sysctl_acpi_sony_gen_handler(SYSCTL_HANDLER_ARGS)
166{
167 device_t dev = arg1;
168 int function = oidp->oid_arg2;
169 int error = 0, val;
170
171 acpi_GetInteger(acpi_get_handle(dev),
172 acpi_sony_oids[function].getmethod, &val);
173 error = sysctl_handle_int(oidp, &val, 0, req);
174 if (error || !req->newptr || !acpi_sony_oids[function].setmethod)
175 return (error);
176 acpi_SetInteger(acpi_get_handle(dev),
177 acpi_sony_oids[function].setmethod, val);
178 return (0);
179}