[Nios2-dev] [PATCH v2] watchdog: Add driver for Altera Watchdog Timer

Walter Goossens waltergoossens at home.nl
Wed Feb 9 09:54:33 EST 2011


Hi Tobias,

One small remark below, looks ok otherwise.
Thanks for the work you put into this!

On 2/8/11 2:22 PM, Tobias Klauser wrote:
[...]
> +static struct miscdevice altera_wdt_miscdev = {
> +	.minor	= WATCHDOG_MINOR,
> +	.name	= "watchdog",
> +	.fops	=&altera_wdt_fops,
> +};
> +
> +static int __devinit altera_wdt_probe(struct platform_device *pdev)
> +{
> +	struct resource *res, *mem;
> +	const u32 *freq_prop, *timeout_prop;
Type should be const __be32 * here.
> +	unsigned long timeout;
> +	int ret;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res)
> +		return -ENOENT;
> +
> +	mem = devm_request_mem_region(&pdev->dev, res->start,
> +				      resource_size(res), pdev->name);
> +	if (!mem)
> +		return -EBUSY;
> +
> +	altera_wdt_priv.base = devm_ioremap_nocache(&pdev->dev, mem->start,
> +						    resource_size(mem));
> +	if (!altera_wdt_priv.base)
> +		return -ENOMEM;
> +
> +	freq_prop = of_get_property(pdev->dev.of_node, "clock-frequency", NULL);
> +	if (!freq_prop)
> +		return -ENODEV;
> +
> +	timeout_prop = of_get_property(pdev->dev.of_node, "timeout", NULL);
> +	if (!timeout_prop)
> +		return -ENODEV;
> +
> +	/* Add 1 as the timeout property actually holds the load value */
> +	timeout = be32_to_cpup(timeout_prop) + 1;
> +	/* Convert timeout to msecs */
> +	timeout = timeout / (be32_to_cpup(freq_prop) / MSEC_PER_SEC);
> +	/* Tickle the watchdog twice per timeout period */
> +	altera_wdt_priv.wdt_timeout = msecs_to_jiffies(timeout / 2);
> +
> +	ret = misc_register(&altera_wdt_miscdev);
> +	if (ret)
> +		return ret;
> +
> +	altera_wdt_setup();
> +	altera_wdt_priv.next_heartbeat = jiffies + heartbeat * HZ;
> +	setup_timer(&altera_wdt_priv.timer, altera_wdt_ping, 0);
> +	mod_timer(&altera_wdt_priv.timer, jiffies + altera_wdt_priv.wdt_timeout);
> +
> +	pr_info(WATCHDOG_NAME " enabled (heartbeat=%d sec, nowayout=%d)\n",
> +		heartbeat, nowayout);
> +
> +	return 0;
> +}
> +
> +static int __devexit altera_wdt_remove(struct platform_device *pdev)
> +{
> +	misc_deregister(&altera_wdt_miscdev);
> +	return 0;
> +}
> +
> +static struct of_device_id altera_wdt_match[] = {
> +	{ .compatible = "ALTR,wdt-1.0", },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, altera_wdt_match);
> +
> +static struct platform_driver altera_wdt_driver = {
> +	.probe		= altera_wdt_probe,
> +	.remove		= __devexit_p(altera_wdt_remove),
> +	.driver		= {
> +		.owner		= THIS_MODULE,
> +		.name		= WATCHDOG_NAME,
> +		.of_match_table	= altera_wdt_match,
> +	},
> +};
> +
> +static int __init altera_wdt_init(void)
> +{
> +	return platform_driver_register(&altera_wdt_driver);
> +}
> +
> +static void __exit altera_wdt_exit(void)
> +{
> +	platform_driver_unregister(&altera_wdt_driver);
> +}
> +
> +module_init(altera_wdt_init);
> +module_exit(altera_wdt_exit);
> +
> +MODULE_AUTHOR("Walter Goossens, Tobias Klauser<tklauser at distanz.ch>");
> +MODULE_DESCRIPTION("Driver for Altera Watchdog Timer");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
> +MODULE_ALIAS("platform:" WATCHDOG_NAME);



More information about the devicetree-discuss mailing list