Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp29333iol; Wed, 8 Jun 2022 20:47:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4I/IERgRcz2RkMZSLDFPnJOIcv641QQc5D4gdzzKUbz+AOzwL28nSrdqPypiOB0D66JnM X-Received: by 2002:a17:906:49d4:b0:6d6:e5ec:9a23 with SMTP id w20-20020a17090649d400b006d6e5ec9a23mr34971555ejv.79.1654746442371; Wed, 08 Jun 2022 20:47:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654746442; cv=none; d=google.com; s=arc-20160816; b=ZuUbQ6Xa56tNpQmRtK5xVH/kuaqqgt54mS++9Ez02ir2jKQUbCAU3E06i+6fbh7S/x xfhyCUg2a5LoPPn6s4LHP93zXVJATDzpJEcIloPA15z0dLheqhzPcI+/AFJV6TVjUVU/ t9RcGCwLqpFfVaI5BhPFCubETjtQzqKAPk7wIL/v5hezp5g7NI5Cv9BsxO+1fsF2griI mG3E3iqYPdYIidR2U16DwaFBxs1okpi562iNZiPWP9k5U20s31CglIL1FzZkmgs9H9KE ErSy8NWw45THnJsxaOsX0wgKq5JsCJ+f14Kx+xiHukBuxyofJ5kA0QqFRIFuhT5eklwn PR4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=zUInyvNeOnDXs6rfO5VKVDhyL30Ry7vKQyVq8b/sXhM=; b=MCzTaj0XyNPzypR3wrYD0yu65h+JRlgJCiJLk5lENP+dfNCRTqF8MfW5C5oKVTCGed HX0lNkvCQKkXIIhcjdNGI0MUdKWFEDQLPfI1QN9QAIEjn479aTCldIh+gH8Dgmo3Dxyo Udyafbbh9vmtByCPP3I1T26QwECMew8DXzvVCwQd23Guy83R/FK5rD0w5f2Mh2iV570b +svecBkidW2zBnQ/jf5jQuR8MvwsGZMoFWzt8bkRwlsFuQXqgdUNQiBC6x0RasFaqHO3 vQFz7nhEsUv94PlR17hruve8H1PJDET2R80Wt3VAXYuewhYW8yjVj144oOZjrOTF68Bb 1leg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=URFVRvzY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c23-20020a1709060fd700b006ff165f19e6si22560650ejk.350.2022.06.08.20.46.57; Wed, 08 Jun 2022 20:47:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=URFVRvzY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236691AbiFICWt (ORCPT + 99 others); Wed, 8 Jun 2022 22:22:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236634AbiFICWm (ORCPT ); Wed, 8 Jun 2022 22:22:42 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E6C27E1E8; Wed, 8 Jun 2022 19:22:41 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id d129so20560462pgc.9; Wed, 08 Jun 2022 19:22:41 -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=zUInyvNeOnDXs6rfO5VKVDhyL30Ry7vKQyVq8b/sXhM=; b=URFVRvzYDluiblUwQq0fFYaerhtlF8YxghQ8N9Sk9qFp3XcUC/UN6ixBnaxA2e4s9l 2XU1ufsmKeJFRB8lKM/0XUTQ/seh6zC/7VWXW2ktyopwuZvHMa1x42kogSv8c9cYuK5i keBswrmSPE26QtkbcNEIqCYXw0L9DJJdv8Hz/RFjEo5yib6drZVERoP/5ge5QUE5I4JO s+5/rxrM0nBL0ig3B3rRwZr2ndKjhCmlcQpdyM6l8ekz29Pb4d9wWNvoAVelyCL2IDEW 2WNlja1Ue5RBd7NabxHWxha+FK3kDgvIDtp5e/ZDNmCQSKuXljhNcLxLGG2Zqw3gab0h fhfA== 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=zUInyvNeOnDXs6rfO5VKVDhyL30Ry7vKQyVq8b/sXhM=; b=KQf2vBYaJ6W/PBsq9U2mA4d3tMtq835LFlbwnYRKyn2U6x/IwjCwZJPmWcBmekIWUD IMPyyxuFGEj1k6Ryq24pww7qHAq/Kzyvpv1KJqJlIOzAqzXQCTc436V+7zbdODQcjvwo pAU7ARKnrKcHS0T/JFDrmzbq2sLMH3SsgOZfPJvqzFiNhfx7X2dD9Cs3XA2MGccWEgmu ePwrYrZG5ta4wqOv0L8FJDjiR91t/tVLVputNTJFXfosLbcGMjJgaWS1tTdrxFkg1YdM OwdjTk45E8NNKdGBeSz9+l3MTg+H/5HIexG7eriZdAFitLYi+qWUm6tGGILIsrH+PPKw 73Rw== X-Gm-Message-State: AOAM5317tV7Uus3HjFG9cYnH3yqa2xKxn5LFGCpHBJkRTDZPLCFObA3E e/2c81SNegK/l3OkuZKzX1I= X-Received: by 2002:a63:ea4f:0:b0:3c6:6534:d8f2 with SMTP id l15-20020a63ea4f000000b003c66534d8f2mr32515923pgk.187.1654741360832; Wed, 08 Jun 2022 19:22:40 -0700 (PDT) Received: from localhost.localdomain ([2402:7500:478:d041:804b:4db9:72:b011]) by smtp.gmail.com with ESMTPSA id y22-20020aa78056000000b005183f333721sm15748770pfm.87.2022.06.08.19.22.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jun 2022 19:22:40 -0700 (PDT) From: cy_huang To: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, lee.jones@linaro.org, daniel.thompson@linaro.org, jingoohan1@gmail.com Cc: pavel@ucw.cz, deller@gmx.de, cy_huang@richtek.com, lucas_tsai@richtek.com, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/2] backlight: rt4831: Apply ocp level from devicetree Date: Thu, 9 Jun 2022 10:22:19 +0800 Message-Id: <1654741339-12756-3-git-send-email-u0084500@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1654741339-12756-1-git-send-email-u0084500@gmail.com> References: <1654741339-12756-1-git-send-email-u0084500@gmail.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: ChiYuan Huang Add 'richtek,bled-ocp-microamp' property parsing in device_property_init function. This value may configure prior to the kernel driver. If it's not specified in devicetree, keep the original setting. Else, use clamp to align the value in min/max range and also roundup to choose the best selector. Reported-by: Lucas Tsai Signed-off-by: ChiYuan Huang Reviewed-by: Daniel Thompson --- Since v2: - Prase the 'richtek,bled-ocp-microamp', clamp the value in min/max range, and roundup to get the best selector. --- drivers/video/backlight/rt4831-backlight.c | 33 +++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/video/backlight/rt4831-backlight.c b/drivers/video/backlight/rt4831-backlight.c index 42155c7..8c2001b 100644 --- a/drivers/video/backlight/rt4831-backlight.c +++ b/drivers/video/backlight/rt4831-backlight.c @@ -12,6 +12,7 @@ #define RT4831_REG_BLCFG 0x02 #define RT4831_REG_BLDIML 0x04 #define RT4831_REG_ENABLE 0x08 +#define RT4831_REG_BLOPT2 0x11 #define RT4831_BLMAX_BRIGHTNESS 2048 @@ -23,6 +24,11 @@ #define RT4831_BLDIML_MASK GENMASK(2, 0) #define RT4831_BLDIMH_MASK GENMASK(10, 3) #define RT4831_BLDIMH_SHIFT 3 +#define RT4831_BLOCP_MASK GENMASK(1, 0) + +#define RT4831_BLOCP_MINUA 900000 +#define RT4831_BLOCP_MAXUA 1800000 +#define RT4831_BLOCP_STEPUA 300000 struct rt4831_priv { struct device *dev; @@ -85,7 +91,7 @@ static int rt4831_parse_backlight_properties(struct rt4831_priv *priv, { struct device *dev = priv->dev; u8 propval; - u32 brightness; + u32 brightness, ocp_uA; unsigned int val = 0; int ret; @@ -120,6 +126,31 @@ static int rt4831_parse_backlight_properties(struct rt4831_priv *priv, if (ret) return ret; + /* + * This OCP level is used to protect and limit the inductor current. + * If inductor peak current reach the level, low-side MOSFET will be + * turned off. Meanwhile, the output channel current may be limited. + * To match the configured channel current, the inductor chosen must + * be higher than the OCP level. + * + * Not like the OVP level, the default 21V can be used in the most + * application. But if the chosen OCP level is smaller than needed, + * it will also affect the backlight channel output current to be + * smaller than the register setting. + */ + ret = device_property_read_u32(dev, "richtek,bled-ocp-microamp", + &ocp_uA); + if (!ret) { + ocp_uA = clamp_val(ocp_uA, RT4831_BLOCP_MINUA, + RT4831_BLOCP_MAXUA); + val = roundup(ocp_uA - RT4831_BLOCP_MINUA, + RT4831_BLOCP_STEPUA); + ret = regmap_update_bits(priv->regmap, RT4831_REG_BLOPT2, + RT4831_BLOCP_MASK, val); + if (ret) + return ret; + } + ret = device_property_read_u8(dev, "richtek,channel-use", &propval); if (ret) { dev_err(dev, "richtek,channel-use DT property missing\n"); -- 2.7.4