Skip to contentSkip to conversation

add hardware independent clock source

RFC In review Antony Pavlov 4 participants 11 messages Dec 15, 2013 – Dec 16, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Then porting barebox to a new SoC/board it is possible a situation then clocksource is broken or not yet present. In the broken/absent clocksource situation serial barebox console can't work correctly. Working on barebox for a DIGIC chip I have faced this situation. To overcome the problem I introduced the software-only clocksource.

The sample of hardware independent clock source is in the following patch:

[JUST RFC] ARM: DIGIC: add csrc-dummy

Please comment on this approach!
May be there is some ready receipt for broken clocksource case?

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

RFC 1/1 ARM: DIGIC: add csrc-dummy

The clocksource csrc-timer driver that uses DIGIC
hardware TIMER2 perfectrly works on Canon A1100,
but does not works on Canon EOS 600D.
IMHO we need additional timer initialisation.

This patch introduces a quick-and-dirty termporary solution for this situation: a clocksource driver that does not use any hardware at all.

Also this driver is very handy for running barebox on Magic Lantern EOS qemu-based emulator as
the emulator does not realize timer counter register at all!

---
 arch/arm/mach-digic/Kconfig      |  3 +++
 arch/arm/mach-digic/Makefile     |  1 +
 arch/arm/mach-digic/csrc-dummy.c | 49 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 arch/arm/mach-digic/csrc-dummy.c
arch/arm/mach-digic/Kconfig +3 -0
index 557cad4..d0524bc 100644
@@ -16,4 +16,7 @@ config ARCH_TEXT_BASE
 config DIGIC_CSRC_TIMER
 	bool
 
+config DIGIC_CSRC_DUMMY
+	bool
+
 endif
arch/arm/mach-digic/Makefile +1 -0
index 1d7cb72..31e5ac1 100644
@@ -1,2 +1,3 @@
 obj-y += core.o
 obj-$(CONFIG_DIGIC_CSRC_TIMER) += csrc-timer.o
+obj-$(CONFIG_DIGIC_CSRC_DUMMY) += csrc-dummy.o
arch/arm/mach-digic/csrc-dummy.c new file +49 -0

49 lines not on this page · raw message

Signature · 7 lines
1.8.5


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

Re: [JUST RFC] ARM: DIGIC: add csrc-dummy

Quoted 14 lines

The clocksource csrc-timer driver that uses DIGIC hardware TIMER2 perfectrly works on Canon A1100, but does not works on Canon EOS 600D.
IMHO we need additional timer initialisation.

This patch introduces a quick-and-dirty termporary solution for this situation: a clocksource driver that does not use any hardware at all.

Also this driver is very handy for running barebox on Magic Lantern EOS qemu-based emulator as
the emulator does not realize timer counter register at all!

...

arch/arm/mach-digic/csrc-dummy.c line 44

Quoted 2 lines
arch/arm/mach-digic/csrc-dummy.c new file +2 -0
+	printf("clocksource_init: mult=%08x, shift=%08x\n",
+			dummy_cs.mult, dummy_cs.shift);

No reason to spam into console. Put this into pr_debug.

---
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#3 lore raw

Re: [JUST RFC] ARM: DIGIC: add csrc-dummy

Quoted 13 lines · On Sun, 15 Dec 2013 22:08:00 +0400 Alexander Shiyan <[email protected]> wrote:
Quoted 13 lines

The clocksource csrc-timer driver that uses DIGIC hardware TIMER2 perfectrly works on Canon A1100, but does not works on Canon EOS 600D.
IMHO we need additional timer initialisation.

This patch introduces a quick-and-dirty termporary solution for this situation: a clocksource driver that does not use any hardware at all.

Also this driver is very handy for running barebox on Magic Lantern EOS qemu-based emulator as
the emulator does not realize timer counter register at all!

Quoted 7 lines
Quoted 1 line

...

arch/arm/mach-digic/csrc-dummy.c line 44

Quoted 2 lines
arch/arm/mach-digic/csrc-dummy.c new file +2 -0
+	printf("clocksource_init: mult=%08x, shift=%08x\n",
+			dummy_cs.mult, dummy_cs.shift);

No reason to spam into console. Put this into pr_debug.

Of cause there is no reason to spam into console!

This patch is mailed only for illustration of the concept, it even can't be applyed.

Have you any comments on the concept itself?

--
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw

Re: [JUST RFC] ARM: DIGIC: add csrc-dummy

Quoted 24 lines
Quoted 13 lines · On Sun, 15 Dec 2013 22:08:00 +0400 Alexander Shiyan <[email protected]> wrote:
Quoted 13 lines

