diff options
Diffstat (limited to 'drivers/rtc')
| -rw-r--r-- | drivers/rtc/rtc-x1205.c | 53 |
1 files changed, 18 insertions, 35 deletions
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c index 6583c1a8b070..9aae49139a0a 100644 --- a/drivers/rtc/rtc-x1205.c +++ b/drivers/rtc/rtc-x1205.c | |||
| @@ -155,11 +155,11 @@ static int x1205_get_status(struct i2c_client *client, unsigned char *sr) | |||
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, | 157 | static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, |
| 158 | int datetoo, u8 reg_base, unsigned char alm_enable) | 158 | u8 reg_base, unsigned char alm_enable) |
| 159 | { | 159 | { |
| 160 | int i, xfer, nbytes; | 160 | int i, xfer; |
| 161 | unsigned char buf[8]; | ||
| 162 | unsigned char rdata[10] = { 0, reg_base }; | 161 | unsigned char rdata[10] = { 0, reg_base }; |
| 162 | unsigned char *buf = rdata + 2; | ||
| 163 | 163 | ||
| 164 | static const unsigned char wel[3] = { 0, X1205_REG_SR, | 164 | static const unsigned char wel[3] = { 0, X1205_REG_SR, |
| 165 | X1205_SR_WEL }; | 165 | X1205_SR_WEL }; |
| @@ -170,9 +170,9 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
| 170 | static const unsigned char diswe[3] = { 0, X1205_REG_SR, 0 }; | 170 | static const unsigned char diswe[3] = { 0, X1205_REG_SR, 0 }; |
| 171 | 171 | ||
| 172 | dev_dbg(&client->dev, | 172 | dev_dbg(&client->dev, |
| 173 | "%s: secs=%d, mins=%d, hours=%d\n", | 173 | "%s: sec=%d min=%d hour=%d mday=%d mon=%d year=%d wday=%d\n", |
| 174 | __func__, | 174 | __func__, tm->tm_sec, tm->tm_min, tm->tm_hour, tm->tm_mday, |
| 175 | tm->tm_sec, tm->tm_min, tm->tm_hour); | 175 | tm->tm_mon, tm->tm_year, tm->tm_wday); |
| 176 | 176 | ||
| 177 | buf[CCR_SEC] = bin2bcd(tm->tm_sec); | 177 | buf[CCR_SEC] = bin2bcd(tm->tm_sec); |
| 178 | buf[CCR_MIN] = bin2bcd(tm->tm_min); | 178 | buf[CCR_MIN] = bin2bcd(tm->tm_min); |
| @@ -180,23 +180,15 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
| 180 | /* set hour and 24hr bit */ | 180 | /* set hour and 24hr bit */ |
| 181 | buf[CCR_HOUR] = bin2bcd(tm->tm_hour) | X1205_HR_MIL; | 181 | buf[CCR_HOUR] = bin2bcd(tm->tm_hour) | X1205_HR_MIL; |
| 182 | 182 | ||
| 183 | /* should we also set the date? */ | 183 | buf[CCR_MDAY] = bin2bcd(tm->tm_mday); |
| 184 | if (datetoo) { | ||
| 185 | dev_dbg(&client->dev, | ||
| 186 | "%s: mday=%d, mon=%d, year=%d, wday=%d\n", | ||
| 187 | __func__, | ||
| 188 | tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); | ||
| 189 | 184 | ||
| 190 | buf[CCR_MDAY] = bin2bcd(tm->tm_mday); | 185 | /* month, 1 - 12 */ |
| 186 | buf[CCR_MONTH] = bin2bcd(tm->tm_mon + 1); | ||
| 191 | 187 | ||
| 192 | /* month, 1 - 12 */ | 188 | /* year, since the rtc epoch*/ |
| 193 | buf[CCR_MONTH] = bin2bcd(tm->tm_mon + 1); | 189 | buf[CCR_YEAR] = bin2bcd(tm->tm_year % 100); |
| 194 | 190 | buf[CCR_WDAY] = tm->tm_wday & 0x07; | |
| 195 | /* year, since the rtc epoch*/ | 191 | buf[CCR_Y2K] = bin2bcd((tm->tm_year + 1900) / 100); |
| 196 | buf[CCR_YEAR] = bin2bcd(tm->tm_year % 100); | ||
| 197 | buf[CCR_WDAY] = tm->tm_wday & 0x07; | ||
| 198 | buf[CCR_Y2K] = bin2bcd((tm->tm_year + 1900) / 100); | ||
| 199 | } | ||
| 200 | 192 | ||
| 201 | /* If writing alarm registers, set compare bits on registers 0-4 */ | 193 | /* If writing alarm registers, set compare bits on registers 0-4 */ |
| 202 | if (reg_base < X1205_CCR_BASE) | 194 | if (reg_base < X1205_CCR_BASE) |
| @@ -214,17 +206,8 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
| 214 | return -EIO; | 206 | return -EIO; |
| 215 | } | 207 | } |
| 216 | 208 | ||
| 217 | 209 | xfer = i2c_master_send(client, rdata, sizeof(rdata)); | |
| 218 | /* write register's data */ | 210 | if (xfer != sizeof(rdata)) { |
| 219 | if (datetoo) | ||
| 220 | nbytes = 8; | ||
| 221 | else | ||
| 222 | nbytes = 3; | ||
| 223 | for (i = 0; i < nbytes; i++) | ||
| 224 | rdata[2+i] = buf[i]; | ||
| 225 | |||
| 226 | xfer = i2c_master_send(client, rdata, nbytes+2); | ||
| 227 | if (xfer != nbytes+2) { | ||
| 228 | dev_err(&client->dev, | 211 | dev_err(&client->dev, |
| 229 | "%s: result=%d addr=%02x, data=%02x\n", | 212 | "%s: result=%d addr=%02x, data=%02x\n", |
| 230 | __func__, | 213 | __func__, |
| @@ -282,7 +265,7 @@ static int x1205_fix_osc(struct i2c_client *client) | |||
| 282 | 265 | ||
| 283 | memset(&tm, 0, sizeof(tm)); | 266 | memset(&tm, 0, sizeof(tm)); |
| 284 | 267 | ||
| 285 | err = x1205_set_datetime(client, &tm, 1, X1205_CCR_BASE, 0); | 268 | err = x1205_set_datetime(client, &tm, X1205_CCR_BASE, 0); |
| 286 | if (err < 0) | 269 | if (err < 0) |
| 287 | dev_err(&client->dev, "unable to restart the oscillator\n"); | 270 | dev_err(&client->dev, "unable to restart the oscillator\n"); |
| 288 | 271 | ||
| @@ -481,7 +464,7 @@ static int x1205_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 481 | static int x1205_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 464 | static int x1205_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
| 482 | { | 465 | { |
| 483 | return x1205_set_datetime(to_i2c_client(dev), | 466 | return x1205_set_datetime(to_i2c_client(dev), |
| 484 | &alrm->time, 1, X1205_ALM0_BASE, alrm->enabled); | 467 | &alrm->time, X1205_ALM0_BASE, alrm->enabled); |
| 485 | } | 468 | } |
| 486 | 469 | ||
| 487 | static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm) | 470 | static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm) |
| @@ -493,7 +476,7 @@ static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
| 493 | static int x1205_rtc_set_time(struct device *dev, struct rtc_time *tm) | 476 | static int x1205_rtc_set_time(struct device *dev, struct rtc_time *tm) |
| 494 | { | 477 | { |
| 495 | return x1205_set_datetime(to_i2c_client(dev), | 478 | return x1205_set_datetime(to_i2c_client(dev), |
| 496 | tm, 1, X1205_CCR_BASE, 0); | 479 | tm, X1205_CCR_BASE, 0); |
| 497 | } | 480 | } |
| 498 | 481 | ||
| 499 | static int x1205_rtc_proc(struct device *dev, struct seq_file *seq) | 482 | static int x1205_rtc_proc(struct device *dev, struct seq_file *seq) |
