linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/3] Make IRQ as optional
@ 2024-01-05 14:53 Biju Das
  2024-01-05 14:53 ` [PATCH v3 1/3] rtc: da9063: " Biju Das
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Biju Das @ 2024-01-05 14:53 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: Biju Das, Support Opensource, linux-rtc, Geert Uytterhoeven,
	Prabhakar Mahadev Lad, Biju Das, linux-renesas-soc

On some platforms (eg: RZ/{G2UL,Five} SMARC EVK), there is no IRQ
populated by default. Add irq optional support.

v2->v3:
 * Dropped clearing redundant RTC_FEATURE_UPDATE_INTERRUPT bit
 * Added Rb tag from Geert for patch#1.
v1->v2:
 * Make RTC patch series separate from dt patches.
 * Propagated real errors for platform_get_irq_byname_optional().
 * Cleared ALARM feature bit for non-irq case.
 * Added Rb tag from Geert for patch#2 and #3
 * Restored dev_err() for devm_request_threaded_irq() as an RTC can wake
   up a system without an IRQ.

Biju Das (3):
  rtc: da9063: Make IRQ as optional
  rtc: da9063: Use device_get_match_data()
  rtc: da9063: Use dev_err_probe()

 drivers/rtc/rtc-da9063.c | 88 ++++++++++++++++++----------------------
 1 file changed, 40 insertions(+), 48 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/3] rtc: da9063: Make IRQ as optional
  2024-01-05 14:53 [PATCH v3 0/3] Make IRQ as optional Biju Das
@ 2024-01-05 14:53 ` Biju Das
  2024-01-05 14:53 ` [PATCH v3 2/3] rtc: da9063: Use device_get_match_data() Biju Das
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Biju Das @ 2024-01-05 14:53 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: Biju Das, Support Opensource, linux-rtc, Geert Uytterhoeven,
	Prabhakar Mahadev Lad, Biju Das, linux-renesas-soc

On some platforms (eg: RZ/{G2UL,Five} SMARC EVK), there is no IRQ
populated by default. Add irq optional support.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2->v3:
 * Dropped clearing redundant RTC_FEATURE_UPDATE_INTERRUPT bit
 * Added Rb tag from Geert
v1->v2:
 * Propagated real errors for platform_get_irq_byname_optional().
 * Cleared ALARM feature bit for non-irq case.
---
 drivers/rtc/rtc-da9063.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/drivers/rtc/rtc-da9063.c b/drivers/rtc/rtc-da9063.c
index 2f5d60622564..b3a1f852c318 100644
--- a/drivers/rtc/rtc-da9063.c
+++ b/drivers/rtc/rtc-da9063.c
@@ -485,25 +485,29 @@ static int da9063_rtc_probe(struct platform_device *pdev)
 		clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->rtc_dev->features);
 	}
 
-	irq_alarm = platform_get_irq_byname(pdev, "ALARM");
-	if (irq_alarm < 0)
+	irq_alarm = platform_get_irq_byname_optional(pdev, "ALARM");
+	if (irq_alarm >= 0) {
+		ret = devm_request_threaded_irq(&pdev->dev, irq_alarm, NULL,
+						da9063_alarm_event,
+						IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+						"ALARM", rtc);
+		if (ret)
+			dev_err(&pdev->dev,
+				"Failed to request ALARM IRQ %d: %d\n",
+				irq_alarm, ret);
+
+		ret = dev_pm_set_wake_irq(&pdev->dev, irq_alarm);
+		if (ret)
+			dev_warn(&pdev->dev,
+				 "Failed to set IRQ %d as a wake IRQ: %d\n",
+				 irq_alarm, ret);
+
+		device_init_wakeup(&pdev->dev, true);
+	}  else if (irq_alarm != -ENXIO) {
 		return irq_alarm;
-
-	ret = devm_request_threaded_irq(&pdev->dev, irq_alarm, NULL,
-					da9063_alarm_event,
-					IRQF_TRIGGER_LOW | IRQF_ONESHOT,
-					"ALARM", rtc);
-	if (ret)
-		dev_err(&pdev->dev, "Failed to request ALARM IRQ %d: %d\n",
-			irq_alarm, ret);
-
-	ret = dev_pm_set_wake_irq(&pdev->dev, irq_alarm);
-	if (ret)
-		dev_warn(&pdev->dev,
-			 "Failed to set IRQ %d as a wake IRQ: %d\n",
-			 irq_alarm, ret);
-
-	device_init_wakeup(&pdev->dev, true);
+	} else {
+		clear_bit(RTC_FEATURE_ALARM, rtc->rtc_dev->features);
+	}
 
 	return devm_rtc_register_device(rtc->rtc_dev);
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/3] rtc: da9063: Use device_get_match_data()
  2024-01-05 14:53 [PATCH v3 0/3] Make IRQ as optional Biju Das
  2024-01-05 14:53 ` [PATCH v3 1/3] rtc: da9063: " Biju Das
