Skip to contentSkip to conversation

Blackfin: on-chip RTC controller driver

PATCH In review Wu, Bryan 3 participants 3 messages Mar 1, 2007 Real time clock (RTC)

lore
Share & tools
lore

Wu, Bryan

author
#0 lore raw

PATCH 5/5 Blackfin: on-chip RTC controller driver

Hi folks,

Here is the blackfin on-chip RTC controller driver for Linux.

It's name is blackfin-driver-rtc.patch

[PATCH] Blackfin: on-chip RTC controller driver

This patch implements the driver necessary use the Analog Devices Blackfin processor's on-chip RTC controller.

---

 Kconfig    |   10 +
 Makefile   |    1
 rtc-bfin.c |  445 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 456 insertions(+)
drivers/rtc/Kconfig +10 -0
Index: linux-2.6/drivers/rtc/Kconfig
===================================================================
@@ -352,4 +352,14 @@
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-v3020.
 
+config RTC_DRV_BFIN
+	tristate "Blackfin On-Chip RTC"
+	depends on RTC_CLASS && BFIN
+	help
+	  If you say yes here you will get support for the
+	  Blackfin On-Chip Real Time Clock.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-bfin.
+
 endmenu
drivers/rtc/Makefile +1 -0
Index: linux-2.6/drivers/rtc/Makefile
===================================================================
@@ -38,3 +38,4 @@
 obj-$(CONFIG_RTC_DRV_V3020)	+= rtc-v3020.o
 obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
 obj-$(CONFIG_RTC_DRV_SH)	+= rtc-sh.o
+obj-$(CONFIG_RTC_DRV_BFIN)	+= rtc-bfin.o
drivers/rtc/rtc-bfin.c new file +445 -0

445 lines not on this page · raw message

---

Thanks
-Bryan Wu

#1 lore raw

drivers/rtc/rtc-bfin.c line 50

Quoted 3 lines · Bryan
drivers/rtc/rtc-bfin.c new file +3 -0
+#define stamp(fmt, args...) pr_debug("%s:%i: " fmt "\n", __FUNCTION__, __LINE__, ## args)
+#define stampit() stamp("here i am")
+

Are these really necessary for the final driver? It's littered all over the place, and presumably the driver should be functional enough to not need this sort of debugging instrumentation.

[snip]

drivers/rtc/rtc-bfin.c line 125

Quoted 10 lines
drivers/rtc/rtc-bfin.c new file +10 -0
+static void rtc_bfin_sync_pending(void)
+{
+	stampit();
+	while (!(bfin_read_RTC_ISTAT() & RTC_ISTAT_WRITE_COMPLETE)) {
+		if (!(bfin_read_RTC_ISTAT() & RTC_ISTAT_WRITE_PENDING))
+			break;
+	}
+	bfin_write_RTC_ISTAT(RTC_ISTAT_WRITE_COMPLETE);
+}
+

No timeout? (and superfluous braces)

drivers/rtc/rtc-bfin.c line 212

Quoted 4 lines
drivers/rtc/rtc-bfin.c new file +4 -0
+	case RTC_PIE_ON:
+		stampit();
+		spin_lock_irq(&rtc->lock);
+		rtc_bfin_sync_pending();

And it's also called under a spinlock each time.. this is a disaster waiting to happen.

#2 lore raw
Quoted 7 lines · Paul Mundt

drivers/rtc/rtc-bfin.c line 49

Quoted 2 lines · Bryan
drivers/rtc/rtc-bfin.c new file +2 -0
+#define stamp(fmt, args...) pr_debug("%s:%i: " fmt "\n", __FUNCTION__, __LINE__, ## args)
+#define stampit() stamp("here i am")

Are these really necessary for the final driver? It's littered all over the place, and presumably the driver should be functional enough to not need this sort of debugging instrumentation.

is there really such a thing as a "final driver" ? :)

keeping the stampit()'s in place means i dont have to re-add and re-delete them every time some one reports a bug ...

Quoted 11 lines

drivers/rtc/rtc-bfin.c line 124

Quoted 9 lines
drivers/rtc/rtc-bfin.c new file +9 -0
+static void rtc_bfin_sync_pending(void)
+{
+     stampit();
+     while (!(bfin_read_RTC_ISTAT() & RTC_ISTAT_WRITE_COMPLETE)) {
+             if (!(bfin_read_RTC_ISTAT() & RTC_ISTAT_WRITE_PENDING))
+                     break;
+     }
+     bfin_write_RTC_ISTAT(RTC_ISTAT_WRITE_COMPLETE);
+}

No timeout? (and superfluous braces)

the ISTAT is reset every clock tick by the hardware itself ... so the timeout is implicit

Quoted 7 lines

drivers/rtc/rtc-bfin.c line 212

Quoted 4 lines
drivers/rtc/rtc-bfin.c new file +4 -0
+     case RTC_PIE_ON:
+             stampit();
+             spin_lock_irq(&rtc->lock);
+             rtc_bfin_sync_pending();

And it's also called under a spinlock each time.. this is a disaster waiting to happen.

i noted the logic behind this decision in the comments in the driver ... i too think it sucks, but i cant fathom a better idea so i'm certainly open to suggestions :)
-mike