~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/mips/generic/board-ranchu.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php