Skip to content

Commit cd49878

Browse files
committed
[platform][vc4] fix time resolution, start genet driver, fix rpi2-test build
1 parent 6177b60 commit cd49878

File tree

5 files changed

+53
-14
lines changed

5 files changed

+53
-14
lines changed

arch/vc4/timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ static enum handler_return timer0_irq(void *arg);
1010

1111
lk_bigtime_t current_time_hires(void) {
1212
//TODO, deal with rollover
13-
return ( ((lk_bigtime_t)*REG32(ST_CHI)) << 32) | *REG32(ST_CLO);
13+
return (( ((lk_bigtime_t)*REG32(ST_CHI)) << 32) | *REG32(ST_CLO)) / 1000;
1414
}
1515

1616
lk_time_t current_time(void) {
17-
return *REG32(ST_CLO);
17+
return current_time_hires();
1818
}
1919

2020
static platform_timer_callback timer_cb = 0;;

platform/bcm28xx/genet.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// based on drivers/net/ethernet/broadcom/genet/bcmgenet.c from linux
2+
// for PHY control, look at the cmd_bits variable in drivers/net/ethernet/broadcom/genet/bcmmii.c
3+
4+
#include <lk/reg.h>
5+
#include <stdio.h>
6+
#include <lk/console_cmd.h>
7+
#include <platform/bcm28xx.h>
8+
#include <lk/debug.h>
9+
10+
static int cmd_genet_dump(int argc, const cmd_args *argv);
11+
12+
STATIC_COMMAND_START
13+
STATIC_COMMAND("dump_genet", "print genet information", &cmd_genet_dump)
14+
STATIC_COMMAND_END(genet);
15+
16+
#define SYS_REV_CTRL (GENET_BASE + 0x0)
17+
18+
static int cmd_genet_dump(int argc, const cmd_args *argv) {
19+
uint32_t reg = *REG32(SYS_REV_CTRL);
20+
uint8_t major = (reg >> 24 & 0x0f);
21+
if (major == 6) major = 5;
22+
else if (major == 5) major = 4;
23+
else if (major == 0) major = 1;
24+
25+
dprintf(INFO, "found GENET controller version %d\n", major);
26+
return 0;
27+
}

platform/bcm28xx/include/platform/bcm28xx.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#define SMI_BASE (BCM_PERIPH_BASE_VIRT + 0x600000)
5656
#define BSC1_BASE (BCM_PERIPH_BASE_VIRT + 0x804000)
5757
#define USB_BASE (BCM_PERIPH_BASE_VIRT + 0x980000)
58+
#define GENET_BASE (0x7d580000) // TODO, this is before the normal BCM_PERIPH_BASE_VIRT bank
5859
#define MCORE_BASE (BCM_PERIPH_BASE_VIRT + 0x0000)
5960

6061
#define ST_CS (ST_BASE + 0x0)
@@ -70,12 +71,14 @@
7071
#define IC0_SRC0 (IC0_BASE + 0x8)
7172
#define IC0_SRC1 (IC0_BASE + 0xc)
7273
#define IC0_VADDR (IC0_BASE + 0x30)
74+
#define IC0_WAKEUP (IC0_BASE + 0x34)
7375

7476
#define IC1_C (IC1_BASE + 0x0)
7577
#define IC1_S (IC1_BASE + 0x4)
7678
#define IC1_SRC0 (IC1_BASE + 0x8)
7779
#define IC1_SRC1 (IC1_BASE + 0xc)
7880
#define IC1_VADDR (IC1_BASE + 0x30)
81+
#define IC1_WAKEUP (IC1_BASE + 0x34)
7982

8083
#define PM_PASSWORD 0x5a000000
8184
#define PM_RSTC (PM_BASE + 0x1c)

platform/bcm28xx/rules.mk

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,28 @@ MODULE := $(LOCAL_DIR)
55
WITH_SMP := 1
66
#LK_HEAP_IMPLEMENTATION ?= dlmalloc
77

8-
ifeq ($(ARCJ),arm)
9-
MODULE_DEPS := \
8+
# 1st pass to set arch
9+
ifeq ($(TARGET),rpi2)
10+
ARCH := arm
11+
ARM_CPU := cortex-a7
12+
GLOBAL_DEFINES += CRYSTAL=19200000
13+
else ifeq ($(TARGET),rpi3)
14+
ARCH := arm64
15+
ARM_CPU := cortex-a53
16+
GLOBAL_DEFINES += CRYSTAL=19200000
17+
else ifeq ($(TARGET),rpi4-vpu)
18+
ARCH ?= vc4
19+
GLOBAL_DEFINES += CRYSTAL=54000000
20+
endif
21+
22+
23+
ifeq ($(ARCH),arm)
24+
MODULE_DEPS += \
1025
dev/timer/arm_generic \
1126
lib/cbuf
12-
MODULE_SRCS +=
27+
MODULE_SRCS += \
1328
$(LOCAL_DIR)/mailbox.c \
29+
$(LOCAL_DIR)/intc.c \
1430

1531
endif
1632

@@ -24,7 +40,7 @@ endif
2440
MODULE_SRCS += \
2541
$(LOCAL_DIR)/gpio.c \
2642
$(LOCAL_DIR)/platform.c \
27-
#$(LOCAL_DIR)/intc.c \
43+
$(LOCAL_DIR)/pll_read.c \
2844

2945

3046
MEMBASE := 0x00000000
@@ -36,8 +52,6 @@ LINKER_SCRIPT += \
3652
$(BUILDDIR)/system-onesegment.ld
3753

3854
ifeq ($(TARGET),rpi2)
39-
ARCH := arm
40-
ARM_CPU := cortex-a7
4155
# put our kernel at 0x80000000
4256
KERNEL_BASE = 0x80000000
4357
KERNEL_LOAD_OFFSET := 0x00008000
@@ -50,8 +64,6 @@ MODULE_SRCS += \
5064
$(LOCAL_DIR)/uart.c
5165

5266
else ifeq ($(TARGET),rpi3)
53-
ARCH := arm64
54-
ARM_CPU := cortex-a53
5567

5668
KERNEL_LOAD_OFFSET := 0x00080000
5769
MEMSIZE ?= 0x40000000 # 1GB
@@ -70,18 +82,16 @@ MODULE_DEPS += \
7082
app/tests \
7183
lib/fdt
7284
else ifeq ($(TARGET),rpi4-vpu)
73-
ARCH ?= vc4
7485
MEMSIZE ?= 0x1400000 # 20MB
7586
MEMBASE ?= 0
7687
GLOBAL_DEFINES += \
7788
BCM2XXX_VPU=1 SMP_MAX_CPUS=1 \
7889
MEMSIZE=$(MEMSIZE) \
7990
MEMBASE=$(MEMBASE) \
80-
CRYSTAL=54000000 \
8191

8292
MODULE_SRCS += \
8393
$(LOCAL_DIR)/uart.c \
84-
$(LOCAL_DIR)/pll_read.c \
94+
$(LOCAL_DIR)/genet.c \
8595

8696
endif
8797

platform/bcm28xx/uart.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ void uart_init(void) {
102102
// assumes interrupts are contiguous
103103
register_int_handler(INTERRUPT_VC_UART + i, &uart_irq, (void *)i);
104104
uint32_t divisor = calculate_baud_divisor(115200);
105-
dprintf(INFO, "changing divisor to %d\n", divisor);
106105

107106
uart_flush(i);
108107

0 commit comments

Comments
 (0)