Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: Ralf Baechle <ralf@linux-mips.org>
To: Aleksandar Markovic <aleksandar.markovic@rt-rk.com>
Cc: linux-mips@linux-mips.org,
	Miodrag Dinic <miodrag.dinic@imgtec.com>,
	Goran Ferenc <goran.ferenc@imgtec.com>,
	Aleksandar Markovic <aleksandar.markovic@imgtec.com>,
	Bo Hu <bohu@google.com>, Douglas Leung <douglas.leung@imgtec.com>,
	James Hogan <james.hogan@imgtec.com>,
	Jin Qian <jinqian@google.com>,
	Paul Burton <paul.burton@imgtec.com>,
	Petar Jovanovic <petar.jovanovic@imgtec.com>,
	Raghu Gandham <raghu.gandham@imgtec.com>
Subject: Re: [PATCH v4 5/8] MIPS: ranchu: Add Ranchu as a new generic-based board
Date: Sat, 26 Aug 2017 12:46:42 +0200	[thread overview]
Message-ID: <20170826104642.GE7433@linux-mips.org> (raw)
In-Reply-To: <1503061833-26563-6-git-send-email-aleksandar.markovic@rt-rk.com>

On Fri, Aug 18, 2017 at 03:08:57PM +0200, Aleksandar Markovic wrote:

(trimmed the cc list a bit by a number of people who probably couldn't
care less.)

> Provide amendments to the Mips generic platform framework so that
                            ^^^^
"MIPS" to keep the trademark lawyers happy.

> +CONFIG_STAGING=y

Sure you want to enable Greg's haunted house?

I haven't checked if it's actually needed but as a general rule leave it
disabled unless you have to.

> diff --git a/arch/mips/generic/Makefile b/arch/mips/generic/Makefile
> index 56b3ea5..14931f2 100644
> --- a/arch/mips/generic/Makefile
> +++ b/arch/mips/generic/Makefile
> @@ -14,4 +14,5 @@ obj-y += proc.o
>  
>  obj-$(CONFIG_YAMON_DT_SHIM)		+= yamon-dt.o
>  obj-$(CONFIG_LEGACY_BOARD_SEAD3)	+= board-sead3.o
> +obj-$(CONFIG_VIRT_BOARD_RANCHU)	+= board-ranchu.o
>  obj-$(CONFIG_KEXEC)			+= kexec.o
> diff --git a/arch/mips/generic/board-ranchu.c b/arch/mips/generic/board-ranchu.c
> new file mode 100644
> index 0000000..500874d
> --- /dev/null
> +++ b/arch/mips/generic/board-ranchu.c
> @@ -0,0 +1,78 @@
> +/*
> + * Copyright (C) 2017 Imagination Technologies Ltd.
> + * Author: Miodrag Dinic <miodrag.dinic@imgtec.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License as published by the
> + * Free Software Foundation;  either version 2 of the  License, or (at your
> + * option) any later version.
> + */
> +
> +#include <linux/of_address.h>
> +
> +#include <asm/machine.h>
> +#include <asm/time.h>

You're using u64 / uint64_t below, so you need to #include <linux/types.h>
rather than playing the include lottery.

> +#define GOLDFISH_TIMER_LOW		0x00
> +#define GOLDFISH_TIMER_HIGH		0x04
> +
> +static __init uint64_t read_rtc_time(void __iomem *base)

The remainder of this file is using u64.  While the ISO C types are
acceptable these days, please try to be consistent in use of types.

> +{
> +	u64 time_low;
> +	u64 time_high;
> +
> +	time_low = readl(base + GOLDFISH_TIMER_LOW);
> +	time_high = readl(base + GOLDFISH_TIMER_HIGH);
> +
> +	return (time_high << 32) | time_low;
> +}

GCC used to generate pretty bad code from source like this.  I haven't
checked if it has improved but generally you want to avoid extending
data to 64 bit types for as long as possible, something like:

{
	u32 high, low;

	low = readl(base + GOLDFISH_TIMER_LOW);
	high = readl(base + GOLDFISH_TIMER_HIGH);

	return ((u64)high << 32) | low;
}

