From patchwork Wed Oct 24 10:38:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Ranostay X-Patchwork-Id: 10654515 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 6D23717F0 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 57A322A18B for ; Wed, 24 Oct 2018 10:39:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C0162A234; Wed, 24 Oct 2018 10:39:07 +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 2EBF22A233 for ; Wed, 24 Oct 2018 10:39:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727117AbeJXTGh (ORCPT ); Wed, 24 Oct 2018 15:06:37 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33151 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726916AbeJXTGh (ORCPT ); Wed, 24 Oct 2018 15:06:37 -0400 Received: by mail-wr1-f67.google.com with SMTP id u1-v6so5030773wrn.0 for ; Wed, 24 Oct 2018 03:39: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:in-reply-to:references; bh=7Va6jtAmjPupNFLQxShJntJTvRnh5DiV01k7Zuk7W5I=; b=KfXI9LA58ByqbRRLdTyEmPSQ3cc5Qy7MNfYxtJhcvQ3Kv31WH9XD5lDN/rusqjlK5A P7nvVfwj0AgyeqjMDbdBQGuZxhhDHqdII+38v1YuVB/uV39xSj/ythEhrq9tPmA2DovL 2t7lf/AuH1LPS20evWmT+difsUGsrfzYNaRlg= 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=7Va6jtAmjPupNFLQxShJntJTvRnh5DiV01k7Zuk7W5I=; b=rfoA6C3dUAYhgN/TK+myZkbxdNkqbDBWf2o+EW1QPdUiEvs/7i5q2G/LGO2U78xzyK jyz0iQPbJPnAo2OIkR6pVThDx6j4OOdTv0PIrPjfqpIyuClByS9SNTMQkWJ0bMGaWodV MATgghYGTN78uI9GuLrC4q908Lv0PEDzOoSTv9DBxtK8fafkpLlqT3j6LD+2dZTLxq2d Jw2V/HtSj7AtpILsUb2Zvb8HrIOfgAiMuwLCgjXLHIWs7EIxJnwiEP49OQWz31fSKZQ4 A/lsdnc6iNVH8SvEviDki3BviO0t1WIiAoz4EzFxU9Pkz/uMyL1K+8QcZ6XhUXCn4Di1 IGyA== X-Gm-Message-State: AGRZ1gL+5WUK61VMPT/KxyzZZi2GXD/ffBVMw8piO2D7tHudBYxyO6sV lgkDjNVRRDsQEEDMdC2OGykIag== X-Google-Smtp-Source: AJdET5fOwvo7shoH922rL53RS4uBPBg2WHTxSp8uuvyrZQ/2qbsZXv53goKAtgAPxquqoXHW0witdw== X-Received: by 2002:adf:bc84:: with SMTP id g4-v6mr2397625wrh.250.1540377542128; Wed, 24 Oct 2018 03:39:02 -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.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Oct 2018 03:39:01 -0700 (PDT) From: Matt Ranostay To: jic23@kernel.org Cc: linux-iio@vger.kernel.org, Matt Ranostay Subject: [PATCH 1/2] iio: potentiometer: tpl0102: switch to using pointer to chip config Date: Wed, 24 Oct 2018 11:38:57 +0100 Message-Id: <20181024103858.28201-2-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 More concise to have a pointer to tpl0102_cfg struct in the iio_priv data than an integer to an index of an array. Signed-off-by: Matt Ranostay Reviewed-by: Slawomir Stepien --- drivers/iio/potentiometer/tpl0102.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/iio/potentiometer/tpl0102.c b/drivers/iio/potentiometer/tpl0102.c index ca1cce58fe20..8e8adabe672b 100644 --- a/drivers/iio/potentiometer/tpl0102.c +++ b/drivers/iio/potentiometer/tpl0102.c @@ -37,7 +37,7 @@ static const struct tpl0102_cfg tpl0102_cfg[] = { struct tpl0102_data { struct regmap *regmap; - unsigned long devid; + const struct tpl0102_cfg *cfg; }; static const struct regmap_config tpl0102_regmap_config = { @@ -72,8 +72,8 @@ static int tpl0102_read_raw(struct iio_dev *indio_dev, return ret ? ret : IIO_VAL_INT; } case IIO_CHAN_INFO_SCALE: - *val = 1000 * tpl0102_cfg[data->devid].kohms; - *val2 = tpl0102_cfg[data->devid].max_pos; + *val = 1000 * data->cfg->kohms; + *val2 = data->cfg->max_pos; return IIO_VAL_FRACTIONAL; } @@ -89,7 +89,7 @@ static int tpl0102_write_raw(struct iio_dev *indio_dev, if (mask != IIO_CHAN_INFO_RAW) return -EINVAL; - if (val >= tpl0102_cfg[data->devid].max_pos || val < 0) + if (val >= data->cfg->max_pos || val < 0) return -EINVAL; return regmap_write(data->regmap, chan->channel, val); @@ -113,7 +113,7 @@ static int tpl0102_probe(struct i2c_client *client, data = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); - data->devid = id->driver_data; + data->cfg = &tpl0102_cfg[id->driver_data]; data->regmap = devm_regmap_init_i2c(client, &tpl0102_regmap_config); if (IS_ERR(data->regmap)) { dev_err(dev, "regmap initialization failed\n"); @@ -123,7 +123,7 @@ static int tpl0102_probe(struct i2c_client *client, indio_dev->dev.parent = dev; indio_dev->info = &tpl0102_info; indio_dev->channels = tpl0102_channels; - indio_dev->num_channels = tpl0102_cfg[data->devid].wipers; + indio_dev->num_channels = data->cfg->wipers; indio_dev->name = client->name; return devm_iio_device_register(dev, indio_dev); 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, };