From patchwork Sun Aug 8 01:56:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 12424621 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.8 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,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 16568C4320E for ; Sun, 8 Aug 2021 01:57:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E039660F5E for ; Sun, 8 Aug 2021 01:57:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230154AbhHHB5w (ORCPT ); Sat, 7 Aug 2021 21:57:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230096AbhHHB5v (ORCPT ); Sat, 7 Aug 2021 21:57:51 -0400 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6384EC0613CF; Sat, 7 Aug 2021 18:57:32 -0700 (PDT) Received: by mail-qk1-x733.google.com with SMTP id a19so14484005qkg.2; Sat, 07 Aug 2021 18:57:32 -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=gdv3BVYPa7slvr9DFE6GbAJc4qpzj6EiXQtId6AIGvo=; b=jynE6zjCH8AX7Z26sxDYXAAOglMipN2NqFPl/XlETswBp08WHZO01KTkWgTA58yXIe 0wIbrk1Yw5G5/CkFX2dpHmsdieufXSy2ZPsxtwAaYrbgfu8PrhVDpke1O2OA2qhyD8YK ltqaJdVZuPW1r9VWqtC5P3//YDtANaWbBnFWm3sTDZnELTbLI5cp/AvBrmn4uVxPFkQ3 2oIwxDlR2G9+22E4nwQ3fgGCxoeYR2YVj2pFTdUPJTWoxqX0oXIuh0l4DJzrGpWsTTEr 5c7UVzfOA4oOHzd2T8Bzkozi+HeJGc9Xl+9vhmBuRUBeBEZJECVTmNNR6M2T7EZjIVRb 4wZQ== 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=gdv3BVYPa7slvr9DFE6GbAJc4qpzj6EiXQtId6AIGvo=; b=tpU8HJO6xSwsJSRuFat2sqb06PqheVh//meY5KUOKt+a1uHqmObUWqxLJ5f26XePNk eK9F5EZCx4T//+PjoAZRCDxuAcjImfXLVbI3n0KKB2lXgfkNdmVXFJrqgHz0TGBBGJqS ajZ+/5l8eVMuhEiaOHxk8tk0fH0jlihhtJ+FQYTdw4ZEPVwp2oB3WTg7hIRAwSc9Qjr1 vuXo2ohDWEChiuJ8xWX12ajv/k+GPuRHdmUb32kyF8jDIsOP/77Msp3jWZAB6iSRIxCv mV1i5O4KLdv8lulJGNsVRUuGC54R6nS+0P4BqhHweUomLti01+PFLpNAeI0RK4j8oXAm ZAWg== X-Gm-Message-State: AOAM531Q6NimqvmMdIAHDPC0ym52sFdEN0Gv6Ku42tYfb28BmRyPYoif pFULmLouqbsWfrqpqWFXO2c9T29EMhoJFw== X-Google-Smtp-Source: ABdhPJzSEaAjVtVBbYg4DK0BzEWpvLvBsasnpIFycTI/5tzF7bSP+JFToZwBfOSH+UW0WiGCHBjIBg== X-Received: by 2002:a37:46d0:: with SMTP id t199mr16675262qka.416.1628387851079; Sat, 07 Aug 2021 18:57:31 -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 k24sm1569612qki.11.2021.08.07.18.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 18:57:30 -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 v5 1/5] iio: adc: ad7949: define and use bitfield names Date: Sat, 7 Aug 2021 21:56:55 -0400 Message-Id: <20210808015659.2955443-2-liambeguin@gmail.com> X-Mailer: git-send-email 2.32.0.452.g940fe202adcb In-Reply-To: <20210808015659.2955443-1-liambeguin@gmail.com> References: <20210808015659.2955443-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 | 49 ++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/ad7949.c b/drivers/iio/adc/ad7949.c index 1b4b3203e428..937241ee2a22 100644 --- a/drivers/iio/adc/ad7949.c +++ b/drivers/iio/adc/ad7949.c @@ -11,13 +11,39 @@ #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, ID_AD7682, @@ -109,8 +135,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 +240,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 Sun Aug 8 01:56:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 12424623 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.8 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,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 04F1CC4320A for ; Sun, 8 Aug 2021 01:57:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C43026115C for ; Sun, 8 Aug 2021 01:57:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230139AbhHHB5w (ORCPT ); Sat, 7 Aug 2021 21:57:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230030AbhHHB5v (ORCPT ); Sat, 7 Aug 2021 21:57:51 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3160C061760; Sat, 7 Aug 2021 18:57:32 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id dk2so7188934qvb.3; Sat, 07 Aug 2021 18:57:32 -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=A37saODTcesuUxyXgpe8ielCQCcU0J71Gt99ymfG4a4=; b=bTvSdeRS2GvrOKEmvzNae0msWjCDDoQcG4I+V3WfQAFksXc1RJHhjiqHDV0Nbp/0QO NIFCI6U9ryZZYTVhDH6UD1E73VUjo4phsuG4pcux8RldxHvXrqclEKMfqrf2Nn5JJ8AP CCqpHkegBWxKglqULkJzk+5SRK2sPeES9IMsuB6Tsgny5UF7AtD0lupcFfk7ywhYpsih QhwxT7aNZZm8cygBDw/G8NZhbfVFF4FCmvbc47EFf+c+dPytT1iuhT8Ez8keUxH1slZW pt9Ngch1F8Z5HM+KetG6ybeMevCoDEDLUH/eUHFeuAkQkeBNJIUt0/lt9xbLgQeVlCfc sxNA== 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=A37saODTcesuUxyXgpe8ielCQCcU0J71Gt99ymfG4a4=; b=G2TY5lUCgr6XgG3kn2Qh/4mOOw2PZWmRL/HtaDrwom9iK/noTVw2870zgeAbfOeOLs mxpcmEmStkuKtttGgLcjLj60ufvxarl4OqyNiOM0nnbgU4nN/Ih/AWnAJtq5b19CPsLt d5leA+NYsBNTWf3KSZqxD8Ehqe/gFCDyvMbWjm5uSVbtYN0h9YOfFbaaTuAQ5sadh3WQ ue/rQqj42SlKFDuBb0NB6DrzX1Zc2SxlCWtcLrZTueBR/3DLg/1K8fKFYipUVLvv4w4X mXe2wEp4H9VXjlVQUQkBTHKCOja9OHr8p3h+fAD9O7snTciHlwTzAb8m+QYlQUthItD2 sHcw== X-Gm-Message-State: AOAM5322PQHNbQKDL3juJ0J3FFji7a7XJDlTmkEoJ86H37UyjPZdHka/ vY5On+i0hsELN2efbCJrTcI03qMIsdWgLA== X-Google-Smtp-Source: ABdhPJz7mwF2WHZhrow+CCmSBsNNPPt+sw8vzuy7tBaFkc71vtlVOqE+VD9VnItqoF7JS/siSO3gFw== X-Received: by 2002:a0c:ead1:: with SMTP id y17mr18252583qvp.12.1628387852144; Sat, 07 Aug 2021 18:57:32 -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 k24sm1569612qki.11.2021.08.07.18.57.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 18:57:31 -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 v5 2/5] iio: adc: ad7949: fix spi messages on non 14-bit controllers Date: Sat, 7 Aug 2021 21:56:56 -0400 Message-Id: <20210808015659.2955443-3-liambeguin@gmail.com> X-Mailer: git-send-email 2.32.0.452.g940fe202adcb In-Reply-To: <20210808015659.2955443-1-liambeguin@gmail.com> References: <20210808015659.2955443-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 | 75 +++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 12 deletions(-) diff --git a/drivers/iio/adc/ad7949.c b/drivers/iio/adc/ad7949.c index 937241ee2a22..3f94ae639a44 100644 --- a/drivers/iio/adc/ad7949.c +++ b/drivers/iio/adc/ad7949.c @@ -14,7 +14,6 @@ #include #define AD7949_MASK_TOTAL GENMASK(13, 0) -#define AD7949_CFG_REG_SIZE_BITS 14 /* CFG: Configuration Update */ #define AD7949_CFG_BIT_OVERWRITE BIT(13) @@ -68,9 +67,11 @@ 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 + * @buf8b: be16 buffer to exchange data with the device in 8-bit transfers */ struct ad7949_adc_chip { struct mutex lock; @@ -78,28 +79,46 @@ 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; + __be16 buf8b; }; 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->cfg = (val & mask) | (ad7949_adc->cfg & ~mask); - ad7949_adc->buffer = ad7949_adc->cfg << shift; + + switch (ad7949_adc->bits_per_word) { + case 16: + tx[0].tx_buf = &ad7949_adc->buffer; + ad7949_adc->buffer = ad7949_adc->cfg << 2; + break; + case 14: + tx[0].tx_buf = &ad7949_adc->buffer; + ad7949_adc->buffer = ad7949_adc->cfg; + break; + case 8: + /* Here, type is big endian as it must be sent in two transfers */ + tx[0].tx_buf = &ad7949_adc->buf8b; + ad7949_adc->buf8b = 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); @@ -116,17 +135,19 @@ 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, }, }; + if (ad7949_adc->bits_per_word == 8) + tx[0].rx_buf = &ad7949_adc->buf8b; + else + tx[0].rx_buf = &ad7949_adc->buffer; + /* * 1: write CFG for sample N and read old data (sample N-2) * 2: if CFG was not changed since sample N-1 then we'll get good data @@ -144,7 +165,6 @@ static int ad7949_spi_read_channel(struct ad7949_adc_chip *ad7949_adc, int *val, } /* 3: write something and read actual data */ - ad7949_adc->buffer = 0; spi_message_init_with_transfers(&msg, tx, 1); ret = spi_sync(ad7949_adc->spi, &msg); if (ret) @@ -158,7 +178,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->buf8b); + /* 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; } @@ -266,6 +304,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; @@ -292,6 +331,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 Sun Aug 8 01:56:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 12424627 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.8 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,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 8AD48C04FE3 for ; Sun, 8 Aug 2021 01:57:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E43E60F5E for ; Sun, 8 Aug 2021 01:57:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230030AbhHHB5y (ORCPT ); Sat, 7 Aug 2021 21:57:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230170AbhHHB5x (ORCPT ); Sat, 7 Aug 2021 21:57:53 -0400 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB98FC061760; Sat, 7 Aug 2021 18:57:33 -0700 (PDT) Received: by mail-qv1-xf36.google.com with SMTP id kl2so7167311qvb.11; Sat, 07 Aug 2021 18:57:33 -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=KAnmaLSOpIA5R8atT5gHnvTQogZ7m/KGmpDl3XjQ8RY=; b=g4JGRd7v2y11EgQWE8J1MZuD7fqNbD1tnr7qPFNvYqcF1Ry6+VxMOzT93C1TX4rWtB joJHnzIcq/FWsohERwxmj/kVUiNpxwI7UK0nsar2VU/HXNW663FQXHaWwxr+6RuMf6rG JRCgkSufOznB8rB1mMhHyDGbekpxdm0Wm0rhSB2x+8LF+Nn5YftKOokB4eKL7zzdqqcq E5uVFRV+vouFWvSEsJX4zZ856kcmBPgfoMsOTp999aERnC39i1OrqZDq52bob7SVn5gW 3MQe3j3ubMreG2dQli1l4m2+nG7fa2+P6/peTqA7u8lLi7qQ1Tyef3uCOhKitYTSPahO NilA== 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=KAnmaLSOpIA5R8atT5gHnvTQogZ7m/KGmpDl3XjQ8RY=; b=fhrskXNMoFcnPcBVHTcnQYz6DCMloeu48YoTGbuJsJZh8qX/SAb33Ld2o8TVNlbFxm ne047Yd5jzWV8CXn+9j2+mHxLGmfyKLQqKThEtVywdFrzs/Ld/k6WPQkcpQQ/mQcqyy7 jt3E7CWUvIkOg+6l/aeRWZf4vhzpvDhglO57b1H8q4gqbtud6IDxmrmqhB4aN+w8ioIM i2wLzy0ec6EZePZ1LYHiujNiJJ/L33OKnKD0EEWk7s0iIRdYIxPmJO/8yG72uUoB2Ia8 /YjbjxWfLzTzVDDrUS3ttOQe8momsTpoRC7traWK71u4E36CSxfAvFbnPP2ymefbGT82 V8Mw== X-Gm-Message-State: AOAM533xj3eI/rS1btEX2B3t3jG4yEV7j5/m3ACu1pBE3QGd1i603/dy W2fkOMYOd5sPyqeQYLW5sok= X-Google-Smtp-Source: ABdhPJyVKjjTLC+TiAvPH9O7W2CsLPaEKdHX6vfc24T+ys40Hftvn82I8oYKsnVVKUqu5aMMfq+42A== X-Received: by 2002:a05:6214:1e1:: with SMTP id c1mr18209630qvu.42.1628387853149; Sat, 07 Aug 2021 18:57:33 -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 k24sm1569612qki.11.2021.08.07.18.57.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 18:57:32 -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 v5 3/5] iio: adc: ad7949: add support for internal vref Date: Sat, 7 Aug 2021 21:56:57 -0400 Message-Id: <20210808015659.2955443-4-liambeguin@gmail.com> X-Mailer: git-send-email 2.32.0.452.g940fe202adcb In-Reply-To: <20210808015659.2955443-1-liambeguin@gmail.com> References: <20210808015659.2955443-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 | 140 ++++++++++++++++++++++++++++++++++----- 1 file changed, 122 insertions(+), 18 deletions(-) diff --git a/drivers/iio/adc/ad7949.c b/drivers/iio/adc/ad7949.c index 3f94ae639a44..14a7c79d637e 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 @@ -78,6 +90,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; @@ -136,6 +149,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[] = { { .len = 2, @@ -156,8 +170,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) @@ -225,6 +240,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) @@ -242,12 +258,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; @@ -286,7 +316,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); @@ -302,14 +332,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) { @@ -343,16 +383,82 @@ 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_optional(dev, "vrefin"); if (IS_ERR(ad7949_adc->vref)) { - dev_err(dev, "fail to request regulator\n"); - return PTR_ERR(ad7949_adc->vref); + ret = PTR_ERR(ad7949_adc->vref); + if (ret != -ENODEV) + return ret; + /* unbuffered? */ + ad7949_adc->vref = devm_regulator_get_optional(dev, "vref"); + if (IS_ERR(ad7949_adc->vref)) { + ret = PTR_ERR(ad7949_adc->vref); + if (ret != -ENODEV) + return ret; + /* Internal then */ + mode = AD7949_CFG_VAL_REF_INT_4096; + } else { + mode = AD7949_CFG_VAL_REF_EXT_TEMP; + } + } else { + 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); @@ -373,7 +479,6 @@ static int ad7949_spi_probe(struct spi_device *spi) err: mutex_destroy(&ad7949_adc->lock); - regulator_disable(ad7949_adc->vref); return ret; } @@ -385,7 +490,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 Sun Aug 8 01:56:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 12424625 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.8 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,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 94746C3F6A3 for ; Sun, 8 Aug 2021 01:57:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7103460C41 for ; Sun, 8 Aug 2021 01:57:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230216AbhHHB5y (ORCPT ); Sat, 7 Aug 2021 21:57:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230197AbhHHB5y (ORCPT ); Sat, 7 Aug 2021 21:57:54 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD466C0613CF; Sat, 7 Aug 2021 18:57:34 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id em4so7219276qvb.0; Sat, 07 Aug 2021 18:57:34 -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=615kMpMCOocH22xvYuBl/egorml5TWflMxM6T2l3ME4=; b=RZpZDh5Nf9S1QhoBOJRE8JjpsRm34WH+ogmJ+Ec9B+JOVOmXpaGCu1340y7cvwxq3j PnzjiIiivp45gBNCXI41aIWGGEfy/3FBQgM4uwc6EIPLbcx+bkBt4f4mYk0zP8giEbYP 9TmrNFvhfi61h6tT5YwBAMU5IxOv+eyh399hLa63qWY6FWwmItvffpHOvghR4E0ecBvF 7TiRLzBlc8vapDoZIk4uhZ54TReoLhQBxWjbHCSFfIH/Ek/qEDfd24En0H2XAf3/drQi qtz2RsCWb7lQ5yTl9z+/jNvwT9QmimqxjneZRT4yWqWa11aTZsbDpVSg+YBF3kr8a4of cw7g== 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=615kMpMCOocH22xvYuBl/egorml5TWflMxM6T2l3ME4=; b=aBgbz1O0p3mN8thGLd6+3P/YjgAWdLqrRWeIDTBoixQEAbFqavyyNX3xu4pSyQOQwJ lb4K/UyIMiMo+MREWYWtvrvGkD2gCE+ziamUIKXVYK7fGuDH5ybnl/+7e/g6pIU8oqeX Nxay9OBF0IqjM9xIE1qHFQCDCXs7HOpT4hvwwDbboFPoDz9t/ipKo0BQNNEtFhKGeTmW KrDYESMRmmWURLIThqtFzMsI2v6VY0IP+E+1OL1LlSxw0JHflmQy9GZ0mw/XLP9T2Sjn dLmBl+Utjdaf1Jaiz5NQrDvVCtAym8F+EDyAb5We9WluvUJUFJsMvpWVQvqkIywGSbXf AtKg== X-Gm-Message-State: AOAM533ktrOiD8ZiN3f4Wpx5eZpila/kzLgGOJ13wzEqq6E5oRuwlHDb m1j7AHTc5tu6aWjjfirfTVo= X-Google-Smtp-Source: ABdhPJw9r9YoePEnovkVjBP6vSKTAZ8PqeNQVXkNc3+dfJQgL7PKXzZtslkEVdAEVDd9DEL/JmYOoQ== X-Received: by 2002:a05:6214:1933:: with SMTP id es19mr170063qvb.42.1628387854101; Sat, 07 Aug 2021 18:57:34 -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 k24sm1569612qki.11.2021.08.07.18.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 18:57:33 -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 v5 4/5] dt-bindings: iio: adc: ad7949: add per channel reference Date: Sat, 7 Aug 2021 21:56:58 -0400 Message-Id: <20210808015659.2955443-5-liambeguin@gmail.com> X-Mailer: git-send-email 2.32.0.452.g940fe202adcb In-Reply-To: <20210808015659.2955443-1-liambeguin@gmail.com> References: <20210808015659.2955443-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 Sun Aug 8 01:56:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 12424629 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.8 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,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 1660FC19F3D for ; Sun, 8 Aug 2021 01:57:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EDAA660F5E for ; Sun, 8 Aug 2021 01:57:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230287AbhHHB6B (ORCPT ); Sat, 7 Aug 2021 21:58:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230222AbhHHB5y (ORCPT ); Sat, 7 Aug 2021 21:57:54 -0400 Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8C31C061760; Sat, 7 Aug 2021 18:57:35 -0700 (PDT) Received: by mail-qv1-xf34.google.com with SMTP id js7so7185389qvb.4; Sat, 07 Aug 2021 18:57:35 -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=gD90amiT9YOyeKllxReMYt4NwrWNc35BmzbD4M2saFY=; b=EZtl5AHp+Pb02/ZMz2IKhSGMmiHPJZITQTTnMUFJZKqRvL3RV9vOPEMZl/uma2WXKy VREWmDFvf3S3+hEwJ/+MYn8h9ddsPoongUw/2OQkWw7/x/QcTRycVauBAx1RNquF/Ry/ Lui4iMMhYGVz32BvdhrJl6YOap9tubx0dr0AXGGZj5hevuq21Z8/WnDYHoZkyM16/lYo DMtj88morEj/yiIgciwfIglnohFUIexODtbPM8Njqc0h3F+jgqLRGXWjLXHo5oFp1Q7i Tez8gkWI5Gpb6G5ZPFiMNpHzT+QrU0bWGajtU26TxtfAfkAYYV/2t9d4EfFu2vIsyihq ndbg== 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=gD90amiT9YOyeKllxReMYt4NwrWNc35BmzbD4M2saFY=; b=Zx5vaZNXfX3cBMGw8shjL1Cm+TfRWLr0iowkGcAWwpBjmGbbUEZQIDmVJ2jNx904w3 5Ii6ojlQmrVDmWyLDA4QSy3WUmTrjBrV/NXxxMDceRuukt3psygQqA2NjdyvnjWkYGx6 OhnJe7bzdxX1ex660VZioWmDvmdFGnz7JQAzV4KhDiz/O1GkfN0NQPK/yI9LqcTGaKRu 9rYFaIkUE9X6zieDrdaJuOtM79Gj7uzZjfzLlpmiykXfKosOPmDipnkzC+azXH6jITMS NpMcq6HeIodWYIcwpN36oNTJlyRvNSuPrAh8OXgU9mIeaURBc6Dho85LY5rMCX/aVIQ1 Q8xQ== X-Gm-Message-State: AOAM530vAhnC0nhETlqoeiWbj43z5/DYB2CAdnsquJtPG/xO6qJers37 O+InaJV86lGRMSxRAFT0IN8= X-Google-Smtp-Source: ABdhPJyPFnuyJGoPvZRayd0TKP+lE12TNqhsQhABnKW06y8imG2MVHYODNASrMTqsWWuiJo0hsR4Pg== X-Received: by 2002:a0c:e6cc:: with SMTP id l12mr6896739qvn.48.1628387855002; Sat, 07 Aug 2021 18:57:35 -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 k24sm1569612qki.11.2021.08.07.18.57.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 18:57:34 -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 v5 5/5] iio: adc: ad7949: use devm managed functions Date: Sat, 7 Aug 2021 21:56:59 -0400 Message-Id: <20210808015659.2955443-6-liambeguin@gmail.com> X-Mailer: git-send-email 2.32.0.452.g940fe202adcb In-Reply-To: <20210808015659.2955443-1-liambeguin@gmail.com> References: <20210808015659.2955443-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 14a7c79d637e..71561eb7898e 100644 --- a/drivers/iio/adc/ad7949.c +++ b/drivers/iio/adc/ad7949.c @@ -466,34 +466,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" }, @@ -516,7 +498,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);