From patchwork Tue May 7 01:17:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Xie X-Patchwork-Id: 241867 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-da0-x23f.google.com (mail-da0-x23f.google.com [IPv6:2607:f8b0:400e:c00::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 A54CB2C00E8 for ; Tue, 7 May 2013 11:20:37 +1000 (EST) Received: by mail-da0-f63.google.com with SMTP id f10sf7109dak.28 for ; Mon, 06 May 2013 18:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=x-received:x-beenthere:x-received:received-spf:from:to:cc:subject :date:message-id:x-mailer:in-reply-to:references:mime-version :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=pHHE94cH0ZJF6u6OWcJiUsWohbOfAuRrByUfVXx2hqg=; b=a8/Upm9AunvNL4Hnsmr8zLqDhJc1sEImcSYHyVTTJ/bih89YRAf8iv2r6+1jbSl9KK iSPMhvW7Un31D1JnmS0ygy7s0R/PxjERStT/hCxYGkMjEdH+crJddenPY0SYKaOb7nJV c1XHDZVe+YSSFJ9d1AWt14ynT3eRHPqVsL78WqsgSAj++eS7Ir6Xn+NBITFn3KxIEPYN 7N0hKCekuTeNKhACkGaweE69V7o40dTQBm0BU2iqZC8uR9ulE4nT/hJCR7ZSj6h0pecR GEgpde2Ucer+hLY0f6Mb8VQUujdKx6I/UXnTMTSTk9/jxy4wVaM9tTBmad5nu+YsOQL2 zPLA== X-Received: by 10.50.40.99 with SMTP id w3mr1085429igk.12.1367889634788; Mon, 06 May 2013 18:20:34 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.50.7.38 with SMTP id g6ls2262597iga.26.canary; Mon, 06 May 2013 18:20:34 -0700 (PDT) X-Received: by 10.68.246.229 with SMTP id xz5mr8178766pbc.1.1367889634294; Mon, 06 May 2013 18:20:34 -0700 (PDT) Received: from na3sys009aog132.obsmtp.com ([74.125.149.250]) by gmr-mx.google.com with SMTP id xb6si4257431pab.0.2013.05.06.18.20.25 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 06 May 2013 18:20:34 -0700 (PDT) Received-SPF: temperror (google.com: error in processing during lookup of cxie4@marvell.com: DNS timeout) client-ip=74.125.149.250; Received: from SC-OWA01.marvell.com ([199.233.58.136]) (using TLSv1) by na3sys009aob132.postini.com ([74.125.148.12]) with SMTP ID DSNKUYhWz8MEHIqi+nB70vK1oFd9VckyjHAP@postini.com; Mon, 06 May 2013 18:20:34 PDT Received: from maili.marvell.com (10.93.76.43) by sc-owa01.marvell.com (10.93.76.21) with Microsoft SMTP Server id 8.3.213.0; Mon, 6 May 2013 18:17:29 -0700 Received: from localhost (unknown [10.38.36.239]) by maili.marvell.com (Postfix) with ESMTP id C69D74E513; Mon, 6 May 2013 18:17:29 -0700 (PDT) From: Chao Xie To: , , , , , , , , , CC: Chao Xie Subject: [rtc-linux] [PATCH 2/2] rtc: pxa: add pxa95x rtc support Date: Mon, 6 May 2013 21:17:27 -0400 Message-ID: <1367889447-15619-3-git-send-email-chao.xie@marvell.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1367889447-15619-1-git-send-email-chao.xie@marvell.com> References: <1367889447-15619-1-git-send-email-chao.xie@marvell.com> MIME-Version: 1.0 X-Original-Sender: cxie4@marvell.com X-Original-Authentication-Results: gmr-mx.google.com; spf=temperror (google.com: error in processing during lookup of cxie4@marvell.com: DNS timeout) smtp.mail=cxie4@marvell.com 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: , the pxa95x rtc need access PBSR register before write to RTTR, RCNR, RDCR, and RYCR registers. Signed-off-by: Chao Xie --- drivers/rtc/rtc-pxa.c | 96 ++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 84 insertions(+), 12 deletions(-) diff --git a/drivers/rtc/rtc-pxa.c b/drivers/rtc/rtc-pxa.c index e261e2f..4ffdd57 100644 --- a/drivers/rtc/rtc-pxa.c +++ b/drivers/rtc/rtc-pxa.c @@ -82,14 +82,28 @@ #define RTCPICR 0x34 #define PIAR 0x38 +#define PSBR_RTC 0x00 + #define rtc_readl(pxa_rtc, reg) \ __raw_readl((pxa_rtc)->base + (reg)) #define rtc_writel(pxa_rtc, reg, value) \ __raw_writel((value), (pxa_rtc)->base + (reg)) - +#define rtc_readl_psbr(pxa_rtc, reg) \ + __raw_readl((pxa_rtc)->base_psbr + (reg)) +#define rtc_writel_psbr(pxa_rtc, reg, value) \ + __raw_writel((value), (pxa_rtc)->base_psbr + (reg)) + +enum { + RTC_PXA27X, + RTC_PXA95X, +}; + struct pxa_rtc { struct resource *ress; + struct resource *ress_psbr; + unsigned int id; void __iomem *base; + void __iomem *base_psbr; int irq_1Hz; int irq_Alrm; struct rtc_device *rtc; @@ -252,9 +266,26 @@ static int pxa_rtc_set_time(struct device *dev, struct rtc_time *tm) { struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev); + /* + * sequence to wirte pxa rtc register RCNR RDCR RYCR is + * 1. set PSBR[RWE] bit, take 2x32-khz to complete + * 2. write to RTC register,take 2x32-khz to complete + * 3. clear PSBR[RWE] bit,take 2x32-khz to complete + */ + if (pxa_rtc->id == RTC_PXA95X) { + rtc_writel_psbr(pxa_rtc, PSBR_RTC, 0x01); + usleep_range(100, 120); + } + rtc_writel(pxa_rtc, RYCR, ryxr_calc(tm)); rtc_writel(pxa_rtc, RDCR, rdxr_calc(tm)); + if (pxa_rtc->id == RTC_PXA95X) { + usleep_range(100, 120); + rtc_writel_psbr(pxa_rtc, PSBR_RTC, 0x00); + usleep_range(100, 120); + } + return 0; } @@ -318,6 +349,20 @@ static const struct rtc_class_ops pxa_rtc_ops = { .proc = pxa_rtc_proc, }; +static struct of_device_id pxa_rtc_dt_ids[] = { + { .compatible = "marvell,pxa-rtc", .data = (void *)RTC_PXA27X }, + { .compatible = "marvell,pxa95x-rtc", .data = (void *)RTC_PXA95X }, + {} +}; +MODULE_DEVICE_TABLE(of, pxa_rtc_dt_ids); + +static const struct platform_device_id pxa_rtc_id_table[] = { + { "pxa-rtc", RTC_PXA27X }, + { "pxa95x-rtc", RTC_PXA95X }, + { }, +}; +MODULE_DEVICE_TABLE(platform, pxa_rtc_id_table); + static int __init pxa_rtc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -332,13 +377,34 @@ static int __init pxa_rtc_probe(struct platform_device *pdev) spin_lock_init(&pxa_rtc->lock); platform_set_drvdata(pdev, pxa_rtc); + if (pdev->dev.of_node) { + const struct of_device_id *of_id = + of_match_device(pxa_rtc_dt_ids, &pdev->dev); + + pxa_rtc->id = (unsigned int)(of_id->data); + } else { + const struct platform_device_id *id = + platform_get_device_id(pdev); + + pxa_rtc->id = id->driver_data; + } + ret = -ENXIO; pxa_rtc->ress = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!pxa_rtc->ress) { - dev_err(dev, "No I/O memory resource defined\n"); + dev_err(dev, "No I/O memory resource(id=0) defined\n"); goto err_ress; } + if (pxa_rtc->id == RTC_PXA95X) { + pxa_rtc->ress_psbr = + platform_get_resource(pdev, IORESOURCE_MEM, 1); + if (!pxa_rtc->ress_psbr) { + dev_err(dev, "No I/O memory resource(id=1) defined\n"); + goto err_ress; + } + } + pxa_rtc->irq_1Hz = platform_get_irq(pdev, 0); if (pxa_rtc->irq_1Hz < 0) { dev_err(dev, "No 1Hz IRQ resource defined\n"); @@ -355,7 +421,17 @@ static int __init pxa_rtc_probe(struct platform_device *pdev) resource_size(pxa_rtc->ress)); if (!pxa_rtc->base) { dev_err(&pdev->dev, "Unable to map pxa RTC I/O memory\n"); - goto err_map; + goto err_map_base; + } + + if (pxa_rtc->id == RTC_PXA95X) { + pxa_rtc->base_psbr = ioremap(pxa_rtc->ress_psbr->start, + resource_size(pxa_rtc->ress_psbr)); + if (!pxa_rtc->base_psbr) { + dev_err(&pdev->dev, + "Unable to map pxa RTC PSBR I/O memory\n"); + goto err_map_base_psbr; + } } /* @@ -384,9 +460,12 @@ static int __init pxa_rtc_probe(struct platform_device *pdev) return 0; err_rtc_reg: + if (pxa_rtc->id == RTC_PXA95X) + iounmap(pxa_rtc->base_psbr); +err_map_base_psbr: iounmap(pxa_rtc->base); +err_map_base: err_ress: -err_map: kfree(pxa_rtc); return ret; } @@ -409,14 +488,6 @@ static int __exit pxa_rtc_remove(struct platform_device *pdev) return 0; } -#ifdef CONFIG_OF -static struct of_device_id pxa_rtc_dt_ids[] = { - { .compatible = "marvell,pxa-rtc" }, - {} -}; -MODULE_DEVICE_TABLE(of, pxa_rtc_dt_ids); -#endif - #ifdef CONFIG_PM_SLEEP static int pxa_rtc_suspend(struct device *dev) { @@ -446,6 +517,7 @@ static struct platform_driver pxa_rtc_driver = { .of_match_table = of_match_ptr(pxa_rtc_dt_ids), .pm = &pxa_rtc_pm_ops, }, + .id_table = pxa_rtc_id_table, }; module_platform_driver_probe(pxa_rtc_driver, pxa_rtc_probe);