Skip to content

Commit 8bc691b

Browse files
jamin-aspeedlegoater
authored andcommitted
hw/timer/aspeed: Add AST2700 Support
The timer controller include 8 sets of 32-bit decrement counters, based on either PCLK or 1MHZ clock and the design of timer controller between AST2600 and AST2700 are almost the same. TIMER0 – TIMER7 has their own individual control and interrupt status register. In other words, users are able to set timer control in register TMC10 with different TIMER base address and clear timer control and interrupt status in register TMC14 with different TIMER base address. Introduce new "aspeed_2700_timer_read" and "aspeed_2700_timer_write" callback functions and a new ast2700 class to support AST2700. The base address of TIMER0 to TIMER7 as following. Base Address of Timer 0 = 0x12C1_0000 Base Address of Timer 1 = 0x12C1_0040 Base Address of Timer 2 = 0x12C1_0080 Base Address of Timer 3 = 0x12C1_00C0 Base Address of Timer 4 = 0x12C1_0100 Base Address of Timer 5 = 0x12C1_0140 Base Address of Timer 6 = 0x12C1_0180 Base Address of Timer 7 = 0x12C1_01C0 The register address space of each TIMER is "0x40" , and uses the following formula to get the index and register of each TIMER. timer_index = offset >> 6; timer_offset = offset & 0x3f; The TMC010 is a counter control set and interrupt status register. Write "1" to TMC10[3:0] will set the specific bits to "1". Introduce a new "aspeed_2700_timer_set_ctrl" function to handle this register behavior. The TMC014 is a counter control clear and interrupt status register, to clear the specific bits to "0", it should write "1" to TMC14[3:0] on the same bit position. Introduce a new "aspeed_2700_timer_clear_ctrl" function to handle this register behavior. TMC014 does not support read operation. Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com> Acked-by: Cédric Le Goater <clg@redhat.com> Link: https://lore.kernel.org/r/20250113064455.1660564-3-jamin_lin@aspeedtech.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
1 parent ef2385b commit 8bc691b

File tree

2 files changed

+209
-0
lines changed

2 files changed

+209
-0
lines changed

hw/timer/aspeed_timer.c

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,197 @@ static void aspeed_2600_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
618618
}
619619
}
620620

