summaryrefslogtreecommitdiffstats
path: root/drivers/rtc/class.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-01-01 16:24:31 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2019-01-01 16:24:31 -0500
commit28e8c4bc8eb483c22d977e147a0b98fc63efadf7 (patch)
tree8006dd759601c70d4dd1fc644ed817e9597cec55 /drivers/rtc/class.c
parentc9bef4a651769927445900564781a9c99fdf6258 (diff)
parent36e14f5fdfdf7cec8887b7ff69cd9bb5051ecf62 (diff)
Merge tag 'rtc-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
Pull RTC updates from Alexandre Belloni: "Subsystem: - new %ptR printk format - rename core files - allow registration of multiple nvmem devices New driver: - i.MX system controller RTC Driver updates: - abx80x: handle voltage ioctls, correct binding doc - m41t80: correct month in alarm reads - pcf85363: add pcf85263 support - pcf8523: properly handle battery low flag - s3c: limit alarm to one year in the future as ALMYEAR is broken - sun6i: rework clock output binding" * tag 'rtc-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (54 commits) rtc: rename core files rtc: nvmem: fix possible use after free rtc: add i.MX system controller RTC support dt-bindings: fsl: scu: add rtc binding rtc: pcf2123: Add Microcrystal rv2123 rtc: class: reimplement devm_rtc_device_register rtc: enforce rtc_timer_init private_data type rtc: abx80x: Implement RTC_VL_READ,CLR ioctls rtc: pcf85363: Add support for NXP pcf85263 rtc dt-bindings: rtc: pcf85363: Document pcf85263 real-time clock rtc: pcf8523: don't return invalid date when battery is low dt-bindings: rtc: use a generic node name for ds1307 PM: Switch to use %ptR m68k/mac: Switch to use %ptR Input: hp_sdc_rtc - Switch to use %ptR rtc: tegra: Switch to use %ptR rtc: s5m: Switch to use %ptR rtc: s3c: Switch to use %ptR rtc: rx8025: Switch to use %ptR rtc: rx6110: Switch to use %ptR ...
Diffstat (limited to 'drivers/rtc/class.c')
-rw-r--r--drivers/rtc/class.c187
1 files changed, 38 insertions, 149 deletions
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 3b43787f154b..ac93b76f2b11 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -178,9 +178,9 @@ static struct rtc_device *rtc_allocate_device(void)
178 timerqueue_init_head(&rtc->timerqueue); 178 timerqueue_init_head(&rtc->timerqueue);
179 INIT_WORK(&rtc->irqwork, rtc_timer_do_work); 179 INIT_WORK(&rtc->irqwork, rtc_timer_do_work);
180 /* Init aie timer */ 180 /* Init aie timer */
181 rtc_timer_init(&rtc->aie_timer, rtc_aie_update_irq, (void *)rtc); 181 rtc_timer_init(&rtc->aie_timer, rtc_aie_update_irq, rtc);
182 /* Init uie timer */ 182 /* Init uie timer */
183 rtc_timer_init(&rtc->uie_rtctimer, rtc_uie_update_irq, (void *)rtc); 183 rtc_timer_init(&rtc->uie_rtctimer, rtc_uie_update_irq, rtc);
184 /* Init pie timer */ 184 /* Init pie timer */
185 hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 185 hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
186 rtc->pie_timer.function = rtc_pie_update_irq; 186 rtc->pie_timer.function = rtc_pie_update_irq;
@@ -278,82 +278,6 @@ static void rtc_device_get_offset(struct rtc_device *rtc)
278} 278}
279 279
280/** 280/**
281 * rtc_device_register - register w/ RTC class
282 * @dev: the device to register
283 *
284 * rtc_device_unregister() must be called when the class device is no
285 * longer needed.
286 *
287 * Returns the pointer to the new struct class device.
288 */
289static struct rtc_device *rtc_device_register(const char *name,
290 struct device *dev,
291 const struct rtc_class_ops *ops,
292 struct module *owner)
293{
294 struct rtc_device *rtc;
295 struct rtc_wkalrm alrm;
296 int id, err;
297
298 id = rtc_device_get_id(dev);
299 if (id < 0) {
300 err = id;
301 goto exit;
302 }
303
304 rtc = rtc_allocate_device();
305 if (!rtc) {
306 err = -ENOMEM;
307 goto exit_ida;
308 }
309
310 rtc->id = id;
311 rtc->ops = ops;
312 rtc->owner = owner;
313 rtc->dev.parent = dev;
314
315 dev_set_name(&rtc->dev, "rtc%d", id);
316
317 rtc_device_get_offset(rtc);
318
319 /* Check to see if there is an ALARM already set in hw */
320 err = __rtc_read_alarm(rtc, &alrm);
321
322 if (!err && !rtc_valid_tm(&alrm.time))
323 rtc_initialize_alarm(rtc, &alrm);
324
325 rtc_dev_prepare(rtc);
326
327 err = cdev_device_add(&rtc->char_dev, &rtc->dev);
328 if (err) {
329 dev_warn(&rtc->dev, "%s: failed to add char device %d:%d\n",
330 name, MAJOR(rtc->dev.devt), rtc->id);
331
332 /* This will free both memory and the ID */
333 put_device(&rtc->dev);
334 goto exit;
335 } else {
336 dev_dbg(&rtc->dev, "%s: dev (%d:%d)\n", name,
337 MAJOR(rtc->dev.devt), rtc->id);
338 }
339
340 rtc_proc_add_device(rtc);
341
342 dev_info(dev, "rtc core: registered %s as %s\n",
343 name, dev_name(&rtc->dev));
344
345 return rtc;
346
347exit_ida:
348 ida_simple_remove(&rtc_ida, id);
349
350exit:
351 dev_err(dev, "rtc core: unable to register %s, err = %d\n",
352 name, err);
353 return ERR_PTR(err);
354}
355
356/**
357 * rtc_device_unregister - removes the previously registered RTC class device 281 * rtc_device_unregister - removes the previously registered RTC class device
358 * 282 *
359 * @rtc: the RTC class device to destroy 283 * @rtc: the RTC class device to destroy
@@ -372,77 +296,6 @@ static void rtc_device_unregister(struct rtc_device *rtc)
372 put_device(&rtc->dev); 296 put_device(&rtc->dev);
373} 297}
374 298
375static void devm_rtc_device_release(struct device *dev, void *res)
376{
377 struct rtc_device *rtc = *(struct rtc_device **)res;
378
379 rtc_nvmem_unregister(rtc);
380 rtc_device_unregister(rtc);
381}
382
383static int devm_rtc_device_match(struct device *dev, void *res, void *data)
384{
385 struct rtc **r = res;
386
387 return *r == data;
388}
389
390/**
391 * devm_rtc_device_register - resource managed rtc_device_register()
392 * @dev: the device to register
393 * @name: the name of the device
394 * @ops: the rtc operations structure
395 * @owner: the module owner
396 *
397 * @return a struct rtc on success, or an ERR_PTR on error
398 *
399 * Managed rtc_device_register(). The rtc_device returned from this function
400 * are automatically freed on driver detach. See rtc_device_register()
401 * for more information.
402 */
403
404struct rtc_device *devm_rtc_device_register(struct device *dev,
405 const char *name,
406 const struct rtc_class_ops *ops,
407 struct module *owner)
408{
409 struct rtc_device **ptr, *rtc;
410
411 ptr = devres_alloc(devm_rtc_device_release, sizeof(*ptr), GFP_KERNEL);
412 if (!ptr)
413 return ERR_PTR(-ENOMEM);
414
415 rtc = rtc_device_register(name, dev, ops, owner);
416 if (!IS_ERR(rtc)) {
417 *ptr = rtc;
418 devres_add(dev, ptr);
419 } else {
420 devres_free(ptr);
421 }
422
423 return rtc;
424}
425EXPORT_SYMBOL_GPL(devm_rtc_device_register);
426
427/**
428 * devm_rtc_device_unregister - resource managed devm_rtc_device_unregister()
429 * @dev: the device to unregister
430 * @rtc: the RTC class device to unregister
431 *
432 * Deallocated a rtc allocated with devm_rtc_device_register(). Normally this
433 * function will not need to be called and the resource management code will
434 * ensure that the resource is freed.
435 */
436void devm_rtc_device_unregister(struct device *dev, struct rtc_device *rtc)
437{
438 int rc;
439
440 rc = devres_release(dev, devm_rtc_device_release,
441 devm_rtc_device_match, rtc);
442 WARN_ON(rc);
443}
444EXPORT_SYMBOL_GPL(devm_rtc_device_unregister);
445
446static void devm_rtc_release_device(struct device *dev, void *res) 299static void devm_rtc_release_device(struct device *dev, void *res)
447{ 300{
448 struct rtc_device *rtc = *(struct rtc_device **)res; 301 struct rtc_device *rtc = *(struct rtc_device **)res;
@@ -529,6 +382,42 @@ int __rtc_register_device(struct module *owner, struct rtc_device *rtc)
529} 382}
530EXPORT_SYMBOL_GPL(__rtc_register_device); 383EXPORT_SYMBOL_GPL(__rtc_register_device);
531 384
385/**
386 * devm_rtc_device_register - resource managed rtc_device_register()
387 * @dev: the device to register
388 * @name: the name of the device (unused)
389 * @ops: the rtc operations structure
390 * @owner: the module owner
391 *
392 * @return a struct rtc on success, or an ERR_PTR on error
393 *
394 * Managed rtc_device_register(). The rtc_device returned from this function
395 * are automatically freed on driver detach.
396 * This function is deprecated, use devm_rtc_allocate_device and
397 * rtc_register_device instead
398 */
399struct rtc_device *devm_rtc_device_register(struct device *dev,
400 const char *name,
401 const struct rtc_class_ops *ops,
402 struct module *owner)
403{
404 struct rtc_device *rtc;
405 int err;
406
407 rtc = devm_rtc_allocate_device(dev);
408 if (IS_ERR(rtc))
409 return rtc;
410
411 rtc->ops = ops;
412
413 err = __rtc_register_device(owner, rtc);
414 if (err)
415 return ERR_PTR(err);
416
417 return rtc;
418}
419EXPORT_SYMBOL_GPL(devm_rtc_device_register);
420
532static int __init rtc_init(void) 421static int __init rtc_init(void)
533{ 422{
534 rtc_class = class_create(THIS_MODULE, "rtc"); 423 rtc_class = class_create(THIS_MODULE, "rtc");