From nobody Wed Jun 17 02:50:48 2026 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D31F73B19A8 for ; Tue, 28 Apr 2026 11:39:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777376385; cv=none; b=TqKN+owuO9M5sQjBKYmrl67/Fuer18cDsli8uY5Fo6QiBGnSGcxXqMSxQz+bu5SOSZVVvBlLph9L7Pg3CmL2JWhdTNnDowKK6kZuyNZJ+pTkXpK80aEJYyrarlankDzFUCwYEs3wvNTWSuAf+gNF59gw6+c6l2PCjQSTIJSz/Gw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777376385; c=relaxed/simple; bh=6Ox/1lZRBtvaCEzjGqWKJlNoXRziKdYDiJOJBsJZJxE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RhxWAnhoBLEUYSdkmC9Ma0laExokVNIscm2dErIrpweayq3StSbzEIkXXlRN0mxT8/uktxbCbSqDS90QgxTwtJEcgzeY6M5FqvDNO6qDGZWYBa8JBAQ9A/GWpBNGPR8rutwmDAAtIDMRQx6PRLX08UVhQQFjS3JI18KXITJgN5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QAWiuHLD; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QAWiuHLD" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-488b0046078so102316605e9.1 for ; Tue, 28 Apr 2026 04:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777376382; x=1777981182; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MKbUTvcePe+bc+QWEqhr7xtWGXq9HDSMNZMknnD7nyk=; b=QAWiuHLD82rTdJGXC2jYo2mbtrfqx3eQK27QENKAM0X01s/T57hXq89ehvsWOxkOBO f4qaYupINUvAPAJeUdppKTF2GM12PDfVKD9pDlS+zlzmRRgbOE5zwV45NDZecrTtDXe2 yH9rKN9cRN3W+w+jLoTKc3EhPSilBuGYWeMFRz5eU/Hn7DwrhOPoeI4CkpnkzMU7TPzZ eSsulDSRuPmRRwmY3m4s0LR2NQMB2ns8LFDm7BlpXik5SKGNEcBzZg9d0OG8ZgnKdOzh LUdQrF2K8dSJJvjaFy+W+Jm+VLHDB4XY7N4P7m0pteUzc+p13qXai/1vnxfKYYfqAF6l HQfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777376382; x=1777981182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=MKbUTvcePe+bc+QWEqhr7xtWGXq9HDSMNZMknnD7nyk=; b=eQYwdMwgK1R2Mi/KU9/zusl8mYULeAM4q0hFkoDZj+uB7LY4mZ9w2/gBn36xw2V719 sDMMRlUmf1GkfgBrF2x3CJqq77zZF9nzQNSrYfnxRyn6iXm8tbYeJGSsxcw8IWzTnozB 0l5aukHHyb/PBCN1UJs5AeJGvsVzWuiTxtVRcDeYhgpTbMJpzw0U+gguoYq6NoiHzBZr OLbwh+i5p4ga9DUNGddecitAj58HoeKKlAJvw37Zw9L0r0k+F6cuvdyLChAvykvQSDIp 4I46PdOwRVE/660EVarNC9YgUU6LM3tSdOFsZp4pkWXZdD8fwB/FMigZnIKSb0ChaFq9 Fj/Q== X-Forwarded-Encrypted: i=1; AFNElJ8HiRxURmSGkYDrpWvC4dwrlWT9k4p1gYTkmNTawT5dL/f0y5/coqGDI/YmR30gtmKdi/yZC9nETviT3bU=@vger.kernel.org X-Gm-Message-State: AOJu0YzshJsIJQBmCDjrJ0YoqMbg3C9y3zCyoLQSoknmJUto/HLUr5/k M7+ZyxmUoaXykGVbvjKcCnQqNquNFJg/IOCBLo4r6ZpaLBMfbAHKh7zL X-Gm-Gg: AeBDieuIiQvIK4YMknjgfhBlYYoMcqgi+LP+opR9Q1vxK4Pkg6vRZcxDsGLTlh3jLUL MXlBppD0OuNV2KMYdei3X4mPrx4YEWlWOgYwzh4jrex6NDFDKvA1rhbUYXseyH41QM+OLxUBs95 FiOuzLQTz0NHaDyoE/ClliuZgGb2CtSsKopuPEbNGgrLy+OFqueY/0S2sPh4A50KmxPNw90E9nf Scw8pMO14dzBDEKj0yyzdYz8hrtSDS+bQllxaZHooeYZftwHBmIkxtmk4xXLVMoQ7uCt+CDgeBE 2t1Wnb0oDSAh9fUm0cZ8d/IC2Rbh961we2wjfdLRyu3PYgP1csaI5CA5nHBDVzLO+VCfeYc0mBf m2oxX0+FO/QKBTOIAUEA/e8dUgCxlOgivLqsd5dQliFIrSnwjW+5/Fo9sSh52cfSIHUW+VGJYuw w+F/b3Rm8Bg51uovZY18iQmOA= X-Received: by 2002:a05:600c:8b54:b0:48a:5339:ef0e with SMTP id 5b1f17b1804b1-48a77ae5405mr46236345e9.3.1777376382166; Tue, 28 Apr 2026 04:39:42 -0700 (PDT) Received: from xeon ([188.163.112.56]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a77aeb223sm43541125e9.3.2026.04.28.04.39.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 04:39:41 -0700 (PDT) From: Svyatoslav Ryhel To: Lee Jones , Pavel Machek , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sakari Ailus , Mauro Carvalho Chehab , Svyatoslav Ryhel Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v4 1/5] dt-bindings: leds: Document TI LM3560 Synchronous Boost Flash Driver Date: Tue, 28 Apr 2026 14:39:18 +0300 Message-ID: <20260428113923.112920-2-clamor95@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260428113923.112920-1-clamor95@gmail.com> References: <20260428113923.112920-1-clamor95@gmail.com> 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 Document TI LM3560 Synchronous Boost Flash Driver used for camera flash LEDs. The TI LM3559 documented in this schema requires a separate compatible, as it utilizes a different programming model =E2=80=94 specifically regarding = the handling of voltage ranges. Signed-off-by: Svyatoslav Ryhel --- .../devicetree/bindings/leds/ti,lm3560.yaml | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/ti,lm3560.yaml diff --git a/Documentation/devicetree/bindings/leds/ti,lm3560.yaml b/Docume= ntation/devicetree/bindings/leds/ti,lm3560.yaml new file mode 100644 index 000000000000..27bbc45bfc85 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/ti,lm3560.yaml @@ -0,0 +1,133 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/ti,lm3560.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: TI LM3560 Synchronous Boost Flash Driver + +maintainers: + - Svyatoslav Ryhel + +description: + The LM3560 is a 2-MHz fixed frequency synchronous boost converter with t= wo + 1000-mA constant current drivers for high-current white LEDs. The dual h= igh- + side current sources allow for grounded cathode LED operation and can be + tied together for providing flash currents at up to 2 A through a single= LED. + An adaptive regulation method ensures the current for each LED remains in + regulation and maximizes efficiency. + +allOf: + - $ref: /schemas/leds/common.yaml# + +properties: + compatible: + enum: + - ti,lm3559 + - ti,lm3560 + + reg: + maxItems: 1 + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + enable-gpios: + description: GPIO connected to the HWEN pin. + maxItems: 1 + + vin-supply: + description: Supply connected to the IN line. + + flash-max-timeout-us: + minimum: 32000 + maximum: 1024000 + default: 32000 + + ti,peak-current-microamp: + description: + The LM3560 features 4 selectable current limits 1.6A, 2.3A, 3A, and = 3.6A. + When the current limit is reached, the LM3560 stops switching for the + remainder of the switching cycle. + enum: [1600000, 2300000, 3000000, 3600000] + default: 1600000 + +patternProperties: + '^led@[01]$': + type: object + $ref: /schemas/leds/common.yaml# + description: LED control bank nodes. + unevaluatedProperties: false + + properties: + reg: + description: Control bank selection (0 =3D bank A, 1 =3D bank B). + maximum: 1 + + flash-max-microamp: + minimum: 62500 + maximum: 1000000 + + led-max-microamp: + minimum: 31250 + maximum: 250000 + + required: + - reg + - flash-max-microamp + - led-max-microamp + +required: + - compatible + - reg + - '#address-cells' + - '#size-cells' + +additionalProperties: false + +examples: + - | + #include + #include + + i2c { + #address-cells =3D <1>; + #size-cells =3D <0>; + + led-controller@53 { + compatible =3D "ti,lm3560"; + reg =3D <0x53>; + + enable-gpios =3D <&gpio 28 GPIO_ACTIVE_HIGH>; + vin-supply =3D <&vdd_3v3_sys>; + + flash-max-timeout-us =3D <1024000>; + ti,peak-current-microamp =3D <1600000>; + + #address-cells =3D <1>; + #size-cells =3D <0>; + + led@0 { + reg =3D <0>; + + function =3D LED_FUNCTION_FLASH; + color =3D ; + + flash-max-microamp =3D <562500>; + led-max-microamp =3D <156250>; + }; + + led@1 { + reg =3D <1>; + + function =3D LED_FUNCTION_FLASH; + color =3D ; + + flash-max-microamp =3D <562500>; + led-max-microamp =3D <156250>; + }; + }; + }; --=20 2.51.0 From nobody Wed Jun 17 02:50:48 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 675FB3B2FFD for ; Tue, 28 Apr 2026 11:39:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777376387; cv=none; b=CPlr6HxUGZhvahHw9JfEOHX+2WD5FEG9gL4YaxzDSeyPSZf4IWhOc+N6d0MuqoMwrFDMIx7LtVzwmnioIiPKEaAAP4RRs8w+j8NU3MVLQ5Ym+hZbY3eRgloBDmBbPCB8q6F1eQ8h1ngPuRVsOXkvoaCIyarNZZ8TqMZd6FNEokI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777376387; c=relaxed/simple; bh=/aTZ7FfNJUxGAerV0GyNvRYzlJf90me3mmU4zDgewOs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hEBspESmlaeEwc2VnRz/IUDMunQXu4AkS1cPqhaJSJb2wkD+tihA9Jxw67YIZQ3yWO2RsV1bSlGadaq23mGCB5zlBBmlYK2Vo09wFwWypLvjUWfkh+y/bv4S8+ALvTlWcZA3T4BE+OzmHx1K23JauHWBlS4yWG6LCY9efoWhEMU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Fd65MjkV; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fd65MjkV" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-488ff90d6c7so96890385e9.2 for ; Tue, 28 Apr 2026 04:39:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777376384; x=1777981184; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qqEpiDmgYxnJFJBZV5oyq8iX4ijdqmclDgeEbjUzvZU=; b=Fd65MjkVQB3E6GV8G/hk9uAj/8TTqNaJBbmypmq0adYW+KGGgx3tijofFRyE20VjpG 2lcaUBL6TeRhAsYgYxU0h0jaxlmw2x88YcrZxEbeTpkrVdeSDXlS/JbvpnVbcIVNBZvr dqd8gciv5iT2Uk8AdIjFCCgFNArQuBHVLT8R6f2iXz0V8sNsoT47oi9VMb2Wcqba5zkf 4CrX3kuxXh97RPJdZykwruAT/KwVy7/1R25gLIX07XU0L1dCDvn/5r/pHEUhU/dvMEH3 eyj+up+GlOt3+T5cXbERY+805a1D9nOTYUiYSsDY3YAAms1pOhyjiDjoevg2rO10Ol/y myMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777376384; x=1777981184; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=qqEpiDmgYxnJFJBZV5oyq8iX4ijdqmclDgeEbjUzvZU=; b=blhlfEKBbdZhw0dbONEBY5mJxe18ZAIUT3drQ2DakOCiHSprAqgr4eewdD6ufJkX9s wGCxs9M/jLsUuvH2gcrOco4jepqwZQ3eFkFUSUa7WwcqkrBLC42b7MlzMAneVAn7XVFy DPfkWtrBBgBAvgaFeOc4jfnOGe3G6kjIN80xnEY1F20S39ZuKhTPpNAGUy24HaVAPUgE BJDXMmpYD65aAC2nEpRhF2Vpl+tX6Ab5ysDejm6WiBy5O2jkc8EkqN3dwWEP3g6EslXi jrz7O/LtTCkzSxhi3Y8AyeZIAL4tIWZ0gPonM7uhNE+fVURMmztX4VmQFJhz4l9Yi5F4 Rrtg== X-Forwarded-Encrypted: i=1; AFNElJ8gprJH8xteWpWGgdTSG7FycVtxoYU7BEXImaWg0DmDWh+kC6+d6YBoq9sis+NJdegBZ4KJfvCfwbgG4lc=@vger.kernel.org X-Gm-Message-State: AOJu0YxIK4LRm8AhH02XmqQeVneQmR71GckQClETc2+81/kj+baPvLET bQ9v5UQr3pb2OZS4u4U2FCFPhRYWk5zpjhtpX+paFHJ8f+9gXErrt5/Z X-Gm-Gg: AeBDievWdlirOrmJhuogScyjqqZHO4ZaFfBCXhQQSxHTcE34Y3mciuGw3OZc1451UY5 8tx2MecJl0fKcL4vaPIvRIPlpjnHCqiesjGc4zAvjeAQZxbeMyWnpTgIOof7Tud/g5aWvaz4F/k BKj0LtfqyVbQWDFNIuylNFjT9aXUj7saX/RNVkqEL4+mGAHv/cUJhmX1K/wbJBQCOVuIHN77tFa Iup3pehOGcsE/aJlGRH38qTutSSckNXjmIUztLJ+FhAhcFbyHqTOps0gaSX7T3kPP/Z70XqDrSy BvdxdVXB/XzkR2i61J3hCW8GMwOHU2r1NFJ3SgZSdTyri1t1PWk5LcVaMX2dHEg1isA0z/3qwcR CPaTor0YCkqRaLK0yEUd6Va+sseNrqKfrSofjXv0qjjkmf/t2FvFpLsN+GZFftfUWlV/2cseT7P IYr46Qwm+RzTfXZbhZAcxWRKc= X-Received: by 2002:a05:600c:1393:b0:488:fd7e:1063 with SMTP id 5b1f17b1804b1-48a77b270efmr43569445e9.29.1777376383549; Tue, 28 Apr 2026 04:39:43 -0700 (PDT) Received: from xeon ([188.163.112.56]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a77aeb223sm43541125e9.3.2026.04.28.04.39.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 04:39:43 -0700 (PDT) From: Svyatoslav Ryhel To: Lee Jones , Pavel Machek , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sakari Ailus , Mauro Carvalho Chehab , Svyatoslav Ryhel Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v4 2/5] media: i2c: lm3560: Fix v4l2 subdev registration Date: Tue, 28 Apr 2026 14:39:19 +0300 Message-ID: <20260428113923.112920-3-clamor95@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260428113923.112920-1-clamor95@gmail.com> References: <20260428113923.112920-1-clamor95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The existing driver does not call media subdev registration, making it invisible to the media framework. Since the LM3560 supports two independent LEDs, register each LED as a separate media entity. Because registering LEDs before device initialization may cause access attempts before the hardware is ready, lm3560_init_device has been moved before the subdevice initializations. An additional helper, lm3560_subdev_cleanup, was added to release LED0 if the initialization of LED1 fails, and to deregister both LEDs in the remove function. Signed-off-by: Svyatoslav Ryhel --- drivers/media/i2c/lm3560.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c index f4cc844f4e3c..edfb07587cab 100644 --- a/drivers/media/i2c/lm3560.c +++ b/drivers/media/i2c/lm3560.c @@ -364,8 +364,15 @@ static int lm3560_subdev_init(struct lm3560_flash *fla= sh, goto err_out; flash->subdev_led[led_no].entity.function =3D MEDIA_ENT_F_FLASH; =20 - return rval; + rval =3D v4l2_async_register_subdev(&flash->subdev_led[led_no]); + if (rval < 0) { + dev_err(flash->dev, "failed to register V4L2 subdev"); + goto error_out_media; + } =20 + return rval; +error_out_media: + media_entity_cleanup(&flash->subdev_led[led_no].entity); err_out: v4l2_ctrl_handler_free(&flash->ctrls_led[led_no]); return rval; @@ -391,6 +398,14 @@ static int lm3560_init_device(struct lm3560_flash *fla= sh) return rval; } =20 +static void lm3560_subdev_cleanup(struct lm3560_flash *flash, + enum lm3560_led_id led_no) +{ + v4l2_async_unregister_subdev(&flash->subdev_led[led_no]); + v4l2_ctrl_handler_free(&flash->ctrls_led[led_no]); + media_entity_cleanup(&flash->subdev_led[led_no].entity); +} + static int lm3560_probe(struct i2c_client *client) { struct lm3560_flash *flash; @@ -425,17 +440,19 @@ static int lm3560_probe(struct i2c_client *client) flash->dev =3D &client->dev; mutex_init(&flash->lock); =20 - rval =3D lm3560_subdev_init(flash, LM3560_LED0, "lm3560-led0"); + rval =3D lm3560_init_device(flash); if (rval < 0) return rval; =20 - rval =3D lm3560_subdev_init(flash, LM3560_LED1, "lm3560-led1"); + rval =3D lm3560_subdev_init(flash, LM3560_LED0, "lm3560-led0"); if (rval < 0) return rval; =20 - rval =3D lm3560_init_device(flash); - if (rval < 0) + rval =3D lm3560_subdev_init(flash, LM3560_LED1, "lm3560-led1"); + if (rval < 0) { + lm3560_subdev_cleanup(flash, LM3560_LED0); return rval; + } =20 i2c_set_clientdata(client, flash); =20 @@ -447,11 +464,8 @@ static void lm3560_remove(struct i2c_client *client) struct lm3560_flash *flash =3D i2c_get_clientdata(client); unsigned int i; =20 - for (i =3D LM3560_LED0; i < LM3560_LED_MAX; i++) { - v4l2_device_unregister_subdev(&flash->subdev_led[i]); - v4l2_ctrl_handler_free(&flash->ctrls_led[i]); - media_entity_cleanup(&flash->subdev_led[i].entity); - } + for (i =3D LM3560_LED0; i < LM3560_LED_MAX; i++) + lm3560_subdev_cleanup(flash, i); } =20 static const struct i2c_device_id lm3560_id_table[] =3D { --=20 2.51.0 From nobody Wed Jun 17 02:50:48 2026 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92B2C3D9DB7 for ; Tue, 28 Apr 2026 11:39:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777376391; cv=none; b=nQnIYRRe3DhLhh9ZKzA3Y0KY2sUd+IaB9hPlGCm1sPsupRyYMIC8uKc2ZCsyLTnry9OhiOoGkEJ6+L2eqRnxgM0HGrgaNP5GMRwePNlrT07fJiAznfKmGHYSK8/ey8fOzZfm6Mc5ru6Hxkx82OvtRTk4cnSVseBRJqfNWzZbAl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777376391; c=relaxed/simple; bh=LRXlNS9x02z8g+CGxmATU/6gvHvDK0YuBVqtECCU2ME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fWH8lSbCZS9IDsYnrpRrISrsQv0Vw9uXdnyJT6eoRtrs/ZkpwSsvc8FTajYrz23GUuPf2k7k9fMbmBieBVHW+QqK+bbRW1kn/zYRacSIZFP0vy7WxWUK7x4ctidh/jPzSo3YYu3O4pzQWGCO6AZpJtwccAXGjfHnSJnmBMxilAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=F33ZpTnE; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F33ZpTnE" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-48a563e4ef7so78676205e9.0 for ; Tue, 28 Apr 2026 04:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777376386; x=1777981186; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2KGU01Qq2W7EXZE5uDuHFOzhjoXBSa5CoF8m94VBiMo=; b=F33ZpTnEflLMf50xgLlKc6vUGNRORo8QcHcqdx0Mhtyml9qGfrQisf/PKui/9v+Wf9 w1AA+6dotF7yKb2DzBKevJnrssvc5r9CpySacJpkrHn/qTPMqlYcaIhZPvW//HgVTVIN cJqzqVPSK0N/iQNnXFL011IqOIbgsFlgkgIadlkWrrQijqti04EAAMQbFDgoRo+pX1qG UdhmtamphWP4KddrddeDheXPH59/rj1hpaBYYJGI9xOivB1W+6achp1QVgDjuxNvTE7e SOswzCYFscl1vB2H0rNAaVy/ikJFj1Km+5ctKx88JIYQDX/y7Of1WCn2QQONK2zqG1Hy MvNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777376386; x=1777981186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2KGU01Qq2W7EXZE5uDuHFOzhjoXBSa5CoF8m94VBiMo=; b=OEpp9KXcr4eanVW4HieSGvKVu/sDaT08wKRo6Ru7t5Oe+FEHUSlhjFgPUb0qXEcYIF Rv8lQlPhW81nRjjUSCQHFZ7VVjpvv5K26RZ2V3fAB9Yd06hJMiiIrzWWtGzpUVSypc3h Ro8DcP8h/JypNGnRfQttsO+9LBVJvqj8YEy6H+mEDvI+PZZkWNxe6kH8uLU7u/kEVz1N 7iDegZ9TPazAlIBa3dPug2k7OewPmZ0QmmzMbrBz6AK+Ml0PSaVFl7hPHwFQNCkE/ZB7 +kGLwc33sAl1OSct1SV8YcvRgtE7mU+Mm0ayjDuEzNMH1zbb/7euI7tnT6j2gGjQZSRw Jq7Q== X-Forwarded-Encrypted: i=1; AFNElJ++NZ5UiZEbk62erJkYbEHzH9dMM3kqsjFvbvGntkByF/LhJq4zvh76IEm34ubuybP6/Q2lquWOfm18q3s=@vger.kernel.org X-Gm-Message-State: AOJu0YxUdmVFtpIQbAmxbhPrHEeFzrhanL6fgS5+DmMMN+EJFfimDjPl DNXg2mNfqfoqo8U+PM6m9rPdVJ2+l3KKCInw1gH0GCBLwrAYkQ5/LCmG X-Gm-Gg: AeBDievXYPkedEewaqvbwcg7CDjjjkaMvdf38kECUMTdrq3pM6ogKc/lND/p0iPx2ZF afpk8MjXIueiLiJqPW5mGeg6XNA+Oj+M9xkavEH64dzRiyCSYMBCtiYvM/RUwht4IB/F8kdTSDF aMB2/0+5FAXMGtFtkZW1WS0mSFzOt0dGBCsuE+qV6+ixNKzI5Im8j6qgoiutPleTbY2iKH2MkuW 5PpOGftdLI/j5i1asmBg8saz/9PIcSD36EBHPEsCn8bAQ/CiKOEoQaYDJKiTEleNBzv2Gp45J51 k2O4DkH/UXEEdp+Sa+xviRllud/3yBJqt/8MtsvC6YvjYp8puFmxlmSRfpCkIDMdUueAtQYjsV6 RPGeHrXo9eKFqA2pcdr6Kab0L5Gb6Aj4qVvRByobwHYo2tzWy5oZtRdFhaOzNqCa8+NRtjMsmtc 1m6fR9mdqEEC5Kq0kfwrtewRw= X-Received: by 2002:a05:600c:1d0a:b0:488:a824:fe04 with SMTP id 5b1f17b1804b1-48a77b1e893mr45325545e9.26.1777376385036; Tue, 28 Apr 2026 04:39:45 -0700 (PDT) Received: from xeon ([188.163.112.56]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a77aeb223sm43541125e9.3.2026.04.28.04.39.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 04:39:44 -0700 (PDT) From: Svyatoslav Ryhel To: Lee Jones , Pavel Machek , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sakari Ailus , Mauro Carvalho Chehab , Svyatoslav Ryhel Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v4 3/5] media: i2c: lm3560: Optimize mutex lock usage Date: Tue, 28 Apr 2026 14:39:20 +0300 Message-ID: <20260428113923.112920-4-clamor95@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260428113923.112920-1-clamor95@gmail.com> References: <20260428113923.112920-1-clamor95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pass the device's own mutex lock to the control handler so that the media framework can handle control access instead of managing it manually. The lock must be common to both sub-devices since they share same hardware, so the individual sub-device locks will not work here. Signed-off-by: Svyatoslav Ryhel --- drivers/media/i2c/lm3560.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c index edfb07587cab..5b568ed9536b 100644 --- a/drivers/media/i2c/lm3560.c +++ b/drivers/media/i2c/lm3560.c @@ -162,14 +162,12 @@ static int lm3560_get_ctrl(struct v4l2_ctrl *ctrl, en= um lm3560_led_id led_no) struct lm3560_flash *flash =3D to_lm3560_flash(ctrl, led_no); int rval =3D -EINVAL; =20 - mutex_lock(&flash->lock); - if (ctrl->id =3D=3D V4L2_CID_FLASH_FAULT) { s32 fault =3D 0; unsigned int reg_val; rval =3D regmap_read(flash->regmap, REG_FLAG, ®_val); if (rval < 0) - goto out; + return rval; if (reg_val & FAULT_SHORT_CIRCUIT) fault |=3D V4L2_FLASH_FAULT_SHORT_CIRCUIT; if (reg_val & FAULT_OVERTEMP) @@ -179,8 +177,6 @@ static int lm3560_get_ctrl(struct v4l2_ctrl *ctrl, enum= lm3560_led_id led_no) ctrl->cur.val =3D fault; } =20 -out: - mutex_unlock(&flash->lock); return rval; } =20 @@ -190,8 +186,6 @@ static int lm3560_set_ctrl(struct v4l2_ctrl *ctrl, enum= lm3560_led_id led_no) u8 tout_bits; int rval =3D -EINVAL; =20 - mutex_lock(&flash->lock); - switch (ctrl->id) { case V4L2_CID_FLASH_LED_MODE: flash->led_mode =3D ctrl->val; @@ -202,14 +196,12 @@ static int lm3560_set_ctrl(struct v4l2_ctrl *ctrl, en= um lm3560_led_id led_no) case V4L2_CID_FLASH_STROBE_SOURCE: rval =3D regmap_update_bits(flash->regmap, REG_CONFIG1, 0x04, (ctrl->val) << 2); - if (rval < 0) - goto err_out; break; =20 case V4L2_CID_FLASH_STROBE: if (flash->led_mode !=3D V4L2_FLASH_LED_MODE_FLASH) { rval =3D -EBUSY; - goto err_out; + break; } flash->led_mode =3D V4L2_FLASH_LED_MODE_FLASH; rval =3D lm3560_mode_ctrl(flash); @@ -218,7 +210,7 @@ static int lm3560_set_ctrl(struct v4l2_ctrl *ctrl, enum= lm3560_led_id led_no) case V4L2_CID_FLASH_STROBE_STOP: if (flash->led_mode !=3D V4L2_FLASH_LED_MODE_FLASH) { rval =3D -EBUSY; - goto err_out; + break; } flash->led_mode =3D V4L2_FLASH_LED_MODE_NONE; rval =3D lm3560_mode_ctrl(flash); @@ -239,8 +231,6 @@ static int lm3560_set_ctrl(struct v4l2_ctrl *ctrl, enum= lm3560_led_id led_no) break; } =20 -err_out: - mutex_unlock(&flash->lock); return rval; } =20 @@ -328,6 +318,8 @@ static int lm3560_init_controls(struct lm3560_flash *fl= ash, if (fault !=3D NULL) fault->flags |=3D V4L2_CTRL_FLAG_VOLATILE; =20 + hdl->lock =3D &flash->lock; + if (hdl->error) return hdl->error; =20 @@ -363,6 +355,7 @@ static int lm3560_subdev_init(struct lm3560_flash *flas= h, if (rval < 0) goto err_out; flash->subdev_led[led_no].entity.function =3D MEDIA_ENT_F_FLASH; + flash->subdev_led[led_no].state_lock =3D &flash->lock; =20 rval =3D v4l2_async_register_subdev(&flash->subdev_led[led_no]); if (rval < 0) { --=20 2.51.0 From nobody Wed Jun 17 02:50:48 2026 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E064F3B27D1 for ; Tue, 28 Apr 2026 11:39:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777376392; cv=none; b=A9ywOnMUHyx93mXLy7+F4KBTRCWsOmZaBQFZzTjYQJNNX43EEQxtHOxUkMqc2cSOJaqTgIy/Kkx/LDwrevHkVFg5yMxHQrkWhKiQiebtGn6oa57P4DyTMo7azUtY9D8ahQ4HaDC09uyZahXPoMTFs/1uXcTpA64MzCm+va+l8io= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777376392; c=relaxed/simple; bh=if5fzn6EiYAdYQ0JVkfWJ2iUwqyjky8GCm3SoGv3Ckg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oW1Sz4YYa754papr6R5dmx+tc6lcJSeuNWnq8Pn8Xmr+MrAReVQ/a+e34viPQT0YyXDQtT34bHS8Sph4D/eoD940A5YLT91vs0ye279pyjvr/ofi6O8/4VNY2yF6mjtuxBtDKw/wrIA2m07GZeyB4LQ7fhGyxZTDNTarYz3/Iaw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Gpesw2fz; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Gpesw2fz" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4891e5b9c1fso97760635e9.2 for ; Tue, 28 Apr 2026 04:39:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777376386; x=1777981186; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+1tztVTuc1e4/H1fOczCbpXpJF5rF4H8B95UHFGdg+4=; b=Gpesw2fzFTKz3Pv8OOpjrTU6vMEMZxzdC62fZuAlAc9+DzxFwLt9EPwtoNR1noA+qj ZB8pfS5t/itOop1S15LBigamXHxTgpP+3ciiC6AZXIQ7g4g5D96Jn0n8qLTEih8Iroud f4jUkcTDGr5uPw1QBQRZcgOjT9VgfAneFLOcmbsQrJI4vnyPtse4qtLeuxeXQxQVl9Aa ENchRSgd+Qfyys+gElBGGpPbASYJaTgd1C2GqorM+NwUVLyCeoYCY4W2h4SzbPYWPyl9 lyDEm3i7pakwl3ukdAc4BNweUfKoszccRSANmL8ObQXzz+eELFn8HVWZ2pR4YtsXMdMD Qv/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777376386; x=1777981186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+1tztVTuc1e4/H1fOczCbpXpJF5rF4H8B95UHFGdg+4=; b=bk3U6gqnzlTbi1eCAMASKFd1vG5I9VV5HgK7KjBlwfmYhXe7C2OXPKAOpUJpKs5eSg KO6vX8LwdWS/Cu3B3oZ6Tpall8EdbeTwVwZ5An+JaGg6oKf4dvbOCN9FynAUwh6KDzc+ HJ0QAFEKGxCkgmIQuAD/3vLJNYvGK8hbwFuuxEzzBr1gcx5zMZawLDeZ8SeQwbCIUiph J2En50rjvkCWjxVaSSZmbF6jNpEeziIy/w8yQ7SX9IVobr993YpMU1/s32oal8Qa1cIE W+AplGD98poeA1skkVnLZfiyvyboPokEUVN+EotkssXFfk+LeyuQ4RGBWQ399liv+2eL SpDg== X-Forwarded-Encrypted: i=1; AFNElJ9DpE8fN0Ntph9ZMWwluPMVpUaG/vziv03jTAm4FwAGm4icjaOfXZ4wmH9TprxJ4s6YRPflmMF4erU9e7Q=@vger.kernel.org X-Gm-Message-State: AOJu0YyXLFdA9I9zZsnC2gcp2RzS0Fb3TJMo51sUyV2erTI+JFJZKe7A NpexBdZSHMTDhVEHeJNqxfkE5wzRY8LPqAmitmQLXa9dAtI5cnX7cpAq X-Gm-Gg: AeBDieuR6G6doOIMfF6Mh6Pt/cuNB4HN5C6e8GP8MpYl72uunL5XbmJzdLWPLc5WPl8 Okhc3BVAboCD9md8MYda7hfz9eMZkUDdW3toMGFdhaL2LE1q45cri6d/7XghPAaJOYG9kn4BwFs T1eHJ4sSiyTS1DVwU+LKBSG9MC/SciXn3iHL8hv3ysqnE3POF4e8SwjH7YRMoK1KsZBVBd4g2gN /pA06qsTe2BH2K2KaC65pUyDAopz0wDPbjsifz0BMCmJrKV1kKZ3WtvbQmfm0YegujXPQi5kGmZ 4EUicPM+4VnI2hOjreHRq7sGfVthVlOUAWonFfvp/mekQV9xSdM2s3KFEcdvL8vqKUqcspFyf1Q isJ5sr9EwxULUPhVbHypG3axioflk6ZsEq0nNTUz+pRtokP0eZ/CqBcvljITwAaBaIqJ0dwSqpR dxgHGcqXj1QYy7D5PDzUUiiAY= X-Received: by 2002:a05:600c:3e19:b0:48a:569c:abab with SMTP id 5b1f17b1804b1-48a77b12a61mr46745105e9.14.1777376386237; Tue, 28 Apr 2026 04:39:46 -0700 (PDT) Received: from xeon ([188.163.112.56]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a77aeb223sm43541125e9.3.2026.04.28.04.39.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 04:39:45 -0700 (PDT) From: Svyatoslav Ryhel To: Lee Jones , Pavel Machek , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sakari Ailus , Mauro Carvalho Chehab , Svyatoslav Ryhel Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v4 4/5] media: i2c: lm3560: Convert to use OF bindings Date: Tue, 28 Apr 2026 14:39:21 +0300 Message-ID: <20260428113923.112920-5-clamor95@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260428113923.112920-1-clamor95@gmail.com> References: <20260428113923.112920-1-clamor95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings. Converting to Device Tree assumes dynamic and independent registration of LEDs. To monitor the configured LEDs, a bitmap has been added. This makes LED cleanup more robust and less context dependent. Signed-off-by: Svyatoslav Ryhel --- drivers/media/i2c/lm3560.c | 145 ++++++++++++++++++++++++++----------- include/media/i2c/lm3560.h | 15 ---- 2 files changed, 102 insertions(+), 58 deletions(-) diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c index 5b568ed9536b..1052c11f42e8 100644 --- a/drivers/media/i2c/lm3560.c +++ b/drivers/media/i2c/lm3560.c @@ -9,11 +9,14 @@ * Ldd-Mlp */ =20 +#include #include #include #include #include +#include #include +#include #include #include #include @@ -43,22 +46,33 @@ enum led_enable { * struct lm3560_flash * * @dev: pointer to &struct device - * @pdata: platform data * @regmap: reg. map for i2c * @lock: muxtex for serial access. * @led_mode: V4L2 LED mode * @ctrls_led: V4L2 controls * @subdev_led: V4L2 subdev + * @led_id: LED status holder + * @peak: peak current + * @max_flash_timeout: flash timeout + * @max_flash_brt: flash mode led brightness + * @max_torch_brt: torch mode led brightness */ struct lm3560_flash { struct device *dev; - struct lm3560_platform_data *pdata; struct regmap *regmap; struct mutex lock; =20 enum v4l2_flash_led_mode led_mode; struct v4l2_ctrl_handler ctrls_led[LM3560_LED_MAX]; struct v4l2_subdev subdev_led[LM3560_LED_MAX]; + + DECLARE_BITMAP(led_id, LM3560_LED_MAX); + + enum lm3560_peak_current peak; + u32 max_flash_timeout; + + u32 max_flash_brt[LM3560_LED_MAX]; + u32 max_torch_brt[LM3560_LED_MAX]; }; =20 #define to_lm3560_flash(_ctrl, _no) \ @@ -269,8 +283,8 @@ static int lm3560_init_controls(struct lm3560_flash *fl= ash, enum lm3560_led_id led_no) { struct v4l2_ctrl *fault; - u32 max_flash_brt =3D flash->pdata->max_flash_brt[led_no]; - u32 max_torch_brt =3D flash->pdata->max_torch_brt[led_no]; + u32 max_flash_brt =3D flash->max_flash_brt[led_no]; + u32 max_torch_brt =3D flash->max_torch_brt[led_no]; struct v4l2_ctrl_handler *hdl =3D &flash->ctrls_led[led_no]; const struct v4l2_ctrl_ops *ops =3D &lm3560_led_ctrl_ops[led_no]; =20 @@ -295,9 +309,9 @@ static int lm3560_init_controls(struct lm3560_flash *fl= ash, /* flash strobe timeout */ v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_TIMEOUT, LM3560_FLASH_TOUT_MIN, - flash->pdata->max_flash_timeout, + flash->max_flash_timeout, LM3560_FLASH_TOUT_STEP, - flash->pdata->max_flash_timeout); + flash->max_flash_timeout); =20 /* flash brt */ v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_INTENSITY, @@ -339,15 +353,18 @@ static const struct regmap_config lm3560_regmap =3D { }; =20 static int lm3560_subdev_init(struct lm3560_flash *flash, - enum lm3560_led_id led_no, char *led_name) + enum lm3560_led_id led_no, + struct fwnode_handle *fwnode) { struct i2c_client *client =3D to_i2c_client(flash->dev); int rval; =20 v4l2_i2c_subdev_init(&flash->subdev_led[led_no], client, &lm3560_ops); flash->subdev_led[led_no].flags |=3D V4L2_SUBDEV_FL_HAS_DEVNODE; - strscpy(flash->subdev_led[led_no].name, led_name, - sizeof(flash->subdev_led[led_no].name)); + snprintf(flash->subdev_led[led_no].name, + sizeof(flash->subdev_led[led_no].name), + "lm3560-led%d", led_no); + flash->subdev_led[led_no].fwnode =3D fwnode; rval =3D lm3560_init_controls(flash, led_no); if (rval) goto err_out; @@ -378,7 +395,7 @@ static int lm3560_init_device(struct lm3560_flash *flas= h) =20 /* set peak current */ rval =3D regmap_update_bits(flash->regmap, - REG_FLASH_TOUT, 0x60, flash->pdata->peak); + REG_FLASH_TOUT, 0x60, flash->peak); if (rval < 0) return rval; /* output disable */ @@ -391,19 +408,23 @@ static int lm3560_init_device(struct lm3560_flash *fl= ash) return rval; } =20 -static void lm3560_subdev_cleanup(struct lm3560_flash *flash, - enum lm3560_led_id led_no) +static void lm3560_subdev_cleanup(struct lm3560_flash *flash) { - v4l2_async_unregister_subdev(&flash->subdev_led[led_no]); - v4l2_ctrl_handler_free(&flash->ctrls_led[led_no]); - media_entity_cleanup(&flash->subdev_led[led_no].entity); + int led_no; + + for_each_set_bit(led_no, flash->led_id, LM3560_LED_MAX) { + v4l2_async_unregister_subdev(&flash->subdev_led[led_no]); + v4l2_ctrl_handler_free(&flash->ctrls_led[led_no]); + media_entity_cleanup(&flash->subdev_led[led_no].entity); + } } =20 static int lm3560_probe(struct i2c_client *client) { struct lm3560_flash *flash; - struct lm3560_platform_data *pdata =3D dev_get_platdata(&client->dev); - int rval; + struct fwnode_handle *node; + u32 peak_ua; + int rval, reg; =20 flash =3D devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); if (flash =3D=3D NULL) @@ -415,36 +436,68 @@ static int lm3560_probe(struct i2c_client *client) return rval; } =20 - /* if there is no platform data, use chip default value */ - if (pdata =3D=3D NULL) { - pdata =3D devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); - if (pdata =3D=3D NULL) - return -ENODEV; - pdata->peak =3D LM3560_PEAK_3600mA; - pdata->max_flash_timeout =3D LM3560_FLASH_TOUT_MAX; - /* led 1 */ - pdata->max_flash_brt[LM3560_LED0] =3D LM3560_FLASH_BRT_MAX; - pdata->max_torch_brt[LM3560_LED0] =3D LM3560_TORCH_BRT_MAX; - /* led 2 */ - pdata->max_flash_brt[LM3560_LED1] =3D LM3560_FLASH_BRT_MAX; - pdata->max_torch_brt[LM3560_LED1] =3D LM3560_TORCH_BRT_MAX; - } - flash->pdata =3D pdata; flash->dev =3D &client->dev; mutex_init(&flash->lock); =20 - rval =3D lm3560_init_device(flash); - if (rval < 0) - return rval; + bitmap_zero(flash->led_id, LM3560_LED_MAX); =20 - rval =3D lm3560_subdev_init(flash, LM3560_LED0, "lm3560-led0"); + flash->peak =3D LM3560_PEAK_1600mA; + rval =3D device_property_read_u32(flash->dev, + "ti,peak-current-microamp", &peak_ua); + if (!rval) { + switch (peak_ua) { + case 1600000: + flash->peak =3D LM3560_PEAK_1600mA; + break; + case 2300000: + flash->peak =3D LM3560_PEAK_2300mA; + break; + case 3000000: + flash->peak =3D LM3560_PEAK_3000mA; + break; + case 3600000: + flash->peak =3D LM3560_PEAK_3600mA; + break; + default: + return -EINVAL; + } + } + + flash->max_flash_timeout =3D LM3560_FLASH_TOUT_MIN * 1000; + device_property_read_u32(flash->dev, "flash-max-timeout-us", + &flash->max_flash_timeout); + flash->max_flash_timeout /=3D 1000; + + rval =3D lm3560_init_device(flash); if (rval < 0) return rval; =20 - rval =3D lm3560_subdev_init(flash, LM3560_LED1, "lm3560-led1"); - if (rval < 0) { - lm3560_subdev_cleanup(flash, LM3560_LED0); - return rval; + device_for_each_child_node(flash->dev, node) { + rval =3D fwnode_property_read_u32(node, "reg", ®); + if (rval < 0) + /* We care only about nodes with reg property */ + continue; + + if (reg =3D=3D LM3560_LED0 || reg =3D=3D LM3560_LED1) { + flash->max_flash_brt[reg] =3D LM3560_FLASH_BRT_MIN; + fwnode_property_read_u32(node, "flash-max-microamp", + &flash->max_flash_brt[reg]); + + flash->max_torch_brt[reg] =3D LM3560_TORCH_BRT_MIN; + fwnode_property_read_u32(node, "led-max-microamp", + &flash->max_torch_brt[reg]); + + rval =3D lm3560_subdev_init(flash, reg, node); + if (rval < 0) { + fwnode_handle_put(node); + lm3560_subdev_cleanup(flash); + return dev_err_probe(flash->dev, rval, + "failed to register led%d\n", + reg); + } + + set_bit(reg, flash->led_id); + } } =20 i2c_set_clientdata(client, flash); @@ -455,12 +508,17 @@ static int lm3560_probe(struct i2c_client *client) static void lm3560_remove(struct i2c_client *client) { struct lm3560_flash *flash =3D i2c_get_clientdata(client); - unsigned int i; =20 - for (i =3D LM3560_LED0; i < LM3560_LED_MAX; i++) - lm3560_subdev_cleanup(flash, i); + lm3560_subdev_cleanup(flash); } =20 +static const struct of_device_id lm3560_of_match[] =3D { + { .compatible =3D "ti,lm3559" }, + { .compatible =3D "ti,lm3560" }, + { } +}; +MODULE_DEVICE_TABLE(of, lm3560_of_match); + static const struct i2c_device_id lm3560_id_table[] =3D { { LM3559_NAME }, { LM3560_NAME }, @@ -473,6 +531,7 @@ static struct i2c_driver lm3560_i2c_driver =3D { .driver =3D { .name =3D LM3560_NAME, .pm =3D NULL, + .of_match_table =3D lm3560_of_match, }, .probe =3D lm3560_probe, .remove =3D lm3560_remove, diff --git a/include/media/i2c/lm3560.h b/include/media/i2c/lm3560.h index 770d8c72c94a..b56c1ff8fd49 100644 --- a/include/media/i2c/lm3560.h +++ b/include/media/i2c/lm3560.h @@ -66,19 +66,4 @@ enum lm3560_peak_current { LM3560_PEAK_3600mA =3D 0x60 }; =20 -/* struct lm3560_platform_data - * - * @peak : peak current - * @max_flash_timeout: flash timeout - * @max_flash_brt: flash mode led brightness - * @max_torch_brt: torch mode led brightness - */ -struct lm3560_platform_data { - enum lm3560_peak_current peak; - - u32 max_flash_timeout; - u32 max_flash_brt[LM3560_LED_MAX]; - u32 max_torch_brt[LM3560_LED_MAX]; -}; - #endif /* __LM3560_H__ */ --=20 2.51.0 From nobody Wed Jun 17 02:50:48 2026 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D2C53AF656 for ; Tue, 28 Apr 2026 11:39:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777376393; cv=none; b=sNB+eD5eXWAqHKYt3cmtAgfDHb5FOZR+t2luLOTzCOHmsOgCYnL+2BcxzhO/Llkt949jfbN72jYbPkRaprfcxtMStZ89J0GnF4SaX2kOnipflxveX+mG0QTMwyiwTYffIGWCptpaePa9gU5H+wzRi8ugzyAnXMrkXz5Ko7MaIGk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777376393; c=relaxed/simple; bh=liWseIjFkuXVt4TWv2i3U3BN73xnSKmtLaF9Z6gcVcY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KeIi5aVs/DmtDY+b1eCaFLCNzTqm6ANk7zhh8RVjx/0yQi796QNFQve7sJTcv0QWPHL3USyuXz0vTvalv0jGSr7v7bpABb7vs/gQZs2oFoZaFf9eJmWrcWkTgprgc8EbbUZHRN49ck3XizlBYm4Rc76UmRM4bHf7HwPJv5R1m+E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c1gzpOYL; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c1gzpOYL" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4852b81c73aso94085595e9.3 for ; Tue, 28 Apr 2026 04:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777376388; x=1777981188; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iONjqkBbha9vIXYKPOr4JdhI2heccbufxTPWG9w70fs=; b=c1gzpOYLEp6OZtxkgha/y4PHz86quAHV0F6O18LwvgydXWjUvzoP2cX2qNKaTZ8HeP wCQHpz4z1owhcpvaONdrR+ETgXzgtFjY/823KCboBSXRgqxAftvQRV2itTcigTS0G1os XRN7Ta6HhifMDsaRhuR6LcU07cpd6ECRrluucI5sbNSHfeV0hhEl1eVQig54KLDAAZo3 c13OkUwll9+uA3kyfrfk18Qca7b3FLDPkXBNYy8gN4AIDL05pTVp+QoFb51zir5pJD61 skZ7a6EXksvKl2X8QL21QOTQdPH+fb24LU7l0ZZRfyhPsEI6P3DgqRQc+1IPK36YeV+L 7rnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777376388; x=1777981188; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iONjqkBbha9vIXYKPOr4JdhI2heccbufxTPWG9w70fs=; b=mBiHx7W+A0n+n7X4l2Y2h/GSZwyZjExojFEYRFNaR4/KJt1OiHdFjTXcsY4LIlUzm/ TV8c3/hPFmlSjGmUXU/r1uAMcHB7T0Zik/RAOeeNO5KQR5RxmWi0dvcZoykb3R4OdZ6q mTgzgV2zg0m39WVhP73RaC5y2SmjJE98e91pJgbHC6v9sGyx8ZKb+5EJkjZWHkpzsVyN TVRXNlnp6o5OIV5aInos6Qul4isy1MYvENyqKbfmXrtmQR+MYEzVZDBiGCgbf/Qc25nZ KcRC5e33vljzyNoVHObFxDvbinkumJ8JZoOGjfUhNg3CTCvNkBv0ZvITsmLkjPPegMzS HNlw== X-Forwarded-Encrypted: i=1; AFNElJ+DqObFxa5Jcd8ipdaa6bXLq80pQ4SgGneCp4ly7N0GWJUI4CDVNOJJ1/HgugNFlbrUcssg17VPF+HOJME=@vger.kernel.org X-Gm-Message-State: AOJu0Yzqv9p9wzN2ah4yBLY43nFo1rtciO5K1w1cglzWMxthh2OYYZtv QGN1UfBB/VGQkqVrzyFfu82BSkV35wh1qTohO2XO7MvCchz/y4RRtOXt X-Gm-Gg: AeBDiesIuqL3nd4viLNe+nfZ7HPkHhNmWColZfpwHkmhTPKs+nlt5xgto9iiy0cl/od bgOqruSL1SIca9dqPPB5pyY2CKnd8x0oARdLVM0mkWgnJ5wSDbZdTuECGR2sIkAFfaaR2CgzHip 1aI7b3cICibtoBUuYpPTpFdskz5CBC97wsDVkzFKXg1KjWb7M1qhRujHPH/f+dqsElCzAYZQbT4 255+QL5/nOFi68HGmRNL4s4cIKDfBNMsjt6Un/3JwnaXFGeydETaMUvA+WmF6uKLh4GTq0ySM7S VldCj1ibiwfqp7wOX9ABCoCQPWaP5bcRA2Cgmp8uJjyq04LpwIDvHKW1GNrpzDZfZormFWe0+Mm tuNOMr33K9T3+ugN/xeXiSz1jdC02EaNBqr+QYriujzsc+E71EGTHkGzDipZHBVyNot01IFm/zH jXzIaCEXlPL+fyuuykxQfGFBg= X-Received: by 2002:a05:600c:8582:b0:485:3abe:ab86 with SMTP id 5b1f17b1804b1-48a77af3ddamr28904405e9.4.1777376387345; Tue, 28 Apr 2026 04:39:47 -0700 (PDT) Received: from xeon ([188.163.112.56]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a77aeb223sm43541125e9.3.2026.04.28.04.39.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 04:39:46 -0700 (PDT) From: Svyatoslav Ryhel To: Lee Jones , Pavel Machek , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sakari Ailus , Mauro Carvalho Chehab , Svyatoslav Ryhel Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v4 5/5] media: i2c: lm3560: Add support for PM features Date: Tue, 28 Apr 2026 14:39:22 +0300 Message-ID: <20260428113923.112920-6-clamor95@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260428113923.112920-1-clamor95@gmail.com> References: <20260428113923.112920-1-clamor95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for power management features to better control the LM3560 within the media framework. To achieve the desired PM support, the HWEN GPIO and VIN power supply were added and configured into power on/off sequences. Added PM operations along with the PM configuration setup. Signed-off-by: Svyatoslav Ryhel --- drivers/media/i2c/lm3560.c | 117 ++++++++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 7 deletions(-) diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c index 1052c11f42e8..29f3ee98e0ca 100644 --- a/drivers/media/i2c/lm3560.c +++ b/drivers/media/i2c/lm3560.c @@ -12,12 +12,15 @@ #include #include #include +#include #include #include #include #include +#include #include #include +#include #include #include #include @@ -48,6 +51,8 @@ enum led_enable { * @dev: pointer to &struct device * @regmap: reg. map for i2c * @lock: muxtex for serial access. + * @hwen_gpio: line connected to HWEN pin + * @vin_supply: line connected to IN supply (2.5V - 5.5V) * @led_mode: V4L2 LED mode * @ctrls_led: V4L2 controls * @subdev_led: V4L2 subdev @@ -62,6 +67,9 @@ struct lm3560_flash { struct regmap *regmap; struct mutex lock; =20 + struct gpio_desc *hwen_gpio; + struct regulator *vin_supply; + enum v4l2_flash_led_mode led_mode; struct v4l2_ctrl_handler ctrls_led[LM3560_LED_MAX]; struct v4l2_subdev subdev_led[LM3560_LED_MAX]; @@ -176,12 +184,17 @@ static int lm3560_get_ctrl(struct v4l2_ctrl *ctrl, en= um lm3560_led_id led_no) struct lm3560_flash *flash =3D to_lm3560_flash(ctrl, led_no); int rval =3D -EINVAL; =20 + if (!pm_runtime_get_if_in_use(flash->dev)) + return 0; + if (ctrl->id =3D=3D V4L2_CID_FLASH_FAULT) { s32 fault =3D 0; unsigned int reg_val; rval =3D regmap_read(flash->regmap, REG_FLAG, ®_val); - if (rval < 0) + if (rval < 0) { + pm_runtime_put(flash->dev); return rval; + } if (reg_val & FAULT_SHORT_CIRCUIT) fault |=3D V4L2_FLASH_FAULT_SHORT_CIRCUIT; if (reg_val & FAULT_OVERTEMP) @@ -191,6 +204,8 @@ static int lm3560_get_ctrl(struct v4l2_ctrl *ctrl, enum= lm3560_led_id led_no) ctrl->cur.val =3D fault; } =20 + pm_runtime_put(flash->dev); + return rval; } =20 @@ -200,6 +215,9 @@ static int lm3560_set_ctrl(struct v4l2_ctrl *ctrl, enum= lm3560_led_id led_no) u8 tout_bits; int rval =3D -EINVAL; =20 + if (!pm_runtime_get_if_in_use(flash->dev)) + return 0; + switch (ctrl->id) { case V4L2_CID_FLASH_LED_MODE: flash->led_mode =3D ctrl->val; @@ -245,6 +263,8 @@ static int lm3560_set_ctrl(struct v4l2_ctrl *ctrl, enum= lm3560_led_id led_no) break; } =20 + pm_runtime_put(flash->dev); + return rval; } =20 @@ -408,6 +428,38 @@ static int lm3560_init_device(struct lm3560_flash *fla= sh) return rval; } =20 +static int lm3560_power_off(struct device *dev) +{ + struct lm3560_flash *flash =3D dev_get_drvdata(dev); + + gpiod_set_value_cansleep(flash->hwen_gpio, 0); + regulator_disable(flash->vin_supply); + + return 0; +} + +static int lm3560_power_on(struct device *dev) +{ + struct lm3560_flash *flash =3D dev_get_drvdata(dev); + int rval; + + rval =3D regulator_enable(flash->vin_supply); + if (rval < 0) { + dev_err(flash->dev, "failed to enable vin power supply\n"); + return rval; + } + + gpiod_set_value_cansleep(flash->hwen_gpio, 1); + + rval =3D lm3560_init_device(flash); + if (rval < 0) { + lm3560_power_off(dev); + return rval; + } + + return 0; +} + static void lm3560_subdev_cleanup(struct lm3560_flash *flash) { int led_no; @@ -441,6 +493,17 @@ static int lm3560_probe(struct i2c_client *client) =20 bitmap_zero(flash->led_id, LM3560_LED_MAX); =20 + flash->hwen_gpio =3D devm_gpiod_get_optional(flash->dev, "enable", + GPIOD_OUT_LOW); + if (IS_ERR(flash->hwen_gpio)) + return dev_err_probe(flash->dev, PTR_ERR(flash->hwen_gpio), + "failed to get hwen gpio\n"); + + flash->vin_supply =3D devm_regulator_get(flash->dev, "vin"); + if (IS_ERR(flash->vin_supply)) + return dev_err_probe(flash->dev, PTR_ERR(flash->vin_supply), + "failed to get vin-supply\n"); + flash->peak =3D LM3560_PEAK_1600mA; rval =3D device_property_read_u32(flash->dev, "ti,peak-current-microamp", &peak_ua); @@ -468,9 +531,19 @@ static int lm3560_probe(struct i2c_client *client) &flash->max_flash_timeout); flash->max_flash_timeout /=3D 1000; =20 + rval =3D regulator_enable(flash->vin_supply); + if (rval < 0) + return dev_err_probe(flash->dev, rval, + "failed to enable vin power supply\n"); + + gpiod_set_value_cansleep(flash->hwen_gpio, 1); + rval =3D lm3560_init_device(flash); if (rval < 0) - return rval; + goto error_disable; + + pm_runtime_set_active(flash->dev); + pm_runtime_enable(flash->dev); =20 device_for_each_child_node(flash->dev, node) { rval =3D fwnode_property_read_u32(node, "reg", ®); @@ -490,10 +563,10 @@ static int lm3560_probe(struct i2c_client *client) rval =3D lm3560_subdev_init(flash, reg, node); if (rval < 0) { fwnode_handle_put(node); - lm3560_subdev_cleanup(flash); - return dev_err_probe(flash->dev, rval, - "failed to register led%d\n", - reg); + dev_err(flash->dev, + "failed to register led%d: %d\n", + reg, rval); + goto error_clean; } =20 set_bit(reg, flash->led_id); @@ -502,7 +575,23 @@ static int lm3560_probe(struct i2c_client *client) =20 i2c_set_clientdata(client, flash); =20 + pm_runtime_set_autosuspend_delay(flash->dev, 1000); + pm_runtime_use_autosuspend(flash->dev); + pm_runtime_idle(flash->dev); + return 0; + +error_clean: + pm_runtime_disable(flash->dev); + pm_runtime_set_suspended(flash->dev); + + lm3560_subdev_cleanup(flash); + +error_disable: + gpiod_set_value_cansleep(flash->hwen_gpio, 0); + regulator_disable(flash->vin_supply); + + return rval; } =20 static void lm3560_remove(struct i2c_client *client) @@ -510,8 +599,22 @@ static void lm3560_remove(struct i2c_client *client) struct lm3560_flash *flash =3D i2c_get_clientdata(client); =20 lm3560_subdev_cleanup(flash); + + /* + * Disable runtime PM. In case runtime PM is disabled in the kernel, + * make sure to turn power off manually. + */ + pm_runtime_disable(&client->dev); + if (!pm_runtime_status_suspended(&client->dev)) { + lm3560_power_off(&client->dev); + pm_runtime_set_suspended(&client->dev); + } } =20 +static const struct dev_pm_ops lm3560_pm_ops =3D { + SET_RUNTIME_PM_OPS(lm3560_power_off, lm3560_power_on, NULL) +}; + static const struct of_device_id lm3560_of_match[] =3D { { .compatible =3D "ti,lm3559" }, { .compatible =3D "ti,lm3560" }, @@ -530,7 +633,7 @@ MODULE_DEVICE_TABLE(i2c, lm3560_id_table); static struct i2c_driver lm3560_i2c_driver =3D { .driver =3D { .name =3D LM3560_NAME, - .pm =3D NULL, + .pm =3D pm_ptr(&lm3560_pm_ops), .of_match_table =3D lm3560_of_match, }, .probe =3D lm3560_probe, --=20 2.51.0