From: daniel.lezcano@linaro.org (Daniel Lezcano)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 38/71] clocksource: sh_mtu2: Split channel fields from sh_mtu2_priv
Date: Fri, 23 May 2014 12:31:18 +0200 [thread overview]
Message-ID: <1400841111-6683-38-git-send-email-daniel.lezcano@linaro.org> (raw)
In-Reply-To: <1400841111-6683-1-git-send-email-daniel.lezcano@linaro.org>
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Create a new sh_mtu2_channel structure to hold the channel-specific
fields in preparation for multiple channels per device support.
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Tested-by: Wolfram Sang <wsa@sang-engineering.com>
---
drivers/clocksource/sh_mtu2.c | 125 +++++++++++++++++++++++------------------
1 file changed, 69 insertions(+), 56 deletions(-)
diff --git a/drivers/clocksource/sh_mtu2.c b/drivers/clocksource/sh_mtu2.c
index 6668455..e509f41 100644
--- a/drivers/clocksource/sh_mtu2.c
+++ b/drivers/clocksource/sh_mtu2.c
@@ -34,12 +34,21 @@
#include <linux/pm_domain.h>
#include <linux/pm_runtime.h>
+struct sh_mtu2_priv;
+
+struct sh_mtu2_channel {
+ struct sh_mtu2_priv *mtu;
+ int irq;
+ struct clock_event_device ced;
+};
+
struct sh_mtu2_priv {
+ struct platform_device *pdev;
+
void __iomem *mapbase;
struct clk *clk;
- int irq;
- struct platform_device *pdev;
- struct clock_event_device ced;
+
+ struct sh_mtu2_channel channel;
};
static DEFINE_RAW_SPINLOCK(sh_mtu2_lock);
@@ -63,10 +72,10 @@ static unsigned long mtu2_reg_offs[] = {
[TGR] = 8,
};
-static inline unsigned long sh_mtu2_read(struct sh_mtu2_priv *p, int reg_nr)
+static inline unsigned long sh_mtu2_read(struct sh_mtu2_channel *ch, int reg_nr)
{
- struct sh_timer_config *cfg = p->pdev->dev.platform_data;
- void __iomem *base = p->mapbase;
+ struct sh_timer_config *cfg = ch->mtu->pdev->dev.platform_data;
+ void __iomem *base = ch->mtu->mapbase;
unsigned long offs;
if (reg_nr == TSTR)
@@ -80,11 +89,11 @@ static inline unsigned long sh_mtu2_read(struct sh_mtu2_priv *p, int reg_nr)
return ioread8(base + offs);
}
-static inline void sh_mtu2_write(struct sh_mtu2_priv *p, int reg_nr,
+static inline void sh_mtu2_write(struct sh_mtu2_channel *ch, int reg_nr,
unsigned long value)
{
- struct sh_timer_config *cfg = p->pdev->dev.platform_data;
- void __iomem *base = p->mapbase;
+ struct sh_timer_config *cfg = ch->mtu->pdev->dev.platform_data;
+ void __iomem *base = ch->mtu->mapbase;
unsigned long offs;
if (reg_nr == TSTR) {
@@ -100,100 +109,100 @@ static inline void sh_mtu2_write(struct sh_mtu2_priv *p, int reg_nr,
iowrite8(value, base + offs);
}
-static void sh_mtu2_start_stop_ch(struct sh_mtu2_priv *p, int start)
+static void sh_mtu2_start_stop_ch(struct sh_mtu2_channel *ch, int start)
{
- struct sh_timer_config *cfg = p->pdev->dev.platform_data;
+ struct sh_timer_config *cfg = ch->mtu->pdev->dev.platform_data;
unsigned long flags, value;
/* start stop register shared by multiple timer channels */
raw_spin_lock_irqsave(&sh_mtu2_lock, flags);
- value = sh_mtu2_read(p, TSTR);
+ value = sh_mtu2_read(ch, TSTR);
if (start)
value |= 1 << cfg->timer_bit;
else
value &= ~(1 << cfg->timer_bit);
- sh_mtu2_write(p, TSTR, value);
+ sh_mtu2_write(ch, TSTR, value);
raw_spin_unlock_irqrestore(&sh_mtu2_lock, flags);
}
-static int sh_mtu2_enable(struct sh_mtu2_priv *p)
+static int sh_mtu2_enable(struct sh_mtu2_channel *ch)
{
unsigned long periodic;
unsigned long rate;
int ret;
- pm_runtime_get_sync(&p->pdev->dev);
- dev_pm_syscore_device(&p->pdev->dev, true);
+ pm_runtime_get_sync(&ch->mtu->pdev->dev);
+ dev_pm_syscore_device(&ch->mtu->pdev->dev, true);
/* enable clock */
- ret = clk_enable(p->clk);
+ ret = clk_enable(ch->mtu->clk);
if (ret) {
- dev_err(&p->pdev->dev, "cannot enable clock\n");
+ dev_err(&ch->mtu->pdev->dev, "cannot enable clock\n");
return ret;
}
/* make sure channel is disabled */
- sh_mtu2_start_stop_ch(p, 0);
+ sh_mtu2_start_stop_ch(ch, 0);
- rate = clk_get_rate(p->clk) / 64;
+ rate = clk_get_rate(ch->mtu->clk) / 64;
periodic = (rate + HZ/2) / HZ;
/* "Periodic Counter Operation" */
- sh_mtu2_write(p, TCR, 0x23); /* TGRA clear, divide clock by 64 */
- sh_mtu2_write(p, TIOR, 0);
- sh_mtu2_write(p, TGR, periodic);
- sh_mtu2_write(p, TCNT, 0);
- sh_mtu2_write(p, TMDR, 0);
- sh_mtu2_write(p, TIER, 0x01);
+ sh_mtu2_write(ch, TCR, 0x23); /* TGRA clear, divide clock by 64 */
+ sh_mtu2_write(ch, TIOR, 0);
+ sh_mtu2_write(ch, TGR, periodic);
+ sh_mtu2_write(ch, TCNT, 0);
+ sh_mtu2_write(ch, TMDR, 0);
+ sh_mtu2_write(ch, TIER, 0x01);
/* enable channel */
- sh_mtu2_start_stop_ch(p, 1);
+ sh_mtu2_start_stop_ch(ch, 1);
return 0;
}
-static void sh_mtu2_disable(struct sh_mtu2_priv *p)
+static void sh_mtu2_disable(struct sh_mtu2_channel *ch)
{
/* disable channel */
- sh_mtu2_start_stop_ch(p, 0);
+ sh_mtu2_start_stop_ch(ch, 0);
/* stop clock */
- clk_disable(p->clk);
+ clk_disable(ch->mtu->clk);
- dev_pm_syscore_device(&p->pdev->dev, false);
- pm_runtime_put(&p->pdev->dev);
+ dev_pm_syscore_device(&ch->mtu->pdev->dev, false);
+ pm_runtime_put(&ch->mtu->pdev->dev);
}
static irqreturn_t sh_mtu2_interrupt(int irq, void *dev_id)
{
- struct sh_mtu2_priv *p = dev_id;
+ struct sh_mtu2_channel *ch = dev_id;
/* acknowledge interrupt */
- sh_mtu2_read(p, TSR);
- sh_mtu2_write(p, TSR, 0xfe);
+ sh_mtu2_read(ch, TSR);
+ sh_mtu2_write(ch, TSR, 0xfe);
/* notify clockevent layer */
- p->ced.event_handler(&p->ced);
+ ch->ced.event_handler(&ch->ced);
return IRQ_HANDLED;
}
-static struct sh_mtu2_priv *ced_to_sh_mtu2(struct clock_event_device *ced)
+static struct sh_mtu2_channel *ced_to_sh_mtu2(struct clock_event_device *ced)
{
- return container_of(ced, struct sh_mtu2_priv, ced);
+ return container_of(ced, struct sh_mtu2_channel, ced);
}
static void sh_mtu2_clock_event_mode(enum clock_event_mode mode,
struct clock_event_device *ced)
{
- struct sh_mtu2_priv *p = ced_to_sh_mtu2(ced);
+ struct sh_mtu2_channel *ch = ced_to_sh_mtu2(ced);
int disabled = 0;
/* deal with old setting first */
switch (ced->mode) {
case CLOCK_EVT_MODE_PERIODIC:
- sh_mtu2_disable(p);
+ sh_mtu2_disable(ch);
disabled = 1;
break;
default:
@@ -202,12 +211,13 @@ static void sh_mtu2_clock_event_mode(enum clock_event_mode mode,
switch (mode) {
case CLOCK_EVT_MODE_PERIODIC:
- dev_info(&p->pdev->dev, "used for periodic clock events\n");
- sh_mtu2_enable(p);
+ dev_info(&ch->mtu->pdev->dev,
+ "used for periodic clock events\n");
+ sh_mtu2_enable(ch);
break;
case CLOCK_EVT_MODE_UNUSED:
if (!disabled)
- sh_mtu2_disable(p);
+ sh_mtu2_disable(ch);
break;
case CLOCK_EVT_MODE_SHUTDOWN:
default:
@@ -217,18 +227,18 @@ static void sh_mtu2_clock_event_mode(enum clock_event_mode mode,
static void sh_mtu2_clock_event_suspend(struct clock_event_device *ced)
{
- pm_genpd_syscore_poweroff(&ced_to_sh_mtu2(ced)->pdev->dev);
+ pm_genpd_syscore_poweroff(&ced_to_sh_mtu2(ced)->mtu->pdev->dev);
}
static void sh_mtu2_clock_event_resume(struct clock_event_device *ced)
{
- pm_genpd_syscore_poweron(&ced_to_sh_mtu2(ced)->pdev->dev);
+ pm_genpd_syscore_poweron(&ced_to_sh_mtu2(ced)->mtu->pdev->dev);
}
-static void sh_mtu2_register_clockevent(struct sh_mtu2_priv *p,
+static void sh_mtu2_register_clockevent(struct sh_mtu2_channel *ch,
char *name, unsigned long rating)
{
- struct clock_event_device *ced = &p->ced;
+ struct clock_event_device *ced = &ch->ced;
int ret;
memset(ced, 0, sizeof(*ced));
@@ -241,23 +251,24 @@ static void sh_mtu2_register_clockevent(struct sh_mtu2_priv *p,
ced->suspend = sh_mtu2_clock_event_suspend;
ced->resume = sh_mtu2_clock_event_resume;
- dev_info(&p->pdev->dev, "used for clock events\n");
+ dev_info(&ch->mtu->pdev->dev, "used for clock events\n");
clockevents_register_device(ced);
- ret = request_irq(p->irq, sh_mtu2_interrupt,
+ ret = request_irq(ch->irq, sh_mtu2_interrupt,
IRQF_TIMER | IRQF_IRQPOLL | IRQF_NOBALANCING,
- dev_name(&p->pdev->dev), p);
+ dev_name(&ch->mtu->pdev->dev), ch);
if (ret) {
- dev_err(&p->pdev->dev, "failed to request irq %d\n", p->irq);
+ dev_err(&ch->mtu->pdev->dev, "failed to request irq %d\n",
+ ch->irq);
return;
}
}
-static int sh_mtu2_register(struct sh_mtu2_priv *p, char *name,
+static int sh_mtu2_register(struct sh_mtu2_channel *ch, char *name,
unsigned long clockevent_rating)
{
if (clockevent_rating)
- sh_mtu2_register_clockevent(p, name, clockevent_rating);
+ sh_mtu2_register_clockevent(ch, name, clockevent_rating);
return 0;
}
@@ -285,8 +296,8 @@ static int sh_mtu2_setup(struct sh_mtu2_priv *p, struct platform_device *pdev)
goto err0;
}
- p->irq = platform_get_irq(p->pdev, 0);
- if (p->irq < 0) {
+ p->channel.irq = platform_get_irq(p->pdev, 0);
+ if (p->channel.irq < 0) {
dev_err(&p->pdev->dev, "failed to get irq\n");
goto err0;
}
@@ -310,7 +321,9 @@ static int sh_mtu2_setup(struct sh_mtu2_priv *p, struct platform_device *pdev)
if (ret < 0)
goto err2;
- ret = sh_mtu2_register(p, (char *)dev_name(&p->pdev->dev),
+ p->channel.mtu = p;
+
+ ret = sh_mtu2_register(&p->channel, (char *)dev_name(&p->pdev->dev),
cfg->clockevent_rating);
if (ret < 0)
goto err3;
--
1.7.9.5
next prev parent reply other threads:[~2014-05-23 10:31 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-23 10:22 [GIT PULL] clockevents: new material for 3.16 Daniel Lezcano
2014-05-23 10:30 ` [PATCH 01/71] clocksource: sh_cmt: Use request_irq() instead of setup_irq() Daniel Lezcano
2014-05-23 10:30 ` [PATCH 02/71] clocksource: sh_cmt: Split channel fields from sh_cmt_priv Daniel Lezcano
2014-05-23 10:30 ` [PATCH 03/71] clocksource: sh_cmt: Rename struct sh_cmt_priv to sh_cmt_device Daniel Lezcano
2014-05-23 10:30 ` [PATCH 04/71] clocksource: sh_cmt: Split channel setup to separate function Daniel Lezcano
2014-05-23 10:30 ` [PATCH 05/71] clocksource: sh_cmt: Constify name argument to sh_cmt_register() Daniel Lezcano
2014-05-23 10:30 ` [PATCH 06/71] clocksource: sh_cmt: Rename mapbase/mapbase_str to mapbase_ch/mapbase Daniel Lezcano
2014-05-23 10:30 ` [PATCH 07/71] clocksource: sh_cmt: Add memory base to sh_cmt_channel structure Daniel Lezcano
2014-05-23 10:30 ` [PATCH 08/71] clocksource: sh_cmt: Add index to struct sh_cmt_channel Daniel Lezcano
2014-05-23 10:30 ` [PATCH 09/71] clocksource: sh_cmt: Replace kmalloc + memset with kzalloc Daniel Lezcano
2014-05-23 10:30 ` [PATCH 10/71] clocksource: sh_cmt: Allocate channels dynamically Daniel Lezcano
2014-05-23 10:30 ` [PATCH 11/71] clocksource: sh_cmt: Split static information from sh_cmt_device Daniel Lezcano
2014-05-23 10:30 ` [PATCH 12/71] clocksource: sh_cmt: Replace hardcoded register values with macros Daniel Lezcano
2014-05-23 10:30 ` [PATCH 13/71] clocksource: sh_cmt: Set cpumask to cpu_possible_mask Daniel Lezcano
2014-05-23 10:30 ` [PATCH 14/71] clocksource: sh_cmt: Hardcode CMT clock event rating to 125 Daniel Lezcano
2014-05-23 10:30 ` [PATCH 15/71] clocksource: sh_cmt: Hardcode CMT clock source " Daniel Lezcano
2014-05-23 10:30 ` [PATCH 16/71] clocksource: sh_cmt: Add support for multiple channels per device Daniel Lezcano
2014-05-23 10:30 ` [PATCH 17/71] clocksource: sh_cmt: Rename clock to "fck" in the non-legacy case Daniel Lezcano
2014-05-23 10:30 ` [PATCH 18/71] clocksource: sh_cmt: Remove FSF mail address from GPL notice Daniel Lezcano
2014-05-23 10:30 ` [PATCH 19/71] clocksource: sh_cmt: Sort headers alphabetically Daniel Lezcano
2014-05-23 10:31 ` [PATCH 20/71] clocksource: sh_cmt: Request IRQ for clock event device only Daniel Lezcano
2014-05-23 10:31 ` [PATCH 21/71] clocksource: sh_tmu: Use request_irq() instead of setup_irq() Daniel Lezcano
2014-05-23 10:31 ` [PATCH 22/71] clocksource: sh_tmu: Split channel fields from sh_tmu_priv Daniel Lezcano
2014-05-23 10:31 ` [PATCH 23/71] clocksource: sh_tmu: Rename struct sh_tmu_priv to sh_tmu_device Daniel Lezcano
2014-05-23 10:31 ` [PATCH 24/71] clocksource: sh_tmu: Split channel setup to separate function Daniel Lezcano
2014-05-23 10:31 ` [PATCH 25/71] clocksource: sh_tmu: Constify name argument to sh_tmu_register() Daniel Lezcano
2014-05-23 10:31 ` [PATCH 26/71] clocksource: sh_tmu: Add memory base to sh_tmu_channel structure Daniel Lezcano
2014-05-23 10:31 ` [PATCH 27/71] clocksource: sh_tmu: Add index to struct sh_tmu_channel Daniel Lezcano
2014-05-23 10:31 ` [PATCH 28/71] clocksource: sh_tmu: Replace kmalloc + memset with kzalloc Daniel Lezcano
2014-05-23 10:31 ` [PATCH 29/71] clocksource: sh_tmu: Allocate channels dynamically Daniel Lezcano
2014-05-23 10:31 ` [PATCH 30/71] clocksource: sh_tmu: Replace hardcoded register values with macros Daniel Lezcano
2014-05-23 10:31 ` [PATCH 31/71] clocksource: sh_tmu: Hardcode TMU clock event and source ratings to 200 Daniel Lezcano
2014-05-23 10:31 ` [PATCH 32/71] clocksource: sh_tmu: Add support for multiple channels per device Daniel Lezcano
2014-05-23 10:31 ` [PATCH 33/71] clocksource: sh_tmu: Rename clock to "fck" in the non-legacy case Daniel Lezcano
2014-05-23 10:31 ` [PATCH 34/71] clocksource: sh_tmu: Remove FSF mail address from GPL notice Daniel Lezcano
2014-05-23 10:31 ` [PATCH 35/71] clocksource: sh_tmu: Sort headers alphabetically Daniel Lezcano
2014-05-23 10:31 ` [PATCH 36/71] clocksource: sh_mtu2: Use request_irq() instead of setup_irq() Daniel Lezcano
2014-05-23 10:31 ` [PATCH 37/71] clocksource: sh_mtu2: Turn sh_mtu2_priv fields into local variables Daniel Lezcano
2014-05-23 10:31 ` Daniel Lezcano [this message]
2014-05-23 10:31 ` [PATCH 39/71] clocksource: sh_mtu2: Rename struct sh_mtu2_priv to sh_mtu2_device Daniel Lezcano
2014-05-23 10:31 ` [PATCH 40/71] clocksource: sh_mtu2: Split channel setup to separate function Daniel Lezcano
2014-05-23 10:31 ` [PATCH 41/71] clocksource: sh_mtu2: Constify name argument to sh_mtu2_register() Daniel Lezcano
2014-05-23 10:31 ` [PATCH 42/71] clocksource: sh_mtu2: Add memory base to sh_mtu2_channel structure Daniel Lezcano
2014-05-23 10:31 ` [PATCH 43/71] clocksource: sh_mtu2: Add index to struct sh_mtu2_channel Daniel Lezcano
2014-05-23 10:31 ` [PATCH 44/71] clocksource: sh_mtu2: Replace kmalloc + memset with kzalloc Daniel Lezcano
2014-05-23 10:31 ` [PATCH 45/71] clocksource: sh_mtu2: Allocate channels dynamically Daniel Lezcano
2014-05-23 10:31 ` [PATCH 46/71] clocksource: sh_mtu2: Replace hardcoded register values with macros Daniel Lezcano
2014-05-23 10:31 ` [PATCH 47/71] clocksource: sh_mtu2: Set cpumask to cpu_possible_mask Daniel Lezcano
2014-05-23 10:31 ` [PATCH 48/71] clocksource: sh_mtu2: Hardcode MTU2 clock event rating to 200 Daniel Lezcano
2014-05-23 10:31 ` [PATCH 49/71] clocksource: sh_mtu2: Add support for multiple channels per device Daniel Lezcano
2014-05-23 10:31 ` [PATCH 50/71] clocksource: sh_mtu2: Rename clock to "fck" in the non-legacy case Daniel Lezcano
2014-05-23 10:31 ` [PATCH 51/71] clocksource: sh_mtu2: Remove FSF mail address from GPL notice Daniel Lezcano
2014-05-23 10:31 ` [PATCH 52/71] clocksource: sh_mtu2: Sort headers alphabetically Daniel Lezcano
2014-05-23 10:31 ` [PATCH 53/71] clocksource: arm_global_timer: Only check for unusable timer on A9 Daniel Lezcano
2014-05-23 10:31 ` [PATCH 54/71] documentaion: DT: allow a A5 compatible string in global timer Daniel Lezcano
2014-05-23 10:31 ` [PATCH 55/71] dts: ca5: add the global timer for the A5 Daniel Lezcano
2014-05-23 10:31 ` [PATCH 56/71] KConfig: Vexpress: build the ARM_GLOBAL_TIMER with vexpress platform Daniel Lezcano
2014-05-23 10:31 ` [PATCH 57/71] clocksource: efm32: use $vendor, $device scheme for compatible string Daniel Lezcano
2014-05-23 10:31 ` [PATCH 58/71] clocksource: sun5i: Add support for reset controller Daniel Lezcano
2014-05-23 10:31 ` [PATCH 59/71] ARM: sun6i: a31: Add support for the High Speed Timers Daniel Lezcano
2014-05-23 10:31 ` [PATCH 60/71] clocksource: qcom: Implement read_current_timer for udelay Daniel Lezcano
2014-05-23 10:31 ` [PATCH 61/71] clocksource: sh_tmu: Fix channel IRQ retrieval in legacy case Daniel Lezcano
2014-05-23 10:31 ` [PATCH 62/71] clocksource: Fix type confusion for clocksource_mmio_readX_Y Daniel Lezcano
2014-05-23 10:31 ` [PATCH 63/71] clocksource: Fix clocksource_mmio_readX_down Daniel Lezcano
2014-05-23 10:31 ` [PATCH 64/71] clocksource: dw_apb_timer_of: Do not trace read_sched_clock Daniel Lezcano
2014-05-23 10:31 ` [PATCH 65/71] clocksource: em_sti: Remove unnecessary OOM messages Daniel Lezcano
2014-05-23 10:31 ` [PATCH 66/71] clocksource: sh_cmt: " Daniel Lezcano
2014-05-23 10:31 ` [PATCH 67/71] clocksource: sh_mtu2: " Daniel Lezcano
2014-05-23 10:31 ` [PATCH 68/71] clocksource: sh_tmu: " Daniel Lezcano
2014-05-23 10:31 ` [PATCH 69/71] clocksource: ftm: Add FlexTimer Module (FTM) Timer devicetree Documentation Daniel Lezcano
2014-05-23 10:31 ` [PATCH 70/71] ARM: dts: vf610: Add Freescale FlexTimer Module timer node Daniel Lezcano
2014-05-23 10:31 ` [PATCH 71/71] clocksource: Add Freescale FlexTimer Module (FTM) timer support Daniel Lezcano
[not found] ` <20140526194512.032c6630@canb.auug.org.au>
2014-05-26 9:52 ` [GIT PULL] clockevents: new material for 3.16 Daniel Lezcano
2014-05-26 13:40 ` Maxime Ripard
2014-05-26 15:07 ` Philipp Zabel
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=1400841111-6683-38-git-send-email-daniel.lezcano@linaro.org \
--to=daniel.lezcano@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).