View | Details | Raw Unified | Return to bug 216552 | Differences between
and this patch

Collapse All | Expand All

(-)share/man/man4/Makefile (+2 lines)
Lines 9-14 Link Here
9
	aacraid.4 \
9
	aacraid.4 \
10
	acpi.4 \
10
	acpi.4 \
11
	${_acpi_asus.4} \
11
	${_acpi_asus.4} \
12
	${_acpi_asus_als.4} \
12
	${_acpi_asus_wmi.4} \
13
	${_acpi_asus_wmi.4} \
13
	${_acpi_dock.4} \
14
	${_acpi_dock.4} \
14
	${_acpi_fujitsu.4} \
15
	${_acpi_fujitsu.4} \
Lines 757-762 Link Here
757
758
758
.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
759
.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
759
_acpi_asus.4=	acpi_asus.4
760
_acpi_asus.4=	acpi_asus.4
761
_acpi_asus_als.4=	acpi_asus_als.4
760
_acpi_asus_wmi.4=	acpi_asus_wmi.4
762
_acpi_asus_wmi.4=	acpi_asus_wmi.4
761
_acpi_dock.4=	acpi_dock.4
763
_acpi_dock.4=	acpi_dock.4
762
_acpi_fujitsu.4=acpi_fujitsu.4
764
_acpi_fujitsu.4=acpi_fujitsu.4
(-)share/man/man4/acpi_asus_als.4 (+93 lines)
Line 0 Link Here
1
.\"
2
.\" Copyright (c) 2017 Henry Hu <henry.hu.sh@gmail.com>
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$
27
.\"
28
.Dd January 28, 2017
29
.Dt ACPI_ASUS_ALS 4
30
.Os
31
.Sh NAME
32
.Nm acpi_asus_als
33
.Nd Asus Ambient Light Sensor
34
.Sh SYNOPSIS
35
To compile this driver into the kernel,
36
place the following line in your
37
kernel configuration file:
38
.Bd -ragged -offset indent
39
.Cd "device acpi_asus_als"
40
.Ed
41
.Pp
42
Alternatively, to load the driver as a
43
module at boot time, place the following line in
44
.Xr loader.conf 5 :
45
.Bd -literal -offset indent
46
acpi_asus_als_load="YES"
47
.Ed
48
.Sh DESCRIPTION
49
The
50
.Nm
51
driver provides support for the ambient light sensor found on recent Asus
52
laptops.
53
It allows one to use the
54
.Xr sysctl 8
55
interface to get the ambient light value from the sensor.
56
The sensor can be controlled through a WMI call. See
57
.Xr acpi_asus_wmi 4
58
for details.
59
.Sh SYSCTL VARIABLES
60
The following sysctls are currently implemented:
61
.Bl -tag -width indent
62
.It Va hw.acpi.asus_als.light
63
The ambient light value, in 0.01 lux.
64
.Sh SEE ALSO
65
.Xr acpi 4 ,
66
.Xr acpi_asus 4 ,
67
.Xr acpi_asus_wmi 4 ,
68
.Xr sysctl 8
69
.Rs
70
.%T Asus Zenbook Ambient Light Sensor Driver
71
.%U https://github.com/victorenator/als
72
.Re
73
.Sh HISTORY
74
The
75
.Nm
76
driver first appeared in
77
.Fx 12 .
78
.Sh AUTHORS
79
.An -nosplit
80
The
81
.Nm
82
driver and this manual page were written by
83
.An Henry Hu Aq Mt henry.hu.sh@gmail.com .
84
.Pp
85
Inspiration came from the
86
.Em Asus Zenbook Ambient Light Sensor Driver
87
started by
88
.An Viktar Vaŭčkievič
89
which maintains a driver implementing this
90
functionality as a
91
.Tn Linux
92
module.
93
(-)sys/dev/acpi_support/acpi_asus_als.c (+203 lines)
Line 0 Link Here
1
/*-
2
 * Copyright (c) 2017 Henry Hu <henry.hu.sh@gmail.com>
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
27
#include <sys/cdefs.h>
28
__FBSDID("$FreeBSD$");
29
30
/*
31
 * Driver for the ambient light sensor found on recent Asus laptops. Inspired
32
 * by the als project which implements the same functionality for Linux.
33
 *
34
 *   <https://github.com/victorenator/als>
35
 *
36
 * May also work on other laptops.
37
 */
38
39
#include "opt_acpi.h"
40
#include <sys/param.h>
41
#include <sys/kernel.h>
42
#include <sys/module.h>
43
#include <sys/bus.h>
44
45
#include <contrib/dev/acpica/include/acpi.h>
46
#include <contrib/dev/acpica/include/accommon.h>
47
48
#include <dev/acpica/acpivar.h>
49
50
#define _COMPONENT	ACPI_OEM
51
ACPI_MODULE_NAME("ASUS-ALS")
52
53
struct acpi_asus_als_softc {
54
	device_t		dev;
55
	ACPI_HANDLE		handle;
56
57
	struct sysctl_ctx_list	sysctl_ctx;
58
	struct sysctl_oid	*sysctl_tree;
59
};
60
61
ACPI_SERIAL_DECL(asus_als, "ACPI ASUS ambient light");
62
63
static int	acpi_asus_als_probe(device_t dev);
64
static int	acpi_asus_als_attach(device_t dev);
65
static int	acpi_asus_als_detach(device_t dev);
66
67
static int	acpi_asus_als_sysctl(SYSCTL_HANDLER_ARGS);
68
static int	acpi_asus_als_sysctl_get(struct acpi_asus_als_softc *sc);
69
70
static device_method_t acpi_asus_als_methods[] = {
71
	DEVMETHOD(device_probe,  acpi_asus_als_probe),
72
	DEVMETHOD(device_attach, acpi_asus_als_attach),
73
	DEVMETHOD(device_detach, acpi_asus_als_detach),
74
75
	{ 0, 0 }
76
};
77
78
static driver_t acpi_asus_als_driver = {
79
	"acpi_asus_als",
80
	acpi_asus_als_methods,
81
	sizeof(struct acpi_asus_als_softc)
82
};
83
84
static devclass_t acpi_asus_als_devclass;
85
86
DRIVER_MODULE(acpi_asus_als, acpi, acpi_asus_als_driver,
87
	acpi_asus_als_devclass, 0, 0);
