forked from Mirrors/opensbi
top: Rename "plat" to "platform" everywhere
This patch renames "plat" to "platform" everywhere for better readablility. Signed-off-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:
314
platform/common/fdt.c
Normal file
314
platform/common/fdt.c
Normal file
@@ -0,0 +1,314 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <plat/fdt.h>
|
||||
|
||||
#define FDT_MAGIC 0xd00dfeed
|
||||
#define FDT_VERSION 17
|
||||
|
||||
struct fdt_header {
|
||||
u32 magic;
|
||||
u32 totalsize;
|
||||
u32 off_dt_struct;
|
||||
u32 off_dt_strings;
|
||||
u32 off_mem_rsvmap;
|
||||
u32 version;
|
||||
u32 last_comp_version; /* <= 17 */
|
||||
u32 boot_cpuid_phys;
|
||||
u32 size_dt_strings;
|
||||
u32 size_dt_struct;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define FDT_BEGIN_NODE 1
|
||||
#define FDT_END_NODE 2
|
||||
#define FDT_PROP 3
|
||||
#define FDT_NOP 4
|
||||
#define FDT_END 9
|
||||
|
||||
u32 fdt_rev32(u32 v)
|
||||
{
|
||||
return ((v & 0x000000FF) << 24) |
|
||||
((v & 0x0000FF00) << 8) |
|
||||
((v & 0x00FF0000) >> 8) |
|
||||
((v & 0xFF000000) >> 24);
|
||||
}
|
||||
|
||||
ulong fdt_strlen(const char *str)
|
||||
{
|
||||
ulong ret = 0;
|
||||
|
||||
while (*str != '\0') {
|
||||
ret++;
|
||||
str++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fdt_strcmp(const char *a, const char *b)
|
||||
{
|
||||
/* search first diff or end of string */
|
||||
for (; *a == *b && *a != '\0'; a++, b++);
|
||||
return *a - *b;
|
||||
}
|
||||
|
||||
int fdt_prop_string_index(const struct fdt_prop *prop,
|
||||
const char *str)
|
||||
{
|
||||
int i;
|
||||
ulong l = 0;
|
||||
const char *p, *end;
|
||||
|
||||
p = prop->value;
|
||||
end = p + prop->len;
|
||||
|
||||
for (i = 0; p < end; i++, p += l) {
|
||||
l = fdt_strlen(p) + 1;
|
||||
if (p + l > end)
|
||||
return -1;
|
||||
if (fdt_strcmp(str, p) == 0)
|
||||
return i; /* Found it; return index */
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct recursive_iter_info {
|
||||
void (*fn)(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv);
|
||||
void *fn_priv;
|
||||
const char *str;
|
||||
};
|
||||
|
||||
#define DATA32(ptr) fdt_rev32(*((u32*)ptr))
|
||||
|
||||
static void recursive_iter(char **data, struct recursive_iter_info *info,
|
||||
const struct fdt_node *parent)
|
||||
{
|
||||
struct fdt_node node;
|
||||
struct fdt_prop prop;
|
||||
|
||||
if (DATA32(*data) != FDT_BEGIN_NODE)
|
||||
return;
|
||||
|
||||
node.data = *data;
|
||||
|
||||
(*data) += sizeof(u32);
|
||||
|
||||
node.parent = parent;
|
||||
node.name = *data;
|
||||
|
||||
*data += fdt_strlen(*data) + 1;
|
||||
while ((ulong)(*data) % sizeof(u32) != 0)
|
||||
(*data)++;
|
||||
|
||||
node.depth = (parent) ? (parent->depth + 1) : 1;
|
||||
|
||||
/* Default cell counts, as per the FDT spec */
|
||||
node.address_cells = 2;
|
||||
node.size_cells = 1;
|
||||
|
||||
info->fn(&node, NULL, info->fn_priv);
|
||||
|
||||
while (DATA32(*data) != FDT_END_NODE) {
|
||||
switch (DATA32(*data)) {
|
||||
case FDT_PROP:
|
||||
prop.node = &node;
|
||||
*data += sizeof(u32);
|
||||
prop.len = DATA32(*data);
|
||||
*data += sizeof(u32);
|
||||
prop.name = &info->str[DATA32(*data)];
|
||||
*data += sizeof(u32);
|
||||
prop.value = *data;
|
||||
*data += prop.len;
|
||||
while ((ulong)(*data) % sizeof(u32) != 0)
|
||||
(*data)++;
|
||||
info->fn(&node, &prop, info->fn_priv);
|
||||
break;
|
||||
case FDT_NOP:
|
||||
*data += sizeof(u32);
|
||||
break;
|
||||
case FDT_BEGIN_NODE:
|
||||
recursive_iter(data, info, &node);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
*data += sizeof(u32);
|
||||
}
|
||||
|
||||
struct match_iter_info {
|
||||
int (*match)(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv);
|
||||
void *match_priv;
|
||||
void (*fn)(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv);
|
||||
void *fn_priv;
|
||||
const char *str;
|
||||
};
|
||||
|
||||
static void match_iter(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv)
|
||||
{
|
||||
char *data;
|
||||
struct match_iter_info *minfo = priv;
|
||||
struct fdt_prop nprop;
|
||||
|
||||
/* Do nothing if node+prop dont match */
|
||||
if (!minfo->match(node, prop, minfo->match_priv))
|
||||
return;
|
||||
|
||||
/* Call function for node */
|
||||
if (minfo->fn)
|
||||
minfo->fn(node, NULL, minfo->fn_priv);
|
||||
|
||||
/* Convert node to character stream */
|
||||
data = node->data;
|
||||
data += sizeof(u32);
|
||||
|
||||
/* Skip node name */
|
||||
data += fdt_strlen(data) + 1;
|
||||
while ((ulong)(data) % sizeof(u32) != 0)
|
||||
data++;
|
||||
|
||||
/* Find node property and its value */
|
||||
while (DATA32(data) == FDT_PROP) {
|
||||
nprop.node = node;
|
||||
data += sizeof(u32);
|
||||
nprop.len = DATA32(data);
|
||||
data += sizeof(u32);
|
||||
nprop.name = &minfo->str[DATA32(data)];
|
||||
data += sizeof(u32);
|
||||
nprop.value = data;
|
||||
data += nprop.len;
|
||||
while ((ulong)(data) % sizeof(u32) != 0)
|
||||
(data)++;
|
||||
/* Call function for every property */
|
||||
if (minfo->fn)
|
||||
minfo->fn(node, &nprop, minfo->fn_priv);
|
||||
}
|
||||
}
|
||||
|
||||
int fdt_match_node_prop(void *fdt,
|
||||
int (*match)(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv),
|
||||
void *match_priv,
|
||||
void (*fn)(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv),
|
||||
void *fn_priv)
|
||||
{
|
||||
char *data;
|
||||
u32 string_offset, data_offset;
|
||||
struct fdt_header *header;
|
||||
struct match_iter_info minfo;
|
||||
struct recursive_iter_info rinfo;
|
||||
|
||||
if (!fdt || !match)
|
||||
return -1;
|
||||
|
||||
header = fdt;
|
||||
if (fdt_rev32(header->magic) != FDT_MAGIC ||
|
||||
fdt_rev32(header->last_comp_version) > FDT_VERSION)
|
||||
return -1;
|
||||
string_offset = fdt_rev32(header->off_dt_strings);
|
||||
data_offset = fdt_rev32(header->off_dt_struct);
|
||||
|
||||
minfo.match = match;
|
||||
minfo.match_priv = match_priv;
|
||||
minfo.fn = fn;
|
||||
minfo.fn_priv = fn_priv;
|
||||
minfo.str = (const char *)(fdt + string_offset);
|
||||
|
||||
rinfo.fn = match_iter;
|
||||
rinfo.fn_priv = &minfo;
|
||||
rinfo.str = minfo.str;
|
||||
|
||||
data = (char *)(fdt + data_offset);
|
||||
recursive_iter(&data, &rinfo, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct match_compat_info {
|
||||
const char *compat;
|
||||
};
|
||||
|
||||
static int match_compat(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv)
|
||||
{
|
||||
struct match_compat_info *cinfo = priv;
|
||||
|
||||
if (!prop)
|
||||
return 0;
|
||||
|
||||
if (fdt_strcmp(prop->name, "compatible"))
|
||||
return 0;
|
||||
|
||||
if (fdt_prop_string_index(prop, cinfo->compat) < 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fdt_compat_node_prop(void *fdt,
|
||||
const char *compat,
|
||||
void (*fn)(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv),
|
||||
void *fn_priv)
|
||||
{
|
||||
struct match_compat_info cinfo = { .compat = compat };
|
||||
|
||||
return fdt_match_node_prop(fdt, match_compat, &cinfo,
|
||||
fn, fn_priv);
|
||||
}
|
||||
|
||||
static int match_walk(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv)
|
||||
{
|
||||
if (!prop)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fdt_walk(void *fdt,
|
||||
void (*fn)(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv),
|
||||
void *fn_priv)
|
||||
{
|
||||
return fdt_match_node_prop(fdt, match_walk, NULL,
|
||||
fn, fn_priv);
|
||||
}
|
||||
|
||||
u32 fdt_size(void *fdt)
|
||||
{
|
||||
struct fdt_header *header;
|
||||
|
||||
if (!fdt)
|
||||
return 0;
|
||||
|
||||
header = fdt;
|
||||
if (fdt_rev32(header->magic) != FDT_MAGIC ||
|
||||
fdt_rev32(header->last_comp_version) > FDT_VERSION)
|
||||
return 0;
|
||||
|
||||
return fdt_rev32(header->totalsize);
|
||||
}
|
73
platform/common/include/plat/fdt.h
Normal file
73
platform/common/include/plat/fdt.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef __FDT_H__
|
||||
#define __FDT_H__
|
||||
|
||||
#include <sbi/sbi_types.h>
|
||||
|
||||
struct fdt_node {
|
||||
char *data;
|
||||
const struct fdt_node *parent;
|
||||
const char *name;
|
||||
int depth;
|
||||
int address_cells;
|
||||
int size_cells;
|
||||
};
|
||||
|
||||
struct fdt_prop {
|
||||
const struct fdt_node *node;
|
||||
const char *name;
|
||||
void *value;
|
||||
u32 len;
|
||||
};
|
||||
|
||||
/* Reverse byte-order of 32bit number */
|
||||
u32 fdt_rev32(u32 v);
|
||||
|
||||
/* Length of a string */
|
||||
ulong fdt_strlen(const char *str);
|
||||
|
||||
/* Compate two strings */
|
||||
int fdt_strcmp(const char *a, const char *b);
|
||||
|
||||
/* Find index of matching string from a list of strings */
|
||||
int fdt_prop_string_index(const struct fdt_prop *prop,
|
||||
const char *str);
|
||||
|
||||
/* Iterate over each property of matching node */
|
||||
int fdt_match_node_prop(void *fdt,
|
||||
int (*match)(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv),
|
||||
void *match_priv,
|
||||
void (*fn)(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv),
|
||||
void *fn_priv);
|
||||
|
||||
/* Iterate over each property of compatible node */
|
||||
int fdt_compat_node_prop(void *fdt,
|
||||
const char *compat,
|
||||
void (*fn)(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv),
|
||||
void *fn_priv);
|
||||
|
||||
/* Iterate over each node and property */
|
||||
int fdt_walk(void *fdt,
|
||||
void (*fn)(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv),
|
||||
void *fn_priv);
|
||||
|
||||
/* Get size of FDT */
|
||||
u32 fdt_size(void *fdt);
|
||||
|
||||
#endif
|
22
platform/common/include/plat/irqchip/plic.h
Normal file
22
platform/common/include/plat/irqchip/plic.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef __IRQCHIP_PLIC_H__
|
||||
#define __IRQCHIP_PLIC_H__
|
||||
|
||||
#include <sbi/sbi_types.h>
|
||||
|
||||
int plic_fdt_fixup(void *fdt, const char *compat);
|
||||
|
||||
int plic_warm_irqchip_init(u32 target_hart);
|
||||
|
||||
int plic_cold_irqchip_init(unsigned long base,
|
||||
u32 num_sources, u32 hart_count);
|
||||
|
||||
#endif
|
22
platform/common/include/plat/serial/sifive-uart.h
Normal file
22
platform/common/include/plat/serial/sifive-uart.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef __SERIAL_SIFIVE_UART_H__
|
||||
#define __SERIAL_SIFIVE_UART_H__
|
||||
|
||||
#include <sbi/sbi_types.h>
|
||||
|
||||
void sifive_uart_putc(char ch);
|
||||
|
||||
char sifive_uart_getc(void);
|
||||
|
||||
int sifive_uart_init(unsigned long base,
|
||||
u32 in_freq, u32 baudrate);
|
||||
|
||||
#endif
|
23
platform/common/include/plat/serial/uart8250.h
Normal file
23
platform/common/include/plat/serial/uart8250.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef __SERIAL_UART8250_H__
|
||||
#define __SERIAL_UART8250_H__
|
||||
|
||||
#include <sbi/sbi_types.h>
|
||||
|
||||
void uart8250_putc(char ch);
|
||||
|
||||
char uart8250_getc(void);
|
||||
|
||||
int uart8250_init(unsigned long base,
|
||||
u32 in_freq, u32 baudrate,
|
||||
u32 reg_shift, u32 reg_width);
|
||||
|
||||
#endif
|
35
platform/common/include/plat/sys/clint.h
Normal file
35
platform/common/include/plat/sys/clint.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef __SYS_CLINT_H__
|
||||
#define __SYS_CLINT_H__
|
||||
|
||||
#include <sbi/sbi_types.h>
|
||||
|
||||
void clint_ipi_inject(u32 target_hart, u32 source_hart);
|
||||
|
||||
void clint_ipi_sync(u32 target_hart, u32 source_hart);
|
||||
|
||||
void clint_ipi_clear(u32 target_hart);
|
||||
|
||||
int clint_warm_ipi_init(u32 target_hart);
|
||||
|
||||
int clint_cold_ipi_init(unsigned long base, u32 hart_count);
|
||||
|
||||
u64 clint_timer_value(void);
|
||||
|
||||
void clint_timer_event_stop(u32 target_hart);
|
||||
|
||||
void clint_timer_event_start(u32 target_hart, u64 next_event);
|
||||
|
||||
int clint_warm_timer_init(u32 target_hart);
|
||||
|
||||
int clint_cold_timer_init(unsigned long base, u32 hart_count);
|
||||
|
||||
#endif
|
10
platform/common/irqchip/objects.mk
Normal file
10
platform/common/irqchip/objects.mk
Normal file
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
#
|
||||
# Authors:
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
|
||||
platform-common-objs-$(PLATFORM_IRQCHIP_PLIC) += irqchip/plic.o
|
118
platform/common/irqchip/plic.c
Normal file
118
platform/common/irqchip/plic.c
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <sbi/riscv_io.h>
|
||||
#include <plat/fdt.h>
|
||||
#include <plat/irqchip/plic.h>
|
||||
|
||||
#define PLIC_PRIORITY_BASE 0x0
|
||||
#define PLIC_PENDING_BASE 0x1000
|
||||
#define PLIC_ENABLE_BASE 0x2000
|
||||
#define PLIC_ENABLE_STRIDE 0x80
|
||||
#define PLIC_CONTEXT_BASE 0x200000
|
||||
#define PLIC_CONTEXT_STRIDE 0x1000
|
||||
|
||||
static u32 plic_hart_count;
|
||||
static u32 plic_num_sources;
|
||||
static volatile void *plic_base;
|
||||
|
||||
static void plic_set_priority(u32 source, u32 val)
|
||||
{
|
||||
writel(val, plic_base);
|
||||
}
|
||||
|
||||
static void plic_set_m_thresh(u32 hartid, u32 val)
|
||||
{
|
||||
volatile void *plic_m_thresh = plic_base +
|
||||
PLIC_CONTEXT_BASE +
|
||||
PLIC_CONTEXT_STRIDE * (2 * hartid);
|
||||
writel(val, plic_m_thresh);
|
||||
}
|
||||
|
||||
static void plic_set_s_thresh(u32 hartid, u32 val)
|
||||
{
|
||||
volatile void *plic_s_thresh = plic_base +
|
||||
PLIC_CONTEXT_BASE +
|
||||
PLIC_CONTEXT_STRIDE * (2 * hartid + 1);
|
||||
writel(val, plic_s_thresh);
|
||||
}
|
||||
|
||||
static void plic_set_s_ie(u32 hartid, u32 word_index, u32 val)
|
||||
{
|
||||
volatile void *plic_s_ie = plic_base +
|
||||
PLIC_ENABLE_BASE +
|
||||
PLIC_ENABLE_STRIDE * (2 * hartid + 1);
|
||||
writel(val, plic_s_ie + word_index * 4);
|
||||
}
|
||||
|
||||
static void plic_fdt_fixup_prop(const struct fdt_node *node,
|
||||
const struct fdt_prop *prop,
|
||||
void *priv)
|
||||
{
|
||||
u32 *cells;
|
||||
u32 i, cells_count;
|
||||
|
||||
if (!prop)
|
||||
return;
|
||||
if (fdt_strcmp(prop->name, "interrupts-extended"))
|
||||
return;
|
||||
|
||||
cells = prop->value;
|
||||
cells_count = prop->len / sizeof(u32);
|
||||
|
||||
if (!cells_count)
|
||||
return;
|
||||
|
||||
for (i = 0; i < cells_count; i++) {
|
||||
if (i % 4 == 1)
|
||||
cells[i] = fdt_rev32(0xffffffff);
|
||||
}
|
||||
}
|
||||
|
||||
int plic_fdt_fixup(void *fdt, const char *compat)
|
||||
{
|
||||
fdt_compat_node_prop(fdt, compat, plic_fdt_fixup_prop, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int plic_warm_irqchip_init(u32 target_hart)
|
||||
{
|
||||
size_t i, ie_words = plic_num_sources / 32 + 1;
|
||||
|
||||
if (plic_hart_count <= target_hart)
|
||||
return -1;
|
||||
|
||||
/* By default, enable all IRQs for S-mode of target HART */
|
||||
for (i = 0; i < ie_words; i++)
|
||||
plic_set_s_ie(target_hart, i, -1);
|
||||
|
||||
/* By default, enable M-mode threshold */
|
||||
plic_set_m_thresh(target_hart, 1);
|
||||
|
||||
/* By default, disable S-mode threshold */
|
||||
plic_set_s_thresh(target_hart, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int plic_cold_irqchip_init(unsigned long base,
|
||||
u32 num_sources, u32 hart_count)
|
||||
{
|
||||
int i;
|
||||
|
||||
plic_hart_count = hart_count;
|
||||
plic_num_sources = num_sources;
|
||||
plic_base = (void *)base;
|
||||
|
||||
/* Configure default priorities of all IRQs */
|
||||
for (i = 0; i < plic_num_sources; i++)
|
||||
plic_set_priority(i, 1);
|
||||
|
||||
return 0;
|
||||
}
|
10
platform/common/objects.mk
Normal file
10
platform/common/objects.mk
Normal file
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
#
|
||||
# Authors:
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
|
||||
platform-common-objs-y += fdt.o
|
11
platform/common/serial/objects.mk
Normal file
11
platform/common/serial/objects.mk
Normal file
@@ -0,0 +1,11 @@
|
||||
#
|
||||
# Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
#
|
||||
# Authors:
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
|
||||
platform-common-objs-$(PLATFORM_SERIAL_UART8250) += serial/uart8250.o
|
||||
platform-common-objs-$(PLATFORM_SERIAL_SIFIVE_UART) += serial/sifive-uart.o
|
97
platform/common/serial/sifive-uart.c
Normal file
97
platform/common/serial/sifive-uart.c
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <sbi/riscv_io.h>
|
||||
#include <sbi/sbi_console.h>
|
||||
#include <plat/serial/sifive-uart.h>
|
||||
|
||||
#define UART_REG_TXFIFO 0
|
||||
#define UART_REG_RXFIFO 1
|
||||
#define UART_REG_TXCTRL 2
|
||||
#define UART_REG_RXCTRL 3
|
||||
#define UART_REG_IE 4
|
||||
#define UART_REG_IP 5
|
||||
#define UART_REG_DIV 6
|
||||
|
||||
#define UART_TXFIFO_FULL 0x80000000
|
||||
#define UART_RXFIFO_EMPTY 0x80000000
|
||||
#define UART_RXFIFO_DATA 0x000000ff
|
||||
#define UART_TXCTRL_TXEN 0x1
|
||||
#define UART_RXCTRL_RXEN 0x1
|
||||
|
||||
static volatile void *uart_base;
|
||||
static u32 uart_in_freq;
|
||||
static u32 uart_baudrate;
|
||||
|
||||
/**
|
||||
* Find minimum divisor divides in_freq to max_target_hz;
|
||||
* Based on uart driver n SiFive FSBL.
|
||||
*
|
||||
* f_baud = f_in / (div + 1) => div = (f_in / f_baud) - 1
|
||||
* The nearest integer solution requires rounding up as to not exceed max_target_hz.
|
||||
* div = ceil(f_in / f_baud) - 1
|
||||
* = floor((f_in - 1 + f_baud) / f_baud) - 1
|
||||
* This should not overflow as long as (f_in - 1 + f_baud) does not exceed
|
||||
* 2^32 - 1, which is unlikely since we represent frequencies in kHz.
|
||||
*/
|
||||
static inline unsigned int uart_min_clk_divisor(uint64_t in_freq,
|
||||
uint64_t max_target_hz)
|
||||
{
|
||||
uint64_t quotient = (in_freq + max_target_hz - 1) / (max_target_hz);
|
||||
// Avoid underflow
|
||||
if (quotient == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return quotient - 1;
|
||||
}
|
||||
}
|
||||
|
||||
static u32 get_reg(u32 num)
|
||||
{
|
||||
return readl(uart_base + (num * 0x4));
|
||||
}
|
||||
|
||||
static void set_reg(u32 num, u32 val)
|
||||
{
|
||||
writel(val, uart_base + (num * 0x4));
|
||||
}
|
||||
|
||||
void sifive_uart_putc(char ch)
|
||||
{
|
||||
while (get_reg(UART_REG_TXFIFO) & UART_TXFIFO_FULL);
|
||||
|
||||
set_reg(UART_REG_TXFIFO, ch);
|
||||
}
|
||||
|
||||
char sifive_uart_getc(void)
|
||||
{
|
||||
u32 ret = get_reg(UART_REG_RXFIFO);
|
||||
if (!(ret & UART_RXFIFO_EMPTY))
|
||||
return ret & UART_RXFIFO_DATA;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sifive_uart_init(unsigned long base,
|
||||
u32 in_freq, u32 baudrate)
|
||||
{
|
||||
uart_base = (volatile void *)base;
|
||||
uart_in_freq = in_freq;
|
||||
uart_baudrate = baudrate;
|
||||
|
||||
/* Configure baudrate */
|
||||
set_reg(UART_REG_DIV, uart_min_clk_divisor(in_freq, baudrate));
|
||||
/* Disable interrupts */
|
||||
set_reg(UART_REG_IE, 0);
|
||||
/* Enable TX */
|
||||
set_reg(UART_REG_TXCTRL, UART_TXCTRL_TXEN);
|
||||
/* Enable Rx */
|
||||
set_reg(UART_REG_RXCTRL, UART_RXCTRL_RXEN);
|
||||
|
||||
return 0;
|
||||
}
|
117
platform/common/serial/uart8250.c
Normal file
117
platform/common/serial/uart8250.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <sbi/riscv_io.h>
|
||||
#include <plat/serial/uart8250.h>
|
||||
|
||||
#define UART_RBR_OFFSET 0 /* In: Recieve Buffer Register */
|
||||
#define UART_THR_OFFSET 0 /* Out: Transmitter Holding Register */
|
||||
#define UART_DLL_OFFSET 0 /* Out: Divisor Latch Low */
|
||||
#define UART_IER_OFFSET 1 /* I/O: Interrupt Enable Register */
|
||||
#define UART_DLM_OFFSET 1 /* Out: Divisor Latch High */
|
||||
#define UART_FCR_OFFSET 2 /* Out: FIFO Control Register */
|
||||
#define UART_IIR_OFFSET 2 /* I/O: Interrupt Identification Register */
|
||||
#define UART_LCR_OFFSET 3 /* Out: Line Control Register */
|
||||
#define UART_MCR_OFFSET 4 /* Out: Modem Control Register */
|
||||
#define UART_LSR_OFFSET 5 /* In: Line Status Register */
|
||||
#define UART_MSR_OFFSET 6 /* In: Modem Status Register */
|
||||
#define UART_SCR_OFFSET 7 /* I/O: Scratch Register */
|
||||
#define UART_MDR1_OFFSET 8 /* I/O: Mode Register */
|
||||
|
||||
#define UART_LSR_FIFOE 0x80 /* Fifo error */
|
||||
#define UART_LSR_TEMT 0x40 /* Transmitter empty */
|
||||
#define UART_LSR_THRE 0x20 /* Transmit-hold-register empty */
|
||||
#define UART_LSR_BI 0x10 /* Break interrupt indicator */
|
||||
#define UART_LSR_FE 0x08 /* Frame error indicator */
|
||||
#define UART_LSR_PE 0x04 /* Parity error indicator */
|
||||
#define UART_LSR_OE 0x02 /* Overrun error indicator */
|
||||
#define UART_LSR_DR 0x01 /* Receiver data ready */
|
||||
#define UART_LSR_BRK_ERROR_BITS 0x1E /* BI, FE, PE, OE bits */
|
||||
|
||||
static volatile void *uart8250_base;
|
||||
static u32 uart8250_in_freq;
|
||||
static u32 uart8250_baudrate;
|
||||
static u32 uart8250_reg_width;
|
||||
static u32 uart8250_reg_shift;
|
||||
|
||||
static u32 get_reg(u32 num)
|
||||
{
|
||||
u32 offset = num << uart8250_reg_shift;
|
||||
|
||||
if (uart8250_reg_width == 1)
|
||||
return readb(uart8250_base + offset);
|
||||
else if (uart8250_reg_width == 2)
|
||||
return readw(uart8250_base + offset);
|
||||
else
|
||||
return readl(uart8250_base + offset);
|
||||
}
|
||||
|
||||
static void set_reg(u32 num, u32 val)
|
||||
{
|
||||
u32 offset = num << uart8250_reg_shift;
|
||||
|
||||
if (uart8250_reg_width == 1)
|
||||
writeb(val, uart8250_base + offset);
|
||||
else if (uart8250_reg_width == 2)
|
||||
writew(val, uart8250_base + offset);
|
||||
else
|
||||
writel(val, uart8250_base + offset);
|
||||
}
|
||||
|
||||
void uart8250_putc(char ch)
|
||||
{
|
||||
while ((get_reg(UART_LSR_OFFSET) & UART_LSR_THRE) == 0);
|
||||
|
||||
set_reg(UART_THR_OFFSET, ch);
|
||||
}
|
||||
|
||||
char uart8250_getc(void)
|
||||
{
|
||||
if (get_reg(UART_LSR_OFFSET) & UART_LSR_DR)
|
||||
return get_reg(UART_RBR_OFFSET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uart8250_init(unsigned long base,
|
||||
u32 in_freq, u32 baudrate,
|
||||
u32 reg_shift, u32 reg_width)
|
||||
{
|
||||
u16 bdiv;
|
||||
|
||||
uart8250_base = (volatile void *)base;
|
||||
uart8250_reg_shift = reg_shift;
|
||||
uart8250_reg_width = reg_width;
|
||||
uart8250_in_freq = in_freq;
|
||||
uart8250_baudrate = baudrate;
|
||||
|
||||
bdiv = uart8250_in_freq / (16 * uart8250_baudrate);
|
||||
|
||||
/* Disable all interrupts */
|
||||
set_reg(UART_IER_OFFSET, 0x00);
|
||||
/* Enable DLAB */
|
||||
set_reg(UART_LCR_OFFSET, 0x80);
|
||||
/* Set divisor low byte */
|
||||
set_reg(UART_DLL_OFFSET, bdiv & 0xff);
|
||||
/* Set divisor high byte */
|
||||
set_reg(UART_DLM_OFFSET, (bdiv >> 8) & 0xff);
|
||||
/* 8 bits, no parity, one stop bit */
|
||||
set_reg(UART_LCR_OFFSET, 0x03);
|
||||
/* Enable FIFO */
|
||||
set_reg(UART_FCR_OFFSET, 0x01);
|
||||
/* No modem control DTR RTS */
|
||||
set_reg(UART_MCR_OFFSET, 0x00);
|
||||
/* Clear line status */
|
||||
get_reg(UART_LSR_OFFSET);
|
||||
/* Read receive buffer */
|
||||
get_reg(UART_RBR_OFFSET);
|
||||
/* Set scratchpad */
|
||||
set_reg(UART_SCR_OFFSET, 0x00);
|
||||
|
||||
return 0;
|
||||
}
|
131
platform/common/sys/clint.c
Normal file
131
platform/common/sys/clint.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <sbi/riscv_io.h>
|
||||
#include <sbi/riscv_atomic.h>
|
||||
#include <plat/sys/clint.h>
|
||||
|
||||
static u32 clint_ipi_hart_count;
|
||||
static volatile void *clint_ipi_base;
|
||||
static volatile u32 *clint_ipi;
|
||||
|
||||
void clint_ipi_inject(u32 target_hart, u32 source_hart)
|
||||
{
|
||||
if ((clint_ipi_hart_count <= target_hart) ||
|
||||
(clint_ipi_hart_count <= source_hart))
|
||||
return;
|
||||
|
||||
/* Set CLINT IPI */
|
||||
writel(1, &clint_ipi[target_hart]);
|
||||
}
|
||||
|
||||
void clint_ipi_sync(u32 target_hart, u32 source_hart)
|
||||
{
|
||||
u32 target_ipi, incoming_ipi;
|
||||
|
||||
if ((clint_ipi_hart_count <= target_hart) ||
|
||||
(clint_ipi_hart_count <= source_hart))
|
||||
return;
|
||||
|
||||
/* Wait until target HART has handled IPI */
|
||||
incoming_ipi = 0;
|
||||
while (1) {
|
||||
target_ipi = readl(&clint_ipi[target_hart]);
|
||||
if (!target_ipi)
|
||||
break;
|
||||
|
||||
incoming_ipi |=
|
||||
atomic_raw_xchg_uint(&clint_ipi[source_hart], 0);
|
||||
}
|
||||
|
||||
if (incoming_ipi)
|
||||
writel(incoming_ipi, &clint_ipi[source_hart]);
|
||||
}
|
||||
|
||||
void clint_ipi_clear(u32 target_hart)
|
||||
{
|
||||
if (clint_ipi_hart_count <= target_hart)
|
||||
return;
|
||||
|
||||
/* Clear CLINT IPI */
|
||||
writel(0, &clint_ipi[target_hart]);
|
||||
}
|
||||
|
||||
int clint_warm_ipi_init(u32 target_hart)
|
||||
{
|
||||
if (clint_ipi_hart_count <= target_hart ||
|
||||
!clint_ipi_base)
|
||||
return -1;
|
||||
|
||||
/* Clear CLINT IPI */
|
||||
clint_ipi_clear(target_hart);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int clint_cold_ipi_init(unsigned long base, u32 hart_count)
|
||||
{
|
||||
/* Figure-out CLINT IPI register address */
|
||||
clint_ipi_hart_count = hart_count;
|
||||
clint_ipi_base = (void *)base;
|
||||
clint_ipi = (u32 *)clint_ipi_base;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u32 clint_time_hart_count;
|
||||
static volatile void *clint_time_base;
|
||||
static volatile u64 *clint_time_val;
|
||||
static volatile u64 *clint_time_cmp;
|
||||
|
||||
u64 clint_timer_value(void)
|
||||
{
|
||||
return readq_relaxed(clint_time_val);
|
||||
}
|
||||
|
||||
void clint_timer_event_stop(u32 target_hart)
|
||||
{
|
||||
if (clint_time_hart_count <= target_hart)
|
||||
return;
|
||||
|
||||
/* Clear CLINT Time Compare */
|
||||
writeq_relaxed(-1ULL, &clint_time_cmp[target_hart]);
|
||||
}
|
||||
|
||||
void clint_timer_event_start(u32 target_hart, u64 next_event)
|
||||
{
|
||||
if (clint_time_hart_count <= target_hart)
|
||||
return;
|
||||
|
||||
/* Program CLINT Time Compare */
|
||||
writeq_relaxed(next_event, &clint_time_cmp[target_hart]);
|
||||
}
|
||||
|
||||
int clint_warm_timer_init(u32 target_hart)
|
||||
{
|
||||
if (clint_time_hart_count <= target_hart ||
|
||||
!clint_time_base)
|
||||
return -1;
|
||||
|
||||
/* Clear CLINT Time Compare */
|
||||
writeq_relaxed(-1ULL, &clint_time_cmp[target_hart]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int clint_cold_timer_init(unsigned long base, u32 hart_count)
|
||||
{
|
||||
/* Figure-out CLINT Time register address */
|
||||
clint_time_hart_count = hart_count;
|
||||
clint_time_base = (void *)base;
|
||||
clint_time_val = (u64 *)(clint_time_base + 0xbff8);
|
||||
clint_time_cmp = (u64 *)(clint_time_base + 0x4000);
|
||||
|
||||
return 0;
|
||||
}
|
10
platform/common/sys/objects.mk
Normal file
10
platform/common/sys/objects.mk
Normal file
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
#
|
||||
# Authors:
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
|
||||
platform-common-objs-$(PLATFORM_SYS_CLINT) += sys/clint.o
|
30
platform/kendryte/k210/config.mk
Normal file
30
platform/kendryte/k210/config.mk
Normal file
@@ -0,0 +1,30 @@
|
||||
#
|
||||
# Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
#
|
||||
# Authors:
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
|
||||
# Essential defines required by SBI platform
|
||||
platform-cppflags-y = -DPLAT_NAME="Kendryte K210"
|
||||
platform-cppflags-y+= -DPLAT_HART_COUNT=2
|
||||
platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192
|
||||
|
||||
# Compiler flags
|
||||
platform-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany
|
||||
platform-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany
|
||||
platform-ldflags-y =
|
||||
|
||||
# Common drivers to enable
|
||||
PLATFORM_IRQCHIP_PLIC=y
|
||||
PLATFORM_SYS_CLINT=y
|
||||
|
||||
# Blobs to build
|
||||
FW_TEXT_START=0x80000000
|
||||
FW_JUMP=n
|
||||
FW_PAYLOAD=y
|
||||
FW_PAYLOAD_OFFSET=0x200000
|
||||
FW_PAYLOAD_FDT_ADDR=0x80040000
|
||||
|
10
platform/kendryte/k210/objects.mk
Normal file
10
platform/kendryte/k210/objects.mk
Normal file
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
#
|
||||
# Authors:
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
|
||||
platform-objs-y += uarths.o sysctl.o platform.o
|
128
platform/kendryte/k210/platform.c
Normal file
128
platform/kendryte/k210/platform.c
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <sbi/riscv_encoding.h>
|
||||
#include <sbi/sbi_const.h>
|
||||
#include <sbi/sbi_platform.h>
|
||||
#include <plat/irqchip/plic.h>
|
||||
#include <plat/sys/clint.h>
|
||||
#include "platform.h"
|
||||
#include "uarths.h"
|
||||
|
||||
#define K210_U_SYS_CLK 1000000000
|
||||
#define K210_U_PERIPH_CLK (K210_U_SYS_CLK / 2)
|
||||
|
||||
#define K210_U_PLIC_NUM_SOURCES 0x35
|
||||
#define K210_U_PLIC_NUM_PRIORITIES 7
|
||||
|
||||
static int k210_console_init(void)
|
||||
{
|
||||
uarths_init(115200, UARTHS_STOP_1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void k210_console_putc(char c)
|
||||
{
|
||||
uarths_putc(c);
|
||||
}
|
||||
|
||||
static char k210_console_getc(void)
|
||||
{
|
||||
return uarths_getc();
|
||||
}
|
||||
|
||||
static u32 k210_pmp_region_count(u32 target_hart)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int k210_pmp_region_info(u32 target_hart, u32 index,
|
||||
ulong *prot, ulong *addr, ulong *log2size)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
*prot = PMP_R | PMP_W | PMP_X;
|
||||
*addr = 0;
|
||||
*log2size = __riscv_xlen;
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
break;
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int k210_cold_irqchip_init(void)
|
||||
{
|
||||
return plic_cold_irqchip_init(PLIC_BASE_ADDR,
|
||||
K210_U_PLIC_NUM_SOURCES,
|
||||
PLAT_HART_COUNT);
|
||||
}
|
||||
|
||||
static int k210_cold_ipi_init(void)
|
||||
{
|
||||
return clint_cold_ipi_init(CLINT_BASE_ADDR,
|
||||
PLAT_HART_COUNT);
|
||||
}
|
||||
|
||||
static int k210_cold_timer_init(void)
|
||||
{
|
||||
return clint_cold_timer_init(CLINT_BASE_ADDR,
|
||||
PLAT_HART_COUNT);
|
||||
}
|
||||
|
||||
static int k210_cold_final_init(void)
|
||||
{
|
||||
return plic_fdt_fixup(sbi_scratch_thishart_arg1_ptr(), "riscv,plic0");
|
||||
}
|
||||
|
||||
static int k210_system_down(u32 type)
|
||||
{
|
||||
/* For now nothing to do. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct sbi_platform platform = {
|
||||
|
||||
.name = STRINGIFY(PLAT_NAME),
|
||||
.features = SBI_PLATFORM_HAS_MMIO_TIMER_VALUE,
|
||||
|
||||
.hart_count = PLAT_HART_COUNT,
|
||||
.hart_stack_size = PLAT_HART_STACK_SIZE,
|
||||
|
||||
.pmp_region_count = k210_pmp_region_count,
|
||||
.pmp_region_info = k210_pmp_region_info,
|
||||
|
||||
|
||||
.console_init = k210_console_init,
|
||||
.console_putc = k210_console_putc,
|
||||
.console_getc = k210_console_getc,
|
||||
|
||||
.cold_irqchip_init = k210_cold_irqchip_init,
|
||||
.warm_irqchip_init = plic_warm_irqchip_init,
|
||||
.ipi_inject = clint_ipi_inject,
|
||||
.ipi_sync = clint_ipi_sync,
|
||||
.ipi_clear = clint_ipi_clear,
|
||||
.warm_ipi_init = clint_warm_ipi_init,
|
||||
.cold_ipi_init = k210_cold_ipi_init,
|
||||
.cold_final_init = k210_cold_final_init,
|
||||
|
||||
.timer_value = clint_timer_value,
|
||||
.timer_event_stop = clint_timer_event_stop,
|
||||
.timer_event_start = clint_timer_event_start,
|
||||
.warm_timer_init = clint_warm_timer_init,
|
||||
.cold_timer_init = k210_cold_timer_init,
|
||||
|
||||
.system_reboot = k210_system_down,
|
||||
.system_shutdown = k210_system_down
|
||||
};
|
1448
platform/kendryte/k210/platform.h
Normal file
1448
platform/kendryte/k210/platform.h
Normal file
File diff suppressed because it is too large
Load Diff
1784
platform/kendryte/k210/sysctl.c
Normal file
1784
platform/kendryte/k210/sysctl.c
Normal file
File diff suppressed because it is too large
Load Diff
945
platform/kendryte/k210/sysctl.h
Normal file
945
platform/kendryte/k210/sysctl.h
Normal file
@@ -0,0 +1,945 @@
|
||||
/* Copyright 2018 Canaan Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef _SYSCTL_H_
|
||||
#define _SYSCTL_H_
|
||||
|
||||
#include <sbi/sbi_types.h>
|
||||
#include "platform.h"
|
||||
|
||||
/**
|
||||
* System controller registers
|
||||
*
|
||||
* | Offset | Name | Description |
|
||||
* |-----------|----------------|-------------------------------------|
|
||||
* | 0x00 | git_id | Git short commit id |
|
||||
* | 0x04 | clk_freq | System clock base frequency |
|
||||
* | 0x08 | pll0 | PLL0 controller |
|
||||
* | 0x0c | pll1 | PLL1 controller |
|
||||
* | 0x10 | pll2 | PLL2 controller |
|
||||
* | 0x14 | resv5 | Reserved |
|
||||
* | 0x18 | pll_lock | PLL lock tester |
|
||||
* | 0x1c | rom_error | AXI ROM detector |
|
||||
* | 0x20 | clk_sel0 | Clock select controller0 |
|
||||
* | 0x24 | clk_sel1 | Clock select controller1 |
|
||||
* | 0x28 | clk_en_cent | Central clock enable |
|
||||
* | 0x2c | clk_en_peri | Peripheral clock enable |
|
||||
* | 0x30 | soft_reset | Soft reset ctrl |
|
||||
* | 0x34 | peri_reset | Peripheral reset controller |
|
||||
* | 0x38 | clk_th0 | Clock threshold controller 0 |
|
||||
* | 0x3c | clk_th1 | Clock threshold controller 1 |
|
||||
* | 0x40 | clk_th2 | Clock threshold controller 2 |
|
||||
* | 0x44 | clk_th3 | Clock threshold controller 3 |
|
||||
* | 0x48 | clk_th4 | Clock threshold controller 4 |
|
||||
* | 0x4c | clk_th5 | Clock threshold controller 5 |
|
||||
* | 0x50 | clk_th6 | Clock threshold controller 6 |
|
||||
* | 0x54 | misc | Miscellaneous controller |
|
||||
* | 0x58 | peri | Peripheral controller |
|
||||
* | 0x5c | spi_sleep | SPI sleep controller |
|
||||
* | 0x60 | reset_status | Reset source status |
|
||||
* | 0x64 | dma_sel0 | DMA handshake selector |
|
||||
* | 0x68 | dma_sel1 | DMA handshake selector |
|
||||
* | 0x6c | power_sel | IO Power Mode Select controller |
|
||||
* | 0x70 | resv28 | Reserved |
|
||||
* | 0x74 | resv29 | Reserved |
|
||||
* | 0x78 | resv30 | Reserved |
|
||||
* | 0x7c | resv31 | Reserved |
|
||||
*/
|
||||
|
||||
typedef enum _sysctl_pll_t {
|
||||
SYSCTL_PLL0,
|
||||
SYSCTL_PLL1,
|
||||
SYSCTL_PLL2,
|
||||
SYSCTL_PLL_MAX
|
||||
} sysctl_pll_t;
|
||||
|
||||
typedef enum _sysctl_clock_source_t {
|
||||
SYSCTL_SOURCE_IN0,
|
||||
SYSCTL_SOURCE_PLL0,
|
||||
SYSCTL_SOURCE_PLL1,
|
||||
SYSCTL_SOURCE_PLL2,
|
||||
SYSCTL_SOURCE_ACLK,
|
||||
SYSCTL_SOURCE_MAX
|
||||
} sysctl_clock_source_t;
|
||||
|
||||
typedef enum _sysctl_dma_channel_t {
|
||||
SYSCTL_DMA_CHANNEL_0,
|
||||
SYSCTL_DMA_CHANNEL_1,
|
||||
SYSCTL_DMA_CHANNEL_2,
|
||||
SYSCTL_DMA_CHANNEL_3,
|
||||
SYSCTL_DMA_CHANNEL_4,
|
||||
SYSCTL_DMA_CHANNEL_5,
|
||||
SYSCTL_DMA_CHANNEL_MAX
|
||||
} sysctl_dma_channel_t;
|
||||
|
||||
typedef enum _sysctl_dma_select_t {
|
||||
SYSCTL_DMA_SELECT_SSI0_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_SSI0_TX_REQ,
|
||||
SYSCTL_DMA_SELECT_SSI1_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_SSI1_TX_REQ,
|
||||
SYSCTL_DMA_SELECT_SSI2_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_SSI2_TX_REQ,
|
||||
SYSCTL_DMA_SELECT_SSI3_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_SSI3_TX_REQ,
|
||||
SYSCTL_DMA_SELECT_I2C0_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_I2C0_TX_REQ,
|
||||
SYSCTL_DMA_SELECT_I2C1_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_I2C1_TX_REQ,
|
||||
SYSCTL_DMA_SELECT_I2C2_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_I2C2_TX_REQ,
|
||||
SYSCTL_DMA_SELECT_UART1_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_UART1_TX_REQ,
|
||||
SYSCTL_DMA_SELECT_UART2_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_UART2_TX_REQ,
|
||||
SYSCTL_DMA_SELECT_UART3_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_UART3_TX_REQ,
|
||||
SYSCTL_DMA_SELECT_AES_REQ,
|
||||
SYSCTL_DMA_SELECT_SHA_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_AI_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_FFT_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_FFT_TX_REQ,
|
||||
SYSCTL_DMA_SELECT_I2S0_TX_REQ,
|
||||
SYSCTL_DMA_SELECT_I2S0_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_I2S1_TX_REQ,
|
||||
SYSCTL_DMA_SELECT_I2S1_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_I2S2_TX_REQ,
|
||||
SYSCTL_DMA_SELECT_I2S2_RX_REQ,
|
||||
SYSCTL_DMA_SELECT_I2S0_BF_DIR_REQ,
|
||||
SYSCTL_DMA_SELECT_I2S0_BF_VOICE_REQ,
|
||||
SYSCTL_DMA_SELECT_MAX
|
||||
} sysctl_dma_select_t;
|
||||
|
||||
/**
|
||||
* System controller clock id
|
||||
*/
|
||||
typedef enum _sysctl_clock_t {
|
||||
SYSCTL_CLOCK_PLL0,
|
||||
SYSCTL_CLOCK_PLL1,
|
||||
SYSCTL_CLOCK_PLL2,
|
||||
SYSCTL_CLOCK_CPU,
|
||||
SYSCTL_CLOCK_SRAM0,
|
||||
SYSCTL_CLOCK_SRAM1,
|
||||
SYSCTL_CLOCK_APB0,
|
||||
SYSCTL_CLOCK_APB1,
|
||||
SYSCTL_CLOCK_APB2,
|
||||
SYSCTL_CLOCK_ROM,
|
||||
SYSCTL_CLOCK_DMA,
|
||||
SYSCTL_CLOCK_AI,
|
||||
SYSCTL_CLOCK_DVP,
|
||||
SYSCTL_CLOCK_FFT,
|
||||
SYSCTL_CLOCK_GPIO,
|
||||
SYSCTL_CLOCK_SPI0,
|
||||
SYSCTL_CLOCK_SPI1,
|
||||
SYSCTL_CLOCK_SPI2,
|
||||
SYSCTL_CLOCK_SPI3,
|
||||
SYSCTL_CLOCK_I2S0,
|
||||
SYSCTL_CLOCK_I2S1,
|
||||
SYSCTL_CLOCK_I2S2,
|
||||
SYSCTL_CLOCK_I2C0,
|
||||
SYSCTL_CLOCK_I2C1,
|
||||
SYSCTL_CLOCK_I2C2,
|
||||
SYSCTL_CLOCK_UART1,
|
||||
SYSCTL_CLOCK_UART2,
|
||||
SYSCTL_CLOCK_UART3,
|
||||
SYSCTL_CLOCK_AES,
|
||||
SYSCTL_CLOCK_FPIOA,
|
||||
SYSCTL_CLOCK_TIMER0,
|
||||
SYSCTL_CLOCK_TIMER1,
|
||||
SYSCTL_CLOCK_TIMER2,
|
||||
SYSCTL_CLOCK_WDT0,
|
||||
SYSCTL_CLOCK_WDT1,
|
||||
SYSCTL_CLOCK_SHA,
|
||||
SYSCTL_CLOCK_OTP,
|
||||
SYSCTL_CLOCK_RTC,
|
||||
SYSCTL_CLOCK_ACLK = 40,
|
||||
SYSCTL_CLOCK_HCLK,
|
||||
SYSCTL_CLOCK_IN0,
|
||||
SYSCTL_CLOCK_MAX
|
||||
} sysctl_clock_t;
|
||||
|
||||
/**
|
||||
* System controller clock select id
|
||||
*/
|
||||
typedef enum _sysctl_clock_select_t {
|
||||
SYSCTL_CLOCK_SELECT_PLL0_BYPASS,
|
||||
SYSCTL_CLOCK_SELECT_PLL1_BYPASS,
|
||||
SYSCTL_CLOCK_SELECT_PLL2_BYPASS,
|
||||
SYSCTL_CLOCK_SELECT_PLL2,
|
||||
SYSCTL_CLOCK_SELECT_ACLK,
|
||||
SYSCTL_CLOCK_SELECT_SPI3,
|
||||
SYSCTL_CLOCK_SELECT_TIMER0,
|
||||
SYSCTL_CLOCK_SELECT_TIMER1,
|
||||
SYSCTL_CLOCK_SELECT_TIMER2,
|
||||
SYSCTL_CLOCK_SELECT_SPI3_SAMPLE,
|
||||
SYSCTL_CLOCK_SELECT_MAX = 11
|
||||
} sysctl_clock_select_t;
|
||||
|
||||
/**
|
||||
* System controller clock threshold id
|
||||
*/
|
||||
typedef enum _sysctl_threshold_t {
|
||||
SYSCTL_THRESHOLD_ACLK,
|
||||
SYSCTL_THRESHOLD_APB0,
|
||||
SYSCTL_THRESHOLD_APB1,
|
||||
SYSCTL_THRESHOLD_APB2,
|
||||
SYSCTL_THRESHOLD_SRAM0,
|
||||
SYSCTL_THRESHOLD_SRAM1,
|
||||
SYSCTL_THRESHOLD_AI,
|
||||
SYSCTL_THRESHOLD_DVP,
|
||||
SYSCTL_THRESHOLD_ROM,
|
||||
SYSCTL_THRESHOLD_SPI0,
|
||||
SYSCTL_THRESHOLD_SPI1,
|
||||
SYSCTL_THRESHOLD_SPI2,
|
||||
SYSCTL_THRESHOLD_SPI3,
|
||||
SYSCTL_THRESHOLD_TIMER0,
|
||||
SYSCTL_THRESHOLD_TIMER1,
|
||||
SYSCTL_THRESHOLD_TIMER2,
|
||||
SYSCTL_THRESHOLD_I2S0,
|
||||
SYSCTL_THRESHOLD_I2S1,
|
||||
SYSCTL_THRESHOLD_I2S2,
|
||||
SYSCTL_THRESHOLD_I2S0_M,
|
||||
SYSCTL_THRESHOLD_I2S1_M,
|
||||
SYSCTL_THRESHOLD_I2S2_M,
|
||||
SYSCTL_THRESHOLD_I2C0,
|
||||
SYSCTL_THRESHOLD_I2C1,
|
||||
SYSCTL_THRESHOLD_I2C2,
|
||||
SYSCTL_THRESHOLD_WDT0,
|
||||
SYSCTL_THRESHOLD_WDT1,
|
||||
SYSCTL_THRESHOLD_MAX = 28
|
||||
} sysctl_threshold_t;
|
||||
|
||||
/**
|
||||
* System controller reset control id
|
||||
*/
|
||||
typedef enum _sysctl_reset_t {
|
||||
SYSCTL_RESET_SOC,
|
||||
SYSCTL_RESET_ROM,
|
||||
SYSCTL_RESET_DMA,
|
||||
SYSCTL_RESET_AI,
|
||||
SYSCTL_RESET_DVP,
|
||||
SYSCTL_RESET_FFT,
|
||||
SYSCTL_RESET_GPIO,
|
||||
SYSCTL_RESET_SPI0,
|
||||
SYSCTL_RESET_SPI1,
|
||||
SYSCTL_RESET_SPI2,
|
||||
SYSCTL_RESET_SPI3,
|
||||
SYSCTL_RESET_I2S0,
|
||||
SYSCTL_RESET_I2S1,
|
||||
SYSCTL_RESET_I2S2,
|
||||
SYSCTL_RESET_I2C0,
|
||||
SYSCTL_RESET_I2C1,
|
||||
SYSCTL_RESET_I2C2,
|
||||
SYSCTL_RESET_UART1,
|
||||
SYSCTL_RESET_UART2,
|
||||
SYSCTL_RESET_UART3,
|
||||
SYSCTL_RESET_AES,
|
||||
SYSCTL_RESET_FPIOA,
|
||||
SYSCTL_RESET_TIMER0,
|
||||
SYSCTL_RESET_TIMER1,
|
||||
SYSCTL_RESET_TIMER2,
|
||||
SYSCTL_RESET_WDT0,
|
||||
SYSCTL_RESET_WDT1,
|
||||
SYSCTL_RESET_SHA,
|
||||
SYSCTL_RESET_RTC,
|
||||
SYSCTL_RESET_MAX = 31
|
||||
} sysctl_reset_t;
|
||||
|
||||
typedef enum _sysctl_power_bank {
|
||||
SYSCTL_POWER_BANK0,
|
||||
SYSCTL_POWER_BANK1,
|
||||
SYSCTL_POWER_BANK2,
|
||||
SYSCTL_POWER_BANK3,
|
||||
SYSCTL_POWER_BANK4,
|
||||
SYSCTL_POWER_BANK5,
|
||||
SYSCTL_POWER_BANK6,
|
||||
SYSCTL_POWER_BANK7,
|
||||
SYSCTL_POWER_BANK_MAX,
|
||||
} sysctl_power_bank_t;
|
||||
|
||||
/**
|
||||
* System controller reset control id
|
||||
*/
|
||||
typedef enum _sysctl_io_power_mode {
|
||||
SYSCTL_POWER_V33,
|
||||
SYSCTL_POWER_V18
|
||||
} sysctl_io_power_mode_t;
|
||||
|
||||
/**
|
||||
* Git short commit id
|
||||
* No. 0 Register (0x00)
|
||||
*/
|
||||
typedef struct _sysctl_git_id {
|
||||
u32 git_id : 32;
|
||||
} __attribute__((packed, aligned(4))) sysctl_git_id_t;
|
||||
|
||||
/**
|
||||
* System clock base frequency
|
||||
* No. 1 Register (0x04)
|
||||
*/
|
||||
typedef struct _sysctl_clk_freq {
|
||||
u32 clk_freq : 32;
|
||||
} __attribute__((packed, aligned(4))) sysctl_clk_freq_t;
|
||||
|
||||
/**
|
||||
* PLL0 controller
|
||||
* No. 2 Register (0x08)
|
||||
*/
|
||||
typedef struct _sysctl_pll0 {
|
||||
u32 clkr0 : 4;
|
||||
u32 clkf0 : 6;
|
||||
u32 clkod0 : 4;
|
||||
u32 bwadj0 : 6;
|
||||
u32 pll_reset0 : 1;
|
||||
u32 pll_pwrd0 : 1;
|
||||
u32 pll_intfb0 : 1;
|
||||
u32 pll_bypass0 : 1;
|
||||
u32 pll_test0 : 1;
|
||||
u32 pll_out_en0 : 1;
|
||||
u32 pll_test_en : 1;
|
||||
u32 reserved : 5;
|
||||
} __attribute__((packed, aligned(4))) sysctl_pll0_t;
|
||||
|
||||
/**
|
||||
* PLL1 controller
|
||||
* No. 3 Register (0x0c)
|
||||
*/
|
||||
typedef struct _sysctl_pll1 {
|
||||
u32 clkr1 : 4;
|
||||
u32 clkf1 : 6;
|
||||
u32 clkod1 : 4;
|
||||
u32 bwadj1 : 6;
|
||||
u32 pll_reset1 : 1;
|
||||
u32 pll_pwrd1 : 1;
|
||||
u32 pll_intfb1 : 1;
|
||||
u32 pll_bypass1 : 1;
|
||||
u32 pll_test1 : 1;
|
||||
u32 pll_out_en1 : 1;
|
||||
u32 reserved : 6;
|
||||
} __attribute__((packed, aligned(4))) sysctl_pll1_t;
|
||||
|
||||
/**
|
||||
* PLL2 controller
|
||||
* No. 4 Register (0x10)
|
||||
*/
|
||||
typedef struct _sysctl_pll2 {
|
||||
u32 clkr2 : 4;
|
||||
u32 clkf2 : 6;
|
||||
u32 clkod2 : 4;
|
||||
u32 bwadj2 : 6;
|
||||
u32 pll_reset2 : 1;
|
||||
u32 pll_pwrd2 : 1;
|
||||
u32 pll_intfb2 : 1;
|
||||
u32 pll_bypass2 : 1;
|
||||
u32 pll_test2 : 1;
|
||||
u32 pll_out_en2 : 1;
|
||||
u32 pll_ckin_sel2 : 2;
|
||||
u32 reserved : 4;
|
||||
} __attribute__((packed, aligned(4))) sysctl_pll2_t;
|
||||
|
||||
/**
|
||||
* PLL lock tester
|
||||
* No. 6 Register (0x18)
|
||||
*/
|
||||
typedef struct _sysctl_pll_lock {
|
||||
u32 pll_lock0 : 2;
|
||||
u32 pll_slip_clear0 : 1;
|
||||
u32 test_clk_out0 : 1;
|
||||
u32 reserved0 : 4;
|
||||
u32 pll_lock1 : 2;
|
||||
u32 pll_slip_clear1 : 1;
|
||||
u32 test_clk_out1 : 1;
|
||||
u32 reserved1 : 4;
|
||||
u32 pll_lock2 : 2;
|
||||
u32 pll_slip_clear2 : 1;
|
||||
u32 test_clk_out2 : 1;
|
||||
u32 reserved2 : 12;
|
||||
} __attribute__((packed, aligned(4))) sysctl_pll_lock_t;
|
||||
|
||||
/**
|
||||
* AXI ROM detector
|
||||
* No. 7 Register (0x1c)
|
||||
*/
|
||||
typedef struct _sysctl_rom_error {
|
||||
u32 rom_mul_error : 1;
|
||||
u32 rom_one_error : 1;
|
||||
u32 reserved : 30;
|
||||
} __attribute__((packed, aligned(4))) sysctl_rom_error_t;
|
||||
|
||||
/**
|
||||
* Clock select controller0
|
||||
* No. 8 Register (0x20)
|
||||
*/
|
||||
typedef struct _sysctl_clk_sel0 {
|
||||
u32 aclk_sel : 1;
|
||||
u32 aclk_divider_sel : 2;
|
||||
u32 apb0_clk_sel : 3;
|
||||
u32 apb1_clk_sel : 3;
|
||||
u32 apb2_clk_sel : 3;
|
||||
u32 spi3_clk_sel : 1;
|
||||
u32 timer0_clk_sel : 1;
|
||||
u32 timer1_clk_sel : 1;
|
||||
u32 timer2_clk_sel : 1;
|
||||
u32 reserved : 16;
|
||||
} __attribute__((packed, aligned(4))) sysctl_clk_sel0_t;
|
||||
|
||||
/**
|
||||
* Clock select controller1
|
||||
* No. 9 Register (0x24)
|
||||
*/
|
||||
typedef struct _sysctl_clk_sel1 {
|
||||
u32 spi3_sample_clk_sel : 1;
|
||||
u32 reserved0 : 30;
|
||||
u32 reserved1 : 1;
|
||||
} __attribute__((packed, aligned(4))) sysctl_clk_sel1_t;
|
||||
|
||||
/**
|
||||
* Central clock enable
|
||||
* No. 10 Register (0x28)
|
||||
*/
|
||||
typedef struct _sysctl_clk_en_cent {
|
||||
u32 cpu_clk_en : 1;
|
||||
u32 sram0_clk_en : 1;
|
||||
u32 sram1_clk_en : 1;
|
||||
u32 apb0_clk_en : 1;
|
||||
u32 apb1_clk_en : 1;
|
||||
u32 apb2_clk_en : 1;
|
||||
u32 reserved : 26;
|
||||
} __attribute__((packed, aligned(4))) sysctl_clk_en_cent_t;
|
||||
|
||||
/**
|
||||
* Peripheral clock enable
|
||||
* No. 11 Register (0x2c)
|
||||
*/
|
||||
typedef struct _sysctl_clk_en_peri {
|
||||
u32 rom_clk_en : 1;
|
||||
u32 dma_clk_en : 1;
|
||||
u32 ai_clk_en : 1;
|
||||
u32 dvp_clk_en : 1;
|
||||
u32 fft_clk_en : 1;
|
||||
u32 gpio_clk_en : 1;
|
||||
u32 spi0_clk_en : 1;
|
||||
u32 spi1_clk_en : 1;
|
||||
u32 spi2_clk_en : 1;
|
||||
u32 spi3_clk_en : 1;
|
||||
u32 i2s0_clk_en : 1;
|
||||
u32 i2s1_clk_en : 1;
|
||||
u32 i2s2_clk_en : 1;
|
||||
u32 i2c0_clk_en : 1;
|
||||
u32 i2c1_clk_en : 1;
|
||||
u32 i2c2_clk_en : 1;
|
||||
u32 uart1_clk_en : 1;
|
||||
u32 uart2_clk_en : 1;
|
||||
u32 uart3_clk_en : 1;
|
||||
u32 aes_clk_en : 1;
|
||||
u32 fpioa_clk_en : 1;
|
||||
u32 timer0_clk_en : 1;
|
||||
u32 timer1_clk_en : 1;
|
||||
u32 timer2_clk_en : 1;
|
||||
u32 wdt0_clk_en : 1;
|
||||
u32 wdt1_clk_en : 1;
|
||||
u32 sha_clk_en : 1;
|
||||
u32 otp_clk_en : 1;
|
||||
u32 reserved : 1;
|
||||
u32 rtc_clk_en : 1;
|
||||
u32 reserved0 : 2;
|
||||
} __attribute__((packed, aligned(4))) sysctl_clk_en_peri_t;
|
||||
|
||||
/**
|
||||
* Soft reset ctrl
|
||||
* No. 12 Register (0x30)
|
||||
*/
|
||||
typedef struct _sysctl_soft_reset {
|
||||
u32 soft_reset : 1;
|
||||
u32 reserved : 31;
|
||||
} __attribute__((packed, aligned(4))) sysctl_soft_reset_t;
|
||||
|
||||
/**
|
||||
* Peripheral reset controller
|
||||
* No. 13 Register (0x34)
|
||||
*/
|
||||
typedef struct _sysctl_peri_reset {
|
||||
u32 rom_reset : 1;
|
||||
u32 dma_reset : 1;
|
||||
u32 ai_reset : 1;
|
||||
u32 dvp_reset : 1;
|
||||
u32 fft_reset : 1;
|
||||
u32 gpio_reset : 1;
|
||||
u32 spi0_reset : 1;
|
||||
u32 spi1_reset : 1;
|
||||
u32 spi2_reset : 1;
|
||||
u32 spi3_reset : 1;
|
||||
u32 i2s0_reset : 1;
|
||||
u32 i2s1_reset : 1;
|
||||
u32 i2s2_reset : 1;
|
||||
u32 i2c0_reset : 1;
|
||||
u32 i2c1_reset : 1;
|
||||
u32 i2c2_reset : 1;
|
||||
u32 uart1_reset : 1;
|
||||
u32 uart2_reset : 1;
|
||||
u32 uart3_reset : 1;
|
||||
u32 aes_reset : 1;
|
||||
u32 fpioa_reset : 1;
|
||||
u32 timer0_reset : 1;
|
||||
u32 timer1_reset : 1;
|
||||
u32 timer2_reset : 1;
|
||||
u32 wdt0_reset : 1;
|
||||
u32 wdt1_reset : 1;
|
||||
u32 sha_reset : 1;
|
||||
u32 reserved : 2;
|
||||
u32 rtc_reset : 1;
|
||||
u32 reserved0 : 2;
|
||||
} __attribute__((packed, aligned(4))) sysctl_peri_reset_t;
|
||||
|
||||
/**
|
||||
* Clock threshold controller 0
|
||||
* No. 14 Register (0x38)
|
||||
*/
|
||||
typedef struct _sysctl_clk_th0 {
|
||||
u32 sram0_gclk_threshold : 4;
|
||||
u32 sram1_gclk_threshold : 4;
|
||||
u32 ai_gclk_threshold : 4;
|
||||
u32 dvp_gclk_threshold : 4;
|
||||
u32 rom_gclk_threshold : 4;
|
||||
u32 reserved : 12;
|
||||
} __attribute__((packed, aligned(4))) sysctl_clk_th0_t;
|
||||
|
||||
/**
|
||||
* Clock threshold controller 1
|
||||
* No. 15 Register (0x3c)
|
||||
*/
|
||||
typedef struct _sysctl_clk_th1 {
|
||||
u32 spi0_clk_threshold : 8;
|
||||
u32 spi1_clk_threshold : 8;
|
||||
u32 spi2_clk_threshold : 8;
|
||||
u32 spi3_clk_threshold : 8;
|
||||
} __attribute__((packed, aligned(4))) sysctl_clk_th1_t;
|
||||
|
||||
/**
|
||||
* Clock threshold controller 2
|
||||
* No. 16 Register (0x40)
|
||||
*/
|
||||
typedef struct _sysctl_clk_th2 {
|
||||
u32 timer0_clk_threshold : 8;
|
||||
u32 timer1_clk_threshold : 8;
|
||||
u32 timer2_clk_threshold : 8;
|
||||
u32 reserved : 8;
|
||||
} __attribute__((packed, aligned(4))) sysctl_clk_th2_t;
|
||||
|
||||
/**
|
||||
* Clock threshold controller 3
|
||||
* No. 17 Register (0x44)
|
||||
*/
|
||||
typedef struct _sysctl_clk_th3 {
|
||||
u32 i2s0_clk_threshold : 16;
|
||||
u32 i2s1_clk_threshold : 16;
|
||||
} __attribute__((packed, aligned(4))) sysctl_clk_th3_t;
|
||||
|
||||
/**
|
||||
* Clock threshold controller 4
|
||||
* No. 18 Register (0x48)
|
||||
*/
|
||||
typedef struct _sysctl_clk_th4 {
|
||||
u32 i2s2_clk_threshold : 16;
|
||||
u32 i2s0_mclk_threshold : 8;
|
||||
u32 i2s1_mclk_threshold : 8;
|
||||
} __attribute__((packed, aligned(4))) sysctl_clk_th4_t;
|
||||
|
||||
/**
|
||||
* Clock threshold controller 5
|
||||
* No. 19 Register (0x4c)
|
||||
*/
|
||||
typedef struct _sysctl_clk_th5 {
|
||||
u32 i2s2_mclk_threshold : 8;
|
||||
u32 i2c0_clk_threshold : 8;
|
||||
u32 i2c1_clk_threshold : 8;
|
||||
u32 i2c2_clk_threshold : 8;
|
||||
} __attribute__((packed, aligned(4))) sysctl_clk_th5_t;
|
||||
|
||||
/**
|
||||
* Clock threshold controller 6
|
||||
* No. 20 Register (0x50)
|
||||
*/
|
||||
typedef struct _sysctl_clk_th6 {
|
||||
u32 wdt0_clk_threshold : 8;
|
||||
u32 wdt1_clk_threshold : 8;
|
||||
u32 reserved0 : 8;
|
||||
u32 reserved1 : 8;
|
||||
} __attribute__((packed, aligned(4))) sysctl_clk_th6_t;
|
||||
|
||||
/**
|
||||
* Miscellaneous controller
|
||||
* No. 21 Register (0x54)
|
||||
*/
|
||||
typedef struct _sysctl_misc {
|
||||
u32 debug_sel : 6;
|
||||
u32 reserved0 : 4;
|
||||
u32 spi_dvp_data_enable: 1;
|
||||
u32 reserved1 : 21;
|
||||
} __attribute__((packed, aligned(4))) sysctl_misc_t;
|
||||
|
||||
/**
|
||||
* Peripheral controller
|
||||
* No. 22 Register (0x58)
|
||||
*/
|
||||
typedef struct _sysctl_peri {
|
||||
u32 timer0_pause : 1;
|
||||
u32 timer1_pause : 1;
|
||||
u32 timer2_pause : 1;
|
||||
u32 timer3_pause : 1;
|
||||
u32 timer4_pause : 1;
|
||||
u32 timer5_pause : 1;
|
||||
u32 timer6_pause : 1;
|
||||
u32 timer7_pause : 1;
|
||||
u32 timer8_pause : 1;
|
||||
u32 timer9_pause : 1;
|
||||
u32 timer10_pause : 1;
|
||||
u32 timer11_pause : 1;
|
||||
u32 spi0_xip_en : 1;
|
||||
u32 spi1_xip_en : 1;
|
||||
u32 spi2_xip_en : 1;
|
||||
u32 spi3_xip_en : 1;
|
||||
u32 spi0_clk_bypass : 1;
|
||||
u32 spi1_clk_bypass : 1;
|
||||
u32 spi2_clk_bypass : 1;
|
||||
u32 i2s0_clk_bypass : 1;
|
||||
u32 i2s1_clk_bypass : 1;
|
||||
u32 i2s2_clk_bypass : 1;
|
||||
u32 jtag_clk_bypass : 1;
|
||||
u32 dvp_clk_bypass : 1;
|
||||
u32 debug_clk_bypass : 1;
|
||||
u32 reserved0 : 1;
|
||||
u32 reserved1 : 6;
|
||||
} __attribute__((packed, aligned(4))) sysctl_peri_t;
|
||||
|
||||
/**
|
||||
* SPI sleep controller
|
||||
* No. 23 Register (0x5c)
|
||||
*/
|
||||
typedef struct _sysctl_spi_sleep {
|
||||
u32 ssi0_sleep : 1;
|
||||
u32 ssi1_sleep : 1;
|
||||
u32 ssi2_sleep : 1;
|
||||
u32 ssi3_sleep : 1;
|
||||
u32 reserved : 28;
|
||||
} __attribute__((packed, aligned(4))) sysctl_spi_sleep_t;
|
||||
|
||||
/**
|
||||
* Reset source status
|
||||
* No. 24 Register (0x60)
|
||||
*/
|
||||
typedef struct _sysctl_reset_status {
|
||||
u32 reset_sts_clr : 1;
|
||||
u32 pin_reset_sts : 1;
|
||||
u32 wdt0_reset_sts : 1;
|
||||
u32 wdt1_reset_sts : 1;
|
||||
u32 soft_reset_sts : 1;
|
||||
u32 reserved : 27;
|
||||
} __attribute__((packed, aligned(4))) sysctl_reset_status_t;
|
||||
|
||||
/**
|
||||
* DMA handshake selector
|
||||
* No. 25 Register (0x64)
|
||||
*/
|
||||
typedef struct _sysctl_dma_sel0 {
|
||||
u32 dma_sel0 : 6;
|
||||
u32 dma_sel1 : 6;
|
||||
u32 dma_sel2 : 6;
|
||||
u32 dma_sel3 : 6;
|
||||
u32 dma_sel4 : 6;
|
||||
u32 reserved : 2;
|
||||
} __attribute__((packed, aligned(4))) sysctl_dma_sel0_t;
|
||||
|
||||
/**
|
||||
* DMA handshake selector
|
||||
* No. 26 Register (0x68)
|
||||
*/
|
||||
typedef struct _sysctl_dma_sel1 {
|
||||
u32 dma_sel5 : 6;
|
||||
u32 reserved : 26;
|
||||
} __attribute__((packed, aligned(4))) sysctl_dma_sel1_t;
|
||||
|
||||
/**
|
||||
* IO Power Mode Select controller
|
||||
* No. 27 Register (0x6c)
|
||||
*/
|
||||
typedef struct _sysctl_power_sel {
|
||||
u32 power_mode_sel0 : 1;
|
||||
u32 power_mode_sel1 : 1;
|
||||
u32 power_mode_sel2 : 1;
|
||||
u32 power_mode_sel3 : 1;
|
||||
u32 power_mode_sel4 : 1;
|
||||
u32 power_mode_sel5 : 1;
|
||||
u32 power_mode_sel6 : 1;
|
||||
u32 power_mode_sel7 : 1;
|
||||
u32 reserved : 24;
|
||||
} __attribute__((packed, aligned(4))) sysctl_power_sel_t;
|
||||
|
||||
/**
|
||||
* System controller object
|
||||
*
|
||||
* The System controller is a peripheral device mapped in the
|
||||
* internal memory map, discoverable in the Configuration String.
|
||||
* It is responsible for low-level configuration of all system
|
||||
* related peripheral device. It contain PLL controller, clock
|
||||
* controller, reset controller, DMA handshake controller, SPI
|
||||
* controller, timer controller, WDT controller and sleep
|
||||
* controller.
|
||||
*/
|
||||
typedef struct _sysctl {
|
||||
/* No. 0 (0x00): Git short commit id */
|
||||
sysctl_git_id_t git_id;
|
||||
/* No. 1 (0x04): System clock base frequency */
|
||||
sysctl_clk_freq_t clk_freq;
|
||||
/* No. 2 (0x08): PLL0 controller */
|
||||
sysctl_pll0_t pll0;
|
||||
/* No. 3 (0x0c): PLL1 controller */
|
||||
sysctl_pll1_t pll1;
|
||||
/* No. 4 (0x10): PLL2 controller */
|
||||
sysctl_pll2_t pll2;
|
||||
/* No. 5 (0x14): Reserved */
|
||||
u32 resv5;
|
||||
/* No. 6 (0x18): PLL lock tester */
|
||||
sysctl_pll_lock_t pll_lock;
|
||||
/* No. 7 (0x1c): AXI ROM detector */
|
||||
sysctl_rom_error_t rom_error;
|
||||
/* No. 8 (0x20): Clock select controller0 */
|
||||
sysctl_clk_sel0_t clk_sel0;
|
||||
/* No. 9 (0x24): Clock select controller1 */
|
||||
sysctl_clk_sel1_t clk_sel1;
|
||||
/* No. 10 (0x28): Central clock enable */
|
||||
sysctl_clk_en_cent_t clk_en_cent;
|
||||
/* No. 11 (0x2c): Peripheral clock enable */
|
||||
sysctl_clk_en_peri_t clk_en_peri;
|
||||
/* No. 12 (0x30): Soft reset ctrl */
|
||||
sysctl_soft_reset_t soft_reset;
|
||||
/* No. 13 (0x34): Peripheral reset controller */
|
||||
sysctl_peri_reset_t peri_reset;
|
||||
/* No. 14 (0x38): Clock threshold controller 0 */
|
||||
sysctl_clk_th0_t clk_th0;
|
||||
/* No. 15 (0x3c): Clock threshold controller 1 */
|
||||
sysctl_clk_th1_t clk_th1;
|
||||
/* No. 16 (0x40): Clock threshold controller 2 */
|
||||
sysctl_clk_th2_t clk_th2;
|
||||
/* No. 17 (0x44): Clock threshold controller 3 */
|
||||
sysctl_clk_th3_t clk_th3;
|
||||
/* No. 18 (0x48): Clock threshold controller 4 */
|
||||
sysctl_clk_th4_t clk_th4;
|
||||
/* No. 19 (0x4c): Clock threshold controller 5 */
|
||||
sysctl_clk_th5_t clk_th5;
|
||||
/* No. 20 (0x50): Clock threshold controller 6 */
|
||||
sysctl_clk_th6_t clk_th6;
|
||||
/* No. 21 (0x54): Miscellaneous controller */
|
||||
sysctl_misc_t misc;
|
||||
/* No. 22 (0x58): Peripheral controller */
|
||||
sysctl_peri_t peri;
|
||||
/* No. 23 (0x5c): SPI sleep controller */
|
||||
sysctl_spi_sleep_t spi_sleep;
|
||||
/* No. 24 (0x60): Reset source status */
|
||||
sysctl_reset_status_t reset_status;
|
||||
/* No. 25 (0x64): DMA handshake selector */
|
||||
sysctl_dma_sel0_t dma_sel0;
|
||||
/* No. 26 (0x68): DMA handshake selector */
|
||||
sysctl_dma_sel1_t dma_sel1;
|
||||
/* No. 27 (0x6c): IO Power Mode Select controller */
|
||||
sysctl_power_sel_t power_sel;
|
||||
/* No. 28 (0x70): Reserved */
|
||||
u32 resv28;
|
||||
/* No. 29 (0x74): Reserved */
|
||||
u32 resv29;
|
||||
/* No. 30 (0x78): Reserved */
|
||||
u32 resv30;
|
||||
/* No. 31 (0x7c): Reserved */
|
||||
u32 resv31;
|
||||
} __attribute__((packed, aligned(4))) sysctl_t;
|
||||
|
||||
/**
|
||||
* Abstruct PLL struct
|
||||
*/
|
||||
typedef struct _sysctl_general_pll {
|
||||
u32 clkr : 4;
|
||||
u32 clkf : 6;
|
||||
u32 clkod : 4;
|
||||
u32 bwadj : 6;
|
||||
u32 pll_reset : 1;
|
||||
u32 pll_pwrd : 1;
|
||||
u32 pll_intfb : 1;
|
||||
u32 pll_bypass : 1;
|
||||
u32 pll_test : 1;
|
||||
u32 pll_out_en : 1;
|
||||
u32 pll_ckin_sel : 2;
|
||||
u32 reserved : 4;
|
||||
} __attribute__((packed, aligned(4))) sysctl_general_pll_t;
|
||||
|
||||
/**
|
||||
* System controller object instanse
|
||||
*/
|
||||
extern volatile sysctl_t *const sysctl;
|
||||
|
||||
/**
|
||||
* Enable clock for peripheral
|
||||
* @param[in] clock The clock to be enable
|
||||
* @return result
|
||||
* - 0 Success
|
||||
* - Other Fail
|
||||
*/
|
||||
int sysctl_clock_enable(sysctl_clock_t clock);
|
||||
|
||||
/**
|
||||
* Enable clock for peripheral
|
||||
* @param[in] clock The clock to be disable
|
||||
* @return result
|
||||
* - 0 Success
|
||||
* - Other Fail
|
||||
*/
|
||||
int sysctl_clock_disable(sysctl_clock_t clock);
|
||||
|
||||
/**
|
||||
* Sysctl clock set threshold
|
||||
* @param[in] which Which threshold to set
|
||||
* @param[in] threshold The threshold value
|
||||
* @return result
|
||||
* - 0 Success
|
||||
* - Other Fail
|
||||
*/
|
||||
int sysctl_clock_set_threshold(sysctl_threshold_t which, int threshold);
|
||||
|
||||
/**
|
||||
* Sysctl clock get threshold
|
||||
* @param[in] which Which threshold to get
|
||||
* @return The threshold value
|
||||
* - Other Value of threshold
|
||||
* - -1 Fail
|
||||
*/
|
||||
int sysctl_clock_get_threshold(sysctl_threshold_t which);
|
||||
|
||||
/**
|
||||
* Sysctl clock set clock select
|
||||
* @param[in] which Which clock select to set
|
||||
* @param[in] select The clock select value
|
||||
* @return result
|
||||
* - 0 Success
|
||||
* - Other Fail
|
||||
*/
|
||||
int sysctl_clock_set_clock_select(sysctl_clock_select_t which, int select);
|
||||
|
||||
/**
|
||||
* Sysctl clock get clock select
|
||||
* @param[in] which Which clock select to get
|
||||
* @return The clock select value
|
||||
* - Other Value of clock select
|
||||
* - -1 Fail
|
||||
*/
|
||||
int sysctl_clock_get_clock_select(sysctl_clock_select_t which);
|
||||
|
||||
/**
|
||||
* Get PLL frequency
|
||||
* @param[in] pll The PLL id
|
||||
* @return The frequency of PLL
|
||||
*/
|
||||
u32 sysctl_pll_get_freq(sysctl_pll_t pll);
|
||||
|
||||
/**
|
||||
* Get base clock frequency by clock id
|
||||
* @param[in] clock The clock id
|
||||
* @return The clock frequency
|
||||
*/
|
||||
u32 sysctl_clock_get_freq(sysctl_clock_t clock);
|
||||
|
||||
/**
|
||||
* Reset device by reset controller
|
||||
* @param[in] reset The reset signal
|
||||
*/
|
||||
void sysctl_reset(sysctl_reset_t reset);
|
||||
|
||||
/**
|
||||
* Enable the PLL and power on with reset
|
||||
* @param[in] pll The pll id
|
||||
* @return Result
|
||||
* - 0 Success
|
||||
* - Other Fail
|
||||
*/
|
||||
int sysctl_pll_enable(sysctl_pll_t pll);
|
||||
|
||||
/**
|
||||
* Disable the PLL and power off
|
||||
* @param[in] pll The pll id
|
||||
* @return Result
|
||||
* - 0 Success
|
||||
* - Other Fail
|
||||
*/
|
||||
int sysctl_pll_disable(sysctl_pll_t pll);
|
||||
|
||||
/**
|
||||
* Select DMA channel handshake peripheral signal
|
||||
* @param[in] channel The DMA channel
|
||||
* @param[in] select The peripheral select
|
||||
* @return Result
|
||||
* - 0 Success
|
||||
* - Other Fail
|
||||
*/
|
||||
int sysctl_dma_select(sysctl_dma_channel_t channel, sysctl_dma_select_t select);
|
||||
|
||||
/**
|
||||
* Set SPI0_D0-D7 DVP_D0-D7 as spi and dvp data pin
|
||||
* @param[in] en Enable or not
|
||||
* @return Result
|
||||
* - 0 Success
|
||||
* - Other Fail
|
||||
*/
|
||||
u32 sysctl_set_spi0_dvp_data(u8 en);
|
||||
|
||||
/**
|
||||
* Set io power mode
|
||||
* @param[in] power_bank IO power bank
|
||||
* @param[in] io_power_mode Set power mode 3.3v or 1.8
|
||||
* @return Result
|
||||
* - 0 Success
|
||||
* - Other Fail
|
||||
*/
|
||||
void sysctl_set_power_mode(sysctl_power_bank_t power_bank, sysctl_io_power_mode_t io_power_mode);
|
||||
|
||||
/**
|
||||
* Set frequency of CPU
|
||||
* @param[in] freq The desired frequency in Hz
|
||||
* @return The actual frequency of CPU after set
|
||||
*/
|
||||
u32 sysctl_cpu_set_freq(u32 freq);
|
||||
|
||||
/**
|
||||
* Init PLL freqency
|
||||
* @param[in] pll The PLL id
|
||||
* @param[in] pll_freq The desired frequency in Hz
|
||||
|
||||
*/
|
||||
u32 sysctl_pll_set_freq(sysctl_pll_t pll, u32 pll_freq);
|
||||
|
||||
/**
|
||||
* Enable interrupt
|
||||
*/
|
||||
void sysctl_enable_irq(void);
|
||||
|
||||
/**
|
||||
* Disable interrupt
|
||||
*/
|
||||
void sysctl_disable_irq(void);
|
||||
|
||||
/**
|
||||
* Get the time start up to now
|
||||
* @return The time of microsecond
|
||||
*/
|
||||
u64 sysctl_get_time_us(void);
|
||||
|
||||
void sysctl_usleep(u64 usec);
|
||||
|
||||
#endif /* _SYSCTL_H_ */
|
56
platform/kendryte/k210/uarths.c
Normal file
56
platform/kendryte/k210/uarths.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/* Copyright 2018 Canaan Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "sysctl.h"
|
||||
#include "uarths.h"
|
||||
|
||||
static volatile struct uarths *const uarths =
|
||||
(volatile struct uarths *)UARTHS_BASE_ADDR;
|
||||
|
||||
void uarths_init(u32 baud_rate, enum uarths_stopbit stopbit)
|
||||
{
|
||||
u32 freq = sysctl_clock_get_freq(SYSCTL_CLOCK_CPU);
|
||||
u16 div = freq / baud_rate - 1;
|
||||
|
||||
/* Set UART registers */
|
||||
uarths->div.div = div;
|
||||
uarths->txctrl.nstop = stopbit;
|
||||
uarths->txctrl.txen = 1;
|
||||
uarths->rxctrl.rxen = 1;
|
||||
uarths->txctrl.txcnt = 0;
|
||||
uarths->rxctrl.rxcnt = 0;
|
||||
uarths->ip.txwm = 0;
|
||||
uarths->ip.rxwm = 0;
|
||||
uarths->ie.txwm = 0;
|
||||
uarths->ie.rxwm = 0;
|
||||
}
|
||||
|
||||
void uarths_putc(char c)
|
||||
{
|
||||
while (uarths->txdata.full);
|
||||
|
||||
uarths->txdata.data = (u8)c;
|
||||
}
|
||||
|
||||
char uarths_getc(void)
|
||||
{
|
||||
struct uarths_rxdata recv = uarths->rxdata;
|
||||
|
||||
if (recv.empty)
|
||||
return '\0';
|
||||
|
||||
return recv.data;
|
||||
}
|
||||
|
170
platform/kendryte/k210/uarths.h
Normal file
170
platform/kendryte/k210/uarths.h
Normal file
@@ -0,0 +1,170 @@
|
||||
/* Copyright 2018 Canaan Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Universal Asynchronous Receiver/Transmitter (UART)
|
||||
* The UART peripheral supports the following features:
|
||||
*
|
||||
* - 8-N-1 and 8-N-2 formats: 8 data bits, no parity bit, 1 start
|
||||
* bit, 1 or 2 stop bits
|
||||
*
|
||||
* - 8-entry transmit and receive FIFO buffers with programmable
|
||||
* watermark interrupts
|
||||
*
|
||||
* - 16× Rx oversampling with 2/3 majority voting per bit
|
||||
*
|
||||
* The UART peripheral does not support hardware flow control or
|
||||
* other modem control signals, or synchronous serial data
|
||||
* tranfesrs.
|
||||
*
|
||||
* UART RAM Layout
|
||||
* | Address | Name | Description |
|
||||
* |-----------|----------|---------------------------------|
|
||||
* | 0x000 | txdata | Transmit data register |
|
||||
* | 0x004 | rxdata | Receive data register |
|
||||
* | 0x008 | txctrl | Transmit control register |
|
||||
* | 0x00C | rxctrl | Receive control register |
|
||||
* | 0x010 | ie | UART interrupt enable |
|
||||
* | 0x014 | ip | UART Interrupt pending |
|
||||
* | 0x018 | div | Baud rate divisor |
|
||||
*/
|
||||
|
||||
#ifndef _UARTHS_H_
|
||||
#define _UARTHS_H_
|
||||
|
||||
#include <sbi/sbi_types.h>
|
||||
#include "platform.h"
|
||||
|
||||
/* Register address offsets */
|
||||
#define UARTHS_REG_TXFIFO 0x00
|
||||
#define UARTHS_REG_RXFIFO 0x04
|
||||
#define UARTHS_REG_TXCTRL 0x08
|
||||
#define UARTHS_REG_RXCTRL 0x0c
|
||||
#define UARTHS_REG_IE 0x10
|
||||
#define UARTHS_REG_IP 0x14
|
||||
#define UARTHS_REG_DIV 0x18
|
||||
|
||||
/* TXCTRL register */
|
||||
#define UARTHS_TXEN 0x01
|
||||
#define UARTHS_TXWM(x) (((x) & 0xffff) << 16)
|
||||
|
||||
/* RXCTRL register */
|
||||
#define UARTHS_RXEN 0x01
|
||||
#define UARTHS_RXWM(x) (((x) & 0xffff) << 16)
|
||||
|
||||
/* IP register */
|
||||
#define UARTHS_IP_TXWM 0x01
|
||||
#define UARTHS_IP_RXWM 0x02
|
||||
|
||||
struct uarths_txdata {
|
||||
/* Bits [7:0] is data */
|
||||
u32 data : 8;
|
||||
/* Bits [30:8] is 0 */
|
||||
u32 zero : 23;
|
||||
/* Bit 31 is full status */
|
||||
u32 full : 1;
|
||||
} __attribute__((packed, aligned(4)));
|
||||
|
||||
struct uarths_rxdata {
|
||||
/* Bits [7:0] is data */
|
||||
u32 data : 8;
|
||||
/* Bits [30:8] is 0 */
|
||||
u32 zero : 23;
|
||||
/* Bit 31 is empty status */
|
||||
u32 empty : 1;
|
||||
} __attribute__((packed, aligned(4)));
|
||||
|
||||
struct uarths_txctrl {
|
||||
/* Bit 0 is txen, controls whether the Tx channel is active. */
|
||||
u32 txen : 1;
|
||||
/* Bit 1 is nstop, 0 for one stop bit and 1 for two stop bits */
|
||||
u32 nstop : 1;
|
||||
/* Bits [15:2] is reserved */
|
||||
u32 resv0 : 14;
|
||||
/* Bits [18:16] is threshold of interrupt triggers */
|
||||
u32 txcnt : 3;
|
||||
/* Bits [31:19] is reserved */
|
||||
u32 resv1 : 13;
|
||||
} __attribute__((packed, aligned(4)));
|
||||
|
||||
struct uarths_rxctrl {
|
||||
/* Bit 0 is txen, controls whether the Tx channel is active. */
|
||||
u32 rxen : 1;
|
||||
/* Bits [15:1] is reserved */
|
||||
u32 resv0 : 15;
|
||||
/* Bits [18:16] is threshold of interrupt triggers */
|
||||
u32 rxcnt : 3;
|
||||
/* Bits [31:19] is reserved */
|
||||
u32 resv1 : 13;
|
||||
} __attribute__((packed, aligned(4)));
|
||||
|
||||
struct uarths_ip {
|
||||
/* Bit 0 is txwm, raised less than txcnt */
|
||||
u32 txwm : 1;
|
||||
/* Bit 1 is txwm, raised greater than rxcnt */
|
||||
u32 rxwm : 1;
|
||||
/* Bits [31:2] is 0 */
|
||||
u32 zero : 30;
|
||||
} __attribute__((packed, aligned(4)));
|
||||
|
||||
struct uarths_ie {
|
||||
/* Bit 0 is txwm, raised less than txcnt */
|
||||
u32 txwm : 1;
|
||||
/* Bit 1 is txwm, raised greater than rxcnt */
|
||||
u32 rxwm : 1;
|
||||
/* Bits [31:2] is 0 */
|
||||
u32 zero : 30;
|
||||
} __attribute__((packed, aligned(4)));
|
||||
|
||||
struct uarths_div {
|
||||
/* Bits [31:2] is baud rate divisor register */
|
||||
u32 div : 16;
|
||||
/* Bits [31:16] is 0 */
|
||||
u32 zero : 16;
|
||||
} __attribute__((packed, aligned(4)));
|
||||
|
||||
struct uarths {
|
||||
/* Address offset 0x00 */
|
||||
struct uarths_txdata txdata;
|
||||
/* Address offset 0x04 */
|
||||
struct uarths_rxdata rxdata;
|
||||
/* Address offset 0x08 */
|
||||
struct uarths_txctrl txctrl;
|
||||
/* Address offset 0x0c */
|
||||
struct uarths_rxctrl rxctrl;
|
||||
/* Address offset 0x10 */
|
||||
struct uarths_ie ie;
|
||||
/* Address offset 0x14 */
|
||||
struct uarths_ip ip;
|
||||
/* Address offset 0x18 */
|
||||
struct uarths_div div;
|
||||
} __attribute__((packed, aligned(4)));
|
||||
|
||||
enum uarths_interrupt_mode {
|
||||
UARTHS_SEND = 1,
|
||||
UARTHS_RECEIVE = 2,
|
||||
UARTHS_SEND_RECEIVE = 3,
|
||||
};
|
||||
|
||||
enum uarths_stopbit {
|
||||
UARTHS_STOP_1,
|
||||
UARTHS_STOP_2
|
||||
};
|
||||
|
||||
void uarths_init(u32 baud_rate, enum uarths_stopbit stopbit);
|
||||
void uarths_putc(char c);
|
||||
char uarths_getc(void);
|
||||
|
||||
#endif /* _UARTHS_H_ */
|
32
platform/qemu/sifive_u/config.mk
Normal file
32
platform/qemu/sifive_u/config.mk
Normal file
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
#
|
||||
# Authors:
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
|
||||
# Essential defines required by SBI platform
|
||||
platform-cppflags-y = -DPLAT_NAME="QEMU SiFive Unleashed"
|
||||
platform-cppflags-y+= -DPLAT_HART_COUNT=1
|
||||
platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192
|
||||
|
||||
# Compiler flags
|
||||
platform-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany
|
||||
platform-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany
|
||||
platform-ldflags-y =
|
||||
|
||||
# Common drivers to enable
|
||||
PLATFORM_IRQCHIP_PLIC=y
|
||||
PLATFORM_SERIAL_SIFIVE_UART=y
|
||||
PLATFORM_SYS_CLINT=y
|
||||
|
||||
# Blobs to build
|
||||
FW_TEXT_START=0x80000000
|
||||
FW_JUMP=y
|
||||
FW_JUMP_ADDR=0x80200000
|
||||
FW_JUMP_FDT_ADDR=0x82200000
|
||||
FW_PAYLOAD=y
|
||||
FW_PAYLOAD_OFFSET=0x200000
|
||||
FW_PAYLOAD_FDT_ADDR=0x82200000
|
10
platform/qemu/sifive_u/objects.mk
Normal file
10
platform/qemu/sifive_u/objects.mk
Normal file
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
#
|
||||
# Authors:
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
|
||||
platform-objs-y += platform.o
|
114
platform/qemu/sifive_u/platform.c
Normal file
114
platform/qemu/sifive_u/platform.c
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <sbi/riscv_encoding.h>
|
||||
#include <sbi/sbi_const.h>
|
||||
#include <sbi/sbi_platform.h>
|
||||
#include <plat/irqchip/plic.h>
|
||||
#include <plat/serial/sifive-uart.h>
|
||||
#include <plat/sys/clint.h>
|
||||
|
||||
#define SIFIVE_U_SYS_CLK 1000000000
|
||||
#define SIFIVE_U_PERIPH_CLK (SIFIVE_U_SYS_CLK / 2)
|
||||
|
||||
#define SIFIVE_U_CLINT_ADDR 0x2000000
|
||||
|
||||
#define SIFIVE_U_PLIC_ADDR 0xc000000
|
||||
#define SIFIVE_U_PLIC_NUM_SOURCES 0x35
|
||||
#define SIFIVE_U_PLIC_NUM_PRIORITIES 7
|
||||
|
||||
#define SIFIVE_U_UART0_ADDR 0x10013000
|
||||
#define SIFIVE_U_UART1_ADDR 0x10023000
|
||||
|
||||
static int sifive_u_cold_final_init(void)
|
||||
{
|
||||
return plic_fdt_fixup(sbi_scratch_thishart_arg1_ptr(), "riscv,plic0");
|
||||
}
|
||||
|
||||
static u32 sifive_u_pmp_region_count(u32 target_hart)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int sifive_u_pmp_region_info(u32 target_hart, u32 index,
|
||||
ulong *prot, ulong *addr, ulong *log2size)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
*prot = PMP_R | PMP_W | PMP_X;
|
||||
*addr = 0;
|
||||
*log2size = __riscv_xlen;
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
break;
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int sifive_u_console_init(void)
|
||||
{
|
||||
return sifive_uart_init(SIFIVE_U_UART0_ADDR,
|
||||
SIFIVE_U_PERIPH_CLK, 115200);
|
||||
}
|
||||
|
||||
static int sifive_u_cold_irqchip_init(void)
|
||||
{
|
||||
return plic_cold_irqchip_init(SIFIVE_U_PLIC_ADDR,
|
||||
SIFIVE_U_PLIC_NUM_SOURCES,
|
||||
PLAT_HART_COUNT);
|
||||
}
|
||||
|
||||
static int sifive_u_cold_ipi_init(void)
|
||||
{
|
||||
return clint_cold_ipi_init(SIFIVE_U_CLINT_ADDR,
|
||||
PLAT_HART_COUNT);
|
||||
}
|
||||
|
||||
static int sifive_u_cold_timer_init(void)
|
||||
{
|
||||
return clint_cold_timer_init(SIFIVE_U_CLINT_ADDR,
|
||||
PLAT_HART_COUNT);
|
||||
}
|
||||
|
||||
static int sifive_u_system_down(u32 type)
|
||||
{
|
||||
/* For now nothing to do. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct sbi_platform platform = {
|
||||
.name = STRINGIFY(PLAT_NAME),
|
||||
.features = SBI_PLATFORM_HAS_MMIO_TIMER_VALUE,
|
||||
.hart_count = PLAT_HART_COUNT,
|
||||
.hart_stack_size = PLAT_HART_STACK_SIZE,
|
||||
.pmp_region_count = sifive_u_pmp_region_count,
|
||||
.pmp_region_info = sifive_u_pmp_region_info,
|
||||
.cold_final_init = sifive_u_cold_final_init,
|
||||
.console_putc = sifive_uart_putc,
|
||||
.console_getc = sifive_uart_getc,
|
||||
.console_init = sifive_u_console_init,
|
||||
.cold_irqchip_init = sifive_u_cold_irqchip_init,
|
||||
.warm_irqchip_init = plic_warm_irqchip_init,
|
||||
.ipi_inject = clint_ipi_inject,
|
||||
.ipi_sync = clint_ipi_sync,
|
||||
.ipi_clear = clint_ipi_clear,
|
||||
.warm_ipi_init = clint_warm_ipi_init,
|
||||
.cold_ipi_init = sifive_u_cold_ipi_init,
|
||||
.timer_value = clint_timer_value,
|
||||
.timer_event_stop = clint_timer_event_stop,
|
||||
.timer_event_start = clint_timer_event_start,
|
||||
.warm_timer_init = clint_warm_timer_init,
|
||||
.cold_timer_init = sifive_u_cold_timer_init,
|
||||
.system_reboot = sifive_u_system_down,
|
||||
.system_shutdown = sifive_u_system_down
|
||||
};
|
32
platform/qemu/virt/config.mk
Normal file
32
platform/qemu/virt/config.mk
Normal file
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
#
|
||||
# Authors:
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
|
||||
# Essential defines required by SBI platform
|
||||
platform-cppflags-y = -DPLAT_NAME="QEMU Virt Machine"
|
||||
platform-cppflags-y+= -DPLAT_HART_COUNT=8
|
||||
platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192
|
||||
|
||||
# Compiler flags
|
||||
platform-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany
|
||||
platform-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany
|
||||
platform-ldflags-y =
|
||||
|
||||
# Common drivers to enable
|
||||
PLATFORM_IRQCHIP_PLIC=y
|
||||
PLATFORM_SERIAL_UART8250=y
|
||||
PLATFORM_SYS_CLINT=y
|
||||
|
||||
# Blobs to build
|
||||
FW_TEXT_START=0x80000000
|
||||
FW_JUMP=y
|
||||
FW_JUMP_ADDR=0x80200000
|
||||
FW_JUMP_FDT_ADDR=0x82200000
|
||||
FW_PAYLOAD=y
|
||||
FW_PAYLOAD_OFFSET=0x200000
|
||||
FW_PAYLOAD_FDT_ADDR=0x82200000
|
10
platform/qemu/virt/objects.mk
Normal file
10
platform/qemu/virt/objects.mk
Normal file
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
#
|
||||
# Authors:
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
|
||||
platform-objs-y += platform.o
|
112
platform/qemu/virt/platform.c
Normal file
112
platform/qemu/virt/platform.c
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <sbi/riscv_encoding.h>
|
||||
#include <sbi/sbi_const.h>
|
||||
#include <sbi/sbi_platform.h>
|
||||
#include <plat/irqchip/plic.h>
|
||||
#include <plat/serial/uart8250.h>
|
||||
#include <plat/sys/clint.h>
|
||||
|
||||
#define VIRT_TEST_ADDR 0x100000
|
||||
|
||||
#define VIRT_CLINT_ADDR 0x2000000
|
||||
|
||||
#define VIRT_PLIC_ADDR 0xc000000
|
||||
#define VIRT_PLIC_NUM_SOURCES 127
|
||||
#define VIRT_PLIC_NUM_PRIORITIES 7
|
||||
|
||||
#define VIRT_UART16550_ADDR 0x10000000
|
||||
|
||||
static int virt_cold_final_init(void)
|
||||
{
|
||||
return plic_fdt_fixup(sbi_scratch_thishart_arg1_ptr(), "riscv,plic0");
|
||||
}
|
||||
|
||||
static u32 virt_pmp_region_count(u32 target_hart)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int virt_pmp_region_info(u32 target_hart, u32 index,
|
||||
ulong *prot, ulong *addr, ulong *log2size)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
*prot = PMP_R | PMP_W | PMP_X;
|
||||
*addr = 0;
|
||||
*log2size = __riscv_xlen;
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
break;
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int virt_console_init(void)
|
||||
{
|
||||
return uart8250_init(VIRT_UART16550_ADDR,
|
||||
1843200, 115200, 0, 1);
|
||||
}
|
||||
|
||||
static int virt_cold_irqchip_init(void)
|
||||
{
|
||||
return plic_cold_irqchip_init(VIRT_PLIC_ADDR,
|
||||
VIRT_PLIC_NUM_SOURCES,
|
||||
PLAT_HART_COUNT);
|
||||
}
|
||||
|
||||
static int virt_cold_ipi_init(void)
|
||||
{
|
||||
return clint_cold_ipi_init(VIRT_CLINT_ADDR,
|
||||
PLAT_HART_COUNT);
|
||||
}
|
||||
|
||||
static int virt_cold_timer_init(void)
|
||||
{
|
||||
return clint_cold_timer_init(VIRT_CLINT_ADDR,
|
||||
PLAT_HART_COUNT);
|
||||
}
|
||||
|
||||
static int virt_system_down(u32 type)
|
||||
{
|
||||
/* For now nothing to do. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct sbi_platform platform = {
|
||||
.name = STRINGIFY(PLAT_NAME),
|
||||
.features = SBI_PLATFORM_HAS_MMIO_TIMER_VALUE,
|
||||
.hart_count = PLAT_HART_COUNT,
|
||||
.hart_stack_size = PLAT_HART_STACK_SIZE,
|
||||
.pmp_region_count = virt_pmp_region_count,
|
||||
.pmp_region_info = virt_pmp_region_info,
|
||||
.cold_final_init = virt_cold_final_init,
|
||||
.console_putc = uart8250_putc,
|
||||
.console_getc = uart8250_getc,
|
||||
.console_init = virt_console_init,
|
||||
.cold_irqchip_init = virt_cold_irqchip_init,
|
||||
.warm_irqchip_init = plic_warm_irqchip_init,
|
||||
.ipi_inject = clint_ipi_inject,
|
||||
.ipi_sync = clint_ipi_sync,
|
||||
.ipi_clear = clint_ipi_clear,
|
||||
.warm_ipi_init = clint_warm_ipi_init,
|
||||
.cold_ipi_init = virt_cold_ipi_init,
|
||||
.timer_value = clint_timer_value,
|
||||
.timer_event_stop = clint_timer_event_stop,
|
||||
.timer_event_start = clint_timer_event_start,
|
||||
.warm_timer_init = clint_warm_timer_init,
|
||||
.cold_timer_init = virt_cold_timer_init,
|
||||
.system_reboot = virt_system_down,
|
||||
.system_shutdown = virt_system_down
|
||||
};
|
32
platform/sifive/hifive_u540/config.mk
Normal file
32
platform/sifive/hifive_u540/config.mk
Normal file
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
#
|
||||
# Authors:
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
|
||||
# Essential defines required by SBI platform
|
||||
platform-cppflags-y = -DPLAT_NAME="SiFive HiFive U540"
|
||||
platform-cppflags-y+= -DPLAT_HART_COUNT=5
|
||||
platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192
|
||||
|
||||
# Compiler flags
|
||||
platform-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany
|
||||
platform-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany
|
||||
platform-ldflags-y =
|
||||
|
||||
# Common drivers to enable
|
||||
PLATFORM_IRQCHIP_PLIC=y
|
||||
PLATFORM_SERIAL_SIFIVE_UART=y
|
||||
PLATFORM_SYS_CLINT=y
|
||||
|
||||
# Blobs to build
|
||||
FW_TEXT_START=0x80000000
|
||||
FW_JUMP=y
|
||||
FW_JUMP_ADDR=0x80200000
|
||||
FW_JUMP_FDT_ADDR=0x82200000
|
||||
FW_PAYLOAD=y
|
||||
FW_PAYLOAD_OFFSET=0x200000
|
||||
FW_PAYLOAD_FDT_ADDR=0x82200000
|
10
platform/sifive/hifive_u540/objects.mk
Normal file
10
platform/sifive/hifive_u540/objects.mk
Normal file
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
#
|
||||
# Authors:
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
|
||||
platform-objs-y += platform.o
|
131
platform/sifive/hifive_u540/platform.c
Normal file
131
platform/sifive/hifive_u540/platform.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <sbi/riscv_encoding.h>
|
||||
#include <sbi/sbi_const.h>
|
||||
#include <sbi/sbi_platform.h>
|
||||
#include <sbi/riscv_io.h>
|
||||
#include <plat/irqchip/plic.h>
|
||||
#include <plat/serial/sifive-uart.h>
|
||||
#include <plat/sys/clint.h>
|
||||
|
||||
#define SIFIVE_U_SYS_CLK 1000000000
|
||||
|
||||
#define SIFIVE_U_CLINT_ADDR 0x2000000
|
||||
|
||||
#define SIFIVE_U_PLIC_ADDR 0xc000000
|
||||
#define SIFIVE_U_PLIC_NUM_SOURCES 0x35
|
||||
#define SIFIVE_U_PLIC_NUM_PRIORITIES 7
|
||||
|
||||
#define SIFIVE_U_UART0_ADDR 0x10010000
|
||||
#define SIFIVE_U_UART1_ADDR 0x10011000
|
||||
#define SIFIVE_UART_BAUDRATE 115200
|
||||
|
||||
/* PRCI clock related macros */
|
||||
//TODO: Do we need a separate driver for this ?
|
||||
#define SIFIVE_PRCI_BASE_ADDR 0x10000000
|
||||
#define SIFIVE_PRCI_CLKMUXSTATUSREG 0x002C
|
||||
#define SIFIVE_PRCI_CLKMUX_STATUS_TLCLKSEL (0x1 << 1)
|
||||
|
||||
static int sifive_u_cold_final_init(void)
|
||||
{
|
||||
return plic_fdt_fixup(sbi_scratch_thishart_arg1_ptr(), "riscv,plic0");
|
||||
}
|
||||
|
||||
static u32 sifive_u_pmp_region_count(u32 target_hart)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int sifive_u_pmp_region_info(u32 target_hart, u32 index,
|
||||
ulong *prot, ulong *addr, ulong *log2size)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
*prot = PMP_R | PMP_W | PMP_X;
|
||||
*addr = 0;
|
||||
*log2size = __riscv_xlen;
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
break;
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int sifive_u_console_init(void)
|
||||
{
|
||||
unsigned long peri_in_freq;
|
||||
|
||||
if (readl((volatile void *)SIFIVE_PRCI_BASE_ADDR +
|
||||
SIFIVE_PRCI_CLKMUXSTATUSREG) &
|
||||
SIFIVE_PRCI_CLKMUX_STATUS_TLCLKSEL){
|
||||
peri_in_freq = SIFIVE_U_SYS_CLK;
|
||||
} else {
|
||||
peri_in_freq = SIFIVE_U_SYS_CLK / 2;
|
||||
}
|
||||
|
||||
return sifive_uart_init(SIFIVE_U_UART0_ADDR,
|
||||
peri_in_freq, SIFIVE_UART_BAUDRATE);
|
||||
}
|
||||
|
||||
static int sifive_u_cold_irqchip_init(void)
|
||||
{
|
||||
return plic_cold_irqchip_init(SIFIVE_U_PLIC_ADDR,
|
||||
SIFIVE_U_PLIC_NUM_SOURCES,
|
||||
PLAT_HART_COUNT);
|
||||
}
|
||||
|
||||
static int sifive_u_cold_ipi_init(void)
|
||||
{
|
||||
return clint_cold_ipi_init(SIFIVE_U_CLINT_ADDR,
|
||||
PLAT_HART_COUNT);
|
||||
}
|
||||
|
||||
static int sifive_u_cold_timer_init(void)
|
||||
{
|
||||
return clint_cold_timer_init(SIFIVE_U_CLINT_ADDR,
|
||||
PLAT_HART_COUNT);
|
||||
}
|
||||
|
||||
static int sifive_u_system_down(u32 type)
|
||||
{
|
||||
/* For now nothing to do. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct sbi_platform platform = {
|
||||
.name = STRINGIFY(PLAT_NAME),
|
||||
.features = SBI_PLATFORM_HAS_MMIO_TIMER_VALUE,
|
||||
.hart_count = PLAT_HART_COUNT,
|
||||
.hart_stack_size = PLAT_HART_STACK_SIZE,
|
||||
.pmp_region_count = sifive_u_pmp_region_count,
|
||||
.pmp_region_info = sifive_u_pmp_region_info,
|
||||
.cold_final_init = sifive_u_cold_final_init,
|
||||
.console_putc = sifive_uart_putc,
|
||||
.console_getc = sifive_uart_getc,
|
||||
.console_init = sifive_u_console_init,
|
||||
.cold_irqchip_init = sifive_u_cold_irqchip_init,
|
||||
.warm_irqchip_init = plic_warm_irqchip_init,
|
||||
.ipi_inject = clint_ipi_inject,
|
||||
.ipi_sync = clint_ipi_sync,
|
||||
.ipi_clear = clint_ipi_clear,
|
||||
.warm_ipi_init = clint_warm_ipi_init,
|
||||
.cold_ipi_init = sifive_u_cold_ipi_init,
|
||||
.timer_value = clint_timer_value,
|
||||
.timer_event_stop = clint_timer_event_stop,
|
||||
.timer_event_start = clint_timer_event_start,
|
||||
.warm_timer_init = clint_warm_timer_init,
|
||||
.cold_timer_init = sifive_u_cold_timer_init,
|
||||
.system_reboot = sifive_u_system_down,
|
||||
.system_shutdown = sifive_u_system_down
|
||||
};
|
Reference in New Issue
Block a user