The clocksource csrc-timer driver that uses DIGIC hardware TIMER2 perfectrly works on Canon A1100, but does not works on Canon EOS 600D.
IMHO we need additional timer initialisation.

This patch introduces a quick-and-dirty termporary solution for this situation: a clocksource driver that does not use any hardware at all.

Also this driver is very handy for running barebox on Magic Lantern EOS qemu-based emulator as
the emulator does not realize timer counter register at all!

Quoted 7 lines
Quoted 1 line

...

arch/arm/mach-digic/csrc-dummy.c line 44

Quoted 2 lines
arch/arm/mach-digic/csrc-dummy.c new file +2 -0
+	printf("clocksource_init: mult=%08x, shift=%08x\n",
+			dummy_cs.mult, dummy_cs.shift);

No reason to spam into console. Put this into pr_debug.

Quoted 6 lines

Of cause there is no reason to spam into console!

This patch is mailed only for illustration of the concept, it even can't be applyed.

Have you any comments on the concept itself?

I am not a guru, sorry :)

---
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#5 lore raw

Re: [JUST RFC] ARM: DIGIC: add csrc-dummy

In reply to Antony Pavlov

Hi Antony,

Quoted 67 lines · Antony Pavlov

The clocksource csrc-timer driver that uses DIGIC
hardware TIMER2 perfectrly works on Canon A1100,
but does not works on Canon EOS 600D.
IMHO we need additional timer initialisation.

This patch introduces a quick-and-dirty termporary solution for this situation: a clocksource driver that does not use any hardware at all.

Also this driver is very handy for running barebox on Magic Lantern EOS qemu-based emulator as
the emulator does not realize timer counter register at all!

---
 arch/arm/mach-digic/Kconfig      |  3 +++
 arch/arm/mach-digic/Makefile     |  1 +
 arch/arm/mach-digic/csrc-dummy.c | 49 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 arch/arm/mach-digic/csrc-dummy.c
arch/arm/mach-digic/Kconfig +3 -0
index 557cad4..d0524bc 100644
@@ -16,4 +16,7 @@ config ARCH_TEXT_BASE
 config DIGIC_CSRC_TIMER
 	bool
 
+config DIGIC_CSRC_DUMMY
+	bool
+
 endif
arch/arm/mach-digic/Makefile +1 -0
index 1d7cb72..31e5ac1 100644
@@ -1,2 +1,3 @@
 obj-y += core.o
 obj-$(CONFIG_DIGIC_CSRC_TIMER) += csrc-timer.o
+obj-$(CONFIG_DIGIC_CSRC_DUMMY) += csrc-dummy.o
arch/arm/mach-digic/csrc-dummy.c new file +20 -0
new file mode 100644
index 0000000..68c68a3
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2013 Antony Pavlov <[email protected]>
+ *
+ * This file is part of barebox.
+ * See file CREDITS for list of people who contributed to this project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <init.h>
+#include <clock.h>
+

arch/arm/mach-digic/csrc-dummy.c line 30

Quoted 10 lines
arch/arm/mach-digic/csrc-dummy.c new file +10 -0
+#include <stdio.h>
+
+static uint64_t dummy_counter;
+
+static uint64_t dummy_cs_read(void)
+{
+	dummy_counter += 2000;
+	return dummy_counter;
+}
+

So if I understand it right, you assume here that the instructions to read this value will take 0.02 ms?

- Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#6 lore raw

Re: [JUST RFC] ARM: DIGIC: add csrc-dummy

Quoted 74 lines · On Sun, 15 Dec 2013 20:30:16 +0100 Alexander Aring <[email protected]> wrote:

Hi Antony,

Quoted 71 lines · Antony Pavlov

The clocksource csrc-timer driver that uses DIGIC
hardware TIMER2 perfectrly works on Canon A1100,
but does not works on Canon EOS 600D.
IMHO we need additional timer initialisation.

This patch introduces a quick-and-dirty termporary solution for this situation: a clocksource driver that does not use any hardware at all.

Also this driver is very handy for running barebox on Magic Lantern EOS qemu-based emulator as
the emulator does not realize timer counter register at all!

---
 arch/arm/mach-digic/Kconfig      |  3 +++
 arch/arm/mach-digic/Makefile     |  1 +
 arch/arm/mach-digic/csrc-dummy.c | 49 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 arch/arm/mach-digic/csrc-dummy.c
arch/arm/mach-digic/Kconfig +3 -0
index 557cad4..d0524bc 100644
@@ -16,4 +16,7 @@ config ARCH_TEXT_BASE
 config DIGIC_CSRC_TIMER
 	bool
 
