/* Send 8 bits. */ static void out_byte(unsigned char x) { int i; TK_SDA_DIR(1); for (i = 8; i--;) { /* The chip latches incoming bits on the rising edge of SCL. */ TK_SCL_OUT(0); TK_SDA_OUT(x & 1); tempudelay(1); TK_SCL_OUT(1); tempudelay(1); x >>= 1; } TK_SDA_DIR(0); }
static int ds1302_probe(void) { int retval, res; TK_RST_DIR(1); TK_SCL_DIR(1); TK_SDA_DIR(0); /* Try to talk to timekeeper. */ ds1302_wenable(); start(); out_byte(0xc0); /* write RAM byte 0 */ out_byte(MAGIC_PATTERN); /* write something magic */ start(); out_byte(0xc1); /* read RAM byte 0 */ if((res = in_byte()) == MAGIC_PATTERN) { char buf[100]; stop(); ds1302_wdisable(); printk("%s: RTC found.\n", ds1302_name); printk("%s: SDA, SCL, RST on PB%i, PB%i, %s%i\n", ds1302_name, CONFIG_ETRAX_DS1302_SDABIT, CONFIG_ETRAX_DS1302_SCLBIT, #ifdef CONFIG_ETRAX_DS1302_RST_ON_GENERIC_PORT "GENIO", #else "PB", #endif CONFIG_ETRAX_DS1302_RSTBIT); get_rtc_status(buf); printk(buf); retval = 1; } else { stop(); printk("%s: RTC not found.\n", ds1302_name); retval = 0; } return retval; }
static unsigned char in_byte(void) { unsigned char x = 0; int i; /* Read byte. Bits come LSB first, on the falling edge of SCL. * Assume SDA is in input direction already. */ TK_SDA_DIR(0); for (i = 8; i--;) { TK_SCL_OUT(0); tempudelay(1); x >>= 1; x |= (TK_SDA_IN() << 7); TK_SCL_OUT(1); tempudelay(1); } return x; }