This replaces legacy arch/arc/lib/timer.c implementation and allows us to describe ARC Timers in Device Tree. Among other things that way we may properly inherit Timer's clock from CPU's clock s they really run synchronously.master
commit
5cf618ee60
@ -0,0 +1,19 @@ |
||||
/* |
||||
* Copyright (C) 2017 Synopsys, Inc. All rights reserved. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
/include/ "skeleton.dtsi" |
||||
|
||||
/ { |
||||
cpu_card { |
||||
core_clk: core_clk { |
||||
#clock-cells = <0>; |
||||
compatible = "fixed-clock"; |
||||
clock-frequency = <750000000>; |
||||
u-boot,dm-pre-reloc; |
||||
}; |
||||
}; |
||||
}; |
||||
|
@ -0,0 +1,19 @@ |
||||
/* |
||||
* Copyright (C) 2017 Synopsys, Inc. All rights reserved. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
/include/ "skeleton.dtsi" |
||||
|
||||
/ { |
||||
cpu_card { |
||||
core_clk: core_clk { |
||||
#clock-cells = <0>; |
||||
compatible = "fixed-clock"; |
||||
clock-frequency = <100000000>; |
||||
u-boot,dm-pre-reloc; |
||||
}; |
||||
}; |
||||
}; |
||||
|
@ -0,0 +1,17 @@ |
||||
/* |
||||
* Copyright (C) 2017 Synopsys, Inc. All rights reserved. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
/dts-v1/; |
||||
|
||||
/include/ "axc001.dtsi" |
||||
/include/ "axs10x_mb.dtsi" |
||||
|
||||
|
||||
/ { |
||||
chosen { |
||||
stdout-path = &uart0; |
||||
}; |
||||
}; |
||||
|
@ -0,0 +1,17 @@ |
||||
/* |
||||
* Copyright (C) 2017 Synopsys, Inc. All rights reserved. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
/dts-v1/; |
||||
|
||||
/include/ "axc003.dtsi" |
||||
/include/ "axs10x_mb.dtsi" |
||||
|
||||
|
||||
/ { |
||||
chosen { |
||||
stdout-path = &uart0; |
||||
}; |
||||
}; |
||||
|
@ -1,57 +0,0 @@ |
||||
/* |
||||
* Copyright (C) 2015 Synopsys, Inc. All rights reserved. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
/dts-v1/; |
||||
|
||||
#include "skeleton.dtsi" |
||||
|
||||
/ { |
||||
#address-cells = <1>; |
||||
#size-cells = <1>; |
||||
|
||||
aliases { |
||||
console = &uart0; |
||||
}; |
||||
|
||||
clocks { |
||||
apbclk: apbclk { |
||||
compatible = "fixed-clock"; |
||||
clock-frequency = <50000000>; |
||||
#clock-cells = <0>; |
||||
}; |
||||
}; |
||||
|
||||
uart0: serial0@e0022000 { |
||||
compatible = "snps,dw-apb-uart"; |
||||
reg = <0xe0022000 0x1000>; |
||||
reg-shift = <2>; |
||||
reg-io-width = <4>; |
||||
}; |
||||
|
||||
ethernet@e0018000 { |
||||
#interrupt-cells = <1>; |
||||
compatible = "altr,socfpga-stmmac"; |
||||
reg = < 0xe0018000 0x2000 >; |
||||
interrupts = < 25 >; |
||||
interrupt-names = "macirq"; |
||||
phy-mode = "gmii"; |
||||
snps,pbl = < 32 >; |
||||
clocks = <&apbclk>; |
||||
clock-names = "stmmaceth"; |
||||
max-speed = <100>; |
||||
}; |
||||
|
||||
ehci@0xe0040000 { |
||||
compatible = "generic-ehci"; |
||||
reg = < 0xe0040000 0x100 >; |
||||
interrupts = < 8 >; |
||||
}; |
||||
|
||||
ohci@0xe0060000 { |
||||
compatible = "generic-ohci"; |
||||
reg = < 0xe0060000 0x100 >; |
||||
interrupts = < 8 >; |
||||
}; |
||||
}; |
@ -0,0 +1,66 @@ |
||||
/* |
||||
* Copyright (C) 2017 Synopsys, Inc. All rights reserved. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
/ { |
||||
axs10x_mb@e0000000 { |
||||
compatible = "simple-bus"; |
||||
#address-cells = <1>; |
||||
#size-cells = <1>; |
||||
ranges = <0x00000000 0xe0000000 0x10000000>; |
||||
u-boot,dm-pre-reloc; |
||||
|
||||
clocks { |
||||
compatible = "simple-bus"; |
||||
u-boot,dm-pre-reloc; |
||||
|
||||
apbclk: apbclk { |
||||
compatible = "fixed-clock"; |
||||
clock-frequency = <50000000>; |
||||
#clock-cells = <0>; |
||||
}; |
||||
|
||||
uartclk: uartclk { |
||||
compatible = "fixed-clock"; |
||||
clock-frequency = <33333333>; |
||||
#clock-cells = <0>; |
||||
u-boot,dm-pre-reloc; |
||||
}; |
||||
}; |
||||
|
||||
ethernet@18000 { |
||||
#interrupt-cells = <1>; |
||||
compatible = "altr,socfpga-stmmac"; |
||||
reg = < 0x18000 0x2000 >; |
||||
interrupts = < 25 >; |
||||
interrupt-names = "macirq"; |
||||
phy-mode = "gmii"; |
||||
snps,pbl = < 32 >; |
||||
clocks = <&apbclk>; |
||||
clock-names = "stmmaceth"; |
||||
max-speed = <100>; |
||||
}; |
||||
|
||||
ehci@0x40000 { |
||||
compatible = "generic-ehci"; |
||||
reg = < 0x40000 0x100 >; |
||||
interrupts = < 8 >; |
||||
}; |
||||
|
||||
ohci@0x60000 { |
||||
compatible = "generic-ohci"; |
||||
reg = < 0x60000 0x100 >; |
||||
interrupts = < 8 >; |
||||
}; |
||||
|
||||
uart0: serial0@22000 { |
||||
compatible = "snps,dw-apb-uart"; |
||||
reg = <0x22000 0x100>; |
||||
clocks = <&uartclk>; |
||||
reg-shift = <2>; |
||||
reg-io-width = <4>; |
||||
}; |
||||
}; |
||||
}; |
@ -1,24 +0,0 @@ |
||||
/*
|
||||
* Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <asm/arcregs.h> |
||||
|
||||
#define NH_MODE (1 << 1) /* Disable timer if CPU is halted */ |
||||
|
||||
int timer_init(void) |
||||
{ |
||||
write_aux_reg(ARC_AUX_TIMER0_CTRL, NH_MODE); |
||||
/* Set max value for counter/timer */ |
||||
write_aux_reg(ARC_AUX_TIMER0_LIMIT, 0xffffffff); |
||||
/* Set initial count value and restart counter/timer */ |
||||
write_aux_reg(ARC_AUX_TIMER0_CNT, 0); |
||||
return 0; |
||||
} |
||||
|
||||
unsigned long timer_read_counter(void) |
||||
{ |
||||
return read_aux_reg(ARC_AUX_TIMER0_CNT); |
||||
} |
@ -0,0 +1,24 @@ |
||||
ARC Timer |
||||
|
||||
Required properties: |
||||
|
||||
- compatible : should be "snps,arc-timer". |
||||
- reg : Specifies timer ID, could be either 0 or 1. |
||||
- clocks : Specifies clocks that drives the counter. |
||||
|
||||
Examples: |
||||
|
||||
timer@0 { |
||||
compatible = "snps,arc-timer"; |
||||
clocks = <&core_clk>; |
||||
reg = <0>; |
||||
}; |
||||
|
||||
timer@1 { |
||||
compatible = "snps,arc-timer"; |
||||
clocks = <&core_clk>; |
||||
reg = <1>; |
||||
}; |
||||
|
||||
NOTE: if you specify both timers, clocks always should be the same |
||||
as each timer is driven by the same core clock. |
@ -0,0 +1,113 @@ |
||||
/*
|
||||
* Copyright (C) 2016 Synopsys, Inc. All rights reserved. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <dm.h> |
||||
#include <errno.h> |
||||
#include <timer.h> |
||||
#include <asm/arcregs.h> |
||||
#include <asm/io.h> |
||||
|
||||
DECLARE_GLOBAL_DATA_PTR; |
||||
|
||||
#define NH_MODE (1 << 1) |
||||
|
||||
/*
|
||||
* ARC timer control registers are mapped to auxiliary address space. |
||||
* There are special ARC asm command to access that addresses. |
||||
* Therefore we use built-in functions to read from and write to timer |
||||
* control register. |
||||
*/ |
||||
|
||||
/* Driver private data. Contains timer id. Could be either 0 or 1. */ |
||||
struct arc_timer_priv { |
||||
uint timer_id; |
||||
}; |
||||
|
||||
static int arc_timer_get_count(struct udevice *dev, u64 *count) |
||||
{ |
||||
u32 val = 0; |
||||
struct arc_timer_priv *priv = dev_get_priv(dev); |
||||
|
||||
switch (priv->timer_id) { |
||||
case 0: |
||||
val = read_aux_reg(ARC_AUX_TIMER0_CNT); |
||||
break; |
||||
case 1: |
||||
val = read_aux_reg(ARC_AUX_TIMER1_CNT); |
||||
break; |
||||
} |
||||
*count = timer_conv_64(val); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int arc_timer_probe(struct udevice *dev) |
||||
{ |
||||
int id; |
||||
struct arc_timer_priv *priv = dev_get_priv(dev); |
||||
|
||||
/* Get registers offset and size */ |
||||
id = fdtdec_get_int(gd->fdt_blob, dev->of_offset, "reg", -1); |
||||
if (id < 0) |
||||
return -EINVAL; |
||||
|
||||
if (id > 1) |
||||
return -ENXIO; |
||||
|
||||
priv->timer_id = (uint)id; |
||||
|
||||
/*
|
||||
* In ARC core there're special registers (Auxiliary or AUX) in its |
||||
* separate memory space that are used for accessing some hardware |
||||
* features of the core. They are not mapped in normal memory space |
||||
* and also always have the same location regardless core configuration. |
||||
* Thus to simplify understanding of the programming model we chose to |
||||
* access AUX regs of Timer0 and Timer1 separately instead of using |
||||
* offsets from some base address. |
||||
*/ |
||||
|
||||
switch (priv->timer_id) { |
||||
case 0: |
||||
/* Disable timer if CPU is halted */ |
||||
write_aux_reg(ARC_AUX_TIMER0_CTRL, NH_MODE); |
||||
/* Set max value for counter/timer */ |
||||
write_aux_reg(ARC_AUX_TIMER0_LIMIT, 0xffffffff); |
||||
/* Set initial count value and restart counter/timer */ |
||||
write_aux_reg(ARC_AUX_TIMER0_CNT, 0); |
||||
break; |
||||
case 1: |
||||
/* Disable timer if CPU is halted */ |
||||
write_aux_reg(ARC_AUX_TIMER1_CTRL, NH_MODE); |
||||
/* Set max value for counter/timer */ |
||||
write_aux_reg(ARC_AUX_TIMER1_LIMIT, 0xffffffff); |
||||
/* Set initial count value and restart counter/timer */ |
||||
write_aux_reg(ARC_AUX_TIMER1_CNT, 0); |
||||
break; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
|
||||
static const struct timer_ops arc_timer_ops = { |
||||
.get_count = arc_timer_get_count, |
||||
}; |
||||
|
||||
static const struct udevice_id arc_timer_ids[] = { |
||||
{ .compatible = "snps,arc-timer" }, |
||||
{} |
||||
}; |
||||
|
||||
U_BOOT_DRIVER(arc_timer) = { |
||||
.name = "arc_timer", |
||||
.id = UCLASS_TIMER, |
||||
.of_match = arc_timer_ids, |
||||
.probe = arc_timer_probe, |
||||
.ops = &arc_timer_ops, |
||||
.flags = DM_FLAG_PRE_RELOC, |
||||
.priv_auto_alloc_size = sizeof(struct arc_timer_priv), |
||||
}; |
Loading…
Reference in new issue