From patchwork Thu Jun 20 21:03:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 806844 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 B956A80605; Thu, 20 Jun 2024 21:41:36 +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=1718919698; cv=none; b=Af6uLoqGo8AVj4xU4xEgsdyCEZjgl25LIjSeeq/ItLML5dTHkndSDH3mUxDvLewqpVeIjUGxGLCQbdsG3bkR++EY1lG3f0c4bb9wruN8pnqzl/2BaunyG3kLBG9xbTb/nezxMYNn362DroeJ+DG2bb6oVomlwOMpmOJWDSinWME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919698; c=relaxed/simple; bh=qIfrIKATqfuPjRd1rJItllla07DSiqttjga7AD3nt70=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OShQXk4NFe/dnTX4Upozv9CzeFpZ91pnU662EuN+SO//pqai33hUxeg8rbwf1tT4ar6cV9vTfvHrSA6kjpqFY9aXgUGKlt8vUo/MxJs1fAcKVEIA0clbS0E8cxRbhCOWwsx0heFZRdC12mZ1nNW9FbHttkjli9bV79ZQLVQQevA= 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=Ia1YVTJU; 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="Ia1YVTJU" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4217990f997so10940905e9.2; Thu, 20 Jun 2024 14:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919695; x=1719524495; 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=UO3bPIz654pf/D6EIkpGpwR8o7HByTNexKTs9bSHTKU=; b=Ia1YVTJUYGWoboidLnoYCEA8opzxMZTmANN0z7KxB3lDXAX47LIn6mS8P8Yji3McN8 v5hIXEP71ioslhr38/C5TalnHz9cFtB+IvgWPJiMVIg4E1hXqYlgdEbXQgnyPdmTjdU6 7kAjWQEGPfacUPed/ts6s0pJbVzFaqM1nmMWdNtVLbsGhuTM2PA+UHOJKdPvIaMBL52U mX/O0ORiTFnpJoG8eYGFj1jhYfF1b4s1912q304ApTd/+VYmr+a/xUBfaydpE9lmV1pE fcC531Dq3Rk9fltO++fALN8Up2d8a4Jnj2lyy37UXcbUcmJ1aM7LqBHnN9uvMHhd8R6f lywg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919695; x=1719524495; 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=UO3bPIz654pf/D6EIkpGpwR8o7HByTNexKTs9bSHTKU=; b=pVT5iseLnjwTcLeJQcrBqgZJNOuXVxLzZTYfkk6rJQAyV/+844UonFIDfyMg0W3nau iJfu6zFXtQwkpeouADI9mcDA9z7FwpSNOLwiMEw0VkoK3Hc3zMtnpxCGabGFAvT1H+UK k9FjP6aaSnIJovTsA2b6/Wjwd/nX1ZtyJrZCQCuP5ggzP3ccDRUgL1Z/0Oes9VQ/fGTx 7rrOyBuSGg1Fk4uR7Zrc5TmIXYNjaCcBBoOKgVMaGc+IUdxIQmNJWKVtjpw+aJACM6gF HvPcKmu7U48+dh4ZMJZjEgkGQlpfBRw5Gzl+cMzwevJIlVNwUivSVvY3T1ei68h42jnl JWPA== X-Forwarded-Encrypted: i=1; AJvYcCVySfdTMs34ti377mw8qd+KbOZqYDHfwOAH/60+DrcponXWA1dcixy5aIQD8+Yt90O6eymwMBVZNysKWtTb6U+RopgcEEvGh4Dz+qFfrsw3FDSzU/xhjBtW9DwVAbxDZY1yNML884yCJJnw3rzF4Ae2yV5i7z1oSBKFIaerSxHQktIxEwU= X-Gm-Message-State: AOJu0YykIn+Y0eBczCiUKRC5S3Zui+MaHPvYq0T6LS0ul2lFu7TYX3Rd DWZtqYTKdJ3fsnO71Zag64Q1StrQBQJeVab8ZYhzLX/0gEg7FtAi X-Google-Smtp-Source: AGHT+IFEzWusxFXvMZvw4UyCquqT84VRYUFkbHavE4G7q+sRDOdCEFBP5v2CiIv83oXTkKD3pDnYdQ== X-Received: by 2002:a5d:6a51:0:b0:35f:2a43:3b16 with SMTP id ffacd0b85a97d-36317d7365emr5143753f8f.33.1718919694915; Thu, 20 Jun 2024 14:41:34 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:34 -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 v7 01/20] dt-bindings: leds-lp55xx: Limit pwr-sel property to ti,lp8501 Date: Thu, 20 Jun 2024 23:03:17 +0200 Message-ID: <20240620210401.22053-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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 Thu Jun 20 21:03:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 806147 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 B9DF584A4E; Thu, 20 Jun 2024 21:41:37 +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=1718919699; cv=none; b=F3RhY6UCtQg3pv2aZBFj64fdjIHKzaSQ+Y9MG/H87C1E9fHy4GL10gTHXb/lGvA+lyWzYg33vW761XdDiNFBukVdCBqjK/+Q/9AV5iM98o4EiG/4w444JNFEMEJv+PNQBCRnRdTj2pTVX5bAWzAU8h89MmTBhxIHhaxXJDk4f0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919699; c=relaxed/simple; bh=3eWDuOuAPXIqwQ37BEI/rk2/PA31lRgF9hfGMCW6fwg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PXfwuglir4x/49alf1OLaVByL4yDWp51LJM4hagrowPPuuAbzaNsUUwtPgmKfxA2Pq5+5lFzHA+X1tVMRQmWXnm0qTrUFmV2c0hQgR2JXPLM3fXADiJS3Z8mbEH1crwlfdGu5HRpl3k0BYnloU2AMEMtjmjex1LORcZ/vhCg478= 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=M0Y5gYJo; 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="M0Y5gYJo" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-362bc731810so1336428f8f.1; Thu, 20 Jun 2024 14:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919696; x=1719524496; 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=21mSbP0lHQ/HlE9P4YVvtfNI3i5USmGh/e5NZFrr3Ik=; b=M0Y5gYJo9Apnc9P5zMYUUpR5IxWg5gumJd/9U5OGgBXGdVA9qsRti95wd57dTP/qYe s+pRR6VKG7kEFElO/x7hq9UhKfDAVc8SyZN6b67/n5TQoNzYhAFz6uk/taEJ8XiJxxQE ZhY50Er8Js+Qzh8ViH0V5i6K9sBqdfr0GimOikPjLC2rVo9M8+Opi2CWsoggTCuWrjCN 5t/v6ve8qlSov7tS4Cux34sOsVkLlr9GFg/fTGUcBo3Ts8HMbq1lPUjVL/Z//4MhUn06 f4PAvMDA3qXvAf9wo8Dg6APWcBWg0laVzpKy2QjrgmGbJh73C/tj3P0ebqxNcNNZ8bBN C0EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919696; x=1719524496; 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=21mSbP0lHQ/HlE9P4YVvtfNI3i5USmGh/e5NZFrr3Ik=; b=UJq47vk36n0l9IhoYUOpFXDmODEpQfYN1NGmTFUlZ9Ida+vssFnAfY+xjgn69ov1ce Rpqjz8Iz680ijymJhFi1/WoApwHYSkMbctC2PpQfrKmR+pTSizkv72bbd6JJBI542YjB n3U/rbgHtAuNBC0CbZG9MdNQ3ELnQzwzetETkZCluU3mxy8R1VcqwbBsiiksT6s1dfFv fkealZpXVGQFCJFmpIApu++6IcBLSnmFfKx348so7Iy082rKsskgXo2Xp8KvLXDAp+/u BKm2Twc/8+D4IjZtC9zogLGH1M7RTiXzuNyDevlu6nBURkrA/AsdH9fwXRO5zLH0Q5Yy qaVA== X-Forwarded-Encrypted: i=1; AJvYcCXOM0IdocnH4hdb3BPdYSpbhjwmautMyXfNDSCvF6+8XclI1Zlm6MaeiR6FAMoHh4usJip/vX6nXxYOoWWgwVSJbBHqugA7f2n9XYSDqqsbnwsTr7Aco39ALRvjArPDApXdkPKN5jteq2Py0Hm7s/fHowdIJrwd7Y1MqilImgylIYifhuM= X-Gm-Message-State: AOJu0YzUKf3fQODgEiGf1TgfPouqsABeEKXFE5jxHwiu1Y+i8Y8Z4/oY BBA6oeex36jmmtiOHaKrLXkSD6fUlzoifroNDddcl9tX9FHhgpeo X-Google-Smtp-Source: AGHT+IEFLIX+wmCXEP2Yfp8YMkEfiHh13M0ZPa6i8iEJE3ko0z+kBvgeh+lwvV5q3eazQaT1PARBRA== X-Received: by 2002:adf:e909:0:b0:360:9d1a:a8d with SMTP id ffacd0b85a97d-363170ed4a0mr6241422f8f.13.1718919696101; Thu, 20 Jun 2024 14:41:36 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:35 -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 v7 02/20] dt-bindings: leds-lp55xx: Add new ti,lp5569 compatible Date: Thu, 20 Jun 2024 23:03:18 +0200 Message-ID: <20240620210401.22053-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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 Thu Jun 20 21:03:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 806843 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 088751369BB; Thu, 20 Jun 2024 21:41:38 +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=1718919701; cv=none; b=UnLnU8DNEp3TUHS9roPV3yCPWd3vj/iglrO+p4Pq1wQ4dYXUR1Py+priOFo6zqoaFxbAFS1NVriTY4sfEeOaH4egP4FCQMOdixkgD6/ACFV0lpTc2sfB8McSBk/rw/etXpmfDxUx7MB4lXp311SPpM+Z9M0DM8wQO5JTXdln9Js= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919701; c=relaxed/simple; bh=sE7BEi0V3MPo7LYVvCaONFV2uxx5c3Tzjkb8r1lhILc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BO8i1bqH5QXNYghwBjkjHt6cGlLoxp1r+dBg4k3fFLaT9UaX4qSUe/pwqFYHo/+o8Lc+JbxSp37as+E3+MQCfYv7t4S2NQoFlW47IHC4QhYQqS8VE8UGpvKcuH1SRgXt9KYInhbSAwAuaQZalsVjzn6npFXIazzYeWpXCa49+7E= 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=dbMPQfEi; 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="dbMPQfEi" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-364a39824baso1095499f8f.1; Thu, 20 Jun 2024 14:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919697; x=1719524497; 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=KjPisN1PMRe1qse8O7opznHt2cXkcbQFbYa4pfP3ZFA=; b=dbMPQfEiWkQh9XVkpUNYgZ7CXFyfJpgImPxVq5i/oZTOg+IaCSZefliO1dXsxDwPOd lCudOM0YQIFjIq1p7x1S0JE0h60xTNiwKLC3tx+ISzvFGe+Ms/LnLwbL4i1I+5kVHVEW 4I0enkBa5bRtTLzSzAOo6l8Y3QLWS/1mWUH3mptvcNqzyqxxPRGT8bdu2JYBG8QISwGW yDPUq74j1EgAvr2fd0ZOa/f2l1rmPl9bzWAGpYW6KYp7ZwGCZCTIHwPl/b1i1iWTUfnR rMsQvSFQy3Mv7tGrNsjPks+jZnmcroI/tyweepvsJepxb6LIgQbl65yc2xuZGlLZFMI8 R6pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919697; x=1719524497; 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=KjPisN1PMRe1qse8O7opznHt2cXkcbQFbYa4pfP3ZFA=; b=SQPBK/5XQjlfH+ehP3duLCdp0lk/0EJi81iasTySEXsVJpKO/WAgm7gMyGARtXtpdp 7ONFwZqcK8JMxkzglhqgo+VnjK5HeqE9AEB1VlK2MpkJoYxkOxy2FJtqmjc8BGssdL2T cUIoYSeEGbzbVRQIBh70LTt1XanEakWjBhQBisoOP9TXfvneCMUXxBJsXrBCXmBeNvVG izSooGoUy3iEOeLWvQGZdJbXFdPq5Oqszk67DMaL41HVgFDO6Cipgnsxd8pc8WEqzmTi pT3Ng8n+bZ2jIFBVMhUP7GCSa8gkiVwxCCt3CqA+JXcSIg3DJsA+W9CvSH2/gCJICIcr bNRA== X-Forwarded-Encrypted: i=1; AJvYcCXzqO17jlFQxl5Xa8z2Y9rhuIuNnBn58CsuVVf409hwxUPm+3dOrySUYwjZh7CxCWF9q20zWUO04Nlhc7SUDJlRfkLBiF6JjVAlj4DAScksF5EgywNiULvI6p3aUnHJ/EiLQVA0rK+XCh1ztvUXIds+kkRRS/DGy74x/DTLV0YHpWrmYGI= X-Gm-Message-State: AOJu0YykHNsZ39hKFNqrcml52V7gTh8GF1iR5ssCypr8FzcwW8XvNDJG w51vu8iZr9pdJ/+dfNtXXDaA3Ql0roMqfo8qNdi2hQ2SDiNQXxHO X-Google-Smtp-Source: AGHT+IFRyQ1cKxar5w++zr3kxXPLXeuUhcUTrHGza3Xaca0Gv23+bViZpUj8pOwfnCjW4OuHlE/9Xw== X-Received: by 2002:a05:6000:e50:b0:35f:1128:2514 with SMTP id ffacd0b85a97d-36317b7920bmr4637046f8f.32.1718919697166; Thu, 20 Jun 2024 14:41:37 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:36 -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 v7 03/20] leds: leds-lp55xx: Generalize stop_all_engine OP Date: Thu, 20 Jun 2024 23:03:19 +0200 Message-ID: <20240620210401.22053-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones 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 | 36 +++++++++++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 16 ++++++++++++-- drivers/leds/leds-lp8501.c | 20 ++++++++++------- 6 files changed, 84 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..2cbc5b302fd4 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,35 @@ 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 __always_unused 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 Thu Jun 20 21:03:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 806146 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.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 3622913F439; Thu, 20 Jun 2024 21:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919702; cv=none; b=N/J+oTeb069Z82LoTHE8RgECpeZ2cAhHFzcJdcewQYWoAnUVseRPtNosuhrVoQMwlz/Jek03W/0emsC3Fu0qczvTkMxmzdnBXpvU3LZ1Izc/sPGZ97NY6rHsPDZyYDMVIu8GoNHCanwPPvVwjYptyMlHKXHRh2fmIPlMad23SVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919702; c=relaxed/simple; bh=rXcU8iiU1Iw3qaeUh/u0Y0vxeXXw0aYyFmlBEnJt+vM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AQtkGu0niZzp7tcP/r5dbDV/5w56OuPYB/CYAHIO1TTQ+AOQmsvuG6SnSSHZeJ/TGyVVhhUZKmUnFJGQNoUZCaWSGWOnsFTZcRxiElSE/O4bzAfZXgl4vYbO1tdfRUdwmtM4Fc0V8xAnRcxJQOhEgdNU5c6qpLOki8TsyTw8jM4= 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=k/G32jHb; arc=none smtp.client-ip=209.85.128.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="k/G32jHb" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4218008c613so13101635e9.2; Thu, 20 Jun 2024 14:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919698; x=1719524498; 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=MKRnVk20sBZCF2C/tq3Dlx1M0E6+DdeiFmOrQ03dDyM=; b=k/G32jHb94LC0ZyWl9omwHJhRGh6GgulyaHCayJXEUiR/DN6kYGIc8Jdb5+TpQ67eu t+Gglm6dGyVVL14+rafqrVIfNZ0xNCMejEl5U/urYcleb5KokcbnW3mqmpJbHbcegn85 aZKlgNRSZmXcWEt2n0nynUDYEZGSH75zjIOBwwaxE2g1TPaT5wLD/15R3mr9fSU0uVQT r5K6WhH3UtYub4xWydA5uTod4kiH7Vqsor91YIQVTcrVchaIccJWxWAR8CT4xZYp6bZP Ca6jEMkCnb6R+SNf5QwAS9P27elslRPO2g20y5kGDIonOuOspkWHdXy7R8iACTS5s9BS Uxgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919698; x=1719524498; 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=MKRnVk20sBZCF2C/tq3Dlx1M0E6+DdeiFmOrQ03dDyM=; b=jYlxjjfSGF4WrWCrxVSeSmuWdxpmLEQm9fRuER659Ypl/9sVyoU95iRxerM8J2ujuQ LRqtmh4WxggQPAVtbdLYlmt2LLZqb/NGAhhL+pPtTUI27lB92qA4Qkq/4EvhvI9rQrFE r8AZ1NWAMX462cEzoWRfsEDnDBiS7Kr47KMG9UvfS6Tb/w9nYs5Cq0DLU5XaxSoHT6n3 pN0udzvT2HLF86yQYNKCzKRYhckWAH5mE26wY/yYY+x7amH20mLjWKjAA7il0PkdpOhs 9srR25fj25477KykvRramHnUmJHrUGBY1FjLRhEnRNebv2rapV0oCiR23f4BbV1ipCUF BG5g== X-Forwarded-Encrypted: i=1; AJvYcCUl2d+AayuqBxeDXEWpH85Wh5mpj+GM9gFtTIzUu/HzhWA8Lmvrd3efieiRU4VD/fZxzQahgvZjdrTkKu7zL8UiW7MRS8DPCiVzukhwOvI8zfjhz7s2Gwqe76zAG/xXDzYDJmjeKCbVnTL15J+qGQVMGHIaqM5RYUbwsQm78WBzKqWQOpg= X-Gm-Message-State: AOJu0Yz6PwKgbuhyJueUa7CtYQfq8gHOHuj1AXyO+L08OQGRI08Ynlkm phoPnHXlGg7dMiNJNlRoAjyswFDpGLUPHZMd1TEy0KrmyPBjwk/r X-Google-Smtp-Source: AGHT+IGRDCu7BN49rTEA/ox+gphmnVYnzy+qnc0tesEguaD0LeYAnACtrGK3tCuncwrmjA98dGQzBg== X-Received: by 2002:a05:600c:9a3:b0:424:7d6a:dd2e with SMTP id 5b1f17b1804b1-4247d6add73mr23834635e9.19.1718919698367; Thu, 20 Jun 2024 14:41:38 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:37 -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 v7 04/20] leds: leds-lp55xx: Generalize probe/remove functions Date: Thu, 20 Jun 2024 23:03:20 +0200 Message-ID: <20240620210401.22053-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones 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 | 141 ++++++++++++++++++++++-------- drivers/leds/leds-lp55xx-common.h | 21 +---- drivers/leds/leds-lp8501.c | 81 +---------------- 6 files changed, 127 insertions(+), 362 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 2cbc5b302fd4..2949ea56a170 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -49,7 +49,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 __always_unused ret; u8 val; @@ -69,7 +69,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); @@ -78,7 +78,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; @@ -88,7 +88,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; @@ -111,7 +111,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; @@ -176,7 +176,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); @@ -187,7 +187,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); @@ -197,7 +197,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; @@ -459,10 +459,21 @@ 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 void lp55xx_deinit_device(struct lp55xx_chip *chip) +{ + struct lp55xx_platform_data *pdata = chip->pdata; + + if (chip->clk) + clk_disable_unprepare(chip->clk); + + if (pdata->enable_gpiod) + gpiod_set_value(pdata->enable_gpiod, 0); +} + +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; @@ -512,24 +523,11 @@ 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 int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip) { struct lp55xx_platform_data *pdata = chip->pdata; - - if (chip->clk) - clk_disable_unprepare(chip->clk); - - 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) -{ - 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; @@ -566,12 +564,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) @@ -585,19 +582,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, @@ -690,9 +685,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; @@ -749,7 +744,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 Thu Jun 20 21:03:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 806842 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 3934B14373D; Thu, 20 Jun 2024 21:41:41 +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=1718919703; cv=none; b=nkDlGfBYK8Yy/k704MFohX5c6qyy13WDdRfbQNdjfHNCmQZbY5FHqTXweCufihAjLFKuyYWtvubZgFHWnT56BrZcxjwR5gJxEulY+rHDqrHEQbwYT/Sz7YM8M48nUR7FjSqgQGzZ8bz09i8n1RhTtykSkcS1McyMXba2PgVr62M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919703; c=relaxed/simple; bh=k1mXjvx/G8zS0uIhmuzJpBHoZ+lhLAJjEsOyhtMNUTQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s8Hg/JTpvjLvklPDVk/Y1xtIoaMjxrLp+RRrh2MlAiMOT7/TeH5qOuhSYKAwqKnqNDzdyqu9HU197SDldkWpeOR3zLtukqbHRJ2xwfF1w2AkKwnHqjKTBl+rioQ5r8qO7eW+ypNFKg5siQB58S92ja+QZmfRbuJQHGrExLDvQgM= 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=eU/rMTzP; 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="eU/rMTzP" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-364a39824baso1095520f8f.1; Thu, 20 Jun 2024 14:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919699; x=1719524499; 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=Y8U8NBtMm/u2IVD8/kM9yB3umzeKyozmtPIP44s+PjY=; b=eU/rMTzPW1ulpZmJ0E0Yfu5jrDeBuAwisK7GTVjfbDqQaeSkGOCO2ct/rM/ShG6tAX mz1ILXJzvi7TCwAVdEkqW9GNBya3hOGT1E8OCdXrD4/1wZ4/8IgbxWo0YyXDRyTrd1+L LxYu9HDBaQzHpMXDW0kWOhH5vWxNsWhZh7dfM2Zs3D0tCLrJFGiN/tHyUWLrhow4PoS/ Y5/sEqKtaDjAjrQg15pC2P+P89/czs43ecCTnsgpkV8bax3A4lguGR7beUtUiMSnCch/ HryyhFKberOe9us9leoU61eeFlrcO3YIXPN7CDO4Vk9Qg+EzuAP9PAthJfxC1DB1KDZi eC4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919699; x=1719524499; 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=Y8U8NBtMm/u2IVD8/kM9yB3umzeKyozmtPIP44s+PjY=; b=i9btxbPLfss5BETf9MsGRweXgJXrCFzH1aUIbR1CHLUk8J/8jwx64Cdx+zfN7JPWCE qOl4kBTzR2tknQxth+bjlpcv3iz7B6Ucn/ruWF4XXp3cKRrR2QBKTF6Qscdxp+61Ksu0 u9wolz18+Rq5f8LtD6Ik+bd3BrkNojinGXVtBEwt1HAAbjXacfF+beaInplwoZOWxCrK HyLT/wyTgOCaNcd41FJrd2O35WmAjoaNBrkCdGnMQfHqXl7X3lX4rObwoxV9TqNRlb/k 0mESXQesAiX0BJE9F6BgewLc058MbjiWoD8dQ35U3F4qcqBOCw3Ex1UmWo6JhVMx6/u/ x44g== X-Forwarded-Encrypted: i=1; AJvYcCXaA+jWZGbnilNlyz8B8yrFYZBEERAEAXrFLC2SbXoU1ln0rzVwXKlXtUj90jiNVI/V7GJ4UpZHlZ9Kr6v21CgKSGWVt1zCI7X2B+2oE08iZNAeqJ46KnFfw08UZiWPLX/i7jXnMyNaVQ/BsIfa8hmSagL3ii5r6zWQQa/Fbv/g5+OIJ4k= X-Gm-Message-State: AOJu0Yz27J8uhHCVAHIXBrfKSgtB498fyvPfwrf5u/LlKHCp7kANqmDu C/f2GVK2XeJac+hoO4HTOO4kH8XF+VTN9b+R1HJ9yi0nczxIz1eQ6GRMRQ== X-Google-Smtp-Source: AGHT+IHsvAbpWfMA3+B/I7g4oI+WwGIW+26bofaf8uy/t9lMfPUWhc3jZsW/7FTkiLBfhUSlTqdpVg== X-Received: by 2002:adf:e508:0:b0:361:93d5:782f with SMTP id ffacd0b85a97d-36316ff8165mr4569354f8f.9.1718919699590; Thu, 20 Jun 2024 14:41:39 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:39 -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 v7 05/20] leds: leds-lp55xx: Generalize load_engine function Date: Thu, 20 Jun 2024 23:03:21 +0200 Message-ID: <20240620210401.22053-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones 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 | 33 ++++++++++++++++++++++++++++++- drivers/leds/leds-lp55xx-common.h | 1 + drivers/leds/leds-lp8501.c | 17 ++-------------- 6 files changed, 43 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 2949ea56a170..3461158ad372 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -9,6 +9,7 @@ * Derived from leds-lp5521.c, leds-lp5523.c */ +#include #include #include #include @@ -26,8 +27,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 @@ -76,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 Thu Jun 20 21:03:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 806145 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 665CE81AC6; Thu, 20 Jun 2024 21:41:42 +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=1718919704; cv=none; b=X1xOSPEmGtdP8RniY6T08hXxHVeTFJgabPkJ8FTyZZgVpwy5+TiEg+N2dLWyCSC8MVjD/l0GduLicGCjlIlTP8RMMYT5AM1ebSFz/WiHA2z3yJWZydeuwK8ugdq2I6FYD81SDw/Pi1z85MGm5qfzg9x8Cki220QD5f+X01YU70c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919704; c=relaxed/simple; bh=93mLiP28wcMMSQVfz1jQoVHsOuQ4sq2xtPfGbLAzlCA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hcapR5mMn/M99Sfc3P4hqmAhvDM4l4d1NjAoIpd4MS1MMT9mSSrOq07xauTl8j9TofqLuxRSLqxIvn2IzYoXEmOAR0qe28K1KsHAgCak3yUU+dVLaa/zhpVIpTij/GtAhitS3EzXML0TwLPQpRvjrQPEQsj0tpn5SETHkltkCZ8= 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=LOZrgZ7K; 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="LOZrgZ7K" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3621ac606e1so1512575f8f.1; Thu, 20 Jun 2024 14:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919701; x=1719524501; 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=Geth/2KKrcJZcCPnaOdrUx/dTUWfUCygBMVeN3xinMk=; b=LOZrgZ7Kudk7i8l8C8YVGJYyi5hD4LBed/RC1sErIpEk7CMfzhamNju3RWbvlO97Z9 gUOuiJEu6N5H6HU0Jj7/36XS6t7AYB6bi1HZOeBhVpV1U3erYFWZWtkO6znvNgorA9qi lTEgzV27gZUpnVuUwcJIMMfr4P+N9UNIi1GY8EGysnweMyGYiFalJ/XRDbWQPu4hzuVn RaSLDmeuy8f0gQdN+6WxuWLAfRCiDWF72BSgc/x1LCd5ZaVOIjPlnp8ROoSxMP56Fn/6 NQXu3EkMHxPfS/FnU88wIkNy+pcildCYcsn6d63v5/qbVJjQ8Vb1+WJXB5COb9YZX/1m J31g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919701; x=1719524501; 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=Geth/2KKrcJZcCPnaOdrUx/dTUWfUCygBMVeN3xinMk=; b=t21dnZUgyyBftLK/7XncOtWLKw3cIXy2fCIhpgatnahwBUfy83pSZaYjyoNicGJOJF h782wlkqDbjLSyzqkNNZs/iYb7A3pKfI5Jucs4YfzbZKFyIla4iu3nu7y6/u6W2Vur+c EkvfxKTIh9Uqv75S/8zPEL6CkBC7TgJrzvhjCXYcXLkAGgfa6WWOCNNp9SV9QykP+bro gcxNG1Mks+2P3GDLofz5+KhUMEz6thTfM6iIsMG+OAlZIWoi0UnWBfo832HSBEagK+wx SXbbtbrvMBLMLQ1Js2VMLw1EX6+JH85wZC/oWF3k1BEVUDq8jzzBakZlFXmAOhzDrmR/ CsMQ== X-Forwarded-Encrypted: i=1; AJvYcCUvh5UZTPwHUm92YrQt52fJe3wcpPHQk5GUKDxuIw/acf4Ef4DRudipbwD+X7K1ORVkWXiI6XH/K8QVkHjyg3vMWY1XHAKm9viY31LE/MG+twlmqrwWs/09CrzMHhEhMY7fIBW17c4vCUZCMj+rKsqRQeuXoNFOMsr33iL6tHrlFjTMcrI= X-Gm-Message-State: AOJu0YxsJ3NZv44NONJjnzWbnHXjNPqTAnggvTHwEusLEj4m4iQfu91J jLDxncqe0uT5pfVRr912PtPve0dJlCJmfJaI7f2G0FENPi/eRUJS X-Google-Smtp-Source: AGHT+IG1AtB/Je5Y5QUAK/S/XjPd8hsBxT00S04mpmksVGV5uVHlNRIzKYvaX9QzfM0UDUeWj4mxeg== X-Received: by 2002:adf:fa81:0:b0:362:8f0f:1c7c with SMTP id ffacd0b85a97d-3630191cb58mr6212487f8f.33.1718919700654; Thu, 20 Jun 2024 14:41:40 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:40 -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 v7 06/20] leds: leds-lp55xx: Generalize load_engine_and_select_page function Date: Thu, 20 Jun 2024 23:03:22 +0200 Message-ID: <20240620210401.22053-7-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones 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 3461158ad372..38564b9cda0d 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -46,6 +46,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 Thu Jun 20 21:03:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 806841 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 7C84614D45A; Thu, 20 Jun 2024 21:41:43 +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=1718919705; cv=none; b=hkIUjtFOln/0xpa3AwtHxyreNOkems/MvxtMF4Lv6jezFE2V30nRzC8EBS8CAkUFyFqT1IJDlaXEdYgHhViXm2MabWfw8dzJdzlQVxr4EODImDqOn8MbSpqOYbnGu8ctENT4V5FLOWUbyghT+L4N2VTVg1l3N+hG3bQhqzcWLtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919705; c=relaxed/simple; bh=vSqdD0lB+GHwFfN2RL+57FqEEEIb8AoA7CDQH3bU0ZY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R/TO+V26FpA1c9T4SLU/bLR32oGr27vLaU1XuS/8Eq4ftyMon+m59hEQJ6MZypk9zjAcL8gYgxh0yzGtZTo5qC9R+hbDLY+m9823njt8qDAoo9sQC7o33uTN/gV1QiwESpFT3qpvjEZnIHQCZl1BKcGg83mvccbRx3HlSb+f53I= 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=jK8cV8OD; 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="jK8cV8OD" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-365663f51adso643620f8f.1; Thu, 20 Jun 2024 14:41:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919702; x=1719524502; 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=FrbReal7lMIAAtnYiQ/ZH8usDjXZPMQ9YxNeEJWEqEw=; b=jK8cV8ODbEX0HzHA0MkYBhTZPTwM+zpDA/Ig6p1QQkVzRmN3BT64iOzzbdwuULsP2S NBGzAAnwnZBs7dJtbQe2xYx1c0lA0ntMg4iOMy9zPEXyTEF9MJ0wiLyq6YkJy8inWxUH 1oU3wNyO6XMo9BRz13rM4U5LLRxbXjQtOCrYIS8XOVES7Jr8ncyaOLA5CM1u5Om3j+wU H/y2cNQOsBHfoKE8BkvwEfqKYcrlmPWAMJ/N+SpyGZCk/g5Ig9cIMXIlfioKl6Tr/AAA rlbL6DNgOkgZ9t53/pbzTC+/5aYzhAHVZI4NjABM0zycw6L9Pi/Cw0hkPXQyhaaBRheD VOGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919702; x=1719524502; 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=FrbReal7lMIAAtnYiQ/ZH8usDjXZPMQ9YxNeEJWEqEw=; b=tvkVf1db8YLOZZG8Z/SmRQ+iCNRZ2GYuSyAXbzO9iqJ0chZs6O/VhIx51D9+vWbw7q 5gpweQkxis/3GEXjimxAm6TdiqFBIwRezA9elT738GyYG7Gy+JW+hMpXKEBvPVUXPqbZ y6nqnq+1z3qNmc5V0jFDJm2KnRR1WcEdxsoBS+zC7fnfsxHzCN7o0DCTUxwW/mck7m// UuQW4HZHH3GvR22cZFdWKiIQeE0XeTM9ViXDhB5CPQsBujqLcJSz0+eWyv5sS+ktMuZX antPC9vfZnMsyF3Zm3iSBYDEfD/j9FsDK26zAuPaT8SvKLo1wX7hahj01QCVtyjy1e4H Vi0A== X-Forwarded-Encrypted: i=1; AJvYcCUglYkNIkj/z2B1I7uPXd7uV23OMvY6uiMwJWmTCRkhlPILkT9IkNNguQuHYpdoG8WqMXZBPoGREP+FPURphAxxGfYMa6430xpSiyJwq3UwmmCuhw8eU5HZ9bwQUKLrN1kty9rpucLo2QHMD7Rw5PeT9Uibml3JwYjSu+ZPKHB80oyzBsI= X-Gm-Message-State: AOJu0YymQ4bMkobO0nIL73sWSMXnaYTB4B/R1/68xnEQ+fe4Mi0ETQOp l9WYB0F9tJQgb0CcI1XdMwHuEWgOHIpRu391J0l5fCzbwrk14zAe X-Google-Smtp-Source: AGHT+IHkxXiYUY4OUlcuibf2iOS73Ks7WqypO/UENCk3K49BCq8itEffCUwnXRS84RiFyCA7IzZ7vA== X-Received: by 2002:a5d:4392:0:b0:35f:1d10:18f0 with SMTP id ffacd0b85a97d-36319a85fadmr5144982f8f.64.1718919701736; Thu, 20 Jun 2024 14:41:41 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:41 -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 v7 07/20] leds: leds-lp55xx: Generalize run_engine function Date: Thu, 20 Jun 2024 23:03:23 +0200 Message-ID: <20240620210401.22053-8-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones 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 38564b9cda0d..9830df285b96 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -46,6 +46,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 Thu Jun 20 21:03:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 806144 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 6108614E2E8; Thu, 20 Jun 2024 21:41:44 +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=1718919706; cv=none; b=Yv69B+EPVmpzHTpEhnVgo+w8n2MVQ2hebBChmVN8H2CT8PE9KSg2dbKxTjxWZoRWnMJXTIkWh/u5bTQYfgiue1UUILWkzW0AbJcBMU+UUgV8zoGYEO6FQcOtdo/AJStLg42G78ko4Wo/1D3TjJPM2lBQ+L0bcjtyGnLxYYLzDmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919706; c=relaxed/simple; bh=mlZSelBVvZtwuU/2C3qMj1tJdoE+0Svue0obmtqn07c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K6Nk2bGphSGWWrR9Vh3IxZCuE7ZQ/RweB7YP/OQRuMUSbZMBXZ8GNf2W8klc/UDbH+F4ntFg0TlBAfsHznqVNikqrxOYwmo+SoW7K15I0qvzsvsC46nz8gnhRQ5pCoI3cauaEiPY+fgggjvIvRSNcjvgSLw3nck6sfv0+oFhuyg= 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=cO1NcIZJ; 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="cO1NcIZJ" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-364ff42999eso1007111f8f.3; Thu, 20 Jun 2024 14:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919703; x=1719524503; 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=jHse+1T6WeaJG4+3neoshaVfJI4hAbZOvD4R8BooVmQ=; b=cO1NcIZJweBwlwej89S6+pn+Jcs4GgRwbHCQCYyMWy3/lGAhoE/PkktUdW5qNqA4mq O9nQWGxd8GVAUuwxVrV16NERdBf6o+TAt1RXjmXLXbSq+TgPhMLCJpzq54pL2IwN8Pvj vLSy9xuqyMKcDoXtNadU+PAAbcplnE6DHToZy75LSOKHbG3KUryWqWFFkab1M1zpOHa7 Olc/Zv33iY3SZxTXBwWHk8K0NjFSD7MkesKZg8d2Htn2ukMGBK0RlZ2CzW7LEuUpObch vz0XJ5WLQEe8cR6kPg0havDbOJ9r9wsKIY5CWo1AXDniqG7fi+9rRzSj7lwoR/UEOhZB YwRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919703; x=1719524503; 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=jHse+1T6WeaJG4+3neoshaVfJI4hAbZOvD4R8BooVmQ=; b=f89B9CZoIGl7HUuE/NZYoyBsdVc47R6fl5/T4dAAshnZ1+x1D6WP65NW+UV/fYTCUe ZAe+Vl1vgSJBtbSRoGBodQ+115Xj9SOO/yb0CwL099/iQuZz7Mc9WY7Qq33DQqxE0WRK 4MHewmYKT6zQqvE9UfWUM/8rjoooERD0ESeLScHbXO33P63HpWjg91zMBI5e2w5yxdgi YfZsqDlCAy1h2aPOt2hVhe2gDRQTHJahZqzRsVGi3adRIEz9SFlwWZ2qToK8kPVt1qNv 0XGc8e9nwBQO/dG+1t9UkvqeGn9M493PoZt4kNOljPNQk+AcW/3QolP2WLfZmAMVspyM IQIA== X-Forwarded-Encrypted: i=1; AJvYcCVxUpsz8pFWb7qC5/uvPhYLEWDJQlelwRIp1gla9NCHiAhlvcd7R3BdQGCmv/o7Eb3yQ5bi2/VxELW0DuHhRN/LntGR8Ub/X9h9/t5ym5m7yJE0rfzEbrU6oNznbWvN8NKQHim3yhrFve112tIW9IfhywC7+ikfBQKqzDtl5WWuMkCAzjk= X-Gm-Message-State: AOJu0YybdfVixGraw2WwQLgKR+Bhf15f5M+TOBpV5EuqA+G8czSd+4xs kgzZzpjYCKfT3O8WV3fKvd0RxdH0lr/4Jdw4S3BfNU6+KGABF0Fy X-Google-Smtp-Source: AGHT+IED8g6wNWdLSHX50sDChtCdEi8LkIpkUVUHTE0ZTyTWvEgWeTNOWV0MCtxc2ps7Yb1xlLkamg== X-Received: by 2002:a05:6000:12d0:b0:362:721a:fa2 with SMTP id ffacd0b85a97d-36317b83131mr5316479f8f.30.1718919702723; Thu, 20 Jun 2024 14:41:42 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:42 -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 v7 08/20] leds: leds-lp55xx: Generalize update_program_memory function Date: Thu, 20 Jun 2024 23:03:24 +0200 Message-ID: <20240620210401.22053-9-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones 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 9830df285b96..8c20d7b4bc82 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -27,6 +27,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 Thu Jun 20 21:03:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 806840 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 7DE1014F9F5; Thu, 20 Jun 2024 21:41:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919707; cv=none; b=GCMp/243KhzpiGiQ45DCzIiQjn9+bj/anOG1PtSHhw4Nb5xBZ0m5C5+sjOOLDSGq7juXm0ZeLGdPq/xQ3Qs3rtbYZ0Ud1M3zsKKolH4FdxVPhOayerxTu8G/xxOlgqfRT7OBPnlBN33Ro7vdIUTzn4XL96usXbSpq+0C8CWBOJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919707; c=relaxed/simple; bh=mzUPFIIxdCJwxUOnfqzZylBnwNQvZ6vmXNHDWnXpbf4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jTcW/ev6g8tYc4Sx5E5fUmhsJgMFfmkPsOw7J+mn5blBLTV/TNYHFRL7z7WMqcvpJe/cu+1U8cOJN8byOuPc7wqBw1kjpO+EhE0sGBAeEhOLbwrwSX/7Av/23ZFJTSTL250WX8Id8nGx3Fy/q6yTny6Zyn+sSbPkbvt6dYJr6OI= 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=TRuPiIJ3; 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="TRuPiIJ3" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-421bb51d81aso13089875e9.3; Thu, 20 Jun 2024 14:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919704; x=1719524504; 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=G42UoLjDGP8cncbUgriha0bkzwbPhVTETU0H4hWp8b8=; b=TRuPiIJ3UJQ9LTgtIKYUMbBVS72yDJsSKdJyNO2KfQcD+TQ9gbpZJOkTEs1+0LnA/y GYZr7oyLLNhJyjCWJly5lVpmXRJ4ptpPI8nX6lXvov3yWxL+pDW4NSd/atRBkUq+bJ/O yjnKwrCkcSHXmU5KX+d/3RL3SIgERxF8HZNEbnaK8SmYziIAAVfYMUoedyfl6xmkwA0v DU3PO9mJGEtJXSclPb5ppkuA51MXmlk5CWSDlGGe+xH42iGcLCXfcTZwoK3UFBat1I3S BjReYuyvGdOPFDEI2opHEaJAqPYTxITY0PYHmpjnAhg/g8ndlnSuQmKf9RGWWE+1Xp4q gQfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919704; x=1719524504; 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=G42UoLjDGP8cncbUgriha0bkzwbPhVTETU0H4hWp8b8=; b=FOC3hCp2AxpNnWsriumgt/kZ3SL8vrbGApfXyeozxgDyWj2K2+sZb+bi4vLGwW4Oae pLATpGZnJCeGIxcuHhbcO6u/WJcxw69ISdRQ/Jrscc6ezniZqxtyWZgDosi0vvqpGrDs stuNj4HCoZ0RCQkMvtKc7f1Dt3ZLeKuEQ0Hz4sHy8/E49vVYBvVsbLPSf3fCj0ZNqt2l VkmXBCCn0XmlLkiWmf7lLUsXhqxv8YaKQi/iEv7WzGM5pxFpV4twqvG3e+1PPJzSCRAE 77jMHHrjlBm5VEhi+wBsumctMCWu3Bq9awllMSMax9tHZ7UmuEpSyW19+5GMQjHc0fcC gZig== X-Forwarded-Encrypted: i=1; AJvYcCXzYnDamX1ER3WxUoqnGgCEKsyoJecwe4c0/O/Z03LualyiDqcL4CNtt4aQREamrl9GpabJUFAkmu0PVxXHYxrfMPIdTVCxGJL7QoQbUXaBRmTiVKtXdQ3iGg+RATGrvgFOf1EnGz4rIbQUNczOXmMpKHW4dpMKVY4vhqZgkc2Bu9frceA= X-Gm-Message-State: AOJu0YyrDhHo88iHjXgOghh3IZMvpSFwTQ0l8S3Gl6BtR3E4LBn6dpk0 dVkm8AeUhVQVmOndUnXgqRmTlMBL4EZ3qJ5VlIVzej59AYDHm9AX X-Google-Smtp-Source: AGHT+IGdcoZqvlv52iXsCp+2DvdDihH7FiIQztaQbnfKOkgP5kW4Lz3Kepk8hiQe7C9b9WP+77gkuA== X-Received: by 2002:a05:600c:63c4:b0:41e:db33:9a4e with SMTP id 5b1f17b1804b1-4247529d538mr46815315e9.39.1718919703795; Thu, 20 Jun 2024 14:41:43 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:43 -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 v7 09/20] leds: leds-lp55xx: Generalize firmware_loaded function Date: Thu, 20 Jun 2024 23:03:25 +0200 Message-ID: <20240620210401.22053-10-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones 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 8c20d7b4bc82..1c9348ed3edc 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 Thu Jun 20 21:03:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 806143 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.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 778C51514CB; Thu, 20 Jun 2024 21:41:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919708; cv=none; b=olsms+fiznK6+8V9qG6ZiZ4aWsLBLdpUd8jzkV6SsMOPoCG/adUaPYSuz5XuzEH20Z2hTNr7+7ijmUK4iSf+3XH9rctScMgKkqPDyRqDJ5WFfqMWS94YHDPjD5CgoP6xXhMRoe1P+NVPAjL/tDBFSS6hRmIty+MUjY3MlY6H+OE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919708; c=relaxed/simple; bh=9W8X/uXPJ33ZTJoIbeDuSXduZ5KaunqFPUGZtRzhOa0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n1EW0DpTKrdVRieEi3LlTgU7Chm///pTxc1biJy8xS0tQ9SVszkWUOOmOOo5B04SzjwLuAxwnpkmUhl9brQdk7yjZHGBZ8PWsjF4mm250f1a+PJqWuPTcifutvUf4hGJWXWRHEHR2DFbSxROylqhwUZ3opoCzS3rhvkonL+Zbv4= 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=a4TyCx14; arc=none smtp.client-ip=209.85.128.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="a4TyCx14" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-42189d3c7efso16358955e9.2; Thu, 20 Jun 2024 14:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919705; x=1719524505; 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=vudVfkGmrTvIppVR7JpN4yzf5uM8Dn6rAyVmA1h9sfE=; b=a4TyCx149EhJdqzzsIjl0F6wL1ErR2ll3zLrcC1EQqlWmTtuaOWVzz8WXFJseRwAgV r9iJo2mLy1dpwR+bn39uqg4d+YL9R0DkE4CzFHlWup+8CIg4D2gYdx6x63oj3JdkCoHZ b8/jhAefcfdrR2xh1LzKscclDkAvC8jwMpU8qj8cVcRLQ63okyRisH2A8iqdFOh2+6bn AsCcYWGbj2ziiLdGvmmYVkBolauesbPbTqJ1G7x0O3bVonHDd4sBQMUF1Y/4k7IlqMpr iaxd00XWsf8ihtkIdDv+CcOwhv/fYmIb/pU/oItXhdsEr2c5f6bqjzZj+GzeDP7hXn68 OgiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919705; x=1719524505; 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=vudVfkGmrTvIppVR7JpN4yzf5uM8Dn6rAyVmA1h9sfE=; b=ox/JDgqkwGINvIISpG8ZBdYWigVEDzcZ7WZwjlq9/Mo8hA/DLvThWgvsuiNm+cQYQm tA6/G3JhViKt1P0nzE0YE9QFoHi8OxIRDtUmhYpTaYiQZFcGXy1hnpelUt3VHjAuGIOs zPnksqzQpnn9spwCoW3wHjqc8YBBFBg2Glnq7/ffsGayukdxCDzUA8KDqtLuwQdZt3sW eedUrrQ5DLIqk+1gsmmkDarVRdWhiItOp9cndPR2Fvip2OGeGrkuc4NNd8whtOMcldUQ qNLUrx9algXid7oYH5DdjNAfeuxbicQCYlZYUujuGUi2ufIJ1T2fnKgvh608meJir+TC EDlw== X-Forwarded-Encrypted: i=1; AJvYcCVIYsKLYZi6lMdW0MBs5CK1f7699wrGDTRqRGibbCUG7Bvh5sd/fu+7pEFpxUtoKm463/KB7F9A7HHgjmB8UjYAnxaajI7RF96jSVQsK/F9GtX/lSdi7+2Ma8XH7VrtVK05+qCrrWF/FVB7lC7A6IckIP8iZGTU/dfguHrnwmCdELH1Evw= X-Gm-Message-State: AOJu0Yx+jVBuAj/DbHWLy8KYW0H24eq0kPoxe1YTM/qKCpaCOiqw0946 Vnbjw4pWsYtPpBB1IBuyzjRivny4m6Pn+KNHs8RT/zp74GwiwWTp X-Google-Smtp-Source: AGHT+IFmAh5GyF8H+4C6AqYClJGLrvIeVbqL4Uione9FDq72sMw28eTl9CZR/+l6ZKOTZ4xJGwGp7g== X-Received: by 2002:a7b:c307:0:b0:421:7f07:92cf with SMTP id 5b1f17b1804b1-4247529c28amr64655905e9.36.1718919704881; Thu, 20 Jun 2024 14:41:44 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:44 -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 v7 10/20] leds: leds-lp55xx: Generalize led_brightness function Date: Thu, 20 Jun 2024 23:03:26 +0200 Message-ID: <20240620210401.22053-11-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones 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 1c9348ed3edc..cc393e407837 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 Thu Jun 20 21:03:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 806839 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.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 9DE5415251B; Thu, 20 Jun 2024 21:41:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919709; cv=none; b=UipvZOjxGb6TSbnnBq9PGRnxXW+Cg04dds5YtvLstUOCwElnUa4uMvfG7A7nEEdWMc1irOJfUifGYoesDG/O2/+v8oy5r8LpnOGncCxhF4GJvAploH7tYNLl9HzA9CldyOft9v9qL29J8cyc6F8rEUlQmFgWTj9wz8O7dheBhg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919709; c=relaxed/simple; bh=DNqXmzHMEsh3DwV1S15V2tQqJuzOJaJFTIW5s/jJFbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j1Zwhb3z2XS2sOrPzoUPTlcM2p0aBU0rPrKknHO7Zlk3JtiNfFNhw25xfzewa2ElVXr5q4RFpeYqI+G4g/Jdub1t+8plHoEe6+YTXl/tW96lT9mIsEXzQEyH9qct+rlp3wpl01ALR5q+oJkjCHhnnye3IL0GQNGoHvRvShx0Q7w= 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=VCiJdOVA; arc=none smtp.client-ip=209.85.128.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="VCiJdOVA" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-42165f6645fso12603295e9.2; Thu, 20 Jun 2024 14:41:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919706; x=1719524506; 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=+cd55MwcmwxDYM1xS6QNPLsC66LDeGdAfdzlXmx5K3c=; b=VCiJdOVAsD9eyNGNdQTJXnfPsLtMZoXWnItCfXx3179sgwJaiVINV57Y/a0oFm3Wdz EL5iTH6sk2Xf56XiiYlMMYq3XOxiUoGgZ16/FGD8ne+oSkRWFLqLGybzFroyHEugq3Xi goQ7nmHokBwA7+n2NSt0zYB8cg+xgALcttqbk/eESLVNIOFEYDAt5E7+YJmkUGFKX3EV 8nB0W2NoiFgZ5VuDZpUINmjtKhGvxXpLCPaphj+E9mRUJFnxG+10lJojDMgAyFmNEha9 PXtr3anNzHkTq2s5iecd6tuSulBofn64Ik/6pZTl9hYCXlV605qDUkvMvsrzi2FMlJQK RdQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919706; x=1719524506; 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=+cd55MwcmwxDYM1xS6QNPLsC66LDeGdAfdzlXmx5K3c=; b=JsSQQGtPoV8mkUC73yU1d6G7FnPQN9iU7za6+uHmrO/pimiCzQbzy2vx6ADmbqW8kZ iFEORVm4l7jpJPw5N+VJXWHwVj/CogfIoExEX1I5qg4/Rxm2O3gLBkBrFQ6S2HDQBWxB 6IDEXcjJMSRr0VysRpII4eFRlld7+Iq7UV40rMNs9uGdovW/dymf+bl0Qy4qO96V//M8 me19UjpBEnrKEUCgseSrfQBLLn0VfeIpCnFYNAb1RJ1c1KjK+2Dj2i5oZFRNSJANKst5 3r3tnCTymuQPThwpK0rwkzaiohWsmO5thsXvn0DbVoSbkUsOPBOEA64E5NaK7NBjgljU aPzQ== X-Forwarded-Encrypted: i=1; AJvYcCXYJV+7QtnUPeMwAnHD/iJ3xQQhTDPeh3CutabCO+6QBchOHz3OwdW0T2ZxXNujK87llkPd2wyy8h/DKgUk5DnsdajFx64a4xu+d0CFK8M9dqZpVzdmr9Mz69rjb/K8eJ99rdiIzYyMEzUNATZaOWBOvHPXcbdwby+JxxY42JWtPdCEMh8= X-Gm-Message-State: AOJu0YzzeHQPaCZ/ISl2QmUhJQ1L05iNJ6IS6WzwWkZttmDAAr6QjV1H C/WmW61/p2h3/5jmf5RgbgeMAp7se5EP1Fwn/GzEUwEO765V9uyx X-Google-Smtp-Source: AGHT+IEdvuvSWbCecqBEgSesFZlQBBEStjHAOm0Pgpsjz9YMgGQeq1pufHl8QVbs2bQsqAMUxCl0Nw== X-Received: by 2002:a05:600c:4f95:b0:421:c211:a57e with SMTP id 5b1f17b1804b1-4247529b019mr55449665e9.35.1718919705895; Thu, 20 Jun 2024 14:41:45 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:45 -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 v7 11/20] leds: leds-lp55xx: Generalize multicolor_brightness function Date: Thu, 20 Jun 2024 23:03:27 +0200 Message-ID: <20240620210401.22053-12-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones 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 cc393e407837..27008b6a4757 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 Thu Jun 20 21:03:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 806142 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.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 94B8784D13; Thu, 20 Jun 2024 21:41:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919710; cv=none; b=tHeamG3+q54aKvYwiKAiz9JLU1bt/79+UWvyg5pFgNoQt5EF/Sh4aCGUqXp5kISrB4DkVqZpbbSW06RGwnJd8x80EfmsLh8Du70VrCZpTfMYcx8GGMPPj1noBhNOPWYrpZ95ebR3unqugqyPoMvR9Gtax3NTIxr4w+JzVsoxvBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919710; c=relaxed/simple; bh=bE+H6/d5S3V3ne3J941Ravni7sgv7nsfpyZypdmVHYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EIcs+t7FhOdbazsGaoksL+cZr7U9ovPKD3eIAsPLBL90kteOxHCxnY7mlBKMidbo3bzT5q9DF5hLVQYm4TxZHCl9Gbr2PSAvW5V3mV03zjzMArrsEsedrrmzPLjl/JrdjTsl9RlBWYIeUEKeuQdFjrnLBS6Y7sP9327j+zr1OQc= 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=fTz9sE7j; arc=none smtp.client-ip=209.85.128.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="fTz9sE7j" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-421a1b834acso12260665e9.3; Thu, 20 Jun 2024 14:41:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919707; x=1719524507; 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=2HSlEfR9855aoWqKhwBylO/wmGxDdnbWadMM9N3fBmc=; b=fTz9sE7j4hn59nDYxGebcnjopzivshGBH+rtFjdqjb5YFruuUZ016TZAs7R+aQxj+A Z6bziJXesNpbm4EQFNyQv40FNurg314bp8C3PF8NVy73b3ARGHSKchwopEU9gR0B3Aam mCmAW7KgYbG7f4FeyLDVYDGpZ45ujg7CTWXebWJ1jtZNJxOXDZTSmErLwbAM89GTUw9v maOn53+blUukWChQCRie8Jp0R+Ua1S2EQQU16DbvxazEtUUw3oltajjw9reR5VPZQxaV gdGp787XOyusBr6pqPZziCsgNolVHQbk+HJhW1Qz1E7WiABx21cZOuXHAGBpfeYX395Z lLzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919707; x=1719524507; 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=2HSlEfR9855aoWqKhwBylO/wmGxDdnbWadMM9N3fBmc=; b=WoCl6Q7wJ+Y7Fo/YW61wwsU/5NXgVaFNc/7x7m77btEPjl2TaeR+SQ9yFzeUEtFiGL +f+dJ3b8pcDQ1PuZWuMAtaNVgEyBdsB2T1iCrqTR/3vxKbepEts7FV4/sMrWZATEpnaD j1+wKL5qGGxhTU9IEjM0MTi3tHjpy5hDoOtsL+MT1OmiHAnRBwkHfNVkVnI1GHsRibwC 9Xssqh8T7QdCiIEk9jNJjB4PvC7sEB2n116vwvklMTfQNRoKS1zD4nhElbFD51Ty2iv1 GY4WVuKZwDzf6LDolQdjeJprFJxfUIFjBHvXEtnxd1rD8TE9UraixNTV74bOADCoyUw8 SZbQ== X-Forwarded-Encrypted: i=1; AJvYcCUsQjTQny83LDnDGliMR6RmI/p5UoUGHmofcFi5EXdv4+F8ffoOLO6w3MJ94b2c7OX6GiXQ6TkKe16f/J/sWuZxTmSRcHZxIZVVNNfAiNpHVQ8y0EqH1VyZcxbXvgarHljw/cIma5TLkQhzJIKVCNfnzrk7DkuD61WTqfXhpnLGuSeBxvc= X-Gm-Message-State: AOJu0Yy+JPxD/aj/VWbgz4pFNnKKVSA3z4gLvTV9KxIzPzppk3NmUf+1 umzmlfsKiIcCjBDsap18n0cFyY8z4ozJsO3QALGAaN06ejn54k67 X-Google-Smtp-Source: AGHT+IH/VuiTnrgvURk9WxGkgxAwkINU/kU9JwtJoavYc3B3TrwzkfvOmcjJ0v4OzleqCWVz+WYWzA== X-Received: by 2002:a05:600c:5c4:b0:421:5ada:c137 with SMTP id 5b1f17b1804b1-4247529b439mr50778335e9.33.1718919706912; Thu, 20 Jun 2024 14:41:46 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:46 -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 v7 12/20] leds: leds-lp55xx: Generalize set_led_current function Date: Thu, 20 Jun 2024 23:03:28 +0200 Message-ID: <20240620210401.22053-13-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones 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 27008b6a4757..d17538ebfcf9 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 Thu Jun 20 21:03:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 806838 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.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 A8918153BF9; Thu, 20 Jun 2024 21:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919711; cv=none; b=fcTWhMBz9MN2a7o2TPhWbvwKLdzOZS2bFtR45/+ccLw4p2F4pHoUWZ6zYvbCYyZyESFeCx8t5sUNVtP8N3ae3+D1+Ukg41K5SMI9RtNWqXp55sIYDyDvB+rS3snpyi1lODh7xYIWBZ3IdFwla4MHsn9rR6Mwd/+4Wv+XrUvROxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919711; c=relaxed/simple; bh=WYfEnqGU/jttnGRW1Dl3AAXqGn8PsUodgf/YFXg4lD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HF7UD/BVPDcxkPrYoKlgyQO6V2FsrRhmqoIcnRbdoLlf9g5uLqYzlvAu2YcSq8cqGnyv+Poy7471sE1H3hLB9Iqj/BiyZOKRDRtDsl3+8lz8609VjqYQqX9Rqq8U7vqIt+jIZmYPKBoDDy6wjjDmL+US+s/j9GO8Fvx1EyeNPTk= 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=FNVHmV6M; arc=none smtp.client-ip=209.85.128.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="FNVHmV6M" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-42172ed3487so11049685e9.0; Thu, 20 Jun 2024 14:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919708; x=1719524508; 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=gKKOM38AF+UhyCgTW0uK8yuV/Hf10uvfG1nRgbJlZYo=; b=FNVHmV6MlHzr3OuUp9ocEczGFrXe3OsxbuRf4onxFl1VyJt/wmuV7xSQyk29170d4y I8i8Gb/xhm/C1bRnmB2iB4l2qOc6hMDrrZQ6YECehGHO9zsn/tiKMzfS6Ksp1Brrx2Sc aUufs/7zUOpSowJGJO9550hr3dREbGEwni2d8bUrOyLbPtF+D/xJHO5wy4NdxQcfLA4E SN8vpJeWLAtoDuu73P+lq/QMxjTHMUZA1G7ve9KqQgEhINRN21Vu5GtAKbe4MxWC3frr 6ypfDR7kZpY1hSB+QlfO1jlqUEfrkUrWBFJYWrJXfGqaVlcc7nzao7JqZ3gxVNJdKxNU tQLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919708; x=1719524508; 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=gKKOM38AF+UhyCgTW0uK8yuV/Hf10uvfG1nRgbJlZYo=; b=pQvj238w/86UjowDkQRvRZtyIk6Lv2LmmD6nFIlBiqfleCO/RfjCDu83jpLMDiE78X ESLg+NSpmF2CMr6W4C84m/ZFoBjSPTD6q6eLKhxtIRZFaD1j56DtBbG00uW9hJagFWx0 ljAC2kJVV68DWUJoB01d0aUQlqgeTvz8JGFxCFjP+XgHTA1ayPw/P9UanQ4G3WQyQk3y uEdtffqVoFuiv+N0k63pOjqIFBOEGG/m4MfsufRyiitspSy3fal/oO6m72FfUsooNo/G 2sgd3OZSnr5LlPJIvDLHjSFcWLrZqhdQh8me2C36HTK5k7oy0YXMOkTse+irRvYFDnCY dUuw== X-Forwarded-Encrypted: i=1; AJvYcCVMNo4InjEKkKP3c0hlg+nitManM1N5n/7VHRhd/EIagTc0PJH5Rp52g3Uxxo1XgqPzgGTBAy14talZzkX1EGbAHai7RFp7VH+oy1i8gr4prqFiJFXcXikFcR7j3Hd+pO4lC5yCqxPIrBUA9COGTB1BQcmmTSInrNXNu4GLMyxunDzQjjU= X-Gm-Message-State: AOJu0YwgqWlVopQGiakzgVpsq0ak0V66M/f/oD3PypYkfaNb2IGYwCkS V7Uvli0c+IE6gGohXf0x8vHUTQ/VIP8z/5TfT+9L/qb+SsNvIEpf+a5FgQ== X-Google-Smtp-Source: AGHT+IE5SXGll+857JotNm7EnE6f284l4CEv18cEuilWB+T2YFyLxi+CVXAz+u8M9EM74+BgJWc5hA== X-Received: by 2002:a05:600c:5123:b0:424:7543:863e with SMTP id 5b1f17b1804b1-42475438771mr49736835e9.6.1718919707928; Thu, 20 Jun 2024 14:41:47 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:47 -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 v7 13/20] leds: leds-lp55xx: Generalize turn_off_channels function Date: Thu, 20 Jun 2024 23:03:29 +0200 Message-ID: <20240620210401.22053-14-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones 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 d17538ebfcf9..58121f27f17b 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 Thu Jun 20 21:03:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 806141 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EA20154C08; Thu, 20 Jun 2024 21:41:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919712; cv=none; b=USiIxpB32GITlnBa0YezzWoJcWlaqVxpG0hjWaHeCO7oZZHcf2EYKE0qBy6XDF0rtESD6918zs4c8t+nFynav8VyFfkl9SNdXg91EvWwourrdDJnvwIHkIxrGFXRbZ6v+ZsYTZ0aJhvRx8DHsjCYTZ0UAu23jk8HKpl/jv8h5Wo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919712; c=relaxed/simple; bh=qRBtdteaTcYg4FIgeWPA5RcNj/YAZq33i0IGtnVaMP4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GhUb7wf1P6EnOnW/yL3VbS7pJTFAvA89BsIlVXgeo1pzQT4DcCyXH1hXCNw8TQAJzHsfGnZDaijgtDyJejnlbWlKVcjrjL3YO4gQeqMqXLpbnQLJStSpFqpdaL2MwCvoDb+K0Nwo/Td0yK+pcjaSMOBp5SDr8OpQuvzWZbkp6C8= 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=D1OVqfJ6; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D1OVqfJ6" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-42172ab4b60so14068625e9.0; Thu, 20 Jun 2024 14:41:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919709; x=1719524509; 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=e73alUsXrK9XDxh1X7OdUWZvWORqfMxB50eGvz/bNmU=; b=D1OVqfJ6lytZMvcHZcMK5osc2QY/b7zYtRBtIIPnifO39tP2a8zecftr0UF8NPhCOm kfM3LgIsAf80EquJXZBENOXEAQDLwAiOku5phiuiCeOBJabWZDepOhviY6+U4yQ5+9jV CUbBBWWcIEVDllQK++sABpYLDNOgmks29BAbDO1X4IcZBSlVK3AVMjg6SnesQR4880P3 F2CQ7TDGb56RTHacH7t3PM7QArXZ5QPhb6/j5g22BlQ25J1vBTZKoFF3U9iEVc8MOTrS TgPRSIHafO6oUpB4uMFOTK7MPTZ1rwTqamRXujAxrh8WEwDeO33Lyf/NkAa8zcExfdT1 qzcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919709; x=1719524509; 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=e73alUsXrK9XDxh1X7OdUWZvWORqfMxB50eGvz/bNmU=; b=duWEi16P5G1V+XyqyDofoJJACRZGhuTPZ4lEIDg4gSvkYRhcYjm12LoK68a4VlGZdr T+9CDCGmwgbuLvuDonDYmZh1R0yRS6rHxlvTzopIA+eooywICQKQN5VQPSfVCvI3u/V5 8JIvAv/YFBZSBf9qEEBdCff2Ms8LyJY+aNE3JHJLcSTQGMJj9AajG7vWQ/Dn/qv2oIR9 Iv188V2VpGXRqzHnJWqyyt/heblHHw9bQ1SzCVvmOlXR5ld9C27vunFBXonvoADuomq+ xKIw3aF+tXe6DMTziea8OlXFqy3DxZI7H54JAu+qetVKvRcbREu135I55FCFx0jcpr9o vkjg== X-Forwarded-Encrypted: i=1; AJvYcCW9mcdY3eIqxgyAJu0Z5fHIcd4MZi9bq3Ke3Cs87qkcYXA9KeQLqV0My4pw5uKvtC+POOgKlmvrafcN7q2QWwOTZ1iEVWem7lVuZjat71xIqsJpt6y6L9ZCaHIwA3tS4Ay/pPpBxn2B/UOtBO/kGlhqyERIuT8ki4dMG07e2dBfAmO6+Hk= X-Gm-Message-State: AOJu0YzwtY9pQoJqMlj2RHf18MePNbi1sULAF4Qp6sXenc9mItnZG2n5 0bB3/rN1glpjAJsOEVY3vIO7s/B0DcDkNlNvayas3pF2YELymrkTo6WZGw== X-Google-Smtp-Source: AGHT+IER4ynEAoINSHQbQlylmfWpT+L++crRpnhYQj9wf4vIE1iytfKHF4mucaedDIXmbjE6GY3sGw== X-Received: by 2002:a05:600c:b4b:b0:41f:ed4b:93f9 with SMTP id 5b1f17b1804b1-42475182a65mr47724925e9.19.1718919708943; Thu, 20 Jun 2024 14:41:48 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:48 -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 v7 14/20] leds: leds-lp55xx: Generalize stop_engine function Date: Thu, 20 Jun 2024 23:03:30 +0200 Message-ID: <20240620210401.22053-15-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones 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 58121f27f17b..cecff34e6e15 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 Thu Jun 20 21:03: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: 806837 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 C4E171553B4; Thu, 20 Jun 2024 21:41:51 +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=1718919714; cv=none; b=kxYPFCJ00a174dB7ne+E48e+lQyLAoRt8JXb7Gi5LVL485BMqFDGjAIgMtMkK3J79SwEmAxg34DODv41IaDdw8nqeQ9Co96FBTtaWiBWG/Fw2y94aHBr6HIU/dt77APaQ8qNhaEY3WEbThuZWEfY2Uaw9ErUpgpJaENFA64WRcM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919714; c=relaxed/simple; bh=xIfhZd12c7XRnkbv7tz+FMHPDNGQOGQnVqAKk7l9NkY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DDjIdU9kxhDsftpitEJ3AyzXrjfKmoHc4XMU4NIjOxQuk7TWxXjDNpiPlqZlQ0e3bk2HEpaO61LCeZ4553s9VDjtz9Adp3ds9FklIx/eyp7atZNhxOlDxm/aN3ZpktH38Z5wgEcrigcqEhlT7t2644CjDiKeOnEwzvosi85ewks= 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=VAt0tq+G; 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="VAt0tq+G" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-364a39824baso1095621f8f.1; Thu, 20 Jun 2024 14:41:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919710; x=1719524510; 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=R08tb1yYmAfU91n0VowZ692+xVkx6UEt3wQz/LuzwAE=; b=VAt0tq+G51XKYvYaq+YHjPGfZUF25nGvexXUiMRdZbx+rhxpi5Rxznn2n3VNngeYuF GOLnP1rRzanQpvrBsuHN9dHBTh/UWXWE1tByS81s5WGHe3YwkJ0ybERvUHXpHjkVzoZ1 Uf7I9NFp+a4+kARgZFBIQQM2/bJ65UffNW4Rh5Iy3MBu2ekcLngMQ8UqwRoqh6KxIr2/ RL+T2Zoa/5Ts1AgVSUccqVl1wLKsocPajQrQj0VcRMlktP5X3Q5Hd6IU1LPhjgjYtbRX OpIjBcj5eOaVdXE7PFhBnrpL0UFPhWR08b/rR1J94CfXPET6JxG3to8YL8KcRFhAl9c4 2WMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919710; x=1719524510; 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=R08tb1yYmAfU91n0VowZ692+xVkx6UEt3wQz/LuzwAE=; b=XCgA7Mo4LmwUTr1zj9PG10IQjzwN5VLS9Lx2PYM7fJdnhQhFAzCKu6wLI3z6mLFyRe 6Zq0F6QdTA6qmRhxawXOb1b+lzKU6epnbtDzArcaebbi6KgnoR6PFpjg1SufLZ70smnU yEZvk8XYwQMKuQOFvhbbtY+0GoUI9ZQ8rx93by+cCHkALBYEu0RLqpnMfO2nJoC3WHgP Q/yS17vQjbJRKNOdnFQyB5Az2ISfCvVpW8rLrE+UkqAGOu3mkR6WfCHKhURCVy62YoE5 7LQuqBFUW6YoRUSy2dcXwB+2EhYOhlullgQo/rJWPtS4gb261CWji+QR3YxTMVvvriNE 7U5Q== X-Forwarded-Encrypted: i=1; AJvYcCWxXY7f7WwC8OXJfewCF/HkjPQcuV6xnk8fVPVUQ9m/YOEfjapFZjXKn2D88vIh5YmFLY9WucXtuC04P8v4AiuNlB1Jc1ZglCrgoWbAYed199xIMf/edMZf48oOq6JWIXAPhbTj6gPwaZwkS/fZIIEolAPyxQ4ONc60gDkI5lwGrf6AoeA= X-Gm-Message-State: AOJu0YyuwAUWUA/kRJJrlDuQA0pvhPNnxwgiorwo7CPwkuivzF2IinOt ZxAE39pc3u6LHp6q3lpJ1zmzv64oXBoNOb7xpDMlL18sculROjNt X-Google-Smtp-Source: AGHT+IGRlchOpTVAx3LcUg0513lW0pu20rSZ6FzEQug6XxMgIYePv2T4DGO2Q+LxwzEZ24l6WKhwxA== X-Received: by 2002:a05:6000:1104:b0:360:9910:6f5 with SMTP id ffacd0b85a97d-363191d9819mr4575703f8f.46.1718919709997; Thu, 20 Jun 2024 14:41:49 -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-366383f68acsm48866f8f.2.2024.06.20.14.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41:49 -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 v7 15/20] leds: leds-lp55xx: Generalize sysfs engine_load and engine_mode Date: Thu, 20 Jun 2024 23:03:31 +0200 Message-ID: <20240620210401.22053-16-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones 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 | 44 ++++++++++------ 4 files changed, 117 insertions(+), 186 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 cecff34e6e15..0974488780c0 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 sysfs_emit(buf, "run\n"); + case LP55XX_ENGINE_LOAD: + return sysfs_emit(buf, "load\n"); + case LP55XX_ENGINE_DISABLED: + default: + return sysfs_emit(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..5b3e9473cadc 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -35,21 +35,21 @@ enum lp55xx_engine_mode { #define LP55XX_DEV_ATTR_WO(name, store) \ DEVICE_ATTR(name, S_IWUSR, NULL, store) -#define show_mode(nr) \ +#define LP55XX_DEV_ATTR_ENGINE_MODE(nr) \ static ssize_t show_engine##nr##_mode(struct device *dev, \ - struct device_attribute *attr, \ - char *buf) \ + struct device_attribute *attr, \ + char *buf) \ { \ - return show_engine_mode(dev, attr, buf, nr); \ -} - -#define store_mode(nr) \ + return lp55xx_show_engine_mode(dev, attr, buf, nr); \ +} \ static ssize_t store_engine##nr##_mode(struct device *dev, \ - struct device_attribute *attr, \ - const char *buf, size_t len) \ + 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); \ +} \ +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, \ @@ -67,13 +67,14 @@ static ssize_t store_engine##nr##_leds(struct device *dev, \ return store_engine_leds(dev, attr, buf, len, nr); \ } -#define store_load(nr) \ +#define LP55XX_DEV_ATTR_ENGINE_LOAD(nr) \ static ssize_t store_engine##nr##_load(struct device *dev, \ - struct device_attribute *attr, \ - const char *buf, size_t len) \ + 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); \ +} \ +static LP55XX_DEV_ATTR_WO(engine##nr##_load, store_engine##nr##_load) struct lp55xx_led; struct lp55xx_chip; @@ -227,4 +228,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 Thu Jun 20 21:03: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: 806140 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 AC0A9155C8B; Thu, 20 Jun 2024 21:41:52 +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=1718919714; cv=none; b=I+OHiRI0q5jJvvrzKN5jKVPAqbdnpQ06dscZAy5f4G/8xaAptMzdYV+WbKqUjhfb8on6qAZuqbExWfWOrXaNDM7CGgfnZdqE2RdIDlEPnEQbeKXCYqjaw/0dWGu4UzHtTtAFK8QeC1Cyo7G7FGRMcayRo6lD5mOOhK78RgoKS4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919714; c=relaxed/simple; bh=oQTkijkig+TTMGeA52/UiQnffzMmX+MMJCK7FJjxfjw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kOl9iQajCZO/IFVl1GngshuJNm4u4QLHoSHzPQvetw3R8qA1isG4qjreqQ6WczeiD9K1EPXivq+uXYSwVyX5qq3tRpmqGsuXbm/4u7z+OtQitDgTSjAVXBwdBsxCqiJTeXmSLFnHCC2AIwq25Q2MOHbOJ0fhboAu+W7NBQPGTSE= 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=PGreFVkK; 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="PGreFVkK" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-36532d177a0so694733f8f.2; Thu, 20 Jun 2024 14:41:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919711; x=1719524511; 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=Zkzn+tBnOJfYBqIIubPBDn9JQ0osj8n0lCkRhH87/uc=; b=PGreFVkKPiNvgDzf2wGercGtny1kRO+ITPsJI2HVdJcwvtR+CATt5xaYq6+x/48HMf 3aHthIr0/XsQG8TeK86h7VsSwVJJj6hs6MKsRc8jMeydxPb+NhA08/cRRKWcpn1/8xb4 ZOO7kIkQNmGfjmoOUxQvG1k8S385yoVCuPuJsimjQ4toI2gmqnuuK7MdduNjJnV0deDO 9jPh1wq+Gqs8BqsFMYh4fBICWDFWwxXTb6HQUqWfWj6n/3MciKM3OHOvgh4Jjl8ztWZe PoHXrMZ5jHU9ydL1OHBn32JU3V37wEjW6K4smqzQ84uMIz6kY5cNfLwzXmCZFd5artyi EAMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919711; x=1719524511; 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=Zkzn+tBnOJfYBqIIubPBDn9JQ0osj8n0lCkRhH87/uc=; b=lD2sEnuIxPi1q0OwBob8CF7e2Qdp0Ge6MGu11SAYnGjkHbZIiyA+UWRc7X21TrJpM4 SZA1+w6pqvPrpFOhSHBFapBGM7A6OOouFn/vBTwbaXRg7IdKKDIv3iwwaEIMrDPNzb4B m1oyVK/XmHAmHEKEu065QHDop3SHaW7bXOE848JjhsAA8oJKrTwRPd43fWuFD0cXG4kQ HmpvLs9f0l07IYV6egsjJ3ZsIeGRUSnFZ5KxHQBbFMkuDFBTrrz4lt9P5yVVhHTKh3f8 6YQWFRszEPl033jMVBP4ku2AFUnwvj7HNSzVDVfPprpM7CvOx/f1+tfhF1NNWPZpUePQ 9FIA== X-Forwarded-Encrypted: i=1; AJvYcCWseYwcJgEHXPa6ST6b2l/oJZWLgJ2CBu2Fqxr2EyG7OQhp1ulgCRtzg8SPnJTArYs4ZdF1L/nKIVfhOwQvZ2Zk3xU+w4oiBu46Wp3Kkwtl1kMZS9YoKwOwd91Kmb5sWC67JTSUkUtQWZHi1+3/W3Cm/COVxeKUxtZQqpgvaeRaZeW6+3Y= X-Gm-Message-State: AOJu0YyUGnuWQC7VOKAVFLyZnMcvc5o8Pq6PUbq4cMMf9Xrzj5Q/0kip zprWdiVu+6/1uJmm+E/ki/m5BiqXxklnVhIOaNdtgsgLpKC6iyO/ X-Google-Smtp-Source: AGHT+IGZo5QC0yd+XO10iyD96v8flgjMViHGOzXne7J8H4hSPiXUTukXgwTXxgm1z44esHTdlU7xJQ== X-Received: by 2002:a5d:464a:0:b0:361:1ef2:a273 with SMTP id ffacd0b85a97d-363171e2bfdmr4819067f8f.13.1718919710958; Thu, 20 Jun 2024 14:41: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-366383f68acsm48866f8f.2.2024.06.20.14.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41: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 v7 16/20] leds: leds-lp55xx: Generalize sysfs engine_leds Date: Thu, 20 Jun 2024 23:03:32 +0200 Message-ID: <20240620210401.22053-17-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5523.c | 119 +----------------------------- drivers/leds/leds-lp55xx-common.c | 109 +++++++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 32 ++++---- 3 files changed, 131 insertions(+), 129 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 0974488780c0..f0b673c61396 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -62,6 +62,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,113 @@ 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; + unsigned int led_active; + int i, pos = 0; + + for (i = 0; i < cfg->max_channel; i++) { + led_active = LED_ACTIVE(chip->engines[nr - 1].led_mux, i); + pos += sysfs_emit_at(buf, pos, "%x", led_active); + } + + 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 5b3e9473cadc..5f2394a6de15 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -51,21 +51,21 @@ static ssize_t store_engine##nr##_mode(struct device *dev, \ static LP55XX_DEV_ATTR_RW(engine##nr##_mode, show_engine##nr##_mode, \ store_engine##nr##_mode) -#define show_leds(nr) \ +#define LP55XX_DEV_ATTR_ENGINE_LEDS(nr) \ static ssize_t show_engine##nr##_leds(struct device *dev, \ - struct device_attribute *attr, \ - char *buf) \ + struct device_attribute *attr, \ + char *buf) \ { \ - return show_engine_leds(dev, attr, buf, nr); \ -} - -#define store_leds(nr) \ -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_show_engine_leds(dev, attr, buf, nr); \ +} \ +static ssize_t store_engine##nr##_leds(struct device *dev, \ + struct device_attribute *attr, \ + const char *buf, size_t len) \ +{ \ + return lp55xx_store_engine_leds(dev, attr, buf, len, nr); \ +} \ +static LP55XX_DEV_ATTR_RW(engine##nr##_leds, show_engine##nr##_leds, \ + store_engine##nr##_leds) #define LP55XX_DEV_ATTR_ENGINE_LOAD(nr) \ static ssize_t store_engine##nr##_load(struct device *dev, \ @@ -238,5 +238,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 Thu Jun 20 21:03: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: 806836 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 AFB7B156881; Thu, 20 Jun 2024 21:41:53 +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=1718919715; cv=none; b=L13Ukln97xpmX9U43cgbJFPcspuHSoPgowHcSvRIrGFLakGOnKMtWts2V8IRLvlnMr2KoLCXQ1GJS97x755qy+y6jb0dXvitjfr2ifPOjW4bTS3XEPsWyvQ2B4e0cZW/z2uhYJMUi56hCzO3dVYTwRP0hTt+mRkf7Vv418I5mcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919715; c=relaxed/simple; bh=3bxi4xkVgRCvQWcLRemgpCSBNvRxdHNqfr0Vs3j/pwE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sh3hGy21M/dZjMqvWEHk2mvgOthWghdvvSBRucOwdBZygDWHkgGcgOh+sPeLXi1/5P0AYTR9bZY+PUW9OG+YdJXIk0PIAmvEih7Gl/AUpGUG/ICvG+NXsOkX973LWwRiyhNnCWXxOgJaQHOarZtRu+zG9UHHbfKtWaSCar0+B3w= 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=Q46KRl+2; 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="Q46KRl+2" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-356c4e926a3so1348255f8f.1; Thu, 20 Jun 2024 14:41:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919712; x=1719524512; 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=t+4e8cF7k4UIhR54Dq5vhlEbflgX0teWBDZHJEHCUVk=; b=Q46KRl+2zkv59QaG09Cgl0ghT5kNOir30utOWMak3Y41t4cFd5dBv+Io1dy7sYhXz1 tShwkTORUGcUkQmjUPyIvOuDlVIIKEATya0OlckPBrX/JZ5hb39RQCkZDdva64h83s1A j7F2pYrVxGQqRf5XH11jgv4ct22VRbb1PsXjNgH9sMSo0Gzrgms3HCQvuOrUBeVV2ICY V+wtIMwNGaVAnWp/Nr6vflcCGnuL7RChjwkBEaqfK0D6/P0E9Ggn2Todhmk3Eemoxd58 Nx8AtsZudWaYlWIk0wEA2DlPCI1VhDmTA2kGbcso7MLahXuuErHtL6pFOqw/Uy7hfxjq OspQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919712; x=1719524512; 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=t+4e8cF7k4UIhR54Dq5vhlEbflgX0teWBDZHJEHCUVk=; b=KpCRmuBWk2yMxhcz5szByq9eJtXSHFmRtFsbtYhP5o1GGZ1nFaOlz/jkF+GomJvSOc KRMqAFPijeUsyBGUTAjvtLdXJ+ZnGxSsNIwcVakBTHgrc1OTuVuErl4At4ad+HrXm9zI pbUXAAvUzKZXDjFtz9fRT07yLz+iUK63WLYtgZqo32cx7qcHdf5sy9gY9+gLOgntedhy KWKSaobAEX+o5K8Bn75bo3Em7KtbcrGR8okQpW/BJ+qlONDN1Bd/GjbGviQYatRSzgoo a3Lo4VYKtPCMZO60VHsz9FB1NjiDgQSRsmyVNFene9AME0WoPQjIpd5jE3XyxJRzHOxT 6Pcg== X-Forwarded-Encrypted: i=1; AJvYcCXOopL5vuMOkKCkt5o13SQmfXQehG0JEDg4ZDYr0WNZj712x3Yct7JiqdKIUGDCnd4eCBiXLhVaHwfT485k3kx2ow3N3L+0v85Dk7KBlB+woX5gXXNa8U4z40LNClwsiFXirA/z9F76I3OV4u0xucb6ABluF5LYAVdclrzYXgEthSPV8i0= X-Gm-Message-State: AOJu0Yx1nCAGUgU4bsZnxPU8rdCAg116ecYPQeW79knoUsmWNmgyAfUh AhkfCImzblN9fDDjlBTBsA6Jh762zYD/jXEbfvCD7sYDGyVLpExI X-Google-Smtp-Source: AGHT+IE89vtUqykSfwG4/UqU/41QvI1+DU0/USmG3j4zV4xuiwT3UBISKEkD8Si2axwErmNGev2GzQ== X-Received: by 2002:adf:ecc9:0:b0:362:b5d7:8116 with SMTP id ffacd0b85a97d-363176ad7a0mr4974790f8f.28.1718919712031; Thu, 20 Jun 2024 14:41: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-366383f68acsm48866f8f.2.2024.06.20.14.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41: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 Subject: [PATCH v7 17/20] leds: leds-lp55xx: Generalize sysfs master_fader Date: Thu, 20 Jun 2024 23:03:33 +0200 Message-ID: <20240620210401.22053-18-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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. Suggested-by: Lee Jones Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5523.c | 150 +++--------------------------- drivers/leds/leds-lp55xx-common.c | 113 ++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 32 +++++++ 3 files changed, 156 insertions(+), 139 deletions(-) diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 9d91c2c5a3eb..1b3ffdc3dfa3 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, @@ -516,6 +382,12 @@ static struct lp55xx_device_config lp5523_cfg = { .reg_led_current_base = { .addr = LP5523_REG_LED_CURRENT_BASE, }, + .reg_master_fader_base = { + .addr = LP5523_REG_MASTER_FADER_BASE, + }, + .reg_led_ctrl_base = { + .addr = LP5523_REG_LED_CTRL_BASE, + }, .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-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index f0b673c61396..dd7630aaa438 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -64,6 +64,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 @@ -800,6 +803,116 @@ 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); + + return ret ? ret : sysfs_emit(buf, "%u\n", val); +} +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); + + return ret ? ret : len; +} +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 5f2394a6de15..6dcffa0db647 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -76,6 +76,22 @@ static ssize_t store_engine##nr##_load(struct device *dev, \ } \ static LP55XX_DEV_ATTR_WO(engine##nr##_load, store_engine##nr##_load) +#define LP55XX_DEV_ATTR_MASTER_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); \ +} \ +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); \ +} \ +static LP55XX_DEV_ATTR_RW(master_fader##nr, show_master_fader##nr, \ + store_master_fader##nr) + struct lp55xx_led; struct lp55xx_chip; @@ -103,6 +119,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 @@ -123,6 +141,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; @@ -244,5 +264,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 Thu Jun 20 21:03: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: 806139 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2B0D158A0E; Thu, 20 Jun 2024 21:41:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919716; cv=none; b=RQSJJxRV1exZB46h6EDQ2/OCCeaRfjBS60N3FcoRs7uELyj5f4s8AsvbQSCtAwn+um26/lfFW5qBHpxXRfKtnYvC/Tlr57BXY0QGZO/94Lv3ncRjqgSvlLIG5mN3IWGdwInwUZGMz2DU4PlQIvL41H4fdmk54TvyRTmet6SjrtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919716; c=relaxed/simple; bh=om+AGcMqGqbbvVEm3jP/AcMHWRQ189MNta7RWJNBdAE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JSeN2pHGgxuGp2q5znbgx5VdoaIU5XoZRqJ6O2XKH/VIm55kz3m7IS13cDZqkYgEm0yeQmVRq5YyRPWmLMpzfg2+zsrChP5R3lJjo+jSut/FuL9AuKmKWrqBJMSWMQ5k1zA/eAq5eAIQzPvYSNnqhbmnGYhilhf7WLaVVQnswdQ= 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=XK17Sa+K; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XK17Sa+K" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4218008c613so13102805e9.2; Thu, 20 Jun 2024 14:41:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919713; x=1719524513; 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=o1OuxhTObrcU5gxabuse02Wd0S4fCa29l4HMpyoKad4=; b=XK17Sa+K0cSHcLUpWUXW2SVe5d4VC+cgeEd6m8DzS+Vh7MBBJNTlQTYoQ8LIJA7bf1 TRKVevExsf6VS3BF21TQK1bEamem1Z9wU3uqgEUATfMEDMHTKmECVwOWJQE2nyW/YDLb 7r7Q9Sri0vPAcDxRADlWDqN85o4MqIBM4XdSs5VEn6JdXOr/HpCrMZGFjBzNeheVoLTv 2oJEXFYyxshigQZIY6ymgpcZ+wPdG8kcqZBmTOtHMbiMjIRT/fba7lo5ZTavhvTRb9sY gjEcLiCMHs99kxlT4WE/d7FeSDaFur2RCSZkWg+PTV70U2ujD9Kvkz/fDLcA3UDGoP3a y5Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919713; x=1719524513; 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=o1OuxhTObrcU5gxabuse02Wd0S4fCa29l4HMpyoKad4=; b=tGgpf+h2D5gtCMpNmamxT4EDAw8acROnV2bLgGhqCtD+kRb0k4DAbqHOVFsSG71lM0 PLxNbRLiG13WB9RHMFxxCDnfDsOlHqYWL9Ih819qAVq3HcF2dgm97+Q/b7GP6VDG1ncI FOd/Penuo+CaJIM92G5s0SqIK0BiLpkScPzbxzAMk4zcwwTYJePmdQ9EK4zUtbE6tBMG 6wP12PywV/ThKNBT0EM5d78XNgdWUbFDJnzvQdQYShnhC/V9+Mdnd+qYvw3ChkO1GRBm 68O7OGsGzNC+TcLTGu1sUHHFzY/POp2NWf+E/b2u3+XdiPn+CxgrHf1Ed+IPumBwjTdG FPpA== X-Forwarded-Encrypted: i=1; AJvYcCWvHZ/X9jGUt4uDigD2zTG1dJw6YC/aIC7CZ2QXSq1IiMuaxstGcjbJgz9gUF+fLKy4rR8+JxVUaoel9WCiZMESAGktlfFwINWjlcmx32DDLDt6ZVejIfZxYxENQqe6TAV6RIwGyBBQD9XCz2xZ16WY8MnzJ8SQMGklrM4cgZ0tSFOWN8k= X-Gm-Message-State: AOJu0Ywfus76g1NcC8wGgHojrC97VhuPuxJNLKNBC652IsgJ9Jv5H16N 263mmfPJVW7o5g9cQWb+BKV9JqyB5C9rTcMRVlE1oXc6nEEQeH4x X-Google-Smtp-Source: AGHT+IEASjCKXAJxibFoOHruCEMKhms/BaRjSGO1VC+A28yrsJaHqq4tCIyjB66a6lZsDL38xBfxnA== X-Received: by 2002:adf:ce83:0:b0:35f:48e:fe59 with SMTP id ffacd0b85a97d-36319990f66mr4607369f8f.66.1718919713017; Thu, 20 Jun 2024 14:41: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-366383f68acsm48866f8f.2.2024.06.20.14.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41: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 v7 18/20] leds: leds-lp55xx: Support ENGINE program up to 128 bytes Date: Thu, 20 Jun 2024 23:03:34 +0200 Message-ID: <20240620210401.22053-19-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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 1b3ffdc3dfa3..54ead09488a5 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 dd7630aaa438..1b71f512206d 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -27,7 +27,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; @@ -1276,7 +1295,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); @@ -1300,6 +1319,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 6dcffa0db647..1bb7c559662c 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 Thu Jun 20 21:03: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: 806835 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 DEB0215AAC1; Thu, 20 Jun 2024 21:41:55 +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=1718919717; cv=none; b=roQ3ysHz1CnnHJHPPFNUt9O41ty42FUHk3JJ8s9QIcZ1wQ8JeUGMXjEoFtovQoywKYqsQ327zNYPnJdOA0umloQd/E/jYogkBgKZRpt5APtvunovHoU+KaCp3iNBK6Ek+XwnUm1HJVSZVnnU/JNyqwjfXxpus9qhg6CzxBLG8Hw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919717; c=relaxed/simple; bh=nA6S+D3r9en9RPR0VVUrNP1Uukp9Qu5XclTQ7m4h5G0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nKF+XrJgfDQNLRpMmuB2Vjir3zlh/Jygx9KsFcQtPY3X5ZJiyvmd37pdVxJQK8sUq51/8w3nbTF2VS1Z1C8thBGCxxtjIPZDsoNpXmwiI0VlvnzingJJlk7Igvf83JqmNhys2ndgo04uwxUjqcpuNtGUPCkvZp1rzqQPcjottVY= 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=Gj9Zr4rx; 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="Gj9Zr4rx" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3608e6d14b6so987079f8f.0; Thu, 20 Jun 2024 14:41:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919714; x=1719524514; 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=DddTKLoW+PPYUSvSFIuzDD8SGvM2v8GitD/QPej7SSQ=; b=Gj9Zr4rxaLrYb9zprIqucXb7MDnUiI+OVZMBkuGI3LGTPBGZ0V8fiZ6FDMmoZB7s5U JBWANE/JvPyTccqac1hLrK4MfJVMqdXRVUAGWWOgXkX+0zWj4YEhnE+m5eVcy2edsdBi 5mpwNlXXvVCmq8a9rxCj4iNTHC2osPzAETS0kam6smeu3wkTXM1WOAInN5hjxNPqZCFU vo/94WWZhp2CAe1fH0aKRfCmPkfgzYDHy01Ob7m21Wycgf6WLl+xuWsmawDzi4Yz5/LX xs4hR84Stp5r0cJHl/dfp9AUUuVXmgsjWhoyKt7i5HS2LfXVV9K4Rq0n/Qmkhm228GyJ XJEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919714; x=1719524514; 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=DddTKLoW+PPYUSvSFIuzDD8SGvM2v8GitD/QPej7SSQ=; b=au3WIkqZWD+H6XvbqMIStYcve3cKzcWZuEGrqtNt3MrsY3OoIhrucuCkhl5olvp9tH UTJ5yziXl2F5PgpIYnWtKRG0zrOkAtJScuyd9BeESkSWCWQYhCkp0ErD8i/2MA/2lVA5 y1pm20bHXXFHVgypDcgtttG28fCc/C3v0GCQa7EeL5EVJvz4dWt3Nv0l+rs83VF8/BWN zSEzFPfIhKE4tU0yWvGEZj3pNieyf8W/OmC4OdQ4Hzb9NVdBvcMpQS1WgDxvAa09JPOo 0R4KbjFTvjvrUzxgIpnP2crrZJ0TQmhGCaWk4kBU8AnAHvjm52kaq4sanKg3Myx9O5P2 KYoA== X-Forwarded-Encrypted: i=1; AJvYcCV1lpbGbiJ954JN1c3SJSjMU9I0Fh3zjUlBf4Cf3GKzV/es4v444M+GOdsV8u712ltv95OlThLlgDXE74iyxFrhLRfUxr9PpwU8hX+zlfQIzFQL0vyh4kyGgZE3XIQSWN2zHjrSpj5KZzp0znzIfZjR+7h3tsamnxkPGoGU1UA1JkYtJWg= X-Gm-Message-State: AOJu0YyTJRfAB3ve9k0TNPt1jULxPEGzle6mJkQqH+mDN6KN7e8G/Q7r TONyYvVLhxqBtDe0w0gWZVntQNhwQ9qRMw6hJ/MkAlc1MP+rNJu7qWejDg== X-Google-Smtp-Source: AGHT+IGf3fiWg8vvd3bkA6Jv4H54SKxc5jQBJ2LdfCyVfQRTvA8cmsxpUBbjgdxm2nSQG98azGm99A== X-Received: by 2002:a5d:438a:0:b0:362:ec51:b9ea with SMTP id ffacd0b85a97d-36317b7d437mr5263809f8f.34.1718919714148; Thu, 20 Jun 2024 14:41: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-366383f68acsm48866f8f.2.2024.06.20.14.41.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41: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 v7 19/20] leds: leds-lp55xx: Drop deprecated defines Date: Thu, 20 Jun 2024 23:03:35 +0200 Message-ID: <20240620210401.22053-20-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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 54ead09488a5..57df920192d2 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 Thu Jun 20 21:03: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: 806138 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 D6EA615B128; Thu, 20 Jun 2024 21:41:56 +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=1718919719; cv=none; b=nO/hXhzho8Kwmhh8h5QwCJ8hBf+bLpWyTH91KhUq5KmDeaOgB66AvPkW3z41+vFxMpFOG63dxFk+INrfXUuDkbHgGF1GOpLF/xYNYuG1MgX9A1A72ssp6mwfBZVRAYFiTklKXhmL2rsT8j1XOAxLD+j8WQUcIwF8bKPCx3dTtLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718919719; c=relaxed/simple; bh=wINUYX9pejABlv7SU67v72B0Zzb9RE2u3+nIvhutk3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Iwjtjk5MsG3yrXWh6gyMaK/SK6ZhB2Pw+DKiQa/b4y4J/CGyhVaw46pDpanS01HHv5xcEkzUFaN6u3ExICa5W+6hldb1SHxM1vipXQ0pUiyc4UAO1QJxh85XUInF1j2ddPbOKxCobp2yZ7GeWJ3eUmujmzZeIC/hjfV6rqVjek0= 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=VvkwzMVV; 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="VvkwzMVV" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3627ef1fc07so1095277f8f.3; Thu, 20 Jun 2024 14:41:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718919715; x=1719524515; 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=1OQsFZpwEXi9lylzWtTn4BG6KCXD+UB508NyBvv1q2w=; b=VvkwzMVVg9dfm+OLelwvdOq/qW/8k5nLp8WhR4seOd0z/sfNBTOd2V9xwWzpvf7BFp cRsACjji5PSGDs2+XPYJDNq5yFhDqL0QBSILnv9eqsCyG5M1TVntQLOHU2c5beupOWj8 RiHShWEcKoAuVp6h7V9Xc9gpk/iLonrdLLluzzJz6jKZw0Nzs5BzLI8NkBSvoJFTs7JC rS8MFlImC/zZbZlS569hmyjsOFjzCdnlfTH5Yx5z/C+fHXU6Mqgzo5MQW800zrQnRqXe 19L7RkjrviMp6eY33RNFuH5N+Fj08kvJ/k0+9J9PSpQnAy5PgBq3KLC+cFww10G+s6ph TkQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718919715; x=1719524515; 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=1OQsFZpwEXi9lylzWtTn4BG6KCXD+UB508NyBvv1q2w=; b=bI3rxeF0A5SGzNtngtEBJzatxY4cSCXe8Rv84HG7q3yMgncz366cJ/WjpTieGyUJPN lFo9ZEo74iqsyXNp2zhSXQEz0COEjPByhRayioqO2NTvLHpARb+nMAKLG9BdGWqEmIPZ u4vZrWSL3W1zJhsIJPnOt3OkWLYbfx8e3oLrf52dlLJaVfY10MmK5pIaosAnK1cRToWd 646ggroEUw4r3bu9JNRAA9wsHOxA4+BJQCToqyLmatYdgWarymfyfF3yFoL6WIXTUXW9 jlmA6jip9GIL3yR2Q3uPIIikbS+Vw8Rw614mCQWbQ1o/zoB8eVWB41+8DTUjuQ7K9YxC GBag== X-Forwarded-Encrypted: i=1; AJvYcCU/V22yjW7kI4r/JBbFPsHSsl2v4ya+45vkEpE6RTSdYh50DtrXlfpGl5DgM5z9zVgW13/LPCr8VUYmPSEJoDkS+liIONW1bvnzTxcd5oOtmLE381yVTXwcrkT4k83EHmfIHjIkMiUIrRpq//Olj+8HUv6Rm+oDtdI/ys4kTC/EzBeK5RM= X-Gm-Message-State: AOJu0Yz0TBuUOtTKl1h4aL92p/6Bn0KNoy3b+qpCT/2PcYCaoyDO/Gxh nm4VZD8UpYAUjlOsTv3IPB36FxtdZ+AIfDErolDV/8U1UVo3nJfn X-Google-Smtp-Source: AGHT+IEDFY8uqL011VMS+ZYlm7jM0co9XDm/8+p0l+CpcuUFHVpLDjnC9fI4sCPXdEX/5ZHwT/xpxg== X-Received: by 2002:adf:8b91:0:b0:35f:1c34:adfc with SMTP id ffacd0b85a97d-36319a856b9mr4654863f8f.67.1718919715200; Thu, 20 Jun 2024 14:41: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-366383f68acsm48866f8f.2.2024.06.20.14.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:41: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 v7 20/20] leds: leds-lp5569: Add support for Texas Instruments LP5569 Date: Thu, 20 Jun 2024 23:03:36 +0200 Message-ID: <20240620210401.22053-21-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620210401.22053-1-ansuelsmth@gmail.com> References: <20240620210401.22053-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 | 544 +++++++++++++++++++++++++++++++++++++ 3 files changed, 558 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..7ccd8dd6026a --- /dev/null +++ b/drivers/leds/leds-lp5569.c @@ -0,0 +1,544 @@ +// 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, + }, + .reg_master_fader_base = { + .addr = LP5569_REG_MASTER_FADER_BASE, + }, + .reg_led_ctrl_base = { + .addr = LP5569_REG_LED_CTRL_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");