rtc-pcf8563.c (e5fc9cc0266e5babcf84c81908ec8843b7e3349f) rtc-pcf8563.c (2a4e2b8780c6df42b19c053243dada7fa4d311ee)
1/*
2 * An I2C driver for the Philips PCF8563 RTC
3 * Copyright 2005-06 Tower Technologies
4 *
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 * Maintainers: http://www.nslu2-linux.org/
7 *
8 * based on the other drivers in this same directory.

--- 66 unchanged lines hidden (view full) ---

75
76 struct i2c_msg msgs[] = {
77 { client->addr, 0, 1, buf }, /* setup read ptr */
78 { client->addr, I2C_M_RD, 13, buf }, /* read status + date */
79 };
80
81 /* read registers */
82 if ((i2c_transfer(client->adapter, msgs, 2)) != 2) {
1/*
2 * An I2C driver for the Philips PCF8563 RTC
3 * Copyright 2005-06 Tower Technologies
4 *
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 * Maintainers: http://www.nslu2-linux.org/
7 *
8 * based on the other drivers in this same directory.

--- 66 unchanged lines hidden (view full) ---

75
76 struct i2c_msg msgs[] = {
77 { client->addr, 0, 1, buf }, /* setup read ptr */
78 { client->addr, I2C_M_RD, 13, buf }, /* read status + date */
79 };
80
81 /* read registers */
82 if ((i2c_transfer(client->adapter, msgs, 2)) != 2) {
83 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
83 dev_err(&client->dev, "%s: read error\n", __func__);
84 return -EIO;
85 }
86
87 if (buf[PCF8563_REG_SC] & PCF8563_SC_LV)
88 dev_info(&client->dev,
89 "low voltage detected, date/time is not reliable.\n");
90
91 dev_dbg(&client->dev,
92 "%s: raw data is st1=%02x, st2=%02x, sec=%02x, min=%02x, hr=%02x, "
93 "mday=%02x, wday=%02x, mon=%02x, year=%02x\n",
84 return -EIO;
85 }
86
87 if (buf[PCF8563_REG_SC] & PCF8563_SC_LV)
88 dev_info(&client->dev,
89 "low voltage detected, date/time is not reliable.\n");
90
91 dev_dbg(&client->dev,
92 "%s: raw data is st1=%02x, st2=%02x, sec=%02x, min=%02x, hr=%02x, "
93 "mday=%02x, wday=%02x, mon=%02x, year=%02x\n",
94 __FUNCTION__,
94 __func__,
95 buf[0], buf[1], buf[2], buf[3],
96 buf[4], buf[5], buf[6], buf[7],
97 buf[8]);
98
99
100 tm->tm_sec = BCD2BIN(buf[PCF8563_REG_SC] & 0x7F);
101 tm->tm_min = BCD2BIN(buf[PCF8563_REG_MN] & 0x7F);
102 tm->tm_hour = BCD2BIN(buf[PCF8563_REG_HR] & 0x3F); /* rtc hr 0-23 */

--- 4 unchanged lines hidden (view full) ---

107 if (tm->tm_year < 70)
108 tm->tm_year += 100; /* assume we are in 1970...2069 */
109 /* detect the polarity heuristically. see note above. */
110 pcf8563->c_polarity = (buf[PCF8563_REG_MO] & PCF8563_MO_C) ?
111 (tm->tm_year >= 100) : (tm->tm_year < 100);
112
113 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
114 "mday=%d, mon=%d, year=%d, wday=%d\n",
95 buf[0], buf[1], buf[2], buf[3],
96 buf[4], buf[5], buf[6], buf[7],
97 buf[8]);
98
99
100 tm->tm_sec = BCD2BIN(buf[PCF8563_REG_SC] & 0x7F);
101 tm->tm_min = BCD2BIN(buf[PCF8563_REG_MN] & 0x7F);
102 tm->tm_hour = BCD2BIN(buf[PCF8563_REG_HR] & 0x3F); /* rtc hr 0-23 */

--- 4 unchanged lines hidden (view full) ---

107 if (tm->tm_year < 70)
108 tm->tm_year += 100; /* assume we are in 1970...2069 */
109 /* detect the polarity heuristically. see note above. */
110 pcf8563->c_polarity = (buf[PCF8563_REG_MO] & PCF8563_MO_C) ?
111 (tm->tm_year >= 100) : (tm->tm_year < 100);
112
113 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
114 "mday=%d, mon=%d, year=%d, wday=%d\n",
115 __FUNCTION__,
115 __func__,
116 tm->tm_sec, tm->tm_min, tm->tm_hour,
117 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
118
119 /* the clock can give out invalid datetime, but we cannot return
120 * -EINVAL otherwise hwclock will refuse to set the time on bootup.
121 */
122 if (rtc_valid_tm(tm) < 0)
123 dev_err(&client->dev, "retrieved date/time is not valid.\n");

