linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
@ 2015-08-14  8:38 maoguang.meng
  2015-08-14  9:57 ` Daniel Kurtz
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: maoguang.meng @ 2015-08-14  8:38 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Matthias Brugger, Hongzhou Yang, Yingjoe Chen, linux-gpio,
	linux-arm-kernel, linux-mediatek, linux-kernel, Maoguang Meng

From: Maoguang Meng <maoguang.meng@mediatek.com>

This patch implement irq_set_wake to get who is wakeup source and
setup on suspend resume.

Signed-off-by: Maoguang Meng <maoguang.meng@mediatek.com>

---
changes since v3:
-add a comment in mtk_eint_chip_read_mask.
-delete ALIGN when allocate eint_offsets.ports.
-fix unrelated change.

changes since v2:
-modify irq_wake to handle irq wakeup source.
-allocate two buffers separately.
-fix some codestyle.

Changes since v1:
-implement irq_wake handler.
---

 drivers/pinctrl/mediatek/pinctrl-mt8173.c     |  1 +
 drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 91 ++++++++++++++++++++++++++-
 drivers/pinctrl/mediatek/pinctrl-mtk-common.h |  4 ++
 3 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/mediatek/pinctrl-mt8173.c b/drivers/pinctrl/mediatek/pinctrl-mt8173.c
index d0c811d..ad27184 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mt8173.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mt8173.c
@@ -385,6 +385,7 @@ static struct platform_driver mtk_pinctrl_driver = {
 	.driver = {
 		.name = "mediatek-mt8173-pinctrl",
 		.of_match_table = mt8173_pctrl_match,
+		.pm = &mtk_eint_pm_ops,
 	},
 };
 
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
index ad1ea16..fe34ce9 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
@@ -33,6 +33,7 @@
 #include <linux/mfd/syscon.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
+#include <linux/pm.h>
 #include <dt-bindings/pinctrl/mt65xx.h>
 
 #include "../core.h"
@@ -1062,6 +1063,77 @@ static int mtk_eint_set_type(struct irq_data *d,
 	return 0;
 }
 
+static int mtk_eint_irq_set_wake(struct irq_data *d, unsigned int on)
+{
+	struct mtk_pinctrl *pctl = irq_data_get_irq_chip_data(d);
+	int shift = d->hwirq & 0x1f;
+	int reg = d->hwirq >> 5;
+
+	if (on)
+		pctl->wake_mask[reg] |= BIT(shift);
+	else
+		pctl->wake_mask[reg] &= ~BIT(shift);
+
+	return 0;
+}
+
+static void mtk_eint_chip_write_mask(const struct mtk_eint_offsets *chip,
+		void __iomem *eint_reg_base, u32 *buf)
+{
+	int port;
+	void __iomem *reg;
+
+	for (port = 0; port < chip->ports; port++) {
+		reg = eint_reg_base + (port << 2);
+		writel_relaxed(~buf[port], reg + chip->mask_set);
+		writel_relaxed(buf[port], reg + chip->mask_clr);
+	}
+}
+
+static void mtk_eint_chip_read_mask(const struct mtk_eint_offsets *chip,
+		void __iomem *eint_reg_base, u32 *buf)
+{
+	int port;
+	void __iomem *reg;
+
+	for (port = 0; port < chip->ports; port++) {
+		reg = eint_reg_base + chip->mask + (port << 2);
+		buf[port] = ~readl_relaxed(reg);
+		/* Mask is 0 when irq is enabled, and 1 when disabled. */
+	}
+}
+
+static int mtk_eint_suspend(struct device *device)
+{
+	void __iomem *reg;
+	struct mtk_pinctrl *pctl = dev_get_drvdata(device);
+	const struct mtk_eint_offsets *eint_offsets =
+			&pctl->devdata->eint_offsets;
+
+	reg = pctl->eint_reg_base;
+	mtk_eint_chip_read_mask(eint_offsets, reg, pctl->cur_mask);
+	mtk_eint_chip_write_mask(eint_offsets, reg, pctl->wake_mask);
+
+	return 0;
+}
+
+static int mtk_eint_resume(struct device *device)
+{
+	struct mtk_pinctrl *pctl = dev_get_drvdata(device);
+	const struct mtk_eint_offsets *eint_offsets =
+			&pctl->devdata->eint_offsets;
+
+	mtk_eint_chip_write_mask(eint_offsets,
+			pctl->eint_reg_base, pctl->cur_mask);
+
+	return 0;
+}
+
+const struct dev_pm_ops mtk_eint_pm_ops = {
+	.suspend = mtk_eint_suspend,
+	.resume = mtk_eint_resume,
+};
+
 static void mtk_eint_ack(struct irq_data *d)
 {
 	struct mtk_pinctrl *pctl = irq_data_get_irq_chip_data(d);
@@ -1076,10 +1148,12 @@ static void mtk_eint_ack(struct irq_data *d)
 
 static struct irq_chip mtk_pinctrl_irq_chip = {
 	.name = "mt-eint",
+	.irq_disable = mtk_eint_mask,
 	.irq_mask = mtk_eint_mask,
 	.irq_unmask = mtk_eint_unmask,
 	.irq_ack = mtk_eint_ack,
 	.irq_set_type = mtk_eint_set_type,
+	.irq_set_wake = mtk_eint_irq_set_wake,
 	.irq_request_resources = mtk_pinctrl_irq_request_resources,
 	.irq_release_resources = mtk_pinctrl_irq_release_resources,
 };
@@ -1217,7 +1291,7 @@ int mtk_pctrl_init(struct platform_device *pdev,
 	struct device_node *np = pdev->dev.of_node, *node;
 	struct property *prop;
 	struct resource *res;
-	int i, ret, irq;
+	int i, ret, irq, ports_buf;
 
 	pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL);
 	if (!pctl)
@@ -1319,6 +1393,21 @@ int mtk_pctrl_init(struct platform_device *pdev,
 		goto chip_error;
 	}
 
+	ports_buf = pctl->devdata->eint_offsets.ports;
+	pctl->wake_mask = devm_kcalloc(&pdev->dev, ports_buf,
+					sizeof(*pctl->wake_mask), GFP_KERNEL);
+	if (!pctl->wake_mask) {
+		ret = -ENOMEM;
+		goto chip_error;
+	}
+
+	pctl->cur_mask = devm_kcalloc(&pdev->dev, ports_buf,
+					sizeof(*pctl->cur_mask), GFP_KERNEL);
+	if (!pctl->cur_mask) {
+		ret = -ENOMEM;
+		goto chip_error;
+	}
+
 	pctl->eint_dual_edges = devm_kcalloc(&pdev->dev, pctl->devdata->ap_num,
 					     sizeof(int), GFP_KERNEL);
 	if (!pctl->eint_dual_edges) {
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.h b/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
index 30213e5..f1be8e8 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
@@ -266,6 +266,8 @@ struct mtk_pinctrl {
 	void __iomem		*eint_reg_base;
 	struct irq_domain	*domain;
 	int			*eint_dual_edges;
+	u32 *wake_mask;
+	u32 *cur_mask;
 };
 
 int mtk_pctrl_init(struct platform_device *pdev,
@@ -281,4 +283,6 @@ int mtk_pconf_spec_set_ies_smt_range(struct regmap *regmap,
 		const struct mtk_pin_ies_smt_set *ies_smt_infos, unsigned int info_num,
 		unsigned int pin, unsigned char align, int value);
 
+extern const struct dev_pm_ops mtk_eint_pm_ops;
+
 #endif /* __PINCTRL_MTK_COMMON_H */
-- 
1.8.1.1.dirty


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-08-14  8:38 [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume maoguang.meng
@ 2015-08-14  9:57 ` Daniel Kurtz
  2015-08-17  7:52 ` Yingjoe Chen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 19+ messages in thread
From: Daniel Kurtz @ 2015-08-14  9:57 UTC (permalink / raw)
  To: maoguang meng
  Cc: Linus Walleij, Matthias Brugger, Hongzhou Yang, Yingjoe Chen,
	linux-gpio, linux-arm-kernel, linux-mediatek, linux-kernel

On Fri, Aug 14, 2015 at 4:38 PM, <maoguang.meng@mediatek.com> wrote:
>
> From: Maoguang Meng <maoguang.meng@mediatek.com>
>
> This patch implement irq_set_wake to get who is wakeup source and
> setup on suspend resume.
>
> Signed-off-by: Maoguang Meng <maoguang.meng@mediatek.com>

Reviewed-by: Daniel Kurtz <djkurtz@chromium.org>

Thanks!
-Dan

>
> ---
> changes since v3:
> -add a comment in mtk_eint_chip_read_mask.
> -delete ALIGN when allocate eint_offsets.ports.
> -fix unrelated change.
>
> changes since v2:
> -modify irq_wake to handle irq wakeup source.
> -allocate two buffers separately.
> -fix some codestyle.
>
> Changes since v1:
> -implement irq_wake handler.
> ---
>
>  drivers/pinctrl/mediatek/pinctrl-mt8173.c     |  1 +
>  drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 91 ++++++++++++++++++++++++++-
>  drivers/pinctrl/mediatek/pinctrl-mtk-common.h |  4 ++
>  3 files changed, 95 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mt8173.c b/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> index d0c811d..ad27184 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> @@ -385,6 +385,7 @@ static struct platform_driver mtk_pinctrl_driver = {
>         .driver = {
>                 .name = "mediatek-mt8173-pinctrl",
>                 .of_match_table = mt8173_pctrl_match,
> +               .pm = &mtk_eint_pm_ops,
>         },
>  };
>
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> index ad1ea16..fe34ce9 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> @@ -33,6 +33,7 @@
>  #include <linux/mfd/syscon.h>
>  #include <linux/delay.h>
>  #include <linux/interrupt.h>
> +#include <linux/pm.h>
>  #include <dt-bindings/pinctrl/mt65xx.h>
>
>  #include "../core.h"
> @@ -1062,6 +1063,77 @@ static int mtk_eint_set_type(struct irq_data *d,
>         return 0;
>  }
>
> +static int mtk_eint_irq_set_wake(struct irq_data *d, unsigned int on)
> +{
> +       struct mtk_pinctrl *pctl = irq_data_get_irq_chip_data(d);
> +       int shift = d->hwirq & 0x1f;
> +       int reg = d->hwirq >> 5;
> +
> +       if (on)
> +               pctl->wake_mask[reg] |= BIT(shift);
> +       else
> +               pctl->wake_mask[reg] &= ~BIT(shift);
> +
> +       return 0;
> +}
> +
> +static void mtk_eint_chip_write_mask(const struct mtk_eint_offsets *chip,
> +               void __iomem *eint_reg_base, u32 *buf)
> +{
> +       int port;
> +       void __iomem *reg;
> +
> +       for (port = 0; port < chip->ports; port++) {
> +               reg = eint_reg_base + (port << 2);
> +               writel_relaxed(~buf[port], reg + chip->mask_set);
> +               writel_relaxed(buf[port], reg + chip->mask_clr);
> +       }
> +}
> +
> +static void mtk_eint_chip_read_mask(const struct mtk_eint_offsets *chip,
> +               void __iomem *eint_reg_base, u32 *buf)
> +{
> +       int port;
> +       void __iomem *reg;
> +
> +       for (port = 0; port < chip->ports; port++) {
> +               reg = eint_reg_base + chip->mask + (port << 2);
> +               buf[port] = ~readl_relaxed(reg);
> +               /* Mask is 0 when irq is enabled, and 1 when disabled. */
> +       }
> +}
> +
> +static int mtk_eint_suspend(struct device *device)
> +{
> +       void __iomem *reg;
> +       struct mtk_pinctrl *pctl = dev_get_drvdata(device);
> +       const struct mtk_eint_offsets *eint_offsets =
> +                       &pctl->devdata->eint_offsets;
> +
> +       reg = pctl->eint_reg_base;
> +       mtk_eint_chip_read_mask(eint_offsets, reg, pctl->cur_mask);
> +       mtk_eint_chip_write_mask(eint_offsets, reg, pctl->wake_mask);
> +
> +       return 0;
> +}
> +
> +static int mtk_eint_resume(struct device *device)
> +{
> +       struct mtk_pinctrl *pctl = dev_get_drvdata(device);
> +       const struct mtk_eint_offsets *eint_offsets =
> +                       &pctl->devdata->eint_offsets;
> +
> +       mtk_eint_chip_write_mask(eint_offsets,
> +                       pctl->eint_reg_base, pctl->cur_mask);
> +
> +       return 0;
> +}
> +
> +const struct dev_pm_ops mtk_eint_pm_ops = {
> +       .suspend = mtk_eint_suspend,
> +       .resume = mtk_eint_resume,
> +};
> +
>  static void mtk_eint_ack(struct irq_data *d)
>  {
>         struct mtk_pinctrl *pctl = irq_data_get_irq_chip_data(d);
> @@ -1076,10 +1148,12 @@ static void mtk_eint_ack(struct irq_data *d)
>
>  static struct irq_chip mtk_pinctrl_irq_chip = {
>         .name = "mt-eint",
> +       .irq_disable = mtk_eint_mask,
>         .irq_mask = mtk_eint_mask,
>         .irq_unmask = mtk_eint_unmask,
>         .irq_ack = mtk_eint_ack,
>         .irq_set_type = mtk_eint_set_type,
> +       .irq_set_wake = mtk_eint_irq_set_wake,
>         .irq_request_resources = mtk_pinctrl_irq_request_resources,
>         .irq_release_resources = mtk_pinctrl_irq_release_resources,
>  };
> @@ -1217,7 +1291,7 @@ int mtk_pctrl_init(struct platform_device *pdev,
>         struct device_node *np = pdev->dev.of_node, *node;
>         struct property *prop;
>         struct resource *res;
> -       int i, ret, irq;
> +       int i, ret, irq, ports_buf;
>
>         pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL);
>         if (!pctl)
> @@ -1319,6 +1393,21 @@ int mtk_pctrl_init(struct platform_device *pdev,
>                 goto chip_error;
>         }
>
> +       ports_buf = pctl->devdata->eint_offsets.ports;
> +       pctl->wake_mask = devm_kcalloc(&pdev->dev, ports_buf,
> +                                       sizeof(*pctl->wake_mask), GFP_KERNEL);
> +       if (!pctl->wake_mask) {
> +               ret = -ENOMEM;
> +               goto chip_error;
> +       }
> +
> +       pctl->cur_mask = devm_kcalloc(&pdev->dev, ports_buf,
> +                                       sizeof(*pctl->cur_mask), GFP_KERNEL);
> +       if (!pctl->cur_mask) {
> +               ret = -ENOMEM;
> +               goto chip_error;
> +       }
> +
>         pctl->eint_dual_edges = devm_kcalloc(&pdev->dev, pctl->devdata->ap_num,
>                                              sizeof(int), GFP_KERNEL);
>         if (!pctl->eint_dual_edges) {
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.h b/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
> index 30213e5..f1be8e8 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
> @@ -266,6 +266,8 @@ struct mtk_pinctrl {
>         void __iomem            *eint_reg_base;
>         struct irq_domain       *domain;
>         int                     *eint_dual_edges;
> +       u32 *wake_mask;
> +       u32 *cur_mask;
>  };
>
>  int mtk_pctrl_init(struct platform_device *pdev,
> @@ -281,4 +283,6 @@ int mtk_pconf_spec_set_ies_smt_range(struct regmap *regmap,
>                 const struct mtk_pin_ies_smt_set *ies_smt_infos, unsigned int info_num,
>                 unsigned int pin, unsigned char align, int value);
>
> +extern const struct dev_pm_ops mtk_eint_pm_ops;
> +
>  #endif /* __PINCTRL_MTK_COMMON_H */
> --
> 1.8.1.1.dirty
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-08-14  8:38 [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume maoguang.meng
  2015-08-14  9:57 ` Daniel Kurtz
