mcp7940n: rewrite init code to make it easier to customize

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
1 files changed, 15 insertions(+), 8 deletions(-)

M devices/i2c/mcp7940n.c
M devices/i2c/mcp7940n.c +15 -8
@@ 53,19 53,26 @@ static inline uint8_t mod10(uint8_t v)
  */
 int mcp7940n_init(const struct tm *tm)
 {
-	struct mcp7940n_timekeeping_regs tmp;
+	uint8_t control;
+	uint8_t sec;
+	int ret;
 
-	if (!mcp7940n_read(offsetof(struct mcp7940n, timekeeping), &tmp,
-			   sizeof(tmp)))
+	if (!mcp7940n_read(offsetof(struct mcp7940n, timekeeping.sec), &sec,
+			   sizeof(sec)))
 		return -1;
 
-	if (tmp.sec & MCP7940N_SEC_ST)
-		return +1; /* already started, don't disturb the time */
+	if (sec & MCP7940N_SEC_ST) {
+		ret = +1; /* already running, don't disturb the time */
+	} else {
+		if (!mcp7940n_settime(tm))
+			return -1;
 
-	if (!mcp7940n_settime(tm))
-		return -1;
+		ret = 0; /* started just now */
+	}
 
-	return 0;
+	/* ... initialize MFP here as desired ... */
+
+	return ret;
 }
 
 /*