mbox series

[v1,00/16] Add support to MT6323 RTC and its power device

Message ID cover.1521794176.git.sean.wang@mediatek.com
Headers show
Series Add support to MT6323 RTC and its power device | expand

Message

Sean Wang March 23, 2018, 9:14 a.m. UTC
From: Sean Wang <sean.wang@mediatek.com>

Hi,

The series keeps to extend the capability of BPI-R2 board with MT7623 and
the result can as well bring benefits into the other MediaTek PMICs such
as MT6397 or SoCs.

The series sent across mfd, rtc, pm, dt-binding sub-system is for hoping
to let people have a simple cross-reference to know the exact dependency
and why those patches are being split in that way between each one.

Patch 1-3: Add dt-binding to the related devices newly or already
	   supported.
Patch 4-5: Extend driver with the functionality of MT6323 RTC device.
Patch 6-9 and 12-13: Add a few of trivial fixups, cleanups and
	  improvements.
Patch 10-11: It's a preparation for Patch 14 adding a new driver.
Patch 14: Add a new driver for a power-off driver.
Patch 15-16: Update MAINTAINERS with these new files being added.

	Sean

Sean Wang (16):
  dt-bindings: power: reset: mediatek: add bindings for power device
  dt-bindings: rtc: mediatek: add bindings for PMIC RTC
  dt-bindings: mfd: mediatek: add a description for MT6323 RTC
  mfd: mt6397: add MT6323 RTC support into MT6397 driver
  rtc: mediatek: add MT6323 support to RTC driver
  rtc: mediatek: remove unnecessary parentheses
  rtc: mediatek: replace a poll with regmap_read_poll_timeout
  rtc: mediatek: remove unnecessary irq_dispose_mapping
  rtc: mediatek: convert to use device managed functions
  rtc: mediatek: add devm_of_platform_populate
  rtc: mediatek: move the declaration into a globally visible header
    file
  rtc: mediatek: cleanup header files to include
  rtc: mediatek: update license converting to using SPDX identifiers
  power: reset: mediatek: add a power-off driver using PMIC RTC device
  MAINTAINERS: update entry for ARM/Mediatek RTC DRIVER
  MAINTAINERS: add an entry for MediaTek board level shutdown driver

 Documentation/devicetree/bindings/mfd/mt6397.txt   |   4 +-
 .../bindings/power/reset/mt6397-rtc-poweroff.txt   |  24 ++++
 .../devicetree/bindings/rtc/rtc-mt6397.txt         |  39 ++++++
 MAINTAINERS                                        |   9 ++
 drivers/mfd/mt6397-core.c                          |  23 +++-
 drivers/power/reset/Kconfig                        |   9 ++
 drivers/power/reset/Makefile                       |   1 +
 drivers/power/reset/mt6397-rtc-poweroff.c          | 100 ++++++++++++++
 drivers/rtc/rtc-mt6397.c                           | 145 +++++----------------
 include/linux/rtc/mt6397.h                         |  73 +++++++++++
 10 files changed, 314 insertions(+), 113 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/power/reset/mt6397-rtc-poweroff.txt
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
 create mode 100644 drivers/power/reset/mt6397-rtc-poweroff.c
 create mode 100644 include/linux/rtc/mt6397.h

Comments

Alexandre Belloni March 23, 2018, 9:57 a.m. UTC | #1
On 23/03/2018 at 17:15:08 +0800, sean.wang@mediatek.com wrote:
> From: Sean Wang <sean.wang@mediatek.com>
> 
> This is in preparation for allowing other drivers can share the
> declaration, so move the declaration into a globally visible header file.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  drivers/rtc/rtc-mt6397.c   | 53 +---------------------------------
>  include/linux/rtc/mt6397.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++

This should go in include/linux/mfd/

