rtc: ab-b5ze-s3: remove mutex
Alexandre Belloni
maintainerPATCH 1/5 rtc: ab-b5ze-s3: remove mutex
The rtc_ops are already called with the RTC mutex locked so there is no need to have a separate lock, unless it is used in the irq handler.
Signed-off-by Alexandre Belloni <[email protected]>
--- drivers/rtc/rtc-ab-b5ze-s3.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-)
drivers/rtc/rtc-ab-b5ze-s3.c +2 -17
@@ -22,7 +22,6 @@*/ #include <linux/module.h> -#include <linux/mutex.h> #include <linux/rtc.h> #include <linux/i2c.h> #include <linux/bcd.h>
@@ -128,7 +127,6 @@struct abb5zes3_rtc_data {struct rtc_device *rtc;struct regmap *regmap; -struct mutex lock;int irq;
@@ -138,8 +136,7 @@ struct abb5zes3_rtc_data {/* * Try and match register bits w/ fixed null values to see whether we -* are dealing with an ABB5ZES3. Note: this function is called early -* during init and hence does need mutex protection. +* are dealing with an ABB5ZES3. */ static int abb5zes3_i2c_validate_chip (struct regmap *regmap) {
@@ -273,12 +270,9 @@ static int abb5zes3_rtc_set_time(struct device *dev, struct rtc_time *tm) regs[ABB5ZES3_REG_RTC_MO ] =bin2bcd (tm->tm_mon +1 ); regs[ABB5ZES3_REG_RTC_YR ] =bin2bcd (tm->tm_year -100 ); -mutex_lock (&data->lock); ret =regmap_bulk_write (data->regmap,ABB5ZES3_REG_RTC_SC , regs +ABB5ZES3_REG_RTC_SC ,ABB5ZES3_RTC_SEC_LEN ); -mutex_unlock (&data->lock); -return ret; }
@@ -447,12 +441,10 @@ static int abb5zes3_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)struct abb5zes3_rtc_data *data =dev_get_drvdata (dev);int ret; -mutex_lock (&data->lock);if (data->timer_alarm) ret =_abb5zes3_rtc_read_timer (dev, alarm);else ret =_abb5zes3_rtc_read_alarm (dev, alarm); -mutex_unlock (&data->lock);return ret; }
@@ -590,7 +582,6 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)struct rtc_time rtc_tm;int ret; -mutex_lock (&data->lock); ret =_abb5zes3_rtc_read_time (dev, &rtc_tm);if (ret) goto err;
@@ -630,8 +621,6 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ret =_abb5zes3_rtc_set_alarm (dev, alarm); err: -mutex_unlock (&data->lock); -if (ret)dev_err (dev,"%s: unable to configure alarm (%d)\n" , __func__, ret);
@@ -650,8 +639,7 @@ static inline int _abb5zes3_rtc_battery_low_irq_enable(struct regmap *regmap,/* * Check current RTC status and enable/disable what needs to be. Return 0 if -* everything went ok and a negative value upon error. Note: this function -* is called early during init and hence does need mutex protection. +* everything went ok and a negative value upon error. */ static int abb5zes3_rtc_check_setup (struct device *dev) {
@@ -788,12 +776,10 @@ static int abb5zes3_rtc_alarm_irq_enable(struct device *dev,int ret =0 ;if (rtc_data->irq) { -mutex_lock (&rtc_data->lock);if (rtc_data->timer_alarm) ret =_abb5zes3_rtc_update_timer (dev, enable);else ret =_abb5zes3_rtc_update_alarm (dev, enable); -mutex_unlock (&rtc_data->lock); }return ret;
@@ -908,7 +894,6 @@ static int abb5zes3_probe(struct i2c_client *client, goto err; } -mutex_init (&data->lock); data->regmap = regmap;dev_set_drvdata (dev, data);
Signature · 1 line
2.20.1
Alexandre Belloni
maintainerPATCH 2/5 rtc: ab-b5ze-s3: remove unnecessary gotos
Rework error handling to remove unnecessary gotos.
Signed-off-by Alexandre Belloni <[email protected]>
--- drivers/rtc/rtc-ab-b5ze-s3.c | 93 +++++++++++++++--------------------- 1 file changed, 38 insertions(+), 55 deletions(-)
drivers/rtc/rtc-ab-b5ze-s3.c +38 -55
@@ -227,14 +227,12 @@ static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm)if (ret) {dev_err (dev,"%s: reading RTC time failed (%d)\n" , __func__, ret); - goto err; +return ret; }/* If clock integrity is not guaranteed, do not return a time value */ -if (regs[ABB5ZES3_REG_RTC_SC ] &ABB5ZES3_REG_RTC_SC_OSC ) { - ret = -ENODATA ; - goto err; - } +if (regs[ABB5ZES3_REG_RTC_SC ] &ABB5ZES3_REG_RTC_SC_OSC ) +return -ENODATA ; tm->tm_sec =bcd2bin (regs[ABB5ZES3_REG_RTC_SC ] &0x7F ); tm->tm_min =bcd2bin (regs[ABB5ZES3_REG_RTC_MN ]);
@@ -252,7 +250,6 @@ static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm) tm->tm_mon =bcd2bin (regs[ABB5ZES3_REG_RTC_MO ]) -1 ;/* starts at 1 */ tm->tm_year =bcd2bin (regs[ABB5ZES3_REG_RTC_YR ]) +100 ; -err:return ret; }
@@ -326,23 +323,23 @@ static int _abb5zes3_rtc_read_timer(struct device *dev,if (ret) {dev_err (dev,"%s: reading Timer A section failed (%d)\n" , __func__, ret); - goto err; +return ret; }/* get current time ... */ ret =_abb5zes3_rtc_read_time (dev, &rtc_tm);if (ret) - goto err; +return ret;/* ... convert to seconds ... */ ret =rtc_tm_to_time (&rtc_tm, &rtc_secs);if (ret) - goto err; +return ret;/* ... add remaining timer A time ... */ ret =sec_from_timer_a (&timer_secs, regs[1 ], regs[2 ]);if (ret) - goto err; +return ret;/* ... and convert back. */ rtc_time_to_tm (rtc_secs + timer_secs, alarm_tm);
@@ -351,13 +348,12 @@ static int _abb5zes3_rtc_read_timer(struct device *dev,if (ret) {dev_err (dev,"%s: reading ctrl reg failed (%d)\n" , __func__, ret); - goto err; +return ret; } alarm->enabled = !!(reg &ABB5ZES3_REG_CTRL2_WTAIE ); -err: -return ret; +return 0 ; }/* Read alarm currently configured via a RTC alarm registers. */
@@ -376,7 +372,7 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev,if (ret) {dev_err (dev,"%s: reading alarm section failed (%d)\n" , __func__, ret); - goto err; +return ret; } alarm_tm->tm_sec =0 ;
@@ -392,18 +388,18 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev,*/ ret =_abb5zes3_rtc_read_time (dev, &rtc_tm);if (ret) - goto err; +return ret; alarm_tm->tm_year = rtc_tm.tm_year; alarm_tm->tm_mon = rtc_tm.tm_mon; ret =rtc_tm_to_time (&rtc_tm, &rtc_secs);if (ret) - goto err; +return ret; ret =rtc_tm_to_time (alarm_tm, &alarm_secs);if (ret) - goto err; +return ret;if (alarm_secs < rtc_secs) {if (alarm_tm->tm_mon ==11 ) {
@@ -418,13 +414,12 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev,if (ret) {dev_err (dev,"%s: reading ctrl reg failed (%d)\n" , __func__, ret); - goto err; +return ret; } alarm->enabled = !!(reg &ABB5ZES3_REG_CTRL1_AIE ); -err: -return ret; +return 0 ; }/*
@@ -465,15 +460,15 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ret =_abb5zes3_rtc_read_time (dev, &rtc_tm);if (ret) - goto err; +return ret; ret =rtc_tm_to_time (&rtc_tm, &rtc_secs);if (ret) - goto err; +return ret; ret =rtc_tm_to_time (alarm_tm, &alarm_secs);if (ret) - goto err; +return ret;/* If alarm time is before current time, disable the alarm */ if (!alarm->enabled || alarm_secs <= rtc_secs) {
@@ -494,13 +489,12 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ret =rtc_tm_to_time (&rtc_tm, &rtc_secs);if (ret) - goto err; +return ret;if (alarm_secs > rtc_secs) {dev_err (dev,"%s: alarm maximum is one month in the " "future (%d)\n" , __func__, ret); - ret = -EINVAL ; - goto err; +return -EINVAL ; } }
@@ -518,17 +512,14 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)if (ret <0 ) {dev_err (dev,"%s: writing ALARM section failed (%d)\n" , __func__, ret); - goto err; +return ret; }/* Record currently configured alarm is not a timer */ data->timer_alarm =0 ;/* Enable or disable alarm interrupt generation */ - ret =_abb5zes3_rtc_update_alarm (dev, enable); - -err: -return ret; +return _abb5zes3_rtc_update_alarm (dev, enable); }/*
@@ -549,7 +540,7 @@ static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm, ABB5ZES3_TIMA_SEC_LEN);if (ret <0 ) {dev_err (dev,"%s: writing timer section failed\n" , __func__); - goto err; +return ret; }/* Configure Timer A as a watchdog timer */
@@ -562,10 +553,7 @@ static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm, data->timer_alarm =1 ;/* Enable or disable timer interrupt generation */ - ret =_abb5zes3_rtc_update_timer (dev, alarm->enabled); - -err: -return ret; +return _abb5zes3_rtc_update_timer (dev, alarm->enabled); }/*
@@ -584,28 +572,28 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ret =_abb5zes3_rtc_read_time (dev, &rtc_tm);if (ret) - goto err; +return ret; ret =rtc_tm_to_time (&rtc_tm, &rtc_secs);if (ret) - goto err; +return ret; ret =rtc_tm_to_time (alarm_tm, &alarm_secs);if (ret) - goto err; +return ret;/* Let's first disable both the alarm and the timer interrupts */ ret =_abb5zes3_rtc_update_alarm (dev, false);if (ret <0 ) {dev_err (dev,"%s: unable to disable alarm (%d)\n" , __func__, ret); - goto err; +return ret; } ret =_abb5zes3_rtc_update_timer (dev, false);if (ret <0 ) {dev_err (dev,"%s: unable to disable timer (%d)\n" , __func__, ret); - goto err; +return ret; } data->timer_alarm =0 ;
@@ -620,7 +608,6 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)else ret =_abb5zes3_rtc_set_alarm (dev, alarm); - err:if (ret)dev_err (dev,"%s: unable to configure alarm (%d)\n" , __func__, ret);
@@ -871,42 +858,38 @@ static int abb5zes3_probe(struct i2c_client *client,if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C |I2C_FUNC_SMBUS_BYTE_DATA | -I2C_FUNC_SMBUS_I2C_BLOCK )) { - ret = -ENODEV ; - goto err; - } +I2C_FUNC_SMBUS_I2C_BLOCK )) +return -ENODEV ; regmap =devm_regmap_init_i2c (client, &abb5zes3_rtc_regmap_config);if (IS_ERR (regmap)) { ret =PTR_ERR (regmap);dev_err (dev,"%s: regmap allocation failed: %d\n" , __func__, ret); - goto err; +return ret; } ret =abb5zes3_i2c_validate_chip (regmap);if (ret) - goto err; +return ret; data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); -if (!data) { - ret = -ENOMEM ; - goto err; - } +if (!data) +return -ENOMEM ; data->regmap = regmap;dev_set_drvdata (dev, data); ret =abb5zes3_rtc_check_setup (dev);if (ret) - goto err; +return ret; data->rtc =devm_rtc_allocate_device (dev); ret =PTR_ERR_OR_ZERO (data->rtc);if (ret) {dev_err (dev,"%s: unable to allocate RTC device (%d)\n" , __func__, ret); - goto err; +return ret; }if (client->irq >0 ) {
@@ -943,7 +926,7 @@ static int abb5zes3_probe(struct i2c_client *client, ret =rtc_register_device (data->rtc); err: -if (ret && data && data->irq) +if (ret && data->irq)device_init_wakeup (dev, false);return ret; }
Signature · 1 line
2.20.1
Alexandre Belloni
maintainerPATCH 3/5 rtc: ab-b5ze-s3: switch to rtc_time64_to_tm/rtc_tm_to_time64
In reply to Alexandre BelloniCall the 64bit versions of rtc_time_to_tm as the range is enforced by the core.
Signed-off-by Alexandre Belloni <[email protected]>
--- drivers/rtc/rtc-ab-b5ze-s3.c | 37 +++++++++--------------------------- 1 file changed, 9 insertions(+), 28 deletions(-)
drivers/rtc/rtc-ab-b5ze-s3.c +9 -28
@@ -332,9 +332,7 @@ static int _abb5zes3_rtc_read_timer(struct device *dev,return ret;/* ... convert to seconds ... */ - ret =rtc_tm_to_time (&rtc_tm, &rtc_secs); -if (ret) -return ret; + rtc_secs =rtc_tm_to_time64 (&rtc_tm);/* ... add remaining timer A time ... */ ret =sec_from_timer_a (&timer_secs, regs[1 ], regs[2 ]);
@@ -342,7 +340,7 @@ static int _abb5zes3_rtc_read_timer(struct device *dev,return ret;/* ... and convert back. */ -rtc_time_to_tm (rtc_secs + timer_secs, alarm_tm); +rtc_time64_to_tm (rtc_secs + timer_secs, alarm_tm); ret =regmap_read (data->regmap,ABB5ZES3_REG_CTRL2 , ®);if (ret) {
@@ -393,13 +391,8 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev, alarm_tm->tm_year = rtc_tm.tm_year; alarm_tm->tm_mon = rtc_tm.tm_mon; - ret =rtc_tm_to_time (&rtc_tm, &rtc_secs); -if (ret) -return ret; - - ret =rtc_tm_to_time (alarm_tm, &alarm_secs); -if (ret) -return ret; + rtc_secs =rtc_tm_to_time64 (&rtc_tm); + alarm_secs =rtc_tm_to_time64 (alarm_tm);if (alarm_secs < rtc_secs) {if (alarm_tm->tm_mon ==11 ) {
@@ -462,13 +455,8 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)if (ret)return ret; - ret =rtc_tm_to_time (&rtc_tm, &rtc_secs); -if (ret) -return ret; - - ret =rtc_tm_to_time (alarm_tm, &alarm_secs); -if (ret) -return ret; + rtc_secs =rtc_tm_to_time64 (&rtc_tm); + alarm_secs =rtc_tm_to_time64 (alarm_tm);/* If alarm time is before current time, disable the alarm */ if (!alarm->enabled || alarm_secs <= rtc_secs) {
@@ -487,9 +475,7 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) rtc_tm.tm_mon +=1 ; } - ret =rtc_tm_to_time (&rtc_tm, &rtc_secs); -if (ret) -return ret; + rtc_secs =rtc_tm_to_time64 (&rtc_tm);if (alarm_secs > rtc_secs) { dev_err(dev, "%s: alarm maximum is one month in the "
@@ -574,13 +560,8 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)if (ret)return ret; - ret =rtc_tm_to_time (&rtc_tm, &rtc_secs); -if (ret) -return ret; - - ret =rtc_tm_to_time (alarm_tm, &alarm_secs); -if (ret) -return ret; + rtc_secs =rtc_tm_to_time64 (&rtc_tm); + alarm_secs =rtc_tm_to_time64 (alarm_tm);/* Let's first disable both the alarm and the timer interrupts */ ret =_abb5zes3_rtc_update_alarm (dev, false);
Signature · 1 line
2.20.1
Alexandre Belloni
maintainerPATCH 4/5 rtc: ab-b5ze-s3: convert to SPDX identifier
In reply to Alexandre BelloniUse SPDX-License-Identifier instead of a verbose license text.
Signed-off-by Alexandre Belloni <[email protected]>
--- drivers/rtc/rtc-ab-b5ze-s3.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/rtc/rtc-ab-b5ze-s3.c +1 -9
@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * rtc-ab-b5ze-s3 - Driver for Abracon AB-RTCMC-32.768Khz-B5ZE-S3 * I2C RTC / Alarm chip
@@ -10,15 +11,6 @@* * This work is based on ISL12057 driver (drivers/rtc/rtc-isl12057.c). * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. */ #include <linux/module.h>
Signature · 1 line
2.20.1
Alexandre Belloni
maintainerPATCH 5/5 rtc: ab-b5ze-s3: remove unnecessary check
In reply to Alexandre BelloniThe core already checks that the alarm is set in the future. IT is not necessary to do it again in the driver.
Signed-off-by Alexandre Belloni <[email protected]>
--- drivers/rtc/rtc-ab-b5ze-s3.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/rtc/rtc-ab-b5ze-s3.c +8 -10
@@ -438,28 +438,25 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) {struct abb5zes3_rtc_data *data =dev_get_drvdata (dev);struct rtc_time *alarm_tm = &alarm->time; -unsigned long rtc_secs, alarm_secs;u8 regs[ABB5ZES3_ALRM_SEC_LEN ];struct rtc_time rtc_tm;int ret, enable =1 ; - ret =_abb5zes3_rtc_read_time (dev, &rtc_tm); -if (ret) -return ret; - - rtc_secs =rtc_tm_to_time64 (&rtc_tm); - alarm_secs =rtc_tm_to_time64 (alarm_tm); - -/* If alarm time is before current time, disable the alarm */ -if (!alarm->enabled || alarm_secs <= rtc_secs) { +if (!alarm->enabled) { enable =0 ; }else { +unsigned long rtc_secs, alarm_secs; +/* * Chip only support alarms up to one month in the future. Let's * return an error if we get something after that limit. * Comparison is done by incrementing rtc_tm month field by one * and checking alarm value is still below. */ + ret =_abb5zes3_rtc_read_time (dev, &rtc_tm); +if (ret) +return ret; +if (rtc_tm.tm_mon ==11 ) {/* handle year wrapping */ rtc_tm.tm_mon =0 ; rtc_tm.tm_year +=1 ;
@@ -468,6 +465,7 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) } rtc_secs =rtc_tm_to_time64 (&rtc_tm); + alarm_secs =rtc_tm_to_time64 (alarm_tm);if (alarm_secs > rtc_secs) { dev_err(dev, "%s: alarm maximum is one month in the "
Signature · 1 line
2.20.1