Skip to content

Commit da5f0ae

Browse files
housellsf37
authored andcommitted
Add Quartz64 support
This adds support for the Pine64 Quartz64 and other devices based on the Rockchip RK3566. The platform support is adapted from the Rockpro64 code, except that the RK356x has A55 cores, and adjusting for the fact that the ARM Generic Timer is the only on-chip timer available. Signed-off-by: Peter S. Housel <[email protected]>
1 parent b96c122 commit da5f0ae

File tree

6 files changed

+189
-1
lines changed

6 files changed

+189
-1
lines changed

libplatsupport/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ elseif(${KernelArch} STREQUAL "riscv")
8282
list(APPEND irqchip_modules "-Wl,--undefined=riscv_plic_ptr")
8383
endif()
8484

85-
if(KernelPlatformQEMUArmVirt)
85+
if(KernelPlatformQEMUArmVirt OR KernelPlatformQuartz64)
8686
if(KernelArmExportPCNTUser AND KernelArmExportPTMRUser)
8787
list(APPEND deps src/arch/arm/generic_ltimer.c)
8888
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright 2019, Data61, CSIRO (ABN 41 687 119 230)
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#pragma once
8+
9+
enum clk_id {
10+
CLK_MASTER,
11+
NCLOCKS,
12+
};
13+
14+
enum clock_gate {
15+
NCLKGATES
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright 2019, Data61, CSIRO (ABN 41 687 119 230)
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#pragma once
8+
9+
#include <platsupport/io.h>
10+
11+
enum i2c_id {
12+
NI2C
13+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2019, Data61, CSIRO (ABN 41 687 119 230)
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#pragma once
8+
9+
#define UART0_PADDR 0xFDD50000
10+
#define UART1_PADDR 0xFE650000
11+
#define UART2_PADDR 0xFE660000
12+
#define UART3_PADDR 0xFE670000
13+
#define UART4_PADDR 0xFE680000
14+
15+
#define UART0_IRQ 148
16+
#define UART1_IRQ 149
17+
#define UART2_IRQ 150
18+
#define UART3_IRQ 151
19+
#define UART4_IRQ 152
20+
21+
enum chardev_id {
22+
RP_UART0,
23+
RP_UART1,
24+
RP_UART2,
25+
RP_UART3,
26+
RP_UART4,
27+
/* Aliases */
28+
PS_SERIAL0 = RP_UART0,
29+
PS_SERIAL1 = RP_UART1,
30+
PS_SERIAL2 = RP_UART2,
31+
PS_SERIAL3 = RP_UART3,
32+
PS_SERIAL4 = RP_UART4,
33+
/* defaults */
34+
PS_SERIAL_DEFAULT = RP_UART2
35+
};
36+
37+
#define DEFAULT_SERIAL_PADDR UART2_PADDR
38+
#define DEFAULT_SERIAL_INTERRUPT UART2_IRQ
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2019, Data61, CSIRO (ABN 41 687 119 230)
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
/**
8+
* Contains the definition for all character devices on this platform.
9+
* Currently this is just a simple patch.
10+
*/
11+
12+
#include "../../chardev.h"
13+
#include "../../common.h"
14+
#include <utils/util.h>
15+
16+
static const int uart1_irqs[] = {UART1_IRQ, -1};
17+
static const int uart2_irqs[] = {UART2_IRQ, -1};
18+
static const int uart3_irqs[] = {UART3_IRQ, -1};
19+
static const int uart4_irqs[] = {UART4_IRQ, -1};
20+
21+
22+
#define UART_DEFN(devid) { \
23+
.id = RP_UART##devid, \
24+
.paddr = UART##devid##_PADDR, \
25+
.size = BIT(12), \
26+
.irqs = uart##devid##_irqs, \
27+
.init_fn = &uart_init \
28+
}
29+
30+
31+
static const struct dev_defn dev_defn[] = {
32+
UART_DEFN(1),
33+
UART_DEFN(2),
34+
UART_DEFN(3),
35+
UART_DEFN(4),
36+
};
37+
38+
struct ps_chardevice *
39+
ps_cdev_init(enum chardev_id id, const ps_io_ops_t *o, struct ps_chardevice *d)
40+
{
41+
unsigned int i;
42+
for (i = 0; i < ARRAY_SIZE(dev_defn); i++) {
43+
if (dev_defn[i].id == id) {
44+
return (dev_defn[i].init_fn(dev_defn + i, o, d)) ? NULL : d;
45+
}
46+
}
47+
return NULL;
48+
}
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2019, Data61, CSIRO (ABN 41 687 119 230)
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#include <string.h>
8+
#include <stdlib.h>
9+
#include <platsupport/serial.h>
10+
#include "../../chardev.h"
11+
12+
#define RHR 0x00
13+
#define THR 0x00
14+
#define IER 0x04
15+
#define LSR 0x14
16+
#define RHR_MASK MASK(8)
17+
#define IER_RHRIT BIT(0)
18+
#define LSR_TXFIFOE BIT(5)
19+
#define LSR_RXFIFOE BIT(0)
20+
21+
#define REG_PTR(base, off) ((volatile uint32_t *)((base) + (off)))
22+
23+
int uart_getchar(ps_chardevice_t *d)
24+
{
25+
int ch = EOF;
26+
27+
if (*REG_PTR(d->vaddr, LSR) & LSR_RXFIFOE) {
28+
ch = *REG_PTR(d->vaddr, RHR) & RHR_MASK;
29+
}
30+
return ch;
31+
}
32+
33+
int uart_putchar(ps_chardevice_t *d, int c)
34+
{
35+
if (c == '\n' && (d->flags & SERIAL_AUTO_CR)) {
36+
uart_putchar(d, '\r');
37+
}
38+
while (!(*REG_PTR(d->vaddr, LSR) & LSR_TXFIFOE)) {
39+
continue;
40+
}
41+
*REG_PTR(d->vaddr, THR) = c;
42+
43+
return c;
44+
}
45+
46+
static void uart_handle_irq(ps_chardevice_t *d UNUSED)
47+
{
48+
/* nothing to do */
49+
}
50+
51+
int uart_init(const struct dev_defn *defn,
52+
const ps_io_ops_t *ops,
53+
ps_chardevice_t *dev)
54+
{
55+
memset(dev, 0, sizeof(*dev));
56+
void *vaddr = chardev_map(defn, ops);
57+
if (vaddr == NULL) {
58+
return -1;
59+
}
60+
61+
/* Set up all the device properties. */
62+
dev->id = defn->id;
63+
dev->vaddr = (void *)vaddr;
64+
dev->read = &uart_read;
65+
dev->write = &uart_write;
66+
dev->handle_irq = &uart_handle_irq;
67+
dev->irqs = defn->irqs;
68+
dev->ioops = *ops;
69+
dev->flags = SERIAL_AUTO_CR;
70+
71+
*REG_PTR(dev->vaddr, IER) = IER_RHRIT;
72+
return 0;
73+
}

0 commit comments

Comments
 (0)