drivers/clocksource/timer-ti-32k.c

Source file repositories/reference/linux-study-clean/drivers/clocksource/timer-ti-32k.c

File Facts

System
Linux kernel
Corpus path
drivers/clocksource/timer-ti-32k.c
Extension
.c
Size
4276 bytes
Lines
166
Domain
Driver Families
Bucket
drivers/clocksource
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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 ti_32k {
	void __iomem		*base;
	void __iomem		*counter;
	struct clocksource	cs;
};

static inline struct ti_32k *to_ti_32k(struct clocksource *cs)
{
	return container_of(cs, struct ti_32k, cs);
}

static u64 notrace ti_32k_read_cycles(struct clocksource *cs)
{
	struct ti_32k *ti = to_ti_32k(cs);

	return (u64)readl_relaxed(ti->counter);
}

static struct ti_32k ti_32k_timer = {
	.cs = {
		.name		= "32k_counter",
		.rating		= 250,
		.read		= ti_32k_read_cycles,
		.mask		= CLOCKSOURCE_MASK(32),
		.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
	},
};

static u64 notrace omap_32k_read_sched_clock(void)
{
	return ti_32k_read_cycles(&ti_32k_timer.cs);
}

static void __init ti_32k_timer_enable_clock(struct device_node *np,
					     const char *name)
{
	struct clk *clock;
	int error;

	clock = of_clk_get_by_name(np->parent, name);
	if (IS_ERR(clock)) {
		/* Only some SoCs have a separate interface clock */
		if (PTR_ERR(clock) == -EINVAL && !strncmp("ick", name, 3))
			return;

		pr_warn("%s: could not get clock %s %li\n",
			__func__, name, PTR_ERR(clock));
		return;
	}

	error = clk_prepare_enable(clock);
	if (error) {
		pr_warn("%s: could not enable %s: %i\n",
			__func__, name, error);
		return;
	}
}

static void __init ti_32k_timer_module_init(struct device_node *np,
					    void __iomem *base)
{
	void __iomem *sysc = base + 4;

	if (!of_device_is_compatible(np->parent, "ti,sysc"))
		return;

	ti_32k_timer_enable_clock(np, "fck");
	ti_32k_timer_enable_clock(np, "ick");

	/*
	 * Force idle module as wkup domain is active with MPU.
	 * No need to tag the module disabled for ti-sysc probe.
	 */
	writel_relaxed(0, sysc);
}

static int __init ti_32k_timer_init(struct device_node *np)
{
	int ret;

	ti_32k_timer.base = of_iomap(np, 0);
	if (!ti_32k_timer.base) {
		pr_err("Can't ioremap 32k timer base\n");
		return -ENXIO;
	}

	if (!of_machine_is_compatible("ti,am43"))
		ti_32k_timer.cs.flags |= CLOCK_SOURCE_SUSPEND_NONSTOP;

	ti_32k_timer.counter = ti_32k_timer.base;

Annotation

Implementation Notes