Esempio n. 1
0
/* Clockevent device: use one-shot mode */
static void nmdk_clkevt_mode(enum clock_event_mode mode,
			     struct clock_event_device *dev)
{
	u32 cr;

	switch (mode) {
	case CLOCK_EVT_MODE_PERIODIC:
		pr_err("%s: periodic mode not supported\n", __func__);
		break;
	case CLOCK_EVT_MODE_ONESHOT:
		/* Load highest value, enable device, enable interrupts */
		cr = readl(mtu_base + MTU_CR(1));
		writel(0, mtu_base + MTU_LR(1));
		writel(cr | MTU_CRn_ENA, mtu_base + MTU_CR(1));
		writel(1 << 1, mtu_base + MTU_IMSC);
		break;
	case CLOCK_EVT_MODE_SHUTDOWN:
	case CLOCK_EVT_MODE_UNUSED:
		/* disable irq */
		writel(0, mtu_base + MTU_IMSC);
		/* disable timer */
		cr = readl(mtu_base + MTU_CR(1));
		cr &= ~MTU_CRn_ENA;
		writel(cr, mtu_base + MTU_CR(1));
		/* load some high default value */
		writel(0xffffffff, mtu_base + MTU_LR(1));
		break;
	case CLOCK_EVT_MODE_RESUME:
		break;
	}
}
Esempio n. 2
0
void __init nmdk_timer_init(void)
{
	unsigned long rate;
	struct clk *clk0;
	u32 cr = MTU_CRn_32BITS;

	clk0 = clk_get_sys("mtu0", NULL);
	BUG_ON(IS_ERR(clk0));

	clk_enable(clk0);

	/*
	 * Tick rate is 2.4MHz for Nomadik and 2.4Mhz, 100MHz or 133 MHz
	 * for ux500.
	 * Use a divide-by-16 counter if the tick rate is more than 32MHz.
	 * At 32 MHz, the timer (with 32 bit counter) can be programmed
	 * to wake-up at a max 127s a head in time. Dividing a 2.4 MHz timer
	 * with 16 gives too low timer resolution.
	 */
	rate = clk_get_rate(clk0);
	if (rate > 32000000) {
		rate /= 16;
		cr |= MTU_CRn_PRESCALE_16;
	} else {
		cr |= MTU_CRn_PRESCALE_1;
	}

	/* Timer 0 is the free running clocksource */
	writel(cr, mtu_base + MTU_CR(0));
	writel(0, mtu_base + MTU_LR(0));
	writel(0, mtu_base + MTU_BGLR(0));
	writel(cr | MTU_CRn_ENA, mtu_base + MTU_CR(0));

	/* Now the clock source is ready */
	nmdk_clksrc.read = nmdk_read_timer;

	if (clocksource_register_hz(&nmdk_clksrc, rate))
		pr_err("timer: failed to initialize clock source %s\n",
		       nmdk_clksrc.name);

	init_sched_clock(&cd, nomadik_update_sched_clock, 32, rate);

	/* Timer 1 is used for events */

	clockevents_calc_mult_shift(&nmdk_clkevt, rate, MTU_MIN_RANGE);

	writel(cr | MTU_CRn_ONESHOT, mtu_base + MTU_CR(1)); /* off, currently */

	nmdk_clkevt.max_delta_ns =
		clockevent_delta2ns(0xffffffff, &nmdk_clkevt);
	nmdk_clkevt.min_delta_ns =
		clockevent_delta2ns(0x00000002, &nmdk_clkevt);
	nmdk_clkevt.cpumask	= cpumask_of(0);

	/* Register irq and clockevents */
	setup_irq(IRQ_MTU0, &nmdk_timer_irq);
	clockevents_register_device(&nmdk_clkevt);
}
void mtu_clocksource_reset(void)
{
	writel(MTU_CRn_DIS, mtu0_base + MTU_CR(1));

	/* ClockSource: configure load and background-load, and fire it up */
	writel(u8500_cycle, mtu0_base + MTU_LR(1));
	writel(u8500_cycle, mtu0_base + MTU_BGLR(1));

	writel(MTU_CRn_PRESCALE_1 | MTU_CRn_32BITS | MTU_CRn_ENA |
	       MTU_CRn_FREERUNNING, mtu0_base + MTU_CR(1));
}
Esempio n. 4
0
void nmdk_clksrc_reset(void)
{
	
	writel(0, mtu_base + MTU_CR(0));

	
	writel(nmdk_cycle, mtu_base + MTU_LR(0));
	writel(nmdk_cycle, mtu_base + MTU_BGLR(0));

	writel(clk_prescale | MTU_CRn_32BITS | MTU_CRn_ENA,
	       mtu_base + MTU_CR(0));
}
Esempio n. 5
0
void nmdk_clksrc_reset(void)
{
	/* Disable */
	writel(0, mtu_base + MTU_CR(0));

	/* ClockSource: configure load and background-load, and fire it up */
	writel(nmdk_cycle, mtu_base + MTU_LR(0));
	writel(nmdk_cycle, mtu_base + MTU_BGLR(0));

	writel(clk_prescale | MTU_CRn_32BITS | MTU_CRn_ENA,
	       mtu_base + MTU_CR(0));
}
Esempio n. 6
0
/* Configure a free-running, auto-wrap counter with no prescaler */
int timer_init(void)
{
	writel(MTU_CRn_ENA | MTU_CRn_PRESCALE_1 | MTU_CRn_32BITS,
	       CONFIG_SYS_TIMERBASE + MTU_CR(0));
	reset_timer();
	return 0;
}
Esempio n. 7
0
/* Configure a free-running, auto-wrap counter with /16 prescaler */
int timer_init(void)
{
	timerbase = CONFIG_SYS_TIMERBASE;

	writel(MTU_CRn_ENA | MTU_CRn_PRESCALE_16 | MTU_CRn_32BITS,
	       timerbase + MTU_CR(MTU_TIMER));
	reset_timer();
	return 0;
}
/*
 * Clockevent
 */
