diff options
author | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2017-07-06 05:41:59 -0400 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2017-07-07 07:14:08 -0400 |
commit | b91336df8ac2f5d15a2132074ba596580526db1d (patch) | |
tree | fa24a82fdbb2d7367ee6acc3c9318f903785c85b /drivers/rtc/class.c | |
parent | d1bec20facd6eae17cb2f39ebbf443c95c650490 (diff) |
rtc: class separate id allocation from registration
Create rtc_device_get_id to allocate the id for an RTC.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers/rtc/class.c')
-rw-r--r-- | drivers/rtc/class.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index fb39c1334d7b..93ce88e1b1cb 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c | |||
@@ -186,6 +186,27 @@ static struct rtc_device *rtc_allocate_device(void) | |||
186 | return rtc; | 186 | return rtc; |
187 | } | 187 | } |
188 | 188 | ||
189 | static int rtc_device_get_id(struct device *dev) | ||
190 | { | ||
191 | int of_id = -1, id = -1; | ||
192 | |||
193 | if (dev->of_node) | ||
194 | of_id = of_alias_get_id(dev->of_node, "rtc"); | ||
195 | else if (dev->parent && dev->parent->of_node) | ||
196 | of_id = of_alias_get_id(dev->parent->of_node, "rtc"); | ||
197 | |||
198 | if (of_id >= 0) { | ||
199 | id = ida_simple_get(&rtc_ida, of_id, of_id + 1, GFP_KERNEL); | ||
200 | if (id < 0) | ||
201 | dev_warn(dev, "/aliases ID %d not available\n", of_id); | ||
202 | } | ||
203 | |||
204 | if (id < 0) | ||
205 | id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL); | ||
206 | |||
207 | return id; | ||
208 | } | ||
209 | |||
189 | /** | 210 | /** |
190 | * rtc_device_register - register w/ RTC class | 211 | * rtc_device_register - register w/ RTC class |
191 | * @dev: the device to register | 212 | * @dev: the device to register |
@@ -201,27 +222,12 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, | |||
201 | { | 222 | { |
202 | struct rtc_device *rtc; | 223 | struct rtc_device *rtc; |
203 | struct rtc_wkalrm alrm; | 224 | struct rtc_wkalrm alrm; |
204 | int of_id = -1, id = -1, err; | 225 | int id, err; |
205 | |||
206 | if (dev->of_node) | ||
207 | of_id = of_alias_get_id(dev->of_node, "rtc"); | ||
208 | else if (dev->parent && dev->parent->of_node) | ||
209 | of_id = of_alias_get_id(dev->parent->of_node, "rtc"); | ||
210 | |||
211 | if (of_id >= 0) { | ||
212 | id = ida_simple_get(&rtc_ida, of_id, of_id + 1, | ||
213 | GFP_KERNEL); | ||
214 | if (id < 0) | ||
215 | dev_warn(dev, "/aliases ID %d not available\n", | ||
216 | of_id); | ||
217 | } | ||
218 | 226 | ||
227 | id = rtc_device_get_id(dev); | ||
219 | if (id < 0) { | 228 | if (id < 0) { |
220 | id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL); | 229 | err = id; |
221 | if (id < 0) { | 230 | goto exit; |
222 | err = id; | ||
223 | goto exit; | ||
224 | } | ||
225 | } | 231 | } |
226 | 232 | ||
227 | rtc = rtc_allocate_device(); | 233 | rtc = rtc_allocate_device(); |