From patchwork Fri Feb 23 10:12:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 10237195 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7ECD560209 for ; Fri, 23 Feb 2018 10:13:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B7E3294FB for ; Fri, 23 Feb 2018 10:13:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 501BF294FF; Fri, 23 Feb 2018 10:13:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BB2AB294FB for ; Fri, 23 Feb 2018 10:13:21 +0000 (UTC) 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:Message-ID:Subject:To:From :Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=FCrjCBy14mN8VO12JvQaxzHyeRdBGYBal6IEvD1vPQk=; b=SLkLhYZpWgVX9k r8dyubSXRLXZipeWutXQ7pYB5ac7rkfBFIuImMV297SYCH3GGPwk8tAjCt5kV6kS6+YnGx0OWZwKF Gf3U2OSUyFV4QCVhvEf5UT3PAqR3YP1VkNg6i6tNFe0KUHLUdJGUnjAYsb9rxDVZjePXJUqacDRd7 2lU3ZAG71pJTCupCUWmR6j/DefyyIRW7hQImxUgCbP3CAfIeXDWigbC+cNrLLhYkZGL1VZN8ZxHKP Rxm7gK2JVi6PA7dKOfwo33rU42CZdmpO0ZwFF9rZZ20lUluWqKnbILHToOGNI4U4B2P1R4ueSJhVy EAlx0NgSy02H4RMz8DwA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1epALo-0006Is-BO; Fri, 23 Feb 2018 10:13:12 +0000 Received: from eddie.linux-mips.org ([148.251.95.138] helo=cvs.linux-mips.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1epALj-0006Hc-V7 for linux-arm-kernel@lists.infradead.org; Fri, 23 Feb 2018 10:13:10 +0000 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23990723AbeBWKMzDbaZl (ORCPT ); Fri, 23 Feb 2018 11:12:55 +0100 Date: Fri, 23 Feb 2018 11:12:54 +0100 From: Ladislav Michl To: linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org Subject: [PATCH 0/6] Implement event capture for OMAP (draft) Message-ID: <20180223101254.GA5746@lenoch> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.3 (2018-01-21) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180223_021308_051624_7DE833B6 X-CRM114-Status: GOOD ( 11.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: t-kristo@ti.com, grygorii.strashko@ti.com, aaro.koskinen@iki.fi, tony@atomide.com, Keerthy , daniel.lezcano@linaro.org, robh+dt@kernel.org, narmstrong@baylibre.com, thierry.reding@gmail.com, Brecht Neyrinck , sebastian.reichel@collabora.co.uk, Thomas Gleixner , Claudiu.Beznea@microchip.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, this patchset based on next-20180223 first cleans up playground (patches 1-4 which I'd appreciate to be reviewed and merged eventually) and then adds event capture functionality which is just good for doing: $ echo 0 > /sys/class/pwm/pwmchip4/export $ cat /sys/class/pwm/pwmchip4/pwm0/capture 1000000 500000 $ cat /sys/class/pwm/pwmchip4/pwm0/capture 100000 50000 $ cat /sys/class/pwm/pwmchip4/pwm0/capture 100000 75000 Above measured frequencies are 1kHz and 10kHz with 50% duty cycle, the last one is with 75% duty cycle. However with 100kHz it sometimes ends with: $ cat /sys/class/pwm/pwmchip4/pwm0/capture omap_dm_timer_read_status: timer not available or enabled. 12462 6231 So locking is probably not done right, therefore patches 5 and 6 are sent only for reference, as there's also another fundamental problem: Hardware can be told to capture both edges, but there's no way to tell it which one should be captured first. Other posibility would be first configure for rising edge and reconfigure in interrupt for falling one. Here we meet latency problem again: https://www.spinics.net/lists/linux-omap/msg140081.html Attached test patch shows average diff around 150us (sometimes over 300us) which pretty much limits maximum measurable frequency. I tried to misuse PM_QOS_CPU_DMA_LATENCY to overcome latency issue, but with no luck. Ladislav Michl (6): clocksource: timer-ti-dm: Make unexported functions static clocksource: timer-ti-dm: Consolidate set source clocksource: timer-ti-dm: Check prescaler value pwm: pwm-omap-dmtimer: Fix frequency when using prescaler clocksource: timer-ti-dm: Add event capture pwm: pwm-omap-dmtimer: Add capture functionality drivers/clocksource/timer-ti-dm.c | 263 ++++++++++++++++------------- drivers/pwm/pwm-omap-dmtimer.c | 220 +++++++++++++++++++----- include/clocksource/timer-ti-dm.h | 33 ---- include/linux/platform_data/dmtimer-omap.h | 8 + 4 files changed, 340 insertions(+), 184 deletions(-) Latency test patch: diff --git a/drivers/pwm/pwm-omap-dmtimer.c b/drivers/pwm/pwm-omap-dmtimer.c index 5a2fc0e0a1c5..c1a94740079a 100644 --- a/drivers/pwm/pwm-omap-dmtimer.c +++ b/drivers/pwm/pwm-omap-dmtimer.c @@ -46,7 +46,7 @@ struct pwm_omap_dmtimer_chip { const struct omap_dm_timer_ops *pdata; struct platform_device *dm_timer_pdev; unsigned long freq; - unsigned int ev_cnt, overflow, width; + unsigned int ev_cnt, overflow, width, counter_irq, counter_captured; }; static inline struct pwm_omap_dmtimer_chip * @@ -280,6 +280,8 @@ static int pwm_omap_dmtimer_capture(struct pwm_chip *chip, omap->ev_cnt = omap->width = 0; spin_unlock_irqrestore(&omap->lock, flags); + printk("diff: %d\n", pwm_omap_dmtimer_ticks_to_ns(omap, omap->counter_irq - omap->counter_captured)); + res = wait_event_interruptible_timeout(omap->wait, omap->width > 0, timeout); @@ -317,6 +319,8 @@ static irqreturn_t pwm_omap_dmtimer_irq(int irq, void *dev_id) if (l & OMAP_TIMER_INT_CAPTURE) { if (!omap->width && omap->ev_cnt == 1) { omap->pdata->read_capture(omap->dm_timer, &c1, &c2); + omap->counter_irq = omap->pdata->read_counter(omap->dm_timer); + omap->counter_captured = c2; omap->width = pwm_omap_dmtimer_get_width(omap, c1, c2); wake_up(&omap->wait); }