From patchwork Thu Apr 10 08:05:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Ying X-Patchwork-Id: 338004 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id BD29214009B for ; Thu, 10 Apr 2014 18:03:20 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965179AbaDJIDT (ORCPT ); Thu, 10 Apr 2014 04:03:19 -0400 Received: from co9ehsobe002.messaging.microsoft.com ([207.46.163.25]:1684 "EHLO co9outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965073AbaDJIDR (ORCPT ); Thu, 10 Apr 2014 04:03:17 -0400 Received: from mail168-co9-R.bigfish.com (10.236.132.232) by CO9EHSOBE026.bigfish.com (10.236.130.89) with Microsoft SMTP Server id 14.1.225.22; Thu, 10 Apr 2014 08:02:54 +0000 Received: from mail168-co9 (localhost [127.0.0.1]) by mail168-co9-R.bigfish.com (Postfix) with ESMTP id D5058AA010A; Thu, 10 Apr 2014 08:02:53 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1f42h2148h1ee6h1de0h1fdah2073h2146h1202h1e76h2189h1d1ah1d2ah21bch1fc6h208chzz1de098h8275bh8275dh1de097hz2dh2a8h839he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1b2fh2222h224fh1fb3h1d0ch1d2eh1d3fh1dc1h1dfeh1dffh1e23h1fe8h1ff5h2218h2216h226dh22d0h24afh2327h2336h2438h2461h2487h24d7h2516h2545h255eh25cch25f6h2605h268bh26d3h1155h) Received: from mail168-co9 (localhost.localdomain [127.0.0.1]) by mail168-co9 (MessageSwitch) id 1397116971362520_32424; Thu, 10 Apr 2014 08:02:51 +0000 (UTC) Received: from CO9EHSMHS007.bigfish.com (unknown [10.236.132.246]) by mail168-co9.bigfish.com (Postfix) with ESMTP id E18C3AC009D; Thu, 10 Apr 2014 08:02:34 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO9EHSMHS007.bigfish.com (10.236.130.17) with Microsoft SMTP Server (TLS) id 14.16.227.3; Thu, 10 Apr 2014 08:02:35 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-002.039d.mgd.msft.net (10.84.1.15) with Microsoft SMTP Server (TLS) id 14.3.174.2; Thu, 10 Apr 2014 08:02:56 +0000 Received: from victor.ap.freescale.net (victor.ap.freescale.net [10.192.241.62]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id s3A82r1I024144; Thu, 10 Apr 2014 01:02:54 -0700 From: Liu Ying To: CC: , , , Subject: [PATCH] pwm: i.MX: Avoid sample fifo overflow for i.MX pwm version2 Date: Thu, 10 Apr 2014 16:05:11 +0800 Message-ID: <1397117111-19306-1-git-send-email-Ying.Liu@freescale.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% X-FOPE-CONNECTOR: Id%0$Dn%FREESCALE.MAIL.ONMICROSOFT.COM$RO%1$TLS%0$FQDN%$TlsDn% Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org The i.MX pwm version2 is embedded in several i.MX SoCs, such as i.MX27, i.MX51 and i.MX6SL. There are four 16bit sample fifos in this IP, each of which determines the duty period of a PWM waveform in one full cycle. The IP spec mentions that we should not write a fourth sample because the fifo will become full and trigger a fifo write error(FWE) which will prevent the PWM from starting once it is enabled. In order to avoid any sample fifo overflow issue, this patch does software reset to clear all the sample fifos in the very beginning of the pwm configuration function. The fifo overflow issue can be reproduced by the following commands on the i.MX6SL evk platform, assuming we use pwm2 for the debug LED which is driven by the pin HSIC_STROBE and the maximal brightness is 255. echo 0 > /sys/class/leds/user/brightness echo 0 > /sys/class/leds/user/brightness echo 0 > /sys/class/leds/user/brightness echo 0 > /sys/class/leds/user/brightness echo 255 > /sys/class/leds/user/brightness Here, FWE happens(PWMSR register reads 0x58) and the LED can not be lighten. Cc: Sascha Hauer Cc: Shawn Guo Cc: linux-pwm@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Liu Ying --- drivers/pwm/pwm-imx.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c index cc47733..efdce53 100644 --- a/drivers/pwm/pwm-imx.c +++ b/drivers/pwm/pwm-imx.c @@ -38,6 +38,7 @@ #define MX3_PWMCR_DBGEN (1 << 22) #define MX3_PWMCR_CLKSRC_IPG_HIGH (2 << 16) #define MX3_PWMCR_CLKSRC_IPG (1 << 16) +#define MX3_PWMCR_SWR (1 << 3) #define MX3_PWMCR_EN (1 << 0) struct imx_chip { @@ -107,6 +108,12 @@ static int imx_pwm_config_v2(struct pwm_chip *chip, unsigned long period_cycles, duty_cycles, prescale; u32 cr; + /* do software reset in case fifo overflows */ + writel(MX3_PWMCR_SWR, imx->mmio_base + MX3_PWMCR); + do { + cr = readl(imx->mmio_base + MX3_PWMCR); + } while (cr & MX3_PWMCR_SWR); + c = clk_get_rate(imx->clk_per); c = c * period_ns; do_div(c, 1000000000);