From patchwork Mon Feb 14 03:36:17 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: 12744858 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 E9820C433EF for ; Mon, 14 Feb 2022 03:36:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237674AbiBNDgh (ORCPT ); Sun, 13 Feb 2022 22:36:37 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:58804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231682AbiBNDge (ORCPT ); Sun, 13 Feb 2022 22:36:34 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DA1855499; Sun, 13 Feb 2022 19:36:28 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id y18so9493435plb.11; Sun, 13 Feb 2022 19:36:28 -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=5VhvayD2Jc8dwud20cGrPE69DlH/zxn3R9XFQ9KzGKE=; b=VtkVHw4rLG4MqsijMorJoABoJyrczVKpYJBrRVPFXIwb1jIEWviZny0RrErLo9IevO oF//xlli/i5MJKX5d5yS1B7XWBbRY/HkebLfWv10WIXZLevgG37LPYF6+XzjMLRHk00g 0x6W/F9ATyYNFrqgZERcAkuoVEZpmPakNSgjmGs0YATMsbWrAFaAios844X+/sT8E60o x8eZmSooydFgvpkdooIVBQbEEeq3OC/MqGqJ49L3F725XTE5YxoAVZVkZYUI4zA2RPzp huXn04mv6Zo4z3impbXBFCwClcFTKl3Q3cKMiN3HfxQtAEv+tvXHiiGemdTyHFIecrSD s5dw== 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=5VhvayD2Jc8dwud20cGrPE69DlH/zxn3R9XFQ9KzGKE=; b=mqOBKOiGYyqyaW8c0SV0EB895/rRbt0EyWlXznrvO0/3Pd5OFAGP3pfzleOvN5rxPh rad+6Wg72EMcvs/5Bp0HbpB+HIkzsPWHuf9nqgXYqjb6QZzz+5Nb9hnws0TPGJ9iGyP5 e+B9Xn9aXKuBfk+RzRNwTez7R+31Th+PUTLku9xilahv++nkc8RpkGAbTlm8rGlA+N2l 8kky91h2M+9Df7Z8XXgYpdRnEdQ/ViCXDcwDmTXxebTwRRRRH9zbf2bZ5dgrfHuVRku1 KG3rOEw7/LJjdZ3fPRI5WbJz8rZZ96VN7Mg9GaYvfLjY5ocdSs4iHwLnnqSDJwjp498m OnWA== X-Gm-Message-State: AOAM533BHwEEAtXDnw58Hu8fLJWgsE9ecl5hskJy6x0/0I4PmLcypL2d vKXO2iCBLKPuJfAamLUU3c4= X-Google-Smtp-Source: ABdhPJw2APNMGXAeRL3m60gWQS+lNR5Vw+G3zphDeTd3UndF75Lv77FwwcF0JT2Q8szCRHBazvp/OQ== X-Received: by 2002:a17:902:eb85:: with SMTP id q5mr323264plg.173.1644809787778; Sun, 13 Feb 2022 19:36:27 -0800 (PST) Received: from localhost.localdomain ([27.7.103.158]) by smtp.gmail.com with ESMTPSA id me14sm36012pjb.41.2022.02.13.19.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Feb 2022 19:36:27 -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 v2 1/4] iio: potentiometer: Alignment to match the open parenthesis Date: Mon, 14 Feb 2022 09:06:17 +0530 Message-Id: <20220214033620.4059-2-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220214033620.4059-1-jagathjog1996@gmail.com> References: <20220214033620.4059-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Fix following checkpatch.pl check by removing black space CHECK: Alignment should match open parenthesis Signed-off-by: Jagath Jog J --- drivers/iio/potentiometer/ds1803.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/iio/potentiometer/ds1803.c b/drivers/iio/potentiometer/ds1803.c index 20b45407eaac..3481dd460525 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; @@ -110,7 +110,7 @@ static const struct iio_info ds1803_info = { }; static int ds1803_probe(struct i2c_client *client, - const struct i2c_device_id *id) + const struct i2c_device_id *id) { struct device *dev = &client->dev; struct ds1803_data *data; From patchwork Mon Feb 14 03:36:18 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: 12744859 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 2B4F3C433EF for ; Mon, 14 Feb 2022 03:36:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240020AbiBNDgl (ORCPT ); Sun, 13 Feb 2022 22:36:41 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:58864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231682AbiBNDgj (ORCPT ); Sun, 13 Feb 2022 22:36:39 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 172B855BEB; Sun, 13 Feb 2022 19:36:31 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id z17so9496403plb.9; Sun, 13 Feb 2022 19:36:31 -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=G7KqLxqPXt/++zKfasndyL6p23tdrDEEEjd2RPr4XZo=; b=Pc7IxxDbPMy2UhDaeNT6VbKrKdAb8RyVUEzmuNZ+LoKtxXGF5Quz9RWZm8uv3JqQ/o xuK7wnKECOSpAO/KIt+8UPJjpXsc8FMHa11rkrhHl+ZWQhbDntA99DmKBtT+TWpxYV8o WLrwupk7DSZaCgltu+WtqclK5cogCElvYJ0n+tNR0ON7gpwmNnuhQS25TYlSz2CoPpku uDUE7cY7h0qGQxhq6nVWUI6lxJPPCSwG6F+pHDDRT5LscxJf6igszJrM/ynVL2pYeJNU ZCKSDe3e91iS/0Wdd5Ix004ap+ggZ4FRfNMDJfMXcSn5kkWqJRIhupn+Eh4Db5EZLgbi A59Q== 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=G7KqLxqPXt/++zKfasndyL6p23tdrDEEEjd2RPr4XZo=; b=WcZsgoCWQV8RNbENufSZjZH3whljPdN5RbbCciD5KeEPvGsh3Cb7EIKQdwBGNrfEia xUkTBwssXxcoOpxlCZIaGHpaFTVWuSqsCojV7UEBb+xXKd/7nU/Q/CTiWRl9HPo6XW7G CcTLxslIYY/l5j/5U7F34TF975xbg/c9DQCvA5hY4iQy2gxSxjlwV+4dcxgLXJiIyK+r wypNsN9hEAlOd/Qsc/xjTAmSkbHcMbaAdxk/PLWodEPsCZM3K31oecEHnTpwRuJF8ZKA M8W0bi6kqRvRQDkdjRWp2f3skWa7g5mcmj3gyHWhkxxe4Td99N5zA5GbWIHuWZkJ34+G jFLw== X-Gm-Message-State: AOAM531s8+ZKhIDTjVutlNEYvkN3MK5/RmZH2gd5kX3zsI+SEFAJnF9c ZxomXS/h+pht29TYAJ6TaKQ= X-Google-Smtp-Source: ABdhPJxFip/rAnmBpWGFq5IRDYYEHXGsve+3nLRSSiVFjg1Xq6Mu6k+N4QorJjdWtWg0Y0DwQc88VA== X-Received: by 2002:a17:902:778b:: with SMTP id o11mr4796423pll.87.1644809790406; Sun, 13 Feb 2022 19:36:30 -0800 (PST) Received: from localhost.localdomain ([27.7.103.158]) by smtp.gmail.com with ESMTPSA id me14sm36012pjb.41.2022.02.13.19.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Feb 2022 19:36:30 -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 v2 2/4] iio: potentiometer: Add available functionality Date: Mon, 14 Feb 2022 09:06:18 +0530 Message-Id: <20220214033620.4059-3-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220214033620.4059-1-jagathjog1996@gmail.com> References: <20220214033620.4059-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 it can accepts through sysfs entry. Signed-off-by: Jagath Jog J --- drivers/iio/potentiometer/ds1803.c | 38 ++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/drivers/iio/potentiometer/ds1803.c b/drivers/iio/potentiometer/ds1803.c index 3481dd460525..bccb9ccac931 100644 --- a/drivers/iio/potentiometer/ds1803.c +++ b/drivers/iio/potentiometer/ds1803.c @@ -27,12 +27,13 @@ enum ds1803_type { struct ds1803_cfg { int kohms; + int avail[3]; }; static const struct ds1803_cfg ds1803_cfg[] = { - [DS1803_010] = { .kohms = 10, }, - [DS1803_050] = { .kohms = 50, }, - [DS1803_100] = { .kohms = 100, }, + [DS1803_010] = { .avail = { 0, 1, 255 }, .kohms = 10, }, + [DS1803_050] = { .avail = { 0, 1, 255 }, .kohms = 50, }, + [DS1803_100] = { .avail = { 0, 1, 255 }, .kohms = 100, }, }; struct ds1803_data { @@ -40,13 +41,14 @@ struct ds1803_data { 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[] = { @@ -104,9 +106,25 @@ 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, From patchwork Mon Feb 14 03:36:19 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: 12744860 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 4B5F0C4332F for ; Mon, 14 Feb 2022 03:36:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240030AbiBNDgl (ORCPT ); Sun, 13 Feb 2022 22:36:41 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:58888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240016AbiBNDgk (ORCPT ); Sun, 13 Feb 2022 22:36:40 -0500 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EBA45549F; Sun, 13 Feb 2022 19:36:33 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id f6so5988116pfj.11; Sun, 13 Feb 2022 19:36:33 -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=Nv4JMXgMO20d7B2ax+48GScvasA65BFCFc5OkzevOTQ=; b=qlE73LKY0kBePfGFTxDbJIXAQQeLmyp+GS/34vW7PPnrmzGfnXQLcZJ/qRC0kkQNcB fF8k3/lz9HiVxVLAEriZtY+/Bm3jfa1ATAddQRsy7/3458uy+jBzedIapK+bgZ9+ifPh 6sRy4Wt6JZ+WRigwuxrB85Hda6VnTFmXDe/2GbIXRNwTMWmQo+qkmgTF0VYakketlk2G g6fAhXA09NWxPTQz6VQywo38TyL0weNR1KrYzpZzNIRc9AcTxrC6o8DU2LRnhKHmUU+f xPe/e7hP+kPw0iMV4RGWARexdm6lV8E9rbauXqFT8zuGw6Wgjga1E1oATntdmlnWhkOF XGCg== 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=Nv4JMXgMO20d7B2ax+48GScvasA65BFCFc5OkzevOTQ=; b=TVgu+XNeakrhD/lNH9ghBVdK9kucCJpeT3PxxJpXszHn3UYWvtFZBYtb9z8smOSYi6 oGc3eiNsA0QGiC7z+UFkTOeLznmM/6xTFMPUXwkQluYlnJyaviOfya9zW1IRJg/znipp 98ABSbclqVa5LfGbRog44lftwmSKJDJzZmUyrufufZqC3YjJNDpLdL2Xuvo352+SmumV d0cbKvA9VgpubbZeEEjP8g3LF0MnMLxqKahP4GT7Ri+g2ZH4Uf7qVnsuSaUQ4Gy0dVt5 xPxKZCuFn15XcFvBtvN+2iShC7aW3x4PLpN/HOgrl/PxKiB7ndUM6KflCmEYOpRfPaku caLQ== X-Gm-Message-State: AOAM532YUnjAW5HXExte1Zqrs6Agrjo5V/EOYKEhwgdDoKDk67Hy8zN+ mOWXNaSJo8mj7axy7lMe1Gk= X-Google-Smtp-Source: ABdhPJzo22jpHlKs2Q/5p+4d57dolvve3lfK53/i2MmdK+JcTaVF2vjUVEwfBXvLag8jWxxZAp5sqQ== X-Received: by 2002:a63:8a:: with SMTP id 132mr10192837pga.338.1644809793069; Sun, 13 Feb 2022 19:36:33 -0800 (PST) Received: from localhost.localdomain ([27.7.103.158]) by smtp.gmail.com with ESMTPSA id me14sm36012pjb.41.2022.02.13.19.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Feb 2022 19:36:32 -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 v2 3/4] iio: potentiometer: Add support for Maxim DS3502 Date: Mon, 14 Feb 2022 09:06:19 +0530 Message-Id: <20220214033620.4059-4-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220214033620.4059-1-jagathjog1996@gmail.com> References: <20220214033620.4059-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 | 101 ++++++++++++++++++++--------- 2 files changed, 75 insertions(+), 32 deletions(-) diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig index 832df8da2bc6..cd9aaceb15fe 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 + similar 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 bccb9ccac931..0990536e7f36 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 @@ -16,44 +19,64 @@ #include #include -#define DS1803_MAX_POS 255 -#define DS1803_WRITE(chan) (0xa8 | ((chan) + 1)) +#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 { + int wipers; int kohms; int avail[3]; -}; - -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, }, + const struct iio_chan_spec *channels; + u8 num_channels; }; struct ds1803_data { struct i2c_client *client; const struct ds1803_cfg *cfg; + enum ds1803_type chip_type; }; -#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 iio_chan_spec ds3502_channels[] = { + DS1803_CHANNEL(0, DS3502_WR_IVR), +}; + +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) }, + [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) }, + [DS3502] = { .wipers = 1, .avail = { 0, 1, 127 }, .kohms = 10, + .channels = ds3502_channels, + .num_channels = ARRAY_SIZE(ds3502_channels) }, }; static int ds1803_read_raw(struct iio_dev *indio_dev, @@ -67,17 +90,30 @@ 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); - if (ret < 0) - return ret; - - *val = result[pot]; - return IIO_VAL_INT; + switch (data->chip_type) { + case DS1803_010: + case DS1803_050: + case DS1803_100: + ret = i2c_master_recv(data->client, result, + indio_dev->num_channels); + if (ret < 0) + return ret; + *val = result[pot]; + return IIO_VAL_INT; + case DS3502: + ret = i2c_smbus_read_byte_data(data->client, + chan->address); + if (ret < 0) + return ret; + *val = ret; + return IIO_VAL_INT; + default: + return -EINVAL; + } 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; } @@ -89,21 +125,22 @@ 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; + int max_pos = data->cfg->avail[2]; + u8 addr = chan->address; 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: 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, struct iio_chan_spec const *chan, @@ -142,20 +179,24 @@ static int ds1803_probe(struct i2c_client *client, data = iio_priv(indio_dev); data->client = client; - data->cfg = &ds1803_cfg[id->driver_data]; + data->chip_type = (uintptr_t)device_get_match_data(dev); + if (data->chip_type < DS1803_010 || data->chip_type > DS3502) + data->chip_type = id->driver_data; + data->cfg = &ds1803_cfg[data->chip_type]; 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); } 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,ds1803-010", .data = (void *)DS1803_010 }, + { .compatible = "maxim,ds1803-050", .data = (void *)DS1803_050 }, + { .compatible = "maxim,ds1803-100", .data = (void *)DS1803_100 }, + { .compatible = "maxim,ds3502", .data = (void *)DS3502 }, {} }; MODULE_DEVICE_TABLE(of, ds1803_dt_ids); @@ -164,6 +205,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); @@ -180,5 +222,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 Mon Feb 14 03:36:20 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: 12744861 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 01591C433EF for ; Mon, 14 Feb 2022 03:36:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240034AbiBNDgn (ORCPT ); Sun, 13 Feb 2022 22:36:43 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:58958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240041AbiBNDgn (ORCPT ); Sun, 13 Feb 2022 22:36:43 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46F0A554A7; Sun, 13 Feb 2022 19:36:36 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id r64-20020a17090a43c600b001b8854e682eso14534512pjg.0; Sun, 13 Feb 2022 19:36:36 -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=71JHL6a4At1Gw4scubZ3vrvM30dBBl26C7Z0Kh+8KMw=; b=mZ49mRwWfDmp3iYBkllMhJUkVa5kQuZpd+tynyl22CyLrHhIC3fx64g/1Q7S2g7lEc eLpsWpkuqT4sdLWBzIFqTWd64JfL4lMr3hSR3Zwar4fkMlMHDcqaQZJkFOg0yXFrvox2 d4X96a9ngFGaJ1pVKLuUY4QMnJU/Rkjolg+gZjaCrPwkfaq2Ao7q/GTD4wE3ByHmmoVS C5ELJ1k2FngJwFF7JL/kS4Un1dOevBvgCwPNJi8tw/ECedIh0gArM/5OuWxVUocwEcot 3zj0exIZnjEkX0LObu9DPwORJiWEOyivpnRiLPb+KpvAwHYfZf9XQUCCVoAwoqdhN+yh H81A== 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=71JHL6a4At1Gw4scubZ3vrvM30dBBl26C7Z0Kh+8KMw=; b=Td5jr+uhABpKdxcrl6KoH8ZDmfHtuS81TjniYYHjOjm4N68nem2OUsmHer/Mo1maH8 PRQ08RxOtEjA24PQeck76nTE14mrxTQz+n3EIuMrQYYa+YzuwJG5m7ny//FLIPg/3MiS 9yryBbSsUsjbjC0bKOFYhCympivNvxgfI0YZht0+8FJ9li0wHihvcOqeRn8zRZUlUBsu 89Pjb/5+k5DgM+oyHAO561WxoUqwk+ckagWfQCYnmiq/19RQmGrauKWKD6o1Yda0ECkr nkt760DfykBdNxGQIGFUgG5l+FaRexYmCsEQUMSqNtWGn+dmP0vhI33oEZF3yzvemS5v FuYA== X-Gm-Message-State: AOAM532L8ohaILunrkRxPp6bZ6kJpPYWIGy8QlL3FJsmmdGllbH4LMdX 8Z3ynM8cDRGNaaTLFv+eM3Y= X-Google-Smtp-Source: ABdhPJx/R5tfH6vto0gngrbOJJ/rpDiBT4GsalobpJjtB0kxAQ+xAf5xQ1Ma314sAFn2pJWPguNKHw== X-Received: by 2002:a17:902:db07:: with SMTP id m7mr7217884plx.107.1644809795730; Sun, 13 Feb 2022 19:36:35 -0800 (PST) Received: from localhost.localdomain ([27.7.103.158]) by smtp.gmail.com with ESMTPSA id me14sm36012pjb.41.2022.02.13.19.36.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Feb 2022 19:36:35 -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 v2 4/4] dt-bindings: iio: potentiometer: Add Maxim DS3502 in trivial-devices Date: Mon, 14 Feb 2022 09:06:20 +0530 Message-Id: <20220214033620.4059-5-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220214033620.4059-1-jagathjog1996@gmail.com> References: <20220214033620.4059-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 --- 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