rtc-x1205.c (4edac2b442d6176afb0ae431123993dc00882987) | rtc-x1205.c (2a4e2b8780c6df42b19c053243dada7fa4d311ee) |
---|---|
1/* 2 * An i2c driver for the Xicor/Intersil X1205 RTC 3 * Copyright 2004 Karen Spearel 4 * Copyright 2005 Alessandro Zummo 5 * 6 * please send all reports to: 7 * Karen Spearel <kas111 at gmail dot com> 8 * Alessandro Zummo <a.zummo@towertech.it> --- 85 unchanged lines hidden (view full) --- 94 95 struct i2c_msg msgs[] = { 96 { client->addr, 0, 2, dt_addr }, /* setup read ptr */ 97 { client->addr, I2C_M_RD, 8, buf }, /* read date */ 98 }; 99 100 /* read date registers */ 101 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | 1/* 2 * An i2c driver for the Xicor/Intersil X1205 RTC 3 * Copyright 2004 Karen Spearel 4 * Copyright 2005 Alessandro Zummo 5 * 6 * please send all reports to: 7 * Karen Spearel <kas111 at gmail dot com> 8 * Alessandro Zummo <a.zummo@towertech.it> --- 85 unchanged lines hidden (view full) --- 94 95 struct i2c_msg msgs[] = { 96 { client->addr, 0, 2, dt_addr }, /* setup read ptr */ 97 { client->addr, I2C_M_RD, 8, buf }, /* read date */ 98 }; 99 100 /* read date registers */ 101 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { |
102 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); | 102 dev_err(&client->dev, "%s: read error\n", __func__); |
103 return -EIO; 104 } 105 106 dev_dbg(&client->dev, 107 "%s: raw read data - sec=%02x, min=%02x, hr=%02x, " 108 "mday=%02x, mon=%02x, year=%02x, wday=%02x, y2k=%02x\n", | 103 return -EIO; 104 } 105 106 dev_dbg(&client->dev, 107 "%s: raw read data - sec=%02x, min=%02x, hr=%02x, " 108 "mday=%02x, mon=%02x, year=%02x, wday=%02x, y2k=%02x\n", |
109 __FUNCTION__, | 109 __func__, |
110 buf[0], buf[1], buf[2], buf[3], 111 buf[4], buf[5], buf[6], buf[7]); 112 113 tm->tm_sec = BCD2BIN(buf[CCR_SEC]); 114 tm->tm_min = BCD2BIN(buf[CCR_MIN]); 115 tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */ 116 tm->tm_mday = BCD2BIN(buf[CCR_MDAY]); 117 tm->tm_mon = BCD2BIN(buf[CCR_MONTH]) - 1; /* mon is 0-11 */ 118 tm->tm_year = BCD2BIN(buf[CCR_YEAR]) 119 + (BCD2BIN(buf[CCR_Y2K]) * 100) - 1900; 120 tm->tm_wday = buf[CCR_WDAY]; 121 122 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 123 "mday=%d, mon=%d, year=%d, wday=%d\n", | 110 buf[0], buf[1], buf[2], buf[3], 111 buf[4], buf[5], buf[6], buf[7]); 112 113 tm->tm_sec = BCD2BIN(buf[CCR_SEC]); 114 tm->tm_min = BCD2BIN(buf[CCR_MIN]); 115 tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */ 116 tm->tm_mday = BCD2BIN(buf[CCR_MDAY]); 117 tm->tm_mon = BCD2BIN(buf[CCR_MONTH]) - 1; /* mon is 0-11 */ 118 tm->tm_year = BCD2BIN(buf[CCR_YEAR]) 119 + (BCD2BIN(buf[CCR_Y2K]) * 100) - 1900; 120 tm->tm_wday = buf[CCR_WDAY]; 121 122 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 123 "mday=%d, mon=%d, year=%d, wday=%d\n", |
124 __FUNCTION__, | 124 __func__, |
125 tm->tm_sec, tm->tm_min, tm->tm_hour, 126 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 127 128 return 0; 129} 130 131static int x1205_get_status(struct i2c_client *client, unsigned char *sr) 132{ 133 static unsigned char sr_addr[2] = { 0, X1205_REG_SR }; 134 135 struct i2c_msg msgs[] = { 136 { client->addr, 0, 2, sr_addr }, /* setup read ptr */ 137 { client->addr, I2C_M_RD, 1, sr }, /* read status */ 138 }; 139 140 /* read status register */ 141 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | 125 tm->tm_sec, tm->tm_min, tm->tm_hour, 126 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 127 128 return 0; 129} 130 131static int x1205_get_status(struct i2c_client *client, unsigned char *sr) 132{ 133 static unsigned char sr_addr[2] = { 0, X1205_REG_SR }; 134 135 struct i2c_msg msgs[] = { 136 { client->addr, 0, 2, sr_addr }, /* setup read ptr */ 137 { client->addr, I2C_M_RD, 1, sr }, /* read status */ 138 }; 139 140 /* read status register */ 141 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { |
142 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); | 142 dev_err(&client->dev, "%s: read error\n", __func__); |
143 return -EIO; 144 } 145 146 return 0; 147} 148 149static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, 150 int datetoo, u8 reg_base) --- 6 unchanged lines hidden (view full) --- 157 158 static const unsigned char rwel[3] = { 0, X1205_REG_SR, 159 X1205_SR_WEL | X1205_SR_RWEL }; 160 161 static const unsigned char diswe[3] = { 0, X1205_REG_SR, 0 }; 162 163 dev_dbg(&client->dev, 164 "%s: secs=%d, mins=%d, hours=%d\n", | 143 return -EIO; 144 } 145 146 return 0; 147} 148 149static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, 150 int datetoo, u8 reg_base) --- 6 unchanged lines hidden (view full) --- 157 158 static const unsigned char rwel[3] = { 0, X1205_REG_SR, 159 X1205_SR_WEL | X1205_SR_RWEL }; 160 161 static const unsigned char diswe[3] = { 0, X1205_REG_SR, 0 }; 162 163 dev_dbg(&client->dev, 164 "%s: secs=%d, mins=%d, hours=%d\n", |
165 __FUNCTION__, | 165 __func__, |
166 tm->tm_sec, tm->tm_min, tm->tm_hour); 167 168 buf[CCR_SEC] = BIN2BCD(tm->tm_sec); 169 buf[CCR_MIN] = BIN2BCD(tm->tm_min); 170 171 /* set hour and 24hr bit */ 172 buf[CCR_HOUR] = BIN2BCD(tm->tm_hour) | X1205_HR_MIL; 173 174 /* should we also set the date? */ 175 if (datetoo) { 176 dev_dbg(&client->dev, 177 "%s: mday=%d, mon=%d, year=%d, wday=%d\n", | 166 tm->tm_sec, tm->tm_min, tm->tm_hour); 167 168 buf[CCR_SEC] = BIN2BCD(tm->tm_sec); 169 buf[CCR_MIN] = BIN2BCD(tm->tm_min); 170 171 /* set hour and 24hr bit */ 172 buf[CCR_HOUR] = BIN2BCD(tm->tm_hour) | X1205_HR_MIL; 173 174 /* should we also set the date? */ 175 if (datetoo) { 176 dev_dbg(&client->dev, 177 "%s: mday=%d, mon=%d, year=%d, wday=%d\n", |
178 __FUNCTION__, | 178 __func__, |
179 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 180 181 buf[CCR_MDAY] = BIN2BCD(tm->tm_mday); 182 183 /* month, 1 - 12 */ 184 buf[CCR_MONTH] = BIN2BCD(tm->tm_mon + 1); 185 186 /* year, since the rtc epoch*/ 187 buf[CCR_YEAR] = BIN2BCD(tm->tm_year % 100); 188 buf[CCR_WDAY] = tm->tm_wday & 0x07; 189 buf[CCR_Y2K] = BIN2BCD(tm->tm_year / 100); 190 } 191 192 /* this sequence is required to unlock the chip */ 193 if ((xfer = i2c_master_send(client, wel, 3)) != 3) { | 179 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 180 181 buf[CCR_MDAY] = BIN2BCD(tm->tm_mday); 182 183 /* month, 1 - 12 */ 184 buf[CCR_MONTH] = BIN2BCD(tm->tm_mon + 1); 185 186 /* year, since the rtc epoch*/ 187 buf[CCR_YEAR] = BIN2BCD(tm->tm_year % 100); 188 buf[CCR_WDAY] = tm->tm_wday & 0x07; 189 buf[CCR_Y2K] = BIN2BCD(tm->tm_year / 100); 190 } 191 192 /* this sequence is required to unlock the chip */ 193 if ((xfer = i2c_master_send(client, wel, 3)) != 3) { |
194 dev_err(&client->dev, "%s: wel - %d\n", __FUNCTION__, xfer); | 194 dev_err(&client->dev, "%s: wel - %d\n", __func__, xfer); |
195 return -EIO; 196 } 197 198 if ((xfer = i2c_master_send(client, rwel, 3)) != 3) { | 195 return -EIO; 196 } 197 198 if ((xfer = i2c_master_send(client, rwel, 3)) != 3) { |
199 dev_err(&client->dev, "%s: rwel - %d\n", __FUNCTION__, xfer); | 199 dev_err(&client->dev, "%s: rwel - %d\n", __func__, xfer); |
200 return -EIO; 201 } 202 203 /* write register's data */ 204 for (i = 0; i < (datetoo ? 8 : 3); i++) { 205 unsigned char rdata[3] = { 0, reg_base + i, buf[i] }; 206 207 xfer = i2c_master_send(client, rdata, 3); 208 if (xfer != 3) { 209 dev_err(&client->dev, 210 "%s: xfer=%d addr=%02x, data=%02x\n", | 200 return -EIO; 201 } 202 203 /* write register's data */ 204 for (i = 0; i < (datetoo ? 8 : 3); i++) { 205 unsigned char rdata[3] = { 0, reg_base + i, buf[i] }; 206 207 xfer = i2c_master_send(client, rdata, 3); 208 if (xfer != 3) { 209 dev_err(&client->dev, 210 "%s: xfer=%d addr=%02x, data=%02x\n", |
211 __FUNCTION__, | 211 __func__, |
212 xfer, rdata[1], rdata[2]); 213 return -EIO; 214 } 215 }; 216 217 /* disable further writes */ 218 if ((xfer = i2c_master_send(client, diswe, 3)) != 3) { | 212 xfer, rdata[1], rdata[2]); 213 return -EIO; 214 } 215 }; 216 217 /* disable further writes */ 218 if ((xfer = i2c_master_send(client, diswe, 3)) != 3) { |
219 dev_err(&client->dev, "%s: diswe - %d\n", __FUNCTION__, xfer); | 219 dev_err(&client->dev, "%s: diswe - %d\n", __func__, xfer); |
220 return -EIO; 221 } 222 223 return 0; 224} 225 226static int x1205_fix_osc(struct i2c_client *client) 227{ --- 16 unchanged lines hidden (view full) --- 244 245 struct i2c_msg msgs[] = { 246 { client->addr, 0, 2, dtr_addr }, /* setup read ptr */ 247 { client->addr, I2C_M_RD, 1, &dtr }, /* read dtr */ 248 }; 249 250 /* read dtr register */ 251 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | 220 return -EIO; 221 } 222 223 return 0; 224} 225 226static int x1205_fix_osc(struct i2c_client *client) 227{ --- 16 unchanged lines hidden (view full) --- 244 245 struct i2c_msg msgs[] = { 246 { client->addr, 0, 2, dtr_addr }, /* setup read ptr */ 247 { client->addr, I2C_M_RD, 1, &dtr }, /* read dtr */ 248 }; 249 250 /* read dtr register */ 251 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { |
252 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); | 252 dev_err(&client->dev, "%s: read error\n", __func__); |
253 return -EIO; 254 } 255 | 253 return -EIO; 254 } 255 |
256 dev_dbg(&client->dev, "%s: raw dtr=%x\n", __FUNCTION__, dtr); | 256 dev_dbg(&client->dev, "%s: raw dtr=%x\n", __func__, dtr); |
257 258 *trim = 0; 259 260 if (dtr & X1205_DTR_DTR0) 261 *trim += 20; 262 263 if (dtr & X1205_DTR_DTR1) 264 *trim += 10; --- 11 unchanged lines hidden (view full) --- 276 277 struct i2c_msg msgs[] = { 278 { client->addr, 0, 2, atr_addr }, /* setup read ptr */ 279 { client->addr, I2C_M_RD, 1, &atr }, /* read atr */ 280 }; 281 282 /* read atr register */ 283 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | 257 258 *trim = 0; 259 260 if (dtr & X1205_DTR_DTR0) 261 *trim += 20; 262 263 if (dtr & X1205_DTR_DTR1) 264 *trim += 10; --- 11 unchanged lines hidden (view full) --- 276 277 struct i2c_msg msgs[] = { 278 { client->addr, 0, 2, atr_addr }, /* setup read ptr */ 279 { client->addr, I2C_M_RD, 1, &atr }, /* read atr */ 280 }; 281 282 /* read atr register */ 283 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { |
284 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); | 284 dev_err(&client->dev, "%s: read error\n", __func__); |
285 return -EIO; 286 } 287 | 285 return -EIO; 286 } 287 |
288 dev_dbg(&client->dev, "%s: raw atr=%x\n", __FUNCTION__, atr); | 288 dev_dbg(&client->dev, "%s: raw atr=%x\n", __func__, atr); |
289 290 /* atr is a two's complement value on 6 bits, 291 * perform sign extension. The formula is 292 * Catr = (atr * 0.25pF) + 11.00pF. 293 */ 294 if (atr & 0x20) 295 atr |= 0xC0; 296 | 289 290 /* atr is a two's complement value on 6 bits, 291 * perform sign extension. The formula is 292 * Catr = (atr * 0.25pF) + 11.00pF. 293 */ 294 if (atr & 0x20) 295 atr |= 0xC0; 296 |
297 dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __FUNCTION__, atr, atr); | 297 dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __func__, atr, atr); |
298 299 *trim = (atr * 250) + 11000; 300 | 298 299 *trim = (atr * 250) + 11000; 300 |
301 dev_dbg(&client->dev, "%s: real=%d\n", __FUNCTION__, *trim); | 301 dev_dbg(&client->dev, "%s: real=%d\n", __func__, *trim); |
302 303 return 0; 304} 305 306struct x1205_limit 307{ 308 unsigned char reg, mask, min, max; 309}; --- 37 unchanged lines hidden (view full) --- 347 struct i2c_msg msgs[2] = { 348 { client->addr, 0, 2, addr }, 349 { client->addr, I2C_M_RD, 1, &buf }, 350 }; 351 352 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { 353 dev_err(&client->dev, 354 "%s: could not read register %x\n", | 302 303 return 0; 304} 305 306struct x1205_limit 307{ 308 unsigned char reg, mask, min, max; 309}; --- 37 unchanged lines hidden (view full) --- 347 struct i2c_msg msgs[2] = { 348 { client->addr, 0, 2, addr }, 349 { client->addr, I2C_M_RD, 1, &buf }, 350 }; 351 352 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { 353 dev_err(&client->dev, 354 "%s: could not read register %x\n", |
355 __FUNCTION__, probe_zero_pattern[i]); | 355 __func__, probe_zero_pattern[i]); |
356 357 return -EIO; 358 } 359 360 if ((buf & probe_zero_pattern[i+1]) != 0) { 361 dev_err(&client->dev, 362 "%s: register=%02x, zero pattern=%d, value=%x\n", | 356 357 return -EIO; 358 } 359 360 if ((buf & probe_zero_pattern[i+1]) != 0) { 361 dev_err(&client->dev, 362 "%s: register=%02x, zero pattern=%d, value=%x\n", |
363 __FUNCTION__, probe_zero_pattern[i], i, buf); | 363 __func__, probe_zero_pattern[i], i, buf); |
364 365 return -ENODEV; 366 } 367 } 368 369 /* check limits (only registers with bcd values) */ 370 for (i = 0; i < ARRAY_SIZE(probe_limits_pattern); i++) { 371 unsigned char reg, value; 372 373 unsigned char addr[2] = { 0, probe_limits_pattern[i].reg }; 374 375 struct i2c_msg msgs[2] = { 376 { client->addr, 0, 2, addr }, 377 { client->addr, I2C_M_RD, 1, ® }, 378 }; 379 380 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { 381 dev_err(&client->dev, 382 "%s: could not read register %x\n", | 364 365 return -ENODEV; 366 } 367 } 368 369 /* check limits (only registers with bcd values) */ 370 for (i = 0; i < ARRAY_SIZE(probe_limits_pattern); i++) { 371 unsigned char reg, value; 372 373 unsigned char addr[2] = { 0, probe_limits_pattern[i].reg }; 374 375 struct i2c_msg msgs[2] = { 376 { client->addr, 0, 2, addr }, 377 { client->addr, I2C_M_RD, 1, ® }, 378 }; 379 380 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { 381 dev_err(&client->dev, 382 "%s: could not read register %x\n", |
383 __FUNCTION__, probe_limits_pattern[i].reg); | 383 __func__, probe_limits_pattern[i].reg); |
384 385 return -EIO; 386 } 387 388 value = BCD2BIN(reg & probe_limits_pattern[i].mask); 389 390 if (value > probe_limits_pattern[i].max || 391 value < probe_limits_pattern[i].min) { 392 dev_dbg(&client->dev, 393 "%s: register=%x, lim pattern=%d, value=%d\n", | 384 385 return -EIO; 386 } 387 388 value = BCD2BIN(reg & probe_limits_pattern[i].mask); 389 390 if (value > probe_limits_pattern[i].max || 391 value < probe_limits_pattern[i].min) { 392 dev_dbg(&client->dev, 393 "%s: register=%x, lim pattern=%d, value=%d\n", |
394 __FUNCTION__, probe_limits_pattern[i].reg, | 394 __func__, probe_limits_pattern[i].reg, |
395 i, value); 396 397 return -ENODEV; 398 } 399 } 400 401 return 0; 402} --- 179 unchanged lines hidden --- | 395 i, value); 396 397 return -ENODEV; 398 } 399 } 400 401 return 0; 402} --- 179 unchanged lines hidden --- |