RTC: add RTC class interface to m41t00 driver
Actually, it'd be worth trying drivers/rtc/rtc-ds1307.c ... the M41T00 is one of a family of mostly-compatible RTC chips, and the ds1307 driver should be pretty much the least-common-denominator there. They all use the same I2C address, and the same register layout for the calendar/time function.
I'd expect rtc-ds1307 to handle the m41t00 already, or with at most minor tweaks to recognize whatever's different. It should already be ignoring the bits in the clock/calendar registers that vary, as well as the SRAM and (for some other chips) the alarm. (Not that I2C has ways to tell us what IRQ the alarm would use, but that's a different tale!)
- Dave
Quoted 11 lines · David Brownell
Actually, it'd be worth trying
drivers/rtc/rtc-ds1307.c... the M41T00 is one of a family of mostly-compatible RTC chips, and the ds1307 driver should be pretty much the least-common-denominator there. They all use the same I2C address, and the same register layout for the calendar/time function.I'd expect rtc-ds1307 to handle the m41t00 already, or with at most minor tweaks to recognize whatever's different. It should already be ignoring the bits in the clock/calendar registers that vary, as well as the SRAM and (for some other chips) the alarm. (Not that I2C has ways to tell us what IRQ the alarm would use, but that's a different tale!)
Thanks for your suggestion. I have looked rtc-ds1307 too before I tried to modify m41t00 driver.
It seems some works are still needed to support M41Txx chips by the driver.
1. The driver contains ds_1340 (or st m41t00) definition, but it seems no way to select the ds_type.
2. As m41t00_chip_info_tbl[] in m41t00 driver shows, M41T81 and M41T85 have different register layout.
3. It lacks some features (ST bit, HT bit, SQW freq.) in m41t00 driver, though I personally does not need these features.
I choose changing m41t00 driver by (1) and (2).
If we really need a super generic driver, I suppose adding ds13xx support to new m41txx driver is less hard. I think having separate drivers are good enough for now.
---
Atsushi Nemoto
Hi Atsushi,
Hi David,
I've seen very late that the rtc-ds1307.c driver supports the quite simple m41t00 as well. As Mark's m41t00.c claimed to support even the m41t81 and the m41st85, I startet at this point.
First, I sent my approach to Mark (m41t00.c), Alessandro (rtc-subsytem) and Jean (i2c-subsystem) to discuss the strategy. And if I understood them right, they found the idea good, to move the i2c/chips/m41t00.h to an rtc/rtc-m41txx.c driver, as this should be the general place for such rtc-drivers.
As Atsushi has done almost the same work, I postet my version on friday to pretend the next person to do this job and to start the discussion, how to get to a suitable version for all - including Mark with his arch/ppc/platforms/katana.c boards.
I confirm, that the rtc-ds1307.c driver works with m41t00. But the m41t8x or m41st8x differs a lot from the m41t00 (HT bit, ST bit, SQW freq - like Atsushi wrote it already).
Quoted 3 lines · Atsushi Nemoto
2. As m41t00_chip_info_tbl[] in m41t00 driver shows, M41T81 and M41T85 have different register layout.
The register layout seems to depend on the watchdog and alarm functionality.
The features differs from chip to chip, that's why I intodruced a "features"-field in struct m41txx_chip_info.
Quoted 3 lines
3. It lacks some features (ST bit, HT bit, SQW freq.) in m41t00 driver, though I personally does not need these features.
You need at least to clear the Stop Bit (ST) and the Halt Update Bit (HT) unless your m41t8x will always report the time of the last power fail and not the current time.
For me there is still the open question, if the workqueue-part and the exported symbols (m41t00_get_rtc_time, ) should stay or not. I don't need it and Atsushi seems to share my opinion. But...?
On monday, I can continue work on it.
Alexander
Signature · 4 lines
Alexander Bigga Tel: +49 4873 90 10 866 mycable GmbH Fax: +49 4873 90 19 76 Boeker Stieg 43 D-24613 Aukrug eMail: [email protected]
Quoted 6 lines · Alexander Bigga
Hi Atsushi,
Hi David,I've seen very late that the
rtc-ds1307.cdriver supports the quite simple m41t00 as well. As Mark'sm41t00.cclaimed to support even the m41t81 and the m41st85, I startet at this point.
I touched on that in my reply to Atsushi ... basically, the approach used in rtc-ds1307 is "least common denominator", and sticking to the fully compatible register subset and generic I2C framework.
That helped avoid needing to work around the lack of driver model support in the I2C stack, at the (minor to me!) price of not handling features that would need platform_data hooks to support ... like <linux/clk.h> support for SQW, and RTC alarm irqs.
Quoted 5 lines
First, I sent my approach to Mark (
m41t00.c), Alessandro (rtc-subsytem) and Jean (i2c-subsystem) to discuss the strategy. And if I understood them right, they found the idea good, to move thei2c/chips/m41t00.hto anrtc/rtc-m41txx.cdriver, as this should be the general place for such rtc-drivers.
Agreed that RTC drivers should now use the (newish) RTC framework, and these should move out of the "misc i2c chips" area. Not all RTCs fit in the drivers/rtc area though ... an RTC can be a secondary function of a multipurpose chip. (I suspect the Kconfig for their RTC interfaces should probably live in drivers/rtc though...)
Quoted 2 lines
As Atsushi has done almost the same work, I postet my version on friday to pretend the next person to do this job and to start the discussion,
Discussion is now started. :)
Quoted 2 lines
how to get to a suitable version for all - including Mark with his
arch/ppc/platforms/katana.cboards.
I suspect not all that board support is upstream yet; I can't see anything creating the m41t00 platform devices as required by the current m41t00.c driver ... neither on katana, nor any other board.
So it looks to me like RTC class support is not the only issue!
Plus, Mr. Grep tells me there's a separate m41t81 driver in mips/sibyte/swarm/rtc_m41t81.c ...
Quoted 1 line
I confirm, that the
rtc-ds1307.cdriver works with m41t00.
Good to know that ... I tried to be careful, but I didn't have a board with one of those to test with, just docs. Thanks! At some point we may decide it's safe to remove i2c/chips/ds1337.c, but I'd want similar confirmation for the ds1337 chip.
Quoted 8 lines
Quoted 2 lines · Atsushi Nemoto
2. As m41t00_chip_info_tbl[] in m41t00 driver shows, M41T81 and M41T85 have different register layout.
The register layout seems to depend on the watchdog and alarm functionality.
The features differs from chip to chip, that's why I intodruced a "features"-field in structm41txx_chip_info.
I'm not sure that'd be sufficient; if you look at the various RTCs, you'll notice that the control bits are in wildly different places.
You may end up doing more "switch (chip_type) {...}" than testing of the feature bits, if you get beyond those three chips.
Quoted 7 lines
Quoted 3 lines
3. It lacks some features (ST bit, HT bit, SQW freq.) in m41t00 driver, though I personally does not need these features.
You need at least to clear the Stop Bit (ST) and the Halt Update Bit (HT) unless your m41t8x will always report the time of the last power fail and not the current time.
Yes, but the m41t8x chips aren't register-compatible with those other RTCs, so I would not expect them to work the same. :)
Quoted 3 lines
For me there is still the open question, if the workqueue-part and the exported symbols (
m41t00_get_rtc_time, ) should stay or not. I don't need it and Atsushi seems to share my opinion. But...?
None of the other RTC drivers export private APIs or require a workqueue, so you won't need them on an m41t8x driver either.
I noticed that the katana board uses a different scheme for the "initialize the system time/date" problem addressed by CONFIG_RTC_HCTOSYS, and that seems to be the reason for the m41t00.c driver to export an API. (Much the same way that the PC-style "cmos clock" exports an API used early in x86 booting, which likewise bypasses the RTC framework ...)
I suspect there are arch-specific issues to work through there, both for initializing the clock at boot and for re-initializing it after resume. (CONFIG_RTC_HCTOSYS doesn't currently address the latter...)
- Dave
Quoted 1 line · you
Discussion is now started. :)
Hope to hear more arguments ;-)
Quoted 3 lines
I suspect not all that board support is upstream yet; I can't see anything creating the m41t00 platform devices as required by the current
m41t00.cdriver ... neither on katana, nor any other board.
Your're right. First, I was confused too, but then Mark pointed me to a patch, which is never gone into mainline:
http://lists.lm-sensors.org/pipermail/lm-sensors/2005-December/014727.html
Be aware of the different names: m41t00 and m41txx!
Quoted 2 lines
Plus, Mr. Grep tells me there's a separate m41t81 driver in
mips/sibyte/swarm/rtc_m41t81.c...
Oh, yes. I found it too, but didn't checked it further.
Quoted 2 lines
You may end up doing more "switch (
chip_type) {...}" than testing of the feature bits, if you get beyond those three chips.
In deed. If I want to support all.
Quoted 9 lines
I noticed that the katana board uses a different scheme for the "initialize the system time/date" problem addressed by
CONFIG_RTC_HCTOSYS, and that seems to be the reason for them41t00.cdriver to export an API. (Much the same way that the PC-style "cmos clock" exports an API used early in x86 booting, which likewise bypasses the RTC framework ...)I suspect there are arch-specific issues to work through there, both for initializing the clock at boot and for re-initializing it after resume. (
CONFIG_RTC_HCTOSYSdoesn't currently address the latter...)
This question, only Mark can unswer, or?
Alexander
Signature · 4 lines
Alexander Bigga Tel: +49 4873 90 10 866 mycable GmbH Fax: +49 4873 901 976 Boeker Stieg 43 D-24613 Aukrug eMail: [email protected]
Quoted 10 lines · Atsushi Nemoto
Quoted 6 lines · David Brownell
Actually, it'd be worth trying
drivers/rtc/rtc-ds1307.c... the M41T00 is one of a family of mostly-compatible RTC chips, and the ds1307 driver should be pretty much the least-common-denominator there. They all use the same I2C address, and the same register layout for the calendar/time function.
...Thanks for your suggestion. I have looked rtc-ds1307 too before I tried to modify m41t00 driver.
I couldn't tell that from any email I've seen, but it's good to know.
Quoted 2 lines
1. The driver contains
ds_1340(or st m41t00) definition, but it seems no way to select theds_type.
Which is harmless, since the driver has no code that really needs to care. As I said, it's a least-common-denominator driver ... used in my case with a SOC that integrates a highly functional (primary) RTC, because only the external RTC provides its own battery-backed power domain.
This is a limitation of the I2C stack ... one that I observe is being worked around by m41t00.c platform_device tricks. A side effect of those tricks is to prevent hooking up more than one of this type I2C chip to a system ... not pretty (especially given that it's not documented), but often OK.
Quoted 2 lines
2. As m41t00_chip_info_tbl[] in m41t00 driver shows, M41T81 and M41T85 have different register layout.
Right, suggesting the m41t00.c driver is more misnamed than rtc-ds1307.c because it doesn't even insist on software-compatible chips! And I'll note that its Kconfig doesn't mention that support either ...
It would have made more sense to me to have the M41T81 and M41T85 be in a different driver, because of the incompatible register layout. That's the more traditional approach.
Quoted 2 lines
3. It lacks some features (ST bit, HT bit, SQW freq.) in m41t00 driver, though I personally does not need these features.
Right: "least-common-denominator". Most of those chips can do square wave output (SQW), which should arguably be exposed as a <linux/clk.h> signal like other such signals.
Plus, handling square wave output would in general need board-specific configuration (also not directly supported by I2C), since the SQW pin often doubles as an alarm interrupt output ... I'd rather have an alarm! The ds1337 has two alarm pins, ds1339 muxes two alarms to one pin.
The ds1307 chip has NVRAM too, also not exposed ... even though that's the natural place to store manufacturing info like ethernet ids.
And there are many other chip differences that software might care about.
Quoted 5 lines
I choose changing m41t00 driver by (1) and (2).
If we really need a super generic driver, I suppose adding ds13xx support to new m41txx driver is less hard. I think having separate drivers are good enough for now.
My approach was to go for "least common denominator", not "super generic". Also, I avoided trying to work around I2C stack issues like the omission of per-board tables/customization. When I2C eventually has a nice clean solution for those issues, I expect that will mean adopting the better solution involves fewer changes.
But I was mostly pointing out that if the goal was to support the m41t00 RTC (the normal reading of $SUBJECT), that work has been done for some time and has already been pushed upstream.
- Dave
Quoted 7 lines · David Brownell
Quoted 2 lines
1. The driver contains
ds_1340(or st m41t00) definition, but it seems no way to select theds_type.Which is harmless, since the driver has no code that really needs to care. As I said, it's a least-common-denominator driver ... used in my case with a SOC that integrates a highly functional (primary) RTC, because only the external RTC provides its own battery-backed power domain.
Oh, I missed that point. It should work for m41t00 indeed.
Quoted 5 lines
This is a limitation of the I2C stack ... one that I observe is being worked around by
m41t00.cplatform_devicetricks. A side effect of those tricks is to prevent hooking up more than one of this type I2C chip to a system ... not pretty (especially given that it's not documented), but often OK.
Yes, some more works would be needed on m41t00 to support multiple (different) M41Txx chips at same time.
Quoted 3 lines
It would have made more sense to me to have the M41T81 and M41T85 be in a different driver, because of the incompatible register layout. That's the more traditional approach.
Now I'm thinking this way. Still thinking...
Quoted 5 lines
My approach was to go for "least common denominator", not "super generic". Also, I avoided trying to work around I2C stack issues like the omission of per-board tables/customization. When I2C eventually has a nice clean solution for those issues, I expect that will mean adopting the better solution involves fewer changes.
OK, I see. I think LCD approach is worth indeed.
Quoted 3 lines
But I was mostly pointing out that if the goal was to support the m41t00 RTC (the normal reading of $SUBJECT), that work has been done for some time and has already been pushed upstream.
My real target is M41T80, which seems a subset of M41T81. (Sorry for not writing this before.)
I agree m41t00 can be supported by rtc-ds1307 driver already.
So the next theme would be how we support M41T8x chips. I think Alexander's rtc-m41txx is good candidate for them.
Then M41T00 users can choose rtc-ds1307 or rtc-m41t00. Not so bad, I think.
---
Atsushi Nemoto
Quoted 5 lines · Atsushi Nemoto
Quoted 3 lines
It would have made more sense to me to have the M41T81 and M41T85 be in a different driver, because of the incompatible register layout. That's the more traditional approach.
Now I'm thinking this way. Still thinking...
Yes, but on the other side: except of this single shift in the registers, it works in the m41txx (or what the name will be) and won't do any extra work to the driver.
Even the m41t80 and m41t81 differs in their features. So you always have to distinguish inside the driver.
Quoted 2 lines
My real target is M41T80, which seems a subset of M41T81. (Sorry for not writing this before.)
My target is a M41ST85.
Quoted 2 lines
So the next theme would be how we support M41T8x chips. I think Alexander's rtc-m41txx is good candidate for them.
There are also M41st9x chips and M41t6x chips and a M41t11... But ok, most difference is watchdog/alarm or not.
Quoted 2 lines
Then M41T00 users can choose rtc-ds1307 or rtc-m41t00. Not so bad, I think.
As long, as the user will be pointed out this possibilties in the Kconfig - I agree.
Alexander
Signature · 4 lines
Alexander Bigga Tel: +49 4873 90 10 866 mycable GmbH Fax: +49 4873 901 976 Boeker Stieg 43 D-24613 Aukrug eMail: [email protected]