From nobody Fri Oct 3 20:25:50 2025 Received: from mail-oa1-f51.google.com (mail-oa1-f51.google.com [209.85.160.51]) (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 A47202BE02C for ; Mon, 25 Aug 2025 22:55:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756162543; cv=none; b=HFHRMI/wY75I9a+G5xpbBkkUB+qCEV2jKBi7kc65li98Dbh8xrR1Rbqi1B4dMMt/e5ErV/gyDyuZVdq65gHnbltg6eyk6RpGPzzgqr8odbq05Gk5mKwzahFoRhBw0T4eGNtd0K7H69y23JVRT+1WAZ20bXl4oBUn2TFsbSoumSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756162543; c=relaxed/simple; bh=ejiW++p+A0I9xjvm23IuPsPQ6EO4iCmJb+R47NFoGFU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Buf2akt5E1mWUhCuyYJiwa/L1xZK1SaC0Awr0UY7bYzpj1GtEWjFS0ix1J+oIJAgXRnW6Y7Sce7sJEE757TZ42xNpmHMRx8pO0LJ/uGgasr+9iKD5GMw+Ic002yvYs/69ia2zqkW46MHU08l74V+pEEeUo4i0cAUoT2DFA5Np/M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=raYk3nZ2; arc=none smtp.client-ip=209.85.160.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="raYk3nZ2" Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-30ccec928f6so1484682fac.3 for ; Mon, 25 Aug 2025 15:55:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1756162540; x=1756767340; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=mCS1blGVKzhibBa+GC93mJ6dY0HkTwPO0389IUyBXCQ=; b=raYk3nZ2h0JirOq0RbGPWGuD3i/BfBEOaDV3EFRISMwqJVjv1cNXk5GdWfFg27GaXW AimnX2M4TBmeZKETT7ujlxZ1pKc0Zvz5KIRkkw3nJaGsVUgunBxfLnEB7B6bTXusaJ16 RJu+9NtC0E5SmLXDAVvEsYl0U9y/Xc9V86U+DFECvGSEuUzHN/a0m8iVCr/HvAtMrema ou6sGk5uC1lCHngoqADlNv3vyu6wu70l06ZVdMGBHJQl5uuQorPXvjHdW4aTM8Ncclmd rPDafvoHbcUdbHV0pmnAvqcPRxIQWydLU+iwCymjcSu+wV2eJVGKU7a04D7PNtpwNDVN nHgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756162540; x=1756767340; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mCS1blGVKzhibBa+GC93mJ6dY0HkTwPO0389IUyBXCQ=; b=iA/Y9U79tiR2aj416Nj022mM8h1dxdncZuk1Rrg1HV1UmD21IuwRxAICxRGYFTeQpK uXmPWuulgaYOKF95+5Ykj3prOIDlK986LSJLGMLyVA8hj5t8LbMT7BiI5hdtcVCRPSfn IyKbsP8N71hGitvRp1ZtUeWMd8QgdC9sAl+EeMOOJFohQxcthOL5if3MZmRjV/f7EpMM j+mPa76DYKA+Z5d9eq7+ShfKVgsMAGP/hQN5mlQnRAvl+PPwqG2XcaG6ikkoKl1ucW30 9WR5o66tfCESc23xoWoDkDpw3+qs26SGgOIUpMqUknWhRF8gvdcbh+iJxkrFBe0eSQ+w zJaw== X-Forwarded-Encrypted: i=1; AJvYcCVfx4czlIVX9lf9V0iCEzS/e1ewwuAkTlMn4SDLaw+6NKbfwXwk4zRLbq+0wHVS2egjcgVJhNxAvbJ/DCA=@vger.kernel.org X-Gm-Message-State: AOJu0YzmGctT6rmsO5ZmuSfUslnyodIEQqH5yjoYt92G/o7Mi7u7NSgi ZQxX7Gj4o06Ie7Z8xilnuI4yTLTDGhwX2tmvGN0P6XXMpJHpWiFxsU5q6QjwhsKi1sicabmQdcl no8cG X-Gm-Gg: ASbGncs2Z5Hy3nz0Z/HTgrhEEunhXWeLspcvr3UNpbmJlOhpmwBctSAIRw6Sei1uEG9 ca8GhTEAHYjxh/6ifdNI0r0DGXhIabLlMCH5aOXNQ6zH2G+uNE0YqlZDnLKayDFQ4emC6MlEsZ1 vYE1gqsPomMwWHsc4+2sYyNKs+zdRsHhSJXnFlIIhex+87hBFvF4IpsL4JNgPv3fzsLM5RIbFGq h3Zjyjj43VZoJnRWj60VaL9UnS3ZoAbGR4oqBs2F0tWMY6Le6f9bh4hw96M76QQczYL4v9/QTkr 43AMFJcaaHkwTInd3GRCQpz3Ceu0A/F+RDUJF7Sf3rNSZTWMU9drtRy3k176b0oFCE+lGpUtVCb ErRbiPm9UHKhf5aysMJSd8wEpmz2ls+2fBtunACM= X-Google-Smtp-Source: AGHT+IG4VbfJVkJxZqA+j3n+8jvXqEZbWK6Ftb5Y0wcjCOXmZgkbdUMlYCsFzEePddd25RPW+aio1w== X-Received: by 2002:a05:6870:1698:b0:314:b6a6:68aa with SMTP id 586e51a60fabf-314dce1b218mr6156559fac.50.1756162540620; Mon, 25 Aug 2025 15:55:40 -0700 (PDT) Received: from [127.0.1.1] ([2600:8803:e7e4:1d00:5075:40f3:ff25:c24c]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7450e49d36esm1991747a34.40.2025.08.25.15.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Aug 2025 15:55:40 -0700 (PDT) From: David Lechner Date: Mon, 25 Aug 2025 17:55:00 -0500 Subject: [PATCH v2 1/4] dt-bindings: iio: adc: adi,ad7124: fix clocks properties Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250825-iio-adc-ad7124-proper-clock-support-v2-1-4dcff9db6b35@baylibre.com> References: <20250825-iio-adc-ad7124-proper-clock-support-v2-0-4dcff9db6b35@baylibre.com> In-Reply-To: <20250825-iio-adc-ad7124-proper-clock-support-v2-0-4dcff9db6b35@baylibre.com> To: Michael Hennerich , Jonathan Cameron , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3149; i=dlechner@baylibre.com; h=from:subject:message-id; bh=ejiW++p+A0I9xjvm23IuPsPQ6EO4iCmJb+R47NFoGFU=; b=owEBbQGS/pANAwAKAcLMIAH/AY/AAcsmYgBorOnQTpaL89+dgO4/3roWZJ3pfkCnrM9sgbTYp 69gDTUeMLeJATMEAAEKAB0WIQTsGNmeYg6D1pzYaJjCzCAB/wGPwAUCaKzp0AAKCRDCzCAB/wGP wKXZB/94Npdyo0oG2GLwGHIRiUblJ/LO92HfZFEtoR9yHzK2EzuzUTptn0My93mXkFjWFrR0rqE pGf47hKzPM/uQdvDDvWIQxElDCdZLvDDnsskpkYFmSt4NZ+8NwR6LJwJTrQL+ETXRuqFJUUHXeC hChKs17tcnrW/YnI3A4Cep96UcZL3od5n5Rm09eIe2MZcwHikmSg+TYu9DDAQIjzfKXBYmdm9kL WzeHXQmSanbjEkgGTeTeN7abWznb9kzbmZtu+twd4Qoja+wp8uPWwxhDOQAKzyiIJ+cqUdrwyxu 1csZ9aC5Ho6zvTGZ2+Tx+toMDO13ZdYirBeDi6ysFmXLMpjF X-Developer-Key: i=dlechner@baylibre.com; a=openpgp; fpr=8A73D82A6A1F509907F373881F8AF88C82F77C03 Use correct clocks properties for the AD7124 family of ADCs. These ADCs have an internal clock along with an optional external clock that can be connected to the CLK pin. This pin can be wired up 3 ways: 1. Not connected - the internal clock is used. 2. Connected to an external clock (input) - the external clock is used. 3. Connected to the CLK pin on another ADC (output) - the internal clock is used on one and the other is configured for an external clock. The new bindings describe these 3 cases by picking one of the following: 1. Omit both clocks and #clock-cells properties. 2. Include only the clocks property with a phandle to the external clock. 3. Include only the #clock-cells property on the ADC providing the output. The clock-names property is now deprecated and should not be used. The MCLK signal that it refers to is an internal counter in the ADC and therefore does not make sense as a devicetree property as it can't be connected to anything external to the ADC. Since there is only one possible external clock, the clock-names property is not needed anyway. Based on the implementation of the Linux driver, it looks like the "mclk" clock was basically being used as a control to select the power mode of the ADC, which is not something that should be done in the devicetree. Reviewed-by: Rob Herring (Arm) Signed-off-by: David Lechner --- .../devicetree/bindings/iio/adc/adi,ad7124.yaml | 21 ++++++++++++++++-= ---- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml b/Do= cumentation/devicetree/bindings/iio/adc/adi,ad7124.yaml index 4dd5395730c10925c86782116dfd70a75d033bfb..2e3f84db6193b3d8765e2bdbd2d= 3175cf1892ba4 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml @@ -28,12 +28,21 @@ properties: =20 clocks: maxItems: 1 - description: phandle to the master clock (mclk) + description: Optional external clock connected to the CLK pin. =20 clock-names: + deprecated: true + description: + MCLK is an internal counter in the ADC. Do not use this property. items: - const: mclk =20 + '#clock-cells': + description: + The CLK pin can be used as an output. When that is the case, include + this property. + const: 0 + interrupts: description: IRQ line for the ADC maxItems: 1 @@ -67,10 +76,14 @@ properties: required: - compatible - reg - - clocks - - clock-names - interrupts =20 +# Can't have both clock input and output at the same time. +not: + required: + - '#clock-cells' + - clocks + patternProperties: "^channel@([0-9]|1[0-5])$": $ref: adc.yaml @@ -136,8 +149,6 @@ examples: interrupt-parent =3D <&gpio>; rdy-gpios =3D <&gpio 25 GPIO_ACTIVE_LOW>; refin1-supply =3D <&adc_vref>; - clocks =3D <&ad7124_mclk>; - clock-names =3D "mclk"; =20 #address-cells =3D <1>; #size-cells =3D <0>; --=20 2.43.0 From nobody Fri Oct 3 20:25:50 2025 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (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 8623A2C08BF for ; Mon, 25 Aug 2025 22:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756162545; cv=none; b=oSG8L74X2aySDlpBcZsknT8Db5tZAawfQRDUFA+byXe3WjcAFBzQ6yJE/dMdIriyesTbzQR6EUsBCDNDWsE9582ktD+73G4MXo7eIKrCnHE99sMkh3fPezkzIINt4CtN6w14bGL+jGHIvmb8sFIUyHO7ZPutkfHeP1BssCHnP0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756162545; c=relaxed/simple; bh=iRPbZ3NmESqwUlU+AgCDLlpOo6ZQJuC2kenB043PMZY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FMfPHzoggPPgDH+0Sw+NMrgqp8vUdIbGTzGjujQpjIv0fbgG6evUp5iP2YjbX77KOt/trlyrsDxjjbmOWYVrD3Z6j/sh/k0XpzhXx+JY6TiKZtgI1XeGgSVIxQKeATlFh5n5BLI5DHYfioJNDITs09S1rE1Qmec1+ifDPBAogeQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=ekB0ld9Y; arc=none smtp.client-ip=209.85.210.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="ekB0ld9Y" Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-74526ca7a46so399612a34.2 for ; Mon, 25 Aug 2025 15:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1756162542; x=1756767342; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=USr+bxgxSSWwC2RjKRZCmku7TsEQGjaRWrkzaOYT/hU=; b=ekB0ld9YKtmuu+JauQS1tllkpphT66gdfz5wqQMa+jnPZFKNnO48uAmlibi+sjDoEj 7fsIya5NudA49tMIkT068hUdWvGnZckbu9CSF3XJzuigwGUUnvBrfHcpi/DYSGgLbDy1 gcdgDkZj3dnS9XZq9UwP3kkc5A54/DcTth39OAsUyJiRK9KFJiBpg507vAJ+PIgm0z31 QRMMB4ODoTsLKYZyLxCkX/75nIEeN0nuBoiGFD1DbXrIYHsz80iljRTpNPg5O9I22yCC rTh4XRnJRpQ6gFlpTmr1dLriwz0O4svS1jhr8XRjdL4IY5YO8H6+S6nC/juRia0/6igx O/yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756162542; x=1756767342; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=USr+bxgxSSWwC2RjKRZCmku7TsEQGjaRWrkzaOYT/hU=; b=YiyPmQCyYn0+farviaj91wTGYbJkMmyuQfrH+MPqfcqYIOlkx5Uv57oXT5qQl9xVFT i/l1DArmfvRMZhwyQ6/qxdt35QR06UvteOyZ0Ush4LSp7QZ1Ik2YGsD+XSaZrHVCsUye BZwZLyUVcOy5CyqEw8490Mibe0mUNn7BfqvLYbheEXGpVzcbNSEmrFh3PsrnrXk70oj9 kmgyG1GoV6X+0NW9snTaE7DipXGmGAhTSd6XTBekVs96zIrmrvSmxX8se5R2Vbl0mB0D 27taQZuDiMFcFDbgNjUp5YxSpkl9qryR5ow+COV6gNUqNURFAwJKb8FwlNPx+eyA181K AY9A== X-Forwarded-Encrypted: i=1; AJvYcCXAzeBn+dNOyXh23S5IeXT1YC1gdFDXL+cfD+5EaAjbc3CuIpy9XfL4O4Npc5HnUGb52Y04dGoGEivT6RY=@vger.kernel.org X-Gm-Message-State: AOJu0YzntWqNInfsrOo3j/b9zXVB9gMh3IhxRqlgvrO/qKPqcB1djAV8 wyj4hSp6wT0vPUMUjwclttBGgZz5laJl+0FSbPT63CufI2+RZ+051AKpWQGkE+bNO0dtM6EZYL0 pc7Nr X-Gm-Gg: ASbGnct4RcZfXbJoPltMA/9CyCelUvTWtKQulQfNvNtnluubwmLIyo2VkBrmAAe2S4d jxO5JNzvWj14/9O1WGzrCl14QrvazULkacHtoxPzESFQc1/1reNNfvr1c8lL97rTqpsw66Lq0En y4psny1AHmcRzw1HFbCUPDceV319L/dbaT9ARIV41tE4tU72H2aaNTUe77W2vu2BeegLidByrjH go6HvWSQNJFEsg3YXTGCOOaWrIBuWwd1cnAgDsDCAuC9NWrw9vsoRj2j1YXvqF6S7o+SEG4SmHo PrwTSStx/78i1nKN6gdIAW3jE/s/LOjDJ5+T4ZwAOw0I9TMECOYz6hYUwcE68Z/azDVVMbs/ly9 xDpaVh7Nqu8t4XoBBKWhkOidxbHKy X-Google-Smtp-Source: AGHT+IHlGmNyIPUVE50HY9dGh77AHvPnG3SeflnB+KHOWyXaq14AyQRptbYJJmrjvo4NTSd31zmq+w== X-Received: by 2002:a05:6830:7312:b0:744:f0db:a1a8 with SMTP id 46e09a7af769-74500ace8a5mr5718564a34.36.1756162542459; Mon, 25 Aug 2025 15:55:42 -0700 (PDT) Received: from [127.0.1.1] ([2600:8803:e7e4:1d00:5075:40f3:ff25:c24c]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7450e49d36esm1991747a34.40.2025.08.25.15.55.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Aug 2025 15:55:42 -0700 (PDT) From: David Lechner Date: Mon, 25 Aug 2025 17:55:01 -0500 Subject: [PATCH v2 2/4] iio: adc: ad7124: do not require mclk Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250825-iio-adc-ad7124-proper-clock-support-v2-2-4dcff9db6b35@baylibre.com> References: <20250825-iio-adc-ad7124-proper-clock-support-v2-0-4dcff9db6b35@baylibre.com> In-Reply-To: <20250825-iio-adc-ad7124-proper-clock-support-v2-0-4dcff9db6b35@baylibre.com> To: Michael Hennerich , Jonathan Cameron , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4211; i=dlechner@baylibre.com; h=from:subject:message-id; bh=iRPbZ3NmESqwUlU+AgCDLlpOo6ZQJuC2kenB043PMZY=; b=owEBbQGS/pANAwAKAcLMIAH/AY/AAcsmYgBorOnWbuf6NViok3VnnttZmjsRZUbduojje2wxs flPgVuyMuGJATMEAAEKAB0WIQTsGNmeYg6D1pzYaJjCzCAB/wGPwAUCaKzp1gAKCRDCzCAB/wGP wOytCACbhbEDQwMJStOx+iK43ZJ906hiYrpgABhn6pbD4Tpd6YwtWPbrXTnxuc7EGl/fKVEkBxw 7+Fp6vLKLABFCl3p+Btdam3SWsq9ivsNaIQHB7Si1dgs8LDX09EM28KhrVnVXn6X4r7cRxbxW5i vapcerWI8P4CSa5SaSwWUKUSl1hZnHVDXrP8iXJHEo1aXVEILMDyxVMMFCqpT6/RudDEDjdetad 7b8GwYhRN+5+nSKuBx5imQSORCkMxRPO741I44JoAyiWM1d0jTcLaoDTZNP/IfISwAjY6lTWZUu 1BASM3xneUCYji//pD2S26B3wACRr92oGp6Dpj4vaGwp1lii X-Developer-Key: i=dlechner@baylibre.com; a=openpgp; fpr=8A73D82A6A1F509907F373881F8AF88C82F77C03 Make the "mclk" clock optional in the ad7124 driver. The MCLK is an internal counter on the ADC, so it is not something that should be coming from the devicetree. However, existing users may be using this to essentially select the power mode of the ADC from the devicetree. In order to not break those users, we have to keep the existing "mclk" handling, but now it is optional. Now, when the "mclk" clock is omitted from the devicetree, the driver will default to the full power mode. Support for an external clock and dynamic power mode switching can be added later if needed. Signed-off-by: David Lechner --- drivers/iio/adc/ad7124.c | 62 ++++++++++++++++++++++++++++++++++----------= ---- 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index 3fc24f5fffc8f200c8656cb97f9e7f80546f688b..49003c8436463f49a47564644fd= 8e405579df829 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -174,7 +174,6 @@ struct ad7124_state { struct ad_sigma_delta sd; struct ad7124_channel *channels; struct regulator *vref[4]; - struct clk *mclk; unsigned int adc_control; unsigned int num_channels; struct mutex cfgs_lock; /* lock for configs access */ @@ -254,7 +253,9 @@ static void ad7124_set_channel_odr(struct ad7124_state = *st, unsigned int channel { unsigned int fclk, odr_sel_bits; =20 - fclk =3D clk_get_rate(st->mclk); + fclk =3D ad7124_master_clk_freq_hz[FIELD_GET(AD7124_ADC_CONTROL_POWER_MOD= E, + st->adc_control)]; + /* * FS[10:0] =3D fCLK / (fADC x 32) where: * fADC is the output data rate @@ -1111,21 +1112,50 @@ static int ad7124_parse_channel_config(struct iio_d= ev *indio_dev, static int ad7124_setup(struct ad7124_state *st) { struct device *dev =3D &st->sd.spi->dev; - unsigned int fclk, power_mode; + unsigned int power_mode; + struct clk *mclk; int i, ret; =20 - fclk =3D clk_get_rate(st->mclk); - if (!fclk) - return dev_err_probe(dev, -EINVAL, "Failed to get mclk rate\n"); + /* + * Always use full power mode for max performance. If needed, the driver + * could be adapted to use a dynamic power mode based on the requested + * output data rate. + */ + power_mode =3D AD7124_ADC_CONTROL_POWER_MODE_FULL; =20 - /* The power mode changes the master clock frequency */ - power_mode =3D ad7124_find_closest_match(ad7124_master_clk_freq_hz, - ARRAY_SIZE(ad7124_master_clk_freq_hz), - fclk); - if (fclk !=3D ad7124_master_clk_freq_hz[power_mode]) { - ret =3D clk_set_rate(st->mclk, fclk); - if (ret) - return dev_err_probe(dev, ret, "Failed to set mclk rate\n"); + /* + * This "mclk" business is needed for backwards compatibility with old + * devicetrees that specified a fake clock named "mclk" to select the + * power mode. + */ + mclk =3D devm_clk_get_optional_enabled(dev, "mclk"); + if (IS_ERR(mclk)) + return dev_err_probe(dev, PTR_ERR(mclk), "Failed to get mclk\n"); + + if (mclk) { + unsigned long mclk_hz; + + mclk_hz =3D clk_get_rate(mclk); + if (!mclk_hz) + return dev_err_probe(dev, -EINVAL, + "Failed to get mclk rate\n"); + + /* + * This logic is a bit backwards, which is why it is only here + * for backwards compatibility. The driver should be able to set + * the power mode as it sees fit and the f_clk/mclk rate should + * be dynamic accordingly. But here, we are selecting a fixed + * power mode based on the given "mclk" rate. + */ + power_mode =3D ad7124_find_closest_match(ad7124_master_clk_freq_hz, + ARRAY_SIZE(ad7124_master_clk_freq_hz), mclk_hz); + + if (mclk_hz !=3D ad7124_master_clk_freq_hz[power_mode]) { + ret =3D clk_set_rate(mclk, mclk_hz); + if (ret) + return dev_err_probe(dev, ret, + "Failed to set mclk rate\n"); + } } =20 /* Set the power mode */ @@ -1303,10 +1333,6 @@ static int ad7124_probe(struct spi_device *spi) return ret; } =20 - st->mclk =3D devm_clk_get_enabled(&spi->dev, "mclk"); - if (IS_ERR(st->mclk)) - return dev_err_probe(dev, PTR_ERR(st->mclk), "Failed to get mclk\n"); - ret =3D ad7124_soft_reset(st); if (ret < 0) return ret; --=20 2.43.0 From nobody Fri Oct 3 20:25:50 2025 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (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 4E34D2C1584 for ; Mon, 25 Aug 2025 22:55:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756162546; cv=none; b=Az6+vN2Bu1JO/sPc7v4bIu/IYHYwvVY2v9lPkSit5A63CDHahS2PSA46EcfXH+jRgOUMTrzHs2O3vdSwgLw8kQ5h4/qytOrWdnai+GY1LD4mHKo8oxmG/hEitXsISpXr5CC8CppfxdkE/aCjuLafq7DPv8pWQPA5jdieJ7SuZSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756162546; c=relaxed/simple; bh=xFruIh1dJkHwC4/899ebphgTT8LU3IBSfD9CxxH6rBU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cPq6gztLMnWeW101C5ia3XTN1h2mxHTjJZcynfzewwAaomKoNfnJfYZMIAdpfz7avPZ7MH3p9HvH8tS9Ievyezacnyog1zEQ03GBjcXpTGvSUH54ws+H2flMvQY1DMajAe5bvm97dNiJEkXwE90eicBrSIgs2ohIPBXh2HPUYgw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=n1WyOluA; arc=none smtp.client-ip=209.85.210.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="n1WyOluA" Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-744fa68531dso1349012a34.1 for ; Mon, 25 Aug 2025 15:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1756162543; x=1756767343; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=3cSpwhr4OHdGE4D7f/XRjFwNJZRCfq1FRXvwP6Ffuu8=; b=n1WyOluApMuUl5jFE3BftQuH7pdkcH5qrm7CxTzACv9zDaQcsgnRet2wdy44KvS5Qp OE70lBQZtLltpUoJw41vRYkcpFjZHE6IobWpiS/YhBFAO9z/5pKtpEadJqv+46nKp808 3xsIcznk1dGdLXX4IxPvzeLXRwKEuBq45zR0eDKEy73lgAiRnF45L2GcMDBY27GyNDIQ oQnqwddQ2la8U8skkcOZm+HNp82NdF4aGkh9GK091W6lQkjaJWeYPpqy1HWzPIjDbA18 eftnsehQSFGXGCgw/4RTZallAsh30/fZ7eMDlKB1/trJDbeo51IGVLzXnTZUEnQPqiHr kP9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756162543; x=1756767343; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3cSpwhr4OHdGE4D7f/XRjFwNJZRCfq1FRXvwP6Ffuu8=; b=h0kGDTfN0xzb+rBJCc+TecpYHx0wured2fiZdRIDQSCEmM+8S2Z+WosWx/WlfKWVBd mF/W0zv/CU69FNua7gjBV+m2r/zVG0hHQeOmtTaJBsTfVwfvacmA1saQ0xHETMwXb7Ro aHiExSzL/CwfSS87mhCQZwHXHudXM/MeTN8H7ERJhcdankJvy+KjxoQ+6L2wPJwWe3o+ rVYzYi+0yjgyh+SIAI/CKx1HraDBUHjpy7le5WgUogiEtO589Yw93YaDLqRC5mkjptrL 89jOqIZecFxcrKDdzLD7THGHlBR/LPvnqrvET9IOOYeVtnIswA/r3za8H8xj/xw0D9at UlQQ== X-Forwarded-Encrypted: i=1; AJvYcCU65eW9jECdpn2YlQbMdVnv8wHNY2hOLQMsZafDcE0KJjspvQxQMXw3cY7DjJjTQnfEN0zQsU8Z+PAsKxY=@vger.kernel.org X-Gm-Message-State: AOJu0YzZHuq5WgV50Ba9Q4Cu6H+uFhR+aUKujmdBYyEYqR1Bev4updlc vEY2n+/27ilMbhCwjKvll/Sj3v48qC3IDmMvngKXSS1GyBWCi7/cOUGTQPguhisABIUb1DLWr/i xG2cs X-Gm-Gg: ASbGncvZjQMjX5lDbS/rIhmykhiFjp3oNDo29jQ0VXks0Eov3s43wQoiDKgbTp0hSQI hjdluieHj5bjCtguWO48peV3fVfHzoVFduL3WTQwAt5pClKBIZfWky3+BC8CIONfemED3KKN2WM YaJ0c1mIKjysOLuKJ+82wYabYxFIjbjcel6+a7eJfLDU60bfUa0+HNnU5/0Nv14O0d5IPdL5veG 3Nl4zQRUrZNaPZUUikr/D6OtfDi2RwGPrB3L8a5baT0TjTr6CaMCJQ2/AFBlk9NZ1D3JUIgyRe6 43F8N9gSTyLqTyJONQtcw1TkxcIQ9+zib19Rhrol0scJvjUSJfiYW11ZmGCNMZJ56CAP72EEUBI O5O4NGBGaQxr19288dghcJ2eiZKS1 X-Google-Smtp-Source: AGHT+IFa2v3+6INnkH7Pb5/iizOJp22ndKBOs+CMIlrim3qXEPy+qesWesPnrUp++GZY9Sn9kwfd7A== X-Received: by 2002:a05:6830:3709:b0:743:bc1:e85e with SMTP id 46e09a7af769-74500909d36mr8870111a34.4.1756162543309; Mon, 25 Aug 2025 15:55:43 -0700 (PDT) Received: from [127.0.1.1] ([2600:8803:e7e4:1d00:5075:40f3:ff25:c24c]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7450e49d36esm1991747a34.40.2025.08.25.15.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Aug 2025 15:55:42 -0700 (PDT) From: David Lechner Date: Mon, 25 Aug 2025 17:55:02 -0500 Subject: [PATCH v2 3/4] iio: adc: ad7124: add external clock support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250825-iio-adc-ad7124-proper-clock-support-v2-3-4dcff9db6b35@baylibre.com> References: <20250825-iio-adc-ad7124-proper-clock-support-v2-0-4dcff9db6b35@baylibre.com> In-Reply-To: <20250825-iio-adc-ad7124-proper-clock-support-v2-0-4dcff9db6b35@baylibre.com> To: Michael Hennerich , Jonathan Cameron , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3361; i=dlechner@baylibre.com; h=from:subject:message-id; bh=xFruIh1dJkHwC4/899ebphgTT8LU3IBSfD9CxxH6rBU=; b=owEBbQGS/pANAwAKAcLMIAH/AY/AAcsmYgBorOnd4kGuMzUs+5R/ZjrILO91LzOXg1ah8NaTn rXbP1qwduOJATMEAAEKAB0WIQTsGNmeYg6D1pzYaJjCzCAB/wGPwAUCaKzp3QAKCRDCzCAB/wGP wBG/B/kBCLUzo5Ug4ObjK+ki9kZv+caTdb2FSLirv+ysmkoM4afa9xyubai6R2+I+n4hcJL1LCk IwHZkITi0GnQgL1SGTITs5U7uh86pTEOEwxuujoHDRhRQuSZY/DnlIBZ1AuyLNO/6ZpRZtjRaFx RVi35UiU7rvKwYtQy3BteTLxAVtHD4m1dmrtXQ892/S1RJ23ajFeMiINkwLjOKJLDU58ezbjaYZ bq6k/DqvD9+ig/6gBS4JBpGR+XX9+QYyCH12oLc9qLtOKjBx9sZK8iCvJo4o/gHNxLkGsNjX88Y qS2R2zcf00OYP+T0UigsXoIe+GWqV9iiV1PzQGZ4R2Duhoq9 X-Developer-Key: i=dlechner@baylibre.com; a=openpgp; fpr=8A73D82A6A1F509907F373881F8AF88C82F77C03 Add support for an external clock source to the AD7124 ADC driver. Previously, the driver only supported using the internal clock and had bad devicetree bindings that used a fake clock to essentially select the power mode. This is preserved for backwards compatibility. If the clock is not named "mclk", then we know that the devicetree is using the correct bindings and we can configure the chip to use an external clock source rather than internal. Also drop a redundant comment when configuring the register fields instead of adding more. Signed-off-by: David Lechner --- drivers/iio/adc/ad7124.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index 49003c8436463f49a47564644fd8e405579df829..4112c484c2371cfa6f26acb0d7c= 5b2a308a5fb35 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -18,6 +18,7 @@ #include #include #include +#include =20 #include #include @@ -44,6 +45,11 @@ #define AD7124_STATUS_POR_FLAG BIT(4) =20 /* AD7124_ADC_CONTROL */ +#define AD7124_ADC_CONTROL_CLK_SEL GENMASK(1, 0) +#define AD7124_ADC_CONTROL_CLK_SEL_INT 0 +#define AD7124_ADC_CONTROL_CLK_SEL_INT_OUT 1 +#define AD7124_ADC_CONTROL_CLK_SEL_EXT 2 +#define AD7124_ADC_CONTROL_CLK_SEL_EXT_DIV4 3 #define AD7124_ADC_CONTROL_MODE GENMASK(5, 2) #define AD7124_ADC_CONTROL_MODE_CONTINUOUS 0 #define AD7124_ADC_CONTROL_MODE_SINGLE 1 @@ -1112,7 +1118,7 @@ static int ad7124_parse_channel_config(struct iio_dev= *indio_dev, static int ad7124_setup(struct ad7124_state *st) { struct device *dev =3D &st->sd.spi->dev; - unsigned int power_mode; + unsigned int power_mode, clk_sel; struct clk *mclk; int i, ret; =20 @@ -1156,9 +1162,43 @@ static int ad7124_setup(struct ad7124_state *st) return dev_err_probe(dev, ret, "Failed to set mclk rate\n"); } + + clk_sel =3D AD7124_ADC_CONTROL_CLK_SEL_INT; + } else { + struct clk *clk; + + clk =3D devm_clk_get_optional_enabled(dev, NULL); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), + "Failed to get external clock\n"); + + if (clk) { + unsigned long clk_hz; + + clk_hz =3D clk_get_rate(clk); + if (!clk_hz) + return dev_err_probe(dev, -EINVAL, + "Failed to get external clock rate\n"); + + /* + * The external clock may be 4x the nominal clock rate, + * in which case the ADC needs to be configured to + * divide it by 4. Using MEGA is a bit arbitrary, but + * the expected clock rates are either 614.4 kHz or + * 2.4576 MHz, so this should work. + */ + if (clk_hz > MEGA) + clk_sel =3D AD7124_ADC_CONTROL_CLK_SEL_EXT_DIV4; + else + clk_sel =3D AD7124_ADC_CONTROL_CLK_SEL_EXT; + } else { + clk_sel =3D AD7124_ADC_CONTROL_CLK_SEL_INT; + } } =20 - /* Set the power mode */ + st->adc_control &=3D ~AD7124_ADC_CONTROL_CLK_SEL; + st->adc_control |=3D FIELD_PREP(AD7124_ADC_CONTROL_CLK_SEL, clk_sel); + st->adc_control &=3D ~AD7124_ADC_CONTROL_POWER_MODE; st->adc_control |=3D FIELD_PREP(AD7124_ADC_CONTROL_POWER_MODE, power_mode= ); =20 --=20 2.43.0 From nobody Fri Oct 3 20:25:50 2025 Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (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 252012C15AF for ; Mon, 25 Aug 2025 22:55:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756162546; cv=none; b=GcJg9BjYIUDC3SPUYbH6DOqLe5XI6ttKMPfaNk4db7u5fXXDwIDJzKwXGBiMkRVmBzQq3lvWtTBwcg4ZkC1fsS3HX2znaTa59q9yp84ftjGS2AbSH68F8QTJ7qXp3sSKy+8lOArOkvzG7F5t71F721CUFP2AdSfeLxg6lv/kXwo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756162546; c=relaxed/simple; bh=tjk3gE0WrgpzRG+qNpzFNmWAh/0bn0ThRzR4E4Bla4Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kWoMDXl/dsmfc1IXJGUXh/Zf3vFxt+b1vKKOLWHfMG4ucNoB+FTQBRjErpYx8NN6op/VdHTgUfG3njoxrEshtzaXL4CYAYLvuRA24VksI4R6YWZSGkkrdxpZS3QrH/DwT5MlnA9E+Jz/f9MtRwFfioip7Nsjs1eeQE73fq1JW2A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=eFFVFINB; arc=none smtp.client-ip=209.85.210.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="eFFVFINB" Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-74382041c9eso2764162a34.3 for ; Mon, 25 Aug 2025 15:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1756162544; x=1756767344; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=tUg+X3OovrLl3jRGXt22VZgAMJQUCaveNyIMtY/SHNs=; b=eFFVFINB0OWJam8eW2scaoJSVXpLiOYU1XmDLjPaVZrFBR7sYqbzgm6FnfmSe9h273 AFMi6lmy167YsAHJ93i4+ND+Erhqjj0qlU1nAoDvWOkf+lN0GvQZ8bxCucTkWyE+Iozc EgxZof8Vo5sEv0aBJfNlMGwl9myodi310mK9qjQYTLMvWmkenLzAqmhpK/BLDVzEaHju 7pjPp7ZONuZahG9IKIFoMrcIeYOLmngkSDZwkLA+q39SLPaLKmWuacZcalttJOGgGU5C H9jU4zVRRSOM/eJjcMQTGG5cXhzf7XjEGagWs+x8J7b6vUr2mXqWG4Vi4xLZEJokXzaF uymA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756162544; x=1756767344; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tUg+X3OovrLl3jRGXt22VZgAMJQUCaveNyIMtY/SHNs=; b=AIEmC/qi9+AZRaHjDhLGwTDKL3jymddJ2f9FBpBq2NiNGI1Y4WPC+jnI8RNX8fqQda foj7IcigBp+u4mDXqfmWHIopt9i5TwOhnzuAAmYnsA7nFZtlc6r/PdFhKs/2tQhsCoTQ WBuXLswQmcY/H8BNqLDt4Ss/w4GrpSrU2u5c4PXjYrri+H2Z3Q5V61uVJ5ID7ALNtK48 W4Nq/w+aKaQk2JaAF35ZfjEPrxSYw9OyYPOUql+O4XYdRjn1F2S69bN2zmm/fbDxIPst vo24db9mBhsUuOkPubUz0jEEUweZiT9XjY8nLbBGP3pvkgROy1hBM2eBOlX6iHO3m+J9 Y33g== X-Forwarded-Encrypted: i=1; AJvYcCWqvDlc4K+p/b7CNsux6FQlH8CNZdE0jwPhSfZ9/TnBhXjh/Rl8lYPmhHq7NZGkRrH0oik+zS53P7cHZQ4=@vger.kernel.org X-Gm-Message-State: AOJu0YzO24tIAgVc1NSiVqFUE9AX4AQ37EDPUKpsAmC+I2B6CCaynYu2 tqo4l4ptZokg2F0fuW65jR8An4XimMkdrJWpQEcQpUoYsWJGwTYRcL4MX4Rd42MsgZMWJa5X/Rf QRD1X X-Gm-Gg: ASbGncs7yIIpxznvSCZG6uJc9hWA1g3XvuSpaZW9OKg9nyPR/x5ke8dyjoR93HJf8aA wtxAeQ9Rc+wnvO85Y8L5phfMsu5pNbDF8YSygaH87SLl3279DIR9Fse5fTB6Tq8zp9KrZSAMyGw gClbS5zNI9dCx7yMIUVW+BzOmzNZuqp1WCCwkT1XMtQka6r3I+YMykmrkTGPOOm2t7jx181e5fe QTQEUDmnF5XEmgWpL2maikD75H/JAdPL9vdezDyv0Hn3tv3DVV/3Ui3LEj3lFhqrD9Buhv5FzpA w4J7hJjObdDJ+HPhsxdlXV0EnAkw2bTaNLmoEoeswhvg25KdsyweI2y0jyK1hyHU+sW9iJyFj8X AxW5CnQ6GiebuoEzqTbDVdZ50dAw7 X-Google-Smtp-Source: AGHT+IFCV21ITWeFB/BXbML1vk/uK4JJ4ZrnOgbjhNvnAGJwuaXDQhCv0Qf5XpMdn8BAGIcG78CRpA== X-Received: by 2002:a05:6830:2589:b0:744:f0db:a19b with SMTP id 46e09a7af769-74500a7d191mr7861655a34.31.1756162544133; Mon, 25 Aug 2025 15:55:44 -0700 (PDT) Received: from [127.0.1.1] ([2600:8803:e7e4:1d00:5075:40f3:ff25:c24c]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7450e49d36esm1991747a34.40.2025.08.25.15.55.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Aug 2025 15:55:43 -0700 (PDT) From: David Lechner Date: Mon, 25 Aug 2025 17:55:03 -0500 Subject: [PATCH v2 4/4] iio: adc: ad7124: add clock output support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250825-iio-adc-ad7124-proper-clock-support-v2-4-4dcff9db6b35@baylibre.com> References: <20250825-iio-adc-ad7124-proper-clock-support-v2-0-4dcff9db6b35@baylibre.com> In-Reply-To: <20250825-iio-adc-ad7124-proper-clock-support-v2-0-4dcff9db6b35@baylibre.com> To: Michael Hennerich , Jonathan Cameron , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3180; i=dlechner@baylibre.com; h=from:subject:message-id; bh=tjk3gE0WrgpzRG+qNpzFNmWAh/0bn0ThRzR4E4Bla4Y=; b=owEBbQGS/pANAwAKAcLMIAH/AY/AAcsmYgBorOnjBfnNftKxcXPip3vtWX6R8Nzqt2xFFn5Pv Nd3Gtwnnv2JATMEAAEKAB0WIQTsGNmeYg6D1pzYaJjCzCAB/wGPwAUCaKzp4wAKCRDCzCAB/wGP wM9hB/9bQSHHNCRs1R1WBE+5kN22Qdp9kRZ1pAPQHgEqDvV7LPi5fvY/upvaQGZ4hKjO5orPq+V SHqoWM4glZS+lBd0Gy1TawX4/SXikGEtyRLRT5nGMeTkupcTtm9jBUT8IKHNUX+h587B/fAF6Au qzuTEjV9yz+vhGYkTmwpa10oTNTdpZ+J0MEWolPiaFA0kYE5HoK0rx27t08//E+tDLyXt6OOdBP bGOcXEyuM4hozDE+CvFLIVNAfa7RrusuI1a3lW1lN+SDCV3e4AdutyInmAifAIH2G4VXYN1E4Ji /XlU5D7fseDr/AORNUa5dUS1Pgvar/H3eZ2poDxq5G/28kLy X-Developer-Key: i=dlechner@baylibre.com; a=openpgp; fpr=8A73D82A6A1F509907F373881F8AF88C82F77C03 Add support for the AD7124's internal clock output. If the #clock-cells property is present, turn on the internal clock output during probe. If both the clocks and #clock-names properties are present (not allowed by devicetree bindings), assume that an external clock is being used so that we don't accidentally have two outputs fighting each other. Signed-off-by: David Lechner --- We could make this fancier and only turn on the output on demand of a clock consumer, but then we have to deal with locking of the SPI bus to be able to write to the register. So I opted for the simpler solution of always turning it on during probe. This would only be used for synchronizing with other similar ADCs, so implementing the functions for a more general-purpose clock seems a bit overkill. --- drivers/iio/adc/ad7124.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index 4112c484c2371cfa6f26acb0d7c5b2a308a5fb35..a1c5f059b284c4f8797986628b9= 2b70fd84e90f4 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include #include +#include #include =20 #include @@ -125,10 +127,12 @@ static const unsigned int ad7124_reg_size[] =3D { 3, 3, 3, 3, 3 }; =20 +#define AD7124_INT_CLK_HZ 614400 + static const int ad7124_master_clk_freq_hz[3] =3D { - [AD7124_LOW_POWER] =3D 76800, - [AD7124_MID_POWER] =3D 153600, - [AD7124_FULL_POWER] =3D 614400, + [AD7124_LOW_POWER] =3D AD7124_INT_CLK_HZ / 8, + [AD7124_MID_POWER] =3D AD7124_INT_CLK_HZ / 4, + [AD7124_FULL_POWER] =3D AD7124_INT_CLK_HZ, }; =20 static const char * const ad7124_ref_names[] =3D { @@ -1164,6 +1168,33 @@ static int ad7124_setup(struct ad7124_state *st) } =20 clk_sel =3D AD7124_ADC_CONTROL_CLK_SEL_INT; + } else if (!device_property_present(dev, "clocks") && + device_property_present(dev, "clock-names")) { + struct clk_hw *clk_hw; + + const char *name __free(kfree) =3D kasprintf(GFP_KERNEL, "%s-clk", + fwnode_get_name(dev_fwnode(dev))); + if (!name) + return -ENOMEM; + + clk_hw =3D devm_clk_hw_register_fixed_rate(dev, name, NULL, 0, + AD7124_INT_CLK_HZ); + if (IS_ERR(clk_hw)) + return dev_err_probe(dev, PTR_ERR(clk_hw), + "Failed to register clock provider\n"); + + ret =3D devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, + clk_hw); + if (ret) + return dev_err_probe(dev, ret, + "Failed to add clock provider\n"); + + /* + * Treat the clock as always on. This way we don't have to deal + * with someone trying to enable/disable the clock while we are + * reading samples. + */ + clk_sel =3D AD7124_ADC_CONTROL_CLK_SEL_INT_OUT; } else { struct clk *clk; =20 --=20 2.43.0