From patchwork Wed Dec 16 06:02:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 11976673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC66BC0018C for ; Wed, 16 Dec 2020 06:03:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B84F223355 for ; Wed, 16 Dec 2020 06:03:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725885AbgLPGDT (ORCPT ); Wed, 16 Dec 2020 01:03:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725813AbgLPGDT (ORCPT ); Wed, 16 Dec 2020 01:03:19 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6846C061793 for ; Tue, 15 Dec 2020 22:02:38 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id h186so5459517pfe.0 for ; Tue, 15 Dec 2020 22:02:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wAiuD9XjlCIapOopak2nGjcyJTtN7EQoKtyOBuUMM/8=; b=lzoRL8jiwfeQzR3vFP+aT/FVxOstPfy+BhfXRl7IW5zK5KqaPsuLiaQ/nAZ9ZlwFvO mbcHsnIKMJ+qOv8SrFmGhUi8IEwZpfNwb8PxT85KJ4frHD6RzTTOzaMlFAp2wzh8Fs9w g9HNr75ZHk7lnPAXw54HJRhtrpb4GtTYaDr3s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wAiuD9XjlCIapOopak2nGjcyJTtN7EQoKtyOBuUMM/8=; b=d1hTP4wo14b/0++72Xx5T1lGurb/awYqgGbAwq9Neq9rCCntNQ2ID9tlGan/NG5yms ghz4Np1/xb/9JMcYyg3RHUDcKXuPn+QmxTyLxRUDszit+Qx+D65fK7eXnVdGMhVzPhzn KRzOF2B/RYSvL0S+a4RMSF/0kUnCAtriJu609HhUuiWm4iQ4vW8vdtq9S8ilD1WeBn1o Sc8qE8NePgaZnujsDZTohmNT6SPQWeXQNW/vnn9MZ1Bv/AhYp2QTBoIKv84QH4sBuuD4 PxVutEy3nBkDgm3bchQ2hoO9rJIYDfzLLsZsZdF0nwYv8EhunJjJ8Kej2k/LihL5ys/F 5MBg== X-Gm-Message-State: AOAM531qiawqeetke+5orWjQGpK6wj6muEuplmBWLYAEe5+5vUdzLsA1 FCQUTnMvc+phZ3pCLpEVN2EpcA== X-Google-Smtp-Source: ABdhPJy8dnPbEB1gtrYK5L+BD+O80AggiNyiV0KHXqaDFto85as/QBlsQuOXbATRDihYenbg+3GOCw== X-Received: by 2002:a63:4e4c:: with SMTP id o12mr31516796pgl.348.1608098558549; Tue, 15 Dec 2020 22:02:38 -0800 (PST) Received: from localhost ([2620:15c:202:201:7220:84ff:fe09:94fe]) by smtp.gmail.com with ESMTPSA id t135sm926121pfc.39.2020.12.15.22.02.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Dec 2020 22:02:37 -0800 (PST) From: Gwendal Grignou To: gabriele.mzt@gmail.com, jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com Cc: linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v4 1/3] iio: acpi_als: Add timestamp channel Date: Tue, 15 Dec 2020 22:02:31 -0800 Message-Id: <20201216060233.597689-2-gwendal@chromium.org> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog In-Reply-To: <20201216060233.597689-1-gwendal@chromium.org> References: <20201216060233.597689-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add timestamp channel in list of channel, to allow retrieving timestamps when events are produced. Signed-off-by: Gwendal Grignou --- Changes in v4: Fix spelling. drivers/iio/light/acpi-als.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c index 2be7180e2cbfa..57512ac74eba1 100644 --- a/drivers/iio/light/acpi-als.c +++ b/drivers/iio/light/acpi-als.c @@ -45,24 +45,23 @@ static const struct iio_chan_spec acpi_als_channels[] = { .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_PROCESSED), }, + IIO_CHAN_SOFT_TIMESTAMP(1), }; /* * 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. + * support _ALI (illuminance): + * One channel, padding and timestamp. */ -#define ACPI_ALS_EVT_NR_SOURCES ARRAY_SIZE(acpi_als_channels) #define ACPI_ALS_EVT_BUFFER_SIZE \ - (sizeof(s64) + (ACPI_ALS_EVT_NR_SOURCES * sizeof(s32))) + (sizeof(s32) + sizeof(s32) + sizeof(s64)) struct acpi_als { struct acpi_device *device; struct mutex lock; - s32 evt_buffer[ACPI_ALS_EVT_BUFFER_SIZE]; + s32 evt_buffer[ACPI_ALS_EVT_BUFFER_SIZE / sizeof(s32)] __aligned(8); }; /* From patchwork Wed Dec 16 06:02:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 11976675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12E4AC0007A for ; Wed, 16 Dec 2020 06:03:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D35872333E for ; Wed, 16 Dec 2020 06:03:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725889AbgLPGDV (ORCPT ); Wed, 16 Dec 2020 01:03:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725813AbgLPGDU (ORCPT ); Wed, 16 Dec 2020 01:03:20 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6762C061794 for ; Tue, 15 Dec 2020 22:02:40 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id lj6so916192pjb.0 for ; Tue, 15 Dec 2020 22:02:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AvbQ9zuHWaYlHbOGm/uPKSOpodNkKA9DlZ6AZo27xeQ=; b=b78MCG8kS+1+DonslS8cIWVQESsxEOcTi8wA4lmDsKligdo1kK290Iv/uHrRoUgm4m zTWKLAhMHH8Tov+b6PSqoA1V41F2lVWxpW7fhb9nB9fDmcQssgO9Glc1Ua5MfSxNOEZc EFRYGZwxBongbH5HFbEeDVtRn2Obq172r5b+k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AvbQ9zuHWaYlHbOGm/uPKSOpodNkKA9DlZ6AZo27xeQ=; b=L7O4DbD2s68Q+OMjwHgAFuYkeqeLCGMCnicr7ymfjMJdHBSNsKZV0u9xzzzVoTfQsd kF8pWYhjg83/4x2ou57WeevA3WP1UKNoeUd6U0EHKMC3vQuGn8E84DEJZvvsbzBLNQQq RpANeqSqMF/+lihtYJ18VxinY2gQU3rHvrAo49A0QklBb940uYqjv3D8Xw2IXS+vLTpu iuONmaVa13pGhOoMMlE1DeZJuojzca+wbAeenWGTKEv097ql1+sDGIVpknbsq90CXuD2 s/kZvb6+nT8JVovPP80CNUong+g1SbeAtt5cJ0mqJTpKFqSYE7rWNQWYV9AoLG0JkaKw 9dpg== X-Gm-Message-State: AOAM5308UrnRzORWrIepaAlLx7/YrnEIFA8YYz+lzmznPoE45pi+2SiL Kwh7Qfc3Tds+MNOMrM0vuP+vcQ== X-Google-Smtp-Source: ABdhPJwRXF6TXaosv6qAtN7YqtLQGLaZMsbYhmzdyh/5ZceUBZOsLpm4UkYTgGiQLExt0sjwUSzo2g== X-Received: by 2002:a17:902:ea89:b029:da:539e:9bb with SMTP id x9-20020a170902ea89b02900da539e09bbmr30989980plb.52.1608098560347; Tue, 15 Dec 2020 22:02:40 -0800 (PST) Received: from localhost ([2620:15c:202:201:7220:84ff:fe09:94fe]) by smtp.gmail.com with ESMTPSA id r67sm913781pfc.82.2020.12.15.22.02.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Dec 2020 22:02:39 -0800 (PST) From: Gwendal Grignou To: gabriele.mzt@gmail.com, jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com Cc: linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v4 2/3] iio: acpi_als: Add local variable dev in probe Date: Tue, 15 Dec 2020 22:02:32 -0800 Message-Id: <20201216060233.597689-3-gwendal@chromium.org> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog In-Reply-To: <20201216060233.597689-1-gwendal@chromium.org> References: <20201216060233.597689-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use dev = &device->dev in probe routine for clarity. Remove setting parent of iio device, already done in iio_device_alloc(). Signed-off-by: Gwendal Grignou --- Added in v4. drivers/iio/light/acpi-als.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c index 57512ac74eba1..32cd0f8438c33 100644 --- a/drivers/iio/light/acpi-als.c +++ b/drivers/iio/light/acpi-als.c @@ -165,8 +165,9 @@ static int acpi_als_add(struct acpi_device *device) struct acpi_als *als; struct iio_dev *indio_dev; struct iio_buffer *buffer; + struct device *dev = &device->dev; - indio_dev = devm_iio_device_alloc(&device->dev, sizeof(*als)); + indio_dev = devm_iio_device_alloc(dev, sizeof(*als)); if (!indio_dev) return -ENOMEM; @@ -182,13 +183,13 @@ static int acpi_als_add(struct acpi_device *device) indio_dev->channels = acpi_als_channels; indio_dev->num_channels = ARRAY_SIZE(acpi_als_channels); - buffer = devm_iio_kfifo_allocate(&device->dev); + buffer = devm_iio_kfifo_allocate(dev); if (!buffer) return -ENOMEM; iio_device_attach_buffer(indio_dev, buffer); - return devm_iio_device_register(&device->dev, indio_dev); + return devm_iio_device_register(dev, indio_dev); } static const struct acpi_device_id acpi_als_device_ids[] = { From patchwork Wed Dec 16 06:02:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 11976677 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28AF6C2BBCD for ; Wed, 16 Dec 2020 06:03:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F124D23356 for ; Wed, 16 Dec 2020 06:03:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725890AbgLPGDX (ORCPT ); Wed, 16 Dec 2020 01:03:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725813AbgLPGDX (ORCPT ); Wed, 16 Dec 2020 01:03:23 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 931EEC06179C for ; Tue, 15 Dec 2020 22:02:42 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id j1so12342164pld.3 for ; Tue, 15 Dec 2020 22:02:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SgM+VOwZmDqop2rBaARBECFV/B2gUrcHCig3D5vYhhU=; b=R9y6Ul0ZfqkIpfB2JBRos9aRgnuNaAw6IfviLBIWGL/TMfgIVF7fNzwUk1peRYfh41 yFkOr75KGIgr9FxLMJnDHe5Vf2PliQJohLZy8pQpuyAqX7BSQ6Qo40iL6JxJDun1yzAc MnJXPlgR4Xyma0K24QQjrXyQUB+ZM7PtS+wFI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SgM+VOwZmDqop2rBaARBECFV/B2gUrcHCig3D5vYhhU=; b=qqLa4YEBSGarwYVJhyX1PBRvBoGfmYZ2x5TL4mbxkxE86VzqXumifBUZmp5ZrnxLyT U97vz8CIMUBTf7Jvms4C+whCzbnUQGWFCsIEIqY5DNFOapZZod2dK9CfvkEb/V//zzIo 3yJybcG24KNpKt8HTAwJ7S1hGlpEH4w4eyPieBM4wwIh2MjpAQ8MscSp4p7tu0iBa6ZV /6/o3JVqYaNsQ/X/BM8DJdvuworG9bzvNXsVItf1K928PY+AJ3xyIuKGvJQeEkAsR2rm Wm6F554087kjmor+t1xlmfj0lbeFMf2aM7vA8zNO44Z1N8p2IP4zCSapTzWsaoztKwMT vVBg== X-Gm-Message-State: AOAM530m03UxKg9BZIQzLZ4lM3B7x79U/QkyXOcCM4ojHWYB3NEVx5BE qzVR/CnFTrYP0/QwU8r1FUdfkg== X-Google-Smtp-Source: ABdhPJyWfT0bI+MP32VeDmSzkn6ZpqxLzXGR+JJEjf2ercVjrm/TY8Bv/pY5Sf+5mDDZUVdB+DUMFg== X-Received: by 2002:a17:90b:1b0b:: with SMTP id nu11mr1784010pjb.143.1608098562139; Tue, 15 Dec 2020 22:02:42 -0800 (PST) Received: from localhost ([2620:15c:202:201:7220:84ff:fe09:94fe]) by smtp.gmail.com with ESMTPSA id b22sm924636pfo.163.2020.12.15.22.02.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Dec 2020 22:02:41 -0800 (PST) From: Gwendal Grignou To: gabriele.mzt@gmail.com, jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com Cc: linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v4 3/3] iio: acpi_als: Add trigger support Date: Tue, 15 Dec 2020 22:02:33 -0800 Message-Id: <20201216060233.597689-4-gwendal@chromium.org> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog In-Reply-To: <20201216060233.597689-1-gwendal@chromium.org> References: <20201216060233.597689-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org As some firmware does not notify on illuminance changes, add a trigger to be able to query light via software (sysfs-trigger or hrtrigger). Check iio_info reports the sensor as buffer capable: iio:device0: acpi-als (buffer capable) To test, check we can get data on demand on an Intel based chromebook: echo 1 > iio_sysfs_trigger/add_trigger cat trigger2/name > iio\:device0/trigger/current_trigger for i in iio\:device0/scan_elements/*_en iio\:device0/buffer/enable ; do echo 1 > $i done od -x /dev/iio\:device0& echo 1 > trigger2/trigger_now Signed-off-by: Gwendal Grignou --- Changes in v4: Added comments when pf->timestamp is 0 and valid. Fix spelling. drivers/iio/light/acpi-als.c | 88 +++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 22 deletions(-) diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c index 32cd0f8438c33..57d558ea5c0f1 100644 --- a/drivers/iio/light/acpi-als.c +++ b/drivers/iio/light/acpi-als.c @@ -16,11 +16,15 @@ #include #include #include +#include #include #include #include #include +#include +#include +#include #define ACPI_ALS_CLASS "als" #define ACPI_ALS_DEVICE_NAME "acpi-als" @@ -60,6 +64,7 @@ static const struct iio_chan_spec acpi_als_channels[] = { struct acpi_als { struct acpi_device *device; struct mutex lock; + struct iio_trigger *trig; s32 evt_buffer[ACPI_ALS_EVT_BUFFER_SIZE / sizeof(s32)] __aligned(8); }; @@ -103,33 +108,20 @@ 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(indio_dev); - s32 val; - int ret; - mutex_lock(&als->lock); - - memset(buffer, 0, ACPI_ALS_EVT_BUFFER_SIZE); + if (!iio_buffer_enabled(indio_dev) || + !iio_trigger_using_own(indio_dev)) + return; switch (event) { case ACPI_ALS_NOTIFY_ILLUMINANCE: - ret = acpi_als_read_value(als, ACPI_ALS_ILLUMINANCE, &val); - if (ret < 0) - goto out; - *buffer++ = val; + iio_trigger_poll_chained(als->trig); 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, @@ -160,12 +152,47 @@ static const struct iio_info acpi_als_info = { .read_raw = acpi_als_read_raw, }; +static irqreturn_t acpi_als_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct acpi_als *als = iio_priv(indio_dev); + s32 *buffer = als->evt_buffer; + s32 val; + int ret; + + mutex_lock(&als->lock); + + ret = acpi_als_read_value(als, ACPI_ALS_ILLUMINANCE, &val); + if (ret < 0) + goto out; + *buffer = val; + + /* + * When coming from own trigger via polls, set polling function timestamp + * here. + * Given ACPI notifier is already in a thread and call function directly, + * there is no need to set the timestamp in the notify function. + * + * If the timestamp was actually 0, the timestamp is set one more time. + */ + if (!pf->timestamp) + pf->timestamp = iio_get_time_ns(indio_dev); + + iio_push_to_buffers_with_timestamp(indio_dev, buffer, pf->timestamp); +out: + mutex_unlock(&als->lock); + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + static int acpi_als_add(struct acpi_device *device) { struct acpi_als *als; struct iio_dev *indio_dev; - struct iio_buffer *buffer; struct device *dev = &device->dev; + int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*als)); if (!indio_dev) @@ -179,15 +206,32 @@ static int acpi_als_add(struct acpi_device *device) indio_dev->name = ACPI_ALS_DEVICE_NAME; indio_dev->info = &acpi_als_info; - indio_dev->modes = INDIO_BUFFER_SOFTWARE; + indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = acpi_als_channels; indio_dev->num_channels = ARRAY_SIZE(acpi_als_channels); - buffer = devm_iio_kfifo_allocate(dev); - if (!buffer) + als->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", + indio_dev->name, + indio_dev->id); + if (!als->trig) return -ENOMEM; - iio_device_attach_buffer(indio_dev, buffer); + iio_trigger_set_drvdata(als->trig, indio_dev); + ret = devm_iio_trigger_register(dev, als->trig); + if (ret) + return ret; + /* + * Set hardware trigger by default to let events flow when + * BIOS support notification. + */ + indio_dev->trig = iio_trigger_get(als->trig); + + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, + iio_pollfunc_store_time, + acpi_als_trigger_handler, + NULL); + if (ret) + return ret; return devm_iio_device_register(dev, indio_dev); }