From nobody Tue Nov 24 04:43:04 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=1794892982; b=nT5LWYih0BNefgdZuI8wkXrSRCrsP3VwwvTjj+v0N8SphnMZF8+j7n5kIIzte6Kt6p8f OY3LjhLVgK3SacbJwova8KTHZm5gfnQEz+bxuYNy74geaq1mxDsAj5FCeRTTohRUTfVNI BTeA50kt7wLL/kJ8Aq/+CiDVW38BX9xfVNcIBgp1FPgQfC+9/IYBRaQGnEJRfAaiAk9n0 yYkwUbHuf4M6//gZFGGm49r/XDLw8zy5s5hqISeeuJZBTiLaFH8lY+h2UO2Asn9/JiC1J /lZE9CB+5MSvgElsg5tSk3DtwGA2GIesRGm0BvqYFxBOA0SjON2n/bKubtvfxx1Npig== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794892982; 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=31b9JNt65Yxrug1LN8vG9BjZbzLc7SOgE34Mxiobvik=; b=PcPMVponCZyzZ1EHLQIMxa1cbR5XbxE3Sm0UDOKfqqw/ELFEMoHALbDcrntoOk6735mw tjzwWlJQhez9BmvVGBfZNCmkss0eOgVOnhAxHLIqp62OSKBmWKB0Kf3NoESqM2vsLsanM 8lXXDdCq1rYWaMw4b3pRsIX9Wc7oJpOZMJTVNqoO6BfVmkPvRXLJ509MhRtRISxpHFIA7 MyTvks9dI4UHfplv2/JIITbuNgWemNho/+ipGQfSs6/9Cnqdva9YEb0kBq1loAg9lcAsH 8SmQtGaJVIRWesg5YDUey/rJKMS8uhcHVizZEbNW/wQW+6kfH3nmYNI9pxaz5so8O0A== 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=Wos2GmYz; 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 7875A606A31C; Tue, 17 Nov 2026 05:23:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7875A606A31C 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) header.d=mail.ustc.edu.cn header.i=@mail.ustc.edu.cn header.a=rsa-sha256 header.s=dkim header.b=Wos2GmYz 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=31b9JNt65Yxrug1LN8vG9BjZbzLc7SOgE3 4Mxiobvik=; b=Wos2GmYz4wT1yqHDfX3UepwLqNl69xsD2isOLA16G34OFlX14l nl3qjvh+0WC9wz3UHoG7bNNeO5WP25JxVUEf3kwUYoDDJWvhoZ4dsqiuZ0xtSF24 XJYgzxjVwj+6cQNkJU9p5E4XE908OWhozXhhJv4g6RHvSPXlhkjlHSI0k= Received: from xuqianhui.ustc.edu.cn (unknown [114.214.190.181]) by mailimap2024 (Coremail) with SMTP id 3pYKCgBHxTmx5PtqLkTLAA--.216S3; Tue, 17 Nov 2026 13:22:58 +0800 (CST) From: Qianhui Xu To: Liam Girdwood , Mark Brown Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v12 1/2] regulator: dt-bindings: willsemi,wl2868c: add the WL2868C camera PMIC Date: Tue, 17 Nov 2026 13:22:56 +0800 Message-ID: <20261117052257.34849-2-xiaqinghuan@mail.ustc.edu.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261117052257.34849-1-xiaqinghuan@mail.ustc.edu.cn> References: <20261117052257.34849-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: 3pYKCgBHxTmx5PtqLkTLAA--.216S3 X-Coremail-Antispam: 1UD129KBjvJXoWxCrW5JF45urykZr17WF4kZwb_yoWrZw4rpF Z8GrsFkFs5Cr1xG3yxK3W8u3W3KF1rArn5Ar1UC348Kan0qFnaqr9Iyw15Za4Yyw48GFW2 yryqvF47J3WrZrJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPSb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI 8067AKxVWUGwA2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF 64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcV CY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv 6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c 02F40Ex7xfMcIj6xIIjxv20xvE14v26r126r1DMcIj6I8E87Iv67AKxVWUJVW8JwAm72CE 4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_Jw0_GFylc2xSY4 AK67AK6r4rMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8C rVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8Zw CIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6ryUMIIF0xvE2Ix0cI8IcVCY1x02 67AKxVW8Jr0_Cr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxV W8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7I U5l2MUUUUUU== X-CM-SenderInfo: 50ld1x5qjk3t3q6ptxnoox23vfohv3gofq/1tbiAREOB2r7WdojVwAvsQ 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. The example enables ldo1, which is fed from VIN12, so it also describes vin12-supply; the binding says an input may only be left out when the outputs it feeds are unused on a given board. Reviewed-by: Rob Herring (Arm) Signed-off-by: Qianhui Xu --- .../bindings/regulator/willsemi,wl2868c.yaml | 99 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 105 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 000000000..972813fbd --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/willsemi,wl2868c.yaml @@ -0,0 +1,99 @@ +# 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 th= at + 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 <&vreg_vsys>; + vin12-supply =3D <&vreg_vin12>; + + regulators { + ldo1 { + regulator-max-microvolt =3D <1128000>; + regulator-min-microvolt =3D <1128000>; + }; + }; + }; + }; +... diff --git a/MAINTAINERS b/MAINTAINERS index 8014b9f82..435beaf95 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -29058,6 +29058,12 @@ 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 + WILOCITY WIL6210 WIRELESS DRIVER L: linux-wireless@vger.kernel.org S: Orphan --=20 2.53.0 From nobody Tue Nov 24 04:43:04 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=1794892984; b=o3bTxnqHaCWHfJF3kjEmTrC1wcbV+gBEijSaJrrtMjtBjuF76g6zu3Ih+xgdr9+Zs2fJ o8+rUx+UcIj94IA2O7LLB8y8DjoOM1yeVlPEz6Wsa2ilTdVjxAHBTMIckQa40ZeUUBAEl FoFD0IRw+V4CU1BZBS41D8Ig+xlKatpmgVGKAoQbBhhK/Fp36rG8tMbM53vwDVAXv9UNn m4xSP1JMGMSt4M7vnMFTMlzFOklJXJFrrW3Vzb8hFCXw/B3HMnlCr5uQdGa70yBM7AOHC EMBEeF/KEZqE+qkt9K+3auwKBuS0CUjJlmCrLvVm+I4My4kOOPpxIo8mf4HNNN/R6fw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794892984; 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=iO3C0qwkx/2/OW6tUnlCC7klG0lJ071qcVyOmvICxIg=; b=ESaylg7vYbQZOFFYsPDMVBGyNS3qeM09kJgH8YYvfw3Olnd4QbU3IkiwkCmTS7Spb2+8 swiE0EWd1aoRlLGFeUoUYc2qa7xRxIrCD9LkW179LDZzbzbv7daO46O9gLEam8Skwu4Dt QW+lSBc0jZV3nwnnaMuh8asuwmB7m9WjR+weif2f+tBq/aHY9mH68ZsspY9L8/+ueTQiU T318SR25tSkn40zKPeFRRa2kb2T1NUME2QUmtC//bUGqAIn6Gkd0aRLtgL8N9oJ0h9V8h zUBUK/QJ3lRFy3v3IVr2YaLbkw34zk4In/j5YZUrzx62XQUvkUwBlxZYJHa5zcgHh6g== 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=jeZwz2tR; 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 B29A2606A335; Tue, 17 Nov 2026 05:23:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B29A2606A335 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) header.d=mail.ustc.edu.cn header.i=@mail.ustc.edu.cn header.a=rsa-sha256 header.s=dkim header.b=jeZwz2tR 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=iO3C0qwkx/2/OW6tUnlCC7klG0lJ071qcV yOmvICxIg=; b=jeZwz2tRpOHEWzwpW0y0k9VdJn34h4GOEwuk4Lb2lBfLWTD/Ux /AhbEAjRsZ+H5GBr7ijoAC44xs1O5gRj6NjEIIORPW7yt1VMJGtRyf9VJoV3RRzf F85s/r1mAec3QQ3O4bW0jF7pS/yv/i+vmLfr2Fa3s/ArqR3B2F/yQOr6c= Received: from xuqianhui.ustc.edu.cn (unknown [114.214.190.181]) by mailimap2024 (Coremail) with SMTP id 3pYKCgBHxTmx5PtqLkTLAA--.216S4; Tue, 17 Nov 2026 13:22:59 +0800 (CST) From: Qianhui Xu To: Liam Girdwood , Mark Brown Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v12 2/2] regulator: willsemi,wl2868c: add the WL2868C camera PMIC driver Date: Tue, 17 Nov 2026 13:22:57 +0800 Message-ID: <20261117052257.34849-3-xiaqinghuan@mail.ustc.edu.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261117052257.34849-1-xiaqinghuan@mail.ustc.edu.cn> References: <20261117052257.34849-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: 3pYKCgBHxTmx5PtqLkTLAA--.216S4 X-Coremail-Antispam: 1UD129KBjvAXoW3ZrWxAw4fuFWkWF1rZFW5Wrg_yoW8XrWrAo WIqr1Y9w48tw4rW3yFkF1UC3srXrWjk34rZ3W5KFs5uFyDZ3W3C34a9ay3XFnxtr4UKrW3 u34ftrnxGF4xJFZxn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUOe7k0a2IF6w4kM7kC6x804xWl14x267AKxVWrJVCq3wAFc2x0 x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87 I2jVAFwI0_Jryl82xGYIkIc2x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY 1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20x vEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280 aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzV Aqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUAVWUtwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S 6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I0En4kS14v26r1q6r43MxkIec xEwVAFwVW8WwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02 F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GF ylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI 0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x 07bzYLPUUUUU= X-CM-SenderInfo: 50ld1x5qjk3t3q6ptxnoox23vfohv3gofq/1tbiAREOB2r7WdojVwAwsP 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 starts asserted, is released only after the control supply is up, followed by a delay for the device to come up, and is asserted again before the supply is disabled on unbind. 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, but only when SYS_EN is already set: with SYS_EN clear the per-LDO bits are presets for outputs that are off, and seeding them would make the first enable() of one output switch all of them on. 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 control logic and the I2C interface are powered from the higher of VIN7 and VSYS. The driver enables VSYS, falling back to VIN7 on boards that do not describe VSYS, and keeps it enabled for as long as it is bound: without it the device does not answer on the bus. The device ID is read only after the control supply is up and RST_N has been released. The LDOx_SEQ fields also have to be taken over: a non-zero slot moves that output from the LDOx_EN bit to the power-up sequencer, and writes to the enable register then have no effect on it (datasheet WL2868C Rev 1.4, "0x0A, 0x0B, 0x0C and 0x0D: LDOx_SEQ", p.35). The binding describes no sequencing, so the driver clears the four slot registers during probe and keeps the enable register as the only control path; otherwise enable() and disable() would silently do nothing for an output a slot had claimed. The reset value is 0 and no known board programs it, but firmware runs before us and may. Signed-off-by: Qianhui Xu --- MAINTAINERS | 1 + drivers/regulator/Kconfig | 11 + drivers/regulator/Makefile | 1 + drivers/regulator/wl2868c-regulator.c | 301 ++++++++++++++++++++++++++ 4 files changed, 314 insertions(+) create mode 100644 drivers/regulator/wl2868c-regulator.c diff --git a/MAINTAINERS b/MAINTAINERS index 435beaf95..5a3913c45 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -29063,6 +29063,7 @@ 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 =20 WILOCITY WIL6210 WIRELESS DRIVER L: linux-wireless@vger.kernel.org diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index a54a54919..79bdba077 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -1851,6 +1851,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 134eee274..662f31a14 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -211,6 +211,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 000000000..9ffb08dcb --- /dev/null +++ b/drivers/regulator/wl2868c-regulator.c @@ -0,0 +1,301 @@ +// 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 +/* 0x0a..0x0d: seven 4-bit LDOx_SEQ slots; 0 =3D driven by LDOx_EN in 0x0e= . */ +#define WL2868C_LDO_SEQ 0x0a +#define WL2868C_LDO_SEQ_LEN 4 +#define WL2868C_LDO_ENABLE 0x0e +#define WL2868C_SYS_ENABLE BIT(7) +#define WL2868C_LDO_ENABLE_MASK GENMASK(6, 0) + +/* RST_N must be released after the control supply is up, not before. */ +#define WL2868C_RESET_RELEASE_US 1000 +/* Time the device needs after RST_N is released before it answers on I2C.= */ +#define WL2868C_STARTUP_US 1000 + +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() when SYS_EN was set, so an output the firmware + * left on is carried over instead of being cleared by the first + * enable; when SYS_EN was clear no output is on at all. + */ + 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) +{ + struct wl2868c *chip =3D rdev_get_drvdata(rdev); + unsigned int mask =3D WL2868C_SYS_ENABLE | rdev->desc->enable_mask; + unsigned int value; + int ret; + + ret =3D regmap_read(chip->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_assert(void *data) +{ + gpiod_set_value_cansleep(data, 1); +} + +/* + * VIN7 and VSYS both feed the control logic and the I2C interface, which = run + * from the higher of the two. The binding requires at least one of them, = and + * whichever is present has to stay up for as long as the driver is bound: + * without it the device does not answer on the bus at all. + */ +static int wl2868c_enable_control_supply(struct device *dev) +{ + int ret; + + ret =3D devm_regulator_get_enable_optional(dev, "vsys"); + if (ret !=3D -ENODEV) + return ret; + + ret =3D devm_regulator_get_enable_optional(dev, "vin7"); + if (ret) + return dev_err_probe(dev, ret, "Failed to enable the control supply\n"); + + return 0; +} + +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; + static const u8 no_seq[WL2868C_LDO_SEQ_LEN]; + 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; + + /* + * RST_N starts asserted and is released only once the control supply is + * up. The reset action is registered after the supply action on + * purpose: devres unwinds in reverse order, so RST_N is asserted again + * before the supply is disabled on unbind, not after. + */ + reset =3D devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(reset)) + return dev_err_probe(dev, PTR_ERR(reset), "Failed to get reset GPIO\n"); + + 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"); + + ret =3D wl2868c_enable_control_supply(dev); + if (ret) + return ret; + + if (reset) { + fsleep(WL2868C_RESET_RELEASE_US); + gpiod_set_value_cansleep(reset, 0); + ret =3D devm_add_action_or_reset(dev, wl2868c_reset_assert, reset); + if (ret) + return ret; + fsleep(WL2868C_STARTUP_US); + } + + 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); + + /* + * LDOx_SEQ[3:0] (0x0a..0x0d) assigns an output to one of the seven + * power-up sequencer slots; any value but 0 moves that LDO from the + * LDOx_EN bit in 0x0e to the sequencer, where writes to 0x0e have no + * effect (datasheet WL2868C Rev 1.4, "0x0A, 0x0B, 0x0C and 0x0D: + * LDOx_SEQ", p.35). The binding describes no sequencing, so clear the + * slots: every output then stays under the enable register this driver + * owns. The reset value is 0 and no board is known to program it, but + * firmware can, and a stale slot would make enable() silently inert. + * Outputs a slot had turned on are switched off here; no consumer is + * up yet at probe time. + */ + ret =3D regmap_bulk_write(config.regmap, WL2868C_LDO_SEQ, no_seq, + WL2868C_LDO_SEQ_LEN); + if (ret) + return dev_err_probe(dev, ret, "Failed to clear the sequencer slots\n"); + + /* + * Seed the tracked set with the outputs the firmware left enabled, so + * that the first enable() or disable() of any output preserves them. + * SYS_EN gates the whole chip: while it is clear no output is up, the + * per-LDO bits are only presets and is_enabled() reports every output + * as off. Seeding them in that state would make the first enable() of + * any single output switch all the presets on. + */ + 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"); + + if (value & WL2868C_SYS_ENABLE) + 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"); --=20 2.53.0