+config DIGIC_CSRC_DUMMY
+	bool
+
 endif
arch/arm/mach-digic/Makefile +1 -0
index 1d7cb72..31e5ac1 100644
@@ -1,2 +1,3 @@
 obj-y += core.o
 obj-$(CONFIG_DIGIC_CSRC_TIMER) += csrc-timer.o
+obj-$(CONFIG_DIGIC_CSRC_DUMMY) += csrc-dummy.o
arch/arm/mach-digic/csrc-dummy.c new file +24 -0
new file mode 100644
index 0000000..68c68a3
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2013 Antony Pavlov <[email protected]>
+ *
+ * This file is part of barebox.
+ * See file CREDITS for list of people who contributed to this project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <init.h>
+#include <clock.h>
+
+#include <stdio.h>
+
+static uint64_t dummy_counter;
+
Quoted 8 lines

arch/arm/mach-digic/csrc-dummy.c line 30

Quoted 6 lines
arch/arm/mach-digic/csrc-dummy.c new file +6 -0
+static uint64_t dummy_cs_read(void)
+{
+	dummy_counter += 2000;
+	return dummy_counter;
+}
+

So if I understand it right, you assume here that the instructions to read this value will take 0.02 ms?

It is not quite. I don't assume initially the time to read this value. This value ("2000") was a suboptimal value for __specific board__ under the __specific circumstances__.
I have selected this value after several experiments.

--
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#7 lore raw

Re: [JUST RFC] ARM: DIGIC: add csrc-dummy

Quoted 86 lines · Antony Pavlov
Quoted 74 lines · On Sun, 15 Dec 2013 20:30:16 +0100 Alexander Aring <[email protected]> wrote:

Hi Antony,

Quoted 71 lines · Antony Pavlov

The clocksource csrc-timer driver that uses DIGIC
hardware TIMER2 perfectrly works on Canon A1100,
but does not works on Canon EOS 600D.
IMHO we need additional timer initialisation.

This patch introduces a quick-and-dirty termporary solution for this situation: a clocksource driver that does not use any hardware at all.

Also this driver is very handy for running barebox on Magic Lantern EOS qemu-based emulator as
the emulator does not realize timer counter register at all!

---
 arch/arm/mach-digic/Kconfig      |  3 +++
 arch/arm/mach-digic/Makefile     |  1 +
 arch/arm/mach-digic/csrc-dummy.c | 49 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 arch/arm/mach-digic/csrc-dummy.c
arch/arm/mach-digic/Kconfig +3 -0
index 557cad4..d0524bc 100644
@@ -16,4 +16,7 @@ config ARCH_TEXT_BASE
 config DIGIC_CSRC_TIMER
 	bool
 
+config DIGIC_CSRC_DUMMY
+	bool
+
 endif
arch/arm/mach-digic/Makefile +1 -0
index 1d7cb72..31e5ac1 100644
@@ -1,2 +1,3 @@
 obj-y += core.o
 obj-$(CONFIG_DIGIC_CSRC_TIMER) += csrc-timer.o
+obj-$(CONFIG_DIGIC_CSRC_DUMMY) += csrc-dummy.o
arch/arm/mach-digic/csrc-dummy.c new file +24 -0
new file mode 100644
index 0000000..68c68a3
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2013 Antony Pavlov <[email protected]>
+ *
+ * This file is part of barebox.
+ * See file CREDITS for list of people who contributed to this project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <init.h>
+#include <clock.h>
+
+#include <stdio.h>
+
+static uint64_t dummy_counter;
+
Quoted 8 lines

arch/arm/mach-digic/csrc-dummy.c line 30

Quoted 6 lines
arch/arm/mach-digic/csrc-dummy.c new file +6 -0
+static uint64_t dummy_cs_read(void)
+{
+	dummy_counter += 2000;
+	return dummy_counter;
+}
+

So if I understand it right, you assume here that the instructions to read this value will take 0.02 ms?

Quoted 5 lines

It is not quite. I don't assume initially the time to read this value. This value ("2000") was a suboptimal value for __specific board__ under the __specific circumstances__.
I have selected this value after several experiments.

mhh, I am thinking maybe about some calculation with clock ticks. Maybe some "nop" operations and inline assembler. In the processor datasheet should stand how long one "nop" instruction will take. Then you can increase the dummy_counter intervall and waits longer, that should deincrease the amount of failure (I think).