--- 4 unchanged lines hidden (view full) ---

128static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
129{
130 struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
131 int i, err;
132 unsigned char buf[9];
133
134 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
135 "mday=%d, mon=%d, year=%d, wday=%d\n",
116 tm->tm_sec, tm->tm_min, tm->tm_hour,
117 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
118
119 /* the clock can give out invalid datetime, but we cannot return
120 * -EINVAL otherwise hwclock will refuse to set the time on bootup.
121 */
122 if (rtc_valid_tm(tm) < 0)
123 dev_err(&client->dev, "retrieved date/time is not valid.\n");

--- 4 unchanged lines hidden (view full) ---

128static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
129{
130 struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
131 int i, err;
132 unsigned char buf[9];
133
134 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
135 "mday=%d, mon=%d, year=%d, wday=%d\n",
136 __FUNCTION__,
136 __func__,
137 tm->tm_sec, tm->tm_min, tm->tm_hour,
138 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
139
140 /* hours, minutes and seconds */
141 buf[PCF8563_REG_SC] = BIN2BCD(tm->tm_sec);
142 buf[PCF8563_REG_MN] = BIN2BCD(tm->tm_min);
143 buf[PCF8563_REG_HR] = BIN2BCD(tm->tm_hour);
144

--- 13 unchanged lines hidden (view full) ---

158 for (i = 0; i < 7; i++) {
159 unsigned char data[2] = { PCF8563_REG_SC + i,
160 buf[PCF8563_REG_SC + i] };
161
162 err = i2c_master_send(client, data, sizeof(data));
163 if (err != sizeof(data)) {
164 dev_err(&client->dev,
165 "%s: err=%d addr=%02x, data=%02x\n",
137 tm->tm_sec, tm->tm_min, tm->tm_hour,
138 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
139
140 /* hours, minutes and seconds */
141 buf[PCF8563_REG_SC] = BIN2BCD(tm->tm_sec);
142 buf[PCF8563_REG_MN] = BIN2BCD(tm->tm_min);
143 buf[PCF8563_REG_HR] = BIN2BCD(tm->tm_hour);
144

--- 13 unchanged lines hidden (view full) ---

158 for (i = 0; i < 7; i++) {
159 unsigned char data[2] = { PCF8563_REG_SC + i,
160 buf[PCF8563_REG_SC + i] };
161
162 err = i2c_master_send(client, data, sizeof(data));
163 if (err != sizeof(data)) {
164 dev_err(&client->dev,
165 "%s: err=%d addr=%02x, data=%02x\n",
166 __FUNCTION__, err, data[0], data[1]);
166 __func__, err, data[0], data[1]);
167 return -EIO;
168 }
169 };
170
171 return 0;
172}
173
174struct pcf8563_limit

--- 28 unchanged lines hidden (view full) ---

203 { client->addr, I2C_M_RD, 1, &buf },
204 };
205
206 xfer = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
207
208 if (xfer != ARRAY_SIZE(msgs)) {
209 dev_err(&client->dev,
210 "%s: could not read register 0x%02X\n",
167 return -EIO;
168 }
169 };
170
171 return 0;
172}
173
174struct pcf8563_limit

--- 28 unchanged lines hidden (view full) ---

203 { client->addr, I2C_M_RD, 1, &buf },
204 };
205
206 xfer = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
207
208 if (xfer != ARRAY_SIZE(msgs)) {
209 dev_err(&client->dev,
210 "%s: could not read register 0x%02X\n",
211 __FUNCTION__, pattern[i].reg);
211 __func__, pattern[i].reg);
212
213 return -EIO;
214 }
215
216 value = BCD2BIN(buf & pattern[i].mask);
217
218 if (value > pattern[i].max ||
219 value < pattern[i].min) {
220 dev_dbg(&client->dev,
221 "%s: pattern=%d, reg=%x, mask=0x%02x, min=%d, "
222 "max=%d, value=%d, raw=0x%02X\n",
212
213 return -EIO;
214 }
215
216 value = BCD2BIN(buf & pattern[i].mask);
217
218 if (value > pattern[i].max ||
219 value < pattern[i].min) {
220 dev_dbg(&client->dev,
221 "%s: pattern=%d, reg=%x, mask=0x%02x, min=%d, "
222 "max=%d, value=%d, raw=0x%02X\n",
223 __FUNCTION__, i, pattern[i].reg, pattern[i].mask,
223 __func__, i, pattern[i].reg, pattern[i].mask,
224 pattern[i].min, pattern[i].max,
225 value, buf);
226
227 return -ENODEV;
228 }
229 }
230
231 return 0;

--- 95 unchanged lines hidden ---
224 pattern[i].min, pattern[i].max,
225 value, buf);
226
227 return -ENODEV;
228 }
229 }
230
231 return 0;

--- 95 unchanged lines hidden ---