drivers/clocksource/timer-loongson1-pwm.c

Source file repositories/reference/linux-study-clean/drivers/clocksource/timer-loongson1-pwm.c

File Facts

System
Linux kernel
Corpus path
drivers/clocksource/timer-loongson1-pwm.c
Extension
.c
Size
6139 bytes
Lines
237
Domain
Driver Families
Bucket
drivers/clocksource
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ls1x_clocksource {
	void __iomem *reg_base;
	unsigned long ticks_per_jiffy;
	struct clocksource clksrc;
};

static inline struct ls1x_clocksource *to_ls1x_clksrc(struct clocksource *c)
{
	return container_of(c, struct ls1x_clocksource, clksrc);
}

static inline void ls1x_pwmtimer_set_period(unsigned int period,
					    struct timer_of *to)
{
	writel(period, timer_of_base(to) + PWM_LRC);
	writel(period, timer_of_base(to) + PWM_HRC);
}

static inline void ls1x_pwmtimer_clear(struct timer_of *to)
{
	writel(0, timer_of_base(to) + PWM_CNTR);
}

static inline void ls1x_pwmtimer_start(struct timer_of *to)
{
	writel((INT_EN | PWM_OE | CNT_EN), timer_of_base(to) + PWM_CTRL);
}

static inline void ls1x_pwmtimer_stop(struct timer_of *to)
{
	writel(0, timer_of_base(to) + PWM_CTRL);
}

static inline void ls1x_pwmtimer_irq_ack(struct timer_of *to)
{
	int val;

	val = readl(timer_of_base(to) + PWM_CTRL);
	val |= INT_SR;
	writel(val, timer_of_base(to) + PWM_CTRL);
}

static irqreturn_t ls1x_clockevent_isr(int irq, void *dev_id)
{
	struct clock_event_device *clkevt = dev_id;
	struct timer_of *to = to_timer_of(clkevt);

	ls1x_pwmtimer_irq_ack(to);
	ls1x_pwmtimer_clear(to);
	ls1x_pwmtimer_start(to);

	clkevt->event_handler(clkevt);

	return IRQ_HANDLED;
}

static int ls1x_clockevent_set_state_periodic(struct clock_event_device *clkevt)
{
	struct timer_of *to = to_timer_of(clkevt);

	raw_spin_lock(&ls1x_timer_lock);
	ls1x_pwmtimer_set_period(timer_of_period(to), to);
	ls1x_pwmtimer_clear(to);
	ls1x_pwmtimer_start(to);
	raw_spin_unlock(&ls1x_timer_lock);

	return 0;
}

static int ls1x_clockevent_tick_resume(struct clock_event_device *clkevt)
{
	raw_spin_lock(&ls1x_timer_lock);
	ls1x_pwmtimer_start(to_timer_of(clkevt));
	raw_spin_unlock(&ls1x_timer_lock);

	return 0;
}

static int ls1x_clockevent_set_state_shutdown(struct clock_event_device *clkevt)
{
	raw_spin_lock(&ls1x_timer_lock);
	ls1x_pwmtimer_stop(to_timer_of(clkevt));
	raw_spin_unlock(&ls1x_timer_lock);

	return 0;
}

static int ls1x_clockevent_set_next(unsigned long evt,
				    struct clock_event_device *clkevt)
{

Annotation

Implementation Notes