@ 2015-08-17  7:52 ` Yingjoe Chen
  2015-08-17  9:09   ` Daniel Kurtz
  2015-08-24 16:27 ` Sudeep Holla
  2015-08-26 12:41 ` Linus Walleij
  3 siblings, 1 reply; 19+ messages in thread
From: Yingjoe Chen @ 2015-08-17  7:52 UTC (permalink / raw)
  To: maoguang.meng
  Cc: Linus Walleij, Matthias Brugger, Hongzhou Yang, linux-gpio,
	linux-arm-kernel, linux-mediatek, linux-kernel

On Fri, 2015-08-14 at 16:38 +0800, maoguang.meng@mediatek.com wrote:
> From: Maoguang Meng <maoguang.meng@mediatek.com>
> 
> This patch implement irq_set_wake to get who is wakeup source and
> setup on suspend resume.
> 
> Signed-off-by: Maoguang Meng <maoguang.meng@mediatek.com>
> 
> ---
> changes since v3:
> -add a comment in mtk_eint_chip_read_mask.
> -delete ALIGN when allocate eint_offsets.ports.
> -fix unrelated change.
> 
> changes since v2:
> -modify irq_wake to handle irq wakeup source.
> -allocate two buffers separately.
> -fix some codestyle.
> 
> Changes since v1:
> -implement irq_wake handler.
> ---
> 
>  drivers/pinctrl/mediatek/pinctrl-mt8173.c     |  1 +
>  drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 91 ++++++++++++++++++++++++++-
>  drivers/pinctrl/mediatek/pinctrl-mtk-common.h |  4 ++
>  3 files changed, 95 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mt8173.c b/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> index d0c811d..ad27184 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> @@ -385,6 +385,7 @@ static struct platform_driver mtk_pinctrl_driver = {
>  	.driver = {
>  		.name = "mediatek-mt8173-pinctrl",
>  		.of_match_table = mt8173_pctrl_match,
> +		.pm = &mtk_eint_pm_ops,
>  	},
>  };
>  
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> index ad1ea16..fe34ce9 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> @@ -33,6 +33,7 @@
>  #include <linux/mfd/syscon.h>
>  #include <linux/delay.h>
>  #include <linux/interrupt.h>
> +#include <linux/pm.h>
>  #include <dt-bindings/pinctrl/mt65xx.h>
>  
>  #include "../core.h"
> @@ -1062,6 +1063,77 @@ static int mtk_eint_set_type(struct irq_data *d,
>  	return 0;
>  }
>  
> +static int mtk_eint_irq_set_wake(struct irq_data *d, unsigned int on)
> +{
> +	struct mtk_pinctrl *pctl = irq_data_get_irq_chip_data(d);
> +	int shift = d->hwirq & 0x1f;
> +	int reg = d->hwirq >> 5;
> +
> +	if (on)
> +		pctl->wake_mask[reg] |= BIT(shift);
> +	else
> +		pctl->wake_mask[reg] &= ~BIT(shift);
> +
> +	return 0;
> +}

Hi Maoguang,

You changed from set_bit/clear_bit to this, but didn't add any locking.
Since this is basic read/modify/write, is it OK to do it without
locking?

