Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2866351rwd; Fri, 19 May 2023 11:12:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5eKyPrUwBizK3ldmxO7gU6xtd97E9I6enelrEFysEW5wZfKUfBkVNykO5Mgf1ZyOnY5IBY X-Received: by 2002:a17:902:e752:b0:1a1:bff4:49e9 with SMTP id p18-20020a170902e75200b001a1bff449e9mr4352456plf.23.1684519979439; Fri, 19 May 2023 11:12:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684519979; cv=none; d=google.com; s=arc-20160816; b=fduC/vv1HAehyFwnZWwRfrapX++IFr0RaE5pD3vEXb6/KR9Po0YjU3BszME3EGH0GF YhNy2mfBZjObO97UPctq74HLTG6vxxCGNRRGoskIofe1vz1vsMDLhrGyaUqrR/8aGp5i k4vZO6zm3A3YLz58DbzbpoB81yijgdOTw+/Q9rCq9Mw67YiqO+Ec8wc4brlStbEKYjCh fJkfndPW5VakecJe2SkjRsl/2D4N8WSnTfXI8SodEyhXD+ktWQTXu8OGIrTkEqWPvRbq c3+d28Nq9yW9tr4MTTdTOkcu8HDXvSTdLnugp8f7yGaLEZSlYEkVyZ+R5skTvLXLFYQa 9HXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vE2czkRUGQFVQ3kTZwHE+KiPxSvXioMK05vHyS7BUOM=; b=SQLapEkg23Atwl6PjJs2rK07HXoLMgO9r0hCHtXyJByADCmWKcmL76aCpak65dgYih eJ8OaVhZX2sCIlGvqub/P9YVpQXfpwWbDQtmoMXhQxmm7AOTUj2pDpCcS8eXtZwFCtZl iZgUcgAq7OCvyTPniTOzutnaF8U1ZZ6aqXO7Zh3ZQQ51kAK3VghJMui4QHW/jgHd6XAh FHV/IP3ZpuGtif+iZlawOcGLhaMeacBFWlJbNBjzKuuW8X4vnPe8hkSDUp4FhErV3ult 9mhvpD01unZJEN1iEahC64Z7ZE8S2vq1xWG77oYtUGu6N/Z5MX0Q+e/DqZODZXsu3jN4 Hwaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=HmKe4ZBv; 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 ay2-20020a1709028b8200b001ab2a0e3163si3640752plb.598.2023.05.19.11.12.42; Fri, 19 May 2023 11:12:59 -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=20221208 header.b=HmKe4ZBv; 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 S231707AbjESSJa (ORCPT + 99 others); Fri, 19 May 2023 14:09:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231345AbjESSJ1 (ORCPT ); Fri, 19 May 2023 14:09:27 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A08FB1A5; Fri, 19 May 2023 11:09:25 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-510d9218506so2305914a12.1; Fri, 19 May 2023 11:09:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684519764; x=1687111764; 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=vE2czkRUGQFVQ3kTZwHE+KiPxSvXioMK05vHyS7BUOM=; b=HmKe4ZBvFoFR+AEbrNRMOVUmVCOfY9dOl0ifMdl0i5+dBtYkuP1jcEF4rnFUsNZv07 zCyywr+WtfKmuv9ls9b7XAlBJn3sgwaoidVwMOJG6H/KpYU5zjW+iRiqqY/wlUDMNh1e ZlTy7bdUDq2gbPlVYhxnl4E4IZ8fzGj2JffgpxIVDxCtdddaAzxGiRuI5oebrt7h8Ah/ wCWGJJBSfrC5bg51AxrCqen5EPFsNMlMGptE2jvU/CGPW748YMxyUDY7ahth7b8AXzuN 5j/6T1z1usf/Yw3LcBCLjIEAgEGzVozB9OwmYfaWwnntU8dDf+S/ZJp5RxywM56KBjjj oWkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684519764; x=1687111764; 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=vE2czkRUGQFVQ3kTZwHE+KiPxSvXioMK05vHyS7BUOM=; b=MPqOX8P0Btr4/YYw1PgR0sgotAUeK4s7vGLlIzNcsijBjdhN2ttPoA9R6mTaWHjGB/ tZw0NLYKlw9eHg58vidPdDiK2kWHFotXinKipXSnC1uAPGBYZLTrtT+nCo0RCCYcJaWN w6PBmJ4Xr86b31CUhrkZAqpV0Cg51RCYIkqI0uvox3jt/Atbc1lHMxJnwbqnXh0A2ezr iCzx02keKzsNQkZLYFsY5mm+mbr4ykFFZKHoEmnoZD7jnBtjfD+GH1M9uYHCdW4YoFO8 CQqB6tOm4RlGQwWLzf6EPrwX+ISVLlZyB96m1fcVDSvGIodVL/nPYmPumUoVBWMNWQOy HuEw== X-Gm-Message-State: AC+VfDxjvhvfSkB9pihRehnGHSlZxWDtNejmKoDph8/Ck5odzGgSG0JD 2TLWh1u7a4IiHNHYjuvx0ME= X-Received: by 2002:a05:6402:190c:b0:506:bbf8:5152 with SMTP id e12-20020a056402190c00b00506bbf85152mr9819481edz.9.1684519763945; Fri, 19 May 2023 11:09:23 -0700 (PDT) Received: from localhost.my.domain (83.11.222.198.ipv4.supernova.orange.pl. [83.11.222.198]) by smtp.gmail.com with ESMTPSA id g26-20020aa7c85a000000b0050690bc07a3sm19824edt.18.2023.05.19.11.09.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 11:09:23 -0700 (PDT) From: Artur Weber To: Lee Jones , Rob Herring , Krzysztof Kozlowski Cc: Daniel Thompson , Jingoo Han , Pavel Machek , Andy Gross , Bjorn Andersson , Konrad Dybcio , Thierry Reding , Jonathan Hunter , Helge Deller , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Luca Weiss , Artur Weber , dri-devel@lists.freedesktop.org, linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-tegra@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-pwm@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht Subject: [PATCH v2 2/4] video: backlight: lp855x: get PWM for PWM mode during probe Date: Fri, 19 May 2023 20:07:26 +0200 Message-Id: <20230519180728.2281-3-aweber.kernel@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230519180728.2281-1-aweber.kernel@gmail.com> References: <20230519180728.2281-1-aweber.kernel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Also deprecate the pwm-period DT property, as it is now redundant (pwms property already contains period value). Signed-off-by: Artur Weber --- drivers/video/backlight/lp855x_bl.c | 48 ++++++++++++++++------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c index a57c9ef3b1cc..0ef850dd8e84 100644 --- a/drivers/video/backlight/lp855x_bl.c +++ b/drivers/video/backlight/lp855x_bl.c @@ -218,23 +218,10 @@ static int lp855x_configure(struct lp855x *lp) static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br) { - struct pwm_device *pwm; struct pwm_state state; - /* request pwm device with the consumer name */ - if (!lp->pwm) { - pwm = devm_pwm_get(lp->dev, lp->chipname); - if (IS_ERR(pwm)) - return; - - lp->pwm = pwm; - - pwm_init_state(lp->pwm, &state); - } else { - pwm_get_state(lp->pwm, &state); - } + pwm_get_state(lp->pwm, &state); - state.period = lp->pdata->period_ns; state.duty_cycle = div_u64(br * state.period, max_br); state.enabled = state.duty_cycle; @@ -339,6 +326,7 @@ static int lp855x_parse_dt(struct lp855x *lp) of_property_read_string(node, "bl-name", &pdata->name); of_property_read_u8(node, "dev-ctrl", &pdata->device_control); of_property_read_u8(node, "init-brt", &pdata->initial_brightness); + /* Deprecated, specify period in pwms property instead */ of_property_read_u32(node, "pwm-period", &pdata->period_ns); /* Fill ROM platform data if defined */ @@ -399,6 +387,7 @@ static int lp855x_probe(struct i2c_client *cl) const struct i2c_device_id *id = i2c_client_get_device_id(cl); const struct acpi_device_id *acpi_id = NULL; struct device *dev = &cl->dev; + struct pwm_state pwmstate; struct lp855x *lp; int ret; @@ -457,11 +446,6 @@ static int lp855x_probe(struct i2c_client *cl) } } - if (lp->pdata->period_ns > 0) - lp->mode = PWM_BASED; - else - lp->mode = REGISTER_BASED; - lp->supply = devm_regulator_get(dev, "power"); if (IS_ERR(lp->supply)) { if (PTR_ERR(lp->supply) == -EPROBE_DEFER) @@ -472,11 +456,31 @@ static int lp855x_probe(struct i2c_client *cl) lp->enable = devm_regulator_get_optional(dev, "enable"); if (IS_ERR(lp->enable)) { ret = PTR_ERR(lp->enable); - if (ret == -ENODEV) { + if (ret == -ENODEV) lp->enable = NULL; - } else { + else return dev_err_probe(dev, ret, "getting enable regulator\n"); - } + } + + lp->pwm = devm_pwm_get(lp->dev, lp->chipname); + if (IS_ERR(lp->pwm)) { + ret = PTR_ERR(lp->pwm); + if (ret == -ENODEV || ret == -EINVAL) + lp->pwm = NULL; + else + return dev_err_probe(dev, ret, "getting PWM\n"); + + lp->mode = REGISTER_BASED; + dev_dbg(dev, "mode: register based\n"); + } else { + pwm_init_state(lp->pwm, &pwmstate); + /* Legacy platform data compatibility */ + if (lp->pdata->period_ns > 0) + pwmstate.period = lp->pdata->period_ns; + pwm_apply_state(lp->pwm, &pwmstate); + + lp->mode = PWM_BASED; + dev_dbg(dev, "mode: PWM based\n"); } if (lp->supply) { -- 2.40.1