summaryrefslogtreecommitdiff
path: root/sys/dev/acpi/acpiasus.c
blob: c378da4e264a969998d7e61e87a782bfa1beab61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/* $OpenBSD: acpiasus.c,v 1.17 2014/02/21 18:49:06 deraadt Exp $ */
/* $NetBSD: asus_acpi.c,v 1.2.2.2 2008/04/03 12:42:37 mjf Exp $ */
/*
 * Copyright (c) 2007, 2008 Jared D. McNeill <jmcneill@invisible.ca>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * ASUS ACPI hotkeys driver.
 */

#include <sys/param.h>
#include <sys/device.h>
#include <sys/systm.h>

#include <dev/acpi/acpireg.h>
#include <dev/acpi/acpivar.h>
#include <dev/acpi/acpidev.h>
#include <dev/acpi/amltypes.h>
#include <dev/acpi/dsdt.h>

#include "audio.h"
#include "wskbd.h"

struct acpiasus_softc {
	struct device		sc_dev;

	struct acpi_softc	*sc_acpi;
	struct aml_node		*sc_devnode;
};

#define ASUS_NOTIFY_WIRELESSON		0x10
#define ASUS_NOTIFY_WIRELESSOFF		0x11
#define ASUS_NOTIFY_TASKSWITCH		0x12
#define ASUS_NOTIFY_VOLUMEMUTE		0x13
#define ASUS_NOTIFY_VOLUMEDOWN		0x14
#define ASUS_NOTIFY_VOLUMEUP		0x15
#define ASUS_NOTIFY_LCDSWITCHOFF0	0x16
#define ASUS_NOTIFY_LCDSWITCHOFF1	0x1a
#define ASUS_NOTIFY_LCDCHANGERES	0x1b
#define ASUS_NOTIFY_USERDEF0		0x1c
#define ASUS_NOTIFY_USERDEF1		0x1d
#define ASUS_NOTIFY_BRIGHTNESSLOW	0x20
#define ASUS_NOTIFY_BRIGHTNESSHIGH	0x2f
#define ASUS_NOTIFY_DISPLAYCYCLEDOWN	0x30
#define ASUS_NOTIFY_DISPLAYCYCLEUP	0x32

#define ASUS_NOTIFY_POWERCONNECT	0x50
#define ASUS_NOTIFY_POWERDISCONNECT	0x51

#define	ASUS_SDSP_LCD			0x01
#define	ASUS_SDSP_CRT			0x02
#define	ASUS_SDSP_TV			0x04
#define	ASUS_SDSP_DVI			0x08
#define	ASUS_SDSP_ALL \
	(ASUS_SDSP_LCD | ASUS_SDSP_CRT | ASUS_SDSP_TV | ASUS_SDSP_DVI)

int	acpiasus_match(struct device *, void *, void *);
void	acpiasus_attach(struct device *, struct device *, void *);
void	acpiasus_init(struct device *);
int	acpiasus_notify(struct aml_node *, int, void *);
int	acpiasus_activate(struct device *, int);

#if NAUDIO > 0 && NWSKBD > 0
extern int wskbd_set_mixervolume(long, long);
#endif

struct cfattach acpiasus_ca = {
	sizeof(struct acpiasus_softc), acpiasus_match, acpiasus_attach,
	NULL, acpiasus_activate
};

struct cfdriver acpiasus_cd = {
	NULL, "acpiasus", DV_DULL
};

const char *acpiasus_hids[] = { ACPI_DEV_ASUS, 0 };

int
acpiasus_match(struct device *parent, void *match, void *aux)
{
	struct acpi_attach_args *aa = aux;
	struct cfdata *cf = match;

	return (acpi_matchhids(aa, acpiasus_hids, cf->cf_driver->cd_name));
}

void
acpiasus_attach(struct device *parent, struct device *self, void *aux)
{
	struct acpiasus_softc *sc = (struct acpiasus_softc *)self;
	struct acpi_attach_args *aa = aux;

	sc->sc_acpi = (struct acpi_softc *)parent;
	sc->sc_devnode = aa->aaa_node;

	printf("\n");

	acpiasus_init(self);

	aml_register_notify(sc->sc_devnode, aa->aaa_dev,
	    acpiasus_notify, sc, ACPIDEV_NOPOLL);
}

void
acpiasus_init(struct device *self)
{
	struct acpiasus_softc *sc = (struct acpiasus_softc *)self;
	struct aml_value cmd;
	struct aml_value ret;

	bzero(&cmd, sizeof(cmd));
	cmd.type = AML_OBJTYPE_INTEGER;
	cmd.v_integer = 0x40;		/* Disable ASL display switching. */

	if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "INIT", 1, &cmd, &ret))
		printf("%s: no INIT\n", DEVNAME(sc));
	else
		aml_freevalue(&ret);
}

int
acpiasus_notify(struct aml_node *node, int notify, void *arg)
{
	struct acpiasus_softc *sc = arg;

	if (notify >= ASUS_NOTIFY_BRIGHTNESSLOW &&
	    notify <= ASUS_NOTIFY_BRIGHTNESSHIGH) {
#ifdef ACPIASUS_DEBUG
		printf("%s: brightness %d percent\n", DEVNAME(sc),
		    (notify & 0xf) * 100 / 0xf);
#endif
		return 0;
	}

	switch (notify) {
	case ASUS_NOTIFY_WIRELESSON:	/* Handled by AML. */
	case ASUS_NOTIFY_WIRELESSOFF:	/* Handled by AML. */
		break;
	case ASUS_NOTIFY_TASKSWITCH:
		break;
	case ASUS_NOTIFY_DISPLAYCYCLEDOWN:
	case ASUS_NOTIFY_DISPLAYCYCLEUP:
		break;
#if NAUDIO > 0 && NWSKBD > 0
	case ASUS_NOTIFY_VOLUMEMUTE:
		wskbd_set_mixervolume(0, 1);
		break;
	case ASUS_NOTIFY_VOLUMEDOWN:
		wskbd_set_mixervolume(-1, 1);
		break;
	case ASUS_NOTIFY_VOLUMEUP:
		wskbd_set_mixervolume(1, 1);
		break;
#else
	case ASUS_NOTIFY_VOLUMEMUTE:
	case ASUS_NOTIFY_VOLUMEDOWN:
	case ASUS_NOTIFY_VOLUMEUP:
		break;
#endif
	case ASUS_NOTIFY_POWERCONNECT:
	case ASUS_NOTIFY_POWERDISCONNECT:
		break;

	case ASUS_NOTIFY_LCDSWITCHOFF0:
	case ASUS_NOTIFY_LCDSWITCHOFF1:
		break;

	case ASUS_NOTIFY_LCDCHANGERES:
		break;

	case ASUS_NOTIFY_USERDEF0:
	case ASUS_NOTIFY_USERDEF1:
		break;

	default:
		printf("%s: unknown event 0x%02x\n", DEVNAME(sc), notify);
		break;
	}

	return 0;
}

int
acpiasus_activate(struct device *self, int act)
{
	struct acpiasus_softc *sc = (struct acpiasus_softc *)self;
	struct aml_value cmd;
	struct aml_value ret;

	switch (act) {
	case DVACT_WAKEUP:
		acpiasus_init(self);

		bzero(&cmd, sizeof(cmd));
		cmd.type = AML_OBJTYPE_INTEGER;
		cmd.v_integer = ASUS_SDSP_LCD;

		if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "SDSP", 1,
		    &cmd, &ret))
			printf("%s: no SDSP\n", DEVNAME(sc));
		else
			aml_freevalue(&ret);
		break;
	}
	return (0);
}