Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp63170pxb; Wed, 29 Sep 2021 21:14:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyneymGFg6HVy9IGogbBtqMCiB50Ydypph5v+jixGfZW9O98dkQSN9sk18Crb4/x+/nRGwv X-Received: by 2002:a65:4884:: with SMTP id n4mr3153680pgs.68.1632975261466; Wed, 29 Sep 2021 21:14:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632975261; cv=none; d=google.com; s=arc-20160816; b=qDXi0K/mGgtsyzNAXy75MG2yt+TUqRh73ZviTLpNua22/r8YZKui1JYry4v0jFNHP3 OuWNwgj5o4MNNitBN5c123tHipS10K82ujBfGLDqDS8em68x4bvBXa0QA2N+LTX+2vOg FH3AcqrPdVZq6F/QTDkTbwBq2ZumWdQsXWT9DR2OLjOXwVFbjKODpKNNHhNmvFA4gHzG SmHAtuqHv0WKk7o40+mS430sLFyE8QJIU0U0eqODTELduAUPVKZx/nlHA+w3F1yAhczQ cMBnX1ZX0WohKRGNSEMtL3mq31Dye73ZcOJjV7Ou5CCjh6dxLetg3OrAZyKJmDyk8fQC KuVw== 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=WeDXeZP1ls0a4a7huoehjDpYS6WRxjwUMz4KIfb+5b8o/NHA4bxPiljgFkY1awWER/ Cc0d6zl2i1W0/wnIP2TAbmIAra3FgS0P9pbwsBtmZckX2pcd2F+2EAILV+OdreRgv0K4 To1TEF68TiTtIZ3EYbD84CeS5vHS4bML79pEIRblDFyjKx3GBjXHfhyXTdnZB4wDwmBf zdSUorbl4wKSSjEkbidF64J+f3HctHH6sLzQyHo4blOvHETVuClCS5auLdIck5/jnjF2 Z53K86RvD2Sz7ulXmurGbIp8lVj0Ov8H43CIL97BLMzaGqtgm/dUteYe2PuIkg1x13mH UUWg== 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-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 u6si3423135pfk.157.2021.09.29.21.14.07; Wed, 29 Sep 2021 21:14:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S1347707AbhI3DHm (ORCPT + 99 others); Wed, 29 Sep 2021 23:07:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347638AbhI3DHl (ORCPT ); Wed, 29 Sep 2021 23:07:41 -0400 Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6477BC06161C for ; Wed, 29 Sep 2021 20:05:59 -0700 (PDT) Received: by mail-ot1-x32a.google.com with SMTP id c6-20020a9d2786000000b005471981d559so5526140otb.5 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=p31Lr58sYfAQp2K6Nt25yS3592Rz65+lx4fpp5iQPCpHnagTNjvxCWdYlYBINgLd3v 2ER8MNBUZd0xZVslI/3Da8ORr6vhpltk0ic8ubPaoIks34c16mLu+GiymMg3X7bG9sfX WFssUv2YYuYteh8STETnz342oLzgpRE45FVwvEE6R7jDH2lEp7W0tfBZvd1plt6FyISj X1I+IzaYipULbMtKLD1h9m9YM0cOyfj4kZ+vul1t8WmM73nfBbGEUBeWcSweLwcU3hZ8 xrS8IycwdnYR2Hl1xQsU4h/2hOkYM3tIX/Qd8ldwErjT3dKbRCc2UWYRHINy1SHgMeHR T46A== X-Gm-Message-State: AOAM532RY3yvcJ05jmX95wg/Ghg2AQ5p2ummATuIRVUtrfioN/x27YdP fa7YE/UDrrR/NSzAteR6Cfioxg== 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=20Kleine-K=C3=B6nig?= , 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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(-) 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, -- 2.32.0