From patchwork Sat Nov 18 23:20:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Fritz X-Patchwork-Id: 10064959 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A041A6023A for ; Sat, 18 Nov 2017 23:21:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92CF1292FC for ; Sat, 18 Nov 2017 23:21:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87BB6295C2; Sat, 18 Nov 2017 23:21:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DEF4295D9 for ; Sat, 18 Nov 2017 23:21:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030948AbdKRXUs (ORCPT ); Sat, 18 Nov 2017 18:20:48 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:41239 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1763885AbdKRXUq (ORCPT ); Sat, 18 Nov 2017 18:20:46 -0500 Received: by mail-wr0-f194.google.com with SMTP id z14so5004285wrb.8; Sat, 18 Nov 2017 15:20:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eFI9V6c3gcWMs14SBHeHwQulCZ5LI68Wv+1aVEoHXTg=; b=EYVWA67PyYtADgFS+phmbiyTfGZW/52ov2VmezDGg38aY9EHoeGLF4SWHQU1VT4XqH Jq8TZ+WGaNDbbnAtlgoKyaUXgt86pzFh+c35lb2o5ypwh9IvWr5C7iLcsCKlD+nIM/8L pwfDIt/LanjWghW4X7P+Kwl23X/gm4Drrdng17pHM/ff02kgo/4SQlxl5+xRWuRfN6ag ebxfNLN2TG6p8LwmsENQS0j8BQi0lsVRmf+pCGkEx13PCT7T0qnCAMTLGhec8VYAc84n arlmjntCU8AQVmrybp+4VGZiAI2qnOX0spAEM9iCRxgXofnDpMBacC7RjwS0o6EJCjzf u1cQ== 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; bh=eFI9V6c3gcWMs14SBHeHwQulCZ5LI68Wv+1aVEoHXTg=; b=WXp2FQu/DbtWMKIy6WBC9P5icZl5QYR0Hyr8J7x3y9rs5tmTbxJb9icok9WEqC/+No qrqfkjRfhyjSKIKCP/8YMkTSEEJ0ETHc/e/WLEVj3wj3dmWCMAPgelSiAvAvCGsU81n4 O4v8z8JgGbseOYzfPQFu9QY+glcghdeImzbzc97mDKVY45ECWdivngj8+j7tL+j/T9Yw deR1Vyu59/OD7QTBZMfsqUlD76JdK4ieS8y3uXttNiPkE87ikKUZW8llRXb4a/GbQg6L YIlFkZMDcOKD+bYpzCxOWaZO1hM2Qr/zbgBApe/cuPalfU1gghQoxDPkO097NnvneV+e 12rA== X-Gm-Message-State: AJaThX7yhivP/XroIdeDaCEAJkGCXBYwxrJTMxpZzWTs3M9omSmqA1nv mEd67Lnh7BldRTxuNULyJ8A= X-Google-Smtp-Source: AGs4zMbRiwVH5ffFIq33xeFWnEcGfCAPq3UiZTzzyCrtYj6FfqW4/6YFNmzpWkfYb2ev992/MeDkjA== X-Received: by 10.223.131.166 with SMTP id 35mr7691810wre.84.1511047244698; Sat, 18 Nov 2017 15:20:44 -0800 (PST) Received: from mars.fritz.box (HSI-KBW-109-193-021-110.hsi7.kabel-badenwuerttemberg.de. [109.193.21.110]) by smtp.googlemail.com with ESMTPSA id u5sm7612831wmf.44.2017.11.18.15.20.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 18 Nov 2017 15:20:43 -0800 (PST) From: Christoph Fritz To: Jonathan Cameron , Peter Meerwald-Stadler , Rob Herring Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v2 3/3] iio: light: isl76683 add way to adjust irq threshold Date: Sun, 19 Nov 2017 00:20:30 +0100 Message-Id: <1511047230-7021-4-git-send-email-chf.fritz@googlemail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1511047230-7021-1-git-send-email-chf.fritz@googlemail.com> References: <1511047230-7021-1-git-send-email-chf.fritz@googlemail.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds sysfs read/write support for upper and lower irq thresholds. So it's possible that only on certain lux ranges the irq triggered measurement happens. Signed-off-by: Christoph Fritz --- .../ABI/testing/sysfs-bus-iio-light-isl76683 | 17 +++++++ drivers/iio/light/isl76683.c | 57 ++++++++++++++++++++-- 2 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-light-isl76683 diff --git a/Documentation/ABI/testing/sysfs-bus-iio-light-isl76683 b/Documentation/ABI/testing/sysfs-bus-iio-light-isl76683 new file mode 100644 index 0000000..c7e08d7 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-iio-light-isl76683 @@ -0,0 +1,17 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_illuminance_threshold_low +Date: November 2017 +KernelVersion: 4.15.0 +Contact: linux-iio@vger.kernel.org +Description: + Raw value of lower threshold for the interrupt. + Reading returns 8-bit MSB data of a 16-bit threshold. + Writing 0...255 represents 8-bit MSB data of a 16-bit threshold. + +What: /sys/bus/iio/devices/iio:deviceX/in_illuminance_threshold_up +Date: November 2017 +KernelVersion: 4.15.0 +Contact: linux-iio@vger.kernel.org +Description: + Raw value of upper threshold for the interrupt. + Reading returns 8-bit MSB data of a 16-bit threshold. + Writing 0...255 represents 8-bit MSB data of a 16-bit threshold. diff --git a/drivers/iio/light/isl76683.c b/drivers/iio/light/isl76683.c index 4d158f6..1507158 100644 --- a/drivers/iio/light/isl76683.c +++ b/drivers/iio/light/isl76683.c @@ -74,11 +74,14 @@ static const int isl76683_lux_ranges_available[] = { #define ISL76683_KOHM_MAX 1000 #define ISL76683_INTPERS_DEFAULT 0x0 #define ISL76683_THR_DEFAULT 0x7f +#define ISL76683_THR_MAX 0xFF struct isl76683_chip { enum isl76683_lux_range luxrange; int external_resistor; enum isl76683_dmode photodiode; + int threshold_up; + int threshold_low; struct i2c_client *client; struct regmap *rmp; struct completion irq_complete; @@ -157,13 +160,12 @@ static int isl76683_set_config(struct isl76683_chip *chip) if (ret < 0) return ret; - ret = regmap_write(chip->rmp, ISL76683_REG_THR_HI, - ISL76683_THR_DEFAULT); + ret = regmap_write(chip->rmp, ISL76683_REG_THR_HI, chip->threshold_up); if (ret < 0) return ret; return regmap_write(chip->rmp, ISL76683_REG_THR_LO, - ISL76683_THR_DEFAULT); + chip->threshold_low); } static int isl76683_power(struct isl76683_chip *chip, bool on) @@ -402,11 +404,58 @@ static int isl76683_write_raw(struct iio_dev *indio_dev, return -EINVAL; } +#define ISL76683_SYSFS_STORE(ident, _max) \ +static ssize_t in_illuminance_##ident##_store(struct device *dev, \ + struct device_attribute *attr, \ + const char *buf, size_t len) \ +{ \ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); \ + struct isl76683_chip *chip = iio_priv(indio_dev); \ + unsigned int val; \ + int ret; \ + \ + if (kstrtouint(buf, 10, &val)) \ + return -EINVAL; \ + \ + if (val > _max) \ + return -EINVAL; \ + \ + mutex_lock(&chip->lock); \ + chip->ident = val; \ + ret = isl76683_set_config(chip); \ + mutex_unlock(&chip->lock); \ + \ + if (ret) \ + return -EIO; \ + \ + return len; \ +} + +ISL76683_SYSFS_STORE(threshold_low, ISL76683_THR_MAX) +ISL76683_SYSFS_STORE(threshold_up, ISL76683_THR_MAX) + +#define ISL76683_SYSFS_SHOW(ident, show_val) \ +static ssize_t in_illuminance_##ident##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ \ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); \ + struct isl76683_chip *chip = iio_priv(indio_dev); \ + \ + return snprintf(buf, PAGE_SIZE, "%i\n", show_val); \ +} + +ISL76683_SYSFS_SHOW(threshold_up, chip->threshold_up) +ISL76683_SYSFS_SHOW(threshold_low, chip->threshold_low) + static IIO_CONST_ATTR(in_illuminance_scale_available, ISL76683_LUXRANGE_STR); +static IIO_DEVICE_ATTR_RW(in_illuminance_threshold_up, 0); +static IIO_DEVICE_ATTR_RW(in_illuminance_threshold_low, 0); static struct attribute *isl76683_attributes[] = { &iio_const_attr_in_illuminance_scale_available.dev_attr.attr, + &iio_dev_attr_in_illuminance_threshold_up.dev_attr.attr, + &iio_dev_attr_in_illuminance_threshold_low.dev_attr.attr, NULL }; @@ -508,6 +557,8 @@ static int isl76683_probe(struct i2c_client *client, chip->luxrange = ISL76683_LUX_RANGE_DEFAULT; chip->external_resistor = rs; chip->photodiode = ISL76683_DIODE_DEFAULT; + chip->threshold_up = ISL76683_THR_DEFAULT; + chip->threshold_low = ISL76683_THR_DEFAULT; chip->rmp = devm_regmap_init_i2c(client, &isl76683_regmap_config); if (IS_ERR(chip->rmp)) {