Re: [PATCH] Add watchdog driver for w90p910

From: Wan ZongShun
Date: Tue Aug 04 2009 - 22:56:05 EST


Dear Wim,

I'm much obliged to you for helping me.
Before resubmitting fixed patch, I think it better to answer you
regarding your questions.

2009/8/5 Wim Van Sebroeck <wim@xxxxxxxxx>:
> Hi Wan,
>
> I reviewed your code and have some comments and questions.
>
> ...
>
>> +struct w90p910_wdt {
>> + Â Â struct resource Â*res;
>> +   struct clk    *wdt_clock;
>> + Â Â struct platform_device *pdev;
>> +   unsigned int   open_lock;
>> +   unsigned int   wdt_irq;
>> +   void __iomem   *wdt_base;
>> +   char       expect_close;
>> +   spinlock_t    wdt_lock;
>> +};
>
> Where is the spinlock initialized?

Sure, I forget it. sorry.
>
>> +static irqreturn_t w90p910_wdt_irq(int irq, void *dev_id)
>> +{
>> + Â Â w90p910_wdt_keepalive();
>> + Â Â return IRQ_HANDLED;
>> +}
>
> How does the interrupt work? what does the watchdog do when it times out?
> (Is there a datasheet available somewhere?)
>

The mechanism of watchdog of w90p910 is that the interrupt will occur
periodicity every a given time interval.

Hmm, there are only two choices to confirm the system running, one to
clear this WTIF and WTR bits in handler of interrupt, the other to
reset them in user application before interrupt occurs.


>> +static int w90p910_wdt_settimeout(int new_time_level)
>> +{
>> + Â Â unsigned int val;
>> +
>> + Â Â if ((new_time_level < 0) || (new_time_level > WDT_MAX_TIME_LEVEL))
>> + Â Â Â Â Â Â return -EINVAL;
>> +
>> + Â Â val = __raw_readl(w90p910_wdt->wdt_base + REG_WTCR);
>> + Â Â val &= ~WTIS;
>> + Â Â val |= new_time_level;
>
> Shouldn't this be val |= (new_time_level << 0x04); ?

sure.

> The read-write cyclus to REG_WTCR should also be guarded with a spinlock.
> Can you incorporate the call to w90p910_wdt_start() in the ioctl code into this function?
>

Do you mean that I should merge the "w90p910_wdt_settimeout" to
"w90p910_wdt_start()"? or contrary?

>
>> +static ssize_t w90p910_wdt_write(struct file *file, const char *data,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â size_t len, loff_t *ppos)
>
> should be: ..., const char __user *data, ...
>
sure.
>
>> +static int __devinit w90p910wdt_probe(struct platform_device *pdev)
>> +{
>> + Â Â int ret;
>> +
>> + Â Â w90p910_wdt = kzalloc(sizeof(struct w90p910_wdt), GFP_KERNEL);
>> + Â Â if (!w90p910_wdt)
>> + Â Â Â Â Â Â return -ENOMEM;
>> +
>> + Â Â w90p910_wdt->pdev = pdev;
>> +
>> + Â Â w90p910_wdt->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> + Â Â if (w90p910_wdt->res == NULL) {
>> + Â Â Â Â Â Â dev_err(&pdev->dev, "no memory resource specified\n");
>> + Â Â Â Â Â Â ret = -ENOENT;
>> + Â Â Â Â Â Â goto err_get;
>> + Â Â }
>> +
>> + Â Â if (!request_mem_region(w90p910_wdt->res->start,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â resource_size(w90p910_wdt->res), pdev->name)) {
>> + Â Â Â Â Â Â dev_err(&pdev->dev, "failed to get memory region\n");
>> + Â Â Â Â Â Â ret = -ENOENT;
>> + Â Â Â Â Â Â goto err_req;
>
> This should be: goto err_get;

sure.
> ...
>
>> +
>> +static int __devexit w90p910wdt_remove(struct platform_device *pdev)
>> +{
>
> The misc_deregister(&w90p910wdt_miscdev); should go first. We don't want userspace interactivity when we clean up all reservations.
>
>> + Â Â free_irq(w90p910_wdt->wdt_irq, NULL);
>> +
>> + Â Â clk_disable(w90p910_wdt->wdt_clock);
>> + Â Â clk_put(w90p910_wdt->wdt_clock);
>> +
>> + Â Â iounmap(w90p910_wdt->wdt_base);
>> +
>> + Â Â release_mem_region(w90p910_wdt->res->start,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â resource_size(w90p910_wdt->res));
>> +
>> + Â Â kfree(w90p910_wdt);
>> +
>> + Â Â misc_deregister(&w90p910wdt_miscdev);
>
> see comment about misc_deregister above.
>
> For the rest the code looks good to me.
>
> Kind regards,
> Wim.
>
>



--
Wan z.s
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/