arch/powerpc/platforms/52xx/mpc52xx_gpt.c

Source file repositories/reference/linux-study-clean/arch/powerpc/platforms/52xx/mpc52xx_gpt.c

File Facts

System
Linux kernel
Corpus path
arch/powerpc/platforms/52xx/mpc52xx_gpt.c
Extension
.c
Size
22741 bytes
Lines
781
Domain
Architecture Layer
Bucket
arch/powerpc
Inferred role
Architecture Layer: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations mpc52xx_wdt_fops = {
	.owner		= THIS_MODULE,
	.write		= mpc52xx_wdt_write,
	.unlocked_ioctl = mpc52xx_wdt_ioctl,
	.compat_ioctl	= compat_ptr_ioctl,
	.open		= mpc52xx_wdt_open,
	.release	= mpc52xx_wdt_release,
};

static struct miscdevice mpc52xx_wdt_miscdev = {
	.minor		= WATCHDOG_MINOR,
	.name		= "watchdog",
	.fops		= &mpc52xx_wdt_fops,
};

static int mpc52xx_gpt_wdt_init(void)
{
	int err;

	/* try to register the watchdog misc device */
	err = misc_register(&mpc52xx_wdt_miscdev);
	if (err)
		pr_err("%s: cannot register watchdog device\n", WDT_IDENTITY);
	else
		pr_info("%s: watchdog device registered\n", WDT_IDENTITY);
	return err;
}

static int mpc52xx_gpt_wdt_setup(struct mpc52xx_gpt_priv *gpt,
				 const u32 *period)
{
	u64 real_timeout;

	/* remember the gpt for the wdt operation */
	mpc52xx_gpt_wdt = gpt;

	/* configure the wdt if the device tree contained a timeout */
	if (!period || *period == 0)
		return 0;

	real_timeout = (u64) *period * 1000000000ULL;
	if (mpc52xx_gpt_do_start(gpt, real_timeout, 0, 1))
		dev_warn(gpt->dev, "starting as wdt failed\n");
	else
		dev_info(gpt->dev, "watchdog set to %us timeout\n", *period);
	return 0;
}

#else

static int mpc52xx_gpt_wdt_init(void)
{
	return 0;
}

static inline int mpc52xx_gpt_wdt_setup(struct mpc52xx_gpt_priv *gpt,
					const u32 *period)
{
	return 0;
}

#endif	/*  CONFIG_MPC5200_WDT	*/

/* ---------------------------------------------------------------------
 * of_platform bus binding code
 */
static int mpc52xx_gpt_probe(struct platform_device *ofdev)
{
	struct mpc52xx_gpt_priv *gpt;

	gpt = devm_kzalloc(&ofdev->dev, sizeof *gpt, GFP_KERNEL);
	if (!gpt)
		return -ENOMEM;

	raw_spin_lock_init(&gpt->lock);
	gpt->dev = &ofdev->dev;
	gpt->ipb_freq = mpc5xxx_get_bus_frequency(&ofdev->dev);
	gpt->regs = of_iomap(ofdev->dev.of_node, 0);
	if (!gpt->regs)
		return -ENOMEM;

	dev_set_drvdata(&ofdev->dev, gpt);

	mpc52xx_gpt_gpio_setup(gpt);
	mpc52xx_gpt_irq_setup(gpt, ofdev->dev.of_node);

	mutex_lock(&mpc52xx_gpt_list_mutex);
	list_add(&gpt->list, &mpc52xx_gpt_list);
	mutex_unlock(&mpc52xx_gpt_list_mutex);

Annotation

Implementation Notes