uint8_t rtc_read(uint32_t addr) { uint8_t data; rtc_init(); rtc_ce(1); rtc_dir(1); rtc_do(1); /* Don't care */ rtc_do(1); /* R/#W = 1(READ) */ rtc_do(1); /* AD = 1 */ rtc_do(0); /* DT = 0 */ rtc_do(addr & 0x8); /* A3 */ rtc_do(addr & 0x4); /* A2 */ rtc_do(addr & 0x2); /* A1 */ rtc_do(addr & 0x1); /* A0 */ rtc_dir(0); (void)rtc_di(); (void)rtc_di(); (void)rtc_di(); (void)rtc_di(); data = rtc_di(); /* D3 */ data <<= 1; data |= rtc_di(); /* D2 */ data <<= 1; data |= rtc_di(); /* D1 */ data <<= 1; data |= rtc_di(); /* D0 */ rtc_ce(0); return data & 0xf; }
static int rs5c313_read_reg(struct rs5c313_softc *sc, int addr) { int data; /* output */ rtc_dir(sc, 1); /* control */ rtc_do(sc, 1); /* ignored */ rtc_do(sc, 1); /* R/#W = 1(READ) */ rtc_do(sc, 1); /* AD = 1 */ rtc_do(sc, 0); /* DT = 0 */ /* address */ rtc_do(sc, addr & 0x8); /* A3 */ rtc_do(sc, addr & 0x4); /* A2 */ rtc_do(sc, addr & 0x2); /* A1 */ rtc_do(sc, addr & 0x1); /* A0 */ /* input */ rtc_dir(sc, 0); /* ignore */ (void)rtc_di(sc); (void)rtc_di(sc); (void)rtc_di(sc); (void)rtc_di(sc); /* data */ data = rtc_di(sc); /* D3 */ data <<= 1; data |= rtc_di(sc); /* D2 */ data <<= 1; data |= rtc_di(sc); /* D1 */ data <<= 1; data |= rtc_di(sc); /* D0 */ return data; }