>  2 files changed, 73 insertions(+), 52 deletions(-)
>  create mode 100644 include/linux/rtc/mt6397.h
> 
> diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> index d133d1f..015609d 100644
> --- a/drivers/rtc/rtc-mt6397.c
> +++ b/drivers/rtc/rtc-mt6397.c
> @@ -19,63 +19,12 @@
>  #include <linux/of_platform.h>
>  #include <linux/regmap.h>
>  #include <linux/rtc.h>
> -#include <linux/jiffies.h>
>  #include <linux/platform_device.h>
>  #include <linux/of_address.h>
>  #include <linux/of_irq.h>
>  #include <linux/io.h>
>  #include <linux/mfd/mt6397/core.h>
> -
> -#define RTC_BBPU		0x0000
> -#define RTC_BBPU_CBUSY		BIT(6)
> -
> -#define RTC_WRTGR		0x003c
> -
> -#define RTC_IRQ_STA		0x0002
> -#define RTC_IRQ_STA_AL		BIT(0)
> -#define RTC_IRQ_STA_LP		BIT(3)
> -
> -#define RTC_IRQ_EN		0x0004
> -#define RTC_IRQ_EN_AL		BIT(0)
> -#define RTC_IRQ_EN_ONESHOT	BIT(2)
> -#define RTC_IRQ_EN_LP		BIT(3)
> -#define RTC_IRQ_EN_ONESHOT_AL	(RTC_IRQ_EN_ONESHOT | RTC_IRQ_EN_AL)
> -
> -#define RTC_AL_MASK		0x0008
> -#define RTC_AL_MASK_DOW		BIT(4)
> -
> -#define RTC_TC_SEC		0x000a
> -/* Min, Hour, Dom... register offset to RTC_TC_SEC */
> -#define RTC_OFFSET_SEC		0
> -#define RTC_OFFSET_MIN		1
> -#define RTC_OFFSET_HOUR		2
> -#define RTC_OFFSET_DOM		3
> -#define RTC_OFFSET_DOW		4
> -#define RTC_OFFSET_MTH		5
> -#define RTC_OFFSET_YEAR		6
> -#define RTC_OFFSET_COUNT	7
> -
> -#define RTC_AL_SEC		0x0018
> -
> -#define RTC_PDN2		0x002e
> -#define RTC_PDN2_PWRON_ALARM	BIT(4)
> -
> -#define RTC_MIN_YEAR		1968
> -#define RTC_BASE_YEAR		1900
> -#define RTC_NUM_YEARS		128
> -#define RTC_MIN_YEAR_OFFSET	(RTC_MIN_YEAR - RTC_BASE_YEAR)
> -
> -#define MTK_RTC_POLL_DELAY_US	10
> -#define MTK_RTC_POLL_TIMEOUT	(jiffies_to_usecs(HZ))
> -
> -struct mt6397_rtc {
> -	struct device		*dev;
> -	struct rtc_device	*rtc_dev;
> -	struct mutex		lock;
> -	struct regmap		*regmap;
> -	int			irq;
> -	u32			addr_base;
> -};
> +#include <linux/rtc/mt6397.h>
>  
>  static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc)
>  {
> diff --git a/include/linux/rtc/mt6397.h b/include/linux/rtc/mt6397.h
> new file mode 100644
> index 0000000..4b19f51
> --- /dev/null
> +++ b/include/linux/rtc/mt6397.h
> @@ -0,0 +1,72 @@
> +

Unnecessary empty line

> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2014-2018 MediaTek Inc.
> + *
> + * Author: Tianping.Fang <tianping.fang@mediatek.com>
> + *	   Sean Wang <sean.wang@mediatek.com>
> + */
> +
> +#ifndef _LINUX_RTC_MT6397_H_
> +#define _LINUX_RTC_MT6397_H_
> +
> +#include <linux/jiffies.h>
> +#include <linux/mutex.h>
> +#include <linux/regmap.h>
> +#include <linux/rtc.h>
> +
> +#define RTC_BBPU		0x0000
> +#define RTC_BBPU_CBUSY		BIT(6)
> +
> +#define RTC_WRTGR		0x003c
> +
> +#define RTC_IRQ_STA		0x0002
> +#define RTC_IRQ_STA_AL		BIT(0)
> +#define RTC_IRQ_STA_LP		BIT(3)
> +
> +#define RTC_IRQ_EN		0x0004
> +#define RTC_IRQ_EN_AL		BIT(0)
> +#define RTC_IRQ_EN_ONESHOT	BIT(2)
> +#define RTC_IRQ_EN_LP		BIT(3)
> +#define RTC_IRQ_EN_ONESHOT_AL	(RTC_IRQ_EN_ONESHOT | RTC_IRQ_EN_AL)
> +
> +#define RTC_AL_MASK		0x0008
> +#define RTC_AL_MASK_DOW		BIT(4)
> +
> +#define RTC_TC_SEC		0x000a
> +/* Min, Hour, Dom... register offset to RTC_TC_SEC */
> +#define RTC_OFFSET_SEC		0
> +#define RTC_OFFSET_MIN		1
> +#define RTC_OFFSET_HOUR		2
> +#define RTC_OFFSET_DOM		3
> +#define RTC_OFFSET_DOW		4
> +#define RTC_OFFSET_MTH		5
> +#define RTC_OFFSET_YEAR		6
> +#define RTC_OFFSET_COUNT	7
> +
> +#define RTC_AL_SEC		0x0018
> +
> +#define RTC_PDN2		0x002e
> +#define RTC_PDN2_PWRON_ALARM	BIT(4)
> +
> +#define RTC_MIN_YEAR		1968
> +#define RTC_BASE_YEAR		1900
> +#define RTC_NUM_YEARS		128
> +#define RTC_MIN_YEAR_OFFSET	(RTC_MIN_YEAR - RTC_BASE_YEAR)
> +
> +#define MTK_RTC_POLL_DELAY_US	10
> +#define MTK_RTC_POLL_TIMEOUT	(jiffies_to_usecs(HZ))
> +
> +struct mt6397_rtc {
> +	struct device		*dev;
> +	struct rtc_device	*rtc_dev;
> +
> +	/* protect registers accessing */
> +	struct mutex		lock;
> +	struct regmap		*regmap;
> +	int			irq;
> +	u32			addr_base;
> +};
> +
> +#endif /* _LINUX_RTC_MT6397_H_ */
> +
> -- 
> 2.7.4
>
Alexandre Belloni March 23, 2018, 10:01 a.m. UTC | #2
Hi,

The subject line should be rtc: mt6397: (to differentiate with rtc-mt7622)

On 23/03/2018 at 17:15:02 +0800, sean.wang@mediatek.com wrote:
> From: Sean Wang <sean.wang@mediatek.com>
> 
> Just to add MT6323 support to the existent RTC driver.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  drivers/rtc/rtc-mt6397.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> index 385f830..0df7ccd 100644
> --- a/drivers/rtc/rtc-mt6397.c
> +++ b/drivers/rtc/rtc-mt6397.c
> @@ -398,6 +398,7 @@ static SIMPLE_DEV_PM_OPS(mt6397_pm_ops, mt6397_rtc_suspend,
>  			mt6397_rtc_resume);
>  
>  static const struct of_device_id mt6397_rtc_of_match[] = {
> +	{ .compatible = "mediatek,mt6323-rtc", },
>  	{ .compatible = "mediatek,mt6397-rtc", },
>  	{ }
>  };
> -- 
> 2.7.4
>
Alexandre Belloni March 23, 2018, 10:21 a.m. UTC | #3
On 23/03/2018 at 17:15:03 +0800, sean.wang@mediatek.com wrote:
> From: Sean Wang <sean.wang@mediatek.com>
> 
> Remove unnecessary parentheses due to explicit C operator precedence.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  drivers/rtc/rtc-mt6397.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> index 0df7ccd..4411c08 100644
> --- a/drivers/rtc/rtc-mt6397.c
> +++ b/drivers/rtc/rtc-mt6397.c
> @@ -106,7 +106,7 @@ static irqreturn_t mtk_rtc_irq_handler_thread(int irq, void *data)
>  	int ret;
>  
>  	ret = regmap_read(rtc->regmap, rtc->addr_base + RTC_IRQ_STA, &irqsta);
> -	if ((ret >= 0) && (irqsta & RTC_IRQ_STA_AL)) {
> +	if (ret >= 0 && irqsta & RTC_IRQ_STA_AL) {

I don't think this makes the code particularly clearer.

>  		rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);
>  		irqen = irqsta & ~RTC_IRQ_EN_AL;
>  		mutex_lock(&rtc->lock);
> -- 
> 2.7.4
>
Alexandre Belloni March 23, 2018, 10:38 a.m. UTC | #4
On 23/03/2018 at 17:15:05 +0800, sean.wang@mediatek.com wrote:
> From: Sean Wang <sean.wang@mediatek.com>
> 
> It's unnecessary doing irq_dispose_mapping as a reverse operation for
> platform_get_irq.
> 
> Ususally, irq_dispose_mapping should be called in error path or module
> removal to release the resources for irq_of_parse_and_map requested.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  drivers/rtc/rtc-mt6397.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> index b62eaa8..cefb83b 100644
> --- a/drivers/rtc/rtc-mt6397.c
> +++ b/drivers/rtc/rtc-mt6397.c
> @@ -17,7 +17,6 @@
>  #include <linux/module.h>
>  #include <linux/regmap.h>
>  #include <linux/rtc.h>
> -#include <linux/irqdomain.h>
>  #include <linux/jiffies.h>
>  #include <linux/platform_device.h>
>  #include <linux/of_address.h>
> @@ -336,7 +335,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
>  	if (ret) {
>  		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
>  			rtc->irq, ret);
> -		goto out_dispose_irq;
> +		return ret;
>  	}
>  
>  	device_init_wakeup(&pdev->dev, 1);
> @@ -353,8 +352,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
>  
>  out_free_irq:
>  	free_irq(rtc->irq, rtc->rtc_dev);
> -out_dispose_irq:
> -	irq_dispose_mapping(rtc->irq);
> +

Don't you still have a irq_create_mapping?

>  	return ret;
>  }
>  
> @@ -364,7 +362,6 @@ static int mtk_rtc_remove(struct platform_device *pdev)
>  
>  	rtc_device_unregister(rtc->rtc_dev);
>  	free_irq(rtc->irq, rtc->rtc_dev);
> -	irq_dispose_mapping(rtc->irq);
>  
>  	return 0;
>  }
> -- 
> 2.7.4
>
Alexandre Belloni March 23, 2018, 10:50 a.m. UTC | #5
On 23/03/2018 at 17:15:06 +0800, sean.wang@mediatek.com wrote:
> From: Sean Wang <sean.wang@mediatek.com>
> 
> Use device managed operation to simplify error handling, reduce source
> code size, and reduce the likelyhood of bugs, and remove our removal
> callback which contains anything already done by device managed functions.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  drivers/rtc/rtc-mt6397.c | 31 ++++++++-----------------------
>  1 file changed, 8 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> index cefb83b..bfc5d6f 100644
> --- a/drivers/rtc/rtc-mt6397.c
> +++ b/drivers/rtc/rtc-mt6397.c
> @@ -14,6 +14,7 @@
>  
>  #include <linux/delay.h>
>  #include <linux/init.h>
> +#include <linux/interrupt.h>
>  #include <linux/module.h>
>  #include <linux/regmap.h>
>  #include <linux/rtc.h>
> @@ -328,10 +329,10 @@ static int mtk_rtc_probe(struct platform_device *pdev)
>  
>  	platform_set_drvdata(pdev, rtc);
>  
> -	ret = request_threaded_irq(rtc->irq, NULL,
> -				   mtk_rtc_irq_handler_thread,
> -				   IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
> -				   "mt6397-rtc", rtc);
> +	ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
> +					mtk_rtc_irq_handler_thread,
> +					IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
> +					"mt6397-rtc", rtc);
>  	if (ret) {
>  		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
>  			rtc->irq, ret);
> @@ -340,30 +341,15 @@ static int mtk_rtc_probe(struct platform_device *pdev)
>  
>  	device_init_wakeup(&pdev->dev, 1);
>  
> -	rtc->rtc_dev = rtc_device_register("mt6397-rtc", &pdev->dev,
> -					   &mtk_rtc_ops, THIS_MODULE);
> +	rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "mt6397-rtc",
> +						&mtk_rtc_ops, THIS_MODULE);

