.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
---|
1 | 2 | /* |
---|
2 | 3 | * rtc-ab-b5ze-s3 - Driver for Abracon AB-RTCMC-32.768Khz-B5ZE-S3 |
---|
3 | 4 | * I2C RTC / Alarm chip |
---|
.. | .. |
---|
6 | 7 | * |
---|
7 | 8 | * Detailed datasheet of the chip is available here: |
---|
8 | 9 | * |
---|
9 | | - * http://www.abracon.com/realtimeclock/AB-RTCMC-32.768kHz-B5ZE-S3-Application-Manual.pdf |
---|
| 10 | + * https://www.abracon.com/realtimeclock/AB-RTCMC-32.768kHz-B5ZE-S3-Application-Manual.pdf |
---|
10 | 11 | * |
---|
11 | 12 | * This work is based on ISL12057 driver (drivers/rtc/rtc-isl12057.c). |
---|
12 | 13 | * |
---|
13 | | - * This program is free software; you can redistribute it and/or modify |
---|
14 | | - * it under the terms of the GNU General Public License as published by |
---|
15 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
16 | | - * (at your option) any later version. |
---|
17 | | - * |
---|
18 | | - * This program is distributed in the hope that it will be useful, |
---|
19 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
21 | | - * GNU General Public License for more details. |
---|
22 | 14 | */ |
---|
23 | 15 | |
---|
24 | 16 | #include <linux/module.h> |
---|
25 | | -#include <linux/mutex.h> |
---|
26 | 17 | #include <linux/rtc.h> |
---|
27 | 18 | #include <linux/i2c.h> |
---|
28 | 19 | #include <linux/bcd.h> |
---|
.. | .. |
---|
128 | 119 | struct abb5zes3_rtc_data { |
---|
129 | 120 | struct rtc_device *rtc; |
---|
130 | 121 | struct regmap *regmap; |
---|
131 | | - struct mutex lock; |
---|
132 | 122 | |
---|
133 | 123 | int irq; |
---|
134 | 124 | |
---|
.. | .. |
---|
138 | 128 | |
---|
139 | 129 | /* |
---|
140 | 130 | * Try and match register bits w/ fixed null values to see whether we |
---|
141 | | - * are dealing with an ABB5ZES3. Note: this function is called early |
---|
142 | | - * during init and hence does need mutex protection. |
---|
| 131 | + * are dealing with an ABB5ZES3. |
---|
143 | 132 | */ |
---|
144 | 133 | static int abb5zes3_i2c_validate_chip(struct regmap *regmap) |
---|
145 | 134 | { |
---|
.. | .. |
---|
230 | 219 | if (ret) { |
---|
231 | 220 | dev_err(dev, "%s: reading RTC time failed (%d)\n", |
---|
232 | 221 | __func__, ret); |
---|
233 | | - goto err; |
---|
| 222 | + return ret; |
---|
234 | 223 | } |
---|
235 | 224 | |
---|
236 | 225 | /* If clock integrity is not guaranteed, do not return a time value */ |
---|
237 | | - if (regs[ABB5ZES3_REG_RTC_SC] & ABB5ZES3_REG_RTC_SC_OSC) { |
---|
238 | | - ret = -ENODATA; |
---|
239 | | - goto err; |
---|
240 | | - } |
---|
| 226 | + if (regs[ABB5ZES3_REG_RTC_SC] & ABB5ZES3_REG_RTC_SC_OSC) |
---|
| 227 | + return -ENODATA; |
---|
241 | 228 | |
---|
242 | 229 | tm->tm_sec = bcd2bin(regs[ABB5ZES3_REG_RTC_SC] & 0x7F); |
---|
243 | 230 | tm->tm_min = bcd2bin(regs[ABB5ZES3_REG_RTC_MN]); |
---|
.. | .. |
---|
255 | 242 | tm->tm_mon = bcd2bin(regs[ABB5ZES3_REG_RTC_MO]) - 1; /* starts at 1 */ |
---|
256 | 243 | tm->tm_year = bcd2bin(regs[ABB5ZES3_REG_RTC_YR]) + 100; |
---|
257 | 244 | |
---|
258 | | -err: |
---|
259 | 245 | return ret; |
---|
260 | 246 | } |
---|
261 | 247 | |
---|
.. | .. |
---|
273 | 259 | regs[ABB5ZES3_REG_RTC_MO] = bin2bcd(tm->tm_mon + 1); |
---|
274 | 260 | regs[ABB5ZES3_REG_RTC_YR] = bin2bcd(tm->tm_year - 100); |
---|
275 | 261 | |
---|
276 | | - mutex_lock(&data->lock); |
---|
277 | 262 | ret = regmap_bulk_write(data->regmap, ABB5ZES3_REG_RTC_SC, |
---|
278 | 263 | regs + ABB5ZES3_REG_RTC_SC, |
---|
279 | 264 | ABB5ZES3_RTC_SEC_LEN); |
---|
280 | | - mutex_unlock(&data->lock); |
---|
281 | | - |
---|
282 | 265 | |
---|
283 | 266 | return ret; |
---|
284 | 267 | } |
---|
.. | .. |
---|
332 | 315 | if (ret) { |
---|
333 | 316 | dev_err(dev, "%s: reading Timer A section failed (%d)\n", |
---|
334 | 317 | __func__, ret); |
---|
335 | | - goto err; |
---|
| 318 | + return ret; |
---|
336 | 319 | } |
---|
337 | 320 | |
---|
338 | 321 | /* get current time ... */ |
---|
339 | 322 | ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); |
---|
340 | 323 | if (ret) |
---|
341 | | - goto err; |
---|
| 324 | + return ret; |
---|
342 | 325 | |
---|
343 | 326 | /* ... convert to seconds ... */ |
---|
344 | | - ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); |
---|
345 | | - if (ret) |
---|
346 | | - goto err; |
---|
| 327 | + rtc_secs = rtc_tm_to_time64(&rtc_tm); |
---|
347 | 328 | |
---|
348 | 329 | /* ... add remaining timer A time ... */ |
---|
349 | 330 | ret = sec_from_timer_a(&timer_secs, regs[1], regs[2]); |
---|
350 | 331 | if (ret) |
---|
351 | | - goto err; |
---|
| 332 | + return ret; |
---|
352 | 333 | |
---|
353 | 334 | /* ... and convert back. */ |
---|
354 | | - rtc_time_to_tm(rtc_secs + timer_secs, alarm_tm); |
---|
| 335 | + rtc_time64_to_tm(rtc_secs + timer_secs, alarm_tm); |
---|
355 | 336 | |
---|
356 | 337 | ret = regmap_read(data->regmap, ABB5ZES3_REG_CTRL2, ®); |
---|
357 | 338 | if (ret) { |
---|
358 | 339 | dev_err(dev, "%s: reading ctrl reg failed (%d)\n", |
---|
359 | 340 | __func__, ret); |
---|
360 | | - goto err; |
---|
| 341 | + return ret; |
---|
361 | 342 | } |
---|
362 | 343 | |
---|
363 | 344 | alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL2_WTAIE); |
---|
364 | 345 | |
---|
365 | | -err: |
---|
366 | | - return ret; |
---|
| 346 | + return 0; |
---|
367 | 347 | } |
---|
368 | 348 | |
---|
369 | 349 | /* Read alarm currently configured via a RTC alarm registers. */ |
---|
.. | .. |
---|
382 | 362 | if (ret) { |
---|
383 | 363 | dev_err(dev, "%s: reading alarm section failed (%d)\n", |
---|
384 | 364 | __func__, ret); |
---|
385 | | - goto err; |
---|
| 365 | + return ret; |
---|
386 | 366 | } |
---|
387 | 367 | |
---|
388 | 368 | alarm_tm->tm_sec = 0; |
---|
.. | .. |
---|
398 | 378 | */ |
---|
399 | 379 | ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); |
---|
400 | 380 | if (ret) |
---|
401 | | - goto err; |
---|
| 381 | + return ret; |
---|
402 | 382 | |
---|
403 | 383 | alarm_tm->tm_year = rtc_tm.tm_year; |
---|
404 | 384 | alarm_tm->tm_mon = rtc_tm.tm_mon; |
---|
405 | 385 | |
---|
406 | | - ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); |
---|
407 | | - if (ret) |
---|
408 | | - goto err; |
---|
409 | | - |
---|
410 | | - ret = rtc_tm_to_time(alarm_tm, &alarm_secs); |
---|
411 | | - if (ret) |
---|
412 | | - goto err; |
---|
| 386 | + rtc_secs = rtc_tm_to_time64(&rtc_tm); |
---|
| 387 | + alarm_secs = rtc_tm_to_time64(alarm_tm); |
---|
413 | 388 | |
---|
414 | 389 | if (alarm_secs < rtc_secs) { |
---|
415 | 390 | if (alarm_tm->tm_mon == 11) { |
---|
.. | .. |
---|
424 | 399 | if (ret) { |
---|
425 | 400 | dev_err(dev, "%s: reading ctrl reg failed (%d)\n", |
---|
426 | 401 | __func__, ret); |
---|
427 | | - goto err; |
---|
| 402 | + return ret; |
---|
428 | 403 | } |
---|
429 | 404 | |
---|
430 | 405 | alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL1_AIE); |
---|
431 | 406 | |
---|
432 | | -err: |
---|
433 | | - return ret; |
---|
| 407 | + return 0; |
---|
434 | 408 | } |
---|
435 | 409 | |
---|
436 | 410 | /* |
---|
.. | .. |
---|
447 | 421 | struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); |
---|
448 | 422 | int ret; |
---|
449 | 423 | |
---|
450 | | - mutex_lock(&data->lock); |
---|
451 | 424 | if (data->timer_alarm) |
---|
452 | 425 | ret = _abb5zes3_rtc_read_timer(dev, alarm); |
---|
453 | 426 | else |
---|
454 | 427 | ret = _abb5zes3_rtc_read_alarm(dev, alarm); |
---|
455 | | - mutex_unlock(&data->lock); |
---|
456 | 428 | |
---|
457 | 429 | return ret; |
---|
458 | 430 | } |
---|
.. | .. |
---|
466 | 438 | { |
---|
467 | 439 | struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); |
---|
468 | 440 | struct rtc_time *alarm_tm = &alarm->time; |
---|
469 | | - unsigned long rtc_secs, alarm_secs; |
---|
470 | 441 | u8 regs[ABB5ZES3_ALRM_SEC_LEN]; |
---|
471 | 442 | struct rtc_time rtc_tm; |
---|
472 | 443 | int ret, enable = 1; |
---|
473 | 444 | |
---|
474 | | - ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); |
---|
475 | | - if (ret) |
---|
476 | | - goto err; |
---|
477 | | - |
---|
478 | | - ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); |
---|
479 | | - if (ret) |
---|
480 | | - goto err; |
---|
481 | | - |
---|
482 | | - ret = rtc_tm_to_time(alarm_tm, &alarm_secs); |
---|
483 | | - if (ret) |
---|
484 | | - goto err; |
---|
485 | | - |
---|
486 | | - /* If alarm time is before current time, disable the alarm */ |
---|
487 | | - if (!alarm->enabled || alarm_secs <= rtc_secs) { |
---|
| 445 | + if (!alarm->enabled) { |
---|
488 | 446 | enable = 0; |
---|
489 | 447 | } else { |
---|
| 448 | + unsigned long rtc_secs, alarm_secs; |
---|
| 449 | + |
---|
490 | 450 | /* |
---|
491 | 451 | * Chip only support alarms up to one month in the future. Let's |
---|
492 | 452 | * return an error if we get something after that limit. |
---|
493 | 453 | * Comparison is done by incrementing rtc_tm month field by one |
---|
494 | 454 | * and checking alarm value is still below. |
---|
495 | 455 | */ |
---|
| 456 | + ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); |
---|
| 457 | + if (ret) |
---|
| 458 | + return ret; |
---|
| 459 | + |
---|
496 | 460 | if (rtc_tm.tm_mon == 11) { /* handle year wrapping */ |
---|
497 | 461 | rtc_tm.tm_mon = 0; |
---|
498 | 462 | rtc_tm.tm_year += 1; |
---|
.. | .. |
---|
500 | 464 | rtc_tm.tm_mon += 1; |
---|
501 | 465 | } |
---|
502 | 466 | |
---|
503 | | - ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); |
---|
504 | | - if (ret) |
---|
505 | | - goto err; |
---|
| 467 | + rtc_secs = rtc_tm_to_time64(&rtc_tm); |
---|
| 468 | + alarm_secs = rtc_tm_to_time64(alarm_tm); |
---|
506 | 469 | |
---|
507 | 470 | if (alarm_secs > rtc_secs) { |
---|
508 | | - dev_err(dev, "%s: alarm maximum is one month in the " |
---|
509 | | - "future (%d)\n", __func__, ret); |
---|
510 | | - ret = -EINVAL; |
---|
511 | | - goto err; |
---|
| 471 | + dev_err(dev, "%s: alarm maximum is one month in the future (%d)\n", |
---|
| 472 | + __func__, ret); |
---|
| 473 | + return -EINVAL; |
---|
512 | 474 | } |
---|
513 | 475 | } |
---|
514 | 476 | |
---|
.. | .. |
---|
526 | 488 | if (ret < 0) { |
---|
527 | 489 | dev_err(dev, "%s: writing ALARM section failed (%d)\n", |
---|
528 | 490 | __func__, ret); |
---|
529 | | - goto err; |
---|
| 491 | + return ret; |
---|
530 | 492 | } |
---|
531 | 493 | |
---|
532 | 494 | /* Record currently configured alarm is not a timer */ |
---|
533 | 495 | data->timer_alarm = 0; |
---|
534 | 496 | |
---|
535 | 497 | /* Enable or disable alarm interrupt generation */ |
---|
536 | | - ret = _abb5zes3_rtc_update_alarm(dev, enable); |
---|
537 | | - |
---|
538 | | -err: |
---|
539 | | - return ret; |
---|
| 498 | + return _abb5zes3_rtc_update_alarm(dev, enable); |
---|
540 | 499 | } |
---|
541 | 500 | |
---|
542 | 501 | /* |
---|
.. | .. |
---|
557 | 516 | ABB5ZES3_TIMA_SEC_LEN); |
---|
558 | 517 | if (ret < 0) { |
---|
559 | 518 | dev_err(dev, "%s: writing timer section failed\n", __func__); |
---|
560 | | - goto err; |
---|
| 519 | + return ret; |
---|
561 | 520 | } |
---|
562 | 521 | |
---|
563 | 522 | /* Configure Timer A as a watchdog timer */ |
---|
.. | .. |
---|
570 | 529 | data->timer_alarm = 1; |
---|
571 | 530 | |
---|
572 | 531 | /* Enable or disable timer interrupt generation */ |
---|
573 | | - ret = _abb5zes3_rtc_update_timer(dev, alarm->enabled); |
---|
574 | | - |
---|
575 | | -err: |
---|
576 | | - return ret; |
---|
| 532 | + return _abb5zes3_rtc_update_timer(dev, alarm->enabled); |
---|
577 | 533 | } |
---|
578 | 534 | |
---|
579 | 535 | /* |
---|
.. | .. |
---|
590 | 546 | struct rtc_time rtc_tm; |
---|
591 | 547 | int ret; |
---|
592 | 548 | |
---|
593 | | - mutex_lock(&data->lock); |
---|
594 | 549 | ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); |
---|
595 | 550 | if (ret) |
---|
596 | | - goto err; |
---|
| 551 | + return ret; |
---|
597 | 552 | |
---|
598 | | - ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); |
---|
599 | | - if (ret) |
---|
600 | | - goto err; |
---|
601 | | - |
---|
602 | | - ret = rtc_tm_to_time(alarm_tm, &alarm_secs); |
---|
603 | | - if (ret) |
---|
604 | | - goto err; |
---|
| 553 | + rtc_secs = rtc_tm_to_time64(&rtc_tm); |
---|
| 554 | + alarm_secs = rtc_tm_to_time64(alarm_tm); |
---|
605 | 555 | |
---|
606 | 556 | /* Let's first disable both the alarm and the timer interrupts */ |
---|
607 | 557 | ret = _abb5zes3_rtc_update_alarm(dev, false); |
---|
608 | 558 | if (ret < 0) { |
---|
609 | 559 | dev_err(dev, "%s: unable to disable alarm (%d)\n", __func__, |
---|
610 | 560 | ret); |
---|
611 | | - goto err; |
---|
| 561 | + return ret; |
---|
612 | 562 | } |
---|
613 | 563 | ret = _abb5zes3_rtc_update_timer(dev, false); |
---|
614 | 564 | if (ret < 0) { |
---|
615 | 565 | dev_err(dev, "%s: unable to disable timer (%d)\n", __func__, |
---|
616 | 566 | ret); |
---|
617 | | - goto err; |
---|
| 567 | + return ret; |
---|
618 | 568 | } |
---|
619 | 569 | |
---|
620 | 570 | data->timer_alarm = 0; |
---|
.. | .. |
---|
628 | 578 | alarm_secs - rtc_secs); |
---|
629 | 579 | else |
---|
630 | 580 | ret = _abb5zes3_rtc_set_alarm(dev, alarm); |
---|
631 | | - |
---|
632 | | - err: |
---|
633 | | - mutex_unlock(&data->lock); |
---|
634 | 581 | |
---|
635 | 582 | if (ret) |
---|
636 | 583 | dev_err(dev, "%s: unable to configure alarm (%d)\n", __func__, |
---|
.. | .. |
---|
650 | 597 | |
---|
651 | 598 | /* |
---|
652 | 599 | * Check current RTC status and enable/disable what needs to be. Return 0 if |
---|
653 | | - * everything went ok and a negative value upon error. Note: this function |
---|
654 | | - * is called early during init and hence does need mutex protection. |
---|
| 600 | + * everything went ok and a negative value upon error. |
---|
655 | 601 | */ |
---|
656 | 602 | static int abb5zes3_rtc_check_setup(struct device *dev) |
---|
657 | 603 | { |
---|
.. | .. |
---|
675 | 621 | ABB5ZES3_REG_TIM_CLK_COF1 | ABB5ZES3_REG_TIM_CLK_COF2 | |
---|
676 | 622 | ABB5ZES3_REG_TIM_CLK_TBM | ABB5ZES3_REG_TIM_CLK_TAM); |
---|
677 | 623 | ret = regmap_update_bits(regmap, ABB5ZES3_REG_TIM_CLK, mask, |
---|
678 | | - ABB5ZES3_REG_TIM_CLK_COF0 | ABB5ZES3_REG_TIM_CLK_COF1 | |
---|
679 | | - ABB5ZES3_REG_TIM_CLK_COF2); |
---|
| 624 | + ABB5ZES3_REG_TIM_CLK_COF0 | |
---|
| 625 | + ABB5ZES3_REG_TIM_CLK_COF1 | |
---|
| 626 | + ABB5ZES3_REG_TIM_CLK_COF2); |
---|
680 | 627 | if (ret < 0) { |
---|
681 | 628 | dev_err(dev, "%s: unable to initialize clkout register (%d)\n", |
---|
682 | 629 | __func__, ret); |
---|
.. | .. |
---|
729 | 676 | * switchover flag but not battery low flag. The latter is checked |
---|
730 | 677 | * later below. |
---|
731 | 678 | */ |
---|
732 | | - mask = (ABB5ZES3_REG_CTRL3_PM0 | ABB5ZES3_REG_CTRL3_PM1 | |
---|
733 | | - ABB5ZES3_REG_CTRL3_PM2 | ABB5ZES3_REG_CTRL3_BLIE | |
---|
734 | | - ABB5ZES3_REG_CTRL3_BSIE| ABB5ZES3_REG_CTRL3_BSF); |
---|
| 679 | + mask = (ABB5ZES3_REG_CTRL3_PM0 | ABB5ZES3_REG_CTRL3_PM1 | |
---|
| 680 | + ABB5ZES3_REG_CTRL3_PM2 | ABB5ZES3_REG_CTRL3_BLIE | |
---|
| 681 | + ABB5ZES3_REG_CTRL3_BSIE | ABB5ZES3_REG_CTRL3_BSF); |
---|
735 | 682 | ret = regmap_update_bits(regmap, ABB5ZES3_REG_CTRL3, mask, 0); |
---|
736 | 683 | if (ret < 0) { |
---|
737 | 684 | dev_err(dev, "%s: unable to initialize CTRL3 register (%d)\n", |
---|
.. | .. |
---|
748 | 695 | } |
---|
749 | 696 | |
---|
750 | 697 | if (reg & ABB5ZES3_REG_RTC_SC_OSC) { |
---|
751 | | - dev_err(dev, "clock integrity not guaranteed. Osc. has stopped " |
---|
752 | | - "or has been interrupted.\n"); |
---|
753 | | - dev_err(dev, "change battery (if not already done) and " |
---|
754 | | - "then set time to reset osc. failure flag.\n"); |
---|
| 698 | + dev_err(dev, "clock integrity not guaranteed. Osc. has stopped or has been interrupted.\n"); |
---|
| 699 | + dev_err(dev, "change battery (if not already done) and then set time to reset osc. failure flag.\n"); |
---|
755 | 700 | } |
---|
756 | 701 | |
---|
757 | 702 | /* |
---|
.. | .. |
---|
769 | 714 | |
---|
770 | 715 | data->battery_low = reg & ABB5ZES3_REG_CTRL3_BLF; |
---|
771 | 716 | if (data->battery_low) { |
---|
772 | | - dev_err(dev, "RTC battery is low; please, consider " |
---|
773 | | - "changing it!\n"); |
---|
| 717 | + dev_err(dev, "RTC battery is low; please, consider changing it!\n"); |
---|
774 | 718 | |
---|
775 | 719 | ret = _abb5zes3_rtc_battery_low_irq_enable(regmap, false); |
---|
776 | 720 | if (ret) |
---|
777 | | - dev_err(dev, "%s: disabling battery low interrupt " |
---|
778 | | - "generation failed (%d)\n", __func__, ret); |
---|
| 721 | + dev_err(dev, "%s: disabling battery low interrupt generation failed (%d)\n", |
---|
| 722 | + __func__, ret); |
---|
779 | 723 | } |
---|
780 | 724 | |
---|
781 | 725 | return ret; |
---|
.. | .. |
---|
788 | 732 | int ret = 0; |
---|
789 | 733 | |
---|
790 | 734 | if (rtc_data->irq) { |
---|
791 | | - mutex_lock(&rtc_data->lock); |
---|
792 | 735 | if (rtc_data->timer_alarm) |
---|
793 | 736 | ret = _abb5zes3_rtc_update_timer(dev, enable); |
---|
794 | 737 | else |
---|
795 | 738 | ret = _abb5zes3_rtc_update_alarm(dev, enable); |
---|
796 | | - mutex_unlock(&rtc_data->lock); |
---|
797 | 739 | } |
---|
798 | 740 | |
---|
799 | 741 | return ret; |
---|
.. | .. |
---|
885 | 827 | |
---|
886 | 828 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | |
---|
887 | 829 | I2C_FUNC_SMBUS_BYTE_DATA | |
---|
888 | | - I2C_FUNC_SMBUS_I2C_BLOCK)) { |
---|
889 | | - ret = -ENODEV; |
---|
890 | | - goto err; |
---|
891 | | - } |
---|
| 830 | + I2C_FUNC_SMBUS_I2C_BLOCK)) |
---|
| 831 | + return -ENODEV; |
---|
892 | 832 | |
---|
893 | 833 | regmap = devm_regmap_init_i2c(client, &abb5zes3_rtc_regmap_config); |
---|
894 | 834 | if (IS_ERR(regmap)) { |
---|
895 | 835 | ret = PTR_ERR(regmap); |
---|
896 | 836 | dev_err(dev, "%s: regmap allocation failed: %d\n", |
---|
897 | 837 | __func__, ret); |
---|
898 | | - goto err; |
---|
| 838 | + return ret; |
---|
899 | 839 | } |
---|
900 | 840 | |
---|
901 | 841 | ret = abb5zes3_i2c_validate_chip(regmap); |
---|
902 | 842 | if (ret) |
---|
903 | | - goto err; |
---|
| 843 | + return ret; |
---|
904 | 844 | |
---|
905 | 845 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
---|
906 | | - if (!data) { |
---|
907 | | - ret = -ENOMEM; |
---|
908 | | - goto err; |
---|
909 | | - } |
---|
| 846 | + if (!data) |
---|
| 847 | + return -ENOMEM; |
---|
910 | 848 | |
---|
911 | | - mutex_init(&data->lock); |
---|
912 | 849 | data->regmap = regmap; |
---|
913 | 850 | dev_set_drvdata(dev, data); |
---|
914 | 851 | |
---|
915 | 852 | ret = abb5zes3_rtc_check_setup(dev); |
---|
916 | 853 | if (ret) |
---|
917 | | - goto err; |
---|
| 854 | + return ret; |
---|
918 | 855 | |
---|
919 | 856 | data->rtc = devm_rtc_allocate_device(dev); |
---|
920 | 857 | ret = PTR_ERR_OR_ZERO(data->rtc); |
---|
921 | 858 | if (ret) { |
---|
922 | 859 | dev_err(dev, "%s: unable to allocate RTC device (%d)\n", |
---|
923 | 860 | __func__, ret); |
---|
924 | | - goto err; |
---|
| 861 | + return ret; |
---|
925 | 862 | } |
---|
926 | 863 | |
---|
927 | 864 | if (client->irq > 0) { |
---|
928 | 865 | ret = devm_request_threaded_irq(dev, client->irq, NULL, |
---|
929 | 866 | _abb5zes3_rtc_interrupt, |
---|
930 | | - IRQF_SHARED|IRQF_ONESHOT, |
---|
| 867 | + IRQF_SHARED | IRQF_ONESHOT, |
---|
931 | 868 | DRV_NAME, client); |
---|
932 | 869 | if (!ret) { |
---|
933 | 870 | device_init_wakeup(dev, true); |
---|
.. | .. |
---|
949 | 886 | if (!data->battery_low && data->irq) { |
---|
950 | 887 | ret = _abb5zes3_rtc_battery_low_irq_enable(regmap, true); |
---|
951 | 888 | if (ret) { |
---|
952 | | - dev_err(dev, "%s: enabling battery low interrupt " |
---|
953 | | - "generation failed (%d)\n", __func__, ret); |
---|
| 889 | + dev_err(dev, "%s: enabling battery low interrupt generation failed (%d)\n", |
---|
| 890 | + __func__, ret); |
---|
954 | 891 | goto err; |
---|
955 | 892 | } |
---|
956 | 893 | } |
---|
.. | .. |
---|
958 | 895 | ret = rtc_register_device(data->rtc); |
---|
959 | 896 | |
---|
960 | 897 | err: |
---|
961 | | - if (ret && data && data->irq) |
---|
| 898 | + if (ret && data->irq) |
---|
962 | 899 | device_init_wakeup(dev, false); |
---|
963 | 900 | return ret; |
---|
964 | | -} |
---|
965 | | - |
---|
966 | | -static int abb5zes3_remove(struct i2c_client *client) |
---|
967 | | -{ |
---|
968 | | - struct abb5zes3_rtc_data *rtc_data = dev_get_drvdata(&client->dev); |
---|
969 | | - |
---|
970 | | - if (rtc_data->irq > 0) |
---|
971 | | - device_init_wakeup(&client->dev, false); |
---|
972 | | - |
---|
973 | | - return 0; |
---|
974 | 901 | } |
---|
975 | 902 | |
---|
976 | 903 | #ifdef CONFIG_PM_SLEEP |
---|
.. | .. |
---|
1019 | 946 | .of_match_table = of_match_ptr(abb5zes3_dt_match), |
---|
1020 | 947 | }, |
---|
1021 | 948 | .probe = abb5zes3_probe, |
---|
1022 | | - .remove = abb5zes3_remove, |
---|
1023 | 949 | .id_table = abb5zes3_id, |
---|
1024 | 950 | }; |
---|
1025 | 951 | module_i2c_driver(abb5zes3_driver); |
---|