From patchwork Wed Jun 23 03:27:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 465880 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1340107jao; Tue, 22 Jun 2021 20:28:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyipgSxXcVcT5oUDI2bww/p3pJFVVHXjHtL4+Wr1/lF5KnevEglO5zlSUSm7e3godpAErPU X-Received: by 2002:a17:90a:9b02:: with SMTP id f2mr6260425pjp.123.1624418882825; Tue, 22 Jun 2021 20:28:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624418882; cv=none; d=google.com; s=arc-20160816; b=jco5VwTwC12UBgaUsyqipZYKICZqUkp2pvTiAt33y1zlYXU6xq5vCtEmLkttBCcGDu 493ZulRj3HcfmNNdlm3B3fhMMskRNDVW3KudwknnR2SFVHyRIs52IXIngYiza6Cvl5nN jkFr0kqa+1eeLToGIG5EskfWGle9ZLFhc5CwJ50LFHdCJyf17dBG2xDrWRzaZQei/4Ti m88uhJaeRGMo04b4E4aaqsjOfZxlGdRp46xsLsWuq3uW9vaTZkGJexmIZsZreBG7ENg3 j0P60QX0/NxdvkyaTnPxy8nxrwtL85phFMfnYF+RM0wbQwe/LRuGz5xFbBiElURkxOUm FZgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :delivered-to; bh=JMuxhTYROjgx5QULq2BZS2oDybm62u2BvUDiK5gZyzc=; b=Cel03g3jUbHmYwCrWKIOrAAqLza17EgVfWJv3sWg9GS4nuCFaSrDHP+zsOkdHZRRvH vrt0EBw83iUSROYnKy6dUHSUMbKR32Y0L9aBFc6aIw3MMo7x4kPtYVQ8HXh5TPYMOzFf T07mn6URWM2RZsZqhXLxF8Ne0DP6ox95O8j3mgGZG6/gzvG+QQx0D/Aw/JL/9DmbC2Mk rgpgGrC/YFFoQgGlhka7wV8fq+jJrg4TnWoXv9/8jvUwl9iPLlPq27jU6v4GpfhyDa4L cZ+6q4oczR7Xz1GFfr8FU/oZeiq15CbM13vpR6cuOx6em5Yf+PZjgZhHhYVl37FGg9Hl Q7jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="YbNbLV/A"; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id v7si1697487pfu.38.2021.06.22.20.28.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Jun 2021 20:28:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="YbNbLV/A"; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0C0B96E0C9; Wed, 23 Jun 2021 03:27:59 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by gabe.freedesktop.org (Postfix) with ESMTPS id 164656E0C9 for ; Wed, 23 Jun 2021 03:27:58 +0000 (UTC) Received: by mail-ot1-x329.google.com with SMTP id x17-20020a05683000d1b029045fb1889a9eso119836oto.5 for ; Tue, 22 Jun 2021 20:27:57 -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=JMuxhTYROjgx5QULq2BZS2oDybm62u2BvUDiK5gZyzc=; b=YbNbLV/AthBTeNVil1kpX3c8VOgFAmopKeEmIfPIMPIPYZkoXtnlnfEQ0T/sNnMsf2 SYtNrDU17OYcxuO8gEDTh1N7YKbOc302add5Coep/i4R3fH1UocRi582IzdC1UomiaIo UOgNN69DmXyTcba9boWIxksL17ifBydlbQkgPDxmFK1g7ylObkWYn0G51CeHvgXBPzwD LcstrFIGUa7A7vOswuLzp+GxqSTlWd+xj1bm1AwTsfHxJOwOVKB4xBFjrd1fku8zfEI7 //NsRMqRRs48hrsX3G4vhhSNFaPCblxHaMtZzClLwhUb71dOrgbcE7Y3ujDJlR+J5UqT 84ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JMuxhTYROjgx5QULq2BZS2oDybm62u2BvUDiK5gZyzc=; b=e8g4RhxkPF6pJYQ/RKPgTvhhkcVJYWE4EVfdRIy96eQRx/BZco48VH1WpfL8TFCfgY n9P8tWgCmk+/R1P5dZjmxl5BjwJYCiUjK7Hb4giczcUUmbxd+DogqS9COQKVoOqMMr8A J1Vr3YUcHbpf3jgQi8EjQmYmNZaxDV4NyJSxvYcFyU8QrjggjftdVE98SvMYCdHdhQnW M/Jw72D2m9j0qI4I9B+jMA+VxNB4cyuIrDOo3xoyrmP6WNDyh1IN6QWmpq84BArODqXW +wYGURTkkx528+QuGo8nuknw2cCEQok7FE3JxWxHXPX5HWTXajWUakxiuKlx55gr+9N5 knrA== X-Gm-Message-State: AOAM533nGfrFYNa0vuXXH8t/ECNBb6U7pPc63Qo6m6VtpwXJP8KHFIvS 8PGuCPD8hCFeYu3k/rKIrR8JSg== X-Received: by 2002:a05:6830:905:: with SMTP id v5mr6050659ott.280.1624418877306; Tue, 22 Jun 2021 20:27:57 -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 c205sm4708363oib.20.2021.06.22.20.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Jun 2021 20:27:56 -0700 (PDT) From: Bjorn Andersson To: Thierry Reding , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= , Lee Jones , Doug Anderson Subject: [PATCH v4 1/2] pwm: Introduce single-PWM of_xlate function Date: Tue, 22 Jun 2021 22:27:54 -0500 Message-Id: <20210623032755.1170809-1-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, Jonas Karlman , David Airlie , Robert Foss , dri-devel@lists.freedesktop.org, Neil Armstrong , linux-kernel@vger.kernel.org, Jernej Skrabec , Andrzej Hajda , Laurent Pinchart Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 v3: - None Changes since v2: - 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.31.0 diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index a42999f877d2..5e9c876fccc4 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 cfb683827d32..8cd82fb54483 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) pwm->chip.npwm = (id->driver_data & HAS_SECONDARY_PWM) ? 2 : 1; if (IS_ENABLED(CONFIG_OF)) { - pwm->chip.of_xlate = pxa_pwm_of_xlate; + pwm->chip.of_xlate = of_pwm_single_xlate; pwm->chip.of_pwm_n_cells = 1; } diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 5a73251d28e3..6aff1fa4fe5d 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -411,6 +411,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,