From patchwork Wed Jun 22 19:22:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivaylo Dimitrov X-Patchwork-Id: 9193583 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 63E196075A for ; Wed, 22 Jun 2016 19:25:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E4492840A for ; Wed, 22 Jun 2016 19:25:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4109C28415; Wed, 22 Jun 2016 19:25:43 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7E2CF2840A for ; Wed, 22 Jun 2016 19:25:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bFnl2-0001Bb-0x; Wed, 22 Jun 2016 19:24:16 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bFnkE-0000hx-6G for linux-arm-kernel@lists.infradead.org; Wed, 22 Jun 2016 19:23:28 +0000 Received: by mail-wm0-x243.google.com with SMTP id r201so4205071wme.0 for ; Wed, 22 Jun 2016 12:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ynZsDctT7E9sUA5XcsEnFtPb7T9xS3TBUqEJ8cHCkdo=; b=qEC8WZCWPfF4gsVwNatmaw+wg25awn9PyIwQa/uQZGV+mBNqfRBW8M/RV2RUFx/t3d qUSDT1QOQQ8bLcIZzVySesvvEAP5YRgkgDA8Upo+LA92Y/4gf3/fPaceyc6NQQBt484T yLufvdOHtow8riQXdEnlUtnIzaqwArM+onY5zTpww30AA2ZrECnILr6ac/G2t9cAoueQ CeZhiFV0d5BuLcIcPOClRpKn582RS9Kfabo0Rwhin48N1DsvwJ+HScg12bBwRiQ6NqYg vOzncaGld+XPO7aI/IeJlXFyDH63pHbvegq/FaFhAYtY/ntkDSoZZOxTtwiZVzEXplRb W1wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ynZsDctT7E9sUA5XcsEnFtPb7T9xS3TBUqEJ8cHCkdo=; b=SppOMlQytiPVr9r3HEIsFtHrLWc/cnfRmNL7zTtgsEfMKORk9mKTWBzYeauNwMk9D+ x0u/KokQma6Sl5Oo6Vva8MQvNlFSKGs+gSiQwNgLuH+8N0KtL3bJk3HeLcshuyRUlhz9 jLOjXvMjfOQdWQ42G53Xwthv0+1AKKUokA+MCHLVwUYoKAyXFt35aDxRs/5xuX7YTKwM jUuVMINOOssXQA0t58idcK1B60hxrmKR6FtbXurgrW8RI2edtGzTvq9JIpOiJZ+ZVy/2 j5jJ01u192OYMCQnN6EP5PMIqZ0ANGYE5oIHVyZqwuhGMUuCcn/kAurIOYCnOcbNxuPR NbWg== X-Gm-Message-State: ALyK8tK2/6DfvXDXasy/+a5l+iV50I9t1t96wUJ/wvAvbXjZbYOzM/h3JTPtdGZYg5T9jg== X-Received: by 10.194.168.225 with SMTP id zz1mr14247239wjb.114.1466623384043; Wed, 22 Jun 2016 12:23:04 -0700 (PDT) Received: from localhost.localdomain ([46.249.74.23]) by smtp.gmail.com with ESMTPSA id b200sm265952wmb.9.2016.06.22.12.23.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Jun 2016 12:23:03 -0700 (PDT) From: Ivaylo Dimitrov To: robh+dt@kernel.org, mark.rutland@arm.com, ijc+devicetree@hellion.org.uk, galak@codeaurora.org, thierry.reding@gmail.com, bcousson@baylibre.com, tony@atomide.com, linux@arm.linux.org.uk, mchehab@osg.samsung.com Subject: [RESEND PATCH v2 5/5] ir-rx51: use hrtimer instead of dmtimer Date: Wed, 22 Jun 2016 22:22:21 +0300 Message-Id: <1466623341-30130-6-git-send-email-ivo.g.dimitrov.75@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466623341-30130-1-git-send-email-ivo.g.dimitrov.75@gmail.com> References: <1466623341-30130-1-git-send-email-ivo.g.dimitrov.75@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160622_122326_576712_BDC0129C X-CRM114-Status: GOOD ( 20.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Ivaylo Dimitrov , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, sre@kernel.org, pavel@ucw.cz, pali.rohar@gmail.com, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org MIME-Version: 1.0 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 Drop dmtimer usage for pulse timer in favor of hrtimer. That allows removing PWM dmitimer platform data usage. Signed-off-by: Ivaylo Dimitrov --- arch/arm/mach-omap2/board-rx51-peripherals.c | 4 - arch/arm/mach-omap2/pdata-quirks.c | 3 - drivers/media/rc/ir-rx51.c | 166 ++++++--------------------- include/linux/platform_data/media/ir-rx51.h | 1 - 4 files changed, 37 insertions(+), 137 deletions(-) diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c index e487575..a5ab712 100644 --- a/arch/arm/mach-omap2/board-rx51-peripherals.c +++ b/arch/arm/mach-omap2/board-rx51-peripherals.c @@ -1242,10 +1242,6 @@ static struct pwm_omap_dmtimer_pdata __maybe_unused pwm_dmtimer_pdata = { #if defined(CONFIG_IR_RX51) || defined(CONFIG_IR_RX51_MODULE) static struct lirc_rx51_platform_data rx51_lirc_data = { .set_max_mpu_wakeup_lat = omap_pm_set_max_mpu_wakeup_lat, -#if IS_ENABLED(CONFIG_OMAP_DM_TIMER) - .dmtimer = &pwm_dmtimer_pdata, -#endif - }; static struct platform_device rx51_lirc_device = { diff --git a/arch/arm/mach-omap2/pdata-quirks.c b/arch/arm/mach-omap2/pdata-quirks.c index 0d7b05a..7cc672b 100644 --- a/arch/arm/mach-omap2/pdata-quirks.c +++ b/arch/arm/mach-omap2/pdata-quirks.c @@ -486,9 +486,6 @@ static struct pwm_omap_dmtimer_pdata pwm_dmtimer_pdata = { static struct lirc_rx51_platform_data __maybe_unused rx51_lirc_data = { .set_max_mpu_wakeup_lat = omap_pm_set_max_mpu_wakeup_lat, -#if IS_ENABLED(CONFIG_OMAP_DM_TIMER) - .dmtimer = &pwm_dmtimer_pdata, -#endif }; static struct platform_device __maybe_unused rx51_lirc_device = { diff --git a/drivers/media/rc/ir-rx51.c b/drivers/media/rc/ir-rx51.c index 1cbb43d..82fb6f2 100644 --- a/drivers/media/rc/ir-rx51.c +++ b/drivers/media/rc/ir-rx51.c @@ -22,10 +22,10 @@ #include #include #include +#include #include #include -#include #include #define LIRC_RX51_DRIVER_FEATURES (LIRC_CAN_SET_SEND_DUTY_CYCLE | \ @@ -36,32 +36,26 @@ #define WBUF_LEN 256 -#define TIMER_MAX_VALUE 0xffffffff - struct lirc_rx51 { struct pwm_device *pwm; - pwm_omap_dmtimer *pulse_timer; - struct pwm_omap_dmtimer_pdata *dmtimer; + struct hrtimer timer; struct device *dev; struct lirc_rx51_platform_data *pdata; wait_queue_head_t wqueue; - unsigned long fclk_khz; unsigned int freq; /* carrier frequency */ unsigned int duty_cycle; /* carrier duty cycle */ - unsigned int irq_num; - unsigned int match; int wbuf[WBUF_LEN]; int wbuf_index; unsigned long device_is_open; }; -static void lirc_rx51_on(struct lirc_rx51 *lirc_rx51) +static inline void lirc_rx51_on(struct lirc_rx51 *lirc_rx51) { pwm_enable(lirc_rx51->pwm); } -static void lirc_rx51_off(struct lirc_rx51 *lirc_rx51) +static inline void lirc_rx51_off(struct lirc_rx51 *lirc_rx51) { pwm_disable(lirc_rx51->pwm); } @@ -72,61 +66,21 @@ static int init_timing_params(struct lirc_rx51 *lirc_rx51) int duty, period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, lirc_rx51->freq); duty = DIV_ROUND_CLOSEST(lirc_rx51->duty_cycle * period, 100); - lirc_rx51->dmtimer->set_int_enable(lirc_rx51->pulse_timer, 0); pwm_config(pwm, duty, period); - lirc_rx51->dmtimer->start(lirc_rx51->pulse_timer); - - lirc_rx51->match = 0; - return 0; } -#define tics_after(a, b) ((long)(b) - (long)(a) < 0) - -static int pulse_timer_set_timeout(struct lirc_rx51 *lirc_rx51, int usec) +static enum hrtimer_restart lirc_rx51_timer_cb(struct hrtimer *timer) { - int counter; - - BUG_ON(usec < 0); - - if (lirc_rx51->match == 0) - counter = lirc_rx51->dmtimer->read_counter(lirc_rx51->pulse_timer); - else - counter = lirc_rx51->match; - - counter += (u32)(lirc_rx51->fclk_khz * usec / (1000)); - lirc_rx51->dmtimer->set_match(lirc_rx51->pulse_timer, 1, counter); - lirc_rx51->dmtimer->set_int_enable(lirc_rx51->pulse_timer, - PWM_OMAP_DMTIMER_INT_MATCH); - if (tics_after(lirc_rx51->dmtimer->read_counter(lirc_rx51->pulse_timer), - counter)) { - return 1; - } - return 0; -} + struct lirc_rx51 *lirc_rx51 = + container_of(timer, struct lirc_rx51, timer); + ktime_t now; -static irqreturn_t lirc_rx51_interrupt_handler(int irq, void *ptr) -{ - unsigned int retval; - struct lirc_rx51 *lirc_rx51 = ptr; - - retval = lirc_rx51->dmtimer->read_status(lirc_rx51->pulse_timer); - if (!retval) - return IRQ_NONE; - - if (retval & ~PWM_OMAP_DMTIMER_INT_MATCH) - dev_err_ratelimited(lirc_rx51->dev, - ": Unexpected interrupt source: %x\n", retval); - - lirc_rx51->dmtimer->write_status(lirc_rx51->pulse_timer, - PWM_OMAP_DMTIMER_INT_MATCH | - PWM_OMAP_DMTIMER_INT_OVERFLOW | - PWM_OMAP_DMTIMER_INT_CAPTURE); if (lirc_rx51->wbuf_index < 0) { dev_err_ratelimited(lirc_rx51->dev, - ": BUG wbuf_index has value of %i\n", + "BUG wbuf_index has value of %i\n", lirc_rx51->wbuf_index); goto end; } @@ -136,6 +90,8 @@ static irqreturn_t lirc_rx51_interrupt_handler(int irq, void *ptr) * pulses until we catch up. */ do { + u64 ns; + if (lirc_rx51->wbuf_index >= WBUF_LEN) goto end; if (lirc_rx51->wbuf[lirc_rx51->wbuf_index] == -1) @@ -146,80 +102,24 @@ static irqreturn_t lirc_rx51_interrupt_handler(int irq, void *ptr) else lirc_rx51_on(lirc_rx51); - retval = pulse_timer_set_timeout(lirc_rx51, - lirc_rx51->wbuf[lirc_rx51->wbuf_index]); + ns = 1000 * lirc_rx51->wbuf[lirc_rx51->wbuf_index]; + hrtimer_add_expires_ns(timer, ns); + lirc_rx51->wbuf_index++; - } while (retval); + now = timer->base->get_time(); + + } while (hrtimer_get_expires_tv64(timer) < now.tv64); - return IRQ_HANDLED; + return HRTIMER_RESTART; end: /* Stop TX here */ lirc_rx51_off(lirc_rx51); lirc_rx51->wbuf_index = -1; - lirc_rx51->dmtimer->stop(lirc_rx51->pulse_timer); - lirc_rx51->dmtimer->set_int_enable(lirc_rx51->pulse_timer, 0); wake_up_interruptible(&lirc_rx51->wqueue); - return IRQ_HANDLED; -} - -static int lirc_rx51_init_port(struct lirc_rx51 *lirc_rx51) -{ - struct clk *clk_fclk; - int retval; - - lirc_rx51->pwm = pwm_get(lirc_rx51->dev, NULL); - if (IS_ERR(lirc_rx51->pwm)) { - retval = PTR_ERR(lirc_rx51->pwm); - dev_err(lirc_rx51->dev, ": pwm_get failed: %d\n", retval); - return retval; - } - - lirc_rx51->pulse_timer = lirc_rx51->dmtimer->request(); - if (lirc_rx51->pulse_timer == NULL) { - dev_err(lirc_rx51->dev, ": Error requesting pulse timer\n"); - retval = -EBUSY; - goto err1; - } - - lirc_rx51->dmtimer->set_source(lirc_rx51->pulse_timer, - PWM_OMAP_DMTIMER_SRC_SYS_CLK); - lirc_rx51->dmtimer->enable(lirc_rx51->pulse_timer); - lirc_rx51->irq_num = - lirc_rx51->dmtimer->get_irq(lirc_rx51->pulse_timer); - retval = request_irq(lirc_rx51->irq_num, lirc_rx51_interrupt_handler, - IRQF_SHARED, "lirc_pulse_timer", lirc_rx51); - if (retval) { - dev_err(lirc_rx51->dev, ": Failed to request interrupt line\n"); - goto err2; - } - - clk_fclk = lirc_rx51->dmtimer->get_fclk(lirc_rx51->pulse_timer); - lirc_rx51->fclk_khz = clk_get_rate(clk_fclk) / 1000; - - return 0; - -err2: - lirc_rx51->dmtimer->free(lirc_rx51->pulse_timer); -err1: - pwm_put(lirc_rx51->pwm); - - return retval; -} - -static int lirc_rx51_free_port(struct lirc_rx51 *lirc_rx51) -{ - lirc_rx51->dmtimer->set_int_enable(lirc_rx51->pulse_timer, 0); - free_irq(lirc_rx51->irq_num, lirc_rx51); - lirc_rx51_off(lirc_rx51); - lirc_rx51->dmtimer->disable(lirc_rx51->pulse_timer); - lirc_rx51->dmtimer->free(lirc_rx51->pulse_timer); - lirc_rx51->wbuf_index = -1; - pwm_put(lirc_rx51->pwm); - - return 0; + return HRTIMER_NORESTART; } static ssize_t lirc_rx51_write(struct file *file, const char *buf, @@ -258,8 +158,9 @@ static ssize_t lirc_rx51_write(struct file *file, const char *buf, lirc_rx51_on(lirc_rx51); lirc_rx51->wbuf_index = 1; - pulse_timer_set_timeout(lirc_rx51, lirc_rx51->wbuf[0]); - + hrtimer_start(&lirc_rx51->timer, + ns_to_ktime(1000 * lirc_rx51->wbuf[0]), + HRTIMER_MODE_REL); /* * Don't return back to the userspace until the transfer has * finished @@ -359,14 +260,24 @@ static int lirc_rx51_open(struct inode *inode, struct file *file) if (test_and_set_bit(1, &lirc_rx51->device_is_open)) return -EBUSY; - return lirc_rx51_init_port(lirc_rx51); + lirc_rx51->pwm = pwm_get(lirc_rx51->dev, NULL); + if (IS_ERR(lirc_rx51->pwm)) { + int res = PTR_ERR(lirc_rx51->pwm); + + dev_err(lirc_rx51->dev, "pwm_get failed: %d\n", res); + return res; + } + + return 0; } static int lirc_rx51_release(struct inode *inode, struct file *file) { struct lirc_rx51 *lirc_rx51 = file->private_data; - lirc_rx51_free_port(lirc_rx51); + hrtimer_cancel(&lirc_rx51->timer); + lirc_rx51_off(lirc_rx51); + pwm_put(lirc_rx51->pwm); clear_bit(1, &lirc_rx51->device_is_open); @@ -441,11 +352,6 @@ static int lirc_rx51_probe(struct platform_device *dev) return -ENXIO; } - if (!lirc_rx51.pdata->dmtimer) { - dev_err(&dev->dev, "no dmtimer?\n"); - return -ENODEV; - } - pwm = pwm_get(&dev->dev, NULL); if (IS_ERR(pwm)) { int err = PTR_ERR(pwm); @@ -459,7 +365,9 @@ static int lirc_rx51_probe(struct platform_device *dev) lirc_rx51.freq = DIV_ROUND_CLOSEST(pwm_get_period(pwm), NSEC_PER_SEC); pwm_put(pwm); - lirc_rx51.dmtimer = lirc_rx51.pdata->dmtimer; + hrtimer_init(&lirc_rx51.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + lirc_rx51.timer.function = lirc_rx51_timer_cb; + lirc_rx51.dev = &dev->dev; lirc_rx51_driver.dev = &dev->dev; lirc_rx51_driver.minor = lirc_register_driver(&lirc_rx51_driver); diff --git a/include/linux/platform_data/media/ir-rx51.h b/include/linux/platform_data/media/ir-rx51.h index 6acf22d..812d873 100644 --- a/include/linux/platform_data/media/ir-rx51.h +++ b/include/linux/platform_data/media/ir-rx51.h @@ -3,7 +3,6 @@ struct lirc_rx51_platform_data { int(*set_max_mpu_wakeup_lat)(struct device *dev, long t); - struct pwm_omap_dmtimer_pdata *dmtimer; }; #endif