You should probably switch to devm_rtc_allocate_device() and
rtc_register_device instead of devm_rtc_device_register.

>  	if (IS_ERR(rtc->rtc_dev)) {
>  		dev_err(&pdev->dev, "register rtc device failed\n");
>  		ret = PTR_ERR(rtc->rtc_dev);
> -		goto out_free_irq;
> +		return ret;

ret doesn't seem necessary anymore here.
Sean Wang March 24, 2018, 7:06 a.m. UTC | #6
On Fri, 2018-03-23 at 11:01 +0100, Alexandre Belloni wrote:
> Hi,
> 
> The subject line should be rtc: mt6397: (to differentiate with rtc-mt7622)
> 

Sure, I will change subject line into rtc: mt6397: along with the other
related patches.

> On 23/03/2018 at 17:15:02 +0800, sean.wang@mediatek.com wrote:
> > From: Sean Wang <sean.wang@mediatek.com>
> > 
> > Just to add MT6323 support to the existent RTC driver.
> > 
> > Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> > ---
> >  drivers/rtc/rtc-mt6397.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> > index 385f830..0df7ccd 100644
> > --- a/drivers/rtc/rtc-mt6397.c
> > +++ b/drivers/rtc/rtc-mt6397.c
> > @@ -398,6 +398,7 @@ static SIMPLE_DEV_PM_OPS(mt6397_pm_ops, mt6397_rtc_suspend,
> >  			mt6397_rtc_resume);
> >  
> >  static const struct of_device_id mt6397_rtc_of_match[] = {
> > +	{ .compatible = "mediatek,mt6323-rtc", },
> >  	{ .compatible = "mediatek,mt6397-rtc", },
> >  	{ }
> >  };
> > -- 
> > 2.7.4
> > 
> 


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sean Wang March 24, 2018, 7:14 a.m. UTC | #7
On Fri, 2018-03-23 at 11:21 +0100, Alexandre Belloni wrote:
> On 23/03/2018 at 17:15:03 +0800, sean.wang@mediatek.com wrote:
> > From: Sean Wang <sean.wang@mediatek.com>
> > 
> > Remove unnecessary parentheses due to explicit C operator precedence.
> > 
> > Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> > ---
> >  drivers/rtc/rtc-mt6397.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> > index 0df7ccd..4411c08 100644
> > --- a/drivers/rtc/rtc-mt6397.c
> > +++ b/drivers/rtc/rtc-mt6397.c
> > @@ -106,7 +106,7 @@ static irqreturn_t mtk_rtc_irq_handler_thread(int irq, void *data)
> >  	int ret;
> >  
> >  	ret = regmap_read(rtc->regmap, rtc->addr_base + RTC_IRQ_STA, &irqsta);
> > -	if ((ret >= 0) && (irqsta & RTC_IRQ_STA_AL)) {
> > +	if (ret >= 0 && irqsta & RTC_IRQ_STA_AL) {
> 
> I don't think this makes the code particularly clearer.
> 

But it is still a one of check items in checkpatch

CHECK:UNNECESSARY_PARENTHESES: Unnecessary parentheses around 'ret >= 0'
#126: FILE: drivers/rtc/rtc-xxx.c:109:
+       if ((ret >= 0) && (irqsta & RTC_IRQ_STA_AL)) {


or we still want to keep it in parentheses around here?

> >  		rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);
> >  		irqen = irqsta & ~RTC_IRQ_EN_AL;
> >  		mutex_lock(&rtc->lock);
> > -- 
> > 2.7.4
> > 
> 


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sean Wang March 24, 2018, 7:31 a.m. UTC | #8
On Fri, 2018-03-23 at 10:57 +0100, Alexandre Belloni wrote:
> On 23/03/2018 at 17:15:08 +0800, sean.wang@mediatek.com wrote:
> > From: Sean Wang <sean.wang@mediatek.com>
> > 
> > This is in preparation for allowing other drivers can share the
> > declaration, so move the declaration into a globally visible header file.
> > 
> > Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> > ---
> >  drivers/rtc/rtc-mt6397.c   | 53 +---------------------------------
> >  include/linux/rtc/mt6397.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++
> 
> This should go in include/linux/mfd/

include/linux/mfd/mt6397 is present, so include/linux/mfd/mt6397/rtc.h
seems a nice place to keep these declarations for the pmic rtc.

> >  2 files changed, 73 insertions(+), 52 deletions(-)
> >  create mode 100644 include/linux/rtc/mt6397.h
> > 
> > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> > index d133d1f..015609d 100644
> > --- a/drivers/rtc/rtc-mt6397.c
> > +++ b/drivers/rtc/rtc-mt6397.c
> > @@ -19,63 +19,12 @@
> >  #include <linux/of_platform.h>
> >  #include <linux/regmap.h>
> >  #include <linux/rtc.h>
> > -#include <linux/jiffies.h>
> >  #include <linux/platform_device.h>
> >  #include <linux/of_address.h>
> >  #include <linux/of_irq.h>
> >  #include <linux/io.h>
> >  #include <linux/mfd/mt6397/core.h>
> > -
> > -#define RTC_BBPU		0x0000
> > -#define RTC_BBPU_CBUSY		BIT(6)
> > -
> > -#define RTC_WRTGR		0x003c
> > -
> > -#define RTC_IRQ_STA		0x0002
> > -#define RTC_IRQ_STA_AL		BIT(0)
> > -#define RTC_IRQ_STA_LP		BIT(3)
> > -
> > -#define RTC_IRQ_EN		0x0004
> > -#define RTC_IRQ_EN_AL		BIT(0)
> > -#define RTC_IRQ_EN_ONESHOT	BIT(2)
> > -#define RTC_IRQ_EN_LP		BIT(3)
> > -#define RTC_IRQ_EN_ONESHOT_AL	(RTC_IRQ_EN_ONESHOT | RTC_IRQ_EN_AL)
> > -
> > -#define RTC_AL_MASK		0x0008
> > -#define RTC_AL_MASK_DOW		BIT(4)
> > -
> > -#define RTC_TC_SEC		0x000a
> > -/* Min, Hour, Dom... register offset to RTC_TC_SEC */
> > -#define RTC_OFFSET_SEC		0
> > -#define RTC_OFFSET_MIN		1
> > -#define RTC_OFFSET_HOUR		2
> > -#define RTC_OFFSET_DOM		3
> > -#define RTC_OFFSET_DOW		4
> > -#define RTC_OFFSET_MTH		5
> > -#define RTC_OFFSET_YEAR		6
> > -#define RTC_OFFSET_COUNT	7
> > -
> > -#define RTC_AL_SEC		0x0018
> > -
> > -#define RTC_PDN2		0x002e
> > -#define RTC_PDN2_PWRON_ALARM	BIT(4)
> > -
> > -#define RTC_MIN_YEAR		1968
> > -#define RTC_BASE_YEAR		1900
> > -#define RTC_NUM_YEARS		128
> > -#define RTC_MIN_YEAR_OFFSET	(RTC_MIN_YEAR - RTC_BASE_YEAR)
> > -
> > -#define MTK_RTC_POLL_DELAY_US	10
> > -#define MTK_RTC_POLL_TIMEOUT	(jiffies_to_usecs(HZ))
> > -
> > -struct mt6397_rtc {
> > -	struct device		*dev;
> > -	struct rtc_device	*rtc_dev;
> > -	struct mutex		lock;
> > -	struct regmap		*regmap;
> > -	int			irq;
> > -	u32			addr_base;
> > -};
> > +#include <linux/rtc/mt6397.h>
> >  
> >  static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc)
> >  {
> > diff --git a/include/linux/rtc/mt6397.h b/include/linux/rtc/mt6397.h
> > new file mode 100644
> > index 0000000..4b19f51
> > --- /dev/null
> > +++ b/include/linux/rtc/mt6397.h
> > @@ -0,0 +1,72 @@
> > +
> 
> Unnecessary empty line
> 

will remove the unnecessary empty line

> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright (C) 2014-2018 MediaTek Inc.
> > + *
> > + * Author: Tianping.Fang <tianping.fang@mediatek.com>
> > + *	   Sean Wang <sean.wang@mediatek.com>
> > + */
> > +
> > +#ifndef _LINUX_RTC_MT6397_H_
> > +#define _LINUX_RTC_MT6397_H_
> > +
> > +#include <linux/jiffies.h>
> > +#include <linux/mutex.h>
> > +#include <linux/regmap.h>
> > +#include <linux/rtc.h>
> > +
> > +#define RTC_BBPU		0x0000
> > +#define RTC_BBPU_CBUSY		BIT(6)
> > +
> > +#define RTC_WRTGR		0x003c
> > +
> > +#define RTC_IRQ_STA		0x0002
> > +#define RTC_IRQ_STA_AL		BIT(0)
> > +#define RTC_IRQ_STA_LP		BIT(3)
> > +
> > +#define RTC_IRQ_EN		0x0004
> > +#define RTC_IRQ_EN_AL		BIT(0)
> > +#define RTC_IRQ_EN_ONESHOT	BIT(2)
> > +#define RTC_IRQ_EN_LP		BIT(3)
> > +#define RTC_IRQ_EN_ONESHOT_AL	(RTC_IRQ_EN_ONESHOT | RTC_IRQ_EN_AL)
> > +
> > +#define RTC_AL_MASK		0x0008
> > +#define RTC_AL_MASK_DOW		BIT(4)
> > +
> > +#define RTC_TC_SEC		0x000a
> > +/* Min, Hour, Dom... register offset to RTC_TC_SEC */
> > +#define RTC_OFFSET_SEC		0
> > +#define RTC_OFFSET_MIN		1
> > +#define RTC_OFFSET_HOUR		2
> > +#define RTC_OFFSET_DOM		3
> > +#define RTC_OFFSET_DOW		4
> > +#define RTC_OFFSET_MTH		5
> > +#define RTC_OFFSET_YEAR		6
> > +#define RTC_OFFSET_COUNT	7
> > +
> > +#define RTC_AL_SEC		0x0018
> > +
> > +#define RTC_PDN2		0x002e
> > +#define RTC_PDN2_PWRON_ALARM	BIT(4)
> > +
> > +#define RTC_MIN_YEAR		1968
> > +#define RTC_BASE_YEAR		1900
> > +#define RTC_NUM_YEARS		128
> > +#define RTC_MIN_YEAR_OFFSET	(RTC_MIN_YEAR - RTC_BASE_YEAR)
> > +
> > +#define MTK_RTC_POLL_DELAY_US	10
> > +#define MTK_RTC_POLL_TIMEOUT	(jiffies_to_usecs(HZ))
> > +
> > +struct mt6397_rtc {
> > +	struct device		*dev;
> > +	struct rtc_device	*rtc_dev;
> > +
> > +	/* protect registers accessing */
> > +	struct mutex		lock;
> > +	struct regmap		*regmap;
> > +	int			irq;
> > +	u32			addr_base;
> > +};
> > +
> > +#endif /* _LINUX_RTC_MT6397_H_ */
> > +
> > -- 
> > 2.7.4
> > 
> 


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alexandre Belloni March 24, 2018, 6:53 p.m. UTC | #9
On 24/03/2018 at 15:14:12 +0800, Sean Wang wrote:
> On Fri, 2018-03-23 at 11:21 +0100, Alexandre Belloni wrote:
> > On 23/03/2018 at 17:15:03 +0800, sean.wang@mediatek.com wrote:
> > > From: Sean Wang <sean.wang@mediatek.com>
> > > 
> > > Remove unnecessary parentheses due to explicit C operator precedence.
> > > 
> > > Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> > > ---
> > >  drivers/rtc/rtc-mt6397.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> > > index 0df7ccd..4411c08 100644
> > > --- a/drivers/rtc/rtc-mt6397.c
> > > +++ b/drivers/rtc/rtc-mt6397.c
> > > @@ -106,7 +106,7 @@ static irqreturn_t mtk_rtc_irq_handler_thread(int irq, void *data)
> > >  	int ret;
> > >  
> > >  	ret = regmap_read(rtc->regmap, rtc->addr_base + RTC_IRQ_STA, &irqsta);
> > > -	if ((ret >= 0) && (irqsta & RTC_IRQ_STA_AL)) {
> > > +	if (ret >= 0 && irqsta & RTC_IRQ_STA_AL) {
> > 
> > I don't think this makes the code particularly clearer.
> > 
> 
> But it is still a one of check items in checkpatch
> 
> CHECK:UNNECESSARY_PARENTHESES: Unnecessary parentheses around 'ret >= 0'
> #126: FILE: drivers/rtc/rtc-xxx.c:109:
> +       if ((ret >= 0) && (irqsta & RTC_IRQ_STA_AL)) {
> 
> 
> or we still want to keep it in parentheses around here?
> 

Yeah, this is a matter of taste, I would keep the parentheses.
Alexandre Belloni March 24, 2018, 6:54 p.m. UTC | #10
On 24/03/2018 at 15:31:49 +0800, Sean Wang wrote:
> On Fri, 2018-03-23 at 10:57 +0100, Alexandre Belloni wrote:
> > On 23/03/2018 at 17:15:08 +0800, sean.wang@mediatek.com wrote:
> > > From: Sean Wang <sean.wang@mediatek.com>
> > > 
> > > This is in preparation for allowing other drivers can share the
> > > declaration, so move the declaration into a globally visible header file.
> > > 
> > > Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> > > ---
> > >  drivers/rtc/rtc-mt6397.c   | 53 +---------------------------------
> > >  include/linux/rtc/mt6397.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++
> > 
> > This should go in include/linux/mfd/
> 
> include/linux/mfd/mt6397 is present, so include/linux/mfd/mt6397/rtc.h
> seems a nice place to keep these declarations for the pmic rtc.
> 

Yes, this seems good to me.

> > >  2 files changed, 73 insertions(+), 52 deletions(-)
> > >  create mode 100644 include/linux/rtc/mt6397.h
> > > 
> > > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> > > index d133d1f..015609d 100644
> > > --- a/drivers/rtc/rtc-mt6397.c
> > > +++ b/drivers/rtc/rtc-mt6397.c
> > > @@ -19,63 +19,12 @@
> > >  #include <linux/of_platform.h>
> > >  #include <linux/regmap.h>
> > >  #include <linux/rtc.h>
> > > -#include <linux/jiffies.h>
> > >  #include <linux/platform_device.h>
> > >  #include <linux/of_address.h>
> > >  #include <linux/of_irq.h>
> > >  #include <linux/io.h>
> > >  #include <linux/mfd/mt6397/core.h>
> > > -
> > > -#define RTC_BBPU		0x0000
> > > -#define RTC_BBPU_CBUSY		BIT(6)
> > > -
> > > -#define RTC_WRTGR		0x003c
> > > -
> > > -#define RTC_IRQ_STA		0x0002
> > > -#define RTC_IRQ_STA_AL		BIT(0)
> > > -#define RTC_IRQ_STA_LP		BIT(3)
> > > -
> > > -#define RTC_IRQ_EN		0x0004
> > > -#define RTC_IRQ_EN_AL		BIT(0)
> > > -#define RTC_IRQ_EN_ONESHOT	BIT(2)
> > > -#define RTC_IRQ_EN_LP		BIT(3)
> > > -#define RTC_IRQ_EN_ONESHOT_AL	(RTC_IRQ_EN_ONESHOT | RTC_IRQ_EN_AL)
> > > -
> > > -#define RTC_AL_MASK		0x0008
> > > -#define RTC_AL_MASK_DOW		BIT(4)
> > > -
> > > -#define RTC_TC_SEC		0x000a
> > > -/* Min, Hour, Dom... register offset to RTC_TC_SEC */
> > > -#define RTC_OFFSET_SEC		0
> > > -#define RTC_OFFSET_MIN		1
> > > -#define RTC_OFFSET_HOUR		2
> > > -#define RTC_OFFSET_DOM		3
> > > -#define RTC_OFFSET_DOW		4
> > > -#define RTC_OFFSET_MTH		5
> > > -#define RTC_OFFSET_YEAR		6
> > > -#define RTC_OFFSET_COUNT	7
> > > -
> > > -#define RTC_AL_SEC		0x0018
> > > -
> > > -#define RTC_PDN2		0x002e
> > > -#define RTC_PDN2_PWRON_ALARM	BIT(4)
> > > -
> > > -#define RTC_MIN_YEAR		1968
> > > -#define RTC_BASE_YEAR		1900
> > > -#define RTC_NUM_YEARS		128
> > > -#define RTC_MIN_YEAR_OFFSET	(RTC_MIN_YEAR - RTC_BASE_YEAR)
> > > -
> > > -#define MTK_RTC_POLL_DELAY_US	10
> > > -#define MTK_RTC_POLL_TIMEOUT	(jiffies_to_usecs(HZ))
> > > -
> > > -struct mt6397_rtc {
> > > -	struct device		*dev;
> > > -	struct rtc_device	*rtc_dev;
> > > -	struct mutex		lock;
> > > -	struct regmap		*regmap;
> > > -	int			irq;
> > > -	u32			addr_base;
> > > -};
> > > +#include <linux/rtc/mt6397.h>
> > >  
> > >  static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc)
> > >  {
> > > diff --git a/include/linux/rtc/mt6397.h b/include/linux/rtc/mt6397.h
> > > new file mode 100644
> > > index 0000000..4b19f51
> > > --- /dev/null
> > > +++ b/include/linux/rtc/mt6397.h
> > > @@ -0,0 +1,72 @@
> > > +
> > 
> > Unnecessary empty line
> > 
> 
> will remove the unnecessary empty line
> 
> > > +// SPDX-License-Identifier: GPL-2.0
> > > +/*
> > > + * Copyright (C) 2014-2018 MediaTek Inc.
> > > + *
> > > + * Author: Tianping.Fang <tianping.fang@mediatek.com>
> > > + *	   Sean Wang <sean.wang@mediatek.com>
> > > + */
> > > +
> > > +#ifndef _LINUX_RTC_MT6397_H_
> > > +#define _LINUX_RTC_MT6397_H_
> > > +
> > > +#include <linux/jiffies.h>
> > > +#include <linux/mutex.h>
> > > +#include <linux/regmap.h>
> > > +#include <linux/rtc.h>
> > > +
> > > +#define RTC_BBPU		0x0000
> > > +#define RTC_BBPU_CBUSY		BIT(6)
> > > +
> > > +#define RTC_WRTGR		0x003c
> > > +
> > > +#define RTC_IRQ_STA		0x0002
> > > +#define RTC_IRQ_STA_AL		BIT(0)
> > > +#define RTC_IRQ_STA_LP		BIT(3)
> > > +
> > > +#define RTC_IRQ_EN		0x0004
> > > +#define RTC_IRQ_EN_AL		BIT(0)
> > > +#define RTC_IRQ_EN_ONESHOT	BIT(2)
> > > +#define RTC_IRQ_EN_LP		BIT(3)
> > > +#define RTC_IRQ_EN_ONESHOT_AL	(RTC_IRQ_EN_ONESHOT | RTC_IRQ_EN_AL)
> > > +
> > > +#define RTC_AL_MASK		0x0008
> > > +#define RTC_AL_MASK_DOW		BIT(4)
> > > +
> > > +#define RTC_TC_SEC		0x000a
> > > +/* Min, Hour, Dom... register offset to RTC_TC_SEC */
> > > +#define RTC_OFFSET_SEC		0
> > > +#define RTC_OFFSET_MIN		1
> > > +#define RTC_OFFSET_HOUR		2
> > > +#define RTC_OFFSET_DOM		3
> > > +#define RTC_OFFSET_DOW		4
> > > +#define RTC_OFFSET_MTH		5
> > > +#define RTC_OFFSET_YEAR		6
> > > +#define RTC_OFFSET_COUNT	7
> > > +
> > > +#define RTC_AL_SEC		0x0018
> > > +
> > > +#define RTC_PDN2		0x002e
> > > +#define RTC_PDN2_PWRON_ALARM	BIT(4)
> > > +
> > > +#define RTC_MIN_YEAR		1968
> > > +#define RTC_BASE_YEAR		1900
> > > +#define RTC_NUM_YEARS		128
> > > +#define RTC_MIN_YEAR_OFFSET	(RTC_MIN_YEAR - RTC_BASE_YEAR)
> > > +
> > > +#define MTK_RTC_POLL_DELAY_US	10
> > > +#define MTK_RTC_POLL_TIMEOUT	(jiffies_to_usecs(HZ))
> > > +
> > > +struct mt6397_rtc {
> > > +	struct device		*dev;
> > > +	struct rtc_device	*rtc_dev;
> > > +
> > > +	/* protect registers accessing */
> > > +	struct mutex		lock;
> > > +	struct regmap		*regmap;
> > > +	int			irq;
> > > +	u32			addr_base;
> > > +};
> > > +
> > > +#endif /* _LINUX_RTC_MT6397_H_ */
> > > +
> > > -- 
> > > 2.7.4
> > > 
> > 
> 
>
Sean Wang March 24, 2018, 7:21 p.m. UTC | #11
On Sat, 2018-03-24 at 19:53 +0100, Alexandre Belloni wrote:
> On 24/03/2018 at 15:14:12 +0800, Sean Wang wrote:
> > On Fri, 2018-03-23 at 11:21 +0100, Alexandre Belloni wrote:
> > > On 23/03/2018 at 17:15:03 +0800, sean.wang@mediatek.com wrote:
> > > > From: Sean Wang <sean.wang@mediatek.com>
> > > > 
> > > > Remove unnecessary parentheses due to explicit C operator precedence.
> > > > 
> > > > Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> > > > ---
> > > >  drivers/rtc/rtc-mt6397.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> > > > index 0df7ccd..4411c08 100644
> > > > --- a/drivers/rtc/rtc-mt6397.c
> > > > +++ b/drivers/rtc/rtc-mt6397.c
> > > > @@ -106,7 +106,7 @@ static irqreturn_t mtk_rtc_irq_handler_thread(int irq, void *data)
> > > >  	int ret;
> > > >  
> > > >  	ret = regmap_read(rtc->regmap, rtc->addr_base + RTC_IRQ_STA, &irqsta);
> > > > -	if ((ret >= 0) && (irqsta & RTC_IRQ_STA_AL)) {
> > > > +	if (ret >= 0 && irqsta & RTC_IRQ_STA_AL) {
> > > 
> > > I don't think this makes the code particularly clearer.
> > > 
> > 
> > But it is still a one of check items in checkpatch
> > 
> > CHECK:UNNECESSARY_PARENTHESES: Unnecessary parentheses around 'ret >= 0'
> > #126: FILE: drivers/rtc/rtc-xxx.c:109:
> > +       if ((ret >= 0) && (irqsta & RTC_IRQ_STA_AL)) {
> > 
> > 
> > or we still want to keep it in parentheses around here?
> > 
> 
> Yeah, this is a matter of taste, I would keep the parentheses.

okay, lets keep the parentheses

> 
> 


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Fabio Estevam March 24, 2018, 8 p.m. UTC | #12
On Fri, Mar 23, 2018 at 6:15 AM,  <sean.wang@mediatek.com> wrote:

> --- /dev/null
> +++ b/include/linux/rtc/mt6397.h
> @@ -0,0 +1,72 @@
> +
> +// SPDX-License-Identifier: GPL-2.0

According to Documentation/process/license-rules.rst the SPDX notation
for C header file should be:

/* SPDX-License-Identifier: GPL-2.0 */
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sean Wang March 25, 2018, 3:13 a.m. UTC | #13
On Sat, 2018-03-24 at 17:00 -0300, Fabio Estevam wrote:
> On Fri, Mar 23, 2018 at 6:15 AM,  <sean.wang@mediatek.com> wrote:
> 
> > --- /dev/null
> > +++ b/include/linux/rtc/mt6397.h
> > @@ -0,0 +1,72 @@
> > +
> > +// SPDX-License-Identifier: GPL-2.0
> 
> According to Documentation/process/license-rules.rst the SPDX notation
> for C header file should be:
> 
> /* SPDX-License-Identifier: GPL-2.0 */


Thank you, I'll have an improvement according to the license rule.



--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sean Wang March 26, 2018, 2:22 a.m. UTC | #14
On Fri, 2018-03-23 at 11:38 +0100, Alexandre Belloni wrote:
> On 23/03/2018 at 17:15:05 +0800, sean.wang@mediatek.com wrote:
> > From: Sean Wang <sean.wang@mediatek.com>
> > 
> > It's unnecessary doing irq_dispose_mapping as a reverse operation for
> > platform_get_irq.
> > 
> > Ususally, irq_dispose_mapping should be called in error path or module
> > removal to release the resources for irq_of_parse_and_map requested.
> > 
> > Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> > ---
> >  drivers/rtc/rtc-mt6397.c | 7 ++-----
> >  1 file changed, 2 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> > index b62eaa8..cefb83b 100644
> > --- a/drivers/rtc/rtc-mt6397.c
> > +++ b/drivers/rtc/rtc-mt6397.c
> > @@ -17,7 +17,6 @@
> >  #include <linux/module.h>
> >  #include <linux/regmap.h>
> >  #include <linux/rtc.h>
> > -#include <linux/irqdomain.h>
> >  #include <linux/jiffies.h>
> >  #include <linux/platform_device.h>
> >  #include <linux/of_address.h>
> > @@ -336,7 +335,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
> >  	if (ret) {
> >  		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
> >  			rtc->irq, ret);
> > -		goto out_dispose_irq;
> > +		return ret;
> >  	}
> >  
> >  	device_init_wakeup(&pdev->dev, 1);
> > @@ -353,8 +352,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
> >  
> >  out_free_irq:
> >  	free_irq(rtc->irq, rtc->rtc_dev);
> > -out_dispose_irq:
> > -	irq_dispose_mapping(rtc->irq);
> > +
> 
> Don't you still have a irq_create_mapping?
> 

Sorry for that I didn't mention in the beginning that the series must
depend on another patch [1]. With the patch, the job irq_create_mapping
had been moved from rtc to mfd, so here it should be better to cleanup
up irq_dispose_mapping in all paths.

[1] https://patchwork.kernel.org/patch/9954643/

> >  	return ret;
> >  }
> >  
> > @@ -364,7 +362,6 @@ static int mtk_rtc_remove(struct platform_device *pdev)
> >  
> >  	rtc_device_unregister(rtc->rtc_dev);
> >  	free_irq(rtc->irq, rtc->rtc_dev);
> > -	irq_dispose_mapping(rtc->irq);
> >  
> >  	return 0;
> >  }
> > -- 
> > 2.7.4
> > 
> 


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sean Wang March 26, 2018, 4:07 a.m. UTC | #15
On Fri, 2018-03-23 at 11:50 +0100, Alexandre Belloni wrote:
> On 23/03/2018 at 17:15:06 +0800, sean.wang@mediatek.com wrote:
> > From: Sean Wang <sean.wang@mediatek.com>
> > 
> > Use device managed operation to simplify error handling, reduce source
> > code size, and reduce the likelyhood of bugs, and remove our removal
> > callback which contains anything already done by device managed functions.
> > 
> > Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> > ---
> >  drivers/rtc/rtc-mt6397.c | 31 ++++++++-----------------------
> >  1 file changed, 8 insertions(+), 23 deletions(-)
> > 
> > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> > index cefb83b..bfc5d6f 100644
> > --- a/drivers/rtc/rtc-mt6397.c
> > +++ b/drivers/rtc/rtc-mt6397.c
> > @@ -14,6 +14,7 @@
> >  
> >  #include <linux/delay.h>
> >  #include <linux/init.h>
> > +#include <linux/interrupt.h>
> >  #include <linux/module.h>
> >  #include <linux/regmap.h>
> >  #include <linux/rtc.h>
> > @@ -328,10 +329,10 @@ static int mtk_rtc_probe(struct platform_device *pdev)
> >  
> >  	platform_set_drvdata(pdev, rtc);
> >  
> > -	ret = request_threaded_irq(rtc->irq, NULL,
> > -				   mtk_rtc_irq_handler_thread,
> > -				   IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
> > -				   "mt6397-rtc", rtc);
> > +	ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
> > +					mtk_rtc_irq_handler_thread,
> > +					IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
> > +					"mt6397-rtc", rtc);
> >  	if (ret) {
> >  		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
> >  			rtc->irq, ret);
> > @@ -340,30 +341,15 @@ static int mtk_rtc_probe(struct platform_device *pdev)
> >  
> >  	device_init_wakeup(&pdev->dev, 1);
> >  
> > -	rtc->rtc_dev = rtc_device_register("mt6397-rtc", &pdev->dev,
> > -					   &mtk_rtc_ops, THIS_MODULE);
> > +	rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "mt6397-rtc",
> > +						&mtk_rtc_ops, THIS_MODULE);
> 
> You should probably switch to devm_rtc_allocate_device() and
> rtc_register_device instead of devm_rtc_device_register.
> 

Just would like to know something details

It seems you just encourage me to switch into the new registration
method and currently devm_rtc_device_register I used for the driver
shouldn't cause any harm. right?

> >  	if (IS_ERR(rtc->rtc_dev)) {
> >  		dev_err(&pdev->dev, "register rtc device failed\n");
> >  		ret = PTR_ERR(rtc->rtc_dev);
> > -		goto out_free_irq;
> > +		return ret;
> 
> ret doesn't seem necessary anymore here.


okay, it'll be removed

> 
> 


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alexandre Belloni March 27, 2018, 3:07 p.m. UTC | #16
On 26/03/2018 at 12:07:45 +0800, Sean Wang wrote:
> > > -	rtc->rtc_dev = rtc_device_register("mt6397-rtc", &pdev->dev,
> > > -					   &mtk_rtc_ops, THIS_MODULE);
> > > +	rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "mt6397-rtc",
> > > +						&mtk_rtc_ops, THIS_MODULE);
> > 
> > You should probably switch to devm_rtc_allocate_device() and
> > rtc_register_device instead of devm_rtc_device_register.
> > 
> 
> Just would like to know something details
> 
> It seems you just encourage me to switch into the new registration
> method and currently devm_rtc_device_register I used for the driver
> shouldn't cause any harm. right?
> 

It will work but it will have to be converted to rtc_register_device
later anyway.
Lee Jones March 28, 2018, 11:15 a.m. UTC | #17
On Fri, 23 Mar 2018, sean.wang@mediatek.com wrote:

> From: Sean Wang <sean.wang@mediatek.com>
> 
> Add compatible string as "mt6323-rtc" that will make the OF core spawn
> child devices for the RTC subnode of that MT6323 MFD node.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  drivers/mfd/mt6397-core.c | 23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
> index 77b64bd..f71874a 100644
> --- a/drivers/mfd/mt6397-core.c
> +++ b/drivers/mfd/mt6397-core.c
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright (c) 2014 MediaTek Inc.
> + * Copyright (c) 2014-2018 MediaTek Inc.
>   * Author: Flora Fu, MediaTek
>   *
>   * This program is free software; you can redistribute it and/or modify
> @@ -23,6 +23,9 @@
>  #include <linux/mfd/mt6397/registers.h>
>  #include <linux/mfd/mt6323/registers.h>
>  
> +#define MT6323_RTC_BASE		0x8000
> +#define MT6323_RTC_SIZE		0x3e
> +
>  #define MT6397_RTC_BASE		0xe000
>  #define MT6397_RTC_SIZE		0x3e
>  
> @@ -30,6 +33,19 @@
>  #define MT6391_CID_CODE		0x91
>  #define MT6397_CID_CODE		0x97
>  
> +static const struct resource mt6323_rtc_resources[] = {
> +	{
> +		.start = MT6323_RTC_BASE,
> +		.end   = MT6323_RTC_BASE + MT6323_RTC_SIZE,
> +		.flags = IORESOURCE_MEM,
> +	},
> +	{
> +		.start = MT6323_IRQ_STATUS_RTC,
> +		.end   = MT6323_IRQ_STATUS_RTC,
> +		.flags = IORESOURCE_IRQ,
> +	},
> +};

Please use the DEFINE_RES_* helpers instead.

Defined in: include/linux/ioport.h

>  static const struct resource mt6397_rtc_resources[] = {
>  	{
>  		.start = MT6397_RTC_BASE,
> @@ -55,6 +71,11 @@ static const struct resource mt6397_keys_resources[] = {
>  
>  static const struct mfd_cell mt6323_devs[] = {
>  	{
> +		.name = "mt6323-rtc",
> +		.num_resources = ARRAY_SIZE(mt6323_rtc_resources),
> +		.resources = mt6323_rtc_resources,
> +		.of_compatible = "mediatek,mt6323-rtc",
> +	}, {
>  		.name = "mt6323-regulator",
>  		.of_compatible = "mediatek,mt6323-regulator"
>  	}, {