Revision abd0c6bd hw/omap1.c

b/hw/omap1.c
3358 3358
        printf("%s: conversion failed\n", __FUNCTION__);
3359 3359
}
3360 3360

  
3361
static inline uint8_t omap_rtc_bcd(int num)
3362
{
3363
    return ((num / 10) << 4) | (num % 10);
3364
}
3365

  
3366
static inline int omap_rtc_bin(uint8_t num)
3367
{
3368
    return (num & 15) + 10 * (num >> 4);
3369
}
3370

  
3371 3361
static uint32_t omap_rtc_read(void *opaque, target_phys_addr_t addr)
3372 3362
{
3373 3363
    struct omap_rtc_s *s = (struct omap_rtc_s *) opaque;
......
3376 3366

  
3377 3367
    switch (offset) {
3378 3368
    case 0x00:	/* SECONDS_REG */
3379
        return omap_rtc_bcd(s->current_tm.tm_sec);
3369
        return to_bcd(s->current_tm.tm_sec);
3380 3370

  
3381 3371
    case 0x04:	/* MINUTES_REG */
3382
        return omap_rtc_bcd(s->current_tm.tm_min);
3372
        return to_bcd(s->current_tm.tm_min);
3383 3373

  
3384 3374
    case 0x08:	/* HOURS_REG */
3385 3375
        if (s->pm_am)
3386 3376
            return ((s->current_tm.tm_hour > 11) << 7) |
3387
                    omap_rtc_bcd(((s->current_tm.tm_hour - 1) % 12) + 1);
3377
                    to_bcd(((s->current_tm.tm_hour - 1) % 12) + 1);
3388 3378
        else
3389
            return omap_rtc_bcd(s->current_tm.tm_hour);
3379
            return to_bcd(s->current_tm.tm_hour);
3390 3380

  
3391 3381
    case 0x0c:	/* DAYS_REG */
3392
        return omap_rtc_bcd(s->current_tm.tm_mday);
3382
        return to_bcd(s->current_tm.tm_mday);
3393 3383

  
3394 3384
    case 0x10:	/* MONTHS_REG */
3395
        return omap_rtc_bcd(s->current_tm.tm_mon + 1);
3385
        return to_bcd(s->current_tm.tm_mon + 1);
3396 3386

  
3397 3387
    case 0x14:	/* YEARS_REG */
3398
        return omap_rtc_bcd(s->current_tm.tm_year % 100);
3388
        return to_bcd(s->current_tm.tm_year % 100);
3399 3389

  
3400 3390
    case 0x18:	/* WEEK_REG */
3401 3391
        return s->current_tm.tm_wday;
3402 3392

  
3403 3393
    case 0x20:	/* ALARM_SECONDS_REG */
3404
        return omap_rtc_bcd(s->alarm_tm.tm_sec);
3394
        return to_bcd(s->alarm_tm.tm_sec);
3405 3395

  
3406 3396
    case 0x24:	/* ALARM_MINUTES_REG */
3407
        return omap_rtc_bcd(s->alarm_tm.tm_min);
3397
        return to_bcd(s->alarm_tm.tm_min);
3408 3398

  
3409 3399
    case 0x28:	/* ALARM_HOURS_REG */
3410 3400
        if (s->pm_am)
3411 3401
            return ((s->alarm_tm.tm_hour > 11) << 7) |
3412
                    omap_rtc_bcd(((s->alarm_tm.tm_hour - 1) % 12) + 1);
3402
                    to_bcd(((s->alarm_tm.tm_hour - 1) % 12) + 1);
3413 3403
        else
3414
            return omap_rtc_bcd(s->alarm_tm.tm_hour);
3404
            return to_bcd(s->alarm_tm.tm_hour);
3415 3405

  
3416 3406
    case 0x2c:	/* ALARM_DAYS_REG */
3417
        return omap_rtc_bcd(s->alarm_tm.tm_mday);
3407
        return to_bcd(s->alarm_tm.tm_mday);
3418 3408

  
3419 3409
    case 0x30:	/* ALARM_MONTHS_REG */
3420
        return omap_rtc_bcd(s->alarm_tm.tm_mon + 1);
3410
        return to_bcd(s->alarm_tm.tm_mon + 1);
3421 3411

  
3422 3412
    case 0x34:	/* ALARM_YEARS_REG */
3423
        return omap_rtc_bcd(s->alarm_tm.tm_year % 100);
3413
        return to_bcd(s->alarm_tm.tm_year % 100);
3424 3414

  
3425 3415
    case 0x40:	/* RTC_CTRL_REG */
3426 3416
        return (s->pm_am << 3) | (s->auto_comp << 2) |
......
3459 3449
        printf("RTC SEC_REG <-- %02x\n", value);
3460 3450
#endif
3461 3451
        s->ti -= s->current_tm.tm_sec;
3462
        s->ti += omap_rtc_bin(value);
3452
        s->ti += from_bcd(value);
3463 3453
        return;
3464 3454

  
3465 3455
    case 0x04:	/* MINUTES_REG */
......
3467 3457
        printf("RTC MIN_REG <-- %02x\n", value);
3468 3458
#endif
3469 3459
        s->ti -= s->current_tm.tm_min * 60;
3470
        s->ti += omap_rtc_bin(value) * 60;
3460
        s->ti += from_bcd(value) * 60;
3471 3461
        return;
3472 3462

  
3473 3463
    case 0x08:	/* HOURS_REG */
......
3476 3466
#endif
3477 3467
        s->ti -= s->current_tm.tm_hour * 3600;
3478 3468
        if (s->pm_am) {
3479
            s->ti += (omap_rtc_bin(value & 0x3f) & 12) * 3600;
3469
            s->ti += (from_bcd(value & 0x3f) & 12) * 3600;
3480 3470
            s->ti += ((value >> 7) & 1) * 43200;
3481 3471
        } else
3482
            s->ti += omap_rtc_bin(value & 0x3f) * 3600;
3472
            s->ti += from_bcd(value & 0x3f) * 3600;
3483 3473
        return;
3484 3474

  
3485 3475
    case 0x0c:	/* DAYS_REG */
......
3487 3477
        printf("RTC DAY_REG <-- %02x\n", value);
3488 3478
#endif
3489 3479
        s->ti -= s->current_tm.tm_mday * 86400;
3490
        s->ti += omap_rtc_bin(value) * 86400;
3480
        s->ti += from_bcd(value) * 86400;
3491 3481
        return;
3492 3482

  
3493 3483
    case 0x10:	/* MONTHS_REG */
......
3495 3485
        printf("RTC MTH_REG <-- %02x\n", value);
3496 3486
#endif
3497 3487
        memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
3498
        new_tm.tm_mon = omap_rtc_bin(value);
3488
        new_tm.tm_mon = from_bcd(value);
3499 3489
        ti[0] = mktimegm(&s->current_tm);
3500 3490
        ti[1] = mktimegm(&new_tm);
3501 3491

  
......
3505 3495
        } else {
3506 3496
            /* A less accurate version */
3507 3497
            s->ti -= s->current_tm.tm_mon * 2592000;
3508
            s->ti += omap_rtc_bin(value) * 2592000;
3498
            s->ti += from_bcd(value) * 2592000;
3509 3499
        }
3510 3500
        return;
3511 3501

  
......
3514 3504
        printf("RTC YRS_REG <-- %02x\n", value);
3515 3505
#endif
3516 3506
        memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
3517
        new_tm.tm_year += omap_rtc_bin(value) - (new_tm.tm_year % 100);
3507
        new_tm.tm_year += from_bcd(value) - (new_tm.tm_year % 100);
3518 3508
        ti[0] = mktimegm(&s->current_tm);
3519 3509
        ti[1] = mktimegm(&new_tm);
3520 3510

  
......
3524 3514
        } else {
3525 3515
            /* A less accurate version */
3526 3516
            s->ti -= (s->current_tm.tm_year % 100) * 31536000;
3527
            s->ti += omap_rtc_bin(value) * 31536000;
3517
            s->ti += from_bcd(value) * 31536000;
3528 3518
        }
