From patchwork Thu Mar 24 14:10:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tommaso Merciai X-Patchwork-Id: 1609056 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.a=rsa-sha256 header.s=google header.b=KwNsXjG+; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KPRxH06znz9s1l for ; Fri, 25 Mar 2022 01:12:02 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 92FCE8406C; Thu, 24 Mar 2022 15:11:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="KwNsXjG+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 777EC840D4; Thu, 24 Mar 2022 15:11:13 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4617C840C1 for ; Thu, 24 Mar 2022 15:11:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=tommaso.merciai@amarulasolutions.com Received: by mail-ed1-x531.google.com with SMTP id u26so5738674eda.12 for ; Thu, 24 Mar 2022 07:11:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xR8qT+l5ev/agbeJW6aNPzxxioihFcI9rOytN8fbMmQ=; b=KwNsXjG+ScmKPAcv2NaZ9Tz3tAcwtc9C3T+Vu08hkjs2B8dNXQEezR5VNIEAOQNNJe bkN5r6dxUkrVIgtmSCbCzjeFivAfkcrBqyxl+xsdNbU/he9HhNxdMmqICM2a7Wde0UpK QDRIGuE5nZpAsLncfAfETbyPZPRjuQ96tCyhI= 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:mime-version:content-transfer-encoding; bh=xR8qT+l5ev/agbeJW6aNPzxxioihFcI9rOytN8fbMmQ=; b=sEYpsNXvh99931Eng1e5DpaTxFk9NbjJb1m6/HYkwpXU63oie5VRVAHTB011Ao4BcW cHHzAyNIYxbk0AINQpCxcO3+kac/4fgPmUr++BzimEIdsjq8FsMuaCdb2C8jre1yQcTj MKG7l+f4nceKmoWYIGexM8FhmFhleUwhIRfnq7fFjlVlweZDTG/LneDFsUZPL3sBgZoj e3KoB1K0WoxkHSi0S2If/m+1l2EPn3SwU9ymQQpA9LFAMQYN0ur810JnaE2U09OvGnB/ DCO/OIEwq6rvJ16CEBFFV7pSQD3j737MHY1ws4yIPBsxxseEyCw+slgcgE1AmGsM3nNO 3wMQ== X-Gm-Message-State: AOAM530hwx2W0GIBCsMMMVrGM7TECjh5NAveeLYUWWEfdfU/3ncfxmlB EzCQZ+CyzchdsHYk54rH0Jf/IzRmRBfkkA== X-Google-Smtp-Source: ABdhPJxA5uKhJIwF5YvQKVT30bDaXNitNtU6UDqzbMT30A1k8dF26MjYf/PpS5SHs9RsZRC9tScESQ== X-Received: by 2002:a05:6402:d0e:b0:418:f011:275e with SMTP id eb14-20020a0564020d0e00b00418f011275emr6782482edb.323.1648131068931; Thu, 24 Mar 2022 07:11:08 -0700 (PDT) Received: from tom-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-79-0-195-19.business.telecomitalia.it. [79.0.195.19]) by smtp.gmail.com with ESMTPSA id s15-20020a170906778f00b006df84c19995sm1209355ejm.224.2022.03.24.07.11.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 07:11:08 -0700 (PDT) From: Tommaso Merciai To: Cc: tommaso.merciai@amarulasolutions.com, alb3rto.merciai@gmail.com, Peng Fan , Ye Li , Andrey Zhizhikin , Alice Guo , u-boot@lists.denx.de Subject: [PATCH v3 6/9] driver: pwm: pwm-imx: introduce pwm_dm_imx_get_parms Date: Thu, 24 Mar 2022 15:10:49 +0100 Message-Id: <20220324141052.16378-7-tommaso.merciai@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220324141052.16378-1-tommaso.merciai@amarulasolutions.com> References: <20220324141052.16378-1-tommaso.merciai@amarulasolutions.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Introduce pwm_dm_imx_get_parms, dm version of pwm_imx_get_parms. This function get clock rate using clk dm api Signed-off-by: Tommaso Merciai --- drivers/pwm/pwm-imx.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c index 429b57a423..c683909b2c 100644 --- a/drivers/pwm/pwm-imx.c +++ b/drivers/pwm/pwm-imx.c @@ -153,6 +153,36 @@ struct imx_pwm_priv { struct clk *ipg_clk; }; +int pwm_dm_imx_get_parms(struct imx_pwm_priv *priv, int period_ns, + int duty_ns, unsigned long *period_c, unsigned long *duty_c, + unsigned long *prescale) +{ + unsigned long long c; + + c = clk_get_rate(priv->per_clk); + c = c * period_ns; + do_div(c, 1000000000); + *period_c = c; + + *prescale = *period_c / 0x10000 + 1; + + *period_c /= *prescale; + c = *period_c * (unsigned long long)duty_ns; + do_div(c, period_ns); + *duty_c = c; + + /* + * according to imx pwm RM, the real period value should be + * PERIOD value in PWMPR plus 2. + */ + if (*period_c > 2) + *period_c -= 2; + else + *period_c = 0; + + return 0; +} + static int imx_pwm_set_invert(struct udevice *dev, uint channel, bool polarity) { @@ -173,7 +203,7 @@ static int imx_pwm_set_config(struct udevice *dev, uint channel, debug("%s: Config '%s' channel: %d\n", __func__, dev->name, channel); - pwm_imx_get_parms(period_ns, duty_ns, &period_cycles, &duty_cycles, + pwm_dm_imx_get_parms(priv, period_ns, duty_ns, &period_cycles, &duty_cycles, &prescale); return pwm_config_internal(regs, period_cycles, duty_cycles, prescale);