From patchwork Fri Nov 8 08:45:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgUMOpcm9u?= X-Patchwork-Id: 11234315 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 40AB81599 for ; Fri, 8 Nov 2019 08:46:47 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0A5FE206DF for ; Fri, 8 Nov 2019 08:46:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="l1KUybme"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C1dyS/W0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0A5FE206DF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0XQz1t7FkBNq99EM7Xuub0BMjuAjKwgiOuXwb0YuioE=; b=l1KUybmeslMwX5 pqHLGNUdhnh1utYPEAu7hPDNNq6MbEoVeiz0ZtH3E3Qo41PYwCMGcFSBJlwVfVslhGAcqcJoPQewh UP0XEFPwGxXvbQF7t4ffTgA7Sih2X+09Old+7kL+Np7W7LQtgimd7ot/HmsNWcLb7yTJvyjBVj087 xq0WvaiHp8kg7K8Y9lcy64GpiP4qwLl7Md/tVPXl/AA7UTmPSrJxcrRTM1QESQy069rLTh3j9/5dd sASN0KY8PFVyL4izMz7NH1R3v8/sUb+lyA1tmh4aj++Y10dQwtDm1lMXE6PCZHY05dmlwP/N3N1ZH H28rK8xI4ycRNJhui0EA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iSzun-0006aO-NL; Fri, 08 Nov 2019 08:46:45 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iSztb-0005Jx-RW for linux-arm-kernel@lists.infradead.org; Fri, 08 Nov 2019 08:45:35 +0000 Received: by mail-wm1-x341.google.com with SMTP id z26so5261443wmi.4 for ; Fri, 08 Nov 2019 00:45:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o1BbTTGdSFKY2gKlnZB56hqOxy66kjY0LgiclhRJDv0=; b=C1dyS/W0NAlPRWhXtx8M04st3Ji81RU6NVq5t+9WHq97OdhgLePwxDGl3Cruq/vZPd DhMB3BDpQ9jyil8oXeLUcnBbpOhWwv0qM4eJ9r1DWxSVAXweAgSmuhTKrKoIW/UjqRB8 3iIe5/qXLUa7pNPl83YENVRzssGRhi4YaVcGmiVRgz7IBMqSAZAhijS+2p7GRQfbwuFk cl38aPIvbDXot2aNqlghO7DJoyJx3cor3VtsLCISWwWyl1arlRUPR4VUcxBxW+kfmzmf EV+V1LpkKB8obh/ddgEvSJ9UeBITSOTJAlg23+Lw9qzcOjOi6UY2ZlMHWRXoO0xS1W5/ t7Pw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=o1BbTTGdSFKY2gKlnZB56hqOxy66kjY0LgiclhRJDv0=; b=RYDISj0aWb8Yr4ZJwnB+oITSiagrg0eoj2QmcnIpqxYDYG714mg646hH9pzyJ2me2H rwzOLkUfrk5hkTkE/XvmG1idbN58um32lfxGxgFKi4gtpXxgFoNSclkdxf0RAAE56rVU plzLyN2zJsybQDUoynfpKg/qVD8+IANx0dpz+yCWGA3WX/7DbB4xv99eCMBT8HyRy5LV 9RPv/oWAhH6ytRLTFqr5DgPtDSyOGaw+sUKs9TfCMFCBJYJxgxUMVMoj8XiJR7mTG+UH ymBK9BV9RfmCsw57cHjpY2O9Ilu/HCnGQ2k6Dejs3MExZOhB+vRnbLI0wHJNNmd5NRJD 3ZEA== X-Gm-Message-State: APjAAAV83LySCOqGelNOsC/0JoqxFKVc2qYiLttjLmUPY/Z9CZQ672P8 PAVzchWkJopsgyrg37Yx3yE= X-Google-Smtp-Source: APXvYqxwBaxdGVAxdGG5OfhwPgDnJ/JZT/ybNdD4d2t31vpqkvY3E2BRG4vS88zywqSF6FNS60xWrQ== X-Received: by 2002:a1c:740a:: with SMTP id p10mr7053319wmc.121.1573202729584; Fri, 08 Nov 2019 00:45:29 -0800 (PST) Received: from clement-Latitude-7490.outsight.local (lputeaux-656-1-11-33.w82-127.abo.wanadoo.fr. [82.127.142.33]) by smtp.gmail.com with ESMTPSA id q25sm6662665wra.3.2019.11.08.00.45.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2019 00:45:29 -0800 (PST) From: =?utf-8?b?Q2zDqW1lbnQgUMOpcm9u?= To: Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6n?= =?utf-8?q?ig?= , Rob Herring , Mark Rutland , Maxime Ripard , Chen-Yu Tsai , Philipp Zabel Subject: [PATCH v4 4/7] pwm: sun4i: Add support to output source clock directly Date: Fri, 8 Nov 2019 09:45:14 +0100 Message-Id: <20191108084517.21617-5-peron.clem@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191108084517.21617-1-peron.clem@gmail.com> References: <20191108084517.21617-1-peron.clem@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191108_004531_899016_51DCFDB9 X-CRM114-Status: GOOD ( 16.42 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:341 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (peron.clem[at]gmail.com) -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, Jernej Skrabec , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, =?utf-8?b?Q2zDqW1lbnQgUMOpcm9u?= , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Jernej Skrabec PWM core has an option to bypass whole logic and output unchanged source clock as PWM output. This is achieved by enabling bypass bit. Note that when bypass is enabled, no other setting has any meaning, not even enable bit. This mode of operation is needed to achieve high enough frequency to serve as clock source for AC200 chip which is integrated into same package as H6 SoC. Signed-off-by: Jernej Skrabec Signed-off-by: Clément Péron --- drivers/pwm/pwm-sun4i.c | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c index a10022d6c0fd..9cc928ab47bc 100644 --- a/drivers/pwm/pwm-sun4i.c +++ b/drivers/pwm/pwm-sun4i.c @@ -3,6 +3,10 @@ * Driver for Allwinner sun4i Pulse Width Modulation Controller * * Copyright (C) 2014 Alexandre Belloni + * + * Limitations: + * - When outputing the source clock directly, the PWM logic will be bypassed + * and the currently running period is not guaranteed to be completed */ #include @@ -73,6 +77,7 @@ static const u32 prescaler_table[] = { struct sun4i_pwm_data { bool has_prescaler_bypass; + bool has_direct_mod_clk_output; unsigned int npwm; }; @@ -118,6 +123,20 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip, val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); + /* + * PWM chapter in H6 manual has a diagram which explains that if bypass + * bit is set, no other setting has any meaning. Even more, experiment + * proved that also enable bit is ignored in this case. + */ + if ((val & BIT_CH(PWM_BYPASS, pwm->hwpwm)) && + sun4i_pwm->data->has_direct_mod_clk_output) { + state->period = DIV_ROUND_UP_ULL(NSEC_PER_SEC, clk_rate); + state->duty_cycle = DIV_ROUND_UP_ULL(state->period, 2); + state->polarity = PWM_POLARITY_NORMAL; + state->enabled = true; + return; + } + if ((PWM_REG_PRESCAL(val, pwm->hwpwm) == PWM_PRESCAL_MASK) && sun4i_pwm->data->has_prescaler_bypass) prescaler = 1; @@ -204,6 +223,7 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, struct sun4i_pwm_chip *sun4i_pwm = to_sun4i_pwm_chip(chip); struct pwm_state cstate; u32 ctrl; + bool bypass = false; int ret; unsigned int delay_us; unsigned long now; @@ -218,9 +238,24 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, } } + /* + * Although it would make much more sense to check for bypass in + * sun4i_pwm_calculate(), value of bypass bit also depends on "enabled". + */ + if (state->enabled) { + u32 clk_rate = clk_get_rate(sun4i_pwm->clk); + bypass = (state->period * clk_rate >= NSEC_PER_SEC) && + (state->period * clk_rate < 2 * NSEC_PER_SEC) && + (state->duty_cycle * clk_rate * 2 >= NSEC_PER_SEC); + } + spin_lock(&sun4i_pwm->ctrl_lock); ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); + /* We can skip calculation and apply parameters */ + if (bypass && sun4i_pwm->data->has_direct_mod_clk_output) + goto bypass_mode; + if ((cstate.period != state->period) || (cstate.duty_cycle != state->duty_cycle)) { u32 period, duty, val; @@ -258,6 +293,7 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ctrl |= BIT_CH(PWM_ACT_STATE, pwm->hwpwm); ctrl |= BIT_CH(PWM_CLK_GATING, pwm->hwpwm); + if (state->enabled) { ctrl |= BIT_CH(PWM_EN, pwm->hwpwm); } else if (!sun4i_pwm->needs_delay[pwm->hwpwm]) { @@ -265,6 +301,14 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ctrl &= ~BIT_CH(PWM_CLK_GATING, pwm->hwpwm); } +bypass_mode: + if (sun4i_pwm->data->has_direct_mod_clk_output) { + if (bypass) + ctrl |= BIT_CH(PWM_BYPASS, pwm->hwpwm); + else + ctrl &= ~BIT_CH(PWM_BYPASS, pwm->hwpwm); + } + sun4i_pwm_writel(sun4i_pwm, ctrl, PWM_CTRL_REG); spin_unlock(&sun4i_pwm->ctrl_lock);