From patchwork Thu Sep 30 03:05:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 514868 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:4087:0:0:0:0 with SMTP id m7csp648472jam; Wed, 29 Sep 2021 20:06:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRdonaojSKrvk4+0rTAROtfqQsXIslmLbcfEg4aXbss4NsTWO8YRrlTilwmWp9stcRIOqT X-Received: by 2002:a05:6402:5250:: with SMTP id t16mr4149471edd.227.1632971162098; Wed, 29 Sep 2021 20:06:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632971162; cv=none; d=google.com; s=arc-20160816; b=UQw+8c6hwQwj8366SghZ14iz9xkliODFNo9Fx1BmUjKkrXC8wsb9IgH7AZ6n+8c7Fx NU6NSq3TowVe+ZpFHlw8JoAnv8ewzsWXFFpHKkVCHmGMMHkKwnAChe086nFzvwjupbsn h9MSjQX3Hx8hdPF+J6Ci8GZ6NA+vedUlN0svrU2UtZyASciRewqztBFi55ZroFiXA7YB h8VIP10TMxp4w2b0NJkBOqB7Frk1GyhWBPJVpa7GITYNJfc2OW6jQwhK3M41Up8rdUNK vpLctu3iijiBc+anPGxSLhZaVyW/zeFdjfBaL27eOLk8PB0T3h2irmuyNB66ewHn9aw4 e52w== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=a+OqbWheVa9fktnks13xlGqW75vpzjA26oxz+hbw1HY=; b=QB4xt/N3BhvhfmfhTkfEHQp4kazJXyo8pzkiFOzfS0bB9XVxndz0PD7PkekANw1j5J aA0ZI/xzrT29Do7KEwa+asbxMMmsq9ID2TSar+CQXUo1Jh/gRZjfO0bc8q29HGFRjq2O aBolkbULzmBTnLv+vYhZlMNSDuyXRjL9/ZqPH8VcicGc9AbPnWm7FEyrNiUjA9j8CR/i VE5gED+BJnGaCoFQUK8Ng401dobN/s/pcQ5nccRmhg+15m+KYG6686FplZluY5e3W9fq dQX9smYNzhv6cWfQtb5C37lKC2cNjyTBTm5f25P/1GionlkhrM0Y+40AG63P5mctt+St rfoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=znAFf3H0; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 5si2146628ejm.251.2021.09.29.20.06.01; Wed, 29 Sep 2021 20:06:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=znAFf3H0; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347764AbhI3DHm (ORCPT + 17 others); Wed, 29 Sep 2021 23:07:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347683AbhI3DHl (ORCPT ); Wed, 29 Sep 2021 23:07:41 -0400 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A299C06176A for ; Wed, 29 Sep 2021 20:05:59 -0700 (PDT) Received: by mail-ot1-x32b.google.com with SMTP id o59-20020a9d2241000000b0054745f28c69so5479560ota.13 for ; Wed, 29 Sep 2021 20:05:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=a+OqbWheVa9fktnks13xlGqW75vpzjA26oxz+hbw1HY=; b=znAFf3H00WKsy4tsdN/blEqQS1FQG4hLSnbrDru8KT0e+dYyY6FgCCbU6nkQvMc9kq SJHNZa4NxUImqemIzWZvsR4xLbVwebZV96Uq+4O9gslI5AA3PILSzVt3MN9iRzCxN7LP CAOkIM66hRORXfnLoVjBK5ViWi+/2qbnTwEoD0QjvdkaXGB3FQYmPwQbiPOboybsrmwm DE9u0o1/rvbW7VapxxR3YIwrBMaH4pW+6ScA57bR5fusCVomI1ucPNmrFfT026NLrtHJ NlrxGS4OGI0VeL/xk00FV8UVemIGjLVj6YTBiWym/5PzHtU5XsY1XX/qRrIyyeFQ6fv+ g1hg== 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:mime-version :content-transfer-encoding; bh=a+OqbWheVa9fktnks13xlGqW75vpzjA26oxz+hbw1HY=; b=I6+tvPBrkUy7LtllkZ18oe5jRmwhzY+BM1HYrFCtmUKOFVhDq8HhtdsGFy1qVX1Mba a1GskWEXWNkOS9SxsF0sSx/FT9Nn8VM0EGPQEKsl2mpO80qjfo7LpPe3ZirKHtHaxFAz BGkfjhxZygSRVkBkQ6IYPAuzJGmAsdxxioAjBvobJoxfjE2H5eSOMjduTEjxsCoO4MPN F/9pXWZvnkXRAtUTJJgC/8beoO/GXQrWxsFwnwTYxVvDjFmgDyq4x22eBVV8Cg0oF4CH YLP8pBFtZYclxgb05MMIsa+i6ejNc2T3xyXf/+73Fb/xW+AXmRtQCM1kYkl/R5JPTMur 3ndA== X-Gm-Message-State: AOAM530odWgUxIVm5me1QR5kfOezd1hXsJ28sKGR7rZxYD7NkgBSWRYQ 8pq4AcuVg+a9051L5cFQEgx1zw== X-Received: by 2002:a05:6830:31ae:: with SMTP id q14mr3156053ots.66.1632971158712; Wed, 29 Sep 2021 20:05:58 -0700 (PDT) Received: from builder.lan (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id s16sm323358otq.78.2021.09.29.20.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 20:05:57 -0700 (PDT) From: Bjorn Andersson To: Thierry Reding , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= , Lee Jones Cc: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, linux-arm-msm@vger.kernel.org, Doug Anderson Subject: [PATCH v6 1/3] pwm: Introduce single-PWM of_xlate function Date: Wed, 29 Sep 2021 22:05:55 -0500 Message-Id: <20210930030557.1426-1-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The existing pxa driver and the upcoming addition of PWM support in the TI sn565dsi86 DSI/eDP bridge driver both has a single PWM channel and thereby a need for a of_xlate function with the period as its single argument. Introduce a common helper function in the core that can be used as of_xlate by such drivers and migrate the pxa driver to use this. Signed-off-by: Bjorn Andersson Tested-by: Steev Klimaszewski --- Changes since v4: - None drivers/pwm/core.c | 26 ++++++++++++++++++++++++++ drivers/pwm/pwm-pxa.c | 16 +--------------- include/linux/pwm.h | 2 ++ 3 files changed, 29 insertions(+), 15 deletions(-) -- 2.32.0 diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 4527f09a5c50..2c6b155002a2 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -152,6 +152,32 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args) } EXPORT_SYMBOL_GPL(of_pwm_xlate_with_flags); +struct pwm_device * +of_pwm_single_xlate(struct pwm_chip *pc, const struct of_phandle_args *args) +{ + struct pwm_device *pwm; + + if (pc->of_pwm_n_cells < 1) + return ERR_PTR(-EINVAL); + + /* validate that one cell is specified, optionally with flags */ + if (args->args_count != 1 && args->args_count != 2) + return ERR_PTR(-EINVAL); + + pwm = pwm_request_from_chip(pc, 0, NULL); + if (IS_ERR(pwm)) + return pwm; + + pwm->args.period = args->args[0]; + pwm->args.polarity = PWM_POLARITY_NORMAL; + + if (args->args_count == 2 && args->args[2] & PWM_POLARITY_INVERTED) + pwm->args.polarity = PWM_POLARITY_INVERSED; + + return pwm; +} +EXPORT_SYMBOL_GPL(of_pwm_single_xlate); + static void of_pwmchip_add(struct pwm_chip *chip) { if (!chip->dev || !chip->dev->of_node) diff --git a/drivers/pwm/pwm-pxa.c b/drivers/pwm/pwm-pxa.c index a9efdcf839ae..238ec88c130b 100644 --- a/drivers/pwm/pwm-pxa.c +++ b/drivers/pwm/pwm-pxa.c @@ -148,20 +148,6 @@ static const struct platform_device_id *pxa_pwm_get_id_dt(struct device *dev) return id ? id->data : NULL; } -static struct pwm_device * -pxa_pwm_of_xlate(struct pwm_chip *pc, const struct of_phandle_args *args) -{ - struct pwm_device *pwm; - - pwm = pwm_request_from_chip(pc, 0, NULL); - if (IS_ERR(pwm)) - return pwm; - - pwm->args.period = args->args[0]; - - return pwm; -} - static int pwm_probe(struct platform_device *pdev) { const struct platform_device_id *id = platform_get_device_id(pdev); @@ -187,7 +173,7 @@ static int pwm_probe(struct platform_device *pdev) pc->chip.npwm = (id->driver_data & HAS_SECONDARY_PWM) ? 2 : 1; if (IS_ENABLED(CONFIG_OF)) { - pc->chip.of_xlate = pxa_pwm_of_xlate; + pc->chip.of_xlate = of_pwm_single_xlate; pc->chip.of_pwm_n_cells = 1; } diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 725c9b784e60..dd51d4931fdc 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -414,6 +414,8 @@ struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip, struct pwm_device *of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args); +struct pwm_device *of_pwm_single_xlate(struct pwm_chip *pc, + const struct of_phandle_args *args); struct pwm_device *pwm_get(struct device *dev, const char *con_id); struct pwm_device *of_pwm_get(struct device *dev, struct device_node *np,