Commit 9d2b7e532da8aadfcc1bd85b62ec5dd853e870e3

Authored by Stephen Warren
Committed by Linus Torvalds
1 parent 7ab26cd1ef

rtc: honor device tree /alias entries when assigning IDs

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 <swarren@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 20 additions and 4 deletions Side-by-side Diff

... ... @@ -14,6 +14,7 @@
14 14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 15  
16 16 #include <linux/module.h>
  17 +#include <linux/of.h>
17 18 #include <linux/rtc.h>
18 19 #include <linux/kdev_t.h>
19 20 #include <linux/idr.h>
20 21  
21 22  
... ... @@ -157,12 +158,27 @@
157 158 {
158 159 struct rtc_device *rtc;
159 160 struct rtc_wkalrm alrm;
160   - int id, err;
  161 + int of_id = -1, id = -1, err;
161 162  
162   - id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL);
  163 + if (dev->of_node)
  164 + of_id = of_alias_get_id(dev->of_node, "rtc");
  165 + else if (dev->parent && dev->parent->of_node)
  166 + of_id = of_alias_get_id(dev->parent->of_node, "rtc");
  167 +
  168 + if (of_id >= 0) {
  169 + id = ida_simple_get(&rtc_ida, of_id, of_id + 1,
  170 + GFP_KERNEL);
  171 + if (id < 0)
  172 + dev_warn(dev, "/aliases ID %d not available\n",
  173 + of_id);
  174 + }
  175 +
163 176 if (id < 0) {
164   - err = id;
165   - goto exit;
  177 + id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL);
  178 + if (id < 0) {
  179 + err = id;
  180 + goto exit;
  181 + }
166 182 }
167 183  
168 184 rtc = kzalloc(sizeof(struct rtc_device), GFP_KERNEL);