621+
static void aspeed_2700_timer_set_ctrl(AspeedTimerCtrlState *s, int index,
622+
uint32_t reg)
623+
{
624+
const uint8_t overflow_interrupt_mask = BIT(op_overflow_interrupt);
625+
const uint8_t external_clock_mask = BIT(op_external_clock);
626+
const uint8_t pulse_enable_mask = BIT(op_pulse_enable);
627+
const uint8_t enable_mask = BIT(op_enable);
628+
AspeedTimer *t;
629+
uint8_t t_old;
630+
uint8_t t_new;
631+
int shift;
632+
633+
/*
634+
* Only 1 will set the specific bits to 1
635+
* Handle a dependency between the 'enable' and remaining three
636+
* configuration bits - i.e. if more than one bit in the control set has
637+
* set, including the 'enable' bit, perform configuration and then
638+
* enable the timer.
639+
* Interrupt Status bit should not be set.
640+
*/
641+
642+
t = &s->timers[index];
643+
shift = index * TIMER_CTRL_BITS;
644+
645+
t_old = (s->ctrl >> shift) & TIMER_CTRL_MASK;
646+
t_new = reg & TIMER_CTRL_MASK;
647+
648+
if (!(t_old & external_clock_mask) &&
649+
(t_new & external_clock_mask)) {
650+
aspeed_timer_ctrl_external_clock(t, true);
651+
s->ctrl = deposit32(s->ctrl, shift + op_external_clock, 1, 1);
652+
}
653+
654+
if (!(t_old & overflow_interrupt_mask) &&
655+
(t_new & overflow_interrupt_mask)) {
656+
aspeed_timer_ctrl_overflow_interrupt(t, true);
657+
s->ctrl = deposit32(s->ctrl, shift + op_overflow_interrupt, 1, 1);
658+
}
659+
660+
661+
if (!(t_old & pulse_enable_mask) &&
662+
(t_new & pulse_enable_mask)) {
663+
aspeed_timer_ctrl_pulse_enable(t, true);
664+
s->ctrl = deposit32(s->ctrl, shift + op_pulse_enable, 1, 1);
665+
}
666+
667+
/* If we are enabling, do so last */
668+
if (!(t_old & enable_mask) &&
669+
(t_new & enable_mask)) {
670+
aspeed_timer_ctrl_enable(t, true);
671+
s->ctrl = deposit32(s->ctrl, shift + op_enable, 1, 1);
672+
}
673+
}
674+
675+
static void aspeed_2700_timer_clear_ctrl(AspeedTimerCtrlState *s, int index,
676+
uint32_t reg)
677+
{
678+
const uint8_t overflow_interrupt_mask = BIT(op_overflow_interrupt);
679+
const uint8_t external_clock_mask = BIT(op_external_clock);
680+
const uint8_t pulse_enable_mask = BIT(op_pulse_enable);
681+
const uint8_t enable_mask = BIT(op_enable);
682+
AspeedTimer *t;
683+
uint8_t t_old;
684+
uint8_t t_new;
685+
int shift;
686+
687+
/*
688+
* Only 1 will clear the specific bits to 0
689+
* Handle a dependency between the 'enable' and remaining three
690+
* configuration bits - i.e. if more than one bit in the control set has
691+
* clear, including the 'enable' bit, then disable the timer and perform
692+
* configuration
693+
*/
694+
695+
t = &s->timers[index];
696+
shift = index * TIMER_CTRL_BITS;
697+
698+
t_old = (s->ctrl >> shift) & TIMER_CTRL_MASK;
699+
t_new = reg & TIMER_CTRL_MASK;
700+
701+
/* If we are disabling, do so first */
702+
if ((t_old & enable_mask) &&
703+
(t_new & enable_mask)) {
704+
aspeed_timer_ctrl_enable(t, false);
705+
s->ctrl = deposit32(s->ctrl, shift + op_enable, 1, 0);
706+
}
707+
708+
if ((t_old & external_clock_mask) &&
709+
(t_new & external_clock_mask)) {
710+
aspeed_timer_ctrl_external_clock(t, false);
711+
s->ctrl = deposit32(s->ctrl, shift + op_external_clock, 1, 0);
712+
}
713+
714+
if ((t_old & overflow_interrupt_mask) &&
715+
(t_new & overflow_interrupt_mask)) {
716+
aspeed_timer_ctrl_overflow_interrupt(t, false);
717+
s->ctrl = deposit32(s->ctrl, shift + op_overflow_interrupt, 1, 0);
718+
}
719+
720+
if ((t_old & pulse_enable_mask) &&
721+
(t_new & pulse_enable_mask)) {
722+
aspeed_timer_ctrl_pulse_enable(t, false);
723+
s->ctrl = deposit32(s->ctrl, shift + op_pulse_enable, 1, 0);
724+
}
725+
726+
/* Clear interrupt status */
727+
if (reg & 0x10000) {
728+
s->irq_sts = deposit32(s->irq_sts, index, 1, 0);
729+
}
730+
}
731+
732+
static uint64_t aspeed_2700_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
733+
{
734+
uint32_t timer_offset = offset & 0x3f;
735+
int timer_index = offset >> 6;
736+
uint64_t value = 0;
737+
738+
if (timer_index >= ASPEED_TIMER_NR_TIMERS) {
739+
qemu_log_mask(LOG_GUEST_ERROR,
740+
"%s: offset 0x%" PRIx64 " out of bounds\n",
741+
__func__, offset);
742+
return 0;
743+
}
744+
745+
switch (timer_offset) {
746+
/*
747+
* Counter Status
748+
* Counter Reload
749+
* Counter First Matching
750+
* Counter Second Matching
751+
*/
752+
case 0x00 ... 0x0C:
753+
value = aspeed_timer_get_value(&s->timers[timer_index],
754+
timer_offset >> 2);
755+
break;
756+
/* Counter Control and Interrupt Status */
757+
case 0x10:
758+
value = deposit64(value, 0, 4,
759+
extract32(s->ctrl, timer_index * 4, 4));
760+
value = deposit64(value, 16, 1,
761+
extract32(s->irq_sts, timer_index, 1));
762+
break;
763+
default:
764+
qemu_log_mask(LOG_GUEST_ERROR, "%s: no getter for offset 0x%"
765+
PRIx64"\n", __func__, offset);
766+
value = 0;
767+
break;
768+
}
769+
trace_aspeed_timer_read(offset, value);
770+
return value;
771+
}
772+
773+
static void aspeed_2700_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
774+
uint64_t value)
775+
{
776+
const uint32_t timer_value = (uint32_t)(value & 0xFFFFFFFF);
777+
uint32_t timer_offset = offset & 0x3f;
778+
int timer_index = offset >> 6;
779+
780+
if (timer_index >= ASPEED_TIMER_NR_TIMERS) {
781+
qemu_log_mask(LOG_GUEST_ERROR,
782+
"%s: offset 0x%" PRIx64 " out of bounds\n",
783+
__func__, offset);
784+
}
785+
786+
switch (timer_offset) {
787+
/*
788+
* Counter Status
789+
* Counter Reload
790+
* Counter First Matching
791+
* Counter Second Matching
792+
*/
793+
case 0x00 ... 0x0C:
794+
aspeed_timer_set_value(s, timer_index, timer_offset >> 2,
795+
timer_value);
796+
break;
797+
/* Counter Control Set and Interrupt Status */
798+
case 0x10:
799+
aspeed_2700_timer_set_ctrl(s, timer_index, timer_value);
800+
break;
801+
/* Counter Control Clear and Interrupr Status */
802+
case 0x14:
803+
aspeed_2700_timer_clear_ctrl(s, timer_index, timer_value);
804+
break;
805+
default:
806+
qemu_log_mask(LOG_GUEST_ERROR, "%s: no setter for offset 0x%"
807+
PRIx64"\n", __func__, offset);
808+
break;
809+
}
810+
}
811+
621812
static void aspeed_init_one_timer(AspeedTimerCtrlState *s, uint8_t id)
622813
{
623814
AspeedTimer *t = &s->timers[id];
@@ -788,13 +979,30 @@ static const TypeInfo aspeed_1030_timer_info = {
788979
.class_init = aspeed_1030_timer_class_init,
789980
};
790981

982+
static void aspeed_2700_timer_class_init(ObjectClass *klass, void *data)
983+
{
984+
DeviceClass *dc = DEVICE_CLASS(klass);
985+
AspeedTimerClass *awc = ASPEED_TIMER_CLASS(klass);
986+
987+
dc->desc = "ASPEED 2700 Timer";
988+
awc->read = aspeed_2700_timer_read;
989+
awc->write = aspeed_2700_timer_write;
990+
}
991+
992+
static const TypeInfo aspeed_2700_timer_info = {
993+
.name = TYPE_ASPEED_2700_TIMER,
994+
.parent = TYPE_ASPEED_TIMER,
995+
.class_init = aspeed_2700_timer_class_init,
996+
};
997+
791998
static void aspeed_timer_register_types(void)
792999
{
7931000
type_register_static(&aspeed_timer_info);
7941001
type_register_static(&aspeed_2400_timer_info);
7951002
type_register_static(&aspeed_2500_timer_info);
7961003
type_register_static(&aspeed_2600_timer_info);
7971004
type_register_static(&aspeed_1030_timer_info);
1005+
type_register_static(&aspeed_2700_timer_info);
7981006
}
7991007

8001008
type_init(aspeed_timer_register_types)

include/hw/timer/aspeed_timer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ OBJECT_DECLARE_TYPE(AspeedTimerCtrlState, AspeedTimerClass, ASPEED_TIMER)
3232
#define TYPE_ASPEED_2500_TIMER TYPE_ASPEED_TIMER "-ast2500"
3333
#define TYPE_ASPEED_2600_TIMER TYPE_ASPEED_TIMER "-ast2600"
3434
#define TYPE_ASPEED_1030_TIMER TYPE_ASPEED_TIMER "-ast1030"
35+
#define TYPE_ASPEED_2700_TIMER TYPE_ASPEED_TIMER "-ast2700"
3536

3637
#define ASPEED_TIMER_NR_TIMERS 8
3738

0 commit comments

Comments
 (0)