From patchwork Sat Jun 15 23:11:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805060 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54242171B0; Sat, 15 Jun 2024 23:12:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493173; cv=none; b=XcGfNz+SGCHnblw+mZAO9j+uH2arKvI5dvVUn42AISF0wW58wx7z96rC/7CmVuAt2B2MoiNr5Q3MveHZ9uzbMsv2DEMdz7NcmScG5XIXVJ71AnaCQI6jKsbDxfPCzLfSeLllo8oiHD2ch6wz7zE/rCyl8fhcG6bz7FRfJhDwTVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493173; c=relaxed/simple; bh=uJNHCAS/njBj0P1AkFg9onLP6rk8u5HT5DX/4ybEeDA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xu4lwJgTSCucoC9reyFbPlMyPBcyof4a6Kg6HLbXqk6PLx/mCM/qvpTTFxSveoN0b1uSX6qemCXYD0Z8Ja7braCw1dvN6jMJCQg/Fr+V4v1AQ2cEdrIbo4kjACVHVfSnmq7QfbzWGTs4fw9OS5pWqkqd9WmN9yB+4QMS54Ta/9Q= 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=CT4t42wl; arc=none smtp.client-ip=209.85.221.43 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="CT4t42wl" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-35f2d723ef0so2865061f8f.1; Sat, 15 Jun 2024 16:12:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493171; x=1719097971; 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=hhl9kavocLfzcqvimV+c3enKC1Q7IIpoT3nV0k3W8no=; b=CT4t42wld13m6zDkf4mcGTFokkXt6Wb+vFrVxiKmZjf97+/PwepdHZhFO87QUHH8EU 9nQHnxpD9xVzT2EqMhTBQ6nKG7UYy5WZkRcIMMNZdbf6HXrdIK60HV7ylImdVb3pypWK zRm+OTji7S8n3MA2FFFX5iOx0ln3mu8oOHQL6lHuwjkqi0YdZY/Z9eMKhkFuv72FH6Xr D4WDOqAUTkNf6eHjm5qH1iZDiewG3yFc/C+RDj1p9EmTXUSVk5cT6e7V08welUW23RIx WhPf3Et3LSQDE2YdrcbrLdMJjJ/n087boh8tgWiLmib1O76u0DBuGFv49AQ4as/5Adg3 HWHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493171; x=1719097971; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hhl9kavocLfzcqvimV+c3enKC1Q7IIpoT3nV0k3W8no=; b=E56RPA7vWddC20W4ME2g75HhOWjrcxvpiXJETOloRKSdgy130dUWzTHJU2O22jIgqy F12LyXk+8ZQpFtRctws5g67Ji+xWN/jZTX+EUsJcqf4qss0SIn0W0Z9KD6U21gYXN927 tnH426ICQPDzdU0hl22lTM5h+J1yR3WVMz4e6gWmQ25kIx+xfwOSZJkcJiHi2XnXg1AI x3owYwbCBjDdnZTxo/DxFvflbjlLqItejxLNaSBiaZI20gVrBDoPlMS+f5Lo1MEESv6K hbeKHUNNjLfu53VdEh+xsS5EBxh9CWDeM4RAMuem3dldSLVegv8G6k93v6m+jnsKgy65 wBew== X-Forwarded-Encrypted: i=1; AJvYcCVO0Nfts4LK21yjkdCooVHLEImpvR2+96JQ5Yn2RG5xrShOXYqH2JnltzyGE3ieHjCy1niygonrCcnHU7guDKSFQlzU/M8EyLtd9RoKoYC6Sk8sut7o4FNILirnzviCCh8rRrP60bqzRJy3ZoVvQFUTbK5zleE+huw3MmKhAaAdz0y/wQc= X-Gm-Message-State: AOJu0Yz9WRr1hhR74B4zaNs3GgNnBDNGyUB4r4Vh7FXWu1Qs3KtV5tz4 TtezYHLnFqLaoBomUotW7amYAQIKZStUIumWgGRaWioAQCLokAwr X-Google-Smtp-Source: AGHT+IHhtkIpspuVDjEAU+y6cLXh0UeyxdihKJNNZa6ThcAfR2u265DyiMdC/wlKlkfGl6MM0/BYgQ== X-Received: by 2002:adf:f584:0:b0:35f:2b1d:433 with SMTP id ffacd0b85a97d-3607a746a11mr4485896f8f.26.1718493170556; Sat, 15 Jun 2024 16:12:50 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:12:50 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 01/20] dt-bindings: leds-lp55xx: limit pwr-sel property to ti,lp8501 Date: Sun, 16 Jun 2024 01:11:31 +0200 Message-ID: <20240615231152.28201-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 pwr-sel property is specific to ti,lp8501, make it conditional of the related compatible. Signed-off-by: Christian Marangi Acked-by: Rob Herring (Arm) --- .../devicetree/bindings/leds/leds-lp55xx.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/leds/leds-lp55xx.yaml b/Documentation/devicetree/bindings/leds/leds-lp55xx.yaml index e9d4514d0166..77828dedbb9f 100644 --- a/Documentation/devicetree/bindings/leds/leds-lp55xx.yaml +++ b/Documentation/devicetree/bindings/leds/leds-lp55xx.yaml @@ -151,6 +151,16 @@ patternProperties: $ref: /schemas/types.yaml#/definitions/string description: name of channel +if: + not: + properties: + compatible: + contains: + const: ti,lp8501 +then: + properties: + pwr-sel: false + required: - compatible - reg From patchwork Sat Jun 15 23:11:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804585 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 A219261FF4; Sat, 15 Jun 2024 23:12:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493175; cv=none; b=QHNb8A8qlLg56HaBPmHo2b28yPOASViHDl2aOmfWnSXkQa0wRB6BcDZi9w2tS1IH5vAq+lP977UtrHXt+HUyjamOw9gQGwSXOa3pRWtUqTVb+6rbRO58zGcnA/Fv2Y5P3zA79G01h8hvxvfWYr5YJ6lEGV7g91pfgWW1pR//lSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493175; c=relaxed/simple; bh=Y77MrkgTPpF9SsM+rM+21V+XO+R9QBEbnKLnh784hwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KQilNTEX9VOZq5h8Y1PyMwQvDlbRi0l/St6bZ06uhXLLhDnriu9VVEWk94k2N6ZO2YyJuJ0GQKyojqR9MRmqMYdWFDurV5UliQCN0she+Jo81M5gVDttGdNMBrp5liZvbIdgakg7AExgvUrn9sEK1t2/QksfhHAgjfWjcP7i7Uw= 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=T0873CJN; arc=none smtp.client-ip=209.85.221.41 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="T0873CJN" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-35f089e35e7so2148223f8f.0; Sat, 15 Jun 2024 16:12:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493172; x=1719097972; 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=icpBlnTDdeuMUSDTs5EH982zOvuXd6X7dmffVumwKI8=; b=T0873CJNdMMlanFn+eVhaDV01wq9AeWWSVuDTLn+fcU10+b/n2XKp9Tb9GCo9SjjhZ 90N5k+T5wxKdZGzTR5N8w/yRgLxwpt84kjBjBNj58wV4/aZa/dk/OP1Rp4K6aXpWgy9U P2w+333QpfCaiYwbLtu9E+S7zsSF8nWiGhqohxSQsl4o9vGQt2ttekQ8MFrV39oatYjP wq6g8n4/kSbR6N1hNAFUyWZKzV0s7uP/EAPLfcThGp52ggJ7lMT/nA2BQo7mp6y8Rjbw kI+xXZLWsXoT9ZjsHqK0KiEgTigf+9ZElGOsG3mUoNdTr3RPGPpSRLCWrQZwwwWR41a1 4dCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493172; x=1719097972; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=icpBlnTDdeuMUSDTs5EH982zOvuXd6X7dmffVumwKI8=; b=CFfN06clXNv74kZPVRrbEb+aTBVveACl8yLyXe7CgHQHHMEK9vZyywDK0IP+LL2Wjh BI5sj83XCsE/IpQX7CQLGAMapgZq102xuJmhCDOtfCMENW85pZq4lLQ72UArw4Evfro2 gwu4J/HudDKSy6Ccis2KpWJcvVIfXQxjg4YIwsJNrsjY0pleM1Cl4KKbDxn+fhHQI08q tUV7sO0NPafU3Mnf9WKIMMlN37UcIqiHz5PFrOSyxeGEA4Mv74mdOwl3gtVZqDrNVrus IHvFwEf6P+UgkRl+NeUUi/brXxBVZi5xPbWPZWT39VUd01vqcGpbMwD8Z3kuWZ1K1CKO E6DQ== X-Forwarded-Encrypted: i=1; AJvYcCVNfmR1tWQOp6CYLtw5L0MfNXyz7ZAhLRmV0/36FeRF9wn+UU6veh9gNinfvvFCWnL/rAGd+3NX2910fGDnYkMOUKK2Ni8/L+n0HvHxA82qUs2pAsllqJy1ZPgk3XJ5MvrmBkNgv9wSUBN69NUeUzJfaD6bNFpy39CYoT0dIBAhGPajpyk= X-Gm-Message-State: AOJu0Yx/rRXBqsAm3io4j1yzmr2LaDkHIAyixsT8SkAnb7cSGJd3aUjY zdrKYalNEwyQ5XUoNsuTCinXWvLhmHkqRltZdLrZ4TLu6E4i3VQo X-Google-Smtp-Source: AGHT+IGnWe0YtPha/kSXCaPedR48JnOd+Z7TjQuF7S1Uz+gM07Td4oPj43fgbmA7xrhZJnVzUpOGIQ== X-Received: by 2002:adf:ea04:0:b0:35f:22e3:1e0c with SMTP id ffacd0b85a97d-3607a7e7c65mr4483920f8f.69.1718493171675; Sat, 15 Jun 2024 16:12:51 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:12:51 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi , Conor Dooley Subject: [PATCH v5 02/20] dt-bindings: leds-lp55xx: Add new ti,lp5569 compatible Date: Sun, 16 Jun 2024 01:11:32 +0200 Message-ID: <20240615231152.28201-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add new ti,lp5569 compatible, this is similar to national,lp5523 with slight change to reg order and reg type and advanced way for LED fault. Signed-off-by: Christian Marangi Acked-by: Conor Dooley --- Documentation/devicetree/bindings/leds/leds-lp55xx.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/leds/leds-lp55xx.yaml b/Documentation/devicetree/bindings/leds/leds-lp55xx.yaml index 77828dedbb9f..fe8aaecf3010 100644 --- a/Documentation/devicetree/bindings/leds/leds-lp55xx.yaml +++ b/Documentation/devicetree/bindings/leds/leds-lp55xx.yaml @@ -28,6 +28,7 @@ properties: - national,lp5523 - ti,lp55231 - ti,lp5562 + - ti,lp5569 - ti,lp8501 reg: From patchwork Sat Jun 15 23:11:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805059 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C7156CDB1; Sat, 15 Jun 2024 23:12:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493176; cv=none; b=kvlwwA4AxV9/WEKAG0s9y1d/U34AryWPiqPfuZRKMxhlXt6FbleprzATBgvII4mJttN6LUcDygCq6rPB9EErx8LgfHbOOPv8j5DI5yV8qltzpLHMpkBHbdbU2rObOWudVMKrcxDEOYphd4YdpI7osXvU0K8KEtmSlwPLZwLIttk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493176; c=relaxed/simple; bh=7K9mqaTETySvuzjK9xdgn1c1FBiHLPCe90b8s130S88=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l0w4sUpX0Jcy1Yo8pXaGaEocN5XsPWNxugpE9cWtSaOCugM4OFeh+AR3PGQVIHI5aDeav1janfFCU/aLXor/1zorksFPJ172iURQB0YExLfBV4jFbENdTY12UOmZ8YWz/SYo54PjieiBWo4dVMAn+HTQHSqGY6ttmduxieUUnhg= 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=ihqhHd+5; arc=none smtp.client-ip=209.85.221.47 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="ihqhHd+5" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-35f1c209842so2473675f8f.3; Sat, 15 Jun 2024 16:12:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493173; x=1719097973; 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=bgUqbKJ3KZ0XYOb7eIEMwltUD5FPtloQr77Z4ivfpvU=; b=ihqhHd+5UeYxZew8IUDXRG4bP+j9nGX6bDiPpTMcdcen87N/y6pWeev30i7nuFrcif srk/JQ6VVKpP3p2V4gq4yA97eFcSum00llUmYyXt1pSIK0rbKe6YqN/vqkHZhOUe5UJx mTW9No5MLyUZ+qrbmPAbQkESlJkXkpSl1xwpmmiNsVo9AyXYVpsxhqDozno8+gFUVdss iz7NTGS8gzMVUl627eK1PcJ26ZHbbkkp7C8FmEVo2T+R9Yg0+wg8VZMAWyPZjMjcNtKx p4r/J3hPyyh0rxuPT8dCNwwaJN4ueUFZc0DI8Mn1DnboYV5m6NpiVTiaBoa0hqMdetxn z1tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493173; x=1719097973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bgUqbKJ3KZ0XYOb7eIEMwltUD5FPtloQr77Z4ivfpvU=; b=R+97gmBARklZEzj8NOvyydVTiGdMM6gaEmPzKoG9h4ShoywRlZEaQG9VIrV4YRy8Ha +ZxJv5JnydmU4BrM0pRgjqxBIj8WcOOPuLelkAQ79uTco40Rcy4vzb2bYbECeF6HUB4N j7DnA7hwngzooGyNd54og3VZm2DrZVgVEtWD1V5uPAwGfA0wTMltB+clBaKLDCqgrByp dMYCGJSWrgUumRMXLZJRR7R8vZJkYmLoMmXRHt8BoWAOMi/LAW6Vhr4UHNr7a0LJz49A GscVhBhjaZcKuE6cgUeiaiQ/aBZ/+AHoWB4HWbY7Frk0c9ymzF92EcNsgCM/rPgqRfOs SPuQ== X-Forwarded-Encrypted: i=1; AJvYcCVNhQW6y+ZUthAXmMcuRvROxKf7NtDv6FIypNmEiaduBJGl/LvHKbgAa4aXE4sR5NKCNc82C3cKVqnaXPbkRKl+g0hBepOx6odWHILs/oNTtMhSLt60xloLPiABB2lMI1+W79/I6N34eZIRqwPri5FUC9LVHZbK8KcshBHu3UJImjL2DJs= X-Gm-Message-State: AOJu0Yw9hlj+H7Wcfu0tvjX0/EyAk0rAJK7ydd4FvKIxNJyncaBx9Kuj vQunpb9wt0PRmETwbHDA5jGxkCckcZSvX61gxweZcxpYsufjkSaZYeqlWw== X-Google-Smtp-Source: AGHT+IFX/I/rUoGx5Iayxk80cUJbp3dQzagVxQu9Oy7ry6EpORCwj7ROacPyFJdL/WotX4l6EL7fkA== X-Received: by 2002:adf:ff82:0:b0:360:827f:1c40 with SMTP id ffacd0b85a97d-360827f1e37mr3692074f8f.54.1718493172772; Sat, 15 Jun 2024 16:12:52 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:12:52 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 03/20] leds: leds-lp55xx: generalize stop_all_engine OP Date: Sun, 16 Jun 2024 01:11:33 +0200 Message-ID: <20240615231152.28201-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In all the lp55xx based driver, we have a similar implementation of the stop_all_engine function with the only difference of the required sleep for the OP MODE change. The main difference is legacy LEDs require a min of 152 us while new one use a generic 1-2ms. The new one use a 1-2ms sleep as suggested in the datasheet IN ALTERNATIVE to a much more robust approach by using the newly introduced ENGINE_BUSY bit in the STATUS reg. To better handle sleep after OP MODE change, add support for polling the ENGINE_BUSY bit and use the legacy sleep for old LEDs. With this change, stop_all_engine can be generalized and moved to lp55xx-common. To make more clear the double usage of lp55xx_reg, define a union for additional scope of mask and shift. Update all lp55xx based driver to use the new generalized function and define the required bits in the device_config struct. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 11 ++++------ drivers/leds/leds-lp5523.c | 20 +++++++++++------- drivers/leds/leds-lp5562.c | 15 ++++++------- drivers/leds/leds-lp55xx-common.c | 35 +++++++++++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 16 ++++++++++++-- drivers/leds/leds-lp8501.c | 20 +++++++++++------- 6 files changed, 83 insertions(+), 34 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index f9c8b568b652..15ef5ae58623 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -135,12 +135,6 @@ static void lp5521_load_engine(struct lp55xx_chip *chip) lp5521_wait_opmode_done(); } -static void lp5521_stop_all_engines(struct lp55xx_chip *chip) -{ - lp55xx_write(chip, LP5521_REG_OP_MODE, 0); - lp5521_wait_opmode_done(); -} - static void lp5521_stop_engine(struct lp55xx_chip *chip) { enum lp55xx_engine_index idx = chip->engine_idx; @@ -499,6 +493,9 @@ static const struct attribute_group lp5521_group = { /* Chip specific configurations */ static struct lp55xx_device_config lp5521_cfg = { + .reg_op_mode = { + .addr = LP5521_REG_OP_MODE, + }, .reset = { .addr = LP5521_REG_RESET, .val = LP5521_RESET, @@ -585,7 +582,7 @@ static void lp5521_remove(struct i2c_client *client) struct lp55xx_led *led = i2c_get_clientdata(client); struct lp55xx_chip *chip = led->chip; - lp5521_stop_all_engines(chip); + lp55xx_stop_all_engine(chip); lp55xx_unregister_sysfs(chip); lp55xx_deinit_device(chip); } diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 38de853f9939..79931555eddd 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -41,7 +41,10 @@ #define LP5523_REG_LED_PWM_BASE 0x16 #define LP5523_REG_LED_CURRENT_BASE 0x26 #define LP5523_REG_CONFIG 0x36 + #define LP5523_REG_STATUS 0x3A +#define LP5523_ENGINE_BUSY BIT(4) + #define LP5523_REG_RESET 0x3D #define LP5523_REG_LED_TEST_CTRL 0x41 #define LP5523_REG_LED_TEST_ADC 0x42 @@ -190,12 +193,6 @@ static void lp5523_load_engine_and_select_page(struct lp55xx_chip *chip) lp55xx_write(chip, LP5523_REG_PROG_PAGE_SEL, page_sel[idx]); } -static void lp5523_stop_all_engines(struct lp55xx_chip *chip) -{ - lp55xx_write(chip, LP5523_REG_OP_MODE, 0); - lp5523_wait_opmode_done(); -} - static void lp5523_stop_engine(struct lp55xx_chip *chip) { enum lp55xx_engine_index idx = chip->engine_idx; @@ -322,7 +319,7 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) } out: - lp5523_stop_all_engines(chip); + lp55xx_stop_all_engine(chip); return ret; } @@ -873,6 +870,13 @@ static const struct attribute_group lp5523_group = { /* Chip specific configurations */ static struct lp55xx_device_config lp5523_cfg = { + .reg_op_mode = { + .addr = LP5523_REG_OP_MODE, + }, + .engine_busy = { + .addr = LP5523_REG_STATUS, + .mask = LP5523_ENGINE_BUSY, + }, .reset = { .addr = LP5523_REG_RESET, .val = LP5523_RESET, @@ -959,7 +963,7 @@ static void lp5523_remove(struct i2c_client *client) struct lp55xx_led *led = i2c_get_clientdata(client); struct lp55xx_chip *chip = led->chip; - lp5523_stop_all_engines(chip); + lp55xx_stop_all_engine(chip); lp55xx_unregister_sysfs(chip); lp55xx_deinit_device(chip); } diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index 39db9aeb67c5..28469bd2c75b 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -144,12 +144,6 @@ static void lp5562_load_engine(struct lp55xx_chip *chip) lp5562_wait_opmode_done(); } -static void lp5562_stop_engine(struct lp55xx_chip *chip) -{ - lp55xx_write(chip, LP5562_REG_OP_MODE, LP5562_CMD_DISABLE); - lp5562_wait_opmode_done(); -} - static void lp5562_run_engine(struct lp55xx_chip *chip, bool start) { int ret; @@ -160,7 +154,7 @@ static void lp5562_run_engine(struct lp55xx_chip *chip, bool start) if (!start) { lp55xx_write(chip, LP5562_REG_ENABLE, LP5562_ENABLE_DEFAULT); lp5562_wait_enable_done(); - lp5562_stop_engine(chip); + lp55xx_stop_all_engine(chip); lp55xx_write(chip, LP5562_REG_ENG_SEL, LP5562_ENG_SEL_PWM); lp55xx_write(chip, LP5562_REG_OP_MODE, LP5562_CMD_DIRECT); lp5562_wait_opmode_done(); @@ -369,7 +363,7 @@ static int lp5562_run_predef_led_pattern(struct lp55xx_chip *chip, int mode) return -EINVAL; } - lp5562_stop_engine(chip); + lp55xx_stop_all_engine(chip); /* Set LED map as RGB */ lp55xx_write(chip, LP5562_REG_ENG_SEL, LP5562_ENG_SEL_RGB); @@ -495,6 +489,9 @@ static const struct attribute_group lp5562_group = { /* Chip specific configurations */ static struct lp55xx_device_config lp5562_cfg = { .max_channel = LP5562_MAX_LEDS, + .reg_op_mode = { + .addr = LP5562_REG_OP_MODE, + }, .reset = { .addr = LP5562_REG_RESET, .val = LP5562_RESET, @@ -577,7 +574,7 @@ static void lp5562_remove(struct i2c_client *client) struct lp55xx_led *led = i2c_get_clientdata(client); struct lp55xx_chip *chip = led->chip; - lp5562_stop_engine(chip); + lp55xx_stop_all_engine(chip); lp55xx_unregister_sysfs(chip); lp55xx_deinit_device(chip); diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 8e7074f0fee0..7d8fe67a38c7 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,12 @@ #include "leds-lp55xx-common.h" +/* OP MODE require at least 153 us to clear regs */ +#define LP55XX_CMD_SLEEP 200 + +/* Program Commands */ +#define LP55xx_MODE_DISABLE_ALL_ENG 0x0 + /* External clock rate */ #define LP55XX_CLK_32K 32768 @@ -40,6 +47,34 @@ static struct lp55xx_led *mcled_cdev_to_led(struct led_classdev_mc *mc_cdev) return container_of(mc_cdev, struct lp55xx_led, mc_cdev); } +static void lp55xx_wait_opmode_done(struct lp55xx_chip *chip) +{ + struct lp55xx_device_config *cfg = chip->cfg; + int ret; + u8 val; + + /* + * Recent chip supports BUSY bit for engine. + * Check support by checking if val is not 0. + * For legacy device, sleep at least 153 us. + */ + if (cfg->engine_busy.val) + read_poll_timeout(lp55xx_read, ret, !(val & cfg->engine_busy.mask), + LP55XX_CMD_SLEEP, LP55XX_CMD_SLEEP * 10, false, + chip, cfg->engine_busy.addr, &val); + else + usleep_range(LP55XX_CMD_SLEEP, LP55XX_CMD_SLEEP * 2); +} + +void lp55xx_stop_all_engine(struct lp55xx_chip *chip) +{ + struct lp55xx_device_config *cfg = chip->cfg; + + lp55xx_write(chip, cfg->reg_op_mode.addr, LP55xx_MODE_DISABLE_ALL_ENG); + lp55xx_wait_opmode_done(chip); +} +EXPORT_SYMBOL_GPL(lp55xx_stop_all_engine); + static void lp55xx_reset_device(struct lp55xx_chip *chip) { struct lp55xx_device_config *cfg = chip->cfg; diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 2f38c5b33830..c7c8a77ddb1a 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -81,15 +81,22 @@ struct lp55xx_chip; /* * struct lp55xx_reg * @addr : Register address - * @val : Register value + * @val : Register value (can also used as mask or shift) */ struct lp55xx_reg { u8 addr; - u8 val; + union { + u8 val; + u8 mask; + u8 shift; + }; }; /* * struct lp55xx_device_config + * @reg_op_mode : Chip specific OP MODE reg addr + * @engine_busy : Chip specific engine busy + * (if not supported 153 us sleep) * @reset : Chip specific reset command * @enable : Chip specific enable command * @max_channel : Maximum number of channels @@ -102,6 +109,8 @@ struct lp55xx_reg { * @dev_attr_group : Device specific attributes */ struct lp55xx_device_config { + const struct lp55xx_reg reg_op_mode; /* addr, shift */ + const struct lp55xx_reg engine_busy; /* addr, mask */ const struct lp55xx_reg reset; const struct lp55xx_reg enable; const int max_channel; @@ -191,6 +200,9 @@ extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg, /* external clock detection */ extern bool lp55xx_is_extclk_used(struct lp55xx_chip *chip); +/* common chip functions */ +extern void lp55xx_stop_all_engine(struct lp55xx_chip *chip); + /* common device init/deinit functions */ extern int lp55xx_init_device(struct lp55xx_chip *chip); extern void lp55xx_deinit_device(struct lp55xx_chip *chip); diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c index ac50aa88939a..57e184dda490 100644 --- a/drivers/leds/leds-lp8501.c +++ b/drivers/leds/leds-lp8501.c @@ -58,6 +58,9 @@ #define LP8501_INT_CLK BIT(0) #define LP8501_DEFAULT_CFG (LP8501_PWM_PSAVE | LP8501_AUTO_INC | LP8501_PWR_SAVE) +#define LP8501_REG_STATUS 0x3A +#define LP8501_ENGINE_BUSY BIT(4) + #define LP8501_REG_RESET 0x3D #define LP8501_RESET 0xFF @@ -141,12 +144,6 @@ static void lp8501_load_engine(struct lp55xx_chip *chip) lp55xx_write(chip, LP8501_REG_PROG_PAGE_SEL, page_sel[idx]); } -static void lp8501_stop_engine(struct lp55xx_chip *chip) -{ - lp55xx_write(chip, LP8501_REG_OP_MODE, 0); - lp8501_wait_opmode_done(); -} - static void lp8501_turn_off_channels(struct lp55xx_chip *chip) { int i; @@ -163,7 +160,7 @@ static void lp8501_run_engine(struct lp55xx_chip *chip, bool start) /* stop engine */ if (!start) { - lp8501_stop_engine(chip); + lp55xx_stop_all_engine(chip); lp8501_turn_off_channels(chip); return; } @@ -285,6 +282,13 @@ static int lp8501_led_brightness(struct lp55xx_led *led) /* Chip specific configurations */ static struct lp55xx_device_config lp8501_cfg = { + .reg_op_mode = { + .addr = LP8501_REG_OP_MODE, + }, + .engine_busy = { + .addr = LP8501_REG_STATUS, + .maks = LP8501_ENGINE_BUSY, + }, .reset = { .addr = LP8501_REG_RESET, .val = LP8501_RESET, @@ -369,7 +373,7 @@ static void lp8501_remove(struct i2c_client *client) struct lp55xx_led *led = i2c_get_clientdata(client); struct lp55xx_chip *chip = led->chip; - lp8501_stop_engine(chip); + lp55xx_stop_all_engine(chip); lp55xx_unregister_sysfs(chip); lp55xx_deinit_device(chip); } From patchwork Sat Jun 15 23:11:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804584 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF1136FE07; Sat, 15 Jun 2024 23:12:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493178; cv=none; b=DdE4CI1qdVzRHq741TU3LJuU4pje2jRLrfxHVrUi8gdCGssormBXdnKq0AMggclDaNHpflfk8DUT0tCtTM0wbDBY4AXOGO+7OKETeVvwy9XDwniaO5CboBsBNTlmZ9FEAdvzOU536dEjaiAEd2nTBu+/CQyOezi58ruTLk8AD8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493178; c=relaxed/simple; bh=4iKREXqtG+bHi3JhzKVgQHf9qkMSJAXfYE9OEqhFzkQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qyYRrxv/mleqowORC/n6tIBJ1tF95CAW+2xn20441vvfJ4TzeFl3kx2PkReH4Z64u2fJNJAsPd9hRTiMx+EC/2R6D2vOpemc4C4mjONFaPa8VTQjJA4Z2j54SZE4wE9p1KniZFK7pZykKMf9J4Vhys1m3JVdBYlO6VBj4X4lSUQ= 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=IsfhcU08; arc=none smtp.client-ip=209.85.221.47 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="IsfhcU08" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-35f236a563cso2693871f8f.2; Sat, 15 Jun 2024 16:12:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493174; x=1719097974; 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=RA4Nk0ePc9s+tFGRFpwDtzewJ/kSziGoBVfzNx9x38o=; b=IsfhcU08uFyrlbt9NdZaL1rPJ5p8DJAAfFI5emj+rJoBG5/cI2FZRSCNVagj5SW6Cy vvbRHgFVvmrweeA9iVlUzaWgAeKpTU2AOlqRd74nl4EuVpSFEkWd2O8za2dxtpo9zzDx XT1YPvBlurO2Hjv7Wbl7U1GNs5ghoVxtegzA45/icB+U0th4SKTDt8VU+TpY1WPe29So gXE/DMMZLAXJczJpr7DwFExQID1SaDlKxNDdxeOF/wjdi0QZ/uw6fdiNi6ds1cMX31zG AmMTvvLxeL44GvKnZ1q71rfU3izPct3jC+O/htuDMs9wks1bvh1n71muyngVRMoNZIei c2ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493174; x=1719097974; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RA4Nk0ePc9s+tFGRFpwDtzewJ/kSziGoBVfzNx9x38o=; b=UHlJ+6BR2WmpzFZnBmKRVd69SIQ9ytOox+QoH7qjQMNwMiCobaPTT5/Nahr1PZZBRF F+aV7zzE8mJyUkRFY5CGoRfQ5wOHx+EtxptD+zW8VUje3ehMzbesF7XH85ccy/yzBPQW 0poyF2Io+Qw1Fdik4fOqN9/81+3Rire3OyTK7o+ObHcKhm9xCj33RxA8XnGbpTpXPA+O NCZKExJRBZyhr8/1qmcGO0dsC6DqT/4Y7hiWzcaBYtFMB7PP9BHJe6mzsHB039gxakVY pQC9eenu0zJ/rdYthQ10PjKVHOvYBRS6cHzcjdMir5cvE5sJrp13pkXzsAIbfvY9Njtf U5hA== X-Forwarded-Encrypted: i=1; AJvYcCX0RETlhSha+3nnok/xA0Z0AzS26BbhihT5eqprUzQd6bo6q3cSU/Cq+I3NMTFGy7BfAlW0SIRR54XPFTldMGovjvohA+EWyb5QDHBx5A3EWX6E6jand+SMvPQTiu4uarsEgFN7Fl2Wtsc7G2zkzcdzVZ9M5qoc9f9rqAU9QrChEWVHbds= X-Gm-Message-State: AOJu0YzEFENkZMQ9HfhbV5mD0HG437nTKjXhOVwz4/7R9tp83cg2A48u h61GUV9xn0dry5WGF88id8gg/nThNpiGdKDExnE/MDIxgHiErAtS X-Google-Smtp-Source: AGHT+IHNd91+H2Ebn/bBdrVIZeXAJM2vQ1A63Sur6LAO8fJ2YFBbJ+hE85P1jW7CSW1UPs9Oc59URg== X-Received: by 2002:a5d:51c8:0:b0:35f:a0c:7cf2 with SMTP id ffacd0b85a97d-3607a77fa42mr4250435f8f.51.1718493173826; Sat, 15 Jun 2024 16:12:53 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.12.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:12:53 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 04/20] leds: leds-lp55xx: generalize probe/remove functions Date: Sun, 16 Jun 2024 01:11:34 +0200 Message-ID: <20240615231152.28201-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that stop_all_engine is generalized, probe and remove function are the same across every lp55xx based LED driver and can be generalized. To permit to use a common probe, make use of the OF match_data and i2c driver_data value to store the device_config struct specific for the LED. Also drop the now unused exported symbol in lp55xx-common and make them static. Update any lp55xx based LED driver to use the new generic probe/remove. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 81 +------------------- drivers/leds/leds-lp5523.c | 85 ++------------------- drivers/leds/leds-lp5562.c | 80 +------------------ drivers/leds/leds-lp55xx-common.c | 123 +++++++++++++++++++++++------- drivers/leds/leds-lp55xx-common.h | 21 +---- drivers/leds/leds-lp8501.c | 81 +------------------- 6 files changed, 119 insertions(+), 352 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 15ef5ae58623..5015f385cc17 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -514,87 +514,14 @@ static struct lp55xx_device_config lp5521_cfg = { .dev_attr_group = &lp5521_group, }; -static int lp5521_probe(struct i2c_client *client) -{ - const struct i2c_device_id *id = i2c_client_get_device_id(client); - int ret; - struct lp55xx_chip *chip; - struct lp55xx_led *led; - struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev); - struct device_node *np = dev_of_node(&client->dev); - - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); - if (!chip) - return -ENOMEM; - - chip->cfg = &lp5521_cfg; - - if (!pdata) { - if (np) { - pdata = lp55xx_of_populate_pdata(&client->dev, np, - chip); - if (IS_ERR(pdata)) - return PTR_ERR(pdata); - } else { - dev_err(&client->dev, "no platform data\n"); - return -EINVAL; - } - } - - led = devm_kcalloc(&client->dev, - pdata->num_channels, sizeof(*led), GFP_KERNEL); - if (!led) - return -ENOMEM; - - chip->cl = client; - chip->pdata = pdata; - - mutex_init(&chip->lock); - - i2c_set_clientdata(client, led); - - ret = lp55xx_init_device(chip); - if (ret) - goto err_init; - - dev_info(&client->dev, "%s programmable led chip found\n", id->name); - - ret = lp55xx_register_leds(led, chip); - if (ret) - goto err_out; - - ret = lp55xx_register_sysfs(chip); - if (ret) { - dev_err(&client->dev, "registering sysfs failed\n"); - goto err_out; - } - - return 0; - -err_out: - lp55xx_deinit_device(chip); -err_init: - return ret; -} - -static void lp5521_remove(struct i2c_client *client) -{ - struct lp55xx_led *led = i2c_get_clientdata(client); - struct lp55xx_chip *chip = led->chip; - - lp55xx_stop_all_engine(chip); - lp55xx_unregister_sysfs(chip); - lp55xx_deinit_device(chip); -} - static const struct i2c_device_id lp5521_id[] = { - { "lp5521", 0 }, /* Three channel chip */ + { "lp5521", .driver_data = (kernel_ulong_t)&lp5521_cfg, }, /* Three channel chip */ { } }; MODULE_DEVICE_TABLE(i2c, lp5521_id); static const struct of_device_id of_lp5521_leds_match[] = { - { .compatible = "national,lp5521", }, + { .compatible = "national,lp5521", .data = &lp5521_cfg, }, {}, }; @@ -605,8 +532,8 @@ static struct i2c_driver lp5521_driver = { .name = "lp5521", .of_match_table = of_lp5521_leds_match, }, - .probe = lp5521_probe, - .remove = lp5521_remove, + .probe = lp55xx_probe, + .remove = lp55xx_remove, .id_table = lp5521_id, }; diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 79931555eddd..bd0209e2ee42 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -895,90 +895,17 @@ static struct lp55xx_device_config lp5523_cfg = { .dev_attr_group = &lp5523_group, }; -static int lp5523_probe(struct i2c_client *client) -{ - const struct i2c_device_id *id = i2c_client_get_device_id(client); - int ret; - struct lp55xx_chip *chip; - struct lp55xx_led *led; - struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev); - struct device_node *np = dev_of_node(&client->dev); - - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); - if (!chip) - return -ENOMEM; - - chip->cfg = &lp5523_cfg; - - if (!pdata) { - if (np) { - pdata = lp55xx_of_populate_pdata(&client->dev, np, - chip); - if (IS_ERR(pdata)) - return PTR_ERR(pdata); - } else { - dev_err(&client->dev, "no platform data\n"); - return -EINVAL; - } - } - - led = devm_kcalloc(&client->dev, - pdata->num_channels, sizeof(*led), GFP_KERNEL); - if (!led) - return -ENOMEM; - - chip->cl = client; - chip->pdata = pdata; - - mutex_init(&chip->lock); - - i2c_set_clientdata(client, led); - - ret = lp55xx_init_device(chip); - if (ret) - goto err_init; - - dev_info(&client->dev, "%s Programmable led chip found\n", id->name); - - ret = lp55xx_register_leds(led, chip); - if (ret) - goto err_out; - - ret = lp55xx_register_sysfs(chip); - if (ret) { - dev_err(&client->dev, "registering sysfs failed\n"); - goto err_out; - } - - return 0; - -err_out: - lp55xx_deinit_device(chip); -err_init: - return ret; -} - -static void lp5523_remove(struct i2c_client *client) -{ - struct lp55xx_led *led = i2c_get_clientdata(client); - struct lp55xx_chip *chip = led->chip; - - lp55xx_stop_all_engine(chip); - lp55xx_unregister_sysfs(chip); - lp55xx_deinit_device(chip); -} - static const struct i2c_device_id lp5523_id[] = { - { "lp5523", LP5523 }, - { "lp55231", LP55231 }, + { "lp5523", .driver_data = (kernel_ulong_t)&lp5523_cfg, }, + { "lp55231", .driver_data = (kernel_ulong_t)&lp5523_cfg, }, { } }; MODULE_DEVICE_TABLE(i2c, lp5523_id); static const struct of_device_id of_lp5523_leds_match[] = { - { .compatible = "national,lp5523", }, - { .compatible = "ti,lp55231", }, + { .compatible = "national,lp5523", .data = &lp5523_cfg, }, + { .compatible = "ti,lp55231", .data = &lp5523_cfg, }, {}, }; @@ -989,8 +916,8 @@ static struct i2c_driver lp5523_driver = { .name = "lp5523x", .of_match_table = of_lp5523_leds_match, }, - .probe = lp5523_probe, - .remove = lp5523_remove, + .probe = lp55xx_probe, + .remove = lp55xx_remove, .id_table = lp5523_id, }; diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index 28469bd2c75b..65a6a05c3848 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -508,86 +508,14 @@ static struct lp55xx_device_config lp5562_cfg = { .dev_attr_group = &lp5562_group, }; -static int lp5562_probe(struct i2c_client *client) -{ - int ret; - struct lp55xx_chip *chip; - struct lp55xx_led *led; - struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev); - struct device_node *np = dev_of_node(&client->dev); - - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); - if (!chip) - return -ENOMEM; - - chip->cfg = &lp5562_cfg; - - if (!pdata) { - if (np) { - pdata = lp55xx_of_populate_pdata(&client->dev, np, - chip); - if (IS_ERR(pdata)) - return PTR_ERR(pdata); - } else { - dev_err(&client->dev, "no platform data\n"); - return -EINVAL; - } - } - - - led = devm_kcalloc(&client->dev, - pdata->num_channels, sizeof(*led), GFP_KERNEL); - if (!led) - return -ENOMEM; - - chip->cl = client; - chip->pdata = pdata; - - mutex_init(&chip->lock); - - i2c_set_clientdata(client, led); - - ret = lp55xx_init_device(chip); - if (ret) - goto err_init; - - ret = lp55xx_register_leds(led, chip); - if (ret) - goto err_out; - - ret = lp55xx_register_sysfs(chip); - if (ret) { - dev_err(&client->dev, "registering sysfs failed\n"); - goto err_out; - } - - return 0; - -err_out: - lp55xx_deinit_device(chip); -err_init: - return ret; -} - -static void lp5562_remove(struct i2c_client *client) -{ - struct lp55xx_led *led = i2c_get_clientdata(client); - struct lp55xx_chip *chip = led->chip; - - lp55xx_stop_all_engine(chip); - - lp55xx_unregister_sysfs(chip); - lp55xx_deinit_device(chip); -} - static const struct i2c_device_id lp5562_id[] = { - { "lp5562", 0 }, + { "lp5562", .driver_data = (kernel_ulong_t)&lp5562_cfg, }, { } }; MODULE_DEVICE_TABLE(i2c, lp5562_id); static const struct of_device_id of_lp5562_leds_match[] = { - { .compatible = "ti,lp5562", }, + { .compatible = "ti,lp5562", .data = &lp5562_cfg, }, {}, }; @@ -598,8 +526,8 @@ static struct i2c_driver lp5562_driver = { .name = "lp5562", .of_match_table = of_lp5562_leds_match, }, - .probe = lp5562_probe, - .remove = lp5562_remove, + .probe = lp55xx_probe, + .remove = lp55xx_remove, .id_table = lp5562_id, }; diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 7d8fe67a38c7..a2ea449a1d5e 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -32,6 +32,8 @@ /* External clock rate */ #define LP55XX_CLK_32K 32768 +static void lp55xx_deinit_device(struct lp55xx_chip *chip); + static struct lp55xx_led *cdev_to_lp55xx_led(struct led_classdev *cdev) { return container_of(cdev, struct lp55xx_led, cdev); @@ -49,7 +51,7 @@ static struct lp55xx_led *mcled_cdev_to_led(struct led_classdev_mc *mc_cdev) static void lp55xx_wait_opmode_done(struct lp55xx_chip *chip) { - struct lp55xx_device_config *cfg = chip->cfg; + const struct lp55xx_device_config *cfg = chip->cfg; int ret; u8 val; @@ -68,7 +70,7 @@ static void lp55xx_wait_opmode_done(struct lp55xx_chip *chip) void lp55xx_stop_all_engine(struct lp55xx_chip *chip) { - struct lp55xx_device_config *cfg = chip->cfg; + const struct lp55xx_device_config *cfg = chip->cfg; lp55xx_write(chip, cfg->reg_op_mode.addr, LP55xx_MODE_DISABLE_ALL_ENG); lp55xx_wait_opmode_done(chip); @@ -77,7 +79,7 @@ EXPORT_SYMBOL_GPL(lp55xx_stop_all_engine); static void lp55xx_reset_device(struct lp55xx_chip *chip) { - struct lp55xx_device_config *cfg = chip->cfg; + const struct lp55xx_device_config *cfg = chip->cfg; u8 addr = cfg->reset.addr; u8 val = cfg->reset.val; @@ -87,7 +89,7 @@ static void lp55xx_reset_device(struct lp55xx_chip *chip) static int lp55xx_detect_device(struct lp55xx_chip *chip) { - struct lp55xx_device_config *cfg = chip->cfg; + const struct lp55xx_device_config *cfg = chip->cfg; u8 addr = cfg->enable.addr; u8 val = cfg->enable.val; int ret; @@ -110,7 +112,7 @@ static int lp55xx_detect_device(struct lp55xx_chip *chip) static int lp55xx_post_init_device(struct lp55xx_chip *chip) { - struct lp55xx_device_config *cfg = chip->cfg; + const struct lp55xx_device_config *cfg = chip->cfg; if (!cfg->post_init_device) return 0; @@ -175,7 +177,7 @@ static int lp55xx_set_mc_brightness(struct led_classdev *cdev, { struct led_classdev_mc *mc_dev = lcdev_to_mccdev(cdev); struct lp55xx_led *led = mcled_cdev_to_led(mc_dev); - struct lp55xx_device_config *cfg = led->chip->cfg; + const struct lp55xx_device_config *cfg = led->chip->cfg; led_mc_calc_color_components(&led->mc_cdev, brightness); return cfg->multicolor_brightness_fn(led); @@ -186,7 +188,7 @@ static int lp55xx_set_brightness(struct led_classdev *cdev, enum led_brightness brightness) { struct lp55xx_led *led = cdev_to_lp55xx_led(cdev); - struct lp55xx_device_config *cfg = led->chip->cfg; + const struct lp55xx_device_config *cfg = led->chip->cfg; led->brightness = (u8)brightness; return cfg->brightness_fn(led); @@ -196,7 +198,7 @@ static int lp55xx_init_led(struct lp55xx_led *led, struct lp55xx_chip *chip, int chan) { struct lp55xx_platform_data *pdata = chip->pdata; - struct lp55xx_device_config *cfg = chip->cfg; + const struct lp55xx_device_config *cfg = chip->cfg; struct device *dev = &chip->cl->dev; int max_channel = cfg->max_channel; struct mc_subled *mc_led_info; @@ -458,10 +460,10 @@ bool lp55xx_is_extclk_used(struct lp55xx_chip *chip) } EXPORT_SYMBOL_GPL(lp55xx_is_extclk_used); -int lp55xx_init_device(struct lp55xx_chip *chip) +static int lp55xx_init_device(struct lp55xx_chip *chip) { struct lp55xx_platform_data *pdata; - struct lp55xx_device_config *cfg; + const struct lp55xx_device_config *cfg; struct device *dev = &chip->cl->dev; int ret = 0; @@ -511,9 +513,8 @@ int lp55xx_init_device(struct lp55xx_chip *chip) err: return ret; } -EXPORT_SYMBOL_GPL(lp55xx_init_device); -void lp55xx_deinit_device(struct lp55xx_chip *chip) +static void lp55xx_deinit_device(struct lp55xx_chip *chip) { struct lp55xx_platform_data *pdata = chip->pdata; @@ -523,12 +524,11 @@ void lp55xx_deinit_device(struct lp55xx_chip *chip) if (pdata->enable_gpiod) gpiod_set_value(pdata->enable_gpiod, 0); } -EXPORT_SYMBOL_GPL(lp55xx_deinit_device); -int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip) +static int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip) { struct lp55xx_platform_data *pdata = chip->pdata; - struct lp55xx_device_config *cfg = chip->cfg; + const struct lp55xx_device_config *cfg = chip->cfg; int num_channels = pdata->num_channels; struct lp55xx_led *each; u8 led_current; @@ -565,12 +565,11 @@ int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip) err_init_led: return ret; } -EXPORT_SYMBOL_GPL(lp55xx_register_leds); -int lp55xx_register_sysfs(struct lp55xx_chip *chip) +static int lp55xx_register_sysfs(struct lp55xx_chip *chip) { struct device *dev = &chip->cl->dev; - struct lp55xx_device_config *cfg = chip->cfg; + const struct lp55xx_device_config *cfg = chip->cfg; int ret; if (!cfg->run_engine || !cfg->firmware_cb) @@ -584,19 +583,17 @@ int lp55xx_register_sysfs(struct lp55xx_chip *chip) return cfg->dev_attr_group ? sysfs_create_group(&dev->kobj, cfg->dev_attr_group) : 0; } -EXPORT_SYMBOL_GPL(lp55xx_register_sysfs); -void lp55xx_unregister_sysfs(struct lp55xx_chip *chip) +static void lp55xx_unregister_sysfs(struct lp55xx_chip *chip) { struct device *dev = &chip->cl->dev; - struct lp55xx_device_config *cfg = chip->cfg; + const struct lp55xx_device_config *cfg = chip->cfg; if (cfg->dev_attr_group) sysfs_remove_group(&dev->kobj, cfg->dev_attr_group); sysfs_remove_group(&dev->kobj, &lp55xx_engine_attr_group); } -EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs); static int lp55xx_parse_common_child(struct device_node *np, struct lp55xx_led_config *cfg, @@ -689,9 +686,9 @@ static int lp55xx_parse_logical_led(struct device_node *np, return ret; } -struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev, - struct device_node *np, - struct lp55xx_chip *chip) +static struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev, + struct device_node *np, + struct lp55xx_chip *chip) { struct device_node *child; struct lp55xx_platform_data *pdata; @@ -748,7 +745,81 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev, return pdata; } -EXPORT_SYMBOL_GPL(lp55xx_of_populate_pdata); + +int lp55xx_probe(struct i2c_client *client) +{ + const struct i2c_device_id *id = i2c_client_get_device_id(client); + int ret; + struct lp55xx_chip *chip; + struct lp55xx_led *led; + struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev); + struct device_node *np = dev_of_node(&client->dev); + + chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + chip->cfg = i2c_get_match_data(client); + + if (!pdata) { + if (np) { + pdata = lp55xx_of_populate_pdata(&client->dev, np, + chip); + if (IS_ERR(pdata)) + return PTR_ERR(pdata); + } else { + dev_err(&client->dev, "no platform data\n"); + return -EINVAL; + } + } + + led = devm_kcalloc(&client->dev, + pdata->num_channels, sizeof(*led), GFP_KERNEL); + if (!led) + return -ENOMEM; + + chip->cl = client; + chip->pdata = pdata; + + mutex_init(&chip->lock); + + i2c_set_clientdata(client, led); + + ret = lp55xx_init_device(chip); + if (ret) + goto err_init; + + dev_info(&client->dev, "%s Programmable led chip found\n", id->name); + + ret = lp55xx_register_leds(led, chip); + if (ret) + goto err_out; + + ret = lp55xx_register_sysfs(chip); + if (ret) { + dev_err(&client->dev, "registering sysfs failed\n"); + goto err_out; + } + + return 0; + +err_out: + lp55xx_deinit_device(chip); +err_init: + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_probe); + +void lp55xx_remove(struct i2c_client *client) +{ + struct lp55xx_led *led = i2c_get_clientdata(client); + struct lp55xx_chip *chip = led->chip; + + lp55xx_stop_all_engine(chip); + lp55xx_unregister_sysfs(chip); + lp55xx_deinit_device(chip); +} +EXPORT_SYMBOL_GPL(lp55xx_remove); MODULE_AUTHOR("Milo Kim "); MODULE_DESCRIPTION("LP55xx Common Driver"); diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index c7c8a77ddb1a..26a724acac16 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -164,7 +164,7 @@ struct lp55xx_chip { struct lp55xx_platform_data *pdata; struct mutex lock; /* lock for user-space interface */ int num_leds; - struct lp55xx_device_config *cfg; + const struct lp55xx_device_config *cfg; enum lp55xx_engine_index engine_idx; struct lp55xx_engine engines[LP55XX_ENGINE_MAX]; const struct firmware *fw; @@ -203,21 +203,8 @@ extern bool lp55xx_is_extclk_used(struct lp55xx_chip *chip); /* common chip functions */ extern void lp55xx_stop_all_engine(struct lp55xx_chip *chip); -/* common device init/deinit functions */ -extern int lp55xx_init_device(struct lp55xx_chip *chip); -extern void lp55xx_deinit_device(struct lp55xx_chip *chip); - -/* common LED class device functions */ -extern int lp55xx_register_leds(struct lp55xx_led *led, - struct lp55xx_chip *chip); - -/* common device attributes functions */ -extern int lp55xx_register_sysfs(struct lp55xx_chip *chip); -extern void lp55xx_unregister_sysfs(struct lp55xx_chip *chip); - -/* common device tree population function */ -extern struct lp55xx_platform_data -*lp55xx_of_populate_pdata(struct device *dev, struct device_node *np, - struct lp55xx_chip *chip); +/* common probe/remove function */ +extern int lp55xx_probe(struct i2c_client *client); +extern void lp55xx_remove(struct i2c_client *client); #endif /* _LEDS_LP55XX_COMMON_H */ diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c index 57e184dda490..d3c718bb8275 100644 --- a/drivers/leds/leds-lp8501.c +++ b/drivers/leds/leds-lp8501.c @@ -305,87 +305,14 @@ static struct lp55xx_device_config lp8501_cfg = { .run_engine = lp8501_run_engine, }; -static int lp8501_probe(struct i2c_client *client) -{ - const struct i2c_device_id *id = i2c_client_get_device_id(client); - int ret; - struct lp55xx_chip *chip; - struct lp55xx_led *led; - struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev); - struct device_node *np = dev_of_node(&client->dev); - - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); - if (!chip) - return -ENOMEM; - - chip->cfg = &lp8501_cfg; - - if (!pdata) { - if (np) { - pdata = lp55xx_of_populate_pdata(&client->dev, np, - chip); - if (IS_ERR(pdata)) - return PTR_ERR(pdata); - } else { - dev_err(&client->dev, "no platform data\n"); - return -EINVAL; - } - } - - led = devm_kcalloc(&client->dev, - pdata->num_channels, sizeof(*led), GFP_KERNEL); - if (!led) - return -ENOMEM; - - chip->cl = client; - chip->pdata = pdata; - - mutex_init(&chip->lock); - - i2c_set_clientdata(client, led); - - ret = lp55xx_init_device(chip); - if (ret) - goto err_init; - - dev_info(&client->dev, "%s Programmable led chip found\n", id->name); - - ret = lp55xx_register_leds(led, chip); - if (ret) - goto err_out; - - ret = lp55xx_register_sysfs(chip); - if (ret) { - dev_err(&client->dev, "registering sysfs failed\n"); - goto err_out; - } - - return 0; - -err_out: - lp55xx_deinit_device(chip); -err_init: - return ret; -} - -static void lp8501_remove(struct i2c_client *client) -{ - struct lp55xx_led *led = i2c_get_clientdata(client); - struct lp55xx_chip *chip = led->chip; - - lp55xx_stop_all_engine(chip); - lp55xx_unregister_sysfs(chip); - lp55xx_deinit_device(chip); -} - static const struct i2c_device_id lp8501_id[] = { - { "lp8501", 0 }, + { "lp8501", .driver_data = (kernel_ulong_t)&lp8501_cfg, }, { } }; MODULE_DEVICE_TABLE(i2c, lp8501_id); static const struct of_device_id of_lp8501_leds_match[] = { - { .compatible = "ti,lp8501", }, + { .compatible = "ti,lp8501", .data = &lp8501_cfg, }, {}, }; @@ -396,8 +323,8 @@ static struct i2c_driver lp8501_driver = { .name = "lp8501", .of_match_table = of_lp8501_leds_match, }, - .probe = lp8501_probe, - .remove = lp8501_remove, + .probe = lp55xx_probe, + .remove = lp55xx_remove, .id_table = lp8501_id, }; From patchwork Sat Jun 15 23:11:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805058 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.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 78F9273440; Sat, 15 Jun 2024 23:12:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493178; cv=none; b=DmvtdEMeqXVdZkeaMDVH94uJbSCckw6gNHH8jfbHyCBXExfcButYE73FS+nS4/95hoCQVK+pEZilwtwLY9nhUiGgFsKdrUjSDUg6n1SFgaAB432U5+0HYBrBJe0WMPrCq6LIkcPi7a4DSQbECd/blrs7j3ozx7T7u4ypqK9FSu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493178; c=relaxed/simple; bh=cvAiLUhTdfb5YLxDKNEaxqaIFMQeeKrIojLSJL4XvEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E389GM7oiU82XSlHbaf9nt/QpZW5c6dqF+X1fSrlVh9stuMexSFuwt9sb2+70iriu+4Pcsvio7MDtiXlJ3tjdEX/DrcC4sbbS5aNM8m6hSVal2+OGfsLdWq2QGSIQw0dw8wFP6FzUw30ZmVqVopnAz/J4dprEYrU18nXfxny9B0= 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=SMkZIIJT; arc=none smtp.client-ip=209.85.221.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="SMkZIIJT" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-35f1c490c13so3634923f8f.3; Sat, 15 Jun 2024 16:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493175; x=1719097975; 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=VEeaFUg3lKCARsm4zm9LOeHkJGdpWuIijdSVUZOssgc=; b=SMkZIIJT6/jhWoFNoCzM+b8KHmpMZwajuXjB8Zo1cf5hOA4G4eOsQxz6Fyjz5hEnvA vp2TDW3SKz/FiwC5e1UkPTUXlamvCzZwNdiakEOAR/teVtmVosXkyWtuPavUplfklD2z 5S1RvwQxWtFRrbN8IKw4YfyqPA8QAUm0qT/CCEZa2g/VDSaz0LP96kydp7YraLKDcz5k I6CpOwKNBHdt+brP+H+o21Y06hoCyzWUyH0Rc/Vv9pKs0ojRbd2q9Mq8GnRoZ1/sfCz3 CDVY6uS4eJMTMw1pM+bEj2q17lDX3yiXSeR4izZgj/XvQVIBR43RD7NVXmrB3UqfOUq9 EcUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493175; x=1719097975; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VEeaFUg3lKCARsm4zm9LOeHkJGdpWuIijdSVUZOssgc=; b=Ei7hEAy9q/HDIFunrHO1HzmjPEbJ+P97a3oWMOAWK/105+FuS2Mksovc9YtSsthUzi /vgf0m24tGMQOs/+XqjwfWh6pTb619GPXtO3KnXJm94pcQoIQ3xqJWIZP65yrsAtZ1R8 JkAyW2cpVeQwgDimFgXvnbQrOP9s0JRYG+cbNyGL8bQmfyrIyHjBefh+o9EMLOwKozlI iemN+2o4MpGiU2mYfnj8KR+x9rJDG2vA5pnj22UoCQ7ohN91wccbdm4j0oyPee5U5R3u UrGOiyARKbB1lLlVq2+P/+VTn+4WvbSbPUhw44R8VgGDNsvULD30WkCVPdLzU0KFfNxB LXtg== X-Forwarded-Encrypted: i=1; AJvYcCUJ6WWE3yMDApLNB1bkdAvN3U6DLxCui7m2peFmXVvQ6J0tK51QVxuxWTQXUcQulJ0fg/fCjPexv2a6u18YmCk244FfZur4BfFQxDoQkP9AbIIo8BxElciITjohl7xT33QuZMMZ2YAUrGrtsaGvbiqoV/COUtTwrJxGf5HjR8OG9l+OVdc= X-Gm-Message-State: AOJu0YyAlk9pndMf8AYhqqUbFFTAiuh0CYuIVUCwpuL+7FbrdOESzlzO NoXMrb7P08ssEAQbx1i656knwRhOCqZEs15181R4f3K/16wRmnZ8 X-Google-Smtp-Source: AGHT+IHW/3OugEVeEU+2effz9irHwRbIdkW4AQOZ9q8Kqg8k2OQ71taTtZpkFKXRzEoECzUR9a4HrQ== X-Received: by 2002:a5d:6a10:0:b0:35f:1f06:3d9d with SMTP id ffacd0b85a97d-3607a7888f4mr5168880f8f.70.1718493174813; Sat, 15 Jun 2024 16:12:54 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:12:54 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 05/20] leds: leds-lp55xx: generalize load_engine function Date: Sun, 16 Jun 2024 01:11:35 +0200 Message-ID: <20240615231152.28201-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 LED driver based on lp55xx have all a very similar implementation for load_engine function. Move the function to lp55xx-common and rework the define to be more dynamic instead of having to declare a temp array for them. Engine mask are the same for every LED based on lp55xx. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 26 +++---------------------- drivers/leds/leds-lp5523.c | 26 +++---------------------- drivers/leds/leds-lp5562.c | 24 ++--------------------- drivers/leds/leds-lp55xx-common.c | 32 ++++++++++++++++++++++++++++++- drivers/leds/leds-lp55xx-common.h | 1 + drivers/leds/leds-lp8501.c | 17 ++-------------- 6 files changed, 42 insertions(+), 84 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 5015f385cc17..08db470fff6c 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -115,26 +115,6 @@ static void lp5521_set_led_current(struct lp55xx_led *led, u8 led_current) led_current); } -static void lp5521_load_engine(struct lp55xx_chip *chip) -{ - enum lp55xx_engine_index idx = chip->engine_idx; - static const u8 mask[] = { - [LP55XX_ENGINE_1] = LP5521_MODE_R_M, - [LP55XX_ENGINE_2] = LP5521_MODE_G_M, - [LP55XX_ENGINE_3] = LP5521_MODE_B_M, - }; - - static const u8 val[] = { - [LP55XX_ENGINE_1] = LP5521_LOAD_R, - [LP55XX_ENGINE_2] = LP5521_LOAD_G, - [LP55XX_ENGINE_3] = LP5521_LOAD_B, - }; - - lp55xx_update_bits(chip, LP5521_REG_OP_MODE, mask[idx], val[idx]); - - lp5521_wait_opmode_done(); -} - static void lp5521_stop_engine(struct lp55xx_chip *chip) { enum lp55xx_engine_index idx = chip->engine_idx; @@ -264,7 +244,7 @@ static void lp5521_firmware_loaded(struct lp55xx_chip *chip) * 2) write firmware data into program memory */ - lp5521_load_engine(chip); + lp55xx_load_engine(chip); lp5521_update_program_memory(chip, fw->data, fw->size); } @@ -415,7 +395,7 @@ static ssize_t store_engine_mode(struct device *dev, engine->mode = LP55XX_ENGINE_RUN; } else if (!strncmp(buf, "load", 4)) { lp5521_stop_engine(chip); - lp5521_load_engine(chip); + lp55xx_load_engine(chip); engine->mode = LP55XX_ENGINE_LOAD; } else if (!strncmp(buf, "disabled", 8)) { lp5521_stop_engine(chip); @@ -441,7 +421,7 @@ static ssize_t store_engine_load(struct device *dev, mutex_lock(&chip->lock); chip->engine_idx = nr; - lp5521_load_engine(chip); + lp55xx_load_engine(chip); ret = lp5521_update_program_memory(chip, buf, len); mutex_unlock(&chip->lock); diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index bd0209e2ee42..086b4d8975a4 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -159,26 +159,6 @@ static int lp5523_post_init_device(struct lp55xx_chip *chip) return lp5523_init_program_engine(chip); } -static void lp5523_load_engine(struct lp55xx_chip *chip) -{ - enum lp55xx_engine_index idx = chip->engine_idx; - static const u8 mask[] = { - [LP55XX_ENGINE_1] = LP5523_MODE_ENG1_M, - [LP55XX_ENGINE_2] = LP5523_MODE_ENG2_M, - [LP55XX_ENGINE_3] = LP5523_MODE_ENG3_M, - }; - - static const u8 val[] = { - [LP55XX_ENGINE_1] = LP5523_LOAD_ENG1, - [LP55XX_ENGINE_2] = LP5523_LOAD_ENG2, - [LP55XX_ENGINE_3] = LP5523_LOAD_ENG3, - }; - - lp55xx_update_bits(chip, LP5523_REG_OP_MODE, mask[idx], val[idx]); - - lp5523_wait_opmode_done(); -} - static void lp5523_load_engine_and_select_page(struct lp55xx_chip *chip) { enum lp55xx_engine_index idx = chip->engine_idx; @@ -188,7 +168,7 @@ static void lp5523_load_engine_and_select_page(struct lp55xx_chip *chip) [LP55XX_ENGINE_3] = LP5523_PAGE_ENG3, }; - lp5523_load_engine(chip); + lp55xx_load_engine(chip); lp55xx_write(chip, LP5523_REG_PROG_PAGE_SEL, page_sel[idx]); } @@ -425,7 +405,7 @@ static ssize_t store_engine_mode(struct device *dev, engine->mode = LP55XX_ENGINE_RUN; } else if (!strncmp(buf, "load", 4)) { lp5523_stop_engine(chip); - lp5523_load_engine(chip); + lp55xx_load_engine(chip); engine->mode = LP55XX_ENGINE_LOAD; } else if (!strncmp(buf, "disabled", 8)) { lp5523_stop_engine(chip); @@ -502,7 +482,7 @@ static int lp5523_load_mux(struct lp55xx_chip *chip, u16 mux, int nr) [LP55XX_ENGINE_3] = LP5523_PAGE_MUX3, }; - lp5523_load_engine(chip); + lp55xx_load_engine(chip); ret = lp55xx_write(chip, LP5523_REG_PROG_PAGE_SEL, mux_page[nr]); if (ret) diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index 65a6a05c3848..5e26a52f534f 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -124,26 +124,6 @@ static void lp5562_set_led_current(struct lp55xx_led *led, u8 led_current) lp55xx_write(led->chip, addr[led->chan_nr], led_current); } -static void lp5562_load_engine(struct lp55xx_chip *chip) -{ - enum lp55xx_engine_index idx = chip->engine_idx; - static const u8 mask[] = { - [LP55XX_ENGINE_1] = LP5562_MODE_ENG1_M, - [LP55XX_ENGINE_2] = LP5562_MODE_ENG2_M, - [LP55XX_ENGINE_3] = LP5562_MODE_ENG3_M, - }; - - static const u8 val[] = { - [LP55XX_ENGINE_1] = LP5562_LOAD_ENG1, - [LP55XX_ENGINE_2] = LP5562_LOAD_ENG2, - [LP55XX_ENGINE_3] = LP5562_LOAD_ENG3, - }; - - lp55xx_update_bits(chip, LP5562_REG_OP_MODE, mask[idx], val[idx]); - - lp5562_wait_opmode_done(); -} - static void lp5562_run_engine(struct lp55xx_chip *chip, bool start) { int ret; @@ -270,7 +250,7 @@ static void lp5562_firmware_loaded(struct lp55xx_chip *chip) * 2) write firmware data into program memory */ - lp5562_load_engine(chip); + lp55xx_load_engine(chip); lp5562_update_firmware(chip, fw->data, fw->size); } @@ -371,7 +351,7 @@ static int lp5562_run_predef_led_pattern(struct lp55xx_chip *chip, int mode) /* Load engines */ for (i = LP55XX_ENGINE_1; i <= LP55XX_ENGINE_3; i++) { chip->engine_idx = i; - lp5562_load_engine(chip); + lp55xx_load_engine(chip); } /* Clear program registers */ diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index a2ea449a1d5e..06cbdef70f9a 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -26,8 +26,24 @@ /* OP MODE require at least 153 us to clear regs */ #define LP55XX_CMD_SLEEP 200 -/* Program Commands */ +/* + * Program Memory Operations + * Same Mask for each engine for both mode and exec + * ENG1 GENMASK(3, 2) + * ENG2 GENMASK(5, 4) + * ENG3 GENMASK(7, 6) + */ #define LP55xx_MODE_DISABLE_ALL_ENG 0x0 +#define LP55xx_MODE_ENG_MASK GENMASK(1, 0) +#define LP55xx_MODE_DISABLE_ENG FIELD_PREP_CONST(LP55xx_MODE_ENG_MASK, 0x0) +#define LP55xx_MODE_LOAD_ENG FIELD_PREP_CONST(LP55xx_MODE_ENG_MASK, 0x1) +#define LP55xx_MODE_RUN_ENG FIELD_PREP_CONST(LP55xx_MODE_ENG_MASK, 0x2) +#define LP55xx_MODE_HALT_ENG FIELD_PREP_CONST(LP55xx_MODE_ENG_MASK, 0x3) + +#define LP55xx_MODE_ENGn_SHIFT(n, shift) ((shift) + (2 * (3 - (n)))) +#define LP55xx_MODE_ENGn_MASK(n, shift) (LP55xx_MODE_ENG_MASK << LP55xx_MODE_ENGn_SHIFT(n, shift)) +#define LP55xx_MODE_ENGn_GET(n, mode, shift) \ + (((mode) >> LP55xx_MODE_ENGn_SHIFT(n, shift)) & LP55xx_MODE_ENG_MASK) /* External clock rate */ #define LP55XX_CLK_32K 32768 @@ -77,6 +93,20 @@ void lp55xx_stop_all_engine(struct lp55xx_chip *chip) } EXPORT_SYMBOL_GPL(lp55xx_stop_all_engine); +void lp55xx_load_engine(struct lp55xx_chip *chip) +{ + enum lp55xx_engine_index idx = chip->engine_idx; + const struct lp55xx_device_config *cfg = chip->cfg; + u8 mask, val; + + mask = LP55xx_MODE_ENGn_MASK(idx, cfg->reg_op_mode.shift); + val = LP55xx_MODE_LOAD_ENG << LP55xx_MODE_ENGn_SHIFT(idx, cfg->reg_op_mode.shift); + + lp55xx_update_bits(chip, cfg->reg_op_mode.addr, mask, val); + lp55xx_wait_opmode_done(chip); +} +EXPORT_SYMBOL_GPL(lp55xx_load_engine); + static void lp55xx_reset_device(struct lp55xx_chip *chip) { const struct lp55xx_device_config *cfg = chip->cfg; diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 26a724acac16..bb146bcecdcf 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -202,6 +202,7 @@ extern bool lp55xx_is_extclk_used(struct lp55xx_chip *chip); /* common chip functions */ extern void lp55xx_stop_all_engine(struct lp55xx_chip *chip); +extern void lp55xx_load_engine(struct lp55xx_chip *chip); /* common probe/remove function */ extern int lp55xx_probe(struct i2c_client *client); diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c index d3c718bb8275..04173d6875af 100644 --- a/drivers/leds/leds-lp8501.c +++ b/drivers/leds/leds-lp8501.c @@ -119,17 +119,6 @@ static int lp8501_post_init_device(struct lp55xx_chip *chip) static void lp8501_load_engine(struct lp55xx_chip *chip) { enum lp55xx_engine_index idx = chip->engine_idx; - static const u8 mask[] = { - [LP55XX_ENGINE_1] = LP8501_MODE_ENG1_M, - [LP55XX_ENGINE_2] = LP8501_MODE_ENG2_M, - [LP55XX_ENGINE_3] = LP8501_MODE_ENG3_M, - }; - - static const u8 val[] = { - [LP55XX_ENGINE_1] = LP8501_LOAD_ENG1, - [LP55XX_ENGINE_2] = LP8501_LOAD_ENG2, - [LP55XX_ENGINE_3] = LP8501_LOAD_ENG3, - }; static const u8 page_sel[] = { [LP55XX_ENGINE_1] = LP8501_PAGE_ENG1, @@ -137,9 +126,7 @@ static void lp8501_load_engine(struct lp55xx_chip *chip) [LP55XX_ENGINE_3] = LP8501_PAGE_ENG3, }; - lp55xx_update_bits(chip, LP8501_REG_OP_MODE, mask[idx], val[idx]); - - lp8501_wait_opmode_done(); + lp55xx_load_engine(chip); lp55xx_write(chip, LP8501_REG_PROG_PAGE_SEL, page_sel[idx]); } @@ -287,7 +274,7 @@ static struct lp55xx_device_config lp8501_cfg = { }, .engine_busy = { .addr = LP8501_REG_STATUS, - .maks = LP8501_ENGINE_BUSY, + .mask = LP8501_ENGINE_BUSY, }, .reset = { .addr = LP8501_REG_RESET, From patchwork Sat Jun 15 23:11:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804583 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 752227345F; Sat, 15 Jun 2024 23:12:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493179; cv=none; b=O9LBujSFfoNfnJIuUfmPq+PjqQPjQkfbCYnVma+eRyySD6SVra7v9UR9ZYsfmUQey2sriXh3+UW2yUTA96QZ/hFMFhxQqxvbD8AJLAV1jm2OHH5bLbb8eeIGYPkxrxTHyW6TKnsx5WQarvDtwiDw+g5WXhzXIzvo4p9eTbeJN94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493179; c=relaxed/simple; bh=Ub55otHmmC1QQ5xAyYlayyWLB0FlRN7yWkd2deY5BeQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GhDQXf7/FC7DZfVzwDqhfRASUwqWATn1S0Ki34qItruUAg57HKAOh/82bp/mEwvIuoHG3kpn9RxQ2dGb0ZpoMZIr60lAvN0KLanY+CJxMtInd5tHRTaZS7rSiEG5L34gm+ZsHqXnvCkXMqgyltxdnrVwqZJ7psXTv6t415Gc8Cg= 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=MaW+B6Nb; arc=none smtp.client-ip=209.85.221.42 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="MaW+B6Nb" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-35e1fcd0c0fso2558353f8f.0; Sat, 15 Jun 2024 16:12:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493176; x=1719097976; 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=T4qut46IlBJ6FtNVM5MuTrqvuDmUzrni7QhOXs9dZ4Q=; b=MaW+B6Nb68/oLWrZNU46jj/wATEEcZsySE1al+5cGkLwsiEUutd3Z01wZTkcOF8axb tlvuCAeD1UHCpTiUHbl/Wpq1TWVLiniBmHU+IPJFaYK+HmetZc1npWCnSmI8Z8XmOrtD 007akX1EDeKCYj0bWqA6OL6AIRPvyGqPgfHHxIJaHTR3N78LCXyDMOw74Epq2piIy+Lq 0j4FUF5Nqe79BbPET9lKZ6S0Nl6jxlun2ZbcceuHmbiX/8l2OAfrZ7EMHKYKW50m5dLk cAUBjyO6QUwM3avWON4tfjICnhOOgNcAZ3bixYgC3YFV5mYFmXFp83bgcCkfkHNQyWmS 5rOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493176; x=1719097976; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T4qut46IlBJ6FtNVM5MuTrqvuDmUzrni7QhOXs9dZ4Q=; b=pDxqOkLCFIQXIt4E1sUAsQ/arlJIs04WDxKafuzHh9VaNgY++x9BtOZjVbAemcTlKQ nz3iPH4Lv/wRO06Ue4Fg6mkl2w9OyUzn7VK8vyjKSdhBIHOQTlFFS2/tPnp7Cd+HRH8F 3qxdHochYrdG4HxQOOpkRdExsRnYCr8gf39OqfkMk9cZbas/rZrQdep3IEi70s6jmHV0 JGF9V5RZgceKMoOp5bnaaIZ97gjxu9z33tIhh8XduXoso8uf5apj7Na2+n5VzoQ6UTiG CVDITUifwUWooFCX3hceD0OjCUyILBhxOowetwtO5KxfubcsSZsjdpXdxCiRQ1zP6khS TYrg== X-Forwarded-Encrypted: i=1; AJvYcCX40cs+9vAWGKlL1bC5VIJq0pk4+t+Y1bnBdYZODJ5F6anVj/O2I/IZUNoI7+VuwWLFldBtxhMQycVrjwPvTagidPbQwqQXBfeFOZ6FeezCRXRk2IdWfbu7y8lkByjqCVGpN/5IBAqhRmnMQF6aoZO+sxQyx6/xxBW9N5wo0JSIZXlep50= X-Gm-Message-State: AOJu0Ywvu5pLGN0usR0nl2dgIrbmJQVKpXT1WmCKhPg+gzIMPufzncxi MRzsYb8bd28LuWt4HhIGAnRvSFiauinR+JFZZwRuoW6pWuBaCtV1 X-Google-Smtp-Source: AGHT+IETCd31gyHMtr+vUX5/5+3MJB86kMdjW/xPPt5/fu7Fy3MUlfy0e7GmWRAkiFDisDoC++7ePA== X-Received: by 2002:a5d:4b8d:0:b0:35e:8364:f4d4 with SMTP id ffacd0b85a97d-3607a788853mr3876514f8f.58.1718493175788; Sat, 15 Jun 2024 16:12:55 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:12:55 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 06/20] leds: leds-lp55xx: generalize load_engine_and_select_page function Date: Sun, 16 Jun 2024 01:11:36 +0200 Message-ID: <20240615231152.28201-7-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize load_engine_and_select_page by reworking the implementation and making it part of the generic load_engine function. Add a new option in device_config, pages_per_engine used to define pages assigned to each engine. With this option set, it's assumed LED chip supports pages and load_engine will correctly setup the write page. An equal amount of pages is assigned to each engine and they are assigned from page 0. Update any lp55xx based LED driver to define the option and use the new function. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5523.c | 22 +++++----------------- drivers/leds/leds-lp55xx-common.c | 10 ++++++++++ drivers/leds/leds-lp55xx-common.h | 3 +++ drivers/leds/leds-lp8501.c | 19 +++---------------- 4 files changed, 21 insertions(+), 33 deletions(-) diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 086b4d8975a4..8dabd5814110 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -30,6 +30,7 @@ * 0x40 engine 2 muxing info * 0x50 engine 3 muxing info */ +#define LP5523_PAGES_PER_ENGINE 1 #define LP5523_MAX_LEDS 9 /* Registers */ @@ -159,20 +160,6 @@ static int lp5523_post_init_device(struct lp55xx_chip *chip) return lp5523_init_program_engine(chip); } -static void lp5523_load_engine_and_select_page(struct lp55xx_chip *chip) -{ - enum lp55xx_engine_index idx = chip->engine_idx; - static const u8 page_sel[] = { - [LP55XX_ENGINE_1] = LP5523_PAGE_ENG1, - [LP55XX_ENGINE_2] = LP5523_PAGE_ENG2, - [LP55XX_ENGINE_3] = LP5523_PAGE_ENG3, - }; - - lp55xx_load_engine(chip); - - lp55xx_write(chip, LP5523_REG_PROG_PAGE_SEL, page_sel[idx]); -} - static void lp5523_stop_engine(struct lp55xx_chip *chip) { enum lp55xx_engine_index idx = chip->engine_idx; @@ -272,7 +259,7 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) /* write LED MUX address space for each engine */ for (i = LP55XX_ENGINE_1; i <= LP55XX_ENGINE_3; i++) { chip->engine_idx = i; - lp5523_load_engine_and_select_page(chip); + lp55xx_load_engine(chip); for (j = 0; j < LP5523_PROGRAM_LENGTH; j++) { ret = lp55xx_write(chip, LP5523_REG_PROG_MEM + j, @@ -362,7 +349,7 @@ static void lp5523_firmware_loaded(struct lp55xx_chip *chip) * 2) write firmware data into program memory */ - lp5523_load_engine_and_select_page(chip); + lp55xx_load_engine(chip); lp5523_update_program_memory(chip, fw->data, fw->size); } @@ -544,7 +531,7 @@ static ssize_t store_engine_load(struct device *dev, mutex_lock(&chip->lock); chip->engine_idx = nr; - lp5523_load_engine_and_select_page(chip); + lp55xx_load_engine(chip); ret = lp5523_update_program_memory(chip, buf, len); mutex_unlock(&chip->lock); @@ -865,6 +852,7 @@ static struct lp55xx_device_config lp5523_cfg = { .addr = LP5523_REG_ENABLE, .val = LP5523_ENABLE, }, + .pages_per_engine = LP5523_PAGES_PER_ENGINE, .max_channel = LP5523_MAX_LEDS, .post_init_device = lp5523_post_init_device, .brightness_fn = lp5523_led_brightness, diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 06cbdef70f9a..636e3ca0bb87 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -45,6 +45,11 @@ #define LP55xx_MODE_ENGn_GET(n, mode, shift) \ (((mode) >> LP55xx_MODE_ENGn_SHIFT(n, shift)) & LP55xx_MODE_ENG_MASK) +/* Memory Page Selection */ +#define LP55xx_REG_PROG_PAGE_SEL 0x4f +/* If supported, each ENGINE have an equal amount of pages offset from page 0 */ +#define LP55xx_PAGE_OFFSET(n, pages) (((n) - 1) * (pages)) + /* External clock rate */ #define LP55XX_CLK_32K 32768 @@ -104,6 +109,11 @@ void lp55xx_load_engine(struct lp55xx_chip *chip) lp55xx_update_bits(chip, cfg->reg_op_mode.addr, mask, val); lp55xx_wait_opmode_done(chip); + + /* Setup PAGE if supported (pages_per_engine not 0)*/ + if (cfg->pages_per_engine) + lp55xx_write(chip, LP55xx_REG_PROG_PAGE_SEL, + LP55xx_PAGE_OFFSET(idx, cfg->pages_per_engine)); } EXPORT_SYMBOL_GPL(lp55xx_load_engine); diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index bb146bcecdcf..015ac2ef4e4d 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -99,6 +99,8 @@ struct lp55xx_reg { * (if not supported 153 us sleep) * @reset : Chip specific reset command * @enable : Chip specific enable command + * @pages_per_engine : Assigned pages for each engine + * (if not set chip doesn't support pages) * @max_channel : Maximum number of channels * @post_init_device : Chip specific initialization code * @brightness_fn : Brightness function @@ -113,6 +115,7 @@ struct lp55xx_device_config { const struct lp55xx_reg engine_busy; /* addr, mask */ const struct lp55xx_reg reset; const struct lp55xx_reg enable; + const int pages_per_engine; const int max_channel; /* define if the device has specific initialization process */ diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c index 04173d6875af..abe2c4b213d7 100644 --- a/drivers/leds/leds-lp8501.c +++ b/drivers/leds/leds-lp8501.c @@ -21,6 +21,7 @@ #include "leds-lp55xx-common.h" #define LP8501_PROGRAM_LENGTH 32 +#define LP8501_PAGES_PER_ENGINE 1 #define LP8501_MAX_LEDS 9 /* Registers */ @@ -116,21 +117,6 @@ static int lp8501_post_init_device(struct lp55xx_chip *chip) LP8501_PWR_CONFIG_M, chip->pdata->pwr_sel); } -static void lp8501_load_engine(struct lp55xx_chip *chip) -{ - enum lp55xx_engine_index idx = chip->engine_idx; - - static const u8 page_sel[] = { - [LP55XX_ENGINE_1] = LP8501_PAGE_ENG1, - [LP55XX_ENGINE_2] = LP8501_PAGE_ENG2, - [LP55XX_ENGINE_3] = LP8501_PAGE_ENG3, - }; - - lp55xx_load_engine(chip); - - lp55xx_write(chip, LP8501_REG_PROG_PAGE_SEL, page_sel[idx]); -} - static void lp8501_turn_off_channels(struct lp55xx_chip *chip) { int i; @@ -250,7 +236,7 @@ static void lp8501_firmware_loaded(struct lp55xx_chip *chip) * 2) write firmware data into program memory */ - lp8501_load_engine(chip); + lp55xx_load_engine(chip); lp8501_update_program_memory(chip, fw->data, fw->size); } @@ -284,6 +270,7 @@ static struct lp55xx_device_config lp8501_cfg = { .addr = LP8501_REG_ENABLE, .val = LP8501_ENABLE, }, + .pages_per_engine = LP8501_PAGES_PER_ENGINE, .max_channel = LP8501_MAX_LEDS, .post_init_device = lp8501_post_init_device, .brightness_fn = lp8501_led_brightness, From patchwork Sat Jun 15 23:11:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805057 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 5616649651; Sat, 15 Jun 2024 23:12:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493180; cv=none; b=CYQLgxh84Pa+YXf+VRvUN0mrBkeFO8hbQ2ZyLUf8Y8+RNfIxkBXnaPzWiVay7qvrfmLTDIil+lNJPAx6+JOeSqHKDQ530dWCJyT/xJnoETkKDFwbZKdE+4HGKeG+FGjdq8/IZLx0ItN/7dXwVOCqCQo/m81bTUIFHRch8vhjZ9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493180; c=relaxed/simple; bh=wBbxrLnkfNyobL87UuOQj2jlt6y5twjfk2owp+xVlEg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LOOlN4irmmuoK7es/0BHJ4Cm7i6qk7Bgyhmb+gmi3AS+JoNOPXMJTblPQh10HjexQkGx6DFx/Nrd0NmUTQ4q615HWgdowOy3J5G57c3zUb/VKUYBQrJcQB4cSgORNknpoitSRIeE7T4GHYlLGc0UIaMMk6I8xQUng3OC5zJbTBM= 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=duLbg0Hb; arc=none smtp.client-ip=209.85.221.50 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="duLbg0Hb" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-35dc1d8867eso2683062f8f.0; Sat, 15 Jun 2024 16:12:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493177; x=1719097977; 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=01Yp5Oo+fAXFWYQsh1sHng/98wv/JHqgWnDMLUMpVTA=; b=duLbg0HbN1f7zM02xKQJsVyYSlU/B2EXc5IoC2eVnwHaNVEWFohE4on+CHRJV6/5EQ OigG2OlgATg4Bneqfe1k/jo4MgLPL+PjnVqbfflhFrx8RZ55KlOx6SJ52oSVPypqeYl6 7P4E8TngDqL/6tjH+UvH+W7fR/OO62PJLI2vS7/un8LL2bMe7xxPkxLQwgvwCnOqxvmQ x1FTWB74FhMU9GnwpDyS99lajzPfCZy/oBwpxljc/+3/Qlk3Gr4ppYXRaTGTURGUkxUy ISjNs3pGIb3v7HuLOSE7NEknbn845rm2Lo8h/q/+OvalFN6fNNuGxjqxP7aXtjkQcdDE u2NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493177; x=1719097977; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=01Yp5Oo+fAXFWYQsh1sHng/98wv/JHqgWnDMLUMpVTA=; b=t+4GWryXMOPOnfQ+PVn05OCIIPBPmuXlpaFeMWT8IM5odn0kM5me/EkjxCCiurFH+x KZ4ywLf1y/k8cTnBDHv7WfcY/eiA0BU37rltrFCK7TJEkM+f7CXC8f2MylGXjg1HJNmd AkdhlMPMADBJBgRRdn1kTBuxZKYy31lUslhKsjlJUXgQKoqx49qfLKkiFagjz0Rq6dMt fmpPwkKXC0+z3Uber5uZx4iUPaCDTyNCD71iJiG9vyVUCgzx05jdUMLEnVMqTtUt1IZU qhLP67u/7Q4xTvwSjECRv1LIAJH2IlmyrK0e9GlzUQGW6TtXLfIPUyXxG/n62UjmvYm3 Qmig== X-Forwarded-Encrypted: i=1; AJvYcCWDyy9O4sdLlyD3UzDntehhxSsqZIj9oMMqDpCLD0Zxq2KGMG/gzlcZ9ckey7PiYlbINLM2dNWO4UYYhtUKJEkwf4ESXTFfvSjnBkHZjbLZfMtrOP+j3HpJD9hRXJSX2QLP1ojFH0+Yi2yd/PKaiptTwkRUVNfJP+0k4/Mp15dVlb/G/bc= X-Gm-Message-State: AOJu0YwO0vQ/HKuLvilZ5/5fpRN8MNM5MCjVCFo9GoNgBKk5W1ESbAYn odNde2T+O6Q1+CLuNyLDQKGoiiOG5FTMKWBWT9Oo+sVx4qGB5X5V X-Google-Smtp-Source: AGHT+IHGOXmwdXsv0JmO350tR/IRub9s6kG5HfX4x8NT92ixLql//Ji4UrU4XfGFtDIKhwoaNftmbA== X-Received: by 2002:a5d:4e42:0:b0:35f:1c34:adfc with SMTP id ffacd0b85a97d-3607a78db97mr4320898f8f.67.1718493176722; Sat, 15 Jun 2024 16:12:56 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:12:56 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 07/20] leds: leds-lp55xx: generalize run_engine function Date: Sun, 16 Jun 2024 01:11:37 +0200 Message-ID: <20240615231152.28201-8-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize run_engine function for lp55xx based LED driver. The logic is similar to every LED driver, rework it with more macro magic and account for LED model that might have OP MODE and EXEC at base offset in the reg. Update any lp55xx based LED driver to use this generalized function and declare required bits. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 42 +++++------------------------- drivers/leds/leds-lp5523.c | 41 +++-------------------------- drivers/leds/leds-lp5562.c | 42 +++++------------------------- drivers/leds/leds-lp55xx-common.c | 43 +++++++++++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 2 ++ drivers/leds/leds-lp8501.c | 41 +++-------------------------- 6 files changed, 65 insertions(+), 146 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 08db470fff6c..0b9f99f4fff2 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -132,8 +132,6 @@ static void lp5521_stop_engine(struct lp55xx_chip *chip) static void lp5521_run_engine(struct lp55xx_chip *chip, bool start) { int ret; - u8 mode; - u8 exec; /* stop engine */ if (!start) { @@ -143,40 +141,9 @@ static void lp5521_run_engine(struct lp55xx_chip *chip, bool start) return; } - /* - * To run the engine, - * operation mode and enable register should updated at the same time - */ - - ret = lp55xx_read(chip, LP5521_REG_OP_MODE, &mode); - if (ret) - return; - - ret = lp55xx_read(chip, LP5521_REG_ENABLE, &exec); - if (ret) - return; - - /* change operation mode to RUN only when each engine is loading */ - if (LP5521_R_IS_LOADING(mode)) { - mode = (mode & ~LP5521_MODE_R_M) | LP5521_RUN_R; - exec = (exec & ~LP5521_EXEC_R_M) | LP5521_RUN_R; - } - - if (LP5521_G_IS_LOADING(mode)) { - mode = (mode & ~LP5521_MODE_G_M) | LP5521_RUN_G; - exec = (exec & ~LP5521_EXEC_G_M) | LP5521_RUN_G; - } - - if (LP5521_B_IS_LOADING(mode)) { - mode = (mode & ~LP5521_MODE_B_M) | LP5521_RUN_B; - exec = (exec & ~LP5521_EXEC_B_M) | LP5521_RUN_B; - } - - lp55xx_write(chip, LP5521_REG_OP_MODE, mode); - lp5521_wait_opmode_done(); - - lp55xx_update_bits(chip, LP5521_REG_ENABLE, LP5521_EXEC_M, exec); - lp5521_wait_enable_done(); + ret = lp55xx_run_engine_common(chip); + if (!ret) + lp5521_wait_enable_done(); } static int lp5521_update_program_memory(struct lp55xx_chip *chip, @@ -476,6 +443,9 @@ static struct lp55xx_device_config lp5521_cfg = { .reg_op_mode = { .addr = LP5521_REG_OP_MODE, }, + .reg_exec = { + .addr = LP5521_REG_ENABLE, + }, .reset = { .addr = LP5521_REG_RESET, .val = LP5521_RESET, diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 8dabd5814110..b28955b72189 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -184,10 +184,6 @@ static void lp5523_turn_off_channels(struct lp55xx_chip *chip) static void lp5523_run_engine(struct lp55xx_chip *chip, bool start) { - int ret; - u8 mode; - u8 exec; - /* stop engine */ if (!start) { lp5523_stop_engine(chip); @@ -195,39 +191,7 @@ static void lp5523_run_engine(struct lp55xx_chip *chip, bool start) return; } - /* - * To run the engine, - * operation mode and enable register should updated at the same time - */ - - ret = lp55xx_read(chip, LP5523_REG_OP_MODE, &mode); - if (ret) - return; - - ret = lp55xx_read(chip, LP5523_REG_ENABLE, &exec); - if (ret) - return; - - /* change operation mode to RUN only when each engine is loading */ - if (LP5523_ENG1_IS_LOADING(mode)) { - mode = (mode & ~LP5523_MODE_ENG1_M) | LP5523_RUN_ENG1; - exec = (exec & ~LP5523_EXEC_ENG1_M) | LP5523_RUN_ENG1; - } - - if (LP5523_ENG2_IS_LOADING(mode)) { - mode = (mode & ~LP5523_MODE_ENG2_M) | LP5523_RUN_ENG2; - exec = (exec & ~LP5523_EXEC_ENG2_M) | LP5523_RUN_ENG2; - } - - if (LP5523_ENG3_IS_LOADING(mode)) { - mode = (mode & ~LP5523_MODE_ENG3_M) | LP5523_RUN_ENG3; - exec = (exec & ~LP5523_EXEC_ENG3_M) | LP5523_RUN_ENG3; - } - - lp55xx_write(chip, LP5523_REG_OP_MODE, mode); - lp5523_wait_opmode_done(); - - lp55xx_update_bits(chip, LP5523_REG_ENABLE, LP5523_EXEC_M, exec); + lp55xx_run_engine_common(chip); } static int lp5523_init_program_engine(struct lp55xx_chip *chip) @@ -840,6 +804,9 @@ static struct lp55xx_device_config lp5523_cfg = { .reg_op_mode = { .addr = LP5523_REG_OP_MODE, }, + .reg_exec = { + .addr = LP5523_REG_ENABLE, + }, .engine_busy = { .addr = LP5523_REG_STATUS, .mask = LP5523_ENGINE_BUSY, diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index 5e26a52f534f..fb05439576c3 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -127,8 +127,6 @@ static void lp5562_set_led_current(struct lp55xx_led *led, u8 led_current) static void lp5562_run_engine(struct lp55xx_chip *chip, bool start) { int ret; - u8 mode; - u8 exec; /* stop engine */ if (!start) { @@ -141,40 +139,9 @@ static void lp5562_run_engine(struct lp55xx_chip *chip, bool start) return; } - /* - * To run the engine, - * operation mode and enable register should updated at the same time - */ - - ret = lp55xx_read(chip, LP5562_REG_OP_MODE, &mode); - if (ret) - return; - - ret = lp55xx_read(chip, LP5562_REG_ENABLE, &exec); - if (ret) - return; - - /* change operation mode to RUN only when each engine is loading */ - if (LP5562_ENG1_IS_LOADING(mode)) { - mode = (mode & ~LP5562_MODE_ENG1_M) | LP5562_RUN_ENG1; - exec = (exec & ~LP5562_EXEC_ENG1_M) | LP5562_RUN_ENG1; - } - - if (LP5562_ENG2_IS_LOADING(mode)) { - mode = (mode & ~LP5562_MODE_ENG2_M) | LP5562_RUN_ENG2; - exec = (exec & ~LP5562_EXEC_ENG2_M) | LP5562_RUN_ENG2; - } - - if (LP5562_ENG3_IS_LOADING(mode)) { - mode = (mode & ~LP5562_MODE_ENG3_M) | LP5562_RUN_ENG3; - exec = (exec & ~LP5562_EXEC_ENG3_M) | LP5562_RUN_ENG3; - } - - lp55xx_write(chip, LP5562_REG_OP_MODE, mode); - lp5562_wait_opmode_done(); - - lp55xx_update_bits(chip, LP5562_REG_ENABLE, LP5562_EXEC_M, exec); - lp5562_wait_enable_done(); + ret = lp55xx_run_engine_common(chip); + if (!ret) + lp5562_wait_enable_done(); } static int lp5562_update_firmware(struct lp55xx_chip *chip, @@ -472,6 +439,9 @@ static struct lp55xx_device_config lp5562_cfg = { .reg_op_mode = { .addr = LP5562_REG_OP_MODE, }, + .reg_exec = { + .addr = LP5562_REG_ENABLE, + }, .reset = { .addr = LP5562_REG_RESET, .val = LP5562_RESET, diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 636e3ca0bb87..9c2e3b2c72fb 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -45,6 +45,15 @@ #define LP55xx_MODE_ENGn_GET(n, mode, shift) \ (((mode) >> LP55xx_MODE_ENGn_SHIFT(n, shift)) & LP55xx_MODE_ENG_MASK) +#define LP55xx_EXEC_ENG_MASK GENMASK(1, 0) +#define LP55xx_EXEC_HOLD_ENG FIELD_PREP_CONST(LP55xx_EXEC_ENG_MASK, 0x0) +#define LP55xx_EXEC_STEP_ENG FIELD_PREP_CONST(LP55xx_EXEC_ENG_MASK, 0x1) +#define LP55xx_EXEC_RUN_ENG FIELD_PREP_CONST(LP55xx_EXEC_ENG_MASK, 0x2) +#define LP55xx_EXEC_ONCE_ENG FIELD_PREP_CONST(LP55xx_EXEC_ENG_MASK, 0x3) + +#define LP55xx_EXEC_ENGn_SHIFT(n, shift) ((shift) + (2 * (3 - (n)))) +#define LP55xx_EXEC_ENGn_MASK(n, shift) (LP55xx_EXEC_ENG_MASK << LP55xx_EXEC_ENGn_SHIFT(n, shift)) + /* Memory Page Selection */ #define LP55xx_REG_PROG_PAGE_SEL 0x4f /* If supported, each ENGINE have an equal amount of pages offset from page 0 */ @@ -117,6 +126,40 @@ void lp55xx_load_engine(struct lp55xx_chip *chip) } EXPORT_SYMBOL_GPL(lp55xx_load_engine); +int lp55xx_run_engine_common(struct lp55xx_chip *chip) +{ + const struct lp55xx_device_config *cfg = chip->cfg; + u8 mode, exec; + int i, ret; + + /* To run the engine, both OP MODE and EXEC needs to be put in RUN mode */ + ret = lp55xx_read(chip, cfg->reg_op_mode.addr, &mode); + if (ret) + return ret; + + ret = lp55xx_read(chip, cfg->reg_exec.addr, &exec); + if (ret) + return ret; + + /* Switch to RUN only for engine that were put in LOAD previously */ + for (i = LP55XX_ENGINE_1; i <= LP55XX_ENGINE_3; i++) { + if (LP55xx_MODE_ENGn_GET(i, mode, cfg->reg_op_mode.shift) != LP55xx_MODE_LOAD_ENG) + continue; + + mode &= ~LP55xx_MODE_ENGn_MASK(i, cfg->reg_op_mode.shift); + mode |= LP55xx_MODE_RUN_ENG << LP55xx_MODE_ENGn_SHIFT(i, cfg->reg_op_mode.shift); + exec &= ~LP55xx_EXEC_ENGn_MASK(i, cfg->reg_exec.shift); + exec |= LP55xx_EXEC_RUN_ENG << LP55xx_EXEC_ENGn_SHIFT(i, cfg->reg_exec.shift); + } + + lp55xx_write(chip, cfg->reg_op_mode.addr, mode); + lp55xx_wait_opmode_done(chip); + lp55xx_write(chip, cfg->reg_exec.addr, exec); + + return 0; +} +EXPORT_SYMBOL_GPL(lp55xx_run_engine_common); + static void lp55xx_reset_device(struct lp55xx_chip *chip) { const struct lp55xx_device_config *cfg = chip->cfg; diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 015ac2ef4e4d..dd74b214ec74 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -112,6 +112,7 @@ struct lp55xx_reg { */ struct lp55xx_device_config { const struct lp55xx_reg reg_op_mode; /* addr, shift */ + const struct lp55xx_reg reg_exec; /* addr, shift */ const struct lp55xx_reg engine_busy; /* addr, mask */ const struct lp55xx_reg reset; const struct lp55xx_reg enable; @@ -206,6 +207,7 @@ extern bool lp55xx_is_extclk_used(struct lp55xx_chip *chip); /* common chip functions */ extern void lp55xx_stop_all_engine(struct lp55xx_chip *chip); extern void lp55xx_load_engine(struct lp55xx_chip *chip); +extern int lp55xx_run_engine_common(struct lp55xx_chip *chip); /* common probe/remove function */ extern int lp55xx_probe(struct i2c_client *client); diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c index abe2c4b213d7..47b30e9d04a2 100644 --- a/drivers/leds/leds-lp8501.c +++ b/drivers/leds/leds-lp8501.c @@ -127,10 +127,6 @@ static void lp8501_turn_off_channels(struct lp55xx_chip *chip) static void lp8501_run_engine(struct lp55xx_chip *chip, bool start) { - int ret; - u8 mode; - u8 exec; - /* stop engine */ if (!start) { lp55xx_stop_all_engine(chip); @@ -138,39 +134,7 @@ static void lp8501_run_engine(struct lp55xx_chip *chip, bool start) return; } - /* - * To run the engine, - * operation mode and enable register should updated at the same time - */ - - ret = lp55xx_read(chip, LP8501_REG_OP_MODE, &mode); - if (ret) - return; - - ret = lp55xx_read(chip, LP8501_REG_ENABLE, &exec); - if (ret) - return; - - /* change operation mode to RUN only when each engine is loading */ - if (LP8501_ENG1_IS_LOADING(mode)) { - mode = (mode & ~LP8501_MODE_ENG1_M) | LP8501_RUN_ENG1; - exec = (exec & ~LP8501_EXEC_ENG1_M) | LP8501_RUN_ENG1; - } - - if (LP8501_ENG2_IS_LOADING(mode)) { - mode = (mode & ~LP8501_MODE_ENG2_M) | LP8501_RUN_ENG2; - exec = (exec & ~LP8501_EXEC_ENG2_M) | LP8501_RUN_ENG2; - } - - if (LP8501_ENG3_IS_LOADING(mode)) { - mode = (mode & ~LP8501_MODE_ENG3_M) | LP8501_RUN_ENG3; - exec = (exec & ~LP8501_EXEC_ENG3_M) | LP8501_RUN_ENG3; - } - - lp55xx_write(chip, LP8501_REG_OP_MODE, mode); - lp8501_wait_opmode_done(); - - lp55xx_update_bits(chip, LP8501_REG_ENABLE, LP8501_EXEC_M, exec); + lp55xx_run_engine_common(chip); } static int lp8501_update_program_memory(struct lp55xx_chip *chip, @@ -258,6 +222,9 @@ static struct lp55xx_device_config lp8501_cfg = { .reg_op_mode = { .addr = LP8501_REG_OP_MODE, }, + .reg_exec = { + .addr = LP8501_REG_ENABLE, + }, .engine_busy = { .addr = LP8501_REG_STATUS, .mask = LP8501_ENGINE_BUSY, From patchwork Sat Jun 15 23:11:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804582 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60E43757F0; Sat, 15 Jun 2024 23:12:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493181; cv=none; b=DKNPqmHyTJxELc/TiGVQJorQLzZDyQtbvTEeFh2ZJbvn9t3k6012esvjFVaE7jATRpIPyfXs20z/hBZxrMTnpEXzGM47jVfUwDkrbMgntlMGhycQs9OBbYc5yLDNz6sh04DaxiP1aLu32ND25oZmIQkpQafBq1VL/wAURfN438E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493181; c=relaxed/simple; bh=jpvVBinjL8elz0QeGVnppBN3OzVoAOQIVXhAfL4l4Ps=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gW9T682rIamn3X2awHyOcZqkRhCYXm+v9wgvQphuR1gqAIuQudkLpQdPK3srec2OKwIw3JnTtxUGTSu/2neZpaPz0SMC4sFgdRIpRYlz9bwj67RayPFvFE5loV/XgO5JnaN6u0uT80Kkvm+aYezYL069XyX8NnHWLrjcijOy0DY= 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=Vn15l0Iv; arc=none smtp.client-ip=209.85.221.48 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="Vn15l0Iv" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-35f27eed98aso2722433f8f.2; Sat, 15 Jun 2024 16:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493178; x=1719097978; 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=vMFwm7/QZL9Sy2AQL6wNOzbSx3Ekmm89kZ4tXsz7YGs=; b=Vn15l0Iv+u/vO0NbhEdWDdpxNM5lPEgMjFu4dtxNQ9CXOiNROfOmyIHK13vRBbgf4H q0P8HIjUdz0ylCc08gcgi7zj8wtOafuhjsYuffg/8SM4h8Y78bNOm09sFYT0U+96ageB RJsO2BoLm0yUVhQu9wKUEBhqOslo+lPl5wBdD4miChAe9qx4edZz6LLQ8VSXimezI5Nm 3zSKMOLLy208sTjo3zTo//ajVi1R1KWzwuA3D4aTOSv2i9nyITxXx+3pFx39UCq8hf2a VhlPIB+QMYj+ScX3UnpFvudoeadaxIheYeB1Fh3W2UPoZPEJOlvYyucr20miDPyOgY4q pCvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493178; x=1719097978; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vMFwm7/QZL9Sy2AQL6wNOzbSx3Ekmm89kZ4tXsz7YGs=; b=eno2UswUO1J5aLNMi+RvLSQEm0+s+2gFxw32SYINIheIA/vRVH5MBtyyJLziZM5JwQ QoSV+cyO2nLd5AbrrjbDAXmJwrFQsxAdh7iHoLjKNY6OS4PyHvhTi8Z90l8DFiOi/SoE 0rkl9DVwxvW97nWwVVMACGQ1qSd4ECAMRfKYAOT3Q1+vGf9GuhbPhoPXYTCd+jZxjuxv gcJCA7WjYxggU30Iv6xghzFI1mUsLFWRHk05q0x7/hddJ3OELw2Smj/atQn4/DGkqnpi rDxUSaEF+xFTL+px0SqZ4DDuMWjzh38wxA5OPLHI2fqfAAbYCpaIp3yJxW4MO+av+cL7 8R0g== X-Forwarded-Encrypted: i=1; AJvYcCV2V/oEtpzji4G+CWNCf1Czjprs5+0Hlm1tLmPZNhBMfK10kvuvQhpl6buL6xb+imNvtMh/IGBEbylN97fxAGVqbU1NYc2AzvDsg3gLr2IkOxvjZQ8l0eP0gdMl+Qr1GyKbrBUknLWTxl7eQ+tghGyJljMrAMVdKplmxODso2eqbnwZPqQ= X-Gm-Message-State: AOJu0Yxxx60gVlPlISaS/3rMELxU0dHk3aXjd1/dNVsUpNG9ouwZXs3i 2eZtgCV9Zj5VvhJ1MQdDlHJTts1CJTpVGXyt9EUPCsYlwl2eEG/u X-Google-Smtp-Source: AGHT+IEd3fJu/LlQEoPSSPQFqcWODjkaR43WHJ+V4HOU1ONSOFkHGm/XUFcw85oxFMIjG9YOObLu6A== X-Received: by 2002:a05:6000:188d:b0:360:82c7:f07f with SMTP id ffacd0b85a97d-36082c7f5dbmr3254125f8f.57.1718493177610; Sat, 15 Jun 2024 16:12:57 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:12:57 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 08/20] leds: leds-lp55xx: generalize update_program_memory function Date: Sun, 16 Jun 2024 01:11:38 +0200 Message-ID: <20240615231152.28201-9-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 LED Driver based on lp55xx all use the same logic to write memory in SMEM. The only difference is that legacy chip doesn't support pages and have the engine regs one after another. To handle this apply the same logic used for load_engine also for update_program_memory. Introduce a new config in device_config, base_prog. For LED chip that doesn't support pages, offset this values of 32 for each engine. Update all lp55xx based LED driver to use this new function and define all the required bits. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 56 +++-------------------------- drivers/leds/leds-lp5523.c | 50 +++----------------------- drivers/leds/leds-lp5562.c | 58 +++---------------------------- drivers/leds/leds-lp55xx-common.c | 57 ++++++++++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 4 +++ drivers/leds/leds-lp8501.c | 52 +++------------------------ 6 files changed, 79 insertions(+), 198 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 0b9f99f4fff2..7ea3e5715f59 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -146,55 +146,6 @@ static void lp5521_run_engine(struct lp55xx_chip *chip, bool start) lp5521_wait_enable_done(); } -static int lp5521_update_program_memory(struct lp55xx_chip *chip, - const u8 *data, size_t size) -{ - enum lp55xx_engine_index idx = chip->engine_idx; - u8 pattern[LP5521_PROGRAM_LENGTH] = {0}; - static const u8 addr[] = { - [LP55XX_ENGINE_1] = LP5521_REG_R_PROG_MEM, - [LP55XX_ENGINE_2] = LP5521_REG_G_PROG_MEM, - [LP55XX_ENGINE_3] = LP5521_REG_B_PROG_MEM, - }; - unsigned cmd; - char c[3]; - int nrchars; - int ret; - int offset = 0; - int i = 0; - - while ((offset < size - 1) && (i < LP5521_PROGRAM_LENGTH)) { - /* separate sscanfs because length is working only for %s */ - ret = sscanf(data + offset, "%2s%n ", c, &nrchars); - if (ret != 1) - goto err; - - ret = sscanf(c, "%2x", &cmd); - if (ret != 1) - goto err; - - pattern[i] = (u8)cmd; - offset += nrchars; - i++; - } - - /* Each instruction is 16bit long. Check that length is even */ - if (i % 2) - goto err; - - for (i = 0; i < LP5521_PROGRAM_LENGTH; i++) { - ret = lp55xx_write(chip, addr[idx] + i, pattern[i]); - if (ret) - return -EINVAL; - } - - return size; - -err: - dev_err(&chip->cl->dev, "wrong pattern format\n"); - return -EINVAL; -} - static void lp5521_firmware_loaded(struct lp55xx_chip *chip) { const struct firmware *fw = chip->fw; @@ -212,7 +163,7 @@ static void lp5521_firmware_loaded(struct lp55xx_chip *chip) */ lp55xx_load_engine(chip); - lp5521_update_program_memory(chip, fw->data, fw->size); + lp55xx_update_program_memory(chip, fw->data, fw->size); } static int lp5521_post_init_device(struct lp55xx_chip *chip) @@ -389,7 +340,7 @@ static ssize_t store_engine_load(struct device *dev, chip->engine_idx = nr; lp55xx_load_engine(chip); - ret = lp5521_update_program_memory(chip, buf, len); + ret = lp55xx_update_program_memory(chip, buf, len); mutex_unlock(&chip->lock); @@ -454,6 +405,9 @@ static struct lp55xx_device_config lp5521_cfg = { .addr = LP5521_REG_ENABLE, .val = LP5521_ENABLE_DEFAULT, }, + .prog_mem_base = { + .addr = LP5521_REG_R_PROG_MEM, + }, .max_channel = LP5521_MAX_LEDS, .post_init_device = lp5521_post_init_device, .brightness_fn = lp5521_led_brightness, diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index b28955b72189..395c57330484 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -254,49 +254,6 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) return ret; } -static int lp5523_update_program_memory(struct lp55xx_chip *chip, - const u8 *data, size_t size) -{ - u8 pattern[LP5523_PROGRAM_LENGTH] = {0}; - unsigned int cmd; - char c[3]; - int nrchars; - int ret; - int offset = 0; - int i = 0; - - while ((offset < size - 1) && (i < LP5523_PROGRAM_LENGTH)) { - /* separate sscanfs because length is working only for %s */ - ret = sscanf(data + offset, "%2s%n ", c, &nrchars); - if (ret != 1) - goto err; - - ret = sscanf(c, "%2x", &cmd); - if (ret != 1) - goto err; - - pattern[i] = (u8)cmd; - offset += nrchars; - i++; - } - - /* Each instruction is 16bit long. Check that length is even */ - if (i % 2) - goto err; - - for (i = 0; i < LP5523_PROGRAM_LENGTH; i++) { - ret = lp55xx_write(chip, LP5523_REG_PROG_MEM + i, pattern[i]); - if (ret) - return -EINVAL; - } - - return size; - -err: - dev_err(&chip->cl->dev, "wrong pattern format\n"); - return -EINVAL; -} - static void lp5523_firmware_loaded(struct lp55xx_chip *chip) { const struct firmware *fw = chip->fw; @@ -314,7 +271,7 @@ static void lp5523_firmware_loaded(struct lp55xx_chip *chip) */ lp55xx_load_engine(chip); - lp5523_update_program_memory(chip, fw->data, fw->size); + lp55xx_update_program_memory(chip, fw->data, fw->size); } static ssize_t show_engine_mode(struct device *dev, @@ -496,7 +453,7 @@ static ssize_t store_engine_load(struct device *dev, chip->engine_idx = nr; lp55xx_load_engine(chip); - ret = lp5523_update_program_memory(chip, buf, len); + ret = lp55xx_update_program_memory(chip, buf, len); mutex_unlock(&chip->lock); @@ -819,6 +776,9 @@ static struct lp55xx_device_config lp5523_cfg = { .addr = LP5523_REG_ENABLE, .val = LP5523_ENABLE, }, + .prog_mem_base = { + .addr = LP5523_REG_PROG_MEM, + }, .pages_per_engine = LP5523_PAGES_PER_ENGINE, .max_channel = LP5523_MAX_LEDS, .post_init_device = lp5523_post_init_device, diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index fb05439576c3..7f3733fc446e 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -144,59 +144,6 @@ static void lp5562_run_engine(struct lp55xx_chip *chip, bool start) lp5562_wait_enable_done(); } -static int lp5562_update_firmware(struct lp55xx_chip *chip, - const u8 *data, size_t size) -{ - enum lp55xx_engine_index idx = chip->engine_idx; - u8 pattern[LP5562_PROGRAM_LENGTH] = {0}; - static const u8 addr[] = { - [LP55XX_ENGINE_1] = LP5562_REG_PROG_MEM_ENG1, - [LP55XX_ENGINE_2] = LP5562_REG_PROG_MEM_ENG2, - [LP55XX_ENGINE_3] = LP5562_REG_PROG_MEM_ENG3, - }; - unsigned cmd; - char c[3]; - int program_size; - int nrchars; - int offset = 0; - int ret; - int i; - - /* clear program memory before updating */ - for (i = 0; i < LP5562_PROGRAM_LENGTH; i++) - lp55xx_write(chip, addr[idx] + i, 0); - - i = 0; - while ((offset < size - 1) && (i < LP5562_PROGRAM_LENGTH)) { - /* separate sscanfs because length is working only for %s */ - ret = sscanf(data + offset, "%2s%n ", c, &nrchars); - if (ret != 1) - goto err; - - ret = sscanf(c, "%2x", &cmd); - if (ret != 1) - goto err; - - pattern[i] = (u8)cmd; - offset += nrchars; - i++; - } - - /* Each instruction is 16bit long. Check that length is even */ - if (i % 2) - goto err; - - program_size = i; - for (i = 0; i < program_size; i++) - lp55xx_write(chip, addr[idx] + i, pattern[i]); - - return 0; - -err: - dev_err(&chip->cl->dev, "wrong pattern format\n"); - return -EINVAL; -} - static void lp5562_firmware_loaded(struct lp55xx_chip *chip) { const struct firmware *fw = chip->fw; @@ -218,7 +165,7 @@ static void lp5562_firmware_loaded(struct lp55xx_chip *chip) */ lp55xx_load_engine(chip); - lp5562_update_firmware(chip, fw->data, fw->size); + lp55xx_update_program_memory(chip, fw->data, fw->size); } static int lp5562_post_init_device(struct lp55xx_chip *chip) @@ -450,6 +397,9 @@ static struct lp55xx_device_config lp5562_cfg = { .addr = LP5562_REG_ENABLE, .val = LP5562_ENABLE_DEFAULT, }, + .prog_mem_base = { + .addr = LP5562_REG_PROG_MEM_ENG1, + }, .post_init_device = lp5562_post_init_device, .set_led_current = lp5562_set_led_current, .brightness_fn = lp5562_led_brightness, diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 9c2e3b2c72fb..9f060b412435 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -26,6 +26,8 @@ /* OP MODE require at least 153 us to clear regs */ #define LP55XX_CMD_SLEEP 200 +#define LP55xx_PROGRAM_LENGTH 32 + /* * Program Memory Operations * Same Mask for each engine for both mode and exec @@ -160,6 +162,61 @@ int lp55xx_run_engine_common(struct lp55xx_chip *chip) } EXPORT_SYMBOL_GPL(lp55xx_run_engine_common); +int lp55xx_update_program_memory(struct lp55xx_chip *chip, + const u8 *data, size_t size) +{ + enum lp55xx_engine_index idx = chip->engine_idx; + const struct lp55xx_device_config *cfg = chip->cfg; + u8 pattern[LP55xx_PROGRAM_LENGTH] = { }; + u8 start_addr = cfg->prog_mem_base.addr; + int i = 0, offset = 0; + int ret; + + while ((offset < size - 1) && (i < LP55xx_PROGRAM_LENGTH)) { + unsigned int cmd; + int nrchars; + char c[3]; + + /* separate sscanfs because length is working only for %s */ + ret = sscanf(data + offset, "%2s%n ", c, &nrchars); + if (ret != 1) + goto err; + + ret = sscanf(c, "%2x", &cmd); + if (ret != 1) + goto err; + + pattern[i] = (u8)cmd; + offset += nrchars; + i++; + } + + /* Each instruction is 16bit long. Check that length is even */ + if (i % 2) + goto err; + + /* + * For legacy LED chip with no page support, engine base address are + * one after another at offset of 32. + * For LED chip that support page, PAGE is already set in load_engine. + */ + if (!cfg->pages_per_engine) + start_addr += LP55xx_PROGRAM_LENGTH * idx; + + for (i = 0; i < LP55xx_PROGRAM_LENGTH; i++) { + ret = lp55xx_write(chip, start_addr + i, pattern[i]); + if (ret) + return -EINVAL; + } + + return size; + +err: + dev_err(&chip->cl->dev, "wrong pattern format\n"); + return -EINVAL; +} +EXPORT_SYMBOL_GPL(lp55xx_update_program_memory); + static void lp55xx_reset_device(struct lp55xx_chip *chip) { const struct lp55xx_device_config *cfg = chip->cfg; diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index dd74b214ec74..f0bbd41fdab3 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -99,6 +99,7 @@ struct lp55xx_reg { * (if not supported 153 us sleep) * @reset : Chip specific reset command * @enable : Chip specific enable command + * @prog_mem_base : Chip specific base reg address for chip SMEM programming * @pages_per_engine : Assigned pages for each engine * (if not set chip doesn't support pages) * @max_channel : Maximum number of channels @@ -116,6 +117,7 @@ struct lp55xx_device_config { const struct lp55xx_reg engine_busy; /* addr, mask */ const struct lp55xx_reg reset; const struct lp55xx_reg enable; + const struct lp55xx_reg prog_mem_base; const int pages_per_engine; const int max_channel; @@ -208,6 +210,8 @@ extern bool lp55xx_is_extclk_used(struct lp55xx_chip *chip); extern void lp55xx_stop_all_engine(struct lp55xx_chip *chip); extern void lp55xx_load_engine(struct lp55xx_chip *chip); extern int lp55xx_run_engine_common(struct lp55xx_chip *chip); +extern int lp55xx_update_program_memory(struct lp55xx_chip *chip, + const u8 *data, size_t size); /* common probe/remove function */ extern int lp55xx_probe(struct i2c_client *client); diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c index 47b30e9d04a2..d4094d20bdc1 100644 --- a/drivers/leds/leds-lp8501.c +++ b/drivers/leds/leds-lp8501.c @@ -137,53 +137,6 @@ static void lp8501_run_engine(struct lp55xx_chip *chip, bool start) lp55xx_run_engine_common(chip); } -static int lp8501_update_program_memory(struct lp55xx_chip *chip, - const u8 *data, size_t size) -{ - u8 pattern[LP8501_PROGRAM_LENGTH] = {0}; - unsigned cmd; - char c[3]; - int update_size; - int nrchars; - int offset = 0; - int ret; - int i; - - /* clear program memory before updating */ - for (i = 0; i < LP8501_PROGRAM_LENGTH; i++) - lp55xx_write(chip, LP8501_REG_PROG_MEM + i, 0); - - i = 0; - while ((offset < size - 1) && (i < LP8501_PROGRAM_LENGTH)) { - /* separate sscanfs because length is working only for %s */ - ret = sscanf(data + offset, "%2s%n ", c, &nrchars); - if (ret != 1) - goto err; - - ret = sscanf(c, "%2x", &cmd); - if (ret != 1) - goto err; - - pattern[i] = (u8)cmd; - offset += nrchars; - i++; - } - - /* Each instruction is 16bit long. Check that length is even */ - if (i % 2) - goto err; - - update_size = i; - for (i = 0; i < update_size; i++) - lp55xx_write(chip, LP8501_REG_PROG_MEM + i, pattern[i]); - - return 0; - -err: - dev_err(&chip->cl->dev, "wrong pattern format\n"); - return -EINVAL; -} - static void lp8501_firmware_loaded(struct lp55xx_chip *chip) { const struct firmware *fw = chip->fw; @@ -201,7 +154,7 @@ static void lp8501_firmware_loaded(struct lp55xx_chip *chip) */ lp55xx_load_engine(chip); - lp8501_update_program_memory(chip, fw->data, fw->size); + lp55xx_update_program_memory(chip, fw->data, fw->size); } static int lp8501_led_brightness(struct lp55xx_led *led) @@ -237,6 +190,9 @@ static struct lp55xx_device_config lp8501_cfg = { .addr = LP8501_REG_ENABLE, .val = LP8501_ENABLE, }, + .prog_mem_base = { + .addr = LP8501_REG_PROG_MEM, + }, .pages_per_engine = LP8501_PAGES_PER_ENGINE, .max_channel = LP8501_MAX_LEDS, .post_init_device = lp8501_post_init_device, From patchwork Sat Jun 15 23:11:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805056 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21AC477624; Sat, 15 Jun 2024 23:12:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493182; cv=none; b=c0aLggErBbGtbqqr4ciIVqAWFPPZ6Dmk0mQjILMiWnAJjLfLwVnlXOVi5nJ+/CpTJbRWyWuROEcH5/KJWWWGm9YgFspx99+ZmRBizw7JwayWU88JZ6nGiY72oYvC9kl6jw/jjlNH55m3KwGcuCC80yjCtC2XQmdFRMUmr5tS1L0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493182; c=relaxed/simple; bh=apm5rwcCzjeljGR2q/A/ytEBR6gnOCuyH5llSEY300g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ipxLWDnnrj44mIQ/UyUu7zOVbX8ZnIIwOtiXKW/k2JYi9BWSgk6LB3o4tDlJpKyCr1SOwqaNj5RWjWo1/ImCluHkaWAc4vfWoLXJHSH2tk8aNELArIEfLTR1EneaLFaywplLVOBifFcQ4mh7LXHNTYcL+KcP7LnQuqHKK0syMAI= 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=b/hDVBhR; arc=none smtp.client-ip=209.85.221.42 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="b/hDVBhR" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-35f275c7286so2952895f8f.2; Sat, 15 Jun 2024 16:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493178; x=1719097978; 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=jA3gS4eCwa1PxS2bZ3pvhQoaJRFYvkm+SPUckuQyVmw=; b=b/hDVBhRk8HK9meOqt4XkG9FxRuTSRPQTUzgRKrm3V255uZKmcmmolmsfoBYcfzmRD vkrpPujHZssIKqzB6JGqQd7lSIRx2WTyq385Us1f5lrcg3GHVZpGY3OHuG1s6DrZQSZx S0KYx7Hl1DlbSrLdsYE6sYt+y2Ugq1CQPjwxIOv5fPaLtKUlYSbs4q5jYQjacmsIss2Z UtbRXs2XyWtxktsyj4xI5C6Fqq9DVmnWV9ZR/LiY6eFgRd8Zz4/KRXpx8vsEFc+q+mf3 36oyLdR3DCUDxrL4iYfTmzT+TDCon7ABX7JIFMx5vo566HW48A8yxXvpDAxcGAEBFWy+ 9bkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493178; x=1719097978; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jA3gS4eCwa1PxS2bZ3pvhQoaJRFYvkm+SPUckuQyVmw=; b=MDoA4Xtau2AmlZyBbyxubdH4hNZ6XlC06L9/V9iDDOb/3+5LMHxLFZ0+K0G08Rq3Bf 74Ox5dUkMk5CTdkv3O2L2PYKGor6hQBk0N8ko3uC/Sp3xHQuIVnbaeLfBxw6y8VxGE2r 5LmqyYOJCCyGYBVyeotMWn693cwUcq78OvWBAN8oujKu+uQktI7yBmKwtUUyElmSvEJa SL6QfhCIFP+CWPmybz3ZF9XSmdEXDxcEzLrBQLjMTsgZwlsA8KG6QfdsbbI1whCEsh18 9LL1mIWj9W4DMLNDX/5PXb1xT9ZX3cR+ta43WQYldl6d8Nl5cz5/C9/QweWnPk2l7GRW xTag== X-Forwarded-Encrypted: i=1; AJvYcCXMHFVzZX0jlreVNfMr9Eg/ryKd5BNof3FTe8ajtMhrHVam9fi6HW1D1RpwlC7Pug0BN5WRhnfkKdBPCbN/pNRv398DQTjVIctS8zgm5+4GkY5AzR5GAtI+ZS0FbI74cw0t9GApB6bhJDWNztPj3jtAjmvQ4NTKLJPt2Ghy7daA8lKNEi0= X-Gm-Message-State: AOJu0YxnlKG9aPK21B6OkPwDgHTOUHngwrt435Nu/5JCsFYrVgRDpoGm NpTbqeVe359BU78p4sgPXXjpHGp1uT390fVynyFa4YmvRzsBP3sU X-Google-Smtp-Source: AGHT+IH5IEes8KcTT4kLIz0dO8JavcqR2prjRLWGwfj6nYoOrkQvq6G2iaGk3BKe8v4CrNUNr7Bjkw== X-Received: by 2002:a05:6000:1564:b0:357:73ca:9c00 with SMTP id ffacd0b85a97d-3607a7660fbmr4808861f8f.32.1718493178496; Sat, 15 Jun 2024 16:12:58 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.12.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:12:58 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 09/20] leds: leds-lp55xx: generalize firmware_loaded function Date: Sun, 16 Jun 2024 01:11:39 +0200 Message-ID: <20240615231152.28201-10-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize firmware_loaded function as lp55xx based LED driver all share the same logic. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 22 +--------------------- drivers/leds/leds-lp5523.c | 22 +--------------------- drivers/leds/leds-lp5562.c | 26 +------------------------- drivers/leds/leds-lp55xx-common.c | 25 +++++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 1 + drivers/leds/leds-lp8501.c | 22 +--------------------- 6 files changed, 30 insertions(+), 88 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 7ea3e5715f59..722b5cd9236e 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -146,26 +146,6 @@ static void lp5521_run_engine(struct lp55xx_chip *chip, bool start) lp5521_wait_enable_done(); } -static void lp5521_firmware_loaded(struct lp55xx_chip *chip) -{ - const struct firmware *fw = chip->fw; - - if (fw->size > LP5521_PROGRAM_LENGTH) { - dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n", - fw->size); - return; - } - - /* - * Program memory sequence - * 1) set engine mode to "LOAD" - * 2) write firmware data into program memory - */ - - lp55xx_load_engine(chip); - lp55xx_update_program_memory(chip, fw->data, fw->size); -} - static int lp5521_post_init_device(struct lp55xx_chip *chip) { int ret; @@ -413,7 +393,7 @@ static struct lp55xx_device_config lp5521_cfg = { .brightness_fn = lp5521_led_brightness, .multicolor_brightness_fn = lp5521_multicolor_brightness, .set_led_current = lp5521_set_led_current, - .firmware_cb = lp5521_firmware_loaded, + .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp5521_run_engine, .dev_attr_group = &lp5521_group, }; diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 395c57330484..5525d60c342c 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -254,26 +254,6 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) return ret; } -static void lp5523_firmware_loaded(struct lp55xx_chip *chip) -{ - const struct firmware *fw = chip->fw; - - if (fw->size > LP5523_PROGRAM_LENGTH) { - dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n", - fw->size); - return; - } - - /* - * Program memory sequence - * 1) set engine mode to "LOAD" - * 2) write firmware data into program memory - */ - - lp55xx_load_engine(chip); - lp55xx_update_program_memory(chip, fw->data, fw->size); -} - static ssize_t show_engine_mode(struct device *dev, struct device_attribute *attr, char *buf, int nr) @@ -785,7 +765,7 @@ static struct lp55xx_device_config lp5523_cfg = { .brightness_fn = lp5523_led_brightness, .multicolor_brightness_fn = lp5523_multicolor_brightness, .set_led_current = lp5523_set_led_current, - .firmware_cb = lp5523_firmware_loaded, + .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp5523_run_engine, .dev_attr_group = &lp5523_group, }; diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index 7f3733fc446e..e50b68c9ccf3 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -144,30 +144,6 @@ static void lp5562_run_engine(struct lp55xx_chip *chip, bool start) lp5562_wait_enable_done(); } -static void lp5562_firmware_loaded(struct lp55xx_chip *chip) -{ - const struct firmware *fw = chip->fw; - - /* - * the firmware is encoded in ascii hex character, with 2 chars - * per byte - */ - if (fw->size > (LP5562_PROGRAM_LENGTH * 2)) { - dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n", - fw->size); - return; - } - - /* - * Program memory sequence - * 1) set engine mode to "LOAD" - * 2) write firmware data into program memory - */ - - lp55xx_load_engine(chip); - lp55xx_update_program_memory(chip, fw->data, fw->size); -} - static int lp5562_post_init_device(struct lp55xx_chip *chip) { int ret; @@ -404,7 +380,7 @@ static struct lp55xx_device_config lp5562_cfg = { .set_led_current = lp5562_set_led_current, .brightness_fn = lp5562_led_brightness, .run_engine = lp5562_run_engine, - .firmware_cb = lp5562_firmware_loaded, + .firmware_cb = lp55xx_firmware_loaded_cb, .dev_attr_group = &lp5562_group, }; diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 9f060b412435..51bbe91cc7f2 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -217,6 +217,31 @@ int lp55xx_update_program_memory(struct lp55xx_chip *chip, } EXPORT_SYMBOL_GPL(lp55xx_update_program_memory); +void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip) +{ + const struct firmware *fw = chip->fw; + + /* + * the firmware is encoded in ascii hex character, with 2 chars + * per byte + */ + if (fw->size > LP55xx_PROGRAM_LENGTH * 2) { + dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n", + fw->size); + return; + } + + /* + * Program memory sequence + * 1) set engine mode to "LOAD" + * 2) write firmware data into program memory + */ + + lp55xx_load_engine(chip); + lp55xx_update_program_memory(chip, fw->data, fw->size); +} +EXPORT_SYMBOL_GPL(lp55xx_firmware_loaded_cb); + static void lp55xx_reset_device(struct lp55xx_chip *chip) { const struct lp55xx_device_config *cfg = chip->cfg; diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index f0bbd41fdab3..cbc122c56828 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -212,6 +212,7 @@ extern void lp55xx_load_engine(struct lp55xx_chip *chip); extern int lp55xx_run_engine_common(struct lp55xx_chip *chip); extern int lp55xx_update_program_memory(struct lp55xx_chip *chip, const u8 *data, size_t size); +extern void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip); /* common probe/remove function */ extern int lp55xx_probe(struct i2c_client *client); diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c index d4094d20bdc1..1ea7bb73cd22 100644 --- a/drivers/leds/leds-lp8501.c +++ b/drivers/leds/leds-lp8501.c @@ -137,26 +137,6 @@ static void lp8501_run_engine(struct lp55xx_chip *chip, bool start) lp55xx_run_engine_common(chip); } -static void lp8501_firmware_loaded(struct lp55xx_chip *chip) -{ - const struct firmware *fw = chip->fw; - - if (fw->size > LP8501_PROGRAM_LENGTH) { - dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n", - fw->size); - return; - } - - /* - * Program memory sequence - * 1) set engine mode to "LOAD" - * 2) write firmware data into program memory - */ - - lp55xx_load_engine(chip); - lp55xx_update_program_memory(chip, fw->data, fw->size); -} - static int lp8501_led_brightness(struct lp55xx_led *led) { struct lp55xx_chip *chip = led->chip; @@ -198,7 +178,7 @@ static struct lp55xx_device_config lp8501_cfg = { .post_init_device = lp8501_post_init_device, .brightness_fn = lp8501_led_brightness, .set_led_current = lp8501_set_led_current, - .firmware_cb = lp8501_firmware_loaded, + .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp8501_run_engine, }; From patchwork Sat Jun 15 23:11:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804581 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 137AB8175B; Sat, 15 Jun 2024 23:13:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493183; cv=none; b=NC+NtINMRloMuXqvr/98/aQMfUMxc7zBf9HcQMv2FqnKUoWyw1Tx5VGFfQJSRR9EiW9+DGv60UHJAbzxLXApq8+jA7rhYA2Zz22lAWhbO3B44asqOhpQcyN8xHFMQ4BdtyfrYn+ghZhCI7di/zcWzxcCWgOAuBSV1pvFpIMgk1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493183; c=relaxed/simple; bh=U0orKFk2dhQdQvk92NKAOsmad1yNY3xl/DPRqhxJn14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gIloW2SmBnicHr9APFFiAmM2whQgg+MNwdXK6edKLeLSfoQEft3mDdSqDYFOiICsRWA4NOrnxP8rHTMT4g/Ipox/404TxaUD7jwEtWOuWQJJK22BYPeZYbVqN2aq3oFRNUj2KRhbq1tXEl45iw+GK+3HpqFuwGx3mO29srFtEWs= 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=g09jh1mR; arc=none smtp.client-ip=209.85.221.47 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="g09jh1mR" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-35f223e7691so2120640f8f.1; Sat, 15 Jun 2024 16:13:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493179; x=1719097979; 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=qwJ/5jg54x8XV3v6t3PKGyWXpISXPGstbY09wxVLffY=; b=g09jh1mRB96i+joC9rztg6BOHr9pAX2R1VU+eoKin3ZDY1aGxj6QbIhjxL7PKdEqUU +wcNT36z8yUXPmsxpw4Mmi7XidE+eLfwN+kyH4Xn3EzVMYWycVmymMGeKvai4hDcy1G8 lOVpEdjY7VKQQ1dxZJi9sy+YJpRz+S2PvdI95QTm98zqSMqEJVMBZ4UaCvQHgGNl8mR6 cDjAn0Qk9vZwjTV8JgH9vdFgAIYJIblRz6uC/0w6wUXV9FM7T9CZNfDU7xAW4t7RlR7w 7PrHW8rJiUiyqbcMtCKxA8LObct7Pf9vNPgldynxFwuN7ZdOWUBjNkMICDOo+dMN7dZq +IHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493179; x=1719097979; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qwJ/5jg54x8XV3v6t3PKGyWXpISXPGstbY09wxVLffY=; b=FpoNT7SOWa295jjVn6w4RRwSpqMQQsfHF/E6uH0NbP3zEUdQo8ubJHbljgueEbu60g FI4AtOKsGCKgsoKdEnmwAb5BaNar8htU5fLXlij5zAkdWo2iMZDf31DuVq0GnwqMnOMz +JPAqZW2QCIhPgWrk001s/Ex2yti3L+f1cLj5NUew12srGz7TM2liU5ppjagO6wGbYX4 jLJHF/VTzEpGPTGmlW8+MYte1BdZamOurISI2viQDm6g7P2tJuU3LDACNEphStpSennX C6jT+VWHI+wPdO/cHYA0YsinCzjmy6XrCP5EKGNGCbrRHfyPLiPIvvB2JgDU1kQScgQI 82Ow== X-Forwarded-Encrypted: i=1; AJvYcCURGDLeubRfGwberquVgBiN7EtRYXHNrn5WO07nLG/AlColh1KUagAReFV9eB58+TYLKb4LvxrxsoqYUFWUCWEXozTe1+mCCeF3yyHBdqh0fPn9HOs/GusQJOVmaZvAxyEOHekuXo5+0KSOVmMdq6J83zY5ADVO/uAsXm2bT+fqCn8D0IA= X-Gm-Message-State: AOJu0YwEy3snr1VLsdtvqxh+SRJJvq4ag/T/jH3auHKyVtnQ0l50fHaa TfyuYVRhP21vNwtrMpC7/RN27vQBA1pH833MyNpc85WbxFfQkINC X-Google-Smtp-Source: AGHT+IHU3X3jPsKGU8Cnltkc45b0cl+S2v86R8QTSPYXzfQhwMsLnTJZXSWCnn5GbUncMjC0lRbkAQ== X-Received: by 2002:a5d:64ab:0:b0:35f:2c6b:ffe4 with SMTP id ffacd0b85a97d-36071901383mr11670182f8f.28.1718493179384; Sat, 15 Jun 2024 16:12:59 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:12:59 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 10/20] leds: leds-lp55xx: generalize led_brightness function Date: Sun, 16 Jun 2024 01:11:40 +0200 Message-ID: <20240615231152.28201-11-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize led_brightness function as the implementation is the same for most of the lp55xx based LED driver. Introduce a new option in device_config, reg_led_pwm_base since the reg value is not the same for every LED chip. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 18 ++++-------------- drivers/leds/leds-lp5523.c | 17 ++++------------- drivers/leds/leds-lp55xx-common.c | 14 ++++++++++++++ drivers/leds/leds-lp55xx-common.h | 3 +++ drivers/leds/leds-lp8501.c | 18 ++++-------------- 5 files changed, 29 insertions(+), 41 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 722b5cd9236e..e4d0dcdbf11b 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -241,19 +241,6 @@ static int lp5521_multicolor_brightness(struct lp55xx_led *led) return ret; } -static int lp5521_led_brightness(struct lp55xx_led *led) -{ - struct lp55xx_chip *chip = led->chip; - int ret; - - mutex_lock(&chip->lock); - ret = lp55xx_write(chip, LP5521_REG_LED_PWM_BASE + led->chan_nr, - led->brightness); - mutex_unlock(&chip->lock); - - return ret; -} - static ssize_t show_engine_mode(struct device *dev, struct device_attribute *attr, char *buf, int nr) @@ -388,9 +375,12 @@ static struct lp55xx_device_config lp5521_cfg = { .prog_mem_base = { .addr = LP5521_REG_R_PROG_MEM, }, + .reg_led_pwm_base = { + .addr = LP5521_REG_LED_PWM_BASE, + }, .max_channel = LP5521_MAX_LEDS, .post_init_device = lp5521_post_init_device, - .brightness_fn = lp5521_led_brightness, + .brightness_fn = lp55xx_led_brightness, .multicolor_brightness_fn = lp5521_multicolor_brightness, .set_led_current = lp5521_set_led_current, .firmware_cb = lp55xx_firmware_loaded_cb, diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 5525d60c342c..a3b4063d504e 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -683,18 +683,6 @@ static int lp5523_multicolor_brightness(struct lp55xx_led *led) return ret; } -static int lp5523_led_brightness(struct lp55xx_led *led) -{ - struct lp55xx_chip *chip = led->chip; - int ret; - - mutex_lock(&chip->lock); - ret = lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + led->chan_nr, - led->brightness); - mutex_unlock(&chip->lock); - return ret; -} - static LP55XX_DEV_ATTR_RW(engine1_mode, show_engine1_mode, store_engine1_mode); static LP55XX_DEV_ATTR_RW(engine2_mode, show_engine2_mode, store_engine2_mode); static LP55XX_DEV_ATTR_RW(engine3_mode, show_engine3_mode, store_engine3_mode); @@ -759,10 +747,13 @@ static struct lp55xx_device_config lp5523_cfg = { .prog_mem_base = { .addr = LP5523_REG_PROG_MEM, }, + .reg_led_pwm_base = { + .addr = LP5523_REG_LED_PWM_BASE, + }, .pages_per_engine = LP5523_PAGES_PER_ENGINE, .max_channel = LP5523_MAX_LEDS, .post_init_device = lp5523_post_init_device, - .brightness_fn = lp5523_led_brightness, + .brightness_fn = lp55xx_led_brightness, .multicolor_brightness_fn = lp5523_multicolor_brightness, .set_led_current = lp5523_set_led_current, .firmware_cb = lp55xx_firmware_loaded_cb, diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 51bbe91cc7f2..726283f155a0 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -242,6 +242,20 @@ void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip) } EXPORT_SYMBOL_GPL(lp55xx_firmware_loaded_cb); +int lp55xx_led_brightness(struct lp55xx_led *led) +{ + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + int ret; + + mutex_lock(&chip->lock); + ret = lp55xx_write(chip, cfg->reg_led_pwm_base.addr + led->chan_nr, + led->brightness); + mutex_unlock(&chip->lock); + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_led_brightness); + static void lp55xx_reset_device(struct lp55xx_chip *chip) { const struct lp55xx_device_config *cfg = chip->cfg; diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index cbc122c56828..4578418e5011 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -100,6 +100,7 @@ struct lp55xx_reg { * @reset : Chip specific reset command * @enable : Chip specific enable command * @prog_mem_base : Chip specific base reg address for chip SMEM programming + * @reg_led_pwm_base : Chip specific base reg address for LED PWM conf * @pages_per_engine : Assigned pages for each engine * (if not set chip doesn't support pages) * @max_channel : Maximum number of channels @@ -118,6 +119,7 @@ struct lp55xx_device_config { const struct lp55xx_reg reset; const struct lp55xx_reg enable; const struct lp55xx_reg prog_mem_base; + const struct lp55xx_reg reg_led_pwm_base; const int pages_per_engine; const int max_channel; @@ -213,6 +215,7 @@ extern int lp55xx_run_engine_common(struct lp55xx_chip *chip); extern int lp55xx_update_program_memory(struct lp55xx_chip *chip, const u8 *data, size_t size); extern void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip); +extern int lp55xx_led_brightness(struct lp55xx_led *led); /* common probe/remove function */ extern int lp55xx_probe(struct i2c_client *client); diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c index 1ea7bb73cd22..8f1fd9525e9a 100644 --- a/drivers/leds/leds-lp8501.c +++ b/drivers/leds/leds-lp8501.c @@ -137,19 +137,6 @@ static void lp8501_run_engine(struct lp55xx_chip *chip, bool start) lp55xx_run_engine_common(chip); } -static int lp8501_led_brightness(struct lp55xx_led *led) -{ - struct lp55xx_chip *chip = led->chip; - int ret; - - mutex_lock(&chip->lock); - ret = lp55xx_write(chip, LP8501_REG_LED_PWM_BASE + led->chan_nr, - led->brightness); - mutex_unlock(&chip->lock); - - return ret; -} - /* Chip specific configurations */ static struct lp55xx_device_config lp8501_cfg = { .reg_op_mode = { @@ -173,10 +160,13 @@ static struct lp55xx_device_config lp8501_cfg = { .prog_mem_base = { .addr = LP8501_REG_PROG_MEM, }, + .reg_led_pwm_base = { + .addr = LP8501_REG_LED_PWM_BASE, + }, .pages_per_engine = LP8501_PAGES_PER_ENGINE, .max_channel = LP8501_MAX_LEDS, .post_init_device = lp8501_post_init_device, - .brightness_fn = lp8501_led_brightness, + .brightness_fn = lp55xx_led_brightness, .set_led_current = lp8501_set_led_current, .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp8501_run_engine, From patchwork Sat Jun 15 23:11:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805055 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3C4912D743; Sat, 15 Jun 2024 23:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493183; cv=none; b=apiUuYsEKgpRAZ2gD1kZIqxX1hU+22LpjhtTCFKXRRQy7UohqL5lHyxprYKp8/iuNicZXFt84WH3e+DMgzOSC3NaQ2MW3ehXmaBv0iK6/Qzdoi2kMOWqjN3of9QGb3+lQSczGUR7LgjpJwr4fYZYybl7O8gqW1p9VqXQ9Te06KQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493183; c=relaxed/simple; bh=ZJDV39hSgo6/+74yn9pAfMDBxRXa1yEaTqYO1Bioi40=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jAMznaQ4PYxhucQv22p0hGqcO//9y+/pFpnxkiS8ZvkCdzUWOnvUjGdL6tCAilAX15vAhfpq+uyqbeCBF4LoXlNtPr3hbW1S6olxKcYRTX+9GrgG+T+esUhLxdRaGmf5PoOo1k1/c9aK7+Y9sLLxWm+79/uqD8C3n6Bcf7zKgAU= 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=bhfEoB1x; arc=none smtp.client-ip=209.85.221.47 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="bhfEoB1x" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3608e6d14b6so414560f8f.0; Sat, 15 Jun 2024 16:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493180; x=1719097980; 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=reTZJNzq8aHLKkEuuQCDgaH0V9cWHkEAk851oTzT2nY=; b=bhfEoB1xI0rlX3zgGbsBFvYvkc4SjnZkvbMDdLTb1SpNz8DM0IfVMJko6d6QYG9YMj PtViOBtmt62bGvBXQ8kvdEuy06G3Gr8bMibubnbCK8lHzM6dFwYVvr9KaH+1j/8uJaDN 2X0HaFHqjzEeTYDXAopxbgWTPH6FiYNjcM08yqDJrqVJE7NAhRKI2Qyv0sHkWacWCAdN 6YtCaaUpanQIwTasE0pqhL8YHWsxBvVXJ59V3+oArMjy1x0y3qieAklpn6tuFUX+Dfey mCKlfOKwA2L9SeMYC4qjOefdKBYcyFx+y5Y/KoqBH0WmxNmLfUXJ61ZmSb8N/wsfir5P Nc8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493180; x=1719097980; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=reTZJNzq8aHLKkEuuQCDgaH0V9cWHkEAk851oTzT2nY=; b=pPW4YfHMGUJf/SlIKfDS2JyoRB7OVsrEnTVkYDJKJe70wp6J0xSnrY2s3BsbDlj6d5 j7xSpXaHE0x50EQlhFgT4kuH4pDoBJWsrxxDxWwVD5XNh90Cv0IGcfjyPcEy1+alXcg/ Cet4RZhFZ9xdw2A4eVvbBVT3lEcvv1/5OmhoBUza1dakYTZ4I+sGYL12j/7FwoczueLT JhBy5lj/0PPk1L/YA28tADLplgctwNGH8Ut3PRYtOvXj4zqE+WfOBsgXZEaIEMq4Ubgc 0jzgz9AOCkCU5eYmScMw12R1tsDgIJovSGrMNT8mtb50QAuQZw/pGiW1LOhhlPdFOfhK G4Iw== X-Forwarded-Encrypted: i=1; AJvYcCXF8ePurPog8DR1W66Q1ELt1UNWKRX/zTVcDyXv3iACqMgiGS3MmJ06290UhD8sxn1YioI6nYWw/8Bl/0L8iLuVnYcRd7W9BoJhOrZBXw29JGfvYBOYnHE5f2JOKdfeLb3OEfaEOLq32kIPBpS0HsWR2J4RnkjORLE/5YhkqmXoLMj4vlk= X-Gm-Message-State: AOJu0Yz57mZif7/t41M0hvuAlDBoeQx7R6T/D3QlMaNDQWPxiYVq/HHT XckU86ptfys35HgyHCLkOotD3Cipwo28btTR+8uDe6HRGlUjp1XH X-Google-Smtp-Source: AGHT+IEeCYY6mdLo3thvqaP4z+4x3ehx+Uoe4ODHNCHnAV6Ez9dzMnuwjXrEVFYdz5DONT0iDjNF6A== X-Received: by 2002:a05:6000:248:b0:35f:2cd8:cb31 with SMTP id ffacd0b85a97d-3607a762d2amr4734757f8f.35.1718493180265; Sat, 15 Jun 2024 16:13:00 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.12.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:12:59 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 11/20] leds: leds-lp55xx: generalize multicolor_brightness function Date: Sun, 16 Jun 2024 01:11:41 +0200 Message-ID: <20240615231152.28201-12-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize multicolor_brightness function as the implementation is the same for most of the lp55xx based LED driver. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 21 +-------------------- drivers/leds/leds-lp5523.c | 21 +-------------------- drivers/leds/leds-lp55xx-common.c | 21 +++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 1 + 4 files changed, 24 insertions(+), 40 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index e4d0dcdbf11b..dd7e996f22f9 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -222,25 +222,6 @@ static int lp5521_run_selftest(struct lp55xx_chip *chip, char *buf) return 0; } -static int lp5521_multicolor_brightness(struct lp55xx_led *led) -{ - struct lp55xx_chip *chip = led->chip; - int ret; - int i; - - mutex_lock(&chip->lock); - for (i = 0; i < led->mc_cdev.num_colors; i++) { - ret = lp55xx_write(chip, - LP5521_REG_LED_PWM_BASE + - led->mc_cdev.subled_info[i].channel, - led->mc_cdev.subled_info[i].brightness); - if (ret) - break; - } - mutex_unlock(&chip->lock); - return ret; -} - static ssize_t show_engine_mode(struct device *dev, struct device_attribute *attr, char *buf, int nr) @@ -381,7 +362,7 @@ static struct lp55xx_device_config lp5521_cfg = { .max_channel = LP5521_MAX_LEDS, .post_init_device = lp5521_post_init_device, .brightness_fn = lp55xx_led_brightness, - .multicolor_brightness_fn = lp5521_multicolor_brightness, + .multicolor_brightness_fn = lp55xx_multicolor_brightness, .set_led_current = lp5521_set_led_current, .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp5521_run_engine, diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index a3b4063d504e..bfa0c4431ede 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -664,25 +664,6 @@ static ssize_t store_master_fader_leds(struct device *dev, return ret; } -static int lp5523_multicolor_brightness(struct lp55xx_led *led) -{ - struct lp55xx_chip *chip = led->chip; - int ret; - int i; - - mutex_lock(&chip->lock); - for (i = 0; i < led->mc_cdev.num_colors; i++) { - ret = lp55xx_write(chip, - LP5523_REG_LED_PWM_BASE + - led->mc_cdev.subled_info[i].channel, - led->mc_cdev.subled_info[i].brightness); - if (ret) - break; - } - mutex_unlock(&chip->lock); - return ret; -} - static LP55XX_DEV_ATTR_RW(engine1_mode, show_engine1_mode, store_engine1_mode); static LP55XX_DEV_ATTR_RW(engine2_mode, show_engine2_mode, store_engine2_mode); static LP55XX_DEV_ATTR_RW(engine3_mode, show_engine3_mode, store_engine3_mode); @@ -754,7 +735,7 @@ static struct lp55xx_device_config lp5523_cfg = { .max_channel = LP5523_MAX_LEDS, .post_init_device = lp5523_post_init_device, .brightness_fn = lp55xx_led_brightness, - .multicolor_brightness_fn = lp5523_multicolor_brightness, + .multicolor_brightness_fn = lp55xx_multicolor_brightness, .set_led_current = lp5523_set_led_current, .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp5523_run_engine, diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 726283f155a0..9e7c4a798687 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -256,6 +256,27 @@ int lp55xx_led_brightness(struct lp55xx_led *led) } EXPORT_SYMBOL_GPL(lp55xx_led_brightness); +int lp55xx_multicolor_brightness(struct lp55xx_led *led) +{ + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + int ret; + int i; + + mutex_lock(&chip->lock); + for (i = 0; i < led->mc_cdev.num_colors; i++) { + ret = lp55xx_write(chip, + cfg->reg_led_pwm_base.addr + + led->mc_cdev.subled_info[i].channel, + led->mc_cdev.subled_info[i].brightness); + if (ret) + break; + } + mutex_unlock(&chip->lock); + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_multicolor_brightness); + static void lp55xx_reset_device(struct lp55xx_chip *chip) { const struct lp55xx_device_config *cfg = chip->cfg; diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 4578418e5011..021dd17bc5d7 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -216,6 +216,7 @@ extern int lp55xx_update_program_memory(struct lp55xx_chip *chip, const u8 *data, size_t size); extern void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip); extern int lp55xx_led_brightness(struct lp55xx_led *led); +extern int lp55xx_multicolor_brightness(struct lp55xx_led *led); /* common probe/remove function */ extern int lp55xx_probe(struct i2c_client *client); From patchwork Sat Jun 15 23:11:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804580 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.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 AA69B69D3C; Sat, 15 Jun 2024 23:13:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493184; cv=none; b=mIf4f5QRE0YvP1lBfXrdqS+KhsY7tZU0v3vyyJXBsdLYZ4Srv7yZ+Ya9bhbz+PKUdLQxAigbcFT+eO4UguLx1ZMoHZWC8PWwzfN8S575U4xtLb3468gfChFL5dlALrNg2p8YGPNVYyhZj21zm1h15vResLq6Bp3zoHgvEqs9HVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493184; c=relaxed/simple; bh=yroiYVCG3OrL9rLeHVt+g+A3LCLonVZlQg1L6D97zTM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uV9bUMJu0DrUQjhKbn58bNzja0bq0khQzW0v0kzLb/3yK+g/iH1LaWIi+H6NE6T6Jo4zZD5R0VqqO3kDL5PWZJXbJmb30CYYFZd7CI0qku/bwf+dXlSNxWZI2NL287lDEtKuIq0uw//nn8iST8vs9Ve+YpfzoA0bRWJ5UnV/xy8= 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=IZrdJC7C; arc=none smtp.client-ip=209.85.221.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="IZrdJC7C" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-35f1c209893so3520148f8f.2; Sat, 15 Jun 2024 16:13:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493181; x=1719097981; 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=5ZlvWImeqPpjcJvX0N7IvZkD4LWa/430M0KkBEQJ84o=; b=IZrdJC7Cp+ynBOAbpPby2FdQtukaBG9HmBHCe+Zk4QLSeT5b6eOjI4KQRrj05+D6aj zM8QZxyUaYtOgxSWEq4kE2U6JaazEVwgr5QJ8lNHjlP0uklViKlQG+oqoLIwOnpVufwk 3lJuuZ4s4VAV/BxOsb5RaEsWUjShhmjM8JROCtSUUCnZSUAOIkdM+Q8ktDmJNb92U7rU FnZsEUTEH3gcFc3g0RGZjjK7rIXnT43RXFzNmCIYVIfLIBRfzTR2YDRVyh6nIK6jClvC 1HZ3Nr3gzMIqIplUfFCdlXHY62vqeIq/Lhuk7EF7vaujNir4i8SMlHIYc1FKLic73ume 48Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493181; x=1719097981; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5ZlvWImeqPpjcJvX0N7IvZkD4LWa/430M0KkBEQJ84o=; b=eZ0j94L1SnDg8TOOl/ryA/eGlCW89vc6jkYAugsmqDprR2tLDdnN0+eNrZ8x8af3cj ylFXfRORucKsXWFDvp2mPl3h5RNHBpTZTz+qnQaXywMPcMNQSb5xo9RJoKydmwLaBJjJ C0zP3Bj6NR6oHXOhRzZ/TsOJeRG2TRZyhWPDkRDv5e4JlOSMbJo5moVv0ze6WPIBqDql 94cIhid9GjN3A0we5h2gplvxXu+yZ6vVOujPr9c+Efm4SfjnEiZm0kDygGO1Nv2Sgl67 RY2hl02J2jkT2kRoZVeBV0lljwmNlGBRf0XP2WJiKaQTmBqGJwfw9NKhqB/kjXxq9m1l 4uzA== X-Forwarded-Encrypted: i=1; AJvYcCVQ6X6cBGPg1GvpLXMJ5Z0bMq3GTibKEjRjTGthNhMuszqWqwN3CwLBeqBqkH/ODE0cMk/rXRf5INDfATBLE6b+26/YK/w8WSB4PE2TsKGa3xkJrgZMM5OqVyAjKgZ5Wg6R9RqiA7jgVPtfOkOGICWix10AYvQr2fp53e3ojrILM54G4/E= X-Gm-Message-State: AOJu0YwXrszVIGMHrhnzcIg3KYKmsW8dUgh88ZVYKQ5AN4xmXUKiqI9r De8WWqvPkk+HiY9LGxGaFlBAXm8upMt1ZF8aRRs2ayRkPA61vzJZJjAnNQ== X-Google-Smtp-Source: AGHT+IFS3kmr+W04MV3qaugiybrhTsp2g+gp+bBgc6KDRWpEeH0VTXX8wa3UPa++539vCcG44887zQ== X-Received: by 2002:a5d:424d:0:b0:35f:650f:c316 with SMTP id ffacd0b85a97d-3607a768c89mr5389793f8f.41.1718493181215; Sat, 15 Jun 2024 16:13:01 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:13:00 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 12/20] leds: leds-lp55xx: generalize set_led_current function Date: Sun, 16 Jun 2024 01:11:42 +0200 Message-ID: <20240615231152.28201-13-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize set_led_current function as the implementation is the same for most of the lp55xx based LED driver. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 12 ++++-------- drivers/leds/leds-lp5523.c | 12 ++++-------- drivers/leds/leds-lp55xx-common.c | 11 +++++++++++ drivers/leds/leds-lp55xx-common.h | 3 +++ drivers/leds/leds-lp8501.c | 12 ++++-------- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index dd7e996f22f9..a1a3bf0ff703 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -108,13 +108,6 @@ static inline void lp5521_wait_enable_done(void) usleep_range(500, 600); } -static void lp5521_set_led_current(struct lp55xx_led *led, u8 led_current) -{ - led->led_current = led_current; - lp55xx_write(led->chip, LP5521_REG_LED_CURRENT_BASE + led->chan_nr, - led_current); -} - static void lp5521_stop_engine(struct lp55xx_chip *chip) { enum lp55xx_engine_index idx = chip->engine_idx; @@ -359,11 +352,14 @@ static struct lp55xx_device_config lp5521_cfg = { .reg_led_pwm_base = { .addr = LP5521_REG_LED_PWM_BASE, }, + .reg_led_current_base = { + .addr = LP5521_REG_LED_CURRENT_BASE, + }, .max_channel = LP5521_MAX_LEDS, .post_init_device = lp5521_post_init_device, .brightness_fn = lp55xx_led_brightness, .multicolor_brightness_fn = lp55xx_multicolor_brightness, - .set_led_current = lp5521_set_led_current, + .set_led_current = lp55xx_set_led_current, .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp5521_run_engine, .dev_attr_group = &lp5521_group, diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index bfa0c4431ede..3030a4495808 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -122,13 +122,6 @@ static inline void lp5523_wait_opmode_done(void) usleep_range(1000, 2000); } -static void lp5523_set_led_current(struct lp55xx_led *led, u8 led_current) -{ - led->led_current = led_current; - lp55xx_write(led->chip, LP5523_REG_LED_CURRENT_BASE + led->chan_nr, - led_current); -} - static int lp5523_post_init_device(struct lp55xx_chip *chip) { int ret; @@ -731,12 +724,15 @@ static struct lp55xx_device_config lp5523_cfg = { .reg_led_pwm_base = { .addr = LP5523_REG_LED_PWM_BASE, }, + .reg_led_current_base = { + .addr = LP5523_REG_LED_CURRENT_BASE, + }, .pages_per_engine = LP5523_PAGES_PER_ENGINE, .max_channel = LP5523_MAX_LEDS, .post_init_device = lp5523_post_init_device, .brightness_fn = lp55xx_led_brightness, .multicolor_brightness_fn = lp55xx_multicolor_brightness, - .set_led_current = lp5523_set_led_current, + .set_led_current = lp55xx_set_led_current, .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp5523_run_engine, .dev_attr_group = &lp5523_group, diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 9e7c4a798687..0d9c2990c335 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -277,6 +277,17 @@ int lp55xx_multicolor_brightness(struct lp55xx_led *led) } EXPORT_SYMBOL_GPL(lp55xx_multicolor_brightness); +void lp55xx_set_led_current(struct lp55xx_led *led, u8 led_current) +{ + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + + led->led_current = led_current; + lp55xx_write(led->chip, cfg->reg_led_current_base.addr + led->chan_nr, + led_current); +} +EXPORT_SYMBOL_GPL(lp55xx_set_led_current); + static void lp55xx_reset_device(struct lp55xx_chip *chip) { const struct lp55xx_device_config *cfg = chip->cfg; diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 021dd17bc5d7..e638049d9297 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -101,6 +101,7 @@ struct lp55xx_reg { * @enable : Chip specific enable command * @prog_mem_base : Chip specific base reg address for chip SMEM programming * @reg_led_pwm_base : Chip specific base reg address for LED PWM conf + * @reg_led_current_base : Chip specific base reg address for LED current conf * @pages_per_engine : Assigned pages for each engine * (if not set chip doesn't support pages) * @max_channel : Maximum number of channels @@ -120,6 +121,7 @@ struct lp55xx_device_config { const struct lp55xx_reg enable; const struct lp55xx_reg prog_mem_base; const struct lp55xx_reg reg_led_pwm_base; + const struct lp55xx_reg reg_led_current_base; const int pages_per_engine; const int max_channel; @@ -217,6 +219,7 @@ extern int lp55xx_update_program_memory(struct lp55xx_chip *chip, extern void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip); extern int lp55xx_led_brightness(struct lp55xx_led *led); extern int lp55xx_multicolor_brightness(struct lp55xx_led *led); +extern void lp55xx_set_led_current(struct lp55xx_led *led, u8 led_current); /* common probe/remove function */ extern int lp55xx_probe(struct i2c_client *client); diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c index 8f1fd9525e9a..d924572e4533 100644 --- a/drivers/leds/leds-lp8501.c +++ b/drivers/leds/leds-lp8501.c @@ -84,13 +84,6 @@ static inline void lp8501_wait_opmode_done(void) usleep_range(1000, 2000); } -static void lp8501_set_led_current(struct lp55xx_led *led, u8 led_current) -{ - led->led_current = led_current; - lp55xx_write(led->chip, LP8501_REG_LED_CURRENT_BASE + led->chan_nr, - led_current); -} - static int lp8501_post_init_device(struct lp55xx_chip *chip) { int ret; @@ -163,11 +156,14 @@ static struct lp55xx_device_config lp8501_cfg = { .reg_led_pwm_base = { .addr = LP8501_REG_LED_PWM_BASE, }, + .reg_led_current_base = { + .addr = LP8501_REG_LED_CURRENT_BASE, + }, .pages_per_engine = LP8501_PAGES_PER_ENGINE, .max_channel = LP8501_MAX_LEDS, .post_init_device = lp8501_post_init_device, .brightness_fn = lp55xx_led_brightness, - .set_led_current = lp8501_set_led_current, + .set_led_current = lp55xx_set_led_current, .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp8501_run_engine, }; From patchwork Sat Jun 15 23:11:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805054 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA533139D05; Sat, 15 Jun 2024 23:13:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493185; cv=none; b=rEdLL0WSptWZxb+Q8GjEJjBvkRFpJwVP3CEu8SKM01oWmWyau5Y0pj9CnQ1TK7iCVklbiU9i5l8cPtUDOnHNiwujd8TuGZM1QqasEed05dCO3oDs/aWYN/oHoSxbiH4TESH4MKI/Vhf/feQZFvaxhywVPGPklk9wAhApoF109xM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493185; c=relaxed/simple; bh=jrUwrkPYp4hCHlkd6P6OYbxXe4swsLYG9zbBf4AA20s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mph8baFKeIAKqbGwob6OWlUZjKneh4Jjyd9XXCJ/obmRovCk/i2K/gEPyqM8nAiv2ez3uY9/J0Fsxop0up/UK7C5+QDJpMTTT1m/lHgdRim3cCpvmJUtIMzrLS5PdSDT2Qc3rpIDR2jyi1PFy+q3BCcbThbdXl9Xl2Ts7urt/4o= 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=CiQz/KFH; arc=none smtp.client-ip=209.85.221.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="CiQz/KFH" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-35f2c0b7701so1878081f8f.0; Sat, 15 Jun 2024 16:13:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493182; x=1719097982; 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=TJT+GSRKfcK8dGlTgwx48L15a3Q2jtdAFK5lJ52goD4=; b=CiQz/KFHpvhE2kjEiJcNdSKXlqAS3l1iMWdfX+9t0k00luF3bC2Bu3BhBeBJ78JBdo F+g4BIgnGNuBXe41B6VaIOG7tsB69DImW+gjoJWB7x/eBnhr9Jt6BcfRgJnNOqtDMEYF Jg7GntwciGaCAD1Tey9n8W/KYa+gLY12aNM1hZ0noavzWb8zgPfUXnAx16B9G+7g1wt9 5lA93yJ1yQdLrdF/J19N9TuWdddZWH6/EFqpFIp8PO+yYpCHCpZYWDI4ydXWbEQ7/Hbb MtNVgP8HBdu0Gdg1I96WMEG/tEnAB22NHe2iMnoE2+HyzOASL4HnkGk7HgAzcYL/WtVl GYTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493182; x=1719097982; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TJT+GSRKfcK8dGlTgwx48L15a3Q2jtdAFK5lJ52goD4=; b=aikZR5yWcCXls/BfvpQnVyQnRzjdaRHdeLEs/R4f1F/DljJpCqOs7ctI2VS0qB7C0H KKshST/FMSPwqDt2jDxYwAQGwERGYv7hHKVavFfNjsIVEh5lJAIeBoMVQ2DTWUYee3wa gski0yk8rA/gjO1NWVotAOOYQtyjnxgBX1z+IL9aNVWjxIZn8RizfF9WdmJW24MaAMwr IZqj76pq71KX/dGECJ7Geobajl2Ixm9vxRZbjNVOgAlX2LIeZCWFUx+ewoQIqK+9E6Mp xOIhzJzWu7PePv+t6wXlxM7Ms7foqfCmVacGeFSt6nwy1K9qMSWabgg6nZcmvPvXO/gu dTMA== X-Forwarded-Encrypted: i=1; AJvYcCWe1bcSUzIOTIKsGV1DMDrA6r86D5a61Oy19dwLP/CM39gy2Q3581tL9IsafJNa4VZvD4G2szYHigqTYfsH9CNX0CFdjAcaMTi83AiEq5q0JS+kt/PeiD3scpPXXbTwQOc5a32P5+QqrydeA1O9dYN6TBwoFiDLKJ+Z/fjEKPn0xhXqa14= X-Gm-Message-State: AOJu0YyR/He5xf6rmfZyzooGOXl608EGzQuWU+F4Y5ajjWYnQ4eB/vTR oOJFBEnsrXu6A8LL1X0PkL73yI/ev3MzY92k91zqqUFISd+9QQy1 X-Google-Smtp-Source: AGHT+IHOACnByiXh6AMFMUrwSyBl501NtFDMCPKG6jaIGE0uKoJkcJqd3dkgs0PM0w/ZFFMSL0rzHg== X-Received: by 2002:adf:f14a:0:b0:360:8d70:d368 with SMTP id ffacd0b85a97d-3608d70d391mr2482228f8f.29.1718493182241; Sat, 15 Jun 2024 16:13:02 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:13:01 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 13/20] leds: leds-lp55xx: generalize turn_off_channels function Date: Sun, 16 Jun 2024 01:11:43 +0200 Message-ID: <20240615231152.28201-14-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize turn_off_channels function as the implementation is the same for most of the lp55xx based LED driver. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5523.c | 10 +--------- drivers/leds/leds-lp55xx-common.c | 10 ++++++++++ drivers/leds/leds-lp55xx-common.h | 1 + drivers/leds/leds-lp8501.c | 10 +--------- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 3030a4495808..4a4463cb44a4 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -167,20 +167,12 @@ static void lp5523_stop_engine(struct lp55xx_chip *chip) lp5523_wait_opmode_done(); } -static void lp5523_turn_off_channels(struct lp55xx_chip *chip) -{ - int i; - - for (i = 0; i < LP5523_MAX_LEDS; i++) - lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + i, 0); -} - static void lp5523_run_engine(struct lp55xx_chip *chip, bool start) { /* stop engine */ if (!start) { lp5523_stop_engine(chip); - lp5523_turn_off_channels(chip); + lp55xx_turn_off_channels(chip); return; } diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 0d9c2990c335..028a485d3561 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -288,6 +288,16 @@ void lp55xx_set_led_current(struct lp55xx_led *led, u8 led_current) } EXPORT_SYMBOL_GPL(lp55xx_set_led_current); +void lp55xx_turn_off_channels(struct lp55xx_chip *chip) +{ + const struct lp55xx_device_config *cfg = chip->cfg; + int i; + + for (i = 0; i < cfg->max_channel; i++) + lp55xx_write(chip, cfg->reg_led_pwm_base.addr + i, 0); +} +EXPORT_SYMBOL_GPL(lp55xx_turn_off_channels); + static void lp55xx_reset_device(struct lp55xx_chip *chip) { const struct lp55xx_device_config *cfg = chip->cfg; diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index e638049d9297..531fbb0acb2e 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -220,6 +220,7 @@ extern void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip); extern int lp55xx_led_brightness(struct lp55xx_led *led); extern int lp55xx_multicolor_brightness(struct lp55xx_led *led); extern void lp55xx_set_led_current(struct lp55xx_led *led, u8 led_current); +extern void lp55xx_turn_off_channels(struct lp55xx_chip *chip); /* common probe/remove function */ extern int lp55xx_probe(struct i2c_client *client); diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c index d924572e4533..1fb876f64cb7 100644 --- a/drivers/leds/leds-lp8501.c +++ b/drivers/leds/leds-lp8501.c @@ -110,20 +110,12 @@ static int lp8501_post_init_device(struct lp55xx_chip *chip) LP8501_PWR_CONFIG_M, chip->pdata->pwr_sel); } -static void lp8501_turn_off_channels(struct lp55xx_chip *chip) -{ - int i; - - for (i = 0; i < LP8501_MAX_LEDS; i++) - lp55xx_write(chip, LP8501_REG_LED_PWM_BASE + i, 0); -} - static void lp8501_run_engine(struct lp55xx_chip *chip, bool start) { /* stop engine */ if (!start) { lp55xx_stop_all_engine(chip); - lp8501_turn_off_channels(chip); + lp55xx_turn_off_channels(chip); return; } From patchwork Sat Jun 15 23:11:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804579 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDA3B13A3E7; Sat, 15 Jun 2024 23:13:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493186; cv=none; b=ZmH2BKpaehR2Vjh6Vs4H5HJWDhEkO3zm8SgDElhxNZz772FVi+HKo3BIROUJmAnWhImsQFPHH0MIb05nLQkza7iqYZrsJj8ocTQRq+MdxkhbqtYT2tsE/ZOzG4k0abAtO+DxXi7ULVps1nIUB387BEYw6ZKptJSROmpO8Y9JYz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493186; c=relaxed/simple; bh=+7IjSR/kqGIvv4H3fDY0x3wGXGdPGipVLZxe/zr7DoQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NUA5KWggTIKXyR3Wj+PljK4qHUDhwpFoUk7SyZKs4tcdD3vB9Ml+EEmp/+qxqziGm7gei/PdnHp9x/pqj5LfSfuhtznf6XuxUa56ESdCa/ouQlBu41hwDAFDFp7BcqO1nszUfqbFgwBVRy2GQ5xyEJVgUvlfzLuyWiNJlE73Hks= 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=ItZa8Svw; arc=none smtp.client-ip=209.85.221.44 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="ItZa8Svw" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-35dc1d8867eso2683096f8f.0; Sat, 15 Jun 2024 16:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493183; x=1719097983; 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=YPWkWTvKJqfRuDQmtB8UvlJrzwDG/2gWSmvAtvh8RdA=; b=ItZa8SvwwM13qZUpX627ZMTT36I8tgALS6JIkxLOg4tUd0sxklN0hbkjSoxuUPBDwx LvZNXFUiW24fqElIiGxMvSh2EROoGIEG7ebpFRPSjcc5ga0cbq9WKjkn959CV8xlfLim qeN4anmG/ssx7RUYn715sRG7MowV/DMhs+Ku0tKTN8v436ygZ+EtJw7KtxXwroJvJmnO T9Cl7WqJd1sfsDbAfT5TGKmvPERn1M0NYyKXAUJH/+I2WVBkqmLjkwLhQqSU3+8I57Xc acT17dn6UZzeQujIXVOjXOhfsIt2WI5d+GMfNYEsozL385OhCJE0YNNZEWgUb3nhxwSS TtIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493183; x=1719097983; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YPWkWTvKJqfRuDQmtB8UvlJrzwDG/2gWSmvAtvh8RdA=; b=mS7KeNsZM1qfh9vCeKz0nlRjK84WUxTp3KMqxxvGxcPdo++XrH/OXtr/1bjNhM6iMH pqR8ImSGuGGLCq+mrPgyGcmwgV0uaEBEQ8vg6aD/Hjq3K9E2/x1BQLrkAs+A4nKTWqWo YF7ek8zjBdJuj+vE5ANYEmk00MGnWCA3QN00msM6u3uaX+zgUkfsE9N6P+yoJES6xz5X XBkR/+HeOwfuk7Rj+fqA/ZNBX6fgPES68lvWK5rdm9381h93TjU78pzqJMhWomtbpf56 pNVsTnddHU+4RCZT8rFO8ugMVCSk2Rgg/Evme4C6Fx2Zn7ydLyo4p4WENbOzU9hU9wxU mduw== X-Forwarded-Encrypted: i=1; AJvYcCXztPklq0z+RAYHdNBOyFUTOeQb1uyaKDrwtDmAfkrv79JBIgw4wGRWHkmfpjrOfSgF+rbBTtXYxH3wenqUsnjqwMXpiG+OCQvojBLWmsj9AKyeX+LDIgmRteUn/PusTEhHNqkXGZvZSGktvRjCPJ+A+rnqY6tsfaAwqpJTDRhFROMsWCE= X-Gm-Message-State: AOJu0YyK2QwCwbC0ODKlA0gQjd18gBYyeahsdh0mQXtZcHwacl2Gno+D +IerdN2fApTEyp3e5SJIOfGO/DJVSkyKtgmbCXj0Cv2zOgUhUWgUEf0Lgw== X-Google-Smtp-Source: AGHT+IHd8c7kQFNa8jP9GcXZWb7yTpIbNIGJIZkLgnAd58fzdHo9dXUcoPjoEe4jb+UFwN1on0QIQg== X-Received: by 2002:a05:6000:5:b0:35f:2614:4be7 with SMTP id ffacd0b85a97d-3607a76b77emr3729352f8f.37.1718493183152; Sat, 15 Jun 2024 16:13:03 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:13:02 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 14/20] leds: leds-lp55xx: generalize stop_engine function Date: Sun, 16 Jun 2024 01:11:44 +0200 Message-ID: <20240615231152.28201-15-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize stop_engine function as the implementation is the same for most of the lp55xx based LED driver. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 20 +++----------------- drivers/leds/leds-lp5523.c | 20 +++----------------- drivers/leds/leds-lp55xx-common.c | 13 +++++++++++++ drivers/leds/leds-lp55xx-common.h | 1 + 4 files changed, 20 insertions(+), 34 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index a1a3bf0ff703..4afae0c70d19 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -108,27 +108,13 @@ static inline void lp5521_wait_enable_done(void) usleep_range(500, 600); } -static void lp5521_stop_engine(struct lp55xx_chip *chip) -{ - enum lp55xx_engine_index idx = chip->engine_idx; - static const u8 mask[] = { - [LP55XX_ENGINE_1] = LP5521_MODE_R_M, - [LP55XX_ENGINE_2] = LP5521_MODE_G_M, - [LP55XX_ENGINE_3] = LP5521_MODE_B_M, - }; - - lp55xx_update_bits(chip, LP5521_REG_OP_MODE, mask[idx], 0); - - lp5521_wait_opmode_done(); -} - static void lp5521_run_engine(struct lp55xx_chip *chip, bool start) { int ret; /* stop engine */ if (!start) { - lp5521_stop_engine(chip); + lp55xx_stop_engine(chip); lp55xx_write(chip, LP5521_REG_OP_MODE, LP5521_CMD_DIRECT); lp5521_wait_opmode_done(); return; @@ -253,11 +239,11 @@ static ssize_t store_engine_mode(struct device *dev, lp5521_run_engine(chip, true); engine->mode = LP55XX_ENGINE_RUN; } else if (!strncmp(buf, "load", 4)) { - lp5521_stop_engine(chip); + lp55xx_stop_engine(chip); lp55xx_load_engine(chip); engine->mode = LP55XX_ENGINE_LOAD; } else if (!strncmp(buf, "disabled", 8)) { - lp5521_stop_engine(chip); + lp55xx_stop_engine(chip); engine->mode = LP55XX_ENGINE_DISABLED; } diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 4a4463cb44a4..1dd909a0fff5 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -153,25 +153,11 @@ static int lp5523_post_init_device(struct lp55xx_chip *chip) return lp5523_init_program_engine(chip); } -static void lp5523_stop_engine(struct lp55xx_chip *chip) -{ - enum lp55xx_engine_index idx = chip->engine_idx; - static const u8 mask[] = { - [LP55XX_ENGINE_1] = LP5523_MODE_ENG1_M, - [LP55XX_ENGINE_2] = LP5523_MODE_ENG2_M, - [LP55XX_ENGINE_3] = LP5523_MODE_ENG3_M, - }; - - lp55xx_update_bits(chip, LP5523_REG_OP_MODE, mask[idx], 0); - - lp5523_wait_opmode_done(); -} - static void lp5523_run_engine(struct lp55xx_chip *chip, bool start) { /* stop engine */ if (!start) { - lp5523_stop_engine(chip); + lp55xx_stop_engine(chip); lp55xx_turn_off_channels(chip); return; } @@ -277,11 +263,11 @@ static ssize_t store_engine_mode(struct device *dev, lp5523_run_engine(chip, true); engine->mode = LP55XX_ENGINE_RUN; } else if (!strncmp(buf, "load", 4)) { - lp5523_stop_engine(chip); + lp55xx_stop_engine(chip); lp55xx_load_engine(chip); engine->mode = LP55XX_ENGINE_LOAD; } else if (!strncmp(buf, "disabled", 8)) { - lp5523_stop_engine(chip); + lp55xx_stop_engine(chip); engine->mode = LP55XX_ENGINE_DISABLED; } diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 028a485d3561..46b1eb1ce775 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -298,6 +298,19 @@ void lp55xx_turn_off_channels(struct lp55xx_chip *chip) } EXPORT_SYMBOL_GPL(lp55xx_turn_off_channels); +void lp55xx_stop_engine(struct lp55xx_chip *chip) +{ + enum lp55xx_engine_index idx = chip->engine_idx; + const struct lp55xx_device_config *cfg = chip->cfg; + u8 mask; + + mask = LP55xx_MODE_ENGn_MASK(idx, cfg->reg_op_mode.shift); + lp55xx_update_bits(chip, cfg->reg_op_mode.addr, mask, 0); + + lp55xx_wait_opmode_done(chip); +} +EXPORT_SYMBOL_GPL(lp55xx_stop_engine); + static void lp55xx_reset_device(struct lp55xx_chip *chip) { const struct lp55xx_device_config *cfg = chip->cfg; diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 531fbb0acb2e..0aba6955a3af 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -221,6 +221,7 @@ extern int lp55xx_led_brightness(struct lp55xx_led *led); extern int lp55xx_multicolor_brightness(struct lp55xx_led *led); extern void lp55xx_set_led_current(struct lp55xx_led *led, u8 led_current); extern void lp55xx_turn_off_channels(struct lp55xx_chip *chip); +extern void lp55xx_stop_engine(struct lp55xx_chip *chip); /* common probe/remove function */ extern int lp55xx_probe(struct i2c_client *client); From patchwork Sat Jun 15 23:11:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805053 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.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 C824213A86C; Sat, 15 Jun 2024 23:13:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493188; cv=none; b=pKLlzYB2gUvzpCfy/4rE0Cr4cRMr/Ji9ishqS1IM3uxKKuVJRnh+m939yWcYkOlppWFJ2VLSkT19KIyK9uSvMH8FIwt2K6nwR7wbX2DDI9zGaxrdJlvJsA3Xg0/jkZXKsk8DPCYTBkuEeg0lJ+PQCkKKjbDtTPWY6UrNDxAtRbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493188; c=relaxed/simple; bh=eDCzwNIT591azxhv6PXsf1s5SvTRycO5Fm/oFIO5rU4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FEDtlHpFqo0V9wPR+hufNZ9H+2T+/RfntaYn+ZgkPjYE1dHUyR6ndxIhdJ5gOKm9myMC2yeky7Et0N/BtREa+/Dn74HufrbVL/d8l78dvJwjN/2+Totib4xanB4OLtqM0bCG14FnX3LG5DHjQcdtCCDV0ndcWMLcl5C+MtLJxCE= 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=KOCVOua7; arc=none smtp.client-ip=209.85.221.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="KOCVOua7" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3608e6d14b6so414578f8f.0; Sat, 15 Jun 2024 16:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493184; x=1719097984; 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=rg5TqlrNR+nh/4AugtVKGL98AXuwEC87Lj9NvCDOYXs=; b=KOCVOua7CrJxuUZpNxbWxeKPRjOvTNXMKH5kEM1oo/6LKKYuYdvaF2Zi/uGtnT5F0U EyAG41ZIxIcW8jQ7C8CqpupUR1/KCyITOz5I0LHTl+76+4ApJBGrgrvkf/8/A803Px1f fUJorfe7ge7CKj4OK5iZznvTbKOToGi3upenQzwNeDSHnkavbv5YZZCaGyO/qgs4lXw/ zbiepyvpigA+mYtnCmENt4Pksaz4KIPJZZ7mYyJlJ5xqReU05WELFK8eNDilR/wW+MPV 6Vz0kb30840KWF47BIPaILiOsVNSX2uaEVl++n6HPVPag4rhP/LlB4KImc34hdqZvFq4 xAVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493184; x=1719097984; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rg5TqlrNR+nh/4AugtVKGL98AXuwEC87Lj9NvCDOYXs=; b=pFm3j4TRwmZkcYibHxYhbQbWpHtX9f1Um5tK7biK1I3FulE/y+gnlbnEudRHlBn452 dTlUlJZNRv7gVMS5KXV2A2enQFHuVE31O27Mf7ki4quHYsq7PHLwyvs0PtT+68TLYt0A MI6fBAmIPLbHWmYLjjGIHP08idMyzYjeifZZhoYVUObyxf3miq/ROUI8wNtO0k9RtKfW CIkf7ZpwX0NkJJzpi8V0bvrm5O0vLH0KvKxC+U1P1NM5WZldz9NYsdWh/nDmq7kEKUSK flQPC0mBx0bvlNH2eYcHrMI+fu8mUzMickgu97kG6Mvm3EnWByt8QIljUCDcBgiwtWlZ 8SoQ== X-Forwarded-Encrypted: i=1; AJvYcCVPTnkXWvJhnR8X/5FDHxlxyCakrndc5TIRrqKc//+aNab1YVfOAq/MQaiRxjphQejI0S9ZEXPNFV0ndimg14MSjSYH6xjI3ZbBR24dsMVE+iNnEhW62ubJEQl8BY8TkCWDodM+3MiENE6PNCUjcOZNBzxeVIrGvWsyx+3C71sDN49b8pI= X-Gm-Message-State: AOJu0YyC+2oBnBcTizJtrao6LPOtYW9ExoUnc8VmsigfvyUgeaF/nCmb Pwv99dAzYqaakMJaRKLFzFl0j7/xbEKFDpNKPP9kMcVSzQY/B4wk X-Google-Smtp-Source: AGHT+IELWRWUvbB66aD9Fsh2nj6tetnWGSH7UB29glV/DBq4kpDnwTHRB8KizmjUwy2/k6xYTGjyUw== X-Received: by 2002:a05:6000:2aa:b0:360:73f4:9f19 with SMTP id ffacd0b85a97d-3607a77f9efmr5500063f8f.50.1718493184134; Sat, 15 Jun 2024 16:13:04 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.13.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:13:03 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 15/20] leds: leds-lp55xx: generalize sysfs engine_load and engine_mode Date: Sun, 16 Jun 2024 01:11:45 +0200 Message-ID: <20240615231152.28201-16-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize sysfs engine_load and engine_mode since their implementation is the same acrosso some lp55xx based LED driver. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 88 +++---------------------------- drivers/leds/leds-lp5523.c | 88 +++---------------------------- drivers/leds/leds-lp55xx-common.c | 83 ++++++++++++++++++++++++++--- drivers/leds/leds-lp55xx-common.h | 26 +++++++-- 4 files changed, 112 insertions(+), 173 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 4afae0c70d19..519e7627ac22 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -201,82 +201,6 @@ static int lp5521_run_selftest(struct lp55xx_chip *chip, char *buf) return 0; } -static ssize_t show_engine_mode(struct device *dev, - struct device_attribute *attr, - char *buf, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - enum lp55xx_engine_mode mode = chip->engines[nr - 1].mode; - - switch (mode) { - case LP55XX_ENGINE_RUN: - return sprintf(buf, "run\n"); - case LP55XX_ENGINE_LOAD: - return sprintf(buf, "load\n"); - case LP55XX_ENGINE_DISABLED: - default: - return sprintf(buf, "disabled\n"); - } -} -show_mode(1) -show_mode(2) -show_mode(3) - -static ssize_t store_engine_mode(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - struct lp55xx_engine *engine = &chip->engines[nr - 1]; - - mutex_lock(&chip->lock); - - chip->engine_idx = nr; - - if (!strncmp(buf, "run", 3)) { - lp5521_run_engine(chip, true); - engine->mode = LP55XX_ENGINE_RUN; - } else if (!strncmp(buf, "load", 4)) { - lp55xx_stop_engine(chip); - lp55xx_load_engine(chip); - engine->mode = LP55XX_ENGINE_LOAD; - } else if (!strncmp(buf, "disabled", 8)) { - lp55xx_stop_engine(chip); - engine->mode = LP55XX_ENGINE_DISABLED; - } - - mutex_unlock(&chip->lock); - - return len; -} -store_mode(1) -store_mode(2) -store_mode(3) - -static ssize_t store_engine_load(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - int ret; - - mutex_lock(&chip->lock); - - chip->engine_idx = nr; - lp55xx_load_engine(chip); - ret = lp55xx_update_program_memory(chip, buf, len); - - mutex_unlock(&chip->lock); - - return ret; -} -store_load(1) -store_load(2) -store_load(3) - static ssize_t lp5521_selftest(struct device *dev, struct device_attribute *attr, char *buf) @@ -293,12 +217,12 @@ static ssize_t lp5521_selftest(struct device *dev, } /* device attributes */ -static LP55XX_DEV_ATTR_RW(engine1_mode, show_engine1_mode, store_engine1_mode); -static LP55XX_DEV_ATTR_RW(engine2_mode, show_engine2_mode, store_engine2_mode); -static LP55XX_DEV_ATTR_RW(engine3_mode, show_engine3_mode, store_engine3_mode); -static LP55XX_DEV_ATTR_WO(engine1_load, store_engine1_load); -static LP55XX_DEV_ATTR_WO(engine2_load, store_engine2_load); -static LP55XX_DEV_ATTR_WO(engine3_load, store_engine3_load); +LP55XX_DEV_ATTR_ENGINE_MODE(1); +LP55XX_DEV_ATTR_ENGINE_MODE(2); +LP55XX_DEV_ATTR_ENGINE_MODE(3); +LP55XX_DEV_ATTR_ENGINE_LOAD(1); +LP55XX_DEV_ATTR_ENGINE_LOAD(2); +LP55XX_DEV_ATTR_ENGINE_LOAD(3); static LP55XX_DEV_ATTR_RO(selftest, lp5521_selftest); static struct attribute *lp5521_attributes[] = { diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 1dd909a0fff5..19b119a2b256 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -225,60 +225,6 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) return ret; } -static ssize_t show_engine_mode(struct device *dev, - struct device_attribute *attr, - char *buf, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - enum lp55xx_engine_mode mode = chip->engines[nr - 1].mode; - - switch (mode) { - case LP55XX_ENGINE_RUN: - return sprintf(buf, "run\n"); - case LP55XX_ENGINE_LOAD: - return sprintf(buf, "load\n"); - case LP55XX_ENGINE_DISABLED: - default: - return sprintf(buf, "disabled\n"); - } -} -show_mode(1) -show_mode(2) -show_mode(3) - -static ssize_t store_engine_mode(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - struct lp55xx_engine *engine = &chip->engines[nr - 1]; - - mutex_lock(&chip->lock); - - chip->engine_idx = nr; - - if (!strncmp(buf, "run", 3)) { - lp5523_run_engine(chip, true); - engine->mode = LP55XX_ENGINE_RUN; - } else if (!strncmp(buf, "load", 4)) { - lp55xx_stop_engine(chip); - lp55xx_load_engine(chip); - engine->mode = LP55XX_ENGINE_LOAD; - } else if (!strncmp(buf, "disabled", 8)) { - lp55xx_stop_engine(chip); - engine->mode = LP55XX_ENGINE_DISABLED; - } - - mutex_unlock(&chip->lock); - - return len; -} -store_mode(1) -store_mode(2) -store_mode(3) - static int lp5523_mux_parse(const char *buf, u16 *mux, size_t len) { u16 tmp_mux = 0; @@ -392,28 +338,6 @@ store_leds(1) store_leds(2) store_leds(3) -static ssize_t store_engine_load(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - int ret; - - mutex_lock(&chip->lock); - - chip->engine_idx = nr; - lp55xx_load_engine(chip); - ret = lp55xx_update_program_memory(chip, buf, len); - - mutex_unlock(&chip->lock); - - return ret; -} -store_load(1) -store_load(2) -store_load(3) - static ssize_t lp5523_selftest(struct device *dev, struct device_attribute *attr, char *buf) @@ -635,15 +559,15 @@ static ssize_t store_master_fader_leds(struct device *dev, return ret; } -static LP55XX_DEV_ATTR_RW(engine1_mode, show_engine1_mode, store_engine1_mode); -static LP55XX_DEV_ATTR_RW(engine2_mode, show_engine2_mode, store_engine2_mode); -static LP55XX_DEV_ATTR_RW(engine3_mode, show_engine3_mode, store_engine3_mode); +LP55XX_DEV_ATTR_ENGINE_MODE(1); +LP55XX_DEV_ATTR_ENGINE_MODE(2); +LP55XX_DEV_ATTR_ENGINE_MODE(3); static LP55XX_DEV_ATTR_RW(engine1_leds, show_engine1_leds, store_engine1_leds); static LP55XX_DEV_ATTR_RW(engine2_leds, show_engine2_leds, store_engine2_leds); static LP55XX_DEV_ATTR_RW(engine3_leds, show_engine3_leds, store_engine3_leds); -static LP55XX_DEV_ATTR_WO(engine1_load, store_engine1_load); -static LP55XX_DEV_ATTR_WO(engine2_load, store_engine2_load); -static LP55XX_DEV_ATTR_WO(engine3_load, store_engine3_load); +LP55XX_DEV_ATTR_ENGINE_LOAD(1); +LP55XX_DEV_ATTR_ENGINE_LOAD(2); +LP55XX_DEV_ATTR_ENGINE_LOAD(3); static LP55XX_DEV_ATTR_RO(selftest, lp5523_selftest); static LP55XX_DEV_ATTR_RW(master_fader1, show_master_fader1, store_master_fader1); diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 46b1eb1ce775..1a23352c9850 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -541,8 +541,8 @@ static int lp55xx_request_firmware(struct lp55xx_chip *chip) } static ssize_t select_engine_show(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); struct lp55xx_chip *chip = led->chip; @@ -551,8 +551,8 @@ static ssize_t select_engine_show(struct device *dev, } static ssize_t select_engine_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) + struct device_attribute *attr, + const char *buf, size_t len) { struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); struct lp55xx_chip *chip = led->chip; @@ -593,8 +593,8 @@ static inline void lp55xx_run_engine(struct lp55xx_chip *chip, bool start) } static ssize_t run_engine_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) + struct device_attribute *attr, + const char *buf, size_t len) { struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); struct lp55xx_chip *chip = led->chip; @@ -620,6 +620,77 @@ static ssize_t run_engine_store(struct device *dev, static DEVICE_ATTR_RW(select_engine); static DEVICE_ATTR_WO(run_engine); +ssize_t lp55xx_show_engine_mode(struct device *dev, + struct device_attribute *attr, + char *buf, int nr) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + enum lp55xx_engine_mode mode = chip->engines[nr - 1].mode; + + switch (mode) { + case LP55XX_ENGINE_RUN: + return sprintf(buf, "run\n"); + case LP55XX_ENGINE_LOAD: + return sprintf(buf, "load\n"); + case LP55XX_ENGINE_DISABLED: + default: + return sprintf(buf, "disabled\n"); + } +} +EXPORT_SYMBOL_GPL(lp55xx_show_engine_mode); + +ssize_t lp55xx_store_engine_mode(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + struct lp55xx_engine *engine = &chip->engines[nr - 1]; + + mutex_lock(&chip->lock); + + chip->engine_idx = nr; + + if (!strncmp(buf, "run", 3)) { + cfg->run_engine(chip, true); + engine->mode = LP55XX_ENGINE_RUN; + } else if (!strncmp(buf, "load", 4)) { + lp55xx_stop_engine(chip); + lp55xx_load_engine(chip); + engine->mode = LP55XX_ENGINE_LOAD; + } else if (!strncmp(buf, "disabled", 8)) { + lp55xx_stop_engine(chip); + engine->mode = LP55XX_ENGINE_DISABLED; + } + + mutex_unlock(&chip->lock); + + return len; +} +EXPORT_SYMBOL_GPL(lp55xx_store_engine_mode); + +ssize_t lp55xx_store_engine_load(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + int ret; + + mutex_lock(&chip->lock); + + chip->engine_idx = nr; + lp55xx_load_engine(chip); + ret = lp55xx_update_program_memory(chip, buf, len); + + mutex_unlock(&chip->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_store_engine_load); + static struct attribute *lp55xx_engine_attributes[] = { &dev_attr_select_engine.attr, &dev_attr_run_engine.attr, diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 0aba6955a3af..00d16a86b750 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -40,7 +40,7 @@ static ssize_t show_engine##nr##_mode(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ { \ - return show_engine_mode(dev, attr, buf, nr); \ + return lp55xx_show_engine_mode(dev, attr, buf, nr); \ } #define store_mode(nr) \ @@ -48,9 +48,14 @@ static ssize_t store_engine##nr##_mode(struct device *dev, \ struct device_attribute *attr, \ const char *buf, size_t len) \ { \ - return store_engine_mode(dev, attr, buf, len, nr); \ + return lp55xx_store_engine_mode(dev, attr, buf, len, nr); \ } +#define LP55XX_DEV_ATTR_ENGINE_MODE(nr) \ + show_mode(nr) \ + store_mode(nr) \ + static LP55XX_DEV_ATTR_RW(engine##nr##_mode, show_engine##nr##_mode, store_engine##nr##_mode) + #define show_leds(nr) \ static ssize_t show_engine##nr##_leds(struct device *dev, \ struct device_attribute *attr, \ @@ -72,9 +77,13 @@ static ssize_t store_engine##nr##_load(struct device *dev, \ struct device_attribute *attr, \ const char *buf, size_t len) \ { \ - return store_engine_load(dev, attr, buf, len, nr); \ + return lp55xx_store_engine_load(dev, attr, buf, len, nr); \ } +#define LP55XX_DEV_ATTR_ENGINE_LOAD(nr) \ + store_load(nr) \ + static LP55XX_DEV_ATTR_WO(engine##nr##_load, store_engine##nr##_load) + struct lp55xx_led; struct lp55xx_chip; @@ -227,4 +236,15 @@ extern void lp55xx_stop_engine(struct lp55xx_chip *chip); extern int lp55xx_probe(struct i2c_client *client); extern void lp55xx_remove(struct i2c_client *client); +/* common sysfs function */ +extern ssize_t lp55xx_show_engine_mode(struct device *dev, + struct device_attribute *attr, + char *buf, int nr); +extern ssize_t lp55xx_store_engine_mode(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr); +extern ssize_t lp55xx_store_engine_load(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr); + #endif /* _LEDS_LP55XX_COMMON_H */ From patchwork Sat Jun 15 23:11:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804578 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 DFD5B13AA51; Sat, 15 Jun 2024 23:13:06 +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=1718493189; cv=none; b=uJtlu/ZeoRp0ck/j4Oas8PRPoKVsbZO4X4372xV29XlhrJndqhHSXQk/ywyX+GSZUwDbb1mlGozJc5KjLpActzZEK7sC5EPzuw0Ud4qpQwXLcSNpcosTjwhRM4L1NXOYh8vnUHLTR00zvnSL4UjEOGyvbVWNJ8jYWAqpM9NDEXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493189; c=relaxed/simple; bh=s+Xy1QEPPUf4SIg0wEw2U1aiJooBNiy7cynH6Fvn1gE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kUzCLqtIeQJtQEXs62w3v7duMz2WNiTeWFKoe4K6gXvflzatx0M1G2A6ttse3sozFvDhrcuQNrJNtfsVHdcLi8Wiek1PoqRBADG83wCnOIM6ZQEPmBb/ZxLo7MJ38KZuxvGolo4KwUSXhFSEPXf60xs2pkSdpHQzGRZ9mFt22y4= 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=TNRzLlTd; 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="TNRzLlTd" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-42172ed3487so25028705e9.0; Sat, 15 Jun 2024 16:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493185; x=1719097985; 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=HvDbI2xilT38vRdpEN0TMS7XC7ztBOK0klqpk68uRTQ=; b=TNRzLlTdJYtQwSA0d24QqiLf5779LEUrzKKeA0Ph5rW7hKgd0qjDkiYCsg5Jxl6Mjz mWMqVouSbmh+EWCDX0Z5p2kRqwbnR/K4E96BwotJAZxqqJJCNVqxkzSH+Hu7t8PrSSj3 9of1YqbsH00PPW6mnG7Bvrfi/xqjaHtzlAl1dUxYT0ps5H3X6Krk9L3vb0xbjLvYuGcX lQTcX0vODmb31ffwnsue8rkJmZRtu+BaJGiooolv8hb+RqKE8luDg6rdX8QL9YZQjrOB 6qdl0MiJ2f0dK7t/FcGir907La0CMKHya56Tbscqk0brXobs5CChtLwQ4/E2xTsCu2SQ SZqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493185; x=1719097985; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HvDbI2xilT38vRdpEN0TMS7XC7ztBOK0klqpk68uRTQ=; b=cnp4b4bRw9hM1HFU0k8B71u+A7cTPVsMHKX/OyJAT+3f7s1DriCgohSh5x+SR/wrXB bN9bn739s8nw8Uc6L8olnuv/Wsgf1WgCmXOXv9JAVA1wqbTgIB8XZ6qdJBguQpKCAuou ZY5vIto0WeMmsIE0CLzavXbhIvBQMYPkQEk6lc+Cb08da239C9mYwJmfsGI+/GXTSqI2 HFMKggvmszBah6Op/07d553cuW4Po7WmlhOQHyyO8N06fVszVplbNyTolEOuLaGKR5L1 tl1iRMvV+Kzc9+QuUqVGjWfnadPjyTzK7G0ISxAELhwun7zlYWXI1q/9iTUTc9aoDuKb Maiw== X-Forwarded-Encrypted: i=1; AJvYcCVh87qhga3SI1watWsfu7JNcvEj/ao4qXVBWixdeZryKlM/KR9elIvTR7fSNZJbpq8PNTA1c0h3AzeMjdtcc84oAWRKNl5VhBKkjGs5tBPMlGjrtlc54o63fW2/AFpSC3fy3guVtIttv4VGzfjCdvkAXcnNBa0Vcca3nmoLftlwwSPpwMM= X-Gm-Message-State: AOJu0YyKMreWOEoboE7bkQImIuz3Ot23ZF4BV20SENm05KiHM6HOle17 vduoXuM7bYDIsgtiJ97MTLcGQHcKjMqTSeHsjDftdaXUgrLxnav5 X-Google-Smtp-Source: AGHT+IEI+Gkdy87U976pBdRgKuum0fBiZTVEGKvF9xsJ/BW79IB8rjJX5BoMz7nBT73DMNYsxfMnvw== X-Received: by 2002:a05:600c:3550:b0:421:e3d6:920b with SMTP id 5b1f17b1804b1-42304811e38mr51229905e9.3.1718493185184; Sat, 15 Jun 2024 16:13:05 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.13.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:13:04 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 16/20] leds: leds-lp55xx: generalize sysfs engine_leds Date: Sun, 16 Jun 2024 01:11:46 +0200 Message-ID: <20240615231152.28201-17-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize sysfs engine_leds since their implementation is the same across some lp55xx based LED driver. While at it simplify the implementation for show_engine_leds. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5523.c | 119 +----------------------------- drivers/leds/leds-lp55xx-common.c | 108 +++++++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 15 +++- 3 files changed, 124 insertions(+), 118 deletions(-) diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 19b119a2b256..9d91c2c5a3eb 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -225,119 +225,6 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) return ret; } -static int lp5523_mux_parse(const char *buf, u16 *mux, size_t len) -{ - u16 tmp_mux = 0; - int i; - - len = min_t(int, len, LP5523_MAX_LEDS); - - for (i = 0; i < len; i++) { - switch (buf[i]) { - case '1': - tmp_mux |= (1 << i); - break; - case '0': - break; - case '\n': - i = len; - break; - default: - return -1; - } - } - *mux = tmp_mux; - - return 0; -} - -static void lp5523_mux_to_array(u16 led_mux, char *array) -{ - int i, pos = 0; - - for (i = 0; i < LP5523_MAX_LEDS; i++) - pos += sprintf(array + pos, "%x", LED_ACTIVE(led_mux, i)); - - array[pos] = '\0'; -} - -static ssize_t show_engine_leds(struct device *dev, - struct device_attribute *attr, - char *buf, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - char mux[LP5523_MAX_LEDS + 1]; - - lp5523_mux_to_array(chip->engines[nr - 1].led_mux, mux); - - return sprintf(buf, "%s\n", mux); -} -show_leds(1) -show_leds(2) -show_leds(3) - -static int lp5523_load_mux(struct lp55xx_chip *chip, u16 mux, int nr) -{ - struct lp55xx_engine *engine = &chip->engines[nr - 1]; - int ret; - static const u8 mux_page[] = { - [LP55XX_ENGINE_1] = LP5523_PAGE_MUX1, - [LP55XX_ENGINE_2] = LP5523_PAGE_MUX2, - [LP55XX_ENGINE_3] = LP5523_PAGE_MUX3, - }; - - lp55xx_load_engine(chip); - - ret = lp55xx_write(chip, LP5523_REG_PROG_PAGE_SEL, mux_page[nr]); - if (ret) - return ret; - - ret = lp55xx_write(chip, LP5523_REG_PROG_MEM, (u8)(mux >> 8)); - if (ret) - return ret; - - ret = lp55xx_write(chip, LP5523_REG_PROG_MEM + 1, (u8)(mux)); - if (ret) - return ret; - - engine->led_mux = mux; - return 0; -} - -static ssize_t store_engine_leds(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - struct lp55xx_engine *engine = &chip->engines[nr - 1]; - u16 mux = 0; - ssize_t ret; - - if (lp5523_mux_parse(buf, &mux, len)) - return -EINVAL; - - mutex_lock(&chip->lock); - - chip->engine_idx = nr; - ret = -EINVAL; - - if (engine->mode != LP55XX_ENGINE_LOAD) - goto leave; - - if (lp5523_load_mux(chip, mux, nr)) - goto leave; - - ret = len; -leave: - mutex_unlock(&chip->lock); - return ret; -} -store_leds(1) -store_leds(2) -store_leds(3) - static ssize_t lp5523_selftest(struct device *dev, struct device_attribute *attr, char *buf) @@ -562,9 +449,9 @@ static ssize_t store_master_fader_leds(struct device *dev, LP55XX_DEV_ATTR_ENGINE_MODE(1); LP55XX_DEV_ATTR_ENGINE_MODE(2); LP55XX_DEV_ATTR_ENGINE_MODE(3); -static LP55XX_DEV_ATTR_RW(engine1_leds, show_engine1_leds, store_engine1_leds); -static LP55XX_DEV_ATTR_RW(engine2_leds, show_engine2_leds, store_engine2_leds); -static LP55XX_DEV_ATTR_RW(engine3_leds, show_engine3_leds, store_engine3_leds); +LP55XX_DEV_ATTR_ENGINE_LEDS(1); +LP55XX_DEV_ATTR_ENGINE_LEDS(2); +LP55XX_DEV_ATTR_ENGINE_LEDS(3); LP55XX_DEV_ATTR_ENGINE_LOAD(1); LP55XX_DEV_ATTR_ENGINE_LOAD(2); LP55XX_DEV_ATTR_ENGINE_LOAD(3); diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 1a23352c9850..687693bed868 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -61,6 +61,8 @@ /* If supported, each ENGINE have an equal amount of pages offset from page 0 */ #define LP55xx_PAGE_OFFSET(n, pages) (((n) - 1) * (pages)) +#define LED_ACTIVE(mux, led) (!!(mux & (0x0001 << led))) + /* External clock rate */ #define LP55XX_CLK_32K 32768 @@ -691,6 +693,112 @@ ssize_t lp55xx_store_engine_load(struct device *dev, } EXPORT_SYMBOL_GPL(lp55xx_store_engine_load); +static int lp55xx_mux_parse(struct lp55xx_chip *chip, const char *buf, + u16 *mux, size_t len) +{ + const struct lp55xx_device_config *cfg = chip->cfg; + u16 tmp_mux = 0; + int i; + + len = min_t(int, len, cfg->max_channel); + + for (i = 0; i < len; i++) { + switch (buf[i]) { + case '1': + tmp_mux |= (1 << i); + break; + case '0': + break; + case '\n': + i = len; + break; + default: + return -1; + } + } + *mux = tmp_mux; + + return 0; +} + +ssize_t lp55xx_show_engine_leds(struct device *dev, + struct device_attribute *attr, + char *buf, int nr) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + int i, pos = 0; + + for (i = 0; i < cfg->max_channel; i++) + pos += sysfs_emit_at(buf, pos, "%x", + LED_ACTIVE(chip->engines[nr - 1].led_mux, + i)); + + pos += sysfs_emit_at(buf, pos, "\n"); + + return pos; +} +EXPORT_SYMBOL_GPL(lp55xx_show_engine_leds); + +static int lp55xx_load_mux(struct lp55xx_chip *chip, u16 mux, int nr) +{ + struct lp55xx_engine *engine = &chip->engines[nr - 1]; + const struct lp55xx_device_config *cfg = chip->cfg; + u8 mux_page; + int ret; + + lp55xx_load_engine(chip); + + /* Derive the MUX page offset by starting at the end of the ENGINE pages */ + mux_page = cfg->pages_per_engine * LP55XX_ENGINE_MAX + (nr - 1); + ret = lp55xx_write(chip, LP55xx_REG_PROG_PAGE_SEL, mux_page); + if (ret) + return ret; + + ret = lp55xx_write(chip, cfg->prog_mem_base.addr, (u8)(mux >> 8)); + if (ret) + return ret; + + ret = lp55xx_write(chip, cfg->prog_mem_base.addr + 1, (u8)(mux)); + if (ret) + return ret; + + engine->led_mux = mux; + return 0; +} + +ssize_t lp55xx_store_engine_leds(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + struct lp55xx_engine *engine = &chip->engines[nr - 1]; + u16 mux = 0; + ssize_t ret; + + if (lp55xx_mux_parse(chip, buf, &mux, len)) + return -EINVAL; + + mutex_lock(&chip->lock); + + chip->engine_idx = nr; + ret = -EINVAL; + + if (engine->mode != LP55XX_ENGINE_LOAD) + goto leave; + + if (lp55xx_load_mux(chip, mux, nr)) + goto leave; + + ret = len; +leave: + mutex_unlock(&chip->lock); + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_store_engine_leds); + static struct attribute *lp55xx_engine_attributes[] = { &dev_attr_select_engine.attr, &dev_attr_run_engine.attr, diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 00d16a86b750..212bdb216c9a 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -61,7 +61,7 @@ static ssize_t show_engine##nr##_leds(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ { \ - return show_engine_leds(dev, attr, buf, nr); \ + return lp55xx_show_engine_leds(dev, attr, buf, nr); \ } #define store_leds(nr) \ @@ -69,9 +69,14 @@ static ssize_t store_engine##nr##_leds(struct device *dev, \ struct device_attribute *attr, \ const char *buf, size_t len) \ { \ - return store_engine_leds(dev, attr, buf, len, nr); \ + return lp55xx_store_engine_leds(dev, attr, buf, len, nr); \ } +#define LP55XX_DEV_ATTR_ENGINE_LEDS(nr) \ + show_leds(nr) \ + store_leds(nr) \ + static LP55XX_DEV_ATTR_RW(engine##nr##_leds, show_engine##nr##_leds, store_engine##nr##_leds) + #define store_load(nr) \ static ssize_t store_engine##nr##_load(struct device *dev, \ struct device_attribute *attr, \ @@ -246,5 +251,11 @@ extern ssize_t lp55xx_store_engine_mode(struct device *dev, extern ssize_t lp55xx_store_engine_load(struct device *dev, struct device_attribute *attr, const char *buf, size_t len, int nr); +extern ssize_t lp55xx_show_engine_leds(struct device *dev, + struct device_attribute *attr, + char *buf, int nr); +extern ssize_t lp55xx_store_engine_leds(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr); #endif /* _LEDS_LP55XX_COMMON_H */ From patchwork Sat Jun 15 23:11:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805052 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 F12C213AD2B; Sat, 15 Jun 2024 23:13:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493190; cv=none; b=C/7psD+2SnI2BZrs6bt5gLN5TrYTDZeJ59YDD64TMEHxFydPcT4vx+hxDYVI9WiHNfDbGe3wMrHyPuifdXpBKQnLzv3fK+gi+QwUs9T4Ca3d4PevOGZj+jKbWTbCsycqrUD8JIbNE/tRymlVMpUXssg7mE7ySboiDvYb3kxme0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493190; c=relaxed/simple; bh=rLp5PUoWlLYXy9ow7R+J0uBhguk6lzJWLm+9dQJ/NIA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AL/TiQwGpP7nrkOSLbp/VvQsO+Hs1grekNrZC2bk/ad4Ogv6hQTYPm2TpDaW77xpFez5zjOIOUQQ5TxfBMY3WV6fsxvlBP9A2zj/mBRx8IhhX3oVTOIUflMQXJ9RRANsyUbqFqXFgpyKBWPBnl42OvnIEBCjzqRXHLh2kn013jw= 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=erWPdYBY; arc=none smtp.client-ip=209.85.221.41 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="erWPdYBY" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-35f2d723ef0so2865115f8f.1; Sat, 15 Jun 2024 16:13:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493186; x=1719097986; 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=qe05OY5XgNl7IgZQMzl3g7W3eb3ZqytHjml6Zdphh7I=; b=erWPdYBYVTl8vhz/2eCqMmingVrRipSVqj+MG6+Zop6laQZm2WSl4/lsWIsocU+Sy+ ANdCe9cD3ZJfsYxbcaY3eTIDUPyXh/e4s5nw9YCk0l7wNhFy0cuuACSo4ue4qE4mK2Jo K0vDApRBlobXsDyscBdJZxWixx3EqUD9vDrpfFbFDDpl6zU7wExIkxI/7/82VbWnayKX JpZwar3qYgVoVGDyzwycROxGgDiNkFarP7nEbXlzk57hpIrlPwxa08S0cwujuj7Mpajx 3OGuZkwPh17o0cykXqVOgUY25q5HkekUIJjop32D+WbaIHSUAOcSJtiAoiafqjsYdotV yQ8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493186; x=1719097986; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qe05OY5XgNl7IgZQMzl3g7W3eb3ZqytHjml6Zdphh7I=; b=T5ymiFZKcP+rCh+x67uKOIfj/t9aXnYHfetezL/R1Fpy4X648ImQHL8FG3FmgIrpMB RKwx0Xrba/1rDwwyojdKe1z6u391zGlpcShOQDZxmdbwjUa/B76jKGmKeGhUNGmHqbJd Plt/RYRJf9eX1NOSDSqa+I9/yPERmfZGV3MNT8tQby8SLutMIbpVLjzt3uH0Bdxq7hwm tCa+hI98DHj0wUfup6lhFcZq5oWonobVBgrQ/1j6j4E+nXTKUr4Ivw/upbmx3hAYl4ev q5L4tMdZsXJp3aUkpPnfV7QflbVMwRW4wozXa0aDGuwcXUL21J3i4Bpogqx07bxkRtQ1 7LSw== X-Forwarded-Encrypted: i=1; AJvYcCVrd9y/T7spGYKFtE7KKwGf+G/PPIemlkotltXdMeagAlBjU+JC4mqH3WzVlWW8vnrxO1bNMgazUaPOozY/Kvx1cKIDAGZCSuoMEdeKwYyFhc2edMiHqX1/4Y3Xt635LH+8cKiOOLr5ayU0XB5wloM+Y5SZjkagDvKztxpLCGEOM/K831Y= X-Gm-Message-State: AOJu0YwtqB++/zsfvxugO9GxkaSfAEzSFT1woezCNTkz81kSYaMxG3fr qYTpN92AW9mOfh7gsKJpEZs/UJLR8JXr0/bJ23PGdYB39064jLsW X-Google-Smtp-Source: AGHT+IHm64I/T3lr/JtVXnnZuxi+3VMj/vc9rYWyeT9SeyeSzuP5ktBTfWWM5B1bTsOsrgh6zEnVzg== X-Received: by 2002:adf:e88b:0:b0:360:8f85:a5f1 with SMTP id ffacd0b85a97d-3608f85a70amr1330174f8f.5.1718493186165; Sat, 15 Jun 2024 16:13:06 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:13:05 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 17/20] leds: leds-lp55xx: generalize sysfs master_fader Date: Sun, 16 Jun 2024 01:11:47 +0200 Message-ID: <20240615231152.28201-18-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize sysfs master_fader since their implementation is the same across some lp55xx based LED driver. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5523.c | 144 ++---------------------------- drivers/leds/leds-lp55xx-common.c | 119 ++++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 37 ++++++++ 3 files changed, 161 insertions(+), 139 deletions(-) diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 9d91c2c5a3eb..6f25a6c32869 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -315,137 +315,6 @@ static ssize_t lp5523_selftest(struct device *dev, return pos; } -#define show_fader(nr) \ -static ssize_t show_master_fader##nr(struct device *dev, \ - struct device_attribute *attr, \ - char *buf) \ -{ \ - return show_master_fader(dev, attr, buf, nr); \ -} - -#define store_fader(nr) \ -static ssize_t store_master_fader##nr(struct device *dev, \ - struct device_attribute *attr, \ - const char *buf, size_t len) \ -{ \ - return store_master_fader(dev, attr, buf, len, nr); \ -} - -static ssize_t show_master_fader(struct device *dev, - struct device_attribute *attr, - char *buf, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - int ret; - u8 val; - - mutex_lock(&chip->lock); - ret = lp55xx_read(chip, LP5523_REG_MASTER_FADER_BASE + nr - 1, &val); - mutex_unlock(&chip->lock); - - if (ret == 0) - ret = sprintf(buf, "%u\n", val); - - return ret; -} -show_fader(1) -show_fader(2) -show_fader(3) - -static ssize_t store_master_fader(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - int ret; - unsigned long val; - - if (kstrtoul(buf, 0, &val)) - return -EINVAL; - - if (val > 0xff) - return -EINVAL; - - mutex_lock(&chip->lock); - ret = lp55xx_write(chip, LP5523_REG_MASTER_FADER_BASE + nr - 1, - (u8)val); - mutex_unlock(&chip->lock); - - if (ret == 0) - ret = len; - - return ret; -} -store_fader(1) -store_fader(2) -store_fader(3) - -static ssize_t show_master_fader_leds(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - int i, ret, pos = 0; - u8 val; - - mutex_lock(&chip->lock); - - for (i = 0; i < LP5523_MAX_LEDS; i++) { - ret = lp55xx_read(chip, LP5523_REG_LED_CTRL_BASE + i, &val); - if (ret) - goto leave; - - val = (val & LP5523_FADER_MAPPING_MASK) - >> LP5523_FADER_MAPPING_SHIFT; - if (val > 3) { - ret = -EINVAL; - goto leave; - } - buf[pos++] = val + '0'; - } - buf[pos++] = '\n'; - ret = pos; -leave: - mutex_unlock(&chip->lock); - return ret; -} - -static ssize_t store_master_fader_leds(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - int i, n, ret; - u8 val; - - n = min_t(int, len, LP5523_MAX_LEDS); - - mutex_lock(&chip->lock); - - for (i = 0; i < n; i++) { - if (buf[i] >= '0' && buf[i] <= '3') { - val = (buf[i] - '0') << LP5523_FADER_MAPPING_SHIFT; - ret = lp55xx_update_bits(chip, - LP5523_REG_LED_CTRL_BASE + i, - LP5523_FADER_MAPPING_MASK, - val); - if (ret) - goto leave; - } else { - ret = -EINVAL; - goto leave; - } - } - ret = len; -leave: - mutex_unlock(&chip->lock); - return ret; -} - LP55XX_DEV_ATTR_ENGINE_MODE(1); LP55XX_DEV_ATTR_ENGINE_MODE(2); LP55XX_DEV_ATTR_ENGINE_MODE(3); @@ -456,14 +325,11 @@ LP55XX_DEV_ATTR_ENGINE_LOAD(1); LP55XX_DEV_ATTR_ENGINE_LOAD(2); LP55XX_DEV_ATTR_ENGINE_LOAD(3); static LP55XX_DEV_ATTR_RO(selftest, lp5523_selftest); -static LP55XX_DEV_ATTR_RW(master_fader1, show_master_fader1, - store_master_fader1); -static LP55XX_DEV_ATTR_RW(master_fader2, show_master_fader2, - store_master_fader2); -static LP55XX_DEV_ATTR_RW(master_fader3, show_master_fader3, - store_master_fader3); -static LP55XX_DEV_ATTR_RW(master_fader_leds, show_master_fader_leds, - store_master_fader_leds); +LP55XX_DEV_ATTR_MASTER_FADER(1); +LP55XX_DEV_ATTR_MASTER_FADER(2); +LP55XX_DEV_ATTR_MASTER_FADER(3); +static LP55XX_DEV_ATTR_RW(master_fader_leds, lp55xx_show_master_fader_leds, + lp55xx_store_master_fader_leds); static struct attribute *lp5523_attributes[] = { &dev_attr_engine1_mode.attr, diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 687693bed868..ac02ab938dd8 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -63,6 +63,9 @@ #define LED_ACTIVE(mux, led) (!!(mux & (0x0001 << led))) +/* MASTER FADER common property */ +#define LP55xx_FADER_MAPPING_MASK GENMASK(7, 6) + /* External clock rate */ #define LP55XX_CLK_32K 32768 @@ -799,6 +802,122 @@ ssize_t lp55xx_store_engine_leds(struct device *dev, } EXPORT_SYMBOL_GPL(lp55xx_store_engine_leds); +ssize_t lp55xx_show_master_fader(struct device *dev, + struct device_attribute *attr, + char *buf, int nr) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + int ret; + u8 val; + + mutex_lock(&chip->lock); + ret = lp55xx_read(chip, cfg->reg_master_fader_base.addr + nr - 1, &val); + mutex_unlock(&chip->lock); + + if (ret == 0) + ret = sprintf(buf, "%u\n", val); + + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_show_master_fader); + +ssize_t lp55xx_store_master_fader(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + int ret; + unsigned long val; + + if (kstrtoul(buf, 0, &val)) + return -EINVAL; + + if (val > 0xff) + return -EINVAL; + + mutex_lock(&chip->lock); + ret = lp55xx_write(chip, cfg->reg_master_fader_base.addr + nr - 1, + (u8)val); + mutex_unlock(&chip->lock); + + if (ret == 0) + ret = len; + + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_store_master_fader); + +ssize_t lp55xx_show_master_fader_leds(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + int i, ret, pos = 0; + u8 val; + + mutex_lock(&chip->lock); + + for (i = 0; i < cfg->max_channel; i++) { + ret = lp55xx_read(chip, cfg->reg_led_ctrl_base.addr + i, &val); + if (ret) + goto leave; + + val = FIELD_GET(LP55xx_FADER_MAPPING_MASK, val); + if (val > FIELD_MAX(LP55xx_FADER_MAPPING_MASK)) { + ret = -EINVAL; + goto leave; + } + buf[pos++] = val + '0'; + } + buf[pos++] = '\n'; + ret = pos; +leave: + mutex_unlock(&chip->lock); + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_show_master_fader_leds); + +ssize_t lp55xx_store_master_fader_leds(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + int i, n, ret; + u8 val; + + n = min_t(int, len, cfg->max_channel); + + mutex_lock(&chip->lock); + + for (i = 0; i < n; i++) { + if (buf[i] >= '0' && buf[i] <= '3') { + val = (buf[i] - '0') << __bf_shf(LP55xx_FADER_MAPPING_MASK); + ret = lp55xx_update_bits(chip, + cfg->reg_led_ctrl_base.addr + i, + LP55xx_FADER_MAPPING_MASK, + val); + if (ret) + goto leave; + } else { + ret = -EINVAL; + goto leave; + } + } + ret = len; +leave: + mutex_unlock(&chip->lock); + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_store_master_fader_leds); + static struct attribute *lp55xx_engine_attributes[] = { &dev_attr_select_engine.attr, &dev_attr_run_engine.attr, diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 212bdb216c9a..063d7392b6a2 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -89,6 +89,27 @@ static ssize_t store_engine##nr##_load(struct device *dev, \ store_load(nr) \ static LP55XX_DEV_ATTR_WO(engine##nr##_load, store_engine##nr##_load) +#define show_fader(nr) \ +static ssize_t show_master_fader##nr(struct device *dev, \ + struct device_attribute *attr, \ + char *buf) \ +{ \ + return lp55xx_show_master_fader(dev, attr, buf, nr); \ +} + +#define store_fader(nr) \ +static ssize_t store_master_fader##nr(struct device *dev, \ + struct device_attribute *attr, \ + const char *buf, size_t len) \ +{ \ + return lp55xx_store_master_fader(dev, attr, buf, len, nr); \ +} + +#define LP55XX_DEV_ATTR_MASTER_FADER(nr) \ + show_fader(nr) \ + store_fader(nr) \ + static LP55XX_DEV_ATTR_RW(master_fader##nr, show_master_fader##nr, store_master_fader##nr) + struct lp55xx_led; struct lp55xx_chip; @@ -116,6 +137,8 @@ struct lp55xx_reg { * @prog_mem_base : Chip specific base reg address for chip SMEM programming * @reg_led_pwm_base : Chip specific base reg address for LED PWM conf * @reg_led_current_base : Chip specific base reg address for LED current conf + * @reg_master_fader_base : Chip specific base reg address for master fader base + * @reg_led_ctrl_base : Chip specific base reg address for LED ctrl base * @pages_per_engine : Assigned pages for each engine * (if not set chip doesn't support pages) * @max_channel : Maximum number of channels @@ -136,6 +159,8 @@ struct lp55xx_device_config { const struct lp55xx_reg prog_mem_base; const struct lp55xx_reg reg_led_pwm_base; const struct lp55xx_reg reg_led_current_base; + const struct lp55xx_reg reg_master_fader_base; + const struct lp55xx_reg reg_led_ctrl_base; const int pages_per_engine; const int max_channel; @@ -257,5 +282,17 @@ extern ssize_t lp55xx_show_engine_leds(struct device *dev, extern ssize_t lp55xx_store_engine_leds(struct device *dev, struct device_attribute *attr, const char *buf, size_t len, int nr); +extern ssize_t lp55xx_show_master_fader(struct device *dev, + struct device_attribute *attr, + char *buf, int nr); +extern ssize_t lp55xx_store_master_fader(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr); +extern ssize_t lp55xx_show_master_fader_leds(struct device *dev, + struct device_attribute *attr, + char *buf); +extern ssize_t lp55xx_store_master_fader_leds(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len); #endif /* _LEDS_LP55XX_COMMON_H */ From patchwork Sat Jun 15 23:11:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804577 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 633E113B5A8; Sat, 15 Jun 2024 23:13:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493191; cv=none; b=RVga1eawU63HOeQUmalrTrZKI3kuvzfTWCkJS6UecqFVwBYCe+kAR9lBJ1VkT/vnf14FScAQNbDoii760hLiueaLKU5awgFusJbgqkvyA8N8j++CVDWiKb4f6mXYDJLN/qBMqKLgnw7zZyN/XvJO5CAXSHLHdYqP+jmiTcxQIwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493191; c=relaxed/simple; bh=LeGY0C+gTRF6uWpv1p5f7568QENp8tJvyJ6FnoORh0Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=buvBeQP3O1+ASkSCKGZ3iN76E+rhHzUQiD0IflnHOIchpSXR55ZX75pt1fJ8JP0yI6in4PZ9o/kE3sHH1S5/hYSayN8JZ5rk2i53bAX0fAStqRR7TPjaWXpzMmhv0aljybneFtzST/WM/VQhqc48tNHCqQsQ6qMxZdRv7s3Z0vw= 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=WCTfEHCC; arc=none smtp.client-ip=209.85.167.41 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="WCTfEHCC" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-5295eb47b48so3885660e87.1; Sat, 15 Jun 2024 16:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493187; x=1719097987; 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=BNUCQuNA9inI5/zx15X+ljjMizg9qNzUcqGlCVUVA2I=; b=WCTfEHCCKzs/QjqLbXISeef1hJfm+5FykAvO5KN1CqQ4hntzMffbFcaEeNhgJz84ey 47/VUlSGz8o72ufx9RjYxaY8wWVTlpMkw+HtukXjzW1Gn02QsqW8Qi6ZaHpACOZcdI+b M3vMSOCVz2nphZKBp1qVi49M7sGXtfiPAZHN4WRb4DrGlBcknLLKl0lGK6tOApgShJHd KfPnQoBeeTDOtmYIZEcdmJWcyJjzKxOTw3FYcStbFwoVuAe058KxeqImSnJso9AriSEE JM5OIS5TPil5j+JkqcHm9y75JtUHxmu8u2ouaHqJTNSKV8OUdrGCbij4CcpkDD7bjoeS MYcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493187; x=1719097987; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BNUCQuNA9inI5/zx15X+ljjMizg9qNzUcqGlCVUVA2I=; b=qNSs6p0xwPmEIWhftFTgz983oll2vSC0U+qmWycLoevKfeGawR6QCqzGSkOROT5tU1 b39GVIGZUSR8diplxv12nsiaZoYHILWef0TSIsmMMrf3Vr9HlGrCBlm0APc2jRPrh4YV cw+4m0LOfX7QfXVgSL6pYFauhfPkac8JRM3A6S0uQJF/IZGCiHPLKlLVhH2pSXTHn8zd /OQRC1fsEvTy10duI82yrNe74+eSvVfO+/OHbjv/M26p16mYC0KLvn8UbIpCWrU75yca 7m0ofKlxZfAxZ6Mk7WXD4o0VEyK5I3NZXSQzLjmEpPdWCYtXzMgNaNcpB79OzXGetDNC pkVw== X-Forwarded-Encrypted: i=1; AJvYcCV15D/0DjdDNPSRhqfKfwOvqP7G9m2a324gApeIjPh7JCwh5uFNFT5zGswnLyTA/Ij3hEOqWUgLgKKFLvW1lXH4sj6CooE09Bnmi9Ofbes8k5blX1U5C9DWmrHLiP4D/JYRsaSVA07D6yMjBDCYYqVQiWlEOAhYR/jnxWTMqNX0Hz4UOFE= X-Gm-Message-State: AOJu0Yy4QNrV9NjhSTyqr+iWUujuHxRpmYK1oD7GkqqmiqWT2ngiM+Di Too/3zyXH4eBnPPAob6LFbRA3m8xBmmwXDApfJZSsTudsft9NjrT X-Google-Smtp-Source: AGHT+IGo8LUrFDaG8gHXZ5DI1kJy+ZloRFRLUaIMvPVOPaiVrc+Wf/sn8lHFDuMj0yEEywARCjZ96A== X-Received: by 2002:a05:6512:3d10:b0:52c:a8c4:4d99 with SMTP id 2adb3069b0e04-52ca8c44ec0mr4614573e87.68.1718493187205; Sat, 15 Jun 2024 16:13:07 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:13:06 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 18/20] leds: leds-lp55xx: support ENGINE program up to 128 bytes Date: Sun, 16 Jun 2024 01:11:48 +0200 Message-ID: <20240615231152.28201-19-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some LED chip supports up to 16 pages and with some magic they can be divided in 4 page for each ENGINE + 1 for each MUX. Following this we can support bigger programs up to 128 bytes. Rework the update_program_memory function to support program of multiple pages instead of hardcoding it to one page per programs. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5523.c | 5 ++- drivers/leds/leds-lp5562.c | 7 ++-- drivers/leds/leds-lp55xx-common.c | 54 ++++++++++++++++++++++++------- drivers/leds/leds-lp55xx-common.h | 2 ++ 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 6f25a6c32869..1d00c6cc4174 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -21,7 +21,6 @@ #include "leds-lp55xx-common.h" -#define LP5523_PROGRAM_LENGTH 32 /* bytes */ /* Memory is used like this: * 0x00 engine 1 program * 0x10 engine 2 program @@ -172,7 +171,7 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) int ret; u8 status; /* one pattern per engine setting LED MUX start and stop addresses */ - static const u8 pattern[][LP5523_PROGRAM_LENGTH] = { + static const u8 pattern[][LP55xx_BYTES_PER_PAGE] = { { 0x9c, 0x30, 0x9c, 0xb0, 0x9d, 0x80, 0xd8, 0x00, 0}, { 0x9c, 0x40, 0x9c, 0xc0, 0x9d, 0x80, 0xd8, 0x00, 0}, { 0x9c, 0x50, 0x9c, 0xd0, 0x9d, 0x80, 0xd8, 0x00, 0}, @@ -196,7 +195,7 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) chip->engine_idx = i; lp55xx_load_engine(chip); - for (j = 0; j < LP5523_PROGRAM_LENGTH; j++) { + for (j = 0; j < LP55xx_BYTES_PER_PAGE; j++) { ret = lp55xx_write(chip, LP5523_REG_PROG_MEM + j, pattern[i - 1][j]); if (ret) diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index e50b68c9ccf3..109162f1720f 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -19,7 +19,6 @@ #include "leds-lp55xx-common.h" -#define LP5562_PROGRAM_LENGTH 32 #define LP5562_MAX_LEDS 4 /* ENABLE Register 00h */ @@ -212,9 +211,9 @@ static void lp5562_write_program_memory(struct lp55xx_chip *chip, /* check the size of program count */ static inline bool _is_pc_overflow(struct lp55xx_predef_pattern *ptn) { - return ptn->size_r >= LP5562_PROGRAM_LENGTH || - ptn->size_g >= LP5562_PROGRAM_LENGTH || - ptn->size_b >= LP5562_PROGRAM_LENGTH; + return ptn->size_r >= LP55xx_BYTES_PER_PAGE || + ptn->size_g >= LP55xx_BYTES_PER_PAGE || + ptn->size_b >= LP55xx_BYTES_PER_PAGE; } static int lp5562_run_predef_led_pattern(struct lp55xx_chip *chip, int mode) diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index ac02ab938dd8..9b03d6596c24 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -26,7 +26,8 @@ /* OP MODE require at least 153 us to clear regs */ #define LP55XX_CMD_SLEEP 200 -#define LP55xx_PROGRAM_LENGTH 32 +#define LP55xx_PROGRAM_PAGES 16 +#define LP55xx_MAX_PROGRAM_LENGTH (LP55xx_BYTES_PER_PAGE * 4) /* 128 bytes (4 pages) */ /* * Program Memory Operations @@ -172,12 +173,16 @@ int lp55xx_update_program_memory(struct lp55xx_chip *chip, { enum lp55xx_engine_index idx = chip->engine_idx; const struct lp55xx_device_config *cfg = chip->cfg; - u8 pattern[LP55xx_PROGRAM_LENGTH] = { }; + u8 pattern[LP55xx_MAX_PROGRAM_LENGTH] = { }; u8 start_addr = cfg->prog_mem_base.addr; - int i = 0, offset = 0; - int ret; + int page, i = 0, offset = 0; + int program_length, ret; + + program_length = LP55xx_BYTES_PER_PAGE; + if (cfg->pages_per_engine) + program_length *= cfg->pages_per_engine; - while ((offset < size - 1) && (i < LP55xx_PROGRAM_LENGTH)) { + while ((offset < size - 1) && (i < program_length)) { unsigned int cmd; int nrchars; char c[3]; @@ -206,12 +211,20 @@ int lp55xx_update_program_memory(struct lp55xx_chip *chip, * For LED chip that support page, PAGE is already set in load_engine. */ if (!cfg->pages_per_engine) - start_addr += LP55xx_PROGRAM_LENGTH * idx; + start_addr += LP55xx_BYTES_PER_PAGE * idx; - for (i = 0; i < LP55xx_PROGRAM_LENGTH; i++) { - ret = lp55xx_write(chip, start_addr + i, pattern[i]); - if (ret) - return -EINVAL; + for (page = 0; page < program_length / LP55xx_BYTES_PER_PAGE; page++) { + /* Write to the next page each 32 bytes (if supported) */ + if (cfg->pages_per_engine) + lp55xx_write(chip, LP55xx_REG_PROG_PAGE_SEL, + LP55xx_PAGE_OFFSET(idx, cfg->pages_per_engine) + page); + + for (i = 0; i < LP55xx_BYTES_PER_PAGE; i++) { + ret = lp55xx_write(chip, start_addr + i, + pattern[i + (page * LP55xx_BYTES_PER_PAGE)]); + if (ret) + return -EINVAL; + } } return size; @@ -224,13 +237,19 @@ EXPORT_SYMBOL_GPL(lp55xx_update_program_memory); void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip) { + const struct lp55xx_device_config *cfg = chip->cfg; const struct firmware *fw = chip->fw; + int program_length; + + program_length = LP55xx_BYTES_PER_PAGE; + if (cfg->pages_per_engine) + program_length *= cfg->pages_per_engine; /* * the firmware is encoded in ascii hex character, with 2 chars * per byte */ - if (fw->size > LP55xx_PROGRAM_LENGTH * 2) { + if (fw->size > program_length * 2) { dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n", fw->size); return; @@ -1281,7 +1300,7 @@ static struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev, int lp55xx_probe(struct i2c_client *client) { const struct i2c_device_id *id = i2c_client_get_device_id(client); - int ret; + int program_length, ret; struct lp55xx_chip *chip; struct lp55xx_led *led; struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev); @@ -1305,6 +1324,17 @@ int lp55xx_probe(struct i2c_client *client) } } + /* Validate max program page */ + program_length = LP55xx_BYTES_PER_PAGE; + if (chip->cfg->pages_per_engine) + program_length *= chip->cfg->pages_per_engine; + + /* support a max of 128bytes */ + if (program_length > LP55xx_MAX_PROGRAM_LENGTH) { + dev_err(&client->dev, "invalid pages_per_engine configured\n"); + return -EINVAL; + } + led = devm_kcalloc(&client->dev, pdata->num_channels, sizeof(*led), GFP_KERNEL); if (!led) diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 063d7392b6a2..5e1f7fea5985 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -14,6 +14,8 @@ #include +#define LP55xx_BYTES_PER_PAGE 32 /* bytes */ + enum lp55xx_engine_index { LP55XX_ENGINE_INVALID, LP55XX_ENGINE_1, From patchwork Sat Jun 15 23:11:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805051 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 D112F13B792; Sat, 15 Jun 2024 23:13:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493191; cv=none; b=dj1f94+4ba/zlLGgtx+P63IBDTs7/b/ywZAkTgefYTZaJ59JOHNNhJyLQlBrz1+0rToTqg8tBbUqAb6df7c4mkszTPcYX2DEL/5FDGMruOpfWTtWLbu8HHbHKADpkxtMEQK6TaZ+4S4xDnyLZ9OE0dDeNeqkh0Vrsn8qQ52wW7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493191; c=relaxed/simple; bh=Qri5xysaOutaV7cRmfiajw/hUm4xS4gzT2WmqGJ6O6I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n2K4rIK0WbLLZyqYlKS/t9k1aifsESj+tGX1hL3gcD/zJFIIGgKNqRWMJEjP6b8cRlNSw17P6WjdXmjz+UlZdCSJv5ryGPPBRy28KvFb9u4yPwIRR8ac17ez0nomg2TRXNXftoUFivmQlkHoM9HD3jzQZDD1CpcTcBcDm3TDaYE= 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=cvKacfKk; arc=none smtp.client-ip=209.85.221.53 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="cvKacfKk" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-35f236a563cso2693941f8f.2; Sat, 15 Jun 2024 16:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493188; x=1719097988; 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=6ZO2jSTOjjW2TJhM4hgpkZ9GfcYTJ+1yDgbg82D4U2A=; b=cvKacfKkfPRpHh5fLiQI/386W2vL7Bk54d6Xsxncg8F1Ra2NXUXUq9U27Qi6Ouwrgb UgpfvcKD5iBtzmkThlUo3uH8W1hFHAcmUQZzuFmlP4M1boWbLSUuLkRFGqT/CVFoxe1w Ecm5MwgRP2v5L6TCilfOMnlGyXyaKglVghYDl+WQTVDQilsouPccOvZthmDQKaDjViRS mG6ZLcEfr9WcnnkNK3DbLwIuRSUbjwTwSHh9PrOaSxW3j+FLU6aluE3dzn9VPQsN0ApH OqSUO7OpExg5XUVD+6AX4S3DOAGR/SO1BW7NF60nMjZZjIXOv2/RUs+fr1sEtSObRNVF 2Bzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493188; x=1719097988; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6ZO2jSTOjjW2TJhM4hgpkZ9GfcYTJ+1yDgbg82D4U2A=; b=YM8ql8UDpUtcMRwAvkGa2cPPJSHGrEoYxpDHsyNhE6rwS3lJY8TH/Wo+ZfIjG2JWym FRyMGjj+4P67seusH9cOy8DAYP/dgGp4olbyZQbPK3GmRaxHqrGSjWmuMFD3JoVkzu6s SyTbybpq5GlpTThivl7c9YhOt1R7TpRLDH/OBJJ8J5JMQyBeGp96ncEdCGi3YnQqNSnG ufScLHbdVDIBu6I5ByuZEijXBmxKwbUYqKgkD29mcxFvHyJ+GWYPa2tTJt87BOTu/rAh ctcX3R/N7X8IhLb3bEQojqk0GuL1NUgX45/WjD6n+fKWMfhAMm0EUnWKZaliaFOecnIL t7hA== X-Forwarded-Encrypted: i=1; AJvYcCX2L7VwgNqcobj+L9dPQ5BCK15JAzN98SO5gmEueOkXBcFFvghapfejLGSrWii9d/gOGZMAKFqGW9D7M/hUjVYnhcN+7IjiuapsI1UCX1tQm2ywwiBy7LoFQceP4/UBRqq9r8L9jxsTPzuJhGcGo1aDDF5Eo43DyrxjqaaL5jaZoIxwf9c= X-Gm-Message-State: AOJu0YzkOECblIrgI0wQnTELlCzVVP/27E2gExcDWdiZe2GTQ/0+pysj rzw/c1vZzm3oRrr79Hw+D680+1Giq3JbMXAMianhybqH/0iVjtt1 X-Google-Smtp-Source: AGHT+IG7NLtcLSkyl76usc4zy3b6iXheFgskBkDQjdlsxrMfyJcQrbL5TBfiZQgjqXqjKnDlkriLIA== X-Received: by 2002:a5d:6312:0:b0:360:6435:b37 with SMTP id ffacd0b85a97d-3607a726087mr4898708f8f.9.1718493188148; Sat, 15 Jun 2024 16:13:08 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.13.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:13:07 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 19/20] leds: leds-lp55xx: drop deprecated defines Date: Sun, 16 Jun 2024 01:11:49 +0200 Message-ID: <20240615231152.28201-20-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Drop deprecated defines not used anymore as the related function got moved to lp55xx-common. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 24 -------------------- drivers/leds/leds-lp5523.c | 46 -------------------------------------- drivers/leds/leds-lp5562.c | 15 ------------- drivers/leds/leds-lp8501.c | 31 ------------------------- 4 files changed, 116 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 519e7627ac22..de0f8ea48eba 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -21,7 +21,6 @@ #include "leds-lp55xx-common.h" -#define LP5521_PROGRAM_LENGTH 32 #define LP5521_MAX_LEDS 3 #define LP5521_CMD_DIRECT 0x3F @@ -73,29 +72,6 @@ /* Reset register value */ #define LP5521_RESET 0xFF -/* Program Memory Operations */ -#define LP5521_MODE_R_M 0x30 /* Operation Mode Register */ -#define LP5521_MODE_G_M 0x0C -#define LP5521_MODE_B_M 0x03 -#define LP5521_LOAD_R 0x10 -#define LP5521_LOAD_G 0x04 -#define LP5521_LOAD_B 0x01 - -#define LP5521_R_IS_LOADING(mode) \ - ((mode & LP5521_MODE_R_M) == LP5521_LOAD_R) -#define LP5521_G_IS_LOADING(mode) \ - ((mode & LP5521_MODE_G_M) == LP5521_LOAD_G) -#define LP5521_B_IS_LOADING(mode) \ - ((mode & LP5521_MODE_B_M) == LP5521_LOAD_B) - -#define LP5521_EXEC_R_M 0x30 /* Enable Register */ -#define LP5521_EXEC_G_M 0x0C -#define LP5521_EXEC_B_M 0x03 -#define LP5521_EXEC_M 0x3F -#define LP5521_RUN_R 0x20 -#define LP5521_RUN_G 0x08 -#define LP5521_RUN_B 0x02 - static inline void lp5521_wait_opmode_done(void) { /* operation mode change needs to be longer than 153 us */ diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 1d00c6cc4174..eb686240f097 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -73,54 +73,8 @@ #define LP5523_EXT_CLK_USED 0x08 #define LP5523_ENG_STATUS_MASK 0x07 -#define LP5523_FADER_MAPPING_MASK 0xC0 -#define LP5523_FADER_MAPPING_SHIFT 6 - -/* Memory Page Selection */ -#define LP5523_PAGE_ENG1 0 -#define LP5523_PAGE_ENG2 1 -#define LP5523_PAGE_ENG3 2 -#define LP5523_PAGE_MUX1 3 -#define LP5523_PAGE_MUX2 4 -#define LP5523_PAGE_MUX3 5 - -/* Program Memory Operations */ -#define LP5523_MODE_ENG1_M 0x30 /* Operation Mode Register */ -#define LP5523_MODE_ENG2_M 0x0C -#define LP5523_MODE_ENG3_M 0x03 -#define LP5523_LOAD_ENG1 0x10 -#define LP5523_LOAD_ENG2 0x04 -#define LP5523_LOAD_ENG3 0x01 - -#define LP5523_ENG1_IS_LOADING(mode) \ - ((mode & LP5523_MODE_ENG1_M) == LP5523_LOAD_ENG1) -#define LP5523_ENG2_IS_LOADING(mode) \ - ((mode & LP5523_MODE_ENG2_M) == LP5523_LOAD_ENG2) -#define LP5523_ENG3_IS_LOADING(mode) \ - ((mode & LP5523_MODE_ENG3_M) == LP5523_LOAD_ENG3) - -#define LP5523_EXEC_ENG1_M 0x30 /* Enable Register */ -#define LP5523_EXEC_ENG2_M 0x0C -#define LP5523_EXEC_ENG3_M 0x03 -#define LP5523_EXEC_M 0x3F -#define LP5523_RUN_ENG1 0x20 -#define LP5523_RUN_ENG2 0x08 -#define LP5523_RUN_ENG3 0x02 - -#define LED_ACTIVE(mux, led) (!!(mux & (0x0001 << led))) - -enum lp5523_chip_id { - LP5523, - LP55231, -}; - static int lp5523_init_program_engine(struct lp55xx_chip *chip); -static inline void lp5523_wait_opmode_done(void) -{ - usleep_range(1000, 2000); -} - static int lp5523_post_init_device(struct lp55xx_chip *chip) { int ret; diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index 109162f1720f..6ba5dbb9cace 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -37,21 +37,6 @@ /* OPMODE Register 01h */ #define LP5562_REG_OP_MODE 0x01 -#define LP5562_MODE_ENG1_M 0x30 -#define LP5562_MODE_ENG2_M 0x0C -#define LP5562_MODE_ENG3_M 0x03 -#define LP5562_LOAD_ENG1 0x10 -#define LP5562_LOAD_ENG2 0x04 -#define LP5562_LOAD_ENG3 0x01 -#define LP5562_RUN_ENG1 0x20 -#define LP5562_RUN_ENG2 0x08 -#define LP5562_RUN_ENG3 0x02 -#define LP5562_ENG1_IS_LOADING(mode) \ - ((mode & LP5562_MODE_ENG1_M) == LP5562_LOAD_ENG1) -#define LP5562_ENG2_IS_LOADING(mode) \ - ((mode & LP5562_MODE_ENG2_M) == LP5562_LOAD_ENG2) -#define LP5562_ENG3_IS_LOADING(mode) \ - ((mode & LP5562_MODE_ENG3_M) == LP5562_LOAD_ENG3) /* BRIGHTNESS Registers */ #define LP5562_REG_R_PWM 0x04 diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c index 1fb876f64cb7..ee4ff4586bc0 100644 --- a/drivers/leds/leds-lp8501.c +++ b/drivers/leds/leds-lp8501.c @@ -20,28 +20,14 @@ #include "leds-lp55xx-common.h" -#define LP8501_PROGRAM_LENGTH 32 #define LP8501_PAGES_PER_ENGINE 1 #define LP8501_MAX_LEDS 9 /* Registers */ #define LP8501_REG_ENABLE 0x00 #define LP8501_ENABLE BIT(6) -#define LP8501_EXEC_M 0x3F -#define LP8501_EXEC_ENG1_M 0x30 -#define LP8501_EXEC_ENG2_M 0x0C -#define LP8501_EXEC_ENG3_M 0x03 -#define LP8501_RUN_ENG1 0x20 -#define LP8501_RUN_ENG2 0x08 -#define LP8501_RUN_ENG3 0x02 #define LP8501_REG_OP_MODE 0x01 -#define LP8501_MODE_ENG1_M 0x30 -#define LP8501_MODE_ENG2_M 0x0C -#define LP8501_MODE_ENG3_M 0x03 -#define LP8501_LOAD_ENG1 0x10 -#define LP8501_LOAD_ENG2 0x04 -#define LP8501_LOAD_ENG3 0x01 #define LP8501_REG_PWR_CONFIG 0x05 #define LP8501_PWR_CONFIG_M 0x03 @@ -65,25 +51,8 @@ #define LP8501_REG_RESET 0x3D #define LP8501_RESET 0xFF -#define LP8501_REG_PROG_PAGE_SEL 0x4F -#define LP8501_PAGE_ENG1 0 -#define LP8501_PAGE_ENG2 1 -#define LP8501_PAGE_ENG3 2 - #define LP8501_REG_PROG_MEM 0x50 -#define LP8501_ENG1_IS_LOADING(mode) \ - ((mode & LP8501_MODE_ENG1_M) == LP8501_LOAD_ENG1) -#define LP8501_ENG2_IS_LOADING(mode) \ - ((mode & LP8501_MODE_ENG2_M) == LP8501_LOAD_ENG2) -#define LP8501_ENG3_IS_LOADING(mode) \ - ((mode & LP8501_MODE_ENG3_M) == LP8501_LOAD_ENG3) - -static inline void lp8501_wait_opmode_done(void) -{ - usleep_range(1000, 2000); -} - static int lp8501_post_init_device(struct lp55xx_chip *chip) { int ret; From patchwork Sat Jun 15 23:11:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804576 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 E1B6B13BC01; Sat, 15 Jun 2024 23:13:10 +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=1718493193; cv=none; b=FjHfBnWaxrvGnGgWnRpJJvbWnXXe46l3Rr5UWnKj1BksJCCRBKfO/UUjci87Ad7wmYuSZuedWWOArJLNUZzo01vuD1eV6+z8qDJnpe9N1tDUcCGIO2WxLCxfDwoCTTZP3QXXQbpHPciSzvY0UCuhwUFPgZ2lzieaN7MHpW9U2qM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718493193; c=relaxed/simple; bh=ku+VGfnNI34F254MFdUC0xDb4Yx+yRR3yHZAkkb9RSw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MLIvCKnwClEJy9i7bIDmiDcw25g2+bBS+loLjqr803OMzwLLBoYAxqFqTkGNkDMd0HP3didMt4NYntawwsfrwZcaOaPqbeRNJFX2TspA/Qdx+gQgFmchDq/Ss/9djabQz8/FzUTJ/8Lb0piM7Sb8/0BZnitA76PWqldrhD8Vfus= 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=Zef32v+h; 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="Zef32v+h" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-42172ab4b60so30400555e9.0; Sat, 15 Jun 2024 16:13:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718493189; x=1719097989; 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=eUfgJaiAMs8UzsHkdvv07vuPTP2fZMr9yKyEFTSMlvM=; b=Zef32v+hwG9vWrFxGGbXn4HF9GeTaX1zojcBEVQjYT7oJZ1vCKPYSFv/I8nQ1aI6g3 xN5/iembU/ENwOOU4rRU5HYjceNn7gFsKhvuGoGjVcT44J7UHrES9+yhTuWoSKZHCh2s 9iMWquJge8TxWZNJOCD0XAEwYt2ihrVXY2dourvnB9kD9KdXqA9vWXFmXS4yL12GhlSz S156ik4OuvwBUu/qw1BTiCxR3xIqxQmrD/sLRi0D6DDfNHTne7tqBPZQ3RuLdah1ITuF /9wiW5UMYzcHgmG7Qvs/C9ivnEHQeU3seKgnWcrFm8Be0cMIr/sar67Wwho91Om5AMka 8sIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718493189; x=1719097989; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eUfgJaiAMs8UzsHkdvv07vuPTP2fZMr9yKyEFTSMlvM=; b=eBwzK/vupgYIuKGmKe2mjoRiesI7Dgk3gEtXv2FRe/mqNy2zBXRWRorKeNpU9l2IvA 3Q4gK9GZyqUbALg2GA1Iil/vmuWhAMyL6y2hvn71kt3sjLK27+ZJSnivL7txrIt4UbBl z6t3QVFNHlkTW0g/K/c/d8WXj7C6wN3Gh3XXilBpKWrf3N/IFTaeJrJ8HVEHJQHhIrmt GADEKYsAy2x90wJw2BozY4/c4MjPlPcyx2WUnA6j10kmytL/8iQmiXHarFZA9wgDup76 BGWTofztwlLeGLJeUOhywMJW9gtudW/JErJqdun0ULOwhnJ5sHUvN3Nr42/HwMMvysPI lKIA== X-Forwarded-Encrypted: i=1; AJvYcCXHyBG7gCmNMgr+9S0g1KZEOAH6xydUKQ0MnhYNYjjJKaCfJ76J5bM17MQnr0ygvWo5xFibxFuxrX2YbBpm/18iJSCgSCyLFXWPaDjpyNv1HyNisipkHhhaUKUR71D1MwXpEyvmoy29Fd5lTDdlxfrF4mohJA0Q5WiKWQKFAWp4Yed6gcE= X-Gm-Message-State: AOJu0YzW7viQta0cTLf63+e5gJCtCNn1rVd/EvukCVHg/HRHKloMCEDM HoKCXRzD1wAgJgJL7tXmG94q1cDqVMDI0+DTnKTP3mU5cfyT9b2u X-Google-Smtp-Source: AGHT+IEL4+kbVpdEgcEIeKM2g4q5q9aWZiAUukl4ufvB1q01k/ZthG958aYqC8l1qn0eXx9743pVag== X-Received: by 2002:a5d:6341:0:b0:360:7279:858e with SMTP id ffacd0b85a97d-3607a7d96e2mr3276940f8f.50.1718493189156; Sat, 15 Jun 2024 16:13:09 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3607509355dsm8145532f8f.13.2024.06.15.16.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 16:13:08 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v5 20/20] leds: leds-lp5569: Add support for Texas Instruments LP5569 Date: Sun, 16 Jun 2024 01:11:50 +0200 Message-ID: <20240615231152.28201-21-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240615231152.28201-1-ansuelsmth@gmail.com> References: <20240615231152.28201-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add support for Texas Instruments LP5569 LED driver. Texas Instruments LP5569 is 9 channels chip with programmable engines. It almost a copy of LP5523 with fundamental changes to regs order and regs content. Has difference in how the clock is handled and doesn't support detecting clock time automatically, different handling for selftest and different scheme for the status regs. LED chip supports ENGINE and MUX to group LED and run precompiled code with magic values to run patterns. This is loaded via the sysfs entry and it's passed as a string of ASCII HEX char. One some devices using this LED Controller (a NBG7815 Router) it was found loading big precompiled pattern with up to 96 bytes of code. To have support for this "extended" scenario, hardcode each engine to support 4 pages of precompiled pattern (128 bytes of code) and 1 page for each MUX. This gives plenty of space for any kind precompiled pattern keeping simple logic for page handling of each engine and mux. Signed-off-by: Christian Marangi --- drivers/leds/Kconfig | 16 +- drivers/leds/Makefile | 1 + drivers/leds/leds-lp5569.c | 542 +++++++++++++++++++++++++++++++++++++ 3 files changed, 556 insertions(+), 3 deletions(-) create mode 100644 drivers/leds/leds-lp5569.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 05e6af88b88c..b1d7d94317b3 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -414,7 +414,7 @@ config LEDS_LP50XX module will be called leds-lp50xx. config LEDS_LP55XX_COMMON - tristate "Common Driver for TI/National LP5521/5523/55231/5562/8501" + tristate "Common Driver for TI/National LP5521/5523/55231/5562/5569/8501" depends on LEDS_CLASS depends on LEDS_CLASS_MULTICOLOR depends on OF @@ -422,8 +422,8 @@ config LEDS_LP55XX_COMMON select FW_LOADER select FW_LOADER_USER_HELPER help - This option supports common operations for LP5521/5523/55231/5562/8501 - devices. + This option supports common operations for LP5521/5523/55231/5562/5569/ + 8501 devices. config LEDS_LP5521 tristate "LED Support for N.S. LP5521 LED driver chip" @@ -456,6 +456,16 @@ config LEDS_LP5562 Driver provides direct control via LED class and interface for programming the engines. +config LEDS_LP5569 + tristate "LED Support for TI LP5569 LED driver chip" + depends on LEDS_CLASS && I2C + depends on LEDS_LP55XX_COMMON + help + If you say yes here you get support for TI LP5569 LED driver. + It is 9 channels chip with programmable engines. + Driver provides direct control via LED class and interface for + programming the engines. + config LEDS_LP8501 tristate "LED Support for TI LP8501 LED driver chip" depends on LEDS_CLASS && I2C diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index effdfc6f1e95..ad21941efa19 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -51,6 +51,7 @@ obj-$(CONFIG_LEDS_LP50XX) += leds-lp50xx.o obj-$(CONFIG_LEDS_LP5521) += leds-lp5521.o obj-$(CONFIG_LEDS_LP5523) += leds-lp5523.o obj-$(CONFIG_LEDS_LP5562) += leds-lp5562.o +obj-$(CONFIG_LEDS_LP5569) += leds-lp5569.o obj-$(CONFIG_LEDS_LP55XX_COMMON) += leds-lp55xx-common.o obj-$(CONFIG_LEDS_LP8501) += leds-lp8501.o obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o diff --git a/drivers/leds/leds-lp5569.c b/drivers/leds/leds-lp5569.c new file mode 100644 index 000000000000..389ed307935c --- /dev/null +++ b/drivers/leds/leds-lp5569.c @@ -0,0 +1,542 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024 Christian Marangi + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "leds-lp55xx-common.h" + +#define LP5569_MAX_LEDS 9 + +/* Memory is used like this: + * 0x00 engine 1 program (4 pages) + * 0x40 engine 2 program (4 pages) + * 0x80 engine 3 program (4 pages) + * 0xc0 engine 1 muxing info (1 page) + * 0xd0 engine 2 muxing info (1 page) + * 0xe0 engine 3 muxing info (1 page) + */ +#define LP5569_PAGES_PER_ENGINE 4 + +#define LP5569_REG_ENABLE 0x00 +#define LP5569_ENABLE BIT(6) + +#define LP5569_REG_EXEC_CTRL 0x01 +#define LP5569_MODE_ENG_SHIFT 2 + +#define LP5569_REG_OP_MODE 0x02 +#define LP5569_EXEC_ENG_SHIFT 2 + +#define LP5569_REG_ENABLE_LEDS_MSB 0x04 +#define LP5569_REG_ENABLE_LEDS_LSB 0x05 +#define LP5569_REG_LED_CTRL_BASE 0x07 +#define LP5569_FADER_MAPPING_MASK GENMASK(7, 5) +#define LP5569_REG_LED_PWM_BASE 0x16 +#define LP5569_REG_LED_CURRENT_BASE 0x22 +#define LP5569_REG_MISC 0x2F +#define LP5569_AUTO_INC BIT(6) +#define LP5569_PWR_SAVE BIT(5) +#define LP5569_CP_MODE_MASK GENMASK(4, 3) +#define LP5569_PWM_PWR_SAVE BIT(2) +#define LP5569_INTERNAL_CLK BIT(0) +#define LP5569_REG_MISC2 0x33 +#define LP5569_LED_SHORT_TEST BIT(4) +#define LP5569_LED_OPEN_TEST BIT(3) +#define LP5569_REG_STATUS 0x3C +#define LP5569_MASK_BUSY BIT(7) +#define LP5569_STARTUP_BUSY BIT(6) +#define LP5569_ENGINE_BUSY BIT(5) +#define LP5569_ENGINE1_INT BIT(2) +#define LP5569_ENGINE2_INT BIT(1) +#define LP5569_ENGINE3_INT BIT(0) +#define LP5569_ENG_STATUS_MASK (LP5569_ENGINE1_INT | LP5569_ENGINE2_INT | \ + LP5569_ENGINE3_INT) +#define LP5569_REG_IO_CONTROL 0x3D +#define LP5569_CLK_OUTPUT BIT(3) +#define LP5569_REG_RESET 0x3F +#define LP5569_RESET 0xFF +#define LP5569_REG_MASTER_FADER_BASE 0x46 +#define LP5569_REG_CH1_PROG_START 0x4B +#define LP5569_REG_CH2_PROG_START 0x4C +#define LP5569_REG_CH3_PROG_START 0x4D +#define LP5569_REG_PROG_PAGE_SEL 0x4F +#define LP5569_REG_PROG_MEM 0x50 +#define LP5569_REG_LED_FAULT1 0x81 +#define LP5569_LED_FAULT8 BIT(0) +#define LP5569_REG_LED_FAULT2 0x82 +#define LP5569_LED_FAULT7 BIT(7) +#define LP5569_LED_FAULT6 BIT(6) +#define LP5569_LED_FAULT5 BIT(5) +#define LP5569_LED_FAULT4 BIT(4) +#define LP5569_LED_FAULT3 BIT(3) +#define LP5569_LED_FAULT2 BIT(2) +#define LP5569_LED_FAULT1 BIT(1) +#define LP5569_LED_FAULT0 BIT(0) + +#define LP5569_ENG1_PROG_ADDR 0x0 +#define LP5569_ENG2_PROG_ADDR 0x40 +#define LP5569_ENG3_PROG_ADDR 0x80 +#define LP5569_ENG1_MUX_ADDR 0xc0 +#define LP5569_ENG2_MUX_ADDR 0xd0 +#define LP5569_ENG3_MUX_ADDR 0xe0 + +#define LEDn_STATUS_FAULT(n, status) ((status) >> (n) & BIT(0)) + +#define LP5569_DEFAULT_CONFIG \ + (LP5569_AUTO_INC | LP5569_PWR_SAVE | LP5569_PWM_PWR_SAVE) + +static void lp5569_run_engine(struct lp55xx_chip *chip, bool start) +{ + if (!start) { + lp55xx_stop_engine(chip); + lp55xx_turn_off_channels(chip); + return; + } + + lp55xx_run_engine_common(chip); +} + +static int lp5569_init_program_engine(struct lp55xx_chip *chip) +{ + int i; + int j; + int ret; + u8 status; + /* Precompiled pattern per ENGINE setting LED MUX start and stop addresses */ + static const u8 pattern[][LP55xx_BYTES_PER_PAGE] = { + { 0x9c, LP5569_ENG1_MUX_ADDR, 0x9c, 0xb0, 0x9d, 0x80, 0xd8, 0x00, 0}, + { 0x9c, LP5569_ENG2_MUX_ADDR, 0x9c, 0xc0, 0x9d, 0x80, 0xd8, 0x00, 0}, + { 0x9c, LP5569_ENG3_MUX_ADDR, 0x9c, 0xd0, 0x9d, 0x80, 0xd8, 0x00, 0}, + }; + + /* Setup each ENGINE program start address */ + ret = lp55xx_write(chip, LP5569_REG_CH1_PROG_START, LP5569_ENG1_PROG_ADDR); + if (ret) + return ret; + + ret = lp55xx_write(chip, LP5569_REG_CH2_PROG_START, LP5569_ENG2_PROG_ADDR); + if (ret) + return ret; + + ret = lp55xx_write(chip, LP5569_REG_CH3_PROG_START, LP5569_ENG3_PROG_ADDR); + if (ret) + return ret; + + /* Write precompiled pattern for LED MUX address space for each ENGINE */ + for (i = LP55XX_ENGINE_1; i <= LP55XX_ENGINE_3; i++) { + chip->engine_idx = i; + lp55xx_load_engine(chip); + + for (j = 0; j < LP55xx_BYTES_PER_PAGE; j++) { + ret = lp55xx_write(chip, LP5569_REG_PROG_MEM + j, + pattern[i - 1][j]); + if (ret) + goto out; + } + } + + lp5569_run_engine(chip, true); + + /* Let the programs run for couple of ms and check the engine status */ + usleep_range(3000, 6000); + lp55xx_read(chip, LP5569_REG_STATUS, &status); + status = FIELD_GET(LP5569_ENG_STATUS_MASK, status); + + if (status != LP5569_ENG_STATUS_MASK) { + dev_err(&chip->cl->dev, + "could not configure LED engine, status = 0x%.2x\n", + status); + ret = -EINVAL; + } + +out: + lp55xx_stop_all_engine(chip); + return ret; +} + +static int lp5569_post_init_device(struct lp55xx_chip *chip) +{ + int ret; + int val; + + ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE); + if (ret) + return ret; + + /* Chip startup time is 500 us, 1 - 2 ms gives some margin */ + usleep_range(1000, 2000); + + val = LP5569_DEFAULT_CONFIG; + val |= FIELD_PREP(LP5569_CP_MODE_MASK, chip->pdata->charge_pump_mode); + + if (chip->pdata->clock_mode == LP55XX_CLOCK_INT) { + ret = lp55xx_update_bits(chip, LP5569_REG_IO_CONTROL, + LP5569_CLK_OUTPUT, + LP5569_CLK_OUTPUT); + if (ret) + return ret; + + val |= LP5569_INTERNAL_CLK; + } + + ret = lp55xx_write(chip, LP5569_REG_MISC, val); + if (ret) + return ret; + + return lp5569_init_program_engine(chip); +} + +static ssize_t lp5569_led_open_test(struct lp55xx_led *led, char *buf) +{ + struct lp55xx_chip *chip = led->chip; + struct lp55xx_platform_data *pdata = chip->pdata; + bool leds_fault[LP5569_MAX_LEDS]; + struct lp55xx_led *led_tmp = led; + int i, ret, pos = 0; + u8 status; + + /* Set in STANDBY state */ + ret = lp55xx_write(chip, LP5569_REG_ENABLE, 0); + if (ret) + goto exit; + + /* Wait 1ms for device to enter STANDBY state */ + usleep_range(1000, 2000); + + /* Set Charge Pump to 1.5x */ + ret = lp55xx_update_bits(chip, LP5569_REG_MISC, + FIELD_PREP(LP5569_CP_MODE_MASK, LP55XX_CP_BOOST), + LP5569_CP_MODE_MASK); + if (ret) + goto exit; + + /* Enable LED Open Test */ + ret = lp55xx_update_bits(chip, LP5569_REG_MISC2, LP5569_LED_OPEN_TEST, + LP5569_LED_OPEN_TEST); + if (ret) + goto exit; + + /* Put Device in NORMAL state */ + ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE); + if (ret) + goto exit; + + /* Wait 500 us for device to enter NORMAL state */ + usleep_range(500, 750); + + /* Enable LED and set to 100% brightness */ + for (i = 0; i < pdata->num_channels; i++) { + ret = lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led_tmp->chan_nr, + LED_FULL); + if (ret) + goto exit; + + led_tmp++; + } + + /* Wait 500 us for device to fill status regs */ + usleep_range(500, 750); + + /* Parse status led fault 1 regs */ + ret = lp55xx_read(chip, LP5569_REG_LED_FAULT1, &status); + if (ret < 0) + goto exit; + + for (i = 0; i < 8; i++) + leds_fault[i] = !!((status >> i) & 0x1); + + /* Parse status led fault 2 regs */ + ret = lp55xx_read(chip, LP5569_REG_LED_FAULT2, &status); + if (ret < 0) + goto exit; + + for (i = 0; i < 1; i++) + leds_fault[i + 8] = !!((status >> i) & 0x1); + + /* Report LED fault */ + led_tmp = led; + for (i = 0; i < pdata->num_channels; i++) { + if (leds_fault[led_tmp->chan_nr]) + pos += sprintf(buf + pos, "LED %d OPEN FAIL\n", + led_tmp->chan_nr); + + led_tmp++; + } + + ret = pos; + +exit: + /* Disable LED Open Test */ + lp55xx_update_bits(chip, LP5569_REG_MISC2, LP5569_LED_OPEN_TEST, + 0); + + led_tmp = led; + for (i = 0; i < pdata->num_channels; i++) { + lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led_tmp->chan_nr, + 0); + + led_tmp++; + } + + return ret; +} + +static ssize_t lp5569_led_short_test(struct lp55xx_led *led, char *buf) +{ + struct lp55xx_chip *chip = led->chip; + struct lp55xx_platform_data *pdata = chip->pdata; + bool leds_fault[LP5569_MAX_LEDS]; + struct lp55xx_led *led_tmp = led; + int i, ret, pos = 0; + u8 status; + + /* Set in STANDBY state */ + ret = lp55xx_write(chip, LP5569_REG_ENABLE, 0); + if (ret) + goto exit; + + /* Wait 1ms for device to enter STANDBY state */ + usleep_range(1000, 2000); + + /* Set Charge Pump to 1x */ + ret = lp55xx_update_bits(chip, LP5569_REG_MISC, + FIELD_PREP(LP5569_CP_MODE_MASK, LP55XX_CP_BYPASS), + LP5569_CP_MODE_MASK); + if (ret) + goto exit; + + /* Enable LED and set to 100% brightness and current to 100% (25.5mA) */ + for (i = 0; i < pdata->num_channels; i++) { + ret = lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led_tmp->chan_nr, + LED_FULL); + if (ret) + goto exit; + + ret = lp55xx_write(chip, LP5569_REG_LED_CURRENT_BASE + led_tmp->chan_nr, + LED_FULL); + if (ret) + goto exit; + + led_tmp++; + } + + /* Put Device in NORMAL state */ + ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE); + if (ret) + goto exit; + + /* Wait 500 us for device to enter NORMAL state */ + usleep_range(500, 750); + + /* Enable LED Shorted Test */ + ret = lp55xx_update_bits(chip, LP5569_REG_MISC2, LP5569_LED_OPEN_TEST, + LP5569_LED_SHORT_TEST); + if (ret) + goto exit; + + /* Wait 500 us for device to fill status regs */ + usleep_range(500, 750); + + /* Parse status led fault 1 regs */ + ret = lp55xx_read(chip, LP5569_REG_LED_FAULT1, &status); + if (ret < 0) + goto exit; + + for (i = 0; i < 8; i++) + leds_fault[i] = !!LEDn_STATUS_FAULT(i, status); + + /* Parse status led fault 2 regs */ + ret = lp55xx_read(chip, LP5569_REG_LED_FAULT2, &status); + if (ret < 0) + goto exit; + + for (i = 0; i < 1; i++) + leds_fault[i + 8] = !!LEDn_STATUS_FAULT(i, status); + + /* Report LED fault */ + led_tmp = led; + for (i = 0; i < pdata->num_channels; i++) { + if (leds_fault[led_tmp->chan_nr]) + pos += sprintf(buf + pos, "LED %d SHORTED FAIL\n", + led_tmp->chan_nr); + + led_tmp++; + } + + ret = pos; + +exit: + /* Disable LED Shorted Test */ + lp55xx_update_bits(chip, LP5569_REG_MISC2, LP5569_LED_SHORT_TEST, + 0); + + led_tmp = led; + for (i = 0; i < pdata->num_channels; i++) { + lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led_tmp->chan_nr, + 0); + + led_tmp++; + } + + return ret; +} + +static ssize_t lp5569_selftest(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + int i, pos = 0; + + mutex_lock(&chip->lock); + + /* Test LED Open */ + pos = lp5569_led_open_test(led, buf); + if (pos < 0) + goto fail; + + /* Test LED Shorted */ + pos = lp5569_led_short_test(led, buf); + if (pos < 0) + goto fail; + + for (i = 0; i < chip->pdata->num_channels; i++) { + /* Restore current */ + lp55xx_write(chip, LP5569_REG_LED_CURRENT_BASE + led->chan_nr, + led->led_current); + + /* Restore brightness */ + lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led->chan_nr, + led->brightness); + led++; + } + + if (pos == 0) + pos = sprintf(buf, "OK\n"); + goto release_lock; +fail: + pos = sprintf(buf, "FAIL\n"); + +release_lock: + mutex_unlock(&chip->lock); + + return pos; +} + +LP55XX_DEV_ATTR_ENGINE_MODE(1); +LP55XX_DEV_ATTR_ENGINE_MODE(2); +LP55XX_DEV_ATTR_ENGINE_MODE(3); +LP55XX_DEV_ATTR_ENGINE_LEDS(1); +LP55XX_DEV_ATTR_ENGINE_LEDS(2); +LP55XX_DEV_ATTR_ENGINE_LEDS(3); +LP55XX_DEV_ATTR_ENGINE_LOAD(1); +LP55XX_DEV_ATTR_ENGINE_LOAD(2); +LP55XX_DEV_ATTR_ENGINE_LOAD(3); +static LP55XX_DEV_ATTR_RO(selftest, lp5569_selftest); +LP55XX_DEV_ATTR_MASTER_FADER(1); +LP55XX_DEV_ATTR_MASTER_FADER(2); +LP55XX_DEV_ATTR_MASTER_FADER(3); +static LP55XX_DEV_ATTR_RW(master_fader_leds, lp55xx_show_master_fader_leds, + lp55xx_store_master_fader_leds); + +static struct attribute *lp5569_attributes[] = { + &dev_attr_engine1_mode.attr, + &dev_attr_engine2_mode.attr, + &dev_attr_engine3_mode.attr, + &dev_attr_engine1_load.attr, + &dev_attr_engine2_load.attr, + &dev_attr_engine3_load.attr, + &dev_attr_engine1_leds.attr, + &dev_attr_engine2_leds.attr, + &dev_attr_engine3_leds.attr, + &dev_attr_selftest.attr, + &dev_attr_master_fader1.attr, + &dev_attr_master_fader2.attr, + &dev_attr_master_fader3.attr, + &dev_attr_master_fader_leds.attr, + NULL, +}; + +static const struct attribute_group lp5569_group = { + .attrs = lp5569_attributes, +}; + +/* Chip specific configurations */ +static struct lp55xx_device_config lp5569_cfg = { + .reg_op_mode = { + .addr = LP5569_REG_OP_MODE, + .shift = LP5569_MODE_ENG_SHIFT, + }, + .reg_exec = { + .addr = LP5569_REG_EXEC_CTRL, + .shift = LP5569_EXEC_ENG_SHIFT, + }, + .reset = { + .addr = LP5569_REG_RESET, + .val = LP5569_RESET, + }, + .enable = { + .addr = LP5569_REG_ENABLE, + .val = LP5569_ENABLE, + }, + .prog_mem_base = { + .addr = LP5569_REG_PROG_MEM, + }, + .reg_led_pwm_base = { + .addr = LP5569_REG_LED_PWM_BASE, + }, + .reg_led_current_base = { + .addr = LP5569_REG_LED_CURRENT_BASE, + }, + .pages_per_engine = LP5569_PAGES_PER_ENGINE, + .max_channel = LP5569_MAX_LEDS, + .post_init_device = lp5569_post_init_device, + .brightness_fn = lp55xx_led_brightness, + .multicolor_brightness_fn = lp55xx_multicolor_brightness, + .set_led_current = lp55xx_set_led_current, + .firmware_cb = lp55xx_firmware_loaded_cb, + .run_engine = lp5569_run_engine, + .dev_attr_group = &lp5569_group, +}; + +static const struct i2c_device_id lp5569_id[] = { + { "lp5569", .driver_data = (kernel_ulong_t)&lp5569_cfg, }, + { } +}; + +MODULE_DEVICE_TABLE(i2c, lp5569_id); + +static const struct of_device_id of_lp5569_leds_match[] = { + { .compatible = "ti,lp5569", .data = &lp5569_cfg, }, + {}, +}; + +MODULE_DEVICE_TABLE(of, of_lp5569_leds_match); + +static struct i2c_driver lp5569_driver = { + .driver = { + .name = "lp5569x", + .of_match_table = of_lp5569_leds_match, + }, + .probe = lp55xx_probe, + .remove = lp55xx_remove, + .id_table = lp5569_id, +}; + +module_i2c_driver(lp5569_driver); + +MODULE_AUTHOR("Christian Marangi "); +MODULE_DESCRIPTION("LP5569 LED engine"); +MODULE_LICENSE("GPL");