From patchwork Thu Apr 13 08:28:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabrizio Lamarque X-Patchwork-Id: 13209938 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 C58EDC77B61 for ; Thu, 13 Apr 2023 08:28:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229746AbjDMI2Y (ORCPT ); Thu, 13 Apr 2023 04:28:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbjDMI2X (ORCPT ); Thu, 13 Apr 2023 04:28:23 -0400 Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B79AF2685 for ; Thu, 13 Apr 2023 01:28:22 -0700 (PDT) Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-1842df7cb53so16989188fac.10 for ; Thu, 13 Apr 2023 01:28:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681374502; x=1683966502; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=3lVC0QIahWICPUq2qmNtFjM9vCzRJJrRAYj3XSJFtR4=; b=Ll5bzTd9Zo3pxJCXNWIq1d/D5RufxKWgFf4ZG+qAJ4wFkRsvu+/vg/diWSShedfArH cbn67u70O9g4ivni3kEBudYPY3UuH6h1N6FriBHXtz2JJhB7C0ryHCBIBmD2LwGwFP2K lF5dFmWVXteeG2z5il+l1tWnXO1W1ovOw5H35z/tG2vQ+5NxBEPa2eROBJ9Bai9vrR+3 y00kReBbAUr7T6odBsmHogkpoxCGm8ewPKkMs0Rjox4rnoDaKmKgThHkckguPhP6D+Ux o+WD6iJI7wvgeo9Sf9lFUGjYc0BuqgPPOh3B9NWoOzMq9KGkXUlnH9EKwMlDgj8mTo65 H4yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681374502; x=1683966502; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3lVC0QIahWICPUq2qmNtFjM9vCzRJJrRAYj3XSJFtR4=; b=A6wuhmoEUQGd8s+ptJO1lthk41waDIuumzzBxt9XMlHoNSOJWtu6g0iNSV6ab5uCJM iTSq2KHQ5XRDz6voBI5A2/67R4nxDfSRbrzeKC/83SIiTSDiu/f2aPGqTaygqOaXOWSQ hXNxWAngMBQiC3zck9aN7D02XrvEvs6wP3w60OhMZMwf4flsrxn8yJomKwsObGbTbesh +RX3nkaGL6OMCEfHl66xIs/oc6HNP2dIcCEa1cFNvKO0PCcKY3VA1JsGCe+JKIXI0DkH gka6Wjl9NEPqKoapNh28AOfbbtTt0qzHrj1Rwa/hZA8bQIuYipBSKLlu2CzCfOoHaZSV cL7Q== X-Gm-Message-State: AAQBX9dNMTNqyYqhrxScOkC6HiIFpzlx6ESpL7ahqwy90q2B5n++JnyR bApwqbXFSal3H2Xqm7L8EXGFUmgaZvy/wQkwBGnnvwsTFa0= X-Google-Smtp-Source: AKy350at+3KAu/ysiXmBQRGHdTbiseSU9DNjoDR0xCWir5/KG5LzHG35x7sV42wjK6iEbBIZrJylaeIvWSfFnaYHs9c= X-Received: by 2002:a05:6870:2e0e:b0:187:7524:9a8d with SMTP id oi14-20020a0568702e0e00b0018775249a8dmr2007003oab.4.1681374501888; Thu, 13 Apr 2023 01:28:21 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Fabrizio Lamarque Date: Thu, 13 Apr 2023 10:28:11 +0200 Message-ID: Subject: [PATCH v2 1/3] iio: adc: ad7192: Fix null pointer dereference on probe To: linux-iio@vger.kernel.org Cc: =?utf-8?q?Nuno_S=C3=A1?= , Jonathan Cameron Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Pointer to indio_dev structure is obtained via spi_get_drvdata() at the beginning of function ad7192_setup(), but the spi->dev->driver_data member is not initialized, hence a NULL pointer is returned. Fixed by changing ad7192_setup() signature to take pointer to struct iio_dev, and get ad7192_state pointer via st = iio_priv(indio_dev); Fixes: bd5dcdeb3fd0 iio: adc: ad7192: convert to device-managed functions Signed-off-by: Fabrizio Lamarque Reviewed-by: Nuno Sa --- Changes in v2: obtained ad7192_state from iio_dev pointer as suggested by Jonathan, removed Reviewed-by since the entire patch changed its content. drivers/iio/adc/ad7192.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.34.1 diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index 55a6ab591016..94a9cf34a255 100644 --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -380,9 +380,9 @@ static int ad7192_of_clock_select(struct ad7192_state *st) return clock_sel; } -static int ad7192_setup(struct ad7192_state *st, struct device_node *np) +static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np) { - struct iio_dev *indio_dev = spi_get_drvdata(st->sd.spi); + struct ad7192_state *st = iio_priv(indio_dev); bool rej60_en, refin2_en; bool buf_en, bipolar, burnout_curr_en; unsigned long long scale_uv; @@ -1073,7 +1073,7 @@ static int ad7192_probe(struct spi_device *spi) } } - ret = ad7192_setup(st, spi->dev.of_node); + ret = ad7192_setup(indio_dev, spi->dev.of_node); if (ret) return ret; From patchwork Thu Apr 13 08:33:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabrizio Lamarque X-Patchwork-Id: 13209944 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 3F581C77B6C for ; Thu, 13 Apr 2023 08:33:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229707AbjDMIdx (ORCPT ); Thu, 13 Apr 2023 04:33:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229734AbjDMIdv (ORCPT ); Thu, 13 Apr 2023 04:33:51 -0400 Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47E802D7F for ; Thu, 13 Apr 2023 01:33:44 -0700 (PDT) Received: by mail-oi1-x22b.google.com with SMTP id bm45so3772526oib.4 for ; Thu, 13 Apr 2023 01:33:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681374823; x=1683966823; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=MkMEzm5Bx+QwNMXwUVJE0CRyJbdWVf8/MgbsIc/reEk=; b=BumFeyqwA36Fj16Pq20+nre14YxBJvUrBmQ37WYLkexmyykG0AikAHIIN8hPww1HTw Cbiookm218ZwhMtsCTC2PC8WkVuAqgoI85wX8i6RAaK/H5pAAwimB97vDpwhyGt/3RBZ 5a+Kn7FzI2VXwdRJt4nPSItU8eD/CZaoapkGakrT3zxVNfkQ0g6kpedsRcmVqyzMmeHe Ib5vL6WcHhpv2GxCJUOVl8FGVINQTOkNclqV0o7tVvGujKlpLhIp5VouOLdaWKBX+plW IbccxXO0YZ3ZM8vvCnPO6tbi7tBgkbjskCNs0Vd+zl5QJJWxOe734mOQWAQSKzkFSuWj txMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681374823; x=1683966823; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MkMEzm5Bx+QwNMXwUVJE0CRyJbdWVf8/MgbsIc/reEk=; b=Ot+DNz1e1E14N4zyYuCFw6R6iuGrZ81yjmtSsT2OLzjRcYxr97uOR9uMPeXIlKPe/1 ZdcY23cwvfVokuByC8/1sXv4z2+rWNaX5ebvxPbUESp1zxClhOv1NBLbiC9cOAaJiIHB HFYgqg2DtJwS7mrshqPQslpzCaYlm4iYcUaywHUQbYHyScpqpgNpr0gNM3pGTfnK2rG+ z3Px5Eu1cYuEj1NYjNJ8lD9CRBxzsdBHzG1H051wDcyhFTuvKAJnjVL0aPzhKk5+9TOh l/Bn8HM63GmUmEq+RrvGXbZYDvMNzd2C0w/FvuDJPMpUDS4B1AcoC7+Q7M7+V2gg6Up1 5mdw== X-Gm-Message-State: AAQBX9cuZybnkGKyVjOhXW3T1pJ0uk6xXvSX4fo+dnIgephcdNx+3FFB Mz8beaDH/e+k1spUGWZ36DtR6PKEl3OM2FNNHIXyU7KftJM= X-Google-Smtp-Source: AKy350bODJ1Ik81e+LL9IflbvdqZdPkk9L6ywy27gSSjwHxLofIrrCwNH0nSFQiz6qSEDPKh8K/0vC2K3FEePK+0GIQ= X-Received: by 2002:aca:120c:0:b0:38b:f7fa:40ac with SMTP id 12-20020aca120c000000b0038bf7fa40acmr313205ois.8.1681374823427; Thu, 13 Apr 2023 01:33:43 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Fabrizio Lamarque Date: Thu, 13 Apr 2023 10:33:32 +0200 Message-ID: Subject: [PATCH 2/3] iio: adc: ad7192: Fix internal/external clock selection To: linux-iio@vger.kernel.org Cc: =?utf-8?q?Nuno_S=C3=A1?= , Jonathan Cameron Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Fixed wrong selection of internal clock when mclk is defined. Resolved a logical inversion introduced in c9ec2cb328e3. Fixes: c9ec2cb328e3 iio: adc: ad7192: use devm_clk_get_optional() for mclk Signed-off-by: Fabrizio Lamarque Reviewed-by: Nuno Sa --- drivers/iio/adc/ad7192.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index 94a9cf34a255..5a9c8898f8af 100644 --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -367,7 +367,7 @@ static int ad7192_of_clock_select(struct ad7192_state *st) clock_sel = AD7192_CLK_INT; /* use internal clock */ - if (st->mclk) { + if (!st->mclk) { if (of_property_read_bool(np, "adi,int-clock-output-enable")) clock_sel = AD7192_CLK_INT_CO; } else { From patchwork Thu Apr 13 08:36:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabrizio Lamarque X-Patchwork-Id: 13209945 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 8CC42C77B6C for ; Thu, 13 Apr 2023 08:36:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229864AbjDMIg5 (ORCPT ); Thu, 13 Apr 2023 04:36:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbjDMIgz (ORCPT ); Thu, 13 Apr 2023 04:36:55 -0400 Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BF4B8A49 for ; Thu, 13 Apr 2023 01:36:40 -0700 (PDT) Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-187916b6543so1263849fac.7 for ; Thu, 13 Apr 2023 01:36:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681374999; x=1683966999; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+VPypZbNf/Utk12NhniVwsu/FBDBW0lw5cAil4ugID0=; b=oduWMN+YeHD8UlReGK0+YcaDwbk1MWEQJKcJZhGiK8vJAmEMmWsr1S0RNit4sHuE0W Bg2+ul4kXpkxY+MtR9VKlfLmsVBztERv6mU0P9jnyRqWPz98Ya2ORxyU03J9kKYOQlev e1ct26n06lONYQ8PC0nEKL6SWO1pQppDsiywtwZT79LCx2JMDGUMFKiPH0HjfD0rcsYi JvQt3hNTzEFKFerwY8HfT7Rsi1udlJgabFkGe5fj1qYj4sNaeDw/B03BsK66VCbmQc+C 8g1bjk6DKvErxmY3wd2s/91A2qccfQOg3C+zI0khSIbHrO57TnnIHLdBFA/Tm/YPQiW/ 4+Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681374999; x=1683966999; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+VPypZbNf/Utk12NhniVwsu/FBDBW0lw5cAil4ugID0=; b=fETmQKQbYI4EIY0zG3ewCIR8JvkOdvSANSVm+HDdhMMltM3ajnBizD2v9qTqw1GWVH OrEUCHki52OsF+2sr6FI0OMt8naEEhMJ5tN9F8vdOGT1Yrz5h9a9GgNaNOe0eB1gA/4b a2088IanIJbuIz2mxZBXVKw3PpBP64ETsIZky+l/iGu933KDSrS/wfwuHNF/PWODjsjY ir/rQvF9xopWpb8GJ/oFY/C0y9Lx1yxs2mT2Q5IGLMtbM4n3fozNFqW+L3MYKksydRnp dXS5YbWo9mVhniIFCW3VyGzEV8Qu/CisiXBQvaMRX4GhGd8KOj1/ntEWzuYTOBVs3bL1 dpLg== X-Gm-Message-State: AAQBX9cJWactaoVtzmMUJqVbz+rLG0GeBrcyO7dJJenCm6OWn/47eNbF 2t2EDvG5XQxjoIo0iWKL+v85va/PXTnPxSokJCCgQrXJLsM= X-Google-Smtp-Source: AKy350Y3quS2UM1ecpArFVp/EsMHeWJcmnNUU3nF0ev+o/WaGwNXwslus0OkXkd52lOVsPfFzD9txsF7qu/S1N7lg3M= X-Received: by 2002:a05:6870:40c1:b0:184:7e3c:e33e with SMTP id l1-20020a05687040c100b001847e3ce33emr705597oal.8.1681374999639; Thu, 13 Apr 2023 01:36:39 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Fabrizio Lamarque Date: Thu, 13 Apr 2023 10:36:28 +0200 Message-ID: Subject: [PATCH 3/3] iio: adc: ad7192: Clarify binding documentation To: linux-iio@vger.kernel.org Cc: =?utf-8?q?Nuno_S=C3=A1?= , Jonathan Cameron Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Added undocumented properties: - adi,clock-xtal - adi,int-clock-output-enable Removed clocks from required properties. Renamed avdd-supply to vreg-supply, while keeping backward compatibility (deprecated avdd-supply). Signed-off-by: Fabrizio Lamarque Signed-off-by: Fabrizio Lamarque --- .../bindings/iio/adc/adi,ad7192.yaml | 28 +++++++++++++++---- drivers/iio/adc/ad7192.c | 18 ++++++------ 2 files changed, 32 insertions(+), 14 deletions(-) return ret; diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml index d521d516088b..5dc7a7eea5f9 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml @@ -32,7 +32,9 @@ properties: clocks: maxItems: 1 - description: phandle to the master clock (mclk) + description: | + phandle to the external master clock (mclk). If not defined, internal + clock is selected. clock-names: items: @@ -45,7 +47,23 @@ properties: description: DVdd voltage supply avdd-supply: - description: AVdd voltage supply + description: Phandle to reference voltage regulator. Use vref-supply instead. + deprecated: true + + vref-supply: + description: Phandle to reference voltage regulator + + adi,clock-xtal: + description: | + This bit selects whether an external crystal oscillator or an external + clock is applied as master (mclk) clock. It is ignored when clocks + property is not set. + type: boolean + + adi,int-clock-output-enable: + description: | + When internal clock is selected, this bit enables clock out pin. + type: boolean adi,rejection-60-Hz-enable: description: | @@ -84,11 +102,9 @@ properties: required: - compatible - reg - - clocks - - clock-names - interrupts - dvdd-supply - - avdd-supply + - vref-supply - spi-cpol - spi-cpha @@ -114,7 +130,7 @@ examples: interrupts = <25 0x2>; interrupt-parent = <&gpio>; dvdd-supply = <&dvdd>; - avdd-supply = <&avdd>; + vref-supply = <&vref>; adi,refin2-pins-enable; adi,rejection-60-Hz-enable; diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index 5a9c8898f8af..a0cac9b60ea8 100644 --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -176,7 +176,7 @@ struct ad7192_chip_info { struct ad7192_state { const struct ad7192_chip_info *chip_info; - struct regulator *avdd; + struct regulator *vref; struct clk *mclk; u16 int_vref_mv; u32 fclk; @@ -1000,17 +1000,19 @@ static int ad7192_probe(struct spi_device *spi) mutex_init(&st->lock); - st->avdd = devm_regulator_get(&spi->dev, "avdd"); - if (IS_ERR(st->avdd)) - return PTR_ERR(st->avdd); + st->vref = devm_regulator_get(&spi->dev, "vref"); + if (IS_ERR(st->vref)) + st->vref = devm_regulator_get(&spi->dev, "avdd"); + if (IS_ERR(st->vref)) + return PTR_ERR(st->vref); - ret = regulator_enable(st->avdd); + ret = regulator_enable(st->vref); if (ret) { - dev_err(&spi->dev, "Failed to enable specified AVdd supply\n"); + dev_err(&spi->dev, "Failed to enable specified VRef supply\n"); return ret; } - ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, st->avdd); + ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, st->vref); if (ret) return ret; @@ -1018,7 +1020,7 @@ static int ad7192_probe(struct spi_device *spi) if (ret) return dev_err_probe(&spi->dev, ret, "Failed to enable specified DVdd supply\n"); - ret = regulator_get_voltage(st->avdd); + ret = regulator_get_voltage(st->vref); if (ret < 0) { dev_err(&spi->dev, "Device tree error, reference voltage undefined\n");