static int s35390a_set_datetime(struct i2c_client *client, struct rtc_time *tm) { struct s35390a *s35390a = i2c_get_clientdata(client); int i, err; char buf[7]; dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d mday=%d, " "mon=%d, year=%d, wday=%d\n", __func__, tm->tm_sec, tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); buf[S35390A_BYTE_YEAR] = bin2bcd(tm->tm_year - 100); buf[S35390A_BYTE_MONTH] = bin2bcd(tm->tm_mon + 1); buf[S35390A_BYTE_DAY] = bin2bcd(tm->tm_mday); buf[S35390A_BYTE_WDAY] = bin2bcd(tm->tm_wday); buf[S35390A_BYTE_HOURS] = s35390a_hr2reg(s35390a, tm->tm_hour); buf[S35390A_BYTE_MINS] = bin2bcd(tm->tm_min); buf[S35390A_BYTE_SECS] = bin2bcd(tm->tm_sec); /* This chip expects the bits of each byte to be in reverse order */ for (i = 0; i < 7; ++i) buf[i] = bitrev8(buf[i]); err = s35390a_set_reg(s35390a, S35390A_CMD_TIME1, buf, sizeof(buf)); return err; }
static int s35390a_set_alarm(struct i2c_client *client, struct rtc_wkalrm *alm) { struct s35390a *s35390a = i2c_get_clientdata(client); char buf[3], sts = 0; int err, i; dev_dbg(&client->dev, "%s: alm is secs=%d, mins=%d, hours=%d mday=%d, "\ "mon=%d, year=%d, wday=%d\n", __func__, alm->time.tm_sec, alm->time.tm_min, alm->time.tm_hour, alm->time.tm_mday, alm->time.tm_mon, alm->time.tm_year, alm->time.tm_wday); /* disable interrupt */ err = s35390a_set_reg(s35390a, S35390A_CMD_STATUS2, &sts, sizeof(sts)); if (err < 0) return err; /* clear pending interrupt, if any */ err = s35390a_get_reg(s35390a, S35390A_CMD_STATUS1, &sts, sizeof(sts)); if (err < 0) return err; if (alm->enabled) sts = S35390A_INT2_MODE_ALARM; else sts = S35390A_INT2_MODE_NOINTR; /* This chip expects the bits of each byte to be in reverse order */ sts = bitrev8(sts); /* set interupt mode*/ err = s35390a_set_reg(s35390a, S35390A_CMD_STATUS2, &sts, sizeof(sts)); if (err < 0) return err; if (alm->time.tm_wday != -1) buf[S35390A_ALRM_BYTE_WDAY] = bin2bcd(alm->time.tm_wday) | 0x80; buf[S35390A_ALRM_BYTE_HOURS] = s35390a_hr2reg(s35390a, alm->time.tm_hour) | 0x80; buf[S35390A_ALRM_BYTE_MINS] = bin2bcd(alm->time.tm_min) | 0x80; if (alm->time.tm_hour >= 12) buf[S35390A_ALRM_BYTE_HOURS] |= 0x40; for (i = 0; i < 3; ++i) buf[i] = bitrev8(buf[i]); err = s35390a_set_reg(s35390a, S35390A_CMD_INT2_REG1, buf, sizeof(buf)); return err; }
static int s35390a_alarm_irq_enable(struct i2c_client *client, unsigned enabled) { struct s35390a *s35390a = i2c_get_clientdata(client); struct rtc_wkalrm *alm; char buf[3], sts; int err, i; err = s35390a_get_reg(s35390a, S35390A_CMD_STATUS2, &sts, sizeof(sts)); if (err) { dev_err(&client->dev, "%s: failed to read STS2 reg\n", __func__); return err; } /* This chip returns the bits of each byte in reverse order */ sts = bitrev8(sts); sts &= ~S35390A_INT1_MODE_MASK; if (enabled) sts |= S35390A_INT1_MODE_ALARM; else sts |= S35390A_INT1_MODE_NOINTR; /* This chip returns the bits of each byte in reverse order */ sts = bitrev8(sts); err = s35390a_set_reg(s35390a, S35390A_CMD_STATUS2, &sts, sizeof(sts)); if (err) { dev_err(&client->dev, "%s: failed to set STS2 reg\n", __func__); return err; } alm = &s35390a->alarm; if (alm->time.tm_wday != -1) buf[S35390A_ALRM_BYTE_WDAY] = bin2bcd(alm->time.tm_wday) | 0x80; buf[S35390A_ALRM_BYTE_HOURS] = s35390a_hr2reg(s35390a, alm->time.tm_hour) | 0x80; buf[S35390A_ALRM_BYTE_MINS] = bin2bcd(alm->time.tm_min) | 0x80; if (alm->time.tm_hour >= 12) buf[S35390A_ALRM_BYTE_HOURS] |= 0x40; /* This chip expects the bits of each byte to be in reverse order */ for (i = 0; i < 3; ++i) buf[i] = bitrev8(buf[i]); return s35390a_set_reg(s35390a, S35390A_CMD_INT1_REG1, buf, sizeof(buf)); }