I2C: add new rx8025 driver
PATCH 1/1 I2C: add new rx8025 driver
Hello,
below is a patch adding support for the Epson RX8025 SA/NB RTC module.
There are a few things I'm not sure about:
- There exists a RTC driver interface in include/asm-arm/rtc.h by Russell King. Should I use it even if it's ARM specific? For now I used the ioctl interface directly.
- Is it correct to name the config symbol SENSORS_RTCRX8025? I question because in my eyes an RTC is not a sensor. OTOH the driver for the 8564 chip (and serveral others) uses SENSORS_RTC8564.
I'd be happy to get some feedback.
Best regards
Uwe
--- >8 ---
Adds support for the Epson RX8025 SA/NB RTC module.
---
drivers/i2c/chips/Kconfig | 10 + drivers/i2c/chips/Makefile | 1 drivers/i2c/chips/rx8025.c | 585 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 596 insertions(+), 0 deletions(-) create mode 100644 drivers/i2c/chips/rx8025.c
8a23a3543a33d98c0ee7626f081e1c9538310afa
drivers/i2c/chips/Kconfig +10 -0
@@ -74,6 +74,16 @@ config SENSORS_RTC8564 This driver can also be built as a module. If so, the module will be called i2c-rtc8564. +config SENSORS_RTCRX8025 + tristate "Epson RX-8025 SA/NB RTC chip" + depends on I2C && EXPERIMENTAL + help + If you say yes here you get support for the + Epson RX-8025 SA/NB RTC chip. + + This driver can also be built as a module. If so, the module + will be called rx8025. + config ISP1301_OMAP tristate "Philips ISP1301 with OMAP OTG" depends on I2C && ARCH_OMAP_OTG
drivers/i2c/chips/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_SENSORS_PCA9539) += pca9539 obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o +obj-$(CONFIG_SENSORS_RTCRX8025) += rx8025.o obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o obj-$(CONFIG_TPS65010) += tps65010.o obj-$(CONFIG_RTC_X1205_I2C) += x1205.o
drivers/i2c/chips/rx8025.c new file +585 -0
585 lines not on this page · raw message
Signature · 8 lines
1.1.6.g8233 -- Uwe Zeisberger FS Forth-Systeme GmbH, A Digi International Company Kueferstrasse 8, D-79206 Breisach, Germany Phone: +49 (7667) 908 0 Fax: +49 (7667) 908 200 Web: www.fsforth.de, www.digi.com
PATCH 1/1 I2C: add new rx8025 driver
Hi Uwe,
Quoted 1 line
below is a patch adding support for the Epson RX8025 SA/NB RTC module.
First of all: where is this chip found? Have you verified if this chip isn't compatible with other chips we have drivers for already?
Quoted 3 lines
- There exists a RTC driver interface in
include/asm-arm/rtc.hby Russell King. Should I use it even if it's ARM specific? For now I used the ioctl interface directly.
See with Alessandro Zummo, he is working on a unified RTC core. Maybe you can simplify your code by using it.
Quoted 3 lines
- Is it correct to name the config symbol
SENSORS_RTCRX8025? I question because in my eyes an RTC is not a sensor. OTOH the driver for the 8564 chip (and serveral others) usesSENSORS_RTC8564.
No, please name it RTC_RX8025 instead. SENSORS_* names for non-sensors drivers is a legacy which we are trying to get rid of.
My comments on your code follow.
drivers/i2c/chips/rx8025.c line 41
Quoted 4 lines
drivers/i2c/chips/rx8025.c new file +4
-0+#define RX8025_REG_ALDHOUR 0x0c +/* 0x0e is reserved */ +#define RX8025_REG_CTRL1 0x0e +#define RX8025_REG_CTRL2 0x0f
Don't you mean 0x0d is reserved?
Quoted 1 line
+static struct
i2c_client*rx8025_rtcclient= NULL;
Don't initialize a static global to NULL explicitly, the compiler will do it for you.
drivers/i2c/chips/rx8025.c line 89
Quoted 3 lines
drivers/i2c/chips/rx8025.c new file +3
-0+static int rx8025_get_rtctime (struct rtc_time *dt) +{ +u8 command =RX8025_REG_CTRL1 <<4 |0x08 ;
I'd suggest parentheses for more clarity.
drivers/i2c/chips/rx8025.c line 90
Quoted 1 line
drivers/i2c/chips/rx8025.c new file +1
-0+u8 result[9 ] = {0 , };
Doesn't seem to actually require an initialization.
Review
Quoted 2 lines
(quoted diff) +2
-0+ if(down_interruptible(&rx8025_lock)) + return -ERESTARTSYS;
Coding style: space between "if" and opening parenthesis.
Also, what exactly are you protecting with this mutex?
drivers/i2c/chips/rx8025.c line 133
Quoted 5 lines
drivers/i2c/chips/rx8025.c new file +5
-0+dev_dbg (&rx8025_rtcclient->dev, +"rx8025_get_rtctime: read 0x%02x 0x%02x 0x%02x 0x%02x" +" 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n" , result[0 ], + result[1 ], result[2 ], result[3 ], result[4 ], result[5 ], + result[6 ], result[7 ], result[8 ]);
When splitting strings, please have the middle space at the end of the first half rather than the beginning of the second half. It makes it easier to spot missing spaces.
Quoted 4 lines
drivers/i2c/chips/rx8025.c new file +4
-0+/* according to the documention read-only-bits read as 0 */ +#define CHECK_ROBITS (reg, mask) \ + if (unlikely(result[2 + (reg)] & ~(mask))) { \ + dev_warn(&rx8025_rtcclient->dev, \
drivers/i2c/chips/rx8025.c line 148
Quoted 10 lines
drivers/i2c/chips/rx8025.c new file +10
-0+ "value for " #reg " out of spec: %x\n", \ + result[2 + (reg)]); \ + result[2 + RX8025_REG_SEC] &= (mask); \ + } +CHECK_ROBITS (RX8025_REG_SEC ,0x7f ); +CHECK_ROBITS (RX8025_REG_MIN ,0x7f ); +CHECK_ROBITS (RX8025_REG_HOUR ,0x3f ); +CHECK_ROBITS (RX8025_REG_WDAY ,0x07 ); +CHECK_ROBITS (RX8025_REG_MDAY ,0x3f ); +CHECK_ROBITS (RX8025_REG_MONTH ,0x1f );
Since you end up checking all unused bits regardless of what the datasheet says, it would be more efficient - and more readble - to just mask the values you read.
+ /* I don't have to do more checking, don't I? */
English: "don't I" should be "do I".
drivers/i2c/chips/rx8025.c line 192
Quoted 5 lines
drivers/i2c/chips/rx8025.c new file +4
-0+static int rx8025_set_rtctime (struct rtc_time *dt) +{ +if (down_interruptible (&rx8025_lock)) +return -ERESTARTSYS ;
Coding style.
drivers/i2c/chips/rx8025.c line 233
Quoted 4 lines
drivers/i2c/chips/rx8025.c new file +4
-0+if (dt->tm_wday <0 || dt->tm_wday >=7 ) { +dev_err (&rx8025_rtcclient->dev, +"rx8025_set_rtctime: hours out of range: %d\n" , + dt->tm_wday);
Typo: "hours" should be "week day".
drivers/i2c/chips/rx8025.c line 246
Quoted 1 line
drivers/i2c/chips/rx8025.c new file +1
-0+if (dt->tm_year <70 || dt->tm_mon >=170 ) {
Typo: "dt->tm_mon" should be "dt->tm_year".
Quoted 7 lines
drivers/i2c/chips/rx8025.c new file +7
-0+/* +* BUG: The HW assumes every year that is a multiple of 4 to be a leap +* year. Next time this is wrong is 2100, which will not be a leap +* year. +*/ + if (dt->tm_mday > 31 || + ((dt->tm_mon = 3 || dt->tm_mon = 5 ||
drivers/i2c/chips/rx8025.c line 270
Quoted 10 lines
drivers/i2c/chips/rx8025.c new file +10
-0+ dt->tm_mon = 8 || dt->tm_mon = 10) + && dt->tm_mday > 30) || + (dt->tm_mon = 1 && dt->tm_mday > 28 + + (dt->tm_year & 3 ? 0 : 1))) { +dev_err (&rx8025_rtcclient->dev, +"rx8025_set_rtctime: day out of range (with month=%d, " +"year=%d): %d\n" , dt->tm_mon, dt->tm_year, dt->tm_mon); + err = -EINVAL ; + goto errout_unlock; + }
Other RTC drivers typically use a 12-element array defining the number of day in each month. It's probably cleaner and more efficient. See i2c-x1205 for an example.
Also, last parameter of dev_err() should be dt->tm_mday, not dt->tm_mon.
drivers/i2c/chips/rx8025.c line 279
Quoted 8 lines
drivers/i2c/chips/rx8025.c new file +8
-0+if ((ctrl1 =i2c_smbus_read_byte_data (rx8025_rtcclient, +RX8025_REG_CTRL1 <<4 )) <0 ) { +dev_err (&rx8025_rtcclient->dev, +"rx8025_set_rtctime: failed to read out " +"RX8025_REG_CTRL1\n" ); + err = -EINVAL ; + goto errout_unlock; + }
-EINVAL doesn't seem to be appropriate. -EIO?
drivers/i2c/chips/rx8025.c line 311
Quoted 4 lines
drivers/i2c/chips/rx8025.c new file +4
-0+if ((err =i2c_transfer (rx8025_rtcclient->adapter, &msg,1 )) <1 ) { + err = err >=0 ? -EIO : err; + goto errout_unlock; + }
i2c_master_send is a convenient wrapper to i2c_transfer when sending a single message (but see right below.)
drivers/i2c/chips/rx8025.c line 331
Quoted 5 lines
drivers/i2c/chips/rx8025.c new file +5
-0+static int rx8025_detect (struct i2c_adapter *adapter,int address,int kind) +{ +int err =0 ; +struct rx8025_data *data; +struct i2c_client *new_client;
Use "client" instead of "new_client" please. Another legacy we try to get rid of.
drivers/i2c/chips/rx8025.c line 336
Quoted 4 lines
drivers/i2c/chips/rx8025.c new file +4
-0+if (!i2c_check_functionality (adapter,I2C_FUNC_I2C )) { +dev_dbg (&adapter->dev,"doesn't support full I2C\n" ); + goto errout; + }
Given that all block transfers you do are standard I2C block transfers, you may consider switching to i2c_smbus_{read,write}_i2c_block_data for SMBus compatibility. This would also make your code more simple, I think.
drivers/i2c/chips/rx8025.c line 349
Quoted 1 line
drivers/i2c/chips/rx8025.c new file +1
-0+ new_client->flags =0 ;
Not needed, as you've kzalloc'd the client structure.
drivers/i2c/chips/rx8025.c line 358
Quoted 3 lines
drivers/i2c/chips/rx8025.c new file +3
-0+if (kind <0 ) { +u8 command =RX8025_REG_SEC <<4 |0x08 ; +u8 result[8 ] = {0 , };
Initalization not needed AFAICS.
Quoted 7 lines
drivers/i2c/chips/rx8025.c new file +7
-0+/* bits 7 of RX8025_REG_MONTH and RX8025_REG_DIGOFF +* "should be set as "0". Their value when read will be "0"" +* +* There are serveral more read-only bits who's "value when +* read is always "0"" according to the spec, but setting them +* yields a "1" sometimes. +*/
drivers/i2c/chips/rx8025.c line 396
Quoted 10 lines
drivers/i2c/chips/rx8025.c new file +10
-0+if (((result[RX8025_REG_MONTH ] | result[RX8025_REG_DIGOFF ]) + &0x80 )) { +dev_dbg (&adapter->dev,"RX8025_REG_MONTH = %x, " +"RX8025_REG_DIGOFF = %x\n" , + result[RX8025_REG_MONTH ], + result[RX8025_REG_DIGOFF ]); + + + goto errout_free; + }
Detection is a bit poor. It could be made much more robust by checking the acual values of the registers. See i2c-x1205.
drivers/i2c/chips/rx8025.c line 423
Quoted 4 lines
drivers/i2c/chips/rx8025.c new file +4
-0+if ((err =misc_register (&rx8025_rtc_dev))) { + rx8025_rtcclient =NULL ; +printk (KERN_ERR "Failed to register rtc device\n" ); + }
Please use dev_err().
drivers/i2c/chips/rx8025.c line 428
Quoted 2 lines
drivers/i2c/chips/rx8025.c new file +2
-0+printk (KERN_INFO "loaded driver for RX-8025 SA/NB on addr %d\n" , + address);
Misleading message. What you did here is register the device with the driver. The driver could have been loaded without ever registering anything. Also, you should use dev_info.
drivers/i2c/chips/rx8025.c line 514
Quoted 9 lines
drivers/i2c/chips/rx8025.c new file +8
-0+static int rx8025_detach_client (struct i2c_client *client) +{ +if (rx8025_rtcclient = client) { +struct list_head *lh = rx8025_clients.next; + + + if (list_entry(lh, struct rx8025_data, list) = data) + lh = lh->next;
No double blank line please.
Additionally, some documentation file in Documentation/i2c/chips would be welcome. And feel free to add yourself in MAINTAINERS as the maintainer of this new driver if you want to take care of it in the future.
Signature · 1 line
Jean Delvare
PATCH 1/1 I2C: add new rx8025 driver
In reply to Uwe ZeisbergerHi Jean,
thanks for all your suggestions, I'll go through them. I agree to most of your suggestions. I don't comment on those and just prepare a new patch. Some of them are mortifying, sorry for them. (Actually I put in these to check how exact the reviews are. You passed ;-)
Quoted 3 lines · Jean Delvare
Quoted 1 line
below is a patch adding support for the Epson RX8025 SA/NB RTC module.
First of all: where is this chip found?
This is a driver I wrote for a custom SoC. Otherwise Google found one or two mails by people having ported the rtc8564 driver to the rx8025 chip.
Quoted 2 lines
Have you verified if this chip isn't compatible with other chips we have drivers for already?
I just compared with the rtc8564 driver as I didn't expect to match that chip. In retrospect this proofs true. (I compared with the kconfig symbols in drivers/i2c/chips that have [Rr][Tt][Cc] in their description. Did I miss anything?)
Quoted 6 lines
Quoted 3 lines
- There exists a RTC driver interface in
include/asm-arm/rtc.hby Russell King. Should I use it even if it's ARM specific? For now I used the ioctl interface directly.See with Alessandro Zummo, he is working on a unified RTC core. Maybe you can simplify your code by using it.
He answered my mail, too. I'll look into it.
Quoted 2 lines
Don't initialize a static global to NULL explicitly, the compiler will do it for you.
I'm not fluent in the different C variants, so I usually prefer to explicitly initialize static global variables with NULL, too.
Quoted 3 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if(down_interruptible(&rx8025_lock)) + return -ERESTARTSYS;[...], what exactly are you protecting with this mutex?
rx8025_clients and rx8025_rtcclient. Maybe I can get rid of it when using Alessandro's RTC core.
Quoted 10 lines
Quoted 10 lines
drivers/i2c/chips/rx8025.c new file +10
-0+/* according to the documention read-only-bits read as 0 */ +#define CHECK_ROBITS (reg, mask) \ + if (unlikely(result[2 + (reg)] & ~(mask))) { \ + dev_warn(&rx8025_rtcclient->dev, \ + "value for " #reg " out of spec: %x\n", \ + result[2 + (reg)]); \ + result[2 + RX8025_REG_SEC] &= (mask); \ + } +CHECK_ROBITS (RX8025_REG_SEC ,0x7f ); +CHECK_ROBITS (RX8025_REG_MIN ,0x7f );
Quoted 8 lines
drivers/i2c/chips/rx8025.c line 148
Quoted 4 lines
drivers/i2c/chips/rx8025.c new file +4
-0+CHECK_ROBITS (RX8025_REG_HOUR ,0x3f ); +CHECK_ROBITS (RX8025_REG_WDAY ,0x07 ); +CHECK_ROBITS (RX8025_REG_MDAY ,0x3f ); +CHECK_ROBITS (RX8025_REG_MONTH ,0x1f );Since you end up checking all unused bits regardless of what the datasheet says, it would be more efficient - and more readble - to just mask the values you read.
While developping I observed that having some of these bits set results in wrong transitions. So I want to warn about it. I put the masking in the if body to have CHECK_ROBITS expand to one statement (without doing do {...} while(0)). Maybe it's sensible to move that check to the detection phase as you suggested.
Quoted 2 lines
Use "client" instead of "
new_client" please. Another legacy we try to get rid of.
That was one that astonished me, too. I just did that to be consistent.
Quoted 9 lines
drivers/i2c/chips/rx8025.c line 336
Quoted 4 lines
drivers/i2c/chips/rx8025.c new file +4
-0+if (!i2c_check_functionality (adapter,I2C_FUNC_I2C )) { +dev_dbg (&adapter->dev,"doesn't support full I2C\n" ); + goto errout; + }Given that all block transfers you do are standard I2C block transfers, you may consider switching to i2c_smbus_{read,write}_i2c_block_data for SMBus compatibility. This would also make your code more simple, I think.
Well I just found out the SMBus interface may match my needs when I posted the driver. I'm not sure about the transfer in rx8025_get_rtctime. In the spec this is called "Simplified read method" so I have to check if the interface suits. (But OTOH the chips supports the "Standard read method for I2C bus", too, so there should be no problem.) The difference is that I don't have to sent "restart", slave address and read bit as part of the request.
Quoted 3 lines
drivers/i2c/chips/rx8025.c line 349
Quoted 1 line
drivers/i2c/chips/rx8025.c new file +1
-0+ new_client->flags =0 ;Not needed, as you've kzalloc'd the client structure.
That's a relict, the driver was initially developped for 2.6.12.5. kzalloc is newer.
Quoted 2 lines
And feel free to add yourself in
MAINTAINERSas the maintainer of this new driver if you want to take care of it in the future.
Yes, I want to, but I didn't hat the courage to do that when submitting the first (non-trivial) patch.
Best regards and many thanks for your detailed review. Uwe
Signature · 5 lines
Uwe Zeisberger FS Forth-Systeme GmbH, A Digi International Company Kueferstrasse 8, D-79206 Breisach, Germany Phone: +49 (7667) 908 0 Fax: +49 (7667) 908 200 Web: www.fsforth.de, www.digi.com
PATCH 1/1 I2C: add new rx8025 driver
In reply to Uwe ZeisbergerHello,
Quoted 4 lines · Jean Delvare
Given that all block transfers you do are standard I2C block transfers, you may consider switching to i2c_smbus_{read,write}_i2c_block_data for SMBus compatibility. This would also make your code more simple, I think.
I don't understand how I specify the length of the block to be read for i2c_smbus_read_i2c_block_data. And i2c_smbus_xfer_emulated looks to me as if it were not possible to use it when my adapter doesn't have algo->smbus_xfer.
Any hints?
Best regards
Uwe
Signature · 5 lines
Uwe Zeisberger FS Forth-Systeme GmbH, A Digi International Company Kueferstrasse 8, D-79206 Breisach, Germany Phone: +49 (7667) 908 0 Fax: +49 (7667) 908 200 Web: www.fsforth.de, www.digi.com
PATCH 1/1 I2C: add new rx8025 driver
In reply to Uwe ZeisbergerHallo Uwe,
Quoted 8 lines
Quoted 4 lines · Jean Delvare
Given that all block transfers you do are standard I2C block transfers, you may consider switching to i2c_smbus_{read,write}_i2c_block_data for SMBus compatibility. This would also make your code more simple, I think.
I don't understand how I specify the length of the block to be read for
i2c_smbus_read_i2c_block_data.
Oops. This is a bug (or at least lack of fundamental feature) in the current implementation of i2c_smbus_read_i2c_block_data. I want to fix it for some times now but always postponed it due to the compatibility issues it raises :(
So there is no way you can use i2c_smbus_read_i2c_block_data in your driver at the moment; stick to i2c_transfer for now.
Quoted 3 lines
(...) And
i2c_smbus_xfer_emulatedlooks to me
as if it were not possible to use it when my adapter doesn't havealgo->smbus_xfer.
Not correct. The i2c-core is able to emulate algo->smbus_xfer using algo->master_xfer. See i2c_smbus_xfer() in i2c-core.c for the test, and i2c_smbus_xfer_emulated() for the implementation.
Signature · 1 line
Jean Delvare
PATCH 1/1 I2C: add new rx8025 driver
In reply to Uwe ZeisbergerHallo Jean,
Quoted 7 lines
Quoted 3 lines
(...) And
i2c_smbus_xfer_emulatedlooks to me
as if it were not possible to use it when my adapter doesn't havealgo->smbus_xfer.Not correct. The i2c-core is able to emulate
algo->smbus_xferusingalgo->master_xfer. Seei2c_smbus_xfer()ini2c-core.cfor the test, andi2c_smbus_xfer_emulated()for the implementation.
I checked that, but my short-term memory played a joke on me. When calling i2c_smbus_read_i2c_block_data(...), i2c_smbus_xfer_emulated is called with size = I2C_SMBUS_I2C_BLOCK_DATA, not I2C_SMBUS_BLOCK_DATA. If it were I2C_SMBUS_BLOCK_DATA (together with read_write = I2C_SMBUS_READ) it would fail.
OK, so you're right once more ...
Uwe
Signature · 5 lines
Uwe Zeisberger FS Forth-Systeme GmbH, A Digi International Company Kueferstrasse 8, D-79206 Breisach, Germany Phone: +49 (7667) 908 0 Fax: +49 (7667) 908 200 Web: www.fsforth.de, www.digi.com
PATCH 1/1 I2C: add new rx8025 driver
In reply to Uwe ZeisbergerAdds support for the Epson RX8025 SA/NB RTC module.
---
MAINTAINERS | 5 drivers/i2c/chips/Kconfig | 10 + drivers/i2c/chips/Makefile | 1 drivers/i2c/chips/rx8025.c | 598 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 614 insertions(+), 0 deletions(-) create mode 100644 drivers/i2c/chips/rx8025.c
2bb51a91a12c7096c50dcb2feb9601095d67f9ba
MAINTAINERS +5 -0
@@ -900,6 +900,11 @@ P: Christopher Hoover M: ch at murgatroid.com, ch at hpl.hp.com S: Maintained +EPSON RX-8025 SA/NB RTC DRIVER +P: Uwe Zeisberger +M: Uwe_Zeisberger at digi.com +S: Maintained + ETHEREXPRESS-16 NETWORK DRIVER P: Philip Blundell M: philb at gnu.org
drivers/i2c/chips/Kconfig +10 -0
@@ -74,6 +74,16 @@ config SENSORS_RTC8564 This driver can also be built as a module. If so, the module will be called i2c-rtc8564. +config RTC_RX8025 + tristate "Epson RX-8025 SA/NB RTC chip" + depends on I2C && EXPERIMENTAL + help + If you say yes here you get support for the + Epson RX-8025 SA/NB RTC chip. + + This driver can also be built as a module. If so, the module + will be called rx8025. + config ISP1301_OMAP tristate "Philips ISP1301 with OMAP OTG" depends on I2C && ARCH_OMAP_OTG
drivers/i2c/chips/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_SENSORS_PCA9539) += pca9539 obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o +obj-$(CONFIG_RTC_RX8025) += rx8025.o obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o obj-$(CONFIG_TPS65010) += tps65010.o obj-$(CONFIG_RTC_X1205_I2C) += x1205.o
drivers/i2c/chips/rx8025.c new file +597 -0
597 lines not on this page · raw message
Signature · 1 line
1.1.6.g5248