Rtc-ds1307 driver question

Hello, happy new year.

I’m actually modifying the driver rtc-ds1307 from kernel 4.19 to have sysfs access to control the reset of osf bit manually when an osf error is catched by the system and when time is unreliable.

So I have now 2 files named osf_status and osf_reset in a folder named rtc.

“osf_status” file is read only because users want to access to OSF bit information from user-space. Furthermore, “osf_reset” file is write only, and when user do an “echo 0 > /sys/osf_reset”, then, the osf_status is 0 and the driver has to change the value of OSF bit to 0.

The main problem I meet is about how to change the value of OSF bit from the driver?

In the kernel.org (kernel 4.19: rtc-ds1307.c), you can see OSF flag is automatically clean after probing of the driver. But, to do this, parameters of function regmap_write are needded:

regmap_write(ds1307->regmap, DS1337_REG_STATUS,
The problem is with my function osf_reset_store:

static ssize_t osf_reset_store(struct device *dev, struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
int ret;
int reset;
ret = kstrtoint(buf, 10, &reset);
if (ret < 0)
return ret;
if ((reset == 0) || (reset == ‘0’)) {
_osf_reset = 1; // a global variable stocking number of reset 0 or 1
_osf_status = 0;// a global variable stocking status of osf bit 0 or 1
//What is following is not correct, but it’s something like this I would like to do (clear the flag OSF //when user echo a 0 in the /sys/osf_reset file). But i can’t access the device because the pattern of //regmap_write is determined by the system rules and cannot be changed.
regmap_write(ds1307->regmap, DS1337_REG_STATUS,
regs[1] & ~DS1337_BIT_OSF);

Thanks for all if you can explain me what i’m doing wrong, and how to bypass the problem if you know. best reguards :-).

I modify the driver to return sysfs access to user-space.