From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: Alexander Shiyan <shc_work@mail.ru>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 04/13] ARM: clps711x: Add clocksource driver
Date: Mon, 11 Mar 2013 12:01:58 +0100 [thread overview]
Message-ID: <20130311110158.GE11170@game.jcrosoft.org> (raw)
In-Reply-To: <1362994003-22653-4-git-send-email-shc_work@mail.ru>
On 13:26 Mon 11 Mar , Alexander Shiyan wrote:
> This patch adds clocksource driver for CLPS711X targets and adds
> support to platform to use this new driver.
>
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> ---
> arch/arm/Kconfig | 1 +
> arch/arm/mach-clps711x/clock.c | 51 ++++++++++++++++-----------------
> drivers/clocksource/Kconfig | 4 ++
> drivers/clocksource/Makefile | 1 +
> drivers/clocksource/clps711x.c | 61 ++++++++++++++++++++++++++++++++++++++++
> 5 files changed, 92 insertions(+), 26 deletions(-)
> create mode 100644 drivers/clocksource/clps711x.c
>
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index 7ac134e..c608454 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -39,6 +39,7 @@ config ARCH_BCM2835
> config ARCH_CLPS711X
> bool "Cirrus Logic EP711x/EP721x/EP731x"
> select CLKDEV_LOOKUP
> + select CLOCKSOURCE_CLPS711X
> select CPU_32v4T
>
> config ARCH_EP93XX
> diff --git a/arch/arm/mach-clps711x/clock.c b/arch/arm/mach-clps711x/clock.c
> index 09cbaf9..e957662 100644
> --- a/arch/arm/mach-clps711x/clock.c
> +++ b/arch/arm/mach-clps711x/clock.c
> @@ -9,25 +9,18 @@
>
> #include <common.h>
> #include <init.h>
> -#include <clock.h>
> +#include <sizes.h>
> #include <asm/io.h>
> #include <linux/clkdev.h>
>
> #include <mach/clps711x.h>
>
> +#define CLPS711X_OSC_FREQ 3686400
> +#define CLPS711X_EXT_FREQ 13000000
> +
> static struct clk {
> unsigned long rate;
> -} uart_clk, bus_clk;
> -
> -static uint64_t clocksource_read(void)
> -{
> - return ~readw(TC2D);
> -}
> -
> -static struct clocksource cs = {
> - .read = clocksource_read,
> - .mask = CLOCKSOURCE_MASK(16),
> -};
> +} uart_clk, bus_clk, timer_clk;
>
> unsigned long clk_get_rate(struct clk *clk)
> {
> @@ -50,22 +43,19 @@ EXPORT_SYMBOL(clk_disable);
>
> static int clocks_init(void)
> {
> - int osc, ext, pll, cpu, timer;
> + int pll, cpu;
> u32 tmp;
>
> - osc = 3686400;
> - ext = 13000000;
> -
> tmp = readl(PLLR) >> 24;
> if (tmp)
> - pll = (osc * tmp) / 2;
> + pll = (CLPS711X_OSC_FREQ * tmp) / 2;
> else
> pll = 73728000; /* Default value for old CPUs */
>
> tmp = readl(SYSFLG2);
> if (tmp & SYSFLG2_CKMODE) {
> - cpu = ext;
> - bus_clk.rate = cpu;
> + cpu = CLPS711X_EXT_FREQ;
> + bus_clk.rate = CLPS711X_EXT_FREQ;
> } else {
> cpu = pll;
> if (cpu >= 36864000)
> @@ -74,25 +64,23 @@ static int clocks_init(void)
> bus_clk.rate = 36864000 / 2;
> }
>
> - uart_clk.rate = bus_clk.rate / 10;
> + uart_clk.rate = DIV_ROUND_CLOSEST(bus_clk.rate, 10);
>
> if (tmp & SYSFLG2_CKMODE) {
> tmp = readw(SYSCON2);
> if (tmp & SYSCON2_OSTB)
> - timer = ext / 26;
> + timer_clk.rate = DIV_ROUND_CLOSEST(CLPS711X_EXT_FREQ, 26);
> else
> - timer = 541440;
> + timer_clk.rate = DIV_ROUND_CLOSEST(CLPS711X_EXT_FREQ, 24);
> } else
> - timer = cpu / 144;
> + timer_clk.rate = DIV_ROUND_CLOSEST(cpu, 144);
>
> tmp = readl(SYSCON1);
> tmp &= ~SYSCON1_TC2M; /* Free running mode */
> tmp |= SYSCON1_TC2S; /* High frequency source */
> writel(tmp, SYSCON1);
>
> - clocks_calc_mult_shift(&cs.mult, &cs.shift, timer, NSEC_PER_SEC, 10);
> -
> - return init_clock(&cs);
> + return 0;
> }
> core_initcall(clocks_init);
>
> @@ -100,6 +88,7 @@ static struct clk_lookup clocks_lookups[] = {
> CLKDEV_CON_ID("bus", &bus_clk),
> CLKDEV_DEV_ID("clps711x_serial0", &uart_clk),
> CLKDEV_DEV_ID("clps711x_serial1", &uart_clk),
> + CLKDEV_DEV_ID("clps711x-cs", &timer_clk),
> };
>
> static int clkdev_init(void)
> @@ -109,3 +98,13 @@ static int clkdev_init(void)
> return 0;
> }
> postcore_initcall(clkdev_init);
> +
> +static const char *clps711x_clocksrc_name = "clps711x-cs";
> +
> +static __init int clps711x_core_init(void)
> +{
> + add_generic_device(clps711x_clocksrc_name, DEVICE_ID_SINGLE, NULL,
> + TC2D, SZ_2, IORESOURCE_MEM, NULL);
> + return 0;
> +}
> +coredevice_initcall(clps711x_core_init);
> diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
> index 3f27cf2..9f3558b 100644
> --- a/drivers/clocksource/Kconfig
> +++ b/drivers/clocksource/Kconfig
> @@ -10,6 +10,10 @@ config CLOCKSOURCE_BCM2835
> bool
> depends on ARCH_BCM2835
>
> +config CLOCKSOURCE_CLPS711X
> + bool
> + depends on ARCH_CLPS711X
> +
> config CLOCKSOURCE_NOMADIK
> bool
> depends on ARM
> diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
> index b0bc8bd..d919881 100644
> --- a/drivers/clocksource/Makefile
> +++ b/drivers/clocksource/Makefile
> @@ -1,4 +1,5 @@
> obj-$(CONFIG_AMBA_SP804) += amba-sp804.o
> obj-$(CONFIG_ARM_SMP_TWD) += arm_smp_twd.o
> obj-$(CONFIG_CLOCKSOURCE_BCM2835) += bcm2835.o
> +obj-$(CONFIG_CLOCKSOURCE_CLPS711X) += clps711x.o
> obj-$(CONFIG_CLOCKSOURCE_NOMADIK) += nomadik.o
> diff --git a/drivers/clocksource/clps711x.c b/drivers/clocksource/clps711x.c
> new file mode 100644
> index 0000000..8c379d3
> --- /dev/null
> +++ b/drivers/clocksource/clps711x.c
> @@ -0,0 +1,61 @@
> +/*
> + * Copyright (C) 2013 Alexander Shiyan <shc_work@mail.ru>
> + *
> + * 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 <common.h>
> +#include <clock.h>
> +#include <io.h>
> +#include <init.h>
> +
> +#include <linux/clk.h>
> +#include <linux/err.h>
> +
> +static __iomem void *clps711x_timer_base;
> +
> +static uint64_t clps711x_cs_read(void)
> +{
> + return ~readw(clps711x_timer_base);
> +}
> +
> +static struct clocksource clps711x_cs = {
> + .read = clps711x_cs_read,
> + .mask = CLOCKSOURCE_MASK(16),
> +};
> +
> +static int clps711x_cs_probe(struct device_d *dev)
> +{
> + u32 rate;
> + struct clk *timer_clk;
> +
> + timer_clk = clk_get(dev, NULL);
> + if (IS_ERR(timer_clk))
> + return PTR_ERR(timer_clk);
> +
> + rate = clk_get_rate(timer_clk);
> + clps711x_timer_base = dev_request_mem_region(dev, 0);
> + if (!clps711x_timer_base) {
> + clk_put(timer_clk);
> + return -ENOENT;
> + }
this deserve a nice crash
> +
> + clocks_calc_mult_shift(&clps711x_cs.mult, &clps711x_cs.shift, rate,
> + NSEC_PER_SEC, 10);
> +
> + return init_clock(&clps711x_cs);
> +}
> +
> +static struct driver_d clps711x_cs_driver = {
> + .name = "clps711x-cs",
> + .probe = clps711x_cs_probe,
> +};
> +
> +static __init int clps711x_cs_init(void)
> +{
> + return platform_driver_register(&clps711x_cs_driver);
> +}
> +coredevice_initcall(clps711x_cs_init);
> --
> 1.7.3.4
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-03-11 11:06 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-11 9:26 [PATCH 01/13] ARM: clep7212: Migrate to config-board Alexander Shiyan
2013-03-11 9:26 ` [PATCH 02/13] ARM: clps711x: Fix setup bus wait state scaling factor for 13Mhz mode Alexander Shiyan
2013-03-11 9:26 ` [PATCH 03/13] ARM: clps711x: Replace numeric PLL option with boolean for raise CPU frequency Alexander Shiyan
2013-03-11 9:26 ` [PATCH 04/13] ARM: clps711x: Add clocksource driver Alexander Shiyan
2013-03-11 11:01 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2013-03-11 11:10 ` Sascha Hauer
2013-03-11 16:22 ` Re[2]: " Alexander Shiyan
2013-03-11 18:00 ` Sascha Hauer
2013-03-11 18:17 ` Re[2]: " Alexander Shiyan
2013-03-11 9:26 ` [PATCH 05/13] ARM: clps711x: Using COMMON_CLK Alexander Shiyan
2013-03-11 11:00 ` Jean-Christophe PLAGNIOL-VILLARD
2013-03-11 11:26 ` Re[2]: " Alexander Shiyan
2013-03-11 11:58 ` Jean-Christophe PLAGNIOL-VILLARD
2013-03-11 9:26 ` [PATCH 06/13] Add Generic GPIO driver Alexander Shiyan
2013-03-11 9:26 ` [PATCH 07/13] ARM: clps711x: Add " Alexander Shiyan
2013-03-11 9:26 ` [PATCH 08/13] Add helpers to define resources Alexander Shiyan
2013-03-11 9:26 ` [PATCH 09/13] ARM: clps711x: Migrate to using DEFINE_RES_MEM macro Alexander Shiyan
2013-03-11 9:26 ` [PATCH 10/13] ARM: clps711x: Limit chipselect setup up to CS5 Alexander Shiyan
2013-03-11 9:26 ` [PATCH 11/13] Add system controller register driver (SYSCON) Alexander Shiyan
2013-03-11 9:26 ` [PATCH 12/13] ARM: clps711x: Export system-wide registers through SYSCON driver Alexander Shiyan
2013-03-11 9:26 ` [PATCH 13/13] serial: clps711x: Migrate to using " Alexander Shiyan
2013-03-11 21:18 ` [PATCH 01/13] ARM: clep7212: Migrate to config-board Sascha Hauer
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=20130311110158.GE11170@game.jcrosoft.org \
--to=plagnioj@jcrosoft.com \
--cc=barebox@lists.infradead.org \
--cc=shc_work@mail.ru \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.