From patchwork Mon Dec 9 22:06:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Warren X-Patchwork-Id: 299211 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-ob0-x23e.google.com (mail-ob0-x23e.google.com [IPv6:2607:f8b0:4003:c01::23e]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (not verified)) by ozlabs.org (Postfix) with ESMTPS id BABC22C00AB for ; Tue, 10 Dec 2013 09:07:05 +1100 (EST) Received: by mail-ob0-f190.google.com with SMTP id wm4sf1211809obc.27 for ; Mon, 09 Dec 2013 14:07:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:from:to:cc:subject:date:message-id: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=PokUbPB+QByqQ2scUUZUeRLTdrFdoDEujnzE2GI8/lU=; b=cHeaxMnpiMg8fF3rru1+ayFyno7qthR61xvpOTgerkAzezYcTNpLNt8Ij/mXCxcitq XG5dxO8ZNMRgPwiGEoGerIi0C8X4VOFtW99fhohL0b6x/F5N/9sfGWhJoPDsmSYnvM2N aqF4wADv3S+bhO9ChjWpvjX1hljAXTpYh6LIdI/dCqmSX10ziewPmbO96mQ1nd4dmDGK boi9/xuOrz2MfsLhPCiuxHRu7Uu0FavJ0zwOFyrwVPjWBbETGWrquQ7UCMpyfczfuG7r UjijsWkLwjFmt4JSj3pTNDVGUbphgRCmKp5Jvbklnbs9Mpu1fmNliXLc5UWQXA+rbEJN lrOw== X-Received: by 10.49.51.104 with SMTP id j8mr109365qeo.18.1386626822224; Mon, 09 Dec 2013 14:07:02 -0800 (PST) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.49.47.103 with SMTP id c7ls2210657qen.24.gmail; Mon, 09 Dec 2013 14:07:01 -0800 (PST) X-Received: by 10.58.181.69 with SMTP id du5mr7543691vec.7.1386626821802; Mon, 09 Dec 2013 14:07:01 -0800 (PST) Received: from avon.wwwdotorg.org (avon.wwwdotorg.org. [70.85.31.133]) by gmr-mx.google.com with ESMTPS id z5si1575965igu.3.2013.12.09.14.07.01 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 09 Dec 2013 14:07:01 -0800 (PST) Received-SPF: pass (google.com: domain of swarren@wwwdotorg.org designates 70.85.31.133 as permitted sender) client-ip=70.85.31.133; Received: from severn.wwwdotorg.org (unknown [192.168.65.5]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by avon.wwwdotorg.org (Postfix) with ESMTPS id 682A66271; Mon, 9 Dec 2013 15:07:01 -0700 (MST) Received: from swarren-lx1.nvidia.com (localhost [127.0.0.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by severn.wwwdotorg.org (Postfix) with ESMTPSA id A686EE460E; Mon, 9 Dec 2013 15:06:44 -0700 (MST) From: Stephen Warren To: Lee Jones , Samuel Ortiz , Alessandro Zummo , Andrew Morton Cc: Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rtc-linux@googlegroups.com, Stephen Warren Subject: [rtc-linux] [PATCH 2/3] rtc: honor device tree /alias entries when assigning IDs Date: Mon, 9 Dec 2013 15:06:48 -0700 Message-Id: <1386626809-6251-2-git-send-email-swarren@wwwdotorg.org> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1386626809-6251-1-git-send-email-swarren@wwwdotorg.org> References: <1386626809-6251-1-git-send-email-swarren@wwwdotorg.org> X-NVConfidentiality: public X-Virus-Scanned: clamav-milter 0.97.8 at avon.wwwdotorg.org X-Virus-Status: Clean X-Original-Sender: swarren@wwwdotorg.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of swarren@wwwdotorg.org designates 70.85.31.133 as permitted sender) smtp.mail=swarren@wwwdotorg.org 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: Stephen Warren Assign RTC device IDs based on device tree /aliases entries if present, falling back to the existing numbering scheme if there is no /aliases entry (which includes when the system isn't booted using DT), or there is a numbering conflict. This is useful in systems with multiple RTC devices, to ensure that the best RTC device is selected as /dev/rtc0, which provides the overall system time. For example, Tegra has an on-SoC RTC that is not battery backed, typically coupled with an off-SoC RTC that is battery backed. Only the latter is useful for populating the system time, yet the former is useful e.g. for wakeup timing, since the time is not lost when the system is sleeps. Signed-off-by: Stephen Warren --- The 3 patches in this series are all independent; they can be applied to their respective subsystems in any order. I'm simply posting them as a series to make the use-case more obvious. --- drivers/rtc/class.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index 02426812bebc..7989b5d030cb 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c @@ -14,6 +14,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include +#include #include #include #include @@ -157,12 +158,25 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, { struct rtc_device *rtc; struct rtc_wkalrm alrm; - int id, err; + int of_id, id = -1, err; + + if (dev->of_node) { + of_id = of_alias_get_id(dev->of_node, "rtc"); + if (of_id >= 0) { + id = ida_simple_get(&rtc_ida, of_id, of_id + 1, + GFP_KERNEL); + if (id < 0) + dev_warn(dev, "/aliases ID %d not available\n", + of_id); + } + } - id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL); if (id < 0) { - err = id; - goto exit; + id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL); + if (id < 0) { + err = id; + goto exit; + } } rtc = kzalloc(sizeof(struct rtc_device), GFP_KERNEL);