Skip to content

Commit f2d0b0d

Browse files
miodragdinicamalon
authored andcommitted
MIPS: ranchu: Add Ranchu as a new generic-based board
Provide amendments to the MIPS generic platform framework so that the new generic-based board Ranchu can be chosen to be built. The Ranchu board is intended to be used by Android emulator. The name "Ranchu" originates from Android development community. "Goldfish" and "Ranchu" are terms used for two generations of virtual boards used by Android emulator. The name "Ranchu" is a newer one among the two, and this patch deals with Ranchu. However, for historical reasons, some devices/drivers still contain the name "Goldfish". MIPS Ranchu machine includes a number of Goldfish devices. The support for Virtio devices is also included. Ranchu board supports up to 16 Virtio devices which can be attached using Virtio MMIO Bus. This is summarized in the following picture: ABUS ||----MIPS CPU || | IRQs ||----Goldfish PIC------------(32)-------- || | | | | | | | | | ||----Goldfish TTY------ | | | | | | | | || | | | | | | | | ||----Goldfish RTC-------- | | | | | | | || | | | | | | | ||----Goldfish FB----------- | | | | | | || | | | | | | ||----Goldfish Events--------- | | | | | || | | | | | ||----Goldfish Audio------------ | | | | || | | | | ||----Goldfish Battery------------ | | | || | | | ||----Android PIPE------------------ | | || | | ||----Virtio MMIO Bus | | || | | | | | || | | (virtio-block)--------- | || (16) | | || | (virtio-net)------------------ Device Tree is created on the QEMU side based on the information about devices IO map and IRQ numbers. Kernel will load this DTB using UHI boot protocol DTB handover mode. Signed-off-by: Miodrag Dinic <miodrag.dinic@mips.com> Signed-off-by: Goran Ferenc <goran.ferenc@mips.com> Signed-off-by: Aleksandar Markovic <aleksandar.markovic@mips.com> Reviewed-by: James Hogan <jhogan@kernel.org> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Paul Burton <paul.burton@mips.com> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/18138/ Signed-off-by: James Hogan <jhogan@kernel.org>
1 parent cdf9347 commit f2d0b0d

File tree

5 files changed

+140
-0
lines changed

5 files changed

+140
-0
lines changed

MAINTAINERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11456,6 +11456,13 @@ S: Maintained
1145611456
F: Documentation/blockdev/ramdisk.txt
1145711457
F: drivers/block/brd.c
1145811458

11459+
RANCHU VIRTUAL BOARD FOR MIPS
11460+
M: Miodrag Dinic <miodrag.dinic@mips.com>
11461+
L: linux-mips@linux-mips.org
11462+
S: Supported
11463+
F: arch/mips/generic/board-ranchu.c
11464+
F: arch/mips/configs/generic/board-ranchu.config
11465+
1145911466
RANDOM NUMBER DRIVER
1146011467
M: "Theodore Ts'o" <tytso@mit.edu>
1146111468
S: Maintained
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
CONFIG_VIRT_BOARD_RANCHU=y
2+
3+
CONFIG_BATTERY_GOLDFISH=y
4+
CONFIG_FB=y
5+
CONFIG_FB_GOLDFISH=y
6+
CONFIG_GOLDFISH=y
7+
CONFIG_STAGING=y
8+
CONFIG_GOLDFISH_AUDIO=y
9+
CONFIG_GOLDFISH_PIC=y
10+
CONFIG_GOLDFISH_PIPE=y
11+
CONFIG_GOLDFISH_TTY=y
12+
CONFIG_RTC_CLASS=y
13+
CONFIG_RTC_DRV_GOLDFISH=y
14+
15+
CONFIG_INPUT_EVDEV=y
16+
CONFIG_INPUT_KEYBOARD=y
17+
CONFIG_KEYBOARD_GOLDFISH_EVENTS=y
18+
19+
CONFIG_MAGIC_SYSRQ=y
20+
CONFIG_POWER_SUPPLY=y
21+
CONFIG_POWER_RESET=y
22+
CONFIG_POWER_RESET_SYSCON=y
23+
CONFIG_POWER_RESET_SYSCON_POWEROFF=y
24+
25+
CONFIG_VIRTIO_BLK=y
26+
CONFIG_VIRTIO_CONSOLE=y
27+
CONFIG_VIRTIO_MMIO=y
28+
CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
29+
CONFIG_NETDEVICES=y
30+
CONFIG_VIRTIO_NET=y

