drivers/clocksource/ingenic-ost.c

Source file repositories/reference/linux-study-clean/drivers/clocksource/ingenic-ost.c

File Facts

System
Linux kernel
Corpus path
drivers/clocksource/ingenic-ost.c
Extension
.c
Size
4424 bytes
Lines
184
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 ingenic_ost_soc_info {
	bool is64bit;
};

struct ingenic_ost {
	void __iomem *regs;
	struct clk *clk;

	struct clocksource cs;
};

static struct ingenic_ost *ingenic_ost;

static u64 notrace ingenic_ost_read_cntl(void)
{
	/* Read using __iomem pointer instead of regmap to avoid locking */
	return readl(ingenic_ost->regs + OST_REG_CNTL);
}

static u64 notrace ingenic_ost_read_cnth(void)
{
	/* Read using __iomem pointer instead of regmap to avoid locking */
	return readl(ingenic_ost->regs + OST_REG_CNTH);
}

static u64 notrace ingenic_ost_clocksource_readl(struct clocksource *cs)
{
	return ingenic_ost_read_cntl();
}

static u64 notrace ingenic_ost_clocksource_readh(struct clocksource *cs)
{
	return ingenic_ost_read_cnth();
}

static int __init ingenic_ost_probe(struct platform_device *pdev)
{
	const struct ingenic_ost_soc_info *soc_info;
	struct device *dev = &pdev->dev;
	struct ingenic_ost *ost;
	struct clocksource *cs;
	struct regmap *map;
	unsigned long rate;
	int err;

	soc_info = device_get_match_data(dev);
	if (!soc_info)
		return -EINVAL;

	ost = devm_kzalloc(dev, sizeof(*ost), GFP_KERNEL);
	if (!ost)
		return -ENOMEM;

	ingenic_ost = ost;

	ost->regs = devm_platform_ioremap_resource(pdev, 0);
	if (IS_ERR(ost->regs))
		return PTR_ERR(ost->regs);

	map = device_node_to_regmap(dev->parent->of_node);
	if (IS_ERR(map)) {
		dev_err(dev, "regmap not found");
		return PTR_ERR(map);
	}

	ost->clk = devm_clk_get_enabled(dev, "ost");
	if (IS_ERR(ost->clk))
		return PTR_ERR(ost->clk);

	/* Clear counter high/low registers */
	if (soc_info->is64bit)
		regmap_write(map, TCU_REG_OST_CNTL, 0);
	regmap_write(map, TCU_REG_OST_CNTH, 0);

	/* Don't reset counter at compare value. */
	regmap_update_bits(map, TCU_REG_OST_TCSR,
			   TCU_OST_TCSR_MASK, TCU_OST_TCSR_CNT_MD);

	rate = clk_get_rate(ost->clk);

	/* Enable OST TCU channel */
	regmap_write(map, TCU_REG_TESR, BIT(TCU_OST_CHANNEL));

	cs = &ost->cs;
	cs->name	= "ingenic-ost";
	cs->rating	= 320;
	cs->flags	= CLOCK_SOURCE_IS_CONTINUOUS;
	cs->mask	= CLOCKSOURCE_MASK(32);

	if (soc_info->is64bit)

Annotation

Implementation Notes