From nobody Wed Dec 17 18:20:21 2025 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58A87258ECA; Tue, 16 Dec 2025 16:17:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765901864; cv=none; b=uitNzeNm7JmWCDbUj3KL4ZRZmreFJkw6x49GuRZoe3ykIoJbDA6ci5nnSNn/+RPbCSH40NnbTF0IuuAElJhmWxTCC+4IKBse/LntZrMvDYr9REOrNfTjCKNd9B2GMDeufKH8HdQn4CMsyBdcWO+reOM9rgrGanh1h3h29eszr/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765901864; c=relaxed/simple; bh=t/b15A41qprKSaWdxOKVWIGNKr5jAWI1VdWCUdw4uCQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=ZbKMClEADCGEnioPy7ZsQYCMnznBjUzjLAr+T4DYUth3NvKxaqjrscRQBSZDKYSdmxMM2NDRXUJIATkFrpBaRFB2NoSl5UIfP/MbkPBQO6cuIwlxEgtAHasEwmxrTilWAo3RuZ8TvyOtS+CrRHj5GrjcWwGU2uTMbKYvXwBxeK8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=CDuwokU8; arc=none smtp.client-ip=68.232.154.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="CDuwokU8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1765901862; x=1797437862; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=t/b15A41qprKSaWdxOKVWIGNKr5jAWI1VdWCUdw4uCQ=; b=CDuwokU8PwILFeUpw+xTCH4rWzWK2yo0SKCQ02HNtwnoSIl92lViZkmT jboYnDJxqpFuwAwG+2p6mhaqXgMk713F7F6RdUXamh5ntM0b9cp6r2d8v nFb3f6SjYZJutjv2r91C8YZvke4CQvbJWGSvnsbUMJBA8QwzZB3Q/wt/6 +F+fO6/hugkVUCGV9AJ0bpydBdWdWWBzu6dpsTkrVH+f/kZQXO+D2X52d yXuw/BQSgPIGjvk2oqCKJUFJIwyCd/0w7GNCkz5seBX1SyNiFhMZG416C ONWD3ptNpufWOdJ+v2EjsyqivBPomMZDOOM7zvcHmngk45cC3YXhcfF3E g==; X-CSE-ConnectionGUID: J2aaPMCDQySqSf1Dg34uUw== X-CSE-MsgGUID: Xlb0KFobSQ+WxMw2mZ1ebg== X-IronPort-AV: E=Sophos;i="6.21,153,1763449200"; d="scan'208";a="217938393" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Dec 2025 09:17:40 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.87.71) by chn-vm-ex4.mchp-main.com (10.10.87.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.29; Tue, 16 Dec 2025 09:17:10 -0700 Received: from [127.0.1.1] (10.10.85.11) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 16 Dec 2025 09:17:07 -0700 From: Ariana Lazar Date: Tue, 16 Dec 2025 14:05:50 +0200 Subject: [PATCH v4 1/2] dt-bindings: iio: dac: adding support for Microchip MCP47FEB02 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: <20251216-mcp47feb02-v4-1-4b687094ff90@microchip.com> References: <20251216-mcp47feb02-v4-0-4b687094ff90@microchip.com> In-Reply-To: <20251216-mcp47feb02-v4-0-4b687094ff90@microchip.com> To: Ariana Lazar , Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley CC: , , , Conor Dooley X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1765886754; l=12407; i=ariana.lazar@microchip.com; s=20250825; h=from:subject:message-id; bh=t/b15A41qprKSaWdxOKVWIGNKr5jAWI1VdWCUdw4uCQ=; b=rahH7EmJUigiHD60/3oTACV/Bf0dszGeoJiiayq+klyQCsce8nUxplQ/TrwVgSVTt/I7y8p83 xoP2yroxgzZD+mF60ipybxgniUN/P0sinwb4y7Oh8wASAYNMxPm8H7D X-Developer-Key: i=ariana.lazar@microchip.com; a=ed25519; pk=jmvf1fSxcnzZmXfITM3L94IwutM+wqA1POQHiYyD6Dk= This is the device tree schema for iio driver for Microchip MCP47F(E/V)B(0/1/2)1, MCP47F(E/V)B(0/1/2)2, MCP47F(E/V)B(0/1/2)4 and MCP47F(E/V)B(0/1/2)8 series of buffered voltage output Digital-to-Analog Converters with nonvolatile or volatile memory and an I2C Interface. The families support up to 8 output channels. The devices can be 8-bit, 10-bit and 12-bit. Signed-off-by: Ariana Lazar Reviewed-by: Conor Dooley --- .../bindings/iio/dac/microchip,mcp47feb02.yaml | 302 +++++++++++++++++= ++++ MAINTAINERS | 6 + 2 files changed, 308 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02= .yaml b/Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d2466aa6bda2106a8b695347a0e= df38462294d03 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml @@ -0,0 +1,302 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/dac/microchip,mcp47feb02.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip MCP47F(E/V)B(0/1/2)(1/2/4/8) DAC with I2C Interface Famil= ies + +maintainers: + - Ariana Lazar + +description: | + Datasheet for MCP47FEB01, MCP47FEB11, MCP47FEB21, MCP47FEB02, MCP47FEB12, + MCP47FEB22 can be found here: + https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/Product= Documents/DataSheets/20005375A.pdf + Datasheet for MCP47FVB01, MCP47FVB11, MCP47FVB21, MCP47FVB02, MCP47FVB12, + MCP47FVB22 can be found here: + https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/Product= Documents/DataSheets/20005405A.pdf + Datasheet for MCP47FEB04, MCP47FEB14, MCP47FEB24, MCP47FEB08, MCP47FEB18, + MCP47FEB28, MCP47FVB04, MCP47FVB14, MCP47FVB24, MCP47FVB08, MCP47FVB18, + MCP47FVB28 can be found here: + https://ww1.microchip.com/downloads/aemDocuments/documents/MSLD/Produc= tDocuments/DataSheets/MCP47FXBX48-Data-Sheet-DS200006368A.pdf + + +------------+--------------+-------------+-------------+------------+ + | Device | Resolution | Channels | Vref number | Memory | + |------------|--------------|-------------|-------------|------------| + | MCP47FEB01 | 8-bit | 1 | 1 | EEPROM | + | MCP47FEB11 | 10-bit | 1 | 1 | EEPROM | + | MCP47FEB21 | 12-bit | 1 | 1 | EEPROM | + |------------|--------------|-------------|-------------|------------| + | MCP47FEB02 | 8-bit | 2 | 1 | EEPROM | + | MCP47FEB12 | 10-bit | 2 | 1 | EEPROM | + | MCP47FEB22 | 12-bit | 2 | 1 | EEPROM | + |------------|--------------|-------------|-------------|------------| + | MCP47FVB01 | 8-bit | 1 | 1 | RAM | + | MCP47FVB11 | 10-bit | 1 | 1 | RAM | + | MCP47FVB21 | 12-bit | 1 | 1 | RAM | + |------------|--------------|-------------|-------------|------------| + | MCP47FVB02 | 8-bit | 2 | 1 | RAM | + | MCP47FVB12 | 10-bit | 2 | 1 | RAM | + | MCP47FVB22 | 12-bit | 2 | 1 | RAM | + |------------|--------------|-------------|-------------|------------| + | MCP47FVB04 | 8-bit | 4 | 2 | RAM | + | MCP47FVB14 | 10-bit | 4 | 2 | RAM | + | MCP47FVB24 | 12-bit | 4 | 2 | RAM | + |------------|--------------|-------------|-------------|------------| + | MCP47FVB08 | 8-bit | 8 | 2 | RAM | + | MCP47FVB18 | 10-bit | 8 | 2 | RAM | + | MCP47FVB28 | 12-bit | 8 | 2 | RAM | + |------------|--------------|-------------|-------------|------------| + | MCP47FEB04 | 8-bit | 4 | 2 | EEPROM | + | MCP47FEB14 | 10-bit | 4 | 2 | EEPROM | + | MCP47FEB24 | 12-bit | 4 | 2 | EEPROM | + |------------|--------------|-------------|-------------|------------| + | MCP47FEB08 | 8-bit | 8 | 2 | EEPROM | + | MCP47FEB18 | 10-bit | 8 | 2 | EEPROM | + | MCP47FEB28 | 12-bit | 8 | 2 | EEPROM | + +------------+--------------+-------------+-------------+------------+ + +properties: + compatible: + enum: + - microchip,mcp47feb01 + - microchip,mcp47feb11 + - microchip,mcp47feb21 + - microchip,mcp47feb02 + - microchip,mcp47feb12 + - microchip,mcp47feb22 + - microchip,mcp47fvb01 + - microchip,mcp47fvb11 + - microchip,mcp47fvb21 + - microchip,mcp47fvb02 + - microchip,mcp47fvb12 + - microchip,mcp47fvb22 + - microchip,mcp47fvb04 + - microchip,mcp47fvb14 + - microchip,mcp47fvb24 + - microchip,mcp47fvb08 + - microchip,mcp47fvb18 + - microchip,mcp47fvb28 + - microchip,mcp47feb04 + - microchip,mcp47feb14 + - microchip,mcp47feb24 + - microchip,mcp47feb08 + - microchip,mcp47feb18 + - microchip,mcp47feb28 + + reg: + maxItems: 1 + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + + vdd-supply: + description: + Provides power to the chip and it could be used as reference voltage= . The + voltage is used to calculate scale. For parts without EEPROM at powe= rup + this will be the selected as voltage reference. + + vref-supply: + description: | + Vref pin (it could be found as Vref0 into the datasheet) may be used= as a + voltage reference when this supply is specified. The internal refere= nce + will be taken into account for voltage reference besides VDD if this= supply + does not exist. + + This supply will be voltage reference for the following outputs: + - for single-channel device: Vout0; + - for dual-channel device: Vout0, Vout1; + - for quad-channel device: Vout0, Vout2; + - for octal-channel device: Vout0, Vout2, Vout6, Vout8; + + vref1-supply: + description: | + Vref1 pin may be used as a voltage reference when this supply is spe= cified. + The internal reference will be taken into account for voltage refere= nce + beside VDD if this supply does not exist. + + This supply will be voltage reference for the following outputs: + - for quad-channel device: Vout1, Vout3; + - for octal-channel device: Vout1, Vout3, Vout5, Vout7; + + lat-gpios: + description: + LAT pin to be used as a hardware trigger to synchronously update the= DAC + channels. The pin is active Low. It could be also found as LAT0 in + datasheet. + maxItems: 1 + + lat1-gpios: + description: + LAT1 pin to be used as a hardware trigger to synchronously update th= e odd + DAC channels on devices with 4 and 8 channels. The pin is active Low. + maxItems: 1 + + microchip,vref-buffered: + type: boolean + description: + Enable buffering of the external Vref/Vref0 pin in cases where the + external reference voltage does not have sufficient current capabili= ty in + order not to drop it=E2=80=99s voltage when connected to the interna= l resistor + ladder circuit. + + microchip,vref1-buffered: + type: boolean + description: + Enable buffering of the external Vref1 pin in cases where the extern= al + reference voltage does not have sufficient current capability in ord= er not + to drop it=E2=80=99s voltage when connected to the internal resistor= ladder + circuit. + +patternProperties: + "^channel@[0-7]$": + $ref: dac.yaml + type: object + description: Voltage output channel. + + properties: + reg: + description: The channel number. + minItems: 1 + maxItems: 8 + + label: + description: Unique name to identify which channel this is. + + required: + - reg + + unevaluatedProperties: false + +required: + - compatible + - reg + - vdd-supply + +allOf: + - if: + properties: + compatible: + contains: + enum: + - microchip,mcp47feb01 + - microchip,mcp47feb11 + - microchip,mcp47feb21 + - microchip,mcp47fvb01 + - microchip,mcp47fvb11 + - microchip,mcp47fvb21 + then: + properties: + lat1-gpios: false + vref1-supply: false + microchip,vref1-buffered: false + channel@0: + properties: + reg: + const: 0 + patternProperties: + "^channel@[1-7]$": false + - if: + properties: + compatible: + contains: + enum: + - microchip,mcp47feb02 + - microchip,mcp47feb12 + - microchip,mcp47feb22 + - microchip,mcp47fvb02 + - microchip,mcp47fvb12 + - microchip,mcp47fvb22 + then: + properties: + lat1-gpios: false + vref1-supply: false + microchip,vref1-buffered: false + patternProperties: + "^channel@[0-1]$": + properties: + reg: + enum: [0, 1] + "^channel@[2-7]$": false + - if: + properties: + compatible: + contains: + enum: + - microchip,mcp47fvb04 + - microchip,mcp47fvb14 + - microchip,mcp47fvb24 + - microchip,mcp47feb04 + - microchip,mcp47feb14 + - microchip,mcp47feb24 + then: + patternProperties: + "^channel@[0-3]$": + properties: + reg: + enum: [0, 1, 2, 3] + "^channel@[4-7]$": false + - if: + properties: + compatible: + contains: + enum: + - microchip,mcp47fvb08 + - microchip,mcp47fvb18 + - microchip,mcp47fvb28 + - microchip,mcp47feb08 + - microchip,mcp47feb18 + - microchip,mcp47feb28 + then: + patternProperties: + "^channel@[0-7]$": + properties: + reg: + enum: [0, 1, 2, 3, 4, 5, 6, 7] + - if: + not: + required: + - vref-supply + then: + properties: + microchip,vref-buffered: false + - if: + not: + required: + - vref1-supply + then: + properties: + microchip,vref1-buffered: false + +additionalProperties: false + +examples: + - | + i2c { + + #address-cells =3D <1>; + #size-cells =3D <0>; + dac@0 { + compatible =3D "microchip,mcp47feb02"; + reg =3D <0>; + vdd-supply =3D <&vdac_vdd>; + vref-supply =3D <&vref_reg>; + + #address-cells =3D <1>; + #size-cells =3D <0>; + channel@0 { + reg =3D <0>; + label =3D "Adjustable_voltage_ch0"; + }; + + channel@1 { + reg =3D <0x1>; + label =3D "Adjustable_voltage_ch1"; + }; + }; + }; +... diff --git a/MAINTAINERS b/MAINTAINERS index a92290fffa163f9fe8fe3f04bf66426f9a894409..6f51890cfc3081bc49c08fddc8a= f526c1ecc8d72 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14938,6 +14938,12 @@ F: Documentation/ABI/testing/sysfs-bus-iio-potenti= ometer-mcp4531 F: drivers/iio/potentiometer/mcp4018.c F: drivers/iio/potentiometer/mcp4531.c =20 +MCP47FEB02 MICROCHIP DAC DRIVER +M: Ariana Lazar +L: linux-iio@vger.kernel.org +S: Supported +F: Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml + MCP4821 DAC DRIVER M: Anshul Dalal L: linux-iio@vger.kernel.org --=20 2.43.0 From nobody Wed Dec 17 18:20:21 2025 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAD8A2D7DD1; Tue, 16 Dec 2025 16:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765901874; cv=none; b=NFc3vASRZtFH2f8feDWOLGIxD0ciXDzgEe/MEGTmON34MUnvoIY4x/Y2t69ZHOgYxxr0lasl6CEjlhTE+pNrQZ/nb5S6stjLHSjn6+0DQi9MAbNVfJovg8AA4Z7oz+o9nfQvZ+fXfHMEEGypCLxyg0trg4+ZTrW8+jbXARyTw+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765901874; c=relaxed/simple; bh=uo1wBk7tGmbm3E0QtTG0KibQTJU/0fefWHMbHhg+aV0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=ENYUG5bDJvJzW04denbHLnvRL9uKPj3kUvdeMSrz5S3kJ4gTc8P7HTfleYyJ0l5zqN2PzgGSDgvPbno6FTHiOSRNfNNEQty1on2K7egVBL2U/RdmPWeYfkGVVtjDmMtLffk+xYFoOaUnWEkXphr+RfuhuqXhrHsFt1HxZSHTsNk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=c8T9pyQ5; arc=none smtp.client-ip=68.232.153.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="c8T9pyQ5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1765901871; x=1797437871; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=uo1wBk7tGmbm3E0QtTG0KibQTJU/0fefWHMbHhg+aV0=; b=c8T9pyQ5RFZLxACAeWGNQaOJBgZocU1kD6QGB/hFHiluZ2z0Aok1PpuZ 0U9/TGR3aqb6kwYVufSSeDBfQfxH7OsnTR/Pk2IBwJXSMWYKNEdEBHvpf WXurdBVP8nCBtlc73dlywauDcOIo74iATCPNOzFk27e/r286NUYEqtzV/ avUnCfMk83tE2XJia1Um8HVoAPi0KlNtuY+0r9Cc8z6CX9DaO7dGrHKpb ck4tZBYF0zxVYy4RFsdSVJXmbcqvSbCt1EjA894eI62GVpA7S1yT0g4t0 ASagx49nyoJu3I0wLOwy1p1gtaTDz3gxV7UJvaKUPRuitFo4Agh3N8TX5 g==; X-CSE-ConnectionGUID: /U12bD3cQVewC+xXEOZP/Q== X-CSE-MsgGUID: QdA8pJbeT1GeWpKVMNEEKw== X-IronPort-AV: E=Sophos;i="6.21,153,1763449200"; d="scan'208";a="281989806" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Dec 2025 09:17:44 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.87.71) by chn-vm-ex3.mchp-main.com (10.10.87.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.29; Tue, 16 Dec 2025 09:17:13 -0700 Received: from [127.0.1.1] (10.10.85.11) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 16 Dec 2025 09:17:10 -0700 From: Ariana Lazar Date: Tue, 16 Dec 2025 14:05:51 +0200 Subject: [PATCH v4 2/2] iio: dac: adding support for Microchip MCP47FEB02 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: <20251216-mcp47feb02-v4-2-4b687094ff90@microchip.com> References: <20251216-mcp47feb02-v4-0-4b687094ff90@microchip.com> In-Reply-To: <20251216-mcp47feb02-v4-0-4b687094ff90@microchip.com> To: Ariana Lazar , Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley CC: , , X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1765886754; l=43679; i=ariana.lazar@microchip.com; s=20250825; h=from:subject:message-id; bh=uo1wBk7tGmbm3E0QtTG0KibQTJU/0fefWHMbHhg+aV0=; b=mziQRuNcTcVQ4Z2Vg80DG1c+vm33nzXiP3hgnO+MrZJgTKYQKlLZztIQlqUR431/bLrp6UTPu 4N5T31y4pzgBo6kWegMY2/WAD20c0VJaIBL9DTrWND6E34NtWMo1KIN X-Developer-Key: i=ariana.lazar@microchip.com; a=ed25519; pk=jmvf1fSxcnzZmXfITM3L94IwutM+wqA1POQHiYyD6Dk= This is the iio driver for Microchip MCP47F(E/V)B(0/1/2)1, MCP47F(E/V)B(0/1/2)2, MCP47F(E/V)B(0/1/2)4 and MCP47F(E/V)B(0/1/2)8 series of buffered voltage output Digital-to-Analog Converters with nonvolatile or volatile memory and an I2C Interface. The families support up to 8 output channels. The devices can be 8-bit, 10-bit and 12-bit. Signed-off-by: Ariana Lazar --- MAINTAINERS | 1 + drivers/iio/dac/Kconfig | 20 + drivers/iio/dac/Makefile | 1 + drivers/iio/dac/mcp47feb02.c | 1251 ++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 1273 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 6f51890cfc3081bc49c08fddc8af526c1ecc8d72..0f97f90ac2f492895d27da86d83= 1df83cb402516 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14943,6 +14943,7 @@ M: Ariana Lazar L: linux-iio@vger.kernel.org S: Supported F: Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml +F: drivers/iio/dac/mcp47feb02.c =20 MCP4821 DAC DRIVER M: Anshul Dalal diff --git a/drivers/iio/dac/Kconfig b/drivers/iio/dac/Kconfig index e0996dc014a3d538ab6b4e0d50ff54ede50f1527..c88abdeb84d428bd5750a10956c= f9305168e43d6 100644 --- a/drivers/iio/dac/Kconfig +++ b/drivers/iio/dac/Kconfig @@ -509,6 +509,26 @@ config MCP4728 To compile this driver as a module, choose M here: the module will be called mcp4728. =20 +config MCP47FEB02 + tristate "MCP47F(E/V)B01/02/04/08/11/12/14/18/21/22/24/28 DAC driver" + depends on I2C + help + Say yes here if you want to build the driver for the Microchip: + - 8-bit DAC: + MCP47FEB01, MCP47FEB02, MCP47FEB04, MCP47FEB08, + MCP47FVB01, MCP47FVB02, MCP47FVB04, MCP47FVB08 + - 10-bit DAC: + MCP47FEB11, MCP47FEB12, MCP47FEB14, MCP47FEB18, + MCP47FVB11, MCP47FVB12, MCP47FVB14, MCP47FVB18 + - 12-bit DAC: + MCP47FEB21, MCP47FEB22, MCP47FEB24, MCP47FEB28, + MCP47FVB21, MCP47FVB22, MCP47FVB24, MCP47FVB28 + having 1 to 8 channels, 8/10/12-bit digital-to-analog converter + (DAC) with I2C interface. + + To compile this driver as a module, choose M here: the module + will be called mcp47feb02. + config MCP4821 tristate "MCP4801/02/11/12/21/22 DAC driver" depends on SPI diff --git a/drivers/iio/dac/Makefile b/drivers/iio/dac/Makefile index 3684cd52b7fa9bc0ad9f855323dcbb2e4965c404..d633a6440fc4b9aba7d8b1c209b= 6dcd05cd982dd 100644 --- a/drivers/iio/dac/Makefile +++ b/drivers/iio/dac/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_MAX5522) +=3D max5522.o obj-$(CONFIG_MAX5821) +=3D max5821.o obj-$(CONFIG_MCP4725) +=3D mcp4725.o obj-$(CONFIG_MCP4728) +=3D mcp4728.o +obj-$(CONFIG_MCP47FEB02) +=3D mcp47feb02.o obj-$(CONFIG_MCP4821) +=3D mcp4821.o obj-$(CONFIG_MCP4922) +=3D mcp4922.o obj-$(CONFIG_STM32_DAC_CORE) +=3D stm32-dac-core.o diff --git a/drivers/iio/dac/mcp47feb02.c b/drivers/iio/dac/mcp47feb02.c new file mode 100644 index 0000000000000000000000000000000000000000..c04f3b72b1b1fc303b1bde63c28= 1aade8a67b2f9 --- /dev/null +++ b/drivers/iio/dac/mcp47feb02.c @@ -0,0 +1,1251 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * IIO driver for MCP47FEB02 Multi-Channel DAC with I2C interface + * + * Copyright (C) 2025 Microchip Technology Inc. and its subsidiaries + * + * Author: Ariana Lazar + * + * Datasheet links: + * [MCP47FEBxx] https://ww1.microchip.com/downloads/aemDocuments/documents= /OTH/ProductDocuments/DataSheets/20005375A.pdf + * [MCP47FVBxx] https://ww1.microchip.com/downloads/aemDocuments/documents= /OTH/ProductDocuments/DataSheets/20005405A.pdf + * [MCP47FxBx4/8] https://ww1.microchip.com/downloads/aemDocuments/documen= ts/MSLD/ProductDocuments/DataSheets/MCP47FXBX48-Data-Sheet-DS200006368A.pdf + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Register addresses must be left shifted with 3 positions in order to ap= pend command mask */ +#define MCP47FEB02_DAC0_REG_ADDR 0x00 +#define MCP47FEB02_VREF_REG_ADDR 0x40 +#define MCP47FEB02_POWER_DOWN_REG_ADDR 0x48 +#define MCP47FEB02_DAC_CTRL_MASK GENMASK(1, 0) + +#define MCP47FEB02_GAIN_CTRL_STATUS_REG_ADDR 0x50 +#define MCP47FEB02_GAIN_BIT_MASK BIT(0) +#define MCP47FEB02_GAIN_BIT_STATUS_EEWA_MASK BIT(6) +#define MCP47FEB02_GAIN_BITS_MASK GENMASK(15, 8) + +#define MCP47FEB02_WIPERLOCK_STATUS_REG_ADDR 0x58 + +#define MCP47FEB02_NV_DAC0_REG_ADDR 0x80 +#define MCP47FEB02_NV_VREF_REG_ADDR 0xC0 +#define MCP47FEB02_NV_POWER_DOWN_REG_ADDR 0xC8 +#define MCP47FEB02_NV_GAIN_CTRL_I2C_SLAVE_REG_ADDR 0xD0 +#define MCP47FEB02_NV_I2C_SLAVE_ADDR_MASK GENMASK(7, 0) + +/* Voltage reference, Power-Down control register and DAC Wiperlock status= register fields */ +#define DAC_CTRL_MASK(ch) (GENMASK(1, 0) << (2 * (ch))) +#define DAC_CTRL_VAL(ch, val) ((val) << (2 * (ch))) + +/* Gain Control and I2C Slave Address Reguster fields */ +#define DAC_GAIN_MASK(ch) (BIT(0) << (8 + (ch))) +#define DAC_GAIN_VAL(ch, val) ((val) << (8 + (ch))) + +#define REG_ADDR(reg) ((reg) << 3) +#define NV_REG_ADDR(reg) ((NV_DAC_ADDR_OFFSET + (reg)) << 3) +#define READFLAG_MASK GENMASK(2, 1) + +#define MCP47FEB02_MAX_CH 8 +#define MCP47FEB02_MAX_SCALES_CH 3 +#define MCP47FEB02_DAC_WIPER_UNLOCKED 0 +#define MCP47FEB02_NORMAL_OPERATION 0 +#define MCP47FEB02_INTERNAL_BAND_GAP_mV 2440 +#define NV_DAC_ADDR_OFFSET 0x10 + +enum mcp47feb02_vref_mode { + MCP47FEB02_VREF_VDD =3D 0, + MCP47FEB02_INTERNAL_BAND_GAP =3D 1, + MCP47FEB02_EXTERNAL_VREF_UNBUFFERED =3D 2, + MCP47FEB02_EXTERNAL_VREF_BUFFERED =3D 3, +}; + +enum mcp47feb02_scale { + MCP47FEB02_SCALE_VDD =3D 0, + MCP47FEB02_SCALE_GAIN_X1 =3D 1, + MCP47FEB02_SCALE_GAIN_X2 =3D 2, +}; + +enum mcp47feb02_gain_bit_mode { + MCP47FEB02_GAIN_BIT_X1 =3D 0, + MCP47FEB02_GAIN_BIT_X2 =3D 1, +}; + +static const char * const mcp47feb02_powerdown_modes[] =3D { + "1kohm_to_gnd", + "100kohm_to_gnd", + "open_circuit", +}; + +/** + * struct mcp47feb02_features - chip specific data + * @name: device name + * @phys_channels: number of hardware channels + * @resolution: DAC resolution + * @have_ext_vref1: does the hardware have an the second external voltage = reference? + * @have_eeprom: does the hardware have an internal eeprom? + */ +struct mcp47feb02_features { + const char *name; + unsigned int phys_channels; + unsigned int resolution; + bool have_ext_vref1; + bool have_eeprom; +}; + +static const struct mcp47feb02_features mcp47feb01_chip_features =3D { + .name =3D "mcp47feb01", + .phys_channels =3D 1, + .resolution =3D 8, + .have_ext_vref1 =3D false, + .have_eeprom =3D true, +}; + +static const struct mcp47feb02_features mcp47feb02_chip_features =3D { + .name =3D "mcp47feb02", + .phys_channels =3D 2, + .resolution =3D 8, + .have_ext_vref1 =3D false, + .have_eeprom =3D true, +}; + +static const struct mcp47feb02_features mcp47feb04_chip_features =3D { + .name =3D "mcp47feb04", + .phys_channels =3D 4, + .resolution =3D 8, + .have_ext_vref1 =3D true, + .have_eeprom =3D true, +}; + +static const struct mcp47feb02_features mcp47feb08_chip_features =3D { + .name =3D "mcp47feb08", + .phys_channels =3D 8, + .resolution =3D 8, + .have_ext_vref1 =3D true, + .have_eeprom =3D true, +}; + +static const struct mcp47feb02_features mcp47feb11_chip_features =3D { + .name =3D "mcp47feb11", + .phys_channels =3D 1, + .resolution =3D 10, + .have_ext_vref1 =3D false, + .have_eeprom =3D true, +}; + +static const struct mcp47feb02_features mcp47feb12_chip_features =3D { + .name =3D "mcp47feb12", + .phys_channels =3D 2, + .resolution =3D 10, + .have_ext_vref1 =3D false, + .have_eeprom =3D true, +}; + +static const struct mcp47feb02_features mcp47feb14_chip_features =3D { + .name =3D "mcp47feb14", + .phys_channels =3D 4, + .resolution =3D 10, + .have_ext_vref1 =3D true, + .have_eeprom =3D true, +}; + +static const struct mcp47feb02_features mcp47feb18_chip_features =3D { + .name =3D "mcp47feb18", + .phys_channels =3D 8, + .resolution =3D 10, + .have_ext_vref1 =3D true, + .have_eeprom =3D true, +}; + +static const struct mcp47feb02_features mcp47feb21_chip_features =3D { + .name =3D "mcp47feb21", + .phys_channels =3D 1, + .resolution =3D 12, + .have_ext_vref1 =3D false, + .have_eeprom =3D true, +}; + +static const struct mcp47feb02_features mcp47feb22_chip_features =3D { + .name =3D "mcp47feb22", + .phys_channels =3D 2, + .resolution =3D 12, + .have_ext_vref1 =3D false, + .have_eeprom =3D true, +}; + +static const struct mcp47feb02_features mcp47feb24_chip_features =3D { + .name =3D "mcp47feb24", + .phys_channels =3D 4, + .resolution =3D 12, + .have_ext_vref1 =3D true, + .have_eeprom =3D true, +}; + +static const struct mcp47feb02_features mcp47feb28_chip_features =3D { + .name =3D "mcp47feb28", + .phys_channels =3D 8, + .resolution =3D 12, + .have_ext_vref1 =3D true, + .have_eeprom =3D true, +}; + +static const struct mcp47feb02_features mcp47fvb01_chip_features =3D { + .name =3D "mcp47fvb01", + .phys_channels =3D 1, + .resolution =3D 8, + .have_ext_vref1 =3D false, + .have_eeprom =3D false, +}; + +static const struct mcp47feb02_features mcp47fvb02_chip_features =3D { + .name =3D "mcp47fvb02", + .phys_channels =3D 2, + .resolution =3D 8, + .have_ext_vref1 =3D false, + .have_eeprom =3D false, +}; + +static const struct mcp47feb02_features mcp47fvb04_chip_features =3D { + .name =3D "mcp47fvb04", + .phys_channels =3D 4, + .resolution =3D 8, + .have_ext_vref1 =3D true, + .have_eeprom =3D false, +}; + +static const struct mcp47feb02_features mcp47fvb08_chip_features =3D { + .name =3D "mcp47fvb08", + .phys_channels =3D 8, + .resolution =3D 8, + .have_ext_vref1 =3D true, + .have_eeprom =3D false, +}; + +static const struct mcp47feb02_features mcp47fvb11_chip_features =3D { + .name =3D "mcp47fvb11", + .phys_channels =3D 1, + .resolution =3D 10, + .have_ext_vref1 =3D false, + .have_eeprom =3D false, +}; + +static const struct mcp47feb02_features mcp47fvb12_chip_features =3D { + .name =3D "mcp47fvb12", + .phys_channels =3D 2, + .resolution =3D 10, + .have_ext_vref1 =3D false, + .have_eeprom =3D false, +}; + +static const struct mcp47feb02_features mcp47fvb14_chip_features =3D { + .name =3D "mcp47fvb14", + .phys_channels =3D 4, + .resolution =3D 10, + .have_ext_vref1 =3D true, + .have_eeprom =3D false, +}; + +static const struct mcp47feb02_features mcp47fvb18_chip_features =3D { + .name =3D "mcp47fvb18", + .phys_channels =3D 8, + .resolution =3D 10, + .have_ext_vref1 =3D true, + .have_eeprom =3D false, +}; + +static const struct mcp47feb02_features mcp47fvb21_chip_features =3D { + .name =3D "mcp47fvb21", + .phys_channels =3D 1, + .resolution =3D 12, + .have_ext_vref1 =3D false, + .have_eeprom =3D false, +}; + +static const struct mcp47feb02_features mcp47fvb22_chip_features =3D { + .name =3D "mcp47fvb22", + .phys_channels =3D 2, + .resolution =3D 12, + .have_ext_vref1 =3D false, + .have_eeprom =3D false, +}; + +static const struct mcp47feb02_features mcp47fvb24_chip_features =3D { + .name =3D "mcp47fvb24", + .phys_channels =3D 4, + .resolution =3D 12, + .have_ext_vref1 =3D true, + .have_eeprom =3D false, +}; + +static const struct mcp47feb02_features mcp47fvb28_chip_features =3D { + .name =3D "mcp47fvb28", + .phys_channels =3D 8, + .resolution =3D 12, + .have_ext_vref1 =3D true, + .have_eeprom =3D false, +}; + +/** + * struct mcp47feb02_channel_data - channel configuration + * @ref_mode: chosen voltage for reference + * @use_2x_gain: output driver gain control + * @powerdown: is false if the channel is in normal operation mode + * @powerdown_mode: selected power-down mode + * @dac_data: dac value + */ +struct mcp47feb02_channel_data { + u8 ref_mode; + bool use_2x_gain; + bool powerdown; + u8 powerdown_mode; + u16 dac_data; +}; + +/** + * struct mcp47feb02_data - chip configuration + * @chdata: options configured for each channel on the device + * @lock: prevents concurrent reads/writes to driver's state members + * @chip_features: pointer to features struct + * @scale_1: scales set on channels that are based on Vref1 + * @scale: scales set on channels that are based on Vref/Vref0 + * @active_channels_mask: enabled channels + * @client: the i2c-client attached to the device + * @regmap: regmap for directly accessing device register + * @vref1_buffered: Vref1 buffer is enabled + * @vref_buffered: Vref/Vref0 buffer is enabled + * @phys_channels: physical channels on the device + * @labels: table with channels labels + * @use_vref1: vref1-supply is defined + * @use_vref: vref-supply is defined + */ +struct mcp47feb02_data { + struct mcp47feb02_channel_data chdata[MCP47FEB02_MAX_CH]; + struct mutex lock; /* prevents concurrent reads/writes to driver's state = members */ + const struct mcp47feb02_features *chip_features; + int scale_1[2 * MCP47FEB02_MAX_SCALES_CH]; + int scale[2 * MCP47FEB02_MAX_SCALES_CH]; + unsigned long active_channels_mask; + struct regmap *regmap; + bool vref1_buffered; + bool vref_buffered; + u16 phys_channels; + const char *labels[MCP47FEB02_MAX_CH]; + bool use_vref1; + bool use_vref; +}; + +static const struct regmap_range mcp47feb02_readable_ranges[] =3D { + regmap_reg_range(MCP47FEB02_DAC0_REG_ADDR, MCP47FEB02_WIPERLOCK_STATUS_RE= G_ADDR), + regmap_reg_range(MCP47FEB02_NV_DAC0_REG_ADDR, MCP47FEB02_NV_GAIN_CTRL_I2C= _SLAVE_REG_ADDR), +}; + +static const struct regmap_range mcp47feb02_writable_ranges[] =3D { + regmap_reg_range(MCP47FEB02_DAC0_REG_ADDR, MCP47FEB02_WIPERLOCK_STATUS_RE= G_ADDR), + regmap_reg_range(MCP47FEB02_NV_DAC0_REG_ADDR, MCP47FEB02_NV_GAIN_CTRL_I2C= _SLAVE_REG_ADDR), +}; + +static const struct regmap_range mcp47feb02_volatile_ranges[] =3D { + regmap_reg_range(MCP47FEB02_DAC0_REG_ADDR, MCP47FEB02_WIPERLOCK_STATUS_RE= G_ADDR), + regmap_reg_range(MCP47FEB02_NV_DAC0_REG_ADDR, MCP47FEB02_NV_GAIN_CTRL_I2C= _SLAVE_REG_ADDR), + regmap_reg_range(MCP47FEB02_DAC0_REG_ADDR, MCP47FEB02_WIPERLOCK_STATUS_RE= G_ADDR), + regmap_reg_range(MCP47FEB02_NV_DAC0_REG_ADDR, MCP47FEB02_NV_GAIN_CTRL_I2C= _SLAVE_REG_ADDR), +}; + +static const struct regmap_access_table mcp47feb02_readable_table =3D { + .yes_ranges =3D mcp47feb02_readable_ranges, + .n_yes_ranges =3D ARRAY_SIZE(mcp47feb02_readable_ranges), +}; + +static const struct regmap_access_table mcp47feb02_writable_table =3D { + .yes_ranges =3D mcp47feb02_writable_ranges, + .n_yes_ranges =3D ARRAY_SIZE(mcp47feb02_writable_ranges), +}; + +static const struct regmap_access_table mcp47feb02_volatile_table =3D { + .yes_ranges =3D mcp47feb02_volatile_ranges, + .n_yes_ranges =3D ARRAY_SIZE(mcp47feb02_volatile_ranges), +}; + +static const struct regmap_config mcp47feb02_regmap_config =3D { + .name =3D "mcp47feb02_regmap", + .reg_bits =3D 8, + .val_bits =3D 16, + .rd_table =3D &mcp47feb02_readable_table, + .wr_table =3D &mcp47feb02_writable_table, + .volatile_table =3D &mcp47feb02_volatile_table, + .max_register =3D MCP47FEB02_NV_GAIN_CTRL_I2C_SLAVE_REG_ADDR, + .read_flag_mask =3D READFLAG_MASK, + .cache_type =3D REGCACHE_MAPLE, + .val_format_endian =3D REGMAP_ENDIAN_BIG, +}; + +/* For devices that doesn't have nonvolatile memory */ +static const struct regmap_range mcp47fvb02_readable_ranges[] =3D { + regmap_reg_range(MCP47FEB02_DAC0_REG_ADDR, MCP47FEB02_WIPERLOCK_STATUS_RE= G_ADDR), +}; + +static const struct regmap_range mcp47fvb02_writable_ranges[] =3D { + regmap_reg_range(MCP47FEB02_DAC0_REG_ADDR, MCP47FEB02_WIPERLOCK_STATUS_RE= G_ADDR), +}; + +static const struct regmap_range mcp47fvb02_volatile_ranges[] =3D { + regmap_reg_range(MCP47FEB02_DAC0_REG_ADDR, MCP47FEB02_WIPERLOCK_STATUS_RE= G_ADDR), + regmap_reg_range(MCP47FEB02_DAC0_REG_ADDR, MCP47FEB02_WIPERLOCK_STATUS_RE= G_ADDR), +}; + +static const struct regmap_access_table mcp47fvb02_readable_table =3D { + .yes_ranges =3D mcp47fvb02_readable_ranges, + .n_yes_ranges =3D ARRAY_SIZE(mcp47fvb02_readable_ranges), +}; + +static const struct regmap_access_table mcp47fvb02_writable_table =3D { + .yes_ranges =3D mcp47fvb02_writable_ranges, + .n_yes_ranges =3D ARRAY_SIZE(mcp47fvb02_writable_ranges), +}; + +static const struct regmap_access_table mcp47fvb02_volatile_table =3D { + .yes_ranges =3D mcp47fvb02_volatile_ranges, + .n_yes_ranges =3D ARRAY_SIZE(mcp47fvb02_volatile_ranges), +}; + +static const struct regmap_config mcp47fvb02_regmap_config =3D { + .name =3D "mcp47fvb02_regmap", + .reg_bits =3D 8, + .val_bits =3D 16, + .rd_table =3D &mcp47fvb02_readable_table, + .wr_table =3D &mcp47fvb02_writable_table, + .volatile_table =3D &mcp47fvb02_volatile_table, + .max_register =3D MCP47FEB02_WIPERLOCK_STATUS_REG_ADDR, + .read_flag_mask =3D READFLAG_MASK, + .cache_type =3D REGCACHE_MAPLE, + .val_format_endian =3D REGMAP_ENDIAN_BIG, +}; + +static int mcp47feb02_write_to_eeprom(struct mcp47feb02_data *data, unsign= ed int reg, + unsigned int val) +{ + int eewa_val, ret; + + /* + * Wait until the currently occurring EEPROM Write Cycle is completed. + * Only serial commands to the volatile memory are allowed. + */ + guard(mutex)(&data->lock); + + ret =3D regmap_read_poll_timeout(data->regmap, MCP47FEB02_GAIN_CTRL_STATU= S_REG_ADDR, + eewa_val, + !(eewa_val & MCP47FEB02_GAIN_BIT_STATUS_EEWA_MASK), + USEC_PER_MSEC, USEC_PER_MSEC * 5); + if (ret) + return ret; + + return regmap_write(data->regmap, reg, val); +} + +static ssize_t store_eeprom_store(struct device *dev, struct device_attrib= ute *attr, + const char *buf, size_t len) +{ + struct mcp47feb02_data *data =3D iio_priv(dev_to_iio_dev(dev)); + unsigned int i, val, val1, eewa_val; + bool state; + int ret; + + ret =3D kstrtobool(buf, &state); + if (ret) + return ret; + + if (!state) + return 0; + + /* + * Verify DAC Wiper and DAC Configuration are unlocked. If both are disab= led, + * writing to EEPROM is available. + */ + ret =3D regmap_read(data->regmap, MCP47FEB02_WIPERLOCK_STATUS_REG_ADDR, &= val); + if (ret) + return ret; + + if (val) { + dev_err(dev, "DAC Wiper and DAC Configuration not are unlocked.\n"); + return -EINVAL; + } + + for_each_set_bit(i, &data->active_channels_mask, data->phys_channels) { + ret =3D mcp47feb02_write_to_eeprom(data, NV_REG_ADDR(i), + data->chdata[i].dac_data); + if (ret) + return ret; + } + + ret =3D regmap_read(data->regmap, MCP47FEB02_VREF_REG_ADDR, &val); + if (ret) + return ret; + + ret =3D mcp47feb02_write_to_eeprom(data, MCP47FEB02_NV_VREF_REG_ADDR, val= ); + if (ret) + return ret; + + ret =3D regmap_read(data->regmap, MCP47FEB02_POWER_DOWN_REG_ADDR, &val); + if (ret) + return ret; + + ret =3D mcp47feb02_write_to_eeprom(data, MCP47FEB02_NV_POWER_DOWN_REG_ADD= R, val); + if (ret) + return ret; + + ret =3D regmap_read_poll_timeout(data->regmap, MCP47FEB02_GAIN_CTRL_STATU= S_REG_ADDR, eewa_val, + !(eewa_val & MCP47FEB02_GAIN_BIT_STATUS_EEWA_MASK), + USEC_PER_MSEC, USEC_PER_MSEC * 5); + if (ret) + return ret; + + ret =3D regmap_read(data->regmap, MCP47FEB02_NV_GAIN_CTRL_I2C_SLAVE_REG_A= DDR, &val); + if (ret) + return ret; + + ret =3D regmap_read(data->regmap, MCP47FEB02_GAIN_CTRL_STATUS_REG_ADDR, &= val1); + if (ret) + return ret; + + ret =3D mcp47feb02_write_to_eeprom(data, MCP47FEB02_NV_GAIN_CTRL_I2C_SLAV= E_REG_ADDR, + (val1 & MCP47FEB02_GAIN_BITS_MASK) | + (val & MCP47FEB02_NV_I2C_SLAVE_ADDR_MASK)); + if (ret) + return ret; + + return len; +} + +static IIO_DEVICE_ATTR_WO(store_eeprom, 0); + +static struct attribute *mcp47feb02_attributes[] =3D { + &iio_dev_attr_store_eeprom.dev_attr.attr, + NULL +}; + +static const struct attribute_group mcp47feb02_attribute_group =3D { + .attrs =3D mcp47feb02_attributes, +}; + +static int mcp47feb02_suspend(struct device *dev) +{ + struct iio_dev *indio_dev =3D dev_get_drvdata(dev); + struct mcp47feb02_data *data =3D iio_priv(indio_dev); + int ret; + u8 ch; + + guard(mutex)(&data->lock); + + for_each_set_bit(ch, &data->active_channels_mask, data->phys_channels) { + u8 pd_mode; + + data->chdata[ch].powerdown =3D true; + pd_mode =3D data->chdata[ch].powerdown_mode + 1; + ret =3D regmap_update_bits(data->regmap, MCP47FEB02_POWER_DOWN_REG_ADDR, + DAC_CTRL_MASK(ch), DAC_CTRL_VAL(ch, pd_mode)); + if (ret) + return ret; + + ret =3D regmap_write(data->regmap, REG_ADDR(ch), data->chdata[ch].dac_da= ta); + if (ret) + return ret; + } + + return 0; +} + +static int mcp47feb02_resume(struct device *dev) +{ + struct iio_dev *indio_dev =3D dev_get_drvdata(dev); + struct mcp47feb02_data *data =3D iio_priv(indio_dev); + u8 ch; + + guard(mutex)(&data->lock); + + for_each_set_bit(ch, &data->active_channels_mask, data->phys_channels) { + u8 pd_mode; + int ret; + + data->chdata[ch].powerdown =3D false; + pd_mode =3D data->chdata[ch].powerdown_mode + 1; + + ret =3D regmap_write(data->regmap, REG_ADDR(ch), data->chdata[ch].dac_da= ta); + if (ret) + return ret; + + ret =3D regmap_update_bits(data->regmap, MCP47FEB02_VREF_REG_ADDR, + DAC_CTRL_MASK(ch), DAC_CTRL_VAL(ch, pd_mode)); + if (ret) + return ret; + + ret =3D regmap_update_bits(data->regmap, MCP47FEB02_GAIN_CTRL_STATUS_REG= _ADDR, + DAC_GAIN_MASK(ch), + DAC_GAIN_VAL(ch, data->chdata[ch].use_2x_gain)); + if (ret) + return ret; + + ret =3D regmap_update_bits(data->regmap, MCP47FEB02_POWER_DOWN_REG_ADDR, + DAC_CTRL_MASK(ch), + DAC_CTRL_VAL(ch, MCP47FEB02_NORMAL_OPERATION)); + if (ret) + return ret; + } + + return 0; +} + +static int mcp47feb02_get_powerdown_mode(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct mcp47feb02_data *data =3D iio_priv(indio_dev); + + return data->chdata[chan->address].powerdown_mode; +} + +static int mcp47feb02_set_powerdown_mode(struct iio_dev *indio_dev, const = struct iio_chan_spec *ch, + unsigned int mode) +{ + struct mcp47feb02_data *data =3D iio_priv(indio_dev); + + data->chdata[ch->address].powerdown_mode =3D mode; + + return 0; +} + +static ssize_t mcp47feb02_read_powerdown(struct iio_dev *indio_dev, uintpt= r_t private, + const struct iio_chan_spec *ch, char *buf) +{ + struct mcp47feb02_data *data =3D iio_priv(indio_dev); + + /* Print if channel is in a power-down mode or not */ + return sysfs_emit(buf, "%d\n", data->chdata[ch->address].powerdown); +} + +static ssize_t mcp47feb02_write_powerdown(struct iio_dev *indio_dev, uintp= tr_t private, + const struct iio_chan_spec *ch, const char *buf, + size_t len) +{ + struct mcp47feb02_data *data =3D iio_priv(indio_dev); + u32 reg =3D ch->address; + u8 tmp_pd_mode; + bool state; + int ret; + + guard(mutex)(&data->lock); + + ret =3D kstrtobool(buf, &state); + if (ret) + return ret; + + /* + * Set the channel to the specified power-down mode. Exiting power-down m= ode + * requires writing normal operation mode (0) to the channel-specific reg= ister bits. + */ + tmp_pd_mode =3D state ? (data->chdata[reg].powerdown_mode + 1) : MCP47FEB= 02_NORMAL_OPERATION; + ret =3D regmap_update_bits(data->regmap, MCP47FEB02_POWER_DOWN_REG_ADDR, + DAC_CTRL_MASK(reg), DAC_CTRL_VAL(reg, tmp_pd_mode)); + if (ret) + return ret; + + data->chdata[reg].powerdown =3D state; + + return len; +} + +static DEFINE_SIMPLE_DEV_PM_OPS(mcp47feb02_pm_ops, mcp47feb02_suspend, mcp= 47feb02_resume); + +static const struct iio_enum mcp47febxx_powerdown_mode_enum =3D { + .items =3D mcp47feb02_powerdown_modes, + .num_items =3D ARRAY_SIZE(mcp47feb02_powerdown_modes), + .get =3D mcp47feb02_get_powerdown_mode, + .set =3D mcp47feb02_set_powerdown_mode, +}; + +static const struct iio_chan_spec_ext_info mcp47feb02_ext_info[] =3D { + { + .name =3D "powerdown", + .read =3D mcp47feb02_read_powerdown, + .write =3D mcp47feb02_write_powerdown, + .shared =3D IIO_SEPARATE, + }, + IIO_ENUM("powerdown_mode", IIO_SEPARATE, &mcp47febxx_powerdown_mode_enum), + IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, &mcp47febxx_powe= rdown_mode_enum), + { } +}; + +static const struct iio_chan_spec mcp47febxx_ch_template =3D { + .type =3D IIO_VOLTAGE, + .output =3D 1, + .indexed =3D 1, + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + .info_mask_separate_available =3D BIT(IIO_CHAN_INFO_SCALE), + .ext_info =3D mcp47feb02_ext_info, +}; + +static void mcp47feb02_init_scale(struct mcp47feb02_data *data, enum mcp47= feb02_scale scale, + int vref_mV, int scale_avail[]) +{ + u32 value_micro, value_int; + u64 tmp; + + /* vref_mV should not be negative */ + tmp =3D (u64)vref_mV * MICRO >> data->chip_features->resolution; + value_int =3D div_u64_rem(tmp, MICRO, &value_micro); + scale_avail[scale * 2] =3D value_int; + scale_avail[scale * 2 + 1] =3D value_micro; +} + +static int mcp47feb02_init_scales_avail(struct mcp47feb02_data *data, int = vdd_mV, + int vref_mV, int vref1_mV) +{ + struct device *dev =3D regmap_get_device(data->regmap); + int tmp_vref; + + mcp47feb02_init_scale(data, MCP47FEB02_SCALE_VDD, vdd_mV, data->scale); + + if (data->use_vref) + tmp_vref =3D vref_mV; + else + tmp_vref =3D MCP47FEB02_INTERNAL_BAND_GAP_mV; + + mcp47feb02_init_scale(data, MCP47FEB02_SCALE_GAIN_X1, tmp_vref, data->sca= le); + mcp47feb02_init_scale(data, MCP47FEB02_SCALE_GAIN_X2, tmp_vref * 2, data-= >scale); + + if (data->phys_channels >=3D 4) { + mcp47feb02_init_scale(data, MCP47FEB02_SCALE_VDD, vdd_mV, data->scale_1); + + if (data->use_vref1 && vref1_mV <=3D 0) + return dev_err_probe(dev, vref1_mV, "Invalid voltage for Vref1\n"); + + if (data->use_vref1) + tmp_vref =3D vref1_mV; + else + tmp_vref =3D MCP47FEB02_INTERNAL_BAND_GAP_mV; + + mcp47feb02_init_scale(data, MCP47FEB02_SCALE_GAIN_X1, + tmp_vref, data->scale_1); + mcp47feb02_init_scale(data, MCP47FEB02_SCALE_GAIN_X2, + tmp_vref * 2, data->scale_1); + } + + return 0; +} + +static int mcp47feb02_read_avail(struct iio_dev *indio_dev, struct iio_cha= n_spec const *ch, + const int **vals, int *type, int *length, long info) +{ + struct mcp47feb02_data *data =3D iio_priv(indio_dev); + + switch (info) { + case IIO_CHAN_INFO_SCALE: + switch (ch->type) { + case IIO_VOLTAGE: + if (data->phys_channels >=3D 4 && (ch->address % 2)) + *vals =3D data->scale_1; + else + *vals =3D data->scale; + + *length =3D 2 * MCP47FEB02_MAX_SCALES_CH; + *type =3D IIO_VAL_INT_PLUS_MICRO; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } + default: + return -EINVAL; + } +} + +static void mcp47feb02_get_scale(int ch, struct mcp47feb02_data *data, int= *val, int *val2) +{ + enum mcp47feb02_scale current_scale; + + if (data->chdata[ch].ref_mode =3D=3D MCP47FEB02_VREF_VDD) + current_scale =3D MCP47FEB02_SCALE_VDD; + else if (data->chdata[ch].use_2x_gain) + current_scale =3D MCP47FEB02_SCALE_GAIN_X2; + else + current_scale =3D MCP47FEB02_SCALE_GAIN_X1; + + if (data->phys_channels >=3D 4 && (ch % 2)) { + *val =3D data->scale_1[current_scale * 2]; + *val2 =3D data->scale_1[current_scale * 2 + 1]; + } else { + *val =3D data->scale[current_scale * 2]; + *val2 =3D data->scale[current_scale * 2 + 1]; + } +} + +static int mcp47feb02_check_scale(struct mcp47feb02_data *data, int val, i= nt val2, int scale[]) +{ + unsigned int i; + + for (i =3D 0; i < MCP47FEB02_MAX_SCALES_CH; i++) { + if (scale[i * 2] =3D=3D val && scale[i * 2 + 1] =3D=3D val2) + return i; + } + + return -EINVAL; +} + +static int mcp47feb02_ch_scale(struct mcp47feb02_data *data, int ch, int s= cale) +{ + int tmp_val, ret; + + if (scale =3D=3D MCP47FEB02_SCALE_VDD) { + tmp_val =3D MCP47FEB02_VREF_VDD; + } else if (data->phys_channels >=3D 4 && (ch % 2)) { + if (data->use_vref1) { + if (data->vref1_buffered) + tmp_val =3D MCP47FEB02_EXTERNAL_VREF_BUFFERED; + else + tmp_val =3D MCP47FEB02_EXTERNAL_VREF_UNBUFFERED; + } else { + tmp_val =3D MCP47FEB02_INTERNAL_BAND_GAP; + } + } else if (data->use_vref) { + if (data->vref_buffered) + tmp_val =3D MCP47FEB02_EXTERNAL_VREF_BUFFERED; + else + tmp_val =3D MCP47FEB02_EXTERNAL_VREF_UNBUFFERED; + } else { + tmp_val =3D MCP47FEB02_INTERNAL_BAND_GAP; + } + + ret =3D regmap_update_bits(data->regmap, MCP47FEB02_VREF_REG_ADDR, + DAC_CTRL_MASK(ch), DAC_CTRL_VAL(ch, tmp_val)); + if (ret) + return ret; + + data->chdata[ch].ref_mode =3D tmp_val; + + return 0; +} + +/* + * Setting the scale in order to choose between VDD and (Vref or Band Gap)= from the user + * space. The VREF pin is either an input or an output, therefore the user= cannot + * simultaneously connect an external voltage reference to the pin and sel= ect the + * internal Band Gap. + * When the DAC=E2=80=99s voltage reference is configured as the VREF pin,= the pin is an input. + * When the DAC=E2=80=99s voltage reference is configured as the internal = Band Gap, + * the VREF pin is an output. + * If Vref/Vref1 voltage is not available, then the internal Band Gap will= be used + * to calculate the values for the scale. + */ +static int mcp47feb02_set_scale(struct mcp47feb02_data *data, int ch, int = scale) +{ + int tmp_val, ret; + + ret =3D mcp47feb02_ch_scale(data, ch, scale); + if (ret) + return ret; + + if (scale =3D=3D MCP47FEB02_SCALE_GAIN_X2) + tmp_val =3D MCP47FEB02_GAIN_BIT_X2; + else + tmp_val =3D MCP47FEB02_GAIN_BIT_X1; + + ret =3D regmap_update_bits(data->regmap, MCP47FEB02_GAIN_CTRL_STATUS_REG_= ADDR, + DAC_GAIN_MASK(ch), DAC_GAIN_VAL(ch, tmp_val)); + if (ret) + return ret; + + data->chdata[ch].use_2x_gain =3D tmp_val; + + return 0; +} + +static int mcp47feb02_read_raw(struct iio_dev *indio_dev, struct iio_chan_= spec const *ch, + int *val, int *val2, long mask) +{ + struct mcp47feb02_data *data =3D iio_priv(indio_dev); + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret =3D regmap_read(data->regmap, REG_ADDR(ch->address), val); + if (ret) + return ret; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + mcp47feb02_get_scale(ch->address, data, val, val2); + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } +} + +static int mcp47feb02_write_raw(struct iio_dev *indio_dev, struct iio_chan= _spec const *ch, + int val, int val2, long mask) +{ + struct mcp47feb02_data *data =3D iio_priv(indio_dev); + int *tmp_scale, ret; + + guard(mutex)(&data->lock); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret =3D regmap_write(data->regmap, REG_ADDR(ch->address), val); + if (ret) + return ret; + + data->chdata[ch->address].dac_data =3D val; + return 0; + case IIO_CHAN_INFO_SCALE: + if (data->phys_channels >=3D 4 && (ch->address % 2)) + tmp_scale =3D data->scale_1; + else + tmp_scale =3D data->scale; + + ret =3D mcp47feb02_check_scale(data, val, val2, tmp_scale); + if (ret < 0) + return ret; + + return mcp47feb02_set_scale(data, ch->address, ret); + default: + return -EINVAL; + } +} + +static int mcp47feb02_read_label(struct iio_dev *indio_dev, struct iio_cha= n_spec const *ch, + char *label) +{ + struct mcp47feb02_data *data =3D iio_priv(indio_dev); + + return sysfs_emit(label, "%s\n", data->labels[ch->address]); +} + +static const struct iio_info mcp47feb02_info =3D { + .read_raw =3D mcp47feb02_read_raw, + .write_raw =3D mcp47feb02_write_raw, + .read_label =3D mcp47feb02_read_label, + .read_avail =3D &mcp47feb02_read_avail, + .attrs =3D &mcp47feb02_attribute_group, +}; + +static const struct iio_info mcp47fvb02_info =3D { + .read_raw =3D mcp47feb02_read_raw, + .write_raw =3D mcp47feb02_write_raw, + .read_label =3D mcp47feb02_read_label, + .read_avail =3D &mcp47feb02_read_avail, +}; + +static int mcp47feb02_parse_fw(struct iio_dev *indio_dev, + const struct mcp47feb02_features *chip_features) +{ + struct iio_chan_spec chanspec =3D mcp47febxx_ch_template; + struct mcp47feb02_data *data =3D iio_priv(indio_dev); + struct device *dev =3D regmap_get_device(data->regmap); + struct iio_chan_spec *channels; + u32 num_channels; + u8 chan_idx =3D 0; + + guard(mutex)(&data->lock); + + num_channels =3D device_get_child_node_count(dev); + if (num_channels > chip_features->phys_channels) + return dev_err_probe(dev, -EINVAL, "More channels than the chip supports= \n"); + + if (!num_channels) + return dev_err_probe(dev, -EINVAL, "No channel specified in the devicetr= ee.\n"); + + channels =3D devm_kcalloc(dev, num_channels, sizeof(*channels), GFP_KERNE= L); + if (!channels) + return -ENOMEM; + + device_for_each_child_node_scoped(dev, child) { + u32 reg =3D 0; + int ret; + + ret =3D fwnode_property_read_u32(child, "reg", ®); + if (ret) + return dev_err_probe(dev, ret, "Invalid channel number\n"); + + if (reg >=3D chip_features->phys_channels) + return dev_err_probe(dev, -EINVAL, + "The index of the channels does not match the chip\n"); + + set_bit(reg, &data->active_channels_mask); + + ret =3D fwnode_property_read_string(child, "label", &data->labels[reg]); + if (ret) + return dev_err_probe(dev, ret, "%pfw: invalid label\n", + fwnode_get_name(child)); + + chanspec.address =3D reg; + chanspec.channel =3D reg; + channels[chan_idx] =3D chanspec; + chan_idx++; + } + + indio_dev->num_channels =3D num_channels; + indio_dev->channels =3D channels; + indio_dev->modes =3D INDIO_DIRECT_MODE; + data->phys_channels =3D chip_features->phys_channels; + + data->vref_buffered =3D device_property_read_bool(dev, "microchip,vref-bu= ffered"); + + if (chip_features->have_ext_vref1) + data->vref1_buffered =3D device_property_read_bool(dev, "microchip,vref1= -buffered"); + + return 0; +} + +static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data) +{ + unsigned int i, vref_ch, gain_ch, pd_ch; + int ret; + + ret =3D regmap_read(data->regmap, MCP47FEB02_VREF_REG_ADDR, &vref_ch); + if (ret) + return ret; + + ret =3D regmap_read(data->regmap, MCP47FEB02_GAIN_CTRL_STATUS_REG_ADDR, &= gain_ch); + if (ret) + return ret; + + ret =3D regmap_read(data->regmap, MCP47FEB02_POWER_DOWN_REG_ADDR, &pd_ch); + if (ret) + return ret; + + gain_ch =3D gain_ch & MCP47FEB02_GAIN_BITS_MASK; + for_each_set_bit(i, &data->active_channels_mask, data->phys_channels) { + struct device *dev =3D regmap_get_device(data->regmap); + unsigned int pd_tmp; + + data->chdata[i].ref_mode =3D (vref_ch >> (2 * i)) & MCP47FEB02_DAC_CTRL_= MASK; + data->chdata[i].use_2x_gain =3D (gain_ch >> i) & MCP47FEB02_GAIN_BIT_MA= SK; + + /* + * Inform the user that the current voltage reference read from the vola= tile + * register of the chip is different from the one specified in the devic= e tree. + * Considering that the user cannot have an external voltage reference c= onnected + * to the pin and select the internal Band Gap at the same time, in orde= r to avoid + * miscofiguring the reference voltage, the volatile register will not b= e written. + * In order to overwrite the setting from volatile register with the one= from the + * device tree, the user needs to write the chosen scale. + */ + switch (data->chdata[i].ref_mode) { + case MCP47FEB02_INTERNAL_BAND_GAP: + if (data->phys_channels >=3D 4 && (i % 2) && data->use_vref1) { + dev_dbg(dev, "ch[%u]: was configured to use internal band gap", i); + dev_dbg(dev, "ch[%u]: reference voltage set to VREF1", i); + break; + } + if ((data->phys_channels < 4 || (data->phys_channels >=3D 4 && !(i % 2)= )) && + data->use_vref) { + dev_dbg(dev, "ch[%u]: was configured to use internal band gap", i); + dev_dbg(dev, "ch[%u]: reference voltage set to VREF", i); + break; + } + break; + case MCP47FEB02_EXTERNAL_VREF_UNBUFFERED: + case MCP47FEB02_EXTERNAL_VREF_BUFFERED: + if (data->phys_channels >=3D 4 && (i % 2) && !data->use_vref1) { + dev_dbg(dev, "ch[%u]: was configured to use VREF1", i); + dev_dbg(dev, + "ch[%u]: reference voltage set to internal band gap", i); + break; + } + if ((data->phys_channels < 4 || (data->phys_channels >=3D 4 && !(i % 2)= )) && + !data->use_vref) { + dev_dbg(dev, "ch[%u]: was configured to use VREF", i); + dev_dbg(dev, + "ch[%u]: reference voltage set to internal band gap", i); + break; + } + break; + } + + pd_tmp =3D (pd_ch >> (2 * i)) & MCP47FEB02_DAC_CTRL_MASK; + data->chdata[i].powerdown_mode =3D pd_tmp ? (pd_tmp - 1) : pd_tmp; + data->chdata[i].powerdown =3D !!(data->chdata[i].powerdown_mode); + } + + return 0; +} + +static int mcp47feb02_init_ch_scales(struct mcp47feb02_data *data, int vdd= _mV, + int vref_mV, int vref1_mV) +{ + unsigned int i; + + for_each_set_bit(i, &data->active_channels_mask, data->phys_channels) { + struct device *dev =3D regmap_get_device(data->regmap); + int ret; + + ret =3D mcp47feb02_init_scales_avail(data, vdd_mV, vref_mV, vref1_mV); + if (ret) + return dev_err_probe(dev, ret, "failed to init scales for ch %u\n", i); + } + + return 0; +} + +static int mcp47feb02_probe(struct i2c_client *client) +{ + const struct mcp47feb02_features *chip_features; + struct device *dev =3D &client->dev; + struct mcp47feb02_data *data; + struct iio_dev *indio_dev; + int vref1_mV =3D 0; + int vref_mV =3D 0; + int vdd_mV; + int ret; + + indio_dev =3D devm_iio_device_alloc(dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data =3D iio_priv(indio_dev); + chip_features =3D i2c_get_match_data(client); + if (!chip_features) + return -EINVAL; + + data->chip_features =3D chip_features; + + if (chip_features->have_eeprom) { + data->regmap =3D devm_regmap_init_i2c(client, &mcp47feb02_regmap_config); + indio_dev->info =3D &mcp47feb02_info; + } else { + data->regmap =3D devm_regmap_init_i2c(client, &mcp47fvb02_regmap_config); + indio_dev->info =3D &mcp47fvb02_info; + } + if (IS_ERR(data->regmap)) + return dev_err_probe(dev, PTR_ERR(data->regmap), "Error initializing i2c= regmap\n"); + + indio_dev->name =3D chip_features->name; + + ret =3D mcp47feb02_parse_fw(indio_dev, chip_features); + if (ret) + return dev_err_probe(dev, ret, "Error parsing firmware data\n"); + + ret =3D devm_mutex_init(dev, &data->lock); + if (ret) + return ret; + + ret =3D devm_regulator_get_enable_read_voltage(dev, "vdd"); + if (ret < 0) + return ret; + + vdd_mV =3D ret / MILLI; + + ret =3D devm_regulator_get_enable_read_voltage(dev, "vref"); + if (ret > 0) { + vref_mV =3D ret / MILLI; + data->use_vref =3D true; + } else { + dev_dbg(dev, "using internal band gap as voltage reference.\n"); + dev_dbg(dev, "Vref is unavailable.\n"); + } + + if (chip_features->have_ext_vref1) { + ret =3D devm_regulator_get_enable_read_voltage(dev, "vref1"); + if (ret > 0) { + vref1_mV =3D ret / MILLI; + data->use_vref1 =3D true; + } else { + dev_dbg(dev, "using internal band gap as voltage reference 1.\n"); + dev_dbg(dev, "Vref1 is unavailable.\n"); + } + } + + ret =3D mcp47feb02_init_ctrl_regs(data); + if (ret) + return dev_err_probe(dev, ret, "Error initialising vref register\n"); + + ret =3D mcp47feb02_init_ch_scales(data, vdd_mV, vref_mV, vref1_mV); + if (ret) + return ret; + + return devm_iio_device_register(dev, indio_dev); +} + +static const struct i2c_device_id mcp47feb02_id[] =3D { + { "mcp47feb01", (kernel_ulong_t)&mcp47feb01_chip_features }, + { "mcp47feb02", (kernel_ulong_t)&mcp47feb02_chip_features }, + { "mcp47feb04", (kernel_ulong_t)&mcp47feb04_chip_features }, + { "mcp47feb08", (kernel_ulong_t)&mcp47feb08_chip_features }, + { "mcp47feb11", (kernel_ulong_t)&mcp47feb11_chip_features }, + { "mcp47feb12", (kernel_ulong_t)&mcp47feb12_chip_features }, + { "mcp47feb14", (kernel_ulong_t)&mcp47feb14_chip_features }, + { "mcp47feb18", (kernel_ulong_t)&mcp47feb18_chip_features }, + { "mcp47feb21", (kernel_ulong_t)&mcp47feb21_chip_features }, + { "mcp47feb22", (kernel_ulong_t)&mcp47feb22_chip_features }, + { "mcp47feb24", (kernel_ulong_t)&mcp47feb24_chip_features }, + { "mcp47feb28", (kernel_ulong_t)&mcp47feb28_chip_features }, + { "mcp47fvb01", (kernel_ulong_t)&mcp47fvb01_chip_features }, + { "mcp47fvb02", (kernel_ulong_t)&mcp47fvb02_chip_features }, + { "mcp47fvb04", (kernel_ulong_t)&mcp47fvb04_chip_features }, + { "mcp47fvb08", (kernel_ulong_t)&mcp47fvb08_chip_features }, + { "mcp47fvb11", (kernel_ulong_t)&mcp47fvb11_chip_features }, + { "mcp47fvb12", (kernel_ulong_t)&mcp47fvb12_chip_features }, + { "mcp47fvb14", (kernel_ulong_t)&mcp47fvb14_chip_features }, + { "mcp47fvb18", (kernel_ulong_t)&mcp47fvb18_chip_features }, + { "mcp47fvb21", (kernel_ulong_t)&mcp47fvb21_chip_features }, + { "mcp47fvb22", (kernel_ulong_t)&mcp47fvb22_chip_features }, + { "mcp47fvb24", (kernel_ulong_t)&mcp47fvb24_chip_features }, + { "mcp47fvb28", (kernel_ulong_t)&mcp47fvb28_chip_features }, + { } +}; +MODULE_DEVICE_TABLE(i2c, mcp47feb02_id); + +static const struct of_device_id mcp47feb02_of_match[] =3D { + { .compatible =3D "microchip,mcp47feb01", .data =3D &mcp47feb01_chip_feat= ures }, + { .compatible =3D "microchip,mcp47feb02", .data =3D &mcp47feb02_chip_feat= ures }, + { .compatible =3D "microchip,mcp47feb04", .data =3D &mcp47feb04_chip_feat= ures }, + { .compatible =3D "microchip,mcp47feb08", .data =3D &mcp47feb08_chip_feat= ures }, + { .compatible =3D "microchip,mcp47feb11", .data =3D &mcp47feb11_chip_feat= ures }, + { .compatible =3D "microchip,mcp47feb12", .data =3D &mcp47feb12_chip_feat= ures }, + { .compatible =3D "microchip,mcp47feb14", .data =3D &mcp47feb14_chip_feat= ures }, + { .compatible =3D "microchip,mcp47feb18", .data =3D &mcp47feb18_chip_feat= ures }, + { .compatible =3D "microchip,mcp47feb21", .data =3D &mcp47feb21_chip_feat= ures }, + { .compatible =3D "microchip,mcp47feb22", .data =3D &mcp47feb22_chip_feat= ures }, + { .compatible =3D "microchip,mcp47feb24", .data =3D &mcp47feb24_chip_feat= ures }, + { .compatible =3D "microchip,mcp47feb28", .data =3D &mcp47feb28_chip_feat= ures }, + { .compatible =3D "microchip,mcp47fvb01", .data =3D &mcp47fvb01_chip_feat= ures }, + { .compatible =3D "microchip,mcp47fvb02", .data =3D &mcp47fvb02_chip_feat= ures }, + { .compatible =3D "microchip,mcp47fvb04", .data =3D &mcp47fvb04_chip_feat= ures }, + { .compatible =3D "microchip,mcp47fvb08", .data =3D &mcp47fvb08_chip_feat= ures }, + { .compatible =3D "microchip,mcp47fvb11", .data =3D &mcp47fvb11_chip_feat= ures }, + { .compatible =3D "microchip,mcp47fvb12", .data =3D &mcp47fvb12_chip_feat= ures }, + { .compatible =3D "microchip,mcp47fvb14", .data =3D &mcp47fvb14_chip_feat= ures }, + { .compatible =3D "microchip,mcp47fvb18", .data =3D &mcp47fvb18_chip_feat= ures }, + { .compatible =3D "microchip,mcp47fvb21", .data =3D &mcp47fvb21_chip_feat= ures }, + { .compatible =3D "microchip,mcp47fvb22", .data =3D &mcp47fvb22_chip_feat= ures }, + { .compatible =3D "microchip,mcp47fvb24", .data =3D &mcp47fvb24_chip_feat= ures }, + { .compatible =3D "microchip,mcp47fvb28", .data =3D &mcp47fvb28_chip_feat= ures }, + { } +}; +MODULE_DEVICE_TABLE(of, mcp47feb02_of_match); + +static struct i2c_driver mcp47feb02_driver =3D { + .driver =3D { + .name =3D "mcp47feb02", + .of_match_table =3D mcp47feb02_of_match, + .pm =3D pm_sleep_ptr(&mcp47feb02_pm_ops), + }, + .probe =3D mcp47feb02_probe, + .id_table =3D mcp47feb02_id, +}; +module_i2c_driver(mcp47feb02_driver); + +MODULE_AUTHOR("Ariana Lazar "); +MODULE_DESCRIPTION("IIO driver for MCP47FEB02 Multi-Channel DAC with I2C i= nterface"); +MODULE_LICENSE("GPL"); --=20 2.43.0