* [PATCH] rtc: pcf85363: Allow to wake up system without IRQ
[not found] <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.eeedf5db-4013-4c3b-be1c-1121df58f897@emailsignatures365.codetwo.com>
@ 2023-05-02 5:54 ` Mike Looijmans
2023-08-16 21:40 ` Alexandre Belloni
0 siblings, 1 reply; 6+ messages in thread
From: Mike Looijmans @ 2023-05-02 5:54 UTC (permalink / raw)
To: linux-rtc
Cc: Mike Looijmans, Alessandro Zummo, Alexandre Belloni, linux-kernel
When wakeup-source is set in the devicetree, set up the device for
using the output as interrupt instead of clock. This is similar to
how other RTC devices handle this.
This allows the clock chip to turn on the board when wired to do
so in hardware.
Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
---
drivers/rtc/rtc-pcf85363.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c
index 8958eadf1c3e..b1543bcdc530 100644
--- a/drivers/rtc/rtc-pcf85363.c
+++ b/drivers/rtc/rtc-pcf85363.c
@@ -434,23 +434,26 @@ static int pcf85363_probe(struct i2c_client *client)
pcf85363->rtc->range_max = RTC_TIMESTAMP_END_2099;
clear_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
+ if (client->irq > 0 || device_property_read_bool(&client->dev,
+ "wakeup-source")) {
+ regmap_write(pcf85363->regmap, CTRL_FLAGS, 0);
+ regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO,
+ PIN_IO_INTA_OUT, PIN_IO_INTAPM);
+ device_init_wakeup(&client->dev, true);
+ set_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
+ }
+
if (client->irq > 0) {
unsigned long irqflags = IRQF_TRIGGER_LOW;
if (dev_fwnode(&client->dev))
irqflags = 0;
-
- regmap_write(pcf85363->regmap, CTRL_FLAGS, 0);
- regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO,
- PIN_IO_INTA_OUT, PIN_IO_INTAPM);
ret = devm_request_threaded_irq(&client->dev, client->irq,
NULL, pcf85363_rtc_handle_irq,
irqflags | IRQF_ONESHOT,
"pcf85363", client);
if (ret)
- dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n");
- else
- set_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
+ dev_warn(&client->dev, "unable to request IRQ, alarm not functional\n");
}
ret = devm_rtc_register_device(pcf85363->rtc);
--
2.17.1
Met vriendelijke groet / kind regards,
Mike Looijmans
System Expert
TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands
T: +31 (0) 499 33 69 69
E: mike.looijmans@topicproducts.com
W: www.topic.nl
Please consider the environment before printing this e-mail
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] rtc: pcf85363: Allow to wake up system without IRQ
2023-05-02 5:54 ` [PATCH] rtc: pcf85363: Allow to wake up system without IRQ Mike Looijmans
@ 2023-08-16 21:40 ` Alexandre Belloni
2023-08-17 5:42 ` Mike Looijmans
0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Belloni @ 2023-08-16 21:40 UTC (permalink / raw)
To: Mike Looijmans; +Cc: linux-rtc, Alessandro Zummo, linux-kernel
Hello Mike,
Sorry for the very late review, there is a small change that is needed:
On 02/05/2023 07:54:58+0200, Mike Looijmans wrote:
> When wakeup-source is set in the devicetree, set up the device for
> using the output as interrupt instead of clock. This is similar to
> how other RTC devices handle this.
>
> This allows the clock chip to turn on the board when wired to do
> so in hardware.
>
> Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
>
> ---
>
> drivers/rtc/rtc-pcf85363.c | 17 ++++++++++-------
> 1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c
> index 8958eadf1c3e..b1543bcdc530 100644
> --- a/drivers/rtc/rtc-pcf85363.c
> +++ b/drivers/rtc/rtc-pcf85363.c
> @@ -434,23 +434,26 @@ static int pcf85363_probe(struct i2c_client *client)
> pcf85363->rtc->range_max = RTC_TIMESTAMP_END_2099;
> clear_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
>
> + if (client->irq > 0 || device_property_read_bool(&client->dev,
> + "wakeup-source")) {
> + regmap_write(pcf85363->regmap, CTRL_FLAGS, 0);
> + regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO,
> + PIN_IO_INTA_OUT, PIN_IO_INTAPM);
> + device_init_wakeup(&client->dev, true);
> + set_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
This should not be done when devm_request_threaded_irq fails.
> + }
> +
> if (client->irq > 0) {
> unsigned long irqflags = IRQF_TRIGGER_LOW;
>
> if (dev_fwnode(&client->dev))
> irqflags = 0;
> -
> - regmap_write(pcf85363->regmap, CTRL_FLAGS, 0);
> - regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO,
> - PIN_IO_INTA_OUT, PIN_IO_INTAPM);
> ret = devm_request_threaded_irq(&client->dev, client->irq,
> NULL, pcf85363_rtc_handle_irq,
> irqflags | IRQF_ONESHOT,
> "pcf85363", client);
> if (ret)
> - dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n");
> - else
> - set_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
> + dev_warn(&client->dev, "unable to request IRQ, alarm not functional\n");
> }
>
> ret = devm_rtc_register_device(pcf85363->rtc);
> --
> 2.17.1
>
>
> Met vriendelijke groet / kind regards,
>
> Mike Looijmans
> System Expert
>
>
> TOPIC Embedded Products B.V.
> Materiaalweg 4, 5681 RJ Best
> The Netherlands
>
> T: +31 (0) 499 33 69 69
> E: mike.looijmans@topicproducts.com
> W: www.topic.nl
>
> Please consider the environment before printing this e-mail
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rtc: pcf85363: Allow to wake up system without IRQ
2023-08-16 21:40 ` Alexandre Belloni
@ 2023-08-17 5:42 ` Mike Looijmans
2023-08-17 8:17 ` Alexandre Belloni
0 siblings, 1 reply; 6+ messages in thread
From: Mike Looijmans @ 2023-08-17 5:42 UTC (permalink / raw)
To: Alexandre Belloni; +Cc: linux-rtc, Alessandro Zummo, linux-kernel
On 16-08-2023 23:40, Alexandre Belloni wrote:
> Hello Mike,
>
> Sorry for the very late review, there is a small change that is needed:
Better late than never
>
> On 02/05/2023 07:54:58+0200, Mike Looijmans wrote:
>> When wakeup-source is set in the devicetree, set up the device for
>> using the output as interrupt instead of clock. This is similar to
>> how other RTC devices handle this.
>>
>> This allows the clock chip to turn on the board when wired to do
>> so in hardware.
>>
>> Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
>>
>> ---
>>
>> drivers/rtc/rtc-pcf85363.c | 17 ++++++++++-------
>> 1 file changed, 10 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c
>> index 8958eadf1c3e..b1543bcdc530 100644
>> --- a/drivers/rtc/rtc-pcf85363.c
>> +++ b/drivers/rtc/rtc-pcf85363.c
>> @@ -434,23 +434,26 @@ static int pcf85363_probe(struct i2c_client *client)
>> pcf85363->rtc->range_max = RTC_TIMESTAMP_END_2099;
>> clear_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
>>
>> + if (client->irq > 0 || device_property_read_bool(&client->dev,
>> + "wakeup-source")) {
>> + regmap_write(pcf85363->regmap, CTRL_FLAGS, 0);
>> + regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO,
>> + PIN_IO_INTA_OUT, PIN_IO_INTAPM);
>> + device_init_wakeup(&client->dev, true);
>> + set_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
>
> This should not be done when devm_request_threaded_irq fails.
Yeah, easiest would be to just clear the feature flag when that happens.
>
>> + }
>> +
>> if (client->irq > 0) {
>> unsigned long irqflags = IRQF_TRIGGER_LOW;
>>
>> if (dev_fwnode(&client->dev))
>> irqflags = 0;
>> -
>> - regmap_write(pcf85363->regmap, CTRL_FLAGS, 0);
>> - regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO,
>> - PIN_IO_INTA_OUT, PIN_IO_INTAPM);
>> ret = devm_request_threaded_irq(&client->dev, client->irq,
>> NULL, pcf85363_rtc_handle_irq,
>> irqflags | IRQF_ONESHOT,
>> "pcf85363", client);
>> if (ret)
>> - dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n");
>> - else
>> - set_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
>> + dev_warn(&client->dev, "unable to request IRQ, alarm not functional\n");
>> }
>>
>> ret = devm_rtc_register_device(pcf85363->rtc);
>> --
>> 2.17.1
>>
>>
--
Mike Looijmans
System Expert
TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands
T: +31 (0) 499 33 69 69
E: mike.looijmans@topic.nl
W: www.topic.nl
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rtc: pcf85363: Allow to wake up system without IRQ
2023-08-17 5:42 ` Mike Looijmans
@ 2023-08-17 8:17 ` Alexandre Belloni
2023-08-17 9:02 ` Mike Looijmans
0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Belloni @ 2023-08-17 8:17 UTC (permalink / raw)
To: Mike Looijmans; +Cc: linux-rtc, Alessandro Zummo, linux-kernel
On 17/08/2023 07:42:25+0200, Mike Looijmans wrote:
> On 16-08-2023 23:40, Alexandre Belloni wrote:
> > Hello Mike,
> >
> > Sorry for the very late review, there is a small change that is needed:
>
> Better late than never
>
> >
> > On 02/05/2023 07:54:58+0200, Mike Looijmans wrote:
> > > When wakeup-source is set in the devicetree, set up the device for
> > > using the output as interrupt instead of clock. This is similar to
> > > how other RTC devices handle this.
> > >
> > > This allows the clock chip to turn on the board when wired to do
> > > so in hardware.
> > >
> > > Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
> > >
> > > ---
> > >
> > > drivers/rtc/rtc-pcf85363.c | 17 ++++++++++-------
> > > 1 file changed, 10 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c
> > > index 8958eadf1c3e..b1543bcdc530 100644
> > > --- a/drivers/rtc/rtc-pcf85363.c
> > > +++ b/drivers/rtc/rtc-pcf85363.c
> > > @@ -434,23 +434,26 @@ static int pcf85363_probe(struct i2c_client *client)
> > > pcf85363->rtc->range_max = RTC_TIMESTAMP_END_2099;
> > > clear_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
> > > + if (client->irq > 0 || device_property_read_bool(&client->dev,
> > > + "wakeup-source")) {
> > > + regmap_write(pcf85363->regmap, CTRL_FLAGS, 0);
> > > + regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO,
> > > + PIN_IO_INTA_OUT, PIN_IO_INTAPM);
> > > + device_init_wakeup(&client->dev, true);
> > > + set_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
> >
> > This should not be done when devm_request_threaded_irq fails.
>
> Yeah, easiest would be to just clear the feature flag when that happens.
My comment was also for device_init_wakeup(&client->dev, true);. I think
the easiest would be to move this block later on and set client->irq to
0 when devm_request_threaded_irq fails.
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rtc: pcf85363: Allow to wake up system without IRQ
2023-08-17 8:17 ` Alexandre Belloni
@ 2023-08-17 9:02 ` Mike Looijmans
2023-08-17 22:25 ` Alexandre Belloni
0 siblings, 1 reply; 6+ messages in thread
From: Mike Looijmans @ 2023-08-17 9:02 UTC (permalink / raw)
To: Alexandre Belloni; +Cc: linux-rtc, Alessandro Zummo, linux-kernel
Met vriendelijke groet / kind regards,
Mike Looijmans
System Expert
TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands
T: +31 (0) 499 33 69 69
E: mike.looijmans@topic.nl
W: www.topic.nl
Please consider the environment before printing this e-mail
On 17-08-2023 10:17, Alexandre Belloni wrote:
> On 17/08/2023 07:42:25+0200, Mike Looijmans wrote:
>> On 16-08-2023 23:40, Alexandre Belloni wrote:
>>> Hello Mike,
>>>
>>> Sorry for the very late review, there is a small change that is needed:
>>
>> Better late than never
>>
>>>
>>> On 02/05/2023 07:54:58+0200, Mike Looijmans wrote:
>>>> When wakeup-source is set in the devicetree, set up the device for
>>>> using the output as interrupt instead of clock. This is similar to
>>>> how other RTC devices handle this.
>>>>
>>>> This allows the clock chip to turn on the board when wired to do
>>>> so in hardware.
>>>>
>>>> Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
>>>>
>>>> ---
>>>>
>>>> drivers/rtc/rtc-pcf85363.c | 17 ++++++++++-------
>>>> 1 file changed, 10 insertions(+), 7 deletions(-)
>>>>
>>>> diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c
>>>> index 8958eadf1c3e..b1543bcdc530 100644
>>>> --- a/drivers/rtc/rtc-pcf85363.c
>>>> +++ b/drivers/rtc/rtc-pcf85363.c
>>>> @@ -434,23 +434,26 @@ static int pcf85363_probe(struct i2c_client *client)
>>>> pcf85363->rtc->range_max = RTC_TIMESTAMP_END_2099;
>>>> clear_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
>>>> + if (client->irq > 0 || device_property_read_bool(&client->dev,
>>>> + "wakeup-source")) {
>>>> + regmap_write(pcf85363->regmap, CTRL_FLAGS, 0);
>>>> + regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO,
>>>> + PIN_IO_INTA_OUT, PIN_IO_INTAPM);
>>>> + device_init_wakeup(&client->dev, true);
>>>> + set_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
>>>
>>> This should not be done when devm_request_threaded_irq fails.
>>
>> Yeah, easiest would be to just clear the feature flag when that happens.
>
> My comment was also for device_init_wakeup(&client->dev, true);. I think
> the easiest would be to move this block later on and set client->irq to
> 0 when devm_request_threaded_irq fails.
>
Ah, clear. That also properly handles things when IRQ fails but wakeup-source
was present. In table form:
IRQ wakeup-source Call "device_init_wakeup" etc.
N/A No No
N/A Yes Yes
OK No Yes
OK Yes Yes
FAIL No No
FAIL Yes Yes
We still have to program the registers before registering the IRQ I think.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rtc: pcf85363: Allow to wake up system without IRQ
2023-08-17 9:02 ` Mike Looijmans
@ 2023-08-17 22:25 ` Alexandre Belloni
0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2023-08-17 22:25 UTC (permalink / raw)
To: Mike Looijmans; +Cc: linux-rtc, Alessandro Zummo, linux-kernel
On 17/08/2023 11:02:43+0200, Mike Looijmans wrote:
> > My comment was also for device_init_wakeup(&client->dev, true);. I think
> > the easiest would be to move this block later on and set client->irq to
> > 0 when devm_request_threaded_irq fails.
> >
>
> Ah, clear. That also properly handles things when IRQ fails but
> wakeup-source was present. In table form:
>
> IRQ wakeup-source Call "device_init_wakeup" etc.
> N/A No No
> N/A Yes Yes
> OK No Yes
> OK Yes Yes
This case is forbidden, you must not have an interrupt property and
wakeup-source at the same time.
> FAIL No No
> FAIL Yes Yes
This is then also forbidden
>
> We still have to program the registers before registering the IRQ I think.
Yes, certainly.
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-08-17 22:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.eeedf5db-4013-4c3b-be1c-1121df58f897@emailsignatures365.codetwo.com>
2023-05-02 5:54 ` [PATCH] rtc: pcf85363: Allow to wake up system without IRQ Mike Looijmans
2023-08-16 21:40 ` Alexandre Belloni
2023-08-17 5:42 ` Mike Looijmans
2023-08-17 8:17 ` Alexandre Belloni
2023-08-17 9:02 ` Mike Looijmans
2023-08-17 22:25 ` 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).