From patchwork Mon Mar 4 14:05:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffen Trumtrar X-Patchwork-Id: 224738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-la0-x23f.google.com (mail-la0-x23f.google.com [IPv6:2a00:1450:4010:c03::23f]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 55F272C034A for ; Tue, 5 Mar 2013 01:06:51 +1100 (EST) Received: by mail-la0-f63.google.com with SMTP id ec20sf1864831lab.8 for ; Mon, 04 Mar 2013 06:06:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=x-received:mime-version:x-beenthere:x-received:x-received :received-spf:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-sa-exim-connect-ip:x-sa-exim-mail-from :x-sa-exim-scanned:x-ptx-original-recipient:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=fgNRa2u5TxhlUwaety3QcJaGRhQWHTCtof73hb18kdU=; b=D7AF662zgyywI81t70q24XnkKvDEmqVdDlSN0MZllixVhxPkmArNaoHNAIC7TcozXC LILaTjKMkNDAKf5PLOnvEQ5SrwV6hLnowPRiZgetPk6BtBuFxLcMS6JsCubqL+NbyYuk XaAj1WRtqQ0zsXmAIEUP4+0+CAoNdDURxre7X4IIKES+KedJcL8ZfuVHZEbvXcexHMTO 8k9JbNohDuce3DaUDf48I3DdaJiWUhehtACI43o+V9zNB25cJxO2VL9KVShUrmDgSVrt 9oKJSuh90fjB5tpIzyheyEGS4bF21d7IcbedVKGd9nWZI+UXw5oFe6/4rLKcG+29TQzu 21pA== X-Received: by 10.180.75.82 with SMTP id a18mr631241wiw.16.1362406008272; Mon, 04 Mar 2013 06:06:48 -0800 (PST) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.180.95.65 with SMTP id di1ls494154wib.26.gmail; Mon, 04 Mar 2013 06:06:47 -0800 (PST) X-Received: by 10.14.184.9 with SMTP id r9mr20072376eem.7.1362406007922; Mon, 04 Mar 2013 06:06:47 -0800 (PST) X-Received: by 10.14.184.9 with SMTP id r9mr20072374eem.7.1362406007913; Mon, 04 Mar 2013 06:06:47 -0800 (PST) Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de. [2001:6f8:1178:4:290:27ff:fe1d:cc33]) by gmr-mx.google.com with ESMTPS id 47si5928100eeh.1.2013.03.04.06.06.47 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 04 Mar 2013 06:06:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of str@pengutronix.de designates 2001:6f8:1178:4:290:27ff:fe1d:cc33 as permitted sender) client-ip=2001:6f8:1178:4:290:27ff:fe1d:cc33; Received: from dude.hi.pengutronix.de ([2001:6f8:1178:2:21e:67ff:fe11:9c5c]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1UCW1j-0004Yf-Ak; Mon, 04 Mar 2013 15:06:03 +0100 Received: from str by dude.hi.pengutronix.de with local (Exim 4.80) (envelope-from ) id 1UCW1h-0002Ja-9K; Mon, 04 Mar 2013 15:06:01 +0100 From: Steffen Trumtrar To: rtc-linux@googlegroups.com, devicetree-discuss@lists.ozlabs.org Cc: Shawn Guo , Alessandro Zummo , linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de, Juergen Beisert , Steffen Trumtrar Subject: [rtc-linux] [PATCH 4/9] MXS/i.MX28: there is more than one way to clock the RTC Date: Mon, 4 Mar 2013 15:05:43 +0100 Message-Id: <1362405948-12992-5-git-send-email-s.trumtrar@pengutronix.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1362405948-12992-1-git-send-email-s.trumtrar@pengutronix.de> References: <1362405948-12992-1-git-send-email-s.trumtrar@pengutronix.de> X-SA-Exim-Connect-IP: 2001:6f8:1178:2:21e:67ff:fe11:9c5c X-SA-Exim-Mail-From: str@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: rtc-linux@googlegroups.com X-Original-Sender: s.trumtrar@pengutronix.de X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of str@pengutronix.de designates 2001:6f8:1178:4:290:27ff:fe1d:cc33 as permitted sender) smtp.mail=str@pengutronix.de Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , From: Juergen Beisert Reflect the possibilities via device tree and configure the RTC correctly Signed-off-by: Juergen Beisert Signed-off-by: Steffen Trumtrar --- arch/arm/boot/dts/imx28.dtsi | 2 ++ drivers/rtc/rtc-stmp3xxx.c | 76 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/arch/arm/boot/dts/imx28.dtsi b/arch/arm/boot/dts/imx28.dtsi index dcd0844..d89af79 100644 --- a/arch/arm/boot/dts/imx28.dtsi +++ b/arch/arm/boot/dts/imx28.dtsi @@ -818,6 +818,8 @@ compatible = "fsl,imx28-rtc", "fsl,stmp3xxx-rtc"; reg = <0x80056000 0x2000>; interrupts = <29>; + clocks = <&clks 65>, <&clks 40> ; + clock-names = "32k", "24m"; }; i2c0: i2c@80058000 { diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c index 7311292..fb4b823 100644 --- a/drivers/rtc/rtc-stmp3xxx.c +++ b/drivers/rtc/rtc-stmp3xxx.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -176,11 +177,55 @@ static irqreturn_t stmp3xxx_rtc_interrupt(int irq, void *dev_id) return IRQ_NONE; } +/* + * To keep the energy consumption low, keep only + * the really used oscillator running when the power is down + */ +static void stmp3xxx_alarm_keep_oscillator(const struct stmp3xxx_rtc_data *rtc_data) +{ + switch (rtc_data->clk_src) { + case MXS_OSC_24M: + /* keep the 24 MHz oscillator running even in power down */ + writel(STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ | /* 24 MHz / 750 */ + STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP, + rtc_data->io + STMP3XXX_RTC_PERSISTENT0_SET); + writel(STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP | + STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE, + rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); + break; + case MXS_OSC_32K: + /* keep the 32 kHz oscillator running even in power down */ + writel(STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ | /* 32 kHz */ + STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP | + STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE, + rtc_data->io + STMP3XXX_RTC_PERSISTENT0_SET); + writel(STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP, + rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); + break; + case MXS_OSC_32K768: + /* keep the 32 kHz oscillator running even in power down */ + writel(STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP | + STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE, + rtc_data->io + STMP3XXX_RTC_PERSISTENT0_SET); + writel(STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ | /* 32.768 kHz */ + STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP, + rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); + break; + case MXS_UNKNOWN: + default: + break; + } +} + static int stmp3xxx_alarm_irq_enable(struct device *dev, unsigned int enabled) { struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev); + stmp3xxx_alarm_keep_oscillator(rtc_data); + if (enabled) { + writel(STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE, /* to be able to sleep */ + rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN, rtc_data->io + STMP3XXX_RTC_PERSISTENT0_SET); @@ -248,6 +293,8 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev) { struct stmp3xxx_rtc_data *rtc_data; struct resource *r; + struct clk *clk; + unsigned long rate; int err; rtc_data = kzalloc(sizeof *rtc_data, GFP_KERNEL); @@ -280,6 +327,35 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev) platform_set_drvdata(pdev, rtc_data); mxs_reset_block(rtc_data->io); + + /* + * configure the RTC to provide the correct time + */ + clk = clk_get(&pdev->dev, "32k"); + if (IS_ERR(clk)) { + /* just a fall back */ + dev_warn(&pdev->dev, "RTC's input clock undefined\n"); + rtc_data->clk_src = MXS_OSC_24M; + } else { + rate = clk_get_rate(clk); + if (rate == 0) { + /* no dedicated external crystal */ + rtc_data->clk_src = MXS_OSC_24M; + dev_info(&pdev->dev, "Using 24 MHz as RTC's clock\n"); + } else if (rate == 32000) { + rtc_data->clk_src = MXS_OSC_32K; + dev_info(&pdev->dev, "Using 32.0 kHz as RTC's clock\n"); + } else if (rate == 32768) { + rtc_data->clk_src = MXS_OSC_32K768; + dev_info(&pdev->dev, "Using 32.768 kHz as RTC's clock\n"); + } else + dev_warn(&pdev->dev, + "Cannot init the RTC's clock source\n"); + } + + /* basically configure the RTC's input clock */ + stmp3xxx_alarm_keep_oscillator(rtc_data); + writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN | STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE,