From nobody Tue Nov 24 04:35:09 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.38.64.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793965385; b=HzSYH8ybabmqtCIXfapMnP8fnvJMWcewL5lJWSBmznlbZgUOqCoupjrBujg30niJOaAM EGD9YDaN230YSVZ9v8eChPAjZboFXsmjLEIxWAXQvY/gAbCggChu8HKTZ0tWEB5rBYP+A Q6tAPLDKBQextm4TX+ps/aRDNB1r+VO65DVKp7+oyYCnmeYmFrtzzmTUO+LNV8ZOUmTsc V5soVWNQC28oDCgP6uecHNUg6K/pnAX27EO3r7zNIq4LhabTIgR1qQs+SMNuncEtcKubK 2ItiAv8TVZ2MjWmca01Qub0huu3csSvk6SnseWxoLkU26ehsisEghP8xL8/XxNEVqaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793965385; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=9q3QyFQZwiKpfJPvHT/cCB0sso+MEjau6PRiMe61Luc=; b=1try/8qaXl/GtIhyv5XSpWNf7A2yXc8t86oq73VFx4ot5wZfgLnEysUtvYQeP0eNvGje HUuXw2qtdtz7juizC3SOTsATZMycakM+vMnlp4QRI89Qn0unLSSG8AfMIIF1VNKDzk7/o a2SKMBKJnBmTxIxHJD3E9NAZOeFNGqVAe8jBpZ4gBhXUAvmOArWFqapZ/IUp/ekj9ydE/ W4xRJ4Kx/MkfO6GFO9PKYUY3wMcoKsmeNVIQ8WvUG6ohJ4kBybuz0X32LtPomGX+FAorr 61QUUtL+Tg1+S8K5ydNNWNWNBVudwfOzjLi/QPYRjDInDxpyruHuZAce2guGy+VYwdA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=mail.ustc.edu.cn; spf=pass smtp.mailfrom=mail.ustc.edu.cn; dkim=pass header.d=mail.ustc.edu.cn header.i=@mail.ustc.edu.cn header.a=rsa-sha256 header.s=dkim header.b=JcfmiEnL; arc=none smtp.remote-ip=202.38.64.46 Received: from ustc.edu.cn (smtp.ustc.edu.cn [202.38.64.46]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FA7A606A907; Fri, 6 Nov 2026 11:43:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8FA7A606A907 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mail.ustc.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mail.ustc.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=mail.ustc.edu.cn header.i=@mail.ustc.edu.cn header.a=rsa-sha256 header.s=dkim header.b=JcfmiEnL DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ustc.edu.cn; s=dkim; h=Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=9q3QyFQZwiKpfJPvHT/cCB0sso+MEjau6P RiMe61Luc=; b=JcfmiEnL4+6zk6//qQbk19P/vxyURTjQpII11GYlbmHgBEt73Y HmBD5ufatsvNFRqtLUUnlWjfurRELpbeGy19DEmoitAGpHSa4e/cuvDehVzHQpFj KLJ6GrqamtbhbnGHehps0ukcwrDW+5fUxHSZhNeMLUxmCliUAj2V1hh7k= Received: from xuqianhui.tail7a2807.ts.net (unknown [114.214.184.75]) by mailimap2024 (Coremail) with SMTP id 3pYKCgBn3DA8ve1qfj2PAA--.533S3; Fri, 06 Nov 2026 19:42:57 +0800 (CST) From: Qianhui Xu To: lgirdwood@gmail.com, broonie@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v8 1/2] regulator: dt-bindings: willsemi,wl2868c: add the WL2868C camera PMIC Date: Fri, 6 Nov 2026 19:42:51 +0800 Message-ID: <20261106114252.988023-2-xiaqinghuan@mail.ustc.edu.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261106114252.988023-1-xiaqinghuan@mail.ustc.edu.cn> References: <20261106114252.988023-1-xiaqinghuan@mail.ustc.edu.cn> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: 3pYKCgBn3DA8ve1qfj2PAA--.533S3 X-Coremail-Antispam: 1UD129KBjvJXoWxCrW5JF45urykZr17WF4kZwb_yoWrCw17pa 98GrsFkFsYkF1xG3yxK3Wfu3W3KF1rArn5Ar1UC34rGan0qFnaqwnIkw15Z3WFyrW8GFW2 yFyDZF47JF1rZrJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBmb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI 8067AKxVWUGwA2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF 64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcV CY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv 6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c 02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE 4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_Jw0_GFyl42xK82 IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC2 0s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMI IF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1l IxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4 A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUghIDDUUUU X-CM-SenderInfo: 50ld1x5qjk3t3q6ptxnoox23vfohv3gofq/1tbiAREDB2rs2VhhrAA6sk Content-Type: text/plain; charset="utf-8" The WL2868C is an I2C-controlled camera power management IC from Will Semiconductor. It provides seven programmable LDOs: LDO1 and LDO2 are fed from a shared VIN12 input and cover 0.496 V to 1.512 V, LDO3 and LDO4 share VIN34, and LDO5 to LDO7 each have their own input, covering 1.504 V to 3.544 V. All outputs are programmable in 8 mV steps and are gated by per-output enable bits with a chip-wide SYS_EN master. The chip also exposes an optional active-low RST_N input. VIN7 and VSYS are both inputs of the internal control logic, which is powered from the higher of the two voltages, so a device tree has to describe at least one of them. The remaining inputs only feed LDOs, so they stay optional: an input can be left unconnected when the outputs it feeds are unused on a given board. Signed-off-by: Qianhui Xu --- .../bindings/regulator/willsemi,wl2868c.yaml | 104 ++++++++++++++++++ MAINTAINERS | 7 ++ 2 files changed, 111 insertions(+) create mode 100644 Documentation/devicetree/bindings/regulator/willsemi,wl= 2868c.yaml diff --git a/Documentation/devicetree/bindings/regulator/willsemi,wl2868c.y= aml b/Documentation/devicetree/bindings/regulator/willsemi,wl2868c.yaml new file mode 100644 index 0000000000..df7990d0d8 --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/willsemi,wl2868c.yaml @@ -0,0 +1,104 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/regulator/willsemi,wl2868c.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Will Semiconductor WL2868C camera power management IC + +maintainers: + - Qianhui Xu + +description: + The WL2868C is a camera power management IC with seven programmable LDOs. + LDO1 and LDO2 share the VIN12 input and cover 0.496 V to 1.512 V; LDO3 a= nd + LDO4 share VIN34, and LDO5 to LDO7 have one input each, covering 1.504 V= to + 3.544 V. All outputs are programmable in 8 mV steps. + + VIN7 and VSYS feed the internal control logic, which is powered from the + higher of the two, so at least one of them has to be connected. The other + inputs only feed LDOs, so an input may be left unconnected on a board + that does not use the outputs it feeds, which is why they are not + mandatory. + +properties: + compatible: + const: willsemi,wl2868c + + reg: + maxItems: 1 + + reset-gpios: + maxItems: 1 + description: Active-low RST_N input. + + vin12-supply: + description: Input supply for LDO1 and LDO2. + + vin34-supply: + description: Input supply for LDO3 and LDO4. + + vin5-supply: + description: Input supply for LDO5. + + vin6-supply: + description: Input supply for LDO6. + + vin7-supply: + description: + Input supply for LDO7 and one of the two supplies of the internal + control logic. + + vsys-supply: + description: + System supply, the other supply of the internal control logic. The + control logic is powered from the higher of VIN7 and VSYS. + + regulators: + type: object + additionalProperties: false + + patternProperties: + "^ldo[1-7]$": + type: object + $ref: regulator.yaml# + unevaluatedProperties: false + +required: + - compatible + - reg + - regulators + +anyOf: + - required: + - vin7-supply + - required: + - vsys-supply + +additionalProperties: false + +examples: + - | + i2c { + #address-cells =3D <1>; + #size-cells =3D <0>; + + pmic@2f { + compatible =3D "willsemi,wl2868c"; + reg =3D <0x2f>; + vsys-supply =3D <&vsys_reg>; + + regulators { + ldo1 { + regulator-max-microvolt =3D <1128000>; + regulator-min-microvolt =3D <1128000>; + }; + }; + }; + }; + + vsys_reg: regulator-vsys { + compatible =3D "regulator-fixed"; + regulator-name =3D "vsys"; + }; +... diff --git a/MAINTAINERS b/MAINTAINERS index fe23913b1e..08cfa3db0e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -30180,6 +30180,13 @@ L: linux-input@vger.kernel.org S: Maintained F: drivers/hid/hid-wiimote* =20 +WILLSEMI WL2868C CAMERA PMIC +M: Qianhui Xu +L: linux-kernel@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/regulator/willsemi,wl2868c.yaml +F: drivers/regulator/wl2868c-regulator.c + WILOCITY WIL6210 WIRELESS DRIVER L: linux-wireless@vger.kernel.org S: Orphan From nobody Tue Nov 24 04:35:09 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.38.64.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793965390; b=4fsDhiDa+4Ka5k5aEZZz/4TJQvXmeTgVDHgv8kYg6vkJOgN0Q/Tc80p1o22frokgNqnV mBGbmCFY1boQKvABZrWE1cDdYwFoIGDkhlUzYtfd8EFusRNABMs+9JC7LMvcO6a3MM4ER uudghTtXgeImqwzBf20SxwfMfR1CrAX8vagkcFwnrdppIzjfJB/uI5qvOpFjpEG0mye7P TBY90gcU1mIsWO703grI3xlaR27xsQG2HGm1i7jLV708Xz3dFtycnfrCT1pZ0KE1+3INx 0puOF0aap6cHDrBYGTe2CbzRUb/Qml3A+mbCscc5LudHn7fmZHshmkWUYpOGJRFxzQA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793965390; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=lQhKFhqTK/py/+bxxobhuRvMFWyvoqHPsKRi9pJf9NE=; b=JdJolZEKWdUVyy0jthqzbeBUYEGyjS5AqH8zItTgnDzu/Y92kk57XIaKs6ZOoNFnsy7G 09ojnjPsgODPnSf1kWueuTxXugLkhfRFlLoYxEfNAi/mci83i99xk4Wl5ddVS5PQno2uC i4te9gvJUv6VL5oz6bKa7Rak8tGPgVLpvBraQnucPqomU1+5mgreInGiKFv1DhWazCYHP mHC5ztc7P+/UtDuqvPitUR9QmOwDFy4Z0kgGjzY3lzbPHhdzjahNACiQC1dB0fl2EhguU lMehmRoDVC+3C/3jIgNIAggN1+A0Vw1Dc7XvlbUyubwA4u8jir0r7AlVeuK+gJXc/pw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=mail.ustc.edu.cn; spf=pass smtp.mailfrom=mail.ustc.edu.cn; dkim=pass header.d=mail.ustc.edu.cn header.i=@mail.ustc.edu.cn header.a=rsa-sha256 header.s=dkim header.b=MiFy2cMg; arc=none smtp.remote-ip=202.38.64.46 Received: from ustc.edu.cn (smtp.ustc.edu.cn [202.38.64.46]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64055606A93B; Fri, 6 Nov 2026 11:43:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 64055606A93B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mail.ustc.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mail.ustc.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=mail.ustc.edu.cn header.i=@mail.ustc.edu.cn header.a=rsa-sha256 header.s=dkim header.b=MiFy2cMg DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ustc.edu.cn; s=dkim; h=Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=lQhKFhqTK/py/+bxxobhuRvMFWyvoqHPsK Ri9pJf9NE=; b=MiFy2cMg91XDBJqIXWWbJ5XuhC/6+6cymxIr69boNyuBdvmBPP tYulebUPzXhdYe5droI86iM77MU+g6kFcx4C2F3Bk7UDTa2PsdVE7zEU7k+vliHC JB/d26nrrh7zwAL949fdb06k4Ky+yDEFF+yKlPW0Wp2W50jG91o6y1r4Q= Received: from xuqianhui.tail7a2807.ts.net (unknown [114.214.184.75]) by mailimap2024 (Coremail) with SMTP id 3pYKCgBn3DA8ve1qfj2PAA--.533S4; Fri, 06 Nov 2026 19:43:01 +0800 (CST) From: Qianhui Xu To: lgirdwood@gmail.com, broonie@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v8 2/2] regulator: willsemi,wl2868c: add the WL2868C camera PMIC driver Date: Fri, 6 Nov 2026 19:42:52 +0800 Message-ID: <20261106114252.988023-3-xiaqinghuan@mail.ustc.edu.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261106114252.988023-1-xiaqinghuan@mail.ustc.edu.cn> References: <20261106114252.988023-1-xiaqinghuan@mail.ustc.edu.cn> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: 3pYKCgBn3DA8ve1qfj2PAA--.533S4 X-Coremail-Antispam: 1UD129KBjvJXoW3ZrWfGF4kKrWxuFyUCrWfZrb_yoWkXw13pF s8Jas3Kr4kGrWFgrZ7Ar1IvF1Ygrs2qryayry8C3yfZw17AFy2qF9a9FW5AFyDGrn7XFyS qayUJa48CF4DuaDanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBvb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI 8067AKxVWUXwA2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF 64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcV CY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv 6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c 02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE 4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_Jw0_GFyl42xK82 IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC2 0s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMI IF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI 42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z2 80aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07bFLvNUUUUU= X-CM-SenderInfo: 50ld1x5qjk3t3q6ptxnoox23vfohv3gofq/1tbiAREDB2rs2VhhrAA7sl Content-Type: text/plain; charset="utf-8" The WL2868C is an I2C camera power management IC with seven LDOs. LDO1 and LDO2 are fed from VIN12 and cover 0.496 V to 1.512 V with a 7-bit voltage selector; LDO3 and LDO4 share VIN34, and LDO5 to LDO7 have one input each, covering 1.504 V to 3.544 V with an 8-bit selector. All outputs step by 8 mV. Every output is gated by a per-LDO bit in the enable register, and the whole chip is additionally gated by the SYS_EN bit in the same register. The driver sets SYS_EN together with the LDO bit on enable and requires both to read back before reporting the regulator as enabled, because no output comes up while SYS_EN is clear. An optional active-low RST_N GPIO is released during probe, followed by a 1 ms delay for the device to come up, and is asserted again when the driver is unbound. The enable register is written as a whole rather than updated bit by bit: the per-LDO bits can be preset by the firmware while SYS_EN is clear, and setting SYS_EN together with a single LDO bit would then switch the preset outputs on as well. The driver therefore tracks the set of LDOs enabled by consumers and writes exactly those bits, so enabling one output cannot power another one. That set is seeded from the register during probe, so an output the firmware left on is not cleared by the first enable() of a different one, and disable() commits the tracked state only after the register write went through, so a failed write cannot make a later enable() switch off an output that the core still believes is on. The I2C interface is powered from the higher of VIN7 and VSYS, so the "vsys" supply is enabled for as long as the driver is bound, before the device ID is read; without it the device does not answer on the bus. Signed-off-by: Qianhui Xu --- drivers/regulator/Kconfig | 11 ++ drivers/regulator/Makefile | 1 + drivers/regulator/wl2868c-regulator.c | 246 ++++++++++++++++++++++++++ 3 files changed, 258 insertions(+) create mode 100644 drivers/regulator/wl2868c-regulator.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index be6b72daa7..f0a604afe5 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -1877,6 +1877,17 @@ config REGULATOR_VQMMC_IPQ4019 This driver provides support for the VQMMC LDO I/0 voltage regulator of the IPQ4019 SD/EMMC controller. =20 +config REGULATOR_WL2868C + tristate "Will Semiconductor WL2868C regulator" + depends on I2C + select REGMAP_I2C + help + Support the seven LDO outputs of the Will Semiconductor WL2868C + camera power management IC. + + To compile this driver as a module, choose M here: the + module will be called wl2868c-regulator. + config REGULATOR_WM831X tristate "Wolfson Microelectronics WM831x PMIC regulators" depends on MFD_WM831X diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 6aabcc5438..37ffa93a9c 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -214,6 +214,7 @@ obj-$(CONFIG_REGULATOR_RZG2L_VBCTRL) +=3D renesas-usb-v= bus-regulator.o obj-$(CONFIG_REGULATOR_VCTRL) +=3D vctrl-regulator.o obj-$(CONFIG_REGULATOR_VEXPRESS) +=3D vexpress-regulator.o obj-$(CONFIG_REGULATOR_VQMMC_IPQ4019) +=3D vqmmc-ipq4019-regulator.o +obj-$(CONFIG_REGULATOR_WL2868C) +=3D wl2868c-regulator.o obj-$(CONFIG_REGULATOR_WM831X) +=3D wm831x-dcdc.o obj-$(CONFIG_REGULATOR_WM831X) +=3D wm831x-isink.o obj-$(CONFIG_REGULATOR_WM831X) +=3D wm831x-ldo.o diff --git a/drivers/regulator/wl2868c-regulator.c b/drivers/regulator/wl28= 68c-regulator.c new file mode 100644 index 0000000000..64baeeacf3 --- /dev/null +++ b/drivers/regulator/wl2868c-regulator.c @@ -0,0 +1,246 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Will Semiconductor WL2868C seven-channel camera regulator driver. + * + * Copyright (C) 2026 Qianhui Xu + */ + +#include +#include +#include +#include +#include +#include +#include + +#define WL2868C_DEVICE_ID 0x00 +#define WL2868C_DEVICE_ID_VALUE 0x82 +#define WL2868C_LDO_ENABLE 0x0e +#define WL2868C_SYS_ENABLE BIT(7) +#define WL2868C_LDO_ENABLE_MASK GENMASK(6, 0) + +struct wl2868c { + struct regmap *regmap; + /* LDO enable bits owned by consumers, in WL2868C_LDO_ENABLE layout. */ + unsigned int enabled; + /* Protects enabled. */ + struct mutex lock; +}; + +static int wl2868c_enable(struct regulator_dev *rdev) +{ + struct wl2868c *chip =3D rdev_get_drvdata(rdev); + unsigned int bits =3D rdev->desc->enable_mask; + unsigned int ldos; + int ret; + + guard(mutex)(&chip->lock); + + /* + * The enable register is written as a whole on purpose. SYS_EN gates + * every output of the chip, and the per-LDO bits may be preset by the + * firmware while SYS_EN is still clear: setting only SYS_EN and our own + * bit would then bring the preset LDOs up as well. Writing the register + * with the bits of the LDOs consumers have enabled, and only those, + * keeps the other outputs off. chip->enabled was seeded from the + * register in probe(), so an output the firmware left on is carried + * over instead of being cleared by the first enable. + */ + ldos =3D (chip->enabled | bits) & WL2868C_LDO_ENABLE_MASK; + ret =3D regmap_write(chip->regmap, WL2868C_LDO_ENABLE, + WL2868C_SYS_ENABLE | ldos); + if (ret) + return ret; + + chip->enabled =3D ldos; + + return 0; +} + +static int wl2868c_disable(struct regulator_dev *rdev) +{ + struct wl2868c *chip =3D rdev_get_drvdata(rdev); + unsigned int bits =3D rdev->desc->enable_mask; + unsigned int ldos; + int ret; + + guard(mutex)(&chip->lock); + + /* + * SYS_EN stays set while at least one output is enabled; the per-LDO + * bits of the other outputs stay clear so that setting it cannot + * switch anything else on. + */ + ldos =3D (chip->enabled & ~bits) & WL2868C_LDO_ENABLE_MASK; + + /* + * The tracked state is committed only once the register write went + * through: a failed write leaves the output on, and the regulator core + * keeps its own use count unchanged, so dropping the bit here would + * make the next enable() of another output switch this one off. + */ + ret =3D regmap_write(chip->regmap, WL2868C_LDO_ENABLE, + ldos ? WL2868C_SYS_ENABLE | ldos : 0); + if (ret) + return ret; + + chip->enabled =3D ldos; + + return 0; +} + +static int wl2868c_is_enabled(struct regulator_dev *rdev) +{ + unsigned int mask =3D WL2868C_SYS_ENABLE | rdev->desc->enable_mask; + unsigned int value; + int ret; + + ret =3D regmap_read(rdev->regmap, WL2868C_LDO_ENABLE, &value); + if (ret) + return ret; + + return (value & mask) =3D=3D mask; +} + +static const struct regulator_ops wl2868c_ops =3D { + .list_voltage =3D regulator_list_voltage_linear, + .map_voltage =3D regulator_map_voltage_linear, + .set_voltage_sel =3D regulator_set_voltage_sel_regmap, + .get_voltage_sel =3D regulator_get_voltage_sel_regmap, + .enable =3D wl2868c_enable, + .disable =3D wl2868c_disable, + .is_enabled =3D wl2868c_is_enabled, +}; + +/* + * LDO1 and LDO2 have a 7-bit voltage selector, the other five have an 8-b= it + * one; all of them step by 8 mV. + */ +#define WL2868C_LDO(_num, _supply, _min, _n_voltages, _vsel_reg, _mask, _e= n) { \ + .name =3D "ldo" #_num, \ + .of_match =3D "ldo" #_num, \ + .regulators_node =3D "regulators", \ + .id =3D (_num) - 1, \ + .type =3D REGULATOR_VOLTAGE, \ + .owner =3D THIS_MODULE, \ + .ops =3D &wl2868c_ops, \ + .supply_name =3D _supply, \ + .min_uV =3D _min, \ + .uV_step =3D 8000, \ + .n_voltages =3D _n_voltages, \ + .vsel_reg =3D _vsel_reg, \ + .vsel_mask =3D _mask, \ + .enable_reg =3D WL2868C_LDO_ENABLE, \ + .enable_mask =3D _en, \ + .enable_time =3D 150, \ +} + +static const struct regulator_desc wl2868c_regulators[] =3D { + WL2868C_LDO(1, "vin12", 496000, 128, 0x03, 0x7f, BIT(0)), + WL2868C_LDO(2, "vin12", 496000, 128, 0x04, 0x7f, BIT(1)), + WL2868C_LDO(3, "vin34", 1504000, 256, 0x05, 0xff, BIT(2)), + WL2868C_LDO(4, "vin34", 1504000, 256, 0x06, 0xff, BIT(3)), + WL2868C_LDO(5, "vin5", 1504000, 256, 0x07, 0xff, BIT(4)), + WL2868C_LDO(6, "vin6", 1504000, 256, 0x08, 0xff, BIT(5)), + WL2868C_LDO(7, "vin7", 1504000, 256, 0x09, 0xff, BIT(6)), +}; + +static const struct regmap_config wl2868c_regmap_config =3D { + .reg_bits =3D 8, + .val_bits =3D 8, + .max_register =3D 0x25, +}; + +static void wl2868c_reset(void *data) +{ + gpiod_set_value_cansleep(data, 1); +} + +static int wl2868c_probe(struct i2c_client *client) +{ + struct device *dev =3D &client->dev; + struct regulator_config config =3D { .dev =3D dev }; + struct regulator_dev *rdev; + struct gpio_desc *reset; + struct wl2868c *chip; + unsigned int id, value; + int ret, i; + + chip =3D devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + mutex_init(&chip->lock); + config.driver_data =3D chip; + + reset =3D devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); + if (IS_ERR(reset)) + return dev_err_probe(dev, PTR_ERR(reset), "Failed to get reset GPIO\n"); + + if (reset) { + ret =3D devm_add_action_or_reset(dev, wl2868c_reset, reset); + if (ret) + return ret; + fsleep(1000); + } + + chip->regmap =3D devm_regmap_init_i2c(client, &wl2868c_regmap_config); + config.regmap =3D chip->regmap; + if (IS_ERR(config.regmap)) + return dev_err_probe(dev, PTR_ERR(config.regmap), + "Failed to create regmap\n"); + + /* + * The I2C interface is powered from the higher of VIN7 and VSYS, so the + * system supply has to be up before the device can answer at all. It + * stays enabled for as long as the driver is bound. + */ + ret =3D devm_regulator_get_enable(dev, "vsys"); + if (ret) + return dev_err_probe(dev, ret, "Failed to enable the system supply\n"); + + ret =3D regmap_read(config.regmap, WL2868C_DEVICE_ID, &id); + if (ret) + return dev_err_probe(dev, ret, "Failed to read device ID\n"); + if (id !=3D WL2868C_DEVICE_ID_VALUE) + return dev_err_probe(dev, -ENODEV, "Unexpected device ID: %#x\n", id); + + /* + * Seed the tracked set with the outputs the firmware left enabled, so + * that the first enable() or disable() of any output preserves them. + * The regulator core reads the state back through is_enabled(), which + * does not look at this set. + */ + ret =3D regmap_read(config.regmap, WL2868C_LDO_ENABLE, &value); + if (ret) + return dev_err_probe(dev, ret, "Failed to read the enable register\n"); + + chip->enabled =3D value & WL2868C_LDO_ENABLE_MASK; + + for (i =3D 0; i < ARRAY_SIZE(wl2868c_regulators); i++) { + rdev =3D devm_regulator_register(dev, &wl2868c_regulators[i], &config); + if (IS_ERR(rdev)) + return dev_err_probe(dev, PTR_ERR(rdev), + "Failed to register LDO%d\n", i + 1); + } + + return 0; +} + +static const struct of_device_id wl2868c_of_match[] =3D { + { .compatible =3D "willsemi,wl2868c" }, + { } +}; +MODULE_DEVICE_TABLE(of, wl2868c_of_match); + +static struct i2c_driver wl2868c_driver =3D { + .driver =3D { + .name =3D "wl2868c", + .of_match_table =3D wl2868c_of_match, + }, + .probe =3D wl2868c_probe, +}; +module_i2c_driver(wl2868c_driver); + +MODULE_DESCRIPTION("Will Semiconductor WL2868C regulator driver"); +MODULE_LICENSE("GPL");