Skip to contentSkip to conversation

RTC:Add RTC driver for Gemini SoC

PATCH In review Hans Ulli Kroll 2 participants 2 messages May 7, 2015 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RTC:Add RTC driver for Gemini SoC

---
 drivers/rtc/Kconfig      |   9 +++
 drivers/rtc/Makefile     |   1 +
 drivers/rtc/rtc-gemini.c | 201 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 211 insertions(+)
 create mode 100644 drivers/rtc/rtc-gemini.c
drivers/rtc/Kconfig +9 -0
index 6149ae0..c6ea9aa 100644
@@ -1362,6 +1362,15 @@ config RTC_DRV_ARMADA38X
 	  This driver can also be built as a module. If so, the module
 	  will be called armada38x-rtc.
 
+config RTC_DRV_GEMINI
+	tristate "Gemini SoC RTC"
+	help
+	  If you say Y here you will get support for the
+	  RTC found on Gemini SoC's.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-gemini.
+
 config RTC_DRV_PS3
 	tristate "PS3 RTC"
 	depends on PPC_PS3
drivers/rtc/Makefile +1 -0
index c31731c..0fd6e22 100644
@@ -64,6 +64,7 @@ obj-$(CONFIG_RTC_DRV_EFI)	+= rtc-efi.o
 obj-$(CONFIG_RTC_DRV_EM3027)	+= rtc-em3027.o
 obj-$(CONFIG_RTC_DRV_EP93XX)	+= rtc-ep93xx.o
 obj-$(CONFIG_RTC_DRV_FM3130)	+= rtc-fm3130.o
+obj-$(CONFIG_RTC_DRV_GEMINI)	+= rtc-gemini.o
 obj-$(CONFIG_RTC_DRV_GENERIC)	+= rtc-generic.o
 obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
 obj-$(CONFIG_RTC_DRV_HYM8563)	+= rtc-hym8563.o
drivers/rtc/rtc-gemini.c new file +201 -0

201 lines not on this page · raw message

Signature · 1 line
2.3.5
#1 lore raw

Hi,

Please also send to the linux-rtc mailing list:
[email protected]

On 07/05/2015 at 19:32:54 +0200, Hans Ulli Kroll wrote :

Please always include a commit log.

Quoted 2 lines

---

[...]

drivers/rtc/rtc-gemini.c line 82

Quoted 12 lines
drivers/rtc/rtc-gemini.c new file +12 -0
+static int gemini_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct gemini_rtc *rtc = dev_get_drvdata(dev);
+
+	unsigned int  days, hour, min, sec;
+	unsigned long offset, time;
+
+	sec  = ioread32(rtc->rtc_base + GEMINI_RTC_SECOND);
+	min  = ioread32(rtc->rtc_base + GEMINI_RTC_MINUTE);
+	hour = ioread32(rtc->rtc_base + GEMINI_RTC_HOUR);
+	days = ioread32(rtc->rtc_base + GEMINI_RTC_DAYS);
+	offset = ioread32(rtc->rtc_base + GEMINI_RTC_RECORD);

Can you use readl() here?

Quoted 14 lines
drivers/rtc/rtc-gemini.c new file +14 -0
+
+	time = offset + days * 86400 + hour * 3600 + min * 60 + sec;
+
+	rtc_time_to_tm(time, tm);
+
+	return 0;
+}
+
+static int gemini_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	struct gemini_rtc *rtc = dev_get_drvdata(dev);
+	unsigned int sec, min, hour, day;
+	unsigned long offset, time;
+

drivers/rtc/rtc-gemini.c line 106

Quoted 10 lines
drivers/rtc/rtc-gemini.c new file +10 -0
+	if (tm->tm_year >= 2148)	/* EPOCH Year + 179 */
+		return -EINVAL;
+
+	rtc_tm_to_time(tm, &time);
+
+	sec = ioread32(rtc->rtc_base + GEMINI_RTC_SECOND);
+	min = ioread32(rtc->rtc_base + GEMINI_RTC_MINUTE);
+	hour = ioread32(rtc->rtc_base + GEMINI_RTC_HOUR);
+	day = ioread32(rtc->rtc_base + GEMINI_RTC_DAYS);
+

ditto.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	offset = time - (day*86400 + hour*3600 + min*60 + sec);
+

If you use spaces around the * in read_time, please do the same here.

drivers/rtc/rtc-gemini.c line 110

Quoted 2 lines
drivers/rtc/rtc-gemini.c new file +2 -0
+	iowrite32(offset, rtc->rtc_base + GEMINI_RTC_RECORD);
+	iowrite32(0x01, rtc->rtc_base + GEMINI_RTC_CR);

writel() ?

Quoted 33 lines
drivers/rtc/rtc-gemini.c new file +33 -0
+
+	return 0;
+}
+
+static struct rtc_class_ops gemini_rtc_ops = {
+	.read_time     = gemini_rtc_read_time,
+	.set_time      = gemini_rtc_set_time,
+};
+
+static int gemini_rtc_probe(struct platform_device *pdev)
+{
+	struct gemini_rtc *rtc;
+	struct device *dev = &pdev->dev;
+	struct resource *res;
+	int ret;
+
+	rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
+	if (unlikely(!rtc))
+		return -ENOMEM;
+	platform_set_drvdata(pdev, rtc);
+
+	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+	if (!res) {
+		ret = -ENODEV;
+		goto err_mem;
+	}
+	rtc->rtc_irq = res->start;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		ret = -ENODEV;
+		goto err_mem;
+	}

drivers/rtc/rtc-gemini.c line 153

Quoted 10 lines
drivers/rtc/rtc-gemini.c new file +10 -0
+	rtc->rtc_base =	devm_ioremap(&pdev->dev, res->start,
+				res->end - res->start + 1);
+
+	ret = request_irq(rtc->rtc_irq, gemini_rtc_interrupt,
+				IRQF_SHARED, pdev->name, dev);
+	if (unlikely(ret))
+		goto err_mem;
+
+	rtc->rtc_dev =	rtc_device_register(pdev->name, dev,
+				&gemini_rtc_ops, THIS_MODULE);

For those 3 functions, the alignment of the wrapped function parameters should match the open parenthesis.

[...]

drivers/rtc/rtc-gemini.c line 201

Quoted 12 lines
drivers/rtc/rtc-gemini.c new file +12 -0
+static int __init gemini_rtc_init(void)
+{
+	return platform_driver_register(&gemini_rtc_driver);
+}
+
+static void __exit gemini_rtc_exit(void)
+{
+	platform_driver_unregister(&gemini_rtc_driver);
+}
+
+module_init(gemini_rtc_init);
+module_exit(gemini_rtc_exit);

I'd remove those and use module_platform_driver()

Thanks!

Signature · 3 lines
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com