rtc: rx8025: use .set_offset/.read_offset

The driver has its own sysfs file to adjust the clock. Fortunately, it is
already in pbb, however, the sign it expects is the opposite of what the
RTC core does (which actually aligns with the RTC).

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211107225458.111068-12-alexandre.belloni@bootlin.com
This commit is contained in:
Alexandre Belloni 2021-11-07 23:54:57 +01:00
parent 3d35840dfb
commit b476266f06
1 changed files with 36 additions and 37 deletions

View File

@ -403,17 +403,7 @@ static int rx8025_alarm_irq_enable(struct device *dev, unsigned int enabled)
return 0; return 0;
} }
static const struct rtc_class_ops rx8025_rtc_ops = {
.read_time = rx8025_get_time,
.set_time = rx8025_set_time,
.read_alarm = rx8025_read_alarm,
.set_alarm = rx8025_set_alarm,
.alarm_irq_enable = rx8025_alarm_irq_enable,
};
/* /*
* Clock precision adjustment support
*
* According to the RX8025 SA/NB application manual the frequency and * According to the RX8025 SA/NB application manual the frequency and
* temperature characteristics can be approximated using the following * temperature characteristics can be approximated using the following
* equation: * equation:
@ -424,11 +414,8 @@ static const struct rtc_class_ops rx8025_rtc_ops = {
* a : Coefficient = (-35 +-5) * 10**-9 * a : Coefficient = (-35 +-5) * 10**-9
* ut: Ultimate temperature in degree = +25 +-5 degree * ut: Ultimate temperature in degree = +25 +-5 degree
* t : Any temperature in degree * t : Any temperature in degree
*
* Note that the clock adjustment in ppb must be entered (which is
* the negative value of the deviation).
*/ */
static int rx8025_get_clock_adjust(struct device *dev, int *adj) static int rx8025_read_offset(struct device *dev, long *offset)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
int digoff; int digoff;
@ -437,63 +424,75 @@ static int rx8025_get_clock_adjust(struct device *dev, int *adj)
if (digoff < 0) if (digoff < 0)
return digoff; return digoff;
*adj = digoff >= 64 ? digoff - 128 : digoff; *offset = digoff >= 64 ? digoff - 128 : digoff;
if (*adj > 0) if (*offset > 0)
(*adj)--; (*offset)--;
*adj *= -RX8025_ADJ_RESOLUTION; *offset *= RX8025_ADJ_RESOLUTION;
return 0; return 0;
} }
static int rx8025_set_clock_adjust(struct device *dev, int adj) static int rx8025_set_offset(struct device *dev, long offset)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
u8 digoff; u8 digoff;
int err; int err;
adj /= -RX8025_ADJ_RESOLUTION; offset /= RX8025_ADJ_RESOLUTION;
if (adj > RX8025_ADJ_DATA_MAX) if (offset > RX8025_ADJ_DATA_MAX)
adj = RX8025_ADJ_DATA_MAX; offset = RX8025_ADJ_DATA_MAX;
else if (adj < RX8025_ADJ_DATA_MIN) else if (offset < RX8025_ADJ_DATA_MIN)
adj = RX8025_ADJ_DATA_MIN; offset = RX8025_ADJ_DATA_MIN;
else if (adj > 0) else if (offset > 0)
adj++; offset++;
else if (adj < 0) else if (offset < 0)
adj += 128; offset += 128;
digoff = adj; digoff = offset;
err = rx8025_write_reg(client, RX8025_REG_DIGOFF, digoff); err = rx8025_write_reg(client, RX8025_REG_DIGOFF, digoff);
if (err) if (err)
return err; return err;
dev_dbg(dev, "%s: write 0x%02x\n", __func__, digoff);
return 0; return 0;
} }
static const struct rtc_class_ops rx8025_rtc_ops = {
.read_time = rx8025_get_time,
.set_time = rx8025_set_time,
.read_alarm = rx8025_read_alarm,
.set_alarm = rx8025_set_alarm,
.alarm_irq_enable = rx8025_alarm_irq_enable,
.read_offset = rx8025_read_offset,
.set_offset = rx8025_set_offset,
};
static ssize_t rx8025_sysfs_show_clock_adjust(struct device *dev, static ssize_t rx8025_sysfs_show_clock_adjust(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
int err, adj; long adj;
int err;
err = rx8025_get_clock_adjust(dev, &adj); dev_warn_once(dev, "clock_adjust_ppb is deprecated, use offset\n");
err = rx8025_read_offset(dev, &adj);
if (err) if (err)
return err; return err;
return sprintf(buf, "%d\n", adj); return sprintf(buf, "%ld\n", -adj);
} }
static ssize_t rx8025_sysfs_store_clock_adjust(struct device *dev, static ssize_t rx8025_sysfs_store_clock_adjust(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
int adj, err; long adj;
int err;
if (sscanf(buf, "%i", &adj) != 1) dev_warn_once(dev, "clock_adjust_ppb is deprecated, use offset\n");
if (kstrtol(buf, 10, &adj) != 0)
return -EINVAL; return -EINVAL;
err = rx8025_set_clock_adjust(dev, adj); err = rx8025_set_offset(dev, -adj);
return err ? err : count; return err ? err : count;
} }