Add Maxim 77802 RTC support
Subsystems (3)
v9 cover Add Maxim 77802 RTC support
Hello Andrew,
I posted this series many times in the last few months, it was first meant to be for 3.17 but never got feedback from the maintainer (still on cc) so I reposted about a month ago [0] for 3.18 but didn't get feedback either. Other people have shown interest in the series though so Reviewed-by tags were collected for most patches.
I noticed that you are picking other RTC drivers on your -mm tree [1] so I wondered if you can pick this one too.
This series add support for the Real Time clock present in the Maxim 77802 Power Managment IC. Previously, the series was part of a bigger one [2] that aimed to add support for all the devices in the max77802 PMIC. But now the max77802 dependencies were already merged for 3.17 so the series can be split and each driver can go through the relevant tree.
While working on the max77802 rtc support a lot of feedback was given and the issues pointed out also apply to a driver for a similar PMIC RTC (max77686). So patches 01/05 to 04/05 in the series are cleanups for the max77686 driver and patch 05/05 adds the support for the max77802 RTC.
I kept the version numbering from the old series so this is version 9 although there were no changes on the max77802 rtc driver since v6 of the old series, only patches 03 and 04 were added on this version which are cleanups for the max77686 rtc.
The series were tested on an Exynos5250 Snow (max77686) and Exynos5420 Peach Pit (max77802) machines and applies cleanly to both 3.17-rc1 and today's linux-next (20140818).
Doug Anderson (1):
rtc: max77686: Allow the max77686 rtc to wakeup the system
Javier Martinez Canillas (4):
rtc: max77686: Remove dead code for SMPL and WTSR.
rtc: max77686: Fail to probe if no RTC regmap irqchip is set
rtc: max77686: Remove unneded info log
rtc: Add driver for Maxim 77802 PMIC Real-Time-Clock
drivers/rtc/Kconfig | 10 + drivers/rtc/Makefile | 1 + drivers/rtc/rtc-max77686.c | 127 +++-------- drivers/rtc/rtc-max77802.c | 513 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 553 insertions(+), 98 deletions(-) create mode 100644 drivers/rtc/rtc-max77802.c
Best regards,
Javier
[0]: https://lkml.org/lkml/2014/8/18/85
[1]: http://ozlabs.org/~akpm/mmots/series
[2]: http://lwn.net/Articles/605350/
PATCH RESEND v9 1/5 rtc: max77686: Allow the max77686 rtc to wakeup the system
From: Doug Anderson <[email protected]>
The max77686 includes an RTC that keeps power during suspend. It's convenient to be able to use it as a wakeup source.
NOTE: due to wakeup ordering problems this patch alone doesn't work so well on exynos5250-snow. You also need something that brings the i2c bus up before the max77686 wakeup runs.
---
Changes since v6: None
Changes since v5:
- Fix $SUBJECT since the patch does not actually touch the mfd subsys. Suggested by Lee Jones.
Changes since v4: None
Changes since v3:
- Keep the note that this patch needs another change due wakeup ordering problems.
--- drivers/rtc/rtc-max77686.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/rtc/rtc-max77686.c +28 -0
@@ -583,6 +583,33 @@ static void max77686_rtc_shutdown(struct platform_device *pdev)#endif /* MAX77686_RTC_WTSR_SMPL */ } +#ifdef CONFIG_PM_SLEEP +static int max77686_rtc_suspend (struct device *dev) +{ +if (device_may_wakeup (dev)) { +struct max77686_rtc_info *info =dev_get_drvdata (dev); + +return enable_irq_wake (info->virq); + } + +return 0 ; +} + +static int max77686_rtc_resume (struct device *dev) +{ +if (device_may_wakeup (dev)) { +struct max77686_rtc_info *info =dev_get_drvdata (dev); + +return disable_irq_wake (info->virq); + } + +return 0 ; +} +#endif + +static SIMPLE_DEV_PM_OPS(max77686_rtc_pm_ops, + max77686_rtc_suspend, max77686_rtc_resume); +static const struct platform_device_id rtc_id[] = { {"max77686-rtc" ,0 }, {},
@@ -592,6 +619,7 @@ static struct platform_driver max77686_rtc_driver = { .driver = { .name = "max77686-rtc", .owner = THIS_MODULE, + .pm = &max77686_rtc_pm_ops, }, .probe = max77686_rtc_probe, .shutdown = max77686_rtc_shutdown,
Signature · 1 line
2.0.0.rc2
Re: [PATCH RESEND v9 1/5] rtc: max77686: Allow the max77686 rtc to wakeup the system
Hi,
Quoted 8 lines · Javier Martinez Canillas
From: Doug Anderson <[email protected]>
The max77686 includes an RTC that keeps power during suspend. It's convenient to be able to use it as a wakeup source.
NOTE: due to wakeup ordering problems this patch alone doesn't work so well on exynos5250-snow. You also need something that brings the i2c bus up before the max77686 wakeup runs.
This note made sense when the patch was first submitted, but no longer does since the i2c change landed. See:
b19c195 i2c: s3c2410: resume the I2C controller earlier
Re: [PATCH RESEND v9 1/5] rtc: max77686: Allow the max77686 rtc to wakeup the system
Hello Doug,
Quoted 9 lines · Doug Anderson
Hi,
Quoted 5 lines · Javier Martinez Canillas
From: Doug Anderson <[email protected]>
The max77686 includes an RTC that keeps power during suspend. It's convenient to be able to use it as a wakeup source.
Quoted 9 lines
Quoted 3 lines
NOTE: due to wakeup ordering problems this patch alone doesn't work so well on exynos5250-snow. You also need something that brings the i2c bus up before the max77686 wakeup runs.
This note made sense when the patch was first submitted, but no longer does since the i2c change landed. See:
b19c195 i2c: s3c2410: resume the I2C controller earlier
You are right, I completely forgot to check if that actually landed and to remove the note in that case...
Maybe when the set is applied the note can be removed from this patch or do you think that I should re-spin the series for that?
Best regards,
Javier
Re: [PATCH RESEND v9 1/5] rtc: max77686: Allow the max77686 rtc to wakeup the system
Hi,
Quoted 5 lines · Javier Martinez Canillas
You are right, I completely forgot to check if that actually landed and to remove the note in that case...
Maybe when the set is applied the note can be removed from this patch or do you think that I should re-spin the series for that?
This seems like something a maintainer could handle removing, but I guess it's totally up to the maintainer. If I were the maintainer I'd rather remove the note myself then see a whole spin of a 5-part series just to fix this. ;)
-Doug
Re: [PATCH RESEND v9 1/5] rtc: max77686: Allow the max77686 rtc to wakeup the system
In reply to Javier Martinez CanillasQuoted 8 lines · On Fri, 12 Sep 2014 10:17:39 +0200 Javier Martinez Canillas…
From: Doug Anderson <[email protected]>
The max77686 includes an RTC that keeps power during suspend. It's convenient to be able to use it as a wakeup source.
NOTE: due to wakeup ordering problems this patch alone doesn't work so well on exynos5250-snow. You also need something that brings the i2c bus up before the max77686 wakeup runs.
I removed this paragraph.
Quoted 2 lines
Signed-off-by Doug Anderson <[email protected]>Reviewed-by Javier Martinez Canillas <[email protected]>
And I rewrote this to Signed-off-by:, as you were on the patch delivery path. Documentation/SubmittingPatches section 12 has the gory details.
Re: [PATCH RESEND v9 1/5] rtc: max77686: Allow the max77686 rtc to wakeup the system
Hello Andrew,
Thanks a lot for taking a look to these patches!
Quoted 4 lines · Andrew Morton
Quoted 2 lines · On Fri, 12 Sep 2014 10:17:39 +0200 Javier Martinez Canillas…
From: Doug Anderson <[email protected]>
Quoted 9 lines
Quoted 6 lines
The max77686 includes an RTC that keeps power during suspend. It's convenient to be able to use it as a wakeup source.
NOTE: due to wakeup ordering problems this patch alone doesn't work so well on exynos5250-snow. You also need something that brings the i2c bus up before the max77686 wakeup runs.
I removed this paragraph.
Great.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Doug Anderson <[email protected]>Reviewed-by Javier Martinez Canillas <[email protected]>And I rewrote this to Signed-off-by:, as you were on the patch delivery path.
Documentation/SubmittingPatchessection 12 has the gory details.
Yes, originally Doug posted this patch separately but was never picked so I included on my series but forgot to add my s-o-b and also to remove the note paragraph.
Best regards,
Javier
PATCH RESEND v9 2/5 rtc: max77686: Remove dead code for SMPL and WTSR.
In reply to Javier Martinez CanillasThe MAX77686 RTC chip has two features called SMPL (Sudden Momentary Power Loss) and WTSR (Watchdog Timeout and Software Resets). Support for these features seems to be implemented in the driver but compilation is disabled using a C pre-processor conditional.
This code has been disabled since the driver was original merged in commit fca1dd03 ("rtc: max77686: add Maxim 77686 driver").
So, since this code has never been built, let's just remove it.
--- drivers/rtc/rtc-max77686.c | 101 --------------------------------------------- 1 file changed, 101 deletions(-)
drivers/rtc/rtc-max77686.c +0 -101
@@ -32,15 +32,6 @@#define RTC_UDR_MASK (1 << RTC_UDR_SHIFT)#define RTC_RBUDR_SHIFT 4#define RTC_RBUDR_MASK (1 << RTC_RBUDR_SHIFT) -/* WTSR and SMPL Register */ -#define WTSRT_SHIFT 0 -#define SMPLT_SHIFT 2 -#define WTSR_EN_SHIFT 6 -#define SMPL_EN_SHIFT 7 -#define WTSRT_MASK (3 << WTSRT_SHIFT) -#define SMPLT_MASK (3 << SMPLT_SHIFT) -#define WTSR_EN_MASK (1 << WTSR_EN_SHIFT) -#define SMPL_EN_MASK (1 << SMPL_EN_SHIFT)/* RTC Hour register */ #define HOUR_PM_SHIFT 6#define HOUR_PM_MASK (1 << HOUR_PM_SHIFT)
@@ -49,7 +40,6 @@#define ALARM_ENABLE_MASK (1 << ALARM_ENABLE_SHIFT)#define MAX77686_RTC_UPDATE_DELAY 16 -#undef MAX77686_RTC_WTSR_SMPLenum {RTC_SEC =0 ,
@@ -412,64 +402,6 @@ static const struct rtc_class_ops max77686_rtc_ops = { .alarm_irq_enable = max77686_rtc_alarm_irq_enable, }; -#ifdef MAX77686_RTC_WTSR_SMPL -static void max77686_rtc_enable_wtsr (struct max77686_rtc_info *info,bool enable) -{ -int ret; -unsigned int val, mask; - -if (enable) - val = (1 <<WTSR_EN_SHIFT ) | (3 <<WTSRT_SHIFT ); -else - val =0 ; - - mask =WTSR_EN_MASK |WTSRT_MASK ; - -dev_info (info->dev,"%s: %s WTSR\n" , __func__, - enable ?"enable" :"disable" ); - - ret =regmap_update_bits (info->max77686->rtc_regmap, -MAX77686_WTSR_SMPL_CNTL , mask, val); -if (ret <0 ) { -dev_err (info->dev,"%s: fail to update WTSR reg(%d)\n" , - __func__, ret); -return ; - } - -max77686_rtc_update (info,MAX77686_RTC_WRITE ); -} - -static void max77686_rtc_enable_smpl (struct max77686_rtc_info *info,bool enable) -{ -int ret; -unsigned int val, mask; - -if (enable) - val = (1 <<SMPL_EN_SHIFT ) | (0 <<SMPLT_SHIFT ); -else - val =0 ; - - mask =SMPL_EN_MASK |SMPLT_MASK ; - -dev_info (info->dev,"%s: %s SMPL\n" , __func__, - enable ?"enable" :"disable" ); - - ret =regmap_update_bits (info->max77686->rtc_regmap, -MAX77686_WTSR_SMPL_CNTL , mask, val); -if (ret <0 ) { -dev_err (info->dev,"%s: fail to update SMPL reg(%d)\n" , - __func__, ret); -return ; - } - -max77686_rtc_update (info,MAX77686_RTC_WRITE ); - - val =0 ; -regmap_read (info->max77686->rtc_regmap,MAX77686_WTSR_SMPL_CNTL , &val); -dev_info (info->dev,"%s: WTSR_SMPL(0x%02x)\n" , __func__, val); -} -#endif /* MAX77686_RTC_WTSR_SMPL */ -static int max77686_rtc_init_reg (struct max77686_rtc_info *info) {u8 data[2 ];
@@ -519,11 +451,6 @@ static int max77686_rtc_probe(struct platform_device *pdev) goto err_rtc; } -#ifdef MAX77686_RTC_WTSR_SMPL -max77686_rtc_enable_wtsr (info, true); -max77686_rtc_enable_smpl (info, true); -#endif -device_init_wakeup (&pdev->dev,1 ); info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max77686-rtc",
@@ -556,33 +483,6 @@ err_rtc:return ret; } -static void max77686_rtc_shutdown (struct platform_device *pdev) -{ -#ifdef MAX77686_RTC_WTSR_SMPL -struct max77686_rtc_info *info =platform_get_drvdata (pdev); -int i; -u8 val =0 ; - -for (i =0 ; i <3 ; i++) { -max77686_rtc_enable_wtsr (info, false); -regmap_read (info->max77686->rtc_regmap,MAX77686_WTSR_SMPL_CNTL , &val); -dev_info (info->dev,"%s: WTSR_SMPL reg(0x%02x)\n" , __func__, - val); -if (val &WTSR_EN_MASK ) { -dev_emerg (info->dev,"%s: fail to disable WTSR\n" , - __func__); - }else { -dev_info (info->dev,"%s: success to disable WTSR\n" , - __func__); -break ; - } - } - -/* Disable SMPL when power off */ -max77686_rtc_enable_smpl (info, false); -#endif /* MAX77686_RTC_WTSR_SMPL */ -} -#ifdef CONFIG_PM_SLEEP static int max77686_rtc_suspend (struct device *dev) {
@@ -622,7 +522,6 @@ static struct platform_driver max77686_rtc_driver = { .pm = &max77686_rtc_pm_ops, }, .probe = max77686_rtc_probe, - .shutdown = max77686_rtc_shutdown, .id_table = rtc_id, };
Signature · 1 line
2.0.0.rc2
PATCH RESEND v9 3/5 rtc: max77686: Fail to probe if no RTC regmap irqchip is set
In reply to Javier Martinez CanillasThe max77686 mfd driver adds a regmap IRQ chip which creates an IRQ domain that is used to map the virtual RTC alarm1 interrupt.
The RTC driver assumes that this will always be true since the PMIC IRQ is a required property according to the max77686 DT binding doc. If an "interrupts" property is not defined for a max77686 PMIC, then the mfd probe function will fail and the RTC platform driver will never be probed. But even when it is not possible to probe the rtc-max77686 driver without a regmap IRQ chip, it's better to explicitly check if the IRQ chip data is not NULL and gracefully fail instead of getting an OOPS.
---
Fixes the issue reported by Krzystof in: https://lkml.org/lkml/2014/8/8/121
--- drivers/rtc/rtc-max77686.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/rtc/rtc-max77686.c +6 -0
@@ -466,6 +466,12 @@ static int max77686_rtc_probe(struct platform_device *pdev) goto err_rtc; } +if (!max77686->rtc_irq_data) { + ret = -EINVAL ; +dev_err (&pdev->dev,"%s: no RTC regmap IRQ chip\n" , __func__); + goto err_rtc; + } + info->virq =regmap_irq_get_virq (max77686->rtc_irq_data,MAX77686_RTCIRQ_RTCA1 );if (!info->virq) {
Signature · 1 line
2.0.0.rc2
PATCH RESEND v9 4/5 rtc: max77686: Remove unneded info log
In reply to Javier Martinez CanillasIf devm_rtc_device_register() fails a dev_err() is already reported so there is no need to do an additional dev_info().
--- drivers/rtc/rtc-max77686.c | 2 -- 1 file changed, 2 deletions(-)
drivers/rtc/rtc-max77686.c +0 -2
@@ -457,8 +457,6 @@ static int max77686_rtc_probe(struct platform_device *pdev) &max77686_rtc_ops, THIS_MODULE);if (IS_ERR (info->rtc_dev)) { -dev_info (&pdev->dev,"%s: fail\n" , __func__); - ret =PTR_ERR (info->rtc_dev);dev_err (&pdev->dev,"Failed to register RTC device: %d\n" , ret);if (ret ==0 )
Signature · 1 line
2.0.0.rc2
PATCH RESEND v9 5/5 rtc: Add driver for Maxim 77802 PMIC Real-Time-Clock
In reply to Javier Martinez CanillasThe MAX7802 PMIC has a Real-Time-Clock (RTC) with two alarms. This patch adds support for the RTC and is based on a driver added by Simon Glass to the Chrome OS kernel 3.8 tree.
---
Changes since v6:
- Remove unused code for SMPL and WTSR. Suggested by Krzysztof Kozlowski.
- Don't spam the kernel log with unnecessarily info and just print for debug. Suggested by Krzysztof Kozlowski.
- Use ARRAY_SIZE() instead of constant value. Suggested by Krzysztof Kozlowski.
- Remove duplicated register setup. Suggested by Krzysztof Kozlowski.
- Don't free/unregister managed allocated resources.
Suggested by Krzysztof Kozlowski.
--- drivers/rtc/Kconfig | 10 + drivers/rtc/Makefile | 1 + drivers/rtc/rtc-max77802.c | 513 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 524 insertions(+) create mode 100644 drivers/rtc/rtc-max77802.c
drivers/rtc/Kconfig +10 -0
@@ -288,6 +288,16 @@ config RTC_DRV_MAX77686 This driver can also be built as a module. If so, the module will be called rtc-max77686. +config RTC_DRV_MAX77802 + tristate "Maxim 77802 RTC" + depends on MFD_MAX77686 + help + If you say yes here you will get support for the + RTC of Maxim MAX77802 PMIC. + + This driver can also be built as a module. If so, the module + will be called rtc-max77802. + config RTC_DRV_RS5C372 tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A" help
drivers/rtc/Makefile +1 -0
@@ -85,6 +85,7 @@ obj-$(CONFIG_RTC_DRV_MAX8998) += rtc-max8998.o obj-$(CONFIG_RTC_DRV_MAX8997) += rtc-max8997.o obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o obj-$(CONFIG_RTC_DRV_MAX77686) += rtc-max77686.o +obj-$(CONFIG_RTC_DRV_MAX77802) += rtc-max77802.o obj-$(CONFIG_RTC_DRV_MC13XXX) += rtc-mc13xxx.o obj-$(CONFIG_RTC_DRV_MCP795) += rtc-mcp795.o obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o
drivers/rtc/rtc-max77802.c new file +513 -0
513 lines not on this page · raw message
Signature · 1 line
2.0.0.rc2
Re: [PATCH RESEND v9 5/5] rtc: Add driver for Maxim 77802 PMIC Real-Time-Clock
Quoted 6 lines · On Fri, 12 Sep 2014 10:17:43 +0200 Javier Martinez Canillas…
The MAX7802 PMIC has a Real-Time-Clock (RTC) with two alarms. This patch adds support for the RTC and is based on a driver added by Simon Glass to the Chrome OS kernel 3.8 tree.
Signed-off-by Javier Martinez Canillas <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>
Would it be appropriate to gather Simon's signoff?
drivers/rtc/rtc-max77802.c line 85
Quoted 8 lines
drivers/rtc/rtc-max77802.c new file +8
-0+static inline int max77802_rtc_calculate_wday (u8 shifted) +{ +int counter =-1 ; + +while (shifted) { + shifted >>=1 ; + counter++; + }
Can't use log2() or similar?
Quoted 2 lines
(quoted diff) +2
-0+ return counter; +}
Re: [PATCH RESEND v9 5/5] rtc: Add driver for Maxim 77802 PMIC Real-Time-Clock
Hello Andrew,
Quoted 11 lines · Andrew Morton
Quoted 6 lines · On Fri, 12 Sep 2014 10:17:43 +0200 Javier Martinez Canillas…
The MAX7802 PMIC has a Real-Time-Clock (RTC) with two alarms. This patch adds support for the RTC and is based on a driver added by Simon Glass to the Chrome OS kernel 3.8 tree.
Signed-off-by Javier Martinez Canillas <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>Would it be appropriate to gather Simon's signoff?
I don't know. The original driver written by Simon supported 2 devices:
max77686 and max77802. I split the max77802 bits and addressed all the issues pointed out on early revisions so even when Simon is mentioned as the MODULE_AUTHOR(), I didn't know if he would like his s-o-b to remain in the patch since it was quite different than the original one from which was based.
Quoted 11 lines
drivers/rtc/rtc-max77802.c line 85
Quoted 8 lines
drivers/rtc/rtc-max77802.c new file +8
-0+static inline int max77802_rtc_calculate_wday (u8 shifted) +{ +int counter =-1 ; + +while (shifted) { + shifted >>=1 ; + counter++; + }Can't use
log2()or similar?
Yes, ffs() - 1 can be used instead of this function indeed.
I see that you already included this patch to your -mm tree [0]. Does it mean that I've to send a follow-up patch on top of this to remove this function or should I send a new version of this patch?
Best regards,
Javier
[0]:
http://ozlabs.org/~akpm/mmots/broken-out/rtc-add-driver-for-maxim-77802-pmic-real-time-clock.patch