From patchwork Mon Feb 7 21:16:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Roberto Jimenez X-Patchwork-Id: 82154 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-gx0-f184.google.com (mail-gx0-f184.google.com [209.85.161.184]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id C4166B711B for ; Tue, 8 Feb 2011 08:17:19 +1100 (EST) Received: by gxk6 with SMTP id 6sf3137083gxk.11 for ; Mon, 07 Feb 2011 13:17:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:mime-version:x-beenthere:received-spf:from:to :cc:subject:date:message-id:x-mailer:in-reply-to:references :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :sender:list-subscribe:list-unsubscribe:content-type; bh=J8tgTqK8+jLoVVgMCa35W3HmEdMJmeQXi/pPPSWUw6s=; b=bjqX0Ag80Uornj2Z+t7vEyg4YPtkgLijSX0s8dlP4AHLDQpsAOr/3VDG2VtmbMEnN4 OSpI+90fqhum7180VckjKK/63OgoXNTvECGtowpyfXS9vF7/SvjNGY5+4bTBMmIQ2Fkc JaET7i7dtsMqRqMLe940DXgniBaijMYsm+naw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=mime-version:x-beenthere:received-spf:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:sender:list-subscribe :list-unsubscribe:content-type; b=ciShNrw1Xju1LlABVQmhy3dvmPZns3yea5P9v3s0rWeJXfGXyrZKuQnLRBfiuyDym9 5VVbHQoBmBfqhqmV804MLpcJlAjg7y5SkyvJe8JA1HhbZ48A5dFu4hM3hXcTQuGk5+Ac aBlHydlxNQrZtv2PPnXoN/emmyATeZ8SfuWsM= Received: by 10.101.180.30 with SMTP id h30mr595394anp.6.1297113435279; Mon, 07 Feb 2011 13:17:15 -0800 (PST) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.100.56.38 with SMTP id e38ls1122408ana.3.p; Mon, 07 Feb 2011 13:17:15 -0800 (PST) Received: by 10.100.42.8 with SMTP id p8mr3454027anp.48.1297113434986; Mon, 07 Feb 2011 13:17:14 -0800 (PST) Received: by 10.100.42.8 with SMTP id p8mr3454026anp.48.1297113434945; Mon, 07 Feb 2011 13:17:14 -0800 (PST) Received: from mail-yw0-f47.google.com (mail-yw0-f47.google.com [209.85.213.47]) by gmr-mx.google.com with ESMTPS id i35si1977804anh.10.2011.02.07.13.17.14 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 07 Feb 2011 13:17:14 -0800 (PST) Received-SPF: neutral (google.com: 209.85.213.47 is neither permitted nor denied by best guess record for domain of mroberto@cpti.cetuc.puc-rio.br) client-ip=209.85.213.47; Received: by mail-yw0-f47.google.com with SMTP id 6so2150970ywi.20 for ; Mon, 07 Feb 2011 13:17:14 -0800 (PST) Received: by 10.147.32.2 with SMTP id k2mr5582152yaj.37.1297113434732; Mon, 07 Feb 2011 13:17:14 -0800 (PST) Received: from localhost.localdomain ([139.82.178.36]) by mx.google.com with ESMTPS id m49sm3208519yha.2.2011.02.07.13.17.12 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 07 Feb 2011 13:17:14 -0800 (PST) From: Marcelo Roberto Jimenez To: linux-kernel@vger.kernel.org, rtc-linux@googlegroups.com, linux@arm.linux.org.uk Cc: john.stultz@linaro.org, tglx@linutronix.de, a.zummo@towertech.it, Marcelo Roberto Jimenez Subject: [rtc-linux] [PATCH 4/4] RTC: sa1100: Update the sa1100 RTC driver. Date: Mon, 7 Feb 2011 19:16:08 -0200 Message-Id: <1297113368-27174-5-git-send-email-mroberto@cpti.cetuc.puc-rio.br> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1297113368-27174-1-git-send-email-mroberto@cpti.cetuc.puc-rio.br> References: <1297113368-27174-1-git-send-email-mroberto@cpti.cetuc.puc-rio.br> X-Original-Sender: mroberto@cpti.cetuc.puc-rio.br X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 209.85.213.47 is neither permitted nor denied by best guess record for domain of mroberto@cpti.cetuc.puc-rio.br) smtp.mail=mroberto@cpti.cetuc.puc-rio.br Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , Since PIE interrupts are now emulated, this patch removes the previous code that used the hardware counters. The removal of read_callback() also fixes a wrong user space behaviour of this driver, which was not returning the right value to read(). Signed-off-by: Marcelo Roberto Jimenez --- drivers/rtc/rtc-sa1100.c | 111 +-------------------------------------------- 1 files changed, 3 insertions(+), 108 deletions(-) diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c index 6c8c74a..1ff0fac 100644 --- a/drivers/rtc/rtc-sa1100.c +++ b/drivers/rtc/rtc-sa1100.c @@ -43,7 +43,6 @@ #define RTC_DEF_TRIM 0 static const unsigned long RTC_FREQ = 1024; -static unsigned long timer_freq; static struct rtc_time rtc_alarm; static DEFINE_SPINLOCK(sa1100_rtc_lock); @@ -156,97 +155,11 @@ static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } -static int sa1100_irq_set_freq(struct device *dev, int freq) -{ - if (freq < 1 || freq > timer_freq) { - return -EINVAL; - } else { - struct rtc_device *rtc = (struct rtc_device *)dev; - - rtc->irq_freq = freq; - - return 0; - } -} - -static int rtc_timer1_count; - -static inline int sa1100_timer1_retrigger(struct rtc_device *rtc) -{ - unsigned long diff; - unsigned long period = timer_freq / rtc->irq_freq; - - spin_lock_irq(&sa1100_rtc_lock); - - do { - OSMR1 += period; - diff = OSMR1 - OSCR; - /* If OSCR > OSMR1, diff is a very large number (unsigned - * math). This means we have a lost interrupt. */ - } while (diff > period); - OIER |= OIER_E1; - - spin_unlock_irq(&sa1100_rtc_lock); - - return 0; -} - -static irqreturn_t timer1_interrupt(int irq, void *dev_id) -{ - struct platform_device *pdev = to_platform_device(dev_id); - struct rtc_device *rtc = platform_get_drvdata(pdev); - - /* - * If we match for the first time, rtc_timer1_count will be 1. - * Otherwise, we wrapped around (very unlikely but - * still possible) so compute the amount of missed periods. - * The match reg is updated only when the data is actually retrieved - * to avoid unnecessary interrupts. - */ - OSSR = OSSR_M1; /* clear match on timer1 */ - - rtc_update_irq(rtc, rtc_timer1_count, RTC_PF | RTC_IRQF); - - if (rtc_timer1_count == 1) - rtc_timer1_count = - (rtc->irq_freq * ((1 << 30) / (timer_freq >> 2))); - - /* retrigger. */ - sa1100_timer1_retrigger(rtc); - - return IRQ_HANDLED; -} - -static int sa1100_rtc_read_callback(struct device *dev, int data) -{ - if (data & RTC_PF) { - struct rtc_device *rtc = (struct rtc_device *)dev; - - /* interpolate missed periods and set match for the next */ - unsigned long period = timer_freq / rtc->irq_freq; - unsigned long oscr = OSCR; - unsigned long osmr1 = OSMR1; - unsigned long missed = (oscr - osmr1)/period; - data += missed << 8; - OSSR = OSSR_M1; /* clear match on timer 1 */ - OSMR1 = osmr1 + (missed + 1)*period; - /* Ensure we didn't miss another match in the mean time. - * Here we compare (match - OSCR) 8 instead of 0 -- - * see comment in pxa_timer_interrupt() for explanation. - */ - while ((signed long)((osmr1 = OSMR1) - OSCR) <= 8) { - data += 0x100; - OSSR = OSSR_M1; /* clear match on timer 1 */ - OSMR1 = osmr1 + period; - } - } - return data; -} - static int sa1100_rtc_open(struct device *dev) { int ret; - struct rtc_device *rtc = (struct rtc_device *)dev; + struct platform_device *plat_dev = to_platform_device(dev); + struct rtc_device *rtc = platform_get_drvdata(plat_dev); ret = request_irq(IRQ_RTC1Hz, sa1100_rtc_interrupt, IRQF_DISABLED, "rtc 1Hz", dev); @@ -260,19 +173,11 @@ static int sa1100_rtc_open(struct device *dev) dev_err(dev, "IRQ %d already in use.\n", IRQ_RTCAlrm); goto fail_ai; } - ret = request_irq(IRQ_OST1, timer1_interrupt, IRQF_DISABLED, - "rtc timer", dev); - if (ret) { - dev_err(dev, "IRQ %d already in use.\n", IRQ_OST1); - goto fail_pi; - } rtc->max_user_freq = RTC_FREQ; - sa1100_irq_set_freq(dev, RTC_FREQ); + rtc_irq_set_freq(rtc, NULL, RTC_FREQ); return 0; - fail_pi: - free_irq(IRQ_RTCAlrm, dev); fail_ai: free_irq(IRQ_RTC1Hz, dev); fail_ui: @@ -287,12 +192,10 @@ static void sa1100_rtc_release(struct device *dev) OSSR = OSSR_M1; spin_unlock_irq(&sa1100_rtc_lock); - free_irq(IRQ_OST1, dev); free_irq(IRQ_RTCAlrm, dev); free_irq(IRQ_RTC1Hz, dev); } - static int sa1100_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) { @@ -366,7 +269,6 @@ static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq) static const struct rtc_class_ops sa1100_rtc_ops = { .open = sa1100_rtc_open, - .read_callback = sa1100_rtc_read_callback, .release = sa1100_rtc_release, .ioctl = sa1100_rtc_ioctl, .read_time = sa1100_rtc_read_time, @@ -380,8 +282,6 @@ static int sa1100_rtc_probe(struct platform_device *pdev) { struct rtc_device *rtc; - timer_freq = get_clock_tick_rate(); - /* * According to the manual we should be able to let RTTR be zero * and then a default diviser for a 32.768KHz clock is used. @@ -407,11 +307,6 @@ static int sa1100_rtc_probe(struct platform_device *pdev) platform_set_drvdata(pdev, rtc); - /* Set the irq_freq */ - /*TODO: Find out who is messing with this value after we initialize - * it here.*/ - rtc->irq_freq = RTC_FREQ; - /* Fix for a nasty initialization problem the in SA11xx RTSR register. * See also the comments in sa1100_rtc_interrupt(). *