88
MODULE_DEPEND(acpi_asus_als, acpi, 1, 1, 1);
89
90
static int
91
acpi_asus_als_probe(device_t dev)
92
{
93
	static char		*asus_ids[] = { "ACPI0008", NULL };
94
95
	struct acpi_asus_als_softc	*sc;
96
	char				*rstr;
97
98
	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
99
100
	if (acpi_disabled("asus_als"))
101
		return (ENXIO);
102
103
	/* Check if ambient light sensor is present. */
104
	rstr = ACPI_ID_PROBE(device_get_parent(dev), dev, asus_ids);
105
	if (rstr == NULL) {
106
		return (ENXIO);
107
	}
108
109
	sc = device_get_softc(dev);
110
	sc->dev = dev;
111
	sc->handle = acpi_get_handle(dev);
112
113
	device_set_desc_copy(dev, "ASUS ambient light sensor");
114
115
	return 0;
116
}
117
118
static int
119
acpi_asus_als_attach(device_t dev)
120
{
121
	struct acpi_asus_als_softc	*sc;
122
	struct acpi_softc		*acpi_sc;
123
124
	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
125
126
	sc = device_get_softc(dev);
127
	acpi_sc = acpi_device_get_parent_softc(dev);
128
129
	sysctl_ctx_init(&sc->sysctl_ctx);
130
	sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
131
		SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
132
		OID_AUTO, "asus_als", CTLFLAG_RD, 0, "");
133
134
	SYSCTL_ADD_PROC(&sc->sysctl_ctx,
135
		SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
136
		"light", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_ANYBODY,
137
		sc, 0, acpi_asus_als_sysctl, "I", "Ambient light value");
138
139
	return (0);
140
}
141
142
static int
143
acpi_asus_als_detach(device_t dev)
144
{
145
	struct acpi_asus_als_softc	*sc;
146
147
	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
148
149
	sc = device_get_softc(dev);
150
151
	sysctl_ctx_free(&sc->sysctl_ctx);
152
153
	return (0);
154
}
155
156
static int
157
acpi_asus_als_sysctl(SYSCTL_HANDLER_ARGS)
158
{
159
	struct acpi_asus_als_softc	*sc;
160
	int				value;
161
	int				error = 0;
162
163
	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
164
165
	sc = (struct acpi_asus_als_softc *)oidp->oid_arg1;
166
167
	ACPI_SERIAL_BEGIN(asus_als);
168
169
	value = acpi_asus_als_sysctl_get(sc);
170
	error = sysctl_handle_int(oidp, &value, 0, req);
171
172
	ACPI_SERIAL_END(asus_als);
173
174
	return (error);
175
}
176
177
static int
178
acpi_asus_als_sysctl_get(struct acpi_asus_als_softc *sc)
179
{
180
	ACPI_BUFFER Buf;
181
	ACPI_OBJECT *Obj;
182
	int         value = 0;
183
184
	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
185
	ACPI_SERIAL_ASSERT(asus_als);
186
187
	Buf.Pointer = NULL;
188
	Buf.Length = ACPI_ALLOCATE_BUFFER;
189
190
	/* Calls _ALI to get the value. */
191
	AcpiEvaluateObject(sc->handle, "_ALI", NULL, &Buf);
192
	Obj = Buf.Pointer;
193
194
	if (Obj->Type != ACPI_TYPE_INTEGER) {
195
		device_printf(sc->dev, "_ALI returned non-integer\n");
196
	} else {
197
		value = Obj->Integer.Value;
198
	}
199
200
	AcpiOsFree(Buf.Pointer);
201
202
	return (value);
203
}
(-)sys/modules/acpi/Makefile (-1 / +1 lines)
Lines 2-7 Link Here
2
2
3
SUBDIR=		acpi_asus acpi_asus_wmi acpi_dock acpi_fujitsu acpi_hp	\
3
SUBDIR=		acpi_asus acpi_asus_wmi acpi_dock acpi_fujitsu acpi_hp	\
4
		acpi_ibm acpi_panasonic acpi_sony acpi_toshiba		\
4
		acpi_ibm acpi_panasonic acpi_sony acpi_toshiba		\
5
		acpi_video acpi_wmi aibs
5
		acpi_video acpi_wmi aibs acpi_asus_als
6
6
7
.include <bsd.subdir.mk>
7
.include <bsd.subdir.mk>
(-)sys/modules/acpi/acpi_asus_als/Makefile (+8 lines)
Line 0 Link Here
1
# $FreeBSD$
2
3
.PATH:	${.CURDIR}/../../../dev/acpi_support
4
5
KMOD=	acpi_asus_als
6
SRCS=	acpi_asus_als.c opt_acpi.h acpi_if.h device_if.h bus_if.h
7
8
.include <bsd.kmod.mk>

Return to bug 216552