# HG changeset patch # User Josef 'Jeff' Sipek # Date 1732401546 18000 # Sat Nov 23 17:39:06 2024 -0500 # Node ID 847184cb2ece40eb642172eae623b384bda74191 # Parent ff874a24d785474c458a6de7e6630bc6ea6e0e11 mcp7940n: rewrite init code to make it easier to customize Signed-off-by: Josef 'Jeff' Sipek diff --git a/devices/i2c/mcp7940n.c b/devices/i2c/mcp7940n.c --- a/devices/i2c/mcp7940n.c +++ b/devices/i2c/mcp7940n.c @@ -53,19 +53,26 @@ */ 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; } /*