3529 3519
        return;
3530 3520

  
......
3535 3525
#ifdef ALMDEBUG
3536 3526
        printf("ALM SEC_REG <-- %02x\n", value);
3537 3527
#endif
3538
        s->alarm_tm.tm_sec = omap_rtc_bin(value);
3528
        s->alarm_tm.tm_sec = from_bcd(value);
3539 3529
        omap_rtc_alarm_update(s);
3540 3530
        return;
3541 3531

  
......
3543 3533
#ifdef ALMDEBUG
3544 3534
        printf("ALM MIN_REG <-- %02x\n", value);
3545 3535
#endif
3546
        s->alarm_tm.tm_min = omap_rtc_bin(value);
3536
        s->alarm_tm.tm_min = from_bcd(value);
3547 3537
        omap_rtc_alarm_update(s);
3548 3538
        return;
3549 3539

  
......
3553 3543
#endif
3554 3544
        if (s->pm_am)
3555 3545
            s->alarm_tm.tm_hour =
3556
                    ((omap_rtc_bin(value & 0x3f)) % 12) +
3546
                    ((from_bcd(value & 0x3f)) % 12) +
3557 3547
                    ((value >> 7) & 1) * 12;
3558 3548
        else
3559
            s->alarm_tm.tm_hour = omap_rtc_bin(value);
3549
            s->alarm_tm.tm_hour = from_bcd(value);
3560 3550
        omap_rtc_alarm_update(s);
3561 3551
        return;
3562 3552

  
......
3564 3554
#ifdef ALMDEBUG
3565 3555
        printf("ALM DAY_REG <-- %02x\n", value);
3566 3556
#endif
3567
        s->alarm_tm.tm_mday = omap_rtc_bin(value);
3557
        s->alarm_tm.tm_mday = from_bcd(value);
3568 3558
        omap_rtc_alarm_update(s);
3569 3559
        return;
3570 3560

  
......
3572 3562
#ifdef ALMDEBUG
3573 3563
        printf("ALM MON_REG <-- %02x\n", value);
3574 3564
#endif
3575
        s->alarm_tm.tm_mon = omap_rtc_bin(value);
3565
        s->alarm_tm.tm_mon = from_bcd(value);
3576 3566
        omap_rtc_alarm_update(s);
3577 3567
        return;
3578 3568

  
......
3580 3570
#ifdef ALMDEBUG
3581 3571
        printf("ALM YRS_REG <-- %02x\n", value);
3582 3572
#endif
3583
        s->alarm_tm.tm_year = omap_rtc_bin(value);
3573
        s->alarm_tm.tm_year = from_bcd(value);
3584 3574
        omap_rtc_alarm_update(s);
3585 3575
        return;
3586 3576

  

Also available in: Unified diff