static int smbus_readrtc(int slaveaddr,int devaddr) { uint32_t err,data; if (wait_busy() < 0) return -1; chip_write(SMB_CMD1, ((devaddr & 0xFF) & 0xFF),32); chip_write(SMB_STRT1, SMB_STRT_WR1B | slaveaddr,32); err = wait_busy(); if (err < 0) return err; /* * Read the data */ chip_write(SMB_STRT1, SMB_STRT_RD1B | slaveaddr, 32); err = wait_busy(); if (err < 0) return err; data = chip_read(SMB_DATA1,32); return (data & 0xFF); }
int RTCFUNC(set,omap)(struct tm *tm, int cent_reg) { unsigned seconds; unsigned minutes; unsigned hours; unsigned day; unsigned month; unsigned year; // convert binary to BCD seconds = BIN2BCD(tm->tm_sec); minutes = BIN2BCD(tm->tm_min); hours = BIN2BCD(tm->tm_hour); day = BIN2BCD(tm->tm_mday); month = BIN2BCD(tm->tm_mon); year = BIN2BCD(tm->tm_year % 100); chip_write(OMAP_RTC_SECONDS, seconds, 32); chip_write(OMAP_RTC_MINUTES, minutes, 32); chip_write(OMAP_RTC_HOURS, hours | MILTIME, 32); chip_write(OMAP_RTC_WEEKS, tm->tm_wday + 1, 32); // 1 to 7, BCD is same as binary, so no conversion needed chip_write(OMAP_RTC_DAYS, day, 32); // day of month chip_write(OMAP_RTC_MONTHS, month, 32); chip_write(OMAP_RTC_YEARS, year, 32); return(0); }
static int smbus_writertc(int slaveaddr,int devaddr,int b) { int err; /* * Make sure the bus is idle (probably should * ignore error here) */ if (wait_busy() < 0) return -1; /* * Write the device address to the controller. There are two * parts, the high part goes in the "CMD" field, and the * low part is the data field. */ chip_write(SMB_CMD1,((devaddr & 0xFF) & 0xFF),32); chip_write(SMB_DATA1,((b & 0xFF) & 0xFF),32); /* * Start the command. Keep pounding on the device until it * submits or the timer expires, whichever comes first. The * datasheet says writes can take up to 10ms, so we'll give it 500. */ chip_write(SMB_STRT1,SMB_STRT_WR2B|slaveaddr,32); /* * Wait till the SMBus interface is done */ err = wait_busy(); if (err < 0) return err; return err; }
static int wait_busy() { uint64_t status; for (;;) { status = chip_read(SMB_STAT1,32) & 0xFF; if (status & SMB_BUSY) continue; break; } if (status & SMB_ERR) { chip_write(SMB_STAT1, (status & SMB_ERR), 32); return -1; } return 0; }
int RTCFUNC(set,hy7201)(struct tm *tm, int cent_reg) { time_t t; t = mktime(tm); /* * mktime assumes local time. We will subtract timezone */ t -= timezone; #ifdef VERBOSE_SUPPORTED if (verbose) { printf("rtc write: %d\n", t); } #endif chip_write(HY7201_RTC_RTCDR, t, 32); return 0; }