From patchwork Sun Feb 20 02:46:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12752489 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67BAAC433EF for ; Sun, 20 Feb 2022 02:46:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240694AbiBTCrC (ORCPT ); Sat, 19 Feb 2022 21:47:02 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:59894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230431AbiBTCrC (ORCPT ); Sat, 19 Feb 2022 21:47:02 -0500 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3701060FF; Sat, 19 Feb 2022 18:46:40 -0800 (PST) Received: by mail-pg1-x530.google.com with SMTP id l73so11211740pge.11; Sat, 19 Feb 2022 18:46:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=w9jy9lnBDfLmIqFJjt9CXkg0EOVyG3IWJdyZ7MDDT48=; b=b3RBdQujzShbpXP9ftARDtcyv9s2VFuR2g7D++WbG/gSp8no5uspjH+cKliZ8KxvP0 nyAxatpn+brK5PhyONXzneWm6ROXvU9eCK9JcmveUthOcwlXdo6nX+4Mq2jZljK+BkqF BD1xdGO8FRyW3ZOgYs6ymI8RYQIFmA3PAm6wy1cKeyouclNDJxGV517/LiQW6AfYnx2Z Y5PmRYkKRhoUuOSKkQebJwqytW72hLSKPtcWT3FWmaFVG6X871gHFFm9tAMncPij3Oef /T7leM+uplL5k1hBFHXG8aBJZ9arB/i6XBzyOidtxYRHHfGuLMddRaXg7/5c0P4ZD0Nn LbFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=w9jy9lnBDfLmIqFJjt9CXkg0EOVyG3IWJdyZ7MDDT48=; b=EbIpd4fGcWKR4zE8S50tCNe8CVkaiq42TaYmzIyTkMRY8YElvcuqFVdyVGatY/9be1 AEYExrXhiutpthym5hPIJrjrlX/JMT7ptuCAeQhAnc1l29dofEjCrWuBmGopYafV3Rb5 BrkXsJ/ZEg9OUn9XxZbTlFYIem4Euzmp0TGJXSxof0Wxoi1uNlEPcv/oAs+fIj/yIzXt D+kyabwSZ/h6a5SKwLGc6gD6Rq7j/p5KxJBWeNqtiNDjwA+RdDVQc8OmJeQRx1lRv2i2 BFbP3GBbiDBA+KQnlafx5Hw7zMir8Wtzmum2X09KZ81tlIiPeuSHn8HdmJMJPYaJQe5p HNfw== X-Gm-Message-State: AOAM530MP16dKEvgyUIX78JRDqGSRvGbqS/YBGcgn8PoaOR2dmlUHqXG hxm94QEvmQ4BZfo0cDMwf90= X-Google-Smtp-Source: ABdhPJwTi4oEX21GhDHC/eBc+pSCwzv/eDr62xXJLSjr1+uG4/tr8bBJlNhNskpfzFgelXuHXh34hA== X-Received: by 2002:a05:6a00:190d:b0:4e9:57a9:af13 with SMTP id y13-20020a056a00190d00b004e957a9af13mr11003812pfi.43.1645325199691; Sat, 19 Feb 2022 18:46:39 -0800 (PST) Received: from localhost.localdomain ([116.73.72.178]) by smtp.gmail.com with ESMTPSA id lw16sm3488761pjb.51.2022.02.19.18.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Feb 2022 18:46:39 -0800 (PST) From: Jagath Jog J To: jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com, sst@poczta.fm, robh+dt@kernel.org Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/7] iio: potentiometer: Alignment to match the open parenthesis Date: Sun, 20 Feb 2022 08:16:26 +0530 Message-Id: <20220220024632.4183-2-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220220024632.4183-1-jagathjog1996@gmail.com> References: <20220220024632.4183-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Fix following checkpatch.pl check by removing blank space. CHECK: Alignment should match open parenthesis. Signed-off-by: Jagath Jog J --- drivers/iio/potentiometer/ds1803.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/iio/potentiometer/ds1803.c b/drivers/iio/potentiometer/ds1803.c index 20b45407eaac..3c542a50ece6 100644 --- a/drivers/iio/potentiometer/ds1803.c +++ b/drivers/iio/potentiometer/ds1803.c @@ -55,8 +55,8 @@ static const struct iio_chan_spec ds1803_channels[] = { }; static int ds1803_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, int *val2, long mask) + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) { struct ds1803_data *data = iio_priv(indio_dev); int pot = chan->channel; @@ -66,7 +66,7 @@ static int ds1803_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: ret = i2c_master_recv(data->client, result, - indio_dev->num_channels); + indio_dev->num_channels); if (ret < 0) return ret; @@ -83,8 +83,8 @@ static int ds1803_read_raw(struct iio_dev *indio_dev, } static int ds1803_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, int val2, long mask) + struct iio_chan_spec const *chan, + int val, int val2, long mask) { struct ds1803_data *data = iio_priv(indio_dev); int pot = chan->channel; @@ -109,8 +109,7 @@ static const struct iio_info ds1803_info = { .write_raw = ds1803_write_raw, }; -static int ds1803_probe(struct i2c_client *client, - const struct i2c_device_id *id) +static int ds1803_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device *dev = &client->dev; struct ds1803_data *data; From patchwork Sun Feb 20 02:46:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12752490 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 877FAC433EF for ; Sun, 20 Feb 2022 02:46:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243333AbiBTCrF (ORCPT ); Sat, 19 Feb 2022 21:47:05 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:59952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241315AbiBTCrD (ORCPT ); Sat, 19 Feb 2022 21:47:03 -0500 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C246C5FA0; Sat, 19 Feb 2022 18:46:42 -0800 (PST) Received: by mail-pg1-x535.google.com with SMTP id 139so11250435pge.1; Sat, 19 Feb 2022 18:46:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uiihxuBwfEAWFN0iioefL1gnjjyjm+Qiro5uJmWB4Mw=; b=k6wSS9R16e0VnxsMB2WaPy1av0Oghsz1AOganzzQ69lnObFYJdgTARI1FrPT0NPNZJ +iys2EVyrHFGBiSZjPVc9MtWnxyXZnrEb5SUh02Nt4DnqSlxgfsNTw+kkt3wTH+DklEc idGti2WJp9/hPY7Pnas6t7S7f3l+fX5Cy9LKbYCdqMCFj1R0jmFP3tfGs5jv/NcQlATA QkJ6dgC8sG4T5myObaB1n9Rl/rgot/kKj0Oc+18p2Ghd2d/ULJbQuQ7HaJxPRWoHSw5Z iEHmHw85n50r+jtOQ2u8lJCPsqZriELX9AaivYA/xPZOiBFwk8qKAILwP18Db3o+dJxb c5Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uiihxuBwfEAWFN0iioefL1gnjjyjm+Qiro5uJmWB4Mw=; b=COji0BjbloIyZKfU8DMg9YxoiuP9uN8rIYxo4X9OO2uBWXDIRrbjRbc4XQKkcjILhq XV4ERo450eT0j9U+snTSg/ieB2gccZJhY9GL+iTSA0Kycnf/jwXgRqWcGH7OiUF9xDA8 o1at56haQEYJK7bj1Wa5xrecYKmXqIkmh6Gmg/aeYzj825SRBeTRpuVCMXpe2o8ljFAC x9ZYyg9xnMSY0c8lbfG34zKEK2pMze8GXDoE1CWTUgF+xHf8Ler5q2+XRNtk9FKp3dED DfAgfOuNQ5Icn4EdHZEX1PlkbIhsVN7QrJA7de6zgOmj3sZIhAjY9LJmWA2uF+TxSSpJ Hprg== X-Gm-Message-State: AOAM530xWE4XdOiagaKd6vIV8vG6cVsQORL4GkPwytHx7qpWIro/rTtP h4wNCIxevPPT9wmnT8DahStjWhj2JbzZbCLIgwc= X-Google-Smtp-Source: ABdhPJx9MWZyyRf0OhWyT7FiO36PEUMWgtqcWeZ/5YSfdheUW8wXKzoXrfOks710EGnG4kDZ3/AAag== X-Received: by 2002:a63:88c1:0:b0:36c:dcd7:2241 with SMTP id l184-20020a6388c1000000b0036cdcd72241mr11534177pgd.141.1645325202279; Sat, 19 Feb 2022 18:46:42 -0800 (PST) Received: from localhost.localdomain ([116.73.72.178]) by smtp.gmail.com with ESMTPSA id lw16sm3488761pjb.51.2022.02.19.18.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Feb 2022 18:46:42 -0800 (PST) From: Jagath Jog J To: jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com, sst@poczta.fm, robh+dt@kernel.org Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/7] iio: potentiometer: Add available functionality Date: Sun, 20 Feb 2022 08:16:27 +0530 Message-Id: <20220220024632.4183-3-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220220024632.4183-1-jagathjog1996@gmail.com> References: <20220220024632.4183-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Adding available functionality for DS1803 driver which will show the minimum, step and maximum values that the driver can accepts through sysfs entry. Now using the max value present in avail array instead of chip type specific macro to make the driver flexible to add other type of potentiometer with different max position value. Signed-off-by: Jagath Jog J --- drivers/iio/potentiometer/ds1803.c | 52 +++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/drivers/iio/potentiometer/ds1803.c b/drivers/iio/potentiometer/ds1803.c index 3c542a50ece6..c9cf7181cb7f 100644 --- a/drivers/iio/potentiometer/ds1803.c +++ b/drivers/iio/potentiometer/ds1803.c @@ -16,7 +16,6 @@ #include #include -#define DS1803_MAX_POS 255 #define DS1803_WRITE(chan) (0xa8 | ((chan) + 1)) enum ds1803_type { @@ -26,27 +25,23 @@ enum ds1803_type { }; struct ds1803_cfg { + int avail[3]; int kohms; }; -static const struct ds1803_cfg ds1803_cfg[] = { - [DS1803_010] = { .kohms = 10, }, - [DS1803_050] = { .kohms = 50, }, - [DS1803_100] = { .kohms = 100, }, -}; - struct ds1803_data { struct i2c_client *client; const struct ds1803_cfg *cfg; }; -#define DS1803_CHANNEL(ch) { \ - .type = IIO_RESISTANCE, \ - .indexed = 1, \ - .output = 1, \ - .channel = (ch), \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ +#define DS1803_CHANNEL(ch) { \ + .type = IIO_RESISTANCE, \ + .indexed = 1, \ + .output = 1, \ + .channel = (ch), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_RAW), \ } static const struct iio_chan_spec ds1803_channels[] = { @@ -54,6 +49,12 @@ static const struct iio_chan_spec ds1803_channels[] = { DS1803_CHANNEL(1), }; +static const struct ds1803_cfg ds1803_cfg[] = { + [DS1803_010] = { .avail = { 0, 1, 255 }, .kohms = 10, }, + [DS1803_050] = { .avail = { 0, 1, 255 }, .kohms = 50, }, + [DS1803_100] = { .avail = { 0, 1, 255 }, .kohms = 100, }, +}; + static int ds1803_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -75,7 +76,7 @@ static int ds1803_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_SCALE: *val = 1000 * data->cfg->kohms; - *val2 = DS1803_MAX_POS; + *val2 = data->cfg->avail[2]; /* Max wiper position */ return IIO_VAL_FRACTIONAL; } @@ -88,13 +89,14 @@ static int ds1803_write_raw(struct iio_dev *indio_dev, { struct ds1803_data *data = iio_priv(indio_dev); int pot = chan->channel; + int max_pos = data->cfg->avail[2]; if (val2 != 0) return -EINVAL; switch (mask) { case IIO_CHAN_INFO_RAW: - if (val > DS1803_MAX_POS || val < 0) + if (val > max_pos || val < 0) return -EINVAL; break; default: @@ -104,9 +106,27 @@ static int ds1803_write_raw(struct iio_dev *indio_dev, return i2c_smbus_write_byte_data(data->client, DS1803_WRITE(pot), val); } +static int ds1803_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, + int *length, long mask) +{ + struct ds1803_data *data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + *vals = data->cfg->avail; + *length = ARRAY_SIZE(data->cfg->avail); + *type = IIO_VAL_INT; + return IIO_AVAIL_RANGE; + } + return -EINVAL; +} + static const struct iio_info ds1803_info = { .read_raw = ds1803_read_raw, .write_raw = ds1803_write_raw, + .read_avail = ds1803_read_avail, }; static int ds1803_probe(struct i2c_client *client, const struct i2c_device_id *id) From patchwork Sun Feb 20 02:46:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12752491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A074C43217 for ; Sun, 20 Feb 2022 02:46:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243348AbiBTCrG (ORCPT ); Sat, 19 Feb 2022 21:47:06 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243334AbiBTCrF (ORCPT ); Sat, 19 Feb 2022 21:47:05 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61571BC27; Sat, 19 Feb 2022 18:46:45 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id gf13-20020a17090ac7cd00b001bbfb9d760eso2110462pjb.2; Sat, 19 Feb 2022 18:46:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=udPMv+VfuCnMjB/kHyzLTWqno3DIHk+LRs09KfjMc5M=; b=PZc+xDICWto09udixdARaogVrIOXYXJiJo/aud0LZR2P7CSQAfI+JBniH8Ntrl/nos BVc1yFXr+wc6fn1qGObAgT7IFXsPY0mIRwHxhdxUgdOYpFTgpCsDHwOVNaVxAZo3B/5d MzAXpTSgh4mLvP64HvKzGm5wuY7ZtzdcknMOknqD7SWM6lamcRAR/L1rQcjuHkpZxqD0 emgkHCeLLwPKSE1Dru5KVS1pn0OcL9P9nisi3e2DHF4UjqfWyuvU6OD2yNVCzgVtgcw0 SWKyf2CrLfT4/sIJpkKOyi5qhT1uWCM3V6cpwX1tewdPqJAwle41iuGYcc9tdDNs2nNn zqeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=udPMv+VfuCnMjB/kHyzLTWqno3DIHk+LRs09KfjMc5M=; b=TbEGa7JPyG+YYX7OW8VCZQEyQMOw6/bkVPoP7V8sPcMxaXVfCcdmLILjtcgCJ65vS2 5m+vBSLt6acSQjqajKaR7n2Ajhb1awv9ABB21pk/TLGKyX6wdNrBUsGGOAfegtdosa/T 1y952cYpbuHFCNMYbldzkOkF/HLxwtXzB9+tth5sJI3kiK4q0ZsLuD3AG9W/j9o0bd7y u1aplZSpptuc2jAg3JsWlN0aY+Z0nH1X3+MkADkdvC3axs50liHj6Fmkv2sZrMk9qPQR IfEFbZXttu6alP95GPsWjdBU+Q0CHr6il9HqzXz/tbdBGBUo7Rh1Oq/hufOU0kKYMo3a rDJQ== X-Gm-Message-State: AOAM533x5ws18aglL794wl+c9JheTFSjga5luoqtgHVgZhsF0fNh5piz qQ8nfqibOIZAW5hVyFVW1co= X-Google-Smtp-Source: ABdhPJyNdx5E/hEt3f2mO+HKsovgFQnGWonopsKFVT7n5HjpGgxIUehBeGC9rbfWTLv/AyYnR7Bd6Q== X-Received: by 2002:a17:902:db05:b0:14d:743f:5162 with SMTP id m5-20020a170902db0500b0014d743f5162mr13531374plx.12.1645325204809; Sat, 19 Feb 2022 18:46:44 -0800 (PST) Received: from localhost.localdomain ([116.73.72.178]) by smtp.gmail.com with ESMTPSA id lw16sm3488761pjb.51.2022.02.19.18.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Feb 2022 18:46:44 -0800 (PST) From: Jagath Jog J To: jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com, sst@poczta.fm, robh+dt@kernel.org Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/7] iio: potentiometer: Add channel information in device data Date: Sun, 20 Feb 2022 08:16:28 +0530 Message-Id: <20220220024632.4183-4-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220220024632.4183-1-jagathjog1996@gmail.com> References: <20220220024632.4183-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Adding each device wiper count and channel information into device private data. Utilizing addr member of struct iio_chan_spec to get the wiper register address so that the value can be read or write to the same address. Signed-off-by: Jagath Jog J --- drivers/iio/potentiometer/ds1803.c | 33 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/iio/potentiometer/ds1803.c b/drivers/iio/potentiometer/ds1803.c index c9cf7181cb7f..cf822e21284e 100644 --- a/drivers/iio/potentiometer/ds1803.c +++ b/drivers/iio/potentiometer/ds1803.c @@ -16,7 +16,8 @@ #include #include -#define DS1803_WRITE(chan) (0xa8 | ((chan) + 1)) +#define DS1803_WIPER_0 0xA9 +#define DS1803_WIPER_1 0xAA enum ds1803_type { DS1803_010, @@ -25,8 +26,11 @@ enum ds1803_type { }; struct ds1803_cfg { + int wipers; int avail[3]; int kohms; + const struct iio_chan_spec *channels; + u8 num_channels; }; struct ds1803_data { @@ -34,25 +38,32 @@ struct ds1803_data { const struct ds1803_cfg *cfg; }; -#define DS1803_CHANNEL(ch) { \ +#define DS1803_CHANNEL(ch, addr) { \ .type = IIO_RESISTANCE, \ .indexed = 1, \ .output = 1, \ .channel = (ch), \ + .address = (addr), \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_RAW), \ } static const struct iio_chan_spec ds1803_channels[] = { - DS1803_CHANNEL(0), - DS1803_CHANNEL(1), + DS1803_CHANNEL(0, DS1803_WIPER_0), + DS1803_CHANNEL(1, DS1803_WIPER_1), }; static const struct ds1803_cfg ds1803_cfg[] = { - [DS1803_010] = { .avail = { 0, 1, 255 }, .kohms = 10, }, - [DS1803_050] = { .avail = { 0, 1, 255 }, .kohms = 50, }, - [DS1803_100] = { .avail = { 0, 1, 255 }, .kohms = 100, }, + [DS1803_010] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms = 10, + .channels = ds1803_channels, + .num_channels = ARRAY_SIZE(ds1803_channels) }, + [DS1803_050] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms = 50, + .channels = ds1803_channels, + .num_channels = ARRAY_SIZE(ds1803_channels) }, + [DS1803_100] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms = 100, + .channels = ds1803_channels, + .num_channels = ARRAY_SIZE(ds1803_channels) }, }; static int ds1803_read_raw(struct iio_dev *indio_dev, @@ -88,7 +99,7 @@ static int ds1803_write_raw(struct iio_dev *indio_dev, int val, int val2, long mask) { struct ds1803_data *data = iio_priv(indio_dev); - int pot = chan->channel; + u8 addr = chan->address; int max_pos = data->cfg->avail[2]; if (val2 != 0) @@ -103,7 +114,7 @@ static int ds1803_write_raw(struct iio_dev *indio_dev, return -EINVAL; } - return i2c_smbus_write_byte_data(data->client, DS1803_WRITE(pot), val); + return i2c_smbus_write_byte_data(data->client, addr, val); } static int ds1803_read_avail(struct iio_dev *indio_dev, @@ -146,8 +157,8 @@ static int ds1803_probe(struct i2c_client *client, const struct i2c_device_id *i data->cfg = &ds1803_cfg[id->driver_data]; indio_dev->info = &ds1803_info; - indio_dev->channels = ds1803_channels; - indio_dev->num_channels = ARRAY_SIZE(ds1803_channels); + indio_dev->channels = data->cfg->channels; + indio_dev->num_channels = data->cfg->num_channels; indio_dev->name = client->name; return devm_iio_device_register(dev, indio_dev); From patchwork Sun Feb 20 02:46:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12752492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44030C433F5 for ; Sun, 20 Feb 2022 02:46:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243374AbiBTCrP (ORCPT ); Sat, 19 Feb 2022 21:47:15 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243375AbiBTCrJ (ORCPT ); Sat, 19 Feb 2022 21:47:09 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB25117A9C; Sat, 19 Feb 2022 18:46:47 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id a11-20020a17090a740b00b001b8b506c42fso15804772pjg.0; Sat, 19 Feb 2022 18:46:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=o7fOFIds8w0t8thTccyYNHJARMbew1IEIkz/ilir+/0=; b=qHmD1f1bdUc569/X51lzKH9xvNBKHlOXIDV1PpGKK0zfNyqj8ZOX36ym1in6X/RDM8 rJX59I94MO2VpQzwWTZcbDhX6Wah3KpsxHsy/NDn+UymNbsmeAWQJwHu3NgIXzccyd+X uawi88S7aUJeA1AkzrygWjCPbpC/3X4mFGqpZzhVZ38zHf9JMqCp+PfuIbAq3IuE8ynV LFYqdaJai8OsYDQ1skSKoi1+ZAPb4NJTsYh+PCe7rwLDQTekSdsumHP7lt2zbEIjVe6X th3cfzLn8jx0UifrmHiBoPYTExUtakj6M1WVFVHq8GOfRoxxSTwSsxAUC0IpW0wI7Ndw NWOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=o7fOFIds8w0t8thTccyYNHJARMbew1IEIkz/ilir+/0=; b=SmUUfsWCBtez+dpQbQ3vaIAsZe3/JTwumoTN4O0c1GLgXfuH8RWmGeU4YXXGxf4HNk O00wJ3UGmtPSEl67yY0WIz8/8fOOifO0LT9jSAq3wF+rufzgG/oW9fm8DYvZXNAQ4Li3 wItSYZ/qc1MAh8k8txuVDUtgLxiy5FZX1FruL2pEnyf67GDYTGEnO5Rhh9jPZrMLKcVk qUleVF/ZRN0Wxd9SBtiVe+/4VEOY26tmnES0WJkJlglS4HiZtB6uY25addxIN/gRjN24 ctYbwgO6FkKesd//Vd7tsd2SABfjq0IGRaP2fatXW2doBtq8F9RO945XG/nJ3F0cHs9u ptOQ== X-Gm-Message-State: AOAM532KhEpHUO4YPMPByT5H/cjLFF2UCd1IcpCspjXM0WkM+gA2ZSxV ++mQZTMc5GF08fVpRC2boQY= X-Google-Smtp-Source: ABdhPJzNJbVBw2uLPAxyJXF3ydfgtqGbefOOWuQlEH2EAhgPLHkhmqqy9eBhT6MPJ5MksxVcS+Hn+g== X-Received: by 2002:a17:902:d4c9:b0:14f:929c:f3c9 with SMTP id o9-20020a170902d4c900b0014f929cf3c9mr4170623plg.45.1645325207348; Sat, 19 Feb 2022 18:46:47 -0800 (PST) Received: from localhost.localdomain ([116.73.72.178]) by smtp.gmail.com with ESMTPSA id lw16sm3488761pjb.51.2022.02.19.18.46.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Feb 2022 18:46:47 -0800 (PST) From: Jagath Jog J To: jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com, sst@poczta.fm, robh+dt@kernel.org Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 4/7] iio: potentiometer: Change to firmware provided data Date: Sun, 20 Feb 2022 08:16:29 +0530 Message-Id: <20220220024632.4183-5-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220220024632.4183-1-jagathjog1996@gmail.com> References: <20220220024632.4183-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Using firmware provided data to get the device specific structure if not available fall back to id->driver_data. Signed-off-by: Jagath Jog J --- drivers/iio/potentiometer/ds1803.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/iio/potentiometer/ds1803.c b/drivers/iio/potentiometer/ds1803.c index cf822e21284e..3b86a4106277 100644 --- a/drivers/iio/potentiometer/ds1803.c +++ b/drivers/iio/potentiometer/ds1803.c @@ -154,7 +154,9 @@ static int ds1803_probe(struct i2c_client *client, const struct i2c_device_id *i data = iio_priv(indio_dev); data->client = client; - data->cfg = &ds1803_cfg[id->driver_data]; + data->cfg = device_get_match_data(dev); + if (!data->cfg) + data->cfg = &ds1803_cfg[id->driver_data]; indio_dev->info = &ds1803_info; indio_dev->channels = data->cfg->channels; From patchwork Sun Feb 20 02:46:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12752493 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C778C433EF for ; Sun, 20 Feb 2022 02:46:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243387AbiBTCrP (ORCPT ); Sat, 19 Feb 2022 21:47:15 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243373AbiBTCrO (ORCPT ); Sat, 19 Feb 2022 21:47:14 -0500 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C904245A5; Sat, 19 Feb 2022 18:46:50 -0800 (PST) Received: by mail-pg1-x535.google.com with SMTP id 12so7672407pgd.0; Sat, 19 Feb 2022 18:46:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ienohvOr86bVgWt3LPZgXi/rHK6KTUPXquXbb0N97Wc=; b=a5ohoCZ/oyGlyMnA4Nfq5vgav/ZOadiMjoNoHfc8Ief+NdFjTcyTLrjZ1rHkaMwhcA EqFelYVsodgB6dHLOsKImevwxgHocwDquUzouVu7G4hNXPI3ErquCBnCclczk1dbzfmw JZENi9pknWYRSkpShYkR57uF/DzeEqmKyovSQ0E0bhT5WxVGCx93DNpcyMB+HDB187GL XRo9xktKG49FQ7BRyDlwNj9wDMbKbCejUoQqVEyS5lR0kJrTwPcR7LJIiRNsWFkppiEE 5pwJLDAGt9CFkEqwnSEdQqQXAgM+WctjLmMpbt4RkuxDRgQGqEpV79StbAyXyJwR6yiE EwGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ienohvOr86bVgWt3LPZgXi/rHK6KTUPXquXbb0N97Wc=; b=y9yuuVhwKE6YNFOh0CqhloTqPs0Q1180790wdbeRgr3S3zxLgEU/t4deQyFf3FnYXD 8C8CQYuXHUFsWQGK2vDOZxQeo6N2Ckn9N05QGUkjD6p3TqKgBqRTv+KpIaIjkXT1Su/d iObsbEN3pMBoKCmakMHodlZ7vhW+ltQncMrt1r6H+/ymzSnO3V0y+Y5z369ZyTaXCY6O 1Gs14Auv4USZUuPELM2IwvJoJZqhv1Al+KHslYUh+t3tbDJFN4F6DdUUxm+qICyAMlEf xalOSt4Qr/742RlL4FmJtUqSehosRrj43Wr+yrOiu+iTbSKjYzvASEZzhvHoD8EPkXlZ DEUg== X-Gm-Message-State: AOAM533uKzix8ChVz+v++m3ZuEuJmAgCt1FoTQCAkswc1KiS7t1pakIa f+7sRp5lv/IbV0vjIrflf20= X-Google-Smtp-Source: ABdhPJyJejfVoRR57gRpqlUDaQG9CRRc3q/Oi9iZs8AgVfsxZxxUKE/ThNNdlax5WFCjqUSnLztCqA== X-Received: by 2002:a65:6c0d:0:b0:364:ae2e:9708 with SMTP id y13-20020a656c0d000000b00364ae2e9708mr11734107pgu.189.1645325210135; Sat, 19 Feb 2022 18:46:50 -0800 (PST) Received: from localhost.localdomain ([116.73.72.178]) by smtp.gmail.com with ESMTPSA id lw16sm3488761pjb.51.2022.02.19.18.46.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Feb 2022 18:46:49 -0800 (PST) From: Jagath Jog J To: jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com, sst@poczta.fm, robh+dt@kernel.org Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 5/7] iio: potentiometer: Add device specific read_raw function Date: Sun, 20 Feb 2022 08:16:30 +0530 Message-Id: <20220220024632.4183-6-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220220024632.4183-1-jagathjog1996@gmail.com> References: <20220220024632.4183-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Added function pointer in the device specific structure to call the appropriate device read_raw function, so that the other type of devices with different read method can be handled. Signed-off-by: Jagath Jog J --- drivers/iio/potentiometer/ds1803.c | 34 ++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/drivers/iio/potentiometer/ds1803.c b/drivers/iio/potentiometer/ds1803.c index 3b86a4106277..1d6175dc4319 100644 --- a/drivers/iio/potentiometer/ds1803.c +++ b/drivers/iio/potentiometer/ds1803.c @@ -31,6 +31,8 @@ struct ds1803_cfg { int kohms; const struct iio_chan_spec *channels; u8 num_channels; + int (*read)(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val); }; struct ds1803_data { @@ -54,16 +56,35 @@ static const struct iio_chan_spec ds1803_channels[] = { DS1803_CHANNEL(1, DS1803_WIPER_1), }; +static int ds1803_read(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val) +{ + struct ds1803_data *data = iio_priv(indio_dev); + int ret; + u8 result[ARRAY_SIZE(ds1803_channels)]; + + ret = i2c_master_recv(data->client, result, indio_dev->num_channels); + if (ret < 0) + return ret; + + *val = result[chan->channel]; + return ret; +} + static const struct ds1803_cfg ds1803_cfg[] = { [DS1803_010] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms = 10, .channels = ds1803_channels, - .num_channels = ARRAY_SIZE(ds1803_channels) }, + .num_channels = ARRAY_SIZE(ds1803_channels), + .read = ds1803_read }, [DS1803_050] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms = 50, .channels = ds1803_channels, - .num_channels = ARRAY_SIZE(ds1803_channels) }, + .num_channels = ARRAY_SIZE(ds1803_channels), + .read = ds1803_read }, [DS1803_100] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms = 100, .channels = ds1803_channels, - .num_channels = ARRAY_SIZE(ds1803_channels) }, + .num_channels = ARRAY_SIZE(ds1803_channels), + .read = ds1803_read }, }; static int ds1803_read_raw(struct iio_dev *indio_dev, @@ -71,20 +92,15 @@ static int ds1803_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct ds1803_data *data = iio_priv(indio_dev); - int pot = chan->channel; int ret; - u8 result[ARRAY_SIZE(ds1803_channels)]; switch (mask) { case IIO_CHAN_INFO_RAW: - ret = i2c_master_recv(data->client, result, - indio_dev->num_channels); + ret = data->cfg->read(indio_dev, chan, val); if (ret < 0) return ret; - *val = result[pot]; return IIO_VAL_INT; - case IIO_CHAN_INFO_SCALE: *val = 1000 * data->cfg->kohms; *val2 = data->cfg->avail[2]; /* Max wiper position */ From patchwork Sun Feb 20 02:46:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12752494 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D125CC43219 for ; Sun, 20 Feb 2022 02:46:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243391AbiBTCrQ (ORCPT ); Sat, 19 Feb 2022 21:47:16 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243395AbiBTCrP (ORCPT ); Sat, 19 Feb 2022 21:47:15 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DB12377C0; Sat, 19 Feb 2022 18:46:53 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id 27so6011637pgk.10; Sat, 19 Feb 2022 18:46:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8mw4ee1LJrxfyyuuaxhOLEBcGc/sqxiZHRacFpkmAkA=; b=AY7W9Q5GaUl50IhGEv8vu9lDJWDqtFUawuJxwqKrn0lkz2LdKvgjrvhDzTJa7rk9ZQ iQrT14ckj2mlwiLfBOyHNOl4qMTxIv34l+tzrTEIhRwUR1Fi1Rla18c3+ytYfltY2wqw ZuGub9elSce+xP95oYxgMf+U7oc4kISu0JWxCBPlRMMtTgjrcolpnuEFLKyomOI9gDGJ Yimhcw89fwx+7jlU5DvC8rqPnjhWCDS8AjClZxgc6OL6ih50x7DxzRHCRAZaRd6K3GKx f7MOrC3pU8Q938dfZjueNKFgLCM++z6oiGiCgdcelBp3oqMXchwY+LpD0sO5I56jrl83 /p4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8mw4ee1LJrxfyyuuaxhOLEBcGc/sqxiZHRacFpkmAkA=; b=adv4FktbX+9+RKeJ02kGFHh0ILl72ujusJN8CN5He5do2rLAdsM7x9Eu5DalSjIugx MVK4xxH1dRN91LZ3OHpZXWU/4Jl6KoPLZrGpOgeW6qBC5d9JZObsOnhr8qWr3Oi+t4LY SvCDhU6cBreNjIu12F1VDCz4lN/m9+NrEw2wdJ+ty+2X3M4mbXejqcdlPJf8wWfasnJk QFNV5zaZRwZZcE+cEkv1wP+OOzw91HBA92hnkTwSuF5o1kyRj2NqJ2tKXl74Efeyl6jX JgnC1ygB+i8W0WIEDBfJh8yY3fFWPo7QpQHUbFNAesrwaSnH8LkJRNpT6n0PPfNE0Jbw 0YYA== X-Gm-Message-State: AOAM530DFs3QVmgy/X/3V9w7zN2mpM2XWHWCho8AvriYWpoAsrCU3n6L tgDqQ1uyMjznZrD0AdKKsPo= X-Google-Smtp-Source: ABdhPJwXxmkznixH0ltMhBA3nqjmCtnIw1nOySQM06n++/BtLwhf5J9XaZGPbesn6fukINyzM1vVhw== X-Received: by 2002:a63:161c:0:b0:372:e459:70e6 with SMTP id w28-20020a63161c000000b00372e45970e6mr11496080pgl.596.1645325212762; Sat, 19 Feb 2022 18:46:52 -0800 (PST) Received: from localhost.localdomain ([116.73.72.178]) by smtp.gmail.com with ESMTPSA id lw16sm3488761pjb.51.2022.02.19.18.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Feb 2022 18:46:52 -0800 (PST) From: Jagath Jog J To: jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com, sst@poczta.fm, robh+dt@kernel.org Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 6/7] iio: potentiometer: Add support for Maxim DS3502 Date: Sun, 20 Feb 2022 08:16:31 +0530 Message-Id: <20220220024632.4183-7-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220220024632.4183-1-jagathjog1996@gmail.com> References: <20220220024632.4183-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The DS3502 is a 7-bit, nonvolatile digital potentiometer featuring an output voltage range of up to 15.5V. DS3502 support is implemented into existing DS1803 driver. Datasheet: https://datasheets.maximintegrated.com/en/ds/DS3502.pdf Signed-off-by: Jagath Jog J --- drivers/iio/potentiometer/Kconfig | 6 +++--- drivers/iio/potentiometer/ds1803.c | 33 +++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig index 832df8da2bc6..01dd3f858d99 100644 --- a/drivers/iio/potentiometer/Kconfig +++ b/drivers/iio/potentiometer/Kconfig @@ -27,11 +27,11 @@ config AD5272 module will be called ad5272. config DS1803 - tristate "Maxim Integrated DS1803 Digital Potentiometer driver" + tristate "Maxim Integrated DS1803 and similar Digital Potentiometer driver" depends on I2C help - Say yes here to build support for the Maxim Integrated DS1803 - digital potentiometer chip. + Say yes here to build support for the Maxim Integrated DS1803 and + DS3502 digital potentiometer chip. To compile this driver as a module, choose M here: the module will be called ds1803. diff --git a/drivers/iio/potentiometer/ds1803.c b/drivers/iio/potentiometer/ds1803.c index 1d6175dc4319..e1e0e81270c0 100644 --- a/drivers/iio/potentiometer/ds1803.c +++ b/drivers/iio/potentiometer/ds1803.c @@ -1,12 +1,15 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Maxim Integrated DS1803 digital potentiometer driver + * Maxim Integrated DS1803 and similar digital potentiometer driver * Copyright (c) 2016 Slawomir Stepien + * Copyright (c) 2022 Jagath Jog J * * Datasheet: https://datasheets.maximintegrated.com/en/ds/DS1803.pdf + * Datasheet: https://datasheets.maximintegrated.com/en/ds/DS3502.pdf * * DEVID #Wipers #Positions Resistor Opts (kOhm) i2c address * ds1803 2 256 10, 50, 100 0101xxx + * ds3502 1 128 10 01010xx */ #include @@ -18,11 +21,13 @@ #define DS1803_WIPER_0 0xA9 #define DS1803_WIPER_1 0xAA +#define DS3502_WR_IVR 0x00 enum ds1803_type { DS1803_010, DS1803_050, DS1803_100, + DS3502, }; struct ds1803_cfg { @@ -56,6 +61,10 @@ static const struct iio_chan_spec ds1803_channels[] = { DS1803_CHANNEL(1, DS1803_WIPER_1), }; +static const struct iio_chan_spec ds3502_channels[] = { + DS1803_CHANNEL(0, DS3502_WR_IVR), +}; + static int ds1803_read(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) @@ -72,6 +81,21 @@ static int ds1803_read(struct iio_dev *indio_dev, return ret; } +static int ds3502_read(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val) +{ + struct ds1803_data *data = iio_priv(indio_dev); + int ret; + + ret = i2c_smbus_read_byte_data(data->client, chan->address); + if (ret < 0) + return ret; + + *val = ret; + return ret; +} + static const struct ds1803_cfg ds1803_cfg[] = { [DS1803_010] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms = 10, .channels = ds1803_channels, @@ -85,6 +109,10 @@ static const struct ds1803_cfg ds1803_cfg[] = { .channels = ds1803_channels, .num_channels = ARRAY_SIZE(ds1803_channels), .read = ds1803_read }, + [DS3502] = { .wipers = 1, .avail = { 0, 1, 127 }, .kohms = 10, + .channels = ds3502_channels, + .num_channels = ARRAY_SIZE(ds3502_channels), + .read = ds3502_read }, }; static int ds1803_read_raw(struct iio_dev *indio_dev, @@ -186,6 +214,7 @@ static const struct of_device_id ds1803_dt_ids[] = { { .compatible = "maxim,ds1803-010", .data = &ds1803_cfg[DS1803_010] }, { .compatible = "maxim,ds1803-050", .data = &ds1803_cfg[DS1803_050] }, { .compatible = "maxim,ds1803-100", .data = &ds1803_cfg[DS1803_100] }, + { .compatible = "maxim,ds3502", .data = &ds1803_cfg[DS3502] }, {} }; MODULE_DEVICE_TABLE(of, ds1803_dt_ids); @@ -194,6 +223,7 @@ static const struct i2c_device_id ds1803_id[] = { { "ds1803-010", DS1803_010 }, { "ds1803-050", DS1803_050 }, { "ds1803-100", DS1803_100 }, + { "ds3502", DS3502 }, {} }; MODULE_DEVICE_TABLE(i2c, ds1803_id); @@ -210,5 +240,6 @@ static struct i2c_driver ds1803_driver = { module_i2c_driver(ds1803_driver); MODULE_AUTHOR("Slawomir Stepien "); +MODULE_AUTHOR("Jagath Jog J "); MODULE_DESCRIPTION("DS1803 digital potentiometer"); MODULE_LICENSE("GPL v2"); From patchwork Sun Feb 20 02:46:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12752495 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E2CCC433F5 for ; Sun, 20 Feb 2022 02:46:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243402AbiBTCrR (ORCPT ); Sat, 19 Feb 2022 21:47:17 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243383AbiBTCrP (ORCPT ); Sat, 19 Feb 2022 21:47:15 -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 EABD31C90F; Sat, 19 Feb 2022 18:46:55 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id i6so5623515pfc.9; Sat, 19 Feb 2022 18:46:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Bcgt5PK1Q0mp9E0RmLUvcE/cB/2glUg86KZveaMOtXU=; b=BmAjtEQEM9r/wz6eZy1u2L5LtdFTRms4kStp5rAyOZKT+oN4W1jMEai/f7FrOkLN1+ BwY1KHsZbVD9JHxrqTxwfmDVxg89lavZEi+MChzupH3SNaZkVth8x1wyTCXA1aowcXLK k0O7PcWVqGLAdMTHF7No+c7oFsyMofq/L+8NUNBcElJ3MxvXg8z+huwrmcvrDs7Xshyu AYBMmfWN+5VCObIBmUxoSd4esT/gVwzrBJ2G3zCUNvKuM4IhBJwTA9LJP9pIrpGtEnrD TPsOpbZ1ZE0NjYRydJ3UrtGy8MwO1B1H2NEiQ/FhoWNyYc1FI5T4HCOHtec4sZHQME4Q Y8hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Bcgt5PK1Q0mp9E0RmLUvcE/cB/2glUg86KZveaMOtXU=; b=ig3W5n9mBhEn/MHQTkiA3pDrdSwqHmMzscpMrzcgDo1oa9y2XW2qHkurDTHkeLB6gH tNGsIWl0e12jRDU/8qQdnI6T5i6wOzZwpNnJMBCA6l8gU1l0YcdqCEWPuybmATHW/QBY XrXfRCxq2ydsNAquEXoSlExv6QR2nkLpWY+tckNHtSIOejB9VMKmnj4yXOxoJGV+1vkx 5g1quPhhCrH0fBTyHi+D5YshIkNF7MiUpGI948KOAV6vL018/4dHRSGvcwqK2Ocfd4+g pLByPhZbQHKqDHiEWEB1cULqZdiup2uaOrHl1BnszAUNqikJ5+K1DoDlluZzSQWIUD2D OCvA== X-Gm-Message-State: AOAM5330clXiAg0EzQ7VWFTv7NH1rt7PP5lz8G8o3BnAVPS58EEpANJ7 YJA84skRTFvU+wqhfMlwXRM= X-Google-Smtp-Source: ABdhPJwhy59ao+hpCRKA/0ilPaaqLNwB0oUCU9MeUz+s5LBO/LHDvOLyfFYxnJEu+nAUWRV4kVecAA== X-Received: by 2002:a05:6a00:278d:b0:4e1:4534:8801 with SMTP id bd13-20020a056a00278d00b004e145348801mr14197924pfb.78.1645325215383; Sat, 19 Feb 2022 18:46:55 -0800 (PST) Received: from localhost.localdomain ([116.73.72.178]) by smtp.gmail.com with ESMTPSA id lw16sm3488761pjb.51.2022.02.19.18.46.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Feb 2022 18:46:55 -0800 (PST) From: Jagath Jog J To: jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com, sst@poczta.fm, robh+dt@kernel.org Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 7/7] dt-bindings: iio: potentiometer: Add Maxim DS3502 in trivial-devices Date: Sun, 20 Feb 2022 08:16:32 +0530 Message-Id: <20220220024632.4183-8-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220220024632.4183-1-jagathjog1996@gmail.com> References: <20220220024632.4183-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Maxim DS3502 is a 7 bit nonvolatile digital potentiometer. Add DS3502 binding into trivial-devices.yaml. Signed-off-by: Jagath Jog J Acked-by: Rob Herring --- Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/trivial-devices.yaml b/Documentation/devicetree/bindings/trivial-devices.yaml index 091792ba993e..b6187603317a 100644 --- a/Documentation/devicetree/bindings/trivial-devices.yaml +++ b/Documentation/devicetree/bindings/trivial-devices.yaml @@ -157,6 +157,8 @@ properties: - maxim,ds1803-050 # 100 kOhm digital potentiometer with I2C interface - maxim,ds1803-100 + # 10 kOhm digital potentiometer with I2C interface + - maxim,ds3502 # Low-Power, 4-/12-Channel, 2-Wire Serial, 12-Bit ADCs - maxim,max1237 # Temperature Sensor, I2C interface