From patchwork Thu Apr 28 09:32:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChiYuan Huang X-Patchwork-Id: 12830254 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 58CA6C433EF for ; Thu, 28 Apr 2022 09:33:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DKEDfHz/puvXdt5BZGko+7xpvvN7KKLT1GcgwddHUyM=; b=OYPUCUkUb2GVSn 7eqhyGEi2WS8iFHFC2rZCyCz8qIyhJfwXq65b+kcwUa8gE/0dK/i2asdVIV3suxhgLfJzMZojCajG qjhyF9UEKlUyZibEBVrn5R8ev5E+3THUfm9L8qJMnXazrNfTWx2WsdkQLVAIpKvI+sp6P7wKNv5mu qYNUGZhBPo+uDw6XGyiyl5kEcBwRKv6z9M1z7Ig8U65K9DVqUbr7N3xVfJn4saO3ziCergm8iBDW+ pTiSxj7ezh0kqYwshLcVGwEzjRx82cBeFP1vQmgIZ73fEobAcXfzimTC/OCIoZ4x2YllYNLVWe+ao OhBdPQy7uS9ipt/2ACUw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk0Wq-005k6K-Cj; Thu, 28 Apr 2022 09:33:40 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk0WR-005jxx-St; Thu, 28 Apr 2022 09:33:17 +0000 Received: by mail-pf1-x435.google.com with SMTP id j6so3744366pfe.13; Thu, 28 Apr 2022 02:33:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Jx2sI9U4OCn+w0obbX5GiL9CUWZWFJnR6/XlVL4TXok=; b=bFBvSiqIfUxsZ8Ums18LxH6niAvg0Lz5mTnbjPoz6e7cc3W40d5Td4P9r4NmpzYzlG pb2pvd/fXNxKbXjjuxJTRfqemXZc5KxQbMZ5Wuk+EUVJrFkJk3ha3u/vUTc8gcDH2ZH4 DYNBWeJ8rGROjMMEZ74Ps4VHWwPSQWgFFGQhUW73O+VsGZpTH8xrRumYjdv5aVujDovW zKdYJPsJ3gw/4mCZrUbNmmJy/mzwVjz8dWSQRaGHn6VmDpfh03IlvxgWESyWPR4FK9Lp 317ZFqDKgDGgi8ciEAnbSuQhGJ9IijVs0u6OI4FyqXw6w9ULSoYT0tsHNkCckiPlaBBO ED6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Jx2sI9U4OCn+w0obbX5GiL9CUWZWFJnR6/XlVL4TXok=; b=IRFKaQPINszb2srVQvrRZzMMPSHZXncQNu21mu+lJEoKiXuvZmVkZB+ZkVMiV4vxEQ gK1vMlFjKBE+3dIqrQ0XVwQybdDTbhC4j5bREmKtz7xdUN0SoIFrx0BtPpqDb4PUPpOe MB5VM1IboVcYpjw30Gf6PR8MWmlrZ5nmw/+/97IIT6ZJuYPzRZX1TuAVlYUdcZ2Yvxt1 MBfyJFUI/zRB9fHeUw3NuYGtSEY2TmYcjDnwkVRxL1e38kWzd5TJFL/eQFDqKK3fmxSd LHqqYMIUdrtW4SwR0QHfamz9lJ3fC3tftCUPCfeT94Laz6XnDAO8sKdmc0Tjoh3wM8fX 4tYw== X-Gm-Message-State: AOAM5316W66ntN3V/3iUFJrEnTPLIbqilvrG9W3gUOhVQ8Q0Yrc99ISt 6pmiZ597L5olMwYpYnEPkeM= X-Google-Smtp-Source: ABdhPJzT2s4BUbfVF0ibXJZuFaWAvgA8sAUtMX0axqPQQcd8lpcMQU7X+4fWs802ydw8Yj9CznwA5g== X-Received: by 2002:a63:8943:0:b0:3aa:f1ce:4f24 with SMTP id v64-20020a638943000000b003aaf1ce4f24mr22369940pgd.34.1651138393834; Thu, 28 Apr 2022 02:33:13 -0700 (PDT) Received: from localhost.localdomain ([2402:7500:569:2b1f:d169:337e:6359:8ff7]) by smtp.gmail.com with ESMTPSA id i66-20020a628745000000b0050d36a5fe70sm15457932pfe.127.2022.04.28.02.33.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Apr 2022 02:33:12 -0700 (PDT) From: cy_huang To: pavel@ucw.cz, matthias.bgg@gmail.com Cc: cy_huang@richtek.com, jacek.anaszewski@gmail.com, gene_chen@richtek.com, linux-leds@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] leds: flash: mt6360: Fix the wrong enable_reg in multicolor brightness set Date: Thu, 28 Apr 2022 17:32:42 +0800 Message-Id: <1651138365-17362-2-git-send-email-u0084500@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1651138365-17362-1-git-send-email-u0084500@gmail.com> References: <1651138365-17362-1-git-send-email-u0084500@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220428_023315_970019_6E356E69 X-CRM114-Status: GOOD ( 11.61 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: ChiYuan Huang Fix the wrong enable_reg in multicolor brightness set. Signed-off-by: ChiYuan Huang --- drivers/leds/flash/leds-mt6360.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/leds/flash/leds-mt6360.c b/drivers/leds/flash/leds-mt6360.c index e1066a5..712cd46 100644 --- a/drivers/leds/flash/leds-mt6360.c +++ b/drivers/leds/flash/leds-mt6360.c @@ -115,7 +115,8 @@ static int mt6360_mc_brightness_set(struct led_classdev *lcdev, struct mc_subled *subled = mccdev->subled_info + i; real_bright = min(lcdev->max_brightness, subled->brightness); - ret = regmap_update_bits(priv->regmap, MT6360_REG_ISNK(i), + ret = regmap_update_bits(priv->regmap, + MT6360_REG_ISNK(subled->channel), MT6360_ISNK_MASK, real_bright); if (ret) goto out; From patchwork Thu Apr 28 09:32:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChiYuan Huang X-Patchwork-Id: 12830272 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6CCF8C433EF for ; Thu, 28 Apr 2022 09:34:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zKYjd0dyCrEmRgxONpUvT+Xkif1YW2Ie5BucqWkgw2w=; b=zpVaSUZoT3KtGK AzvgalHga0dzcKlPscW8wkiXRWiLgyX/+m/Hvv3S1X6nK2/R1/TUnG4QakbaRhqH/2rmmU86xGljh bXozQTPTlgO34siXh5WFVvizvx0VTxh8knntFI2FFOXkSNa6NcyPjJnSIT4srLPjzizTVulVDV136 q6Ot5lnl0bssWC+pw5keuRii+JUxZSB2YpPRhs16kYXowvVmiikymsm+PalFmLljgwl33MsA6UD2G NPiWfCovY6e+z8SL2Mm9KGe4IZmZQHmsGJk51L/i5YSK6vGWhaIvyrwDc/ggPcdS4F39YQuoMaxyc p3LyntpGarQDMjscJz4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk0X6-005kCE-4g; Thu, 28 Apr 2022 09:33:56 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk0WX-005jzL-OZ; Thu, 28 Apr 2022 09:33:26 +0000 Received: by mail-pl1-x630.google.com with SMTP id u7so3827330plg.13; Thu, 28 Apr 2022 02:33:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NM66A5OAYldkjcIb7EpGVNaXhKoeVCq/L19afQaEiL8=; b=hh5ezwk8i9ar3NTDhQHy0zyGei9208iSfcYM4YKq7O7K0RrZv8nlLNVmZC5WZjFeyG wSX/vbgQt2Owd+lFxbpKWcSA8srI+fqG+qf+la3Z5DnRkViqZk9izZXHExD0DrFrdU6g znQ5hG8nP1Qm/IlUv5O9ZnAEjDc0HzgE7Joasu9VCfXtqikXU5Mf1J6AjzQuQCYMFEJX 8XnAzmx4tNgZn8QLBihX54lO8xfa9WhADOdlOAG/dWZIgCLDmQ7YEYe4LKRiFPa2NU6z rjv+mv8su9wKGjN9xhgry1eXts98AoZqtZSFfEafhAowpMyfOrW4ALy/NGCPxvkZWxoh 4Cfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NM66A5OAYldkjcIb7EpGVNaXhKoeVCq/L19afQaEiL8=; b=6yXwgwvh5nTMzo1QQWzB0a0YnWuRzcizNIgc7e/E1D5Dq5jAQZAf9pPrtIJ3X857c3 7mj5DpIL2c4keq/BpVQqtGbB5fH7hGr4xfKyN7s+JnJ6iB+kVBphpnzKESEfhc4ZlpMe Tm00eM6dMtDs4rXFMnb7abvS2n8JmQ9Bj7y7GhPCdJYoippnh9Z831vxX1YqQAtlpGQz jmjw9hW/jEH0z2Nsf1m4iQrdOrY7Hy8GIZkJRImlYwRYg/K9atl/pbLtLHfP0awdLqWu ECy0+zNHNPLPS/q3TSyrpKVY3Nm8sMPj4Q2p7rOHulNsOTSTW1la3jqyw0fdrgvbdQEz ku8Q== X-Gm-Message-State: AOAM533fF6sFLUrkz5yG7j+ojyXmnHS8vUA6jrTV5VA41lSB4KZ9c1ER tLF3IjOeBdgxLLe67kK2w74QuDOSYqI= X-Google-Smtp-Source: ABdhPJy/iXJqbVKjkw099C2uzmg24SKXb49S4CmFSCjXdPCaT9YW/nJ4DtvBfrGPZAG8YdZqZYDZvw== X-Received: by 2002:a17:902:8c81:b0:156:7fee:643b with SMTP id t1-20020a1709028c8100b001567fee643bmr32899635plo.59.1651138398072; Thu, 28 Apr 2022 02:33:18 -0700 (PDT) Received: from localhost.localdomain ([2402:7500:569:2b1f:d169:337e:6359:8ff7]) by smtp.gmail.com with ESMTPSA id i66-20020a628745000000b0050d36a5fe70sm15457932pfe.127.2022.04.28.02.33.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Apr 2022 02:33:17 -0700 (PDT) From: cy_huang To: pavel@ucw.cz, matthias.bgg@gmail.com Cc: cy_huang@richtek.com, jacek.anaszewski@gmail.com, gene_chen@richtek.com, linux-leds@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] leds: flash: mt6360: Remove unused dependency in Kconfig Date: Thu, 28 Apr 2022 17:32:43 +0800 Message-Id: <1651138365-17362-3-git-send-email-u0084500@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1651138365-17362-1-git-send-email-u0084500@gmail.com> References: <1651138365-17362-1-git-send-email-u0084500@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220428_023321_843022_624FE7E1 X-CRM114-Status: GOOD ( 11.11 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: ChiYuan Huang Kconfig already guarantee LED_CLASS_FLASH will be selected. Remove useless dependency for LEDS_CLASS/LEDS_CLASS_FLASH. Signed-off-by: ChiYuan Huang --- drivers/leds/flash/Kconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/leds/flash/Kconfig b/drivers/leds/flash/Kconfig index d3eb689..38b325c 100644 --- a/drivers/leds/flash/Kconfig +++ b/drivers/leds/flash/Kconfig @@ -50,8 +50,7 @@ config LEDS_MAX77693 config LEDS_MT6360 tristate "LED Support for Mediatek MT6360 PMIC" - depends on LEDS_CLASS && OF - depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH + depends on OF depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS depends on MFD_MT6360 From patchwork Thu Apr 28 09:32:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChiYuan Huang X-Patchwork-Id: 12830273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A26E8C433EF for ; Thu, 28 Apr 2022 09:34:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WP2W4A6FjJDrgZoIA/HQPDbYU/L7ygclkF2Kfxi21zc=; b=LORVyS3k/YJUA8 tYC5bi33UU1nsqvfOXbw0BnHNjcFUkGw4NAzdUDkiRDd4WTt2/JOd6un/q9NTv0nnYcsiTHK1RSMU pcH2AsHO0QpJFHYT1fEKg33sPHOzmXSMfPeWOGyfRJ/cXAHX5Kztz5BVJCxc/OliSK2J7kL/518QQ uWOv3DgCQBAYGMIwkLqz4l1j4ldE06aU/J+0XdC/HvJqXpZUrpnLRIKzFgt5F21apMFtSWO3YwUxH PkdZeM9pqKpmaxiAIKmlHjeWQzeLTy5/f+0yeer0EJagWSqVrY6e+k2OyTkl6zAaXeKG3ApxMNJbB +kAEr+14NMeZt7EFDCVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk0Xo-005kXr-Ai; Thu, 28 Apr 2022 09:34:40 +0000 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk0Wa-005k13-Pt; Thu, 28 Apr 2022 09:33:27 +0000 Received: by mail-pg1-x532.google.com with SMTP id q12so3509880pgj.13; Thu, 28 Apr 2022 02:33:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1AZOCN0gvek/FGxRO1VvIesAbLD/uY9lQokPwBAiQ2Q=; b=YEYbQR26QvFnDG1PF6w7QmYol2Q4GQydBVEBYqkJQSs++Okx23pEQjpCAt5udpWvGb dBTvY0C0tpTxrUH6R/rVogmdLJDwlNG/XqT51/lcIkfu9xBTInEARdPEYECYebAltRCF uXKK0TO3OPXz6RiAzb4NjEIuyn2222h/vJ52mccpd+O4COvwSAwKqJGUHuPRRXlj8F4f ofh+Y+/bUfNyOykSrDXX87I9SlaeReno5yJ8C+A8ITIWIQjUvnxhsyZ9eTg1dNcJoR1H TVeub9I20Rqm4QaTkw56oUBCe24BMGdOC16MQoe70pJo/dlg2wSmV9lfkCIMnh1HzaLb IxLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1AZOCN0gvek/FGxRO1VvIesAbLD/uY9lQokPwBAiQ2Q=; b=dfXWpwgXQOux9qt2GqFlKfubToldrZbOBAG749vK4rtuLtfoXyOWRFCe0b3LYNRMrY uoA2Vr1nDCrmqJH3/zfWLPhhiaHwnGlqlOM+UAFMwx+mZdGd/2sQSxSayiT5lxA2MEcI V/g6ZcW0TS0GZg9/VNQ7JV76uLy6cCHduwTwdk7AwiFfMxg5FfjlYSnX1fRcqTVtTPPh HcjZecYqqx1viCKnvus62g2ytGZA8xqKtqMqfRQi+GNwiOEjMu3FtrQx/zjR+SQJD9VQ QTKCDLQVU60mKsQQ46PD47eKQ1FpVB+sbtQA6EVDA0qZQashG/Y8NPkNUGmRu25hOOGy esdQ== X-Gm-Message-State: AOAM531BmG3Ixb6hrvepHK5/5dAqg5nRQOBU9OfApdz/tcvheHW+EEfk XMgEqQ4r3NxXfJsYVb/YAuY= X-Google-Smtp-Source: ABdhPJylt6gFnhP5FlWXUj5/mfYFMndmtRqiV4Nbt5NTYp3aJm4jKwrBC422Bj1EFurlkueUfKl/mg== X-Received: by 2002:a62:fb0e:0:b0:505:fd9e:9218 with SMTP id x14-20020a62fb0e000000b00505fd9e9218mr34800820pfm.78.1651138402659; Thu, 28 Apr 2022 02:33:22 -0700 (PDT) Received: from localhost.localdomain ([2402:7500:569:2b1f:d169:337e:6359:8ff7]) by smtp.gmail.com with ESMTPSA id i66-20020a628745000000b0050d36a5fe70sm15457932pfe.127.2022.04.28.02.33.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Apr 2022 02:33:22 -0700 (PDT) From: cy_huang To: pavel@ucw.cz, matthias.bgg@gmail.com Cc: cy_huang@richtek.com, jacek.anaszewski@gmail.com, gene_chen@richtek.com, linux-leds@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] leds: flash: mt6360: Add mt6360 isnk channel hardware timer dimming mode support Date: Thu, 28 Apr 2022 17:32:44 +0800 Message-Id: <1651138365-17362-4-git-send-email-u0084500@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1651138365-17362-1-git-send-email-u0084500@gmail.com> References: <1651138365-17362-1-git-send-email-u0084500@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220428_023324_935105_64CF33D5 X-CRM114-Status: GOOD ( 22.80 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: ChiYuan Huang Add mt6360 isnk channel hardware timer dimming mode support. Signed-off-by: ChiYuan Huang --- drivers/leds/flash/leds-mt6360.c | 209 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 203 insertions(+), 6 deletions(-) diff --git a/drivers/leds/flash/leds-mt6360.c b/drivers/leds/flash/leds-mt6360.c index 712cd46..8fe3dc4 100644 --- a/drivers/leds/flash/leds-mt6360.c +++ b/drivers/leds/flash/leds-mt6360.c @@ -24,9 +24,19 @@ enum { MT6360_MAX_LEDS }; +#define MT6360_ISNK_PWM_MODE 0 +#define MT6360_ISNK_CC_MODE 2 + #define MT6360_REG_RGBEN 0x380 #define MT6360_REG_ISNK(_led_no) (0x381 + (_led_no)) +#define MT6360_REG_DIM(_led_no) (0x385 + (_led_no)) +#define MT6360_REG_FREQ1 0x389 +#define MT6360_REG_FREQ2 0x38A #define MT6360_ISNK_ENMASK(_led_no) BIT(7 - (_led_no)) +#define MT6360_FREQ13_MASK GENMASK(7, 5) +#define MT6360_FREQ2_MASK GENMASK(4, 2) +#define MT6360_ISNK_MODE_MASK GENMASK(7, 6) +#define MT6360_ISNK_MODE_SHFT 6 #define MT6360_ISNK_MASK GENMASK(4, 0) #define MT6360_CHRINDSEL_MASK BIT(3) @@ -98,13 +108,128 @@ struct mt6360_priv { struct mt6360_led leds[]; }; +static int mt6360_get_selected_freq_duty(unsigned long on, unsigned long off, + unsigned int *fsel, unsigned int *dsel) +{ + static const unsigned int freq_ms[] = { 8000, 4000, 2000, 1000, + 500, 250, 8, 4 }; + unsigned int sum = on + off; + int i; + + /* Check if val is less than the smallest or larger then the largest */ + if (sum > freq_ms[0] || sum < freq_ms[ARRAY_SIZE(freq_ms) - 1]) + return -EINVAL; + + /* Find the frequency for less or equal one */ + for (i = 0; i < ARRAY_SIZE(freq_ms) - 1; i++) { + if (sum >= freq_ms[i]) + break; + } + + *fsel = i; + *dsel = on * 255 / sum; + return 0; +} + +static int mt6360_set_pwm_dimming_param(struct mt6360_priv *priv, + unsigned int led_no, unsigned int fsel, + unsigned int dsel) +{ + unsigned int freq_reg, freq_mask, freq_shift; + int ret; + + switch (led_no) { + case MT6360_LED_ISNK1: + freq_reg = MT6360_REG_FREQ1; + freq_mask = MT6360_FREQ13_MASK; + break; + case MT6360_LED_ISNK2: + freq_reg = MT6360_REG_FREQ1; + freq_mask = MT6360_FREQ2_MASK; + break; + case MT6360_LED_ISNK3: + freq_reg = MT6360_REG_FREQ2; + freq_mask = MT6360_FREQ13_MASK; + break; + default: + return -EINVAL; + } + + freq_shift = ffs(freq_mask) - 1; + + ret = regmap_update_bits(priv->regmap, freq_reg, freq_mask, + fsel << freq_shift); + if (ret) + return ret; + + return regmap_write(priv->regmap, MT6360_REG_DIM(led_no), dsel); +} + +static int mt6360_mc_blink_set(struct led_classdev *lcdev, unsigned long *don, + unsigned long *doff) +{ + struct led_classdev_mc *mccdev = lcdev_to_mccdev(lcdev); + struct mt6360_led *led = container_of(mccdev, struct mt6360_led, mc); + struct mt6360_priv *priv = led->priv; + unsigned int freq_sel, duty_sel; + u8 mc_reg[3]; + int i, ret; + + if (!*don && !*doff) + *don = *doff = 500; + + mutex_lock(&priv->lock); + + ret = regmap_raw_read(priv->regmap, MT6360_REG_ISNK(0), mc_reg, 3); + if (ret) + goto out; + + /* Configure all subleds to CC mode first */ + for (i = 0; i < mccdev->num_colors; i++) { + struct mc_subled *subled = mccdev->subled_info + i; + int ch_idx = subled->channel; + + mc_reg[ch_idx] &= ~MT6360_ISNK_MODE_MASK; + mc_reg[ch_idx] |= MT6360_ISNK_CC_MODE << MT6360_ISNK_MODE_SHFT; + } + + ret = regmap_raw_write(priv->regmap, MT6360_REG_ISNK(0), mc_reg, 3); + if (ret) + goto out; + + /* Get the desired selector for frequency and duty */ + ret = mt6360_get_selected_freq_duty(*don, *doff, &freq_sel, &duty_sel); + if (ret) + goto out; + + /* Configure all subleds dim freq/duty and change to PWM mode */ + for (i = 0; i < mccdev->num_colors; i++) { + struct mc_subled *subled = mccdev->subled_info + i; + int ch_idx = subled->channel; + + ret = mt6360_set_pwm_dimming_param(priv, ch_idx, freq_sel, + duty_sel); + if (ret) + goto out; + + mc_reg[ch_idx] &= ~MT6360_ISNK_MODE_MASK; + mc_reg[ch_idx] |= MT6360_ISNK_PWM_MODE << MT6360_ISNK_MODE_SHFT; + } + + ret = regmap_raw_write(priv->regmap, MT6360_REG_ISNK(0), mc_reg, 3); + +out: + mutex_unlock(&priv->lock); + return ret; +} + static int mt6360_mc_brightness_set(struct led_classdev *lcdev, enum led_brightness level) { struct led_classdev_mc *mccdev = lcdev_to_mccdev(lcdev); struct mt6360_led *led = container_of(mccdev, struct mt6360_led, mc); struct mt6360_priv *priv = led->priv; - u32 real_bright, enable_mask = 0, enable = 0; + u32 real_bright, enable_mask = 0, enable = 0, val; int i, ret; mutex_lock(&priv->lock); @@ -113,11 +238,25 @@ static int mt6360_mc_brightness_set(struct led_classdev *lcdev, for (i = 0; i < mccdev->num_colors; i++) { struct mc_subled *subled = mccdev->subled_info + i; + unsigned int bright_reg = MT6360_REG_ISNK(subled->channel); real_bright = min(lcdev->max_brightness, subled->brightness); - ret = regmap_update_bits(priv->regmap, - MT6360_REG_ISNK(subled->channel), - MT6360_ISNK_MASK, real_bright); + + ret = regmap_read(priv->regmap, bright_reg, &val); + if (ret) + goto out; + + /* Assign the new brightness value */ + val &= ~MT6360_ISNK_MASK; + val |= (real_bright & MT6360_ISNK_MASK); + + /* If LED_OFF, always configure back to CC mode */ + if (level == LED_OFF) { + val &= ~MT6360_ISNK_MODE_MASK; + val |= MT6360_ISNK_CC_MODE << MT6360_ISNK_MODE_SHFT; + } + + ret = regmap_write(priv->regmap, bright_reg, val); if (ret) goto out; @@ -134,6 +273,44 @@ static int mt6360_mc_brightness_set(struct led_classdev *lcdev, return ret; } +static int mt6360_isnk_blink_set(struct led_classdev *lcdev, unsigned long *don, + unsigned long *doff) +{ + struct mt6360_led *led = container_of(lcdev, struct mt6360_led, isnk); + struct mt6360_priv *priv = led->priv; + unsigned int freq_sel, duty_sel; + int ret; + + if (!*don && !*doff) + *don = *doff = 500; + + mutex_lock(&priv->lock); + + ret = regmap_update_bits(priv->regmap, MT6360_REG_ISNK(led->led_no), + MT6360_ISNK_MODE_MASK, + MT6360_ISNK_CC_MODE << MT6360_ISNK_MODE_SHFT); + if (ret) + goto out; + + /* Get the desired selector for frequency and duty */ + ret = mt6360_get_selected_freq_duty(*don, *doff, &freq_sel, &duty_sel); + if (ret) + goto out; + + ret = mt6360_set_pwm_dimming_param(priv, led->led_no, freq_sel, + duty_sel); + if (ret) + goto out; + + ret = regmap_update_bits(priv->regmap, MT6360_REG_ISNK(led->led_no), + MT6360_ISNK_MODE_MASK, + MT6360_ISNK_PWM_MODE << MT6360_ISNK_MODE_SHFT); + +out: + mutex_unlock(&priv->lock); + return ret; +} + static int mt6360_isnk_brightness_set(struct led_classdev *lcdev, enum led_brightness level) { @@ -141,12 +318,27 @@ static int mt6360_isnk_brightness_set(struct led_classdev *lcdev, struct mt6360_priv *priv = led->priv; u32 enable_mask = MT6360_ISNK_ENMASK(led->led_no); u32 val = level ? MT6360_ISNK_ENMASK(led->led_no) : 0; + unsigned int bright_val; int ret; mutex_lock(&priv->lock); - ret = regmap_update_bits(priv->regmap, MT6360_REG_ISNK(led->led_no), - MT6360_ISNK_MASK, level); + ret = regmap_read(priv->regmap, MT6360_REG_ISNK(led->led_no), + &bright_val); + if (ret) + goto out; + + bright_val &= ~MT6360_ISNK_MASK; + bright_val |= (level & MT6360_ISNK_MASK); + + /* If LED_OFF, always configure back to CC mode */ + if (led->led_no != MT6360_LED_ISNKML && level == LED_OFF) { + bright_val &= ~MT6360_ISNK_MODE_MASK; + bright_val |= MT6360_ISNK_CC_MODE << MT6360_ISNK_MODE_SHFT; + } + + ret = regmap_write(priv->regmap, MT6360_REG_ISNK(led->led_no), + bright_val); if (ret) goto out; @@ -666,6 +858,7 @@ static int mt6360_init_isnk_properties(struct mt6360_led *led, lcdev = &led->mc.led_cdev; lcdev->brightness_set_blocking = mt6360_mc_brightness_set; + lcdev->blink_set = mt6360_mc_blink_set; } else { if (led->led_no == MT6360_LED_ISNKML) { step_uA = MT6360_ISNKML_STEPUA; @@ -674,6 +867,10 @@ static int mt6360_init_isnk_properties(struct mt6360_led *led, lcdev = &led->isnk; lcdev->brightness_set_blocking = mt6360_isnk_brightness_set; + + /* Suppose only ISNK1/2/3 support mode change */ + if (led->led_no != MT6360_LED_ISNKML) + lcdev->blink_set = mt6360_isnk_blink_set; } ret = fwnode_property_read_u32(init_data->fwnode, "led-max-microamp", From patchwork Thu Apr 28 09:32:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChiYuan Huang X-Patchwork-Id: 12830274 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF547C433F5 for ; Thu, 28 Apr 2022 09:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ENu+p00VplmzFNNl3GsaexFgVk+QBuBfPjoiOsT7fgk=; b=AvyWzwyfbnjJPI DauYby04nNeQAdjzAwFtdvjygMQKcvpl34JNWTHxrix1/GO1nGXXSX+PDSFP4c56pVUum8LFW4iwD IM31dfhNPeovniEr8RNz6FgxVhfEU7T3HXiqSfUD/A9/gAbODQW3Cs94aqzO5rKaN196HtCyA63qk cxJMpGlfUu4Oey1JvKf5yY8arrABABAwKt0rgCHKxdT+q/XSvXgGe5G5OLVf+j3IfWqohvccLl8me VgkWdi6+BFhODnptmqHPJe1vdM0QclxUmK7nQFfr6ibAj0T++dnpn2/AYUiDmsiuOdo1n8Rl/BK+X +9tLTUx464pW4kLR72WA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk0YY-005kxF-NS; Thu, 28 Apr 2022 09:35:26 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk0Wf-005k21-Bx; Thu, 28 Apr 2022 09:33:31 +0000 Received: by mail-pg1-x530.google.com with SMTP id s137so3533653pgs.5; Thu, 28 Apr 2022 02:33:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xAol5QruUmZ5P63tLTEq5XXd0IGdASrSG85VZ8UAHlI=; b=lYFnD9o6Fu/KxmPfhLdkQVUIHquoNV83EyB2bvo/yAyng6t8035r9ZRaHO/EDUbhDr GIzhEGfpvdkynLsaTT3W/M2RVKfmEvkP3GtbKOPCic0L8Bbw2CCFVOj9U41ojiIGsUY7 8cnGZNjAOmeO4CA3nMcQFed9A1VdUuEWeJ2RTbkNjVqEVUMclNMGlffxLk/NKeQksK4v 4Esa2bEUo7v01epTToF88KS/uCGRV7wIx07pxM8U/cY1rBfPFotEb1KyS7sT02OfGvfk xVgwkbRIQtNjY0JZo+Ik97LKGD1njnECB0L2W1SzHbP+MsQd4sU3s25Gr+IVfzRMJkt3 tapA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xAol5QruUmZ5P63tLTEq5XXd0IGdASrSG85VZ8UAHlI=; b=lkTACNuW5r//UukfV4rZ/+nwjlO+/6R4zz/BWp6XbNMsJRHO3vUKmZAPnE01KoHoN6 fWAkVGY7DyRA1mB2qdr3GLB6lv0lBKG1jHR6kngoMBZJ8HTB/vBQc85a6NisqflzR/Ub VQl14XannciKaOMgmEc88u+HxxIQiDYRzo6ZLeDy3X5yx1urlc+SNuVug6DrZpGC4OOF Q/xqFdOTxCSPXnDTACm3zaBPA2wJaHLPWWLwOpzwRpPBJA65pykwJB97BRv6sdIAKsPE s3055Wk89v9xAekkYyKTg8j/tNsUr+QT/XSFoTo/kTB1IvNt96FlfxQY+xpinobTxmgZ uKbg== X-Gm-Message-State: AOAM532l3mjmEC2dGcx/orBz499fgUcut5vewooL8BtJpp0FMhbABFlM U0MKJL+qJG51ZvRpR0KbAqk= X-Google-Smtp-Source: ABdhPJxKCC/IUC9lzBFfGM+0qywfNnlKk+CMz8KkWBJm6kbeseVQM1NthVu3+iY3LR7DRgvCFa5m8g== X-Received: by 2002:a05:6a00:238f:b0:4f6:b09a:4c63 with SMTP id f15-20020a056a00238f00b004f6b09a4c63mr33920186pfc.35.1651138407168; Thu, 28 Apr 2022 02:33:27 -0700 (PDT) Received: from localhost.localdomain ([2402:7500:569:2b1f:d169:337e:6359:8ff7]) by smtp.gmail.com with ESMTPSA id i66-20020a628745000000b0050d36a5fe70sm15457932pfe.127.2022.04.28.02.33.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Apr 2022 02:33:26 -0700 (PDT) From: cy_huang To: pavel@ucw.cz, matthias.bgg@gmail.com Cc: cy_huang@richtek.com, jacek.anaszewski@gmail.com, gene_chen@richtek.com, linux-leds@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] leds: flash: mt6360: Add mt6360 isnk channel hardwre breath mode support Date: Thu, 28 Apr 2022 17:32:45 +0800 Message-Id: <1651138365-17362-5-git-send-email-u0084500@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1651138365-17362-1-git-send-email-u0084500@gmail.com> References: <1651138365-17362-1-git-send-email-u0084500@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220428_023329_470746_138BB144 X-CRM114-Status: GOOD ( 23.05 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: ChiYuan Huang Add mt6360 isnk channel hardware breath mode support. Signed-off-by: ChiYuan Huang --- drivers/leds/flash/Kconfig | 1 + drivers/leds/flash/leds-mt6360.c | 207 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 207 insertions(+), 1 deletion(-) diff --git a/drivers/leds/flash/Kconfig b/drivers/leds/flash/Kconfig index 38b325c..039ff50 100644 --- a/drivers/leds/flash/Kconfig +++ b/drivers/leds/flash/Kconfig @@ -54,6 +54,7 @@ config LEDS_MT6360 depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS depends on MFD_MT6360 + select LINEAR_RANGE help This option enables support for dual Flash LED drivers found on Mediatek MT6360 PMIC. diff --git a/drivers/leds/flash/leds-mt6360.c b/drivers/leds/flash/leds-mt6360.c index 8fe3dc4..b4a702c 100644 --- a/drivers/leds/flash/leds-mt6360.c +++ b/drivers/leds/flash/leds-mt6360.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -24,7 +25,14 @@ enum { MT6360_MAX_LEDS }; +enum mt6360_iled_range { + MT6360_ILED_RANGE_TRF12ON = 0, /* tr1, tr2, ton, tf1, tf2 */ + MT6360_ILED_RANGE_TOFF, + MT6360_ILED_RANGE_MAX +}; + #define MT6360_ISNK_PWM_MODE 0 +#define MT6360_ISNK_BREATH_MODE 1 #define MT6360_ISNK_CC_MODE 2 #define MT6360_REG_RGBEN 0x380 @@ -32,6 +40,7 @@ enum { #define MT6360_REG_DIM(_led_no) (0x385 + (_led_no)) #define MT6360_REG_FREQ1 0x389 #define MT6360_REG_FREQ2 0x38A +#define MT6360_REG_ISNK_BREATH(_ledno) (0x38B + ((_ledno) * 3)) #define MT6360_ISNK_ENMASK(_led_no) BIT(7 - (_led_no)) #define MT6360_FREQ13_MASK GENMASK(7, 5) #define MT6360_FREQ2_MASK GENMASK(4, 2) @@ -39,6 +48,14 @@ enum { #define MT6360_ISNK_MODE_SHFT 6 #define MT6360_ISNK_MASK GENMASK(4, 0) #define MT6360_CHRINDSEL_MASK BIT(3) +#define MT6360_ISNK_TR1_MASK GENMASK(7, 4) +#define MT6360_ISNK_TR2_MASK GENMASK(3, 0) +#define MT6360_ISNK_TF1_MASK GENMASK(7, 4) +#define MT6360_ISNK_TF2_MASK GENMASK(3, 0) +#define MT6360_ISNK_TON_MASK GENMASK(7, 4) +#define MT6360_ISNK_TOFF_MASK GENMASK(3, 0) +#define MT6360_BREATH_PATTERN_CNT 6 +#define MT6360_BREATH_CFGRG_CNT 3 /* Virtual definition for multicolor */ #define MT6360_VIRTUAL_MULTICOLOR (MT6360_MAX_LEDS + 1) @@ -108,6 +125,46 @@ struct mt6360_priv { struct mt6360_led leds[]; }; +static int mt6360_gen_breath_reg_config(struct led_pattern *pattern, u32 len, + u8 *vals, int val_len) +{ + static const struct linear_range tranges[MT6360_ILED_RANGE_MAX] = { + { 125, 0, 15, 250 }, /* tr/f12 and ton, unit: millisecond */ + { 250, 0, 15, 500 }, /* toff, unit: millisecond */ + }; + static const struct { + int rg_offset; + int mask; + enum mt6360_iled_range rid; + } params[MT6360_BREATH_PATTERN_CNT] = { + { 0, MT6360_ISNK_TR1_MASK, MT6360_ILED_RANGE_TRF12ON }, + { 0, MT6360_ISNK_TR2_MASK, MT6360_ILED_RANGE_TRF12ON }, + { 2, MT6360_ISNK_TON_MASK, MT6360_ILED_RANGE_TRF12ON }, + { 1, MT6360_ISNK_TF1_MASK, MT6360_ILED_RANGE_TRF12ON }, + { 1, MT6360_ISNK_TF2_MASK, MT6360_ILED_RANGE_TRF12ON }, + { 2, MT6360_ISNK_TOFF_MASK, MT6360_ILED_RANGE_TOFF } + }; + unsigned int sel; + int i, shift; + + /* Must contain 6 tuples to configure tr1, tr2, ton, tf1, tf2, toff */ + if (len != MT6360_BREATH_PATTERN_CNT || + val_len != MT6360_BREATH_CFGRG_CNT) + return -EINVAL; + + for (i = 0; i < ARRAY_SIZE(params); i++) { + linear_range_get_selector_within(tranges + params[i].rid, + pattern[i].delta_t, &sel); + + shift = ffs(params[i].mask) - 1; + + vals[params[i].rg_offset] &= ~params[i].mask; + vals[params[i].rg_offset] |= sel << shift; + } + + return 0; +} + static int mt6360_get_selected_freq_duty(unsigned long on, unsigned long off, unsigned int *fsel, unsigned int *dsel) { @@ -165,6 +222,95 @@ static int mt6360_set_pwm_dimming_param(struct mt6360_priv *priv, return regmap_write(priv->regmap, MT6360_REG_DIM(led_no), dsel); } +static int mt6360_mc_pattern_set(struct led_classdev *lcdev, + struct led_pattern *pattern, u32 len, + int repeat) +{ + struct led_classdev_mc *mccdev = lcdev_to_mccdev(lcdev); + struct mt6360_led *led = container_of(mccdev, struct mt6360_led, mc); + struct mt6360_priv *priv = led->priv; + unsigned int reg_base; + u8 cfg_vals[MT6360_BREATH_CFGRG_CNT] = {0}; + u8 mc_reg[3]; + int i, ret; + + ret = mt6360_gen_breath_reg_config(pattern, len, cfg_vals, + sizeof(cfg_vals)); + if (ret) + return ret; + + mutex_lock(&priv->lock); + + ret = regmap_raw_read(priv->regmap, MT6360_REG_ISNK(0), mc_reg, 3); + if (ret) + goto out; + + /* Configure all subleds to CC mode first */ + for (i = 0; i < mccdev->num_colors; i++) { + struct mc_subled *subled = mccdev->subled_info + i; + int ch_idx = subled->channel; + + mc_reg[ch_idx] &= ~MT6360_ISNK_MODE_MASK; + mc_reg[ch_idx] |= MT6360_ISNK_CC_MODE << MT6360_ISNK_MODE_SHFT; + } + + ret = regmap_raw_write(priv->regmap, MT6360_REG_ISNK(0), mc_reg, 3); + if (ret) + goto out; + + for (i = 0; i < mccdev->num_colors; i++) { + struct mc_subled *subled = mccdev->subled_info + i; + int ch_idx = subled->channel; + + reg_base = MT6360_REG_ISNK_BREATH(ch_idx); + + ret = regmap_raw_write(priv->regmap, reg_base, cfg_vals, + sizeof(cfg_vals)); + if (ret) + goto out; + + mc_reg[ch_idx] &= ~MT6360_ISNK_MODE_MASK; + mc_reg[ch_idx] |= + MT6360_ISNK_BREATH_MODE << MT6360_ISNK_MODE_SHFT; + } + + ret = regmap_raw_write(priv->regmap, MT6360_REG_ISNK(0), mc_reg, 3); + +out: + mutex_unlock(&priv->lock); + return ret; +} + +static int mt6360_mc_pattern_clear(struct led_classdev *lcdev) +{ + struct led_classdev_mc *mccdev = lcdev_to_mccdev(lcdev); + struct mt6360_led *led = container_of(mccdev, struct mt6360_led, mc); + struct mt6360_priv *priv = led->priv; + u8 mc_reg[3]; + int i, ret; + + mutex_lock(&priv->lock); + + ret = regmap_raw_read(priv->regmap, MT6360_REG_ISNK(0), mc_reg, 3); + if (ret) + goto out; + + /* Configure all subleds to CC mode first */ + for (i = 0; i < mccdev->num_colors; i++) { + struct mc_subled *subled = mccdev->subled_info + i; + int ch_idx = subled->channel; + + mc_reg[ch_idx] &= ~MT6360_ISNK_MODE_MASK; + mc_reg[ch_idx] |= MT6360_ISNK_CC_MODE << MT6360_ISNK_MODE_SHFT; + } + + ret = regmap_raw_write(priv->regmap, MT6360_REG_ISNK(0), mc_reg, 3); + +out: + mutex_unlock(&priv->lock); + return ret; +} + static int mt6360_mc_blink_set(struct led_classdev *lcdev, unsigned long *don, unsigned long *doff) { @@ -273,6 +419,60 @@ static int mt6360_mc_brightness_set(struct led_classdev *lcdev, return ret; } +static int mt6360_isnk_pattern_set(struct led_classdev *lcdev, + struct led_pattern *pattern, u32 len, + int repeat) +{ + struct mt6360_led *led = container_of(lcdev, struct mt6360_led, isnk); + struct mt6360_priv *priv = led->priv; + unsigned int reg_base = MT6360_REG_ISNK_BREATH(led->led_no); + u8 cfg_vals[MT6360_BREATH_CFGRG_CNT] = {0}; + int ret; + + ret = mt6360_gen_breath_reg_config(pattern, len, cfg_vals, + sizeof(cfg_vals)); + if (ret) + return ret; + + mutex_lock(&priv->lock); + + ret = regmap_raw_write(priv->regmap, reg_base, cfg_vals, + sizeof(cfg_vals)); + if (ret) + goto out; + + /* Toggle mode change to make new parameter applied */ + ret = regmap_update_bits(priv->regmap, MT6360_REG_ISNK(led->led_no), + MT6360_ISNK_MODE_MASK, MT6360_ISNK_CC_MODE + << MT6360_ISNK_MODE_SHFT); + if (ret) + goto out; + + ret = regmap_update_bits(priv->regmap, MT6360_REG_ISNK(led->led_no), + MT6360_ISNK_MODE_MASK, MT6360_ISNK_BREATH_MODE + << MT6360_ISNK_MODE_SHFT); + +out: + mutex_unlock(&priv->lock); + return 0; +} + +static int mt6360_isnk_pattern_clear(struct led_classdev *lcdev) +{ + struct mt6360_led *led = container_of(lcdev, struct mt6360_led, isnk); + struct mt6360_priv *priv = led->priv; + int ret; + + mutex_lock(&priv->lock); + + ret = regmap_update_bits(priv->regmap, MT6360_REG_ISNK(led->led_no), + MT6360_ISNK_MODE_MASK, MT6360_ISNK_CC_MODE + << MT6360_ISNK_MODE_SHFT); + + mutex_unlock(&priv->lock); + return ret; +} + static int mt6360_isnk_blink_set(struct led_classdev *lcdev, unsigned long *don, unsigned long *doff) { @@ -859,6 +1059,8 @@ static int mt6360_init_isnk_properties(struct mt6360_led *led, lcdev = &led->mc.led_cdev; lcdev->brightness_set_blocking = mt6360_mc_brightness_set; lcdev->blink_set = mt6360_mc_blink_set; + lcdev->pattern_set = mt6360_mc_pattern_set; + lcdev->pattern_clear = mt6360_mc_pattern_clear; } else { if (led->led_no == MT6360_LED_ISNKML) { step_uA = MT6360_ISNKML_STEPUA; @@ -869,8 +1071,11 @@ static int mt6360_init_isnk_properties(struct mt6360_led *led, lcdev->brightness_set_blocking = mt6360_isnk_brightness_set; /* Suppose only ISNK1/2/3 support mode change */ - if (led->led_no != MT6360_LED_ISNKML) + if (led->led_no != MT6360_LED_ISNKML) { lcdev->blink_set = mt6360_isnk_blink_set; + lcdev->pattern_set = mt6360_isnk_pattern_set; + lcdev->pattern_clear = mt6360_isnk_pattern_clear; + } } ret = fwnode_property_read_u32(init_data->fwnode, "led-max-microamp",