diff mbox series

[U-Boot,1/5] x86: timer: tsc: Allow specifying clock rate from device tree again

Message ID 1529748231-12859-1-git-send-email-bmeng.cn@gmail.com
State Accepted
Commit 94e72a6bd994078674188bee2efb727a110a1cc6
Delegated to: Bin Meng
Headers show
Series [U-Boot,1/5] x86: timer: tsc: Allow specifying clock rate from device tree again | expand

Commit Message

Bin Meng June 23, 2018, 10:03 a.m. UTC
With the introduction of early timer support in the TSC driver,
the capability of getting clock rate from device tree was lost
unfortunately. Now we bring such functionality back, but with a
limitation that when TSC is used as early timer, specifying clock
rate from device tree does not work.

This fixes random boot failures seen on QEMU targets: printing "TSC
frequency is ZERO" and reset forever.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 drivers/timer/tsc_timer.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Simon Glass June 23, 2018, 2:21 p.m. UTC | #1
On 23 June 2018 at 04:03, Bin Meng <bmeng.cn@gmail.com> wrote:
> With the introduction of early timer support in the TSC driver,
> the capability of getting clock rate from device tree was lost
> unfortunately. Now we bring such functionality back, but with a
> limitation that when TSC is used as early timer, specifying clock
> rate from device tree does not work.
>
> This fixes random boot failures seen on QEMU targets: printing "TSC
> frequency is ZERO" and reset forever.
>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> ---
>
>  drivers/timer/tsc_timer.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Bin Meng June 26, 2018, 10:59 a.m. UTC | #2
On Sat, Jun 23, 2018 at 10:21 PM, Simon Glass <sjg@chromium.org> wrote:
> On 23 June 2018 at 04:03, Bin Meng <bmeng.cn@gmail.com> wrote:
>> With the introduction of early timer support in the TSC driver,
>> the capability of getting clock rate from device tree was lost
>> unfortunately. Now we bring such functionality back, but with a
>> limitation that when TSC is used as early timer, specifying clock
>> rate from device tree does not work.
>>
>> This fixes random boot failures seen on QEMU targets: printing "TSC
>> frequency is ZERO" and reset forever.
>>
>> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
>> ---
>>
>>  drivers/timer/tsc_timer.c | 13 +++++++++++--
>>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>

applied to u-boot-x86, thanks!
diff mbox series

Patch

diff --git a/drivers/timer/tsc_timer.c b/drivers/timer/tsc_timer.c
index cf86999..747f190 100644
--- a/drivers/timer/tsc_timer.c
+++ b/drivers/timer/tsc_timer.c
@@ -377,14 +377,23 @@  static int tsc_timer_probe(struct udevice *dev)
 {
 	struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
 
-	tsc_timer_ensure_setup();
-	uc_priv->clock_rate = gd->arch.clock_rate;
+	if (!uc_priv->clock_rate) {
+		tsc_timer_ensure_setup();
+		uc_priv->clock_rate = gd->arch.clock_rate;
+	} else {
+		gd->arch.tsc_base = rdtsc();
+	}
 
 	return 0;
 }
 
 unsigned long notrace timer_early_get_rate(void)
 {
+	/*
+	 * When TSC timer is used as the early timer, be warned that the timer
+	 * clock rate can only be calibrated via some hardware ways. Specifying
+	 * it in the device tree won't work for the early timer.
+	 */
 	tsc_timer_ensure_setup();
 
 	return gd->arch.clock_rate;