@ 2024-01-05 14:53 ` Biju Das
  2024-01-05 14:53 ` [PATCH v3 3/3] rtc: da9063: Use dev_err_probe() Biju Das
  2024-01-18  0:26 ` [PATCH v3 0/3] Make IRQ as optional Alexandre Belloni
  3 siblings, 0 replies; 5+ messages in thread
From: Biju Das @ 2024-01-05 14:53 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: Biju Das, Support Opensource, linux-rtc, Geert Uytterhoeven,
	Prabhakar Mahadev Lad, Biju Das, linux-renesas-soc

Replace of_match_node()->device_get_match_data() for
the data associated with device match.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2->v3:
 * No change
v1->v2:
 * Added Rb tag from Geert
---
 drivers/rtc/rtc-da9063.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/rtc/rtc-da9063.c b/drivers/rtc/rtc-da9063.c
index b3a1f852c318..265abdd7e935 100644
--- a/drivers/rtc/rtc-da9063.c
+++ b/drivers/rtc/rtc-da9063.c
@@ -377,7 +377,6 @@ static int da9063_rtc_probe(struct platform_device *pdev)
 {
 	struct da9063_compatible_rtc *rtc;
 	const struct da9063_compatible_rtc_regmap *config;
-	const struct of_device_id *match;
 	int irq_alarm;
 	u8 data[RTC_DATA_LEN];
 	int ret;
@@ -385,14 +384,11 @@ static int da9063_rtc_probe(struct platform_device *pdev)
 	if (!pdev->dev.of_node)
 		return -ENXIO;
 
-	match = of_match_node(da9063_compatible_reg_id_table,
-			      pdev->dev.of_node);
-
 	rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
 	if (!rtc)
 		return -ENOMEM;
 
-	rtc->config = match->data;
+	rtc->config = device_get_match_data(&pdev->dev);
 	if (of_device_is_compatible(pdev->dev.of_node, "dlg,da9063-rtc")) {
 		struct da9063 *chip = dev_get_drvdata(pdev->dev.parent);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 3/3] rtc: da9063: Use dev_err_probe()
  2024-01-05 14:53 [PATCH v3 0/3] Make IRQ as optional Biju Das
  2024-01-05 14:53 ` [PATCH v3 1/3] rtc: da9063: " Biju Das
  2024-01-05 14:53 ` [PATCH v3 2/3] rtc: da9063: Use device_get_match_data() Biju Das
@ 2024-01-05 14:53 ` Biju Das
  2024-01-18  0:26 ` [PATCH v3 0/3] Make IRQ as optional Alexandre Belloni
  3 siblings, 0 replies; 5+ messages in thread
From: Biju Das @ 2024-01-05 14:53 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: Biju Das, Support Opensource, linux-rtc, Geert Uytterhoeven,
	Prabhakar Mahadev Lad, Biju Das, linux-renesas-soc

Replace dev_err()->dev_err_probe() to simpilfy probe().

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2->v3:
 * No change.
v1->v2:
 * Added Rb tag from Geert.
 * Restored dev_err() for devm_request_threaded_irq() as an RTC can wake
   up a system without an IRQ.
---
 drivers/rtc/rtc-da9063.c | 42 ++++++++++++++++------------------------
 1 file changed, 17 insertions(+), 25 deletions(-)

diff --git a/drivers/rtc/rtc-da9063.c b/drivers/rtc/rtc-da9063.c
index 265abdd7e935..859397541f29 100644
--- a/drivers/rtc/rtc-da9063.c
+++ b/drivers/rtc/rtc-da9063.c
@@ -407,57 +407,49 @@ static int da9063_rtc_probe(struct platform_device *pdev)
 				 config->rtc_enable_reg,
 				 config->rtc_enable_mask,
 				 config->rtc_enable_mask);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to enable RTC\n");
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(&pdev->dev, ret, "Failed to enable RTC\n");
 
 	ret = regmap_update_bits(rtc->regmap,
 				 config->rtc_enable_32k_crystal_reg,
 				 config->rtc_crystal_mask,
 				 config->rtc_crystal_mask);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to run 32kHz oscillator\n");
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to run 32kHz oscillator\n");
 
 	ret = regmap_update_bits(rtc->regmap,
 				 config->rtc_alarm_secs_reg,
 				 config->rtc_alarm_status_mask,
 				 0);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to access RTC alarm register\n");
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to access RTC alarm register\n");
 
 	ret = regmap_update_bits(rtc->regmap,
 				 config->rtc_alarm_secs_reg,
 				 DA9063_ALARM_STATUS_ALARM,
 				 DA9063_ALARM_STATUS_ALARM);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to access RTC alarm register\n");
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to access RTC alarm register\n");
 
 	ret = regmap_update_bits(rtc->regmap,
 				 config->rtc_alarm_year_reg,
 				 config->rtc_tick_on_mask,
 				 0);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to disable TICKs\n");
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to disable TICKs\n");
 
 	data[RTC_SEC] = 0;
 	ret = regmap_bulk_read(rtc->regmap,
 			       config->rtc_alarm_secs_reg,
 			       &data[config->rtc_data_start],
 			       config->rtc_alarm_len);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to read initial alarm data: %d\n",
-			ret);
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to read initial alarm data\n");
 
 	platform_set_drvdata(pdev, rtc);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 0/3] Make IRQ as optional
  2024-01-05 14:53 [PATCH v3 0/3] Make IRQ as optional Biju Das
                   ` (2 preceding siblings ...)
  2024-01-05 14:53 ` [PATCH v3 3/3] rtc: da9063: Use dev_err_probe() Biju Das
@ 2024-01-18  0:26 ` Alexandre Belloni
  3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2024-01-18  0:26 UTC (permalink / raw)
  To: Alessandro Zummo, Biju Das
  Cc: Support Opensource, linux-rtc, Geert Uytterhoeven,
	Prabhakar Mahadev Lad, Biju Das, linux-renesas-soc