Joe.C



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-08-17  7:52 ` Yingjoe Chen
@ 2015-08-17  9:09   ` Daniel Kurtz
  2015-08-17 13:25     ` Yingjoe Chen
  0 siblings, 1 reply; 19+ messages in thread
From: Daniel Kurtz @ 2015-08-17  9:09 UTC (permalink / raw)
  To: Yingjoe Chen
  Cc: maoguang meng, Linus Walleij, Matthias Brugger, Hongzhou Yang,
	linux-gpio, linux-arm-kernel, linux-mediatek, linux-kernel

On Mon, Aug 17, 2015 at 3:52 PM, Yingjoe Chen <yingjoe.chen@mediatek.com> wrote:
> On Fri, 2015-08-14 at 16:38 +0800, maoguang.meng@mediatek.com wrote:
>> From: Maoguang Meng <maoguang.meng@mediatek.com>
>>
>> This patch implement irq_set_wake to get who is wakeup source and
>> setup on suspend resume.
>>
>> Signed-off-by: Maoguang Meng <maoguang.meng@mediatek.com>
>>
>> ---
>> changes since v3:
>> -add a comment in mtk_eint_chip_read_mask.
>> -delete ALIGN when allocate eint_offsets.ports.
>> -fix unrelated change.
>>
>> changes since v2:
>> -modify irq_wake to handle irq wakeup source.
>> -allocate two buffers separately.
>> -fix some codestyle.
>>
>> Changes since v1:
>> -implement irq_wake handler.
>> ---
>>
>>  drivers/pinctrl/mediatek/pinctrl-mt8173.c     |  1 +
>>  drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 91 ++++++++++++++++++++++++++-
>>  drivers/pinctrl/mediatek/pinctrl-mtk-common.h |  4 ++
>>  3 files changed, 95 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/pinctrl/mediatek/pinctrl-mt8173.c b/drivers/pinctrl/mediatek/pinctrl-mt8173.c
>> index d0c811d..ad27184 100644
>> --- a/drivers/pinctrl/mediatek/pinctrl-mt8173.c
>> +++ b/drivers/pinctrl/mediatek/pinctrl-mt8173.c
>> @@ -385,6 +385,7 @@ static struct platform_driver mtk_pinctrl_driver = {
>>       .driver = {
>>               .name = "mediatek-mt8173-pinctrl",
>>               .of_match_table = mt8173_pctrl_match,
>> +             .pm = &mtk_eint_pm_ops,
>>       },
>>  };
>>
>> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
>> index ad1ea16..fe34ce9 100644
>> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
>> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
>> @@ -33,6 +33,7 @@
>>  #include <linux/mfd/syscon.h>
>>  #include <linux/delay.h>
>>  #include <linux/interrupt.h>
>> +#include <linux/pm.h>
>>  #include <dt-bindings/pinctrl/mt65xx.h>
>>
>>  #include "../core.h"
>> @@ -1062,6 +1063,77 @@ static int mtk_eint_set_type(struct irq_data *d,
>>       return 0;
>>  }
>>
>> +static int mtk_eint_irq_set_wake(struct irq_data *d, unsigned int on)
>> +{
>> +     struct mtk_pinctrl *pctl = irq_data_get_irq_chip_data(d);
>> +     int shift = d->hwirq & 0x1f;
>> +     int reg = d->hwirq >> 5;
>> +
>> +     if (on)
>> +             pctl->wake_mask[reg] |= BIT(shift);
>> +     else
>> +             pctl->wake_mask[reg] &= ~BIT(shift);
>> +
>> +     return 0;
>> +}
>
> Hi Maoguang,
>
> You changed from set_bit/clear_bit to this, but didn't add any locking.
> Since this is basic read/modify/write, is it OK to do it without
> locking?

I believe calling .irq_set_wake() concurrently with itself is
protected by irq_get_desc_buslock():

 int irq_set_irq_wake(unsigned int irq, unsigned int on)
 {
         unsigned long flags;
         struct irq_desc *desc = irq_get_desc_buslock(irq, &flags,
IRQ_GET_DESC_CHECK_GLOBAL);
         int ret = 0;
...
                         ret = set_irq_wake_real(irq, on);
...
         irq_put_desc_busunlock(desc, flags);
         return ret;
 }


I'm not 100% sure about the .suspend/.resume paths, but I don't think
they can occur during .irq_set_wake(), either.
Nor were they protected by the set_bit/clear_bit implementation.

-Dan


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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-08-17  9:09   ` Daniel Kurtz
@ 2015-08-17 13:25     ` Yingjoe Chen
  2015-08-17 21:45       ` Hongzhou Yang
  0 siblings, 1 reply; 19+ messages in thread
From: Yingjoe Chen @ 2015-08-17 13:25 UTC (permalink / raw)
  To: Daniel Kurtz
  Cc: maoguang meng, Linus Walleij, Matthias Brugger, Hongzhou Yang,
	linux-gpio, linux-arm-kernel, linux-mediatek, linux-kernel

On Mon, 2015-08-17 at 17:09 +0800, Daniel Kurtz wrote:
> On Mon, Aug 17, 2015 at 3:52 PM, Yingjoe Chen <yingjoe.chen@mediatek.com> wrote:
> > On Fri, 2015-08-14 at 16:38 +0800, maoguang.meng@mediatek.com wrote:
> >> From: Maoguang Meng <maoguang.meng@mediatek.com>
> >>
> >> This patch implement irq_set_wake to get who is wakeup source and
> >> setup on suspend resume.
> >>
> >> Signed-off-by: Maoguang Meng <maoguang.meng@mediatek.com>
> >>
> >> ---
> >> changes since v3:
> >> -add a comment in mtk_eint_chip_read_mask.
> >> -delete ALIGN when allocate eint_offsets.ports.
> >> -fix unrelated change.
> >>
> >> changes since v2:
> >> -modify irq_wake to handle irq wakeup source.
> >> -allocate two buffers separately.
> >> -fix some codestyle.
> >>
> >> Changes since v1:
> >> -implement irq_wake handler.
> >> ---
> >>
> >>  drivers/pinctrl/mediatek/pinctrl-mt8173.c     |  1 +
> >>  drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 91 ++++++++++++++++++++++++++-
> >>  drivers/pinctrl/mediatek/pinctrl-mtk-common.h |  4 ++
> >>  3 files changed, 95 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/pinctrl/mediatek/pinctrl-mt8173.c b/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> >> index d0c811d..ad27184 100644
> >> --- a/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> >> +++ b/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> >> @@ -385,6 +385,7 @@ static struct platform_driver mtk_pinctrl_driver = {
> >>       .driver = {
> >>               .name = "mediatek-mt8173-pinctrl",
> >>               .of_match_table = mt8173_pctrl_match,
> >> +             .pm = &mtk_eint_pm_ops,
> >>       },
> >>  };
> >>
> >> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> >> index ad1ea16..fe34ce9 100644
> >> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> >> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> >> @@ -33,6 +33,7 @@
> >>  #include <linux/mfd/syscon.h>
> >>  #include <linux/delay.h>
> >>  #include <linux/interrupt.h>
> >> +#include <linux/pm.h>
> >>  #include <dt-bindings/pinctrl/mt65xx.h>
> >>
> >>  #include "../core.h"
> >> @@ -1062,6 +1063,77 @@ static int mtk_eint_set_type(struct irq_data *d,
> >>       return 0;
> >>  }
> >>
> >> +static int mtk_eint_irq_set_wake(struct irq_data *d, unsigned int on)
> >> +{
> >> +     struct mtk_pinctrl *pctl = irq_data_get_irq_chip_data(d);
> >> +     int shift = d->hwirq & 0x1f;
> >> +     int reg = d->hwirq >> 5;
> >> +
> >> +     if (on)
> >> +             pctl->wake_mask[reg] |= BIT(shift);
> >> +     else
> >> +             pctl->wake_mask[reg] &= ~BIT(shift);
> >> +
> >> +     return 0;
> >> +}
> >
> > Hi Maoguang,
> >
> > You changed from set_bit/clear_bit to this, but didn't add any locking.
> > Since this is basic read/modify/write, is it OK to do it without
> > locking?
> 
> I believe calling .irq_set_wake() concurrently with itself is
> protected by irq_get_desc_buslock():
> 
>  int irq_set_irq_wake(unsigned int irq, unsigned int on)
>  {
>          unsigned long flags;
>          struct irq_desc *desc = irq_get_desc_buslock(irq, &flags,
> IRQ_GET_DESC_CHECK_GLOBAL);
>          int ret = 0;
> ...
>                          ret = set_irq_wake_real(irq, on);
> ...
>          irq_put_desc_busunlock(desc, flags);
>          return ret;
>  }

Hi Dan,

You are right, irq_get_desc_buslock will acquire desc lock even when
irq_chip didn't provide irq_bus_lock callback. So this should be OK.
Sorry for the noise.

For this patch:

Acked-by: Yingjoe Chen <yingjoe.chen@mediatek.com>

Joe.C




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-08-17 13:25     ` Yingjoe Chen
@ 2015-08-17 21:45       ` Hongzhou Yang
  0 siblings, 0 replies; 19+ messages in thread
From: Hongzhou Yang @ 2015-08-17 21:45 UTC (permalink / raw)
  To: Yingjoe Chen
  Cc: Daniel Kurtz, maoguang meng, Linus Walleij, Matthias Brugger,
	linux-gpio, linux-arm-kernel, linux-mediatek, linux-kernel

On Mon, 2015-08-17 at 21:25 +0800, Yingjoe Chen wrote:
> On Mon, 2015-08-17 at 17:09 +0800, Daniel Kurtz wrote:
> > On Mon, Aug 17, 2015 at 3:52 PM, Yingjoe Chen <yingjoe.chen@mediatek.com> wrote:
> > > On Fri, 2015-08-14 at 16:38 +0800, maoguang.meng@mediatek.com wrote:
> > >> From: Maoguang Meng <maoguang.meng@mediatek.com>
> > >>
> > >> This patch implement irq_set_wake to get who is wakeup source and
> > >> setup on suspend resume.
> > >>
> > >> Signed-off-by: Maoguang Meng <maoguang.meng@mediatek.com>
> > >>
> > >> ---
> > >> changes since v3:
> > >> -add a comment in mtk_eint_chip_read_mask.
> > >> -delete ALIGN when allocate eint_offsets.ports.
> > >> -fix unrelated change.
> > >>
> > >> changes since v2:
> > >> -modify irq_wake to handle irq wakeup source.
> > >> -allocate two buffers separately.
> > >> -fix some codestyle.
> > >>
> > >> Changes since v1:
> > >> -implement irq_wake handler.
> > >> ---
> > >>
> > >>  drivers/pinctrl/mediatek/pinctrl-mt8173.c     |  1 +
> > >>  drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 91 ++++++++++++++++++++++++++-
> > >>  drivers/pinctrl/mediatek/pinctrl-mtk-common.h |  4 ++
> > >>  3 files changed, 95 insertions(+), 1 deletion(-)
> > >>
> > >> diff --git a/drivers/pinctrl/mediatek/pinctrl-mt8173.c b/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> > >> index d0c811d..ad27184 100644
> > >> --- a/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> > >> +++ b/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> > >> @@ -385,6 +385,7 @@ static struct platform_driver mtk_pinctrl_driver = {
> > >>       .driver = {
> > >>               .name = "mediatek-mt8173-pinctrl",
> > >>               .of_match_table = mt8173_pctrl_match,
> > >> +             .pm = &mtk_eint_pm_ops,
> > >>       },
> > >>  };
> > >>
> > >> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> > >> index ad1ea16..fe34ce9 100644
> > >> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> > >> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> > >> @@ -33,6 +33,7 @@
> > >>  #include <linux/mfd/syscon.h>
> > >>  #include <linux/delay.h>
> > >>  #include <linux/interrupt.h>
> > >> +#include <linux/pm.h>
> > >>  #include <dt-bindings/pinctrl/mt65xx.h>
> > >>
> > >>  #include "../core.h"
> > >> @@ -1062,6 +1063,77 @@ static int mtk_eint_set_type(struct irq_data *d,
> > >>       return 0;
> > >>  }
> > >>
> > >> +static int mtk_eint_irq_set_wake(struct irq_data *d, unsigned int on)
> > >> +{
> > >> +     struct mtk_pinctrl *pctl = irq_data_get_irq_chip_data(d);
> > >> +     int shift = d->hwirq & 0x1f;
> > >> +     int reg = d->hwirq >> 5;
> > >> +
> > >> +     if (on)
> > >> +             pctl->wake_mask[reg] |= BIT(shift);
> > >> +     else
> > >> +             pctl->wake_mask[reg] &= ~BIT(shift);
> > >> +
> > >> +     return 0;
> > >> +}
> > >
> > > Hi Maoguang,
> > >
> > > You changed from set_bit/clear_bit to this, but didn't add any locking.
> > > Since this is basic read/modify/write, is it OK to do it without
> > > locking?
> > 
> > I believe calling .irq_set_wake() concurrently with itself is
> > protected by irq_get_desc_buslock():
> > 
> >  int irq_set_irq_wake(unsigned int irq, unsigned int on)
> >  {
> >          unsigned long flags;
> >          struct irq_desc *desc = irq_get_desc_buslock(irq, &flags,
> > IRQ_GET_DESC_CHECK_GLOBAL);
> >          int ret = 0;
> > ...
> >                          ret = set_irq_wake_real(irq, on);
> > ...
> >          irq_put_desc_busunlock(desc, flags);
> >          return ret;
> >  }
> 
> Hi Dan,
> 
> You are right, irq_get_desc_buslock will acquire desc lock even when
> irq_chip didn't provide irq_bus_lock callback. So this should be OK.
> Sorry for the noise.
> 
> For this patch:
> 
> Acked-by: Yingjoe Chen <yingjoe.chen@mediatek.com>
> 
> Joe.C
> 


