rtc: Add MOXA ART RTC driver
Subsystems (2)
PATCH 1/1 rtc: Add MOXA ART RTC driver
Add RTC driver for MOXA ART SoCs.
---
Notes:
Applies to next-20130703
drivers/rtc/Kconfig | 9 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-moxart.c | 335 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 345 insertions(+) create mode 100644 drivers/rtc/rtc-moxart.c
drivers/rtc/Kconfig +9 -0
@@ -1233,6 +1233,15 @@ config RTC_DRV_SNVS This driver can also be built as a module, if so, the module will be called "rtc-snvs". +config RTC_DRV_MOXART + tristate "MOXA ART RTC" + help + If you say yes here you get support for the MOXA ART + RTC module. + + This driver can also be built as a module. If so, the module + will be called rtc-moxart + comment "HID Sensor RTC drivers" config RTC_DRV_HID_SENSOR_TIME
drivers/rtc/Makefile +1 -0
@@ -77,6 +77,7 @@ obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o obj-$(CONFIG_RTC_DRV_MAX77686) += rtc-max77686.o obj-$(CONFIG_RTC_DRV_MC13XXX) += rtc-mc13xxx.o obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o +obj-$(CONFIG_RTC_DRV_MOXART) += rtc-moxart.o obj-$(CONFIG_RTC_DRV_MPC5121) += rtc-mpc5121.o obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o obj-$(CONFIG_RTC_DRV_NUC900) += rtc-nuc900.o
drivers/rtc/rtc-moxart.c new file +335 -0
335 lines not on this page · raw message
Signature · 1 line
1.8.2.1
drivers/rtc/Makefile obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o · line 81
Quoted 7 lines · Jonas Jensen
+++ b/drivers/rtc/Makefile
drivers/rtc/Makefile +1
-0@@ -77,6 +77,7 @@ obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o obj-$(CONFIG_RTC_DRV_MAX77686) += rtc-max77686.o obj-$(CONFIG_RTC_DRV_MC13XXX) += rtc-mc13xxx.o obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o +obj-$(CONFIG_RTC_DRV_MOXART) += rtc-moxart.o obj-$(CONFIG_RTC_DRV_MPC5121) += rtc-mpc5121.o
It'd be good to keep this sorted.
drivers/rtc/rtc-moxart.c line 69
Quoted 1 line
drivers/rtc/rtc-moxart.c new file +1
-0+struct rtc_plat_data {
This is a bit confusing - normally platform data is data passed in by the platform as part of device registration, not runtime data.
drivers/rtc/rtc-moxart.c line 73
Quoted 4 lines
drivers/rtc/rtc-moxart.c new file +4
-0+struct rtc_device *rtc; +}; + +static spinlock_t rtc_lock;
Why is this global not part of the runtime data? Not that anyone is likely to have two RTCs in the one system but still...
drivers/rtc/rtc-moxart.c line 101
Quoted 12 lines
drivers/rtc/rtc-moxart.c new file +12
-0+u8 moxart_rtc_read_byte (void ) +{ +int i; +u8 data =0 ; + +for (i =0 ; i <8 ; i++) { +gpio_set_value (GPIO_RTC_SCLK ,GPIO_EM1240_LOW ); +udelay (GPIO_RTC_DELAY_TIME ); +gpio_set_value (GPIO_RTC_SCLK ,GPIO_EM1240_HIGH ); +if (gpio_get_value (GPIO_RTC_DATA )) + data |= (1 << i); +udelay (GPIO_RTC_DELAY_TIME );
This looks wrong, although I expect it's probably fine - you're reading the value with no delay after setting the GPIO high. I assume the hardware actually strobes the data out on the the high to low transition but in that case I'd expect the get to be before the raise. Either that or some delay after the raise just to make sure.
It's also very odd seeing the constants for _LOW and _HIGH, these should just be booleans.
drivers/rtc/rtc-moxart.c line 250
Quoted 10 lines
drivers/rtc/rtc-moxart.c new file +10
-0+static int moxart_rtc_ioctl (struct device *dev,unsigned int cmd, +unsigned long arg) +{ +switch (cmd) { +default : +return -ENOIOCTLCMD ; + } + +return 0 ; +}
Why not just remove this function?
drivers/rtc/rtc-moxart.c line 299
Quoted 4 lines
+ out:
drivers/rtc/rtc-moxart.c new file +3
-0+if (pdata->rtc) +rtc_device_unregister (pdata->rtc); +devm_kfree (&pdev->dev, pdata);
devm_kfree() isn't needed, the main point of devm_ is to avoid having to explicitly free things.
drivers/rtc/rtc-moxart.c line 309
Quoted 3 lines
drivers/rtc/rtc-moxart.c new file +3
-0+gpio_free (GPIO_RTC_DATA ); +gpio_free (GPIO_RTC_SCLK ); +gpio_free (GPIO_RTC_RESET );
Use devm_gpio_request().
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130710/be4d14ac/attachment.sig>
PATCH v2 1/1 rtc: Add MOXA ART RTC driver
In reply to Jonas JensenAdd RTC driver for MOXA ART SoCs.
---
Notes:
Thanks for the review Mark, what you said should be fixed in v2.
Applies to next-20130711
Changes since v1:
1. remove defines GPIO_EM1240_HIGH and GPIO_EM1240_LOW
2. rename struct "rtc_plat_data" "moxart_rtc"
3. move rtc_lock to struct moxart_rtc
4. add delay after setting GPIO high
5. remove moxart_rtc_ioctl
6. use devm_gpio_request instead of gpio_request
7. remove explicit devm_kfree
8. change Makefile list order
drivers/rtc/Kconfig | 9 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-moxart.c | 316 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 326 insertions(+) create mode 100644 drivers/rtc/rtc-moxart.c
drivers/rtc/Kconfig +9 -0
@@ -1249,6 +1249,15 @@ config RTC_DRV_SIRFSOC Say "yes" here to support the real time clock on SiRF SOC chips. This driver can also be built as a module called rtc-sirfsoc. +config RTC_DRV_MOXART + tristate "MOXA ART RTC" + help + If you say yes here you get support for the MOXA ART + RTC module. + + This driver can also be built as a module. If so, the module + will be called rtc-moxart + comment "HID Sensor RTC drivers" config RTC_DRV_HID_SENSOR_TIME
drivers/rtc/Makefile +1 -0
@@ -130,3 +130,4 @@ obj-$(CONFIG_RTC_DRV_WM831X) += rtc-wm831x.o obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o obj-$(CONFIG_RTC_DRV_SIRFSOC) += rtc-sirfsoc.o +obj-$(CONFIG_RTC_DRV_MOXART) += rtc-moxart.o
drivers/rtc/rtc-moxart.c new file +316 -0
316 lines not on this page · raw message
Signature · 1 line
1.8.2.1
Quoted 1 line · Jonas Jensen
Add RTC driver for MOXA ART SoCs.
Looks good now. A couple more minor nits.
drivers/rtc/rtc-moxart.c line 89
Quoted 5 lines
drivers/rtc/rtc-moxart.c new file +4
-0+void moxart_rtc_write_byte (u8 data) +{ +u8 moxart_rtc_read_byte (void ) +{
These should be static.
Review
Quoted 2 lines
(quoted diff) +2
-0+ gpio_direction_output(GPIO_RTC_DATA, 0); + gpio_set_value(GPIO_RTC_RESET, 1);
I guess I'd expect the GPIOs to be configured by platform data in case of board changes (it's a bit odd that a SoC RTC is being done with bitbanging, I guess it's on an external chip?).
drivers/rtc/rtc-moxart.c line 264
Quoted 3 lines
drivers/rtc/rtc-moxart.c new file +3
-0+devm_gpio_request (&pdev->dev,GPIO_RTC_DATA ,"rtc_data" ); +devm_gpio_request (&pdev->dev,GPIO_RTC_SCLK ,"rtc_sclk" ); +devm_gpio_request (&pdev->dev,GPIO_RTC_RESET ,"rtc_reset" );
Should check the errors from these.
drivers/rtc/rtc-moxart.c line 267
Quoted 2 lines
drivers/rtc/rtc-moxart.c new file +2
-0+gpio_direction_output (GPIO_RTC_RESET ,0 ); +gpio_direction_output (GPIO_RTC_SCLK ,0 );
devm_gpio_request_one()? Though it doesn't make much difference and you
do have a nice block of devm_gpio_request() above not all of which have
a direction assigned immediately.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130711/7019f737/attachment.sig>
drivers/rtc/rtc-moxart.c line 29
Quoted 8 lines · Jonas Jensen
Add RTC driver for MOXA ART SoCs.
drivers/rtc/rtc-moxart.c new file +7
-0+ +#define GPIO_EM1240_OUTPUT 1 +#define GPIO_EM1240_INPUT 0 + +#define GPIO_RTC_SCLK (5) +#define GPIO_RTC_DATA (6) +#define GPIO_RTC_RESET (7)
Since this is a DT-only platform, you should not really have hardcoded GPIO numbers.
drivers/rtc/rtc-moxart.c line 264
Quoted 3 lines
drivers/rtc/rtc-moxart.c new file +3
-0+devm_gpio_request (&pdev->dev,GPIO_RTC_DATA ,"rtc_data" ); +devm_gpio_request (&pdev->dev,GPIO_RTC_SCLK ,"rtc_sclk" ); +devm_gpio_request (&pdev->dev,GPIO_RTC_RESET ,"rtc_reset" );
Instead, you should use of_get_named_gpio() here, and add a binding document that describes the names.
Arnd
PATCH v3 1/1 rtc: Add MOXA ART RTC driver
In reply to Jonas JensenAdd RTC driver for MOXA ART SoCs.
---
Notes:
Thanks for the replies. This should fix the remaining issues mentioned by Mark and Arnd.
Changes since v2:
1. don't use hardcoded GPIO numbers, use of_get_named_gpio
2. make two functions static, moxart_rtc_write_byte and moxart_rtc_read_byte
3. use devm_gpio_request_one where appropriate
4. add gpio_is_valid check to all of_get_named_gpio
5. check devm_gpio_request return value
6. use devm_rtc_device_register instead of rtc_device_register
7. remove label "out" from moxart_rtc_probe
8. remove moxart_rtc_remove function
Applies to next-20130716
drivers/rtc/Kconfig | 9 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-moxart.c | 330 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 340 insertions(+) create mode 100644 drivers/rtc/rtc-moxart.c
drivers/rtc/Kconfig +9 -0
@@ -1249,6 +1249,15 @@ config RTC_DRV_SIRFSOC Say "yes" here to support the real time clock on SiRF SOC chips. This driver can also be built as a module called rtc-sirfsoc. +config RTC_DRV_MOXART + tristate "MOXA ART RTC" + help + If you say yes here you get support for the MOXA ART + RTC module. + + This driver can also be built as a module. If so, the module + will be called rtc-moxart + comment "HID Sensor RTC drivers" config RTC_DRV_HID_SENSOR_TIME
drivers/rtc/Makefile +1 -0
@@ -130,3 +130,4 @@ obj-$(CONFIG_RTC_DRV_WM831X) += rtc-wm831x.o obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o obj-$(CONFIG_RTC_DRV_SIRFSOC) += rtc-sirfsoc.o +obj-$(CONFIG_RTC_DRV_MOXART) += rtc-moxart.o
drivers/rtc/rtc-moxart.c new file +330 -0
330 lines not on this page · raw message
Signature · 1 line
1.8.2.1
Quoted 1 line · Jonas Jensen
1. don't use hardcoded GPIO numbers, use
of_get_named_gpio
Since you're now using OF you should also be including a binding
document.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130716/e65a6be3/attachment-0001.sig>
Quoted 2 lines · Mark Brown
Since you're now using OF you should also be including a binding document.
The binding document already exist in set of patches adding MOXA ART SoC support ( I intend to mail out v4 once I know how to proceed ):
"[PATCH v3 2/4] ARM: mach-moxart: add MOXA ART device tree files" -
http://lists.infradead.org/pipermail/linux-arm-kernel/2013-July/181757.html
Can it remain as a part of that set?
Or should it be moved here to a new v4 patch?
Changes are available in my public git repository, see Documentation/devicetree/bindings/rtc/moxa,moxart-rtc.txt:
Best regards,
Jonas
Quoted 6 lines · Jonas Jensen
Quoted 2 lines · Mark Brown
Since you're now using OF you should also be including a binding document.
The binding document already exist in set of patches adding MOXA ART SoC support ( I intend to mail out v4 once I know how to proceed ):
If that's the case then you need to point people at the binding document when posting the driver but...
Quoted 1 line
Or should it be moved here to a new v4 patch?
...it's more normal to push the binding along with the driver.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130716/7e5b010a/attachment.sig>
PATCH v4 1/1 rtc: Add MOXA ART RTC driver
In reply to Jonas JensenAdd RTC driver for MOXA ART SoCs.
---
Notes:
Changes since v3:
1. add devicetree bindings document
Applies to next-20130716
.../devicetree/bindings/rtc/moxa,moxart-rtc.txt | 17 ++ drivers/rtc/Kconfig | 9 + drivers/rtc/Makefile | 1 + drivers/rtc/rtc-moxart.c | 330 +++++++++++++++++++++ 4 files changed, 357 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/moxa,moxart-rtc.txt create mode 100644 drivers/rtc/rtc-moxart.c
Documentation/devicetree/bindings/rtc/moxa,moxart-rtc.txt new file +17 -0
@@ -0,0 +1,17 @@ +MOXA ART real-time clock + +Required properties: + +- compatible : Should be "moxa,moxart-rtc" +- gpio-rtc-sclk : RTC sclk gpio, with zero flags +- gpio-rtc-data : RTC data gpio, with zero flags +- gpio-rtc-reset : RTC reset gpio, with zero flags + +Example: + + rtc: rtc { + compatible = "moxa,moxart-rtc"; + gpio-rtc-sclk = <&gpio 5 0>; + gpio-rtc-data = <&gpio 6 0>; + gpio-rtc-reset = <&gpio 7 0>; + };
drivers/rtc/Kconfig +9 -0
@@ -1249,6 +1249,15 @@ config RTC_DRV_SIRFSOC Say "yes" here to support the real time clock on SiRF SOC chips. This driver can also be built as a module called rtc-sirfsoc. +config RTC_DRV_MOXART + tristate "MOXA ART RTC" + help + If you say yes here you get support for the MOXA ART + RTC module. + + This driver can also be built as a module. If so, the module + will be called rtc-moxart + comment "HID Sensor RTC drivers" config RTC_DRV_HID_SENSOR_TIME
drivers/rtc/Makefile +1 -0
@@ -130,3 +130,4 @@ obj-$(CONFIG_RTC_DRV_WM831X) += rtc-wm831x.o obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o obj-$(CONFIG_RTC_DRV_SIRFSOC) += rtc-sirfsoc.o +obj-$(CONFIG_RTC_DRV_MOXART) += rtc-moxart.o
drivers/rtc/rtc-moxart.c new file +330 -0
330 lines not on this page · raw message
Signature · 1 line
1.8.2.1
Quoted 3 lines · Jonas Jensen
Add RTC driver for MOXA ART SoCs.
Signed-off-by Jonas Jensen <[email protected]>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130717/cabf25e8/attachment.sig>