The current solution has the smallest clock resolution (because you don't make any "nops" instructions).

It isn't a quite solution as well and I don't know if this still works with your qemu emulation. It's just a notice for an alternative and an idea. It's the same idea like you already have...

Another question:
How do the original firmware do this? I think there are some date/time information. Is there any additional hardware?

- Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#8 lore raw

Re: [JUST RFC] ARM: DIGIC: add csrc-dummy

In reply to Antony Pavlov
Quoted 15 lines · Antony Pavlov

The clocksource csrc-timer driver that uses DIGIC hardware TIMER2 perfectrly works on Canon A1100, but does not works on Canon EOS 600D.
IMHO we need additional timer initialisation.

This patch introduces a quick-and-dirty termporary solution for this situation: a clocksource driver that does not use any hardware at all.

Also this driver is very handy for running barebox on Magic Lantern EOS qemu-based emulator as
the emulator does not realize timer counter register at all!

---

arch/arm/mach-digic/csrc-dummy.c line 29

Quoted 5 lines
arch/arm/mach-digic/csrc-dummy.c new file +5 -0
+static uint64_t dummy_cs_read(void)
+{
+	dummy_counter += 2000;
+	return dummy_counter;
+}

I also played with the same approach. In my case it was more a fallback when the initialization order was wrong so that the time functions were used before the real clocksource was initialized. Without it time never advanced and every udelay() locked up the system (or it crashed because we didn't check for the clocksource being NULL, can't remember).

Maybe it would be possible to add this clocksource unconditionally on every build, but let a real clocksource take over.

To do this and not silently fall back to a dummy console I suggest a:

static uint64_t dummy_cs_read(void)

{
	static int first;

	if (!first) {
		pr_warn("Warning: Using dummy clocksource\n");
		first = 0;
	}

	dummy_counter += 2000;
	return dummy_counter;
}

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

Re: [JUST RFC] ARM: DIGIC: add csrc-dummy

Quoted 33 lines · Sascha Hauer
Quoted 15 lines · Antony Pavlov

The clocksource csrc-timer driver that uses DIGIC hardware TIMER2 perfectrly works on Canon A1100, but does not works on Canon EOS 600D.
IMHO we need additional timer initialisation.

This patch introduces a quick-and-dirty termporary solution for this situation: a clocksource driver that does not use any hardware at all.

Also this driver is very handy for running barebox on Magic Lantern EOS qemu-based emulator as
the emulator does not realize timer counter register at all!

---

arch/arm/mach-digic/csrc-dummy.c line 29

Quoted 5 lines
arch/arm/mach-digic/csrc-dummy.c new file +5 -0
+static uint64_t dummy_cs_read(void)
+{
+	dummy_counter += 2000;
+	return dummy_counter;
+}

I also played with the same approach. In my case it was more a fallback when the initialization order was wrong so that the time functions were used before the real clocksource was initialized. Without it time never advanced and every udelay() locked up the system (or it crashed because we didn't check for the clocksource being NULL, can't remember).

Maybe it would be possible to add this clocksource unconditionally on every build, but let a real clocksource take over.

To do this and not silently fall back to a dummy console I suggest a:

Quoted 7 lines

static uint64_t dummy_cs_read(void)

{
	static int first;

	if (!first) {
		pr_warn("Warning: Using dummy clocksource\n");
		first = 0;

first = 1;

:-)

- Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#10 lore raw

Re: [JUST RFC] ARM: DIGIC: add csrc-dummy

In reply to Sascha Hauer
Quoted 13 lines · Antony Pavlov
Quoted 12 lines

The clocksource csrc-timer driver that uses DIGIC hardware TIMER2 perfectrly works on Canon A1100, but does not works on Canon EOS 600D.
IMHO we need additional timer initialisation.

This patch introduces a quick-and-dirty termporary solution for this situation: a clocksource driver that does not use any hardware at all.

Also this driver is very handy for running barebox on Magic Lantern EOS qemu-based emulator as
the emulator does not realize timer counter register at all!

...

Quoted 11 lines

I also played with the same approach. In my case it was more a fallback when the initialization order was wrong so that the time functions were used before the real clocksource was initialized. Without it time never advanced and every udelay() locked up the system (or it crashed because we didn't check for the clocksource being NULL, can't remember).

Maybe it would be possible to add this clocksource unconditionally on every build, but let a real clocksource take over.

To do this and not silently fall back to a dummy console I suggest a:

Quoted 7 lines

static uint64_t dummy_cs_read(void)

{
	static int first;

	if (!first) {
		pr_warn("Warning: Using dummy clocksource\n");
		first = 0;

first =1;

---
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox