From patchwork Tue Jul 27 23:29:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 12404641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F18E6C4338F for ; Tue, 27 Jul 2021 23:29:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D86BE60FC2 for ; Tue, 27 Jul 2021 23:29:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233680AbhG0X31 (ORCPT ); Tue, 27 Jul 2021 19:29:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233248AbhG0X3Y (ORCPT ); Tue, 27 Jul 2021 19:29:24 -0400 Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17620C061760; Tue, 27 Jul 2021 16:29:23 -0700 (PDT) Received: by mail-qk1-x734.google.com with SMTP id t68so471203qkf.8; Tue, 27 Jul 2021 16:29:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7ZvGxca2T5yVy2NGNqrtVScB3QVnEfEEyh0E6AQOPKc=; b=T4bSUjbJmH2p0gAddGlgvEhJtTNXR2Mea0clf+LifO7K6E9IsyhSggGWlDMliWKbPL zsJCbkPquUoc10yXignRvGwtpT11Y9K00F8UeEw6uWTbQgQu5lwUKgqLblEthdLVMVb4 TanawNWbPhUBHW5jrAC4awpiUqWYcElneL56ZjRWFj9JaF5lr1an/9u0v7GwbrINvHMu pHT9QC+Nw5Youio1sLMabINgBbpvmZLG5o6jT0ml1bT6wa5uq3XWoIU/bFkHKt1pG26b tgltoTCISuMZDhEQmPcY7Ajc2iMCnm8EiPoNUjUhK9XEhaI7J8jLMji2FzV9QRNDS0S8 G+zA== 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:mime-version:content-transfer-encoding; bh=7ZvGxca2T5yVy2NGNqrtVScB3QVnEfEEyh0E6AQOPKc=; b=IvBx43l73y4vIczoi8Nj8Mr0Ccrhjy6pPGk4qaMmpboFD4SLDLy52Ug6d1mqAa/FeO wS1WU0Cu3b9++DHbEZvLOe/VbJ1F6LTKfEcLAHH+N8jB8FcRoKkweJJUczhCp6r5Iol6 d1S/bma/MQJKNx9HRKcGM++Lg6dEdjMtDWfmqeEffcjGMeotcH/aQZFCspP17/NrmRlb 69qiVl6FIBBdCIR2zvTLJIbnsJ06TsnIa2XLVHtaaTRd3JkCrltZVrcKyDsvJDvnu2x7 f5HZ5T8FRasELOpbFnYYQnxYPsIpBdnq+tKMGSNhd4TwYgLBuObmnWVV2fiftO3WSvfc qHhw== X-Gm-Message-State: AOAM530oOg7ChIzMa2ds2o7t5HR6RS2iKdKpCnUr7v6g3MMtjtDJQKA2 qr5hN+DKvPA6+zhpjM4zBc4= X-Google-Smtp-Source: ABdhPJySfU4EXVnLjVIgS2AmEhizcSCLA1KLOkkpQq34H/w73fwonxyoFsjzX2SrUijd0I6D02NG6Q== X-Received: by 2002:a37:ef05:: with SMTP id j5mr110877qkk.175.1627428562310; Tue, 27 Jul 2021 16:29:22 -0700 (PDT) Received: from shaak.xiphos.ca (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id p188sm2380514qka.114.2021.07.27.16.29.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jul 2021 16:29:21 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, charles-antoine.couret@essensium.com, Nuno.Sa@analog.com Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v4 1/5] iio: adc: ad7949: define and use bitfield names Date: Tue, 27 Jul 2021 19:29:02 -0400 Message-Id: <20210727232906.980769-2-liambeguin@gmail.com> X-Mailer: git-send-email 2.30.1.489.g328c10930387 In-Reply-To: <20210727232906.980769-1-liambeguin@gmail.com> References: <20210727232906.980769-1-liambeguin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Liam Beguin Replace raw configuration register values by using FIELD_PREP and defines to improve readability. Signed-off-by: Liam Beguin --- drivers/iio/adc/ad7949.c | 50 +++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/drivers/iio/adc/ad7949.c b/drivers/iio/adc/ad7949.c index 1b4b3203e428..0b549b8bd7a9 100644 --- a/drivers/iio/adc/ad7949.c +++ b/drivers/iio/adc/ad7949.c @@ -11,12 +11,37 @@ #include #include #include +#include -#define AD7949_MASK_CHANNEL_SEL GENMASK(9, 7) #define AD7949_MASK_TOTAL GENMASK(13, 0) -#define AD7949_OFFSET_CHANNEL_SEL 7 -#define AD7949_CFG_READ_BACK 0x1 -#define AD7949_CFG_REG_SIZE_BITS 14 + +/* CFG: Configuration Update */ +#define AD7949_CFG_BIT_OVERWRITE BIT(13) + +/* INCC: Input Channel Configuration */ +#define AD7949_CFG_BIT_INCC GENMASK(12, 10) +#define AD7949_CFG_VAL_INCC_UNIPOLAR_GND 7 +#define AD7949_CFG_VAL_INCC_UNIPOLAR_COMM 6 +#define AD7949_CFG_VAL_INCC_UNIPOLAR_DIFF 4 +#define AD7949_CFG_VAL_INCC_TEMP 3 +#define AD7949_CFG_VAL_INCC_BIPOLAR 2 +#define AD7949_CFG_VAL_INCC_BIPOLAR_DIFF 0 + +/* INX: Input channel Selection in a binary fashion */ +#define AD7949_CFG_BIT_INX GENMASK(9, 7) + +/* BW: select bandwidth for low-pass filter. Full or Quarter */ +#define AD7949_CFG_BIT_BW_FULL BIT(6) + +/* REF: reference/buffer selection */ +#define AD7949_CFG_BIT_REF GENMASK(5, 3) +#define AD7949_CFG_VAL_REF_EXT_BUF 7 + +/* SEQ: channel sequencer. Allows for scanning channels */ +#define AD7949_CFG_BIT_SEQ GENMASK(2, 1) + +/* RB: Read back the CFG register */ +#define AD7949_CFG_BIT_RBN BIT(0) enum { ID_AD7949 = 0, @@ -109,8 +134,8 @@ static int ad7949_spi_read_channel(struct ad7949_adc_chip *ad7949_adc, int *val, */ for (i = 0; i < 2; i++) { ret = ad7949_spi_write_cfg(ad7949_adc, - channel << AD7949_OFFSET_CHANNEL_SEL, - AD7949_MASK_CHANNEL_SEL); + FIELD_PREP(AD7949_CFG_BIT_INX, channel), + AD7949_CFG_BIT_INX); if (ret) return ret; if (channel == ad7949_adc->current_channel) @@ -214,10 +239,19 @@ static int ad7949_spi_init(struct ad7949_adc_chip *ad7949_adc) { int ret; int val; + u16 cfg; - /* Sequencer disabled, CFG readback disabled, IN0 as default channel */ ad7949_adc->current_channel = 0; - ret = ad7949_spi_write_cfg(ad7949_adc, 0x3C79, AD7949_MASK_TOTAL); + + cfg = FIELD_PREP(AD7949_CFG_BIT_OVERWRITE, 1) | + FIELD_PREP(AD7949_CFG_BIT_INCC, AD7949_CFG_VAL_INCC_UNIPOLAR_GND) | + FIELD_PREP(AD7949_CFG_BIT_INX, ad7949_adc->current_channel) | + FIELD_PREP(AD7949_CFG_BIT_BW_FULL, 1) | + FIELD_PREP(AD7949_CFG_BIT_REF, AD7949_CFG_VAL_REF_EXT_BUF) | + FIELD_PREP(AD7949_CFG_BIT_SEQ, 0x0) | + FIELD_PREP(AD7949_CFG_BIT_RBN, 1); + + ret = ad7949_spi_write_cfg(ad7949_adc, cfg, AD7949_MASK_TOTAL); /* * Do two dummy conversions to apply the first configuration setting. From patchwork Tue Jul 27 23:29:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 12404637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87AFDC4320E for ; Tue, 27 Jul 2021 23:29:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E08760F9C for ; Tue, 27 Jul 2021 23:29:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233605AbhG0X31 (ORCPT ); Tue, 27 Jul 2021 19:29:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233420AbhG0X3Z (ORCPT ); Tue, 27 Jul 2021 19:29:25 -0400 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1569CC061764; Tue, 27 Jul 2021 16:29:24 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id t68so471236qkf.8; Tue, 27 Jul 2021 16:29:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aXrlAfidCULyhP2C11Xrjur7fmsiuYHq0Us9S4wnzkQ=; b=gIzyt668qkm1C+SQ12wfGDyG9bhQPELGz27s398YHVcbPusIriEZ7He1V76wkVB0kI lrTNSNHCkBNKcaQSR66wGYA2/TACwIv+njZJntg9BcMANkzikPaQFIVe9znH/kn5de7a eGLDjLp8FW89y9CEQOIrplgJH0xBCkVfoxV1o/tKPBFHkzAMe6t0wcYQqCl+L8Icvn4t CzpsF9d7AAwfQQLg+mimXQdlwxovUu6WnX4P01MR7Bxmd4HvlgHTxqIXZ5WfwqX8GTgr v+v2rOGVni5lmuUrjyOgGQXfPTKN3w/8hDLEsbis/OTYFcWdsUoJDMXJ97b7f8wmLfh2 Wyxg== 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:mime-version:content-transfer-encoding; bh=aXrlAfidCULyhP2C11Xrjur7fmsiuYHq0Us9S4wnzkQ=; b=UXRNjU8qw9JZlIciRhSJFH1teIItsxeSaq5gRvZwG4tVLkOZaKIMMnFSi/1p11m1KW 7xCOwrOqozsUcsXARmtRBUDTa5kNhEjedaPBaTVSRSuDCbQRuLThzGJsjYKSzP8mJnM0 xYZTsJsphUPllEwNm/5wgDisv9s5100BEH8EaFt72y1bX779wVDBfhosz0Fw1en7eby/ HQVmYuYZMy+ifIJQJ6R26kev5KyA63WktOuuptQC2w4Z6Kl2kImPXlp5IVqqdlp3hf1j /9tJB4n0cT6CCuPGziQq7hgkLL3Ud1tM+ihCwcjEMnlr8yGBntGaPplf3FKP7c/57zRw BY0A== X-Gm-Message-State: AOAM531YTBd3OmgCPjpTkYr8BYMPX4kUeljMG9FAVU/VCNu4DDvZlgYJ Q4cRwH6fEoD0io2BhD4eocc= X-Google-Smtp-Source: ABdhPJyzpYemZkEjJj0ZWcsM0ooRGuVjQq5r3foqRQ0j9iwfbH9uAKjAYpDPVk/SjlsdBvp/dZj88Q== X-Received: by 2002:a05:620a:4d5:: with SMTP id 21mr24466871qks.397.1627428563312; Tue, 27 Jul 2021 16:29:23 -0700 (PDT) Received: from shaak.xiphos.ca (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id p188sm2380514qka.114.2021.07.27.16.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jul 2021 16:29:22 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, charles-antoine.couret@essensium.com, Nuno.Sa@analog.com Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v4 2/5] iio: adc: ad7949: fix spi messages on non 14-bit controllers Date: Tue, 27 Jul 2021 19:29:03 -0400 Message-Id: <20210727232906.980769-3-liambeguin@gmail.com> X-Mailer: git-send-email 2.30.1.489.g328c10930387 In-Reply-To: <20210727232906.980769-1-liambeguin@gmail.com> References: <20210727232906.980769-1-liambeguin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Liam Beguin This driver supports devices with 14-bit and 16-bit sample sizes. This is not always handled properly by spi controllers and can fail. To work around this limitation, pad samples to 16-bit and split the sample into two 8-bit messages in the event that only 8-bit messages are supported by the controller. Signed-off-by: Liam Beguin --- drivers/iio/adc/ad7949.c | 62 ++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/drivers/iio/adc/ad7949.c b/drivers/iio/adc/ad7949.c index 0b549b8bd7a9..f1702c54c8be 100644 --- a/drivers/iio/adc/ad7949.c +++ b/drivers/iio/adc/ad7949.c @@ -67,6 +67,7 @@ static const struct ad7949_adc_spec ad7949_adc_spec[] = { * @indio_dev: reference to iio structure * @spi: reference to spi structure * @resolution: resolution of the chip + * @bits_per_word: number of bits per SPI word * @cfg: copy of the configuration register * @current_channel: current channel in use * @buffer: buffer to send / receive data to / from device @@ -77,6 +78,7 @@ struct ad7949_adc_chip { struct iio_dev *indio_dev; struct spi_device *spi; u8 resolution; + u8 bits_per_word; u16 cfg; unsigned int current_channel; u16 buffer ____cacheline_aligned; @@ -86,19 +88,34 @@ static int ad7949_spi_write_cfg(struct ad7949_adc_chip *ad7949_adc, u16 val, u16 mask) { int ret; - int bits_per_word = ad7949_adc->resolution; - int shift = bits_per_word - AD7949_CFG_REG_SIZE_BITS; struct spi_message msg; struct spi_transfer tx[] = { { .tx_buf = &ad7949_adc->buffer, .len = 2, - .bits_per_word = bits_per_word, + .bits_per_word = ad7949_adc->bits_per_word, }, }; + ad7949_adc->buffer = 0; ad7949_adc->cfg = (val & mask) | (ad7949_adc->cfg & ~mask); - ad7949_adc->buffer = ad7949_adc->cfg << shift; + + switch (ad7949_adc->bits_per_word) { + case 16: + ad7949_adc->buffer = ad7949_adc->cfg << 2; + break; + case 14: + ad7949_adc->buffer = ad7949_adc->cfg; + break; + case 8: + /* Here, type is big endian as it must be sent in two transfers */ + ad7949_adc->buffer = (u16)cpu_to_be16(ad7949_adc->cfg << 2); + break; + default: + dev_err(&ad7949_adc->indio_dev->dev, "unsupported BPW\n"); + return -EINVAL; + } + spi_message_init_with_transfers(&msg, tx, 1); ret = spi_sync(ad7949_adc->spi, &msg); @@ -115,14 +132,12 @@ static int ad7949_spi_read_channel(struct ad7949_adc_chip *ad7949_adc, int *val, { int ret; int i; - int bits_per_word = ad7949_adc->resolution; - int mask = GENMASK(ad7949_adc->resolution - 1, 0); struct spi_message msg; struct spi_transfer tx[] = { { .rx_buf = &ad7949_adc->buffer, .len = 2, - .bits_per_word = bits_per_word, + .bits_per_word = ad7949_adc->bits_per_word, }, }; @@ -157,7 +172,25 @@ static int ad7949_spi_read_channel(struct ad7949_adc_chip *ad7949_adc, int *val, ad7949_adc->current_channel = channel; - *val = ad7949_adc->buffer & mask; + switch (ad7949_adc->bits_per_word) { + case 16: + *val = ad7949_adc->buffer; + /* Shift-out padding bits */ + *val >>= 16 - ad7949_adc->resolution; + break; + case 14: + *val = ad7949_adc->buffer & GENMASK(13, 0); + break; + case 8: + /* Here, type is big endian as data was sent in two transfers */ + *val = be16_to_cpu(ad7949_adc->buffer); + /* Shift-out padding bits */ + *val >>= 16 - ad7949_adc->resolution; + break; + default: + dev_err(&ad7949_adc->indio_dev->dev, "unsupported BPW\n"); + return -EINVAL; + } return 0; } @@ -265,6 +298,7 @@ static int ad7949_spi_init(struct ad7949_adc_chip *ad7949_adc) static int ad7949_spi_probe(struct spi_device *spi) { + u32 spi_ctrl_mask = spi->controller->bits_per_word_mask; struct device *dev = &spi->dev; const struct ad7949_adc_spec *spec; struct ad7949_adc_chip *ad7949_adc; @@ -291,6 +325,18 @@ static int ad7949_spi_probe(struct spi_device *spi) indio_dev->num_channels = spec->num_channels; ad7949_adc->resolution = spec->resolution; + /* Set SPI bits per word */ + if (spi_ctrl_mask & SPI_BPW_MASK(ad7949_adc->resolution)) { + ad7949_adc->bits_per_word = ad7949_adc->resolution; + } else if (spi_ctrl_mask == SPI_BPW_MASK(16)) { + ad7949_adc->bits_per_word = 16; + } else if (spi_ctrl_mask == SPI_BPW_MASK(8)) { + ad7949_adc->bits_per_word = 8; + } else { + dev_err(dev, "unable to find common BPW with spi controller\n"); + return -EINVAL; + } + ad7949_adc->vref = devm_regulator_get(dev, "vref"); if (IS_ERR(ad7949_adc->vref)) { dev_err(dev, "fail to request regulator\n"); From patchwork Tue Jul 27 23:29:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 12404643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B9BEC3F6A3 for ; Tue, 27 Jul 2021 23:29:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 087E760F6B for ; Tue, 27 Jul 2021 23:29:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232972AbhG0X32 (ORCPT ); Tue, 27 Jul 2021 19:29:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233455AbhG0X3Z (ORCPT ); Tue, 27 Jul 2021 19:29:25 -0400 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1355AC061765; Tue, 27 Jul 2021 16:29:25 -0700 (PDT) Received: by mail-qk1-x729.google.com with SMTP id k7so453692qki.11; Tue, 27 Jul 2021 16:29:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FSgaKBtEbUil0nqgPknIVkWqv8lxcnefPu7nUiuVvbk=; b=XLNoVt3ASk7T7Fk3tR000zRe3t5E+DzhV/LxN2CAbtXyEdSkp9nUCjXbLtyi6dWc2Y lTmTzmOazHXabvjabWrSw084ZfSnWvFRt6/NeytEGD4C6jIfKZ2i0UrKvDkvbCHysSuB gFXbwdQT47ivmZhzVNcEdtvE4ooq6pg9ERIVJvlsmgo8NoO9a2ZxXdwMx+PAtWmJhMiP 1uRdEZgBpJlTogpzn5Xe8PSTyEbpAg5U7liO9DRpQif8xeckG7ANZe6C7v4p3nYbpXlS /P17SipCHovHxbn/f/P4KoxpGL8YBzeXC/YNO+2lOXBR/xBIBjQH1dxP6V9O35E/Ibt3 cK9A== 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:mime-version:content-transfer-encoding; bh=FSgaKBtEbUil0nqgPknIVkWqv8lxcnefPu7nUiuVvbk=; b=NX0/wS+HBGbMC9zvUsgYDtsIo6Iwlmm3MKeCdLya5UigcKxosjULINJ78K2wGSatQV M4ArwgtOM6AtxYR1V2w8jtI3QWmfCEvhak8s7Hlsm8XdvJ60sPQTTf9FRITJAW0KWoKk +9TWZnaIwruVA3ml3F9ikxGZViyf2q0C6fbC7cAbbNN4uvr+ZuAjT7FfxNK5uQz9a3gn 0X3At4Aj/cbtomaZizOB5/M5vo5ln+gCuLAjNQEv7OJLSsocSQVVECnZkkxAD+30BA4U NQe7omIuT1G0GnRgbAP9KpOazrvvMl7AGVPqG+xdm/bP+5hD87FI/JPr4FpRnv7cfwGi IAyg== X-Gm-Message-State: AOAM530zPYEeAlCayhQdP1WaF6Dh6HQieY/z1cwKn7ls0ha6xtHrzquu b4jr5vojoIAXagECA7g6pVA= X-Google-Smtp-Source: ABdhPJxRMSNCBX4iZ6KDfPFteKVGp/SsYrelap2aBTVm9rKdiRM7tUFJGe0QHAIrd+dtXhDxKIX1Cg== X-Received: by 2002:a05:620a:13c8:: with SMTP id g8mr24868815qkl.342.1627428564288; Tue, 27 Jul 2021 16:29:24 -0700 (PDT) Received: from shaak.xiphos.ca (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id p188sm2380514qka.114.2021.07.27.16.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jul 2021 16:29:23 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, charles-antoine.couret@essensium.com, Nuno.Sa@analog.com Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v4 3/5] iio: adc: ad7949: add support for internal vref Date: Tue, 27 Jul 2021 19:29:04 -0400 Message-Id: <20210727232906.980769-4-liambeguin@gmail.com> X-Mailer: git-send-email 2.30.1.489.g328c10930387 In-Reply-To: <20210727232906.980769-1-liambeguin@gmail.com> References: <20210727232906.980769-1-liambeguin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Liam Beguin Add support for selecting a custom reference voltage from the devicetree. If an external source is used, a vref regulator should be defined in the devicetree. Signed-off-by: Liam Beguin --- drivers/iio/adc/ad7949.c | 132 +++++++++++++++++++++++++++++++++------ 1 file changed, 114 insertions(+), 18 deletions(-) diff --git a/drivers/iio/adc/ad7949.c b/drivers/iio/adc/ad7949.c index f1702c54c8be..eaea8f5e87d8 100644 --- a/drivers/iio/adc/ad7949.c +++ b/drivers/iio/adc/ad7949.c @@ -35,7 +35,11 @@ /* REF: reference/buffer selection */ #define AD7949_CFG_BIT_REF GENMASK(5, 3) -#define AD7949_CFG_VAL_REF_EXT_BUF 7 +#define AD7949_CFG_VAL_REF_EXT_TEMP_BUF 3 +#define AD7949_CFG_VAL_REF_EXT_TEMP 2 +#define AD7949_CFG_VAL_REF_INT_4096 1 +#define AD7949_CFG_VAL_REF_INT_2500 0 +#define AD7949_CFG_VAL_REF_EXTERNAL BIT(1) /* SEQ: channel sequencer. Allows for scanning channels */ #define AD7949_CFG_BIT_SEQ GENMASK(2, 1) @@ -60,6 +64,14 @@ static const struct ad7949_adc_spec ad7949_adc_spec[] = { [ID_AD7689] = { .num_channels = 8, .resolution = 16 }, }; +/** + * struct ad7949_channel - ADC Channel parameters + * @refsel: reference selection + */ +struct ad7949_channel { + u32 refsel; +}; + /** * struct ad7949_adc_chip - AD ADC chip * @lock: protects write sequences @@ -77,6 +89,7 @@ struct ad7949_adc_chip { struct regulator *vref; struct iio_dev *indio_dev; struct spi_device *spi; + struct ad7949_channel *channels; u8 resolution; u8 bits_per_word; u16 cfg; @@ -133,6 +146,7 @@ static int ad7949_spi_read_channel(struct ad7949_adc_chip *ad7949_adc, int *val, int ret; int i; struct spi_message msg; + struct ad7949_channel *ad7949_chan = &ad7949_adc->channels[channel]; struct spi_transfer tx[] = { { .rx_buf = &ad7949_adc->buffer, @@ -149,8 +163,9 @@ static int ad7949_spi_read_channel(struct ad7949_adc_chip *ad7949_adc, int *val, */ for (i = 0; i < 2; i++) { ret = ad7949_spi_write_cfg(ad7949_adc, - FIELD_PREP(AD7949_CFG_BIT_INX, channel), - AD7949_CFG_BIT_INX); + FIELD_PREP(AD7949_CFG_BIT_INX, channel) | + FIELD_PREP(AD7949_CFG_BIT_REF, ad7949_chan->refsel), + AD7949_CFG_BIT_INX | AD7949_CFG_BIT_REF); if (ret) return ret; if (channel == ad7949_adc->current_channel) @@ -219,6 +234,7 @@ static int ad7949_spi_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct ad7949_adc_chip *ad7949_adc = iio_priv(indio_dev); + struct ad7949_channel *ad7949_chan = &ad7949_adc->channels[chan->channel]; int ret; if (!val) @@ -236,12 +252,26 @@ static int ad7949_spi_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: - ret = regulator_get_voltage(ad7949_adc->vref); - if (ret < 0) - return ret; + switch (ad7949_chan->refsel) { + case AD7949_CFG_VAL_REF_INT_2500: + *val = 2500; + break; + case AD7949_CFG_VAL_REF_INT_4096: + *val = 4096; + break; + case AD7949_CFG_VAL_REF_EXT_TEMP: + case AD7949_CFG_VAL_REF_EXT_TEMP_BUF: + ret = regulator_get_voltage(ad7949_adc->vref); + if (ret < 0) + return ret; + + /* convert value back to mV */ + *val = ret / 1000; + break; + } - *val = ret / 5000; - return IIO_VAL_INT; + *val2 = (1 << ad7949_adc->resolution) - 1; + return IIO_VAL_FRACTIONAL; } return -EINVAL; @@ -280,7 +310,7 @@ static int ad7949_spi_init(struct ad7949_adc_chip *ad7949_adc) FIELD_PREP(AD7949_CFG_BIT_INCC, AD7949_CFG_VAL_INCC_UNIPOLAR_GND) | FIELD_PREP(AD7949_CFG_BIT_INX, ad7949_adc->current_channel) | FIELD_PREP(AD7949_CFG_BIT_BW_FULL, 1) | - FIELD_PREP(AD7949_CFG_BIT_REF, AD7949_CFG_VAL_REF_EXT_BUF) | + FIELD_PREP(AD7949_CFG_BIT_REF, ad7949_adc->channels[0].refsel) | FIELD_PREP(AD7949_CFG_BIT_SEQ, 0x0) | FIELD_PREP(AD7949_CFG_BIT_RBN, 1); @@ -296,14 +326,24 @@ static int ad7949_spi_init(struct ad7949_adc_chip *ad7949_adc) return ret; } +static void ad7949_disable_reg(void *reg) +{ + regulator_disable(reg); +} + static int ad7949_spi_probe(struct spi_device *spi) { u32 spi_ctrl_mask = spi->controller->bits_per_word_mask; struct device *dev = &spi->dev; const struct ad7949_adc_spec *spec; struct ad7949_adc_chip *ad7949_adc; + struct ad7949_channel *ad7949_chan; + struct fwnode_handle *child; struct iio_dev *indio_dev; + int mode; + u32 tmp; int ret; + int i; indio_dev = devm_iio_device_alloc(dev, sizeof(*ad7949_adc)); if (!indio_dev) { @@ -337,16 +377,74 @@ static int ad7949_spi_probe(struct spi_device *spi) return -EINVAL; } - ad7949_adc->vref = devm_regulator_get(dev, "vref"); + /* Setup external voltage ref, buffered? */ + ad7949_adc->vref = devm_regulator_get(dev, "vrefin"); if (IS_ERR(ad7949_adc->vref)) { - dev_err(dev, "fail to request regulator\n"); - return PTR_ERR(ad7949_adc->vref); + /* unbuffered? */ + ad7949_adc->vref = devm_regulator_get(dev, "vref"); + if (IS_ERR(ad7949_adc->vref)) { + /* Internal then */ + mode = AD7949_CFG_VAL_REF_INT_4096; + } + mode = AD7949_CFG_VAL_REF_EXT_TEMP; } + mode = AD7949_CFG_VAL_REF_EXT_TEMP_BUF; - ret = regulator_enable(ad7949_adc->vref); - if (ret < 0) { - dev_err(dev, "fail to enable regulator\n"); - return ret; + if (mode & AD7949_CFG_VAL_REF_EXTERNAL) { + ret = regulator_enable(ad7949_adc->vref); + if (ret < 0) { + dev_err(dev, "fail to enable regulator\n"); + return ret; + } + + ret = devm_add_action_or_reset(dev, ad7949_disable_reg, + ad7949_adc->vref); + if (ret) + return ret; + } + + ad7949_adc->channels = devm_kcalloc(dev, spec->num_channels, + sizeof(*ad7949_adc->channels), + GFP_KERNEL); + if (!ad7949_adc->channels) { + dev_err(dev, "unable to allocate ADC channels\n"); + return -ENOMEM; + } + + /* Initialize all channel structures */ + for (i = 0; i < spec->num_channels; i++) + ad7949_adc->channels[i].refsel = mode; + + /* Read channel specific information form the devicetree */ + device_for_each_child_node(dev, child) { + ret = fwnode_property_read_u32(child, "reg", &i); + if (ret) { + dev_err(dev, "missing reg property in %pfw\n", child); + fwnode_handle_put(child); + return ret; + } + + ad7949_chan = &ad7949_adc->channels[i]; + + ret = fwnode_property_read_u32(child, "adi,internal-ref-microvolt", &tmp); + if (ret < 0 && ret != -EINVAL) { + dev_err(dev, "invalid internal reference in %pfw\n", child); + fwnode_handle_put(child); + return ret; + } + + switch (tmp) { + case 2500000: + ad7949_chan->refsel = AD7949_CFG_VAL_REF_INT_2500; + break; + case 4096000: + ad7949_chan->refsel = AD7949_CFG_VAL_REF_INT_4096; + break; + default: + dev_err(dev, "unsupported internal voltage reference\n"); + fwnode_handle_put(child); + return -EINVAL; + } } mutex_init(&ad7949_adc->lock); @@ -367,7 +465,6 @@ static int ad7949_spi_probe(struct spi_device *spi) err: mutex_destroy(&ad7949_adc->lock); - regulator_disable(ad7949_adc->vref); return ret; } @@ -379,7 +476,6 @@ static int ad7949_spi_remove(struct spi_device *spi) iio_device_unregister(indio_dev); mutex_destroy(&ad7949_adc->lock); - regulator_disable(ad7949_adc->vref); return 0; } From patchwork Tue Jul 27 23:29:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 12404639 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 296BFC41537 for ; Tue, 27 Jul 2021 23:29:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 14A456100A for ; Tue, 27 Jul 2021 23:29:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233729AbhG0X32 (ORCPT ); Tue, 27 Jul 2021 19:29:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233686AbhG0X31 (ORCPT ); Tue, 27 Jul 2021 19:29:27 -0400 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C0D3C061757; Tue, 27 Jul 2021 16:29:26 -0700 (PDT) Received: by mail-qk1-x732.google.com with SMTP id t66so545047qkb.0; Tue, 27 Jul 2021 16:29:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2RbNDDyjg8LeqN8Ur+WvNroKgulCjlo8nSzXgbnXYI8=; b=vaRhEYQ39gDSfch3qn2iuLemkQaknmC+8zgyx/ubcS0n6ABBL1MNuf5dat8e1/gBSl iRF9S0Qzq3puyKCzW+D9nIxSGc4ZbykIgk9NaiwtAca5Dctm842CnBqK0WFhQ7KEuvje f9gc3/i2cirNMuOJyHB5VQxk9v/KNjB0ZIc70Y2NX9jf1Vw9bjKmw5eRHFPIB0F2Hbg7 Rq85B6rHf998IiK42ijaY02zdeNiO/BFcdSoS4zMaW/XMueoJP1mYrGKGwTGGOJAr38l Jo9k3LJl+jAz28lHReUjXyo4Bhebcsyn9iDkBoP6czy0AhKXnb00c7M2E1C1cAPOErhP nS7Q== 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:mime-version:content-transfer-encoding; bh=2RbNDDyjg8LeqN8Ur+WvNroKgulCjlo8nSzXgbnXYI8=; b=PkZ6ozXk26ss3Zz9YwXq+QHqfet6+X/rRJEI1fyGwfLQ/1pM/ge+yEi5TRhVP/ZrDP nFUCrXxdbcx2/SQtcUpcX3WE91BQftVXo/oFckErDTToZp5rARSanSsoX4IiyPoUsIwZ VL1nD/GOwyxQmqn0/iWaCwTHzVOsH9JbUHtk8ejOV3WeD7KMnWCEepi/qOqJcneGIwF9 mrl5uxVH+sBZXM12+fX5LhsCjwiD7LF+ANfIipWwBd3R9ar971ErAbXkxxw2Ze9GwjH/ nsT73sBwfrHITFbNsDgYUtZLLUOPOo7mV62UHseIH0a3Bs1tiTjTh/ebru6XRrVwWCwZ bQ/Q== X-Gm-Message-State: AOAM531IXlXmP0DEhxYNvEVEiuxMhhswQ8IUanpMny8g/nPTSRxwJ+Tq Uv35tVeUAh8h2d+av/HBiHE= X-Google-Smtp-Source: ABdhPJziiBME7bS4VSI257P/dcqtPtRil5PVxBI3EhYJoqfl8wyL+BwRllE5xhS2JrCn65tWsoi6Cg== X-Received: by 2002:a37:847:: with SMTP id 68mr25024897qki.112.1627428565270; Tue, 27 Jul 2021 16:29:25 -0700 (PDT) Received: from shaak.xiphos.ca (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id p188sm2380514qka.114.2021.07.27.16.29.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jul 2021 16:29:24 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, charles-antoine.couret@essensium.com, Nuno.Sa@analog.com Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v4 4/5] dt-bindings: iio: adc: ad7949: add per channel reference Date: Tue, 27 Jul 2021 19:29:05 -0400 Message-Id: <20210727232906.980769-5-liambeguin@gmail.com> X-Mailer: git-send-email 2.30.1.489.g328c10930387 In-Reply-To: <20210727232906.980769-1-liambeguin@gmail.com> References: <20210727232906.980769-1-liambeguin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Liam Beguin Add bindings documentation describing per channel reference voltage selection. This adds the adi,internal-ref-microvolt property, and child nodes for each channel. This is required to properly configure the ADC sample request based on which reference source should be used for the calculation. Signed-off-by: Liam Beguin Reviewed-by: Rob Herring --- .../bindings/iio/adc/adi,ad7949.yaml | 69 +++++++++++++++++-- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7949.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7949.yaml index 9b56bd4d5510..893f72b8081e 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7949.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7949.yaml @@ -26,19 +26,63 @@ properties: reg: maxItems: 1 + vrefin-supply: + description: + Buffered ADC reference voltage supply. + vref-supply: description: - ADC reference voltage supply + Unbuffered ADC reference voltage supply. spi-max-frequency: true - "#io-channel-cells": + '#io-channel-cells': const: 1 + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + required: - compatible - reg - - vref-supply + +patternProperties: + '^channel@([0-7])$': + type: object + description: | + Represents the external channels which are connected to the ADC. + + properties: + reg: + description: | + The channel number. + Up to 4 channels, numbered from 0 to 3 for adi,ad7682. + Up to 8 channels, numbered from 0 to 7 for adi,ad7689 and adi,ad7949. + items: + minimum: 0 + maximum: 7 + + adi,internal-ref-microvolt: + description: | + Internal reference voltage selection in microvolts. + + If no internal reference is specified, the channel will default to the + external reference defined by vrefin-supply (or vref-supply). + vrefin-supply will take precedence over vref-supply if both are defined. + + If no supplies are defined, the reference selection will default to + 4096mV internal reference. + + enum: [2500000, 4096000] + default: 4096000 + + required: + - reg + + additionalProperties: false additionalProperties: false @@ -49,9 +93,26 @@ examples: #size-cells = <0>; adc@0 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "adi,ad7949"; reg = <0>; - vref-supply = <&vdd_supply>; + vrefin-supply = <&vdd_supply>; + + channel@0 { + adi,internal-ref-microvolt = <4096000>; + reg = <0>; + }; + + channel@1 { + adi,internal-ref-microvolt = <2500000>; + reg = <1>; + }; + + channel@2 { + reg = <2>; + }; }; }; ... From patchwork Tue Jul 27 23:29:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 12404645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6D78C432BE for ; Tue, 27 Jul 2021 23:29:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8D7B60F9C for ; Tue, 27 Jul 2021 23:29:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233925AbhG0X3c (ORCPT ); Tue, 27 Jul 2021 19:29:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233258AbhG0X32 (ORCPT ); Tue, 27 Jul 2021 19:29:28 -0400 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00767C061760; Tue, 27 Jul 2021 16:29:26 -0700 (PDT) Received: by mail-qk1-x736.google.com with SMTP id 184so510220qkh.1; Tue, 27 Jul 2021 16:29:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Csc8wT/95G9747ozFthDCH/y0the7872d54YDDPRcbw=; b=R8lSn+PkPn1WSVxtrB4LEJ7u2NOHgF3okdWNJ7xzOeyy+7P9UTaQvTDvHgOadoWXd+ TjrIpwi5jM/N2LoG24fvC2kAzzpO0ewfd8z04v3nyGbssOOgHD7FlJBUBe76gMsFkPsY vj5fla4/G3G+z4DcMWna13jiFz+93+9GdDBojaaNVBHjty/oeMSCUb7pc1Vfnq2GyGKb jq2XbnoDxnGX39jsIGyaRfuccYgoIIs8PS0+fu5lS6pOREKGOznsj96qpMMlEbT9X+md oaCXrySgTc99/VnYmddL/5nMjfKfC7lv83cXA7Wh41DSseJhsDCHAyZtEevK9qOGBB0R Er7w== 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:mime-version:content-transfer-encoding; bh=Csc8wT/95G9747ozFthDCH/y0the7872d54YDDPRcbw=; b=JXTvnHC7JOfhEgtzpMZyXbcf1h4fdtnz00KfUv+u7lrU09mRiH7SCS7BOT53CZD7LX 4iwklvYUfi7OtIMMKnVOQ1T4mErX9YlfgVwxVe0s22ICRWox/oRgsXXhVcbFDLMSJY7r WTN/BSip3QOw0Dlu72U/ptQt1Cz7/TlKVBnJkDf7RXwqvqgrYTdRjBjuFLfcAPEEyXaX diZ9t3tSsJeM16bofCemzCO4/FEJZEGuWSZ6XC4k5q4GKgsUAjFRQdSo5OH1r8bn7Nz/ XmwSHW3g+coKmxfhCmH5DfFVSRsaN1GZILszh/GUBP5dNWmVlCok0jJLoLbcLZxwNrXc sNJw== X-Gm-Message-State: AOAM532b5/q7C49ESrNytHWEt8bMDap5AsddRBpBaPgIQ7c0r03lXEJR ffBgvgTrPTqRyxmgZ2yqWA0= X-Google-Smtp-Source: ABdhPJzw3Glsh4KII0L97nq3gobiOH4Z1doCcqH+8rVV3Qtokh+NZCPlAx9NogU/F9cHuH3KOA5vRQ== X-Received: by 2002:a37:66d6:: with SMTP id a205mr24218043qkc.422.1627428566232; Tue, 27 Jul 2021 16:29:26 -0700 (PDT) Received: from shaak.xiphos.ca (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id p188sm2380514qka.114.2021.07.27.16.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jul 2021 16:29:25 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, charles-antoine.couret@essensium.com, Nuno.Sa@analog.com Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v4 5/5] iio: adc: ad7949: use devm managed functions Date: Tue, 27 Jul 2021 19:29:06 -0400 Message-Id: <20210727232906.980769-6-liambeguin@gmail.com> X-Mailer: git-send-email 2.30.1.489.g328c10930387 In-Reply-To: <20210727232906.980769-1-liambeguin@gmail.com> References: <20210727232906.980769-1-liambeguin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Liam Beguin Switch to devm_iio_device_register to finalize devm migration. This removes the use for iio_device_unregister() and since mutex_destroy() is not necessary here, remove it altogether. Signed-off-by: Liam Beguin --- drivers/iio/adc/ad7949.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/drivers/iio/adc/ad7949.c b/drivers/iio/adc/ad7949.c index eaea8f5e87d8..29a87a12e551 100644 --- a/drivers/iio/adc/ad7949.c +++ b/drivers/iio/adc/ad7949.c @@ -452,34 +452,16 @@ static int ad7949_spi_probe(struct spi_device *spi) ret = ad7949_spi_init(ad7949_adc); if (ret) { dev_err(dev, "enable to init this device: %d\n", ret); - goto err; + return ret; } - ret = iio_device_register(indio_dev); - if (ret) { + ret = devm_iio_device_register(dev, indio_dev); + if (ret) dev_err(dev, "fail to register iio device: %d\n", ret); - goto err; - } - - return 0; - -err: - mutex_destroy(&ad7949_adc->lock); return ret; } -static int ad7949_spi_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7949_adc_chip *ad7949_adc = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - mutex_destroy(&ad7949_adc->lock); - - return 0; -} - static const struct of_device_id ad7949_spi_of_id[] = { { .compatible = "adi,ad7949" }, { .compatible = "adi,ad7682" }, @@ -502,7 +484,6 @@ static struct spi_driver ad7949_spi_driver = { .of_match_table = ad7949_spi_of_id, }, .probe = ad7949_spi_probe, - .remove = ad7949_spi_remove, .id_table = ad7949_spi_id, }; module_spi_driver(ad7949_spi_driver);