From patchwork Fri Apr 25 09:31:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 29044 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f199.google.com (mail-ie0-f199.google.com [209.85.223.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0C550202E6 for ; Fri, 25 Apr 2014 09:32:17 +0000 (UTC) Received: by mail-ie0-f199.google.com with SMTP id rl12sf20664627iec.6 for ; Fri, 25 Apr 2014 02:32:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=+QZYosqy5BcFKJkkRDuy6jCZLwZzWnNZ4zW/92G45k0=; b=GK7m10CCarVlRa1Kq6PLY9UBHvZCYNTkv8mhELxepOty67vZjHRlljnpiFA60cPrAW mRFtX7EMUO+2o95byLueXCCx+564TBjktTgxK1Ll80jV7tV4OtF2s/k1ug8WgUnfCR6c t3igZHOOirRMccf6T9Eo8udru+hZPTergV17NX/YO65LzAcMzqJ9K0LQ7T8FrYHN9hcV 20H7OFNxuY2Fytc9YIol1KDNCx5yQ5abFhI8QUkv/FyKA3KxKTRz9UMz2IN2z/u1CG/O +P5MFAskvh16DCU6qBB7tRwdVkO8Zg9Vc5TaqlSOnL4yyVANeakXY0zNbiRmQyXL2qsu VH4Q== X-Gm-Message-State: ALoCoQl8v4bSVl49WF8d8OsChy3Biu8FKIRo08YISmV4InrnULYzPf0Gu2/F5zpNY5JSBGsXHEzF X-Received: by 10.42.107.146 with SMTP id d18mr3309739icp.8.1398418337276; Fri, 25 Apr 2014 02:32:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.50.81 with SMTP id r75ls1495521qga.71.gmail; Fri, 25 Apr 2014 02:32:17 -0700 (PDT) X-Received: by 10.220.4.132 with SMTP id 4mr5931818vcr.9.1398418337094; Fri, 25 Apr 2014 02:32:17 -0700 (PDT) Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by mx.google.com with ESMTPS id ck5si1567022vdd.145.2014.04.25.02.32.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 25 Apr 2014 02:32:17 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.173; Received: by mail-ve0-f173.google.com with SMTP id oy12so4442859veb.32 for ; Fri, 25 Apr 2014 02:32:17 -0700 (PDT) X-Received: by 10.221.74.200 with SMTP id yx8mr5835149vcb.3.1398418336973; Fri, 25 Apr 2014 02:32:16 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp83309vcb; Fri, 25 Apr 2014 02:32:16 -0700 (PDT) X-Received: by 10.66.192.225 with SMTP id hj1mr6492443pac.142.1398418336036; Fri, 25 Apr 2014 02:32:16 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id py5si4450284pbc.142.2014.04.25.02.32.15 for ; Fri, 25 Apr 2014 02:32:15 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753355AbaDYJb1 (ORCPT + 28 others); Fri, 25 Apr 2014 05:31:27 -0400 Received: from fw-tnat.austin.arm.com ([217.140.110.23]:24903 "EHLO collaborate-mta1.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751075AbaDYJbV (ORCPT ); Fri, 25 Apr 2014 05:31:21 -0400 Received: from e102391-lin.cambridge.arm.com (e102391-lin.cambridge.arm.com [10.1.209.166]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 1CD4013FC94; Fri, 25 Apr 2014 04:31:18 -0500 (CDT) From: Marc Zyngier To: linux-kernel@vger.kernel.org, rtc-linux@googlegroups.com Cc: Russell King , Will Deacon , Catalin Marinas , Alessandro Zummo Subject: [PATCH 3/7] rtc-cmos: allow MMIO to be used when initialized from FDT Date: Fri, 25 Apr 2014 10:31:11 +0100 Message-Id: <1398418275-9671-4-git-send-email-marc.zyngier@arm.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1398418275-9671-1-git-send-email-marc.zyngier@arm.com> References: <1398418275-9671-1-git-send-email-marc.zyngier@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: marc.zyngier@arm.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Currently, rtc-cmos mandates the use of an I/O port. If the resource obtained from the device tree is instead a memory mapped range, the probing will fail. Let the cmos_of_init function try to ioremap the range obtained from FDT. Should this fail, fallback to the normal I/O port. Tested on KVM/ARM with kvmtools as the backend for RTC emulation. Signed-off-by: Marc Zyngier --- drivers/rtc/Kconfig | 3 +++ drivers/rtc/rtc-cmos.c | 67 ++++++++++++++++++++++++++++++++++++++++++----- include/asm-generic/rtc.h | 5 ++++ 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 2e565f8..7e88866 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -677,6 +677,9 @@ config RTC_DRV_CMOS This driver can also be built as a module. If so, the module will be called rtc-cmos. +config RTC_DRV_CMOS_MMIO + bool + config RTC_DRV_ALPHA bool "Alpha PC-style CMOS" depends on ALPHA diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index be2dd17..d535e72 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -66,6 +67,41 @@ struct cmos_rtc { static const char driver_name[] = "rtc_cmos"; +#ifdef CONFIG_RTC_DRV_CMOS_MMIO +static void __iomem *rtc_cmos_base; + +static u8 do_cmos_read(u8 reg) +{ + u8 val; + + if (rtc_cmos_base) { + writeb(reg, rtc_cmos_base); + val = readb(rtc_cmos_base + 1); + } else { + val = CMOS_READ(reg); + } + + return val; +} + +static void do_cmos_write(u8 val, u8 reg) +{ + if (rtc_cmos_base) { + writeb(reg, rtc_cmos_base); + writeb(val, rtc_cmos_base + 1); + } else { + CMOS_WRITE(val, reg); + } +} + +static inline void rtc_cmos_set_base(void __iomem *base) +{ + rtc_cmos_base = base; +} +#else +static void rtc_cmos_set_base(void __iomem *base) {} +#endif + /* The RTC_INTR register may have e.g. RTC_PF set even if RTC_PIE is clear; * always mask it against the irq enable bits in RTC_CONTROL. Bit values * are the same: PF==PIE, AF=AIE, UF=UIE; so RTC_IRQMASK works with both. @@ -663,13 +699,23 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) return -ENODEV; /* Claim I/O ports ASAP, minimizing conflict with legacy driver. - * - * REVISIT non-x86 systems may instead use memory space resources - * (needing ioremap etc), not i/o space resources like this ... + * MMIO gets requested the same way, not that it matters much. */ - ports = request_region(ports->start, - resource_size(ports), - driver_name); + switch(resource_type(ports)) { + case IORESOURCE_IO: + ports = request_region(ports->start, + resource_size(ports), + driver_name); + break; + case IORESOURCE_MEM: + ports = request_mem_region(ports->start, + resource_size(ports), + driver_name); + break; + default: /* Martian I/O??? */ + ports = NULL; + } + if (!ports) { dev_dbg(dev, "i/o registers already in use\n"); return -EBUSY; @@ -1160,10 +1206,17 @@ static inline void cmos_of_init(struct platform_device *pdev) {} static int __init cmos_platform_probe(struct platform_device *pdev) { + struct resource *ports; + cmos_of_init(pdev); + + ports = platform_get_resource(pdev, IORESOURCE_IO, 0); + if (!ports) + ports = platform_get_resource(pdev, IORESOURCE_MEM, 0); + cmos_wake_setup(&pdev->dev); return cmos_do_probe(&pdev->dev, - platform_get_resource(pdev, IORESOURCE_IO, 0), + ports, platform_get_irq(pdev, 0)); } diff --git a/include/asm-generic/rtc.h b/include/asm-generic/rtc.h index 1ad3e78..236693b 100644 --- a/include/asm-generic/rtc.h +++ b/include/asm-generic/rtc.h @@ -28,6 +28,10 @@ #define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */ #define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */ +#ifdef CONFIG_RTC_DRV_CMOS_MMIO +static u8 do_cmos_read(u8 reg); +static void do_cmos_write(u8 val, u8 reg); +#else static inline u8 do_cmos_read(u8 reg) { return CMOS_READ(reg); @@ -37,6 +41,7 @@ static inline void do_cmos_write(u8 val, u8 reg) { CMOS_WRITE(val, reg); } +#endif static inline unsigned long rtc_cmos_lock(void) {