arch/mips/generic/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,14 @@ config FIT_IMAGE_FDT_XILFPGA
4949
Enable this to include the FDT for the MIPSfpga platform
5050
from Imagination Technologies in the FIT kernel image.
5151

52+
config VIRT_BOARD_RANCHU
53+
bool "Support Ranchu platform for Android emulator"
54+
help
55+
This enables support for the platform used by Android emulator.
56+
57+
Ranchu platform consists of a set of virtual devices. This platform
58+
enables emulation of variety of virtual configurations while using
59+
Android emulator. Android emulator is based on Qemu, and contains
60+
the support for the same set of virtual devices.
61+
5262
endif

arch/mips/generic/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ obj-y += proc.o
1515
obj-$(CONFIG_YAMON_DT_SHIM) += yamon-dt.o
1616
obj-$(CONFIG_LEGACY_BOARD_SEAD3) += board-sead3.o
1717
obj-$(CONFIG_KEXEC) += kexec.o
18+
obj-$(CONFIG_VIRT_BOARD_RANCHU) += board-ranchu.o

arch/mips/generic/board-ranchu.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Support code for virtual Ranchu board for MIPS.
3+
*
4+
* Author: Miodrag Dinic <miodrag.dinic@mips.com>
5+
*
6+
* This program is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License as published by the
8+
* Free Software Foundation; either version 2 of the License, or (at your
9+
* option) any later version.
10+
*/
11+
12+
#include <linux/of_address.h>
13+
#include <linux/types.h>
14+
15+
#include <asm/machine.h>
16+
#include <asm/mipsregs.h>
17+
#include <asm/time.h>
18+
19+
#define GOLDFISH_TIMER_LOW 0x00
20+
#define GOLDFISH_TIMER_HIGH 0x04
21+
22+
static __init u64 read_rtc_time(void __iomem *base)
23+
{
24+
u32 time_low;
25+
u32 time_high;
26+
27+
/*
28+
* Reading the low address latches the high value
29+
* as well so there is no fear that we may read
30+
* inaccurate high value.
31+
*/
32+
time_low = readl(base + GOLDFISH_TIMER_LOW);
33+
time_high = readl(base + GOLDFISH_TIMER_HIGH);
34+
35+
return ((u64)time_high << 32) | time_low;
36+
}
37+
38+
static __init unsigned int ranchu_measure_hpt_freq(void)
39+
{
40+
u64 rtc_start, rtc_current, rtc_delta;
41+
unsigned int start, count;
42+
struct device_node *np;
43+
void __iomem *rtc_base;
44+
45+
np = of_find_compatible_node(NULL, NULL, "google,goldfish-rtc");
46+
if (!np)
47+
panic("%s(): Failed to find 'google,goldfish-rtc' dt node!",
48+
__func__);
49+
50+
rtc_base = of_iomap(np, 0);
51+
if (!rtc_base)
52+
panic("%s(): Failed to ioremap Goldfish RTC base!", __func__);
53+
54+
/*
55+
* Poll the nanosecond resolution RTC for one
56+
* second to calibrate the CPU frequency.
57+
*/
58+
rtc_start = read_rtc_time(rtc_base);
59+
start = read_c0_count();
60+
61+
do {
62+
rtc_current = read_rtc_time(rtc_base);
63+
rtc_delta = rtc_current - rtc_start;
64+
} while (rtc_delta < NSEC_PER_SEC);
65+
66+
count = read_c0_count() - start;
67+
68+
/*
69+
* Make sure the frequency will be a round number.
70+
* Without this correction, the returned value may vary
71+
* between subsequent emulation executions.
72+
*
73+
* TODO: Set this value using device tree.
74+
*/
75+
count += 5000;
76+
count -= count % 10000;
77+
78+
iounmap(rtc_base);
79+
80+
return count;
81+
}
82+
83+
static const struct of_device_id ranchu_of_match[] __initconst = {
84+
{
85+
.compatible = "mti,ranchu",
86+
},
87+
};
88+
89+
MIPS_MACHINE(ranchu) = {
90+
.matches = ranchu_of_match,
91+
.measure_hpt_freq = ranchu_measure_hpt_freq,
92+
};

0 commit comments

Comments
 (0)