From nobody Sat Nov 30 00:32:52 2024 Received: from www530.your-server.de (www530.your-server.de [188.40.30.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6A5F1DA106; Fri, 13 Sep 2024 10:29:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.40.30.78 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223363; cv=none; b=irv2WEkok/4w+wgFLeuo5b294IwDiTIQrHksjvpoSW2vFTptdN+v0fBnvrsFhQvcELmCpTxslJ0Z6UTnINesWPaz5KL/zwIlk+E0CqOM8dAlhobB+lpOjxhSaJnofltfnril5cRyGkW9ZWAwNl9DGGWiwZt8qxLKJ/fXSoAk0vU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223363; c=relaxed/simple; bh=Zb7aSV0oW+yKb5Asy8n0NTRp21E2eZbalbz24dawAt8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gWs9RAASJozwVunLs3Hkb78u4gsrrs05/KZAr82uy5ps3YADpFUZa+0GKrWWBt8bZ8/mtqWZsZRLjrnSRJ7Ri0QgnwyL/6rLSKBZBjnCPxRY/9dBkMqAaT7eJL1QKcmJl00L0WZR99p/IJ+ZsX5OKN9kEBZgM+7RWAZiDxGO+T4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=geanix.com; spf=pass smtp.mailfrom=geanix.com; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b=pOjRjJBa; arc=none smtp.client-ip=188.40.30.78 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=geanix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=geanix.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b="pOjRjJBa" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=geanix.com; s=default2211; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=InZ2QQ+90ucsM+b3r4LrCMsMJEs63QT2lHFJ93Q9NzI=; b=pOjRjJBaXSNylMqk2fCd9RGBrs iwWX2/z32DXXy0jZeM0enrxBeST2r0qOOE43uWOd0QqCa/W2upGunGmgSuoHc0465uoFWHE4gU94t p3y9ASE86dbum0yQa2OshhvZpy4AqJlj8VLvMqQ9ZsWy9nUlkKh/S788bMaWEqv02mlXYmVaX7KML 8tN9bjGpUNbDHre4YrNl3yV7cGA8FG1LuKOpBPggqrjoC7VFl9h0+xwaE8YSlcih2IHE2e8DcKuYz 1lHMBuuVQM3K/DGFVYpFbJ89spJKkbETXDMQiYrnW1JpkXZDDSvCQ2+TgX3zi0XfqoQRV/GaKL0+/ BYouRLLQ==; Received: from sslproxy07.your-server.de ([78.47.199.104]) by www530.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sp3YE-0006OS-HU; Fri, 13 Sep 2024 12:29:18 +0200 Received: from [80.62.117.18] (helo=localhost) by sslproxy07.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sp3YD-0006tP-2W; Fri, 13 Sep 2024 12:29:18 +0200 From: Esben Haabendal Date: Fri, 13 Sep 2024 12:29:12 +0200 Subject: [PATCH v2 1/3] rtc: isl12022: Prepare for extending rtc device drvdata Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240913-rtc-isl12022-alarm-irq-v2-1-37309d939723@geanix.com> References: <20240913-rtc-isl12022-alarm-irq-v2-0-37309d939723@geanix.com> In-Reply-To: <20240913-rtc-isl12022-alarm-irq-v2-0-37309d939723@geanix.com> To: Alexandre Belloni , Rasmus Villemoes Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, Esben Haabendal X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1726223356; l=3876; i=esben@geanix.com; s=20240523; h=from:subject:message-id; bh=Zb7aSV0oW+yKb5Asy8n0NTRp21E2eZbalbz24dawAt8=; b=j+sUN1PRgCc5qCFiik84clkclZ6dayhc3rz6vgOC9mXBWmQFzlYwWrQVql8Aqq8dNKVCa9Sq+ sgAsXaYA4yUAD5obCCtkEKhwPVgWqV2fELUtS1dl1yl0vADlwECDgvI X-Developer-Key: i=esben@geanix.com; a=ed25519; pk=PbXoezm+CERhtgVeF/QAgXtEzSkDIahcWfC7RIXNdEk= X-Authenticated-Sender: esben@geanix.com X-Virus-Scanned: Clear (ClamAV 0.103.10/27397/Fri Sep 13 10:48:01 2024) Add a struct to hold the regmap pointer, so more information can be added. This is morally a revert of commit f525b210e9d4 ("rtc: isl12022: Get rid of unneeded private struct isl12022"). Acked-by: Rasmus Villemoes Signed-off-by: Esben Haabendal --- drivers/rtc/rtc-isl12022.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c index 6fa9a68af9d9..d82278fdc29b 100644 --- a/drivers/rtc/rtc-isl12022.c +++ b/drivers/rtc/rtc-isl12022.c @@ -54,6 +54,10 @@ =20 #define ISL12022_BETA_TSE (1 << 7) =20 +struct isl12022 { + struct regmap *regmap; +}; + static umode_t isl12022_hwmon_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, int channel) @@ -116,7 +120,8 @@ static const struct hwmon_chip_info isl12022_hwmon_chip= _info =3D { =20 static void isl12022_hwmon_register(struct device *dev) { - struct regmap *regmap =3D dev_get_drvdata(dev); + struct isl12022 *isl12022 =3D dev_get_drvdata(dev); + struct regmap *regmap =3D isl12022->regmap; struct device *hwmon; int ret; =20 @@ -143,7 +148,8 @@ static void isl12022_hwmon_register(struct device *dev) */ static int isl12022_rtc_read_time(struct device *dev, struct rtc_time *tm) { - struct regmap *regmap =3D dev_get_drvdata(dev); + struct isl12022 *isl12022 =3D dev_get_drvdata(dev); + struct regmap *regmap =3D isl12022->regmap; uint8_t buf[ISL12022_REG_INT + 1]; int ret; =20 @@ -178,7 +184,8 @@ static int isl12022_rtc_read_time(struct device *dev, s= truct rtc_time *tm) =20 static int isl12022_rtc_set_time(struct device *dev, struct rtc_time *tm) { - struct regmap *regmap =3D dev_get_drvdata(dev); + struct isl12022 *isl12022 =3D dev_get_drvdata(dev); + struct regmap *regmap =3D isl12022->regmap; int ret; uint8_t buf[ISL12022_REG_DW + 1]; =20 @@ -210,7 +217,8 @@ static int isl12022_rtc_set_time(struct device *dev, st= ruct rtc_time *tm) =20 static int isl12022_rtc_ioctl(struct device *dev, unsigned int cmd, unsign= ed long arg) { - struct regmap *regmap =3D dev_get_drvdata(dev); + struct isl12022 *isl12022 =3D dev_get_drvdata(dev); + struct regmap *regmap =3D isl12022->regmap; u32 user, val; int ret; =20 @@ -248,7 +256,8 @@ static const struct regmap_config regmap_config =3D { =20 static int isl12022_register_clock(struct device *dev) { - struct regmap *regmap =3D dev_get_drvdata(dev); + struct isl12022 *isl12022 =3D dev_get_drvdata(dev); + struct regmap *regmap =3D isl12022->regmap; struct clk_hw *hw; int ret; =20 @@ -288,7 +297,8 @@ static const u32 trip_levels[2][7] =3D { =20 static void isl12022_set_trip_levels(struct device *dev) { - struct regmap *regmap =3D dev_get_drvdata(dev); + struct isl12022 *isl12022 =3D dev_get_drvdata(dev); + struct regmap *regmap =3D isl12022->regmap; u32 levels[2] =3D {0, 0}; int ret, i, j, x[2]; u8 val, mask; @@ -325,6 +335,7 @@ static void isl12022_set_trip_levels(struct device *dev) =20 static int isl12022_probe(struct i2c_client *client) { + struct isl12022 *isl12022; struct rtc_device *rtc; struct regmap *regmap; int ret; @@ -332,13 +343,19 @@ static int isl12022_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -ENODEV; =20 + /* Allocate driver state */ + isl12022 =3D devm_kzalloc(&client->dev, sizeof(*isl12022), GFP_KERNEL); + if (!isl12022) + return -ENOMEM; + regmap =3D devm_regmap_init_i2c(client, ®map_config); if (IS_ERR(regmap)) { dev_err(&client->dev, "regmap allocation failed\n"); return PTR_ERR(regmap); } + isl12022->regmap =3D regmap; =20 - dev_set_drvdata(&client->dev, regmap); + dev_set_drvdata(&client->dev, isl12022); =20 ret =3D isl12022_register_clock(&client->dev); if (ret) --=20 2.46.0 From nobody Sat Nov 30 00:32:52 2024 Received: from www530.your-server.de (www530.your-server.de [188.40.30.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D3DD1DA10B; Fri, 13 Sep 2024 10:29:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.40.30.78 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223363; cv=none; b=YEtCS1AUmFLIT0s2QKnRECxRYAZb6pLW/+tXb0sgkIhbCvpXJ1iZYVexBXWI9dCJBAuidA/S/+ZzxdL+htaLy7S+aNWj0SzTrDPhqNhMbe7BVYt6p2nlR6/vTr2n1OrHVtArVZHD7XCreZmu3hl6bgbUzxPz/HWqVnor3/SivSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223363; c=relaxed/simple; bh=p5lW8kt+tBRv/bLQuedoXGoUXVQLK2RHiLH/s8cCZJU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TqHEL9YUXl44eh3Lc68kaQZ30dhmB+BuOe2kBTfH7/fzupwImIgTz02z4SdnFmJzci8VdAcKbaTAX7mKU+BJ5FR3hcZtJzuRJNaoLOWumuFJ91EyT4AAN1G99KNjpNAd6u2gs5uVU5cy3DeImAViayJtwkOIgHBLSY/uPXrfk2M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=geanix.com; spf=pass smtp.mailfrom=geanix.com; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b=jVubuQeJ; arc=none smtp.client-ip=188.40.30.78 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=geanix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=geanix.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b="jVubuQeJ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=geanix.com; s=default2211; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=UFkDIJo7jJmHoq3pVOjUKPfo/r4/oVTviXKltWdeniw=; b=jVubuQeJWjnIEIioR4svZB1Khh 6rVT2Kz+pGAmi+MvB5ByDYW9NT45sXeAsWxaX1FVo3ihRdf7ne4t2Yflg6Oz6DQ5V+bOpSB7qDpjQ DOvQITplHSrR6wtEYQFyMkU3QWZVsPBaNUkj7M7m6JqSyVAxv6Azo0KgJx6fLwk6kmh85PtGTCHjO Nk3Qd/DG8gsvnZFcC+Ty8latkUGT33IMCnYn1m1Qu+BQcp1RcxfcK3H+w6uU+xtMtf54T1qAdo7hR lvqS4TJE8DVOCSgedKCX6OmzVCBkyklwGaW6f7V/9lFV9KdA/9je8LFSWFHyMHVPHbPWvMqW69v7B iLWoMRCw==; Received: from sslproxy07.your-server.de ([78.47.199.104]) by www530.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sp3YF-0006Oe-67; Fri, 13 Sep 2024 12:29:19 +0200 Received: from [80.62.117.18] (helo=localhost) by sslproxy07.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sp3YE-0006wr-1B; Fri, 13 Sep 2024 12:29:18 +0200 From: Esben Haabendal Date: Fri, 13 Sep 2024 12:29:13 +0200 Subject: [PATCH v2 2/3] rtc: isl12022: Add alarm support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240913-rtc-isl12022-alarm-irq-v2-2-37309d939723@geanix.com> References: <20240913-rtc-isl12022-alarm-irq-v2-0-37309d939723@geanix.com> In-Reply-To: <20240913-rtc-isl12022-alarm-irq-v2-0-37309d939723@geanix.com> To: Alexandre Belloni , Rasmus Villemoes Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, Esben Haabendal X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1726223357; l=9873; i=esben@geanix.com; s=20240523; h=from:subject:message-id; bh=p5lW8kt+tBRv/bLQuedoXGoUXVQLK2RHiLH/s8cCZJU=; b=i7YQkFAgGBLNJYX7yBB8+uB5k5t5Sl6epAwKTH5U0RbYQ0WamP95YKt+R9+nkSIPMP/OHIROv 5qJbEwOehldB7ZNG6wXm8k5AmDeVdWFGaC65lq8f/AfAA0VN55ef72o X-Developer-Key: i=esben@geanix.com; a=ed25519; pk=PbXoezm+CERhtgVeF/QAgXtEzSkDIahcWfC7RIXNdEk= X-Authenticated-Sender: esben@geanix.com X-Virus-Scanned: Clear (ClamAV 0.103.10/27397/Fri Sep 13 10:48:01 2024) The ISL12022 RTC has a combined INT/fOUT pin, which can be used for alarm interrupt when frequency output is not enabled. The device-tree bindings should ensure that interrupt and clock output is not enabled at the same time. Signed-off-by: Esben Haabendal --- drivers/rtc/rtc-isl12022.c | 234 +++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 227 insertions(+), 7 deletions(-) diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c index d82278fdc29b..8001e3c5da76 100644 --- a/drivers/rtc/rtc-isl12022.c +++ b/drivers/rtc/rtc-isl12022.c @@ -21,7 +21,7 @@ =20 #include =20 -/* ISL register offsets */ +/* RTC - Real time clock registers */ #define ISL12022_REG_SC 0x00 #define ISL12022_REG_MN 0x01 #define ISL12022_REG_HR 0x02 @@ -30,21 +30,36 @@ #define ISL12022_REG_YR 0x05 #define ISL12022_REG_DW 0x06 =20 +/* CSR - Control and status registers */ #define ISL12022_REG_SR 0x07 #define ISL12022_REG_INT 0x08 - #define ISL12022_REG_PWR_VBAT 0x0a - #define ISL12022_REG_BETA 0x0d + +/* ALARM - Alarm registers */ +#define ISL12022_REG_SCA0 0x10 +#define ISL12022_REG_MNA0 0x11 +#define ISL12022_REG_HRA0 0x12 +#define ISL12022_REG_DTA0 0x13 +#define ISL12022_REG_MOA0 0x14 +#define ISL12022_REG_DWA0 0x15 +#define ISL12022_ALARM ISL12022_REG_SCA0 +#define ISL12022_ALARM_LEN (ISL12022_REG_DWA0 - ISL12022_REG_SCA0 + 1) + +/* TEMP - Temperature sensor registers */ #define ISL12022_REG_TEMP_L 0x28 =20 /* ISL register bits */ #define ISL12022_HR_MIL (1 << 7) /* military or 24 hour time */ =20 +#define ISL12022_SR_ALM (1 << 4) #define ISL12022_SR_LBAT85 (1 << 2) #define ISL12022_SR_LBAT75 (1 << 1) =20 +#define ISL12022_INT_ARST (1 << 7) #define ISL12022_INT_WRTC (1 << 6) +#define ISL12022_INT_IM (1 << 5) +#define ISL12022_INT_FOBATB (1 << 4) #define ISL12022_INT_FO_MASK GENMASK(3, 0) #define ISL12022_INT_FO_OFF 0x0 #define ISL12022_INT_FO_32K 0x1 @@ -52,10 +67,17 @@ #define ISL12022_REG_VB85_MASK GENMASK(5, 3) #define ISL12022_REG_VB75_MASK GENMASK(2, 0) =20 +#define ISL12022_ALARM_ENABLE (1 << 7) /* for all ALARM registers */ + #define ISL12022_BETA_TSE (1 << 7) =20 +static struct i2c_driver isl12022_driver; + struct isl12022 { + struct rtc_device *rtc; struct regmap *regmap; + int irq; + bool irq_enabled; }; =20 static umode_t isl12022_hwmon_is_visible(const void *data, @@ -215,6 +237,194 @@ static int isl12022_rtc_set_time(struct device *dev, = struct rtc_time *tm) return regmap_bulk_write(regmap, ISL12022_REG_SC, buf, sizeof(buf)); } =20 +static int isl12022_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *= alarm) +{ + struct rtc_time *tm =3D &alarm->time; + struct isl12022 *isl12022 =3D dev_get_drvdata(dev); + struct regmap *regmap =3D isl12022->regmap; + u8 buf[ISL12022_ALARM_LEN]; + unsigned int i, yr; + int ret; + + ret =3D regmap_bulk_read(regmap, ISL12022_ALARM, buf, sizeof(buf)); + if (ret) { + dev_dbg(dev, "%s: reading ALARM registers failed\n", + __func__); + return ret; + } + + /* The alarm doesn't store the year so get it from the rtc section */ + ret =3D regmap_read(regmap, ISL12022_REG_YR, &yr); + if (ret) { + dev_dbg(dev, "%s: reading YR register failed\n", __func__); + return ret; + } + + dev_dbg(dev, + "%s: sc=3D%02x, mn=3D%02x, hr=3D%02x, dt=3D%02x, mo=3D%02x, dw=3D%02x yr= =3D%u\n", + __func__, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], yr); + + tm->tm_sec =3D bcd2bin(buf[ISL12022_REG_SCA0 - ISL12022_ALARM] & 0x7F); + tm->tm_min =3D bcd2bin(buf[ISL12022_REG_MNA0 - ISL12022_ALARM] & 0x7F); + tm->tm_hour =3D bcd2bin(buf[ISL12022_REG_HRA0 - ISL12022_ALARM] & 0x3F); + tm->tm_mday =3D bcd2bin(buf[ISL12022_REG_DTA0 - ISL12022_ALARM] & 0x3F); + tm->tm_mon =3D bcd2bin(buf[ISL12022_REG_MOA0 - ISL12022_ALARM] & 0x1F) -= 1; + tm->tm_wday =3D buf[ISL12022_REG_DWA0 - ISL12022_ALARM] & 0x07; + tm->tm_year =3D bcd2bin(yr) + 100; + + for (i =3D 0; i < ISL12022_ALARM_LEN; i++) { + if (buf[i] & ISL12022_ALARM_ENABLE) { + alarm->enabled =3D 1; + break; + } + } + + dev_dbg(dev, "%s: %ptR\n", __func__, tm); + + return 0; +} + +static int isl12022_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *a= larm) +{ + struct rtc_time *alarm_tm =3D &alarm->time; + struct isl12022 *isl12022 =3D dev_get_drvdata(dev); + struct regmap *regmap =3D isl12022->regmap; + u8 regs[ISL12022_ALARM_LEN] =3D { 0, }; + struct rtc_time rtc_tm; + int ret, enable, dw; + + ret =3D isl12022_rtc_read_time(dev, &rtc_tm); + if (ret) + return ret; + + /* If the alarm time is before the current time disable the alarm */ + if (!alarm->enabled || rtc_tm_sub(alarm_tm, &rtc_tm) <=3D 0) + enable =3D 0; + else + enable =3D ISL12022_ALARM_ENABLE; + + /* + * Set non-matching day of the week to safeguard against early false + * matching while setting all the alarm registers (this rtc lacks a + * general alarm/irq enable/disable bit). + */ + ret =3D regmap_read(regmap, ISL12022_REG_DW, &dw); + if (ret) { + dev_dbg(dev, "%s: reading DW failed\n", __func__); + return ret; + } + /* ~4 days into the future should be enough to avoid match */ + dw =3D ((dw + 4) % 7) | ISL12022_ALARM_ENABLE; + ret =3D regmap_write(regmap, ISL12022_REG_DWA0, dw); + if (ret) { + dev_dbg(dev, "%s: writing DWA0 failed\n", __func__); + return ret; + } + + /* Program the alarm and enable it for each setting */ + regs[ISL12022_REG_SCA0 - ISL12022_ALARM] =3D bin2bcd(alarm_tm->tm_sec) | = enable; + regs[ISL12022_REG_MNA0 - ISL12022_ALARM] =3D bin2bcd(alarm_tm->tm_min) | = enable; + regs[ISL12022_REG_HRA0 - ISL12022_ALARM] =3D bin2bcd(alarm_tm->tm_hour) |= enable; + regs[ISL12022_REG_DTA0 - ISL12022_ALARM] =3D bin2bcd(alarm_tm->tm_mday) |= enable; + regs[ISL12022_REG_MOA0 - ISL12022_ALARM] =3D bin2bcd(alarm_tm->tm_mon + 1= ) | enable; + regs[ISL12022_REG_DWA0 - ISL12022_ALARM] =3D bin2bcd(alarm_tm->tm_wday & = 7) | enable; + + /* write ALARM registers */ + ret =3D regmap_bulk_write(regmap, ISL12022_ALARM, ®s, sizeof(regs)); + if (ret) { + dev_dbg(dev, "%s: writing ALARM registers failed\n", __func__); + return ret; + } + + return 0; +} + +static irqreturn_t isl12022_rtc_interrupt(int irq, void *data) +{ + struct isl12022 *isl12022 =3D data; + struct rtc_device *rtc =3D isl12022->rtc; + struct device *dev =3D &rtc->dev; + struct regmap *regmap =3D isl12022->regmap; + u32 val =3D 0; + unsigned long events =3D 0; + int ret; + + ret =3D regmap_read(regmap, ISL12022_REG_SR, &val); + if (ret) { + dev_dbg(dev, "%s: reading SR failed\n", __func__); + return IRQ_HANDLED; + } + + if (val & ISL12022_SR_ALM) + events |=3D RTC_IRQF | RTC_AF; + + if (events & RTC_AF) + dev_dbg(dev, "alarm!\n"); + + if (!events) + return IRQ_NONE; + + rtc_update_irq(rtc, 1, events); + return IRQ_HANDLED; +} + +static int isl12022_rtc_alarm_irq_enable(struct device *dev, + unsigned int enabled) +{ + struct isl12022 *isl12022 =3D dev_get_drvdata(dev); + + /* Make sure enabled is 0 or 1 */ + enabled =3D !!enabled; + + if (isl12022->irq_enabled =3D=3D enabled) + return 0; + + if (enabled) + enable_irq(isl12022->irq); + else + disable_irq(isl12022->irq); + + isl12022->irq_enabled =3D enabled; + + return 0; +} + +static int isl12022_setup_irq(struct device *dev, int irq) +{ + struct isl12022 *isl12022 =3D dev_get_drvdata(dev); + struct regmap *regmap =3D isl12022->regmap; + unsigned int reg_mask, reg_val; + u8 buf[ISL12022_ALARM_LEN] =3D { 0, }; + int ret; + + /* Clear and disable all alarm registers */ + ret =3D regmap_bulk_write(regmap, ISL12022_ALARM, buf, sizeof(buf)); + if (ret) + return ret; + + /* + * Enable automatic reset of ALM bit and enable single event interrupt + * mode. + */ + reg_mask =3D ISL12022_INT_ARST | ISL12022_INT_IM | ISL12022_INT_FO_MASK; + reg_val =3D ISL12022_INT_ARST | ISL12022_INT_FO_OFF; + ret =3D regmap_write_bits(regmap, ISL12022_REG_INT, + reg_mask, reg_val); + if (ret) + return ret; + + ret =3D devm_request_threaded_irq(dev, irq, NULL, + isl12022_rtc_interrupt, + IRQF_SHARED | IRQF_ONESHOT, + isl12022_driver.driver.name, + isl12022); + if (ret) + return dev_err_probe(dev, ret, "Unable to request irq %d\n", irq); + + isl12022->irq =3D irq; + return 0; +} + static int isl12022_rtc_ioctl(struct device *dev, unsigned int cmd, unsign= ed long arg) { struct isl12022 *isl12022 =3D dev_get_drvdata(dev); @@ -246,6 +456,9 @@ static const struct rtc_class_ops isl12022_rtc_ops =3D { .ioctl =3D isl12022_rtc_ioctl, .read_time =3D isl12022_rtc_read_time, .set_time =3D isl12022_rtc_set_time, + .read_alarm =3D isl12022_rtc_read_alarm, + .set_alarm =3D isl12022_rtc_set_alarm, + .alarm_irq_enable =3D isl12022_rtc_alarm_irq_enable, }; =20 static const struct regmap_config regmap_config =3D { @@ -349,10 +562,8 @@ static int isl12022_probe(struct i2c_client *client) return -ENOMEM; =20 regmap =3D devm_regmap_init_i2c(client, ®map_config); - if (IS_ERR(regmap)) { - dev_err(&client->dev, "regmap allocation failed\n"); - return PTR_ERR(regmap); - } + if (IS_ERR(regmap)) + return dev_err_probe(&client->dev, PTR_ERR(regmap), "regmap allocation f= ailed\n"); isl12022->regmap =3D regmap; =20 dev_set_drvdata(&client->dev, isl12022); @@ -367,11 +578,20 @@ static int isl12022_probe(struct i2c_client *client) rtc =3D devm_rtc_allocate_device(&client->dev); if (IS_ERR(rtc)) return PTR_ERR(rtc); + isl12022->rtc =3D rtc; =20 rtc->ops =3D &isl12022_rtc_ops; rtc->range_min =3D RTC_TIMESTAMP_BEGIN_2000; rtc->range_max =3D RTC_TIMESTAMP_END_2099; =20 + if (client->irq > 0) { + ret =3D isl12022_setup_irq(&client->dev, client->irq); + if (ret) + return ret; + } else { + clear_bit(RTC_FEATURE_ALARM, rtc->features); + } + return devm_rtc_register_device(rtc); } =20 --=20 2.46.0 From nobody Sat Nov 30 00:32:52 2024 Received: from www530.your-server.de (www530.your-server.de [188.40.30.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EB141DA112; Fri, 13 Sep 2024 10:29:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.40.30.78 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223364; cv=none; b=AeJn3REIti0q7CkmYfP0eIZXUINVS32yCAysm0nBwvCIgzQoZ752IlDVN55vGfzIKwRnNn5GWqCUwwo/ZeqtvQ+NdIJs0Vv5ukRTGctrtGPDQ49TG+fjvfMUHd1igafPHUJaKYVCBuJglOmi89tOE0lmeJSXtO5+a6G7CHpDHqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223364; c=relaxed/simple; bh=1oXD4NzVC1bjitr4jBpT8V7XG4g08+jepLpFv68RC5o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U2STdpmcaH/gVQUZZVs2URu7Bquy5gFXuPn4oqu+6LXCqOKUt9vRbvrW+KFS5jCp+VPWKk9wWWDTAJEwF31Xq6Ada/+HUjt07ztIfDzYON8vlTiH4JKa2Zgj3+p7E7XBi1GdDXBOKZrTnXtNVTyl8XQRUxwhaZozslwAmRUGV/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=geanix.com; spf=pass smtp.mailfrom=geanix.com; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b=huaAeVWN; arc=none smtp.client-ip=188.40.30.78 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=geanix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=geanix.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b="huaAeVWN" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=geanix.com; s=default2211; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=fKWpOn1LSJqL+d1QyUQwAruHGeHxwd3osLSyeITf/gI=; b=huaAeVWNDeeB1GyOSvYGoC5W71 CRaoEYa0W4OojAO8q6NoBan1/LpH32sprDx3Ra4IoBm0rSiuFgy5hhTjlp9JdoS6r1UjDvEMKCEB3 FpoNDpfMAJaMzkgGu6zHneu3b9RmyJaoWmj2XQqWidMylpwBp2rtxDUmmHFaTZ9GQ29WakQAUb8TT yamJOezQMpCWiEnKGFD92RbxXrG4e0W8Xo7DKivg2nF9qUX1RDAKOsUoTywMfohAKrBjOk5MclvMQ T1eBn/JuI3kEc7JhYvcS4GgCi2b/XQz0LsXKk0vODWsVlk+rFHRV6RJXdKWLKxkfI+r9Teu3X71ZS XdpIoYGA==; Received: from sslproxy07.your-server.de ([78.47.199.104]) by www530.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sp3YF-0006Os-RL; Fri, 13 Sep 2024 12:29:19 +0200 Received: from [80.62.117.18] (helo=localhost) by sslproxy07.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sp3YF-00072R-0G; Fri, 13 Sep 2024 12:29:19 +0200 From: Esben Haabendal Date: Fri, 13 Sep 2024 12:29:14 +0200 Subject: [PATCH v2 3/3] rtc: isl12022: Replace uint8_t types with u8 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240913-rtc-isl12022-alarm-irq-v2-3-37309d939723@geanix.com> References: <20240913-rtc-isl12022-alarm-irq-v2-0-37309d939723@geanix.com> In-Reply-To: <20240913-rtc-isl12022-alarm-irq-v2-0-37309d939723@geanix.com> To: Alexandre Belloni , Rasmus Villemoes Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, Esben Haabendal X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1726223357; l=1110; i=esben@geanix.com; s=20240523; h=from:subject:message-id; bh=1oXD4NzVC1bjitr4jBpT8V7XG4g08+jepLpFv68RC5o=; b=BSJemiw0uCbOxTEeFBGp3qPpj8wtMCfMBaW+pi14jb+0o6cTwDlD8UyEpqckE0CMzz2amx6F0 gnjmF1oCy65AL4FyuxPU9tt6MUbi7CtduLB0KEBpTBE79ZTGYMDYg3V X-Developer-Key: i=esben@geanix.com; a=ed25519; pk=PbXoezm+CERhtgVeF/QAgXtEzSkDIahcWfC7RIXNdEk= X-Authenticated-Sender: esben@geanix.com X-Virus-Scanned: Clear (ClamAV 0.103.10/27397/Fri Sep 13 10:48:01 2024) Keep coding style consistent, by using kernel integer types instead of standard types. Signed-off-by: Esben Haabendal --- drivers/rtc/rtc-isl12022.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c index 8001e3c5da76..9b44839a7402 100644 --- a/drivers/rtc/rtc-isl12022.c +++ b/drivers/rtc/rtc-isl12022.c @@ -172,7 +172,7 @@ static int isl12022_rtc_read_time(struct device *dev, s= truct rtc_time *tm) { struct isl12022 *isl12022 =3D dev_get_drvdata(dev); struct regmap *regmap =3D isl12022->regmap; - uint8_t buf[ISL12022_REG_INT + 1]; + u8 buf[ISL12022_REG_INT + 1]; int ret; =20 ret =3D regmap_bulk_read(regmap, ISL12022_REG_SC, buf, sizeof(buf)); @@ -209,7 +209,7 @@ static int isl12022_rtc_set_time(struct device *dev, st= ruct rtc_time *tm) struct isl12022 *isl12022 =3D dev_get_drvdata(dev); struct regmap *regmap =3D isl12022->regmap; int ret; - uint8_t buf[ISL12022_REG_DW + 1]; + u8 buf[ISL12022_REG_DW + 1]; =20 dev_dbg(dev, "%s: %ptR\n", __func__, tm); =20 --=20 2.46.0