From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: Suneel Garapati <suneel.garapati@xilinx.com>
Cc: rtc-linux@googlegroups.com, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, michals@xilinx.com,
sorenb@xilinx.com, Alessandro Zummo <a.zummo@towertech.it>
Subject: Re: [rtc-linux] [PATCH v2 2/2] drivers: rtc: add xilinx zynqmp rtc driver
Date: Tue, 11 Aug 2015 20:31:31 +0200 [thread overview]
Message-ID: <20150811183131.GW3411@piout.net> (raw)
In-Reply-To: <1438336757-23404-2-git-send-email-suneel.garapati@xilinx.com>
Hi,
Please run checkpatch --strict and fix the issues.
On 31/07/2015 at 15:29:17 +0530, Suneel Garapati wrote :
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/io.h>
> +#include <linux/delay.h>
> +#include <linux/rtc.h>
> +
The includes hav to be sorted alphabetically.
> +static int xlnx_rtc_set_time(struct device *dev, struct rtc_time *tm)
> +{
> + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev);
> + unsigned long new_time;
> +
> + rtc_tm_to_time(tm, &new_time);
You should use rtc_tm_to_time64() and rtc_time64_to_tm() throughout the
file.
> + writel(new_time, xrtcdev->reg_base + RTC_SET_TM_WR);
> +
Is that a 32bits register? If yes, you probably want to return an error
if the year is 2106 or after.
> + return 0;
> +}
> +
[...]
> +static int xlnx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> +{
> + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev);
> + unsigned long alarm_time;
> +
Same comment, you probably want to error out if the time overflows a
32bits register.
> + rtc_tm_to_time(&alrm->time, &alarm_time);
> +
> + writel((u32) alarm_time, (xrtcdev->reg_base + RTC_ALRM));
> +
> + xlnx_rtc_alarm_irq_enable(dev, alrm->enabled);
> +
> + return 0;
> +}
> +
> +static void xlnx_init_rtc(struct xlnx_rtc_dev *xrtcdev, u32 calibval)
> +{
> + /*
> + * Based on crystal freq of 33.330 KHz
> + * set the secounds counter and enable, set fractions counter
typo --------------^
> + * to default value suggested as per design spec
> + * to correct RTC delay in frequency over period of time.
> + */
> + calibval &= RTC_CALIB_MASK;
> + writel(calibval, (xrtcdev->reg_base + RTC_CALIB_WR));
> +}
> +
> +static const struct rtc_class_ops xlnx_rtc_ops = {
> + .set_time = xlnx_rtc_set_time,
> + .read_time = xlnx_rtc_read_time,
> + .read_alarm = xlnx_rtc_read_alarm,
> + .set_alarm = xlnx_rtc_set_alarm,
> + .alarm_irq_enable = xlnx_rtc_alarm_irq_enable,
> +};
> +
> +static irqreturn_t xlnx_rtc_interrupt(int irq, void *id)
> +{
> + struct xlnx_rtc_dev *xrtcdev = (struct xlnx_rtc_dev *) id;
> + unsigned int status;
> +
> + status = readl(xrtcdev->reg_base + RTC_INT_STS);
> + /* Check if interrupt asserted */
> + if (!(status & (RTC_INT_SEC | RTC_INT_ALRM)))
> + return IRQ_NONE;
> +
> + /* Clear interrupt */
> + writel(status, xrtcdev->reg_base + RTC_INT_STS);
> +
> + if (status & RTC_INT_SEC)
> + rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_UF);
> + if (status & RTC_INT_ALRM)
> + rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_AF);
> + if (status & RTC_INT_ALRM)
> + printk("alarm interrupt\n");
I guess this is a debug message that you forgot to remove.
> +static int xlnx_rtc_probe(struct platform_device *pdev)
> +{
> + struct xlnx_rtc_dev *xrtcdev;
> + struct resource *res;
> + int ret;
> + unsigned int calibvalue;
> +
> + xrtcdev = devm_kzalloc(&pdev->dev, sizeof(*xrtcdev), GFP_KERNEL);
> + if (!xrtcdev)
> + return -ENOMEM;
> +
> + platform_set_drvdata(pdev, xrtcdev);
> +
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +
> + xrtcdev->reg_base = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR(xrtcdev->reg_base))
> + return PTR_ERR(xrtcdev->reg_base);
> +
> + xrtcdev->alarm_irq = platform_get_irq_byname(pdev, "alarm");
> + if (xrtcdev->alarm_irq < 0) {
> + dev_err(&pdev->dev, "no irq resource\n");
> + return xrtcdev->alarm_irq;
> + }
> + ret = devm_request_irq(&pdev->dev, xrtcdev->alarm_irq,
> + xlnx_rtc_interrupt, 0,
> + dev_name(&pdev->dev), xrtcdev);
> + if (ret) {
> + dev_err(&pdev->dev, "request irq failed\n");
> + return ret;
> + }
> +
> + xrtcdev->sec_irq = platform_get_irq_byname(pdev, "sec");
> + if (xrtcdev->sec_irq < 0) {
> + dev_err(&pdev->dev, "no irq resource\n");
> + return xrtcdev->sec_irq;
> + }
> + ret = devm_request_irq(&pdev->dev, xrtcdev->sec_irq,
> + xlnx_rtc_interrupt, 0,
> + dev_name(&pdev->dev), xrtcdev);
> + if (ret) {
> + dev_err(&pdev->dev, "request irq failed\n");
> + return ret;
> + }
> +
> + ret = of_property_read_u32(pdev->dev.of_node, "calibration",
> + &calibvalue);
> + if (ret)
> + calibvalue = RTC_CALIB_DEF;
> +
> + xlnx_init_rtc(xrtcdev, calibvalue);
> +
> + device_init_wakeup(&pdev->dev, 1);
> +
> + xrtcdev->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
> + &xlnx_rtc_ops, THIS_MODULE);
> + if (IS_ERR(xrtcdev->rtc)) {
> + return PTR_ERR(xrtcdev->rtc);
> + }
> +
> + return 0;
You should use PTR_ERR_OR_ZERO here.
Thanks,
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
--
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
WARNING: multiple messages have this Message-ID (diff)
From: alexandre.belloni@free-electrons.com (Alexandre Belloni)
To: linux-arm-kernel@lists.infradead.org
Subject: [rtc-linux] [PATCH v2 2/2] drivers: rtc: add xilinx zynqmp rtc driver
Date: Tue, 11 Aug 2015 20:31:31 +0200 [thread overview]
Message-ID: <20150811183131.GW3411@piout.net> (raw)
In-Reply-To: <1438336757-23404-2-git-send-email-suneel.garapati@xilinx.com>
Hi,
Please run checkpatch --strict and fix the issues.
On 31/07/2015 at 15:29:17 +0530, Suneel Garapati wrote :
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/io.h>
> +#include <linux/delay.h>
> +#include <linux/rtc.h>
> +
The includes hav to be sorted alphabetically.
> +static int xlnx_rtc_set_time(struct device *dev, struct rtc_time *tm)
> +{
> + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev);
> + unsigned long new_time;
> +
> + rtc_tm_to_time(tm, &new_time);
You should use rtc_tm_to_time64() and rtc_time64_to_tm() throughout the
file.
> + writel(new_time, xrtcdev->reg_base + RTC_SET_TM_WR);
> +
Is that a 32bits register? If yes, you probably want to return an error
if the year is 2106 or after.
> + return 0;
> +}
> +
[...]
> +static int xlnx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> +{
> + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev);
> + unsigned long alarm_time;
> +
Same comment, you probably want to error out if the time overflows a
32bits register.
> + rtc_tm_to_time(&alrm->time, &alarm_time);
> +
> + writel((u32) alarm_time, (xrtcdev->reg_base + RTC_ALRM));
> +
> + xlnx_rtc_alarm_irq_enable(dev, alrm->enabled);
> +
> + return 0;
> +}
> +
> +static void xlnx_init_rtc(struct xlnx_rtc_dev *xrtcdev, u32 calibval)
> +{
> + /*
> + * Based on crystal freq of 33.330 KHz
> + * set the secounds counter and enable, set fractions counter
typo --------------^
> + * to default value suggested as per design spec
> + * to correct RTC delay in frequency over period of time.
> + */
> + calibval &= RTC_CALIB_MASK;
> + writel(calibval, (xrtcdev->reg_base + RTC_CALIB_WR));
> +}
> +
> +static const struct rtc_class_ops xlnx_rtc_ops = {
> + .set_time = xlnx_rtc_set_time,
> + .read_time = xlnx_rtc_read_time,
> + .read_alarm = xlnx_rtc_read_alarm,
> + .set_alarm = xlnx_rtc_set_alarm,
> + .alarm_irq_enable = xlnx_rtc_alarm_irq_enable,
> +};
> +
> +static irqreturn_t xlnx_rtc_interrupt(int irq, void *id)
> +{
> + struct xlnx_rtc_dev *xrtcdev = (struct xlnx_rtc_dev *) id;
> + unsigned int status;
> +
> + status = readl(xrtcdev->reg_base + RTC_INT_STS);
> + /* Check if interrupt asserted */
> + if (!(status & (RTC_INT_SEC | RTC_INT_ALRM)))
> + return IRQ_NONE;
> +
> + /* Clear interrupt */
> + writel(status, xrtcdev->reg_base + RTC_INT_STS);
> +
> + if (status & RTC_INT_SEC)
> + rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_UF);
> + if (status & RTC_INT_ALRM)
> + rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_AF);
> + if (status & RTC_INT_ALRM)
> + printk("alarm interrupt\n");
I guess this is a debug message that you forgot to remove.
> +static int xlnx_rtc_probe(struct platform_device *pdev)
> +{
> + struct xlnx_rtc_dev *xrtcdev;
> + struct resource *res;
> + int ret;
> + unsigned int calibvalue;
> +
> + xrtcdev = devm_kzalloc(&pdev->dev, sizeof(*xrtcdev), GFP_KERNEL);
> + if (!xrtcdev)
> + return -ENOMEM;
> +
> + platform_set_drvdata(pdev, xrtcdev);
> +
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +
> + xrtcdev->reg_base = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR(xrtcdev->reg_base))
> + return PTR_ERR(xrtcdev->reg_base);
> +
> + xrtcdev->alarm_irq = platform_get_irq_byname(pdev, "alarm");
> + if (xrtcdev->alarm_irq < 0) {
> + dev_err(&pdev->dev, "no irq resource\n");
> + return xrtcdev->alarm_irq;
> + }
> + ret = devm_request_irq(&pdev->dev, xrtcdev->alarm_irq,
> + xlnx_rtc_interrupt, 0,
> + dev_name(&pdev->dev), xrtcdev);
> + if (ret) {
> + dev_err(&pdev->dev, "request irq failed\n");
> + return ret;
> + }
> +
> + xrtcdev->sec_irq = platform_get_irq_byname(pdev, "sec");
> + if (xrtcdev->sec_irq < 0) {
> + dev_err(&pdev->dev, "no irq resource\n");
> + return xrtcdev->sec_irq;
> + }
> + ret = devm_request_irq(&pdev->dev, xrtcdev->sec_irq,
> + xlnx_rtc_interrupt, 0,
> + dev_name(&pdev->dev), xrtcdev);
> + if (ret) {
> + dev_err(&pdev->dev, "request irq failed\n");
> + return ret;
> + }
> +
> + ret = of_property_read_u32(pdev->dev.of_node, "calibration",
> + &calibvalue);
> + if (ret)
> + calibvalue = RTC_CALIB_DEF;
> +
> + xlnx_init_rtc(xrtcdev, calibvalue);
> +
> + device_init_wakeup(&pdev->dev, 1);
> +
> + xrtcdev->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
> + &xlnx_rtc_ops, THIS_MODULE);
> + if (IS_ERR(xrtcdev->rtc)) {
> + return PTR_ERR(xrtcdev->rtc);
> + }
> +
> + return 0;
You should use PTR_ERR_OR_ZERO here.
Thanks,
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
WARNING: multiple messages have this Message-ID (diff)
From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: Suneel Garapati <suneel.garapati@xilinx.com>
Cc: rtc-linux@googlegroups.com, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, michals@xilinx.com,
sorenb@xilinx.com, Alessandro Zummo <a.zummo@towertech.it>
Subject: Re: [rtc-linux] [PATCH v2 2/2] drivers: rtc: add xilinx zynqmp rtc driver
Date: Tue, 11 Aug 2015 20:31:31 +0200 [thread overview]
Message-ID: <20150811183131.GW3411@piout.net> (raw)
In-Reply-To: <1438336757-23404-2-git-send-email-suneel.garapati@xilinx.com>
Hi,
Please run checkpatch --strict and fix the issues.
On 31/07/2015 at 15:29:17 +0530, Suneel Garapati wrote :
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/io.h>
> +#include <linux/delay.h>
> +#include <linux/rtc.h>
> +
The includes hav to be sorted alphabetically.
> +static int xlnx_rtc_set_time(struct device *dev, struct rtc_time *tm)
> +{
> + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev);
> + unsigned long new_time;
> +
> + rtc_tm_to_time(tm, &new_time);
You should use rtc_tm_to_time64() and rtc_time64_to_tm() throughout the
file.
> + writel(new_time, xrtcdev->reg_base + RTC_SET_TM_WR);
> +
Is that a 32bits register? If yes, you probably want to return an error
if the year is 2106 or after.
> + return 0;
> +}
> +
[...]
> +static int xlnx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> +{
> + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev);
> + unsigned long alarm_time;
> +
Same comment, you probably want to error out if the time overflows a
32bits register.
> + rtc_tm_to_time(&alrm->time, &alarm_time);
> +
> + writel((u32) alarm_time, (xrtcdev->reg_base + RTC_ALRM));
> +
> + xlnx_rtc_alarm_irq_enable(dev, alrm->enabled);
> +
> + return 0;
> +}
> +
> +static void xlnx_init_rtc(struct xlnx_rtc_dev *xrtcdev, u32 calibval)
> +{
> + /*
> + * Based on crystal freq of 33.330 KHz
> + * set the secounds counter and enable, set fractions counter
typo --------------^
> + * to default value suggested as per design spec
> + * to correct RTC delay in frequency over period of time.
> + */
> + calibval &= RTC_CALIB_MASK;
> + writel(calibval, (xrtcdev->reg_base + RTC_CALIB_WR));
> +}
> +
> +static const struct rtc_class_ops xlnx_rtc_ops = {
> + .set_time = xlnx_rtc_set_time,
> + .read_time = xlnx_rtc_read_time,
> + .read_alarm = xlnx_rtc_read_alarm,
> + .set_alarm = xlnx_rtc_set_alarm,
> + .alarm_irq_enable = xlnx_rtc_alarm_irq_enable,
> +};
> +
> +static irqreturn_t xlnx_rtc_interrupt(int irq, void *id)
> +{
> + struct xlnx_rtc_dev *xrtcdev = (struct xlnx_rtc_dev *) id;
> + unsigned int status;
> +
> + status = readl(xrtcdev->reg_base + RTC_INT_STS);
> + /* Check if interrupt asserted */
> + if (!(status & (RTC_INT_SEC | RTC_INT_ALRM)))
> + return IRQ_NONE;
> +
> + /* Clear interrupt */
> + writel(status, xrtcdev->reg_base + RTC_INT_STS);
> +
> + if (status & RTC_INT_SEC)
> + rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_UF);
> + if (status & RTC_INT_ALRM)
> + rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_AF);
> + if (status & RTC_INT_ALRM)
> + printk("alarm interrupt\n");
I guess this is a debug message that you forgot to remove.
> +static int xlnx_rtc_probe(struct platform_device *pdev)
> +{
> + struct xlnx_rtc_dev *xrtcdev;
> + struct resource *res;
> + int ret;
> + unsigned int calibvalue;
> +
> + xrtcdev = devm_kzalloc(&pdev->dev, sizeof(*xrtcdev), GFP_KERNEL);
> + if (!xrtcdev)
> + return -ENOMEM;
> +
> + platform_set_drvdata(pdev, xrtcdev);
> +
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +
> + xrtcdev->reg_base = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR(xrtcdev->reg_base))
> + return PTR_ERR(xrtcdev->reg_base);
> +
> + xrtcdev->alarm_irq = platform_get_irq_byname(pdev, "alarm");
> + if (xrtcdev->alarm_irq < 0) {
> + dev_err(&pdev->dev, "no irq resource\n");
> + return xrtcdev->alarm_irq;
> + }
> + ret = devm_request_irq(&pdev->dev, xrtcdev->alarm_irq,
> + xlnx_rtc_interrupt, 0,
> + dev_name(&pdev->dev), xrtcdev);
> + if (ret) {
> + dev_err(&pdev->dev, "request irq failed\n");
> + return ret;
> + }
> +
> + xrtcdev->sec_irq = platform_get_irq_byname(pdev, "sec");
> + if (xrtcdev->sec_irq < 0) {
> + dev_err(&pdev->dev, "no irq resource\n");
> + return xrtcdev->sec_irq;
> + }
> + ret = devm_request_irq(&pdev->dev, xrtcdev->sec_irq,
> + xlnx_rtc_interrupt, 0,
> + dev_name(&pdev->dev), xrtcdev);
> + if (ret) {
> + dev_err(&pdev->dev, "request irq failed\n");
> + return ret;
> + }
> +
> + ret = of_property_read_u32(pdev->dev.of_node, "calibration",
> + &calibvalue);
> + if (ret)
> + calibvalue = RTC_CALIB_DEF;
> +
> + xlnx_init_rtc(xrtcdev, calibvalue);
> +
> + device_init_wakeup(&pdev->dev, 1);
> +
> + xrtcdev->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
> + &xlnx_rtc_ops, THIS_MODULE);
> + if (IS_ERR(xrtcdev->rtc)) {
> + return PTR_ERR(xrtcdev->rtc);
> + }
> +
> + return 0;
You should use PTR_ERR_OR_ZERO here.
Thanks,
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
next prev parent reply other threads:[~2015-08-11 18:31 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-31 9:59 [rtc-linux] [PATCH v2 1/2] devicetree: bindings: rtc: add bindings for xilinx zynqmp rtc Suneel Garapati
2015-07-31 9:59 ` Suneel Garapati
2015-07-31 9:59 ` Suneel Garapati
2015-07-31 9:59 ` [rtc-linux] [PATCH v2 2/2] drivers: rtc: add xilinx zynqmp rtc driver Suneel Garapati
2015-07-31 9:59 ` Suneel Garapati
2015-07-31 9:59 ` Suneel Garapati
2015-08-11 18:31 ` Alexandre Belloni [this message]
2015-08-11 18:31 ` [rtc-linux] " Alexandre Belloni
2015-08-11 18:31 ` Alexandre Belloni
2015-08-07 4:53 ` [rtc-linux] Re: [PATCH v2 1/2] devicetree: bindings: rtc: add bindings for xilinx zynqmp rtc suneelgarapati
2015-08-11 18:32 ` Alexandre Belloni
2015-08-11 18:32 ` Alexandre Belloni
2015-08-11 19:29 ` Suneel Garapati
2015-08-11 19:29 ` Suneel Garapati
2015-08-11 19:29 ` Suneel Garapati
2015-08-11 21:20 ` Alexandre Belloni
2015-08-11 21:20 ` Alexandre Belloni
2015-08-11 21:20 ` Alexandre Belloni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150811183131.GW3411@piout.net \
--to=alexandre.belloni@free-electrons.com \
--cc=a.zummo@towertech.it \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michals@xilinx.com \
--cc=rtc-linux@googlegroups.com \
--cc=sorenb@xilinx.com \
--cc=suneel.garapati@xilinx.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.