> +static __init unsigned int ranchu_measure_hpt_freq(void)
> +{
> +	u64 rtc_start, rtc_current, rtc_delta;
> +	unsigned int start, count;
> +	struct device_node *np;
> +	void __iomem *rtc_base;
> +
> +	np = of_find_compatible_node(NULL, NULL, "google,goldfish-rtc");
> +	if (!np)
> +		panic("%s(): Failed to find 'google,goldfish-rtc' dt node!",
> +		      __func__);
> +
> +	rtc_base = of_iomap(np, 0);
> +	if (!rtc_base)
> +		panic("%s(): Failed to ioremap Goldfish RTC base!", __func__);
> +
> +	/*
> +	 * poll the nanosecond resolution RTC for 1 second
> +	 * to calibrate the CPU frequency
> +	 */
> +	rtc_start = read_rtc_time(rtc_base);
> +	start = read_c0_count();
> +
> +	do {
> +		rtc_current = read_rtc_time(rtc_base);
> +		rtc_delta = rtc_current - rtc_start;
> +	} while (rtc_delta < NSEC_PER_SEC);
> +
> +	count = read_c0_count() - start;
> +
> +	count += 5000;	/* round */
> +	count -= count % 10000;
> +
> +	return count;
> +}
> +
> +static const struct of_device_id ranchu_of_match[];
> +
> +MIPS_MACHINE(ranchu) = {
> +	.matches = ranchu_of_match,
> +	.measure_hpt_freq = ranchu_measure_hpt_freq,
> +};
> +
> +static const struct of_device_id ranchu_of_match[] = {
> +	{
> +		.compatible = "mti,ranchu",
> +		.data = &__mips_mach_ranchu,
> +	},
> +};
> -- 
> 2.7.4
> 

  reply	other threads:[~2017-08-26 10:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-18 13:08 [PATCH v4 0/8] MIPS: Add virtual Ranchu board as a generic-based board Aleksandar Markovic
2017-08-18 13:08 ` [PATCH v4 1/8] Documentation: Add device tree binding for Goldfish RTC driver Aleksandar Markovic
2017-08-25  8:34   ` Alexandre Belloni
2017-08-18 13:08 ` [PATCH v4 2/8] rtc: goldfish: Add RTC driver for Android emulator Aleksandar Markovic
2017-08-25  8:34   ` Alexandre Belloni
2017-08-18 13:08 ` [PATCH v4 3/8] Documentation: Add device tree binding for Goldfish PIC driver Aleksandar Markovic
2017-08-18 13:08 ` [PATCH v4 4/8] irqchip/irq-goldfish-pic: Add " Aleksandar Markovic
2017-08-18 13:53   ` Marc Zyngier
2017-08-18 13:08 ` [PATCH v4 5/8] MIPS: ranchu: Add Ranchu as a new generic-based board Aleksandar Markovic
2017-08-26 10:46   ` Ralf Baechle [this message]
2017-08-18 13:08 ` [PATCH v4 6/8] Documentation: Add device tree binding for Goldfish FB driver Aleksandar Markovic
2017-08-18 16:04   ` Sergei Shtylyov
2017-08-18 13:08 ` [PATCH v4 7/8] video: goldfishfb: Add support for device tree bindings Aleksandar Markovic
2017-08-18 13:09 ` [PATCH v4 8/8] MIPS: Unselect ARCH_MIGHT_HAVE_PC_SERIO if MIPS_GENERIC Aleksandar Markovic
2017-08-26 10:52   ` Ralf Baechle
2017-08-28  9:33     ` Miodrag Dinic
2017-08-29  4:55       ` Florian Fainelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170826104642.GE7433@linux-mips.org \
    --to=ralf@linux-mips.org \
    --cc=aleksandar.markovic@imgtec.com \
    --cc=aleksandar.markovic@rt-rk.com \
    --cc=bohu@google.com \
    --cc=douglas.leung@imgtec.com \
    --cc=goran.ferenc@imgtec.com \
    --cc=james.hogan@imgtec.com \
    --cc=jinqian@google.com \
    --cc=linux-mips@linux-mips.org \
    --cc=miodrag.dinic@imgtec.com \
    --cc=paul.burton@imgtec.com \
    --cc=petar.jovanovic@imgtec.com \
    --cc=raghu.gandham@imgtec.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox