From nobody Fri Nov 29 12:47:58 2024 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 00F3619924A for ; Thu, 19 Sep 2024 09:21:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737699; cv=none; b=tXldUQKeeGV33fq8wEon7cEyYvCgsUuGNFKVu+schnTTDAe2BSCX2tmxuM9pgALS1g//n6COxpu0c9LogBxuNK82HqGRabiuVPWQmxwg30sXUqH7OtPGQ/VfgZujhbo8azcNLJUscB5x7txdYUwpgIzQBzdHYkQ1dwshlAir1Tk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737699; c=relaxed/simple; bh=Ou8OfT+69WBiLVaYkprtWanFi5XHSO9mF882Eoasusg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eOmPHFw8Aco6tI3JmJjDbYJPOx22nYRSOEtf3V2fLjjftPwIqpAs8BezeJbwFcucpHpjNe/0Cm4h5zNWQ483FgWyK2D9D5UPa/HQ8vxvv2oG6nedLE8h14mifW3pMA+vqiyDFuP21Myk3MelB02o67/Ls/aPUL3SXdg2yDF3dcs= 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=d+PSUCJZ; arc=none smtp.client-ip=209.85.128.45 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="d+PSUCJZ" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-42cae102702so4787515e9.0 for ; Thu, 19 Sep 2024 02:21:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726737695; x=1727342495; 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=Bm+PhgVISoshe6+u0cv75nF5vnnSUSz3FJSs7aa+aiE=; b=d+PSUCJZmYdEiWLJZUNUc81ViaYPdsnZBvvzWuLxB/8qJoBWNoW3xz5GT4ZJ/rzFHM arpzuFQ3sUwXzIQeLaBvJlBuHD+xQK8wgB90nrjVJwNo3GUnCiJ/gW3FyNpCPdLZlaV3 ojUJ7EQXF7A9gK6qZLp+2ZvQs1TGitn6h5MaH36B43Tleu2JARY+jcx8TA7TVOIUEDSg ncs05gMPftiD3Pr6m/N8M+q72BRnYaRlmevyqQQmjmFw1h6XlL1DtoIHiIHR7p84gQrJ Q4qIeJpygube7gDVuWowf00VjauGlTxsDsgyhoKMOjCpbF8Es1z74YIg6CQWiSmF7nRl mYLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726737695; x=1727342495; 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=Bm+PhgVISoshe6+u0cv75nF5vnnSUSz3FJSs7aa+aiE=; b=NwGVMcqaSvUIEF0FXzNLcNYcSFIly4DYBbdVkjGd/D2c3pwpl+JZ+qYRzBoF/AMGRL 0T1cxd0zp+huTARWy/tMSrquakEzbo97gz/C+wq46MhNXGaOJUoYhaJjyl+cX6NqSeeb 76GJocr6iTg+x4UCJi7reg3MJ4fDyXAPQ55gLVQbikXdNP3MRQoxc19vLbz8NEYysLux gYXN/6vlpZxKruvo30quqcel7wOJ849zfZuoCuieYAlDxLhLzOUP1StLyvehLXcxLyVQ WWfibChuKaxYgTwy/Lww01fSUNdwnfNktKGsAz0T4ZgB/Zuu0G9i1Oss5lIPPVBcRJ3w XO+A== X-Forwarded-Encrypted: i=1; AJvYcCVT+ac9hMtcDut5fkjjqkn99yatfqgvZlKLebbO+zMbGxXqeEj48En8paWGwYIkXfQm0pcRbTykD7uq+7E=@vger.kernel.org X-Gm-Message-State: AOJu0Yy92ZpuGmFvpaWdfBBTpBWNoQ4y/7sT0Zkg1/U1Yvgp0En1PHbz wFXXvVim9aVG9O6RmNqWpYMUWcwjncYMosSI5Cl0MVxuzy/3PjZk92tEAfeoPUc= X-Google-Smtp-Source: AGHT+IFZL+BpyLS0ETVBklimnTddQLSVyt3UeGyl8jNbw4TKvjYFJ4jVSTQlrNtqaiCtdzx8j5Sv0g== X-Received: by 2002:a05:600c:1c04:b0:426:6308:e2f0 with SMTP id 5b1f17b1804b1-42d964d8558mr144476935e9.26.1726737695103; Thu, 19 Sep 2024 02:21:35 -0700 (PDT) Received: from [127.0.1.1] (host-80-117-99-70.retail.telecomitalia.it. [80.117.99.70]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e75468413sm16889465e9.45.2024.09.19.02.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 02:21:34 -0700 (PDT) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Thu, 19 Sep 2024 11:19:57 +0200 Subject: [PATCH v3 01/10] iio: backend: adi-axi-dac: fix wrong register bitfield 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: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-1-a17b9b3d05d9@baylibre.com> References: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> In-Reply-To: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Nuno Sa , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Olivier Moysan Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dlechner@baylibre.com, Angelo Dureghello X-Mailer: b4 0.14.1 From: Angelo Dureghello Fix ADI_DAC_R1_MODE of AXI_DAC_REG_CNTRL_2. Both generic DAC and ad3552r DAC IPs docs are reporting bit 5 for it. https://wiki.analog.com/resources/fpga/docs/axi_dac_ip https://analogdevicesinc.github.io/hdl/library/axi_ad3552r/index.html Signed-off-by: Angelo Dureghello Reviewed-by: Nuno Sa --- drivers/iio/dac/adi-axi-dac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c index 0cb00f3bec04..b8b4171b8043 100644 --- a/drivers/iio/dac/adi-axi-dac.c +++ b/drivers/iio/dac/adi-axi-dac.c @@ -46,7 +46,7 @@ #define AXI_DAC_REG_CNTRL_1 0x0044 #define AXI_DAC_SYNC BIT(0) #define AXI_DAC_REG_CNTRL_2 0x0048 -#define ADI_DAC_R1_MODE BIT(4) +#define ADI_DAC_R1_MODE BIT(5) #define AXI_DAC_DRP_STATUS 0x0074 #define AXI_DAC_DRP_LOCKED BIT(17) /* DAC Channel controls */ --=20 2.45.0.rc1 From nobody Fri Nov 29 12:47:58 2024 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 D5F3C199921 for ; Thu, 19 Sep 2024 09:21:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737700; cv=none; b=nRf7zRPjO3FH+PF0CoFipIb2WQjpCuLmjc+zNzWD6GH+L3XcBneiPwAfB2CMOoWG6VBReCydBfcgUUlRSrw3w40ogf/p9Qfo2/a6UzTrObgr0keJbvK1wH8mm1GCmEHBZcBREJ6Vc0wTF9sFZsA25tIbo2vTDaeYDk1poaiXI+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737700; c=relaxed/simple; bh=rmWek2CE7WPljPSo+Uou9ada/0CF37ebR/ci1deBjQw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rsiCVeJ80ScA7eXfTpe2qtmZCH3v02Kxhx8p9cAe8So81TYKBfZ0SSrzP4/v2T+WJ7iP8j0X+7cSUWzrEV5MPcv8sGjqyNhNSM9wFSzolIRpwXlcYbTPZ8nKpkK9n0uoX4G7Gluh6QTDKURPn2F3xjI4vtciypxMASj5CSZqEdE= 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=DtjLHv9O; arc=none smtp.client-ip=209.85.208.174 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="DtjLHv9O" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2f752d9ab62so5714991fa.3 for ; Thu, 19 Sep 2024 02:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726737697; x=1727342497; 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=bi6dudpwiT1wruYc8KetPgHF34XRCEstNIC9Mcn08hE=; b=DtjLHv9Ok0R4aIHxyMuBkP8LraJYEh7yG/o52UX1tidVBege+0FrDV8wKmPw17Iwd5 oYobHesUlHNE8NGJZYDzR+slheh4nrwYxUnKV4fos8dTVVW+HiAwN+DAWEsJAbF7Ha2a V+TEEq01yIrac54AZWVi1+FcCt12+ut7zDp9sf/HEL9FYAFcEN/dNCvP14tOfmza7qIG wC5WQnI8pug1cEygt2xuBGeokXFBvBlPHDUgkIbKr/WPYmgarR2ZXYlOxHaN+bUWUYbo 2P4NAhkXyg0kBxATKopyCupSMRQrgNVB2B1rj/5/2gJqXqdkvqO6kyTHz51naQhpkozY g/cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726737697; x=1727342497; 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=bi6dudpwiT1wruYc8KetPgHF34XRCEstNIC9Mcn08hE=; b=GC+3aIQKLJMnl9WTTiWfEtHgMd2fhwcascVtF1BrVKL64QtAdNldXmsKTcqMampUyl enr+oftxMTJ/YkMhnWutMgLYObJLS+x3TZRk4GmCLGOCAFyQu42IeW3ConIyXnFgL82m Yo+zRxH3N69B0PTNlZw3w/CR1rnXFmNY0teYz6FW7iynLp1KrsWZe6tB7FMEaaNMGWeT Aw0k9zemuYm0pqTVDgK5JjAUN+8v5I/knrlHXRe5GNCIa6CS0+wH/vdw4lax6Gu6Nyn8 4NmNjhKXlVRYR1eBw5jkjySWL698v6D08tZl++jsq/ssmwx3A3SXO0xskhY9STe+Nsup 28VQ== X-Forwarded-Encrypted: i=1; AJvYcCV56E8C2g5Cwx+XAhX7Vta4odSaVZR+7Xa9NbggjIsoOkjXJre5J2oD8/tD0l2MxMDjrWzpLrCIfRz8qck=@vger.kernel.org X-Gm-Message-State: AOJu0YxvWDjUNWd1j/A4oK9qiW76iX1y+yrpViqJVQcT5cFaOrajAi4R 9qRxbGmC55P3WB9S6BA/AyAD8MlI5fvQIuGH8c29RDupcLvLgW0twom2TLWwTxM= X-Google-Smtp-Source: AGHT+IHyCwBaP2n+hEG21y4E73ikctDq544q5tnqdl4FFCfiMtCFgczBe46WG484l0Gqo1n7oWO3cQ== X-Received: by 2002:a2e:4e02:0:b0:2f7:669c:93c1 with SMTP id 38308e7fff4ca-2f7919042b3mr86992431fa.14.1726737696632; Thu, 19 Sep 2024 02:21:36 -0700 (PDT) Received: from [127.0.1.1] (host-80-117-99-70.retail.telecomitalia.it. [80.117.99.70]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e75468413sm16889465e9.45.2024.09.19.02.21.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 02:21:36 -0700 (PDT) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Thu, 19 Sep 2024 11:19:58 +0200 Subject: [PATCH v3 02/10] dt-bindings: iio: dac: axi-dac: add ad3552r axi variant 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: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-2-a17b9b3d05d9@baylibre.com> References: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> In-Reply-To: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Nuno Sa , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Olivier Moysan Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dlechner@baylibre.com, Angelo Dureghello X-Mailer: b4 0.14.1 From: Angelo Dureghello Add a new compatible and related bindigns for the fpga-based "ad3552r" AXI IP core, a variant of the generic AXI DAC IP. The AXI "ad3552r" IP is a very similar HDL (fpga) variant of the generic AXI "DAC" IP, intended to control ad3552r and similar chips, mainly to reach high speed transfer rates using an additional QSPI DDR interface. The ad3552r device is defined as a child of the AXI DAC, that in this case is acting as an SPI controller. Signed-off-by: Angelo Dureghello --- .../devicetree/bindings/iio/dac/adi,axi-dac.yaml | 40 ++++++++++++++++++= ++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/dac/adi,axi-dac.yaml b/D= ocumentation/devicetree/bindings/iio/dac/adi,axi-dac.yaml index a55e9bfc66d7..6cf0c2cb84e7 100644 --- a/Documentation/devicetree/bindings/iio/dac/adi,axi-dac.yaml +++ b/Documentation/devicetree/bindings/iio/dac/adi,axi-dac.yaml @@ -19,11 +19,13 @@ description: | memory via DMA into the DAC. =20 https://wiki.analog.com/resources/fpga/docs/axi_dac_ip + https://analogdevicesinc.github.io/hdl/library/axi_ad3552r/index.html =20 properties: compatible: enum: - adi,axi-dac-9.1.b + - adi,axi-ad3552r =20 reg: maxItems: 1 @@ -41,22 +43,54 @@ properties: '#io-backend-cells': const: 0 =20 + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + required: - compatible - dmas - reg - clocks =20 +patternProperties: + "^.*@([0-9])$": + type: object + additionalProperties: true + properties: + io-backends: + description: | + AXI backend reference + required: + - io-backends + additionalProperties: false =20 examples: - | dac@44a00000 { - compatible =3D "adi,axi-dac-9.1.b"; - reg =3D <0x44a00000 0x10000>; - dmas =3D <&tx_dma 0>; + compatible =3D "adi,axi-dac-9.1.b"; + reg =3D <0x44a00000 0x10000>; + dmas =3D <&tx_dma 0>; + dma-names =3D "tx"; + #io-backend-cells =3D <0>; + clocks =3D <&axi_clk>; + }; + + - | + axi_dac: spi@44a70000 { + compatible =3D "adi,axi-ad3552r"; + reg =3D <0x44a70000 0x1000>; + dmas =3D <&dac_tx_dma 0>; dma-names =3D "tx"; #io-backend-cells =3D <0>; clocks =3D <&axi_clk>; + + #address-cells =3D <1>; + #size-cells =3D <0>; + + /* DAC devices */ }; ... --=20 2.45.0.rc1 From nobody Fri Nov 29 12:47:58 2024 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 0FD7319995E for ; Thu, 19 Sep 2024 09:21:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737701; cv=none; b=mnUoprObSss0FkfD9FyJ9cL1qtoNdtkyTeCcMUn0YNLoDSojX2J0c731c7m2wu1gbezUAa+6RCLsxTlDms336uGXiQnUKyUux3wSzmCgD3wDpIoEBH0BVT7DjM9njD7sKfp4FAjiKnPelMiYsu9uDu1n0MQ5icxdYiJBY9qf6fE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737701; c=relaxed/simple; bh=i5PZepG1aoFBTCiFDPOYVCA2IFjIkELc4/8zmw5imSo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eLtX7NRY4ZvrVekWc/yhFU+oNElevLYA/P3LFTkCwaME7Rfkv3pqYrKOIjD2tLNLOV+b9JOYOOuIilTNRnaWbi1q2y/tkP6ZG09vMOqpdYRoJitRaWG+bohGkiICltULxgmMindV5gG4mx9fIZCeVJSiy0VU9tUFAqZ6GadkMEA= 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=GruvSxtG; arc=none smtp.client-ip=209.85.128.43 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="GruvSxtG" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-42e748f78d6so4783155e9.0 for ; Thu, 19 Sep 2024 02:21:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726737698; x=1727342498; 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=aMa/yQ2Im0//zhcPUCeMNBxbg9N98XT4Go0CFqsD1eY=; b=GruvSxtGn9TXNzz/DRl1ik8zufhfSeZzIUD1oo/6oGTLyz+0Amwpy6h19B8ylUbj/u UOj2km66k6zmq3DpW7vbx7gYYnble0ojqbn+2huTythr84vx44PmoxLps4Q/8na1umR3 lKXxd04oBz1tKUzKf9d2cyF/iPEWbghnkLdsHPxLEM+8Lzilvi66lYYH+p1E+ZFNEODu fz7g8EtlgAPUQ9m7NQ98aBbCDxsnIt3mdXsAWWXrrs0v0yXsHAJLt6AXvXfg/n3Szn1c etrEjxtVkOZVB9RfCcBhZBuhxcuFRKKBGCxBIkRDOg/EkmKSvYjWxwBN45p8yht9E3KB 0Q7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726737698; x=1727342498; 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=aMa/yQ2Im0//zhcPUCeMNBxbg9N98XT4Go0CFqsD1eY=; b=fbuU8WbW4yZvdgHlAsVpUmwgcsczQESTWSkxv4OQx/HdBYj4mn76uVWx7frGw62Nmx YT8HXMV+qGPWVGIp8E1gzlwMyBwb+zvBWS1hCgAEjO0ZiVpC/0Y7o7Yvbk51IwTT4ABJ 4XCkV61gjDgt/4xt9A3jPYzPXAH0LMThSrLG3fF76X48SULFAUl5jDC2UUkS9WTk+aFO a/qbftckIzbSeQSuEtKvQrUeEQK45S03d7F+lFopiX29Ot4tsgGTeohuavrMowZzA1jY JHRvEh6FcqFmlbz+6TCupWhVsDrIL2IRDXB6yhhN2m/qBR1Gft94eh+t5j7Ha8pyG9g2 9jQw== X-Forwarded-Encrypted: i=1; AJvYcCWHM2CzUeaxboih8og595VbnQj/89BF7WpT74JrXiNyBkc+klGueWXepanR1IWXdASKIADbgvzckP3UVsw=@vger.kernel.org X-Gm-Message-State: AOJu0YwnZPsBU5adAJzelOYOwpReJjRQhQkEqn9QP5hXsGsgufPGm3IT i+rziQmAXEuz6i9g64WRKmQYFZBcMniNi2NTo/LR/9hBtuqSl9AvktvBKXL2SzY= X-Google-Smtp-Source: AGHT+IFzaSnso6ocrF9emwd2RsWQlvTAmzurK9UZ8AOuiIHpVPVrYdehMMnowjm9qAv3d8lc18uSxQ== X-Received: by 2002:a05:600c:4e8a:b0:427:abed:3602 with SMTP id 5b1f17b1804b1-42cdb5675f3mr190980895e9.24.1726737698218; Thu, 19 Sep 2024 02:21:38 -0700 (PDT) Received: from [127.0.1.1] (host-80-117-99-70.retail.telecomitalia.it. [80.117.99.70]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e75468413sm16889465e9.45.2024.09.19.02.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 02:21:37 -0700 (PDT) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Thu, 19 Sep 2024 11:19:59 +0200 Subject: [PATCH v3 03/10] dt-bindings: iio: dac: ad3552r: fix maximum spi speed 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: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-3-a17b9b3d05d9@baylibre.com> References: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> In-Reply-To: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Nuno Sa , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Olivier Moysan Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dlechner@baylibre.com, Angelo Dureghello X-Mailer: b4 0.14.1 From: Angelo Dureghello Fix maximum SPI clock speed, as per datasheet (Rev. B, page 6). Signed-off-by: Angelo Dureghello --- Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml b/D= ocumentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml index fc8b97f82077..41fe00034742 100644 --- a/Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml +++ b/Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml @@ -30,7 +30,7 @@ properties: maxItems: 1 =20 spi-max-frequency: - maximum: 30000000 + maximum: 66000000 =20 reset-gpios: maxItems: 1 --=20 2.45.0.rc1 From nobody Fri Nov 29 12:47:58 2024 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 2E6DD19ABC6 for ; Thu, 19 Sep 2024 09:21:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737704; cv=none; b=dU8TseRenw21wGjbJq2vGoknSSuuEAIsqTztXfoLkWlpep3OzrSwivlmu0BRhe3QaAtVmjAj+5w1BiGXf9qR8+20JSAK2KSjCIoceoGHWudcDvRZpiyN5fOLEKrZSDV0OaYMViYJghhyDdn6cD4cyYtC8VqbAZ51s8aJ4kGGUZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737704; c=relaxed/simple; bh=jcHHpxuLtdpMqMa6vj9yuUj6cUdqApIRaj7aqS82BZk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JstEpSrL7oSXrdHndKMhCWshZwe6gcQIZegvQC3yiIS//rAOStJ724ZcAQL6UHvofaQZdiQpL1bSxcNhulj8lAKRdGYNccyXNA/ippCvQtLeYHw3a8O/XAoCEm6YS4PqpryPBJ3NAfUjXnHJqzBc8plSgzfhH9hcx/2N63M9D+k= 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=g92ThZbj; arc=none smtp.client-ip=209.85.128.42 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="g92ThZbj" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-42cbe624c59so5066855e9.3 for ; Thu, 19 Sep 2024 02:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726737700; x=1727342500; 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=as49kqRLaVJ2yNgnvKYi3cFO3j1mhGpPd7aIfEYa3yM=; b=g92ThZbjlKGnCY1JXRIeiJ73RFATexgcyYgmal0oWlScvd+JD5DLryT4dSOfz5DNMK sE1z6rxEfqFEKUJZef2m97qKBfnv7XHkcAlwmCwJFQhx7N02G9lTSNHhpdyIXswXy9n1 KslL0zkrFaxtvt1XOytDwv4tqlZm7UaEjQXWv8LY7vv+TT7L0EDuWRv1rD1Lzf0O5hf8 +4+DGW6iQBCgCIH6HRIBWaObqT8rWOEENI3PrUo17aoS4WAj3pmvgD3tPZyX1z/U5hjf s2FctNsHhYsWADKe2CXPLhZ+27KFH72bEbrUoQj8a2UlEDTv6Te31K0QF9WCXxfDnhnB S8UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726737700; x=1727342500; 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=as49kqRLaVJ2yNgnvKYi3cFO3j1mhGpPd7aIfEYa3yM=; b=U5dgHbCSz/xRhn7VJ13AACEhvfHucybJWS820XibcYQPgz4GeJUs7CpRp0E1pAt0te hfd2cLpTbU+0DQI8pgGvvDqWsFfq78nvJ1VHjy5URx+3DJ6w2qZnv9ZJAdq3iSzfQA2O 5Nd9g18dvPjojpZyCnA19nwdu1CYRB+YngNqVIEdFVTKrZZsQap9QWT7hxghy6xpubF8 dw0yItsH/kMIFFBcZ7AuCOZJRbgEwT2jEszliQ/L8Fhcr9ceL6j7ut+GCd1jeQpghiZ/ COAxL6f8hdZAYppmo4IFAnn1o6YL3bHzC+nguwaAXxNjEDzCTdMNr76paMWP+T7LXnDC lpew== X-Forwarded-Encrypted: i=1; AJvYcCUAbldsvRF8XbpSd+EQVKuWh7577Am0IekSvkHuZLjxgXsLbaADqpe0AYDFFKz2i4JrhgDE7Aqn0V9S+x4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx06/UYLBe/E/HOkMPXRXACsXw2lAQGNhRHIy4JEEvkIh4aWbcX P9iv0z6ajm9+kmbWDzcye1MwOXclJv0K5EsvoCvNheg+WRwyP2+DrAQgDHrliww= X-Google-Smtp-Source: AGHT+IGWRcc6/8EOmc1T0X5CvPpjxQ1v9/oDjpa2olx4CY/PvhMRizP7HegUuy58IIILTSIW2C88EQ== X-Received: by 2002:a05:600c:4447:b0:42c:b63e:fe8f with SMTP id 5b1f17b1804b1-42d90817e87mr171803165e9.13.1726737699665; Thu, 19 Sep 2024 02:21:39 -0700 (PDT) Received: from [127.0.1.1] (host-80-117-99-70.retail.telecomitalia.it. [80.117.99.70]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e75468413sm16889465e9.45.2024.09.19.02.21.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 02:21:39 -0700 (PDT) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Thu, 19 Sep 2024 11:20:00 +0200 Subject: [PATCH v3 04/10] dt-bindings: iio: dac: ad3552r: add io-backend 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: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-4-a17b9b3d05d9@baylibre.com> References: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> In-Reply-To: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Nuno Sa , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Olivier Moysan Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dlechner@baylibre.com, Angelo Dureghello X-Mailer: b4 0.14.1 From: Angelo Dureghello There is a version AXI DAC IP block (for FPGAs) that provides a physical bus for AD3552R and similar chips, and acts as an SPI controller. For this case, the binding is modified to include some additional properties. Signed-off-by: Angelo Dureghello --- .../devicetree/bindings/iio/dac/adi,ad3552r.yaml | 42 ++++++++++++++++++= ++++ 1 file changed, 42 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml b/D= ocumentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml index 41fe00034742..aca4a41c2633 100644 --- a/Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml +++ b/Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml @@ -60,6 +60,18 @@ properties: $ref: /schemas/types.yaml#/definitions/uint32 enum: [0, 1, 2, 3] =20 + io-backends: + description: The iio backend reference. + An example backend can be found at + https://analogdevicesinc.github.io/hdl/library/axi_ad3552r/index.h= tml + maxItems: 1 + + adi,synchronous-mode: + description: Enable waiting for external synchronization signal. + Some AXI IP configuration can implement a dual-IP layout, with inter= nal + wirings for streaming synchronization. + type: boolean + '#address-cells': const: 1 =20 @@ -128,6 +140,7 @@ patternProperties: - custom-output-range-config =20 allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# - if: properties: compatible: @@ -238,4 +251,33 @@ examples: }; }; }; + + - | + axi_dac: spi@44a70000 { + compatible =3D "adi,axi-ad3552r"; + reg =3D <0x44a70000 0x1000>; + dmas =3D <&dac_tx_dma 0>; + dma-names =3D "tx"; + #io-backend-cells =3D <0>; + clocks =3D <&ref_clk>; + + #address-cells =3D <1>; + #size-cells =3D <0>; + + dac@0 { + compatible =3D "adi,ad3552r"; + reg =3D <0>; + reset-gpios =3D <&gpio0 92 0>; + io-backends =3D <&axi_dac>; + spi-max-frequency =3D <66000000>; + + #address-cells =3D <1>; + #size-cells =3D <0>; + + channel@0 { + reg =3D <0>; + adi,output-range-microvolt =3D <(-10000000) (10000000)>; + }; + }; + }; ... --=20 2.45.0.rc1 From nobody Fri Nov 29 12:47:58 2024 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 CFC3619B589 for ; Thu, 19 Sep 2024 09:21:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737705; cv=none; b=oXplqX4SuuWKXrkQsYEVrNDvi9+rbDRbrYsUuVj9kQBAhU0RCGZzYVtS3U9g9Me61o6Qcu20raCPSdTWVP3pjs041Zq2sIfvz7wRHPfPuy4l7n6ICYps8nmHpWNEH70+0EKx7KcGboj0tO3P3mwJFK3foLVPTVGtHp7wTsjoyYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737705; c=relaxed/simple; bh=ndWW4F3kvG2WWtSE6ODuaqI23NRH5daT94UTOq+wAJI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=USh37zPm5b4cewfF/hQAlMPp9dYwuxmZXy9vycFYmpOAW7X/5MlU+LnQzUPNUJ3yIfgeNhxgGam7ZLD37Nc4anhRn+MOnbX1ew5fkeIXOaAFJ4opre6bSuAqb6heHom3e1Gj+en/FuyOVR6sZiRzY0fDQz96mD+QjVoxdWtbXFA= 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=UXTqFOoU; arc=none smtp.client-ip=209.85.128.44 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="UXTqFOoU" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-42cae6bb895so5638225e9.1 for ; Thu, 19 Sep 2024 02:21:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726737701; x=1727342501; 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=uheLizxjohrzTA32l5fB0xiBW6E/tfS41z/13OK6jvo=; b=UXTqFOoUk/wACY7y71+UTsX6Bo6ykuZf3S8diYTT1xdgzwSbNZGttxwiy5BKZHAN+S 848nYAXtyvTtl2nkQ/jNvBWMfydww4ILww9xJ62+koRudWtCNAvsOAQ56NGf58SNEwGZ 4Wp3c2oBsIJbrJT9E/NUOo2ff6WpEtslQ9i5TGSVOViBuoU1NnU1gIO7PyFCeA6hRcSX XJNXkbJpqKzB6JJS2WPTKaELrye62HUlhv3yLI6fi5WycLFtlBJEcpwix/eArZ9jXSem rWIOhAgkrWR3yjezlzWLFHRrSxOJ+5nug1PbIPl3Y0wxHmckNoEhGejSdJDovE8GxbWL guLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726737701; x=1727342501; 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=uheLizxjohrzTA32l5fB0xiBW6E/tfS41z/13OK6jvo=; b=wEseYrdkcqsEXIxlKlSC8D/RqzNdNRVlEjtSVRpxZUM5flJIn2AcqYs+/DCGUej37N Kf5/1laNll3k4QpGAKMnYKA7LwcJvmRcRltXHAK+OGu0J+cMyNynhPBSMaB7nXoYXktI jO4JpJ39YdOzpAVj1lJVcizky94KbRHqvPggbonjB/EQAJQJhGF0cTmIR8XvAkGffxd0 WD0yt3Se+per9iVzpVodzzPEeGD4gw6eC91GITGXZzK8d9d1jnE+8pMXaMBvnV5aXmeX TPP2rPVn4c9Pb88Ygd7SPKsP4E2cFLFQCG5dRN4jEKoZFTykm3ceVrLtm2XG3lnFyFvK JPiA== X-Forwarded-Encrypted: i=1; AJvYcCXLP23r12P+RNuJO5BvtawqhGcmJGOHJU2UhnDz3Uiz6ihAZly6QCVKi2yBQjMDpSuOtsKXvNMpahst+jc=@vger.kernel.org X-Gm-Message-State: AOJu0YyVU/MPBvn+jtfqAIEm5hbKUF0jHyQdVm4pHYUjVm8W5cAX6C79 2WU/iDP2XKw81GlQ9RxPLixZnsyF2kM5tSZtU2evdz3DRFz8AMzSBJJst621pzg= X-Google-Smtp-Source: AGHT+IGo7k4GbR5Iqbckdvkvhmnrc/hp0sCtcOfUiHzER3VgMV4G+zqq7NZvGjYwmPZu7Anwy34WiA== X-Received: by 2002:a05:600c:511d:b0:42c:b62c:9f36 with SMTP id 5b1f17b1804b1-42cdb5389e4mr187787295e9.5.1726737701158; Thu, 19 Sep 2024 02:21:41 -0700 (PDT) Received: from [127.0.1.1] (host-80-117-99-70.retail.telecomitalia.it. [80.117.99.70]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e75468413sm16889465e9.45.2024.09.19.02.21.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 02:21:40 -0700 (PDT) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Thu, 19 Sep 2024 11:20:01 +0200 Subject: [PATCH v3 05/10] iio: backend: extend features 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: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-5-a17b9b3d05d9@baylibre.com> References: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> In-Reply-To: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Nuno Sa , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Olivier Moysan Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dlechner@baylibre.com, Angelo Dureghello X-Mailer: b4 0.14.1 From: Angelo Dureghello Extend backend features with new calls needed later on this patchset from axi version of ad3552r. The follwoing calls are added: iio_backend_ext_sync_enable enable synchronize channels on external trigger iio_backend_ext_sync_disable disable synchronize channels on external trigger iio_backend_ddr_enable enable ddr bus transfer iio_backend_ddr_disable disable ddr bus transfer iio_backend_set_bus_mode select the type of bus, so that specific read / write operations are performed accordingly iio_backend_buffer_enable enable buffer iio_backend_buffer_disable disable buffer iio_backend_data_transfer_addr define the target register address where the DAC sample will be written. Signed-off-by: Angelo Dureghello --- drivers/iio/industrialio-backend.c | 111 +++++++++++++++++++++++++++++++++= ++++ include/linux/iio/backend.h | 23 ++++++++ 2 files changed, 134 insertions(+) diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-= backend.c index 20b3b5212da7..f4802c422dbf 100644 --- a/drivers/iio/industrialio-backend.c +++ b/drivers/iio/industrialio-backend.c @@ -718,6 +718,117 @@ static int __devm_iio_backend_get(struct device *dev,= struct iio_backend *back) return 0; } =20 +/** + * iio_backend_ext_sync_enable - Enable external synchronization + * @back: Backend device + * + * Enable synchronization by external signal. + * + * RETURNS: + * 0 on success, negative error number on failure. + */ +int iio_backend_ext_sync_enable(struct iio_backend *back) +{ + return iio_backend_op_call(back, ext_sync_enable); +} +EXPORT_SYMBOL_NS_GPL(iio_backend_ext_sync_enable, IIO_BACKEND); + +/** + * iio_backend_ext_sync_disable - Disable external synchronization + * @back: Backend device + * + * Disable synchronization by external signal. + * + * RETURNS: + * 0 on success, negative error number on failure. + */ +int iio_backend_ext_sync_disable(struct iio_backend *back) +{ + return iio_backend_op_call(back, ext_sync_disable); +} +EXPORT_SYMBOL_NS_GPL(iio_backend_ext_sync_disable, IIO_BACKEND); + +/** + * iio_backend_ddr_enable - Enable interface DDR (Double Data Rate) mode + * @back: Backend device + * + * Enabling DDR, data is generated by the IP at each front + * (raising and falling) of the bus clock signal. + * + * RETURNS: + * 0 on success, negative error number on failure. + */ +int iio_backend_ddr_enable(struct iio_backend *back) +{ + return iio_backend_op_call(back, ddr_enable); +} +EXPORT_SYMBOL_NS_GPL(iio_backend_ddr_enable, IIO_BACKEND); + +/** + * iio_backend_ddr_disable - Disable interface DDR (Double Data Rate) mode + * @back: Backend device + * + * Disabling DDR data is generated byt the IP at rising or falling front + * of the interface clock signal (SDR, Single Data Rate). + * + * RETURNS: + * 0 on success, negative error number on failure. + */ +int iio_backend_ddr_disable(struct iio_backend *back) +{ + return iio_backend_op_call(back, ddr_disable); +} +EXPORT_SYMBOL_NS_GPL(iio_backend_ddr_disable, IIO_BACKEND); + +/** + * iio_backend_buffer_enable - Enable iio buffering + * @back: Backend device + * + * Enabling the buffer, buffer data is processed and sent out from the + * bus interface. + * + * RETURNS: + * 0 on success, negative error number on failure. + */ +int iio_backend_buffer_enable(struct iio_backend *back) +{ + return iio_backend_op_call(back, buffer_enable); +} +EXPORT_SYMBOL_NS_GPL(iio_backend_buffer_enable, IIO_BACKEND); + +/** + * iio_backend_buffer_disable - Disable iio buffering + * @back: Backend device + * + * Disabling the buffer, buffer data transfer on the bus interface + * is stopped. + * + * RETURNS: + * 0 on success, negative error number on failure. + */ +int iio_backend_buffer_disable(struct iio_backend *back) +{ + return iio_backend_op_call(back, buffer_disable); +} +EXPORT_SYMBOL_NS_GPL(iio_backend_buffer_disable, IIO_BACKEND); + +/** + * iio_backend_data_transfer_addr - Set data address. + * @back: Backend device + * @address: Data register address + * + * Some devices may need to inform the backend about an address + * where to read or write the data. + * + * RETURNS: + * 0 on success, negative error number on failure. + */ +int iio_backend_data_transfer_addr(struct iio_backend *back, u32 address) +{ + return iio_backend_op_call(back, data_transfer_addr, address); +} +EXPORT_SYMBOL_NS_GPL(iio_backend_data_transfer_addr, IIO_BACKEND); + static struct iio_backend *__devm_iio_backend_fwnode_get(struct device *de= v, const char *name, struct fwnode_handle *fwnode) { diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h index 37d56914d485..41619b803cd6 100644 --- a/include/linux/iio/backend.h +++ b/include/linux/iio/backend.h @@ -14,12 +14,14 @@ struct iio_dev; enum iio_backend_data_type { IIO_BACKEND_TWOS_COMPLEMENT, IIO_BACKEND_OFFSET_BINARY, + IIO_BACKEND_DATA_UNSIGNED, IIO_BACKEND_DATA_TYPE_MAX }; =20 enum iio_backend_data_source { IIO_BACKEND_INTERNAL_CONTINUOUS_WAVE, IIO_BACKEND_EXTERNAL, + IIO_BACKEND_INTERNAL_RAMP_16BIT, IIO_BACKEND_DATA_SOURCE_MAX }; =20 @@ -89,6 +91,13 @@ enum iio_backend_sample_trigger { * @read_raw: Read a channel attribute from a backend device * @debugfs_print_chan_status: Print channel status into a buffer. * @debugfs_reg_access: Read or write register value of backend. + * @ext_sync_enable: Enable external synchronization. + * @ext_sync_disable: Disable external synchronization. + * @ddr_enable: Enable interface DDR (Double Data Rate) mode. + * @ddr_disable: Disable interface DDR (Double Data Rate) mode. + * @buffer_enable: Enable data buffer. + * @buffer_disable: Disable data buffer. + * @data_transfer_addr: Set data address. **/ struct iio_backend_ops { int (*enable)(struct iio_backend *back); @@ -129,6 +138,13 @@ struct iio_backend_ops { size_t len); int (*debugfs_reg_access)(struct iio_backend *back, unsigned int reg, unsigned int writeval, unsigned int *readval); + int (*ext_sync_enable)(struct iio_backend *back); + int (*ext_sync_disable)(struct iio_backend *back); + int (*ddr_enable)(struct iio_backend *back); + int (*ddr_disable)(struct iio_backend *back); + int (*buffer_enable)(struct iio_backend *back); + int (*buffer_disable)(struct iio_backend *back); + int (*data_transfer_addr)(struct iio_backend *back, u32 address); }; =20 /** @@ -164,6 +180,13 @@ int iio_backend_data_sample_trigger(struct iio_backend= *back, int devm_iio_backend_request_buffer(struct device *dev, struct iio_backend *back, struct iio_dev *indio_dev); +int iio_backend_ext_sync_enable(struct iio_backend *back); +int iio_backend_ext_sync_disable(struct iio_backend *back); +int iio_backend_ddr_enable(struct iio_backend *back); +int iio_backend_ddr_disable(struct iio_backend *back); +int iio_backend_buffer_enable(struct iio_backend *back); +int iio_backend_buffer_disable(struct iio_backend *back); +int iio_backend_data_transfer_addr(struct iio_backend *back, u32 address); ssize_t iio_backend_ext_info_set(struct iio_dev *indio_dev, uintptr_t priv= ate, const struct iio_chan_spec *chan, const char *buf, size_t len); --=20 2.45.0.rc1 From nobody Fri Nov 29 12:47:58 2024 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 6358019C572 for ; Thu, 19 Sep 2024 09:21:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737706; cv=none; b=DS6mOcGC0vbllvkZMiLN47yKAhSbvqbnAXasRdBmTV486idfqR9053r74MMLnWe7zgTBPzWiWg39bRFx6V7WJW90xbKFb7Uw/0jLGIsnyY4bZTEbcIwik+BjPODgpGHnQ44zK+TpV2fkAakg1tS2BQ/E9UTVaf4cDjSIK+31gV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737706; c=relaxed/simple; bh=4XGzOom73gIUerRuQzf8Mp6Hdpu6jdjxRrE6nfsGpMw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qOMjE4vBYp3sGB6eeRDuxEIv/1HINMMGk4zs3hQXXoL7FT3SAGs3nDN4itBqYB3O6+WTGzsPxHnWbHeGJepMZzfNqCZa5t2Z16Q3DxhvNmFGBzZm4I6BwMK22ZTeI+aQ2/4U/dOn5vmHYMkkISdYvDFwPaClNtqoTa0caK7S6Zg= 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=XoFofSA6; arc=none smtp.client-ip=209.85.128.47 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="XoFofSA6" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4280ca0791bso5577875e9.1 for ; Thu, 19 Sep 2024 02:21:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726737703; x=1727342503; 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=+NnBndRi3FD2u5hSLd2eWpqMwpmgUucEYsLUxhMHG+Y=; b=XoFofSA6f4r9Lr59vufIy3+8K+ALOQ7y8ga06BSSTdCmWw9hc3njoPABVQ8/HInq4H GvPA3bjtgIX038V3Q1xxwhN51RODz+TiuBZXeTW5JFvvMRqQGagtaZjzh5mXHQ8I1V39 jghM22vb+Ll2ypzn3Filonb9wK5Lj2AO4lAFuIqUfMw9Btf3+yWC/SiUEWQyDyubBrYU EfSG5EP9MF+hMGbbCM9uKbmZTNqPqqgAmBaCIdA+5bOTnE/axCpMW0/8tL7i8tkE+NgX 1Hgl9KUJW7xOfX7Qof0rtCqEUYRFC6o5II/e3PKCZ85GXcXHbaqqMCqMexGm80l+qPn+ iMoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726737703; x=1727342503; 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=+NnBndRi3FD2u5hSLd2eWpqMwpmgUucEYsLUxhMHG+Y=; b=UDVxHjkFc7aT7TTv1TDLJBR0a6ou0wkI1NnAcoEIM4IYeDp/wJAj2fUDvCTFNjtKGZ mH5l0Zp3Yc1Uc8iP1G868DL1ab/dLNyuEHXZ9iUJojDdBe0WYuNycrXx9wxa/AaEFwbT XyYPyvE9tBqBmSkdCXfaSvwiilWU15b5Xc1JCp9Sco4bk3vwRtGGH9q/lJDkmfOBe//n ItVl4fZ0Ge+JZQtUewwO9PKERKvrBVMkLHy17lujNr9dx9+x7TH/TQSi5lh9LwNyznws 8c5Htr6lrG6VFkXyltKm8I7k3EnX1e1OH0hoGhNY0ue1mvz+1DSvmj0G2aqlrmxd0S4g LLbw== X-Forwarded-Encrypted: i=1; AJvYcCXedPmj/nfjSOkjqNiaDW3bc5D5XGiP4XZC8dOD4Yq9If/tNYMJ679iLXKfZH+ZY/+Gr5sfA4st9aOrz58=@vger.kernel.org X-Gm-Message-State: AOJu0YwyrPav9pV7UFEMoP5iT6QdLzJFavmbeEpQblt4t1bOiqwtKHOD wunv6nXBegDXZSvKwLpD0WiGBe7yk+0vr5UMuqVZEb3ZosqdR8qd9nCGaQ8KkZw= X-Google-Smtp-Source: AGHT+IHZHQpR0mpe3LtuSi9Eaj8AoE1qOaflbXcjPyYtDfqSz6Dkp7VzXwt7Q9nBhYgyFNdk0J3Ogg== X-Received: by 2002:adf:8b9e:0:b0:377:205f:c494 with SMTP id ffacd0b85a97d-378c2cfebc6mr14578799f8f.11.1726737702631; Thu, 19 Sep 2024 02:21:42 -0700 (PDT) Received: from [127.0.1.1] (host-80-117-99-70.retail.telecomitalia.it. [80.117.99.70]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e75468413sm16889465e9.45.2024.09.19.02.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 02:21:42 -0700 (PDT) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Thu, 19 Sep 2024 11:20:02 +0200 Subject: [PATCH v3 06/10] iio: backend: adi-axi-dac: extend features 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: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-6-a17b9b3d05d9@baylibre.com> References: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> In-Reply-To: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Nuno Sa , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Olivier Moysan Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dlechner@baylibre.com, Angelo Dureghello X-Mailer: b4 0.14.1 From: Angelo Dureghello Extend AXI-DAC backend with new features required to interface to the ad3552r DAC. Mainly, a new compatible string is added to support the ad3552r-axi DAC IP, very similar to the generic DAC IP but with some customizations to work with the ad3552r. Then, a serie of generic functions has been added to match with ad3552r needs. Function names has been kept generic as much as possible, to allow re-utilization from other frontend drivers. Signed-off-by: Angelo Dureghello --- drivers/iio/dac/adi-axi-dac.c | 274 ++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 265 insertions(+), 9 deletions(-) diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c index b8b4171b8043..3ca3a14c575b 100644 --- a/drivers/iio/dac/adi-axi-dac.c +++ b/drivers/iio/dac/adi-axi-dac.c @@ -44,11 +44,34 @@ #define AXI_DAC_RSTN_MMCM_RSTN BIT(1) #define AXI_DAC_RSTN_RSTN BIT(0) #define AXI_DAC_REG_CNTRL_1 0x0044 +#define AXI_DAC_EXT_SYNC_ARM BIT(1) +#define AXI_DAC_EXT_SYNC_DISARM BIT(2) #define AXI_DAC_SYNC BIT(0) #define AXI_DAC_REG_CNTRL_2 0x0048 +#define AXI_DAC_SDR_DDR_N BIT(16) +#define AXI_DAC_SYMB_8B BIT(14) #define ADI_DAC_R1_MODE BIT(5) +#define AXI_DAC_UNSIGNED_DATA BIT(4) +#define AXI_DAC_REG_STATUS_1 0x54 +#define AXI_DAC_REG_STATUS_2 0x58 #define AXI_DAC_DRP_STATUS 0x0074 #define AXI_DAC_DRP_LOCKED BIT(17) +#define AXI_DAC_CNTRL_DATA_RD 0x0080 +#define AXI_DAC_DATA_RD_8 GENMASK(7, 0) +#define AXI_DAC_DATA_RD_16 GENMASK(15, 0) +#define AXI_DAC_CNTRL_DATA_WR 0x0084 +#define AXI_DAC_DATA_WR_8 GENMASK(23, 16) +#define AXI_DAC_DATA_WR_16 GENMASK(23, 8) +#define AXI_DAC_UI_STATUS 0x0088 +#define AXI_DAC_BUSY BIT(4) +#define AXI_DAC_REG_CUSTOM_CTRL 0x008C +#define AXI_DAC_ADDRESS GENMASK(31, 24) +#define AXI_DAC_SYNCED_TRANSFER BIT(2) +#define AXI_DAC_STREAM BIT(1) +#define AXI_DAC_TRANSFER_DATA BIT(0) + +#define AXI_DAC_STREAM_ENABLE (AXI_DAC_TRANSFER_DATA | AXI_DAC_STREAM) + /* DAC Channel controls */ #define AXI_DAC_REG_CHAN_CNTRL_1(c) (0x0400 + (c) * 0x40) #define AXI_DAC_REG_CHAN_CNTRL_3(c) (0x0408 + (c) * 0x40) @@ -62,11 +85,25 @@ #define AXI_DAC_REG_CHAN_CNTRL_7(c) (0x0418 + (c) * 0x40) #define AXI_DAC_DATA_SEL GENMASK(3, 0) =20 +#define AXI_DAC_RD_ADDR(x) (BIT(7) | (x)) + /* 360 degrees in rad */ #define AXI_DAC_2_PI_MEGA 6283190 + enum { AXI_DAC_DATA_INTERNAL_TONE, AXI_DAC_DATA_DMA =3D 2, + AXI_DAC_DATA_INTERNAL_RAMP_16BIT =3D 11, +}; + +enum { + AXI_DAC_BUS_TYPE_NONE, + AXI_DAC_BUS_TYPE_DDR_QSPI, +}; + +struct axi_dac_info { + unsigned int version; + int bus_type; }; =20 struct axi_dac_state { @@ -77,6 +114,7 @@ struct axi_dac_state { * data/variables. */ struct mutex lock; + const struct axi_dac_info *info; u64 dac_clk; u32 reg_config; bool int_tone; @@ -461,6 +499,11 @@ static int axi_dac_data_source_set(struct iio_backend = *back, unsigned int chan, return regmap_update_bits(st->regmap, AXI_DAC_REG_CHAN_CNTRL_7(chan), AXI_DAC_DATA_SEL, AXI_DAC_DATA_DMA); + case IIO_BACKEND_INTERNAL_RAMP_16BIT: + return regmap_update_bits(st->regmap, + AXI_DAC_REG_CHAN_CNTRL_7(chan), + AXI_DAC_DATA_SEL, + AXI_DAC_DATA_INTERNAL_RAMP_16BIT); default: return -EINVAL; } @@ -518,9 +561,206 @@ static int axi_dac_reg_access(struct iio_backend *bac= k, unsigned int reg, return regmap_write(st->regmap, reg, writeval); } =20 +static int axi_dac_ext_sync_enable(struct iio_backend *back) +{ + struct axi_dac_state *st =3D iio_backend_get_priv(back); + + return regmap_set_bits(st->regmap, AXI_DAC_REG_CNTRL_1, + AXI_DAC_EXT_SYNC_ARM); +} + +static int axi_dac_ext_sync_disable(struct iio_backend *back) +{ + struct axi_dac_state *st =3D iio_backend_get_priv(back); + + return regmap_clear_bits(st->regmap, AXI_DAC_REG_CNTRL_1, + AXI_DAC_EXT_SYNC_DISARM); +} + +static int axi_dac_ddr_enable(struct iio_backend *back) +{ + struct axi_dac_state *st =3D iio_backend_get_priv(back); + + return regmap_clear_bits(st->regmap, AXI_DAC_REG_CNTRL_2, + AXI_DAC_SDR_DDR_N); +} + +static int axi_dac_ddr_disable(struct iio_backend *back) +{ + struct axi_dac_state *st =3D iio_backend_get_priv(back); + + return regmap_set_bits(st->regmap, AXI_DAC_REG_CNTRL_2, + AXI_DAC_SDR_DDR_N); +} + +static int axi_dac_buffer_enable(struct iio_backend *back) +{ + struct axi_dac_state *st =3D iio_backend_get_priv(back); + + return regmap_set_bits(st->regmap, AXI_DAC_REG_CUSTOM_CTRL, + AXI_DAC_STREAM_ENABLE); +} + +static int axi_dac_buffer_disable(struct iio_backend *back) +{ + struct axi_dac_state *st =3D iio_backend_get_priv(back); + + return regmap_clear_bits(st->regmap, AXI_DAC_REG_CUSTOM_CTRL, + AXI_DAC_STREAM_ENABLE); +} + +static int axi_dac_data_transfer_addr(struct iio_backend *back, u32 addres= s) +{ + struct axi_dac_state *st =3D iio_backend_get_priv(back); + + /* + * Sample register address, when the DAC is configured, or stream + * start address when the FSM is in stream state. + */ + return regmap_update_bits(st->regmap, AXI_DAC_REG_CUSTOM_CTRL, + AXI_DAC_ADDRESS, + FIELD_PREP(AXI_DAC_ADDRESS, address)); +} + +static int axi_dac_data_format_set(struct iio_backend *back, unsigned int = ch, + const struct iio_backend_data_fmt *data) +{ + struct axi_dac_state *st =3D iio_backend_get_priv(back); + + if (data->type =3D=3D IIO_BACKEND_DATA_UNSIGNED) + return regmap_clear_bits(st->regmap, AXI_DAC_REG_CNTRL_2, + AXI_DAC_UNSIGNED_DATA); + + return -EINVAL; +} + +static int axi_dac_read_raw(struct iio_backend *back, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct axi_dac_state *st =3D iio_backend_get_priv(back); + int err; + + switch (mask) { + case IIO_CHAN_INFO_FREQUENCY: { + int clk_in, reg; + + /* + * As from AXI IP documentation, + * returning the SCLK depending on the stream mode. + */ + clk_in =3D clk_get_rate(clk_get(st->dev, 0)); + + err =3D regmap_read(st->regmap, AXI_DAC_REG_CUSTOM_CTRL, ®); + if (err) + return err; + + if (reg & AXI_DAC_STREAM) + *val =3D clk_in / 2; + else + *val =3D clk_in / 8; + + return IIO_VAL_INT; + } + default: + return -EINVAL; + } +} + +static int axi_dac_bus_reg_write(struct iio_backend *back, u32 reg, + unsigned int val, size_t data_size) +{ + struct axi_dac_state *st =3D iio_backend_get_priv(back); + + switch (st->info->bus_type) { + case AXI_DAC_BUS_TYPE_DDR_QSPI: { + int ret; + u32 ival; + + if (data_size =3D=3D 2) + ival =3D FIELD_PREP(AXI_DAC_DATA_WR_16, val); + else + ival =3D FIELD_PREP(AXI_DAC_DATA_WR_8, val); + + ret =3D regmap_write(st->regmap, AXI_DAC_CNTRL_DATA_WR, ival); + if (ret) + return ret; + + /* + * Both REG_CNTRL_2 and AXI_DAC_CNTRL_DATA_WR need to know + * the data size. So keeping data size control here only, + * since data size is mandatory for the current transfer. + * DDR state handled separately by specific backend calls, + * generally all raw register writes are SDR. + */ + if (data_size =3D=3D 1) + ret =3D regmap_set_bits(st->regmap, AXI_DAC_REG_CNTRL_2, + AXI_DAC_SYMB_8B); + else + ret =3D regmap_clear_bits(st->regmap, AXI_DAC_REG_CNTRL_2, + AXI_DAC_SYMB_8B); + if (ret) + return ret; + + ret =3D regmap_update_bits(st->regmap, AXI_DAC_REG_CUSTOM_CTRL, + AXI_DAC_ADDRESS, + FIELD_PREP(AXI_DAC_ADDRESS, reg)); + if (ret) + return ret; + + ret =3D regmap_update_bits(st->regmap, AXI_DAC_REG_CUSTOM_CTRL, + AXI_DAC_TRANSFER_DATA, + AXI_DAC_TRANSFER_DATA); + if (ret) + return ret; + + ret =3D regmap_read_poll_timeout(st->regmap, + AXI_DAC_REG_CUSTOM_CTRL, ival, + ival & AXI_DAC_TRANSFER_DATA, + 10, 100 * KILO); + if (ret) + return ret; + + return regmap_clear_bits(st->regmap, AXI_DAC_REG_CUSTOM_CTRL, + AXI_DAC_TRANSFER_DATA); + } + default: + return -EOPNOTSUPP; + } +} + +static int axi_dac_bus_reg_read(struct iio_backend *back, u32 reg, + unsigned int *val, size_t data_size) +{ + struct axi_dac_state *st =3D iio_backend_get_priv(back); + + switch (st->info->bus_type) { + case AXI_DAC_BUS_TYPE_DDR_QSPI: { + int ret; + u32 bval; + + ret =3D axi_dac_bus_reg_write(back, AXI_DAC_RD_ADDR(reg), 0, + data_size); + if (ret) + return ret; + + ret =3D regmap_read_poll_timeout(st->regmap, AXI_DAC_UI_STATUS, + bval, bval !=3D AXI_DAC_BUSY, + 10, 100); + if (ret) + return ret; + + return regmap_read(st->regmap, AXI_DAC_CNTRL_DATA_RD, val); + } + default: + return -EOPNOTSUPP; + } +} + static const struct iio_backend_ops axi_dac_generic_ops =3D { .enable =3D axi_dac_enable, .disable =3D axi_dac_disable, + .read_raw =3D axi_dac_read_raw, .request_buffer =3D axi_dac_request_buffer, .free_buffer =3D axi_dac_free_buffer, .extend_chan_spec =3D axi_dac_extend_chan, @@ -528,6 +768,14 @@ static const struct iio_backend_ops axi_dac_generic_op= s =3D { .ext_info_get =3D axi_dac_ext_info_get, .data_source_set =3D axi_dac_data_source_set, .set_sample_rate =3D axi_dac_set_sample_rate, + .ext_sync_enable =3D axi_dac_ext_sync_enable, + .ext_sync_disable =3D axi_dac_ext_sync_disable, + .ddr_enable =3D axi_dac_ddr_enable, + .ddr_disable =3D axi_dac_ddr_disable, + .buffer_enable =3D axi_dac_buffer_enable, + .buffer_disable =3D axi_dac_buffer_disable, + .data_format_set =3D axi_dac_data_format_set, + .data_transfer_addr =3D axi_dac_data_transfer_addr, .debugfs_reg_access =3D iio_backend_debugfs_ptr(axi_dac_reg_access), }; =20 @@ -545,7 +793,6 @@ static const struct regmap_config axi_dac_regmap_config= =3D { =20 static int axi_dac_probe(struct platform_device *pdev) { - const unsigned int *expected_ver; struct axi_dac_state *st; void __iomem *base; unsigned int ver; @@ -556,8 +803,8 @@ static int axi_dac_probe(struct platform_device *pdev) if (!st) return -ENOMEM; =20 - expected_ver =3D device_get_match_data(&pdev->dev); - if (!expected_ver) + st->info =3D device_get_match_data(&pdev->dev); + if (!st->info) return -ENODEV; =20 clk =3D devm_clk_get_enabled(&pdev->dev, NULL); @@ -588,12 +835,13 @@ static int axi_dac_probe(struct platform_device *pdev) if (ret) return ret; =20 - if (ADI_AXI_PCORE_VER_MAJOR(ver) !=3D ADI_AXI_PCORE_VER_MAJOR(*expected_v= er)) { + if (ADI_AXI_PCORE_VER_MAJOR(ver) !=3D + ADI_AXI_PCORE_VER_MAJOR(st->info->version)) { dev_err(&pdev->dev, "Major version mismatch. Expected %d.%.2d.%c, Reported %d.%.2d.%c\n", - ADI_AXI_PCORE_VER_MAJOR(*expected_ver), - ADI_AXI_PCORE_VER_MINOR(*expected_ver), - ADI_AXI_PCORE_VER_PATCH(*expected_ver), + ADI_AXI_PCORE_VER_MAJOR(st->info->version), + ADI_AXI_PCORE_VER_MINOR(st->info->version), + ADI_AXI_PCORE_VER_PATCH(st->info->version), ADI_AXI_PCORE_VER_MAJOR(ver), ADI_AXI_PCORE_VER_MINOR(ver), ADI_AXI_PCORE_VER_PATCH(ver)); @@ -631,10 +879,18 @@ static int axi_dac_probe(struct platform_device *pdev) return 0; } =20 -static unsigned int axi_dac_9_1_b_info =3D ADI_AXI_PCORE_VER(9, 1, 'b'); +static const struct axi_dac_info dac_generic =3D { + .version =3D ADI_AXI_PCORE_VER(9, 1, 'b'), +}; + +static const struct axi_dac_info dac_ad3552r =3D { + .version =3D ADI_AXI_PCORE_VER(9, 1, 'b'), + .bus_type =3D AXI_DAC_BUS_TYPE_DDR_QSPI, +}; =20 static const struct of_device_id axi_dac_of_match[] =3D { - { .compatible =3D "adi,axi-dac-9.1.b", .data =3D &axi_dac_9_1_b_info }, + { .compatible =3D "adi,axi-dac-9.1.b", .data =3D &dac_generic }, + { .compatible =3D "adi,axi-ad3552r", .data =3D &dac_ad3552r }, {} }; MODULE_DEVICE_TABLE(of, axi_dac_of_match); --=20 2.45.0.rc1 From nobody Fri Nov 29 12:47:58 2024 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.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 EBD4E19D069 for ; Thu, 19 Sep 2024 09:21:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737708; cv=none; b=oXswerLwTp/61UPG8XlsCGX2ExgSeVTWxTkl9IwqEk4tbcVhVJZWlcXiZ3n4UC+tg5xP+J/WKuv7p/JRl/MLqPEXsA/QTP2ABzeVmj5QpPoaVDUUF6g7eg6bi1S4vrkk3bDFxPhJNDD0tFfWSJT64iffOhsGWxkFogsptDe3Csg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737708; c=relaxed/simple; bh=iIDwGqolTd1HpLnj9SN11+oq2F3sidqm8mJBhcm2C6Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jmgHPkrnNElABaRAq18TzWS3I+mPyyzareyZ1X5qECPuOoY3annD0T9S9y/JScU8r7bc6UFyhvulzHbiscx1t8MIUdRsVCxu2gwmnGFf5RLDXaN0+k9jKnVecK3/+x01ZDZ9w5v5CMytRyCFws3c9NnvyxpXabsLGjqo6QqSo+Q= 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=VlxXMEGm; arc=none smtp.client-ip=209.85.128.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="VlxXMEGm" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-42cb0f28bfbso4942215e9.1 for ; Thu, 19 Sep 2024 02:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726737704; x=1727342504; 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=JG7iKoFeabciCOG8LbA5wLcP1lXi7bRJI0HkySWmPCU=; b=VlxXMEGm5Jj00+tDLElu7jPtHeNZLD9ZOLvv7Zwcw+R+H23cbFWPnDwaRY/Dff7LCy vbAw1RjJGxRk6b3gDcrAGmkAMM62bJFxi13JeNfUrvZbHnv1CU0HTcGgalwbiLLzjxys 5aKwrS1K8WWkI5Q10sV+pb3W+ZdFc0/7R/VfbDF8hN5pI04vgQ8fw5vzogOnhXghyZPx WfiqKC669F9uFB2onvl+s3eDQDCPNz7O2MFrISX0yp7ZeU5ZicyDSVJVwm/BOFI4V3nx tuL/cDiGaKuYr+9yzHUCEwEUsB8OI/YBqE4GdrfSupReJtxVyM22qRHAEJgIBhyW7Afx 93xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726737704; x=1727342504; 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=JG7iKoFeabciCOG8LbA5wLcP1lXi7bRJI0HkySWmPCU=; b=PF23XuuMniqpoD+W+8jC0Qcm9WkpQV+ZKL+Krbn6SBlyoxWzenzVuGvAK4pGjc+6ph t/KrfEZYmknehOLGlJkRI0uNsGwjzMYQ7ncxArs1qdjXjCpNUFZqO7aC80+jOKyt6waY S87HmQ51ZsgzxAvK1diyXI4f0udk0P4/Ya7IbelFEyTX62Qrc5CCE17S9NUf1z3mT8wk KmolCEpUxsoNXVfMdDl6JzKfZjJwOYsXFPmsR9UOLO0sGOABp12oHTKt6Kp7KBufyF/a KxcW3p1pYhRBPrk6HleEFkf6YQvOzt4duEw9XiyxkBCZySu5PLSEn0kvKuUiozLc4xys 0k2A== X-Forwarded-Encrypted: i=1; AJvYcCVkk6lDr4Z+698OoAecJ6KBv9yfrxA6XFapB5+7doKH6+VHn1TAofb911DLntFIG8//6ly2Z8w1Pbzm99M=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1pMnsvYxn8NCTryb6t1e6GXBP89ZbYLgXaKza8W8jK9rcYvWv DS0zc9NQstnd0EYH8weZWgn5Y8DJuaUOVOIYt2yN+Gd5ZIBZSQ5fAU+FY/UKFys= X-Google-Smtp-Source: AGHT+IGxDCZWwL0ddFAcwaMdzoqfXORY4yIQqNJDfTozWQfyIFo21DEnt6zWpZeyoweJLYMJkTCjNA== X-Received: by 2002:a05:600c:3b9e:b0:42c:bd4d:e8ba with SMTP id 5b1f17b1804b1-42cdb522847mr171812505e9.8.1726737704023; Thu, 19 Sep 2024 02:21:44 -0700 (PDT) Received: from [127.0.1.1] (host-80-117-99-70.retail.telecomitalia.it. [80.117.99.70]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e75468413sm16889465e9.45.2024.09.19.02.21.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 02:21:43 -0700 (PDT) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Thu, 19 Sep 2024 11:20:03 +0200 Subject: [PATCH v3 07/10] iio: dac: ad3552r: changes to use FIELD_PREP 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: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-7-a17b9b3d05d9@baylibre.com> References: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> In-Reply-To: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Nuno Sa , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Olivier Moysan Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dlechner@baylibre.com, Angelo Dureghello X-Mailer: b4 0.14.1 From: Angelo Dureghello Changes to use FIELD_PREP, so that driver-specific ad3552r_field_prep is removed. Variables (arrays) that was used to call ad3552r_field_prep are removed too. Signed-off-by: Angelo Dureghello --- drivers/iio/dac/ad3552r.c | 166 ++++++++++++++----------------------------= ---- 1 file changed, 49 insertions(+), 117 deletions(-) diff --git a/drivers/iio/dac/ad3552r.c b/drivers/iio/dac/ad3552r.c index bd37d304ca70..c27706c5ba10 100644 --- a/drivers/iio/dac/ad3552r.c +++ b/drivers/iio/dac/ad3552r.c @@ -210,46 +210,6 @@ static const s32 gains_scaling_table[] =3D { [AD3552R_CH_GAIN_SCALING_0_125] =3D 125 }; =20 -enum ad3552r_dev_attributes { - /* - Direct register values */ - /* From 0-3 */ - AD3552R_SDO_DRIVE_STRENGTH, - /* - * 0 -> Internal Vref, vref_io pin floating (default) - * 1 -> Internal Vref, vref_io driven by internal vref - * 2 or 3 -> External Vref - */ - AD3552R_VREF_SELECT, - /* Read registers in ascending order if set. Else descending */ - AD3552R_ADDR_ASCENSION, -}; - -enum ad3552r_ch_attributes { - /* DAC powerdown */ - AD3552R_CH_DAC_POWERDOWN, - /* DAC amplifier powerdown */ - AD3552R_CH_AMPLIFIER_POWERDOWN, - /* Select the output range. Select from enum ad3552r_ch_output_range */ - AD3552R_CH_OUTPUT_RANGE_SEL, - /* - * Over-rider the range selector in order to manually set the output - * voltage range - */ - AD3552R_CH_RANGE_OVERRIDE, - /* Manually set the offset voltage */ - AD3552R_CH_GAIN_OFFSET, - /* Sets the polarity of the offset. */ - AD3552R_CH_GAIN_OFFSET_POLARITY, - /* PDAC gain scaling */ - AD3552R_CH_GAIN_SCALING_P, - /* NDAC gain scaling */ - AD3552R_CH_GAIN_SCALING_N, - /* Rfb value */ - AD3552R_CH_RFB, - /* Channel select. When set allow Input -> DAC and Mask -> DAC */ - AD3552R_CH_SELECT, -}; - struct ad3552r_ch_data { s32 scale_int; s32 scale_dec; @@ -285,45 +245,6 @@ struct ad3552r_desc { unsigned int num_ch; }; =20 -static const u16 addr_mask_map[][2] =3D { - [AD3552R_ADDR_ASCENSION] =3D { - AD3552R_REG_ADDR_INTERFACE_CONFIG_A, - AD3552R_MASK_ADDR_ASCENSION - }, - [AD3552R_SDO_DRIVE_STRENGTH] =3D { - AD3552R_REG_ADDR_INTERFACE_CONFIG_D, - AD3552R_MASK_SDO_DRIVE_STRENGTH - }, - [AD3552R_VREF_SELECT] =3D { - AD3552R_REG_ADDR_SH_REFERENCE_CONFIG, - AD3552R_MASK_REFERENCE_VOLTAGE_SEL - }, -}; - -/* 0 -> reg addr, 1->ch0 mask, 2->ch1 mask */ -static const u16 addr_mask_map_ch[][3] =3D { - [AD3552R_CH_DAC_POWERDOWN] =3D { - AD3552R_REG_ADDR_POWERDOWN_CONFIG, - AD3552R_MASK_CH_DAC_POWERDOWN(0), - AD3552R_MASK_CH_DAC_POWERDOWN(1) - }, - [AD3552R_CH_AMPLIFIER_POWERDOWN] =3D { - AD3552R_REG_ADDR_POWERDOWN_CONFIG, - AD3552R_MASK_CH_AMPLIFIER_POWERDOWN(0), - AD3552R_MASK_CH_AMPLIFIER_POWERDOWN(1) - }, - [AD3552R_CH_OUTPUT_RANGE_SEL] =3D { - AD3552R_REG_ADDR_CH0_CH1_OUTPUT_RANGE, - AD3552R_MASK_CH_OUTPUT_RANGE_SEL(0), - AD3552R_MASK_CH_OUTPUT_RANGE_SEL(1) - }, - [AD3552R_CH_SELECT] =3D { - AD3552R_REG_ADDR_CH_SELECT_16B, - AD3552R_MASK_CH(0), - AD3552R_MASK_CH(1) - } -}; - static u8 _ad3552r_reg_len(u8 addr) { switch (addr) { @@ -399,11 +320,6 @@ static int ad3552r_read_reg(struct ad3552r_desc *dac, = u8 addr, u16 *val) return 0; } =20 -static u16 ad3552r_field_prep(u16 val, u16 mask) -{ - return (val << __ffs(mask)) & mask; -} - /* Update field of a register, shift val if needed */ static int ad3552r_update_reg_field(struct ad3552r_desc *dac, u8 addr, u16= mask, u16 val) @@ -416,21 +332,11 @@ static int ad3552r_update_reg_field(struct ad3552r_de= sc *dac, u8 addr, u16 mask, return ret; =20 reg &=3D ~mask; - reg |=3D ad3552r_field_prep(val, mask); + reg |=3D val; =20 return ad3552r_write_reg(dac, addr, reg); } =20 -static int ad3552r_set_ch_value(struct ad3552r_desc *dac, - enum ad3552r_ch_attributes attr, - u8 ch, - u16 val) -{ - /* Update register related to attributes in chip */ - return ad3552r_update_reg_field(dac, addr_mask_map_ch[attr][0], - addr_mask_map_ch[attr][ch + 1], val); -} - #define AD3552R_CH_DAC(_idx) ((struct iio_chan_spec) { \ .type =3D IIO_VOLTAGE, \ .output =3D true, \ @@ -510,8 +416,14 @@ static int ad3552r_write_raw(struct iio_dev *indio_dev, val); break; case IIO_CHAN_INFO_ENABLE: - err =3D ad3552r_set_ch_value(dac, AD3552R_CH_DAC_POWERDOWN, - chan->channel, !val); + if (chan->channel =3D=3D 0) + val =3D FIELD_PREP(AD3552R_MASK_CH_DAC_POWERDOWN(0), !val); + else + val =3D FIELD_PREP(AD3552R_MASK_CH_DAC_POWERDOWN(1), !val); + + err =3D ad3552r_update_reg_field(dac, AD3552R_REG_ADDR_POWERDOWN_CONFIG, + AD3552R_MASK_CH_DAC_POWERDOWN(chan->channel), + val); break; default: err =3D -EINVAL; @@ -715,9 +627,9 @@ static int ad3552r_reset(struct ad3552r_desc *dac) } =20 return ad3552r_update_reg_field(dac, - addr_mask_map[AD3552R_ADDR_ASCENSION][0], - addr_mask_map[AD3552R_ADDR_ASCENSION][1], - val); + AD3552R_REG_ADDR_INTERFACE_CONFIG_A, + AD3552R_MASK_ADDR_ASCENSION, + FIELD_PREP(AD3552R_MASK_ADDR_ASCENSION, val)); } =20 static void ad3552r_get_custom_range(struct ad3552r_desc *dac, s32 i, s32 = *v_min, @@ -812,20 +724,20 @@ static int ad3552r_configure_custom_gain(struct ad355= 2r_desc *dac, "mandatory custom-output-range-config property missing\n"); =20 dac->ch_data[ch].range_override =3D 1; - reg |=3D ad3552r_field_prep(1, AD3552R_MASK_CH_RANGE_OVERRIDE); + reg |=3D FIELD_PREP(AD3552R_MASK_CH_RANGE_OVERRIDE, 1); =20 err =3D fwnode_property_read_u32(gain_child, "adi,gain-scaling-p", &val); if (err) return dev_err_probe(dev, err, "mandatory adi,gain-scaling-p property missing\n"); - reg |=3D ad3552r_field_prep(val, AD3552R_MASK_CH_GAIN_SCALING_P); + reg |=3D FIELD_PREP(AD3552R_MASK_CH_GAIN_SCALING_P, val); dac->ch_data[ch].p =3D val; =20 err =3D fwnode_property_read_u32(gain_child, "adi,gain-scaling-n", &val); if (err) return dev_err_probe(dev, err, "mandatory adi,gain-scaling-n property missing\n"); - reg |=3D ad3552r_field_prep(val, AD3552R_MASK_CH_GAIN_SCALING_N); + reg |=3D FIELD_PREP(AD3552R_MASK_CH_GAIN_SCALING_N, val); dac->ch_data[ch].n =3D val; =20 err =3D fwnode_property_read_u32(gain_child, "adi,rfb-ohms", &val); @@ -841,9 +753,9 @@ static int ad3552r_configure_custom_gain(struct ad3552r= _desc *dac, dac->ch_data[ch].gain_offset =3D val; =20 offset =3D abs((s32)val); - reg |=3D ad3552r_field_prep((offset >> 8), AD3552R_MASK_CH_OFFSET_BIT_8); + reg |=3D FIELD_PREP(AD3552R_MASK_CH_OFFSET_BIT_8, (offset >> 8)); =20 - reg |=3D ad3552r_field_prep((s32)val < 0, AD3552R_MASK_CH_OFFSET_POLARITY= ); + reg |=3D FIELD_PREP(AD3552R_MASK_CH_OFFSET_POLARITY, (s32)val < 0); addr =3D AD3552R_REG_ADDR_CH_GAIN(ch); err =3D ad3552r_write_reg(dac, addr, offset & AD3552R_MASK_CH_OFFSET_BITS_0_7); @@ -886,9 +798,9 @@ static int ad3552r_configure_device(struct ad3552r_desc= *dac) } =20 err =3D ad3552r_update_reg_field(dac, - addr_mask_map[AD3552R_VREF_SELECT][0], - addr_mask_map[AD3552R_VREF_SELECT][1], - val); + AD3552R_REG_ADDR_SH_REFERENCE_CONFIG, + AD3552R_MASK_REFERENCE_VOLTAGE_SEL, + FIELD_PREP(AD3552R_MASK_REFERENCE_VOLTAGE_SEL, val)); if (err) return err; =20 @@ -900,9 +812,9 @@ static int ad3552r_configure_device(struct ad3552r_desc= *dac) } =20 err =3D ad3552r_update_reg_field(dac, - addr_mask_map[AD3552R_SDO_DRIVE_STRENGTH][0], - addr_mask_map[AD3552R_SDO_DRIVE_STRENGTH][1], - val); + AD3552R_REG_ADDR_INTERFACE_CONFIG_D, + AD3552R_MASK_SDO_DRIVE_STRENGTH, + FIELD_PREP(AD3552R_MASK_SDO_DRIVE_STRENGTH, val)); if (err) return err; } @@ -938,9 +850,15 @@ static int ad3552r_configure_device(struct ad3552r_des= c *dac) "Invalid adi,output-range-microvolt value\n"); =20 val =3D err; - err =3D ad3552r_set_ch_value(dac, - AD3552R_CH_OUTPUT_RANGE_SEL, - ch, val); + if (ch =3D=3D 0) + val =3D FIELD_PREP(AD3552R_MASK_CH_OUTPUT_RANGE_SEL(0), val); + else + val =3D FIELD_PREP(AD3552R_MASK_CH_OUTPUT_RANGE_SEL(1), val); + + err =3D ad3552r_update_reg_field(dac, + AD3552R_REG_ADDR_CH0_CH1_OUTPUT_RANGE, + AD3552R_MASK_CH_OUTPUT_RANGE_SEL(ch), + val); if (err) return err; =20 @@ -958,7 +876,14 @@ static int ad3552r_configure_device(struct ad3552r_des= c *dac) ad3552r_calc_gain_and_offset(dac, ch); dac->enabled_ch |=3D BIT(ch); =20 - err =3D ad3552r_set_ch_value(dac, AD3552R_CH_SELECT, ch, 1); + if (ch =3D=3D 0) + val =3D FIELD_PREP(AD3552R_MASK_CH(0), 1); + else + val =3D FIELD_PREP(AD3552R_MASK_CH(1), 1); + + err =3D ad3552r_update_reg_field(dac, + AD3552R_REG_ADDR_CH_SELECT_16B, + AD3552R_MASK_CH(ch), val); if (err < 0) return err; =20 @@ -970,8 +895,15 @@ static int ad3552r_configure_device(struct ad3552r_des= c *dac) /* Disable unused channels */ for_each_clear_bit(ch, &dac->enabled_ch, dac->model_data->num_hw_channels) { - err =3D ad3552r_set_ch_value(dac, AD3552R_CH_AMPLIFIER_POWERDOWN, - ch, 1); + if (ch =3D=3D 0) + val =3D FIELD_PREP(AD3552R_MASK_CH_OUTPUT_RANGE_SEL(0), 1); + else + val =3D FIELD_PREP(AD3552R_MASK_CH_OUTPUT_RANGE_SEL(1), 1); + + err =3D ad3552r_update_reg_field(dac, + AD3552R_REG_ADDR_POWERDOWN_CONFIG, + AD3552R_MASK_CH_OUTPUT_RANGE_SEL(ch), + val); if (err) return err; } --=20 2.45.0.rc1 From nobody Fri Nov 29 12:47:58 2024 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 718DE19D081 for ; Thu, 19 Sep 2024 09:21:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737710; cv=none; b=sgip4iOml/Rc4nmm0Uix0bWcU0aKCfPV+yNSkSeeTLeaLUpIAplVV26v9Y4p2KouXC8VIrOCID9h0zLQJtoiC5YDuZeyur5ZsaHLxr4pTmY7/8d692epOnK9QLpMCQdfFErzRNwpK7YB3SUflq5GLv9wdIzQxOmpEuUz91b2wNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737710; c=relaxed/simple; bh=j8/N+q3xx0zo4ME80s1UUW0CIjYONFrl4UbHv7FAPvc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TEIlowjq1MrCDu0pvlLhKqbPQbZEGrWyS85vR24qF3dUYiko/5PhODAZoqUCRzbT7xcA8z0zCN5Biz7K1JshI7J/2I9d/vovHGBaWNLao0KUbjtw0F1bwD6A2GkD8Bcby8nH+/7squX+EyTvSPkfuPHmWOSYAG1SD69F44HEznY= 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=N8mkU/tw; arc=none smtp.client-ip=209.85.128.49 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="N8mkU/tw" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-42cbc22e1c4so4622485e9.2 for ; Thu, 19 Sep 2024 02:21:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726737706; x=1727342506; 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=jLx6yZmvlbO/p8tBmjqsRCI8Q1K0tY4FhoZVF6Xko+Q=; b=N8mkU/tw1u8dQISyFCCDES7b9Q6G7WYIu2iwt67S/I2DrrnYmRpuxsNsiLfbZfxfWZ Gf+e9urPTbx105AUs7dXu5+691R/O2/udpsj5uk9xGnF9KqPHBE84i/m7t/1Spzdg48O JAsfXoSne/SwCBxZorLXBI8YlHScGH0B+uzHFwNDrox2tVlDpmY6wLuHwNGvVKH5g2cp VnlZwofNNibkzeaVNxkXUUlphCFRor/P+Hot5jk2zTf4BTspZMhYp1x+8QL1elun04Og +UTY+DG4cEHEsPK7qYwqNpM5qn2QPJFfOF9AU0A2joaK+trnr8A5XJTHNxxlwvt/kq0X fbBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726737706; x=1727342506; 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=jLx6yZmvlbO/p8tBmjqsRCI8Q1K0tY4FhoZVF6Xko+Q=; b=wsLLYD5ZjDlmh3Gachy55VXXsGNQVQ8f0rPdBFGy3DF5MwSAfyRDKr89RCQ8Ue//2X KHiZruu8YOy6qdQDX92H+uqZe2NeE1YLIcNqlfYjntVB/ZUPQ9PC9/v1wxP7roMlyIDJ X9wSvdaDAZRDd4xSv8fvcbNIfbAQx3cVwh++LWXdkF5HaN1Als8QYdqYoOQc3t7jqGBI lHkd8qNJygIlW6p5hfiI9W8FUF/rUQ6Otbn5ZjDe5vmE9CF0LFulsG/n56n14KPFpLPJ p7UyTziiAYQVCLFDrwEQtKW7dtir7LUsFvQ6hGdJIoINMOxAA4IbUPHRAuyWlk/qO/j9 f0gQ== X-Forwarded-Encrypted: i=1; AJvYcCVenOW5dIY/zMHRDW7M1KZxUWTR0ur5Npf1ciiX7Dj4dep+etvZ0WGQQrK9PFJSQBzBUFykXZd46+jkf18=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1TPiv3i16hjaTPQ7BWI6BthWro8aMa03LU5NxroOQb0Nq1d+H 9COBs4xr2zxk7noTu6ZapDRf1rqZLc1CI7vE6zRwI1sP+jey5jiZY2MNl+H4thM= X-Google-Smtp-Source: AGHT+IGZ77pIyE+dpexdg0tka3oR9qQL39jb24X5E5JrxZ854Rym7DSXSTt7pp1iQFPh66pwKu+itg== X-Received: by 2002:a05:600c:1c9a:b0:428:1b0d:8657 with SMTP id 5b1f17b1804b1-42d964d8579mr150036645e9.22.1726737705582; Thu, 19 Sep 2024 02:21:45 -0700 (PDT) Received: from [127.0.1.1] (host-80-117-99-70.retail.telecomitalia.it. [80.117.99.70]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e75468413sm16889465e9.45.2024.09.19.02.21.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 02:21:45 -0700 (PDT) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Thu, 19 Sep 2024 11:20:04 +0200 Subject: [PATCH v3 08/10] iio: dac: ad3552r: extract common code (no changes in behavior intended) 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: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-8-a17b9b3d05d9@baylibre.com> References: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> In-Reply-To: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Nuno Sa , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Olivier Moysan Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dlechner@baylibre.com, Angelo Dureghello X-Mailer: b4 0.14.1 From: Angelo Dureghello Extracting common code, to share common code to be used later by the AXI driver version (ad3552r-axi.c). Signed-off-by: Angelo Dureghello --- drivers/iio/dac/Makefile | 2 +- drivers/iio/dac/ad3552r-common.c | 173 +++++++++++++++++++++++ drivers/iio/dac/ad3552r.c | 293 ++++-------------------------------= ---- drivers/iio/dac/ad3552r.h | 190 +++++++++++++++++++++++++ 4 files changed, 390 insertions(+), 268 deletions(-) diff --git a/drivers/iio/dac/Makefile b/drivers/iio/dac/Makefile index 2cf148f16306..56a125f56284 100644 --- a/drivers/iio/dac/Makefile +++ b/drivers/iio/dac/Makefile @@ -4,7 +4,7 @@ # =20 # When adding new entries keep the list in alphabetical order -obj-$(CONFIG_AD3552R) +=3D ad3552r.o +obj-$(CONFIG_AD3552R) +=3D ad3552r.o ad3552r-common.o obj-$(CONFIG_AD5360) +=3D ad5360.o obj-$(CONFIG_AD5380) +=3D ad5380.o obj-$(CONFIG_AD5421) +=3D ad5421.o diff --git a/drivers/iio/dac/ad3552r-common.c b/drivers/iio/dac/ad3552r-com= mon.c new file mode 100644 index 000000000000..624f3f97cdea --- /dev/null +++ b/drivers/iio/dac/ad3552r-common.c @@ -0,0 +1,173 @@ +// SPDX-License-Identifier: GPL-2.0+ +// +// Copyright (c) 2010-2024 Analog Devices Inc. +// Copyright (c) 2024 Baylibre, SAS + +#include +#include +#include +#include + +#include "ad3552r.h" + +const s32 ad3552r_ch_ranges[AD3552R_MAX_RANGES][2] =3D { + [AD3552R_CH_OUTPUT_RANGE_0__2P5V] =3D { 0, 2500 }, + [AD3552R_CH_OUTPUT_RANGE_0__5V] =3D { 0, 5000 }, + [AD3552R_CH_OUTPUT_RANGE_0__10V] =3D { 0, 10000 }, + [AD3552R_CH_OUTPUT_RANGE_NEG_5__5V] =3D { -5000, 5000 }, + [AD3552R_CH_OUTPUT_RANGE_NEG_10__10V] =3D { -10000, 10000 } +}; +EXPORT_SYMBOL(ad3552r_ch_ranges); + +const s32 ad3542r_ch_ranges[AD3542R_MAX_RANGES][2] =3D { + [AD3542R_CH_OUTPUT_RANGE_0__2P5V] =3D { 0, 2500 }, + [AD3542R_CH_OUTPUT_RANGE_0__3V] =3D { 0, 3000 }, + [AD3542R_CH_OUTPUT_RANGE_0__5V] =3D { 0, 5000 }, + [AD3542R_CH_OUTPUT_RANGE_0__10V] =3D { 0, 10000 }, + [AD3542R_CH_OUTPUT_RANGE_NEG_2P5__7P5V] =3D { -2500, 7500 }, + [AD3542R_CH_OUTPUT_RANGE_NEG_5__5V] =3D { -5000, 5000 } +}; +EXPORT_SYMBOL(ad3542r_ch_ranges); + +u16 ad3552r_calc_custom_gain(u8 p, u8 n, s16 goffs) +{ + u16 reg; + + reg =3D FIELD_PREP(AD3552R_MASK_CH_RANGE_OVERRIDE, 1); + reg |=3D FIELD_PREP(AD3552R_MASK_CH_GAIN_SCALING_P, p); + reg |=3D FIELD_PREP(AD3552R_MASK_CH_GAIN_SCALING_N, n); + reg |=3D FIELD_PREP(AD3552R_MASK_CH_OFFSET_BIT_8, abs((s32)goffs) >> 8); + reg |=3D FIELD_PREP(AD3552R_MASK_CH_OFFSET_POLARITY, (s32)goffs < 0); + + return reg; +} + +int ad3552r_get_ref_voltage(struct device *dev) +{ + int voltage; + int delta =3D 100000; + + voltage =3D devm_regulator_get_enable_read_voltage(dev, "vref"); + if (voltage < 0 && voltage !=3D -ENODEV) + return dev_err_probe(dev, voltage, + "Error getting vref voltage\n"); + + if (voltage =3D=3D -ENODEV) { + if (device_property_read_bool(dev, "adi,vref-out-en")) + return AD3552R_INTERNAL_VREF_PIN_2P5V; + else + return AD3552R_INTERNAL_VREF_PIN_FLOATING; + } + + if (voltage > 2500000 + delta || voltage < 2500000 - delta) { + dev_warn(dev, "vref-supply must be 2.5V"); + return -EINVAL; + } + + return AD3552R_EXTERNAL_VREF_PIN_INPUT; +} + +int ad3552r_get_drive_strength(struct device *dev, u32 *val) +{ + int err; + + err =3D device_property_read_u32(dev, "adi,sdo-drive-strength", val); + if (err) + return err; + + if (*val > 3) { + dev_err(dev, + "adi,sdo-drive-strength must be less than 4\n"); + return -EINVAL; + } + + return 0; +} + +int ad3552r_get_custom_gain(struct device *dev, struct fwnode_handle *chil= d, + u8 *gs_p, u8 *gs_n, u16 *rfb, s16 *goffs) +{ + int err; + u32 val; + struct fwnode_handle *gain_child __free(fwnode_handle) =3D + fwnode_get_named_child_node(child, + "custom-output-range-config"); + + if (!gain_child) + return dev_err_probe(dev, -EINVAL, + "custom-output-range-config mandatory\n"); + + err =3D fwnode_property_read_u32(gain_child, "adi,gain-scaling-p", &val); + if (err) + return dev_err_probe(dev, err, + "adi,gain-scaling-p mandatory\n"); + *gs_p =3D val; + + err =3D fwnode_property_read_u32(gain_child, "adi,gain-scaling-n", &val); + if (err) + return dev_err_probe(dev, err, + "adi,gain-scaling-n property mandatory\n"); + *gs_n =3D val; + + err =3D fwnode_property_read_u32(gain_child, "adi,rfb-ohms", &val); + if (err) + return dev_err_probe(dev, err, + "adi,rfb-ohms mandatory\n"); + *rfb =3D val; + + err =3D fwnode_property_read_u32(gain_child, "adi,gain-offset", &val); + if (err) + return dev_err_probe(dev, err, + "adi,gain-offset mandatory\n"); + *goffs =3D val; + + return 0; +} + +static int ad3552r_find_range(u16 id, s32 *vals) +{ + int i, len; + const s32 (*ranges)[2]; + + if (id =3D=3D AD3542R_ID) { + len =3D ARRAY_SIZE(ad3542r_ch_ranges); + ranges =3D ad3542r_ch_ranges; + } else { + len =3D ARRAY_SIZE(ad3552r_ch_ranges); + ranges =3D ad3552r_ch_ranges; + } + + for (i =3D 0; i < len; i++) + if (vals[0] =3D=3D ranges[i][0] * 1000 && + vals[1] =3D=3D ranges[i][1] * 1000) + return i; + + return -EINVAL; +} + +int ad3552r_get_output_range(struct device *dev, enum ad3552r_id chip_id, + struct fwnode_handle *child, u32 *val) +{ + int ret; + s32 vals[2]; + + /* This property is optional, so returning -ENOENT if missing */ + if (!fwnode_property_present(child, "adi,output-range-microvolt")) + return -ENOENT; + + ret =3D fwnode_property_read_u32_array(child, + "adi,output-range-microvolt", + vals, 2); + if (ret) + return dev_err_probe(dev, ret, + "invalid adi,output-range-microvolt\n"); + + ret =3D ad3552r_find_range(chip_id, vals); + if (ret < 0) + return dev_err_probe(dev, ret, + "invalid adi,output-range-microvolt value\n"); + + *val =3D ret; + + return 0; +} diff --git a/drivers/iio/dac/ad3552r.c b/drivers/iio/dac/ad3552r.c index c27706c5ba10..173282e5e1a1 100644 --- a/drivers/iio/dac/ad3552r.c +++ b/drivers/iio/dac/ad3552r.c @@ -11,185 +11,9 @@ #include #include #include -#include #include =20 -/* Register addresses */ -/* Primary address space */ -#define AD3552R_REG_ADDR_INTERFACE_CONFIG_A 0x00 -#define AD3552R_MASK_SOFTWARE_RESET (BIT(7) | BIT(0)) -#define AD3552R_MASK_ADDR_ASCENSION BIT(5) -#define AD3552R_MASK_SDO_ACTIVE BIT(4) -#define AD3552R_REG_ADDR_INTERFACE_CONFIG_B 0x01 -#define AD3552R_MASK_SINGLE_INST BIT(7) -#define AD3552R_MASK_SHORT_INSTRUCTION BIT(3) -#define AD3552R_REG_ADDR_DEVICE_CONFIG 0x02 -#define AD3552R_MASK_DEVICE_STATUS(n) BIT(4 + (n)) -#define AD3552R_MASK_CUSTOM_MODES GENMASK(3, 2) -#define AD3552R_MASK_OPERATING_MODES GENMASK(1, 0) -#define AD3552R_REG_ADDR_CHIP_TYPE 0x03 -#define AD3552R_MASK_CLASS GENMASK(7, 0) -#define AD3552R_REG_ADDR_PRODUCT_ID_L 0x04 -#define AD3552R_REG_ADDR_PRODUCT_ID_H 0x05 -#define AD3552R_REG_ADDR_CHIP_GRADE 0x06 -#define AD3552R_MASK_GRADE GENMASK(7, 4) -#define AD3552R_MASK_DEVICE_REVISION GENMASK(3, 0) -#define AD3552R_REG_ADDR_SCRATCH_PAD 0x0A -#define AD3552R_REG_ADDR_SPI_REVISION 0x0B -#define AD3552R_REG_ADDR_VENDOR_L 0x0C -#define AD3552R_REG_ADDR_VENDOR_H 0x0D -#define AD3552R_REG_ADDR_STREAM_MODE 0x0E -#define AD3552R_MASK_LENGTH GENMASK(7, 0) -#define AD3552R_REG_ADDR_TRANSFER_REGISTER 0x0F -#define AD3552R_MASK_MULTI_IO_MODE GENMASK(7, 6) -#define AD3552R_MASK_STREAM_LENGTH_KEEP_VALUE BIT(2) -#define AD3552R_REG_ADDR_INTERFACE_CONFIG_C 0x10 -#define AD3552R_MASK_CRC_ENABLE (GENMASK(7, 6) |\ - GENMASK(1, 0)) -#define AD3552R_MASK_STRICT_REGISTER_ACCESS BIT(5) -#define AD3552R_REG_ADDR_INTERFACE_STATUS_A 0x11 -#define AD3552R_MASK_INTERFACE_NOT_READY BIT(7) -#define AD3552R_MASK_CLOCK_COUNTING_ERROR BIT(5) -#define AD3552R_MASK_INVALID_OR_NO_CRC BIT(3) -#define AD3552R_MASK_WRITE_TO_READ_ONLY_REGISTER BIT(2) -#define AD3552R_MASK_PARTIAL_REGISTER_ACCESS BIT(1) -#define AD3552R_MASK_REGISTER_ADDRESS_INVALID BIT(0) -#define AD3552R_REG_ADDR_INTERFACE_CONFIG_D 0x14 -#define AD3552R_MASK_ALERT_ENABLE_PULLUP BIT(6) -#define AD3552R_MASK_MEM_CRC_EN BIT(4) -#define AD3552R_MASK_SDO_DRIVE_STRENGTH GENMASK(3, 2) -#define AD3552R_MASK_DUAL_SPI_SYNCHROUNOUS_EN BIT(1) -#define AD3552R_MASK_SPI_CONFIG_DDR BIT(0) -#define AD3552R_REG_ADDR_SH_REFERENCE_CONFIG 0x15 -#define AD3552R_MASK_IDUMP_FAST_MODE BIT(6) -#define AD3552R_MASK_SAMPLE_HOLD_DIFFERENTIAL_USER_EN BIT(5) -#define AD3552R_MASK_SAMPLE_HOLD_USER_TRIM GENMASK(4, 3) -#define AD3552R_MASK_SAMPLE_HOLD_USER_ENABLE BIT(2) -#define AD3552R_MASK_REFERENCE_VOLTAGE_SEL GENMASK(1, 0) -#define AD3552R_REG_ADDR_ERR_ALARM_MASK 0x16 -#define AD3552R_MASK_REF_RANGE_ALARM BIT(6) -#define AD3552R_MASK_CLOCK_COUNT_ERR_ALARM BIT(5) -#define AD3552R_MASK_MEM_CRC_ERR_ALARM BIT(4) -#define AD3552R_MASK_SPI_CRC_ERR_ALARM BIT(3) -#define AD3552R_MASK_WRITE_TO_READ_ONLY_ALARM BIT(2) -#define AD3552R_MASK_PARTIAL_REGISTER_ACCESS_ALARM BIT(1) -#define AD3552R_MASK_REGISTER_ADDRESS_INVALID_ALARM BIT(0) -#define AD3552R_REG_ADDR_ERR_STATUS 0x17 -#define AD3552R_MASK_REF_RANGE_ERR_STATUS BIT(6) -#define AD3552R_MASK_DUAL_SPI_STREAM_EXCEEDS_DAC_ERR_STATUS BIT(5) -#define AD3552R_MASK_MEM_CRC_ERR_STATUS BIT(4) -#define AD3552R_MASK_RESET_STATUS BIT(0) -#define AD3552R_REG_ADDR_POWERDOWN_CONFIG 0x18 -#define AD3552R_MASK_CH_DAC_POWERDOWN(ch) BIT(4 + (ch)) -#define AD3552R_MASK_CH_AMPLIFIER_POWERDOWN(ch) BIT(ch) -#define AD3552R_REG_ADDR_CH0_CH1_OUTPUT_RANGE 0x19 -#define AD3552R_MASK_CH_OUTPUT_RANGE_SEL(ch) ((ch) ? GENMASK(7, 4) :\ - GENMASK(3, 0)) -#define AD3552R_REG_ADDR_CH_OFFSET(ch) (0x1B + (ch) * 2) -#define AD3552R_MASK_CH_OFFSET_BITS_0_7 GENMASK(7, 0) -#define AD3552R_REG_ADDR_CH_GAIN(ch) (0x1C + (ch) * 2) -#define AD3552R_MASK_CH_RANGE_OVERRIDE BIT(7) -#define AD3552R_MASK_CH_GAIN_SCALING_N GENMASK(6, 5) -#define AD3552R_MASK_CH_GAIN_SCALING_P GENMASK(4, 3) -#define AD3552R_MASK_CH_OFFSET_POLARITY BIT(2) -#define AD3552R_MASK_CH_OFFSET_BIT_8 BIT(0) -/* - * Secondary region - * For multibyte registers specify the highest address because the access = is - * done in descending order - */ -#define AD3552R_SECONDARY_REGION_START 0x28 -#define AD3552R_REG_ADDR_HW_LDAC_16B 0x28 -#define AD3552R_REG_ADDR_CH_DAC_16B(ch) (0x2C - (1 - ch) * 2) -#define AD3552R_REG_ADDR_DAC_PAGE_MASK_16B 0x2E -#define AD3552R_REG_ADDR_CH_SELECT_16B 0x2F -#define AD3552R_REG_ADDR_INPUT_PAGE_MASK_16B 0x31 -#define AD3552R_REG_ADDR_SW_LDAC_16B 0x32 -#define AD3552R_REG_ADDR_CH_INPUT_16B(ch) (0x36 - (1 - ch) * 2) -/* 3 bytes registers */ -#define AD3552R_REG_START_24B 0x37 -#define AD3552R_REG_ADDR_HW_LDAC_24B 0x37 -#define AD3552R_REG_ADDR_CH_DAC_24B(ch) (0x3D - (1 - ch) * 3) -#define AD3552R_REG_ADDR_DAC_PAGE_MASK_24B 0x40 -#define AD3552R_REG_ADDR_CH_SELECT_24B 0x41 -#define AD3552R_REG_ADDR_INPUT_PAGE_MASK_24B 0x44 -#define AD3552R_REG_ADDR_SW_LDAC_24B 0x45 -#define AD3552R_REG_ADDR_CH_INPUT_24B(ch) (0x4B - (1 - ch) * 3) - -/* Useful defines */ -#define AD3552R_MAX_CH 2 -#define AD3552R_MASK_CH(ch) BIT(ch) -#define AD3552R_MASK_ALL_CH GENMASK(1, 0) -#define AD3552R_MAX_REG_SIZE 3 -#define AD3552R_READ_BIT BIT(7) -#define AD3552R_ADDR_MASK GENMASK(6, 0) -#define AD3552R_MASK_DAC_12B 0xFFF0 -#define AD3552R_DEFAULT_CONFIG_B_VALUE 0x8 -#define AD3552R_SCRATCH_PAD_TEST_VAL1 0x34 -#define AD3552R_SCRATCH_PAD_TEST_VAL2 0xB2 -#define AD3552R_GAIN_SCALE 1000 -#define AD3552R_LDAC_PULSE_US 100 - -enum ad3552r_ch_vref_select { - /* Internal source with Vref I/O floating */ - AD3552R_INTERNAL_VREF_PIN_FLOATING, - /* Internal source with Vref I/O at 2.5V */ - AD3552R_INTERNAL_VREF_PIN_2P5V, - /* External source with Vref I/O as input */ - AD3552R_EXTERNAL_VREF_PIN_INPUT -}; - -enum ad3552r_id { - AD3541R_ID =3D 0x400b, - AD3542R_ID =3D 0x4009, - AD3551R_ID =3D 0x400a, - AD3552R_ID =3D 0x4008, -}; - -enum ad3552r_ch_output_range { - /* Range from 0 V to 2.5 V. Requires Rfb1x connection */ - AD3552R_CH_OUTPUT_RANGE_0__2P5V, - /* Range from 0 V to 5 V. Requires Rfb1x connection */ - AD3552R_CH_OUTPUT_RANGE_0__5V, - /* Range from 0 V to 10 V. Requires Rfb2x connection */ - AD3552R_CH_OUTPUT_RANGE_0__10V, - /* Range from -5 V to 5 V. Requires Rfb2x connection */ - AD3552R_CH_OUTPUT_RANGE_NEG_5__5V, - /* Range from -10 V to 10 V. Requires Rfb4x connection */ - AD3552R_CH_OUTPUT_RANGE_NEG_10__10V, -}; - -static const s32 ad3552r_ch_ranges[][2] =3D { - [AD3552R_CH_OUTPUT_RANGE_0__2P5V] =3D {0, 2500}, - [AD3552R_CH_OUTPUT_RANGE_0__5V] =3D {0, 5000}, - [AD3552R_CH_OUTPUT_RANGE_0__10V] =3D {0, 10000}, - [AD3552R_CH_OUTPUT_RANGE_NEG_5__5V] =3D {-5000, 5000}, - [AD3552R_CH_OUTPUT_RANGE_NEG_10__10V] =3D {-10000, 10000} -}; - -enum ad3542r_ch_output_range { - /* Range from 0 V to 2.5 V. Requires Rfb1x connection */ - AD3542R_CH_OUTPUT_RANGE_0__2P5V, - /* Range from 0 V to 3 V. Requires Rfb1x connection */ - AD3542R_CH_OUTPUT_RANGE_0__3V, - /* Range from 0 V to 5 V. Requires Rfb1x connection */ - AD3542R_CH_OUTPUT_RANGE_0__5V, - /* Range from 0 V to 10 V. Requires Rfb2x connection */ - AD3542R_CH_OUTPUT_RANGE_0__10V, - /* Range from -2.5 V to 7.5 V. Requires Rfb2x connection */ - AD3542R_CH_OUTPUT_RANGE_NEG_2P5__7P5V, - /* Range from -5 V to 5 V. Requires Rfb2x connection */ - AD3542R_CH_OUTPUT_RANGE_NEG_5__5V, -}; - -static const s32 ad3542r_ch_ranges[][2] =3D { - [AD3542R_CH_OUTPUT_RANGE_0__2P5V] =3D {0, 2500}, - [AD3542R_CH_OUTPUT_RANGE_0__3V] =3D {0, 3000}, - [AD3542R_CH_OUTPUT_RANGE_0__5V] =3D {0, 5000}, - [AD3542R_CH_OUTPUT_RANGE_0__10V] =3D {0, 10000}, - [AD3542R_CH_OUTPUT_RANGE_NEG_2P5__7P5V] =3D {-2500, 7500}, - [AD3542R_CH_OUTPUT_RANGE_NEG_5__5V] =3D {-5000, 5000} -}; +#include "ad3552r.h" =20 enum ad3552r_ch_gain_scaling { /* Gain scaling of 1 */ @@ -693,75 +517,35 @@ static void ad3552r_calc_gain_and_offset(struct ad355= 2r_desc *dac, s32 ch) dac->ch_data[ch].offset_dec =3D div_s64(tmp, span); } =20 -static int ad3552r_find_range(const struct ad3552r_model_data *model_data, - s32 *vals) -{ - int i; - - for (i =3D 0; i < model_data->num_ranges; i++) - if (vals[0] =3D=3D model_data->ranges_table[i][0] * 1000 && - vals[1] =3D=3D model_data->ranges_table[i][1] * 1000) - return i; - - return -EINVAL; -} - static int ad3552r_configure_custom_gain(struct ad3552r_desc *dac, struct fwnode_handle *child, u32 ch) { struct device *dev =3D &dac->spi->dev; - u32 val; int err; u8 addr; - u16 reg =3D 0, offset; - - struct fwnode_handle *gain_child __free(fwnode_handle) - =3D fwnode_get_named_child_node(child, - "custom-output-range-config"); - if (!gain_child) - return dev_err_probe(dev, -EINVAL, - "mandatory custom-output-range-config property missing\n"); - - dac->ch_data[ch].range_override =3D 1; - reg |=3D FIELD_PREP(AD3552R_MASK_CH_RANGE_OVERRIDE, 1); - - err =3D fwnode_property_read_u32(gain_child, "adi,gain-scaling-p", &val); - if (err) - return dev_err_probe(dev, err, - "mandatory adi,gain-scaling-p property missing\n"); - reg |=3D FIELD_PREP(AD3552R_MASK_CH_GAIN_SCALING_P, val); - dac->ch_data[ch].p =3D val; - - err =3D fwnode_property_read_u32(gain_child, "adi,gain-scaling-n", &val); - if (err) - return dev_err_probe(dev, err, - "mandatory adi,gain-scaling-n property missing\n"); - reg |=3D FIELD_PREP(AD3552R_MASK_CH_GAIN_SCALING_N, val); - dac->ch_data[ch].n =3D val; - - err =3D fwnode_property_read_u32(gain_child, "adi,rfb-ohms", &val); - if (err) - return dev_err_probe(dev, err, - "mandatory adi,rfb-ohms property missing\n"); - dac->ch_data[ch].rfb =3D val; + u16 reg; =20 - err =3D fwnode_property_read_u32(gain_child, "adi,gain-offset", &val); + err =3D ad3552r_get_custom_gain(dev, child, + &dac->ch_data[ch].p, + &dac->ch_data[ch].n, + &dac->ch_data[ch].rfb, + &dac->ch_data[ch].gain_offset); if (err) - return dev_err_probe(dev, err, - "mandatory adi,gain-offset property missing\n"); - dac->ch_data[ch].gain_offset =3D val; + return err; =20 - offset =3D abs((s32)val); - reg |=3D FIELD_PREP(AD3552R_MASK_CH_OFFSET_BIT_8, (offset >> 8)); + dac->ch_data[ch].range_override =3D 1; =20 - reg |=3D FIELD_PREP(AD3552R_MASK_CH_OFFSET_POLARITY, (s32)val < 0); addr =3D AD3552R_REG_ADDR_CH_GAIN(ch); err =3D ad3552r_write_reg(dac, addr, - offset & AD3552R_MASK_CH_OFFSET_BITS_0_7); + abs((s32)dac->ch_data[ch].gain_offset) & + AD3552R_MASK_CH_OFFSET_BITS_0_7); if (err) return dev_err_probe(dev, err, "Error writing register\n"); =20 + reg =3D ad3552r_calc_custom_gain(dac->ch_data[ch].p, dac->ch_data[ch].n, + dac->ch_data[ch].gain_offset); + err =3D ad3552r_write_reg(dac, addr, reg); if (err) return dev_err_probe(dev, err, "Error writing register\n"); @@ -772,30 +556,19 @@ static int ad3552r_configure_custom_gain(struct ad355= 2r_desc *dac, static int ad3552r_configure_device(struct ad3552r_desc *dac) { struct device *dev =3D &dac->spi->dev; - int err, cnt =3D 0, voltage, delta =3D 100000; - u32 vals[2], val, ch; + int err, cnt =3D 0; + u32 val, ch; =20 dac->gpio_ldac =3D devm_gpiod_get_optional(dev, "ldac", GPIOD_OUT_HIGH); if (IS_ERR(dac->gpio_ldac)) return dev_err_probe(dev, PTR_ERR(dac->gpio_ldac), "Error getting gpio ldac"); =20 - voltage =3D devm_regulator_get_enable_read_voltage(dev, "vref"); - if (voltage < 0 && voltage !=3D -ENODEV) - return dev_err_probe(dev, voltage, "Error getting vref voltage\n"); + err =3D ad3552r_get_ref_voltage(dev); + if (err < 0) + return err; =20 - if (voltage =3D=3D -ENODEV) { - if (device_property_read_bool(dev, "adi,vref-out-en")) - val =3D AD3552R_INTERNAL_VREF_PIN_2P5V; - else - val =3D AD3552R_INTERNAL_VREF_PIN_FLOATING; - } else { - if (voltage > 2500000 + delta || voltage < 2500000 - delta) { - dev_warn(dev, "vref-supply must be 2.5V"); - return -EINVAL; - } - val =3D AD3552R_EXTERNAL_VREF_PIN_INPUT; - } + val =3D err; =20 err =3D ad3552r_update_reg_field(dac, AD3552R_REG_ADDR_SH_REFERENCE_CONFIG, @@ -804,13 +577,8 @@ static int ad3552r_configure_device(struct ad3552r_des= c *dac) if (err) return err; =20 - err =3D device_property_read_u32(dev, "adi,sdo-drive-strength", &val); + err =3D ad3552r_get_drive_strength(dev, &val); if (!err) { - if (val > 3) { - dev_err(dev, "adi,sdo-drive-strength must be less than 4\n"); - return -EINVAL; - } - err =3D ad3552r_update_reg_field(dac, AD3552R_REG_ADDR_INTERFACE_CONFIG_D, AD3552R_MASK_SDO_DRIVE_STRENGTH, @@ -835,21 +603,12 @@ static int ad3552r_configure_device(struct ad3552r_de= sc *dac) "reg must be less than %d\n", dac->model_data->num_hw_channels); =20 - if (fwnode_property_present(child, "adi,output-range-microvolt")) { - err =3D fwnode_property_read_u32_array(child, - "adi,output-range-microvolt", - vals, - 2); - if (err) - return dev_err_probe(dev, err, - "adi,output-range-microvolt property could not be parsed\n"); - - err =3D ad3552r_find_range(dac->model_data, vals); - if (err < 0) - return dev_err_probe(dev, err, - "Invalid adi,output-range-microvolt value\n"); + err =3D ad3552r_get_output_range(dev, dac->model_data->chip_id, + child, &val); + if (err && err !=3D -ENOENT) + return err; =20 - val =3D err; + if (!err) { if (ch =3D=3D 0) val =3D FIELD_PREP(AD3552R_MASK_CH_OUTPUT_RANGE_SEL(0), val); else diff --git a/drivers/iio/dac/ad3552r.h b/drivers/iio/dac/ad3552r.h new file mode 100644 index 000000000000..b1caa3c3e807 --- /dev/null +++ b/drivers/iio/dac/ad3552r.h @@ -0,0 +1,190 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * AD3552R Digital <-> Analog converters common header + * + * Copyright 2021-2024 Analog Devices Inc. + * Author: Angelo Dureghello + */ + +#ifndef __DRIVERS_IIO_DAC_AD3552R_H__ +#define __DRIVERS_IIO_DAC_AD3552R_H__ + +/* Register addresses */ +/* Primary address space */ +#define AD3552R_REG_ADDR_INTERFACE_CONFIG_A 0x00 +#define AD3552R_MASK_SOFTWARE_RESET (BIT(7) | BIT(0)) +#define AD3552R_MASK_ADDR_ASCENSION BIT(5) +#define AD3552R_MASK_SDO_ACTIVE BIT(4) +#define AD3552R_REG_ADDR_INTERFACE_CONFIG_B 0x01 +#define AD3552R_MASK_SINGLE_INST BIT(7) +#define AD3552R_MASK_SHORT_INSTRUCTION BIT(3) +#define AD3552R_REG_ADDR_DEVICE_CONFIG 0x02 +#define AD3552R_MASK_DEVICE_STATUS(n) BIT(4 + (n)) +#define AD3552R_MASK_CUSTOM_MODES GENMASK(3, 2) +#define AD3552R_MASK_OPERATING_MODES GENMASK(1, 0) +#define AD3552R_REG_ADDR_CHIP_TYPE 0x03 +#define AD3552R_MASK_CLASS GENMASK(7, 0) +#define AD3552R_REG_ADDR_PRODUCT_ID_L 0x04 +#define AD3552R_REG_ADDR_PRODUCT_ID_H 0x05 +#define AD3552R_REG_ADDR_CHIP_GRADE 0x06 +#define AD3552R_MASK_GRADE GENMASK(7, 4) +#define AD3552R_MASK_DEVICE_REVISION GENMASK(3, 0) +#define AD3552R_REG_ADDR_SCRATCH_PAD 0x0A +#define AD3552R_REG_ADDR_SPI_REVISION 0x0B +#define AD3552R_REG_ADDR_VENDOR_L 0x0C +#define AD3552R_REG_ADDR_VENDOR_H 0x0D +#define AD3552R_REG_ADDR_STREAM_MODE 0x0E +#define AD3552R_MASK_LENGTH GENMASK(7, 0) +#define AD3552R_REG_ADDR_TRANSFER_REGISTER 0x0F +#define AD3552R_MASK_MULTI_IO_MODE GENMASK(7, 6) +#define AD3552R_MASK_STREAM_LENGTH_KEEP_VALUE BIT(2) +#define AD3552R_REG_ADDR_INTERFACE_CONFIG_C 0x10 +#define AD3552R_MASK_CRC_ENABLE (GENMASK(7, 6) |\ + GENMASK(1, 0)) +#define AD3552R_MASK_STRICT_REGISTER_ACCESS BIT(5) +#define AD3552R_REG_ADDR_INTERFACE_STATUS_A 0x11 +#define AD3552R_MASK_INTERFACE_NOT_READY BIT(7) +#define AD3552R_MASK_CLOCK_COUNTING_ERROR BIT(5) +#define AD3552R_MASK_INVALID_OR_NO_CRC BIT(3) +#define AD3552R_MASK_WRITE_TO_READ_ONLY_REGISTER BIT(2) +#define AD3552R_MASK_PARTIAL_REGISTER_ACCESS BIT(1) +#define AD3552R_MASK_REGISTER_ADDRESS_INVALID BIT(0) +#define AD3552R_REG_ADDR_INTERFACE_CONFIG_D 0x14 +#define AD3552R_MASK_ALERT_ENABLE_PULLUP BIT(6) +#define AD3552R_MASK_MEM_CRC_EN BIT(4) +#define AD3552R_MASK_SDO_DRIVE_STRENGTH GENMASK(3, 2) +#define AD3552R_MASK_DUAL_SPI_SYNCHROUNOUS_EN BIT(1) +#define AD3552R_MASK_SPI_CONFIG_DDR BIT(0) +#define AD3552R_REG_ADDR_SH_REFERENCE_CONFIG 0x15 +#define AD3552R_MASK_IDUMP_FAST_MODE BIT(6) +#define AD3552R_MASK_SAMPLE_HOLD_DIFF_USER_EN BIT(5) +#define AD3552R_MASK_SAMPLE_HOLD_USER_TRIM GENMASK(4, 3) +#define AD3552R_MASK_SAMPLE_HOLD_USER_ENABLE BIT(2) +#define AD3552R_MASK_REFERENCE_VOLTAGE_SEL GENMASK(1, 0) +#define AD3552R_REG_ADDR_ERR_ALARM_MASK 0x16 +#define AD3552R_MASK_REF_RANGE_ALARM BIT(6) +#define AD3552R_MASK_CLOCK_COUNT_ERR_ALARM BIT(5) +#define AD3552R_MASK_MEM_CRC_ERR_ALARM BIT(4) +#define AD3552R_MASK_SPI_CRC_ERR_ALARM BIT(3) +#define AD3552R_MASK_WRITE_TO_READ_ONLY_ALARM BIT(2) +#define AD3552R_MASK_PARTIAL_REGISTER_ACCESS_ALARM BIT(1) +#define AD3552R_MASK_REGISTER_ADDRESS_INVALID_ALARM BIT(0) +#define AD3552R_REG_ADDR_ERR_STATUS 0x17 +#define AD3552R_MASK_REF_RANGE_ERR_STATUS BIT(6) +#define AD3552R_MASK_STREAM_EXCEEDS_DAC_ERR_STATUS BIT(5) +#define AD3552R_MASK_MEM_CRC_ERR_STATUS BIT(4) +#define AD3552R_MASK_RESET_STATUS BIT(0) +#define AD3552R_REG_ADDR_POWERDOWN_CONFIG 0x18 +#define AD3552R_MASK_CH_DAC_POWERDOWN(ch) BIT(4 + (ch)) +#define AD3552R_MASK_CH_AMPLIFIER_POWERDOWN(ch) BIT(ch) +#define AD3552R_REG_ADDR_CH0_CH1_OUTPUT_RANGE 0x19 +#define AD3552R_MASK_CH0_RANGE GENMASK(2, 0) +#define AD3552R_MASK_CH1_RANGE GENMASK(6, 4) +#define AD3552R_MASK_CH_OUTPUT_RANGE GENMASK(7, 0) +#define AD3552R_MASK_CH_OUTPUT_RANGE_SEL(ch) ((ch) ? \ + GENMASK(7, 4) : \ + GENMASK(3, 0)) +#define AD3552R_REG_ADDR_CH_OFFSET(ch) (0x1B + (ch) * 2) +#define AD3552R_MASK_CH_OFFSET_BITS_0_7 GENMASK(7, 0) +#define AD3552R_REG_ADDR_CH_GAIN(ch) (0x1C + (ch) * 2) +#define AD3552R_MASK_CH_RANGE_OVERRIDE BIT(7) +#define AD3552R_MASK_CH_GAIN_SCALING_N GENMASK(6, 5) +#define AD3552R_MASK_CH_GAIN_SCALING_P GENMASK(4, 3) +#define AD3552R_MASK_CH_OFFSET_POLARITY BIT(2) +#define AD3552R_MASK_CH_OFFSET_BIT_8 BIT(0) +/* + * Secondary region + * For multibyte registers specify the highest address because the access = is + * done in descending order + */ +#define AD3552R_SECONDARY_REGION_START 0x28 +#define AD3552R_REG_ADDR_HW_LDAC_16B 0x28 +#define AD3552R_REG_ADDR_CH_DAC_16B(ch) (0x2C - (1 - (ch)) * 2) +#define AD3552R_REG_ADDR_DAC_PAGE_MASK_16B 0x2E +#define AD3552R_REG_ADDR_CH_SELECT_16B 0x2F +#define AD3552R_REG_ADDR_INPUT_PAGE_MASK_16B 0x31 +#define AD3552R_REG_ADDR_SW_LDAC_16B 0x32 +#define AD3552R_REG_ADDR_CH_INPUT_16B(ch) (0x36 - (1 - (ch)) * 2) +/* 3 bytes registers */ +#define AD3552R_REG_START_24B 0x37 +#define AD3552R_REG_ADDR_HW_LDAC_24B 0x37 +#define AD3552R_REG_ADDR_CH_DAC_24B(ch) (0x3D - (1 - (ch)) * 3) +#define AD3552R_REG_ADDR_DAC_PAGE_MASK_24B 0x40 +#define AD3552R_REG_ADDR_CH_SELECT_24B 0x41 +#define AD3552R_REG_ADDR_INPUT_PAGE_MASK_24B 0x44 +#define AD3552R_REG_ADDR_SW_LDAC_24B 0x45 +#define AD3552R_REG_ADDR_CH_INPUT_24B(ch) (0x4B - (1 - (ch)) * 3) + +/* Useful defines */ +#define AD3552R_MAX_CH 2 +#define AD3552R_MASK_CH(ch) BIT(ch) +#define AD3552R_MASK_ALL_CH GENMASK(1, 0) +#define AD3552R_MAX_REG_SIZE 3 +#define AD3552R_READ_BIT BIT(7) +#define AD3552R_ADDR_MASK GENMASK(6, 0) +#define AD3552R_MASK_DAC_12B GENMASK(15, 4) +#define AD3552R_DEFAULT_CONFIG_B_VALUE 0x8 +#define AD3552R_SCRATCH_PAD_TEST_VAL1 0x34 +#define AD3552R_SCRATCH_PAD_TEST_VAL2 0xB2 +#define AD3552R_GAIN_SCALE 1000 +#define AD3552R_LDAC_PULSE_US 100 + +#define AD3552R_MAX_RANGES 5 +#define AD3542R_MAX_RANGES 6 + +extern const s32 ad3552r_ch_ranges[AD3552R_MAX_RANGES][2]; +extern const s32 ad3542r_ch_ranges[AD3542R_MAX_RANGES][2]; + +enum ad3552r_id { + AD3541R_ID =3D 0x400b, + AD3542R_ID =3D 0x4009, + AD3551R_ID =3D 0x400a, + AD3552R_ID =3D 0x4008, +}; + +enum ad3552r_ch_vref_select { + /* Internal source with Vref I/O floating */ + AD3552R_INTERNAL_VREF_PIN_FLOATING, + /* Internal source with Vref I/O at 2.5V */ + AD3552R_INTERNAL_VREF_PIN_2P5V, + /* External source with Vref I/O as input */ + AD3552R_EXTERNAL_VREF_PIN_INPUT +}; + +enum ad3542r_ch_output_range { + /* Range from 0 V to 2.5 V. Requires Rfb1x connection */ + AD3542R_CH_OUTPUT_RANGE_0__2P5V, + /* Range from 0 V to 3 V. Requires Rfb1x connection */ + AD3542R_CH_OUTPUT_RANGE_0__3V, + /* Range from 0 V to 5 V. Requires Rfb1x connection */ + AD3542R_CH_OUTPUT_RANGE_0__5V, + /* Range from 0 V to 10 V. Requires Rfb2x connection */ + AD3542R_CH_OUTPUT_RANGE_0__10V, + /* Range from -2.5 V to 7.5 V. Requires Rfb2x connection */ + AD3542R_CH_OUTPUT_RANGE_NEG_2P5__7P5V, + /* Range from -5 V to 5 V. Requires Rfb2x connection */ + AD3542R_CH_OUTPUT_RANGE_NEG_5__5V, +}; + +enum ad3552r_ch_output_range { + /* Range from 0 V to 2.5 V. Requires Rfb1x connection */ + AD3552R_CH_OUTPUT_RANGE_0__2P5V, + /* Range from 0 V to 5 V. Requires Rfb1x connection */ + AD3552R_CH_OUTPUT_RANGE_0__5V, + /* Range from 0 V to 10 V. Requires Rfb2x connection */ + AD3552R_CH_OUTPUT_RANGE_0__10V, + /* Range from -5 V to 5 V. Requires Rfb2x connection */ + AD3552R_CH_OUTPUT_RANGE_NEG_5__5V, + /* Range from -10 V to 10 V. Requires Rfb4x connection */ + AD3552R_CH_OUTPUT_RANGE_NEG_10__10V, +}; + +int ad3552r_get_output_range(struct device *dev, enum ad3552r_id id, + struct fwnode_handle *child, u32 *val); +int ad3552r_get_custom_gain(struct device *dev, struct fwnode_handle *chil= d, + u8 *gs_p, u8 *gs_n, u16 *rfb, s16 *goffs); +u16 ad3552r_calc_custom_gain(u8 p, u8 n, s16 goffs); +int ad3552r_get_ref_voltage(struct device *dev); +int ad3552r_get_drive_strength(struct device *dev, u32 *val); + +#endif /* __DRIVERS_IIO_DAC_AD3552R_H__ */ --=20 2.45.0.rc1 From nobody Fri Nov 29 12:47:58 2024 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 2868019D880 for ; Thu, 19 Sep 2024 09:21:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737711; cv=none; b=F93E9zIIkQR7W3Jb6B4CJ3f7LGUsZfkYJCWhFBnWZKGlFMYSYXoMFej9U+7iNFPWYWWNkpYp5p5/tV33TgIFxXfQDBzp+2p6mBWbTub8tyqSG8iKkeJirvljyQ+iOKkCPP8faLknt6x2R21F3X9SaazOaRQNleWtGML6ROazZB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737711; c=relaxed/simple; bh=dxIuSgsLljoogbghKvOdfLgQnWZp85dbsjJTAeiDw00=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jQFEt7i2Qe22hWMRSQxCNal60qRLRZ9MtsCYwl2BzSGSPR4AJ/Urhc0ce/alWfYJK8w7jjdSYKr/ygUptAmpSY3kbYpoFxd1rvQeeR9qCv0PvgkkUmJH0yi/XrThWAG4cMVS8ArsZUv0DyGV/5XWyiymEAuyp81r2M62dk+aM2g= 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=ez5Zdso8; arc=none smtp.client-ip=209.85.128.45 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="ez5Zdso8" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-42cb7a2e4d6so5028725e9.0 for ; Thu, 19 Sep 2024 02:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726737707; x=1727342507; 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=ENiS9ar8wrYoh8gKiE5vvZpqfPrqs1+FYPNEzNP0wSM=; b=ez5Zdso8aQCBskaujm/rgztdZJjjlDCVgB7eZ9vxFPHkngr8GYQqS8X1wX2Tkw9qSe sZdYKwqd2MD3O11hcIUMTo2AQ8qds+vHh9DvAHXb9sf7YNwSsArS2g7j2okfCtvfUQ0y 3BGTSjNPpX6LalVjPc2sdFm+71EIQpDeDUo4jeC8vLvmNP0a21KEttZot1CJut5O8WB3 8MC70ZX+AjtII4098xmHassJUahOAb5t8o6SiaAcaQVYytvurFY7c0XhNgXKRiQHJgf4 ZrdyQaV3LldMBCV+1/qP82chayT1YQBPfKX3fjhX5j/h1WwPvdoVV7L1rFoItdq5MSxU 7KUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726737707; x=1727342507; 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=ENiS9ar8wrYoh8gKiE5vvZpqfPrqs1+FYPNEzNP0wSM=; b=Z0zciZHrbXMOqCwwrJONd7bQRuO0CffUtfAfZxQHg7yCW016ss1oL57/iZRd4HgBAN a99I5UQoeZrPIfoek/Im2EAL2iznp0VneSN7r/tfBuLmiW1XAxVu1lNPHl9w4oQzmVNg tmFD5kdU5H5E4oDmhA8TUwGqizOP0Pgn0nncifjYyDu//M4Ypy8psuCzFIp6Oay808xT KK/R0tBMPNPgrwxolxVdzcDHF/b0F9t6vqenVRDZEkhbPwRVXyH76H5OINMoZdAskr4E OboXY7Td2TMd1vsLYxUAcRctpK7fLnBX8L7HY74JWCMeJwwgdYCK1P1INWgHQAAbbZ7W jFyQ== X-Forwarded-Encrypted: i=1; AJvYcCXSBZkdfkKuwwpco4MUayAvITCAIVHmpLY5LZjbIegnTJLaEuZCv+XPAKpKcxaw1DhHB45wvzZa11TgMLY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxvr0BUwT0Cr8BbvcYnbndP6zyrgPXk6O6wsGD+X98WweOv8zVG +wtEK9IpIofUFMkBhs07OICFnWYboYRLFODd3yVLNcRuc7F24TJ7UZTfrxVoJlU= X-Google-Smtp-Source: AGHT+IEec+xCrXFc4VYZ9eKpkFZm4VIatYJ6VSPDZ/dlXU0kfHZibngMFxhWwRl47n5tAWxI0/2DLA== X-Received: by 2002:a05:600c:3581:b0:42c:ae30:fc4d with SMTP id 5b1f17b1804b1-42cdb53190emr207000815e9.7.1726737707341; Thu, 19 Sep 2024 02:21:47 -0700 (PDT) Received: from [127.0.1.1] (host-80-117-99-70.retail.telecomitalia.it. [80.117.99.70]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e75468413sm16889465e9.45.2024.09.19.02.21.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 02:21:46 -0700 (PDT) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Thu, 19 Sep 2024 11:20:05 +0200 Subject: [PATCH v3 09/10] iio: dac: ad3552r: add axi platform driver 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: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-9-a17b9b3d05d9@baylibre.com> References: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> In-Reply-To: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Nuno Sa , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Olivier Moysan Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dlechner@baylibre.com, Angelo Dureghello X-Mailer: b4 0.14.1 From: Angelo Dureghello Add support for ad3552r-axi, where ad3552r has to be controlled by the custom (fpga-based) ad3552r AXI DAC IP. Signed-off-by: Angelo Dureghello --- drivers/iio/dac/Kconfig | 11 + drivers/iio/dac/Makefile | 1 + drivers/iio/dac/ad3552r-axi.c | 567 ++++++++++++++++++++++++++= ++++ drivers/iio/dac/ad3552r.h | 9 + include/linux/platform_data/ad3552r-axi.h | 18 + 5 files changed, 606 insertions(+) diff --git a/drivers/iio/dac/Kconfig b/drivers/iio/dac/Kconfig index 1cfd7e2a622f..030af7702a3c 100644 --- a/drivers/iio/dac/Kconfig +++ b/drivers/iio/dac/Kconfig @@ -16,6 +16,17 @@ config AD3552R To compile this driver as a module, choose M here: the module will be called ad3552r. =20 +config AD3552R_AXI + tristate "Analog Devices AD3552R DAC driver, AXI version" + select IIO_BACKEND + help + Say yes here to build support for Analog Devices AD3552R + Digital to Analog Converter, connected through the Xilinx + fpga AXI interface. + + To compile this driver as a module, choose M here: the + module will be called ad3552r-axi. + config AD5064 tristate "Analog Devices AD5064 and similar multi-channel DAC driver" depends on (SPI_MASTER && I2C!=3Dm) || I2C diff --git a/drivers/iio/dac/Makefile b/drivers/iio/dac/Makefile index 56a125f56284..cc2af3aa3f52 100644 --- a/drivers/iio/dac/Makefile +++ b/drivers/iio/dac/Makefile @@ -5,6 +5,7 @@ =20 # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD3552R) +=3D ad3552r.o ad3552r-common.o +obj-$(CONFIG_AD3552R_AXI) +=3D ad3552r-axi.o ad3552r-common.o obj-$(CONFIG_AD5360) +=3D ad5360.o obj-$(CONFIG_AD5380) +=3D ad5380.o obj-$(CONFIG_AD5421) +=3D ad5421.o diff --git a/drivers/iio/dac/ad3552r-axi.c b/drivers/iio/dac/ad3552r-axi.c new file mode 100644 index 000000000000..85c594e149fa --- /dev/null +++ b/drivers/iio/dac/ad3552r-axi.c @@ -0,0 +1,567 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Analog Devices AD3552R + * Digital to Analog converter driver, AXI DAC backend version + * + * Copyright 2024 Analog Devices Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ad3552r.h" + +#define AD3552R_QSPI_LANES 4 + +struct ad3552r_axi_model_data { + const char *model_name; + enum ad3552r_id chip_id; + unsigned int num_hw_channels; + unsigned int sample_storage_bits; +}; + +struct ad3552r_axi_state { + const struct ad3552r_axi_model_data *model_data; + struct gpio_desc *reset_gpio; + struct device *dev; + struct iio_backend *back; + bool single_channel; + struct ad3552r_axi_platform_data *data; + bool ddr_mode; + bool synchronouos_mode; +}; + +static int ad3552r_qspi_update_reg_bits(struct ad3552r_axi_state *st, + u32 reg, u32 mask, u32 val, + size_t xfer_size) +{ + u32 rval; + int err; + + err =3D st->data->bus_reg_read(st->back, reg, &rval, xfer_size); + if (err) + return err; + + rval &=3D ~mask; + rval |=3D val; + + return st->data->bus_reg_write(st->back, reg, rval, xfer_size); +} + +static int ad3552r_axi_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct ad3552r_axi_state *st =3D iio_priv(indio_dev); + int ch =3D chan->channel; + int ret; + + switch (mask) { + case IIO_CHAN_INFO_SAMP_FREQ: { + int sclk; + + ret =3D iio_backend_read_raw(st->back, chan, &sclk, 0, + IIO_CHAN_INFO_FREQUENCY); + if (ret !=3D IIO_VAL_INT) + return -EINVAL; + + /* Using 4 lanes (QSPI) */ + *val =3D DIV_ROUND_CLOSEST(sclk * AD3552R_QSPI_LANES * + (1 + st->ddr_mode), + chan->scan_type.storagebits); + + return IIO_VAL_INT; + } + case IIO_CHAN_INFO_RAW: + ret =3D st->data->bus_reg_read(st->back, + AD3552R_REG_ADDR_CH_DAC_16B(ch), + val, 2); + if (ret) + return ret; + + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + +static int ad3552r_axi_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct ad3552r_axi_state *st =3D iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { + int ch =3D chan->channel; + + return st->data->bus_reg_write(st->back, + AD3552R_REG_ADDR_CH_DAC_16B(ch), val, 2); + } + unreachable(); + default: + return -EINVAL; + } +} + +static int ad3552r_axi_buffer_postenable(struct iio_dev *indio_dev) +{ + struct ad3552r_axi_state *st =3D iio_priv(indio_dev); + struct iio_backend_data_fmt fmt =3D { + .type =3D IIO_BACKEND_DATA_UNSIGNED + }; + int loop_len, val, err; + + /* Inform DAC chip to switch into DDR mode */ + err =3D ad3552r_qspi_update_reg_bits(st, + AD3552R_REG_ADDR_INTERFACE_CONFIG_D, + AD3552R_MASK_SPI_CONFIG_DDR, + AD3552R_MASK_SPI_CONFIG_DDR, 1); + if (err) + return err; + + /* Inform DAC IP to go for DDR mode from now on */ + err =3D iio_backend_ddr_enable(st->back); + if (err) { + dev_warn(st->dev, "could not set DDR mode, not streaming"); + goto exit_err; + } + + st->ddr_mode =3D true; + + switch (*indio_dev->active_scan_mask) { + case AD3552R_CH0_ACTIVE: + st->single_channel =3D true; + loop_len =3D AD3552R_STREAM_2BYTE_LOOP; + val =3D AD3552R_REG_ADDR_CH_DAC_16B(0); + break; + case AD3552R_CH1_ACTIVE: + st->single_channel =3D true; + loop_len =3D AD3552R_STREAM_2BYTE_LOOP; + val =3D AD3552R_REG_ADDR_CH_DAC_16B(1); + break; + case AD3552R_CH0_CH1_ACTIVE: + st->single_channel =3D false; + loop_len =3D AD3552R_STREAM_4BYTE_LOOP; + val =3D AD3552R_REG_ADDR_CH_DAC_16B(1); + break; + default: + err =3D -EINVAL; + goto exit_err_ddr; + } + + err =3D st->data->bus_reg_write(st->back, AD3552R_REG_ADDR_STREAM_MODE, + loop_len, 1); + if (err) + goto exit_err_ddr; + + err =3D iio_backend_data_transfer_addr(st->back, val); + if (err) + goto exit_err_ddr; + + /* + * The EXT_SYNC is mandatory in the CN0585 project where 2 instances + * of the IP are in the design and they need to generate the signals + * synchronized. + * + * Note: in first IP implementations CONFIG EXT_SYNC (RO) can be 0, + * but EXT_SYNC (ext synch ability) is enabled anyway. + */ + if (st->synchronouos_mode) + err =3D iio_backend_ext_sync_enable(st->back); + else + err =3D iio_backend_ext_sync_disable(st->back); + if (err) + goto exit_err_ddr; + + err =3D iio_backend_data_format_set(st->back, 0, &fmt); + if (err) + goto exit_err_sync; + + err =3D iio_backend_buffer_enable(st->back); + if (err) + goto exit_err_sync; + + return 0; + +exit_err_sync: + iio_backend_ext_sync_disable(st->back); + +exit_err_ddr: + iio_backend_ddr_disable(st->back); + +exit_err: + ad3552r_qspi_update_reg_bits(st, + AD3552R_REG_ADDR_INTERFACE_CONFIG_D, + AD3552R_MASK_SPI_CONFIG_DDR, + 0, 1); + + iio_backend_ddr_disable(st->back); + + st->ddr_mode =3D false; + + return err; +} + +static int ad3552r_axi_buffer_predisable(struct iio_dev *indio_dev) +{ + struct ad3552r_axi_state *st =3D iio_priv(indio_dev); + int err; + + err =3D iio_backend_buffer_disable(st->back); + if (err) + return err; + + if (st->synchronouos_mode) { + err =3D iio_backend_ext_sync_disable(st->back); + if (err) + return err; + } + + /* Inform DAC to set in SDR mode */ + err =3D ad3552r_qspi_update_reg_bits(st, + AD3552R_REG_ADDR_INTERFACE_CONFIG_D, + AD3552R_MASK_SPI_CONFIG_DDR, + 0, 1); + if (err) + return err; + + err =3D iio_backend_ddr_disable(st->back); + if (err) + return err; + + st->ddr_mode =3D false; + + return 0; +} + +static int ad3552r_axi_set_output_range(struct ad3552r_axi_state *st, + unsigned int mode) +{ + return ad3552r_qspi_update_reg_bits(st, + AD3552R_REG_ADDR_CH0_CH1_OUTPUT_RANGE, + AD3552R_MASK_CH_OUTPUT_RANGE, + FIELD_PREP(AD3552R_MASK_CH0_RANGE, mode) | + FIELD_PREP(AD3552R_MASK_CH1_RANGE, mode), + 1); +} + +static int ad3552r_axi_reset(struct ad3552r_axi_state *st) +{ + int err; + + st->reset_gpio =3D devm_gpiod_get_optional(st->dev, + "reset", GPIOD_OUT_LOW); + if (IS_ERR(st->reset_gpio)) + return PTR_ERR(st->reset_gpio); + + if (st->reset_gpio) { + fsleep(10); + gpiod_set_value_cansleep(st->reset_gpio, 1); + } else { + err =3D ad3552r_qspi_update_reg_bits(st, + AD3552R_REG_ADDR_INTERFACE_CONFIG_A, + AD3552R_MASK_SOFTWARE_RESET, + AD3552R_MASK_SOFTWARE_RESET, 1); + if (err) + return err; + } + msleep(100); + + return 0; +} + +static int ad3552r_axi_scratch_pad_test(struct ad3552r_axi_state *st) +{ + int err, val; + + err =3D st->data->bus_reg_write(st->back, AD3552R_REG_ADDR_SCRATCH_PAD, + AD3552R_SCRATCH_PAD_TEST_VAL1, 1); + if (err) + return err; + + err =3D st->data->bus_reg_read(st->back, AD3552R_REG_ADDR_SCRATCH_PAD, + &val, 1); + if (err) + return err; + + if (val !=3D AD3552R_SCRATCH_PAD_TEST_VAL1) { + dev_err(st->dev, + "SCRATCH_PAD_TEST mismatch. Expected 0x%x, Read 0x%x\n", + AD3552R_SCRATCH_PAD_TEST_VAL1, val); + return -EIO; + } + + err =3D st->data->bus_reg_write(st->back, AD3552R_REG_ADDR_SCRATCH_PAD, + AD3552R_SCRATCH_PAD_TEST_VAL2, 1); + if (err) + return err; + + err =3D st->data->bus_reg_read(st->back, AD3552R_REG_ADDR_SCRATCH_PAD, + &val, 1); + if (err) + return err; + + if (val !=3D AD3552R_SCRATCH_PAD_TEST_VAL2) { + dev_err(st->dev, + "SCRATCH_PAD_TEST mismatch. Expected 0x%x, Read 0x%x\n", + AD3552R_SCRATCH_PAD_TEST_VAL2, val); + return -EIO; + } + + return 0; +} + +static int ad3552r_axi_setup_custom_gain(struct ad3552r_axi_state *st, + u16 gain, u16 offset) +{ + int err; + + err =3D st->data->bus_reg_write(st->back, AD3552R_REG_ADDR_CH_OFFSET(0), + offset, 1); + if (err) + return dev_err_probe(st->dev, err, "Error writing register\n"); + + err =3D st->data->bus_reg_write(st->back, AD3552R_REG_ADDR_CH_OFFSET(1), + offset, 1); + if (err) + return dev_err_probe(st->dev, err, "Error writing register\n"); + + err =3D st->data->bus_reg_write(st->back, AD3552R_REG_ADDR_CH_GAIN(0), + gain, 1); + if (err) + return dev_err_probe(st->dev, err, "Error writing register\n"); + + err =3D st->data->bus_reg_write(st->back, AD3552R_REG_ADDR_CH_GAIN(1), + gain, 1); + if (err) + return dev_err_probe(st->dev, err, "Error writing register\n"); + + return 0; +} + +static int ad3552r_axi_setup(struct ad3552r_axi_state *st) +{ + struct fwnode_handle *child __free(fwnode_handle) =3D NULL; + u8 gs_p, gs_n; + s16 goffs; + u16 id, rfb; + u16 gain =3D 0, offset =3D 0; + u32 val, range; + int err; + + err =3D ad3552r_axi_reset(st); + if (err) + return err; + + err =3D iio_backend_ddr_disable(st->back); + if (err) + return err; + + err =3D ad3552r_axi_scratch_pad_test(st); + if (err) + return err; + + err =3D st->data->bus_reg_read(st->back, AD3552R_REG_ADDR_PRODUCT_ID_L, + &val, 1); + if (err) + return err; + + id =3D val; + + err =3D st->data->bus_reg_read(st->back, AD3552R_REG_ADDR_PRODUCT_ID_H, + &val, 1); + if (err) + return err; + + id |=3D val << 8; + if (id !=3D st->model_data->chip_id) + dev_info(st->dev, "Chip ID error. Expected 0x%x, Read 0x%x\n", + AD3552R_ID, id); + + err =3D st->data->bus_reg_write(st->back, + AD3552R_REG_ADDR_SH_REFERENCE_CONFIG, + 0, 1); + if (err) + return err; + + err =3D st->data->bus_reg_write(st->back, + AD3552R_REG_ADDR_TRANSFER_REGISTER, + AD3552R_MASK_QUAD_SPI | + AD3552R_MASK_STREAM_LENGTH_KEEP_VALUE, 1); + if (err) + return err; + + err =3D iio_backend_data_source_set(st->back, 0, IIO_BACKEND_EXTERNAL); + if (err) + return err; + + err =3D iio_backend_data_source_set(st->back, 1, IIO_BACKEND_EXTERNAL); + if (err) + return err; + + err =3D ad3552r_get_ref_voltage(st->dev); + if (err < 0) + return err; + + val =3D err; + + err =3D ad3552r_qspi_update_reg_bits(st, + AD3552R_REG_ADDR_SH_REFERENCE_CONFIG, + AD3552R_MASK_REFERENCE_VOLTAGE_SEL, + val, 1); + if (err) + return err; + + err =3D ad3552r_get_drive_strength(st->dev, &val); + if (!err) { + err =3D ad3552r_qspi_update_reg_bits(st, + AD3552R_REG_ADDR_INTERFACE_CONFIG_D, + AD3552R_MASK_SDO_DRIVE_STRENGTH, + val, 1); + if (err) + return err; + } + + st->synchronouos_mode =3D + fwnode_property_read_bool(dev_fwnode(st->dev), + "adi,synchronous-mode"); + + child =3D device_get_named_child_node(st->dev, "channel"); + if (!child) + return -EINVAL; + + /* + * One of "adi,output-range-microvolt" or "custom-output-range-config" + * must be available in fdt. + */ + err =3D ad3552r_get_output_range(st->dev, st->model_data->chip_id, + child, &range); + if (!err) + return ad3552r_axi_set_output_range(st, range); + if (err !=3D -ENOENT) + return err; + + err =3D ad3552r_get_custom_gain(st->dev, child, &gs_p, &gs_n, &rfb, + &goffs); + if (err) + return err; + + gain =3D ad3552r_calc_custom_gain(gs_p, gs_n, goffs); + offset =3D abs((s32)goffs); + + return ad3552r_axi_setup_custom_gain(st, gain, offset); +} + +static const struct iio_buffer_setup_ops ad3552r_axi_buffer_setup_ops =3D { + .postenable =3D ad3552r_axi_buffer_postenable, + .predisable =3D ad3552r_axi_buffer_predisable, +}; + +#define AD3552R_CHANNEL(ch) { \ + .type =3D IIO_VOLTAGE, \ + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_all =3D BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .output =3D 1, \ + .indexed =3D 1, \ + .channel =3D (ch), \ + .scan_index =3D (ch), \ + .scan_type =3D { \ + .sign =3D 'u', \ + .realbits =3D 16, \ + .storagebits =3D 16, \ + .endianness =3D IIO_BE, \ + } \ +} + +static const struct iio_chan_spec ad3552r_axi_channels[] =3D { + AD3552R_CHANNEL(0), + AD3552R_CHANNEL(1), +}; + +static const struct iio_info ad3552r_axi_info =3D { + .read_raw =3D &ad3552r_axi_read_raw, + .write_raw =3D &ad3552r_axi_write_raw, +}; + +static int ad3552r_axi_probe(struct platform_device *pdev) +{ + struct ad3552r_axi_state *st; + struct iio_dev *indio_dev; + int ret; + + indio_dev =3D devm_iio_device_alloc(&pdev->dev, sizeof(*st)); + if (!indio_dev) + return -ENOMEM; + + st =3D iio_priv(indio_dev); + st->dev =3D &pdev->dev; + + st->data =3D pdev->dev.platform_data; + if (!st->data) { + dev_err(&pdev->dev, "no platform data!\n"); + return -ENODEV; + } + + st->back =3D devm_iio_backend_get(&pdev->dev, NULL); + if (IS_ERR(st->back)) + return PTR_ERR(st->back); + + ret =3D devm_iio_backend_enable(&pdev->dev, st->back); + if (ret) + return ret; + + st->model_data =3D device_get_match_data(&pdev->dev); + + indio_dev->name =3D "ad3552r"; + indio_dev->modes =3D INDIO_DIRECT_MODE; + indio_dev->setup_ops =3D &ad3552r_axi_buffer_setup_ops; + indio_dev->channels =3D ad3552r_axi_channels; + indio_dev->num_channels =3D ARRAY_SIZE(ad3552r_axi_channels); + indio_dev->info =3D &ad3552r_axi_info; + + ret =3D devm_iio_backend_request_buffer(&pdev->dev, st->back, indio_dev); + if (ret) + return ret; + + ret =3D ad3552r_axi_setup(st); + if (ret) + return ret; + + return devm_iio_device_register(&pdev->dev, indio_dev); +} + +static const struct ad3552r_axi_model_data ad3552r_model_data =3D { + .model_name =3D "ad3552r", + .chip_id =3D AD3552R_ID, + .num_hw_channels =3D 2, +}; + +static const struct of_device_id ad3552r_axi_of_id[] =3D { + { .compatible =3D "adi,ad3552r", .data =3D &ad3552r_model_data }, + { } +}; +MODULE_DEVICE_TABLE(of, ad3552r_axi_of_id); + +static struct platform_driver axi_ad3552r_driver =3D { + .driver =3D { + .name =3D "ad3552r-axi", + .of_match_table =3D ad3552r_axi_of_id, + }, + .probe =3D ad3552r_axi_probe, +}; +module_platform_driver(axi_ad3552r_driver); + +MODULE_AUTHOR("Dragos Bogdan "); +MODULE_AUTHOR("Angelo Dureghello "); +MODULE_DESCRIPTION("AD3552R Driver - AXI IP version"); +MODULE_LICENSE("GPL"); diff --git a/drivers/iio/dac/ad3552r.h b/drivers/iio/dac/ad3552r.h index b1caa3c3e807..02805eec69a5 100644 --- a/drivers/iio/dac/ad3552r.h +++ b/drivers/iio/dac/ad3552r.h @@ -38,6 +38,8 @@ #define AD3552R_REG_ADDR_TRANSFER_REGISTER 0x0F #define AD3552R_MASK_MULTI_IO_MODE GENMASK(7, 6) #define AD3552R_MASK_STREAM_LENGTH_KEEP_VALUE BIT(2) +#define AD3552R_MASK_DUAL_SPI BIT(6) +#define AD3552R_MASK_QUAD_SPI BIT(7) #define AD3552R_REG_ADDR_INTERFACE_CONFIG_C 0x10 #define AD3552R_MASK_CRC_ENABLE (GENMASK(7, 6) |\ GENMASK(1, 0)) @@ -129,6 +131,13 @@ #define AD3552R_GAIN_SCALE 1000 #define AD3552R_LDAC_PULSE_US 100 =20 +#define AD3552R_STREAM_2BYTE_LOOP 0x02 +#define AD3552R_STREAM_4BYTE_LOOP 0x04 +#define AD3552R_CH0_ACTIVE BIT(0) +#define AD3552R_CH1_ACTIVE BIT(1) +#define AD3552R_CH0_CH1_ACTIVE (AD3552R_CH0_ACTIVE | \ + AD3552R_CH1_ACTIVE) + #define AD3552R_MAX_RANGES 5 #define AD3542R_MAX_RANGES 6 =20 diff --git a/include/linux/platform_data/ad3552r-axi.h b/include/linux/plat= form_data/ad3552r-axi.h new file mode 100644 index 000000000000..7c0db307102c --- /dev/null +++ b/include/linux/platform_data/ad3552r-axi.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2010-2024 Analog Devices Inc. + * Copyright (c) 2024 Baylibre, SAS + */ +#ifndef __LINUX_PLATFORM_DATA_AD3552R_AXI_H__ +#define __LINUX_PLATFORM_DATA_AD3552R_AXI_H__ + +#include + +struct ad3552r_axi_platform_data { + int (*bus_reg_read)(struct iio_backend *back, u32 reg, + unsigned int *val, size_t data_size); + int (*bus_reg_write)(struct iio_backend *back, u32 reg, + unsigned int val, size_t data_size); +}; + +#endif /* __LINUX_PLATFORM_DATA_AD3552R_AXI_H__ */ --=20 2.45.0.rc1 From nobody Fri Nov 29 12:47:58 2024 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.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 95C0A19D8A6 for ; Thu, 19 Sep 2024 09:21:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737712; cv=none; b=CRTJODZ9XBgzGSmFJoXiO6ZAXJplwl1FNrXYqZG3l6FWcgRlSqottSU/oKHOi2nuFCOYT6sXTiUd3XkS/uEKa5Fr+gzFvQKj6HKX7UiqGaaoT8PYBZjt5ZGxJeYq2GZJZX5vPLWXBWB+IbyGQWAg3KOcqUPtIpOll5yZXiwX8EU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726737712; c=relaxed/simple; bh=wTh4ZX/Lq4bxELrDl4dLXCSoDZv2J7fQ9IPUziM5on0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CqYyJdfhXnnSE8FRDI4m57A+iCKJZYtDRdefmG51LCjrbTfmdVR2JliDPsIYJurEj7XmBR/uNe11D95cbi9nlcySZwRLS3em4axs0eV2uo4upYNsTEq8f6x9BXAvRD6xUbbu6+kZy6RyIDBj0Y2N1jE0ooARFKWDgyg/NjbTBaA= 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=XuGsU8RH; arc=none smtp.client-ip=209.85.221.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="XuGsU8RH" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-3770320574aso345498f8f.2 for ; Thu, 19 Sep 2024 02:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726737709; x=1727342509; 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=oDBUjP1+gjd3K5h0oG5X/MTM074M3dAHmKYG+rdovVU=; b=XuGsU8RHmZy85fUTRkuCspmKvGIghq1qVeejrjM5BC4zp/UPiApGrjew28m1eZ7EjD kTS2r8UFnp2EBLgI5mfJP6AnFJrBBR+SSKSa6ihTMmTHkzF+U615OeIoBgMekxvv057g IDEGokjSMP331HwUGqjkXyzYK7XH2r3rb3Ngn3UVtISm04VIZnJpBh9hu0pGFeZxYXUp sdpOu+XT40mSjjL5L8kMPX7s4+s6U/6/M9Ymf0ACHza9Y2vah1EbnHDi6+S/J1UqzpeO X9ktsZhdlWCPd8YoH3vu5x94OiHKAznpSN+0zEQjgPw1kUf+3fEx6g5jYBfvNP0cHhx1 PcJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726737709; x=1727342509; 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=oDBUjP1+gjd3K5h0oG5X/MTM074M3dAHmKYG+rdovVU=; b=bbeghIiY1/vJJtV65efZsa520lZ9bLVxoHYBFaKH6w/fidTfbCWvZy41MRPEjP6kFf OCTgKcZz3ugKv+ob1PGMOiAZrKEgnezmoq5kpmPEEJIarMosY/40LUtW0tVn8LWztbc9 8w2oK7Brob2f4bJGRjqhviLerGIRuMHUFdxFugpaeKk/e8TXU/nnYo89lgLVRkRmT5ak AxgsO0c/6ljeOs7J74P/5MFiBfxndu/x2aLg6Ls3WBsw4l3KmD+NLr8LFP3arhdKliGk suSzKYSbnwrUnGcnJ5bkxLkyID21xmhgrRixGJJbJIa1NKj9kzezzOQl6RZUhtvkhYV6 ejBg== X-Forwarded-Encrypted: i=1; AJvYcCU9TKAyVykvJxOgofyVSHLmNSe5EELG4yq1Htnwo+Y080KmtKpvng7aLxdqDNXvKVYmszqJwpmjEwfXIag=@vger.kernel.org X-Gm-Message-State: AOJu0YyoKXiiFjPkbWKg9eLH71smg7fr0UrLkM7toACuEBfzFGQt2dwm 1f1aig/RmTT2FZKSMYJgSRjoyZW63rBLJqU1D11tmgQ4r556vkifwyiy0LUC2Eo= X-Google-Smtp-Source: AGHT+IHxdr7iojwOBs/10Ra5p+6qT9Z1ZPpg9lcLP/NKiiCl3mLdNMdiNRDGvTctoAV4LaU/+V/Xag== X-Received: by 2002:a5d:4ec4:0:b0:374:c10c:83b3 with SMTP id ffacd0b85a97d-378c2d624a2mr13291883f8f.54.1726737708814; Thu, 19 Sep 2024 02:21:48 -0700 (PDT) Received: from [127.0.1.1] (host-80-117-99-70.retail.telecomitalia.it. [80.117.99.70]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e75468413sm16889465e9.45.2024.09.19.02.21.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 02:21:48 -0700 (PDT) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Thu, 19 Sep 2024 11:20:06 +0200 Subject: [PATCH v3 10/10] iio: backend: adi-axi-dac: add registering of child fdt node 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: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-10-a17b9b3d05d9@baylibre.com> References: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> In-Reply-To: <20240919-wip-bl-ad3552r-axi-v0-iio-testing-v3-0-a17b9b3d05d9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Nuno Sa , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Olivier Moysan Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dlechner@baylibre.com, Angelo Dureghello X-Mailer: b4 0.14.1 From: Angelo Dureghello Change to obtain the fdt use case as reported in the adi,ad3552r.yaml file in this patchset. The DAC device is defined as a child node of the backend. Registering the child fdt node as a platform devices. Signed-off-by: Angelo Dureghello --- drivers/iio/dac/adi-axi-dac.c | 52 +++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c index 3ca3a14c575b..2afc1442cd5a 100644 --- a/drivers/iio/dac/adi-axi-dac.c +++ b/drivers/iio/dac/adi-axi-dac.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -109,6 +110,8 @@ struct axi_dac_info { struct axi_dac_state { struct regmap *regmap; struct device *dev; + /* Target DAC platform device */ + struct platform_device *dac_pdev; /* * lock to protect multiple accesses to the device registers and global * data/variables. @@ -757,6 +760,32 @@ static int axi_dac_bus_reg_read(struct iio_backend *ba= ck, u32 reg, } } =20 +static int axi_dac_create_platform_device(struct axi_dac_state *st, + struct fwnode_handle *child) +{ + struct ad3552r_axi_platform_data pdata =3D { + .bus_reg_read =3D axi_dac_bus_reg_read, + .bus_reg_write =3D axi_dac_bus_reg_write, + }; + struct platform_device_info pi =3D { + .parent =3D st->dev, + .name =3D fwnode_get_name(child), + .id =3D PLATFORM_DEVID_AUTO, + .fwnode =3D child, + .data =3D &pdata, + .size_data =3D sizeof(pdata), + }; + struct platform_device *pdev; + + pdev =3D platform_device_register_full(&pi); + if (IS_ERR(pdev)) + return PTR_ERR(pdev); + + st->dac_pdev =3D pdev; + + return 0; +} + static const struct iio_backend_ops axi_dac_generic_ops =3D { .enable =3D axi_dac_enable, .disable =3D axi_dac_disable, @@ -791,13 +820,22 @@ static const struct regmap_config axi_dac_regmap_conf= ig =3D { .max_register =3D 0x0800, }; =20 +static void axi_dac_remove(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct axi_dac_state *st =3D dev_get_drvdata(dev); + + if (st->dac_pdev) + platform_device_unregister(st->dac_pdev); +} + static int axi_dac_probe(struct platform_device *pdev) { struct axi_dac_state *st; void __iomem *base; unsigned int ver; struct clk *clk; - int ret; + int ret, val; =20 st =3D devm_kzalloc(&pdev->dev, sizeof(*st), GFP_KERNEL); if (!st) @@ -871,6 +909,17 @@ static int axi_dac_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, ret, "failed to register iio backend\n"); =20 + device_for_each_child_node_scoped(&pdev->dev, child) { + /* Processing only reg 0 node */ + ret =3D fwnode_property_read_u32(child, "reg", &val); + if (ret || val !=3D 0) + continue; + + ret =3D axi_dac_create_platform_device(st, child); + if (ret) + continue; + } + dev_info(&pdev->dev, "AXI DAC IP core (%d.%.2d.%c) probed\n", ADI_AXI_PCORE_VER_MAJOR(ver), ADI_AXI_PCORE_VER_MINOR(ver), @@ -901,6 +950,7 @@ static struct platform_driver axi_dac_driver =3D { .of_match_table =3D axi_dac_of_match, }, .probe =3D axi_dac_probe, + .remove =3D axi_dac_remove, }; module_platform_driver(axi_dac_driver); =20 --=20 2.45.0.rc1