Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
feca56f
Documentation
arch
block
crypto
drivers
accessibility
acpi
amba
android
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cdrom
char
clk
clocksource
connector
cpufreq
cpuidle
crypto
dca
devfreq
dio
dma-buf
dma
edac
eisa
extcon
firewire
firmware
fmc
gpio
gpu
hid
hsi
hv
hwmon
hwspinlock
hwtracing
i2c
ide
idle
iio
accel
adc
amplifiers
common
dac
frequency
gyro
humidity
imu
light
Kconfig
Makefile
acpi-als.c
adjd_s311.c
al3320a.c
apds9300.c
bh1750.c
cm32181.c
cm3232.c
cm3323.c
cm36651.c
gp2ap020a00f.c
hid-sensor-als.c
hid-sensor-prox.c
isl29125.c
jsa1212.c
lm3533-als.c
ltr501.c
stk3310.c
tcs3414.c
tcs3472.c
tsl2563.c
tsl4531.c
vcnl4000.c
magnetometer
orientation
pressure
proximity
temperature
trigger
Kconfig
Makefile
buffer_cb.c
iio_core.h
iio_core_trigger.h
industrialio-buffer.c
industrialio-core.c
industrialio-event.c
industrialio-trigger.c
industrialio-triggered-buffer.c
inkern.c
kfifo_buf.c
infiniband
input
iommu
ipack
irqchip
isdn
leds
lguest
macintosh
mailbox
mcb
md
media
memory
memstick
message
mfd
misc
mmc
mtd
net
nfc
ntb
nubus
of
oprofile
parisc
parport
pci
pcmcia
phy
pinctrl
platform
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
s390
sbus
scsi
sfi
sh
sn
soc
spi
spmi
ssb
staging
target
tc
thermal
thunderbolt
tty
uio
usb
uwb
vfio
vhost
video
virt
virtio
vlynq
vme
w1
watchdog
xen
zorro
Kconfig
Makefile
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
REPORTING-BUGS
Breadcrumbs
linux
/
drivers
/
iio
/
light
/
acpi-als.c
Copy path
Blame
Blame
Latest commit
Gabriele Mazzotta
and
Jonathan Cameron
iio: acpi: Add support for ACPI0008 Ambient Light Sensor
May 10, 2015
feca56f
·
May 10, 2015
History
History
231 lines (191 loc) · 5.94 KB
Breadcrumbs
linux
/
drivers
/
iio
/
light
/
acpi-als.c
Top
File metadata and controls
Code
Blame
231 lines (191 loc) · 5.94 KB
Raw
/* * ACPI Ambient Light Sensor Driver * * Based on ALS driver: * Copyright (C) 2009 Zhang Rui <rui.zhang@intel.com> * * Rework for IIO subsystem: * Copyright (C) 2012-2013 Martin Liska <marxin.liska@gmail.com> * * Final cleanup and debugging: * Copyright (C) 2013-2014 Marek Vasut <marex@denx.de> * Copyright (C) 2015 Gabriele Mazzotta <gabriele.mzt@gmail.com> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <linux/module.h> #include <linux/acpi.h> #include <linux/err.h> #include <linux/mutex.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> #include <linux/iio/kfifo_buf.h> #define ACPI_ALS_CLASS "als" #define ACPI_ALS_DEVICE_NAME "acpi-als" #define ACPI_ALS_NOTIFY_ILLUMINANCE 0x80 ACPI_MODULE_NAME("acpi-als"); /* * So far, there's only one channel in here, but the specification for * ACPI0008 says there can be more to what the block can report. Like * chromaticity and such. We are ready for incoming additions! */ static const struct iio_chan_spec acpi_als_channels[] = { { .type = IIO_LIGHT, .scan_type = { .sign = 's', .realbits = 32, .storagebits = 32, }, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), }, }; /* * The event buffer contains timestamp and all the data from * the ACPI0008 block. There are multiple, but so far we only * support _ALI (illuminance). Once someone adds new channels * to acpi_als_channels[], the evt_buffer below will grow * automatically. */ #define EVT_NR_SOURCES ARRAY_SIZE(acpi_als_channels) #define EVT_BUFFER_SIZE \ (sizeof(s64) + (EVT_NR_SOURCES * sizeof(s32))) struct acpi_als { struct acpi_device *device; struct mutex lock; s32 evt_buffer[EVT_BUFFER_SIZE]; }; /* * All types of properties the ACPI0008 block can report. The ALI, ALC, ALT * and ALP can all be handled by als_read_value() below, while the ALR is * special. * * The _ALR property returns tables that can be used to fine-tune the values * reported by the other props based on the particular hardware type and it's * location (it contains tables for "rainy", "bright inhouse lighting" etc.). * * So far, we support only ALI (illuminance). */ #define ACPI_ALS_ILLUMINANCE "_ALI" #define ACPI_ALS_CHROMATICITY "_ALC" #define ACPI_ALS_COLOR_TEMP "_ALT" #define ACPI_ALS_POLLING "_ALP" #define ACPI_ALS_TABLES "_ALR" static int als_read_value(struct acpi_als *als, char *prop, s32 *val) { unsigned long long temp_val; acpi_status status; status = acpi_evaluate_integer(als->device->handle, prop, NULL, &temp_val); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Error reading ALS %s", prop)); return -EIO; } *val = temp_val; return 0; } static void acpi_als_notify(struct acpi_device *device, u32 event) { struct iio_dev *indio_dev = acpi_driver_data(device); struct acpi_als *als = iio_priv(indio_dev); s32 *buffer = als->evt_buffer; s64 time_ns = iio_get_time_ns(); s32 val; int ret; mutex_lock(&als->lock); memset(buffer, 0, EVT_BUFFER_SIZE); switch (event) { case ACPI_ALS_NOTIFY_ILLUMINANCE: ret = als_read_value(als, ACPI_ALS_ILLUMINANCE, &val); if (ret < 0) goto out; *buffer++ = val; break; default: /* Unhandled event */ dev_dbg(&device->dev, "Unhandled ACPI ALS event (%08x)!\n", event); goto out; } iio_push_to_buffers_with_timestamp(indio_dev, als->evt_buffer, time_ns); out: mutex_unlock(&als->lock); } static int acpi_als_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { struct acpi_als *als = iio_priv(indio_dev); s32 temp_val; int ret; if (mask != IIO_CHAN_INFO_RAW) return -EINVAL; /* we support only illumination (_ALI) so far. */ if (chan->type != IIO_LIGHT) return -EINVAL; ret = als_read_value(als, ACPI_ALS_ILLUMINANCE, &temp_val); if (ret < 0) return ret; *val = temp_val; return IIO_VAL_INT; } static const struct iio_info acpi_als_info = { .driver_module = THIS_MODULE, .read_raw = acpi_als_read_raw, }; static int acpi_als_add(struct acpi_device *device) { struct acpi_als *als; struct iio_dev *indio_dev; struct iio_buffer *buffer; indio_dev = devm_iio_device_alloc(&device->dev, sizeof(*als)); if (!indio_dev) return -ENOMEM; als = iio_priv(indio_dev); device->driver_data = indio_dev; als->device = device; mutex_init(&als->lock); indio_dev->name = ACPI_ALS_DEVICE_NAME; indio_dev->dev.parent = &device->dev; indio_dev->info = &acpi_als_info; indio_dev->modes = INDIO_BUFFER_SOFTWARE; indio_dev->channels = acpi_als_channels; indio_dev->num_channels = ARRAY_SIZE(acpi_als_channels); buffer = devm_iio_kfifo_allocate(&device->dev); if (!buffer) return -ENOMEM; iio_device_attach_buffer(indio_dev, buffer); return devm_iio_device_register(&device->dev, indio_dev); } static const struct acpi_device_id acpi_als_device_ids[] = { {"ACPI0008", 0}, {}, }; MODULE_DEVICE_TABLE(acpi, acpi_als_device_ids); static struct acpi_driver acpi_als_driver = { .name = "acpi_als", .class = ACPI_ALS_CLASS, .ids = acpi_als_device_ids, .ops = { .add = acpi_als_add, .notify = acpi_als_notify, }, }; module_acpi_driver(acpi_als_driver); MODULE_AUTHOR("Zhang Rui <rui.zhang@intel.com>"); MODULE_AUTHOR("Martin Liska <marxin.liska@gmail.com>"); MODULE_AUTHOR("Marek Vasut <marex@denx.de>"); MODULE_DESCRIPTION("ACPI Ambient Light Sensor Driver"); MODULE_LICENSE("GPL");
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
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
229
230
231
You can’t perform that action at this time.