Acked-by: Hongzhou Yang <hongzhou.yang@mediatek.com>

Thanks.
Hongzhou



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-08-14  8:38 [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume maoguang.meng
  2015-08-14  9:57 ` Daniel Kurtz
  2015-08-17  7:52 ` Yingjoe Chen
@ 2015-08-24 16:27 ` Sudeep Holla
  2015-09-02  6:02   ` Daniel Kurtz
  2015-08-26 12:41 ` Linus Walleij
  3 siblings, 1 reply; 19+ messages in thread
From: Sudeep Holla @ 2015-08-24 16:27 UTC (permalink / raw)
  To: maoguang.meng
  Cc: Linus Walleij, Sudeep Holla, Hongzhou Yang, linux-kernel,
	linux-gpio, linux-mediatek, Matthias Brugger, Yingjoe Chen,
	linux-arm-kernel, Daniel Kurtz



On 14/08/15 09:38, maoguang.meng@mediatek.com wrote:
> From: Maoguang Meng <maoguang.meng@mediatek.com>
>
> This patch implement irq_set_wake to get who is wakeup source and
> setup on suspend resume.
>
> Signed-off-by: Maoguang Meng <maoguang.meng@mediatek.com>
>
> ---
> changes since v3:
> -add a comment in mtk_eint_chip_read_mask.
> -delete ALIGN when allocate eint_offsets.ports.
> -fix unrelated change.
>
> changes since v2:
> -modify irq_wake to handle irq wakeup source.
> -allocate two buffers separately.
> -fix some codestyle.
>
> Changes since v1:
> -implement irq_wake handler.
> ---
>
>   drivers/pinctrl/mediatek/pinctrl-mt8173.c     |  1 +
>   drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 91 ++++++++++++++++++++++++++-
>   drivers/pinctrl/mediatek/pinctrl-mtk-common.h |  4 ++
>   3 files changed, 95 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mt8173.c b/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> index d0c811d..ad27184 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-mt8173.c
> @@ -385,6 +385,7 @@ static struct platform_driver mtk_pinctrl_driver = {
>   	.driver = {
>   		.name = "mediatek-mt8173-pinctrl",
>   		.of_match_table = mt8173_pctrl_match,
> +		.pm = &mtk_eint_pm_ops,
>   	},
>   };
>
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> index ad1ea16..fe34ce9 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> @@ -33,6 +33,7 @@
>   #include <linux/mfd/syscon.h>
>   #include <linux/delay.h>
>   #include <linux/interrupt.h>
> +#include <linux/pm.h>
>   #include <dt-bindings/pinctrl/mt65xx.h>
>
>   #include "../core.h"
> @@ -1062,6 +1063,77 @@ static int mtk_eint_set_type(struct irq_data *d,
>   	return 0;
>   }
>
> +static int mtk_eint_irq_set_wake(struct irq_data *d, unsigned int on)
> +{
> +	struct mtk_pinctrl *pctl = irq_data_get_irq_chip_data(d);
> +	int shift = d->hwirq & 0x1f;
> +	int reg = d->hwirq >> 5;
> +
> +	if (on)
> +		pctl->wake_mask[reg] |= BIT(shift);
> +	else
> +		pctl->wake_mask[reg] &= ~BIT(shift);
> +
> +	return 0;
> +}

Does this pinmux controller:

1. Support wake-up configuration ? If not, you need to use
    IRQCHIP_SKIP_SET_WAKE. I don't see any value in writing the
    mask_{set,clear} if the same registers are used for {en,dis}able

2. Is in always on domain ? If not, you need save/restore only to
    resume back the functionality. Generally we can set 	
    IRQCHIP_MASK_ON_SUSPEND to ensure non-wake-up interrupts are
    disabled during suspend and re-enabled in resume path. You just
    save/restore raw values without tracking the wake-up source.

Also I see that no care is taken to set the port irq as wake enable
source. It may work with current mainline, but won't with -next. Please
ensure the port irq to the parent interrupt controller remains
enabled(i.e set as wake).

Regards,
Sudeep

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-08-14  8:38 [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume maoguang.meng
                   ` (2 preceding siblings ...)
  2015-08-24 16:27 ` Sudeep Holla
@ 2015-08-26 12:41 ` Linus Walleij
  3 siblings, 0 replies; 19+ messages in thread
From: Linus Walleij @ 2015-08-26 12:41 UTC (permalink / raw)
  To: maoguang meng
  Cc: Matthias Brugger, Hongzhou Yang, Yingjoe Chen, linux-gpio,
	linux-arm-kernel, linux-mediatek, linux-kernel

On Fri, Aug 14, 2015 at 10:38 AM,  <maoguang.meng@mediatek.com> wrote:

> From: Maoguang Meng <maoguang.meng@mediatek.com>
>
> This patch implement irq_set_wake to get who is wakeup source and
> setup on suspend resume.
>
> Signed-off-by: Maoguang Meng <maoguang.meng@mediatek.com>
>
> ---
> changes since v3:
> -add a comment in mtk_eint_chip_read_mask.
> -delete ALIGN when allocate eint_offsets.ports.
> -fix unrelated change.

Patch applied with Daniel's, Yingjoe's and Hongzhu's tags.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-08-24 16:27 ` Sudeep Holla
@ 2015-09-02  6:02   ` Daniel Kurtz
  2015-09-06 10:39     ` maoguang meng
  0 siblings, 1 reply; 19+ messages in thread
From: Daniel Kurtz @ 2015-09-02  6:02 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: maoguang.meng, Linus Walleij, Hongzhou Yang, linux-kernel,
	linux-gpio, linux-mediatek, Matthias Brugger, Yingjoe Chen,
	linux-arm-kernel

Hi maoguang,

On Tue, Aug 25, 2015 at 12:27 AM, Sudeep Holla <sudeep.holla@arm.com> wrote:
>
>
> On 14/08/15 09:38, maoguang.meng@mediatek.com wrote:
>>
>> From: Maoguang Meng <maoguang.meng@mediatek.com>
>>
>> This patch implement irq_set_wake to get who is wakeup source and
>> setup on suspend resume.
>>
>> Signed-off-by: Maoguang Meng <maoguang.meng@mediatek.com>
>>
[snip]

Can you please respond to Sudeep's questions:

> Does this pinmux controller:
>
> 1. Support wake-up configuration ? If not, you need to use
>    IRQCHIP_SKIP_SET_WAKE. I don't see any value in writing the
>    mask_{set,clear} if the same registers are used for {en,dis}able
>
> 2. Is in always on domain ? If not, you need save/restore only to
>    resume back the functionality. Generally we can set
>    IRQCHIP_MASK_ON_SUSPEND to ensure non-wake-up interrupts are
>    disabled during suspend and re-enabled in resume path. You just
>    save/restore raw values without tracking the wake-up source.
>
> Also I see that no care is taken to set the port irq as wake enable
> source. It may work with current mainline, but won't with -next. Please
> ensure the port irq to the parent interrupt controller remains
> enabled(i.e set as wake).

>
> Regards,
> Sudeep

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-09-02  6:02   ` Daniel Kurtz
@ 2015-09-06 10:39     ` maoguang meng
  2015-09-08  9:28       ` Sudeep Holla
  0 siblings, 1 reply; 19+ messages in thread
From: maoguang meng @ 2015-09-06 10:39 UTC (permalink / raw)
  To: Sudeep Holla, Daniel Kurtz
  Cc: Linus Walleij, Hongzhou Yang, linux-kernel, linux-gpio,
	linux-mediatek, Matthias Brugger, Yingjoe Chen, linux-arm-kernel

On Wed, 2015-09-02 at 14:02 +0800, Daniel Kurtz wrote:
> Hi maoguang,
> 
> On Tue, Aug 25, 2015 at 12:27 AM, Sudeep Holla <sudeep.holla@arm.com> wrote:
> >
> >
> > On 14/08/15 09:38, maoguang.meng@mediatek.com wrote:
> >>
> >> From: Maoguang Meng <maoguang.meng@mediatek.com>
> >>
> >> This patch implement irq_set_wake to get who is wakeup source and
> >> setup on suspend resume.
> >>
> >> Signed-off-by: Maoguang Meng <maoguang.meng@mediatek.com>
> >>
> [snip]
> 
> Can you please respond to Sudeep's questions:
> 
> > Does this pinmux controller:
> >
> > 1. Support wake-up configuration ? If not, you need to use
> >    IRQCHIP_SKIP_SET_WAKE. I don't see any value in writing the
> >    mask_{set,clear} if the same registers are used for {en,dis}able

  YES.
  we can call enable_irq_wake(irq) to config this irq as a wake-up
source.

> >
> > 2. Is in always on domain ? If not, you need save/restore only to
> >    resume back the functionality. Generally we can set
> >    IRQCHIP_MASK_ON_SUSPEND to ensure non-wake-up interrupts are
> >    disabled during suspend and re-enabled in resume path. You just
> >    save/restore raw values without tracking the wake-up source.

  YES.

> >
> > Also I see that no care is taken to set the port irq as wake enable
> > source. It may work with current mainline, but won't with -next. Please
> > ensure the port irq to the parent interrupt controller remains
> > enabled(i.e set as wake).

As you know, we do not care the port irq as wake enbale source,
when enter suspend we think no matter what the port irq is
enabled/disabled which are not affected as a wake-up source,
Because eint has a line to receive SPM.

For example,after suspend,press power key(use eint5) will generate an
electrical signal which is send to spm by eint.
and then spm wake cpu.
  
> >
> > Regards,
> > Sudeep

Regards,
Maoguang


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-09-06 10:39     ` maoguang meng
@ 2015-09-08  9:28       ` Sudeep Holla
  2015-09-08 16:50         ` Sudeep Holla
  0 siblings, 1 reply; 19+ messages in thread
From: Sudeep Holla @ 2015-09-08  9:28 UTC (permalink / raw)
  To: maoguang meng
  Cc: Daniel Kurtz, Sudeep Holla, Linus Walleij, Hongzhou Yang,
	linux-kernel, linux-gpio, linux-mediatek, Matthias Brugger,
	Yingjoe Chen, linux-arm-kernel



On 06/09/15 11:39, maoguang meng wrote:
> On Wed, 2015-09-02 at 14:02 +0800, Daniel Kurtz wrote:
>> Hi maoguang,
>>
>> On Tue, Aug 25, 2015 at 12:27 AM, Sudeep Holla <sudeep.holla@arm.com> wrote:
>>>
>>>
>>> On 14/08/15 09:38, maoguang.meng@mediatek.com wrote:
>>>>
>>>> From: Maoguang Meng <maoguang.meng@mediatek.com>
>>>>
>>>> This patch implement irq_set_wake to get who is wakeup source and
>>>> setup on suspend resume.
>>>>
>>>> Signed-off-by: Maoguang Meng <maoguang.meng@mediatek.com>
>>>>
>> [snip]
>>
>> Can you please respond to Sudeep's questions:
>>
>>> Does this pinmux controller:
>>>
>>> 1. Support wake-up configuration ? If not, you need to use
>>>     IRQCHIP_SKIP_SET_WAKE. I don't see any value in writing the
>>>     mask_{set,clear} if the same registers are used for {en,dis}able
>
>    YES.
>    we can call enable_irq_wake(irq) to config this irq as a wake-up
> source.
>

No that doesn't answer my question. Yes you can always call
enable_irq_wake(irq) as along as you have irq_set_wake implemented.
But my question was does this pinmux controller support wake-up
configuration.

IMHO, by looking at the implementation I can confirm *NO*, it doesn't.
So please stop copy-pasting the implementation from other drivers.
The reason is you operate on the same mask_{set,clear} which you use
to {en,dis}able the interrupts which means you don't have to do anything
to configure an interrupt as a wakeup source other than just keeping
them enabled. Hopefully this clarifies.

>>>
>>> 2. Is in always on domain ? If not, you need save/restore only to
>>>     resume back the functionality. Generally we can set
>>>     IRQCHIP_MASK_ON_SUSPEND to ensure non-wake-up interrupts are
>>>     disabled during suspend and re-enabled in resume path. You just
>>>     save/restore raw values without tracking the wake-up source.
>
>    YES.
>

Again *YES* for what part of my question. If it's always-on, then you
don't need this suspend/resume callbacks at all, so I assume the answer
is *NO*.

>>>
>>> Also I see that no care is taken to set the port irq as wake enable
>>> source. It may work with current mainline, but won't with -next. Please
>>> ensure the port irq to the parent interrupt controller remains
>>> enabled(i.e set as wake).
>
> As you know, we do not care the port irq as wake enbale source,
> when enter suspend we think no matter what the port irq is
> enabled/disabled which are not affected as a wake-up source,
> Because eint has a line to receive SPM.
>

I understand that, but for proper wakeup functionality you need to do
configure the parent if you want to identify and handle that wakeup
interrupt. If you don't care then it should be fine.

> For example,after suspend,press power key(use eint5) will generate an
> electrical signal which is send to spm by eint.
> and then spm wake cpu.

Yes I got that, as I mentioned above, I think you don't need to identify
and handle the wakeup interrupt. E.g. if it's a keyboard key press, you
may need to identify the key pressed, so it needs to be handled
properly. In your case, I assume it's just power button whose main
function is to wake/boot and that's already achieved when you are woken up.

Regards,
Sudeep

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-09-08  9:28       ` Sudeep Holla
@ 2015-09-08 16:50         ` Sudeep Holla
  2015-09-11 11:22           ` Chung-Yih Wang (王崇懿)
  2015-09-12  9:50           ` maoguang meng
  0 siblings, 2 replies; 19+ messages in thread
From: Sudeep Holla @ 2015-09-08 16:50 UTC (permalink / raw)
  To: maoguang meng
  Cc: Daniel Kurtz, Sudeep Holla, Linus Walleij, Hongzhou Yang,
	linux-kernel, linux-gpio, linux-mediatek, Matthias Brugger,
	Yingjoe Chen, linux-arm-kernel



On 08/09/15 10:28, Sudeep Holla wrote:
>
>
> On 06/09/15 11:39, maoguang meng wrote:
>> On Wed, 2015-09-02 at 14:02 +0800, Daniel Kurtz wrote:
>>> Hi maoguang,
>>>
>>> On Tue, Aug 25, 2015 at 12:27 AM, Sudeep Holla <sudeep.holla@arm.com> wrote:
>>>>
>>>>
>>>> On 14/08/15 09:38, maoguang.meng@mediatek.com wrote:
>>>>>
>>>>> From: Maoguang Meng <maoguang.meng@mediatek.com>
>>>>>
>>>>> This patch implement irq_set_wake to get who is wakeup source and
>>>>> setup on suspend resume.
>>>>>
>>>>> Signed-off-by: Maoguang Meng <maoguang.meng@mediatek.com>
>>>>>
>>> [snip]
>>>
>>> Can you please respond to Sudeep's questions:
>>>
>>>> Does this pinmux controller:
>>>>
>>>> 1. Support wake-up configuration ? If not, you need to use
>>>>      IRQCHIP_SKIP_SET_WAKE. I don't see any value in writing the
>>>>      mask_{set,clear} if the same registers are used for {en,dis}able
>>
>>     YES.
>>     we can call enable_irq_wake(irq) to config this irq as a wake-up
>> source.
>>
>
> No that doesn't answer my question. Yes you can always call
> enable_irq_wake(irq) as along as you have irq_set_wake implemented.
> But my question was does this pinmux controller support wake-up
> configuration.
>
> IMHO, by looking at the implementation I can confirm *NO*, it doesn't.
> So please stop copy-pasting the implementation from other drivers.
> The reason is you operate on the same mask_{set,clear} which you use
> to {en,dis}able the interrupts which means you don't have to do anything
> to configure an interrupt as a wakeup source other than just keeping
> them enabled. Hopefully this clarifies.
>
>>>>
>>>> 2. Is in always on domain ? If not, you need save/restore only to
>>>>      resume back the functionality. Generally we can set
>>>>      IRQCHIP_MASK_ON_SUSPEND to ensure non-wake-up interrupts are
>>>>      disabled during suspend and re-enabled in resume path. You just
>>>>      save/restore raw values without tracking the wake-up source.
>>
>>     YES.
>>
>
> Again *YES* for what part of my question. If it's always-on, then you
> don't need this suspend/resume callbacks at all, so I assume the answer
> is *NO*.
>

IIUC this pinmux controller, something like below should work.


---->8

 From 7c26992bce047efb66a6ba8d2ffec2b272499df7 Mon Sep 17 00:00:00 2001
From: Sudeep Holla <sudeep.holla@arm.com>
Date: Tue, 8 Sep 2015 17:35:38 +0100
Subject: [PATCH] pinctrl: mediatek: Enable SKIP_SET_WAKE and MASK_ON_SUSPEND

The mediatek pinmux controller doesn't provides any facility to configure
the wakeup sources. So instead of providing redundant irq_set_wake
functionality, SKIP_SET_WAKE could be set to it. Also there's no need to
maintain 2 sets of masks.

This patch enables IRQCHIP_SKIP_SET_WAKE and IRQCHIP_MASK_ON_SUSPEND and
also removes wake_mask.

Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: Hongzhou Yang <hongzhou.yang@mediatek.com>
Cc: Yingjoe Chen <yingjoe.chen@mediatek.com>
Cc: Maoguang Meng <maoguang.meng@mediatek.com>
Cc: Chaotian Jing <chaotian.jing@mediatek.com>
Cc: linux-gpio@vger.kernel.org
Cc: linux-mediatek@lists.infradead.org
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
  drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 24 
+-----------------------
  drivers/pinctrl/mediatek/pinctrl-mtk-common.h |  1 -
  2 files changed, 1 insertion(+), 24 deletions(-)

diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c 
b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
index 7726c6caaf83..d8e194a5bb31 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
@@ -1063,20 +1063,6 @@ static int mtk_eint_set_type(struct irq_data *d,
  	return 0;
  }

-static int mtk_eint_irq_set_wake(struct irq_data *d, unsigned int on)
-{
-	struct mtk_pinctrl *pctl = irq_data_get_irq_chip_data(d);
-	int shift = d->hwirq & 0x1f;
-	int reg = d->hwirq >> 5;
-
-	if (on)
-		pctl->wake_mask[reg] |= BIT(shift);
-	else
-		pctl->wake_mask[reg] &= ~BIT(shift);
-
-	return 0;
-}
-
  static void mtk_eint_chip_write_mask(const struct mtk_eint_offsets *chip,
  		void __iomem *eint_reg_base, u32 *buf)
  {
@@ -1112,7 +1098,6 @@ static int mtk_eint_suspend(struct device *device)

  	reg = pctl->eint_reg_base;
  	mtk_eint_chip_read_mask(eint_offsets, reg, pctl->cur_mask);
-	mtk_eint_chip_write_mask(eint_offsets, reg, pctl->wake_mask);

  	return 0;
  }
@@ -1153,9 +1138,9 @@ static struct irq_chip mtk_pinctrl_irq_chip = {
  	.irq_unmask = mtk_eint_unmask,
  	.irq_ack = mtk_eint_ack,
  	.irq_set_type = mtk_eint_set_type,
-	.irq_set_wake = mtk_eint_irq_set_wake,
  	.irq_request_resources = mtk_pinctrl_irq_request_resources,
  	.irq_release_resources = mtk_pinctrl_irq_release_resources,
+	.flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND,
  };

  static unsigned int mtk_eint_init(struct mtk_pinctrl *pctl)
@@ -1393,13 +1378,6 @@ int mtk_pctrl_init(struct platform_device *pdev,
  	}

  	ports_buf = pctl->devdata->eint_offsets.ports;
-	pctl->wake_mask = devm_kcalloc(&pdev->dev, ports_buf,
-					sizeof(*pctl->wake_mask), GFP_KERNEL);
-	if (!pctl->wake_mask) {
-		ret = -ENOMEM;
-		goto chip_error;
-	}
-
  	pctl->cur_mask = devm_kcalloc(&pdev->dev, ports_buf,
  					sizeof(*pctl->cur_mask), GFP_KERNEL);
  	if (!pctl->cur_mask) {
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.h 
b/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
index 55a534338931..acd804a945d8 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
@@ -267,7 +267,6 @@ struct mtk_pinctrl {
  	void __iomem		*eint_reg_base;
  	struct irq_domain	*domain;
  	int			*eint_dual_edges;
-	u32 *wake_mask;
  	u32 *cur_mask;
  };

-- 
1.9.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-09-08 16:50         ` Sudeep Holla
@ 2015-09-11 11:22           ` Chung-Yih Wang (王崇懿)
  2015-09-11 12:43             ` Sudeep Holla
  2015-09-12  9:50           ` maoguang meng
  1 sibling, 1 reply; 19+ messages in thread
From: Chung-Yih Wang (王崇懿) @ 2015-09-11 11:22 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: maoguang meng, Hongzhou Yang, Linus Walleij, linux-kernel,
	linux-gpio, linux-mediatek, Matthias Brugger, Yingjoe Chen,
	linux-arm-kernel

Hi Sudeep and Maoguang,

   Please correct me if I am wrong. I think the wake_mask Maoguang
implemented is the wake-up configuration and it is how he disabled
other unwanted interrupt sources(e.g. audio jacket insertion) during
suspend.

  With Sudeep's patch which we had similar one before, the system got
waken up by audio jack insertion which we don't want. Maoguang tried
to implement wake_mask as the wake-up configuration to keep track of
effective wakeup sources(i.e. those who makes enable_irq_wake) and
write the wake-up configuration in mtk_eint_suspend(). What is your
suggestion to address this issue? Thanks!

On Wed, Sep 9, 2015 at 12:50 AM, Sudeep Holla <sudeep.holla@arm.com> wrote:
>
>
> On 08/09/15 10:28, Sudeep Holla wrote:
>>
>>
>>
>> On 06/09/15 11:39, maoguang meng wrote:
>>>
>>> On Wed, 2015-09-02 at 14:02 +0800, Daniel Kurtz wrote:
>>>>
>>>> Hi maoguang,
>>>>
>>>> On Tue, Aug 25, 2015 at 12:27 AM, Sudeep Holla <sudeep.holla@arm.com>
>>>> wrote:
>>>>>
>>>>>
>>>>>
>>>>> On 14/08/15 09:38, maoguang.meng@mediatek.com wrote:
>>>>>>
>>>>>>
>>>>>> From: Maoguang Meng <maoguang.meng@mediatek.com>
>>>>>>
>>>>>> This patch implement irq_set_wake to get who is wakeup source and
>>>>>> setup on suspend resume.
>>>>>>
>>>>>> Signed-off-by: Maoguang Meng <maoguang.meng@mediatek.com>
>>>>>>
>>>> [snip]
>>>>
>>>> Can you please respond to Sudeep's questions:
>>>>
>>>>> Does this pinmux controller:
>>>>>
>>>>> 1. Support wake-up configuration ? If not, you need to use
>>>>>      IRQCHIP_SKIP_SET_WAKE. I don't see any value in writing the
>>>>>      mask_{set,clear} if the same registers are used for {en,dis}able
>>>
>>>
>>>     YES.
>>>     we can call enable_irq_wake(irq) to config this irq as a wake-up
>>> source.
>>>
>>
>> No that doesn't answer my question. Yes you can always call
>> enable_irq_wake(irq) as along as you have irq_set_wake implemented.
>> But my question was does this pinmux controller support wake-up
>> configuration.
>>
>> IMHO, by looking at the implementation I can confirm *NO*, it doesn't.
>> So please stop copy-pasting the implementation from other drivers.
>> The reason is you operate on the same mask_{set,clear} which you use
>> to {en,dis}able the interrupts which means you don't have to do anything
>> to configure an interrupt as a wakeup source other than just keeping
>> them enabled. Hopefully this clarifies.
>>
>>>>>
>>>>> 2. Is in always on domain ? If not, you need save/restore only to
>>>>>      resume back the functionality. Generally we can set
>>>>>      IRQCHIP_MASK_ON_SUSPEND to ensure non-wake-up interrupts are
>>>>>      disabled during suspend and re-enabled in resume path. You just
>>>>>      save/restore raw values without tracking the wake-up source.
>>>
>>>
>>>     YES.
>>>
>>
>> Again *YES* for what part of my question. If it's always-on, then you
>> don't need this suspend/resume callbacks at all, so I assume the answer
>> is *NO*.
>>
>
> IIUC this pinmux controller, something like below should work.
>
>
> ---->8
>
> From 7c26992bce047efb66a6ba8d2ffec2b272499df7 Mon Sep 17 00:00:00 2001
> From: Sudeep Holla <sudeep.holla@arm.com>
> Date: Tue, 8 Sep 2015 17:35:38 +0100
> Subject: [PATCH] pinctrl: mediatek: Enable SKIP_SET_WAKE and MASK_ON_SUSPEND
>
> The mediatek pinmux controller doesn't provides any facility to configure
> the wakeup sources. So instead of providing redundant irq_set_wake
> functionality, SKIP_SET_WAKE could be set to it. Also there's no need to
> maintain 2 sets of masks.
>
> This patch enables IRQCHIP_SKIP_SET_WAKE and IRQCHIP_MASK_ON_SUSPEND and
> also removes wake_mask.
>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Matthias Brugger <matthias.bgg@gmail.com>
> Cc: Hongzhou Yang <hongzhou.yang@mediatek.com>
> Cc: Yingjoe Chen <yingjoe.chen@mediatek.com>
> Cc: Maoguang Meng <maoguang.meng@mediatek.com>
> Cc: Chaotian Jing <chaotian.jing@mediatek.com>
> Cc: linux-gpio@vger.kernel.org
> Cc: linux-mediatek@lists.infradead.org
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>  drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 24 +-----------------------
>  drivers/pinctrl/mediatek/pinctrl-mtk-common.h |  1 -
>  2 files changed, 1 insertion(+), 24 deletions(-)
>
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> index 7726c6caaf83..d8e194a5bb31 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> @@ -1063,20 +1063,6 @@ static int mtk_eint_set_type(struct irq_data *d,
>         return 0;
>  }
>
> -static int mtk_eint_irq_set_wake(struct irq_data *d, unsigned int on)
> -{
> -       struct mtk_pinctrl *pctl = irq_data_get_irq_chip_data(d);
> -       int shift = d->hwirq & 0x1f;
> -       int reg = d->hwirq >> 5;
> -
> -       if (on)
> -               pctl->wake_mask[reg] |= BIT(shift);
> -       else
> -               pctl->wake_mask[reg] &= ~BIT(shift);
> -
> -       return 0;
> -}
> -
>  static void mtk_eint_chip_write_mask(const struct mtk_eint_offsets *chip,
>                 void __iomem *eint_reg_base, u32 *buf)
>  {
> @@ -1112,7 +1098,6 @@ static int mtk_eint_suspend(struct device *device)
>
>         reg = pctl->eint_reg_base;
>         mtk_eint_chip_read_mask(eint_offsets, reg, pctl->cur_mask);
> -       mtk_eint_chip_write_mask(eint_offsets, reg, pctl->wake_mask);
>
>         return 0;
>  }
> @@ -1153,9 +1138,9 @@ static struct irq_chip mtk_pinctrl_irq_chip = {
>         .irq_unmask = mtk_eint_unmask,
>         .irq_ack = mtk_eint_ack,
>         .irq_set_type = mtk_eint_set_type,
> -       .irq_set_wake = mtk_eint_irq_set_wake,
>         .irq_request_resources = mtk_pinctrl_irq_request_resources,
>         .irq_release_resources = mtk_pinctrl_irq_release_resources,
> +       .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND,
>  };
>
>  static unsigned int mtk_eint_init(struct mtk_pinctrl *pctl)
> @@ -1393,13 +1378,6 @@ int mtk_pctrl_init(struct platform_device *pdev,
>         }
>
>         ports_buf = pctl->devdata->eint_offsets.ports;
> -       pctl->wake_mask = devm_kcalloc(&pdev->dev, ports_buf,
> -                                       sizeof(*pctl->wake_mask),
> GFP_KERNEL);
> -       if (!pctl->wake_mask) {
> -               ret = -ENOMEM;
> -               goto chip_error;
> -       }
> -
>         pctl->cur_mask = devm_kcalloc(&pdev->dev, ports_buf,
>                                         sizeof(*pctl->cur_mask),
> GFP_KERNEL);
>         if (!pctl->cur_mask) {
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
> b/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
> index 55a534338931..acd804a945d8 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
> @@ -267,7 +267,6 @@ struct mtk_pinctrl {
>         void __iomem            *eint_reg_base;
>         struct irq_domain       *domain;
>         int                     *eint_dual_edges;
> -       u32 *wake_mask;
>         u32 *cur_mask;
>  };
>
> --
> 1.9.1
>
>
> _______________________________________________
> Linux-mediatek mailing list
> Linux-mediatek@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-09-11 11:22           ` Chung-Yih Wang (王崇懿)
@ 2015-09-11 12:43             ` Sudeep Holla
  0 siblings, 0 replies; 19+ messages in thread
From: Sudeep Holla @ 2015-09-11 12:43 UTC (permalink / raw)
  To: Chung-Yih Wang (王崇懿)
  Cc: Sudeep Holla, maoguang meng, Hongzhou Yang, Linus Walleij,
	linux-kernel, linux-gpio, linux-mediatek, Matthias Brugger,
	Yingjoe Chen, linux-arm-kernel



On 11/09/15 12:22, Chung-Yih Wang (王崇懿) wrote:
> Hi Sudeep and Maoguang,
>
>     Please correct me if I am wrong. I think the wake_mask Maoguang
> implemented is the wake-up configuration and it is how he disabled
> other unwanted interrupt sources(e.g. audio jacket insertion) during
> suspend.
>

OK, you are right, I think I now understand the issue. I misread the
code initially thinking the suspend/resume are implemented as
syscore_ops but they are standard device pm ops.

>    With Sudeep's patch which we had similar one before, the system got
> waken up by audio jack insertion which we don't want. Maoguang tried
> to implement wake_mask as the wake-up configuration to keep track of
> effective wakeup sources(i.e. those who makes enable_irq_wake) and
> write the wake-up configuration in mtk_eint_suspend(). What is your
> suggestion to address this issue? Thanks!
>

One option is to convert them to *_noirq callbacks assuming all the
users of this pinctrl irqchip have sanely implemented their
suspend/resume and don't trigger interrupts between dpm_suspend and
suspend_device_irqs. What do you think ?

Regards,
Sudeep

---->8

@@ -1130,8 +1130,8 @@ static int mtk_eint_resume(struct device *device)
  }

  const struct dev_pm_ops mtk_eint_pm_ops = {
-       .suspend = mtk_eint_suspend,
-       .resume = mtk_eint_resume,
+       .suspend_noirq = mtk_eint_suspend,
+       .resume_noirq = mtk_eint_resume,
  };

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-09-08 16:50         ` Sudeep Holla
  2015-09-11 11:22           ` Chung-Yih Wang (王崇懿)
@ 2015-09-12  9:50           ` maoguang meng
  2015-09-14 11:16             ` Sudeep Holla
  1 sibling, 1 reply; 19+ messages in thread
From: maoguang meng @ 2015-09-12  9:50 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: Daniel Kurtz, Linus Walleij, Hongzhou Yang, linux-kernel,
	linux-gpio, linux-mediatek, Matthias Brugger,
	Yingjoe Chen (陳英洲),
	linux-arm-kernel

hi Sudeep:

I test flowlling your blow suggestions,but the system can not be woken.

beacuse,mtk_eint_suspend will mask it.As we know if eint wakeup system
it must be unmasked before enter suspend flow.

e.x

static int __maybe_unused elan_suspend(struct device *dev)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct elan_tp_data *data = i2c_get_clientdata(client);
	int ret;

	/*
	 * We are taking the mutex to make sure sysfs operations are
	 * complete before we attempt to bring the device into low[er]
	 * power mode.
	 */
	ret = mutex_lock_interruptible(&data->sysfs_mutex);
	if (ret)
		return ret;

	disable_irq(client->irq);

	if (device_may_wakeup(dev)) {
		ret = elan_sleep(data);
		/* Enable wake from IRQ */
		data->irq_wake = (enable_irq_wake(client->irq) == 0);
	} else {
		ret = elan_disable_power(data);
	}

	mutex_unlock(&data->sysfs_mutex);
	return ret;
}

thanks

Best Regards,

Maoguang

On Wed, 2015-09-09 at 00:50 +0800, Sudeep Holla wrote:
> 
> On 08/09/15 10:28, Sudeep Holla wrote:
> >
> >
> > On 06/09/15 11:39, maoguang meng wrote:
> >> On Wed, 2015-09-02 at 14:02 +0800, Daniel Kurtz wrote:
> >>> Hi maoguang,
> >>>
> >>> On Tue, Aug 25, 2015 at 12:27 AM, Sudeep Holla <sudeep.holla@arm.com> wrote:
> >>>>
> >>>>
> >>>> On 14/08/15 09:38, maoguang.meng@mediatek.com wrote:
> >>>>>
> >>>>> From: Maoguang Meng <maoguang.meng@mediatek.com>
> >>>>>
> >>>>> This patch implement irq_set_wake to get who is wakeup source and
> >>>>> setup on suspend resume.
> >>>>>
> >>>>> Signed-off-by: Maoguang Meng <maoguang.meng@mediatek.com>
> >>>>>
> >>> [snip]
> >>>
> >>> Can you please respond to Sudeep's questions:
> >>>
> >>>> Does this pinmux controller:
> >>>>
> >>>> 1. Support wake-up configuration ? If not, you need to use
> >>>>      IRQCHIP_SKIP_SET_WAKE. I don't see any value in writing the
> >>>>      mask_{set,clear} if the same registers are used for {en,dis}able
> >>
> >>     YES.
> >>     we can call enable_irq_wake(irq) to config this irq as a wake-up
> >> source.
> >>
> >
> > No that doesn't answer my question. Yes you can always call
> > enable_irq_wake(irq) as along as you have irq_set_wake implemented.
> > But my question was does this pinmux controller support wake-up
> > configuration.
> >
> > IMHO, by looking at the implementation I can confirm *NO*, it doesn't.
> > So please stop copy-pasting the implementation from other drivers.
> > The reason is you operate on the same mask_{set,clear} which you use
> > to {en,dis}able the interrupts which means you don't have to do anything
> > to configure an interrupt as a wakeup source other than just keeping
> > them enabled. Hopefully this clarifies.
> >
> >>>>
> >>>> 2. Is in always on domain ? If not, you need save/restore only to
> >>>>      resume back the functionality. Generally we can set
> >>>>      IRQCHIP_MASK_ON_SUSPEND to ensure non-wake-up interrupts are
> >>>>      disabled during suspend and re-enabled in resume path. You just
> >>>>      save/restore raw values without tracking the wake-up source.
> >>
> >>     YES.
> >>
> >
> > Again *YES* for what part of my question. If it's always-on, then you
> > don't need this suspend/resume callbacks at all, so I assume the answer
> > is *NO*.
> >
> 
> IIUC this pinmux controller, something like below should work.
> 
> 
> ---->8
> 
>  From 7c26992bce047efb66a6ba8d2ffec2b272499df7 Mon Sep 17 00:00:00 2001
> From: Sudeep Holla <sudeep.holla@arm.com>
> Date: Tue, 8 Sep 2015 17:35:38 +0100
> Subject: [PATCH] pinctrl: mediatek: Enable SKIP_SET_WAKE and MASK_ON_SUSPEND
> 
> The mediatek pinmux controller doesn't provides any facility to configure
> the wakeup sources. So instead of providing redundant irq_set_wake
> functionality, SKIP_SET_WAKE could be set to it. Also there's no need to
> maintain 2 sets of masks.
> 
> This patch enables IRQCHIP_SKIP_SET_WAKE and IRQCHIP_MASK_ON_SUSPEND and
> also removes wake_mask.
> 
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Matthias Brugger <matthias.bgg@gmail.com>
> Cc: Hongzhou Yang <hongzhou.yang@mediatek.com>
> Cc: Yingjoe Chen <yingjoe.chen@mediatek.com>
> Cc: Maoguang Meng <maoguang.meng@mediatek.com>
> Cc: Chaotian Jing <chaotian.jing@mediatek.com>
> Cc: linux-gpio@vger.kernel.org
> Cc: linux-mediatek@lists.infradead.org
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>   drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 24 
> +-----------------------
>   drivers/pinctrl/mediatek/pinctrl-mtk-common.h |  1 -
>   2 files changed, 1 insertion(+), 24 deletions(-)
> 
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c 
> b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> index 7726c6caaf83..d8e194a5bb31 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> @@ -1063,20 +1063,6 @@ static int mtk_eint_set_type(struct irq_data *d,
>   	return 0;
>   }
> 
> -static int mtk_eint_irq_set_wake(struct irq_data *d, unsigned int on)
> -{
> -	struct mtk_pinctrl *pctl = irq_data_get_irq_chip_data(d);
> -	int shift = d->hwirq & 0x1f;
> -	int reg = d->hwirq >> 5;
> -
> -	if (on)
> -		pctl->wake_mask[reg] |= BIT(shift);
> -	else
> -		pctl->wake_mask[reg] &= ~BIT(shift);
> -
> -	return 0;
> -}
> -
>   static void mtk_eint_chip_write_mask(const struct mtk_eint_offsets *chip,
>   		void __iomem *eint_reg_base, u32 *buf)
>   {
> @@ -1112,7 +1098,6 @@ static int mtk_eint_suspend(struct device *device)
> 
>   	reg = pctl->eint_reg_base;
>   	mtk_eint_chip_read_mask(eint_offsets, reg, pctl->cur_mask);
> -	mtk_eint_chip_write_mask(eint_offsets, reg, pctl->wake_mask);
> 
>   	return 0;
>   }
> @@ -1153,9 +1138,9 @@ static struct irq_chip mtk_pinctrl_irq_chip = {
>   	.irq_unmask = mtk_eint_unmask,
>   	.irq_ack = mtk_eint_ack,
>   	.irq_set_type = mtk_eint_set_type,
> -	.irq_set_wake = mtk_eint_irq_set_wake,
>   	.irq_request_resources = mtk_pinctrl_irq_request_resources,
>   	.irq_release_resources = mtk_pinctrl_irq_release_resources,
> +	.flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND,
>   };
> 
>   static unsigned int mtk_eint_init(struct mtk_pinctrl *pctl)
> @@ -1393,13 +1378,6 @@ int mtk_pctrl_init(struct platform_device *pdev,
>   	}
> 
>   	ports_buf = pctl->devdata->eint_offsets.ports;
> -	pctl->wake_mask = devm_kcalloc(&pdev->dev, ports_buf,
> -					sizeof(*pctl->wake_mask), GFP_KERNEL);
> -	if (!pctl->wake_mask) {
> -		ret = -ENOMEM;
> -		goto chip_error;
> -	}
> -
>   	pctl->cur_mask = devm_kcalloc(&pdev->dev, ports_buf,
>   					sizeof(*pctl->cur_mask), GFP_KERNEL);
>   	if (!pctl->cur_mask) {
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.h 
> b/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
> index 55a534338931..acd804a945d8 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
> @@ -267,7 +267,6 @@ struct mtk_pinctrl {
>   	void __iomem		*eint_reg_base;
>   	struct irq_domain	*domain;
>   	int			*eint_dual_edges;
> -	u32 *wake_mask;
>   	u32 *cur_mask;
>   };
> 



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-09-12  9:50           ` maoguang meng
@ 2015-09-14 11:16             ` Sudeep Holla
  2015-09-15  2:43               ` Daniel Kurtz
  2015-09-15  2:52               ` Dmitry Torokhov
  0 siblings, 2 replies; 19+ messages in thread
From: Sudeep Holla @ 2015-09-14 11:16 UTC (permalink / raw)
  To: maoguang meng
  Cc: Sudeep Holla, Daniel Kurtz, Linus Walleij, Hongzhou Yang,
	linux-kernel, linux-gpio, linux-mediatek, Matthias Brugger,
	Yingjoe Chen (陳英洲),
	linux-arm-kernel



On 12/09/15 10:50, maoguang meng wrote:
> hi Sudeep:
> 
> I test flowlling your blow suggestions,but the system can not be woken.
> 
> beacuse,mtk_eint_suspend will mask it.As we know if eint wakeup system
> it must be unmasked before enter suspend flow.
> 
> e.x
> 
> static int __maybe_unused elan_suspend(struct device *dev)
> {
> 	struct i2c_client *client = to_i2c_client(dev);
> 	struct elan_tp_data *data = i2c_get_clientdata(client);
> 	int ret;
> 
> 	/*
> 	 * We are taking the mutex to make sure sysfs operations are
> 	 * complete before we attempt to bring the device into low[er]
> 	 * power mode.
> 	 */
> 	ret = mutex_lock_interruptible(&data->sysfs_mutex);
> 	if (ret)
> 		return ret;
> 
> 	disable_irq(client->irq);
> 
> 	if (device_may_wakeup(dev)) {
> 		ret = elan_sleep(data);
> 		/* Enable wake from IRQ */
> 		data->irq_wake = (enable_irq_wake(client->irq) == 0);

This is wrong assumption in the driver. enable_irq_wake doesn't
implicitly enable the IRQ. So the disable_irq should be moved to else.
And the resume patch also needs to be fixed accordingly, otherwise you
may get unbalanced irq. But this should not be the reason for fixing the
pinctrl suspend/resume.

Regards,
Sudeep

--->8

diff --git a/drivers/input/mouse/elan_i2c_core.c
b/drivers/input/mouse/elan_i2c_core.c
index fa945304b9a5..7de26b04f45c 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -1117,13 +1117,13 @@ static int __maybe_unused elan_suspend(struct
device *dev)
        if (ret)
                return ret;

-       disable_irq(client->irq);
-
        if (device_may_wakeup(dev)) {
                ret = elan_sleep(data);
                /* Enable wake from IRQ */
                data->irq_wake = (enable_irq_wake(client->irq) == 0);
        } else {
+               disable_irq(client->irq);
+
                ret = elan_disable_power(data);
        }

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-09-14 11:16             ` Sudeep Holla
@ 2015-09-15  2:43               ` Daniel Kurtz
  2015-09-15  2:52               ` Dmitry Torokhov
  1 sibling, 0 replies; 19+ messages in thread
From: Daniel Kurtz @ 2015-09-15  2:43 UTC (permalink / raw)
  To: Sudeep Holla, Dmitry Torokhov
  Cc: maoguang meng, Linus Walleij, Hongzhou Yang, linux-kernel,
	linux-gpio, linux-mediatek, Matthias Brugger,
	Yingjoe Chen (陳英洲),
	linux-arm-kernel, Linux Input

Adding dtor & linux-input as we are now discussing the elan trackpad driver...

On Mon, Sep 14, 2015 at 7:16 PM, Sudeep Holla <sudeep.holla@arm.com> wrote:
>
>
> On 12/09/15 10:50, maoguang meng wrote:
>> hi Sudeep:
>>
>> I test flowlling your blow suggestions,but the system can not be woken.
>>
>> beacuse,mtk_eint_suspend will mask it.As we know if eint wakeup system
>> it must be unmasked before enter suspend flow.
>>
>> e.x
>>
>> static int __maybe_unused elan_suspend(struct device *dev)
>> {
>>       struct i2c_client *client = to_i2c_client(dev);
>>       struct elan_tp_data *data = i2c_get_clientdata(client);
>>       int ret;
>>
>>       /*
>>        * We are taking the mutex to make sure sysfs operations are
>>        * complete before we attempt to bring the device into low[er]
>>        * power mode.
>>        */
>>       ret = mutex_lock_interruptible(&data->sysfs_mutex);
>>       if (ret)
>>               return ret;
>>
>>       disable_irq(client->irq);
>>
>>       if (device_may_wakeup(dev)) {
>>               ret = elan_sleep(data);
>>               /* Enable wake from IRQ */
>>               data->irq_wake = (enable_irq_wake(client->irq) == 0);
>
> This is wrong assumption in the driver. enable_irq_wake doesn't
> implicitly enable the IRQ. So the disable_irq should be moved to else.
> And the resume patch also needs to be fixed accordingly, otherwise you
> may get unbalanced irq. But this should not be the reason for fixing the
> pinctrl suspend/resume.
>
> Regards,
> Sudeep
>
> --->8
>
> diff --git a/drivers/input/mouse/elan_i2c_core.c
> b/drivers/input/mouse/elan_i2c_core.c
> index fa945304b9a5..7de26b04f45c 100644
> --- a/drivers/input/mouse/elan_i2c_core.c
> +++ b/drivers/input/mouse/elan_i2c_core.c
> @@ -1117,13 +1117,13 @@ static int __maybe_unused elan_suspend(struct
> device *dev)
>         if (ret)
>                 return ret;
>
> -       disable_irq(client->irq);
> -
>         if (device_may_wakeup(dev)) {
>                 ret = elan_sleep(data);
>                 /* Enable wake from IRQ */
>                 data->irq_wake = (enable_irq_wake(client->irq) == 0);
>         } else {
> +               disable_irq(client->irq);
> +
>                 ret = elan_disable_power(data);
>         }

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-09-14 11:16             ` Sudeep Holla
  2015-09-15  2:43               ` Daniel Kurtz
@ 2015-09-15  2:52               ` Dmitry Torokhov
  2015-09-15 17:48                 ` Sudeep Holla
  1 sibling, 1 reply; 19+ messages in thread
From: Dmitry Torokhov @ 2015-09-15  2:52 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: maoguang meng, Hongzhou Yang, Linus Walleij, linux-kernel,
	Daniel Kurtz, linux-gpio, linux-mediatek, Matthias Brugger,
	Yingjoe Chen (陳英洲),
	linux-arm-kernel

On Mon, Sep 14, 2015 at 4:16 AM, Sudeep Holla <sudeep.holla@arm.com> wrote:
>
>
> On 12/09/15 10:50, maoguang meng wrote:
>> hi Sudeep:
>>
>> I test flowlling your blow suggestions,but the system can not be woken.
>>
>> beacuse,mtk_eint_suspend will mask it.As we know if eint wakeup system
>> it must be unmasked before enter suspend flow.
>>
>> e.x
>>
>> static int __maybe_unused elan_suspend(struct device *dev)
>> {
>>       struct i2c_client *client = to_i2c_client(dev);
>>       struct elan_tp_data *data = i2c_get_clientdata(client);
>>       int ret;
>>
>>       /*
>>        * We are taking the mutex to make sure sysfs operations are
>>        * complete before we attempt to bring the device into low[er]
>>        * power mode.
>>        */
>>       ret = mutex_lock_interruptible(&data->sysfs_mutex);
>>       if (ret)
>>               return ret;
>>
>>       disable_irq(client->irq);
>>
>>       if (device_may_wakeup(dev)) {
>>               ret = elan_sleep(data);
>>               /* Enable wake from IRQ */
>>               data->irq_wake = (enable_irq_wake(client->irq) == 0);
>
> This is wrong assumption in the driver. enable_irq_wake doesn't
> implicitly enable the IRQ. So the disable_irq should be moved to else.
> And the resume patch also needs to be fixed accordingly, otherwise you
> may get unbalanced irq. But this should not be the reason for fixing the
> pinctrl suspend/resume.
>

Elan driver does not want to enable servicing IRQs, it just wants to
configure them as wakeup sources. Hence the current elan_suspend() is
fine. When system wakes up and the device is resumed and the driver is
ready to service interrupts it will enable IRQ again.

IOW enable_irq_wake() and enable_irq() are 2 completely different
calls and it is perfectly fine to disable IRQ and then ebale it as a
wakeup source.

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume
  2015-09-15  2:52               ` Dmitry Torokhov
@ 2015-09-15 17:48                 ` Sudeep Holla
  0 siblings, 0 replies; 19+ messages in thread
From: Sudeep Holla @ 2015-09-15 17:48 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Sudeep Holla, maoguang meng, Hongzhou Yang, Linus Walleij,
	linux-kernel, Daniel Kurtz, linux-gpio, linux-mediatek,
	Matthias Brugger, Yingjoe Chen (陳英洲),
	linux-arm-kernel



On 15/09/15 03:52, Dmitry Torokhov wrote:
> On Mon, Sep 14, 2015 at 4:16 AM, Sudeep Holla <sudeep.holla@arm.com> wrote:

[...]

>>
>> This is wrong assumption in the driver. enable_irq_wake doesn't
>> implicitly enable the IRQ. So the disable_irq should be moved to else.
>> And the resume patch also needs to be fixed accordingly, otherwise you
>> may get unbalanced irq. But this should not be the reason for fixing the
>> pinctrl suspend/resume.
>>
>
> Elan driver does not want to enable servicing IRQs, it just wants to
> configure them as wakeup sources. Hence the current elan_suspend() is
> fine. When system wakes up and the device is resumed and the driver is
> ready to service interrupts it will enable IRQ again.
>

Fair enough. But I am struggling to understand how this fits into
existing IRQ infrastructure. Few controllers that don't have wakeup
source configuration facility can set IRQCHIP_SKIP_SET_WAKE and just
leave the interrupts enabled in suspend path to wake it up. So IMO,
the above strategy might not work on such controllers.

> IOW enable_irq_wake() and enable_irq() are 2 completely different
> calls and it is perfectly fine to disable IRQ and then ebale it as a
> wakeup source.

I agree that they are entirely different APIs, I am not sure if we can
support different interrupt controller with such strategy.

Since the irq/pm core handle disabling device IRQs and section "System
Wakeup Interrupts, enable_irq_wake() and disable_irq_wake()" in
Documentation/power/suspend-and-interrupts.txt gives me different
understanding, we can check with tglx on how to handle this.

Regards,
Sudeep

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2015-09-15 17:48 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-14  8:38 [PATCH v4] pinctrl: mediatek: Implement wake handler and suspend resume maoguang.meng
2015-08-14  9:57 ` Daniel Kurtz
2015-08-17  7:52 ` Yingjoe Chen
2015-08-17  9:09   ` Daniel Kurtz
2015-08-17 13:25     ` Yingjoe Chen
2015-08-17 21:45       ` Hongzhou Yang
2015-08-24 16:27 ` Sudeep Holla
2015-09-02  6:02   ` Daniel Kurtz
2015-09-06 10:39     ` maoguang meng
2015-09-08  9:28       ` Sudeep Holla
2015-09-08 16:50         ` Sudeep Holla
2015-09-11 11:22           ` Chung-Yih Wang (王崇懿)
2015-09-11 12:43             ` Sudeep Holla
2015-09-12  9:50           ` maoguang meng
2015-09-14 11:16             ` Sudeep Holla
2015-09-15  2:43               ` Daniel Kurtz
2015-09-15  2:52               ` Dmitry Torokhov
2015-09-15 17:48                 ` Sudeep Holla
2015-08-26 12:41 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).