From patchwork Wed Oct 24 10:38:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Ranostay X-Patchwork-Id: 10654513 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1501A13BF for ; Wed, 24 Oct 2018 10:39:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F275F2A18B for ; Wed, 24 Oct 2018 10:39:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E69252A23C; Wed, 24 Oct 2018 10:39:06 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 B336D2A234 for ; Wed, 24 Oct 2018 10:39:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727009AbeJXTGi (ORCPT ); Wed, 24 Oct 2018 15:06:38 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52032 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726916AbeJXTGi (ORCPT ); Wed, 24 Oct 2018 15:06:38 -0400 Received: by mail-wm1-f65.google.com with SMTP id 143-v6so4815149wmf.1 for ; Wed, 24 Oct 2018 03:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FW9TnEZlPSo/oy0FhpnEb5fjiGrvhhRTUSIl7USI5Q4=; b=mo1vDYVc7XusrunQOu+tUu7n29JW3yifq53JU3lb5oybx5zQPY+erDf+p1rlUb2i4o ZC4gJk1fgN2ebzeUud0ve0j7xJnQcWET8p/pHO060yJx92DDuU+9KILzoIxHEEQ72O/L fmu9/AH+DAAVkMVOBbJTd1uL7kMdVcgt5MLE8= 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=FW9TnEZlPSo/oy0FhpnEb5fjiGrvhhRTUSIl7USI5Q4=; b=mMDvCc+WVvDMl9rWf8fXjD+P6wREKggDM6lUu5/7jAxNgpY/YFEExH6J8dhLBW41vM W4m/DNhrOLBoJH5PjgcqKCGxRLMKSVqwgIDE2n/CbuRNl8nBfZrZlsvkHCP8HzncsJvt rXWGw40GLJas426Ld7VCzu7lDxZSb6THTKZnkL1fEpN0c1FMZsi21jpoHeAOlMCUzGhl huA3IQo4cAc4e6BLzrf7p+ZjyHPVUNB7RfWCjr2syHdn95JRFWfYtthyRN1XVD/k4YDi Xdem3zoVcXyYL3AlSLjjkk5/0n3ovBDp6Zk5bzfVbm5/s4FpyHzviU8ci44xnCHRtX+c rZ5A== X-Gm-Message-State: AGRZ1gJCNeQiIdk95lxHtRe2RbDLCdqq/WgJrme1GZGbyCK+du24gdI3 Art5iLC8jAntpHko7Z0bFo2ZYdydygw= X-Google-Smtp-Source: AJdET5eOchbUhHmv2YbL9p3R2OChkCuRUzjHVQTBDX08YeLxAHnblbwqAvlgpcKykGsJynpLAqcpSg== X-Received: by 2002:a1c:3b89:: with SMTP id i131-v6mr2050472wma.27.1540377543322; Wed, 24 Oct 2018 03:39:03 -0700 (PDT) Received: from roguebox.c.hoisthospitality.com ([185.7.230.213]) by smtp.gmail.com with ESMTPSA id e142-v6sm10012170wmf.20.2018.10.24.03.39.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Oct 2018 03:39:02 -0700 (PDT) From: Matt Ranostay To: jic23@kernel.org Cc: linux-iio@vger.kernel.org, Matt Ranostay Subject: [PATCH 2/2] iio: potentiometer: tpl0102: add IIO_AVAIL_RANGE support Date: Wed, 24 Oct 2018 11:38:58 +0100 Message-Id: <20181024103858.28201-3-matt.ranostay@konsulko.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181024103858.28201-1-matt.ranostay@konsulko.com> References: <20181024103858.28201-1-matt.ranostay@konsulko.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 Report back the step range of the respective potentiometers that are possible back to userspace. Signed-off-by: Matt Ranostay Reviewed-by: Slawomir Stepien --- drivers/iio/potentiometer/tpl0102.c | 33 +++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/drivers/iio/potentiometer/tpl0102.c b/drivers/iio/potentiometer/tpl0102.c index 8e8adabe672b..d5aedf358fc2 100644 --- a/drivers/iio/potentiometer/tpl0102.c +++ b/drivers/iio/potentiometer/tpl0102.c @@ -15,7 +15,7 @@ struct tpl0102_cfg { int wipers; - int max_pos; + int avail[3]; int kohms; }; @@ -28,11 +28,11 @@ enum tpl0102_type { static const struct tpl0102_cfg tpl0102_cfg[] = { /* on-semiconductor parts */ - [CAT5140_503] = { .wipers = 1, .max_pos = 256, .kohms = 50, }, - [CAT5140_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, }, + [CAT5140_503] = { .wipers = 1, .avail = { 0, 1, 255 }, .kohms = 50, }, + [CAT5140_104] = { .wipers = 1, .avail = { 0, 1, 255 }, .kohms = 100, }, /* ti parts */ - [TPL0102_104] = { .wipers = 2, .max_pos = 256, .kohms = 100 }, - [TPL0401_103] = { .wipers = 1, .max_pos = 128, .kohms = 10, }, + [TPL0102_104] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms = 100 }, + [TPL0401_103] = { .wipers = 1, .avail = { 0, 1, 127 }, .kohms = 10, }, }; struct tpl0102_data { @@ -73,13 +73,31 @@ static int tpl0102_read_raw(struct iio_dev *indio_dev, } case IIO_CHAN_INFO_SCALE: *val = 1000 * data->cfg->kohms; - *val2 = data->cfg->max_pos; + *val2 = data->cfg->avail[2] + 1; return IIO_VAL_FRACTIONAL; } return -EINVAL; } +static int tpl0102_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + struct tpl0102_data *data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + *length = ARRAY_SIZE(data->cfg->avail); + *vals = data->cfg->avail; + *type = IIO_VAL_INT; + return IIO_AVAIL_RANGE; + } + + return -EINVAL; +} + static int tpl0102_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) @@ -89,7 +107,7 @@ static int tpl0102_write_raw(struct iio_dev *indio_dev, if (mask != IIO_CHAN_INFO_RAW) return -EINVAL; - if (val >= data->cfg->max_pos || val < 0) + if (val > data->cfg->avail[2] || val < 0) return -EINVAL; return regmap_write(data->regmap, chan->channel, val); @@ -97,6 +115,7 @@ static int tpl0102_write_raw(struct iio_dev *indio_dev, static const struct iio_info tpl0102_info = { .read_raw = tpl0102_read_raw, + .read_avail = tpl0102_read_avail, .write_raw = tpl0102_write_raw, };