From patchwork Sun Jun 16 21:52:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805048 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.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 074BF4E1D1; Sun, 16 Jun 2024 21:55:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574951; cv=none; b=OWOnjKTS+PLvosVxYfE75tJRxXISPqFzzNNzN8g1SQY5o7Nee0PbhrirEsPEyCLz9a1iVYYsjOII99rDgBqM0G39rCTu101Ks1ld5W/kq+eSI2aOlEASzoKW7xPKcvy3v9+a0FsyperX6pY91Yvc3BGAQYFUr6uhR0JuRXU26x8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574951; c=relaxed/simple; bh=uJNHCAS/njBj0P1AkFg9onLP6rk8u5HT5DX/4ybEeDA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q2X6I4rbrBQSKRf6lo+NFh5TEDlIKBoV2XE3Y5tyNzTHcTwTOfsOu6I0S+/VGuMThHHXIn+AGiKWGAm1U92KOmZaIhrU5U62n2g91HY+QVKMlB/VeHehuLxsiWdSWf0bL1EotubvnBxJW5WMjrIW4V/dLhiQkJSaFET5CEtpdBs= 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=fpzXmw4V; arc=none smtp.client-ip=209.85.221.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="fpzXmw4V" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-354b722fe81so3450722f8f.3; Sun, 16 Jun 2024 14:55:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574948; x=1719179748; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hhl9kavocLfzcqvimV+c3enKC1Q7IIpoT3nV0k3W8no=; b=fpzXmw4Vprl7DXgacMimx1cKAlPeFXuKF7mSS27tWIybQsh7cjhQb5NRW6BhYlNywu gkASKUKzh+UQRXwBZEKJbGMNxyGMoOjY6RQAaUzqyHWYHsFmzQS3JSUOH0hw3VkvSDyS oSqionu91yUbQl0BD88Eo9X0TyMwwsOUFANvfupTRMdT9Ggy9EQwuXcn7Xcrwm3rm4UY JYpbSfUeoBEtWEIVydR54JT7wClFH9xuikCH+b3Xg6Ib1yU9f+caz9cN/Zl6b06mla3X VxrCmfh/T3gzvEnFJJE5MI9vJQsaJUj9AjFRCBlNDBG8fR/ElVWlRJ8Rg1yRPy/16ncy O3wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574948; x=1719179748; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hhl9kavocLfzcqvimV+c3enKC1Q7IIpoT3nV0k3W8no=; b=KOebDACg5qp7eR2SV33zIZssvzSV5+GMXfOmQ4574JYflFWlzyoD/c7oHw0hZfb8pK jmDJcl2VLyqih9VIoMvsJp3+UMP3E2VyWTHAewDHTMrcJ/ChcaQyY9+iL3aOQpUyGPyI 5cW1+QGFVxfCfZUPJiKCg5E4tHgB2agJOyUH3zqPuY5aZofM54vUyRZYIc0eILhX6DOB CpAdsglGAmSBcCUbxG7pzm1CJQbSZ06pcSh39mcxkyzPGsE+6pZ1a8Sbf0+41gLCXIL9 RbiGQFJ+BKJ6tiloNj3Pq7WcYQ4gDjJHqTEU7ockuGLq9s72FAe1Aw7BKKK8W0HdzA+p Fkkg== X-Forwarded-Encrypted: i=1; AJvYcCUtzwlvBMTKG2Le31jn2PoxYanYhN2xdUaK52KIF3bs3nAQC2MfkeCk6MaazcvH+doyuvL1Eg0dFrBJLAXN30/yO5/M+FFvgG0FCiOhAtptR/1SFgSGEh8MNEg65Hor1ENve68WqldgT3PzGb3zW2Gd9qi8zins3H+BHMBjlwmQh0dLkmw= X-Gm-Message-State: AOJu0YxSu25WOo8cLjurcvmFBY8rg+UfiKfSV9YneglafLd4gPa9dt1c PzsnE1KN06Q67b4yCon0w5DHxVUYcBFRBqlLYo1Y0VW1S/xq4cGp X-Google-Smtp-Source: AGHT+IEgDF94nZErxST7KQEgSvSxTmuAcS8oyKSZtBL8UmzZ7Exbh1J6JgGFQF3ns00JV5BnF7tVHw== X-Received: by 2002:a5d:68c6:0:b0:34c:d5e8:faad with SMTP id ffacd0b85a97d-3607a78684dmr5145995f8f.58.1718574948216; Sun, 16 Jun 2024 14:55: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-36075104b74sm10362879f8f.107.2024.06.16.14.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:55: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 v6 01/20] dt-bindings: leds-lp55xx: limit pwr-sel property to ti,lp8501 Date: Sun, 16 Jun 2024 23:52:00 +0200 Message-ID: <20240616215226.2112-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-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 Sun Jun 16 21:52:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804695 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 3844D6E613; Sun, 16 Jun 2024 21:55:50 +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=1718574952; cv=none; b=cJoeXJLGy/+eNoszA29RyTygAux3/z56Obh6U9asIxmwv2zKmqf3MOBAPvIAX/YGVjNivP2+gIB/YLL7pXnk41F7O5zfH4buKzrOgVGPjH7BEuzDi0zxmQ+TG2QWP0c4wENf41CH8wRBY2a9ohbJ2zeTfkn/uEZ1xSYMjesRgno= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574952; c=relaxed/simple; bh=Y77MrkgTPpF9SsM+rM+21V+XO+R9QBEbnKLnh784hwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U+90atUNG5PEaW24DZ0me6MTboi9UTd0hOdmoH9xrvUra5D4hbqQg0U42ayXXTOHs7DNot0/zI45dGLfS35N7Et8Z7mqcYcfDHf1UbfmCCTXlgiVHOgkIFlRx5t8fDHoSaBDvFJEBAqYXBW8tBo0ssQlMbZNW+7v+wAwP0sqPDY= 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=Wt297Ca1; 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="Wt297Ca1" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-35f123bf735so2680171f8f.1; Sun, 16 Jun 2024 14:55:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574949; x=1719179749; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=icpBlnTDdeuMUSDTs5EH982zOvuXd6X7dmffVumwKI8=; b=Wt297Ca1b3EcjUel+RfZrFoVwdAx28rZCFAec+ZJ7jRrkEJUVbPT2ZYBR488ANPANw todDySJoQn61Tnpm+ZXfMGtRXUVnHt6qguvPm9Bb0OUbp+mNPFf30ib0CT12yxsM4wqC JX+VEoaquHvaN5CpKWWYnMelnZffM6GkdobCZtrX53gjsqhBKLUmLch5hlyyvlOqL0ME ZeGuuKCMXw+f7IbkB8ZI44kbieRVYTnp3X4Lmbx/FTnWZOIrK6u/tJplbYBNiEvg4flY S8YN+UPJgy4bck3wPDoCmeFJoyX46cLbE8E7N2njLsXQhz+6ua/6VJ8AmoeSxM8gd0ZB 910A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574949; x=1719179749; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=icpBlnTDdeuMUSDTs5EH982zOvuXd6X7dmffVumwKI8=; b=HPQO4jlX/qhopEm3OwzFn/zpEwN211lvE98AyhJI/UAMn/TpEzIKDgktQJ/3F4Jixf sWhutoN8ppY0c6wdEySrwGpTgkw9LKLh8REDNNoCRgBA3YHtMJI9S3mPjvijZZi0nOBg OO0kJCxqia12nA7KaGW6LjDrtYO8HxmvmsZ1Q8MGkMuRF1whDGJ3zs1TWyuO8o/qSgpe yszfT4+JFczEmAUKiIZ3Jx9mX3CDs/PsJCMA+5m4bKk4sAlwqr5DZtt69JvjkLt3/oIh CO/ffuxIEhRWBFQQbLivlo2cW7GyyFcQU5Sx6hr5LHke2+HeOqxlunSuiVZ74SWf+Cqp /HOg== X-Forwarded-Encrypted: i=1; AJvYcCWUgS08Vp2L3N5XEdX+ci9Bv7hbkkft9ugGBAqScK3acRBKDp5U27GdS5j6sunZ6xdNejJpVnBuG3Nk4iJgW7mZGvrpphIDzqvgwfj41CqXrT2Y/fsNwgBj/GDr2uEznk33uk1tl6DwMXg5b8UmSUGv4goMG/ZYjiOXDVbVkvlaHk5pjVo= X-Gm-Message-State: AOJu0Yz6l6vGGA/Ekn/4ZWlFKhon2SXUStCsldTd4PYJ8Mb+EIQlPZpV ag3d+BWz34xSkZKm9I+Zxf8PFe4FTAItZMcbmk0Bz1Fg6A5U7m8AZq57oA== X-Google-Smtp-Source: AGHT+IHJgmBwiky5lSvxatwNV/9cewou/6GlOJWZH6/sDtaslpWQHn81JRlfEEOiVhikh+Qv3C22IA== X-Received: by 2002:a5d:6a50:0:b0:35f:306b:4de5 with SMTP id ffacd0b85a97d-3607a7e2244mr6897138f8f.48.1718574949298; Sun, 16 Jun 2024 14:55: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-36075104b74sm10362879f8f.107.2024.06.16.14.55.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:55: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 , Conor Dooley Subject: [PATCH v6 02/20] dt-bindings: leds-lp55xx: Add new ti,lp5569 compatible Date: Sun, 16 Jun 2024 23:52:01 +0200 Message-ID: <20240616215226.2112-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-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 Sun Jun 16 21:52:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805047 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12A646FE21; Sun, 16 Jun 2024 21:55:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574954; cv=none; b=fH80n94fA9qxeAUYf5l6ZZgHwLCZLJb7T0KxIm0T/9LbDAPzi6SzBY5JiKNg9jYCnOFkJqDVMH0gVKUhkP6WTw8SIkNSNUEj9mZ7B5MyFU94K//ssZOTd5Dv4I+Xnogcj+1T/4DqllT62vxW6FPXXm8LdhOErq8lVirWEmTIzkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574954; c=relaxed/simple; bh=DWMsgU98EjA/nGA8gHZo8pVtEColkPbAo4l6SDd4tZk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QjCKa5VoYvdg0cBeKYKxN6XM+uYSPBnohxVF4UfMfYPHwGND8tF1LSsVpbFtnJHKJYTxX+WbHSz6+QatNtb/3X08fvYk8gGRQtgIsv0PEHlS54AvOqV+OgxNUsWUW+lW0uzjqOYw/fKxV21RWymE0J8hU0EIQ3X7nOq7X3EIx9s= 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=IyHBxyDg; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IyHBxyDg" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-35f1bc63981so2913379f8f.1; Sun, 16 Jun 2024 14:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574950; x=1719179750; 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=5sPiZdGEOdfWoEJbgRox80kKk06PGEyb7AnPIHKYhOE=; b=IyHBxyDgdFLisw+J0BUueBBOzOK6bpM21YE0rdIAAbo52g9/0sJfBnIeSNf+RERKKk ozvyp3nQjSljrHr/4+3THQqA6Zv9zqf/78aN8+ze5rab9Jvw9jGmBoLa5uqMKzsy3IID LHGV91mLPa7lk+W4KpmnSed+gdhMWNtE7KCK+Ev5gqaqobamyz/fN8xAoib9m30CCK37 nBBlEuZhkZGlse9k1D2x9hoD3xq6fgnbwHMTKvgCV/PzIjiB/dqsInkjflgIq9wOgkX0 BDAJ1G4kXgSrWtv5DW70YyziAF/r2SE3jVj351Shr75jTRVaisKeMFpYoUrM2bUhdhuh /CSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574950; x=1719179750; 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=5sPiZdGEOdfWoEJbgRox80kKk06PGEyb7AnPIHKYhOE=; b=iEV3e8QSnjBTKeZEEmrXmvoIkUgS4yw0SqNVtYGTraXtse43UeZufFD4iGFC7oEklq dU9jmCNOcH4yO3yKo6GuXLFsyWQ/9xqQ53Ym/AchB/xY1Wnoommzx7prxAOafVCyD7wL ja83apH7t9Nwz9gW7i2lULuJPUJWWH8YNA31QVtOLBPNxG0vUYQLl1TDqki9KnTXQQZh b1rd0XSB77lu/fd3l9SxS2a0sAssoW0RDNcgRPmDKrkIoX4zs7cbS58fQ+HIaLtKKxlZ J5Tfa4oUgqv0Y54g4h0SN3QjviphoaZN3GX0s7CQn7++iOwo1nAnEwPtWqfhp90QffEC CI5g== X-Forwarded-Encrypted: i=1; AJvYcCUEcXhIGLgfyh4oBJdbc/N3OMdni3KMonGJb9+MKr1/aJzo4JRg1ZjO1zg/6kH7l48Q4D/sXmWpldGSzg/yUh+yRxonBYY+pEnnxYkHcF2HcvxEH0KgAxfu2kjOSWK6uPoaG5pmZsxPsz8CUmTErLdpda8+Sc6k1hF3wmQu2g087kPuD+I= X-Gm-Message-State: AOJu0YzuAT72DyAY9mQuRWX9CCMIIxh8dryVKm2BJY9Bql+nyLxDmCVK ljdwFZLzclf/RuvsRDcWabIwu6RBmA56zfUORpU3Js4PidcfBkuB X-Google-Smtp-Source: AGHT+IEUYIYaIieERl7figqK/ff5zypy6bzT+FM3yv0sY9kYfy8/PqBYCToXIE/nsdaccEDz3rOIMg== X-Received: by 2002:a5d:5408:0:b0:360:965a:b53 with SMTP id ffacd0b85a97d-360965a0b71mr481475f8f.33.1718574950220; Sun, 16 Jun 2024 14:55: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-36075104b74sm10362879f8f.107.2024.06.16.14.55.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:55: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 v6 03/20] leds: leds-lp55xx: generalize stop_all_engine OP Date: Sun, 16 Jun 2024 23:52:02 +0200 Message-ID: <20240616215226.2112-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In all the lp55xx based driver, we have a similar implementation of the stop_all_engine function with the only difference of the required sleep for the OP MODE change. The main difference is legacy LEDs require a min of 152 us while new one use a generic 1-2ms. The new one use a 1-2ms sleep as suggested in the datasheet IN ALTERNATIVE to a much more robust approach by using the newly introduced ENGINE_BUSY bit in the STATUS reg. To better handle sleep after OP MODE change, add support for polling the ENGINE_BUSY bit and use the legacy sleep for old LEDs. With this change, stop_all_engine can be generalized and moved to lp55xx-common. To make more clear the double usage of lp55xx_reg, define a union for additional scope of mask and shift. Update all lp55xx based driver to use the new generalized function and define the required bits in the device_config struct. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 11 ++++------ drivers/leds/leds-lp5523.c | 20 ++++++++++------- drivers/leds/leds-lp5562.c | 15 ++++++------- drivers/leds/leds-lp55xx-common.c | 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 Sun Jun 16 21:52:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804694 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 2B1CE73445; Sun, 16 Jun 2024 21:55:52 +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=1718574955; cv=none; b=gFlGP8flCRX2ZvXP1nRcA/buHYGZ/3iYyR+cqfimMRTvbXZiq0B+Ek93eXpRzRFLw7Xm3C9EHivmKgE3gdIVj03do6W4df/ABg7oTstsSGUH6rDArfAyOXEi7tECcH7R6HKnt8OifSHFnpUG9CaFkiUHkr1O7larUNYr91WFxxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574955; c=relaxed/simple; bh=D+m1L5PapfPb0QEhBfL/fexXfSyHs0tFiyCyLseC7d4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Feqx3l45PzS1OHFCfdWdzIauM45gwvvohyV8YudzG58Ul9cOtBrrAmUVTjjd2crJysyXbpX1eeMw5r1GpoKFPQ99WmisSrQvk45zgF3vAePFfwDmHbEyYn5ostmYehpyShdN3TsZbciTM/31iAGmC8rBtRew6TPWfzl62ks0kA8= 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=PI4729fP; 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="PI4729fP" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-35f1c209842so2861779f8f.3; Sun, 16 Jun 2024 14:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574951; x=1719179751; 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=nzWmmV5lLGO/kDDsghSyyH6GIF1fBoQT5IQ42I5GYNY=; b=PI4729fPUGw37cakY5mZ+b5J3GMFNcw0lUmIGUJyhdPATKY2hTyZV4EBwJPj44Obel dLz6+i99HQE/PYsCUsiJVaDnsDeCDIL0PkcKiAb49x3Goc67UidF/GYtjU4sfKQeCjY3 MgfyRk6Z3BEO83Wb8x0kc8vt/K+TYvOlwqIZ7n/rhCNc/Z88lqfphYVSse2PNHrrgmTh Vdt3BABgLQlWyNXFGv+B6FZoqr4X0LaWkvyDViUIDl8vA/rYaQDziy4QeqTmAN+8n/JB FYxj3hynX+5LoPedVjqNEZainnIwUlvzLgJqhOKm5sEAhWW6ANBiYZnMrJ2VnMMi1P24 9nng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574951; x=1719179751; 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=nzWmmV5lLGO/kDDsghSyyH6GIF1fBoQT5IQ42I5GYNY=; b=gSXEo8vm3hboiRD1gaWBW0XnkzF/yDsoskDE3GhXJkoec1TZA5XR6d7S2cbFCvXSrG fGkGtqBLm6+7vsWKMq05VxnpVBjdU8BFBGgOeAZLRGp5shKtILP9kxbdP2YisqoE/Tzx h0cc3P86fpO2vF8jmHD8SAyroccaEDvHNz3WgZ89YNzR3bGX3sAK3kAsFomUIP16Podf QP1UxkTfC99kTVLRUCVzaT7QEmwMjksQKdEdXI9EzoJxDiIK2MdLOSqLn0wBw6+0eJz9 0VsPkAn4R41OBr/CbN44RMW1R/+2bffkhZPBKxSEkypeYIM9ILM6k3yKWz1I+6LUll6a JRTw== X-Forwarded-Encrypted: i=1; AJvYcCUqd/PEAdqIeS/c+2SJTnvd3UDVmSYA/N+UQAlTczEgoeCE2U0R23UxotqJ5Kz5ukMg7s3ebT/kjbo9ipUQ+4+lLy4WTJqU8eMtHCmMeitUIeAfSQ6u/t+gNdHmg/rD43d+AICkGGdQBLuVDDzQZi4QSJK8QPJeDx+q+ygMA0ZEFWcdoHw= X-Gm-Message-State: AOJu0Yw74gbl2xKwBK50sXuYyGC8dwOrKf6BXPtOikr0J4AuPUAwuUL/ CgqnjuS7EpXA+kZwikpJZIG3LCjW6NOTeHHRX6YtCGkrFHLMhr09 X-Google-Smtp-Source: AGHT+IFb4jmTzPLeORZUwEaD95ny3WMX/WHU5M5q/TLFkTF9pMQxCRBr+cziJ7Fu8BJAwLs4CjlsYA== X-Received: by 2002:a5d:528b:0:b0:35f:488:6d3d with SMTP id ffacd0b85a97d-3607a781081mr5222801f8f.58.1718574951397; Sun, 16 Jun 2024 14:55:51 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36075104b74sm10362879f8f.107.2024.06.16.14.55.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:55: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 v6 04/20] leds: leds-lp55xx: generalize probe/remove functions Date: Sun, 16 Jun 2024 23:52:03 +0200 Message-ID: <20240616215226.2112-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that stop_all_engine is generalized, probe and remove function are the same across every lp55xx based LED driver and can be generalized. To permit to use a common probe, make use of the OF match_data and i2c driver_data value to store the device_config struct specific for the LED. Also drop the now unused exported symbol in lp55xx-common and make them static. Update any lp55xx based LED driver to use the new generic probe/remove. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 81 +------------------- drivers/leds/leds-lp5523.c | 85 ++------------------- drivers/leds/leds-lp5562.c | 80 +------------------ drivers/leds/leds-lp55xx-common.c | 123 +++++++++++++++++++++++------- drivers/leds/leds-lp55xx-common.h | 21 +---- drivers/leds/leds-lp8501.c | 81 +------------------- 6 files changed, 119 insertions(+), 352 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 15ef5ae58623..5015f385cc17 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -514,87 +514,14 @@ static struct lp55xx_device_config lp5521_cfg = { .dev_attr_group = &lp5521_group, }; -static int lp5521_probe(struct i2c_client *client) -{ - const struct i2c_device_id *id = i2c_client_get_device_id(client); - int ret; - struct lp55xx_chip *chip; - struct lp55xx_led *led; - struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev); - struct device_node *np = dev_of_node(&client->dev); - - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); - if (!chip) - return -ENOMEM; - - chip->cfg = &lp5521_cfg; - - if (!pdata) { - if (np) { - pdata = lp55xx_of_populate_pdata(&client->dev, np, - chip); - if (IS_ERR(pdata)) - return PTR_ERR(pdata); - } else { - dev_err(&client->dev, "no platform data\n"); - return -EINVAL; - } - } - - led = devm_kcalloc(&client->dev, - pdata->num_channels, sizeof(*led), GFP_KERNEL); - if (!led) - return -ENOMEM; - - chip->cl = client; - chip->pdata = pdata; - - mutex_init(&chip->lock); - - i2c_set_clientdata(client, led); - - ret = lp55xx_init_device(chip); - if (ret) - goto err_init; - - dev_info(&client->dev, "%s programmable led chip found\n", id->name); - - ret = lp55xx_register_leds(led, chip); - if (ret) - goto err_out; - - ret = lp55xx_register_sysfs(chip); - if (ret) { - dev_err(&client->dev, "registering sysfs failed\n"); - goto err_out; - } - - return 0; - -err_out: - lp55xx_deinit_device(chip); -err_init: - return ret; -} - -static void lp5521_remove(struct i2c_client *client) -{ - struct lp55xx_led *led = i2c_get_clientdata(client); - struct lp55xx_chip *chip = led->chip; - - lp55xx_stop_all_engine(chip); - lp55xx_unregister_sysfs(chip); - lp55xx_deinit_device(chip); -} - static const struct i2c_device_id lp5521_id[] = { - { "lp5521", 0 }, /* Three channel chip */ + { "lp5521", .driver_data = (kernel_ulong_t)&lp5521_cfg, }, /* Three channel chip */ { } }; MODULE_DEVICE_TABLE(i2c, lp5521_id); static const struct of_device_id of_lp5521_leds_match[] = { - { .compatible = "national,lp5521", }, + { .compatible = "national,lp5521", .data = &lp5521_cfg, }, {}, }; @@ -605,8 +532,8 @@ static struct i2c_driver lp5521_driver = { .name = "lp5521", .of_match_table = of_lp5521_leds_match, }, - .probe = lp5521_probe, - .remove = lp5521_remove, + .probe = lp55xx_probe, + .remove = lp55xx_remove, .id_table = lp5521_id, }; diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 79931555eddd..bd0209e2ee42 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -895,90 +895,17 @@ static struct lp55xx_device_config lp5523_cfg = { .dev_attr_group = &lp5523_group, }; -static int lp5523_probe(struct i2c_client *client) -{ - const struct i2c_device_id *id = i2c_client_get_device_id(client); - int ret; - struct lp55xx_chip *chip; - struct lp55xx_led *led; - struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev); - struct device_node *np = dev_of_node(&client->dev); - - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); - if (!chip) - return -ENOMEM; - - chip->cfg = &lp5523_cfg; - - if (!pdata) { - if (np) { - pdata = lp55xx_of_populate_pdata(&client->dev, np, - chip); - if (IS_ERR(pdata)) - return PTR_ERR(pdata); - } else { - dev_err(&client->dev, "no platform data\n"); - return -EINVAL; - } - } - - led = devm_kcalloc(&client->dev, - pdata->num_channels, sizeof(*led), GFP_KERNEL); - if (!led) - return -ENOMEM; - - chip->cl = client; - chip->pdata = pdata; - - mutex_init(&chip->lock); - - i2c_set_clientdata(client, led); - - ret = lp55xx_init_device(chip); - if (ret) - goto err_init; - - dev_info(&client->dev, "%s Programmable led chip found\n", id->name); - - ret = lp55xx_register_leds(led, chip); - if (ret) - goto err_out; - - ret = lp55xx_register_sysfs(chip); - if (ret) { - dev_err(&client->dev, "registering sysfs failed\n"); - goto err_out; - } - - return 0; - -err_out: - lp55xx_deinit_device(chip); -err_init: - return ret; -} - -static void lp5523_remove(struct i2c_client *client) -{ - struct lp55xx_led *led = i2c_get_clientdata(client); - struct lp55xx_chip *chip = led->chip; - - lp55xx_stop_all_engine(chip); - lp55xx_unregister_sysfs(chip); - lp55xx_deinit_device(chip); -} - static const struct i2c_device_id lp5523_id[] = { - { "lp5523", LP5523 }, - { "lp55231", LP55231 }, + { "lp5523", .driver_data = (kernel_ulong_t)&lp5523_cfg, }, + { "lp55231", .driver_data = (kernel_ulong_t)&lp5523_cfg, }, { } }; MODULE_DEVICE_TABLE(i2c, lp5523_id); static const struct of_device_id of_lp5523_leds_match[] = { - { .compatible = "national,lp5523", }, - { .compatible = "ti,lp55231", }, + { .compatible = "national,lp5523", .data = &lp5523_cfg, }, + { .compatible = "ti,lp55231", .data = &lp5523_cfg, }, {}, }; @@ -989,8 +916,8 @@ static struct i2c_driver lp5523_driver = { .name = "lp5523x", .of_match_table = of_lp5523_leds_match, }, - .probe = lp5523_probe, - .remove = lp5523_remove, + .probe = lp55xx_probe, + .remove = lp55xx_remove, .id_table = lp5523_id, }; diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index 28469bd2c75b..65a6a05c3848 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -508,86 +508,14 @@ static struct lp55xx_device_config lp5562_cfg = { .dev_attr_group = &lp5562_group, }; -static int lp5562_probe(struct i2c_client *client) -{ - int ret; - struct lp55xx_chip *chip; - struct lp55xx_led *led; - struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev); - struct device_node *np = dev_of_node(&client->dev); - - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); - if (!chip) - return -ENOMEM; - - chip->cfg = &lp5562_cfg; - - if (!pdata) { - if (np) { - pdata = lp55xx_of_populate_pdata(&client->dev, np, - chip); - if (IS_ERR(pdata)) - return PTR_ERR(pdata); - } else { - dev_err(&client->dev, "no platform data\n"); - return -EINVAL; - } - } - - - led = devm_kcalloc(&client->dev, - pdata->num_channels, sizeof(*led), GFP_KERNEL); - if (!led) - return -ENOMEM; - - chip->cl = client; - chip->pdata = pdata; - - mutex_init(&chip->lock); - - i2c_set_clientdata(client, led); - - ret = lp55xx_init_device(chip); - if (ret) - goto err_init; - - ret = lp55xx_register_leds(led, chip); - if (ret) - goto err_out; - - ret = lp55xx_register_sysfs(chip); - if (ret) { - dev_err(&client->dev, "registering sysfs failed\n"); - goto err_out; - } - - return 0; - -err_out: - lp55xx_deinit_device(chip); -err_init: - return ret; -} - -static void lp5562_remove(struct i2c_client *client) -{ - struct lp55xx_led *led = i2c_get_clientdata(client); - struct lp55xx_chip *chip = led->chip; - - lp55xx_stop_all_engine(chip); - - lp55xx_unregister_sysfs(chip); - lp55xx_deinit_device(chip); -} - static const struct i2c_device_id lp5562_id[] = { - { "lp5562", 0 }, + { "lp5562", .driver_data = (kernel_ulong_t)&lp5562_cfg, }, { } }; MODULE_DEVICE_TABLE(i2c, lp5562_id); static const struct of_device_id of_lp5562_leds_match[] = { - { .compatible = "ti,lp5562", }, + { .compatible = "ti,lp5562", .data = &lp5562_cfg, }, {}, }; @@ -598,8 +526,8 @@ static struct i2c_driver lp5562_driver = { .name = "lp5562", .of_match_table = of_lp5562_leds_match, }, - .probe = lp5562_probe, - .remove = lp5562_remove, + .probe = lp55xx_probe, + .remove = lp55xx_remove, .id_table = lp5562_id, }; diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 2cbc5b302fd4..7e623e4e565c 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -32,6 +32,8 @@ /* External clock rate */ #define LP55XX_CLK_32K 32768 +static void lp55xx_deinit_device(struct lp55xx_chip *chip); + static struct lp55xx_led *cdev_to_lp55xx_led(struct led_classdev *cdev) { return container_of(cdev, struct lp55xx_led, cdev); @@ -49,7 +51,7 @@ static struct lp55xx_led *mcled_cdev_to_led(struct led_classdev_mc *mc_cdev) static void lp55xx_wait_opmode_done(struct lp55xx_chip *chip) { - struct lp55xx_device_config *cfg = chip->cfg; + const struct lp55xx_device_config *cfg = chip->cfg; int __always_unused ret; u8 val; @@ -69,7 +71,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 +80,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 +90,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 +113,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 +178,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 +189,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 +199,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 +461,10 @@ bool lp55xx_is_extclk_used(struct lp55xx_chip *chip) } EXPORT_SYMBOL_GPL(lp55xx_is_extclk_used); -int lp55xx_init_device(struct lp55xx_chip *chip) +static int lp55xx_init_device(struct lp55xx_chip *chip) { struct lp55xx_platform_data *pdata; - struct lp55xx_device_config *cfg; + const struct lp55xx_device_config *cfg; struct device *dev = &chip->cl->dev; int ret = 0; @@ -512,9 +514,8 @@ int lp55xx_init_device(struct lp55xx_chip *chip) err: return ret; } -EXPORT_SYMBOL_GPL(lp55xx_init_device); -void lp55xx_deinit_device(struct lp55xx_chip *chip) +static void lp55xx_deinit_device(struct lp55xx_chip *chip) { struct lp55xx_platform_data *pdata = chip->pdata; @@ -524,12 +525,11 @@ void lp55xx_deinit_device(struct lp55xx_chip *chip) if (pdata->enable_gpiod) gpiod_set_value(pdata->enable_gpiod, 0); } -EXPORT_SYMBOL_GPL(lp55xx_deinit_device); -int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip) +static int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip) { struct lp55xx_platform_data *pdata = chip->pdata; - struct lp55xx_device_config *cfg = chip->cfg; + const struct lp55xx_device_config *cfg = chip->cfg; int num_channels = pdata->num_channels; struct lp55xx_led *each; u8 led_current; @@ -566,12 +566,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 +584,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 +687,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 +746,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 Sun Jun 16 21:52:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805046 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C5227345F; Sun, 16 Jun 2024 21:55:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574956; cv=none; b=pcRnOJzMBqu2A4ge7PpSkAX/7s6aGfZ87a0M1ucjH+M/gJhiicRoMu3DqDc/Rw3Zrrai9d0rbB05sJC+QIrzrNZeBcd/LHgRsYJqm5HMo+nVgWG/mf4CmcIrMoshMNnJvC2+7XyIr3mBXE7EFplVSlqCXi6CbjShscTGkELDeJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574956; c=relaxed/simple; bh=3TZ+IebQtYNEXETmGfpCGMwFMo4N+rTh0reuo4DJlRk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lxG4SStb1ANiyKJZFSBKExYUtcaRb0St6pRhI0X8QmgIpxBMoDtwU/YARB0o6vHba6rKJd72l/uAnug97ij/85ce0CH83pZJ341n492JMgfwK6JmjmJxW9/qBdd07pWudIRifyBJppYNGpivpVIlc012mVCYU9LmEueHQ1fawSk= 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=DJcM3XnM; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DJcM3XnM" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-35f1c209893so4050056f8f.2; Sun, 16 Jun 2024 14:55:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574952; x=1719179752; 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=5+mZzmcMGNCU/o0RXAUSzS4dO6BSnvu96jojHKExu4w=; b=DJcM3XnMxrKWt/UOYW7+ZATi9q6k5OEnAjYk/lbvGWvAix/PqjIx2ioCk+9onphMtr V2N/gO3BXf4hCWPxZGQ5b9Qa/BNXIWGCssaIyT7ngBwzoSKP9AOwb9DptthVLRbYiTix hB3rq+EdyFOwfVZ7jC3tvKXMNq8abHrebb1Mq3y9H0WQR1r1ayva7UaByR6jY4fBqPox qoAuAW1I3e3x3qli/G2+oLpSv9okvX/vf6f0N8XR8elLpixaThWnoQuRk3t0d4yHhRP/ F93nisFCIp5oyq29WRqSShLRx40M2kOnLPmYN3oCvuiwxZ9K98cISDWhgWG1Zh6HXve8 X4mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574952; x=1719179752; 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=5+mZzmcMGNCU/o0RXAUSzS4dO6BSnvu96jojHKExu4w=; b=FRbwKEM72T71e9E/LwyVfDO3iqwxFdAgW3XCVIq3d2qZ0HZ6vtT+RVR1sRslNyHPMP TyD4a3DXvmw/P7UBuIJbmQZ8sXPo4Y4O7aDpk2kooQsS5fzYrpPZTRBIlDyLczGi2tCt O8FpCaZ1qM7iCM96MTI6isuWxSGNtClzqd7N96QZcGHH0o6oauflU+uvh/FjRcuGMgUi fmy7ERPdPXQarX7L24iG2IFk3+zGI1RdZOeHI70nJsYcZ3Dv4cJ1nRjwCFviKNoMicw/ PPQcbqCwvzA+oAYqi/1wAzPCIyGwUL30V9N20NuMjOqG4z6DHGr07gmLZ20U//LmsOVE Payg== X-Forwarded-Encrypted: i=1; AJvYcCWVT/yCjJmfQ8+VfAde5PJJOFlok1tWu4qndaUYVhmXHheE5UBLwroQddxnVjkJAbd5lCcCVQx1cAWSNUiF6DwntGSVF4yNnyEDECbmjivQCGMqsIMhMXJowHk6A3iw+zatxLZ6eb6osg4VpAiM8yh6Pz4K8gcQAyInha5JtV33ZGzYX7g= X-Gm-Message-State: AOJu0YxoZ0UQblPPZXWfNacv+SKayE5O5QeWvJSl3bEjJyjHetijTuT1 YjllvU4Ax301ymm60pjfBKA6XWWTmYGeYmdLAvKMH0/G6k94+a6F X-Google-Smtp-Source: AGHT+IEa+9RKa05J7p7VCepRb9k1SliaBxeh9TbVFjiCez7kzmvETQOt8o9CvYxvUaisZ2wCEvpAZQ== X-Received: by 2002:adf:e943:0:b0:360:71e0:8e69 with SMTP id ffacd0b85a97d-3607a761dcdmr6769784f8f.26.1718574952360; Sun, 16 Jun 2024 14:55: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-36075104b74sm10362879f8f.107.2024.06.16.14.55.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:55: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 v6 05/20] leds: leds-lp55xx: generalize load_engine function Date: Sun, 16 Jun 2024 23:52:04 +0200 Message-ID: <20240616215226.2112-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 LED driver based on lp55xx have all a very similar implementation for load_engine function. Move the function to lp55xx-common and rework the define to be more dynamic instead of having to declare a temp array for them. Engine mask are the same for every LED based on lp55xx. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 26 +++--------------------- drivers/leds/leds-lp5523.c | 26 +++--------------------- drivers/leds/leds-lp5562.c | 24 ++-------------------- drivers/leds/leds-lp55xx-common.c | 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 7e623e4e565c..b5a5ba7c80e4 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 @@ -78,6 +95,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 Sun Jun 16 21:52:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804693 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 0A0A16CDB1; Sun, 16 Jun 2024 21:55:54 +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=1718574956; cv=none; b=RRaLnKcXJwKmE4bzuLFjhCL2ID5xECLuZ3j03bLrb15lT2V1/IUZbrYY7fUv88GBdpzKZMQmZfs5NAM4y6+VhipLRFBUXefa4Mbb62A3L+XoU2tIXYrC+ePLfJwmK0S5+ynkg4LYNFJvLGkI+PfCq90PVDG7ZU5lvhXqLKWb+pg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574956; c=relaxed/simple; bh=ofm1/aqbQ8vyZsai7B92L51HhpZdqT6diDCk8mc9/HE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bGyXUJNXlRZjMwzLOALTv7/UfeyExH1wDtH+DPy/e1CVB3tSnj5bZhV+ebof7pTz63EwaNl7HDv5rfN5U61WfcuuYZZ83HBqyawlsRJOT8zfPohoGDQ5ofVxMwTERVcr6gO6vgc0/GiMqFiyZGkGhFpb+rdDgGMya0Fef3vyrU0= 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=PyoURJBU; 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="PyoURJBU" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-35dc9cef36dso3459185f8f.3; Sun, 16 Jun 2024 14:55:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574953; x=1719179753; 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=y4N1QzuzwTokHn8cBWRXHr0MFuy3qvLg8M7dbWmQS14=; b=PyoURJBU0ZnS9i0h8GSl9F7Abgo7QaMwvxG/bqzboVLN2tYrzCLL6zccMChEijWFkX HJTTieGrwKDnhW9xJvdOx1w2H3aNGbwb45HkH23e/0akDNufNckNzgagSg3Kt4bL/P0F ZIJaDEccrQaQ4h41w0dR6hT5k1l5tQMob9PyNfEt+67Q3KLBF/AVPTWRTtk4E39K77+E 6Iryl7bp/kg0AULOZZSI1qMbjTACI7NhAm8+dmcL+7SeXl9bYU7c2WeqCXKhPhnt8Iig dzDSI9JxuT6e38NgNZMpspJmIwxrOjBEugwum+uV7ZElVoKKt2pmZ1Hfk4d6egZBdeNJ Ubbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574953; x=1719179753; 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=y4N1QzuzwTokHn8cBWRXHr0MFuy3qvLg8M7dbWmQS14=; b=bBzbWjCYg/LrYDqHiYb3exOG6J+OVOTlT/uBKtq++Df2ez5VIt05C0ZmP/RXa/dqRZ 4ZwBFZR0uTN5zM38dK/WnUM6NZ8/OnnuVg3tqNYGxi84Zq+RHWAWi65vbt+PTj2IChUo s2vTjT93YJHTcu8cCpUMoaRnVIvOjKegiUR6yJViHo5eSNBvG+vgNaIByzK+VgMFC+sj v+Gqhy+InZAsrDBOztyagJY/XC1HcsP7RIKmB3ynnjOq4FJHv7l7Ym39OqSa/vfApmNt FvZGzPtKsWVA8kcyzT3Og0Iwzu4znwfm/69E+lYrCumem3kpnnhY6R4kY9Bm3lYphlkb CjDw== X-Forwarded-Encrypted: i=1; AJvYcCW28f7uv8NM9rIMpjAEfxrcV5lWXFzkabGQtGcWGQqN3THHVqpoy6juElhGXZ7r0Y+/DaLVIXsDpda5sAKU6YKchbSip5AAD/t2NWU2ZiQjW5qUJ5y4PAfMmbyXmIZapHlwMqG6Oel+AzvTJtqTS+tczUmcbvZ2HcxhWZ4eBPb8VlRzXqk= X-Gm-Message-State: AOJu0YzeimHax6sKqVpwp+LIrkcP2ZIdMPtjoytLhVOOBRF7GVplXqpv Vg4ir1tRdgl8kkfUsbkG5/4fK2cC1slMIidD0XADO1EcuoKYdvCO X-Google-Smtp-Source: AGHT+IHd+xrJwbuOIV+bwfkNuunqhoJ2y711quJGp4yOiyv6HQEugqt5+WAeaS6KDt9JUkkDXwFjOQ== X-Received: by 2002:adf:cd8c:0:b0:360:791c:aff0 with SMTP id ffacd0b85a97d-3607a72039cmr5853072f8f.8.1718574953315; Sun, 16 Jun 2024 14:55: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-36075104b74sm10362879f8f.107.2024.06.16.14.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:55: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 v6 06/20] leds: leds-lp55xx: generalize load_engine_and_select_page function Date: Sun, 16 Jun 2024 23:52:05 +0200 Message-ID: <20240616215226.2112-7-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize load_engine_and_select_page by reworking the implementation and making it part of the generic load_engine function. Add a new option in device_config, pages_per_engine used to define pages assigned to each engine. With this option set, it's assumed LED chip supports pages and load_engine will correctly setup the write page. An equal amount of pages is assigned to each engine and they are assigned from page 0. Update any lp55xx based LED driver to define the option and use the new function. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5523.c | 22 +++++----------------- drivers/leds/leds-lp55xx-common.c | 10 ++++++++++ drivers/leds/leds-lp55xx-common.h | 3 +++ drivers/leds/leds-lp8501.c | 19 +++---------------- 4 files changed, 21 insertions(+), 33 deletions(-) diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 086b4d8975a4..8dabd5814110 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -30,6 +30,7 @@ * 0x40 engine 2 muxing info * 0x50 engine 3 muxing info */ +#define LP5523_PAGES_PER_ENGINE 1 #define LP5523_MAX_LEDS 9 /* Registers */ @@ -159,20 +160,6 @@ static int lp5523_post_init_device(struct lp55xx_chip *chip) return lp5523_init_program_engine(chip); } -static void lp5523_load_engine_and_select_page(struct lp55xx_chip *chip) -{ - enum lp55xx_engine_index idx = chip->engine_idx; - static const u8 page_sel[] = { - [LP55XX_ENGINE_1] = LP5523_PAGE_ENG1, - [LP55XX_ENGINE_2] = LP5523_PAGE_ENG2, - [LP55XX_ENGINE_3] = LP5523_PAGE_ENG3, - }; - - lp55xx_load_engine(chip); - - lp55xx_write(chip, LP5523_REG_PROG_PAGE_SEL, page_sel[idx]); -} - static void lp5523_stop_engine(struct lp55xx_chip *chip) { enum lp55xx_engine_index idx = chip->engine_idx; @@ -272,7 +259,7 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) /* write LED MUX address space for each engine */ for (i = LP55XX_ENGINE_1; i <= LP55XX_ENGINE_3; i++) { chip->engine_idx = i; - lp5523_load_engine_and_select_page(chip); + lp55xx_load_engine(chip); for (j = 0; j < LP5523_PROGRAM_LENGTH; j++) { ret = lp55xx_write(chip, LP5523_REG_PROG_MEM + j, @@ -362,7 +349,7 @@ static void lp5523_firmware_loaded(struct lp55xx_chip *chip) * 2) write firmware data into program memory */ - lp5523_load_engine_and_select_page(chip); + lp55xx_load_engine(chip); lp5523_update_program_memory(chip, fw->data, fw->size); } @@ -544,7 +531,7 @@ static ssize_t store_engine_load(struct device *dev, mutex_lock(&chip->lock); chip->engine_idx = nr; - lp5523_load_engine_and_select_page(chip); + lp55xx_load_engine(chip); ret = lp5523_update_program_memory(chip, buf, len); mutex_unlock(&chip->lock); @@ -865,6 +852,7 @@ static struct lp55xx_device_config lp5523_cfg = { .addr = LP5523_REG_ENABLE, .val = LP5523_ENABLE, }, + .pages_per_engine = LP5523_PAGES_PER_ENGINE, .max_channel = LP5523_MAX_LEDS, .post_init_device = lp5523_post_init_device, .brightness_fn = lp5523_led_brightness, diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index b5a5ba7c80e4..fd94dc708951 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 @@ -106,6 +111,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 Sun Jun 16 21:52:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805045 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 23DB66E613; Sun, 16 Jun 2024 21:55:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574958; cv=none; b=DQ2mPL8pRmr7z1KTWzWcNP5WGPtCQpctQxQSuEZNGRyVKhZ93U00g++C3MyrxeZAVOfJby6jwCRsQF1gu5R3Quf53e58sCwlkXbGeeFtI/OMzhF2uWCcdyShnSfQ3o6h50erbJwMrOVBdhzOO/Ys2iBZjsdq+JyMYgvMS4/9NSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574958; c=relaxed/simple; bh=Hp4CNik2QpOCAtvxZmqZD1buhNWIVxKCqjcPBUQr9HE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cr0fYsa9JXnMAkq6ddmMVmQlGJ0gZv3hHPvEkSjJWl7z/JxaU7gzZhE7z5GrEqGM5MOElF7z1PhlcDls0pMztPuK/58doBueUouM8j77aX2gNiyyoQY0xjI5DFtj+a2vTtWYmvSOIkEm2VkgyaRNU98gn0whctFnutUgw8skArQ= 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=jwYVyND/; arc=none smtp.client-ip=209.85.221.54 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="jwYVyND/" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-35f1a7386d5so3399778f8f.3; Sun, 16 Jun 2024 14:55:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574954; x=1719179754; 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=9R5HeykZlPSSzfgICXJqQhrwmQuHkAiBQA32m3GVb4M=; b=jwYVyND/e9nMKth2bRTOpbXSMipgC1O3W5ldHKyGsg+55kHXiQDYhXL7fUf/XmaLxh 14oIEiIwjq95Pku+Xq+lfIIFFaso9pPpClOi7IwiNnaznQSEvin+HxfuSkRPOW44s+Le 7fSXvDmIljoZhkwazeFloSAUovs1A39x+q+US4Jcu3rXUbKCfUKKlLO1mQBm9d3ICaso XZXSlsDzDJHEtgtKUxKmR1vw52maPsxfQXCj1imUicRPt8IOO6GaNf7c0TJsDokSlZL+ 5E2oMg39jzYJgnT5Q59TuOz3vu4FJD6wYediRi+VsH9e8NxBAaBpCmYNfuvJ6QhuehqV gHGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574954; x=1719179754; 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=9R5HeykZlPSSzfgICXJqQhrwmQuHkAiBQA32m3GVb4M=; b=C61UJ29yaOXLp/dXOyyhNDw8NNkxaREfqTmjQ4ED/ebIKAbNd4wjVkss7VFTLLHwgq aW9PYErS6uKXtp1GdFB+b0pyjE+UR2a+IzTv4FOAwtZN9RgKwKNimb6SLGPo05+ce6ZK yzd8AOuvozyLE3NLl3LonDmFiybzYuPXMpC+wykmhyrW5d4B3k/tZKrsYw2k84TVKk/Z YNsmz+NsVJIlR2Pc0VZKxdhoXr5Nx924kPQdr3Q3JyMYsndtPsT51wN3p8SyYTeaZ++a +5gdfyXJX0oEJrddL4l2svAFodqNz+JsmYA+OuNJ7TCWRP2kSSsBlT1fppYOnBUvn5mT kXbA== X-Forwarded-Encrypted: i=1; AJvYcCWyIqhHfe4EQnqgPvfHV3ZojdYAP/jBr1JEGWxj4FezSB0wA5oWwGeQZNOCYXoBHKtGT+s1Pm+I4mQo8w6wpsqcJfQWJ/uUxMnjh2g1H01uiKhdQ9yFXTsUnuC2J3XPceaIY3dxTH5F0lAVr5YFR9taHMpKak/EBeMcrB1xtGzm9P9IEOg= X-Gm-Message-State: AOJu0YyL6Bp2uyjvnFPYItWJU/hkpqX9D2hh7a3oR6QvyE0dxNBJlA0r dxqtRe9TsJyoqmHKA6rIutawPylaESq8AHJ5n4d1B78yKDsLNWuh X-Google-Smtp-Source: AGHT+IG7F+UiimGI2YqL+hm2lEd1Pv6ByUtx+vP7ceKzOZOQKmzLXlu6liceXcf+ELJfouW7umZM1g== X-Received: by 2002:a05:6000:1fa9:b0:360:7506:2b8 with SMTP id ffacd0b85a97d-3607a7d97d3mr7056957f8f.52.1718574954382; Sun, 16 Jun 2024 14:55: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-36075104b74sm10362879f8f.107.2024.06.16.14.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:55: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 v6 07/20] leds: leds-lp55xx: generalize run_engine function Date: Sun, 16 Jun 2024 23:52:06 +0200 Message-ID: <20240616215226.2112-8-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize run_engine function for lp55xx based LED driver. The logic is similar to every LED driver, rework it with more macro magic and account for LED model that might have OP MODE and EXEC at base offset in the reg. Update any lp55xx based LED driver to use this generalized function and declare required bits. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 42 +++++------------------------- drivers/leds/leds-lp5523.c | 41 +++-------------------------- drivers/leds/leds-lp5562.c | 42 +++++------------------------- drivers/leds/leds-lp55xx-common.c | 43 +++++++++++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 2 ++ drivers/leds/leds-lp8501.c | 41 +++-------------------------- 6 files changed, 65 insertions(+), 146 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 08db470fff6c..0b9f99f4fff2 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -132,8 +132,6 @@ static void lp5521_stop_engine(struct lp55xx_chip *chip) static void lp5521_run_engine(struct lp55xx_chip *chip, bool start) { int ret; - u8 mode; - u8 exec; /* stop engine */ if (!start) { @@ -143,40 +141,9 @@ static void lp5521_run_engine(struct lp55xx_chip *chip, bool start) return; } - /* - * To run the engine, - * operation mode and enable register should updated at the same time - */ - - ret = lp55xx_read(chip, LP5521_REG_OP_MODE, &mode); - if (ret) - return; - - ret = lp55xx_read(chip, LP5521_REG_ENABLE, &exec); - if (ret) - return; - - /* change operation mode to RUN only when each engine is loading */ - if (LP5521_R_IS_LOADING(mode)) { - mode = (mode & ~LP5521_MODE_R_M) | LP5521_RUN_R; - exec = (exec & ~LP5521_EXEC_R_M) | LP5521_RUN_R; - } - - if (LP5521_G_IS_LOADING(mode)) { - mode = (mode & ~LP5521_MODE_G_M) | LP5521_RUN_G; - exec = (exec & ~LP5521_EXEC_G_M) | LP5521_RUN_G; - } - - if (LP5521_B_IS_LOADING(mode)) { - mode = (mode & ~LP5521_MODE_B_M) | LP5521_RUN_B; - exec = (exec & ~LP5521_EXEC_B_M) | LP5521_RUN_B; - } - - lp55xx_write(chip, LP5521_REG_OP_MODE, mode); - lp5521_wait_opmode_done(); - - lp55xx_update_bits(chip, LP5521_REG_ENABLE, LP5521_EXEC_M, exec); - lp5521_wait_enable_done(); + ret = lp55xx_run_engine_common(chip); + if (!ret) + lp5521_wait_enable_done(); } static int lp5521_update_program_memory(struct lp55xx_chip *chip, @@ -476,6 +443,9 @@ static struct lp55xx_device_config lp5521_cfg = { .reg_op_mode = { .addr = LP5521_REG_OP_MODE, }, + .reg_exec = { + .addr = LP5521_REG_ENABLE, + }, .reset = { .addr = LP5521_REG_RESET, .val = LP5521_RESET, diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 8dabd5814110..b28955b72189 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -184,10 +184,6 @@ static void lp5523_turn_off_channels(struct lp55xx_chip *chip) static void lp5523_run_engine(struct lp55xx_chip *chip, bool start) { - int ret; - u8 mode; - u8 exec; - /* stop engine */ if (!start) { lp5523_stop_engine(chip); @@ -195,39 +191,7 @@ static void lp5523_run_engine(struct lp55xx_chip *chip, bool start) return; } - /* - * To run the engine, - * operation mode and enable register should updated at the same time - */ - - ret = lp55xx_read(chip, LP5523_REG_OP_MODE, &mode); - if (ret) - return; - - ret = lp55xx_read(chip, LP5523_REG_ENABLE, &exec); - if (ret) - return; - - /* change operation mode to RUN only when each engine is loading */ - if (LP5523_ENG1_IS_LOADING(mode)) { - mode = (mode & ~LP5523_MODE_ENG1_M) | LP5523_RUN_ENG1; - exec = (exec & ~LP5523_EXEC_ENG1_M) | LP5523_RUN_ENG1; - } - - if (LP5523_ENG2_IS_LOADING(mode)) { - mode = (mode & ~LP5523_MODE_ENG2_M) | LP5523_RUN_ENG2; - exec = (exec & ~LP5523_EXEC_ENG2_M) | LP5523_RUN_ENG2; - } - - if (LP5523_ENG3_IS_LOADING(mode)) { - mode = (mode & ~LP5523_MODE_ENG3_M) | LP5523_RUN_ENG3; - exec = (exec & ~LP5523_EXEC_ENG3_M) | LP5523_RUN_ENG3; - } - - lp55xx_write(chip, LP5523_REG_OP_MODE, mode); - lp5523_wait_opmode_done(); - - lp55xx_update_bits(chip, LP5523_REG_ENABLE, LP5523_EXEC_M, exec); + lp55xx_run_engine_common(chip); } static int lp5523_init_program_engine(struct lp55xx_chip *chip) @@ -840,6 +804,9 @@ static struct lp55xx_device_config lp5523_cfg = { .reg_op_mode = { .addr = LP5523_REG_OP_MODE, }, + .reg_exec = { + .addr = LP5523_REG_ENABLE, + }, .engine_busy = { .addr = LP5523_REG_STATUS, .mask = LP5523_ENGINE_BUSY, diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index 5e26a52f534f..fb05439576c3 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -127,8 +127,6 @@ static void lp5562_set_led_current(struct lp55xx_led *led, u8 led_current) static void lp5562_run_engine(struct lp55xx_chip *chip, bool start) { int ret; - u8 mode; - u8 exec; /* stop engine */ if (!start) { @@ -141,40 +139,9 @@ static void lp5562_run_engine(struct lp55xx_chip *chip, bool start) return; } - /* - * To run the engine, - * operation mode and enable register should updated at the same time - */ - - ret = lp55xx_read(chip, LP5562_REG_OP_MODE, &mode); - if (ret) - return; - - ret = lp55xx_read(chip, LP5562_REG_ENABLE, &exec); - if (ret) - return; - - /* change operation mode to RUN only when each engine is loading */ - if (LP5562_ENG1_IS_LOADING(mode)) { - mode = (mode & ~LP5562_MODE_ENG1_M) | LP5562_RUN_ENG1; - exec = (exec & ~LP5562_EXEC_ENG1_M) | LP5562_RUN_ENG1; - } - - if (LP5562_ENG2_IS_LOADING(mode)) { - mode = (mode & ~LP5562_MODE_ENG2_M) | LP5562_RUN_ENG2; - exec = (exec & ~LP5562_EXEC_ENG2_M) | LP5562_RUN_ENG2; - } - - if (LP5562_ENG3_IS_LOADING(mode)) { - mode = (mode & ~LP5562_MODE_ENG3_M) | LP5562_RUN_ENG3; - exec = (exec & ~LP5562_EXEC_ENG3_M) | LP5562_RUN_ENG3; - } - - lp55xx_write(chip, LP5562_REG_OP_MODE, mode); - lp5562_wait_opmode_done(); - - lp55xx_update_bits(chip, LP5562_REG_ENABLE, LP5562_EXEC_M, exec); - lp5562_wait_enable_done(); + ret = lp55xx_run_engine_common(chip); + if (!ret) + lp5562_wait_enable_done(); } static int lp5562_update_firmware(struct lp55xx_chip *chip, @@ -472,6 +439,9 @@ static struct lp55xx_device_config lp5562_cfg = { .reg_op_mode = { .addr = LP5562_REG_OP_MODE, }, + .reg_exec = { + .addr = LP5562_REG_ENABLE, + }, .reset = { .addr = LP5562_REG_RESET, .val = LP5562_RESET, diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index fd94dc708951..efb086072efa 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 */ @@ -119,6 +128,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 Sun Jun 16 21:52:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804692 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 229CB7CF33; Sun, 16 Jun 2024 21:55: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=1718574959; cv=none; b=uRxEUEjrSW4ueMjclj9AmR3NfUx+ZVv0a3Bgx7KshFdptk0ey2X0We5nN4NEuhTY/1uJHC8S7aO7kAekAZiKYXsb84Hu1U7luNo8o/PTIud4gPcKDQZY6zcHYlVxt/AySwnbnmwmT6QYh4UATBYwk5dOjgIZ5OT14didOxpY2os= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574959; c=relaxed/simple; bh=szz4KKEIpd8hMo073YXlBdiHLQIOYiN+qa+YszEdo98=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WtbzRQ9JC+sV1lMZdX4u3f7a0v4RkWlmcrstEx9tkLmwjchjm/FTQDhvUpiqsrJSlLAXDg2YHICkjthoYpiOaUf7Gee/zUamfy6qKUnOdgPxlwhDMNlFgTzcdSVJvGcVWhK3F2lU+u3zVj8y4U/M20Vz56+wZIXYe5zFstct9sQ= 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=E7qlMEjz; 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="E7qlMEjz" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-35f1c209842so2861799f8f.3; Sun, 16 Jun 2024 14:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574955; x=1719179755; 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=nmbEIwpOv9kQ2gyavOghBvkw1y9ZRRLoE9/pedGOOhE=; b=E7qlMEjzNsgQfN4mGDcXQFrnJsldOaHairn13ADlLpOGByc4Lm7n5+K/SxFbQuPykH poGGUJOQw1lyaq5CSqtdbVTm2LBgnyKm4QX2m3zVbBCIvM0aSX6Vh4Ggqfvh85szBErY P0tyI7W2D7Ihd4WPe/XPi28gUHg9l2VzgeTxD6erQW3+2P0pmZ81D6eTmBZPJ4NgVwbE xh624JECccsmEFINW4zeDSm2D6XFlaYKvXkkXtXZQkrTrPIlFku64XCVJBSAvcAlxZjN HC71uPm4bfsoY/1oqfVnzeqxVAiVuaiI3PbcNkHz1jA5ldr+zborQI9FakTRQW3wugAV 3E3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574955; x=1719179755; 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=nmbEIwpOv9kQ2gyavOghBvkw1y9ZRRLoE9/pedGOOhE=; b=aHNEGHZdUeo1VlBHzCOagbf+/6uBa5uUeO2Wdryeary8ZbMbmMw/LmKfFRXd9B0wfW k6dyNFwbS5ehIbqvxIvLYLmRMYUZ3M23+Tlwayp7sl6QGqu+OtTxck2AmBZP5NvtoGVO 45MGap1Mqg5kzlQZgc6gY5V5hrf1Yu8u97J9h78cK1ZxCJE3bIRIy2CMXb1TZF0qkBzw 61GdlPcwqxmXBv55ZVv+t3UmMdbQ8ljRuFlp+ek2hCKG+vB/buqyobrSPFhanCLSIeBv JuUWa47xnJygQdnoDJuVxQXXfkcaVB++cFr22PGmdbPB0W3S47AuOFJCKopLoGla5bdW 3w8g== X-Forwarded-Encrypted: i=1; AJvYcCVWoc+7k4VzkTT4nd7efpsqCTVQWny2g0p/wdPi6Kd62hvrPnrJzehgX2+Z2yvYQ6LI9vAnqIxcY0Ydg9tc5Ck+lzauxcBvudNNe1dlSQ6/4B9seODSnmXQTlNuyvwAd6/YECgko3jKL1mejgpNtv9OtN2hrrC8VYDG7+VcV/ivchoX9LY= X-Gm-Message-State: AOJu0YzXDYQE1dGUXRc+FaKjiLl/yGlu516aIPAq0M9lQfHPjeFvKxoC X8fSrVxAArkIRD5jJp6LdXfLYVzkKcnytsWm6qltBv0/CoHt9QYU X-Google-Smtp-Source: AGHT+IFuVpRb6SxT2sBVyyRrjZll5mlrWmiv8RB5q8oldBfkiviPkkzor46WiwHRP1KPS8asZGUYcQ== X-Received: by 2002:adf:ea91:0:b0:360:8fcc:615b with SMTP id ffacd0b85a97d-3608fcc62bamr3097836f8f.47.1718574955320; Sun, 16 Jun 2024 14:55: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-36075104b74sm10362879f8f.107.2024.06.16.14.55.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:55:55 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v6 08/20] leds: leds-lp55xx: generalize update_program_memory function Date: Sun, 16 Jun 2024 23:52:07 +0200 Message-ID: <20240616215226.2112-9-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 LED Driver based on lp55xx all use the same logic to write memory in SMEM. The only difference is that legacy chip doesn't support pages and have the engine regs one after another. To handle this apply the same logic used for load_engine also for update_program_memory. Introduce a new config in device_config, base_prog. For LED chip that doesn't support pages, offset this values of 32 for each engine. Update all lp55xx based LED driver to use this new function and define all the required bits. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 56 +++-------------------------- drivers/leds/leds-lp5523.c | 50 +++----------------------- drivers/leds/leds-lp5562.c | 58 +++---------------------------- drivers/leds/leds-lp55xx-common.c | 57 ++++++++++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 4 +++ drivers/leds/leds-lp8501.c | 52 +++------------------------ 6 files changed, 79 insertions(+), 198 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 0b9f99f4fff2..7ea3e5715f59 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -146,55 +146,6 @@ static void lp5521_run_engine(struct lp55xx_chip *chip, bool start) lp5521_wait_enable_done(); } -static int lp5521_update_program_memory(struct lp55xx_chip *chip, - const u8 *data, size_t size) -{ - enum lp55xx_engine_index idx = chip->engine_idx; - u8 pattern[LP5521_PROGRAM_LENGTH] = {0}; - static const u8 addr[] = { - [LP55XX_ENGINE_1] = LP5521_REG_R_PROG_MEM, - [LP55XX_ENGINE_2] = LP5521_REG_G_PROG_MEM, - [LP55XX_ENGINE_3] = LP5521_REG_B_PROG_MEM, - }; - unsigned cmd; - char c[3]; - int nrchars; - int ret; - int offset = 0; - int i = 0; - - while ((offset < size - 1) && (i < LP5521_PROGRAM_LENGTH)) { - /* separate sscanfs because length is working only for %s */ - ret = sscanf(data + offset, "%2s%n ", c, &nrchars); - if (ret != 1) - goto err; - - ret = sscanf(c, "%2x", &cmd); - if (ret != 1) - goto err; - - pattern[i] = (u8)cmd; - offset += nrchars; - i++; - } - - /* Each instruction is 16bit long. Check that length is even */ - if (i % 2) - goto err; - - for (i = 0; i < LP5521_PROGRAM_LENGTH; i++) { - ret = lp55xx_write(chip, addr[idx] + i, pattern[i]); - if (ret) - return -EINVAL; - } - - return size; - -err: - dev_err(&chip->cl->dev, "wrong pattern format\n"); - return -EINVAL; -} - static void lp5521_firmware_loaded(struct lp55xx_chip *chip) { const struct firmware *fw = chip->fw; @@ -212,7 +163,7 @@ static void lp5521_firmware_loaded(struct lp55xx_chip *chip) */ lp55xx_load_engine(chip); - lp5521_update_program_memory(chip, fw->data, fw->size); + lp55xx_update_program_memory(chip, fw->data, fw->size); } static int lp5521_post_init_device(struct lp55xx_chip *chip) @@ -389,7 +340,7 @@ static ssize_t store_engine_load(struct device *dev, chip->engine_idx = nr; lp55xx_load_engine(chip); - ret = lp5521_update_program_memory(chip, buf, len); + ret = lp55xx_update_program_memory(chip, buf, len); mutex_unlock(&chip->lock); @@ -454,6 +405,9 @@ static struct lp55xx_device_config lp5521_cfg = { .addr = LP5521_REG_ENABLE, .val = LP5521_ENABLE_DEFAULT, }, + .prog_mem_base = { + .addr = LP5521_REG_R_PROG_MEM, + }, .max_channel = LP5521_MAX_LEDS, .post_init_device = lp5521_post_init_device, .brightness_fn = lp5521_led_brightness, diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index b28955b72189..395c57330484 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -254,49 +254,6 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) return ret; } -static int lp5523_update_program_memory(struct lp55xx_chip *chip, - const u8 *data, size_t size) -{ - u8 pattern[LP5523_PROGRAM_LENGTH] = {0}; - unsigned int cmd; - char c[3]; - int nrchars; - int ret; - int offset = 0; - int i = 0; - - while ((offset < size - 1) && (i < LP5523_PROGRAM_LENGTH)) { - /* separate sscanfs because length is working only for %s */ - ret = sscanf(data + offset, "%2s%n ", c, &nrchars); - if (ret != 1) - goto err; - - ret = sscanf(c, "%2x", &cmd); - if (ret != 1) - goto err; - - pattern[i] = (u8)cmd; - offset += nrchars; - i++; - } - - /* Each instruction is 16bit long. Check that length is even */ - if (i % 2) - goto err; - - for (i = 0; i < LP5523_PROGRAM_LENGTH; i++) { - ret = lp55xx_write(chip, LP5523_REG_PROG_MEM + i, pattern[i]); - if (ret) - return -EINVAL; - } - - return size; - -err: - dev_err(&chip->cl->dev, "wrong pattern format\n"); - return -EINVAL; -} - static void lp5523_firmware_loaded(struct lp55xx_chip *chip) { const struct firmware *fw = chip->fw; @@ -314,7 +271,7 @@ static void lp5523_firmware_loaded(struct lp55xx_chip *chip) */ lp55xx_load_engine(chip); - lp5523_update_program_memory(chip, fw->data, fw->size); + lp55xx_update_program_memory(chip, fw->data, fw->size); } static ssize_t show_engine_mode(struct device *dev, @@ -496,7 +453,7 @@ static ssize_t store_engine_load(struct device *dev, chip->engine_idx = nr; lp55xx_load_engine(chip); - ret = lp5523_update_program_memory(chip, buf, len); + ret = lp55xx_update_program_memory(chip, buf, len); mutex_unlock(&chip->lock); @@ -819,6 +776,9 @@ static struct lp55xx_device_config lp5523_cfg = { .addr = LP5523_REG_ENABLE, .val = LP5523_ENABLE, }, + .prog_mem_base = { + .addr = LP5523_REG_PROG_MEM, + }, .pages_per_engine = LP5523_PAGES_PER_ENGINE, .max_channel = LP5523_MAX_LEDS, .post_init_device = lp5523_post_init_device, diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index fb05439576c3..7f3733fc446e 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -144,59 +144,6 @@ static void lp5562_run_engine(struct lp55xx_chip *chip, bool start) lp5562_wait_enable_done(); } -static int lp5562_update_firmware(struct lp55xx_chip *chip, - const u8 *data, size_t size) -{ - enum lp55xx_engine_index idx = chip->engine_idx; - u8 pattern[LP5562_PROGRAM_LENGTH] = {0}; - static const u8 addr[] = { - [LP55XX_ENGINE_1] = LP5562_REG_PROG_MEM_ENG1, - [LP55XX_ENGINE_2] = LP5562_REG_PROG_MEM_ENG2, - [LP55XX_ENGINE_3] = LP5562_REG_PROG_MEM_ENG3, - }; - unsigned cmd; - char c[3]; - int program_size; - int nrchars; - int offset = 0; - int ret; - int i; - - /* clear program memory before updating */ - for (i = 0; i < LP5562_PROGRAM_LENGTH; i++) - lp55xx_write(chip, addr[idx] + i, 0); - - i = 0; - while ((offset < size - 1) && (i < LP5562_PROGRAM_LENGTH)) { - /* separate sscanfs because length is working only for %s */ - ret = sscanf(data + offset, "%2s%n ", c, &nrchars); - if (ret != 1) - goto err; - - ret = sscanf(c, "%2x", &cmd); - if (ret != 1) - goto err; - - pattern[i] = (u8)cmd; - offset += nrchars; - i++; - } - - /* Each instruction is 16bit long. Check that length is even */ - if (i % 2) - goto err; - - program_size = i; - for (i = 0; i < program_size; i++) - lp55xx_write(chip, addr[idx] + i, pattern[i]); - - return 0; - -err: - dev_err(&chip->cl->dev, "wrong pattern format\n"); - return -EINVAL; -} - static void lp5562_firmware_loaded(struct lp55xx_chip *chip) { const struct firmware *fw = chip->fw; @@ -218,7 +165,7 @@ static void lp5562_firmware_loaded(struct lp55xx_chip *chip) */ lp55xx_load_engine(chip); - lp5562_update_firmware(chip, fw->data, fw->size); + lp55xx_update_program_memory(chip, fw->data, fw->size); } static int lp5562_post_init_device(struct lp55xx_chip *chip) @@ -450,6 +397,9 @@ static struct lp55xx_device_config lp5562_cfg = { .addr = LP5562_REG_ENABLE, .val = LP5562_ENABLE_DEFAULT, }, + .prog_mem_base = { + .addr = LP5562_REG_PROG_MEM_ENG1, + }, .post_init_device = lp5562_post_init_device, .set_led_current = lp5562_set_led_current, .brightness_fn = lp5562_led_brightness, diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index efb086072efa..d8614ed973bc 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 @@ -162,6 +164,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 Sun Jun 16 21:52:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805044 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 277DB823B8; Sun, 16 Jun 2024 21:55:57 +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=1718574960; cv=none; b=uaVxDBAQ2bXKD9cBftVp7uWtHMCj7tACMGWHBpMO01U9uf3mZAyzvVH5APNlroyFX+w0dJecZ2Pafbbc5nIxrE7cUsn5mCONeK9D7DUJox6IOvnLPyp+YiQA/fkBCb9LSng1wNjhWmM6CX4lWJGq9VHb9q4ajFUSJg1/g0raL1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574960; c=relaxed/simple; bh=bnl290XGZYqO8ztY5+G526Zwykn8scPJDBZ0edmP3ZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mYIvtMb9g/UXshT7878bk9VKPYbhpcxKaxnPbkuLAWYku3JF638sSP961P+lAyu8UZGcYX57E5YH8o6uRWlMs/nB34Nvt2B0NVAzVNxdHFSG8M3j/wVj7RjDqMcIZHkC0PY77SGaGOS+jm0ixuBkzRh04UDNWgqmSjtKFVq7H/4= 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=fGgHFdiV; 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="fGgHFdiV" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-421757d217aso39742165e9.3; Sun, 16 Jun 2024 14:55:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574956; x=1719179756; 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=cEvkLcIYgsDALWTdvTjXUcvNQL2R6iR0aKcWCRBg8Pc=; b=fGgHFdiVWHYjkMQW7T5qgy/TEVG4F+hkVp5JtY249xtgzOBrK/UKUaMBmsuAtNDeNN bVbXhXQUpn73o56m57jmEcVthHemRJmo3/raSWPtZZwNgrRTG+rolw1oBakNXiX4mjCA Qsh6SyHkxOgl5DdeRxH1xZInn0XGRhq/VgHqeb5Q5iP+O7ut2zfIc0j4zLrGUbmZUj02 TfpUdPUF3ZcETpuYyh8/Ku94ffAp7RxQf5d1sMXCwgWNOkdWO0IdDGCJxevCtjoNsjw+ ldvD1rPUByXphp+H+LTy5EVrbveQC4gU5MFZf/GBPZ1QhGtYcvDO2pvKQBDbz9/Rp3wb Kl+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574956; x=1719179756; 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=cEvkLcIYgsDALWTdvTjXUcvNQL2R6iR0aKcWCRBg8Pc=; b=PsX+BXfSjWNcLaqGG7nQGoUgy4bErKxnQowK5nwJcNcd+KAmttulKmULpdA8IpzPyT e8is0IWb4C8SBStCAWve5zP9Tz2rwHSHWwK7lYK0h5f31stkPvqYFxj5Pcm0OPV9s7dM hDh+FXHE3rpxgSXStV+R56At4CQEHxwiBmeKdB4bnoaDSkWU6mTYdkiMRSZpzLsUl1TU LDA+Ergbzye86i6e2iyK093YDGAvqNUrYPBoMKO7TusInAMVkEJM2ijs3xU8pAeg1ljm 2jdmWhBJFuYpZYT5T/zeMkV0KOgVni4WHgqS1uGVqRoZr2sYhaAmnx9cdkpB8rXezfzZ P6Tg== X-Forwarded-Encrypted: i=1; AJvYcCXjEyJdyC1YTLQuEwrEqvlSXWHD5ojrp87RETwjLFiAv5e2fOegRPjjABXiTHZ108OG/0kSs/T+4EiL5AWr/hyxhT/KvhjJWAPR6G5zuAXt/a2oQKqathPQy8YTSrZxkI3qKXMI0HXTj6SfyI06lOHwHOd1POIrcidMk3X07bqh9nCbm80= X-Gm-Message-State: AOJu0YxA5Rs1dNfej3VaG0j+wd5SOHtkkg3EnaGXApp5Zd7tvVX60MNg 1MbvC9VI9csLRNKljvzlWxdTXiVXv4zFerDrpG4sI4hdotNtJYhh X-Google-Smtp-Source: AGHT+IGdcPPEFyQw170Ym8E0ZHh2zjgUxn3FyqBDh7U8AKTyX0dwD3B/fmNxmkhQCdKd3AM6KpL/3g== X-Received: by 2002:a05:600c:5250:b0:421:dd8c:35a3 with SMTP id 5b1f17b1804b1-42304844c00mr94336475e9.26.1718574956520; Sun, 16 Jun 2024 14:55:56 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36075104b74sm10362879f8f.107.2024.06.16.14.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:55:56 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v6 09/20] leds: leds-lp55xx: generalize firmware_loaded function Date: Sun, 16 Jun 2024 23:52:08 +0200 Message-ID: <20240616215226.2112-10-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize firmware_loaded function as lp55xx based LED driver all share the same logic. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 22 +--------------------- drivers/leds/leds-lp5523.c | 22 +--------------------- drivers/leds/leds-lp5562.c | 26 +------------------------- drivers/leds/leds-lp55xx-common.c | 25 +++++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 1 + drivers/leds/leds-lp8501.c | 22 +--------------------- 6 files changed, 30 insertions(+), 88 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 7ea3e5715f59..722b5cd9236e 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -146,26 +146,6 @@ static void lp5521_run_engine(struct lp55xx_chip *chip, bool start) lp5521_wait_enable_done(); } -static void lp5521_firmware_loaded(struct lp55xx_chip *chip) -{ - const struct firmware *fw = chip->fw; - - if (fw->size > LP5521_PROGRAM_LENGTH) { - dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n", - fw->size); - return; - } - - /* - * Program memory sequence - * 1) set engine mode to "LOAD" - * 2) write firmware data into program memory - */ - - lp55xx_load_engine(chip); - lp55xx_update_program_memory(chip, fw->data, fw->size); -} - static int lp5521_post_init_device(struct lp55xx_chip *chip) { int ret; @@ -413,7 +393,7 @@ static struct lp55xx_device_config lp5521_cfg = { .brightness_fn = lp5521_led_brightness, .multicolor_brightness_fn = lp5521_multicolor_brightness, .set_led_current = lp5521_set_led_current, - .firmware_cb = lp5521_firmware_loaded, + .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp5521_run_engine, .dev_attr_group = &lp5521_group, }; diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 395c57330484..5525d60c342c 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -254,26 +254,6 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) return ret; } -static void lp5523_firmware_loaded(struct lp55xx_chip *chip) -{ - const struct firmware *fw = chip->fw; - - if (fw->size > LP5523_PROGRAM_LENGTH) { - dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n", - fw->size); - return; - } - - /* - * Program memory sequence - * 1) set engine mode to "LOAD" - * 2) write firmware data into program memory - */ - - lp55xx_load_engine(chip); - lp55xx_update_program_memory(chip, fw->data, fw->size); -} - static ssize_t show_engine_mode(struct device *dev, struct device_attribute *attr, char *buf, int nr) @@ -785,7 +765,7 @@ static struct lp55xx_device_config lp5523_cfg = { .brightness_fn = lp5523_led_brightness, .multicolor_brightness_fn = lp5523_multicolor_brightness, .set_led_current = lp5523_set_led_current, - .firmware_cb = lp5523_firmware_loaded, + .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp5523_run_engine, .dev_attr_group = &lp5523_group, }; diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index 7f3733fc446e..e50b68c9ccf3 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -144,30 +144,6 @@ static void lp5562_run_engine(struct lp55xx_chip *chip, bool start) lp5562_wait_enable_done(); } -static void lp5562_firmware_loaded(struct lp55xx_chip *chip) -{ - const struct firmware *fw = chip->fw; - - /* - * the firmware is encoded in ascii hex character, with 2 chars - * per byte - */ - if (fw->size > (LP5562_PROGRAM_LENGTH * 2)) { - dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n", - fw->size); - return; - } - - /* - * Program memory sequence - * 1) set engine mode to "LOAD" - * 2) write firmware data into program memory - */ - - lp55xx_load_engine(chip); - lp55xx_update_program_memory(chip, fw->data, fw->size); -} - static int lp5562_post_init_device(struct lp55xx_chip *chip) { int ret; @@ -404,7 +380,7 @@ static struct lp55xx_device_config lp5562_cfg = { .set_led_current = lp5562_set_led_current, .brightness_fn = lp5562_led_brightness, .run_engine = lp5562_run_engine, - .firmware_cb = lp5562_firmware_loaded, + .firmware_cb = lp55xx_firmware_loaded_cb, .dev_attr_group = &lp5562_group, }; diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index d8614ed973bc..9844823ece63 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -219,6 +219,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 Sun Jun 16 21:52:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804691 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 348D912D74D; Sun, 16 Jun 2024 21:55:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574961; cv=none; b=FvyW50KztaG2f75AmLYR0Lk7h3odxmvyWebUsix4iV6FIi5/+aOKg6/4/BJlf2IYPBL4NqskM4mIsc50zSmzXxI0q/h9rlgcTFYy0To0U7DfZF2qiQuUXrTtsifovtOHBe7N/56Whv4taljsY3rkpPLdXUcH8NBE3EOFeeySzUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574961; c=relaxed/simple; bh=NxsBdO1ugPMVxl+cLRuL99pkvySUXvjOOtPa5hkRW6s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OjgSDPInen2QNamzB64dq+BoTUeviiwgWFy9CPM+cF+1rGl+jac9WVHhI6Ki+zoKfEAFLkzur545Mp99CmNFd03n6xFJKvHRMzZWPwALablBv6qs/apcuHyYphxdxgessiqR8RN2NcwT6GAe4TG8INMv/IOSZ97f5Q9lI9lxilA= 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=m222zH2M; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m222zH2M" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4217dbeb4caso30814395e9.1; Sun, 16 Jun 2024 14:55:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574957; x=1719179757; 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=KHZc/1LWhRCQc67SMp9qGtUXdrtThurh67cPSPDWhgc=; b=m222zH2MriGyrkEz365Ak2gVIY5UnC95DqmcgjOMh+OUG+jieopRzx2HItfMOcNhB5 2yr0a8G41j9B6ULXGBHqvJV5QOdjqOO8/xFJF5L1agVgnMf6T3HVJWFfCKj4KB5eHlL0 Z5aJsh/nNmdHV71pyi1CGqGkKzuxuTV/TnvUtx/AF6wx/VFFmzq4GkZiXqPVGh6FQGcg uQi2vXwb/Qv7xe5RxhJGQ2OZyiXw3drM7JIpvKaKUw9i4EoZ7ZMlrCYpG054UEzno9qu PmDOeAqk127eehGjmiQ88JT1bfzcYKGWNyyz8WbqIrX/noIKUHPskTHNA/rJvmeumNyJ ZihA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574957; x=1719179757; 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=KHZc/1LWhRCQc67SMp9qGtUXdrtThurh67cPSPDWhgc=; b=FlsDj1gLddxiHLcrEkC3lBJIoqBgooqiuYk4vW4mVzHaR3Wpy04FqOY9gSd6PZ0A5Z xVUFGIM4xsw7SeQD8xuTF3M0sXXAOO53r4GN4lqBQfyrWfhAXhqQpvCgvQ1QyKBSI3tI a8erjiRLwqp4xRr7BTZSvEOPrKThkTixBfuR1JY2bV7DBVLMz4LlGZdccTfqtr4QgzSq DHqNgX1/akGBiyI3vV2VpL6sS4GrkWWGI6xpKqfx+SnpePRgOhPHeRdjLcjm212GJe5R 1R7zTLKfWdjEc2jBaK+I+SZP6/AsIxuH9EAidDFbw368CZgiO9OF7vBKPdKqCZooy5To Cmpg== X-Forwarded-Encrypted: i=1; AJvYcCXD/8I/Iiae5rrjeA4Wlbheardp44C12s44JjARan4lVNOirI+zVdq4FGhmw6WCpeVzebQkMAQGIbwWDyNpa8aYcYkIoIoYW/cU6yTlhw6ipgUN8n+QqzspE+zLGvLF6FlVsdXUN4YugMxI+85b1aJqKryuQ8ZXyQ0izaGe47V+Kf6thLY= X-Gm-Message-State: AOJu0YxNm9oafIkRWnpzXo/dQlLyp6upS68ZZJlGYTs4E/XlgWy0aqCK htJpsCxivhziVJzQC5wCWJ31h9QFybphwvBOQA8+2Yzzo1aQrHvwGq0rbw== X-Google-Smtp-Source: AGHT+IHbX67+xJVR8xJIFoy+waN4vpZRJZU8hO44Q455ATBCnRCtv5gzDmauQ7uogKMgC30f5VN9xQ== X-Received: by 2002:a05:600c:364a:b0:421:cbb8:ca7d with SMTP id 5b1f17b1804b1-4230485a61fmr59395415e9.37.1718574957571; Sun, 16 Jun 2024 14:55:57 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36075104b74sm10362879f8f.107.2024.06.16.14.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:55:57 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v6 10/20] leds: leds-lp55xx: generalize led_brightness function Date: Sun, 16 Jun 2024 23:52:09 +0200 Message-ID: <20240616215226.2112-11-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize led_brightness function as the implementation is the same for most of the lp55xx based LED driver. Introduce a new option in device_config, reg_led_pwm_base since the reg value is not the same for every LED chip. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 18 ++++-------------- drivers/leds/leds-lp5523.c | 17 ++++------------- drivers/leds/leds-lp55xx-common.c | 14 ++++++++++++++ drivers/leds/leds-lp55xx-common.h | 3 +++ drivers/leds/leds-lp8501.c | 18 ++++-------------- 5 files changed, 29 insertions(+), 41 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 722b5cd9236e..e4d0dcdbf11b 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -241,19 +241,6 @@ static int lp5521_multicolor_brightness(struct lp55xx_led *led) return ret; } -static int lp5521_led_brightness(struct lp55xx_led *led) -{ - struct lp55xx_chip *chip = led->chip; - int ret; - - mutex_lock(&chip->lock); - ret = lp55xx_write(chip, LP5521_REG_LED_PWM_BASE + led->chan_nr, - led->brightness); - mutex_unlock(&chip->lock); - - return ret; -} - static ssize_t show_engine_mode(struct device *dev, struct device_attribute *attr, char *buf, int nr) @@ -388,9 +375,12 @@ static struct lp55xx_device_config lp5521_cfg = { .prog_mem_base = { .addr = LP5521_REG_R_PROG_MEM, }, + .reg_led_pwm_base = { + .addr = LP5521_REG_LED_PWM_BASE, + }, .max_channel = LP5521_MAX_LEDS, .post_init_device = lp5521_post_init_device, - .brightness_fn = lp5521_led_brightness, + .brightness_fn = lp55xx_led_brightness, .multicolor_brightness_fn = lp5521_multicolor_brightness, .set_led_current = lp5521_set_led_current, .firmware_cb = lp55xx_firmware_loaded_cb, diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 5525d60c342c..a3b4063d504e 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -683,18 +683,6 @@ static int lp5523_multicolor_brightness(struct lp55xx_led *led) return ret; } -static int lp5523_led_brightness(struct lp55xx_led *led) -{ - struct lp55xx_chip *chip = led->chip; - int ret; - - mutex_lock(&chip->lock); - ret = lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + led->chan_nr, - led->brightness); - mutex_unlock(&chip->lock); - return ret; -} - static LP55XX_DEV_ATTR_RW(engine1_mode, show_engine1_mode, store_engine1_mode); static LP55XX_DEV_ATTR_RW(engine2_mode, show_engine2_mode, store_engine2_mode); static LP55XX_DEV_ATTR_RW(engine3_mode, show_engine3_mode, store_engine3_mode); @@ -759,10 +747,13 @@ static struct lp55xx_device_config lp5523_cfg = { .prog_mem_base = { .addr = LP5523_REG_PROG_MEM, }, + .reg_led_pwm_base = { + .addr = LP5523_REG_LED_PWM_BASE, + }, .pages_per_engine = LP5523_PAGES_PER_ENGINE, .max_channel = LP5523_MAX_LEDS, .post_init_device = lp5523_post_init_device, - .brightness_fn = lp5523_led_brightness, + .brightness_fn = lp55xx_led_brightness, .multicolor_brightness_fn = lp5523_multicolor_brightness, .set_led_current = lp5523_set_led_current, .firmware_cb = lp55xx_firmware_loaded_cb, diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 9844823ece63..4d607849cd50 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -244,6 +244,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 Sun Jun 16 21:52:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805043 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 906A513541E; Sun, 16 Jun 2024 21:56:00 +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=1718574962; cv=none; b=CcQRdxTT3Ak+jDZ2TGDTlV3UIlQxwquQXatJktl1GFtY0OSBcAUwtnYk5u61nQj5K0wMxnF6psaTcIY8L6eYEzkzvvBlONV+aTpMeMSM9+pqhJOL0AQtup2fxklOAK3xugBkD2z9592MxREO+VT1+pLm0qY12Rx54uxnIi50WF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574962; c=relaxed/simple; bh=rM0K4/9vjJYHqS3YAXpaJzhrRbVDajL53pbbU+bBn6c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M04q/WMhwfGnkT6wQk9Gxrs0ZZ8hNYWCrQ0leW4f2/YL0cCALRtzKOutZ5IpS70A58d81T+ObgkpWwnXHyt3+rfQ9qIj1pzPDuV9tWAajnqMMu+O+FoGWlGXklPrRh7XSq+a9I1K/LUh9wmrLf+yqLO3d/mU53xsQqoLjq6SeHI= 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=dsATTHlr; 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="dsATTHlr" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-35f223e7691so2470160f8f.1; Sun, 16 Jun 2024 14:56:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574959; x=1719179759; 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=l75o3fwlv4tb6gV40sJ/HQkyJddD7j0kEEi/md20QUE=; b=dsATTHlrSvriUajoaqrYvmOHtLIqwwYNyT72LnCl0WbqHmqI6mLiDPKWKfVGyGWfgl iLTB4/eTqteXsn7EeCbDMngHLK2NtXtg3Z2pz1q7HtWJrY2Gzip5H0kBXZJoyytBNpqb 93eaMLrj67RzncM8/UhjiOBKSSE4gEycSGvLBvMyIONIy0s9c4TcB3fSwZ54yF/IQ6h5 lx5McMkrIb/mjxK9hKqnUffJJVHArlcW4RSS/nIMz7PyU24yAmUtW3LBi9zWIy8r0hJ2 wn52tSAK+fH95PrZL9wc+prGSaONOLeibNw83Sp7fOpk5KV8EbgjqF2DELBtCKzy4TPd hYJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574959; x=1719179759; 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=l75o3fwlv4tb6gV40sJ/HQkyJddD7j0kEEi/md20QUE=; b=Yj7Ke5HOSNCX/ye7Id2oG41NjAeX7JwUEydhL8viV3XYLIf8ooXv5KWJ1WN0qsIYgu VxTaKqj+dm00Fmg96MysD9GyMFjP8I0HWyYAvGT9e9dhwLvnxok1k8pYRa22hD27pS+r CMNbGjtWYTIMoP5dvtl59FXflWFrYzpuIIYRzYwj2w5GcrVNI8PLEK09G/0cyfJXocjn rFavM3uO/FfXeUj/6+RQGgotkS2lw4CpxEC0BtWxGBE9uvY7byvjkgd+J9/tuYEHXguk 0A2mLYLY3N0uJGf6IZwVTent0TDWg0q3s1esQr85KMjxsB6R/xjavgtXMvPh/lT7fc/a o9aw== X-Forwarded-Encrypted: i=1; AJvYcCVC+sASJbq9SW0+GQR6xGbMuMIsj99UewZm12bliYowhw/sOugXent+S3nBBfEGXw/IUXHnVyOSV8xXRT02BaAPCMaOwpslrrrO+kih6610q095zV2Io+kwALKoGLy1sabnN7gdvKJVXG2v5kbotd74yAdRrP/1EOSLFu78T566+2FI5bY= X-Gm-Message-State: AOJu0YyU+yToIEEhMjK06ouD3eAJyDv7w2FbbaoxM5UZbuqkXdSfMl1f SEaXMV7uPjta4gO1HB4V0PHUhm/odESzSdLii/IH6t+3cx7tQq4T X-Google-Smtp-Source: AGHT+IHHCKl1WzRzbQKWQNz8c1xGN2sOW/XQhOjZMJYs+yyK6XMotSMEhw51S4sdKxbbjY0yDHO9XQ== X-Received: by 2002:adf:f5cc:0:b0:360:7c76:dd5 with SMTP id ffacd0b85a97d-3607c760ed5mr6478190f8f.14.1718574958697; Sun, 16 Jun 2024 14:55:58 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36075104b74sm10362879f8f.107.2024.06.16.14.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:55:58 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v6 11/20] leds: leds-lp55xx: generalize multicolor_brightness function Date: Sun, 16 Jun 2024 23:52:10 +0200 Message-ID: <20240616215226.2112-12-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize multicolor_brightness function as the implementation is the same for most of the lp55xx based LED driver. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 21 +-------------------- drivers/leds/leds-lp5523.c | 21 +-------------------- drivers/leds/leds-lp55xx-common.c | 21 +++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 1 + 4 files changed, 24 insertions(+), 40 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index e4d0dcdbf11b..dd7e996f22f9 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -222,25 +222,6 @@ static int lp5521_run_selftest(struct lp55xx_chip *chip, char *buf) return 0; } -static int lp5521_multicolor_brightness(struct lp55xx_led *led) -{ - struct lp55xx_chip *chip = led->chip; - int ret; - int i; - - mutex_lock(&chip->lock); - for (i = 0; i < led->mc_cdev.num_colors; i++) { - ret = lp55xx_write(chip, - LP5521_REG_LED_PWM_BASE + - led->mc_cdev.subled_info[i].channel, - led->mc_cdev.subled_info[i].brightness); - if (ret) - break; - } - mutex_unlock(&chip->lock); - return ret; -} - static ssize_t show_engine_mode(struct device *dev, struct device_attribute *attr, char *buf, int nr) @@ -381,7 +362,7 @@ static struct lp55xx_device_config lp5521_cfg = { .max_channel = LP5521_MAX_LEDS, .post_init_device = lp5521_post_init_device, .brightness_fn = lp55xx_led_brightness, - .multicolor_brightness_fn = lp5521_multicolor_brightness, + .multicolor_brightness_fn = lp55xx_multicolor_brightness, .set_led_current = lp5521_set_led_current, .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp5521_run_engine, diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index a3b4063d504e..bfa0c4431ede 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -664,25 +664,6 @@ static ssize_t store_master_fader_leds(struct device *dev, return ret; } -static int lp5523_multicolor_brightness(struct lp55xx_led *led) -{ - struct lp55xx_chip *chip = led->chip; - int ret; - int i; - - mutex_lock(&chip->lock); - for (i = 0; i < led->mc_cdev.num_colors; i++) { - ret = lp55xx_write(chip, - LP5523_REG_LED_PWM_BASE + - led->mc_cdev.subled_info[i].channel, - led->mc_cdev.subled_info[i].brightness); - if (ret) - break; - } - mutex_unlock(&chip->lock); - return ret; -} - static LP55XX_DEV_ATTR_RW(engine1_mode, show_engine1_mode, store_engine1_mode); static LP55XX_DEV_ATTR_RW(engine2_mode, show_engine2_mode, store_engine2_mode); static LP55XX_DEV_ATTR_RW(engine3_mode, show_engine3_mode, store_engine3_mode); @@ -754,7 +735,7 @@ static struct lp55xx_device_config lp5523_cfg = { .max_channel = LP5523_MAX_LEDS, .post_init_device = lp5523_post_init_device, .brightness_fn = lp55xx_led_brightness, - .multicolor_brightness_fn = lp5523_multicolor_brightness, + .multicolor_brightness_fn = lp55xx_multicolor_brightness, .set_led_current = lp5523_set_led_current, .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp5523_run_engine, diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 4d607849cd50..d3a18045df56 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -258,6 +258,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 Sun Jun 16 21:52:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804690 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 7443D1386BF; Sun, 16 Jun 2024 21:56:01 +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=1718574963; cv=none; b=g4Qd9OV70lzlSoNKo0Ud0HfEhb6IoOykI0PQMiTHKiKEfCeVZvI01pvrVXMEv7Qy111AfaIV8szx8bObVY6FslqNX/Ofg5+EUIKqYeiXaF1O2+we64xouQIyDWR8AoDTsmkHLV093+JbzeGq0mSsFYTIviSU0l4Dy2uMuzjXUQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574963; c=relaxed/simple; bh=nY+8QIq/NVecO0v1z1bXAulWhQ6IcntQKCxitZOJseM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d/ZVSGJQomZGPAQHHUlX30zqfGex6Dc6G/ulRnkJyyxbrMh9yikMZ+k3V9Bc4mhudATS5PqP7Md/ExDkfPMz1+UdQHoY3tspk4DlMGTL3wg/41sanhLYwPqGC3ziTKF99MwhlC3VCZ0r3iTmX0SSChZzkfcoBYe81Mxj1DZ2lUQ= 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=gAJ3oyHC; 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="gAJ3oyHC" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-42165f6645fso30720585e9.2; Sun, 16 Jun 2024 14:56:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574960; x=1719179760; 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=3qoiYX0eH9044ehhjYfAJBrI3lPSxFRdf3bv91uFvdw=; b=gAJ3oyHC4UXytYP1ZwvyqdX1azZQEloFI7DYwCdxkqzyd4k9jdTeESda2VEY9a6mkF NDt23Qp9tmGMwvQTUYUFFx5z+a9zVpDQ5KipW2a1XoAvxFoNuN2zuF8yZgZeYjSmr60Q ZKRHI4CUp6LkynqhLqVfg425RL5qEj2stCSMxg24gC5BepSNnzYo1phomwmZvpJNQBTj 9tw6lsi0Eo6YaKFUlzO1MnJOX0Biz/QfOzt47SqTlMCeqeWISTO3qWHBu+ABJ/s8HmfI OTqGimWs2RZlRi9kAiB669BUEai9fduqO1iralCJ0wF8bcB3bq+UQqTurHV8ms1LG7AC dy4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574960; x=1719179760; 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=3qoiYX0eH9044ehhjYfAJBrI3lPSxFRdf3bv91uFvdw=; b=C6vu9ZTy6Fc54UmYSBweKNr9YZEeXNgyud2b3G4UEkleG2EOzJsvRpa28vo5AbczYz Poh65R/5STR8cn6/FjDWmu/tz/HE8SPs0EDewNWPj8c86XC1e6VU8SThNRDB90W3b8gR 37rnaAC6oGoMEkJKvcFTzMxDReLJT9ybdffmqrw848HCToewF0knJHZfZhxD73Jqr8HJ lht0VqEggeTjDerEutaBfI/+rZHEXSEKLN2myRywr8fREtkOtQzqDdQnNE1nfi+/U8nE eVdXX1HC4yp58HKEEtc1WqkNQYpxihpSOXgdA2pWmwnfOWUaG87DwYskWRYiq4cqm7Sb vbfQ== X-Forwarded-Encrypted: i=1; AJvYcCUj/2Vyi/mZ7cMwHQbrTYCbuKQnUiuMrZ+flxNYW7O3GqSoiUsTgIrTbQQv5pNtGXt8GgxIxhTbWNaA+TdMzQ1/kjMeh0qfBUjss8S4wDojwk7qiZY13p8U0RsiTY11/xd8hgfIXzLkDhyf5hSQrE1di7oygEEqRIQTJHP6HDMSWZ0fmBM= X-Gm-Message-State: AOJu0YwoNmt8TfKb87IrK4UQA2FB2D9HKJ4kiKARAR5dbzt/ESE/63RV 5/Uj6zIaM445ivYj2oIsxBlkcNV5RsQBKhvOJnPi4Ei8Ha4IhkKv X-Google-Smtp-Source: AGHT+IFvtXjcLVHpBKPky6IoqCUz71xxqzcUMkNXxxmMUrdQ4RdGjG6/e6rAyHeSP27vcyXJNk6vHQ== X-Received: by 2002:a05:600c:2303:b0:423:b579:777e with SMTP id 5b1f17b1804b1-423b579785bmr38621805e9.30.1718574959727; Sun, 16 Jun 2024 14:55:59 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36075104b74sm10362879f8f.107.2024.06.16.14.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:55:59 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v6 12/20] leds: leds-lp55xx: generalize set_led_current function Date: Sun, 16 Jun 2024 23:52:11 +0200 Message-ID: <20240616215226.2112-13-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize set_led_current function as the implementation is the same for most of the lp55xx based LED driver. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 12 ++++-------- drivers/leds/leds-lp5523.c | 12 ++++-------- drivers/leds/leds-lp55xx-common.c | 11 +++++++++++ drivers/leds/leds-lp55xx-common.h | 3 +++ drivers/leds/leds-lp8501.c | 12 ++++-------- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index dd7e996f22f9..a1a3bf0ff703 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -108,13 +108,6 @@ static inline void lp5521_wait_enable_done(void) usleep_range(500, 600); } -static void lp5521_set_led_current(struct lp55xx_led *led, u8 led_current) -{ - led->led_current = led_current; - lp55xx_write(led->chip, LP5521_REG_LED_CURRENT_BASE + led->chan_nr, - led_current); -} - static void lp5521_stop_engine(struct lp55xx_chip *chip) { enum lp55xx_engine_index idx = chip->engine_idx; @@ -359,11 +352,14 @@ static struct lp55xx_device_config lp5521_cfg = { .reg_led_pwm_base = { .addr = LP5521_REG_LED_PWM_BASE, }, + .reg_led_current_base = { + .addr = LP5521_REG_LED_CURRENT_BASE, + }, .max_channel = LP5521_MAX_LEDS, .post_init_device = lp5521_post_init_device, .brightness_fn = lp55xx_led_brightness, .multicolor_brightness_fn = lp55xx_multicolor_brightness, - .set_led_current = lp5521_set_led_current, + .set_led_current = lp55xx_set_led_current, .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp5521_run_engine, .dev_attr_group = &lp5521_group, diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index bfa0c4431ede..3030a4495808 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -122,13 +122,6 @@ static inline void lp5523_wait_opmode_done(void) usleep_range(1000, 2000); } -static void lp5523_set_led_current(struct lp55xx_led *led, u8 led_current) -{ - led->led_current = led_current; - lp55xx_write(led->chip, LP5523_REG_LED_CURRENT_BASE + led->chan_nr, - led_current); -} - static int lp5523_post_init_device(struct lp55xx_chip *chip) { int ret; @@ -731,12 +724,15 @@ static struct lp55xx_device_config lp5523_cfg = { .reg_led_pwm_base = { .addr = LP5523_REG_LED_PWM_BASE, }, + .reg_led_current_base = { + .addr = LP5523_REG_LED_CURRENT_BASE, + }, .pages_per_engine = LP5523_PAGES_PER_ENGINE, .max_channel = LP5523_MAX_LEDS, .post_init_device = lp5523_post_init_device, .brightness_fn = lp55xx_led_brightness, .multicolor_brightness_fn = lp55xx_multicolor_brightness, - .set_led_current = lp5523_set_led_current, + .set_led_current = lp55xx_set_led_current, .firmware_cb = lp55xx_firmware_loaded_cb, .run_engine = lp5523_run_engine, .dev_attr_group = &lp5523_group, diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index d3a18045df56..d8662d128945 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -279,6 +279,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 Sun Jun 16 21:52:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805042 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F51313A24D; Sun, 16 Jun 2024 21:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574964; cv=none; b=OlTE4wIufMro6gsjJp7jOoISMgjkxXHnYFMd7Nm+oHrki5EaFPagdPNLw/2VpBEzHyQo5+bW+VE+ZMCBCHzyPiIhsV4+oF38cDCyFdcs8K6qfyFnJr2MxStFvqINABNnPzjrAcx6vaMY1NpGC0BxOGVcZ3Vfep3kQQgT6VI7qjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574964; c=relaxed/simple; bh=EbLGmRy7LcD4aKq9UQD6BVxBGiSR9miLEzJdzhdonfo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nO20fUmeNT0zax6wXxay61LU0cZLMGxllG9RTdXPqTEEIaIp9EQjAZ9Mc3rwLpgRo/kBBNUmwuOQ3NQhb1tVgiA2pYcf0Gd3iKy432sSuP8FZ80yBgeZ7N1yIqLIj/jzFItd6G2SWRFfNMPwJNqvBCz0cCQHqzEzaoZO4IXEvu4= 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=HaWmG/wM; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HaWmG/wM" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-35f27eed98aso3059113f8f.2; Sun, 16 Jun 2024 14:56:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574961; x=1719179761; 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=/eoGUyvX2njKZUc4Ego9siu0xJbl3KtjGslqTW6DXh4=; b=HaWmG/wMBzd0W8SHzwGA010ib9wgXge/FBpOMAMxohJ/J9feRSCX90C6NLjySX1Nlz V7pZBRVpE/yrCLBP1E7BXNBavqpaHU6HyJwWsT9JHYumNR1O2eqGvYm9jr2hDbJsuFFr tb4Z2BA4GoGeykWbYwBLgUFh8ZsNCHaX6wgFFeuPmtMK4s42F3OEYRtudUv5JrzB5Yko 2dHUxxQJ4KQ416hTSSYiF89EKjXKhWa2NbGrB915EiDLxjmVkeNItng43l/HH7AH8MKt f+a4EcFy0a8fHdJMSsENsqCSdSG+hKTbJ5mBs5WxSDwJNdN0ZXI1MqByrujaViF0LgQ5 60+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574961; x=1719179761; 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=/eoGUyvX2njKZUc4Ego9siu0xJbl3KtjGslqTW6DXh4=; b=m+L1z/Jb9ER2xn/bL1WpcTWzfbjxzN+i3TlQXdFygxn/sjqeJJDb0y294rh4IisMlT o8unQC5w2iOamIjJhglgOHymuv8Q08dqZEHdx2e6C8nkwOTS5hDfs/3c/kImzCLWnJ0H GH2OKEQIcH2iyCQsgzkSwSrjswMwSeHs/I4O0H+7FzRivOCFpi9orwqZzsR0lk67k0sD fD/R1H87MZ0bsVcfLjamhJTkb8f+IO3ZKcbM5yr44Lnv4GZMyiGSr+SvdofNf5N1GQjl paH3irNPoTiHYngUi7OhzZlTw9fY8IY3SB4OcGf1mCw5rue3+MNI5wR60Bgmn+xzbnwH MmFQ== X-Forwarded-Encrypted: i=1; AJvYcCWkQUoFuyUD5RhOqqh3X8+MgDu+aASZ/hCN9gbhWI6nY4Shbb8bzVnb9u/QV/kDFHqfrv4MQLIXo5WTsEhU+b0OyMWJhkP0ZFg0HdSsXej937o9E/RbCnyJNFL79UH1UbQqeqZlL8DiObIb8pa7GdPu6xYUiIpHikyKFK5WZkjXgW/JikE= X-Gm-Message-State: AOJu0YwZzpkhCfluB9iKgM+e4O0RzhjPQ2XayY9E6gkxY3nW+OzpOwh8 KIcehvtodkwsY718fJqkfMfyqBt7xyZjKazAp4EAFwfVuMBR4WlmNkj9Pg== X-Google-Smtp-Source: AGHT+IHZ/tJuawD7clx25ood8aMusPMhMMXRoj5Ub/NqdtABJjEfNxnNiFhrupBQBuGKKzJ7LyBycA== X-Received: by 2002:a5d:6e03:0:b0:35f:ece:3f63 with SMTP id ffacd0b85a97d-3607a77afa8mr5365879f8f.46.1718574960833; Sun, 16 Jun 2024 14:56:00 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36075104b74sm10362879f8f.107.2024.06.16.14.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:56:00 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v6 13/20] leds: leds-lp55xx: generalize turn_off_channels function Date: Sun, 16 Jun 2024 23:52:12 +0200 Message-ID: <20240616215226.2112-14-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize turn_off_channels function as the implementation is the same for most of the lp55xx based LED driver. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5523.c | 10 +--------- drivers/leds/leds-lp55xx-common.c | 10 ++++++++++ drivers/leds/leds-lp55xx-common.h | 1 + drivers/leds/leds-lp8501.c | 10 +--------- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 3030a4495808..4a4463cb44a4 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -167,20 +167,12 @@ static void lp5523_stop_engine(struct lp55xx_chip *chip) lp5523_wait_opmode_done(); } -static void lp5523_turn_off_channels(struct lp55xx_chip *chip) -{ - int i; - - for (i = 0; i < LP5523_MAX_LEDS; i++) - lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + i, 0); -} - static void lp5523_run_engine(struct lp55xx_chip *chip, bool start) { /* stop engine */ if (!start) { lp5523_stop_engine(chip); - lp5523_turn_off_channels(chip); + lp55xx_turn_off_channels(chip); return; } diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index d8662d128945..202b598dd177 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -290,6 +290,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 Sun Jun 16 21:52:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804689 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 613926F099; Sun, 16 Jun 2024 21:56:03 +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=1718574965; cv=none; b=fyMkwfnzJYlq3biAE9n29ipFOl7GAhJs5f61dJBTpm8jzyeR0fEQ+6Iq4qKgaoVd/6PKWFYoISaV/J7oornvvN0ojrKMHPhCbXVrWQCX02v2QnhnqYjm4NuqMzGqynvs9smYGERdkh7/MVfQOuQKhJqqVtRtnmYsbe6emT72e/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574965; c=relaxed/simple; bh=u9LqyGK4M8AuebtBqAqjSHIno9Q8tI1IpOGZVec9b38=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mab6VMdMhB3WSR0WefVK+GthWh6nB0wxn63Wz/jOdFn8aE9NjkJ0gO/jmL27qMsazDQSx5S8KyZ0AGuYkWDLjMwERe5uV1sjPB5NdZLDKiqmS24oG/I7xAbL8GeyEB1zO2lnzRkbzculLCS3iyfvWjKc+budLXg5TlKsSXqhgFg= 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=J/bpdE3i; 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="J/bpdE3i" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-35f2c0b7701so2148020f8f.0; Sun, 16 Jun 2024 14:56:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574962; x=1719179762; 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=fKvoQnyg9GY2ofJkbYZwufhkyLyYoaj7gwKUZpBKT6A=; b=J/bpdE3ii+cm0nKPHXO++y0KpGefCW3I2tNBUobSOHIPQoTQNVo76a6cOuZplzSrav xVOcLqpiWYtPwsCB17xephwk3Xpd7wHifo+UyFUNLhrlOJcha+KsqsWnNAtYEHgWY0u/ dvv0fN+9HuP+AlfZ6SJDAkbkkPQGTM0mbeziY3IhoUgOpS7p0Nq/qd+i53Pk/VLdiXKl MnujNQ27psjxTruV3XEOsmMYS7+brHh0QfyPDERm/Gen3ngGHvaZtSUPPxFCktpA68Qs jC8UdX1BT1UrZIcGBdVM4WVdd95G6ItmNrFw8aerU47flM7pZq8fuNhmtcRmrlJZKSme yrvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574962; x=1719179762; 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=fKvoQnyg9GY2ofJkbYZwufhkyLyYoaj7gwKUZpBKT6A=; b=B9vYSUBvA0QxCiWaSwZ/Mw9T6Gqg0WvmCGn0t6hdaDODOa+bjRtYS/G06Hxx7yXh+v 7630vkOg8l2xKnTOpw6My8AByybpjxR+rt3oniwfK+eT6Z0gv4PP6UBw24gGamlw0vRv bNiSd8YDAp8PERHEwwc729NYS4gNk98nFgwSDQwi92q67BDz9LV4Yl4ojXPEcx46WMJ4 4tVX/7hzkLDsbDzs2coWA6b/BrKZi/sLSZwQZW7ShCVIEGQOK3nY9iaotBcXjBPQxvB1 iJmKXQTku5tf2XY0bR2MdRacPlhDkStSYJJ0pc3StHbuUYlAnFcbVg4W1TwcCn3NwjC4 gBeQ== X-Forwarded-Encrypted: i=1; AJvYcCVU5eP4IOGzjr22/D0xNpOQVri7g5NOerlo2mk0btdqzVfUpE1fB6FhMCYEAxie1bbXA6Nom7NcAMfVUIdcAAoSQiEf35DNL6x+gmTfAX4zzKaEFf1zL5xfhO/BgJo8cKjqkr5rbyBat2kj7q7k5EPer1ss/E5tbzsw4/w6FQq4UJfE3rg= X-Gm-Message-State: AOJu0Yx0V1Mzm9AW54SK4p4eeAiw1Nf1kIgOJ4hk4uh4813G2y6bNJNf TO8ca2pZm6ZbCIBuHXUj2YN95E0nMw8eTeAJIJaPioc3N14YNPfo X-Google-Smtp-Source: AGHT+IEWK+0l6NwT5ms/nOdj9u8zDR3ULI0oUIx2mGbqXx49pkKUoy02J8uly+oPf4NGy7PTUjKbBw== X-Received: by 2002:adf:e608:0:b0:360:866f:5083 with SMTP id ffacd0b85a97d-360866f522cmr5709768f8f.32.1718574961758; Sun, 16 Jun 2024 14:56:01 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36075104b74sm10362879f8f.107.2024.06.16.14.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:56:01 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v6 14/20] leds: leds-lp55xx: generalize stop_engine function Date: Sun, 16 Jun 2024 23:52:13 +0200 Message-ID: <20240616215226.2112-15-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize stop_engine function as the implementation is the same for most of the lp55xx based LED driver. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 20 +++----------------- drivers/leds/leds-lp5523.c | 20 +++----------------- drivers/leds/leds-lp55xx-common.c | 13 +++++++++++++ drivers/leds/leds-lp55xx-common.h | 1 + 4 files changed, 20 insertions(+), 34 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index a1a3bf0ff703..4afae0c70d19 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -108,27 +108,13 @@ static inline void lp5521_wait_enable_done(void) usleep_range(500, 600); } -static void lp5521_stop_engine(struct lp55xx_chip *chip) -{ - enum lp55xx_engine_index idx = chip->engine_idx; - static const u8 mask[] = { - [LP55XX_ENGINE_1] = LP5521_MODE_R_M, - [LP55XX_ENGINE_2] = LP5521_MODE_G_M, - [LP55XX_ENGINE_3] = LP5521_MODE_B_M, - }; - - lp55xx_update_bits(chip, LP5521_REG_OP_MODE, mask[idx], 0); - - lp5521_wait_opmode_done(); -} - static void lp5521_run_engine(struct lp55xx_chip *chip, bool start) { int ret; /* stop engine */ if (!start) { - lp5521_stop_engine(chip); + lp55xx_stop_engine(chip); lp55xx_write(chip, LP5521_REG_OP_MODE, LP5521_CMD_DIRECT); lp5521_wait_opmode_done(); return; @@ -253,11 +239,11 @@ static ssize_t store_engine_mode(struct device *dev, lp5521_run_engine(chip, true); engine->mode = LP55XX_ENGINE_RUN; } else if (!strncmp(buf, "load", 4)) { - lp5521_stop_engine(chip); + lp55xx_stop_engine(chip); lp55xx_load_engine(chip); engine->mode = LP55XX_ENGINE_LOAD; } else if (!strncmp(buf, "disabled", 8)) { - lp5521_stop_engine(chip); + lp55xx_stop_engine(chip); engine->mode = LP55XX_ENGINE_DISABLED; } diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 4a4463cb44a4..1dd909a0fff5 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -153,25 +153,11 @@ static int lp5523_post_init_device(struct lp55xx_chip *chip) return lp5523_init_program_engine(chip); } -static void lp5523_stop_engine(struct lp55xx_chip *chip) -{ - enum lp55xx_engine_index idx = chip->engine_idx; - static const u8 mask[] = { - [LP55XX_ENGINE_1] = LP5523_MODE_ENG1_M, - [LP55XX_ENGINE_2] = LP5523_MODE_ENG2_M, - [LP55XX_ENGINE_3] = LP5523_MODE_ENG3_M, - }; - - lp55xx_update_bits(chip, LP5523_REG_OP_MODE, mask[idx], 0); - - lp5523_wait_opmode_done(); -} - static void lp5523_run_engine(struct lp55xx_chip *chip, bool start) { /* stop engine */ if (!start) { - lp5523_stop_engine(chip); + lp55xx_stop_engine(chip); lp55xx_turn_off_channels(chip); return; } @@ -277,11 +263,11 @@ static ssize_t store_engine_mode(struct device *dev, lp5523_run_engine(chip, true); engine->mode = LP55XX_ENGINE_RUN; } else if (!strncmp(buf, "load", 4)) { - lp5523_stop_engine(chip); + lp55xx_stop_engine(chip); lp55xx_load_engine(chip); engine->mode = LP55XX_ENGINE_LOAD; } else if (!strncmp(buf, "disabled", 8)) { - lp5523_stop_engine(chip); + lp55xx_stop_engine(chip); engine->mode = LP55XX_ENGINE_DISABLED; } diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 202b598dd177..09a81476c4ce 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -300,6 +300,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 Sun Jun 16 21:52:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805041 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.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 6BCCE13A86E; Sun, 16 Jun 2024 21:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574966; cv=none; b=rG/05wB2PHUjeAJsIr7QTjV4UhT7YpBQjd9j+JIPPZ9vBRuz1qTRcwJvJ7NKP264cSzWvc0xxSzdzl+eAnjujpBYkmltFnJvQQ1EEf6EBAIfrm1bA0bY9kpdKgs9ZRoJ3LqsVNBUBrHsHTWBagFGdi2sF9RT/LyZW6Opzas+isI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574966; c=relaxed/simple; bh=teN6RcLhTClIKudPtCae74rHmHToMDH/zDtMOoFPC9M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dGI6Gvq7ZUfGjyciZpSorOKoLvV5I0r1vY7awcoT+IFObDY8/KW16evJufNqK9Aegi20VorbVxtMlgl2VWXvIdl9LxGDmjukIFJCGltAyQvAEcm+ve2NfTsH1bywIfbkEbRzAGJoAFSNlIiYkgGuxBhaKBP21Xce7pbY0RYV7+I= 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=YC7dv2Qf; arc=none smtp.client-ip=209.85.221.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="YC7dv2Qf" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-35dc9cef36dso3459237f8f.3; Sun, 16 Jun 2024 14:56:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574963; x=1719179763; 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=936srXE0qPYMcHTRufholGRjWGSRbgibILay/ewjoZA=; b=YC7dv2QfgrnV1b00BFsbQbrNj5J6VlbWaEAmKW2m6sMNjm5cb/UPOkatxHBTlPxAEM 0ExnASIdvhwblK0AYPgQBpquKlR+nWtgGbEimgkwO23LxGiD/cGWC5HZj6QUjW9vcpgb FHrFUJeYslCanSyIyoVGnJGWNC+olMmAy+UqGAnpfL6CHAnhAVwwMH/AHyzoQJQNwV+Y /vtiDmBHSSI62XrAr/04iOaBeX31OmX9QBF8dlsgsXn5palx4yEH3W9t0RAqBy0VTOkz z5g64ImeLrqyRUMIWhl+27Npo7aw+zvhfOhz9gqsdil3+gnfP9uAuYGHInI8KlhziY7j efNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574963; x=1719179763; 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=936srXE0qPYMcHTRufholGRjWGSRbgibILay/ewjoZA=; b=etRnF4zyKfy9X/cDpkjIkMYtBEfgG6tkAyGwE/Wa86QbE/TXFyivptNXdIs8ss8y4Y QXg8NBeWIZXIVTsGcak9YGOqasH+Qn6MNIHf/L7LQolKT/Me6DjuPIse5nrL5GGIW8HL 8zKFXAxjgUpXsPjxFa2MfFcTrES88l/iT9BoSjYvDgWUaQNRMKASe7yd1E3Rh7lvUbkj xmfsk6iEOJVGFUPVtY5lGgNIGCYoNXYDPP4T9HA2wwKcXI/k6mIi74gXT/ayrjCMcs1l L2eqAvywchQRx0AXwKJ+qGCEJKbDMC4x5XqL7q6TpGjl85QpLY7qjPT5cM4rpKobV5Ch Z28w== X-Forwarded-Encrypted: i=1; AJvYcCW+3zn4eQqfYkYV2XkUX2Q0UnRTuiOz/fW0+1e0cDayccz6GW/FAgssYbCk20uKWJkY9IuhzPRgwAv9G2OMcCH7Rqmz/Di/M52tQ8IewazOUnjUqduirKf2DTEvWKwe/PEfKfXKEWngaNxnnyOta76lS9S/OijQQ5IUCbbb5Z+nmBMH8AQ= X-Gm-Message-State: AOJu0Ywx9djlAXR8P075u+hK8w+toGt0IqETR5jT386ieP2nQEw13gty MemWdSrbo0aD3cPxWFgJYVJOwDjiURtIs78QpBH+pqMNrmBertKN X-Google-Smtp-Source: AGHT+IEnTgvpdT6cM2x2z65aBRUyYrbD6Ncd/QQWH/4fRipvVj6ofVQLSONJPv65oJzH/fqllu8jkA== X-Received: by 2002:a5d:528b:0:b0:35f:2729:a110 with SMTP id ffacd0b85a97d-3607a7207c9mr5774521f8f.9.1718574962737; Sun, 16 Jun 2024 14:56:02 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36075104b74sm10362879f8f.107.2024.06.16.14.56.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:56:02 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v6 15/20] leds: leds-lp55xx: generalize sysfs engine_load and engine_mode Date: Sun, 16 Jun 2024 23:52:14 +0200 Message-ID: <20240616215226.2112-16-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize sysfs engine_load and engine_mode since their implementation is the same acrosso some lp55xx based LED driver. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 88 +++---------------------------- drivers/leds/leds-lp5523.c | 88 +++---------------------------- drivers/leds/leds-lp55xx-common.c | 83 ++++++++++++++++++++++++++--- drivers/leds/leds-lp55xx-common.h | 26 +++++++-- 4 files changed, 112 insertions(+), 173 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 4afae0c70d19..519e7627ac22 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -201,82 +201,6 @@ static int lp5521_run_selftest(struct lp55xx_chip *chip, char *buf) return 0; } -static ssize_t show_engine_mode(struct device *dev, - struct device_attribute *attr, - char *buf, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - enum lp55xx_engine_mode mode = chip->engines[nr - 1].mode; - - switch (mode) { - case LP55XX_ENGINE_RUN: - return sprintf(buf, "run\n"); - case LP55XX_ENGINE_LOAD: - return sprintf(buf, "load\n"); - case LP55XX_ENGINE_DISABLED: - default: - return sprintf(buf, "disabled\n"); - } -} -show_mode(1) -show_mode(2) -show_mode(3) - -static ssize_t store_engine_mode(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - struct lp55xx_engine *engine = &chip->engines[nr - 1]; - - mutex_lock(&chip->lock); - - chip->engine_idx = nr; - - if (!strncmp(buf, "run", 3)) { - lp5521_run_engine(chip, true); - engine->mode = LP55XX_ENGINE_RUN; - } else if (!strncmp(buf, "load", 4)) { - lp55xx_stop_engine(chip); - lp55xx_load_engine(chip); - engine->mode = LP55XX_ENGINE_LOAD; - } else if (!strncmp(buf, "disabled", 8)) { - lp55xx_stop_engine(chip); - engine->mode = LP55XX_ENGINE_DISABLED; - } - - mutex_unlock(&chip->lock); - - return len; -} -store_mode(1) -store_mode(2) -store_mode(3) - -static ssize_t store_engine_load(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - int ret; - - mutex_lock(&chip->lock); - - chip->engine_idx = nr; - lp55xx_load_engine(chip); - ret = lp55xx_update_program_memory(chip, buf, len); - - mutex_unlock(&chip->lock); - - return ret; -} -store_load(1) -store_load(2) -store_load(3) - static ssize_t lp5521_selftest(struct device *dev, struct device_attribute *attr, char *buf) @@ -293,12 +217,12 @@ static ssize_t lp5521_selftest(struct device *dev, } /* device attributes */ -static LP55XX_DEV_ATTR_RW(engine1_mode, show_engine1_mode, store_engine1_mode); -static LP55XX_DEV_ATTR_RW(engine2_mode, show_engine2_mode, store_engine2_mode); -static LP55XX_DEV_ATTR_RW(engine3_mode, show_engine3_mode, store_engine3_mode); -static LP55XX_DEV_ATTR_WO(engine1_load, store_engine1_load); -static LP55XX_DEV_ATTR_WO(engine2_load, store_engine2_load); -static LP55XX_DEV_ATTR_WO(engine3_load, store_engine3_load); +LP55XX_DEV_ATTR_ENGINE_MODE(1); +LP55XX_DEV_ATTR_ENGINE_MODE(2); +LP55XX_DEV_ATTR_ENGINE_MODE(3); +LP55XX_DEV_ATTR_ENGINE_LOAD(1); +LP55XX_DEV_ATTR_ENGINE_LOAD(2); +LP55XX_DEV_ATTR_ENGINE_LOAD(3); static LP55XX_DEV_ATTR_RO(selftest, lp5521_selftest); static struct attribute *lp5521_attributes[] = { diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 1dd909a0fff5..19b119a2b256 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -225,60 +225,6 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) return ret; } -static ssize_t show_engine_mode(struct device *dev, - struct device_attribute *attr, - char *buf, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - enum lp55xx_engine_mode mode = chip->engines[nr - 1].mode; - - switch (mode) { - case LP55XX_ENGINE_RUN: - return sprintf(buf, "run\n"); - case LP55XX_ENGINE_LOAD: - return sprintf(buf, "load\n"); - case LP55XX_ENGINE_DISABLED: - default: - return sprintf(buf, "disabled\n"); - } -} -show_mode(1) -show_mode(2) -show_mode(3) - -static ssize_t store_engine_mode(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - struct lp55xx_engine *engine = &chip->engines[nr - 1]; - - mutex_lock(&chip->lock); - - chip->engine_idx = nr; - - if (!strncmp(buf, "run", 3)) { - lp5523_run_engine(chip, true); - engine->mode = LP55XX_ENGINE_RUN; - } else if (!strncmp(buf, "load", 4)) { - lp55xx_stop_engine(chip); - lp55xx_load_engine(chip); - engine->mode = LP55XX_ENGINE_LOAD; - } else if (!strncmp(buf, "disabled", 8)) { - lp55xx_stop_engine(chip); - engine->mode = LP55XX_ENGINE_DISABLED; - } - - mutex_unlock(&chip->lock); - - return len; -} -store_mode(1) -store_mode(2) -store_mode(3) - static int lp5523_mux_parse(const char *buf, u16 *mux, size_t len) { u16 tmp_mux = 0; @@ -392,28 +338,6 @@ store_leds(1) store_leds(2) store_leds(3) -static ssize_t store_engine_load(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - int ret; - - mutex_lock(&chip->lock); - - chip->engine_idx = nr; - lp55xx_load_engine(chip); - ret = lp55xx_update_program_memory(chip, buf, len); - - mutex_unlock(&chip->lock); - - return ret; -} -store_load(1) -store_load(2) -store_load(3) - static ssize_t lp5523_selftest(struct device *dev, struct device_attribute *attr, char *buf) @@ -635,15 +559,15 @@ static ssize_t store_master_fader_leds(struct device *dev, return ret; } -static LP55XX_DEV_ATTR_RW(engine1_mode, show_engine1_mode, store_engine1_mode); -static LP55XX_DEV_ATTR_RW(engine2_mode, show_engine2_mode, store_engine2_mode); -static LP55XX_DEV_ATTR_RW(engine3_mode, show_engine3_mode, store_engine3_mode); +LP55XX_DEV_ATTR_ENGINE_MODE(1); +LP55XX_DEV_ATTR_ENGINE_MODE(2); +LP55XX_DEV_ATTR_ENGINE_MODE(3); static LP55XX_DEV_ATTR_RW(engine1_leds, show_engine1_leds, store_engine1_leds); static LP55XX_DEV_ATTR_RW(engine2_leds, show_engine2_leds, store_engine2_leds); static LP55XX_DEV_ATTR_RW(engine3_leds, show_engine3_leds, store_engine3_leds); -static LP55XX_DEV_ATTR_WO(engine1_load, store_engine1_load); -static LP55XX_DEV_ATTR_WO(engine2_load, store_engine2_load); -static LP55XX_DEV_ATTR_WO(engine3_load, store_engine3_load); +LP55XX_DEV_ATTR_ENGINE_LOAD(1); +LP55XX_DEV_ATTR_ENGINE_LOAD(2); +LP55XX_DEV_ATTR_ENGINE_LOAD(3); static LP55XX_DEV_ATTR_RO(selftest, lp5523_selftest); static LP55XX_DEV_ATTR_RW(master_fader1, show_master_fader1, store_master_fader1); diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 09a81476c4ce..506cde3f4cc1 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -543,8 +543,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; @@ -553,8 +553,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; @@ -595,8 +595,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; @@ -622,6 +622,77 @@ static ssize_t run_engine_store(struct device *dev, static DEVICE_ATTR_RW(select_engine); static DEVICE_ATTR_WO(run_engine); +ssize_t lp55xx_show_engine_mode(struct device *dev, + struct device_attribute *attr, + char *buf, int nr) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + enum lp55xx_engine_mode mode = chip->engines[nr - 1].mode; + + switch (mode) { + case LP55XX_ENGINE_RUN: + return sprintf(buf, "run\n"); + case LP55XX_ENGINE_LOAD: + return sprintf(buf, "load\n"); + case LP55XX_ENGINE_DISABLED: + default: + return sprintf(buf, "disabled\n"); + } +} +EXPORT_SYMBOL_GPL(lp55xx_show_engine_mode); + +ssize_t lp55xx_store_engine_mode(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + struct lp55xx_engine *engine = &chip->engines[nr - 1]; + + mutex_lock(&chip->lock); + + chip->engine_idx = nr; + + if (!strncmp(buf, "run", 3)) { + cfg->run_engine(chip, true); + engine->mode = LP55XX_ENGINE_RUN; + } else if (!strncmp(buf, "load", 4)) { + lp55xx_stop_engine(chip); + lp55xx_load_engine(chip); + engine->mode = LP55XX_ENGINE_LOAD; + } else if (!strncmp(buf, "disabled", 8)) { + lp55xx_stop_engine(chip); + engine->mode = LP55XX_ENGINE_DISABLED; + } + + mutex_unlock(&chip->lock); + + return len; +} +EXPORT_SYMBOL_GPL(lp55xx_store_engine_mode); + +ssize_t lp55xx_store_engine_load(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + int ret; + + mutex_lock(&chip->lock); + + chip->engine_idx = nr; + lp55xx_load_engine(chip); + ret = lp55xx_update_program_memory(chip, buf, len); + + mutex_unlock(&chip->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_store_engine_load); + static struct attribute *lp55xx_engine_attributes[] = { &dev_attr_select_engine.attr, &dev_attr_run_engine.attr, diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 0aba6955a3af..00d16a86b750 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -40,7 +40,7 @@ static ssize_t show_engine##nr##_mode(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ { \ - return show_engine_mode(dev, attr, buf, nr); \ + return lp55xx_show_engine_mode(dev, attr, buf, nr); \ } #define store_mode(nr) \ @@ -48,9 +48,14 @@ static ssize_t store_engine##nr##_mode(struct device *dev, \ struct device_attribute *attr, \ const char *buf, size_t len) \ { \ - return store_engine_mode(dev, attr, buf, len, nr); \ + return lp55xx_store_engine_mode(dev, attr, buf, len, nr); \ } +#define LP55XX_DEV_ATTR_ENGINE_MODE(nr) \ + show_mode(nr) \ + store_mode(nr) \ + static LP55XX_DEV_ATTR_RW(engine##nr##_mode, show_engine##nr##_mode, store_engine##nr##_mode) + #define show_leds(nr) \ static ssize_t show_engine##nr##_leds(struct device *dev, \ struct device_attribute *attr, \ @@ -72,9 +77,13 @@ static ssize_t store_engine##nr##_load(struct device *dev, \ struct device_attribute *attr, \ const char *buf, size_t len) \ { \ - return store_engine_load(dev, attr, buf, len, nr); \ + return lp55xx_store_engine_load(dev, attr, buf, len, nr); \ } +#define LP55XX_DEV_ATTR_ENGINE_LOAD(nr) \ + store_load(nr) \ + static LP55XX_DEV_ATTR_WO(engine##nr##_load, store_engine##nr##_load) + struct lp55xx_led; struct lp55xx_chip; @@ -227,4 +236,15 @@ extern void lp55xx_stop_engine(struct lp55xx_chip *chip); extern int lp55xx_probe(struct i2c_client *client); extern void lp55xx_remove(struct i2c_client *client); +/* common sysfs function */ +extern ssize_t lp55xx_show_engine_mode(struct device *dev, + struct device_attribute *attr, + char *buf, int nr); +extern ssize_t lp55xx_store_engine_mode(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr); +extern ssize_t lp55xx_store_engine_load(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr); + #endif /* _LEDS_LP55XX_COMMON_H */ From patchwork Sun Jun 16 21:52:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 804688 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 762E813AA4C; Sun, 16 Jun 2024 21:56:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574967; cv=none; b=Immod1Sj0Hs+m7nwF4vjOPTJrC5jUtEGpjRHRquPCmBGCorzuiaCEmRiowmV25n557N6R7hzwyc2b4LmfSytLb3D6SpYlcowm9M6wPeSSq+LNGp+Kty/MW6R2U6T2391inVDzvZTU9Kg3rUkIFz+95DM9YDTF1CZatc5Ksb632c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574967; c=relaxed/simple; bh=T3UbZSBHEOWonVq01FuSupTB8ewGy03zPFXoi0Jefd0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HkB/9xjnZshPWSL1oyl7BHTOqhKS9b3cgr21Gw8MHyBTZUwtHeGwrpCLLQ4Hc/jtTl4MQQWz0s+cmY7XqXSOYeSMxMJT4xwJsuQnMGLA0rC/tXKp3spiEVmQ1iDib7kPkhulBUizUrxirsyl3DRKrzkI45eiO+5lPOyO4K8QStk= 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=iVikqjlU; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iVikqjlU" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-35f1cb7a40fso3226773f8f.0; Sun, 16 Jun 2024 14:56:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574964; x=1719179764; 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=tsQ6+wnPGxeyG9A/0+Qd3Wo05d2QvtyTNpm2jCWthiI=; b=iVikqjlUBaoOApBfAYQDMXidBzn7D0Sv6clMozd3oAjph9nV7VAUZ9x+QdDGsiIj1L 5b/Ba4jNE6BudjsXxjH7cSspiSRnkVCRe0R9RSmA7siyE7IU17fvymcD2a1vBrIt1IQd BMmC4rFpkCUAS3UnQ1756CNSE4KPNvjx9LQJYn98UhNJO4KvrviSFg2bDkyaslA5Wo/4 ectelD/LHZFV3SR+HHX716C+5JyoAFsTW4zpldO18d2Spm4UX1dz9gxuyG0wHc0H6tTg 8a2y7MCcFkRGoYTK5G03if0WRtCsdSM1c7RFlWHJJU0OT0t7MNLqHaEANkJLfzQk2dCe 1K5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574964; x=1719179764; 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=tsQ6+wnPGxeyG9A/0+Qd3Wo05d2QvtyTNpm2jCWthiI=; b=prFGNScClauKry2u+jYyB0gz89fTwGelYOdFULKHDiYAeX45fFAKdbGn/Jp/Pbh8ES omSD9AegKCZH6B2REtljMg+M8fjnxka6YUojEbvgvNOvu0tWS8r5QJ0VhsVbbrll0q+I ANsNDL3N2DhMiJIdfHaxiDkuOPZeCTHIgGzum+VhrpYvXGDyO84kaTeE1VRN/Gip/rVb GLglUPGONzV553DLtJ3tntXg3pwB2WKLUWw/EBZB3TZbmG9kigaW+LzmFUto0P1EBrF4 3ymGLJYSlH85L8BhCEZ1ehSJdZqku8knjWqylXKWJ6NjpIx1T6LyDr5VhD1Q0970BWwm hppg== X-Forwarded-Encrypted: i=1; AJvYcCVrBCmebWTg9Q+bcYlm9B2+IPm9UFqw2FbC2PsP1+f9apCK8xL9paBGFex1cLN2diDNZsPP1M0LALV6nrK9vrl74gCxX2D7ju4/z0B51z1B2nStg61+P9S9mcTrmzs0ZnqU6DSSzWBcFFSa9g59IjQWuGFkN1reckAQ1OLWhBiew01YFNI= X-Gm-Message-State: AOJu0Yy5fPs2ZOVONATxP1nrPmqMlpRbNg/XE7IrM3ckaHe0UZ+31EnP CBBRVwaeYQX8QYiLyznAN2NtFX1RNOnQlcd98d1mxM0Qny+SCi3g X-Google-Smtp-Source: AGHT+IE5V75ihQZaYFqFTNT22HtgIZNiyI/80/BzTAZjfrEpnKyjvdaaI/OQbV7+0n7AyJ9WAdAFRg== X-Received: by 2002:adf:f906:0:b0:35f:30ae:a6e4 with SMTP id ffacd0b85a97d-3607a782371mr5606646f8f.46.1718574963806; Sun, 16 Jun 2024 14:56:03 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36075104b74sm10362879f8f.107.2024.06.16.14.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:56:03 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v6 16/20] leds: leds-lp55xx: generalize sysfs engine_leds Date: Sun, 16 Jun 2024 23:52:15 +0200 Message-ID: <20240616215226.2112-17-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize sysfs engine_leds since their implementation is the same across some lp55xx based LED driver. While at it simplify the implementation for show_engine_leds. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5523.c | 119 +----------------------------- drivers/leds/leds-lp55xx-common.c | 108 +++++++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 15 +++- 3 files changed, 124 insertions(+), 118 deletions(-) diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 19b119a2b256..9d91c2c5a3eb 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -225,119 +225,6 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) return ret; } -static int lp5523_mux_parse(const char *buf, u16 *mux, size_t len) -{ - u16 tmp_mux = 0; - int i; - - len = min_t(int, len, LP5523_MAX_LEDS); - - for (i = 0; i < len; i++) { - switch (buf[i]) { - case '1': - tmp_mux |= (1 << i); - break; - case '0': - break; - case '\n': - i = len; - break; - default: - return -1; - } - } - *mux = tmp_mux; - - return 0; -} - -static void lp5523_mux_to_array(u16 led_mux, char *array) -{ - int i, pos = 0; - - for (i = 0; i < LP5523_MAX_LEDS; i++) - pos += sprintf(array + pos, "%x", LED_ACTIVE(led_mux, i)); - - array[pos] = '\0'; -} - -static ssize_t show_engine_leds(struct device *dev, - struct device_attribute *attr, - char *buf, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - char mux[LP5523_MAX_LEDS + 1]; - - lp5523_mux_to_array(chip->engines[nr - 1].led_mux, mux); - - return sprintf(buf, "%s\n", mux); -} -show_leds(1) -show_leds(2) -show_leds(3) - -static int lp5523_load_mux(struct lp55xx_chip *chip, u16 mux, int nr) -{ - struct lp55xx_engine *engine = &chip->engines[nr - 1]; - int ret; - static const u8 mux_page[] = { - [LP55XX_ENGINE_1] = LP5523_PAGE_MUX1, - [LP55XX_ENGINE_2] = LP5523_PAGE_MUX2, - [LP55XX_ENGINE_3] = LP5523_PAGE_MUX3, - }; - - lp55xx_load_engine(chip); - - ret = lp55xx_write(chip, LP5523_REG_PROG_PAGE_SEL, mux_page[nr]); - if (ret) - return ret; - - ret = lp55xx_write(chip, LP5523_REG_PROG_MEM, (u8)(mux >> 8)); - if (ret) - return ret; - - ret = lp55xx_write(chip, LP5523_REG_PROG_MEM + 1, (u8)(mux)); - if (ret) - return ret; - - engine->led_mux = mux; - return 0; -} - -static ssize_t store_engine_leds(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - struct lp55xx_engine *engine = &chip->engines[nr - 1]; - u16 mux = 0; - ssize_t ret; - - if (lp5523_mux_parse(buf, &mux, len)) - return -EINVAL; - - mutex_lock(&chip->lock); - - chip->engine_idx = nr; - ret = -EINVAL; - - if (engine->mode != LP55XX_ENGINE_LOAD) - goto leave; - - if (lp5523_load_mux(chip, mux, nr)) - goto leave; - - ret = len; -leave: - mutex_unlock(&chip->lock); - return ret; -} -store_leds(1) -store_leds(2) -store_leds(3) - static ssize_t lp5523_selftest(struct device *dev, struct device_attribute *attr, char *buf) @@ -562,9 +449,9 @@ static ssize_t store_master_fader_leds(struct device *dev, LP55XX_DEV_ATTR_ENGINE_MODE(1); LP55XX_DEV_ATTR_ENGINE_MODE(2); LP55XX_DEV_ATTR_ENGINE_MODE(3); -static LP55XX_DEV_ATTR_RW(engine1_leds, show_engine1_leds, store_engine1_leds); -static LP55XX_DEV_ATTR_RW(engine2_leds, show_engine2_leds, store_engine2_leds); -static LP55XX_DEV_ATTR_RW(engine3_leds, show_engine3_leds, store_engine3_leds); +LP55XX_DEV_ATTR_ENGINE_LEDS(1); +LP55XX_DEV_ATTR_ENGINE_LEDS(2); +LP55XX_DEV_ATTR_ENGINE_LEDS(3); LP55XX_DEV_ATTR_ENGINE_LOAD(1); LP55XX_DEV_ATTR_ENGINE_LOAD(2); LP55XX_DEV_ATTR_ENGINE_LOAD(3); diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 506cde3f4cc1..df94c1d385b9 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 @@ -693,6 +695,112 @@ ssize_t lp55xx_store_engine_load(struct device *dev, } EXPORT_SYMBOL_GPL(lp55xx_store_engine_load); +static int lp55xx_mux_parse(struct lp55xx_chip *chip, const char *buf, + u16 *mux, size_t len) +{ + const struct lp55xx_device_config *cfg = chip->cfg; + u16 tmp_mux = 0; + int i; + + len = min_t(int, len, cfg->max_channel); + + for (i = 0; i < len; i++) { + switch (buf[i]) { + case '1': + tmp_mux |= (1 << i); + break; + case '0': + break; + case '\n': + i = len; + break; + default: + return -1; + } + } + *mux = tmp_mux; + + return 0; +} + +ssize_t lp55xx_show_engine_leds(struct device *dev, + struct device_attribute *attr, + char *buf, int nr) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + int i, pos = 0; + + for (i = 0; i < cfg->max_channel; i++) + pos += sysfs_emit_at(buf, pos, "%x", + LED_ACTIVE(chip->engines[nr - 1].led_mux, + i)); + + pos += sysfs_emit_at(buf, pos, "\n"); + + return pos; +} +EXPORT_SYMBOL_GPL(lp55xx_show_engine_leds); + +static int lp55xx_load_mux(struct lp55xx_chip *chip, u16 mux, int nr) +{ + struct lp55xx_engine *engine = &chip->engines[nr - 1]; + const struct lp55xx_device_config *cfg = chip->cfg; + u8 mux_page; + int ret; + + lp55xx_load_engine(chip); + + /* Derive the MUX page offset by starting at the end of the ENGINE pages */ + mux_page = cfg->pages_per_engine * LP55XX_ENGINE_MAX + (nr - 1); + ret = lp55xx_write(chip, LP55xx_REG_PROG_PAGE_SEL, mux_page); + if (ret) + return ret; + + ret = lp55xx_write(chip, cfg->prog_mem_base.addr, (u8)(mux >> 8)); + if (ret) + return ret; + + ret = lp55xx_write(chip, cfg->prog_mem_base.addr + 1, (u8)(mux)); + if (ret) + return ret; + + engine->led_mux = mux; + return 0; +} + +ssize_t lp55xx_store_engine_leds(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + struct lp55xx_engine *engine = &chip->engines[nr - 1]; + u16 mux = 0; + ssize_t ret; + + if (lp55xx_mux_parse(chip, buf, &mux, len)) + return -EINVAL; + + mutex_lock(&chip->lock); + + chip->engine_idx = nr; + ret = -EINVAL; + + if (engine->mode != LP55XX_ENGINE_LOAD) + goto leave; + + if (lp55xx_load_mux(chip, mux, nr)) + goto leave; + + ret = len; +leave: + mutex_unlock(&chip->lock); + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_store_engine_leds); + static struct attribute *lp55xx_engine_attributes[] = { &dev_attr_select_engine.attr, &dev_attr_run_engine.attr, diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 00d16a86b750..212bdb216c9a 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -61,7 +61,7 @@ static ssize_t show_engine##nr##_leds(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ { \ - return show_engine_leds(dev, attr, buf, nr); \ + return lp55xx_show_engine_leds(dev, attr, buf, nr); \ } #define store_leds(nr) \ @@ -69,9 +69,14 @@ static ssize_t store_engine##nr##_leds(struct device *dev, \ struct device_attribute *attr, \ const char *buf, size_t len) \ { \ - return store_engine_leds(dev, attr, buf, len, nr); \ + return lp55xx_store_engine_leds(dev, attr, buf, len, nr); \ } +#define LP55XX_DEV_ATTR_ENGINE_LEDS(nr) \ + show_leds(nr) \ + store_leds(nr) \ + static LP55XX_DEV_ATTR_RW(engine##nr##_leds, show_engine##nr##_leds, store_engine##nr##_leds) + #define store_load(nr) \ static ssize_t store_engine##nr##_load(struct device *dev, \ struct device_attribute *attr, \ @@ -246,5 +251,11 @@ extern ssize_t lp55xx_store_engine_mode(struct device *dev, extern ssize_t lp55xx_store_engine_load(struct device *dev, struct device_attribute *attr, const char *buf, size_t len, int nr); +extern ssize_t lp55xx_show_engine_leds(struct device *dev, + struct device_attribute *attr, + char *buf, int nr); +extern ssize_t lp55xx_store_engine_leds(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr); #endif /* _LEDS_LP55XX_COMMON_H */ From patchwork Sun Jun 16 21:52:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 805040 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 7745E12D74D; Sun, 16 Jun 2024 21:56:06 +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=1718574968; cv=none; b=iZ2wlYtG0lgtDDIrkcG0Au+Cdy+WJL/r6k+HBZ+pXY5/x6LxWeeJ2ZP1mk3euVUcL8VUSKLN1ulfObXxWHL9k7OK0oIDRf329Wy8/hvSlOMUHjaxEGzkhSfcuXtBvFjqFhv89NEdmUpoZLycEgLk16btl4cRd6ZjLx0rSS4L+1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574968; c=relaxed/simple; bh=ikEyrlJevGWYN9zluW4S04Lbs5lyXzFXkOdl9hprlNo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UfK8Z1Vr23euAG1knUieGFifd/633R0YJ3k1CJXjRyRb1dR96IkZrzFaR6PMsE+RYLM4w092kk3xVZq0DH77jJcCo1gcurSrIo8MRqTGE1imMoRCnpS+k7TMtATxSH7t/+dV8yfRqCbpndMqxKqXGUZTTicYQ4mlWNNP8cJG3wg= 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=YNzPn6ul; 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="YNzPn6ul" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-35f236a563cso3100915f8f.2; Sun, 16 Jun 2024 14:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574965; x=1719179765; 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=+d3enEU3lgcaUsAUl7uXsmRgHaVq3T0tY3AEAHCizvA=; b=YNzPn6ullzZ3Hwv6jt1vmYY6/4KvxU+/s5a0n5sQsY8cdlMz7jTpwC7YPIIut8JPCX E3loq7R+Fhs5aoJqGv5Ivv0T9hzZ8SunbBbpwC6AnpphKmQu8bnaS8eefCnQA0YjHEVu P+Ssq0bVBRQtunQWoS5q2l6UA+WGwkZxnmf9SSRq2bSbE3b33zHG7LdfaSSd0XApTGk0 336I57as32fNVmICAUUu5brHCZKVUd2UOCgPIoyminRM/W0O+uDkXa5vyxkchvpX50yz 9Bx2C9yNXNmcEDdiJTKoe30KIO8ext6T5DSXZ8jH4nwGP68rmxavlBnduQxQXVDC69C7 Otkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574965; x=1719179765; 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=+d3enEU3lgcaUsAUl7uXsmRgHaVq3T0tY3AEAHCizvA=; b=caqg7SBs6xyP+DsUBxDHt3EyHdv5smxrP8qMX24Gxc1zHNNq+s74kI6j5mPVVB+yrl ONrryR4uB2a9VSPkBdjBQEXEfs6im87/SYO0I9mYjhmK05zgEwdyqfmG/S11bpyOmAR9 w+GnQX+xE1/1vMRACUtqwMBMe8PtcFRP3ewjSJ90bQKXYrgUXmnVcF17L9rMAXEyiLlc xuzSQPitYJZN/x9iVke73VVuAEAVinmcioTYeu11Hc8BtyF+yUDAX/+ed0siDkOk9S5e rlCeccmFGKEcmO/SCAwiticK51lrmLpecfmu61hnQdNz3SbVgwwUJGoKgvRpADPyTwtX qgNw== X-Forwarded-Encrypted: i=1; AJvYcCXmrQSXseHXW8YGQ8pfX5SvDL8ePNFB71AgYpJeHftUv+YzfC/Zb6LL9bmddh9kDrqAJhHEQW1WN5Pdxu4ZZeRGyJK/Z4pRi8ry2sqIvMsDlO1o9zsMObVEEUdtAdK+V76R/g5s+OjBanl+neehWch6ITO+vvP/CBLKeq/2l7mOy8+VrU8= X-Gm-Message-State: AOJu0Ywul4tWyaeBoU16WFG9+Z1vao8Z0pHSv+NXi3dltKjwkRlMEwaB 1+rk7EmAVaMctUtkrFzGVNIuBk9/FOYKVaaoj1nEuMByQFulL+IN X-Google-Smtp-Source: AGHT+IHZIZ9m9fMrXgVp3WcTaIPvyjv+znPuZju5hDYkdCbnipskAA8uwdDgypMRvr7gSEGuCE3jmw== X-Received: by 2002:a05:6000:181c:b0:35f:22e4:fb58 with SMTP id ffacd0b85a97d-3607a725b3fmr6451772f8f.8.1718574964777; Sun, 16 Jun 2024 14:56:04 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36075104b74sm10362879f8f.107.2024.06.16.14.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:56:04 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v6 17/20] leds: leds-lp55xx: generalize sysfs master_fader Date: Sun, 16 Jun 2024 23:52:16 +0200 Message-ID: <20240616215226.2112-18-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Generalize sysfs master_fader since their implementation is the same across some lp55xx based LED driver. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5523.c | 144 ++---------------------------- drivers/leds/leds-lp55xx-common.c | 119 ++++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 37 ++++++++ 3 files changed, 161 insertions(+), 139 deletions(-) diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 9d91c2c5a3eb..6f25a6c32869 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -315,137 +315,6 @@ static ssize_t lp5523_selftest(struct device *dev, return pos; } -#define show_fader(nr) \ -static ssize_t show_master_fader##nr(struct device *dev, \ - struct device_attribute *attr, \ - char *buf) \ -{ \ - return show_master_fader(dev, attr, buf, nr); \ -} - -#define store_fader(nr) \ -static ssize_t store_master_fader##nr(struct device *dev, \ - struct device_attribute *attr, \ - const char *buf, size_t len) \ -{ \ - return store_master_fader(dev, attr, buf, len, nr); \ -} - -static ssize_t show_master_fader(struct device *dev, - struct device_attribute *attr, - char *buf, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - int ret; - u8 val; - - mutex_lock(&chip->lock); - ret = lp55xx_read(chip, LP5523_REG_MASTER_FADER_BASE + nr - 1, &val); - mutex_unlock(&chip->lock); - - if (ret == 0) - ret = sprintf(buf, "%u\n", val); - - return ret; -} -show_fader(1) -show_fader(2) -show_fader(3) - -static ssize_t store_master_fader(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len, int nr) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - int ret; - unsigned long val; - - if (kstrtoul(buf, 0, &val)) - return -EINVAL; - - if (val > 0xff) - return -EINVAL; - - mutex_lock(&chip->lock); - ret = lp55xx_write(chip, LP5523_REG_MASTER_FADER_BASE + nr - 1, - (u8)val); - mutex_unlock(&chip->lock); - - if (ret == 0) - ret = len; - - return ret; -} -store_fader(1) -store_fader(2) -store_fader(3) - -static ssize_t show_master_fader_leds(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - int i, ret, pos = 0; - u8 val; - - mutex_lock(&chip->lock); - - for (i = 0; i < LP5523_MAX_LEDS; i++) { - ret = lp55xx_read(chip, LP5523_REG_LED_CTRL_BASE + i, &val); - if (ret) - goto leave; - - val = (val & LP5523_FADER_MAPPING_MASK) - >> LP5523_FADER_MAPPING_SHIFT; - if (val > 3) { - ret = -EINVAL; - goto leave; - } - buf[pos++] = val + '0'; - } - buf[pos++] = '\n'; - ret = pos; -leave: - mutex_unlock(&chip->lock); - return ret; -} - -static ssize_t store_master_fader_leds(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); - struct lp55xx_chip *chip = led->chip; - int i, n, ret; - u8 val; - - n = min_t(int, len, LP5523_MAX_LEDS); - - mutex_lock(&chip->lock); - - for (i = 0; i < n; i++) { - if (buf[i] >= '0' && buf[i] <= '3') { - val = (buf[i] - '0') << LP5523_FADER_MAPPING_SHIFT; - ret = lp55xx_update_bits(chip, - LP5523_REG_LED_CTRL_BASE + i, - LP5523_FADER_MAPPING_MASK, - val); - if (ret) - goto leave; - } else { - ret = -EINVAL; - goto leave; - } - } - ret = len; -leave: - mutex_unlock(&chip->lock); - return ret; -} - LP55XX_DEV_ATTR_ENGINE_MODE(1); LP55XX_DEV_ATTR_ENGINE_MODE(2); LP55XX_DEV_ATTR_ENGINE_MODE(3); @@ -456,14 +325,11 @@ LP55XX_DEV_ATTR_ENGINE_LOAD(1); LP55XX_DEV_ATTR_ENGINE_LOAD(2); LP55XX_DEV_ATTR_ENGINE_LOAD(3); static LP55XX_DEV_ATTR_RO(selftest, lp5523_selftest); -static LP55XX_DEV_ATTR_RW(master_fader1, show_master_fader1, - store_master_fader1); -static LP55XX_DEV_ATTR_RW(master_fader2, show_master_fader2, - store_master_fader2); -static LP55XX_DEV_ATTR_RW(master_fader3, show_master_fader3, - store_master_fader3); -static LP55XX_DEV_ATTR_RW(master_fader_leds, show_master_fader_leds, - store_master_fader_leds); +LP55XX_DEV_ATTR_MASTER_FADER(1); +LP55XX_DEV_ATTR_MASTER_FADER(2); +LP55XX_DEV_ATTR_MASTER_FADER(3); +static LP55XX_DEV_ATTR_RW(master_fader_leds, lp55xx_show_master_fader_leds, + lp55xx_store_master_fader_leds); static struct attribute *lp5523_attributes[] = { &dev_attr_engine1_mode.attr, diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index df94c1d385b9..62f5d6e8087c 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 @@ -801,6 +804,122 @@ ssize_t lp55xx_store_engine_leds(struct device *dev, } EXPORT_SYMBOL_GPL(lp55xx_store_engine_leds); +ssize_t lp55xx_show_master_fader(struct device *dev, + struct device_attribute *attr, + char *buf, int nr) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + int ret; + u8 val; + + mutex_lock(&chip->lock); + ret = lp55xx_read(chip, cfg->reg_master_fader_base.addr + nr - 1, &val); + mutex_unlock(&chip->lock); + + if (ret == 0) + ret = sprintf(buf, "%u\n", val); + + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_show_master_fader); + +ssize_t lp55xx_store_master_fader(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + int ret; + unsigned long val; + + if (kstrtoul(buf, 0, &val)) + return -EINVAL; + + if (val > 0xff) + return -EINVAL; + + mutex_lock(&chip->lock); + ret = lp55xx_write(chip, cfg->reg_master_fader_base.addr + nr - 1, + (u8)val); + mutex_unlock(&chip->lock); + + if (ret == 0) + ret = len; + + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_store_master_fader); + +ssize_t lp55xx_show_master_fader_leds(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + int i, ret, pos = 0; + u8 val; + + mutex_lock(&chip->lock); + + for (i = 0; i < cfg->max_channel; i++) { + ret = lp55xx_read(chip, cfg->reg_led_ctrl_base.addr + i, &val); + if (ret) + goto leave; + + val = FIELD_GET(LP55xx_FADER_MAPPING_MASK, val); + if (val > FIELD_MAX(LP55xx_FADER_MAPPING_MASK)) { + ret = -EINVAL; + goto leave; + } + buf[pos++] = val + '0'; + } + buf[pos++] = '\n'; + ret = pos; +leave: + mutex_unlock(&chip->lock); + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_show_master_fader_leds); + +ssize_t lp55xx_store_master_fader_leds(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + const struct lp55xx_device_config *cfg = chip->cfg; + int i, n, ret; + u8 val; + + n = min_t(int, len, cfg->max_channel); + + mutex_lock(&chip->lock); + + for (i = 0; i < n; i++) { + if (buf[i] >= '0' && buf[i] <= '3') { + val = (buf[i] - '0') << __bf_shf(LP55xx_FADER_MAPPING_MASK); + ret = lp55xx_update_bits(chip, + cfg->reg_led_ctrl_base.addr + i, + LP55xx_FADER_MAPPING_MASK, + val); + if (ret) + goto leave; + } else { + ret = -EINVAL; + goto leave; + } + } + ret = len; +leave: + mutex_unlock(&chip->lock); + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_store_master_fader_leds); + static struct attribute *lp55xx_engine_attributes[] = { &dev_attr_select_engine.attr, &dev_attr_run_engine.attr, diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 212bdb216c9a..063d7392b6a2 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -89,6 +89,27 @@ static ssize_t store_engine##nr##_load(struct device *dev, \ store_load(nr) \ static LP55XX_DEV_ATTR_WO(engine##nr##_load, store_engine##nr##_load) +#define show_fader(nr) \ +static ssize_t show_master_fader##nr(struct device *dev, \ + struct device_attribute *attr, \ + char *buf) \ +{ \ + return lp55xx_show_master_fader(dev, attr, buf, nr); \ +} + +#define store_fader(nr) \ +static ssize_t store_master_fader##nr(struct device *dev, \ + struct device_attribute *attr, \ + const char *buf, size_t len) \ +{ \ + return lp55xx_store_master_fader(dev, attr, buf, len, nr); \ +} + +#define LP55XX_DEV_ATTR_MASTER_FADER(nr) \ + show_fader(nr) \ + store_fader(nr) \ + static LP55XX_DEV_ATTR_RW(master_fader##nr, show_master_fader##nr, store_master_fader##nr) + struct lp55xx_led; struct lp55xx_chip; @@ -116,6 +137,8 @@ struct lp55xx_reg { * @prog_mem_base : Chip specific base reg address for chip SMEM programming * @reg_led_pwm_base : Chip specific base reg address for LED PWM conf * @reg_led_current_base : Chip specific base reg address for LED current conf + * @reg_master_fader_base : Chip specific base reg address for master fader base + * @reg_led_ctrl_base : Chip specific base reg address for LED ctrl base * @pages_per_engine : Assigned pages for each engine * (if not set chip doesn't support pages) * @max_channel : Maximum number of channels @@ -136,6 +159,8 @@ struct lp55xx_device_config { const struct lp55xx_reg prog_mem_base; const struct lp55xx_reg reg_led_pwm_base; const struct lp55xx_reg reg_led_current_base; + const struct lp55xx_reg reg_master_fader_base; + const struct lp55xx_reg reg_led_ctrl_base; const int pages_per_engine; const int max_channel; @@ -257,5 +282,17 @@ extern ssize_t lp55xx_show_engine_leds(struct device *dev, extern ssize_t lp55xx_store_engine_leds(struct device *dev, struct device_attribute *attr, const char *buf, size_t len, int nr); +extern ssize_t lp55xx_show_master_fader(struct device *dev, + struct device_attribute *attr, + char *buf, int nr); +extern ssize_t lp55xx_store_master_fader(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int nr); +extern ssize_t lp55xx_show_master_fader_leds(struct device *dev, + struct device_attribute *attr, + char *buf); +extern ssize_t lp55xx_store_master_fader_leds(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len); #endif /* _LEDS_LP55XX_COMMON_H */ From patchwork Sun Jun 16 21:52: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: 804687 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.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 74F2A13B286; Sun, 16 Jun 2024 21:56:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574969; cv=none; b=JGKH2a34xEHbC8u1JYSWeoeQAwXYfabaDL4HEVlHFPsgy2dQ1RkXpDkOVbNqV3Wusfgfz+AHrGjupt2w8bKvgJwcV3uDtavRelXKIOvro/ZMJQixj90Op+6heQqw9EWESD5Vzd8VPtphWfRPyLmiHnaQGQDtSsZX5YOiQ4YiSYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574969; c=relaxed/simple; bh=LonxFkH0V4IOHqEQzVqa6HM0cP4Auu668cvEJc/7inw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DR7C2X+jYTEAlIj70OuCvGV0e6NiG8ziJ7Co5Y1tRg+4Rm7VqrtaWnoY6X3Ox0GASfzh3aEHretvD36AvIx4+QZUJfDEANXngTY0kRyQ6fPJQ9gdnayVnkRFRMJEUUH0f6bNWKh7rfft45CWsOWGj1cDmWsS8bhJTYoz7t901V4= 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=OD8fCRSD; arc=none smtp.client-ip=209.85.221.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="OD8fCRSD" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3608e6d14b6so806774f8f.0; Sun, 16 Jun 2024 14:56:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574966; x=1719179766; 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=Ryp4FYkpPGDa+jVapaf05jxp9BKNLD0q4vcW+Q2o9Wc=; b=OD8fCRSDiR3Vi0f4tBiqqeKyfIIhQomsWlTKSjIVhFrW3EfPFhE899XQMfNgD/jPzC yOGXAVu5Q52TxNJ1cgrozfvgq5H1C5oLS5aAsajvjCPXT0N75ogGtLikqZHlBwA3rOez ljynsS1QpF/anzpam1rhYxCctszOpxfoq5LUPeBaHSaHR6FEi5aT/RwnI/z9IVnZ11lr NRzK3GLe2LSyVr1Hfux+/3Z0s0uCN/YGlJJYjDjkc2GY9Rh/rNbxL5IpeGEnfSGNddzr WM/jN6e/jT7QfnOYB0i5QC5TnHUcl4mk3dU9L0egfLrMUz8279WX/lN+Z0OBHRruP6vt RDBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574966; x=1719179766; 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=Ryp4FYkpPGDa+jVapaf05jxp9BKNLD0q4vcW+Q2o9Wc=; b=xTA/0vbAOG3KC4xctavvSieZGdT+sf3yJFrJaNuBwi9/NxyMzbWzrmyOhIHS+s+xmd Gy00PY2qHXA48jsBhJ7H06B7dsQZcIz4mDEyHSInLoXQpavm9ZTLA8zsrBw3nUR2+hqu FjqV4Cp/G4ypOxjV+hCIIEnRSrCh05UK4RGbERfxBpEVoRlw2MM3qAw9LewV+IlWLvoP fJ20Dqdck6XckxV/EZbHqtxeb6PPJCEfNyyfB1pFh9gWJM90Bj3wS8icquTiQcR4wpQK RxCLPcvJwb5TqgcT4Owo9B3Ek3cDo503f1lYe/YLsoBfATM250Hztn2aHivE7dKKjEY6 XL4Q== X-Forwarded-Encrypted: i=1; AJvYcCXaMs8P1HluK7CLKDOT3R1OJhW9Xh6K+42mFMKqV5oC6Kf7XUSayqzHagxT7CSzIvy+Fn3tJsW4SZIqDIBORYHdVDuRGdX2RsO9yeG0QeY+FloJb0T4EuydeDvncw1YwainzwrHcPxRvVVYCjKnRIZjQrZLVLAQI4RPIbHicPz0yeiO45M= X-Gm-Message-State: AOJu0Yw2ChWeKsk7iL5i9B4vhEw9DG5yakLTpHAm4WcKXLy3zFSqZae3 zfhWM2XlkQK7xKedl8g6sCUWOGS8pMGM+1BklMTocW0GlDH/c4Ca9lJunw== X-Google-Smtp-Source: AGHT+IGlWxfUQqryeTKs/UKTuudEVDA0K4Ugx6f7fU01kDvjMlzlzweZVyQFD33iki78O+LQpZ0xxQ== X-Received: by 2002:a05:6000:bcf:b0:360:86ad:7a6f with SMTP id ffacd0b85a97d-36086ad7acamr4741742f8f.48.1718574965766; Sun, 16 Jun 2024 14:56:05 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36075104b74sm10362879f8f.107.2024.06.16.14.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:56:05 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v6 18/20] leds: leds-lp55xx: support ENGINE program up to 128 bytes Date: Sun, 16 Jun 2024 23:52:17 +0200 Message-ID: <20240616215226.2112-19-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some LED chip supports up to 16 pages and with some magic they can be divided in 4 page for each ENGINE + 1 for each MUX. Following this we can support bigger programs up to 128 bytes. Rework the update_program_memory function to support program of multiple pages instead of hardcoding it to one page per programs. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5523.c | 5 ++- drivers/leds/leds-lp5562.c | 7 ++-- drivers/leds/leds-lp55xx-common.c | 54 ++++++++++++++++++++++++------- drivers/leds/leds-lp55xx-common.h | 2 ++ 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 6f25a6c32869..1d00c6cc4174 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -21,7 +21,6 @@ #include "leds-lp55xx-common.h" -#define LP5523_PROGRAM_LENGTH 32 /* bytes */ /* Memory is used like this: * 0x00 engine 1 program * 0x10 engine 2 program @@ -172,7 +171,7 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) int ret; u8 status; /* one pattern per engine setting LED MUX start and stop addresses */ - static const u8 pattern[][LP5523_PROGRAM_LENGTH] = { + static const u8 pattern[][LP55xx_BYTES_PER_PAGE] = { { 0x9c, 0x30, 0x9c, 0xb0, 0x9d, 0x80, 0xd8, 0x00, 0}, { 0x9c, 0x40, 0x9c, 0xc0, 0x9d, 0x80, 0xd8, 0x00, 0}, { 0x9c, 0x50, 0x9c, 0xd0, 0x9d, 0x80, 0xd8, 0x00, 0}, @@ -196,7 +195,7 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) chip->engine_idx = i; lp55xx_load_engine(chip); - for (j = 0; j < LP5523_PROGRAM_LENGTH; j++) { + for (j = 0; j < LP55xx_BYTES_PER_PAGE; j++) { ret = lp55xx_write(chip, LP5523_REG_PROG_MEM + j, pattern[i - 1][j]); if (ret) diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index e50b68c9ccf3..109162f1720f 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -19,7 +19,6 @@ #include "leds-lp55xx-common.h" -#define LP5562_PROGRAM_LENGTH 32 #define LP5562_MAX_LEDS 4 /* ENABLE Register 00h */ @@ -212,9 +211,9 @@ static void lp5562_write_program_memory(struct lp55xx_chip *chip, /* check the size of program count */ static inline bool _is_pc_overflow(struct lp55xx_predef_pattern *ptn) { - return ptn->size_r >= LP5562_PROGRAM_LENGTH || - ptn->size_g >= LP5562_PROGRAM_LENGTH || - ptn->size_b >= LP5562_PROGRAM_LENGTH; + return ptn->size_r >= LP55xx_BYTES_PER_PAGE || + ptn->size_g >= LP55xx_BYTES_PER_PAGE || + ptn->size_b >= LP55xx_BYTES_PER_PAGE; } static int lp5562_run_predef_led_pattern(struct lp55xx_chip *chip, int mode) diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 62f5d6e8087c..04c713e7fb00 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 @@ -174,12 +175,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]; @@ -208,12 +213,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; @@ -226,13 +239,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; @@ -1283,7 +1302,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); @@ -1307,6 +1326,17 @@ int lp55xx_probe(struct i2c_client *client) } } + /* Validate max program page */ + program_length = LP55xx_BYTES_PER_PAGE; + if (chip->cfg->pages_per_engine) + program_length *= chip->cfg->pages_per_engine; + + /* support a max of 128bytes */ + if (program_length > LP55xx_MAX_PROGRAM_LENGTH) { + dev_err(&client->dev, "invalid pages_per_engine configured\n"); + return -EINVAL; + } + led = devm_kcalloc(&client->dev, pdata->num_channels, sizeof(*led), GFP_KERNEL); if (!led) diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 063d7392b6a2..5e1f7fea5985 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -14,6 +14,8 @@ #include +#define LP55xx_BYTES_PER_PAGE 32 /* bytes */ + enum lp55xx_engine_index { LP55XX_ENGINE_INVALID, LP55XX_ENGINE_1, From patchwork Sun Jun 16 21:52: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: 805039 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 756B513B5B5; Sun, 16 Jun 2024 21:56:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574970; cv=none; b=WNbWtSPOMjPcjAOC4ggHEnkr907Y+jSRzgGsZELG03+08KMfIKchjXD7CP99Ja3RRl9Wk2f8xomBTKuwcfZ5GVjTnAMGkgYYUJ9bzwMEfcqBjefjQb9LTuQerk/cqiwyUZAXeyT9BWXgwUYUYNbZpFOBRCwqBuVkQuZrBFU5Q4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574970; c=relaxed/simple; bh=Qri5xysaOutaV7cRmfiajw/hUm4xS4gzT2WmqGJ6O6I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jefg3IHQEpxwV4DmTUhxdOPpOrXZixKtshyTumKP6PAblJ1p1n8QN3vzQfvUbmPODCcKacFO9OIO+EkGt6QujJzRT8Uo3i4OFIzWTE2q4vZ1VP16sF9Qkgw3G7env7W5P8ut4iwNDb0/Hr55GEj3/amxigbxKhPxC+MXXx/y8pg= 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=UI8/EfOl; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UI8/EfOl" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-35f236a563cso3100925f8f.2; Sun, 16 Jun 2024 14:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574967; x=1719179767; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6ZO2jSTOjjW2TJhM4hgpkZ9GfcYTJ+1yDgbg82D4U2A=; b=UI8/EfOlAFySVBQEJKF735FO6LruumMNxqOmOurYYPKIR2UEuiBTxac3WWvj0ony7W srR/MrhsgXqeuCdp4pCrkLue+LLxnuVloGNud1Bo0frMDVso55XAowCx4AYsuJZ5hPDT 3NUhE6K7STVtuT3s7IH3ZltIP/oVfdAClCeoq9ZTPLY7TwkUuxVHPuULHwl2SjS4e/lW DfbIQS+rodhr6Ij4gDkMLNU4PFQpjbkd2j8kBNnRQkqaq8QYKtE7JnngPCDm3xv+aD+l o0BdAyj4xS9kr3xdBuh8fzOMABtmHEwRHp4AKuhIfvkn8nXyY9RnrNjAYpW772KwJ8Gi LyBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574967; x=1719179767; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6ZO2jSTOjjW2TJhM4hgpkZ9GfcYTJ+1yDgbg82D4U2A=; b=pF0HEvxwHSOQaFAjmYi+IkPuutq3woBsf/MykZtCJWCgBjwdeOlbbON0dd/NHGUtl8 UHxxN8gKcCdDS7p7zxyYC/z0wzyY1RUTX8yX0ezDyDTVZ/kDa7BQ4PkMlIumFj7XugcY 9sM0zkXi4kNsUGZEM87q5FMI/nGvrUskP74p4ix5Q5e4M6WfA54MR/Fheb3232Bjcc2A jB9dAs+jNFcRmY2HHfky5ycANWwD0wykMf2xW1DZd8M7N0cLWyvyH+w1qE14xNdwMfp7 dufb/VWEiC5itQiDL0EFVcSDp/DWQI5GaWGFxD+OLsPMpBQFd5N/xiMusutKqaT3MJw8 axmw== X-Forwarded-Encrypted: i=1; AJvYcCVlH4Rk0xsY0VEbPehZaqINzQHfq4tPaXZeU2NVp24WHJh5Jzrhyc1yMvme9/qYA5/S8lAs/ZYWwItfY4BnUh+ZiRQeVYriSIekbD3voQWDx8IuEEAAPPjHcKkigBRi/13gvL4BTkzIqTe5LYOroxI+nw4xdY46FEVIyU/d/FoScjnr5Z4= X-Gm-Message-State: AOJu0YyYTLSpBAqS0zJAE8j4fvJ+KWJelYRXzFh/zgcc267CsDjD8Yaj eGBCO2FMg8X64hzxsVG4J/5xbrDSk/xUaikEvlajYg/Hu9OUaaEx X-Google-Smtp-Source: AGHT+IHAFj5gRKjdBtB+Bnd+nwCZgAD0ffVEVs45lOY0jlsiu/eVDsT06IspppH/RWvxNXW5Zr21eA== X-Received: by 2002:adf:f6cc:0:b0:35f:1f28:2ec9 with SMTP id ffacd0b85a97d-3607a784494mr4992853f8f.70.1718574966782; Sun, 16 Jun 2024 14:56:06 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36075104b74sm10362879f8f.107.2024.06.16.14.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:56:06 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v6 19/20] leds: leds-lp55xx: drop deprecated defines Date: Sun, 16 Jun 2024 23:52:18 +0200 Message-ID: <20240616215226.2112-20-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Drop deprecated defines not used anymore as the related function got moved to lp55xx-common. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 24 -------------------- drivers/leds/leds-lp5523.c | 46 -------------------------------------- drivers/leds/leds-lp5562.c | 15 ------------- drivers/leds/leds-lp8501.c | 31 ------------------------- 4 files changed, 116 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 519e7627ac22..de0f8ea48eba 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -21,7 +21,6 @@ #include "leds-lp55xx-common.h" -#define LP5521_PROGRAM_LENGTH 32 #define LP5521_MAX_LEDS 3 #define LP5521_CMD_DIRECT 0x3F @@ -73,29 +72,6 @@ /* Reset register value */ #define LP5521_RESET 0xFF -/* Program Memory Operations */ -#define LP5521_MODE_R_M 0x30 /* Operation Mode Register */ -#define LP5521_MODE_G_M 0x0C -#define LP5521_MODE_B_M 0x03 -#define LP5521_LOAD_R 0x10 -#define LP5521_LOAD_G 0x04 -#define LP5521_LOAD_B 0x01 - -#define LP5521_R_IS_LOADING(mode) \ - ((mode & LP5521_MODE_R_M) == LP5521_LOAD_R) -#define LP5521_G_IS_LOADING(mode) \ - ((mode & LP5521_MODE_G_M) == LP5521_LOAD_G) -#define LP5521_B_IS_LOADING(mode) \ - ((mode & LP5521_MODE_B_M) == LP5521_LOAD_B) - -#define LP5521_EXEC_R_M 0x30 /* Enable Register */ -#define LP5521_EXEC_G_M 0x0C -#define LP5521_EXEC_B_M 0x03 -#define LP5521_EXEC_M 0x3F -#define LP5521_RUN_R 0x20 -#define LP5521_RUN_G 0x08 -#define LP5521_RUN_B 0x02 - static inline void lp5521_wait_opmode_done(void) { /* operation mode change needs to be longer than 153 us */ diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 1d00c6cc4174..eb686240f097 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -73,54 +73,8 @@ #define LP5523_EXT_CLK_USED 0x08 #define LP5523_ENG_STATUS_MASK 0x07 -#define LP5523_FADER_MAPPING_MASK 0xC0 -#define LP5523_FADER_MAPPING_SHIFT 6 - -/* Memory Page Selection */ -#define LP5523_PAGE_ENG1 0 -#define LP5523_PAGE_ENG2 1 -#define LP5523_PAGE_ENG3 2 -#define LP5523_PAGE_MUX1 3 -#define LP5523_PAGE_MUX2 4 -#define LP5523_PAGE_MUX3 5 - -/* Program Memory Operations */ -#define LP5523_MODE_ENG1_M 0x30 /* Operation Mode Register */ -#define LP5523_MODE_ENG2_M 0x0C -#define LP5523_MODE_ENG3_M 0x03 -#define LP5523_LOAD_ENG1 0x10 -#define LP5523_LOAD_ENG2 0x04 -#define LP5523_LOAD_ENG3 0x01 - -#define LP5523_ENG1_IS_LOADING(mode) \ - ((mode & LP5523_MODE_ENG1_M) == LP5523_LOAD_ENG1) -#define LP5523_ENG2_IS_LOADING(mode) \ - ((mode & LP5523_MODE_ENG2_M) == LP5523_LOAD_ENG2) -#define LP5523_ENG3_IS_LOADING(mode) \ - ((mode & LP5523_MODE_ENG3_M) == LP5523_LOAD_ENG3) - -#define LP5523_EXEC_ENG1_M 0x30 /* Enable Register */ -#define LP5523_EXEC_ENG2_M 0x0C -#define LP5523_EXEC_ENG3_M 0x03 -#define LP5523_EXEC_M 0x3F -#define LP5523_RUN_ENG1 0x20 -#define LP5523_RUN_ENG2 0x08 -#define LP5523_RUN_ENG3 0x02 - -#define LED_ACTIVE(mux, led) (!!(mux & (0x0001 << led))) - -enum lp5523_chip_id { - LP5523, - LP55231, -}; - static int lp5523_init_program_engine(struct lp55xx_chip *chip); -static inline void lp5523_wait_opmode_done(void) -{ - usleep_range(1000, 2000); -} - static int lp5523_post_init_device(struct lp55xx_chip *chip) { int ret; diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index 109162f1720f..6ba5dbb9cace 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -37,21 +37,6 @@ /* OPMODE Register 01h */ #define LP5562_REG_OP_MODE 0x01 -#define LP5562_MODE_ENG1_M 0x30 -#define LP5562_MODE_ENG2_M 0x0C -#define LP5562_MODE_ENG3_M 0x03 -#define LP5562_LOAD_ENG1 0x10 -#define LP5562_LOAD_ENG2 0x04 -#define LP5562_LOAD_ENG3 0x01 -#define LP5562_RUN_ENG1 0x20 -#define LP5562_RUN_ENG2 0x08 -#define LP5562_RUN_ENG3 0x02 -#define LP5562_ENG1_IS_LOADING(mode) \ - ((mode & LP5562_MODE_ENG1_M) == LP5562_LOAD_ENG1) -#define LP5562_ENG2_IS_LOADING(mode) \ - ((mode & LP5562_MODE_ENG2_M) == LP5562_LOAD_ENG2) -#define LP5562_ENG3_IS_LOADING(mode) \ - ((mode & LP5562_MODE_ENG3_M) == LP5562_LOAD_ENG3) /* BRIGHTNESS Registers */ #define LP5562_REG_R_PWM 0x04 diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c index 1fb876f64cb7..ee4ff4586bc0 100644 --- a/drivers/leds/leds-lp8501.c +++ b/drivers/leds/leds-lp8501.c @@ -20,28 +20,14 @@ #include "leds-lp55xx-common.h" -#define LP8501_PROGRAM_LENGTH 32 #define LP8501_PAGES_PER_ENGINE 1 #define LP8501_MAX_LEDS 9 /* Registers */ #define LP8501_REG_ENABLE 0x00 #define LP8501_ENABLE BIT(6) -#define LP8501_EXEC_M 0x3F -#define LP8501_EXEC_ENG1_M 0x30 -#define LP8501_EXEC_ENG2_M 0x0C -#define LP8501_EXEC_ENG3_M 0x03 -#define LP8501_RUN_ENG1 0x20 -#define LP8501_RUN_ENG2 0x08 -#define LP8501_RUN_ENG3 0x02 #define LP8501_REG_OP_MODE 0x01 -#define LP8501_MODE_ENG1_M 0x30 -#define LP8501_MODE_ENG2_M 0x0C -#define LP8501_MODE_ENG3_M 0x03 -#define LP8501_LOAD_ENG1 0x10 -#define LP8501_LOAD_ENG2 0x04 -#define LP8501_LOAD_ENG3 0x01 #define LP8501_REG_PWR_CONFIG 0x05 #define LP8501_PWR_CONFIG_M 0x03 @@ -65,25 +51,8 @@ #define LP8501_REG_RESET 0x3D #define LP8501_RESET 0xFF -#define LP8501_REG_PROG_PAGE_SEL 0x4F -#define LP8501_PAGE_ENG1 0 -#define LP8501_PAGE_ENG2 1 -#define LP8501_PAGE_ENG3 2 - #define LP8501_REG_PROG_MEM 0x50 -#define LP8501_ENG1_IS_LOADING(mode) \ - ((mode & LP8501_MODE_ENG1_M) == LP8501_LOAD_ENG1) -#define LP8501_ENG2_IS_LOADING(mode) \ - ((mode & LP8501_MODE_ENG2_M) == LP8501_LOAD_ENG2) -#define LP8501_ENG3_IS_LOADING(mode) \ - ((mode & LP8501_MODE_ENG3_M) == LP8501_LOAD_ENG3) - -static inline void lp8501_wait_opmode_done(void) -{ - usleep_range(1000, 2000); -} - static int lp8501_post_init_device(struct lp55xx_chip *chip) { int ret; From patchwork Sun Jun 16 21:52: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: 804686 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 CAA7213C3E0; Sun, 16 Jun 2024 21:56:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574973; cv=none; b=HpY4rxGhHz39f7AxjhArcHbeR4nN+d+qrjz7+XE77JWMiuaE9xZReLwfrjhn17dN1aI4cjNrYFqTsLH5xlyT6y47rEUqp3M9liBBNfOSd20MgmayyB39Fy0Hl0HkAcUlCjPJV1ymTyQpvtmxV3NGgHvH6WwgnrBj2h2UcDTTJ8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574973; c=relaxed/simple; bh=ku+VGfnNI34F254MFdUC0xDb4Yx+yRR3yHZAkkb9RSw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=neuXaMsrykemDIAEkGqWiWI00oWhGvNt3gf+EjYkC0oTfmLbs+5Bxsv4R/cBRbAsBZDV4uADrKTTMGh1/uS+JhgD8Kvj+maDIbPSvzXxUmTCD24Y74veolirCrkWSrbUYnZzRWqzwdnMbUkvTLNBKRql4RbqAtFxBIZyNfQXps8= 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=Ro0K+AjK; 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="Ro0K+AjK" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-35f223e7691so2470201f8f.1; Sun, 16 Jun 2024 14:56:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574968; x=1719179768; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eUfgJaiAMs8UzsHkdvv07vuPTP2fZMr9yKyEFTSMlvM=; b=Ro0K+AjK7DMRN0MAsrB1jw85CiZmcF2pjFbbDJqhfVYXi4OOmU9LAGjUzY0R7O9w/4 Gyaa9/IvuHMnosJbZ/jCSg6PSLNe6ZkkrpnWgZSDX2R0khgrdwpsjnppwA/2Hx7vDwPV /pv3p7Xhg8gMF4dmL91zH+JcGW+L+fmMoNABTjix5KjWgzkmXbXFWnd6bYVE3z4YsLvf p0yqLrep8PeRX6gBiToXJctO5csaQM1IN7+qT4C9C5wVg8omdjfNmzmZqbNnq/t82evT uHrGqvi33L/e74IpijR7BBhmWSp3vdZqOgnnxht/ZvGoNwcCbwI/ymIKjgCLRY1m1ctP py7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574968; x=1719179768; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eUfgJaiAMs8UzsHkdvv07vuPTP2fZMr9yKyEFTSMlvM=; b=i9hkaYj5akXxp5huXjKs6/vGrfT4B3jIDzhP7dX29YWDJ3zQpD4TjdvUGROsrSI5nk 2uHy0GZtxg/eObSSlOKCDlwfH29sHmChGDakx2C0JgSiv7q0h8uHfu2doudlSMpCt1FJ NOpYD3FAo5vkG6fHstvQTrBvPJ8djlTJGp4NX3lCr+nA/qoPEuOokm8RFBQdWg3Q2/Dj p2GWR63CzTfA2S5Tbv9+g0vkylXFx4ZYelFAKEFO+ffjz27KOCD/0v2FKugipI/XcToa qtvmyQEQF1dEepAN6EJaQMOwOiL1WVziGVskqRMhWgWODvz7gygcipLiR+NNM6yyD9Se qTGw== X-Forwarded-Encrypted: i=1; AJvYcCXuTk7h9pdf1NgpbbAWBDamjcV4GtHGtxPrUtwTD2WBOYeI2ATFudw7KcIBpnbhgrIRv93fhVmACX/pMifEJVimJcZmtDDkT/E8RtQyG9ywSBa80hKafQRJ5lIwNb/JlwDjWXSlGyvSS4YAuywNB6cUwpEA1fm+ePfOeehJNG22yUwDgAc= X-Gm-Message-State: AOJu0Yzl5W/XjqOnP5GTDCR3nXZKOI2QTxa10j3EKmX7xZ2h6BtFdZb/ CzIOsnHenk3HcpGsA7MNZHWOBKvU2udbLPBR+UmilvwbkOosNCcFiUcNng== X-Google-Smtp-Source: AGHT+IF1GruyNijkxTuy4mGgQEaXC0DkFPBfwkUXT4SY3dAJAqINo/KhTc2ykIoTeDsW3IwPQ/P8TA== X-Received: by 2002:a5d:598a:0:b0:360:7dbf:d3e with SMTP id ffacd0b85a97d-3607dbf0dfemr7328705f8f.7.1718574967951; Sun, 16 Jun 2024 14:56:07 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36075104b74sm10362879f8f.107.2024.06.16.14.56.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:56:07 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v6 20/20] leds: leds-lp5569: Add support for Texas Instruments LP5569 Date: Sun, 16 Jun 2024 23:52:19 +0200 Message-ID: <20240616215226.2112-21-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add support for Texas Instruments LP5569 LED driver. Texas Instruments LP5569 is 9 channels chip with programmable engines. It almost a copy of LP5523 with fundamental changes to regs order and regs content. Has difference in how the clock is handled and doesn't support detecting clock time automatically, different handling for selftest and different scheme for the status regs. LED chip supports ENGINE and MUX to group LED and run precompiled code with magic values to run patterns. This is loaded via the sysfs entry and it's passed as a string of ASCII HEX char. One some devices using this LED Controller (a NBG7815 Router) it was found loading big precompiled pattern with up to 96 bytes of code. To have support for this "extended" scenario, hardcode each engine to support 4 pages of precompiled pattern (128 bytes of code) and 1 page for each MUX. This gives plenty of space for any kind precompiled pattern keeping simple logic for page handling of each engine and mux. Signed-off-by: Christian Marangi --- drivers/leds/Kconfig | 16 +- drivers/leds/Makefile | 1 + drivers/leds/leds-lp5569.c | 542 +++++++++++++++++++++++++++++++++++++ 3 files changed, 556 insertions(+), 3 deletions(-) create mode 100644 drivers/leds/leds-lp5569.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 05e6af88b88c..b1d7d94317b3 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -414,7 +414,7 @@ config LEDS_LP50XX module will be called leds-lp50xx. config LEDS_LP55XX_COMMON - tristate "Common Driver for TI/National LP5521/5523/55231/5562/8501" + tristate "Common Driver for TI/National LP5521/5523/55231/5562/5569/8501" depends on LEDS_CLASS depends on LEDS_CLASS_MULTICOLOR depends on OF @@ -422,8 +422,8 @@ config LEDS_LP55XX_COMMON select FW_LOADER select FW_LOADER_USER_HELPER help - This option supports common operations for LP5521/5523/55231/5562/8501 - devices. + This option supports common operations for LP5521/5523/55231/5562/5569/ + 8501 devices. config LEDS_LP5521 tristate "LED Support for N.S. LP5521 LED driver chip" @@ -456,6 +456,16 @@ config LEDS_LP5562 Driver provides direct control via LED class and interface for programming the engines. +config LEDS_LP5569 + tristate "LED Support for TI LP5569 LED driver chip" + depends on LEDS_CLASS && I2C + depends on LEDS_LP55XX_COMMON + help + If you say yes here you get support for TI LP5569 LED driver. + It is 9 channels chip with programmable engines. + Driver provides direct control via LED class and interface for + programming the engines. + config LEDS_LP8501 tristate "LED Support for TI LP8501 LED driver chip" depends on LEDS_CLASS && I2C diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index effdfc6f1e95..ad21941efa19 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -51,6 +51,7 @@ obj-$(CONFIG_LEDS_LP50XX) += leds-lp50xx.o obj-$(CONFIG_LEDS_LP5521) += leds-lp5521.o obj-$(CONFIG_LEDS_LP5523) += leds-lp5523.o obj-$(CONFIG_LEDS_LP5562) += leds-lp5562.o +obj-$(CONFIG_LEDS_LP5569) += leds-lp5569.o obj-$(CONFIG_LEDS_LP55XX_COMMON) += leds-lp55xx-common.o obj-$(CONFIG_LEDS_LP8501) += leds-lp8501.o obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o diff --git a/drivers/leds/leds-lp5569.c b/drivers/leds/leds-lp5569.c new file mode 100644 index 000000000000..389ed307935c --- /dev/null +++ b/drivers/leds/leds-lp5569.c @@ -0,0 +1,542 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024 Christian Marangi + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "leds-lp55xx-common.h" + +#define LP5569_MAX_LEDS 9 + +/* Memory is used like this: + * 0x00 engine 1 program (4 pages) + * 0x40 engine 2 program (4 pages) + * 0x80 engine 3 program (4 pages) + * 0xc0 engine 1 muxing info (1 page) + * 0xd0 engine 2 muxing info (1 page) + * 0xe0 engine 3 muxing info (1 page) + */ +#define LP5569_PAGES_PER_ENGINE 4 + +#define LP5569_REG_ENABLE 0x00 +#define LP5569_ENABLE BIT(6) + +#define LP5569_REG_EXEC_CTRL 0x01 +#define LP5569_MODE_ENG_SHIFT 2 + +#define LP5569_REG_OP_MODE 0x02 +#define LP5569_EXEC_ENG_SHIFT 2 + +#define LP5569_REG_ENABLE_LEDS_MSB 0x04 +#define LP5569_REG_ENABLE_LEDS_LSB 0x05 +#define LP5569_REG_LED_CTRL_BASE 0x07 +#define LP5569_FADER_MAPPING_MASK GENMASK(7, 5) +#define LP5569_REG_LED_PWM_BASE 0x16 +#define LP5569_REG_LED_CURRENT_BASE 0x22 +#define LP5569_REG_MISC 0x2F +#define LP5569_AUTO_INC BIT(6) +#define LP5569_PWR_SAVE BIT(5) +#define LP5569_CP_MODE_MASK GENMASK(4, 3) +#define LP5569_PWM_PWR_SAVE BIT(2) +#define LP5569_INTERNAL_CLK BIT(0) +#define LP5569_REG_MISC2 0x33 +#define LP5569_LED_SHORT_TEST BIT(4) +#define LP5569_LED_OPEN_TEST BIT(3) +#define LP5569_REG_STATUS 0x3C +#define LP5569_MASK_BUSY BIT(7) +#define LP5569_STARTUP_BUSY BIT(6) +#define LP5569_ENGINE_BUSY BIT(5) +#define LP5569_ENGINE1_INT BIT(2) +#define LP5569_ENGINE2_INT BIT(1) +#define LP5569_ENGINE3_INT BIT(0) +#define LP5569_ENG_STATUS_MASK (LP5569_ENGINE1_INT | LP5569_ENGINE2_INT | \ + LP5569_ENGINE3_INT) +#define LP5569_REG_IO_CONTROL 0x3D +#define LP5569_CLK_OUTPUT BIT(3) +#define LP5569_REG_RESET 0x3F +#define LP5569_RESET 0xFF +#define LP5569_REG_MASTER_FADER_BASE 0x46 +#define LP5569_REG_CH1_PROG_START 0x4B +#define LP5569_REG_CH2_PROG_START 0x4C +#define LP5569_REG_CH3_PROG_START 0x4D +#define LP5569_REG_PROG_PAGE_SEL 0x4F +#define LP5569_REG_PROG_MEM 0x50 +#define LP5569_REG_LED_FAULT1 0x81 +#define LP5569_LED_FAULT8 BIT(0) +#define LP5569_REG_LED_FAULT2 0x82 +#define LP5569_LED_FAULT7 BIT(7) +#define LP5569_LED_FAULT6 BIT(6) +#define LP5569_LED_FAULT5 BIT(5) +#define LP5569_LED_FAULT4 BIT(4) +#define LP5569_LED_FAULT3 BIT(3) +#define LP5569_LED_FAULT2 BIT(2) +#define LP5569_LED_FAULT1 BIT(1) +#define LP5569_LED_FAULT0 BIT(0) + +#define LP5569_ENG1_PROG_ADDR 0x0 +#define LP5569_ENG2_PROG_ADDR 0x40 +#define LP5569_ENG3_PROG_ADDR 0x80 +#define LP5569_ENG1_MUX_ADDR 0xc0 +#define LP5569_ENG2_MUX_ADDR 0xd0 +#define LP5569_ENG3_MUX_ADDR 0xe0 + +#define LEDn_STATUS_FAULT(n, status) ((status) >> (n) & BIT(0)) + +#define LP5569_DEFAULT_CONFIG \ + (LP5569_AUTO_INC | LP5569_PWR_SAVE | LP5569_PWM_PWR_SAVE) + +static void lp5569_run_engine(struct lp55xx_chip *chip, bool start) +{ + if (!start) { + lp55xx_stop_engine(chip); + lp55xx_turn_off_channels(chip); + return; + } + + lp55xx_run_engine_common(chip); +} + +static int lp5569_init_program_engine(struct lp55xx_chip *chip) +{ + int i; + int j; + int ret; + u8 status; + /* Precompiled pattern per ENGINE setting LED MUX start and stop addresses */ + static const u8 pattern[][LP55xx_BYTES_PER_PAGE] = { + { 0x9c, LP5569_ENG1_MUX_ADDR, 0x9c, 0xb0, 0x9d, 0x80, 0xd8, 0x00, 0}, + { 0x9c, LP5569_ENG2_MUX_ADDR, 0x9c, 0xc0, 0x9d, 0x80, 0xd8, 0x00, 0}, + { 0x9c, LP5569_ENG3_MUX_ADDR, 0x9c, 0xd0, 0x9d, 0x80, 0xd8, 0x00, 0}, + }; + + /* Setup each ENGINE program start address */ + ret = lp55xx_write(chip, LP5569_REG_CH1_PROG_START, LP5569_ENG1_PROG_ADDR); + if (ret) + return ret; + + ret = lp55xx_write(chip, LP5569_REG_CH2_PROG_START, LP5569_ENG2_PROG_ADDR); + if (ret) + return ret; + + ret = lp55xx_write(chip, LP5569_REG_CH3_PROG_START, LP5569_ENG3_PROG_ADDR); + if (ret) + return ret; + + /* Write precompiled pattern for LED MUX address space for each ENGINE */ + for (i = LP55XX_ENGINE_1; i <= LP55XX_ENGINE_3; i++) { + chip->engine_idx = i; + lp55xx_load_engine(chip); + + for (j = 0; j < LP55xx_BYTES_PER_PAGE; j++) { + ret = lp55xx_write(chip, LP5569_REG_PROG_MEM + j, + pattern[i - 1][j]); + if (ret) + goto out; + } + } + + lp5569_run_engine(chip, true); + + /* Let the programs run for couple of ms and check the engine status */ + usleep_range(3000, 6000); + lp55xx_read(chip, LP5569_REG_STATUS, &status); + status = FIELD_GET(LP5569_ENG_STATUS_MASK, status); + + if (status != LP5569_ENG_STATUS_MASK) { + dev_err(&chip->cl->dev, + "could not configure LED engine, status = 0x%.2x\n", + status); + ret = -EINVAL; + } + +out: + lp55xx_stop_all_engine(chip); + return ret; +} + +static int lp5569_post_init_device(struct lp55xx_chip *chip) +{ + int ret; + int val; + + ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE); + if (ret) + return ret; + + /* Chip startup time is 500 us, 1 - 2 ms gives some margin */ + usleep_range(1000, 2000); + + val = LP5569_DEFAULT_CONFIG; + val |= FIELD_PREP(LP5569_CP_MODE_MASK, chip->pdata->charge_pump_mode); + + if (chip->pdata->clock_mode == LP55XX_CLOCK_INT) { + ret = lp55xx_update_bits(chip, LP5569_REG_IO_CONTROL, + LP5569_CLK_OUTPUT, + LP5569_CLK_OUTPUT); + if (ret) + return ret; + + val |= LP5569_INTERNAL_CLK; + } + + ret = lp55xx_write(chip, LP5569_REG_MISC, val); + if (ret) + return ret; + + return lp5569_init_program_engine(chip); +} + +static ssize_t lp5569_led_open_test(struct lp55xx_led *led, char *buf) +{ + struct lp55xx_chip *chip = led->chip; + struct lp55xx_platform_data *pdata = chip->pdata; + bool leds_fault[LP5569_MAX_LEDS]; + struct lp55xx_led *led_tmp = led; + int i, ret, pos = 0; + u8 status; + + /* Set in STANDBY state */ + ret = lp55xx_write(chip, LP5569_REG_ENABLE, 0); + if (ret) + goto exit; + + /* Wait 1ms for device to enter STANDBY state */ + usleep_range(1000, 2000); + + /* Set Charge Pump to 1.5x */ + ret = lp55xx_update_bits(chip, LP5569_REG_MISC, + FIELD_PREP(LP5569_CP_MODE_MASK, LP55XX_CP_BOOST), + LP5569_CP_MODE_MASK); + if (ret) + goto exit; + + /* Enable LED Open Test */ + ret = lp55xx_update_bits(chip, LP5569_REG_MISC2, LP5569_LED_OPEN_TEST, + LP5569_LED_OPEN_TEST); + if (ret) + goto exit; + + /* Put Device in NORMAL state */ + ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE); + if (ret) + goto exit; + + /* Wait 500 us for device to enter NORMAL state */ + usleep_range(500, 750); + + /* Enable LED and set to 100% brightness */ + for (i = 0; i < pdata->num_channels; i++) { + ret = lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led_tmp->chan_nr, + LED_FULL); + if (ret) + goto exit; + + led_tmp++; + } + + /* Wait 500 us for device to fill status regs */ + usleep_range(500, 750); + + /* Parse status led fault 1 regs */ + ret = lp55xx_read(chip, LP5569_REG_LED_FAULT1, &status); + if (ret < 0) + goto exit; + + for (i = 0; i < 8; i++) + leds_fault[i] = !!((status >> i) & 0x1); + + /* Parse status led fault 2 regs */ + ret = lp55xx_read(chip, LP5569_REG_LED_FAULT2, &status); + if (ret < 0) + goto exit; + + for (i = 0; i < 1; i++) + leds_fault[i + 8] = !!((status >> i) & 0x1); + + /* Report LED fault */ + led_tmp = led; + for (i = 0; i < pdata->num_channels; i++) { + if (leds_fault[led_tmp->chan_nr]) + pos += sprintf(buf + pos, "LED %d OPEN FAIL\n", + led_tmp->chan_nr); + + led_tmp++; + } + + ret = pos; + +exit: + /* Disable LED Open Test */ + lp55xx_update_bits(chip, LP5569_REG_MISC2, LP5569_LED_OPEN_TEST, + 0); + + led_tmp = led; + for (i = 0; i < pdata->num_channels; i++) { + lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led_tmp->chan_nr, + 0); + + led_tmp++; + } + + return ret; +} + +static ssize_t lp5569_led_short_test(struct lp55xx_led *led, char *buf) +{ + struct lp55xx_chip *chip = led->chip; + struct lp55xx_platform_data *pdata = chip->pdata; + bool leds_fault[LP5569_MAX_LEDS]; + struct lp55xx_led *led_tmp = led; + int i, ret, pos = 0; + u8 status; + + /* Set in STANDBY state */ + ret = lp55xx_write(chip, LP5569_REG_ENABLE, 0); + if (ret) + goto exit; + + /* Wait 1ms for device to enter STANDBY state */ + usleep_range(1000, 2000); + + /* Set Charge Pump to 1x */ + ret = lp55xx_update_bits(chip, LP5569_REG_MISC, + FIELD_PREP(LP5569_CP_MODE_MASK, LP55XX_CP_BYPASS), + LP5569_CP_MODE_MASK); + if (ret) + goto exit; + + /* Enable LED and set to 100% brightness and current to 100% (25.5mA) */ + for (i = 0; i < pdata->num_channels; i++) { + ret = lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led_tmp->chan_nr, + LED_FULL); + if (ret) + goto exit; + + ret = lp55xx_write(chip, LP5569_REG_LED_CURRENT_BASE + led_tmp->chan_nr, + LED_FULL); + if (ret) + goto exit; + + led_tmp++; + } + + /* Put Device in NORMAL state */ + ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE); + if (ret) + goto exit; + + /* Wait 500 us for device to enter NORMAL state */ + usleep_range(500, 750); + + /* Enable LED Shorted Test */ + ret = lp55xx_update_bits(chip, LP5569_REG_MISC2, LP5569_LED_OPEN_TEST, + LP5569_LED_SHORT_TEST); + if (ret) + goto exit; + + /* Wait 500 us for device to fill status regs */ + usleep_range(500, 750); + + /* Parse status led fault 1 regs */ + ret = lp55xx_read(chip, LP5569_REG_LED_FAULT1, &status); + if (ret < 0) + goto exit; + + for (i = 0; i < 8; i++) + leds_fault[i] = !!LEDn_STATUS_FAULT(i, status); + + /* Parse status led fault 2 regs */ + ret = lp55xx_read(chip, LP5569_REG_LED_FAULT2, &status); + if (ret < 0) + goto exit; + + for (i = 0; i < 1; i++) + leds_fault[i + 8] = !!LEDn_STATUS_FAULT(i, status); + + /* Report LED fault */ + led_tmp = led; + for (i = 0; i < pdata->num_channels; i++) { + if (leds_fault[led_tmp->chan_nr]) + pos += sprintf(buf + pos, "LED %d SHORTED FAIL\n", + led_tmp->chan_nr); + + led_tmp++; + } + + ret = pos; + +exit: + /* Disable LED Shorted Test */ + lp55xx_update_bits(chip, LP5569_REG_MISC2, LP5569_LED_SHORT_TEST, + 0); + + led_tmp = led; + for (i = 0; i < pdata->num_channels; i++) { + lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led_tmp->chan_nr, + 0); + + led_tmp++; + } + + return ret; +} + +static ssize_t lp5569_selftest(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); + struct lp55xx_chip *chip = led->chip; + int i, pos = 0; + + mutex_lock(&chip->lock); + + /* Test LED Open */ + pos = lp5569_led_open_test(led, buf); + if (pos < 0) + goto fail; + + /* Test LED Shorted */ + pos = lp5569_led_short_test(led, buf); + if (pos < 0) + goto fail; + + for (i = 0; i < chip->pdata->num_channels; i++) { + /* Restore current */ + lp55xx_write(chip, LP5569_REG_LED_CURRENT_BASE + led->chan_nr, + led->led_current); + + /* Restore brightness */ + lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led->chan_nr, + led->brightness); + led++; + } + + if (pos == 0) + pos = sprintf(buf, "OK\n"); + goto release_lock; +fail: + pos = sprintf(buf, "FAIL\n"); + +release_lock: + mutex_unlock(&chip->lock); + + return pos; +} + +LP55XX_DEV_ATTR_ENGINE_MODE(1); +LP55XX_DEV_ATTR_ENGINE_MODE(2); +LP55XX_DEV_ATTR_ENGINE_MODE(3); +LP55XX_DEV_ATTR_ENGINE_LEDS(1); +LP55XX_DEV_ATTR_ENGINE_LEDS(2); +LP55XX_DEV_ATTR_ENGINE_LEDS(3); +LP55XX_DEV_ATTR_ENGINE_LOAD(1); +LP55XX_DEV_ATTR_ENGINE_LOAD(2); +LP55XX_DEV_ATTR_ENGINE_LOAD(3); +static LP55XX_DEV_ATTR_RO(selftest, lp5569_selftest); +LP55XX_DEV_ATTR_MASTER_FADER(1); +LP55XX_DEV_ATTR_MASTER_FADER(2); +LP55XX_DEV_ATTR_MASTER_FADER(3); +static LP55XX_DEV_ATTR_RW(master_fader_leds, lp55xx_show_master_fader_leds, + lp55xx_store_master_fader_leds); + +static struct attribute *lp5569_attributes[] = { + &dev_attr_engine1_mode.attr, + &dev_attr_engine2_mode.attr, + &dev_attr_engine3_mode.attr, + &dev_attr_engine1_load.attr, + &dev_attr_engine2_load.attr, + &dev_attr_engine3_load.attr, + &dev_attr_engine1_leds.attr, + &dev_attr_engine2_leds.attr, + &dev_attr_engine3_leds.attr, + &dev_attr_selftest.attr, + &dev_attr_master_fader1.attr, + &dev_attr_master_fader2.attr, + &dev_attr_master_fader3.attr, + &dev_attr_master_fader_leds.attr, + NULL, +}; + +static const struct attribute_group lp5569_group = { + .attrs = lp5569_attributes, +}; + +/* Chip specific configurations */ +static struct lp55xx_device_config lp5569_cfg = { + .reg_op_mode = { + .addr = LP5569_REG_OP_MODE, + .shift = LP5569_MODE_ENG_SHIFT, + }, + .reg_exec = { + .addr = LP5569_REG_EXEC_CTRL, + .shift = LP5569_EXEC_ENG_SHIFT, + }, + .reset = { + .addr = LP5569_REG_RESET, + .val = LP5569_RESET, + }, + .enable = { + .addr = LP5569_REG_ENABLE, + .val = LP5569_ENABLE, + }, + .prog_mem_base = { + .addr = LP5569_REG_PROG_MEM, + }, + .reg_led_pwm_base = { + .addr = LP5569_REG_LED_PWM_BASE, + }, + .reg_led_current_base = { + .addr = LP5569_REG_LED_CURRENT_BASE, + }, + .pages_per_engine = LP5569_PAGES_PER_ENGINE, + .max_channel = LP5569_MAX_LEDS, + .post_init_device = lp5569_post_init_device, + .brightness_fn = lp55xx_led_brightness, + .multicolor_brightness_fn = lp55xx_multicolor_brightness, + .set_led_current = lp55xx_set_led_current, + .firmware_cb = lp55xx_firmware_loaded_cb, + .run_engine = lp5569_run_engine, + .dev_attr_group = &lp5569_group, +}; + +static const struct i2c_device_id lp5569_id[] = { + { "lp5569", .driver_data = (kernel_ulong_t)&lp5569_cfg, }, + { } +}; + +MODULE_DEVICE_TABLE(i2c, lp5569_id); + +static const struct of_device_id of_lp5569_leds_match[] = { + { .compatible = "ti,lp5569", .data = &lp5569_cfg, }, + {}, +}; + +MODULE_DEVICE_TABLE(of, of_lp5569_leds_match); + +static struct i2c_driver lp5569_driver = { + .driver = { + .name = "lp5569x", + .of_match_table = of_lp5569_leds_match, + }, + .probe = lp55xx_probe, + .remove = lp55xx_remove, + .id_table = lp5569_id, +}; + +module_i2c_driver(lp5569_driver); + +MODULE_AUTHOR("Christian Marangi "); +MODULE_DESCRIPTION("LP5569 LED engine"); +MODULE_LICENSE("GPL");