From patchwork Fri Feb 23 10:16:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 10237217 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 0C2C5602A0 for ; Fri, 23 Feb 2018 10:16:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF41F29501 for ; Fri, 23 Feb 2018 10:16:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3A8B29506; Fri, 23 Feb 2018 10:16:33 +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=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D57929501 for ; Fri, 23 Feb 2018 10:16:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750861AbeBWKQc (ORCPT ); Fri, 23 Feb 2018 05:16:32 -0500 Received: from eddie.linux-mips.org ([148.251.95.138]:47968 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751366AbeBWKQb (ORCPT ); Fri, 23 Feb 2018 05:16:31 -0500 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23991248AbeBWKQabgMkl (ORCPT + 1 other); Fri, 23 Feb 2018 11:16:30 +0100 Date: Fri, 23 Feb 2018 11:16:29 +0100 From: Ladislav Michl To: linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org Cc: Brecht Neyrinck , Keerthy , daniel.lezcano@linaro.org, thierry.reding@gmail.com, tony@atomide.com, aaro.koskinen@iki.fi, Claudiu.Beznea@microchip.com, narmstrong@baylibre.com, s-anna@ti.com, sebastian.reichel@collabora.co.uk, robh+dt@kernel.org, t-kristo@ti.com, grygorii.strashko@ti.com, Thomas Gleixner Subject: [PATCH 5/6] clocksource: timer-ti-dm: Add event capture Message-ID: <20180223101629.GF5746@lenoch> References: <20180223101254.GA5746@lenoch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180223101254.GA5746@lenoch> User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement event capture functions. Signed-off-by: Ladislav Michl --- drivers/clocksource/timer-ti-dm.c | 47 ++++++++++++++++++++++++++++-- include/linux/platform_data/dmtimer-omap.h | 8 +++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/drivers/clocksource/timer-ti-dm.c b/drivers/clocksource/timer-ti-dm.c index b57e875b74ca..c227d62794a0 100644 --- a/drivers/clocksource/timer-ti-dm.c +++ b/drivers/clocksource/timer-ti-dm.c @@ -576,8 +576,8 @@ static int omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload, } /* Optimized set_load which removes costly spin wait in timer_start */ -int omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload, - unsigned int load) +static int omap_dm_timer_set_load_start(struct omap_dm_timer *timer, + int autoreload, unsigned int load) { u32 l; @@ -627,6 +627,30 @@ static int omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable, return 0; } +static int omap_dm_timer_set_capture(struct omap_dm_timer *timer, + int captmode, int edges) +{ + u32 l; + + if (unlikely(!timer)) + return -EINVAL; + + omap_dm_timer_enable(timer); + l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); + l &= ~(OMAP_TIMER_CTRL_CAPTMODE | OMAP_TIMER_CTRL_SCPWM | + OMAP_TIMER_CTRL_PT | OMAP_TIMER_CTRL_TCM_BOTHEDGES); + l |= OMAP_TIMER_CTRL_GPOCFG; + if (captmode) + l |= OMAP_TIMER_CTRL_CAPTMODE; + l |= edges << 8; + omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); + + /* Save the context */ + timer->context.tclr = l; + omap_dm_timer_disable(timer); + return 0; +} + static int omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on, int toggle, int trigger) { @@ -785,6 +809,22 @@ int omap_dm_timers_active(void) return 0; } +static int omap_dm_timer_read_capture(struct omap_dm_timer *timer, + unsigned int *reg, + unsigned int *reg2) +{ + if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) { + pr_err("%s: timer not available or enabled.\n", __func__); + return -EINVAL; + } + + *reg = omap_dm_timer_read_reg(timer, OMAP_TIMER_CAPTURE_REG); + if (reg2) + *reg2 = omap_dm_timer_read_reg(timer, OMAP_TIMER_CAPTURE2_REG); + + return 0; +} + static const struct of_device_id omap_timer_match[]; /** @@ -930,11 +970,14 @@ const static struct omap_dm_timer_ops dmtimer_ops = { .start = omap_dm_timer_start, .stop = omap_dm_timer_stop, .set_load = omap_dm_timer_set_load, + .set_load_start = omap_dm_timer_set_load_start, .set_match = omap_dm_timer_set_match, + .set_capture = omap_dm_timer_set_capture, .set_pwm = omap_dm_timer_set_pwm, .set_prescaler = omap_dm_timer_set_prescaler, .read_counter = omap_dm_timer_read_counter, .write_counter = omap_dm_timer_write_counter, + .read_capture = omap_dm_timer_read_capture, .read_status = omap_dm_timer_read_status, .write_status = omap_dm_timer_write_status, }; diff --git a/include/linux/platform_data/dmtimer-omap.h b/include/linux/platform_data/dmtimer-omap.h index 757a0f9e26f9..7502f130b213 100644 --- a/include/linux/platform_data/dmtimer-omap.h +++ b/include/linux/platform_data/dmtimer-omap.h @@ -43,8 +43,12 @@ struct omap_dm_timer_ops { int (*set_load)(struct omap_dm_timer *timer, int autoreload, unsigned int value); + int (*set_load_start)(struct omap_dm_timer *timer, int autoreload, + unsigned int value); int (*set_match)(struct omap_dm_timer *timer, int enable, unsigned int match); + int (*set_capture)(struct omap_dm_timer *timer, int captmode, + int edges); int (*set_pwm)(struct omap_dm_timer *timer, int def_on, int toggle, int trigger); int (*set_prescaler)(struct omap_dm_timer *timer, int prescaler); @@ -52,6 +56,10 @@ struct omap_dm_timer_ops { unsigned int (*read_counter)(struct omap_dm_timer *timer); int (*write_counter)(struct omap_dm_timer *timer, unsigned int value); + + int (*read_capture)(struct omap_dm_timer *timer, unsigned int *reg, + unsigned int *reg2); + unsigned int (*read_status)(struct omap_dm_timer *timer); int (*write_status)(struct omap_dm_timer *timer, unsigned int value);