From patchwork Sun Oct 28 20:43:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Ranostay X-Patchwork-Id: 10658701 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 3F49913BF for ; Sun, 28 Oct 2018 20:44:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2760829753 for ; Sun, 28 Oct 2018 20:44:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09FB929756; Sun, 28 Oct 2018 20:44:04 +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 8FD9D29753 for ; Sun, 28 Oct 2018 20:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725967AbeJ2F3s (ORCPT ); Mon, 29 Oct 2018 01:29:48 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:38068 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725841AbeJ2F3s (ORCPT ); Mon, 29 Oct 2018 01:29:48 -0400 Received: by mail-pg1-f193.google.com with SMTP id f8-v6so2858773pgq.5 for ; Sun, 28 Oct 2018 13:44:02 -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; bh=QPOh4tN068+P08bxosmkxOAF8aKJ8eJJWHOa3GSL+co=; b=eG8TEyyDqsjj8yjpmt6NHDZ42uOI0JGrdv+LJLeUSsAtG2oS4ohihdgxbyL0nzSsus efDLsZiqdEzVhPlio41veh6nqLpmZuspKGLFdRTp6ORMLnet/3ohx0becKurnWrmHQDr 2cdU9p76qKAdfjNibzL7cufyIQG7rNwE9J9lg= 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; bh=QPOh4tN068+P08bxosmkxOAF8aKJ8eJJWHOa3GSL+co=; b=GWHJ0ESWGBQZD5huQxEDeg/BiBxj3udqRBkg9YUR7xCqAt13fxO0SIySU2iNVBGJ4u /jlpgyNyk7ejqFZyRAHMJ9rMseDJbutvJwSSHdFys0HSNdwuJ/wt3W2yzjgMIsXYBqaE xyjcaolIxBD75Q3LQ2crXHzffIfTw9GdiBidb74i08852HULIs9PPa040owsSlw8x9UB UV1Fw3neU45yqFCHPj4yYTf2A/4XTM5qZzvq20DiUFmrmSmqPWsbsfq1ducKLCF2O3qX nnYCnXgsWPKWZOYXaQqwYNMHOkb15PgfPWJ7DlBUQa/+NzsLbKt1NBjJ2XZ3Jo0+Utnw mRjA== X-Gm-Message-State: AGRZ1gJ6udG9XIPz+wqu1/BXiPGxav8JGDWBPYErrOgO/j2HgBOyHtPf uQNTMii3zflt8Dt2YmYMUFChhlQV3uk= X-Google-Smtp-Source: AJdET5fw8xda6rOHMJtc8Uc1+KUsPaxU4y71WlffM5c+b202wZ9N6PpUWNymJP8CAdCXD6RDiUPfeg== X-Received: by 2002:a62:de84:: with SMTP id h126-v6mr6082224pfg.129.1540759441546; Sun, 28 Oct 2018 13:44:01 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:4001:b280:6c81:c0d7:73a3:e134]) by smtp.gmail.com with ESMTPSA id h14-v6sm21801622pfn.80.2018.10.28.13.44.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Oct 2018 13:44:00 -0700 (PDT) From: Matt Ranostay To: linux-iio@vger.kernel.org Cc: jic23@kernel.org, Matt Ranostay Subject: [PATCH v2] iio: potentiometer: tpl0102: add IIO_AVAIL_RANGE support Date: Sun, 28 Oct 2018 13:43:54 -0700 Message-Id: <20181028204354.9561-1-matt.ranostay@konsulko.com> X-Mailer: git-send-email 2.17.1 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 the step range of the respective potentiometers that are possible to userspace. Signed-off-by: Matt Ranostay --- Changes from v1: * Made commit message more clear * Add missing .info_mask_separate_available channel defines drivers/iio/potentiometer/tpl0102.c | 34 +++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/drivers/iio/potentiometer/tpl0102.c b/drivers/iio/potentiometer/tpl0102.c index 8e8adabe672b..a0a07e47f13f 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 { @@ -52,6 +52,7 @@ static const struct regmap_config tpl0102_regmap_config = { .channel = (ch), \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW), \ } static const struct iio_chan_spec tpl0102_channels[] = { @@ -73,13 +74,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 +108,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 +116,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, };