Skip to content

Commit 71af915

Browse files
mcbridemattalexandrebelloni
authored andcommitted
rtc: rx8025: fix 12/24 hour mode detection on RX-8035
The 12/24hr flag in the RX-8035 can be found in the hour register, instead of the CTRL1 on the RX-8025. This was overlooked when support for the RX-8035 was added, and was causing read errors when the hour register 'overflowed'. To deal with the relevant register not always being visible in the relevant functions, determine the 12/24 mode at startup and store it in the driver state. Signed-off-by: Mathew McBride <[email protected]> Fixes: f120e2e ("rtc: rx8025: implement RX-8035 support") Cc: [email protected] Signed-off-by: Alexandre Belloni <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5c9f414 commit 71af915

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

drivers/rtc/rtc-rx8025.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
#define RX8025_BIT_CTRL2_XST BIT(5)
5656
#define RX8025_BIT_CTRL2_VDET BIT(6)
5757

58+
#define RX8035_BIT_HOUR_1224 BIT(7)
59+
5860
/* Clock precision adjustment */
5961
#define RX8025_ADJ_RESOLUTION 3050 /* in ppb */
6062
#define RX8025_ADJ_DATA_MAX 62
@@ -78,6 +80,7 @@ struct rx8025_data {
7880
struct rtc_device *rtc;
7981
enum rx_model model;
8082
u8 ctrl1;
83+
int is_24;
8184
};
8285

8386
static s32 rx8025_read_reg(const struct i2c_client *client, u8 number)
@@ -226,7 +229,7 @@ static int rx8025_get_time(struct device *dev, struct rtc_time *dt)
226229

227230
dt->tm_sec = bcd2bin(date[RX8025_REG_SEC] & 0x7f);
228231
dt->tm_min = bcd2bin(date[RX8025_REG_MIN] & 0x7f);
229-
if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
232+
if (rx8025->is_24)
230233
dt->tm_hour = bcd2bin(date[RX8025_REG_HOUR] & 0x3f);
231234
else
232235
dt->tm_hour = bcd2bin(date[RX8025_REG_HOUR] & 0x1f) % 12
@@ -254,7 +257,7 @@ static int rx8025_set_time(struct device *dev, struct rtc_time *dt)
254257
*/
255258
date[RX8025_REG_SEC] = bin2bcd(dt->tm_sec);
256259
date[RX8025_REG_MIN] = bin2bcd(dt->tm_min);
257-
if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
260+
if (rx8025->is_24)
258261
date[RX8025_REG_HOUR] = bin2bcd(dt->tm_hour);
259262
else
260263
date[RX8025_REG_HOUR] = (dt->tm_hour >= 12 ? 0x20 : 0)
@@ -279,6 +282,7 @@ static int rx8025_init_client(struct i2c_client *client)
279282
struct rx8025_data *rx8025 = i2c_get_clientdata(client);
280283
u8 ctrl[2], ctrl2;
281284
int need_clear = 0;
285+
int hour_reg;
282286
int err;
283287

284288
err = rx8025_read_regs(client, RX8025_REG_CTRL1, 2, ctrl);
@@ -303,6 +307,16 @@ static int rx8025_init_client(struct i2c_client *client)
303307

304308
err = rx8025_write_reg(client, RX8025_REG_CTRL2, ctrl2);
305309
}
310+
311+
if (rx8025->model == model_rx_8035) {
312+
/* In RX-8035, 12/24 flag is in the hour register */
313+
hour_reg = rx8025_read_reg(client, RX8025_REG_HOUR);
314+
if (hour_reg < 0)
315+
return hour_reg;
316+
rx8025->is_24 = (hour_reg & RX8035_BIT_HOUR_1224);
317+
} else {
318+
rx8025->is_24 = (ctrl[1] & RX8025_BIT_CTRL1_1224);
319+
}
306320
out:
307321
return err;
308322
}
@@ -329,7 +343,7 @@ static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t)
329343
/* Hardware alarms precision is 1 minute! */
330344
t->time.tm_sec = 0;
331345
t->time.tm_min = bcd2bin(ald[0] & 0x7f);
332-
if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
346+
if (rx8025->is_24)
333347
t->time.tm_hour = bcd2bin(ald[1] & 0x3f);
334348
else
335349
t->time.tm_hour = bcd2bin(ald[1] & 0x1f) % 12
@@ -350,7 +364,7 @@ static int rx8025_set_alarm(struct device *dev, struct rtc_wkalrm *t)
350364
int err;
351365

352366
ald[0] = bin2bcd(t->time.tm_min);
353-
if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
367+
if (rx8025->is_24)
354368
ald[1] = bin2bcd(t->time.tm_hour);
355369
else
356370
ald[1] = (t->time.tm_hour >= 12 ? 0x20 : 0)

0 commit comments

Comments
 (0)