static int u8500_mtu_clkevt_next(unsigned long evt, struct clock_event_device *ev)
{
	writel(1 << 0, mtu0_base + MTU_IMSC);
	writel(evt, mtu0_base + MTU_LR(0));
	/* Load highest value, enable device, enable interrupts */
	writel(MTU_CRn_ONESHOT | MTU_CRn_PRESCALE_1 |
	       MTU_CRn_32BITS | MTU_CRn_ENA,
	       mtu0_base + MTU_CR(0));
	return 0;
}
Esempio n. 9
0
static int nmdk_clkevt_next(unsigned long evt, struct clock_event_device *ev)
{
	writel(1 << 1, mtu_base + MTU_IMSC);
	writel(evt, mtu_base + MTU_LR(1));
	
	writel(MTU_CRn_ONESHOT | clk_prescale |
	       MTU_CRn_32BITS | MTU_CRn_ENA,
	       mtu_base + MTU_CR(1));

	return 0;
}
Esempio n. 10
0
/* Clockevent device: use one-shot mode */
static int nmdk_clkevt_next(unsigned long evt, struct clock_event_device *ev)
{
	writel(1 << 1, mtu_base + MTU_IMSC);
	writel(evt, mtu_base + MTU_LR(1));
	/* Load highest value, enable device, enable interrupts */
	writel(MTU_CRn_ONESHOT | clk_prescale |
	       MTU_CRn_32BITS | MTU_CRn_ENA,
	       mtu_base + MTU_CR(1));

	return 0;
}
Esempio n. 11
0
void nmdk_clkevt_reset(void)
{
	if (clkevt_periodic) {
		
		writel(nmdk_cycle, mtu_base + MTU_LR(1));
		writel(nmdk_cycle, mtu_base + MTU_BGLR(1));

		writel(MTU_CRn_PERIODIC | clk_prescale |
		       MTU_CRn_32BITS | MTU_CRn_ENA,
		       mtu_base + MTU_CR(1));
		writel(1 << 1, mtu_base + MTU_IMSC);
	} else {
		
		(void) nmdk_clkevt_next(nmdk_cycle, NULL);
	}
}
Esempio n. 12
0
void nmdk_clkevt_reset(void)
{
	if (clkevt_periodic) {
		/* Timer: configure load and background-load, and fire it up */
		writel(nmdk_cycle, mtu_base + MTU_LR(1));
		writel(nmdk_cycle, mtu_base + MTU_BGLR(1));

		writel(MTU_CRn_PERIODIC | clk_prescale |
		       MTU_CRn_32BITS | MTU_CRn_ENA,
		       mtu_base + MTU_CR(1));
		writel(1 << 1, mtu_base + MTU_IMSC);
	} else {
		/* Generate an interrupt to start the clockevent again */
		(void) nmdk_clkevt_next(nmdk_cycle, NULL);
	}
}
void mtu_clockevent_reset(void)
{
	if (mtu_periodic) {

		/* Timer: configure load and background-load, and fire it up */
		writel(u8500_cycle, mtu0_base + MTU_LR(0));
		writel(u8500_cycle, mtu0_base + MTU_BGLR(0));

		writel(MTU_CRn_PERIODIC | MTU_CRn_PRESCALE_1 |
		       MTU_CRn_32BITS | MTU_CRn_ENA,
		       mtu0_base + MTU_CR(0));
		writel(1 << 0, mtu0_base + MTU_IMSC);
	} else {
		/* Generate an interrupt to start the clockevent again */
		u8500_mtu_clkevt_next(u8500_cycle, NULL);
	}
}
Esempio n. 14
0
/* Configure a free-running, auto-wrap counter with no prescaler */
int timer_init(void)
{
	ulong val;

	writel(MTU_CRn_ENA | MTU_CRn_PRESCALE_1 | MTU_CRn_32BITS,
	       CONFIG_SYS_TIMERBASE + MTU_CR(0));

	/* Reset the timer */
	writel(0, CONFIG_SYS_TIMERBASE + MTU_LR(0));
	/*
	 * The load-register isn't really immediate: it changes on clock
	 * edges, so we must wait for our newly-written value to appear.
	 * Since we might miss reading 0, wait for any change in value.
	 */
	val = READ_TIMER();
	while (READ_TIMER() == val)
		;

	return 0;
}
static void u8500_mtu_clkevt_mode(enum clock_event_mode mode,
			     struct clock_event_device *dev)
{
	switch (mode) {
	case CLOCK_EVT_MODE_PERIODIC:
		mtu_periodic = true;
		mtu_clockevent_reset();
		break;
	case CLOCK_EVT_MODE_ONESHOT:
		mtu_periodic = false;
		break;
	case CLOCK_EVT_MODE_SHUTDOWN:
	case CLOCK_EVT_MODE_UNUSED:
		writel(MTU_CRn_DIS, mtu0_base + MTU_CR(0));
		writel(0, mtu0_base + MTU_IMSC);
		break;
	case CLOCK_EVT_MODE_RESUME:
		break;
	}
}
Esempio n. 16
0
static void nmdk_clkevt_mode(enum clock_event_mode mode,
			     struct clock_event_device *dev)
{
	switch (mode) {
	case CLOCK_EVT_MODE_PERIODIC:
		clkevt_periodic = true;
		nmdk_clkevt_reset();
		break;
	case CLOCK_EVT_MODE_ONESHOT:
		clkevt_periodic = false;
		break;
	case CLOCK_EVT_MODE_SHUTDOWN:
	case CLOCK_EVT_MODE_UNUSED:
		writel(0, mtu_base + MTU_IMSC);
		
		writel(0, mtu_base + MTU_CR(1));
		
		writel(0xffffffff, mtu_base + MTU_LR(1));
		break;
	case CLOCK_EVT_MODE_RESUME:
		break;
	}
}
Esempio n. 17
0
void __init nmdk_timer_init(void)
{
    unsigned long rate;
    struct clk *clk0;
    struct clk *clk1;
    u32 cr;

    clk0 = clk_get_sys("mtu0", NULL);
    BUG_ON(IS_ERR(clk0));

    clk1 = clk_get_sys("mtu1", NULL);
    BUG_ON(IS_ERR(clk1));

    clk_enable(clk0);
    clk_enable(clk1);

    /*
     * Tick rate is 2.4MHz for Nomadik and 110MHz for ux500:
     * use a divide-by-16 counter if it's more than 16MHz
     */
    cr = MTU_CRn_32BITS;;
    rate = clk_get_rate(clk0);
    if (rate > 16 << 20) {
        rate /= 16;
        cr |= MTU_CRn_PRESCALE_16;
    } else {
        cr |= MTU_CRn_PRESCALE_1;
    }
    clocksource_calc_mult_shift(&nmdk_clksrc, rate, MTU_MIN_RANGE);

    /* Timer 0 is the free running clocksource */
    writel(cr, mtu_base + MTU_CR(0));
    writel(0, mtu_base + MTU_LR(0));
    writel(0, mtu_base + MTU_BGLR(0));
    writel(cr | MTU_CRn_ENA, mtu_base + MTU_CR(0));

    /* Now the scheduling clock is ready */
    nmdk_clksrc.read = nmdk_read_timer;

    if (clocksource_register(&nmdk_clksrc))
        pr_err("timer: failed to initialize clock source %s\n",
               nmdk_clksrc.name);

    /* Timer 1 is used for events, fix according to rate */
    cr = MTU_CRn_32BITS;
    rate = clk_get_rate(clk1);
    if (rate > 16 << 20) {
        rate /= 16;
        cr |= MTU_CRn_PRESCALE_16;
    } else {
        cr |= MTU_CRn_PRESCALE_1;
    }
    clockevents_calc_mult_shift(&nmdk_clkevt, rate, MTU_MIN_RANGE);

    writel(cr | MTU_CRn_ONESHOT, mtu_base + MTU_CR(1)); /* off, currently */

    nmdk_clkevt.max_delta_ns =
        clockevent_delta2ns(0xffffffff, &nmdk_clkevt);
    nmdk_clkevt.min_delta_ns =
        clockevent_delta2ns(0x00000002, &nmdk_clkevt);
    nmdk_clkevt.cpumask	= cpumask_of(0);

    /* Register irq and clockevents */
    setup_irq(IRQ_MTU0, &nmdk_timer_irq);
    clockevents_register_device(&nmdk_clkevt);
}