From dc2eadece70089430f12e4ed6bb1a4421cf3d6f4 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 17 Feb 2014 11:27:49 +0100 Subject: clocksource: sh_cmt: Use request_irq() instead of setup_irq() The driver claims it needs to register an interrupt handler too early for request_irq(). This might have been true in the past, but the only meaningful difference between request_irq() and setup_irq() today is an additional kzalloc() call in request_irq(). As the driver calls kmalloc() itself we know that the slab allocator is available, we can thus switch to request_irq(). Signed-off-by: Laurent Pinchart --- drivers/clocksource/sh_cmt.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'drivers/clocksource') diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index 0b1836a6c539..a3103b871260 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c @@ -728,12 +728,6 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev) goto err1; } - /* request irq using setup_irq() (too early for request_irq()) */ - p->irqaction.name = dev_name(&p->pdev->dev); - p->irqaction.handler = sh_cmt_interrupt; - p->irqaction.dev_id = p; - p->irqaction.flags = IRQF_TIMER | IRQF_IRQPOLL | IRQF_NOBALANCING; - /* get hold of clock */ p->clk = clk_get(&p->pdev->dev, "cmt_fck"); if (IS_ERR(p->clk)) { @@ -786,7 +780,9 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev) } p->cs_enabled = false; - ret = setup_irq(irq, &p->irqaction); + ret = request_irq(irq, sh_cmt_interrupt, + IRQF_TIMER | IRQF_IRQPOLL | IRQF_NOBALANCING, + dev_name(&p->pdev->dev), p); if (ret) { dev_err(&p->pdev->dev, "failed to request irq %d\n", irq); goto err4; -- cgit v1.2.3 From 7269f9333292586f2378c5321b40a8d3779c4653 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 27 Jan 2014 15:29:19 +0100 Subject: clocksource: sh_cmt: Split channel fields from sh_cmt_priv Create a new sh_cmt_channel structure to hold the channel-specific field in preparation for multiple channels per device support. Signed-off-by: Laurent Pinchart --- drivers/clocksource/sh_cmt.c | 385 ++++++++++++++++++++++--------------------- 1 file changed, 199 insertions(+), 186 deletions(-) (limited to 'drivers/clocksource') diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index a3103b871260..351b3ca3ccc4 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c @@ -35,15 +35,10 @@ #include #include -struct sh_cmt_priv { - void __iomem *mapbase; - void __iomem *mapbase_str; - struct clk *clk; - unsigned long width; /* 16 or 32 bit version of hardware block */ - unsigned long overflow_bit; - unsigned long clear_bits; - struct irqaction irqaction; - struct platform_device *pdev; +struct sh_cmt_priv; + +struct sh_cmt_channel { + struct sh_cmt_priv *cmt; unsigned long flags; unsigned long match_value; @@ -55,6 +50,20 @@ struct sh_cmt_priv { struct clocksource cs; unsigned long total_cycles; bool cs_enabled; +}; + +struct sh_cmt_priv { + struct platform_device *pdev; + + void __iomem *mapbase; + void __iomem *mapbase_str; + struct clk *clk; + + struct sh_cmt_channel channel; + + unsigned long width; /* 16 or 32 bit version of hardware block */ + unsigned long overflow_bit; + unsigned long clear_bits; /* callbacks for CMSTR and CMCSR access */ unsigned long (*read_control)(void __iomem *base, unsigned long offs); @@ -114,60 +123,60 @@ static void sh_cmt_write32(void __iomem *base, unsigned long offs, #define CMCNT 1 /* channel register */ #define CMCOR 2 /* channel register */ -static inline unsigned long sh_cmt_read_cmstr(struct sh_cmt_priv *p) +static inline unsigned long sh_cmt_read_cmstr(struct sh_cmt_channel *ch) { - return p->read_control(p->mapbase_str, 0); + return ch->cmt->read_control(ch->cmt->mapbase_str, 0); } -static inline unsigned long sh_cmt_read_cmcsr(struct sh_cmt_priv *p) +static inline unsigned long sh_cmt_read_cmcsr(struct sh_cmt_channel *ch) { - return p->read_control(p->mapbase, CMCSR); + return ch->cmt->read_control(ch->cmt->mapbase, CMCSR); } -static inline unsigned long sh_cmt_read_cmcnt(struct sh_cmt_priv *p) +static inline unsigned long sh_cmt_read_cmcnt(struct sh_cmt_channel *ch) { - return p->read_count(p->mapbase, CMCNT); + return ch->cmt->read_count(ch->cmt->mapbase, CMCNT); } -static inline void sh_cmt_write_cmstr(struct sh_cmt_priv *p, +static inline void sh_cmt_write_cmstr(struct sh_cmt_channel *ch, unsigned long value) { - p->write_control(p->mapbase_str, 0, value); + ch->cmt->write_control(ch->cmt->mapbase_str, 0, value); } -static inline void sh_cmt_write_cmcsr(struct sh_cmt_priv *p, +static inline void sh_cmt_write_cmcsr(struct sh_cmt_channel *ch, unsigned long value) { - p->write_control(p->mapbase, CMCSR, value); + ch->cmt->write_control(ch->cmt->mapbase, CMCSR, value); } -static inline void sh_cmt_write_cmcnt(struct sh_cmt_priv *p, +static inline void sh_cmt_write_cmcnt(struct sh_cmt_channel *ch, unsigned long value) { - p->write_count(p->mapbase, CMCNT, value); + ch->cmt->write_count(ch->cmt->mapbase, CMCNT, value); } -static inline void sh_cmt_write_cmcor(struct sh_cmt_priv *p, +static inline void sh_cmt_write_cmcor(struct sh_cmt_channel *ch, unsigned long value) { - p->write_count(p->mapbase, CMCOR, value); + ch->cmt->write_count(ch->cmt->mapbase, CMCOR, value); } -static unsigned long sh_cmt_get_counter(struct sh_cmt_priv *p, +static unsigned long sh_cmt_get_counter(struct sh_cmt_channel *ch, int *has_wrapped) { unsigned long v1, v2, v3; int o1, o2; - o1 = sh_cmt_read_cmcsr(p) & p->overflow_bit; + o1 = sh_cmt_read_cmcsr(ch) & ch->cmt->overflow_bit; /* Make sure the timer value is stable. Stolen from acpi_pm.c */ do { o2 = o1; - v1 = sh_cmt_read_cmcnt(p); - v2 = sh_cmt_read_cmcnt(p); - v3 = sh_cmt_read_cmcnt(p); - o1 = sh_cmt_read_cmcsr(p) & p->overflow_bit; + v1 = sh_cmt_read_cmcnt(ch); + v2 = sh_cmt_read_cmcnt(ch); + v3 = sh_cmt_read_cmcnt(ch); + o1 = sh_cmt_read_cmcsr(ch) & ch->cmt->overflow_bit; } while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3) || (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2))); @@ -177,52 +186,52 @@ static unsigned long sh_cmt_get_counter(struct sh_cmt_priv *p, static DEFINE_RAW_SPINLOCK(sh_cmt_lock); -static void sh_cmt_start_stop_ch(struct sh_cmt_priv *p, int start) +static void sh_cmt_start_stop_ch(struct sh_cmt_channel *ch, int start) { - struct sh_timer_config *cfg = p->pdev->dev.platform_data; + struct sh_timer_config *cfg = ch->cmt->pdev->dev.platform_data; unsigned long flags, value; /* start stop register shared by multiple timer channels */ raw_spin_lock_irqsave(&sh_cmt_lock, flags); - value = sh_cmt_read_cmstr(p); + value = sh_cmt_read_cmstr(ch); if (start) value |= 1 << cfg->timer_bit; else value &= ~(1 << cfg->timer_bit); - sh_cmt_write_cmstr(p, value); + sh_cmt_write_cmstr(ch, value); raw_spin_unlock_irqrestore(&sh_cmt_lock, flags); } -static int sh_cmt_enable(struct sh_cmt_priv *p, unsigned long *rate) +static int sh_cmt_enable(struct sh_cmt_channel *ch, unsigned long *rate) { int k, ret; - pm_runtime_get_sync(&p->pdev->dev); - dev_pm_syscore_device(&p->pdev->dev, true); + pm_runtime_get_sync(&ch->cmt->pdev->dev); + dev_pm_syscore_device(&ch->cmt->pdev->dev, true); /* enable clock */ - ret = clk_enable(p->clk); + ret = clk_enable(ch->cmt->clk); if (ret) { - dev_err(&p->pdev->dev, "cannot enable clock\n"); + dev_err(&ch->cmt->pdev->dev, "cannot enable clock\n"); goto err0; } /* make sure channel is disabled */ - sh_cmt_start_stop_ch(p, 0); + sh_cmt_start_stop_ch(ch, 0); /* configure channel, periodic mode and maximum timeout */ - if (p->width == 16) { - *rate = clk_get_rate(p->clk) / 512; - sh_cmt_write_cmcsr(p, 0x43); + if (ch->cmt->width == 16) { + *rate = clk_get_rate(ch->cmt->clk) / 512; + sh_cmt_write_cmcsr(ch, 0x43); } else { - *rate = clk_get_rate(p->clk) / 8; - sh_cmt_write_cmcsr(p, 0x01a4); + *rate = clk_get_rate(ch->cmt->clk) / 8; + sh_cmt_write_cmcsr(ch, 0x01a4); } - sh_cmt_write_cmcor(p, 0xffffffff); - sh_cmt_write_cmcnt(p, 0); + sh_cmt_write_cmcor(ch, 0xffffffff); + sh_cmt_write_cmcnt(ch, 0); /* * According to the sh73a0 user's manual, as CMCNT can be operated @@ -236,41 +245,41 @@ static int sh_cmt_enable(struct sh_cmt_priv *p, unsigned long *rate) * take RCLKx2 at maximum. */ for (k = 0; k < 100; k++) { - if (!sh_cmt_read_cmcnt(p)) + if (!sh_cmt_read_cmcnt(ch)) break; udelay(1); } - if (sh_cmt_read_cmcnt(p)) { - dev_err(&p->pdev->dev, "cannot clear CMCNT\n"); + if (sh_cmt_read_cmcnt(ch)) { + dev_err(&ch->cmt->pdev->dev, "cannot clear CMCNT\n"); ret = -ETIMEDOUT; goto err1; } /* enable channel */ - sh_cmt_start_stop_ch(p, 1); + sh_cmt_start_stop_ch(ch, 1); return 0; err1: /* stop clock */ - clk_disable(p->clk); + clk_disable(ch->cmt->clk); err0: return ret; } -static void sh_cmt_disable(struct sh_cmt_priv *p) +static void sh_cmt_disable(struct sh_cmt_channel *ch) { /* disable channel */ - sh_cmt_start_stop_ch(p, 0); + sh_cmt_start_stop_ch(ch, 0); /* disable interrupts in CMT block */ - sh_cmt_write_cmcsr(p, 0); + sh_cmt_write_cmcsr(ch, 0); /* stop clock */ - clk_disable(p->clk); + clk_disable(ch->cmt->clk); - dev_pm_syscore_device(&p->pdev->dev, false); - pm_runtime_put(&p->pdev->dev); + dev_pm_syscore_device(&ch->cmt->pdev->dev, false); + pm_runtime_put(&ch->cmt->pdev->dev); } /* private flags */ @@ -280,24 +289,24 @@ static void sh_cmt_disable(struct sh_cmt_priv *p) #define FLAG_SKIPEVENT (1 << 3) #define FLAG_IRQCONTEXT (1 << 4) -static void sh_cmt_clock_event_program_verify(struct sh_cmt_priv *p, +static void sh_cmt_clock_event_program_verify(struct sh_cmt_channel *ch, int absolute) { unsigned long new_match; - unsigned long value = p->next_match_value; + unsigned long value = ch->next_match_value; unsigned long delay = 0; unsigned long now = 0; int has_wrapped; - now = sh_cmt_get_counter(p, &has_wrapped); - p->flags |= FLAG_REPROGRAM; /* force reprogram */ + now = sh_cmt_get_counter(ch, &has_wrapped); + ch->flags |= FLAG_REPROGRAM; /* force reprogram */ if (has_wrapped) { /* we're competing with the interrupt handler. * -> let the interrupt handler reprogram the timer. * -> interrupt number two handles the event. */ - p->flags |= FLAG_SKIPEVENT; + ch->flags |= FLAG_SKIPEVENT; return; } @@ -309,20 +318,20 @@ static void sh_cmt_clock_event_program_verify(struct sh_cmt_priv *p, * but don't save the new match value yet. */ new_match = now + value + delay; - if (new_match > p->max_match_value) - new_match = p->max_match_value; + if (new_match > ch->max_match_value) + new_match = ch->max_match_value; - sh_cmt_write_cmcor(p, new_match); + sh_cmt_write_cmcor(ch, new_match); - now = sh_cmt_get_counter(p, &has_wrapped); - if (has_wrapped && (new_match > p->match_value)) { + now = sh_cmt_get_counter(ch, &has_wrapped); + if (has_wrapped && (new_match > ch->match_value)) { /* we are changing to a greater match value, * so this wrap must be caused by the counter * matching the old value. * -> first interrupt reprograms the timer. * -> interrupt number two handles the event. */ - p->flags |= FLAG_SKIPEVENT; + ch->flags |= FLAG_SKIPEVENT; break; } @@ -333,7 +342,7 @@ static void sh_cmt_clock_event_program_verify(struct sh_cmt_priv *p, * -> save programmed match value. * -> let isr handle the event. */ - p->match_value = new_match; + ch->match_value = new_match; break; } @@ -344,7 +353,7 @@ static void sh_cmt_clock_event_program_verify(struct sh_cmt_priv *p, * -> save programmed match value. * -> let isr handle the event. */ - p->match_value = new_match; + ch->match_value = new_match; break; } @@ -360,138 +369,138 @@ static void sh_cmt_clock_event_program_verify(struct sh_cmt_priv *p, delay = 1; if (!delay) - dev_warn(&p->pdev->dev, "too long delay\n"); + dev_warn(&ch->cmt->pdev->dev, "too long delay\n"); } while (delay); } -static void __sh_cmt_set_next(struct sh_cmt_priv *p, unsigned long delta) +static void __sh_cmt_set_next(struct sh_cmt_channel *ch, unsigned long delta) { - if (delta > p->max_match_value) - dev_warn(&p->pdev->dev, "delta out of range\n"); + if (delta > ch->max_match_value) + dev_warn(&ch->cmt->pdev->dev, "delta out of range\n"); - p->next_match_value = delta; - sh_cmt_clock_event_program_verify(p, 0); + ch->next_match_value = delta; + sh_cmt_clock_event_program_verify(ch, 0); } -static void sh_cmt_set_next(struct sh_cmt_priv *p, unsigned long delta) +static void sh_cmt_set_next(struct sh_cmt_channel *ch, unsigned long delta) { unsigned long flags; - raw_spin_lock_irqsave(&p->lock, flags); - __sh_cmt_set_next(p, delta); - raw_spin_unlock_irqrestore(&p->lock, flags); + raw_spin_lock_irqsave(&ch->lock, flags); + __sh_cmt_set_next(ch, delta); + raw_spin_unlock_irqrestore(&ch->lock, flags); } static irqreturn_t sh_cmt_interrupt(int irq, void *dev_id) { - struct sh_cmt_priv *p = dev_id; + struct sh_cmt_channel *ch = dev_id; /* clear flags */ - sh_cmt_write_cmcsr(p, sh_cmt_read_cmcsr(p) & p->clear_bits); + sh_cmt_write_cmcsr(ch, sh_cmt_read_cmcsr(ch) & ch->cmt->clear_bits); /* update clock source counter to begin with if enabled * the wrap flag should be cleared by the timer specific * isr before we end up here. */ - if (p->flags & FLAG_CLOCKSOURCE) - p->total_cycles += p->match_value + 1; + if (ch->flags & FLAG_CLOCKSOURCE) + ch->total_cycles += ch->match_value + 1; - if (!(p->flags & FLAG_REPROGRAM)) - p->next_match_value = p->max_match_value; + if (!(ch->flags & FLAG_REPROGRAM)) + ch->next_match_value = ch->max_match_value; - p->flags |= FLAG_IRQCONTEXT; + ch->flags |= FLAG_IRQCONTEXT; - if (p->flags & FLAG_CLOCKEVENT) { - if (!(p->flags & FLAG_SKIPEVENT)) { - if (p->ced.mode == CLOCK_EVT_MODE_ONESHOT) { - p->next_match_value = p->max_match_value; - p->flags |= FLAG_REPROGRAM; + if (ch->flags & FLAG_CLOCKEVENT) { + if (!(ch->flags & FLAG_SKIPEVENT)) { + if (ch->ced.mode == CLOCK_EVT_MODE_ONESHOT) { + ch->next_match_value = ch->max_match_value; + ch->flags |= FLAG_REPROGRAM; } - p->ced.event_handler(&p->ced); + ch->ced.event_handler(&ch->ced); } } - p->flags &= ~FLAG_SKIPEVENT; + ch->flags &= ~FLAG_SKIPEVENT; - if (p->flags & FLAG_REPROGRAM) { - p->flags &= ~FLAG_REPROGRAM; - sh_cmt_clock_event_program_verify(p, 1); + if (ch->flags & FLAG_REPROGRAM) { + ch->flags &= ~FLAG_REPROGRAM; + sh_cmt_clock_event_program_verify(ch, 1); - if (p->flags & FLAG_CLOCKEVENT) - if ((p->ced.mode == CLOCK_EVT_MODE_SHUTDOWN) - || (p->match_value == p->next_match_value)) - p->flags &= ~FLAG_REPROGRAM; + if (ch->flags & FLAG_CLOCKEVENT) + if ((ch->ced.mode == CLOCK_EVT_MODE_SHUTDOWN) + || (ch->match_value == ch->next_match_value)) + ch->flags &= ~FLAG_REPROGRAM; } - p->flags &= ~FLAG_IRQCONTEXT; + ch->flags &= ~FLAG_IRQCONTEXT; return IRQ_HANDLED; } -static int sh_cmt_start(struct sh_cmt_priv *p, unsigned long flag) +static int sh_cmt_start(struct sh_cmt_channel *ch, unsigned long flag) { int ret = 0; unsigned long flags; - raw_spin_lock_irqsave(&p->lock, flags); + raw_spin_lock_irqsave(&ch->lock, flags); - if (!(p->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE))) - ret = sh_cmt_enable(p, &p->rate); + if (!(ch->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE))) + ret = sh_cmt_enable(ch, &ch->rate); if (ret) goto out; - p->flags |= flag; + ch->flags |= flag; /* setup timeout if no clockevent */ - if ((flag == FLAG_CLOCKSOURCE) && (!(p->flags & FLAG_CLOCKEVENT))) - __sh_cmt_set_next(p, p->max_match_value); + if ((flag == FLAG_CLOCKSOURCE) && (!(ch->flags & FLAG_CLOCKEVENT))) + __sh_cmt_set_next(ch, ch->max_match_value); out: - raw_spin_unlock_irqrestore(&p->lock, flags); + raw_spin_unlock_irqrestore(&ch->lock, flags); return ret; } -static void sh_cmt_stop(struct sh_cmt_priv *p, unsigned long flag) +static void sh_cmt_stop(struct sh_cmt_channel *ch, unsigned long flag) { unsigned long flags; unsigned long f; - raw_spin_lock_irqsave(&p->lock, flags); + raw_spin_lock_irqsave(&ch->lock, flags); - f = p->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE); - p->flags &= ~flag; + f = ch->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE); + ch->flags &= ~flag; - if (f && !(p->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE))) - sh_cmt_disable(p); + if (f && !(ch->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE))) + sh_cmt_disable(ch); /* adjust the timeout to maximum if only clocksource left */ - if ((flag == FLAG_CLOCKEVENT) && (p->flags & FLAG_CLOCKSOURCE)) - __sh_cmt_set_next(p, p->max_match_value); + if ((flag == FLAG_CLOCKEVENT) && (ch->flags & FLAG_CLOCKSOURCE)) + __sh_cmt_set_next(ch, ch->max_match_value); - raw_spin_unlock_irqrestore(&p->lock, flags); + raw_spin_unlock_irqrestore(&ch->lock, flags); } -static struct sh_cmt_priv *cs_to_sh_cmt(struct clocksource *cs) +static struct sh_cmt_channel *cs_to_sh_cmt(struct clocksource *cs) { - return container_of(cs, struct sh_cmt_priv, cs); + return container_of(cs, struct sh_cmt_channel, cs); } static cycle_t sh_cmt_clocksource_read(struct clocksource *cs) { - struct sh_cmt_priv *p = cs_to_sh_cmt(cs); + struct sh_cmt_channel *ch = cs_to_sh_cmt(cs); unsigned long flags, raw; unsigned long value; int has_wrapped; - raw_spin_lock_irqsave(&p->lock, flags); - value = p->total_cycles; - raw = sh_cmt_get_counter(p, &has_wrapped); + raw_spin_lock_irqsave(&ch->lock, flags); + value = ch->total_cycles; + raw = sh_cmt_get_counter(ch, &has_wrapped); if (unlikely(has_wrapped)) - raw += p->match_value + 1; - raw_spin_unlock_irqrestore(&p->lock, flags); + raw += ch->match_value + 1; + raw_spin_unlock_irqrestore(&ch->lock, flags); return value + raw; } @@ -499,50 +508,50 @@ static cycle_t sh_cmt_clocksource_read(struct clocksource *cs) static int sh_cmt_clocksource_enable(struct clocksource *cs) { int ret; - struct sh_cmt_priv *p = cs_to_sh_cmt(cs); + struct sh_cmt_channel *ch = cs_to_sh_cmt(cs); - WARN_ON(p->cs_enabled); + WARN_ON(ch->cs_enabled); - p->total_cycles = 0; + ch->total_cycles = 0; - ret = sh_cmt_start(p, FLAG_CLOCKSOURCE); + ret = sh_cmt_start(ch, FLAG_CLOCKSOURCE); if (!ret) { - __clocksource_updatefreq_hz(cs, p->rate); - p->cs_enabled = true; + __clocksource_updatefreq_hz(cs, ch->rate); + ch->cs_enabled = true; } return ret; } static void sh_cmt_clocksource_disable(struct clocksource *cs) { - struct sh_cmt_priv *p = cs_to_sh_cmt(cs); + struct sh_cmt_channel *ch = cs_to_sh_cmt(cs); - WARN_ON(!p->cs_enabled); + WARN_ON(!ch->cs_enabled); - sh_cmt_stop(p, FLAG_CLOCKSOURCE); - p->cs_enabled = false; + sh_cmt_stop(ch, FLAG_CLOCKSOURCE); + ch->cs_enabled = false; } static void sh_cmt_clocksource_suspend(struct clocksource *cs) { - struct sh_cmt_priv *p = cs_to_sh_cmt(cs); + struct sh_cmt_channel *ch = cs_to_sh_cmt(cs); - sh_cmt_stop(p, FLAG_CLOCKSOURCE); - pm_genpd_syscore_poweroff(&p->pdev->dev); + sh_cmt_stop(ch, FLAG_CLOCKSOURCE); + pm_genpd_syscore_poweroff(&ch->cmt->pdev->dev); } static void sh_cmt_clocksource_resume(struct clocksource *cs) { - struct sh_cmt_priv *p = cs_to_sh_cmt(cs); + struct sh_cmt_channel *ch = cs_to_sh_cmt(cs); - pm_genpd_syscore_poweron(&p->pdev->dev); - sh_cmt_start(p, FLAG_CLOCKSOURCE); + pm_genpd_syscore_poweron(&ch->cmt->pdev->dev); + sh_cmt_start(ch, FLAG_CLOCKSOURCE); } -static int sh_cmt_register_clocksource(struct sh_cmt_priv *p, +static int sh_cmt_register_clocksource(struct sh_cmt_channel *ch, char *name, unsigned long rating) { - struct clocksource *cs = &p->cs; + struct clocksource *cs = &ch->cs; cs->name = name; cs->rating = rating; @@ -554,47 +563,47 @@ static int sh_cmt_register_clocksource(struct sh_cmt_priv *p, cs->mask = CLOCKSOURCE_MASK(sizeof(unsigned long) * 8); cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; - dev_info(&p->pdev->dev, "used as clock source\n"); + dev_info(&ch->cmt->pdev->dev, "used as clock source\n"); /* Register with dummy 1 Hz value, gets updated in ->enable() */ clocksource_register_hz(cs, 1); return 0; } -static struct sh_cmt_priv *ced_to_sh_cmt(struct clock_event_device *ced) +static struct sh_cmt_channel *ced_to_sh_cmt(struct clock_event_device *ced) { - return container_of(ced, struct sh_cmt_priv, ced); + return container_of(ced, struct sh_cmt_channel, ced); } -static void sh_cmt_clock_event_start(struct sh_cmt_priv *p, int periodic) +static void sh_cmt_clock_event_start(struct sh_cmt_channel *ch, int periodic) { - struct clock_event_device *ced = &p->ced; + struct clock_event_device *ced = &ch->ced; - sh_cmt_start(p, FLAG_CLOCKEVENT); + sh_cmt_start(ch, FLAG_CLOCKEVENT); /* TODO: calculate good shift from rate and counter bit width */ ced->shift = 32; - ced->mult = div_sc(p->rate, NSEC_PER_SEC, ced->shift); - ced->max_delta_ns = clockevent_delta2ns(p->max_match_value, ced); + ced->mult = div_sc(ch->rate, NSEC_PER_SEC, ced->shift); + ced->max_delta_ns = clockevent_delta2ns(ch->max_match_value, ced); ced->min_delta_ns = clockevent_delta2ns(0x1f, ced); if (periodic) - sh_cmt_set_next(p, ((p->rate + HZ/2) / HZ) - 1); + sh_cmt_set_next(ch, ((ch->rate + HZ/2) / HZ) - 1); else - sh_cmt_set_next(p, p->max_match_value); + sh_cmt_set_next(ch, ch->max_match_value); } static void sh_cmt_clock_event_mode(enum clock_event_mode mode, struct clock_event_device *ced) { - struct sh_cmt_priv *p = ced_to_sh_cmt(ced); + struct sh_cmt_channel *ch = ced_to_sh_cmt(ced); /* deal with old setting first */ switch (ced->mode) { case CLOCK_EVT_MODE_PERIODIC: case CLOCK_EVT_MODE_ONESHOT: - sh_cmt_stop(p, FLAG_CLOCKEVENT); + sh_cmt_stop(ch, FLAG_CLOCKEVENT); break; default: break; @@ -602,16 +611,18 @@ static void sh_cmt_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_cmt_clock_event_start(p, 1); + dev_info(&ch->cmt->pdev->dev, + "used for periodic clock events\n"); + sh_cmt_clock_event_start(ch, 1); break; case CLOCK_EVT_MODE_ONESHOT: - dev_info(&p->pdev->dev, "used for oneshot clock events\n"); - sh_cmt_clock_event_start(p, 0); + dev_info(&ch->cmt->pdev->dev, + "used for oneshot clock events\n"); + sh_cmt_clock_event_start(ch, 0); break; case CLOCK_EVT_MODE_SHUTDOWN: case CLOCK_EVT_MODE_UNUSED: - sh_cmt_stop(p, FLAG_CLOCKEVENT); + sh_cmt_stop(ch, FLAG_CLOCKEVENT); break; default: break; @@ -621,37 +632,37 @@ static void sh_cmt_clock_event_mode(enum clock_event_mode mode, static int sh_cmt_clock_event_next(unsigned long delta, struct clock_event_device *ced) { - struct sh_cmt_priv *p = ced_to_sh_cmt(ced); + struct sh_cmt_channel *ch = ced_to_sh_cmt(ced); BUG_ON(ced->mode != CLOCK_EVT_MODE_ONESHOT); - if (likely(p->flags & FLAG_IRQCONTEXT)) - p->next_match_value = delta - 1; + if (likely(ch->flags & FLAG_IRQCONTEXT)) + ch->next_match_value = delta - 1; else - sh_cmt_set_next(p, delta - 1); + sh_cmt_set_next(ch, delta - 1); return 0; } static void sh_cmt_clock_event_suspend(struct clock_event_device *ced) { - struct sh_cmt_priv *p = ced_to_sh_cmt(ced); + struct sh_cmt_channel *ch = ced_to_sh_cmt(ced); - pm_genpd_syscore_poweroff(&p->pdev->dev); - clk_unprepare(p->clk); + pm_genpd_syscore_poweroff(&ch->cmt->pdev->dev); + clk_unprepare(ch->cmt->clk); } static void sh_cmt_clock_event_resume(struct clock_event_device *ced) { - struct sh_cmt_priv *p = ced_to_sh_cmt(ced); + struct sh_cmt_channel *ch = ced_to_sh_cmt(ced); - clk_prepare(p->clk); - pm_genpd_syscore_poweron(&p->pdev->dev); + clk_prepare(ch->cmt->clk); + pm_genpd_syscore_poweron(&ch->cmt->pdev->dev); } -static void sh_cmt_register_clockevent(struct sh_cmt_priv *p, +static void sh_cmt_register_clockevent(struct sh_cmt_channel *ch, char *name, unsigned long rating) { - struct clock_event_device *ced = &p->ced; + struct clock_event_device *ced = &ch->ced; memset(ced, 0, sizeof(*ced)); @@ -665,19 +676,19 @@ static void sh_cmt_register_clockevent(struct sh_cmt_priv *p, ced->suspend = sh_cmt_clock_event_suspend; ced->resume = sh_cmt_clock_event_resume; - dev_info(&p->pdev->dev, "used for clock events\n"); + dev_info(&ch->cmt->pdev->dev, "used for clock events\n"); clockevents_register_device(ced); } -static int sh_cmt_register(struct sh_cmt_priv *p, char *name, +static int sh_cmt_register(struct sh_cmt_channel *ch, char *name, unsigned long clockevent_rating, unsigned long clocksource_rating) { if (clockevent_rating) - sh_cmt_register_clockevent(p, name, clockevent_rating); + sh_cmt_register_clockevent(ch, name, clockevent_rating); if (clocksource_rating) - sh_cmt_register_clocksource(p, name, clocksource_rating); + sh_cmt_register_clocksource(ch, name, clocksource_rating); return 0; } @@ -685,6 +696,7 @@ static int sh_cmt_register(struct sh_cmt_priv *p, char *name, static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev) { struct sh_timer_config *cfg = pdev->dev.platform_data; + struct sh_cmt_channel *ch = &p->channel; struct resource *res, *res2; int irq, ret; ret = -ENXIO; @@ -763,26 +775,27 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev) p->clear_bits = ~0xc000; } - if (p->width == (sizeof(p->max_match_value) * 8)) - p->max_match_value = ~0; + if (p->width == (sizeof(ch->max_match_value) * 8)) + ch->max_match_value = ~0; else - p->max_match_value = (1 << p->width) - 1; + ch->max_match_value = (1 << p->width) - 1; - p->match_value = p->max_match_value; - raw_spin_lock_init(&p->lock); + ch->cmt = p; + ch->match_value = ch->max_match_value; + raw_spin_lock_init(&ch->lock); - ret = sh_cmt_register(p, (char *)dev_name(&p->pdev->dev), + ret = sh_cmt_register(ch, (char *)dev_name(&p->pdev->dev), cfg->clockevent_rating, cfg->clocksource_rating); if (ret) { dev_err(&p->pdev->dev, "registration failed\n"); goto err4; } - p->cs_enabled = false; + ch->cs_enabled = false; ret = request_irq(irq, sh_cmt_interrupt, IRQF_TIMER | IRQF_IRQPOLL | IRQF_NOBALANCING, - dev_name(&p->pdev->dev), p); + dev_name(&p->pdev->dev), ch); if (ret) { dev_err(&p->pdev->dev, "failed to request irq %d\n", irq); goto err4; -- cgit v1.2.3 From 2653caf4381f9adeec8c18dfec21ec3c855d801c Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 27 Jan 2014 22:04:17 +0100 Subject: clocksource: sh_cmt: Rename struct sh_cmt_priv to sh_cmt_device Channel data is private as well, rename priv to device to make the distrinction between the core device and the channels clearer. Signed-off-by: Laurent Pinchart --- drivers/clocksource/sh_cmt.c | 116 +++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 58 deletions(-) (limited to 'drivers/clocksource') diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index 351b3ca3ccc4..604199a22265 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c @@ -35,10 +35,10 @@ #include #include -struct sh_cmt_priv; +struct sh_cmt_device; struct sh_cmt_channel { - struct sh_cmt_priv *cmt; + struct sh_cmt_device *cmt; unsigned long flags; unsigned long match_value; @@ -52,7 +52,7 @@ struct sh_cmt_channel { bool cs_enabled; }; -struct sh_cmt_priv { +struct sh_cmt_device { struct platform_device *pdev; void __iomem *mapbase; @@ -693,132 +693,132 @@ static int sh_cmt_register(struct sh_cmt_channel *ch, char *name, return 0; } -static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev) +static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev) { struct sh_timer_config *cfg = pdev->dev.platform_data; - struct sh_cmt_channel *ch = &p->channel; + struct sh_cmt_channel *ch = &cmt->channel; struct resource *res, *res2; int irq, ret; ret = -ENXIO; - memset(p, 0, sizeof(*p)); - p->pdev = pdev; + memset(cmt, 0, sizeof(*cmt)); + cmt->pdev = pdev; if (!cfg) { - dev_err(&p->pdev->dev, "missing platform data\n"); + dev_err(&cmt->pdev->dev, "missing platform data\n"); goto err0; } - res = platform_get_resource(p->pdev, IORESOURCE_MEM, 0); + res = platform_get_resource(cmt->pdev, IORESOURCE_MEM, 0); if (!res) { - dev_err(&p->pdev->dev, "failed to get I/O memory\n"); + dev_err(&cmt->pdev->dev, "failed to get I/O memory\n"); goto err0; } /* optional resource for the shared timer start/stop register */ - res2 = platform_get_resource(p->pdev, IORESOURCE_MEM, 1); + res2 = platform_get_resource(cmt->pdev, IORESOURCE_MEM, 1); - irq = platform_get_irq(p->pdev, 0); + irq = platform_get_irq(cmt->pdev, 0); if (irq < 0) { - dev_err(&p->pdev->dev, "failed to get irq\n"); + dev_err(&cmt->pdev->dev, "failed to get irq\n"); goto err0; } /* map memory, let mapbase point to our channel */ - p->mapbase = ioremap_nocache(res->start, resource_size(res)); - if (p->mapbase == NULL) { - dev_err(&p->pdev->dev, "failed to remap I/O memory\n"); + cmt->mapbase = ioremap_nocache(res->start, resource_size(res)); + if (cmt->mapbase == NULL) { + dev_err(&cmt->pdev->dev, "failed to remap I/O memory\n"); goto err0; } /* map second resource for CMSTR */ - p->mapbase_str = ioremap_nocache(res2 ? res2->start : - res->start - cfg->channel_offset, - res2 ? resource_size(res2) : 2); - if (p->mapbase_str == NULL) { - dev_err(&p->pdev->dev, "failed to remap I/O second memory\n"); + cmt->mapbase_str = ioremap_nocache(res2 ? res2->start : + res->start - cfg->channel_offset, + res2 ? resource_size(res2) : 2); + if (cmt->mapbase_str == NULL) { + dev_err(&cmt->pdev->dev, "failed to remap I/O second memory\n"); goto err1; } /* get hold of clock */ - p->clk = clk_get(&p->pdev->dev, "cmt_fck"); - if (IS_ERR(p->clk)) { - dev_err(&p->pdev->dev, "cannot get clock\n"); - ret = PTR_ERR(p->clk); + cmt->clk = clk_get(&cmt->pdev->dev, "cmt_fck"); + if (IS_ERR(cmt->clk)) { + dev_err(&cmt->pdev->dev, "cannot get clock\n"); + ret = PTR_ERR(cmt->clk); goto err2; } - ret = clk_prepare(p->clk); + ret = clk_prepare(cmt->clk); if (ret < 0) goto err3; if (res2 && (resource_size(res2) == 4)) { /* assume both CMSTR and CMCSR to be 32-bit */ - p->read_control = sh_cmt_read32; - p->write_control = sh_cmt_write32; + cmt->read_control = sh_cmt_read32; + cmt->write_control = sh_cmt_write32; } else { - p->read_control = sh_cmt_read16; - p->write_control = sh_cmt_write16; + cmt->read_control = sh_cmt_read16; + cmt->write_control = sh_cmt_write16; } if (resource_size(res) == 6) { - p->width = 16; - p->read_count = sh_cmt_read16; - p->write_count = sh_cmt_write16; - p->overflow_bit = 0x80; - p->clear_bits = ~0x80; + cmt->width = 16; + cmt->read_count = sh_cmt_read16; + cmt->write_count = sh_cmt_write16; + cmt->overflow_bit = 0x80; + cmt->clear_bits = ~0x80; } else { - p->width = 32; - p->read_count = sh_cmt_read32; - p->write_count = sh_cmt_write32; - p->overflow_bit = 0x8000; - p->clear_bits = ~0xc000; + cmt->width = 32; + cmt->read_count = sh_cmt_read32; + cmt->write_count = sh_cmt_write32; + cmt->overflow_bit = 0x8000; + cmt->clear_bits = ~0xc000; } - if (p->width == (sizeof(ch->max_match_value) * 8)) + if (cmt->width == (sizeof(ch->max_match_value) * 8)) ch->max_match_value = ~0; else - ch->max_match_value = (1 << p->width) - 1; + ch->max_match_value = (1 << cmt->width) - 1; - ch->cmt = p; + ch->cmt = cmt; ch->match_value = ch->max_match_value; raw_spin_lock_init(&ch->lock); - ret = sh_cmt_register(ch, (char *)dev_name(&p->pdev->dev), + ret = sh_cmt_register(ch, (char *)dev_name(&cmt->pdev->dev), cfg->clockevent_rating, cfg->clocksource_rating); if (ret) { - dev_err(&p->pdev->dev, "registration failed\n"); + dev_err(&cmt->pdev->dev, "registration failed\n"); goto err4; } ch->cs_enabled = false; ret = request_irq(irq, sh_cmt_interrupt, IRQF_TIMER | IRQF_IRQPOLL | IRQF_NOBALANCING, - dev_name(&p->pdev->dev), ch); + dev_name(&cmt->pdev->dev), ch); if (ret) { - dev_err(&p->pdev->dev, "failed to request irq %d\n", irq); + dev_err(&cmt->pdev->dev, "failed to request irq %d\n", irq); goto err4; } - platform_set_drvdata(pdev, p); + platform_set_drvdata(pdev, cmt); return 0; err4: - clk_unprepare(p->clk); + clk_unprepare(cmt->clk); err3: - clk_put(p->clk); + clk_put(cmt->clk); err2: - iounmap(p->mapbase_str); + iounmap(cmt->mapbase_str); err1: - iounmap(p->mapbase); + iounmap(cmt->mapbase); err0: return ret; } static int sh_cmt_probe(struct platform_device *pdev) { - struct sh_cmt_priv *p = platform_get_drvdata(pdev); + struct sh_cmt_device *cmt = platform_get_drvdata(pdev); struct sh_timer_config *cfg = pdev->dev.platform_data; int ret; @@ -827,20 +827,20 @@ static int sh_cmt_probe(struct platform_device *pdev) pm_runtime_enable(&pdev->dev); } - if (p) { + if (cmt) { dev_info(&pdev->dev, "kept as earlytimer\n"); goto out; } - p = kmalloc(sizeof(*p), GFP_KERNEL); - if (p == NULL) { + cmt = kmalloc(sizeof(*cmt), GFP_KERNEL); + if (cmt == NULL) { dev_err(&pdev->dev, "failed to allocate driver data\n"); return -ENOMEM; } - ret = sh_cmt_setup(p, pdev); + ret = sh_cmt_setup(cmt, pdev); if (ret) { - kfree(p); + kfree(cmt); pm_runtime_idle(&pdev->dev); return ret; } -- cgit v1.2.3 From b882e7b13bc12b3d6b00e4ea2fe374413ddcdd2d Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 27 Jan 2014 22:04:17 +0100 Subject: clocksource: sh_cmt: Split channel setup to separate function Move the channel setup code from sh_cmt_setup to a new sh_cmt_setup_channel function and call it from sh_cmt_setup. Signed-off-by: Laurent Pinchart --- drivers/clocksource/sh_cmt.c | 79 ++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 32 deletions(-) (limited to 'drivers/clocksource') diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index 604199a22265..26f73cf609ba 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c @@ -693,12 +693,55 @@ static int sh_cmt_register(struct sh_cmt_channel *ch, char *name, return 0; } +static int sh_cmt_setup_channel(struct sh_cmt_channel *ch, + struct sh_cmt_device *cmt) +{ + struct sh_timer_config *cfg = cmt->pdev->dev.platform_data; + int irq; + int ret; + + memset(ch, 0, sizeof(*ch)); + ch->cmt = cmt; + + irq = platform_get_irq(cmt->pdev, 0); + if (irq < 0) { + dev_err(&cmt->pdev->dev, "failed to get irq\n"); + return irq; + } + + if (cmt->width == (sizeof(ch->max_match_value) * 8)) + ch->max_match_value = ~0; + else + ch->max_match_value = (1 << cmt->width) - 1; + + ch->match_value = ch->max_match_value; + raw_spin_lock_init(&ch->lock); + + ret = sh_cmt_register(ch, (char *)dev_name(&cmt->pdev->dev), + cfg->clockevent_rating, + cfg->clocksource_rating); + if (ret) { + dev_err(&cmt->pdev->dev, "registration failed\n"); + return ret; + } + ch->cs_enabled = false; + + ret = request_irq(irq, sh_cmt_interrupt, + IRQF_TIMER | IRQF_IRQPOLL | IRQF_NOBALANCING, + dev_name(&cmt->pdev->dev), ch); + if (ret) { + dev_err(&cmt->pdev->dev, "failed to request irq %d\n", irq); + return ret; + } + + return 0; +} + static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev) { struct sh_timer_config *cfg = pdev->dev.platform_data; - struct sh_cmt_channel *ch = &cmt->channel; struct resource *res, *res2; - int irq, ret; + int ret; ret = -ENXIO; memset(cmt, 0, sizeof(*cmt)); @@ -718,12 +761,6 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev) /* optional resource for the shared timer start/stop register */ res2 = platform_get_resource(cmt->pdev, IORESOURCE_MEM, 1); - irq = platform_get_irq(cmt->pdev, 0); - if (irq < 0) { - dev_err(&cmt->pdev->dev, "failed to get irq\n"); - goto err0; - } - /* map memory, let mapbase point to our channel */ cmt->mapbase = ioremap_nocache(res->start, resource_size(res)); if (cmt->mapbase == NULL) { @@ -775,31 +812,9 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev) cmt->clear_bits = ~0xc000; } - if (cmt->width == (sizeof(ch->max_match_value) * 8)) - ch->max_match_value = ~0; - else - ch->max_match_value = (1 << cmt->width) - 1; - - ch->cmt = cmt; - ch->match_value = ch->max_match_value; - raw_spin_lock_init(&ch->lock); - - ret = sh_cmt_register(ch, (char *)dev_name(&cmt->pdev->dev), - cfg->clockevent_rating, - cfg->clocksource_rating); - if (ret) { - dev_err(&cmt->pdev->dev, "registration failed\n"); - goto err4; - } - ch->cs_enabled = false; - - ret = request_irq(irq, sh_cmt_interrupt, - IRQF_TIMER | IRQF_IRQPOLL | IRQF_NOBALANCING, - dev_name(&cmt->pdev->dev), ch); - if (ret) { - dev_err(&cmt->pdev->dev, "failed to request irq %d\n", irq); + ret = sh_cmt_setup_channel(&cmt->channel, cmt); + if (ret < 0) goto err4; - } platform_set_drvdata(pdev, cmt); -- cgit v1.2.3 From 1d053e1d8eb28f42b7ec57d1c11ce70b8fba45ff Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 17 Feb 2014 16:04:16 +0100 Subject: clocksource: sh_cmt: Constify name argument to sh_cmt_register() The name argument is assigned to const structure fields only, constify it. Signed-off-by: Laurent Pinchart --- drivers/clocksource/sh_cmt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/clocksource') diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index 26f73cf609ba..febd6bf7a37d 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c @@ -549,7 +549,7 @@ static void sh_cmt_clocksource_resume(struct clocksource *cs) } static int sh_cmt_register_clocksource(struct sh_cmt_channel *ch, - char *name, unsigned long rating) + const char *name, unsigned long rating) { struct clocksource *cs = &ch->cs; @@ -660,7 +660,7 @@ static void sh_cmt_clock_event_resume(struct clock_event_device *ced) } static void sh_cmt_register_clockevent(struct sh_cmt_channel *ch, - char *name, unsigned long rating) + const char *name, unsigned long rating) { struct clock_event_device *ced = &ch->ced; @@ -680,7 +680,7 @@ static void sh_cmt_register_clockevent(struct sh_cmt_channel *ch, clockevents_register_device(ced); } -static int sh_cmt_register(struct sh_cmt_channel *ch, char *name, +static int sh_cmt_register(struct sh_cmt_channel *ch, const char *name, unsigned long clockevent_rating, unsigned long clocksource_rating) { @@ -717,7 +717,7 @@ static int sh_cmt_setup_channel(struct sh_cmt_channel *ch, ch->match_value = ch->max_match_value; raw_spin_lock_init(&ch->lock); - ret = sh_cmt_register(ch, (char *)dev_name(&cmt->pdev->dev), + ret = sh_cmt_register(ch, dev_name(&cmt->pdev->dev), cfg->clockevent_rating, cfg->clocksource_rating); if (ret) { -- cgit v1.2.3 From 36f1ac982d94cd3cce8ae24abd0676b79dec6126 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 27 Jan 2014 22:04:17 +0100 Subject: clocksource: sh_cmt: Rename mapbase/mapbase_str to mapbase_ch/mapbase The mapbase variable points to the mapped base address of the channel, rename it to mapbase_sh. mapbase_str points to the mapped base address of the CMT device, rename it to mapbase. Signed-off-by: Laurent Pinchart --- drivers/clocksource/sh_cmt.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'drivers/clocksource') diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index febd6bf7a37d..eb93b889e189 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c @@ -55,8 +55,8 @@ struct sh_cmt_channel { struct sh_cmt_device { struct platform_device *pdev; + void __iomem *mapbase_ch; void __iomem *mapbase; - void __iomem *mapbase_str; struct clk *clk; struct sh_cmt_channel channel; @@ -125,41 +125,41 @@ static void sh_cmt_write32(void __iomem *base, unsigned long offs, static inline unsigned long sh_cmt_read_cmstr(struct sh_cmt_channel *ch) { - return ch->cmt->read_control(ch->cmt->mapbase_str, 0); + return ch->cmt->read_control(ch->cmt->mapbase, 0); } static inline unsigned long sh_cmt_read_cmcsr(struct sh_cmt_channel *ch) { - return ch->cmt->read_control(ch->cmt->mapbase, CMCSR); + return ch->cmt->read_control(ch->cmt->mapbase_ch, CMCSR); } static inline unsigned long sh_cmt_read_cmcnt(struct sh_cmt_channel *ch) { - return ch->cmt->read_count(ch->cmt->mapbase, CMCNT); + return ch->cmt->read_count(ch->cmt->mapbase_ch, CMCNT); } static inline void sh_cmt_write_cmstr(struct sh_cmt_channel *ch, unsigned long value) { - ch->cmt->write_control(ch->cmt->mapbase_str, 0, value); + ch->cmt->write_control(ch->cmt->mapbase, 0, value); } static inline void sh_cmt_write_cmcsr(struct sh_cmt_channel *ch, unsigned long value) { - ch->cmt->write_control(ch->cmt->mapbase, CMCSR, value); + ch->cmt->write_control(ch->cmt->mapbase_ch, CMCSR, value); } static inline void sh_cmt_write_cmcnt(struct sh_cmt_channel *ch, unsigned long value) { - ch->cmt->write_count(ch->cmt->mapbase, CMCNT, value); + ch->cmt->write_count(ch->cmt->mapbase_ch, CMCNT, value); } static inline void sh_cmt_write_cmcor(struct sh_cmt_channel *ch, unsigned long value) { - ch->cmt->write_count(ch->cmt->mapbase, CMCOR, value); + ch->cmt->write_count(ch->cmt->mapbase_ch, CMCOR, value); } static unsigned long sh_cmt_get_counter(struct sh_cmt_channel *ch, @@ -761,18 +761,18 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev) /* optional resource for the shared timer start/stop register */ res2 = platform_get_resource(cmt->pdev, IORESOURCE_MEM, 1); - /* map memory, let mapbase point to our channel */ - cmt->mapbase = ioremap_nocache(res->start, resource_size(res)); - if (cmt->mapbase == NULL) { + /* map memory, let mapbase_ch point to our channel */ + cmt->mapbase_ch = ioremap_nocache(res->start, resource_size(res)); + if (cmt->mapbase_ch == NULL) { dev_err(&cmt->pdev->dev, "failed to remap I/O memory\n"); goto err0; } /* map second resource for CMSTR */ - cmt->mapbase_str = ioremap_nocache(res2 ? res2->start : - res->start - cfg->channel_offset, - res2 ? resource_size(res2) : 2); - if (cmt->mapbase_str == NULL) { + cmt->mapbase = ioremap_nocache(res2 ? res2->start : + res->start - cfg->channel_offset, + res2 ? resource_size(res2) : 2); + if (cmt->mapbase == NULL) { dev_err(&cmt->pdev->dev, "failed to remap I/O second memory\n"); goto err1; } @@ -824,9 +824,9 @@ err4: err3: clk_put(cmt->clk); err2: - iounmap(cmt->mapbase_str); -err1: iounmap(cmt->mapbase); +err1: + iounmap(cmt->mapbase_ch); err0: return ret; } -- cgit v1.2.3 From c924d2d2a964715b55b6601be338b3bd05a1ced5 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 27 Jan 2014 22:04:17 +0100 Subject: clocksource: sh_cmt: Add memory base to sh_cmt_channel structure The channel memory base is channel-specific, add it to the channel structure in preparation for support of multiple channels per device. Signed-off-by: Laurent Pinchart --- drivers/clocksource/sh_cmt.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'drivers/clocksource') diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index eb93b889e189..4fcb05dc9ea4 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c @@ -40,6 +40,8 @@ struct sh_cmt_device; struct sh_cmt_channel { struct sh_cmt_device *cmt; + void __iomem *base; + unsigned long flags; unsigned long match_value; unsigned long next_match_value; @@ -130,12 +132,12 @@ static inline unsigned long sh_cmt_read_cmstr(struct sh_cmt_channel *ch) static inline unsigned long sh_cmt_read_cmcsr(struct sh_cmt_channel *ch) { - return ch->cmt->read_control(ch->cmt->mapbase_ch, CMCSR); + return ch->cmt->read_control(ch->base, CMCSR); } static inline unsigned long sh_cmt_read_cmcnt(struct sh_cmt_channel *ch) { - return ch->cmt->read_count(ch->cmt->mapbase_ch, CMCNT); + return ch->cmt->read_count(ch->base, CMCNT); } static inline void sh_cmt_write_cmstr(struct sh_cmt_channel *ch, @@ -147,19 +149,19 @@ static inline void sh_cmt_write_cmstr(struct sh_cmt_channel *ch, static inline void sh_cmt_write_cmcsr(struct sh_cmt_channel *ch, unsigned long value) { - ch->cmt->write_control(ch->cmt->mapbase_ch, CMCSR, value); + ch->cmt->write_control(ch->base, CMCSR, value); } static inline void sh_cmt_write_cmcnt(struct sh_cmt_channel *ch, unsigned long value) { - ch->cmt->write_count(ch->cmt->mapbase_ch, CMCNT, value); + ch->cmt->write_count(ch->base, CMCNT, value); } static inline void sh_cmt_write_cmcor(struct sh_cmt_channel *ch, unsigned long value) { - ch->cmt->write_count(ch->cmt->mapbase_ch, CMCOR, value); + ch->cmt->write_count(ch->base, CMCOR, value); } static unsigned long sh_cmt_get_counter(struct sh_cmt_channel *ch, @@ -702,6 +704,7 @@ static int sh_cmt_setup_channel(struct sh_cmt_channel *ch, memset(ch, 0, sizeof(*ch)); ch->cmt = cmt; + ch->base = cmt->mapbase_ch; irq = platform_get_irq(cmt->pdev, 0); if (irq < 0) { -- cgit v1.2.3 From 740a95184dd61eb0481f75ced05ea5e01b7ce6ac Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 27 Jan 2014 22:04:17 +0100 Subject: clocksource: sh_cmt: Add index to struct sh_cmt_channel Use the index when printing messages to identify the channel. Signed-off-by: Laurent Pinchart --- drivers/clocksource/sh_cmt.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'drivers/clocksource') diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index 4fcb05dc9ea4..6b65621a9733 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c @@ -39,6 +39,7 @@ struct sh_cmt_device; struct sh_cmt_channel { struct sh_cmt_device *cmt; + unsigned int index; void __iomem *base; @@ -216,7 +217,8 @@ static int sh_cmt_enable(struct sh_cmt_channel *ch, unsigned long *rate) /* enable clock */ ret = clk_enable(ch->cmt->clk); if (ret) { - dev_err(&ch->cmt->pdev->dev, "cannot enable clock\n"); + dev_err(&ch->cmt->pdev->dev, "ch%u: cannot enable clock\n", + ch->index); goto err0; } @@ -253,7 +255,8 @@ static int sh_cmt_enable(struct sh_cmt_channel *ch, unsigned long *rate) } if (sh_cmt_read_cmcnt(ch)) { - dev_err(&ch->cmt->pdev->dev, "cannot clear CMCNT\n"); + dev_err(&ch->cmt->pdev->dev, "ch%u: cannot clear CMCNT\n", + ch->index); ret = -ETIMEDOUT; goto err1; } @@ -371,7 +374,8 @@ static void sh_cmt_clock_event_program_verify(struct sh_cmt_channel *ch, delay = 1; if (!delay) - dev_warn(&ch->cmt->pdev->dev, "too long delay\n"); + dev_warn(&ch->cmt->pdev->dev, "ch%u: too long delay\n", + ch->index); } while (delay); } @@ -379,7 +383,8 @@ static void sh_cmt_clock_event_program_verify(struct sh_cmt_channel *ch, static void __sh_cmt_set_next(struct sh_cmt_channel *ch, unsigned long delta) { if (delta > ch->max_match_value) - dev_warn(&ch->cmt->pdev->dev, "delta out of range\n"); + dev_warn(&ch->cmt->pdev->dev, "ch%u: delta out of range\n", + ch->index); ch->next_match_value = delta; sh_cmt_clock_event_program_verify(ch, 0); @@ -565,7 +570,8 @@ static int sh_cmt_register_clocksource(struct sh_cmt_channel *ch, cs->mask = CLOCKSOURCE_MASK(sizeof(unsigned long) * 8); cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; - dev_info(&ch->cmt->pdev->dev, "used as clock source\n"); + dev_info(&ch->cmt->pdev->dev, "ch%u: used as clock source\n", + ch->index); /* Register with dummy 1 Hz value, gets updated in ->enable() */ clocksource_register_hz(cs, 1); @@ -614,12 +620,12 @@ static void sh_cmt_clock_event_mode(enum clock_event_mode mode, switch (mode) { case CLOCK_EVT_MODE_PERIODIC: dev_info(&ch->cmt->pdev->dev, - "used for periodic clock events\n"); + "ch%u: used for periodic clock events\n", ch->index); sh_cmt_clock_event_start(ch, 1); break; case CLOCK_EVT_MODE_ONESHOT: dev_info(&ch->cmt->pdev->dev, - "used for oneshot clock events\n"); + "ch%u: used for oneshot clock events\n", ch->index); sh_cmt_clock_event_start(ch, 0); break; case CLOCK_EVT_MODE_SHUTDOWN: @@ -678,7 +684,8 @@ static void sh_cmt_register_clockevent(struct sh_cmt_channel *ch, ced->suspend = sh_cmt_clock_event_suspend; ced->resume = sh_cmt_clock_event_resume; - dev_info(&ch->cmt->pdev->dev, "used for clock events\n"); + dev_info(&ch->cmt->pdev->dev, "ch%u: used for clock events\n", + ch->index); clockevents_register_device(ced); } @@ -695,7 +702,7 @@ static int sh_cmt_register(struct sh_cmt_channel *ch, const char *name, return 0; } -static int sh_cmt_setup_channel(struct sh_cmt_channel *ch, +static int sh_cmt_setup_channel(struct sh_cmt_channel *ch, unsigned int index, struct sh_cmt_device *cmt) { struct sh_timer_config *cfg = cmt->pdev->dev.platform_data; @@ -705,10 +712,12 @@ static int sh_cmt_setup_channel(struct sh_cmt_channel *ch, memset(ch, 0, sizeof(*ch)); ch->cmt = cmt; ch->base = cmt->mapbase_ch; + ch->index = index; irq = platform_get_irq(cmt->pdev, 0); if (irq < 0) { - dev_err(&cmt->pdev->dev, "failed to get irq\n"); + dev_err(&cmt->pdev->dev, "ch%u: failed to get irq\n", + ch->index); return irq; } @@ -724,7 +733,8 @@ static int sh_cmt_setup_channel(struct sh_cmt_channel *ch, cfg->clockevent_rating, cfg->clocksource_rating); if (ret) { - dev_err(&cmt->pdev->dev, "registration failed\n"); + dev_err(&cmt->pdev->dev, "ch%u: registration failed\n", + ch->index); return ret; } ch->cs_enabled = false; @@ -733,7 +743,8 @@ static int sh_cmt_setup_channel(struct sh_cmt_channel *ch, IRQF_TIMER | IRQF_IRQPOLL | IRQF_NOBALANCING, dev_name(&cmt->pdev->dev), ch); if (ret) { - dev_err(&cmt->pdev->dev, "failed to request irq %d\n", irq); + dev_err(&cmt->pdev->dev, "ch%u: failed to request irq %d\n", + ch->index, irq); return ret; } @@ -815,7 +826,7 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev) cmt->clear_bits = ~0xc000; } - ret = sh_cmt_setup_channel(&cmt->channel, cmt); + ret = sh_cmt_setup_channel(&cmt->channel, cfg->timer_bit, cmt); if (ret < 0) goto err4; -- cgit v1.2.3 From b262bc74dcfd77355720342cbcf89cc8ec12e86b Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 27 Jan 2014 22:04:17 +0100 Subject: clocksource: sh_cmt: Replace kmalloc + memset with kzalloc One kzalloc a day keeps the bugs away. Signed-off-by: Laurent Pinchart --- drivers/clocksource/sh_cmt.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'drivers/clocksource') diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index 6b65621a9733..0779bf194aea 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c @@ -672,8 +672,6 @@ static void sh_cmt_register_clockevent(struct sh_cmt_channel *ch, { struct clock_event_device *ced = &ch->ced; - memset(ced, 0, sizeof(*ced)); - ced->name = name; ced->features = CLOCK_EVT_FEAT_PERIODIC; ced->features |= CLOCK_EVT_FEAT_ONESHOT; @@ -709,7 +707,6 @@ static int sh_cmt_setup_channel(struct sh_cmt_channel *ch, unsigned int index, int irq; int ret; - memset(ch, 0, sizeof(*ch)); ch->cmt = cmt; ch->base = cmt->mapbase_ch; ch->index = index; @@ -758,7 +755,6 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev) int ret; ret = -ENXIO; - memset(cmt, 0, sizeof(*cmt)); cmt->pdev = pdev; if (!cfg) { @@ -861,7 +857,7 @@ static int sh_cmt_probe(struct platform_device *pdev) goto out; } - cmt = kmalloc(sizeof(*cmt), GFP_KERNEL); + cmt = kzalloc(sizeof(*cmt), GFP_KERNEL); if (cmt == NULL) { dev_err(&pdev->dev, "failed to allocate driver data\n"); return -ENOMEM; -- cgit v1.2.3 From f5ec9b194a93c05e2ccdb3e90d9061cfedc806d9 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 27 Jan 2014 22:04:17 +0100 Subject: clocksource: sh_cmt: Allocate channels dynamically This prepares the driver for multi-channel support. Signed-off-by: Laurent Pinchart --- drivers/clocksource/sh_cmt.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'drivers/clocksource') diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index 0779bf194aea..f94db327ac7c 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c @@ -62,7 +62,8 @@ struct sh_cmt_device { void __iomem *mapbase; struct clk *clk; - struct sh_cmt_channel channel; + struct sh_cmt_channel *channels; + unsigned int num_channels; unsigned long width; /* 16 or 32 bit version of hardware block */ unsigned long overflow_bit; @@ -822,7 +823,15 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev) cmt->clear_bits = ~0xc000; } - ret = sh_cmt_setup_channel(&cmt->channel, cfg->timer_bit, cmt); + cmt->channels = kzalloc(sizeof(*cmt->channels), GFP_KERNEL); + if (cmt->channels == NULL) { + ret = -ENOMEM; + goto err4; + } + + cmt->num_channels = 1; + + ret = sh_cmt_setup_channel(&cmt->channels[0], cfg->timer_bit, cmt); if (ret < 0) goto err4; @@ -830,6 +839,7 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev) return 0; err4: + kfree(cmt->channels); clk_unprepare(cmt->clk); err3: clk_put(cmt->clk); -- cgit v1.2.3 From 2cda3ac49d5744432e9ebffb8ba47bef6eca053d Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 11 Feb 2014 23:46:48 +0100 Subject: clocksource: sh_cmt: Split static information from sh_cmt_device Create a new sh_cmt_info structure to hold static information about the device model and reference that structure from the sh_cmt_device structure. Signed-off-by: Laurent Pinchart --- drivers/clocksource/sh_cmt.c | 192 +++++++++++++++++++++++++++---------------- 1 file changed, 122 insertions(+), 70 deletions(-) (limited to 'drivers/clocksource') diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index f94db327ac7c..879b8c2ae556 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c @@ -37,6 +37,52 @@ struct sh_cmt_device; +/* + * The CMT comes in 5 different identified flavours, depending not only on the + * SoC but also on the particular instance. The following table lists the main + * characteristics of those flavours. + * + * 16B 32B 32B-F 48B 48B-2 + * ----------------------------------------------------------------------------- + * Channels 2 1/4 1 6 2/8 + * Control Width 16 16 16 16 32 + * Counter Width 16 32 32 32/48 32/48 + * Shared Start/Stop Y Y Y Y N + * + * The 48-bit gen2 version has a per-channel start/stop register located in the + * channel registers block. All other versions have a shared start/stop register + * located in the global space. + * + * Note that CMT0 on r8a73a4, r8a7790 and r8a7791, while implementing 32-bit + * channels only, is a 48-bit gen2 CMT with the 48-bit channels unavailable. + */ + +enum sh_cmt_model { + SH_CMT_16BIT, + SH_CMT_32BIT, + SH_CMT_32BIT_FAST, + SH_CMT_48BIT, + SH_CMT_48BIT_GEN2, +}; + +struct sh_cmt_info { + enum sh_cmt_model model; + + unsigned long width; /* 16 or 32 bit version of hardware block */ + unsigned long overflow_bit; + unsigned long clear_bits; + + /* callbacks for CMSTR and CMCSR access */ + unsigned long (*read_control)(void __iomem *base, unsigned long offs); + void (*write_control)(void __iomem *base, unsigned long offs, + unsigned long value); + + /* callbacks for CMCNT and CMCOR access */ + unsigned long (*read_count)(void __iomem *base, unsigned long offs); + void (*write_count)(void __iomem *base, unsigned long offs, + unsigned long value); +}; + struct sh_cmt_channel { struct sh_cmt_device *cmt; unsigned int index; @@ -58,49 +104,16 @@ struct sh_cmt_channel { struct sh_cmt_device { struct platform_device *pdev; + const struct sh_cmt_info *info; + void __iomem *mapbase_ch; void __iomem *mapbase; struct clk *clk; struct sh_cmt_channel *channels; unsigned int num_channels; - - unsigned long width; /* 16 or 32 bit version of hardware block */ - unsigned long overflow_bit; - unsigned long clear_bits; - - /* callbacks for CMSTR and CMCSR access */ - unsigned long (*read_control)(void __iomem *base, unsigned long offs); - void (*write_control)(void __iomem *base, unsigned long offs, - unsigned long value); - - /* callbacks for CMCNT and CMCOR access */ - unsigned long (*read_count)(void __iomem *base, unsigned long offs); - void (*write_count)(void __iomem *base, unsigned long offs, - unsigned long value); }; -/* Examples of supported CMT timer register layouts and I/O access widths: - * - * "16-bit counter and 16-bit control" as found on sh7263: - * CMSTR 0xfffec000 16-bit - * CMCSR 0xfffec002 16-bit - * CMCNT 0xfffec004 16-bit - * CMCOR 0xfffec006 16-bit - * - * "32-bit counter and 16-bit control" as found on sh7372, sh73a0, r8a7740: - * CMSTR 0xffca0000 16-bit - * CMCSR 0xffca0060 16-bit - * CMCNT 0xffca0064 32-bit - * CMCOR 0xffca0068 32-bit - * - * "32-bit counter and 32-bit control" as found on r8a73a4 and r8a7790: - * CMSTR 0xffca0500 32-bit - * CMCSR 0xffca0510 32-bit - * CMCNT 0xffca0514 32-bit - * CMCOR 0xffca0518 32-bit - */ - static unsigned long sh_cmt_read16(void __iomem *base, unsigned long offs) { return ioread16(base + (offs << 1)); @@ -123,47 +136,100 @@ static void sh_cmt_write32(void __iomem *base, unsigned long offs, iowrite32(value, base + (offs << 2)); } +static const struct sh_cmt_info sh_cmt_info[] = { + [SH_CMT_16BIT] = { + .model = SH_CMT_16BIT, + .width = 16, + .overflow_bit = 0x80, + .clear_bits = ~0x80, + .read_control = sh_cmt_read16, + .write_control = sh_cmt_write16, + .read_count = sh_cmt_read16, + .write_count = sh_cmt_write16, + }, + [SH_CMT_32BIT] = { + .model = SH_CMT_32BIT, + .width = 32, + .overflow_bit = 0x8000, + .clear_bits = ~0xc000, + .read_control = sh_cmt_read16, + .write_control = sh_cmt_write16, + .read_count = sh_cmt_read32, + .write_count = sh_cmt_write32, + }, + [SH_CMT_32BIT_FAST] = { + .model = SH_CMT_32BIT_FAST, + .width = 32, + .overflow_bit = 0x8000, + .clear_bits = ~0xc000, + .read_control = sh_cmt_read16, + .write_control = sh_cmt_write16, + .read_count = sh_cmt_read32, + .write_count = sh_cmt_write32, + }, + [SH_CMT_48BIT] = { + .model = SH_CMT_48BIT, + .width = 32, + .overflow_bit = 0x8000, + .clear_bits = ~0xc000, + .read_control = sh_cmt_read32, + .write_control = sh_cmt_write32, + .read_count = sh_cmt_read32, + .write_count = sh_cmt_write32, + }, + [SH_CMT_48BIT_GEN2] = { + .model = SH_CMT_48BIT_GEN2, + .width = 32, + .overflow_bit = 0x8000, + .clear_bits = ~0xc000, + .read_control = sh_cmt_read32, + .write_control = sh_cmt_write32, + .read_count = sh_cmt_read32, + .write_count = sh_cmt_write32, + }, +}; + #define CMCSR 0 /* channel register */ #define CMCNT 1 /* channel register */ #define CMCOR 2 /* channel register */ static inline unsigned long sh_cmt_read_cmstr(struct sh_cmt_channel *ch) { - return ch->cmt->read_control(ch->cmt->mapbase, 0); + return ch->cmt->info->read_control(ch->cmt->mapbase, 0); } static inline unsigned long sh_cmt_read_cmcsr(struct sh_cmt_channel *ch) { - return ch->cmt->read_control(ch->base, CMCSR); + return ch->cmt->info->read_control(ch->base, CMCSR); } static inline unsigned long sh_cmt_read_cmcnt(struct sh_cmt_channel *ch) { - return ch->cmt->read_count(ch->base, CMCNT); + return ch->cmt->info->read_count(ch->base, CMCNT); } static inline void sh_cmt_write_cmstr(struct sh_cmt_channel *ch, unsigned long value) { - ch->cmt->write_control(ch->cmt->mapbase, 0, value); + ch->cmt->info->write_control(ch->cmt->mapbase, 0, value); } static inline void sh_cmt_write_cmcsr(struct sh_cmt_channel *ch, unsigned long value) { - ch->cmt->write_control(ch->base, CMCSR, value); + ch->cmt->info->write_control(ch->base, CMCSR, value); } static inline void sh_cmt_write_cmcnt(struct sh_cmt_channel *ch, unsigned long value) { - ch->cmt->write_count(ch->base, CMCNT, value); + ch->cmt->info->write_count(ch->base, CMCNT, value); } static inline void sh_cmt_write_cmcor(struct sh_cmt_channel *ch, unsigned long value) { - ch->cmt->write_count(ch->base, CMCOR, value); + ch->cmt->info->write_count(ch->base, CMCOR, value); } static unsigned long sh_cmt_get_counter(struct sh_cmt_channel *ch, @@ -172,7 +238,7 @@ static unsigned long sh_cmt_get_counter(struct sh_cmt_channel *ch, unsigned long v1, v2, v3; int o1, o2; - o1 = sh_cmt_read_cmcsr(ch) & ch->cmt->overflow_bit; + o1 = sh_cmt_read_cmcsr(ch) & ch->cmt->info->overflow_bit; /* Make sure the timer value is stable. Stolen from acpi_pm.c */ do { @@ -180,7 +246,7 @@ static unsigned long sh_cmt_get_counter(struct sh_cmt_channel *ch, v1 = sh_cmt_read_cmcnt(ch); v2 = sh_cmt_read_cmcnt(ch); v3 = sh_cmt_read_cmcnt(ch); - o1 = sh_cmt_read_cmcsr(ch) & ch->cmt->overflow_bit; + o1 = sh_cmt_read_cmcsr(ch) & ch->cmt->info->overflow_bit; } while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3) || (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2))); @@ -227,7 +293,7 @@ static int sh_cmt_enable(struct sh_cmt_channel *ch, unsigned long *rate) sh_cmt_start_stop_ch(ch, 0); /* configure channel, periodic mode and maximum timeout */ - if (ch->cmt->width == 16) { + if (ch->cmt->info->width == 16) { *rate = clk_get_rate(ch->cmt->clk) / 512; sh_cmt_write_cmcsr(ch, 0x43); } else { @@ -405,7 +471,8 @@ static irqreturn_t sh_cmt_interrupt(int irq, void *dev_id) struct sh_cmt_channel *ch = dev_id; /* clear flags */ - sh_cmt_write_cmcsr(ch, sh_cmt_read_cmcsr(ch) & ch->cmt->clear_bits); + sh_cmt_write_cmcsr(ch, sh_cmt_read_cmcsr(ch) & + ch->cmt->info->clear_bits); /* update clock source counter to begin with if enabled * the wrap flag should be cleared by the timer specific @@ -719,10 +786,10 @@ static int sh_cmt_setup_channel(struct sh_cmt_channel *ch, unsigned int index, return irq; } - if (cmt->width == (sizeof(ch->max_match_value) * 8)) + if (cmt->info->width == (sizeof(ch->max_match_value) * 8)) ch->max_match_value = ~0; else - ch->max_match_value = (1 << cmt->width) - 1; + ch->max_match_value = (1 << cmt->info->width) - 1; ch->match_value = ch->max_match_value; raw_spin_lock_init(&ch->lock); @@ -800,28 +867,13 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev) if (ret < 0) goto err3; - if (res2 && (resource_size(res2) == 4)) { - /* assume both CMSTR and CMCSR to be 32-bit */ - cmt->read_control = sh_cmt_read32; - cmt->write_control = sh_cmt_write32; - } else { - cmt->read_control = sh_cmt_read16; - cmt->write_control = sh_cmt_write16; - } - - if (resource_size(res) == 6) { - cmt->width = 16; - cmt->read_count = sh_cmt_read16; - cmt->write_count = sh_cmt_write16; - cmt->overflow_bit = 0x80; - cmt->clear_bits = ~0x80; - } else { - cmt->width = 32; - cmt->read_count = sh_cmt_read32; - cmt->write_count = sh_cmt_write32; - cmt->overflow_bit = 0x8000; - cmt->clear_bits = ~0xc000; - } + /* identify the model based on the resources */ + if (r