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