aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMylène Josserand <mylene.josserand@free-electrons.com>2016-05-03 05:54:32 -0400
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>2016-05-21 11:03:53 -0400
commit4e7f1a6051d7d5a62021fde0c9ed7005a1a82307 (patch)
treeb28f1d91cfe6229eec284cfc64961a866d25a64a
parent3497610a45d15bd33d1993ddd84951ad21b35ded (diff)
rtc: rv3029: remove 'i2c' in functions names
To prepare the use of regmap to add the support of RV-3049, all the 'i2c' in functions's names are removed. Signed-off-by: Mylène Josserand <mylene.josserand@free-electrons.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
-rw-r--r--drivers/rtc/rtc-rv3029c2.c132
1 files changed, 57 insertions, 75 deletions
diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c
index d0cbf08040cd..091be483e3e9 100644
--- a/drivers/rtc/rtc-rv3029c2.c
+++ b/drivers/rtc/rtc-rv3029c2.c
@@ -116,9 +116,8 @@
116#define RV3029_USR2_RAM_PAGE 0x3C 116#define RV3029_USR2_RAM_PAGE 0x3C
117#define RV3029_USR2_SECTION_LEN 0x04 117#define RV3029_USR2_SECTION_LEN 0x04
118 118
119static int 119static int rv3029_read_regs(struct i2c_client *client, u8 reg, u8 *buf,
120rv3029_i2c_read_regs(struct i2c_client *client, u8 reg, u8 *buf, 120 unsigned len)
121 unsigned len)
122{ 121{
123 int ret; 122 int ret;
124 123
@@ -134,9 +133,8 @@ rv3029_i2c_read_regs(struct i2c_client *client, u8 reg, u8 *buf,
134 return 0; 133 return 0;
135} 134}
136 135
137static int 136static int rv3029_write_regs(struct i2c_client *client, u8 reg, u8 const buf[],
138rv3029_i2c_write_regs(struct i2c_client *client, u8 reg, u8 const buf[], 137 unsigned len)
139 unsigned len)
140{ 138{
141 if ((reg > RV3029_USR1_RAM_PAGE + 7) || 139 if ((reg > RV3029_USR1_RAM_PAGE + 7) ||
142 (reg + len > RV3029_USR1_RAM_PAGE + 8)) 140 (reg + len > RV3029_USR1_RAM_PAGE + 8))
@@ -145,28 +143,27 @@ rv3029_i2c_write_regs(struct i2c_client *client, u8 reg, u8 const buf[],
145 return i2c_smbus_write_i2c_block_data(client, reg, len, buf); 143 return i2c_smbus_write_i2c_block_data(client, reg, len, buf);
146} 144}
147 145
148static int 146static int rv3029_update_bits(struct i2c_client *client, u8 reg, u8 mask,
149rv3029_i2c_update_bits(struct i2c_client *client, u8 reg, u8 mask, u8 set) 147 u8 set)
150{ 148{
151 u8 buf; 149 u8 buf;
152 int ret; 150 int ret;
153 151
154 ret = rv3029_i2c_read_regs(client, reg, &buf, 1); 152 ret = rv3029_read_regs(client, reg, &buf, 1);
155 if (ret < 0) 153 if (ret < 0)
156 return ret; 154 return ret;
157 buf &= ~mask; 155 buf &= ~mask;
158 buf |= set & mask; 156 buf |= set & mask;
159 ret = rv3029_i2c_write_regs(client, reg, &buf, 1); 157 ret = rv3029_write_regs(client, reg, &buf, 1);
160 if (ret < 0) 158 if (ret < 0)
161 return ret; 159 return ret;
162 160
163 return 0; 161 return 0;
164} 162}
165 163
166static int 164static int rv3029_get_sr(struct i2c_client *client, u8 *buf)
167rv3029_i2c_get_sr(struct i2c_client *client, u8 *buf)
168{ 165{
169 int ret = rv3029_i2c_read_regs(client, RV3029_STATUS, buf, 1); 166 int ret = rv3029_read_regs(client, RV3029_STATUS, buf, 1);
170 167
171 if (ret < 0) 168 if (ret < 0)
172 return -EIO; 169 return -EIO;
@@ -174,14 +171,13 @@ rv3029_i2c_get_sr(struct i2c_client *client, u8 *buf)
174 return 0; 171 return 0;
175} 172}
176 173
177static int 174static int rv3029_set_sr(struct i2c_client *client, u8 val)
178rv3029_i2c_set_sr(struct i2c_client *client, u8 val)
179{ 175{
180 u8 buf[1]; 176 u8 buf[1];
181 int sr; 177 int sr;
182 178
183 buf[0] = val; 179 buf[0] = val;
184 sr = rv3029_i2c_write_regs(client, RV3029_STATUS, buf, 1); 180 sr = rv3029_write_regs(client, RV3029_STATUS, buf, 1);
185 dev_dbg(&client->dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]); 181 dev_dbg(&client->dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]);
186 if (sr < 0) 182 if (sr < 0)
187 return -EIO; 183 return -EIO;
@@ -194,7 +190,7 @@ static int rv3029_eeprom_busywait(struct i2c_client *client)
194 u8 sr; 190 u8 sr;
195 191
196 for (i = 100; i > 0; i--) { 192 for (i = 100; i > 0; i--) {
197 ret = rv3029_i2c_get_sr(client, &sr); 193 ret = rv3029_get_sr(client, &sr);
198 if (ret < 0) 194 if (ret < 0)
199 break; 195 break;
200 if (!(sr & RV3029_STATUS_EEBUSY)) 196 if (!(sr & RV3029_STATUS_EEBUSY))
@@ -212,9 +208,9 @@ static int rv3029_eeprom_busywait(struct i2c_client *client)
212static int rv3029_eeprom_exit(struct i2c_client *client) 208static int rv3029_eeprom_exit(struct i2c_client *client)
213{ 209{
214 /* Re-enable eeprom refresh */ 210 /* Re-enable eeprom refresh */
215 return rv3029_i2c_update_bits(client, RV3029_ONOFF_CTRL, 211 return rv3029_update_bits(client, RV3029_ONOFF_CTRL,
216 RV3029_ONOFF_CTRL_EERE, 212 RV3029_ONOFF_CTRL_EERE,
217 RV3029_ONOFF_CTRL_EERE); 213 RV3029_ONOFF_CTRL_EERE);
218} 214}
219 215
220static int rv3029_eeprom_enter(struct i2c_client *client) 216static int rv3029_eeprom_enter(struct i2c_client *client)
@@ -223,7 +219,7 @@ static int rv3029_eeprom_enter(struct i2c_client *client)
223 u8 sr; 219 u8 sr;
224 220
225 /* Check whether we are in the allowed voltage range. */ 221 /* Check whether we are in the allowed voltage range. */
226 ret = rv3029_i2c_get_sr(client, &sr); 222 ret = rv3029_get_sr(client, &sr);
227 if (ret < 0) 223 if (ret < 0)
228 return ret; 224 return ret;
229 if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) { 225 if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) {
@@ -232,11 +228,11 @@ static int rv3029_eeprom_enter(struct i2c_client *client)
232 */ 228 */
233 sr &= ~RV3029_STATUS_VLOW1; 229 sr &= ~RV3029_STATUS_VLOW1;
234 sr &= ~RV3029_STATUS_VLOW2; 230 sr &= ~RV3029_STATUS_VLOW2;
235 ret = rv3029_i2c_set_sr(client, sr); 231 ret = rv3029_set_sr(client, sr);
236 if (ret < 0) 232 if (ret < 0)
237 return ret; 233 return ret;
238 usleep_range(1000, 10000); 234 usleep_range(1000, 10000);
239 ret = rv3029_i2c_get_sr(client, &sr); 235 ret = rv3029_get_sr(client, &sr);
240 if (ret < 0) 236 if (ret < 0)
241 return ret; 237 return ret;
242 if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) { 238 if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) {
@@ -247,8 +243,8 @@ static int rv3029_eeprom_enter(struct i2c_client *client)
247 } 243 }
248 244
249 /* Disable eeprom refresh. */ 245 /* Disable eeprom refresh. */
250 ret = rv3029_i2c_update_bits(client, RV3029_ONOFF_CTRL, 246 ret = rv3029_update_bits(client, RV3029_ONOFF_CTRL,
251 RV3029_ONOFF_CTRL_EERE, 0); 247 RV3029_ONOFF_CTRL_EERE, 0);
252 if (ret < 0) 248 if (ret < 0)
253 return ret; 249 return ret;
254 250
@@ -269,7 +265,7 @@ static int rv3029_eeprom_read(struct i2c_client *client, u8 reg,
269 if (err < 0) 265 if (err < 0)
270 return err; 266 return err;
271 267
272 ret = rv3029_i2c_read_regs(client, reg, buf, len); 268 ret = rv3029_read_regs(client, reg, buf, len);
273 269
274 err = rv3029_eeprom_exit(client); 270 err = rv3029_eeprom_exit(client);
275 if (err < 0) 271 if (err < 0)
@@ -290,11 +286,11 @@ static int rv3029_eeprom_write(struct i2c_client *client, u8 reg,
290 return err; 286 return err;
291 287
292 for (i = 0; i < len; i++, reg++) { 288 for (i = 0; i < len; i++, reg++) {
293 ret = rv3029_i2c_read_regs(client, reg, &tmp, 1); 289 ret = rv3029_read_regs(client, reg, &tmp, 1);
294 if (ret < 0) 290 if (ret < 0)
295 break; 291 break;
296 if (tmp != buf[i]) { 292 if (tmp != buf[i]) {
297 ret = rv3029_i2c_write_regs(client, reg, &buf[i], 1); 293 ret = rv3029_write_regs(client, reg, &buf[i], 1);
298 if (ret < 0) 294 if (ret < 0)
299 break; 295 break;
300 } 296 }
@@ -328,21 +324,20 @@ static int rv3029_eeprom_update_bits(struct i2c_client *client,
328 return 0; 324 return 0;
329} 325}
330 326
331static int 327static int rv3029_read_time(struct i2c_client *client, struct rtc_time *tm)
332rv3029_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
333{ 328{
334 u8 buf[1]; 329 u8 buf[1];
335 int ret; 330 int ret;
336 u8 regs[RV3029_WATCH_SECTION_LEN] = { 0, }; 331 u8 regs[RV3029_WATCH_SECTION_LEN] = { 0, };
337 332
338 ret = rv3029_i2c_get_sr(client, buf); 333 ret = rv3029_get_sr(client, buf);
339 if (ret < 0) { 334 if (ret < 0) {
340 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 335 dev_err(&client->dev, "%s: reading SR failed\n", __func__);
341 return -EIO; 336 return -EIO;
342 } 337 }
343 338
344 ret = rv3029_i2c_read_regs(client, RV3029_W_SEC, regs, 339 ret = rv3029_read_regs(client, RV3029_W_SEC, regs,
345 RV3029_WATCH_SECTION_LEN); 340 RV3029_WATCH_SECTION_LEN);
346 if (ret < 0) { 341 if (ret < 0) {
347 dev_err(&client->dev, "%s: reading RTC section failed\n", 342 dev_err(&client->dev, "%s: reading RTC section failed\n",
348 __func__); 343 __func__);
@@ -375,24 +370,24 @@ rv3029_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
375 370
376static int rv3029_rtc_read_time(struct device *dev, struct rtc_time *tm) 371static int rv3029_rtc_read_time(struct device *dev, struct rtc_time *tm)
377{ 372{
378 return rv3029_i2c_read_time(to_i2c_client(dev), tm); 373 return rv3029_read_time(to_i2c_client(dev), tm);
379} 374}
380 375
381static int 376static int rv3029_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
382rv3029_i2c_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm)
383{ 377{
378 struct i2c_client *client = to_i2c_client(dev);
384 struct rtc_time *const tm = &alarm->time; 379 struct rtc_time *const tm = &alarm->time;
385 int ret; 380 int ret;
386 u8 regs[8]; 381 u8 regs[8];
387 382
388 ret = rv3029_i2c_get_sr(client, regs); 383 ret = rv3029_get_sr(client, regs);
389 if (ret < 0) { 384 if (ret < 0) {
390 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 385 dev_err(&client->dev, "%s: reading SR failed\n", __func__);
391 return -EIO; 386 return -EIO;
392 } 387 }
393 388
394 ret = rv3029_i2c_read_regs(client, RV3029_A_SC, regs, 389 ret = rv3029_read_regs(client, RV3029_A_SC, regs,
395 RV3029_ALARM_SECTION_LEN); 390 RV3029_ALARM_SECTION_LEN);
396 391
397 if (ret < 0) { 392 if (ret < 0) {
398 dev_err(&client->dev, "%s: reading alarm section failed\n", 393 dev_err(&client->dev, "%s: reading alarm section failed\n",
@@ -411,21 +406,14 @@ rv3029_i2c_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm)
411 return 0; 406 return 0;
412} 407}
413 408
414static int 409static int rv3029_rtc_alarm_set_irq(struct i2c_client *client, int enable)
415rv3029_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
416{
417 return rv3029_i2c_read_alarm(to_i2c_client(dev), alarm);
418}
419
420static int rv3029_rtc_i2c_alarm_set_irq(struct i2c_client *client,
421 int enable)
422{ 410{
423 int ret; 411 int ret;
424 412
425 /* enable/disable AIE irq */ 413 /* enable/disable AIE irq */
426 ret = rv3029_i2c_update_bits(client, RV3029_IRQ_CTRL, 414 ret = rv3029_update_bits(client, RV3029_IRQ_CTRL,
427 RV3029_IRQ_CTRL_AIE, 415 RV3029_IRQ_CTRL_AIE,
428 (enable ? RV3029_IRQ_CTRL_AIE : 0)); 416 (enable ? RV3029_IRQ_CTRL_AIE : 0));
429 if (ret < 0) { 417 if (ret < 0) {
430 dev_err(&client->dev, "can't update INT reg\n"); 418 dev_err(&client->dev, "can't update INT reg\n");
431 return ret; 419 return ret;
@@ -434,9 +422,9 @@ static int rv3029_rtc_i2c_alarm_set_irq(struct i2c_client *client,
434 return 0; 422 return 0;
435} 423}
436 424
437static int rv3029_rtc_i2c_set_alarm(struct i2c_client *client, 425static int rv3029_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
438 struct rtc_wkalrm *alarm)
439{ 426{
427 struct i2c_client *client = to_i2c_client(dev);
440 struct rtc_time *const tm = &alarm->time; 428 struct rtc_time *const tm = &alarm->time;
441 int ret; 429 int ret;
442 u8 regs[8]; 430 u8 regs[8];
@@ -449,7 +437,7 @@ static int rv3029_rtc_i2c_set_alarm(struct i2c_client *client,
449 if (tm->tm_year < 100) 437 if (tm->tm_year < 100)
450 return -EINVAL; 438 return -EINVAL;
451 439
452 ret = rv3029_i2c_get_sr(client, regs); 440 ret = rv3029_get_sr(client, regs);
453 if (ret < 0) { 441 if (ret < 0) {
454 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 442 dev_err(&client->dev, "%s: reading SR failed\n", __func__);
455 return -EIO; 443 return -EIO;
@@ -462,28 +450,28 @@ static int rv3029_rtc_i2c_set_alarm(struct i2c_client *client,
462 regs[RV3029_A_DW-RV3029_A_SC] = bin2bcd((tm->tm_wday & 7) - 1); 450 regs[RV3029_A_DW-RV3029_A_SC] = bin2bcd((tm->tm_wday & 7) - 1);
463 regs[RV3029_A_YR-RV3029_A_SC] = bin2bcd((tm->tm_year & 0x7f) - 100); 451 regs[RV3029_A_YR-RV3029_A_SC] = bin2bcd((tm->tm_year & 0x7f) - 100);
464 452
465 ret = rv3029_i2c_write_regs(client, RV3029_A_SC, regs, 453 ret = rv3029_write_regs(client, RV3029_A_SC, regs,
466 RV3029_ALARM_SECTION_LEN); 454 RV3029_ALARM_SECTION_LEN);
467 if (ret < 0) 455 if (ret < 0)
468 return ret; 456 return ret;
469 457
470 if (alarm->enabled) { 458 if (alarm->enabled) {
471 /* clear AF flag */ 459 /* clear AF flag */
472 ret = rv3029_i2c_update_bits(client, RV3029_IRQ_FLAGS, 460 ret = rv3029_update_bits(client, RV3029_IRQ_FLAGS,
473 RV3029_IRQ_FLAGS_AF, 0); 461 RV3029_IRQ_FLAGS_AF, 0);
474 if (ret < 0) { 462 if (ret < 0) {
475 dev_err(&client->dev, "can't clear alarm flag\n"); 463 dev_err(&client->dev, "can't clear alarm flag\n");
476 return ret; 464 return ret;
477 } 465 }
478 /* enable AIE irq */ 466 /* enable AIE irq */
479 ret = rv3029_rtc_i2c_alarm_set_irq(client, 1); 467 ret = rv3029_rtc_alarm_set_irq(client, 1);
480 if (ret) 468 if (ret)
481 return ret; 469 return ret;
482 470
483 dev_dbg(&client->dev, "alarm IRQ armed\n"); 471 dev_dbg(&client->dev, "alarm IRQ armed\n");
484 } else { 472 } else {
485 /* disable AIE irq */ 473 /* disable AIE irq */
486 ret = rv3029_rtc_i2c_alarm_set_irq(client, 0); 474 ret = rv3029_rtc_alarm_set_irq(client, 0);
487 if (ret) 475 if (ret)
488 return ret; 476 return ret;
489 477
@@ -493,13 +481,7 @@ static int rv3029_rtc_i2c_set_alarm(struct i2c_client *client,
493 return 0; 481 return 0;
494} 482}
495 483
496static int rv3029_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) 484static int rv3029_set_time(struct i2c_client *client, struct rtc_time const *tm)
497{
498 return rv3029_rtc_i2c_set_alarm(to_i2c_client(dev), alarm);
499}
500
501static int
502rv3029_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
503{ 485{
504 u8 regs[8]; 486 u8 regs[8];
505 int ret; 487 int ret;
@@ -520,18 +502,18 @@ rv3029_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
520 regs[RV3029_W_DAYS-RV3029_W_SEC] = bin2bcd((tm->tm_wday & 7)+1); 502 regs[RV3029_W_DAYS-RV3029_W_SEC] = bin2bcd((tm->tm_wday & 7)+1);
521 regs[RV3029_W_YEARS-RV3029_W_SEC] = bin2bcd(tm->tm_year - 100); 503 regs[RV3029_W_YEARS-RV3029_W_SEC] = bin2bcd(tm->tm_year - 100);
522 504
523 ret = rv3029_i2c_write_regs(client, RV3029_W_SEC, regs, 505 ret = rv3029_write_regs(client, RV3029_W_SEC, regs,
524 RV3029_WATCH_SECTION_LEN); 506 RV3029_WATCH_SECTION_LEN);
525 if (ret < 0) 507 if (ret < 0)
526 return ret; 508 return ret;
527 509
528 ret = rv3029_i2c_get_sr(client, regs); 510 ret = rv3029_get_sr(client, regs);
529 if (ret < 0) { 511 if (ret < 0) {
530 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 512 dev_err(&client->dev, "%s: reading SR failed\n", __func__);
531 return ret; 513 return ret;
532 } 514 }
533 /* clear PON bit */ 515 /* clear PON bit */
534 ret = rv3029_i2c_set_sr(client, (regs[0] & ~RV3029_STATUS_PON)); 516 ret = rv3029_set_sr(client, (regs[0] & ~RV3029_STATUS_PON));
535 if (ret < 0) { 517 if (ret < 0) {
536 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 518 dev_err(&client->dev, "%s: reading SR failed\n", __func__);
537 return ret; 519 return ret;
@@ -542,7 +524,7 @@ rv3029_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
542 524
543static int rv3029_rtc_set_time(struct device *dev, struct rtc_time *tm) 525static int rv3029_rtc_set_time(struct device *dev, struct rtc_time *tm)
544{ 526{
545 return rv3029_i2c_set_time(to_i2c_client(dev), tm); 527 return rv3029_set_time(to_i2c_client(dev), tm);
546} 528}
547 529
548static const struct rv3029_trickle_tab_elem { 530static const struct rv3029_trickle_tab_elem {
@@ -646,7 +628,7 @@ static int rv3029_read_temp(struct i2c_client *client, int *temp_mC)
646 int ret; 628 int ret;
647 u8 temp; 629 u8 temp;
648 630
649 ret = rv3029_i2c_read_regs(client, RV3029_TEMP_PAGE, &temp, 1); 631 ret = rv3029_read_regs(client, RV3029_TEMP_PAGE, &temp, 1);
650 if (ret < 0) 632 if (ret < 0)
651 return ret; 633 return ret;
652 634
@@ -743,8 +725,8 @@ static void rv3029_hwmon_register(struct i2c_client *client)
743 &client->dev, client->name, client, rv3029_hwmon_groups); 725 &client->dev, client->name, client, rv3029_hwmon_groups);
744 if (IS_ERR(hwmon_dev)) { 726 if (IS_ERR(hwmon_dev)) {
745 dev_warn(&client->dev, 727 dev_warn(&client->dev,
746 "unable to register hwmon device %ld\n", 728 "unable to register hwmon device %ld\n",
747 PTR_ERR(hwmon_dev)); 729 PTR_ERR(hwmon_dev));
748 } 730 }
749} 731}
750 732
@@ -780,7 +762,7 @@ static int rv3029_probe(struct i2c_client *client,
780 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_EMUL)) 762 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_EMUL))
781 return -ENODEV; 763 return -ENODEV;
782 764
783 rc = rv3029_i2c_get_sr(client, buf); 765 rc = rv3029_get_sr(client, buf);
784 if (rc < 0) { 766 if (rc < 0) {
785 dev_err(&client->dev, "reading status failed\n"); 767 dev_err(&client->dev, "reading status failed\n");
786 return rc; 768 return rc;