On Fri, 05 Jan 2024 14:53:41 +0000, Biju Das wrote:
> On some platforms (eg: RZ/{G2UL,Five} SMARC EVK), there is no IRQ
> populated by default. Add irq optional support.
> 
> v2->v3:
>  * Dropped clearing redundant RTC_FEATURE_UPDATE_INTERRUPT bit
>  * Added Rb tag from Geert for patch#1.
> v1->v2:
>  * Make RTC patch series separate from dt patches.
>  * Propagated real errors for platform_get_irq_byname_optional().
>  * Cleared ALARM feature bit for non-irq case.
>  * Added Rb tag from Geert for patch#2 and #3
>  * Restored dev_err() for devm_request_threaded_irq() as an RTC can wake
>    up a system without an IRQ.
> 
> [...]

Applied, thanks!

[1/3] rtc: da9063: Make IRQ as optional
      https://git.kernel.org/abelloni/c/8681de6457aa
[2/3] rtc: da9063: Use device_get_match_data()
      https://git.kernel.org/abelloni/c/4b60c32e979a
[3/3] rtc: da9063: Use dev_err_probe()
      https://git.kernel.org/abelloni/c/f5334aa88345

Best regards,

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-18  0:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-05 14:53 [PATCH v3 0/3] Make IRQ as optional Biju Das
2024-01-05 14:53 ` [PATCH v3 1/3] rtc: da9063: " Biju Das
2024-01-05 14:53 ` [PATCH v3 2/3] rtc: da9063: Use device_get_match_data() Biju Das
2024-01-05 14:53 ` [PATCH v3 3/3] rtc: da9063: Use dev_err_probe() Biju Das
2024-01-18  0:26 ` [PATCH v3 0/3] Make IRQ as optional Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).