/* Caches and returns the value with the changes applied.  */
static int sc_ctrl(const struct device *dev, uint8_t set, uint8_t clear)
/* Caches and returns the value with the changes applied.  */
static int sc_ctrl(const struct device *dev, uint8_t set, uint8_t clear)
{
	struct ds3231_data *data = dev->data;
	const struct ds3231_config *cfg = dev->config;
	struct register_map *rp = &data->registers;
	uint8_t ctrl = (rp->ctrl & ~clear) | set;
	int rc = ctrl;
	if (rp->ctrl != ctrl) {
		uint8_t buf[2] = {
			offsetof(struct register_map, ctrl),
			ctrl,
		};
		rc = i2c_write_dt(&cfg->bus, buf, sizeof(buf));
		if (rc >= 0) {
			rp->ctrl = ctrl;
			rc = ctrl;
		}
	}
	return rc;
}