Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp475924lqp; Wed, 12 Jun 2024 07:17:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUJvGjS6amsnpueRyc1fac0+2/480p9fVWH1MKgmL4BAYoTb416GxyFkCLkIBzE698EeWOWp76uGbOAxledvRJjTsrDRmD9EtrYLQwuNA== X-Google-Smtp-Source: AGHT+IF8qcZlajQsjn8xh93tSPtQmeF1qwFVa7vjdKvalKW/7+7s1IPI8erH8cejUfJdhnIZ9iRj X-Received: by 2002:a05:6808:2020:b0:3d2:1b8a:be32 with SMTP id 5614622812f47-3d23e0a7876mr2265321b6e.42.1718201873187; Wed, 12 Jun 2024 07:17:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718201873; cv=pass; d=google.com; s=arc-20160816; b=JEIylk+LA/N/HbD9t2eAp25iG0SevJrAjuCktNfzTRG5JVoqbN2gSporIMWuJfhc6d FKoTraIaGDdO99yvKFgrBXnOO7UXm6QBtzbyO8RcpC5rHB5WtZ+SNs/JeruAiLLOebtY 0ybtdSuRW139tpNfVbhnnLHsMjFCOnSUyJ7Wu3YmU3BuE8T0Y4+rpPwY/Jocm+hBK0yD ZKfE7UCA2VJbJ32/tcRkUZEFzNet7t4JJitN/hDgKvqfmqqDgFPXtMyfiBc/5J4jnRIo cnV0M3XmlzatXwvjqvsWWt7ck7yr/4P++wJkDXDiDaA/CPJ8Cm2QMTFZWBqsx5VC9kw0 KZ/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=hftruIW0KQj7Pfx4TS18oMb+ZkfBePj5jiEFqzrWZWg=; fh=FKM2odL4Up3nifD3Ec9PTVy7Y5YvTduCsE9MZyDAHUw=; b=bQBjXVi6dOKJnTriwDlQoYu1YepB4amWcLox2vaUCeXPQH9lJ9JgNumoio8UkNt9SV /YJIYFmKoifF9XcBxm/sa0xP1UlkKEeNKJrXVk1tdh0j1mdyRkhFi7SDI6DmrYF2/sKX 10W25d4oqSNvb+8BIiWItGMQCTYGKCxBuWnTfdtbPxnhznYrdIMmTbU0t44sDd385k8E 3wX8yIfJGORjlVdTI9QQ9uPOvX6hezCWQVDb73+eK6nqtndUYEVewv2wQ1SR6KcdDBtW ELIkS+/5jKzwwAfsFU9aTKJ6eIVDBE66nnVppIHN0DD8qCw9dH4yISzbRbkj9zQ1A5oD lDNQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BP5tmI2Y; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-211653-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211653-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ada2fe7eead31-48c735836e2si1847163137.565.2024.06.12.07.17.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 07:17:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211653-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BP5tmI2Y; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-211653-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211653-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id CE11B1C21519 for ; Wed, 12 Jun 2024 14:17:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4BA3917E8E1; Wed, 12 Jun 2024 14:17:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BP5tmI2Y" Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCE2D537F8; Wed, 12 Jun 2024 14:17:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718201848; cv=none; b=cy0MSUx595pIoLt1WFLjR48EL27Y5F0R/mwCLoatN6uGZJxp0i4jnm3jVaCG6uoyzBxD/G8GHkJjaKwP0U+m3Gj3TwhaZGfsSHHx4k/JSYm60kivZlkWrWtDV9ZbzOQTV2b+aD9kFyIAp9w0tvHiYx8PbQwuQxhTQCa7F6bZH/0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718201848; c=relaxed/simple; bh=Cka+oLL1qhMjYwntvJYzxyxhdG6S7GtJtZp7v19EnZQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VM8ZNjil6fUtyvN7ep0sfVPyxSqkr/82jBo1OCPnKp/HWMnWbmW7wU7ujWfRTrleLTr0zuKSxQj93+oKtVELKsUgGq5r/r1ScHwyw1XIucsa69l6sZzsTPp1YRk7Qbn74mIbsc8oilptqADjWNtTn50mi4wn3g17UxAAIzArbds= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BP5tmI2Y; arc=none smtp.client-ip=209.85.208.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2ebed33cb67so25600301fa.0; Wed, 12 Jun 2024 07:17:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718201845; x=1718806645; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hftruIW0KQj7Pfx4TS18oMb+ZkfBePj5jiEFqzrWZWg=; b=BP5tmI2YYguGAXXM9PwriQ+/T1PXlXoIkZWyjgNIAZ/J4n9T2r4W4bY6jijT5sPvx4 UQHPHPpQewDppVi0Klv6a3teHvgn0f33HWT6hVbOACjsV5Mpim8oNbUSnppRt1MElfH3 Xct6BtyT56NOmAOTtPw79L/iiXuvWcRGuI3JCaPxIO+0xYMpDJtfPorb7wvmxDtvDRJc 2s2d+ntjWQn0HSoh/+lBj9hRh9pAyGEETeLbYyBuxz0BoEippOrtBYJfV9mjV8+/C5Q0 vZVUNNTSxlKA+oWdXxtDEpKvTHnuKqsiAaTgTM/ooa7SVkj8JErhUl+6B7nUiO88/LAt lbCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718201845; x=1718806645; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hftruIW0KQj7Pfx4TS18oMb+ZkfBePj5jiEFqzrWZWg=; b=Rf9atYgn/Kew602VRBwAYMSRDD/tXqWSRmiU7Gdku3DkDangITxV0MbcucF8kDH1nX WZZ+p+GpxB/5e/yhgSDjxe+M5/PrgOjukhYsUPDPn0pxjwZGCVzcFPd9H4ywz4mEynmY 2ecUy5crtN4EARun75upqcviWLva6nSm08l2Qq4LruicRSTpAsTbOvrUix9ZG4qVONr3 vv4JbMqj9NL33KZGwQbvPXR3ABkIZUhWSAh7cF0gPaE2BeYfQNA2zkBQewalHZUwb2dH 2L3gjbPYJqRwfvVS7ezHm+2WlWZky62mmvnw7vUZ+xabOdKLfAObU5F4mXOLlU8sQFn7 97+w== X-Forwarded-Encrypted: i=1; AJvYcCVYLf5At+9J3NxJ+jk7/vzJFnxTND9vW61CyVLLOwEEpcsEeBuYRIxVMSbviSQIfdA2fXCd49kZwi8YKcudtEUf4UV3f3gO2V69akrZ8EdLjKMBEWJHc+w+uw0DhzIKoJdDOEaHBa0oMpqHQjwYoLh4qZ9EtAbDPmBnFc4HpPDnnM0WbQ== X-Gm-Message-State: AOJu0YzzNCXYcEqssjTMSgQYQkU5TOiEwJ+DapTekPOGOYd7h+oTxaWN 9wuc4qjzM7zbqpD8eXiPKzltAwNiRToXKizXVN9BY1wJvKI1MWEYclW8fg== X-Received: by 2002:a2e:8508:0:b0:2eb:242b:652a with SMTP id 38308e7fff4ca-2ebfc8bbde0mr13764651fa.15.1718201844912; Wed, 12 Jun 2024 07:17:24 -0700 (PDT) Received: from spiri.. ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42286fe75ebsm27876655e9.9.2024.06.12.07.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 07:17:24 -0700 (PDT) From: Alisa-Dariana Roman X-Google-Original-From: Alisa-Dariana Roman To: Alisa-Dariana Roman , Jonathan Cameron , Michael Hennerich , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alexandru Tachici , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Subject: [PATCH v3 2/2] iio: adc: ad7192: Fix clock config Date: Wed, 12 Jun 2024 17:16:37 +0300 Message-Id: <20240612141637.175709-3-alisa.roman@analog.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240612141637.175709-1-alisa.roman@analog.com> References: <20240612141637.175709-1-alisa.roman@analog.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit There are actually 4 configuration modes of clock source for AD719X devices. Either a crystal can be attached externally between MCLK1 and MCLK2 pins, or an external CMOS-compatible clock can drive the MCLK2 pin. The other 2 modes make use of the 4.92MHz internal clock. Note that the fix tag is for the commit that moved the driver out of staging. Fixes: b581f748cce0 ("staging: iio: adc: ad7192: move out of staging") Signed-off-by: Alisa-Dariana Roman --- drivers/iio/adc/ad7192.c | 58 +++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index 0789121236d6..2301fee9ccd0 100644 --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -398,25 +398,37 @@ static inline bool ad7192_valid_external_frequency(u32 freq) freq <= AD7192_EXT_FREQ_MHZ_MAX); } -static int ad7192_clock_select(struct ad7192_state *st) +static const char *const ad7192_clock_names[] = { + "xtal", + "mclk" +}; + +static int ad7192_clock_setup(struct ad7192_state *st) { struct device *dev = &st->sd.spi->dev; - unsigned int clock_sel; - - clock_sel = AD7192_CLK_INT; + int ret; - /* use internal clock */ - if (!st->mclk) { - if (device_property_read_bool(dev, "adi,int-clock-output-enable")) - clock_sel = AD7192_CLK_INT_CO; + ret = device_property_match_property_string(dev, "clock-names", + ad7192_clock_names, + ARRAY_SIZE(ad7192_clock_names)); + if (ret < 0) { + st->clock_sel = AD7192_CLK_INT; + st->fclk = AD7192_INT_FREQ_MHZ; } else { - if (device_property_read_bool(dev, "adi,clock-xtal")) - clock_sel = AD7192_CLK_EXT_MCLK1_2; - else - clock_sel = AD7192_CLK_EXT_MCLK2; + st->clock_sel = AD7192_CLK_EXT_MCLK1_2 + ret; + + st->mclk = devm_clk_get_enabled(dev, ad7192_clock_names[ret]); + if (IS_ERR(st->mclk)) + return dev_err_probe(dev, PTR_ERR(st->mclk), + "Failed to get mclk\n"); + + st->fclk = clk_get_rate(st->mclk); + if (!ad7192_valid_external_frequency(st->fclk)) + return dev_err_probe(dev, -EINVAL, + "External clock frequency out of bounds\n"); } - return clock_sel; + return 0; } static int ad7192_setup(struct iio_dev *indio_dev, struct device *dev) @@ -1309,23 +1321,9 @@ static int ad7192_probe(struct spi_device *spi) if (ret) return ret; - st->fclk = AD7192_INT_FREQ_MHZ; - - st->mclk = devm_clk_get_optional_enabled(&spi->dev, "mclk"); - if (IS_ERR(st->mclk)) - return PTR_ERR(st->mclk); - - st->clock_sel = ad7192_clock_select(st); - - if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 || - st->clock_sel == AD7192_CLK_EXT_MCLK2) { - st->fclk = clk_get_rate(st->mclk); - if (!ad7192_valid_external_frequency(st->fclk)) { - dev_err(&spi->dev, - "External clock frequency out of bounds\n"); - return -EINVAL; - } - } + ret = ad7192_clock_setup(st); + if (ret) + return ret; ret = ad7192_setup(indio_dev, &spi->dev); if (ret) -- 2.34.1