* [PATCH] iio: light: acpi-als: Properly enable on ASUS Zenbooks
@ 2017-01-18 16:39 Josef Gajdusek
2017-01-18 20:26 ` Marek Vasut
0 siblings, 1 reply; 2+ messages in thread
From: Josef Gajdusek @ 2017-01-18 16:39 UTC (permalink / raw)
To: linux-iio
Cc: jic23, knaack.h, lars, pmeerw, maitysanchayan, gregor.boirie,
linux-kernel, rui.zhang, marxin.liska, marex, atx
ASUS Zenbooks need several special ACPI calls to enable the ALS peripheral.
Otherwise, reads just return 0.
Signed-off-by: Josef Gajdusek <atx@atx.name>
---
drivers/iio/light/acpi-als.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
index f0b47c5..1fe2cd8 100644
--- a/drivers/iio/light/acpi-als.c
+++ b/drivers/iio/light/acpi-als.c
@@ -39,6 +39,9 @@
#define ACPI_ALS_DEVICE_NAME "acpi-als"
#define ACPI_ALS_NOTIFY_ILLUMINANCE 0x80
+#define ACPI_ALS_ASUS_TALS "\\_SB.PCI0.LPCB.EC0.TALS"
+#define ACPI_ALS_ASUS_ALSC "\\_SB.ATKD.ALSC"
+
ACPI_MODULE_NAME("acpi-als");
/*
@@ -180,6 +183,8 @@ static int acpi_als_add(struct acpi_device *device)
struct acpi_als *als;
struct iio_dev *indio_dev;
struct iio_buffer *buffer;
+ acpi_handle handle_tals, handle_alsc;
+ acpi_status status_tals, status_alsc;
indio_dev = devm_iio_device_alloc(&device->dev, sizeof(*als));
if (!indio_dev)
@@ -191,6 +196,18 @@ static int acpi_als_add(struct acpi_device *device)
als->device = device;
mutex_init(&als->lock);
+ /* ASUS Zenbooks need this to enable ALS */
+ status_tals = acpi_get_handle(NULL, ACPI_ALS_ASUS_TALS, &handle_tals);
+ status_alsc = acpi_get_handle(NULL, ACPI_ALS_ASUS_ALSC, &handle_alsc);
+ /* So far only devices with both have been observed */
+ if (ACPI_SUCCESS(status_tals) ^ ACPI_SUCCESS(status_alsc))
+ dev_warn(&device->dev, "Attempting to enable ACPI ALS, but found only one of \""
+ ACPI_ALS_ASUS_TALS "\" and \"" ACPI_ALS_ASUS_ALSC "\"");
+ if (ACPI_SUCCESS(status_tals))
+ acpi_execute_simple_method(handle_tals, NULL, 1);
+ if (ACPI_SUCCESS(status_alsc))
+ acpi_execute_simple_method(handle_alsc, NULL, 1);
+
indio_dev->name = ACPI_ALS_DEVICE_NAME;
indio_dev->dev.parent = &device->dev;
indio_dev->info = &acpi_als_info;
--
2.10.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: light: acpi-als: Properly enable on ASUS Zenbooks
2017-01-18 16:39 [PATCH] iio: light: acpi-als: Properly enable on ASUS Zenbooks Josef Gajdusek
@ 2017-01-18 20:26 ` Marek Vasut
0 siblings, 0 replies; 2+ messages in thread
From: Marek Vasut @ 2017-01-18 20:26 UTC (permalink / raw)
To: Josef Gajdusek, linux-iio
Cc: jic23, knaack.h, lars, pmeerw, maitysanchayan, gregor.boirie,
linux-kernel, rui.zhang, marxin.liska
On 01/18/2017 05:39 PM, Josef Gajdusek wrote:
> ASUS Zenbooks need several special ACPI calls to enable the ALS peripheral.
> Otherwise, reads just return 0.
>
> Signed-off-by: Josef Gajdusek <atx@atx.name>
> ---
> drivers/iio/light/acpi-als.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
> index f0b47c5..1fe2cd8 100644
> --- a/drivers/iio/light/acpi-als.c
> +++ b/drivers/iio/light/acpi-als.c
> @@ -39,6 +39,9 @@
> #define ACPI_ALS_DEVICE_NAME "acpi-als"
> #define ACPI_ALS_NOTIFY_ILLUMINANCE 0x80
>
> +#define ACPI_ALS_ASUS_TALS "\\_SB.PCI0.LPCB.EC0.TALS"
> +#define ACPI_ALS_ASUS_ALSC "\\_SB.ATKD.ALSC"
> +
> ACPI_MODULE_NAME("acpi-als");
>
> /*
> @@ -180,6 +183,8 @@ static int acpi_als_add(struct acpi_device *device)
> struct acpi_als *als;
> struct iio_dev *indio_dev;
> struct iio_buffer *buffer;
> + acpi_handle handle_tals, handle_alsc;
> + acpi_status status_tals, status_alsc;
>
> indio_dev = devm_iio_device_alloc(&device->dev, sizeof(*als));
> if (!indio_dev)
> @@ -191,6 +196,18 @@ static int acpi_als_add(struct acpi_device *device)
> als->device = device;
> mutex_init(&als->lock);
>
> + /* ASUS Zenbooks need this to enable ALS */
> + status_tals = acpi_get_handle(NULL, ACPI_ALS_ASUS_TALS, &handle_tals);
> + status_alsc = acpi_get_handle(NULL, ACPI_ALS_ASUS_ALSC, &handle_alsc);
> + /* So far only devices with both have been observed */
> + if (ACPI_SUCCESS(status_tals) ^ ACPI_SUCCESS(status_alsc))
> + dev_warn(&device->dev, "Attempting to enable ACPI ALS, but found only one of \""
> + ACPI_ALS_ASUS_TALS "\" and \"" ACPI_ALS_ASUS_ALSC "\"");
> + if (ACPI_SUCCESS(status_tals))
> + acpi_execute_simple_method(handle_tals, NULL, 1);
> + if (ACPI_SUCCESS(status_alsc))
> + acpi_execute_simple_method(handle_alsc, NULL, 1);
Pull the system-specific quirk into a function please, don't pollute
common code with broken-ACPI crap.
Also, handle the failures in sequence, avoid the xor and other such
nonsense.
> indio_dev->name = ACPI_ALS_DEVICE_NAME;
> indio_dev->dev.parent = &device->dev;
> indio_dev->info = &acpi_als_info;
>
--
Best regards,
Marek Vasut
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-01-18 20:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-18 16:39 [PATCH] iio: light: acpi-als: Properly enable on ASUS Zenbooks Josef Gajdusek
2017-01-18 20:26 ` Marek Vasut
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.