Re: [RESEND PATCH] dt-bindings: input: Add common keyboard document bindings

2018-07-04 Thread Chen Zhong
On Wed, 2018-07-04 at 15:25 +, Dmitry Torokhov wrote:
> On Fri, Jun 22, 2018 at 02:39:55PM +0800, Chen Zhong wrote:
> > Hi Dmitry,
> > 
> > The other patches in the series to add mediatek pmic keys support are
> > now available in 4.18-rc1, but this patch seems not being merged.
> > 
> >   git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git
> > ib-mfd-input-rtc-v4.18
> > 
> > I have resend the patch, and rebase to 4.18-rc1.
> > Could you help to see if it is good enough to be merged into your tree?
> 
> I thought Rob would pick it up, but since he hasn't I'll do it.
> 
> Thanks.
> 

That would be great helpful.
Thank you.



Re: [RESEND PATCH] dt-bindings: input: Add common keyboard document bindings

2018-07-04 Thread Chen Zhong
On Wed, 2018-07-04 at 15:25 +, Dmitry Torokhov wrote:
> On Fri, Jun 22, 2018 at 02:39:55PM +0800, Chen Zhong wrote:
> > Hi Dmitry,
> > 
> > The other patches in the series to add mediatek pmic keys support are
> > now available in 4.18-rc1, but this patch seems not being merged.
> > 
> >   git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git
> > ib-mfd-input-rtc-v4.18
> > 
> > I have resend the patch, and rebase to 4.18-rc1.
> > Could you help to see if it is good enough to be merged into your tree?
> 
> I thought Rob would pick it up, but since he hasn't I'll do it.
> 
> Thanks.
> 

That would be great helpful.
Thank you.



Re: [RESEND PATCH] dt-bindings: input: Add common keyboard document bindings

2018-06-22 Thread Chen Zhong
Hi Dmitry,

The other patches in the series to add mediatek pmic keys support are
now available in 4.18-rc1, but this patch seems not being merged.

  git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git
ib-mfd-input-rtc-v4.18

I have resend the patch, and rebase to 4.18-rc1.
Could you help to see if it is good enough to be merged into your tree?

Thank you.


On Fri, 2018-06-22 at 14:16 +0800, Chen Zhong wrote:
> This patch adds the device tree binding documentation for common
> keyboard.
> 
> Acked-by: Rob Herring 
> Acked-by: Dmitry Torokhov 
> Signed-off-by: Chen Zhong 
> ---
>  Documentation/devicetree/bindings/input/keys.txt | 8 
>  1 file changed, 8 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/input/keys.txt
> 
> diff --git a/Documentation/devicetree/bindings/input/keys.txt 
> b/Documentation/devicetree/bindings/input/keys.txt
> new file mode 100644
> index 000..a0ea7eb
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/input/keys.txt
> @@ -0,0 +1,8 @@
> +General Keys Properties:
> +
> +Optional properties for Keys:
> +- power-off-time-sec: Duration in seconds which the key should be kept
> + pressed for device to power off automatically. Device with key pressed
> + shutdown feature can specify this property.
> +- linux,keycodes: Specifies the numeric keycode values to be used for
> + reporting key presses.
> \ No newline at end of file




Re: [RESEND PATCH] dt-bindings: input: Add common keyboard document bindings

2018-06-22 Thread Chen Zhong
Hi Dmitry,

The other patches in the series to add mediatek pmic keys support are
now available in 4.18-rc1, but this patch seems not being merged.

  git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git
ib-mfd-input-rtc-v4.18

I have resend the patch, and rebase to 4.18-rc1.
Could you help to see if it is good enough to be merged into your tree?

Thank you.


On Fri, 2018-06-22 at 14:16 +0800, Chen Zhong wrote:
> This patch adds the device tree binding documentation for common
> keyboard.
> 
> Acked-by: Rob Herring 
> Acked-by: Dmitry Torokhov 
> Signed-off-by: Chen Zhong 
> ---
>  Documentation/devicetree/bindings/input/keys.txt | 8 
>  1 file changed, 8 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/input/keys.txt
> 
> diff --git a/Documentation/devicetree/bindings/input/keys.txt 
> b/Documentation/devicetree/bindings/input/keys.txt
> new file mode 100644
> index 000..a0ea7eb
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/input/keys.txt
> @@ -0,0 +1,8 @@
> +General Keys Properties:
> +
> +Optional properties for Keys:
> +- power-off-time-sec: Duration in seconds which the key should be kept
> + pressed for device to power off automatically. Device with key pressed
> + shutdown feature can specify this property.
> +- linux,keycodes: Specifies the numeric keycode values to be used for
> + reporting key presses.
> \ No newline at end of file




[RESEND PATCH] dt-bindings: input: Add common keyboard document bindings

2018-06-22 Thread Chen Zhong
This patch adds the device tree binding documentation for common
keyboard.

Acked-by: Rob Herring 
Acked-by: Dmitry Torokhov 
Signed-off-by: Chen Zhong 
---
 Documentation/devicetree/bindings/input/keys.txt | 8 
 1 file changed, 8 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/keys.txt

diff --git a/Documentation/devicetree/bindings/input/keys.txt 
b/Documentation/devicetree/bindings/input/keys.txt
new file mode 100644
index 000..a0ea7eb
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/keys.txt
@@ -0,0 +1,8 @@
+General Keys Properties:
+
+Optional properties for Keys:
+- power-off-time-sec: Duration in seconds which the key should be kept
+   pressed for device to power off automatically. Device with key pressed
+   shutdown feature can specify this property.
+- linux,keycodes: Specifies the numeric keycode values to be used for
+   reporting key presses.
\ No newline at end of file
-- 
1.8.1.1.dirty



[RESEND PATCH] dt-bindings: input: Add common keyboard document bindings

2018-06-22 Thread Chen Zhong
This patch adds the device tree binding documentation for common
keyboard.

Acked-by: Rob Herring 
Acked-by: Dmitry Torokhov 
Signed-off-by: Chen Zhong 
---
 Documentation/devicetree/bindings/input/keys.txt | 8 
 1 file changed, 8 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/keys.txt

diff --git a/Documentation/devicetree/bindings/input/keys.txt 
b/Documentation/devicetree/bindings/input/keys.txt
new file mode 100644
index 000..a0ea7eb
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/keys.txt
@@ -0,0 +1,8 @@
+General Keys Properties:
+
+Optional properties for Keys:
+- power-off-time-sec: Duration in seconds which the key should be kept
+   pressed for device to power off automatically. Device with key pressed
+   shutdown feature can specify this property.
+- linux,keycodes: Specifies the numeric keycode values to be used for
+   reporting key presses.
\ No newline at end of file
-- 
1.8.1.1.dirty



Re: [GIT PULL] Immutable branch between MFD, Input and RTC due for the v4.18 merge window

2018-04-26 Thread Chen Zhong
On Mon, 2018-04-16 at 15:18 +0100, Lee Jones wrote:
> Enjoy!
> 
> The following changes since commit 60cc43fc888428bb2f18f08997432d426a243338:
> 
>   Linux 4.17-rc1 (2018-04-15 18:24:20 -0700)
> 
> are available in the git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git 
> ib-mfd-input-rtc-v4.18
> 
> for you to fetch changes up to 55d1d1547ab5e52269988af5e7c553796ff68e97:
> 
>   mfd: mt6397: Add PMIC keys support to MT6397 driver (2018-04-16 15:16:11 
> +0100)
> 
> 
> Immutable branch between MFD, Input and RTC due for the v4.18 merge window
> 
> --------
> Chen Zhong (5):
>   mfd: mt6397: Create irq mappings in mfd core driver
>   dt-bindings: input: Add document bindings for mtk-pmic-keys
>   dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
>   input: Add MediaTek PMIC keys support
>   mfd: mt6397: Add PMIC keys support to MT6397 driver
> 
>  .../devicetree/bindings/input/mtk-pmic-keys.txt|  43 +++
>  Documentation/devicetree/bindings/mfd/mt6397.txt   |   6 +
>  drivers/input/keyboard/Kconfig |   9 +
>  drivers/input/keyboard/Makefile|   1 +
>  drivers/input/keyboard/mtk-pmic-keys.c | 339 
> +
>  drivers/mfd/mt6397-core.c  |  26 +-
>  drivers/rtc/rtc-mt6397.c   |   7 +-
>  7 files changed, 424 insertions(+), 7 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
>  create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
> 

Hi Lee,

I’m sorry that I found this patch
https://patchwork.kernel.org/patch/10026705/

is missing in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git
ib-mfd-input-rtc-v4.18

Could you please take this patch up?

Thanks.

Best regards,
Chen Zhong




Re: [GIT PULL] Immutable branch between MFD, Input and RTC due for the v4.18 merge window

2018-04-26 Thread Chen Zhong
On Mon, 2018-04-16 at 15:18 +0100, Lee Jones wrote:
> Enjoy!
> 
> The following changes since commit 60cc43fc888428bb2f18f08997432d426a243338:
> 
>   Linux 4.17-rc1 (2018-04-15 18:24:20 -0700)
> 
> are available in the git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git 
> ib-mfd-input-rtc-v4.18
> 
> for you to fetch changes up to 55d1d1547ab5e52269988af5e7c553796ff68e97:
> 
>   mfd: mt6397: Add PMIC keys support to MT6397 driver (2018-04-16 15:16:11 
> +0100)
> 
> 
> Immutable branch between MFD, Input and RTC due for the v4.18 merge window
> 
> --------
> Chen Zhong (5):
>   mfd: mt6397: Create irq mappings in mfd core driver
>   dt-bindings: input: Add document bindings for mtk-pmic-keys
>   dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
>   input: Add MediaTek PMIC keys support
>   mfd: mt6397: Add PMIC keys support to MT6397 driver
> 
>  .../devicetree/bindings/input/mtk-pmic-keys.txt|  43 +++
>  Documentation/devicetree/bindings/mfd/mt6397.txt   |   6 +
>  drivers/input/keyboard/Kconfig |   9 +
>  drivers/input/keyboard/Makefile|   1 +
>  drivers/input/keyboard/mtk-pmic-keys.c | 339 
> +
>  drivers/mfd/mt6397-core.c  |  26 +-
>  drivers/rtc/rtc-mt6397.c   |   7 +-
>  7 files changed, 424 insertions(+), 7 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
>  create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
> 

Hi Lee,

I’m sorry that I found this patch
https://patchwork.kernel.org/patch/10026705/

is missing in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git
ib-mfd-input-rtc-v4.18

Could you please take this patch up?

Thanks.

Best regards,
Chen Zhong




Re: [PATCH v6 0/6] Add MediaTek PMIC keys support

2018-04-09 Thread Chen Zhong
On Thu, 2018-03-29 at 09:15 -0700, Dmitry Torokhov wrote:
> 
> 
> Oh, sorry, I did not realize you wanted my Ack for bindings. I usually
> leave it to Rob and simply ack the driver itself when I am happy with
> the code.
> 
> I'll go and add my ack to the binding post if that will help merging
> the series.
> 
> Thanks. 

Hi Lee,

May I know if I need to collect Dmitry's comments and send a new version
for the merging?

Thank you.



Re: [PATCH v6 0/6] Add MediaTek PMIC keys support

2018-04-09 Thread Chen Zhong
On Thu, 2018-03-29 at 09:15 -0700, Dmitry Torokhov wrote:
> 
> 
> Oh, sorry, I did not realize you wanted my Ack for bindings. I usually
> leave it to Rob and simply ack the driver itself when I am happy with
> the code.
> 
> I'll go and add my ack to the binding post if that will help merging
> the series.
> 
> Thanks. 

Hi Lee,

May I know if I need to collect Dmitry's comments and send a new version
for the merging?

Thank you.



Re: [PATCH v6 0/6] Add MediaTek PMIC keys support

2018-03-28 Thread Chen Zhong
On Wed, 2018-03-28 at 11:26 +0100, Lee Jones wrote:
> On Tue, 27 Mar 2018, Matthias Brugger wrote:
> 
> > 
> > 
> > On 03/27/2018 10:05 AM, Lee Jones wrote:
> > > On Fri, 23 Mar 2018, Dmitry Torokhov wrote:
> > >> On Thu, Mar 22, 2018 at 10:17:53AM +0800, Sean Wang wrote:
> > >>> Hi, Dmitry and Lee
> > >>>
> > >>> The series seems not being got merged. Are they good enough to be ready
> > >>> into the your tree?
> > >>>
> > >>> Recently I've tested the series with focusing on pwrkey event generated
> > >>> through interrupt when push and release the key on bpi-r2 board and then
> > >>> finally it's working fine. but for homekey it cannot be found on the
> > >>> board and thus I cannot have more tests more about it.
> > >>>
> > >>> Tested-by: Sean Wang 
> > >>
> > >> You have my Ack on the input patch; I expect it go through Lee's tree as
> > >> there are some dependencies on mfd core piece.
> > > 
> > > Are you happy for me to merge the Input dt-bindings without your Ack?
> > > 
> > 
> > They got both Acked in v5, but the commit message was not updated:
> > https://patchwork.kernel.org/patch/9973721/
> > https://patchwork.kernel.org/patch/9973723/
> 
> Thanks Matthias.
> 
> Chen, can you collect all the Acks and repost as a RESEND please?
> 

Thanks Matthias, Lee, Dmitry and Sean for your comments.

Hi Lee,

I have collected the Acks by Rob and sent the v6:
https://patchwork.kernel.org/patch/10026705
https://patchwork.kernel.org/patch/10026707

Are they enough to be merged?

Thank you.




Re: [PATCH v6 0/6] Add MediaTek PMIC keys support

2018-03-28 Thread Chen Zhong
On Wed, 2018-03-28 at 11:26 +0100, Lee Jones wrote:
> On Tue, 27 Mar 2018, Matthias Brugger wrote:
> 
> > 
> > 
> > On 03/27/2018 10:05 AM, Lee Jones wrote:
> > > On Fri, 23 Mar 2018, Dmitry Torokhov wrote:
> > >> On Thu, Mar 22, 2018 at 10:17:53AM +0800, Sean Wang wrote:
> > >>> Hi, Dmitry and Lee
> > >>>
> > >>> The series seems not being got merged. Are they good enough to be ready
> > >>> into the your tree?
> > >>>
> > >>> Recently I've tested the series with focusing on pwrkey event generated
> > >>> through interrupt when push and release the key on bpi-r2 board and then
> > >>> finally it's working fine. but for homekey it cannot be found on the
> > >>> board and thus I cannot have more tests more about it.
> > >>>
> > >>> Tested-by: Sean Wang 
> > >>
> > >> You have my Ack on the input patch; I expect it go through Lee's tree as
> > >> there are some dependencies on mfd core piece.
> > > 
> > > Are you happy for me to merge the Input dt-bindings without your Ack?
> > > 
> > 
> > They got both Acked in v5, but the commit message was not updated:
> > https://patchwork.kernel.org/patch/9973721/
> > https://patchwork.kernel.org/patch/9973723/
> 
> Thanks Matthias.
> 
> Chen, can you collect all the Acks and repost as a RESEND please?
> 

Thanks Matthias, Lee, Dmitry and Sean for your comments.

Hi Lee,

I have collected the Acks by Rob and sent the v6:
https://patchwork.kernel.org/patch/10026705
https://patchwork.kernel.org/patch/10026707

Are they enough to be merged?

Thank you.




[PATCH v6 0/6] Add MediaTek PMIC keys support

2017-10-25 Thread Chen Zhong
MediaTek PMIC are multi-function devices that can handle key interrupts, 
typically there are two keys attached to PMIC, which called pwrkey and homekey. 
PWRKEY usually used to wake up system from sleep. Homekey can used as volume 
down key due to board design. Long press keys can shutdown PMIC, the mode can 
be choose to be one key only or two keys together.
This series add support for key functions for MediaTek PMIC MT6397/MT6323.

Changes since v5:
- use __maybe_unused annotation instead of #ifdef guard
- use of_* API instead of device_* API

Changes since v4:
- rebase to Linux 4.14-rc1
- add a common keyboard binding document
- use child device tree node to define each key

Changes since v3:
- make the naming to be consistent as mtk_pmic or MTK_PMIC
- add suspend/resume functions to enable/disable irq
- change binding properties to define wakeup sources

Changes since v2:
- use standard properties for keycodes and debounce time
- change to use platform_get_irq in leaf drivers
- use better ways to define IRQ resources

Changes since v1:
- create irq mappings in mfd core driver instead of leaf drivers
- remove some unused parts in mtk-pmic-keys driver

Chen Zhong (6):
  mfd: mt6397: create irq mappings in mfd core driver
  dt-bindings: input: Add common keyboard document bindings
  dt-bindings: input: Add document bindings for mtk-pmic-keys
  dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
  input: Add MediaTek PMIC keys support
  mfd: mt6397: Add PMIC keys support to MT6397 driver

 Documentation/devicetree/bindings/input/keys.txt   |   8 +
 .../devicetree/bindings/input/mtk-pmic-keys.txt|  43 +++
 Documentation/devicetree/bindings/mfd/mt6397.txt   |   6 +
 drivers/input/keyboard/Kconfig |   9 +
 drivers/input/keyboard/Makefile|   1 +
 drivers/input/keyboard/mtk-pmic-keys.c | 339 +
 drivers/mfd/mt6397-core.c  |  26 +-
 drivers/rtc/rtc-mt6397.c   |   7 +-
 8 files changed, 432 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/keys.txt
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

-- 
1.9.1




[PATCH v6 0/6] Add MediaTek PMIC keys support

2017-10-25 Thread Chen Zhong
MediaTek PMIC are multi-function devices that can handle key interrupts, 
typically there are two keys attached to PMIC, which called pwrkey and homekey. 
PWRKEY usually used to wake up system from sleep. Homekey can used as volume 
down key due to board design. Long press keys can shutdown PMIC, the mode can 
be choose to be one key only or two keys together.
This series add support for key functions for MediaTek PMIC MT6397/MT6323.

Changes since v5:
- use __maybe_unused annotation instead of #ifdef guard
- use of_* API instead of device_* API

Changes since v4:
- rebase to Linux 4.14-rc1
- add a common keyboard binding document
- use child device tree node to define each key

Changes since v3:
- make the naming to be consistent as mtk_pmic or MTK_PMIC
- add suspend/resume functions to enable/disable irq
- change binding properties to define wakeup sources

Changes since v2:
- use standard properties for keycodes and debounce time
- change to use platform_get_irq in leaf drivers
- use better ways to define IRQ resources

Changes since v1:
- create irq mappings in mfd core driver instead of leaf drivers
- remove some unused parts in mtk-pmic-keys driver

Chen Zhong (6):
  mfd: mt6397: create irq mappings in mfd core driver
  dt-bindings: input: Add common keyboard document bindings
  dt-bindings: input: Add document bindings for mtk-pmic-keys
  dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
  input: Add MediaTek PMIC keys support
  mfd: mt6397: Add PMIC keys support to MT6397 driver

 Documentation/devicetree/bindings/input/keys.txt   |   8 +
 .../devicetree/bindings/input/mtk-pmic-keys.txt|  43 +++
 Documentation/devicetree/bindings/mfd/mt6397.txt   |   6 +
 drivers/input/keyboard/Kconfig |   9 +
 drivers/input/keyboard/Makefile|   1 +
 drivers/input/keyboard/mtk-pmic-keys.c | 339 +
 drivers/mfd/mt6397-core.c  |  26 +-
 drivers/rtc/rtc-mt6397.c   |   7 +-
 8 files changed, 432 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/keys.txt
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

-- 
1.9.1




[PATCH v6 1/6] mfd: mt6397: create irq mappings in mfd core driver

2017-10-25 Thread Chen Zhong
The core driver should create and manage irq mappings instead of
leaf drivers. This patch change to pass irq domain to
devm_mfd_add_devices() and it will create mapping for irq resources
automatically. And remove irq mapping in rtc driver since this has
been done in core driver.

Acked-for-MFD-by: Lee Jones <lee.jo...@linaro.org>
Acked-by: Alexandre Belloni <alexandre.bell...@free-electrons.com>
Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 drivers/mfd/mt6397-core.c |4 ++--
 drivers/rtc/rtc-mt6397.c  |7 +++
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 04a601f..6546d7f 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6323_devs,
   ARRAY_SIZE(mt6323_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
case MT6397_CID_CODE:
@@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6397_devs,
   ARRAY_SIZE(mt6397_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
default:
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 1a61fa5..385f830 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -322,10 +322,9 @@ static int mtk_rtc_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
rtc->addr_base = res->start;
 
-   res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
-   if (rtc->irq <= 0)
-   return -EINVAL;
+   rtc->irq = platform_get_irq(pdev, 0);
+   if (rtc->irq < 0)
+   return rtc->irq;
 
rtc->regmap = mt6397_chip->regmap;
rtc->dev = >dev;
-- 
1.7.9.5



[PATCH v6 1/6] mfd: mt6397: create irq mappings in mfd core driver

2017-10-25 Thread Chen Zhong
The core driver should create and manage irq mappings instead of
leaf drivers. This patch change to pass irq domain to
devm_mfd_add_devices() and it will create mapping for irq resources
automatically. And remove irq mapping in rtc driver since this has
been done in core driver.

Acked-for-MFD-by: Lee Jones 
Acked-by: Alexandre Belloni 
Signed-off-by: Chen Zhong 
---
 drivers/mfd/mt6397-core.c |4 ++--
 drivers/rtc/rtc-mt6397.c  |7 +++
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 04a601f..6546d7f 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6323_devs,
   ARRAY_SIZE(mt6323_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
case MT6397_CID_CODE:
@@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6397_devs,
   ARRAY_SIZE(mt6397_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
default:
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 1a61fa5..385f830 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -322,10 +322,9 @@ static int mtk_rtc_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
rtc->addr_base = res->start;
 
-   res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
-   if (rtc->irq <= 0)
-   return -EINVAL;
+   rtc->irq = platform_get_irq(pdev, 0);
+   if (rtc->irq < 0)
+   return rtc->irq;
 
rtc->regmap = mt6397_chip->regmap;
rtc->dev = >dev;
-- 
1.7.9.5



[PATCH v6 2/6] dt-bindings: input: Add common keyboard document bindings

2017-10-25 Thread Chen Zhong
This patch adds the device tree binding documentation for common
keyboard.

Acked-by: Rob Herring <r...@kernel.org>
Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 Documentation/devicetree/bindings/input/keys.txt |8 
 1 file changed, 8 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/keys.txt

diff --git a/Documentation/devicetree/bindings/input/keys.txt 
b/Documentation/devicetree/bindings/input/keys.txt
new file mode 100644
index 000..a0ea7eb
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/keys.txt
@@ -0,0 +1,8 @@
+General Keys Properties:
+
+Optional properties for Keys:
+- power-off-time-sec: Duration in seconds which the key should be kept
+   pressed for device to power off automatically. Device with key pressed
+   shutdown feature can specify this property.
+- linux,keycodes: Specifies the numeric keycode values to be used for
+   reporting key presses.
\ No newline at end of file
-- 
1.7.9.5



[PATCH v6 2/6] dt-bindings: input: Add common keyboard document bindings

2017-10-25 Thread Chen Zhong
This patch adds the device tree binding documentation for common
keyboard.

Acked-by: Rob Herring 
Signed-off-by: Chen Zhong 
---
 Documentation/devicetree/bindings/input/keys.txt |8 
 1 file changed, 8 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/keys.txt

diff --git a/Documentation/devicetree/bindings/input/keys.txt 
b/Documentation/devicetree/bindings/input/keys.txt
new file mode 100644
index 000..a0ea7eb
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/keys.txt
@@ -0,0 +1,8 @@
+General Keys Properties:
+
+Optional properties for Keys:
+- power-off-time-sec: Duration in seconds which the key should be kept
+   pressed for device to power off automatically. Device with key pressed
+   shutdown feature can specify this property.
+- linux,keycodes: Specifies the numeric keycode values to be used for
+   reporting key presses.
\ No newline at end of file
-- 
1.7.9.5



[PATCH v6 6/6] mfd: mt6397: Add PMIC keys support to MT6397 driver

2017-10-25 Thread Chen Zhong
This patch adds compatible strings and interrupts for pmic keys
which serves as child device of MFD.

Acked-for-MFD-by: Lee Jones <lee.jo...@linaro.org>
Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 drivers/mfd/mt6397-core.c |   22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 6546d7f..77b64bd 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -43,6 +43,16 @@
},
 };
 
+static const struct resource mt6323_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_PWRKEY),
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_FCHRKEY),
+};
+
+static const struct resource mt6397_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6397_IRQ_PWRKEY),
+   DEFINE_RES_IRQ(MT6397_IRQ_HOMEKEY),
+};
+
 static const struct mfd_cell mt6323_devs[] = {
{
.name = "mt6323-regulator",
@@ -50,6 +60,11 @@
}, {
.name = "mt6323-led",
.of_compatible = "mediatek,mt6323-led"
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6323_keys_resources),
+   .resources = mt6323_keys_resources,
+   .of_compatible = "mediatek,mt6323-keys"
},
 };
 
@@ -71,7 +86,12 @@
}, {
.name = "mt6397-pinctrl",
.of_compatible = "mediatek,mt6397-pinctrl",
-   },
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6397_keys_resources),
+   .resources = mt6397_keys_resources,
+   .of_compatible = "mediatek,mt6397-keys"
+   }
 };
 
 static void mt6397_irq_lock(struct irq_data *data)
-- 
1.7.9.5



[PATCH v6 6/6] mfd: mt6397: Add PMIC keys support to MT6397 driver

2017-10-25 Thread Chen Zhong
This patch adds compatible strings and interrupts for pmic keys
which serves as child device of MFD.

Acked-for-MFD-by: Lee Jones 
Signed-off-by: Chen Zhong 
---
 drivers/mfd/mt6397-core.c |   22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 6546d7f..77b64bd 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -43,6 +43,16 @@
},
 };
 
+static const struct resource mt6323_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_PWRKEY),
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_FCHRKEY),
+};
+
+static const struct resource mt6397_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6397_IRQ_PWRKEY),
+   DEFINE_RES_IRQ(MT6397_IRQ_HOMEKEY),
+};
+
 static const struct mfd_cell mt6323_devs[] = {
{
.name = "mt6323-regulator",
@@ -50,6 +60,11 @@
}, {
.name = "mt6323-led",
.of_compatible = "mediatek,mt6323-led"
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6323_keys_resources),
+   .resources = mt6323_keys_resources,
+   .of_compatible = "mediatek,mt6323-keys"
},
 };
 
@@ -71,7 +86,12 @@
}, {
.name = "mt6397-pinctrl",
.of_compatible = "mediatek,mt6397-pinctrl",
-   },
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6397_keys_resources),
+   .resources = mt6397_keys_resources,
+   .of_compatible = "mediatek,mt6397-keys"
+   }
 };
 
 static void mt6397_irq_lock(struct irq_data *data)
-- 
1.7.9.5



[PATCH v6 3/6] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-10-25 Thread Chen Zhong
This patch adds the device tree binding documentation for the MediaTek
pmic keys found on PMIC MT6397/MT6323.

Acked-by: Rob Herring <r...@kernel.org>
Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 .../devicetree/bindings/input/mtk-pmic-keys.txt|   43 
 1 file changed, 43 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt

diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
new file mode 100644
index 000..2888d07
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
@@ -0,0 +1,43 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: See Documentation/devicetree/bindings/input/keys.txt
+
+Optional Properties:
+- wakeup-source: See Documentation/devicetree/bindings/power/wakeup-source.txt
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- power-off-time-sec: See Documentation/devicetree/bindings/input/keys.txt
+
+Example:
+
+   pmic: mt6397 {
+   compatible = "mediatek,mt6397";
+
+   ...
+
+   mt6397keys: mt6397keys {
+   compatible = "mediatek,mt6397-keys";
+   mediatek,long-press-mode = <1>;
+   power-off-time-sec = <0>;
+
+   power {
+   linux,keycodes = <116>;
+   wakeup-source;
+   };
+
+   home {
+   linux,keycodes = <114>;
+   };
+   };
+
+   };
-- 
1.7.9.5



[PATCH v6 3/6] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-10-25 Thread Chen Zhong
This patch adds the device tree binding documentation for the MediaTek
pmic keys found on PMIC MT6397/MT6323.

Acked-by: Rob Herring 
Signed-off-by: Chen Zhong 
---
 .../devicetree/bindings/input/mtk-pmic-keys.txt|   43 
 1 file changed, 43 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt

diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
new file mode 100644
index 000..2888d07
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
@@ -0,0 +1,43 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: See Documentation/devicetree/bindings/input/keys.txt
+
+Optional Properties:
+- wakeup-source: See Documentation/devicetree/bindings/power/wakeup-source.txt
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- power-off-time-sec: See Documentation/devicetree/bindings/input/keys.txt
+
+Example:
+
+   pmic: mt6397 {
+   compatible = "mediatek,mt6397";
+
+   ...
+
+   mt6397keys: mt6397keys {
+   compatible = "mediatek,mt6397-keys";
+   mediatek,long-press-mode = <1>;
+   power-off-time-sec = <0>;
+
+   power {
+   linux,keycodes = <116>;
+   wakeup-source;
+   };
+
+   home {
+   linux,keycodes = <114>;
+   };
+   };
+
+   };
-- 
1.7.9.5



[PATCH v6 5/6] input: Add MediaTek PMIC keys support

2017-10-25 Thread Chen Zhong
This patch add support to handle MediaTek PMIC MT6397/MT6323 key
interrupts including pwrkey and homekey, also add setting for
long press key shutdown behavior.

Acked-by: Dmitry Torokhov <dmitry.torok...@gmail.com>
Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 drivers/input/keyboard/Kconfig |9 +
 drivers/input/keyboard/Makefile|1 +
 drivers/input/keyboard/mtk-pmic-keys.c |  339 
 3 files changed, 349 insertions(+)
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 4c4ab1c..bd4e20a 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -756,4 +756,13 @@ config KEYBOARD_BCM
  To compile this driver as a module, choose M here: the
  module will be called bcm-keypad.
 
+config KEYBOARD_MTK_PMIC
+   tristate "MediaTek PMIC keys support"
+   depends on MFD_MT6397
+   help
+ Say Y here if you want to use the pmic keys (powerkey/homekey).
+
+ To compile this driver as a module, choose M here: the
+ module will be called pmic-keys.
+
 endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index d2338ba..20c0b98 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
 obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
 obj-$(CONFIG_KEYBOARD_MPR121)  += mpr121_touchkey.o
+obj-$(CONFIG_KEYBOARD_MTK_PMIC)+= mtk-pmic-keys.o
 obj-$(CONFIG_KEYBOARD_NEWTON)  += newtonkbd.o
 obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
 obj-$(CONFIG_KEYBOARD_NSPIRE)  += nspire-keypad.o
diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
b/drivers/input/keyboard/mtk-pmic-keys.c
new file mode 100644
index 000..02c67a1
--- /dev/null
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -0,0 +1,339 @@
+/*
+ * Copyright (C) 2017 MediaTek, Inc.
+ *
+ * Author: Chen Zhong <chen.zh...@mediatek.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MTK_PMIC_PWRKEY_RST_EN_MASK0x1
+#define MTK_PMIC_PWRKEY_RST_EN_SHIFT   6
+#define MTK_PMIC_HOMEKEY_RST_EN_MASK   0x1
+#define MTK_PMIC_HOMEKEY_RST_EN_SHIFT  5
+#define MTK_PMIC_RST_DU_MASK   0x3
+#define MTK_PMIC_RST_DU_SHIFT  8
+
+#define MTK_PMIC_PWRKEY_RST\
+   (MTK_PMIC_PWRKEY_RST_EN_MASK << MTK_PMIC_PWRKEY_RST_EN_SHIFT)
+#define MTK_PMIC_HOMEKEY_RST   \
+   (MTK_PMIC_HOMEKEY_RST_EN_MASK << MTK_PMIC_HOMEKEY_RST_EN_SHIFT)
+
+#define MTK_PMIC_PWRKEY_INDEX  0
+#define MTK_PMIC_HOMEKEY_INDEX 1
+#define MTK_PMIC_MAX_KEY_COUNT 2
+
+struct mtk_pmic_keys_regs {
+   u32 deb_reg;
+   u32 deb_mask;
+   u32 intsel_reg;
+   u32 intsel_mask;
+};
+
+#define MTK_PMIC_KEYS_REGS(_deb_reg, _deb_mask,\
+   _intsel_reg, _intsel_mask)  \
+{  \
+   .deb_reg= _deb_reg, \
+   .deb_mask   = _deb_mask,\
+   .intsel_reg = _intsel_reg,  \
+   .intsel_mask= _intsel_mask, \
+}
+
+struct mtk_pmic_regs {
+   const struct mtk_pmic_keys_regs keys_regs[MTK_PMIC_MAX_KEY_COUNT];
+   u32 pmic_rst_reg;
+};
+
+static const struct mtk_pmic_regs mt6397_regs = {
+   .keys_regs[MTK_PMIC_PWRKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6397_CHRSTATUS,
+   0x8, MT6397_INT_RSV, 0x10),
+   .keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6397_OCSTATUS2,
+   0x10, MT6397_INT_RSV, 0x8),
+   .pmic_rst_reg = MT6397_TOP_RST_MISC,
+};
+
+static const struct mtk_pmic_regs mt6323_regs = {
+   .keys_regs[MTK_PMIC_PWRKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x2, MT6323_INT_MISC_CON, 0x10),
+   .keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x4, MT6323_INT_MISC_CON, 0x8),
+   .pmic_rst_reg = MT6323_TOP_RST_MISC,
+};
+
+struct mtk_pmic_keys_info {
+   struct mtk_pmic_keys *keys;
+   const struct mtk_pmic_keys_regs *regs;
+

[PATCH v6 5/6] input: Add MediaTek PMIC keys support

2017-10-25 Thread Chen Zhong
This patch add support to handle MediaTek PMIC MT6397/MT6323 key
interrupts including pwrkey and homekey, also add setting for
long press key shutdown behavior.

Acked-by: Dmitry Torokhov 
Signed-off-by: Chen Zhong 
---
 drivers/input/keyboard/Kconfig |9 +
 drivers/input/keyboard/Makefile|1 +
 drivers/input/keyboard/mtk-pmic-keys.c |  339 
 3 files changed, 349 insertions(+)
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 4c4ab1c..bd4e20a 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -756,4 +756,13 @@ config KEYBOARD_BCM
  To compile this driver as a module, choose M here: the
  module will be called bcm-keypad.
 
+config KEYBOARD_MTK_PMIC
+   tristate "MediaTek PMIC keys support"
+   depends on MFD_MT6397
+   help
+ Say Y here if you want to use the pmic keys (powerkey/homekey).
+
+ To compile this driver as a module, choose M here: the
+ module will be called pmic-keys.
+
 endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index d2338ba..20c0b98 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
 obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
 obj-$(CONFIG_KEYBOARD_MPR121)  += mpr121_touchkey.o
+obj-$(CONFIG_KEYBOARD_MTK_PMIC)+= mtk-pmic-keys.o
 obj-$(CONFIG_KEYBOARD_NEWTON)  += newtonkbd.o
 obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
 obj-$(CONFIG_KEYBOARD_NSPIRE)  += nspire-keypad.o
diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
b/drivers/input/keyboard/mtk-pmic-keys.c
new file mode 100644
index 000..02c67a1
--- /dev/null
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -0,0 +1,339 @@
+/*
+ * Copyright (C) 2017 MediaTek, Inc.
+ *
+ * Author: Chen Zhong 
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MTK_PMIC_PWRKEY_RST_EN_MASK0x1
+#define MTK_PMIC_PWRKEY_RST_EN_SHIFT   6
+#define MTK_PMIC_HOMEKEY_RST_EN_MASK   0x1
+#define MTK_PMIC_HOMEKEY_RST_EN_SHIFT  5
+#define MTK_PMIC_RST_DU_MASK   0x3
+#define MTK_PMIC_RST_DU_SHIFT  8
+
+#define MTK_PMIC_PWRKEY_RST\
+   (MTK_PMIC_PWRKEY_RST_EN_MASK << MTK_PMIC_PWRKEY_RST_EN_SHIFT)
+#define MTK_PMIC_HOMEKEY_RST   \
+   (MTK_PMIC_HOMEKEY_RST_EN_MASK << MTK_PMIC_HOMEKEY_RST_EN_SHIFT)
+
+#define MTK_PMIC_PWRKEY_INDEX  0
+#define MTK_PMIC_HOMEKEY_INDEX 1
+#define MTK_PMIC_MAX_KEY_COUNT 2
+
+struct mtk_pmic_keys_regs {
+   u32 deb_reg;
+   u32 deb_mask;
+   u32 intsel_reg;
+   u32 intsel_mask;
+};
+
+#define MTK_PMIC_KEYS_REGS(_deb_reg, _deb_mask,\
+   _intsel_reg, _intsel_mask)  \
+{  \
+   .deb_reg= _deb_reg, \
+   .deb_mask   = _deb_mask,\
+   .intsel_reg = _intsel_reg,  \
+   .intsel_mask= _intsel_mask, \
+}
+
+struct mtk_pmic_regs {
+   const struct mtk_pmic_keys_regs keys_regs[MTK_PMIC_MAX_KEY_COUNT];
+   u32 pmic_rst_reg;
+};
+
+static const struct mtk_pmic_regs mt6397_regs = {
+   .keys_regs[MTK_PMIC_PWRKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6397_CHRSTATUS,
+   0x8, MT6397_INT_RSV, 0x10),
+   .keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6397_OCSTATUS2,
+   0x10, MT6397_INT_RSV, 0x8),
+   .pmic_rst_reg = MT6397_TOP_RST_MISC,
+};
+
+static const struct mtk_pmic_regs mt6323_regs = {
+   .keys_regs[MTK_PMIC_PWRKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x2, MT6323_INT_MISC_CON, 0x10),
+   .keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x4, MT6323_INT_MISC_CON, 0x8),
+   .pmic_rst_reg = MT6323_TOP_RST_MISC,
+};
+
+struct mtk_pmic_keys_info {
+   struct mtk_pmic_keys *keys;
+   const struct mtk_pmic_keys_regs *regs;
+   unsigned int keycode;
+   int irq;
+   bool wakeup:1;
+};
+
+struct mtk_pmic_keys {
+ 

[PATCH v6 4/6] dt-bindings: mfd: Add bindings for the keys as subnode of PMIC

2017-10-25 Thread Chen Zhong
This patch adds documentation for device tree bindings for keys support
as the subnode of MT6397/MT6323 PMIC.

Acked-by: Rob Herring <r...@kernel.org>
Acked-for-MFD-by: Lee Jones <lee.jo...@linaro.org>
Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 Documentation/devicetree/bindings/mfd/mt6397.txt |6 ++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/mt6397.txt 
b/Documentation/devicetree/bindings/mfd/mt6397.txt
index 522a3bb..d1df77f 100644
--- a/Documentation/devicetree/bindings/mfd/mt6397.txt
+++ b/Documentation/devicetree/bindings/mfd/mt6397.txt
@@ -7,6 +7,7 @@ MT6397/MT6323 is a multifunction device with the following sub 
modules:
 - GPIO
 - Clock
 - LED
+- Keys
 
 It is interfaced to host controller using SPI interface by a proprietary 
hardware
 called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.
@@ -40,6 +41,11 @@ Optional subnodes:
- compatible: "mediatek,mt6323-led"
see Documentation/devicetree/bindings/leds/leds-mt6323.txt
 
+- keys
+   Required properties:
+   - compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+   see Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
+
 Example:
pwrap: pwrap@1000f000 {
compatible = "mediatek,mt8135-pwrap";
-- 
1.7.9.5



[PATCH v6 4/6] dt-bindings: mfd: Add bindings for the keys as subnode of PMIC

2017-10-25 Thread Chen Zhong
This patch adds documentation for device tree bindings for keys support
as the subnode of MT6397/MT6323 PMIC.

Acked-by: Rob Herring 
Acked-for-MFD-by: Lee Jones 
Signed-off-by: Chen Zhong 
---
 Documentation/devicetree/bindings/mfd/mt6397.txt |6 ++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/mt6397.txt 
b/Documentation/devicetree/bindings/mfd/mt6397.txt
index 522a3bb..d1df77f 100644
--- a/Documentation/devicetree/bindings/mfd/mt6397.txt
+++ b/Documentation/devicetree/bindings/mfd/mt6397.txt
@@ -7,6 +7,7 @@ MT6397/MT6323 is a multifunction device with the following sub 
modules:
 - GPIO
 - Clock
 - LED
+- Keys
 
 It is interfaced to host controller using SPI interface by a proprietary 
hardware
 called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.
@@ -40,6 +41,11 @@ Optional subnodes:
- compatible: "mediatek,mt6323-led"
see Documentation/devicetree/bindings/leds/leds-mt6323.txt
 
+- keys
+   Required properties:
+   - compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+   see Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
+
 Example:
pwrap: pwrap@1000f000 {
compatible = "mediatek,mt8135-pwrap";
-- 
1.7.9.5



Re: [PATCH v5 5/6] input: Add MediaTek PMIC keys support

2017-10-24 Thread Chen Zhong
On Mon, 2017-10-23 at 22:44 -0700, Dmitry Torokhov wrote:
> On Wed, Sep 27, 2017 at 06:44:07PM +0800, Chen Zhong wrote:
> > This patch add support to handle MediaTek PMIC MT6397/MT6323 key
> > interrupts including pwrkey and homekey, also add setting for
> > long press key shutdown behavior.
> > 
> > Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
> > ---
> >  drivers/input/keyboard/Kconfig |9 +
> >  drivers/input/keyboard/Makefile|1 +
> >  drivers/input/keyboard/mtk-pmic-keys.c |  341 
> > 
> >  3 files changed, 351 insertions(+)
> >  create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
> > 
> > diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> > index 4c4ab1c..bd4e20a 100644
> > --- a/drivers/input/keyboard/Kconfig
> > +++ b/drivers/input/keyboard/Kconfig
> > @@ -756,4 +756,13 @@ config KEYBOARD_BCM
> >   To compile this driver as a module, choose M here: the
> >   module will be called bcm-keypad.
> >  
> > +config KEYBOARD_MTK_PMIC
> > +   tristate "MediaTek PMIC keys support"
> > +   depends on MFD_MT6397
> > +   help
> > + Say Y here if you want to use the pmic keys (powerkey/homekey).
> > +
> > + To compile this driver as a module, choose M here: the
> > + module will be called pmic-keys.
> > +
> >  endif
> > diff --git a/drivers/input/keyboard/Makefile 
> > b/drivers/input/keyboard/Makefile
> > index d2338ba..20c0b98 100644
> > --- a/drivers/input/keyboard/Makefile
> > +++ b/drivers/input/keyboard/Makefile
> > @@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += 
> > matrix_keypad.o
> >  obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
> >  obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
> >  obj-$(CONFIG_KEYBOARD_MPR121)  += mpr121_touchkey.o
> > +obj-$(CONFIG_KEYBOARD_MTK_PMIC)+= mtk-pmic-keys.o
> >  obj-$(CONFIG_KEYBOARD_NEWTON)  += newtonkbd.o
> >  obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
> >  obj-$(CONFIG_KEYBOARD_NSPIRE)  += nspire-keypad.o
> > diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
> > b/drivers/input/keyboard/mtk-pmic-keys.c
> > new file mode 100644
> > index 000..529fd95
> > --- /dev/null
> > +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> > @@ -0,0 +1,341 @@
> > +/*
> > + * Copyright (C) 2017 MediaTek, Inc.
> > + *
> > + * Author: Chen Zhong <chen.zh...@mediatek.com>
> > + *
> > + * This software is licensed under the terms of the GNU General Public
> > + * License version 2, as published by the Free Software Foundation, and
> > + * may be copied, distributed, and modified under those terms.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + *
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define MTK_PMIC_PWRKEY_RST_EN_MASK0x1
> > +#define MTK_PMIC_PWRKEY_RST_EN_SHIFT   6
> > +#define MTK_PMIC_HOMEKEY_RST_EN_MASK   0x1
> > +#define MTK_PMIC_HOMEKEY_RST_EN_SHIFT  5
> > +#define MTK_PMIC_RST_DU_MASK   0x3
> > +#define MTK_PMIC_RST_DU_SHIFT  8
> > +
> > +#define MTK_PMIC_PWRKEY_RST\
> > +   (MTK_PMIC_PWRKEY_RST_EN_MASK << MTK_PMIC_PWRKEY_RST_EN_SHIFT)
> > +#define MTK_PMIC_HOMEKEY_RST   \
> > +   (MTK_PMIC_HOMEKEY_RST_EN_MASK << MTK_PMIC_HOMEKEY_RST_EN_SHIFT)
> > +
> > +#define MTK_PMIC_PWRKEY_INDEX  0
> > +#define MTK_PMIC_HOMEKEY_INDEX 1
> > +#define MTK_PMIC_MAX_KEY_COUNT 2
> > +
> > +struct mtk_pmic_keys_regs {
> > +   u32 deb_reg;
> > +   u32 deb_mask;
> > +   u32 intsel_reg;
> > +   u32 intsel_mask;
> > +};
> > +
> > +#define MTK_PMIC_KEYS_REGS(_deb_reg, _deb_mask,\
> > +   _intsel_reg, _intsel_mask)  \
> > +{  \
> > +   .deb_reg= _deb_reg, \
> > +   .deb_mask   = _deb_mask,\
> > +   .i

Re: [PATCH v5 5/6] input: Add MediaTek PMIC keys support

2017-10-24 Thread Chen Zhong
On Mon, 2017-10-23 at 22:44 -0700, Dmitry Torokhov wrote:
> On Wed, Sep 27, 2017 at 06:44:07PM +0800, Chen Zhong wrote:
> > This patch add support to handle MediaTek PMIC MT6397/MT6323 key
> > interrupts including pwrkey and homekey, also add setting for
> > long press key shutdown behavior.
> > 
> > Signed-off-by: Chen Zhong 
> > ---
> >  drivers/input/keyboard/Kconfig |9 +
> >  drivers/input/keyboard/Makefile|1 +
> >  drivers/input/keyboard/mtk-pmic-keys.c |  341 
> > 
> >  3 files changed, 351 insertions(+)
> >  create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
> > 
> > diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> > index 4c4ab1c..bd4e20a 100644
> > --- a/drivers/input/keyboard/Kconfig
> > +++ b/drivers/input/keyboard/Kconfig
> > @@ -756,4 +756,13 @@ config KEYBOARD_BCM
> >   To compile this driver as a module, choose M here: the
> >   module will be called bcm-keypad.
> >  
> > +config KEYBOARD_MTK_PMIC
> > +   tristate "MediaTek PMIC keys support"
> > +   depends on MFD_MT6397
> > +   help
> > + Say Y here if you want to use the pmic keys (powerkey/homekey).
> > +
> > + To compile this driver as a module, choose M here: the
> > + module will be called pmic-keys.
> > +
> >  endif
> > diff --git a/drivers/input/keyboard/Makefile 
> > b/drivers/input/keyboard/Makefile
> > index d2338ba..20c0b98 100644
> > --- a/drivers/input/keyboard/Makefile
> > +++ b/drivers/input/keyboard/Makefile
> > @@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += 
> > matrix_keypad.o
> >  obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
> >  obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
> >  obj-$(CONFIG_KEYBOARD_MPR121)  += mpr121_touchkey.o
> > +obj-$(CONFIG_KEYBOARD_MTK_PMIC)+= mtk-pmic-keys.o
> >  obj-$(CONFIG_KEYBOARD_NEWTON)  += newtonkbd.o
> >  obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
> >  obj-$(CONFIG_KEYBOARD_NSPIRE)  += nspire-keypad.o
> > diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
> > b/drivers/input/keyboard/mtk-pmic-keys.c
> > new file mode 100644
> > index 000..529fd95
> > --- /dev/null
> > +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> > @@ -0,0 +1,341 @@
> > +/*
> > + * Copyright (C) 2017 MediaTek, Inc.
> > + *
> > + * Author: Chen Zhong 
> > + *
> > + * This software is licensed under the terms of the GNU General Public
> > + * License version 2, as published by the Free Software Foundation, and
> > + * may be copied, distributed, and modified under those terms.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + *
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define MTK_PMIC_PWRKEY_RST_EN_MASK0x1
> > +#define MTK_PMIC_PWRKEY_RST_EN_SHIFT   6
> > +#define MTK_PMIC_HOMEKEY_RST_EN_MASK   0x1
> > +#define MTK_PMIC_HOMEKEY_RST_EN_SHIFT  5
> > +#define MTK_PMIC_RST_DU_MASK   0x3
> > +#define MTK_PMIC_RST_DU_SHIFT  8
> > +
> > +#define MTK_PMIC_PWRKEY_RST\
> > +   (MTK_PMIC_PWRKEY_RST_EN_MASK << MTK_PMIC_PWRKEY_RST_EN_SHIFT)
> > +#define MTK_PMIC_HOMEKEY_RST   \
> > +   (MTK_PMIC_HOMEKEY_RST_EN_MASK << MTK_PMIC_HOMEKEY_RST_EN_SHIFT)
> > +
> > +#define MTK_PMIC_PWRKEY_INDEX  0
> > +#define MTK_PMIC_HOMEKEY_INDEX 1
> > +#define MTK_PMIC_MAX_KEY_COUNT 2
> > +
> > +struct mtk_pmic_keys_regs {
> > +   u32 deb_reg;
> > +   u32 deb_mask;
> > +   u32 intsel_reg;
> > +   u32 intsel_mask;
> > +};
> > +
> > +#define MTK_PMIC_KEYS_REGS(_deb_reg, _deb_mask,\
> > +   _intsel_reg, _intsel_mask)  \
> > +{  \
> > +   .deb_reg= _deb_reg, \
> > +   .deb_mask   = _deb_mask,\
> > +   .intsel_reg = _intsel_reg,  \

Re: [PATCH v5 5/6] input: Add MediaTek PMIC keys support

2017-10-23 Thread Chen Zhong
Just gentle ping.

On Wed, 2017-09-27 at 18:44 +0800, Chen Zhong wrote:
> This patch add support to handle MediaTek PMIC MT6397/MT6323 key
> interrupts including pwrkey and homekey, also add setting for
> long press key shutdown behavior.
> 
> Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
> ---
>  drivers/input/keyboard/Kconfig |9 +
>  drivers/input/keyboard/Makefile|1 +
>  drivers/input/keyboard/mtk-pmic-keys.c |  341 
> 
>  3 files changed, 351 insertions(+)
>  create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
> 
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index 4c4ab1c..bd4e20a 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -756,4 +756,13 @@ config KEYBOARD_BCM
> To compile this driver as a module, choose M here: the
> module will be called bcm-keypad.
>  
> +config KEYBOARD_MTK_PMIC
> + tristate "MediaTek PMIC keys support"
> + depends on MFD_MT6397
> + help
> +   Say Y here if you want to use the pmic keys (powerkey/homekey).
> +
> +   To compile this driver as a module, choose M here: the
> +   module will be called pmic-keys.
> +
>  endif
> diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
> index d2338ba..20c0b98 100644
> --- a/drivers/input/keyboard/Makefile
> +++ b/drivers/input/keyboard/Makefile
> @@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX)   += 
> matrix_keypad.o
>  obj-$(CONFIG_KEYBOARD_MAX7359)   += max7359_keypad.o
>  obj-$(CONFIG_KEYBOARD_MCS)   += mcs_touchkey.o
>  obj-$(CONFIG_KEYBOARD_MPR121)+= mpr121_touchkey.o
> +obj-$(CONFIG_KEYBOARD_MTK_PMIC)  += mtk-pmic-keys.o
>  obj-$(CONFIG_KEYBOARD_NEWTON)+= newtonkbd.o
>  obj-$(CONFIG_KEYBOARD_NOMADIK)   += nomadik-ske-keypad.o
>  obj-$(CONFIG_KEYBOARD_NSPIRE)+= nspire-keypad.o
> diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
> b/drivers/input/keyboard/mtk-pmic-keys.c
> new file mode 100644
> index 000..529fd95
> --- /dev/null
> +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> @@ -0,0 +1,341 @@
> +/*
> + * Copyright (C) 2017 MediaTek, Inc.
> + *
> + * Author: Chen Zhong <chen.zh...@mediatek.com>
> + *
> + * This software is licensed under the terms of the GNU General Public
> + * License version 2, as published by the Free Software Foundation, and
> + * may be copied, distributed, and modified under those terms.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define MTK_PMIC_PWRKEY_RST_EN_MASK  0x1
> +#define MTK_PMIC_PWRKEY_RST_EN_SHIFT 6
> +#define MTK_PMIC_HOMEKEY_RST_EN_MASK 0x1
> +#define MTK_PMIC_HOMEKEY_RST_EN_SHIFT5
> +#define MTK_PMIC_RST_DU_MASK 0x3
> +#define MTK_PMIC_RST_DU_SHIFT8
> +
> +#define MTK_PMIC_PWRKEY_RST  \
> + (MTK_PMIC_PWRKEY_RST_EN_MASK << MTK_PMIC_PWRKEY_RST_EN_SHIFT)
> +#define MTK_PMIC_HOMEKEY_RST \
> + (MTK_PMIC_HOMEKEY_RST_EN_MASK << MTK_PMIC_HOMEKEY_RST_EN_SHIFT)
> +
> +#define MTK_PMIC_PWRKEY_INDEX0
> +#define MTK_PMIC_HOMEKEY_INDEX   1
> +#define MTK_PMIC_MAX_KEY_COUNT   2
> +
> +struct mtk_pmic_keys_regs {
> + u32 deb_reg;
> + u32 deb_mask;
> + u32 intsel_reg;
> + u32 intsel_mask;
> +};
> +
> +#define MTK_PMIC_KEYS_REGS(_deb_reg, _deb_mask,  \
> + _intsel_reg, _intsel_mask)  \
> +{\
> + .deb_reg= _deb_reg, \
> + .deb_mask   = _deb_mask,\
> + .intsel_reg = _intsel_reg,  \
> + .intsel_mask= _intsel_mask, \
> +}
> +
> +struct mtk_pmic_regs {
> + const struct mtk_pmic_keys_regs keys_regs[MTK_PMIC_MAX_KEY_COUNT];
> + u32 pmic_rst_reg;
> +};
> +
> +static const struct mtk_pmic_regs mt6397_regs = {
> + .keys_regs[MTK_PMIC_PWRKEY_INDEX] =
> + MTK_PMIC_KEYS_REGS(MT6397_CHRSTATUS,
> + 0x8, MT6397_INT_RSV, 0x10),
> + .keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
> + MTK_PMIC_KEYS_REGS(MT6397_OC

Re: [PATCH v5 5/6] input: Add MediaTek PMIC keys support

2017-10-23 Thread Chen Zhong
Just gentle ping.

On Wed, 2017-09-27 at 18:44 +0800, Chen Zhong wrote:
> This patch add support to handle MediaTek PMIC MT6397/MT6323 key
> interrupts including pwrkey and homekey, also add setting for
> long press key shutdown behavior.
> 
> Signed-off-by: Chen Zhong 
> ---
>  drivers/input/keyboard/Kconfig |9 +
>  drivers/input/keyboard/Makefile|1 +
>  drivers/input/keyboard/mtk-pmic-keys.c |  341 
> 
>  3 files changed, 351 insertions(+)
>  create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
> 
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index 4c4ab1c..bd4e20a 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -756,4 +756,13 @@ config KEYBOARD_BCM
> To compile this driver as a module, choose M here: the
> module will be called bcm-keypad.
>  
> +config KEYBOARD_MTK_PMIC
> + tristate "MediaTek PMIC keys support"
> + depends on MFD_MT6397
> + help
> +   Say Y here if you want to use the pmic keys (powerkey/homekey).
> +
> +   To compile this driver as a module, choose M here: the
> +   module will be called pmic-keys.
> +
>  endif
> diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
> index d2338ba..20c0b98 100644
> --- a/drivers/input/keyboard/Makefile
> +++ b/drivers/input/keyboard/Makefile
> @@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX)   += 
> matrix_keypad.o
>  obj-$(CONFIG_KEYBOARD_MAX7359)   += max7359_keypad.o
>  obj-$(CONFIG_KEYBOARD_MCS)   += mcs_touchkey.o
>  obj-$(CONFIG_KEYBOARD_MPR121)+= mpr121_touchkey.o
> +obj-$(CONFIG_KEYBOARD_MTK_PMIC)  += mtk-pmic-keys.o
>  obj-$(CONFIG_KEYBOARD_NEWTON)+= newtonkbd.o
>  obj-$(CONFIG_KEYBOARD_NOMADIK)   += nomadik-ske-keypad.o
>  obj-$(CONFIG_KEYBOARD_NSPIRE)+= nspire-keypad.o
> diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
> b/drivers/input/keyboard/mtk-pmic-keys.c
> new file mode 100644
> index 000..529fd95
> --- /dev/null
> +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> @@ -0,0 +1,341 @@
> +/*
> + * Copyright (C) 2017 MediaTek, Inc.
> + *
> + * Author: Chen Zhong 
> + *
> + * This software is licensed under the terms of the GNU General Public
> + * License version 2, as published by the Free Software Foundation, and
> + * may be copied, distributed, and modified under those terms.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define MTK_PMIC_PWRKEY_RST_EN_MASK  0x1
> +#define MTK_PMIC_PWRKEY_RST_EN_SHIFT 6
> +#define MTK_PMIC_HOMEKEY_RST_EN_MASK 0x1
> +#define MTK_PMIC_HOMEKEY_RST_EN_SHIFT5
> +#define MTK_PMIC_RST_DU_MASK 0x3
> +#define MTK_PMIC_RST_DU_SHIFT8
> +
> +#define MTK_PMIC_PWRKEY_RST  \
> + (MTK_PMIC_PWRKEY_RST_EN_MASK << MTK_PMIC_PWRKEY_RST_EN_SHIFT)
> +#define MTK_PMIC_HOMEKEY_RST \
> + (MTK_PMIC_HOMEKEY_RST_EN_MASK << MTK_PMIC_HOMEKEY_RST_EN_SHIFT)
> +
> +#define MTK_PMIC_PWRKEY_INDEX0
> +#define MTK_PMIC_HOMEKEY_INDEX   1
> +#define MTK_PMIC_MAX_KEY_COUNT   2
> +
> +struct mtk_pmic_keys_regs {
> + u32 deb_reg;
> + u32 deb_mask;
> + u32 intsel_reg;
> + u32 intsel_mask;
> +};
> +
> +#define MTK_PMIC_KEYS_REGS(_deb_reg, _deb_mask,  \
> + _intsel_reg, _intsel_mask)  \
> +{\
> + .deb_reg= _deb_reg, \
> + .deb_mask   = _deb_mask,\
> + .intsel_reg = _intsel_reg,  \
> + .intsel_mask= _intsel_mask, \
> +}
> +
> +struct mtk_pmic_regs {
> + const struct mtk_pmic_keys_regs keys_regs[MTK_PMIC_MAX_KEY_COUNT];
> + u32 pmic_rst_reg;
> +};
> +
> +static const struct mtk_pmic_regs mt6397_regs = {
> + .keys_regs[MTK_PMIC_PWRKEY_INDEX] =
> + MTK_PMIC_KEYS_REGS(MT6397_CHRSTATUS,
> + 0x8, MT6397_INT_RSV, 0x10),
> + .keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
> + MTK_PMIC_KEYS_REGS(MT6397_OCSTATUS2,
> + 0x10, MT6397_INT_RSV, 0x8),
>

[PATCH v5 2/6] dt-bindings: input: Add common keyboard document bindings

2017-09-27 Thread Chen Zhong
This patch adds the device tree binding documentation for common
keyboard.

Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 Documentation/devicetree/bindings/input/keys.txt |8 
 1 file changed, 8 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/keys.txt

diff --git a/Documentation/devicetree/bindings/input/keys.txt 
b/Documentation/devicetree/bindings/input/keys.txt
new file mode 100644
index 000..a0ea7eb
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/keys.txt
@@ -0,0 +1,8 @@
+General Keys Properties:
+
+Optional properties for Keys:
+- power-off-time-sec: Duration in seconds which the key should be kept
+   pressed for device to power off automatically. Device with key pressed
+   shutdown feature can specify this property.
+- linux,keycodes: Specifies the numeric keycode values to be used for
+   reporting key presses.
\ No newline at end of file
-- 
1.7.9.5



[PATCH v5 2/6] dt-bindings: input: Add common keyboard document bindings

2017-09-27 Thread Chen Zhong
This patch adds the device tree binding documentation for common
keyboard.

Signed-off-by: Chen Zhong 
---
 Documentation/devicetree/bindings/input/keys.txt |8 
 1 file changed, 8 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/keys.txt

diff --git a/Documentation/devicetree/bindings/input/keys.txt 
b/Documentation/devicetree/bindings/input/keys.txt
new file mode 100644
index 000..a0ea7eb
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/keys.txt
@@ -0,0 +1,8 @@
+General Keys Properties:
+
+Optional properties for Keys:
+- power-off-time-sec: Duration in seconds which the key should be kept
+   pressed for device to power off automatically. Device with key pressed
+   shutdown feature can specify this property.
+- linux,keycodes: Specifies the numeric keycode values to be used for
+   reporting key presses.
\ No newline at end of file
-- 
1.7.9.5



[PATCH v5 3/6] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-09-27 Thread Chen Zhong
This patch adds the device tree binding documentation for the MediaTek
pmic keys found on PMIC MT6397/MT6323.

Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 .../devicetree/bindings/input/mtk-pmic-keys.txt|   43 
 1 file changed, 43 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt

diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
new file mode 100644
index 000..2888d07
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
@@ -0,0 +1,43 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: See Documentation/devicetree/bindings/input/keys.txt
+
+Optional Properties:
+- wakeup-source: See Documentation/devicetree/bindings/power/wakeup-source.txt
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- power-off-time-sec: See Documentation/devicetree/bindings/input/keys.txt
+
+Example:
+
+   pmic: mt6397 {
+   compatible = "mediatek,mt6397";
+
+   ...
+
+   mt6397keys: mt6397keys {
+   compatible = "mediatek,mt6397-keys";
+   mediatek,long-press-mode = <1>;
+   power-off-time-sec = <0>;
+
+   power {
+   linux,keycodes = <116>;
+   wakeup-source;
+   };
+
+   home {
+   linux,keycodes = <114>;
+   };
+   };
+
+   };
-- 
1.7.9.5



[PATCH v5 3/6] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-09-27 Thread Chen Zhong
This patch adds the device tree binding documentation for the MediaTek
pmic keys found on PMIC MT6397/MT6323.

Signed-off-by: Chen Zhong 
---
 .../devicetree/bindings/input/mtk-pmic-keys.txt|   43 
 1 file changed, 43 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt

diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
new file mode 100644
index 000..2888d07
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
@@ -0,0 +1,43 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: See Documentation/devicetree/bindings/input/keys.txt
+
+Optional Properties:
+- wakeup-source: See Documentation/devicetree/bindings/power/wakeup-source.txt
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- power-off-time-sec: See Documentation/devicetree/bindings/input/keys.txt
+
+Example:
+
+   pmic: mt6397 {
+   compatible = "mediatek,mt6397";
+
+   ...
+
+   mt6397keys: mt6397keys {
+   compatible = "mediatek,mt6397-keys";
+   mediatek,long-press-mode = <1>;
+   power-off-time-sec = <0>;
+
+   power {
+   linux,keycodes = <116>;
+   wakeup-source;
+   };
+
+   home {
+   linux,keycodes = <114>;
+   };
+   };
+
+   };
-- 
1.7.9.5



[PATCH v5 5/6] input: Add MediaTek PMIC keys support

2017-09-27 Thread Chen Zhong
This patch add support to handle MediaTek PMIC MT6397/MT6323 key
interrupts including pwrkey and homekey, also add setting for
long press key shutdown behavior.

Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 drivers/input/keyboard/Kconfig |9 +
 drivers/input/keyboard/Makefile|1 +
 drivers/input/keyboard/mtk-pmic-keys.c |  341 
 3 files changed, 351 insertions(+)
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 4c4ab1c..bd4e20a 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -756,4 +756,13 @@ config KEYBOARD_BCM
  To compile this driver as a module, choose M here: the
  module will be called bcm-keypad.
 
+config KEYBOARD_MTK_PMIC
+   tristate "MediaTek PMIC keys support"
+   depends on MFD_MT6397
+   help
+ Say Y here if you want to use the pmic keys (powerkey/homekey).
+
+ To compile this driver as a module, choose M here: the
+ module will be called pmic-keys.
+
 endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index d2338ba..20c0b98 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
 obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
 obj-$(CONFIG_KEYBOARD_MPR121)  += mpr121_touchkey.o
+obj-$(CONFIG_KEYBOARD_MTK_PMIC)+= mtk-pmic-keys.o
 obj-$(CONFIG_KEYBOARD_NEWTON)  += newtonkbd.o
 obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
 obj-$(CONFIG_KEYBOARD_NSPIRE)  += nspire-keypad.o
diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
b/drivers/input/keyboard/mtk-pmic-keys.c
new file mode 100644
index 000..529fd95
--- /dev/null
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -0,0 +1,341 @@
+/*
+ * Copyright (C) 2017 MediaTek, Inc.
+ *
+ * Author: Chen Zhong <chen.zh...@mediatek.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MTK_PMIC_PWRKEY_RST_EN_MASK0x1
+#define MTK_PMIC_PWRKEY_RST_EN_SHIFT   6
+#define MTK_PMIC_HOMEKEY_RST_EN_MASK   0x1
+#define MTK_PMIC_HOMEKEY_RST_EN_SHIFT  5
+#define MTK_PMIC_RST_DU_MASK   0x3
+#define MTK_PMIC_RST_DU_SHIFT  8
+
+#define MTK_PMIC_PWRKEY_RST\
+   (MTK_PMIC_PWRKEY_RST_EN_MASK << MTK_PMIC_PWRKEY_RST_EN_SHIFT)
+#define MTK_PMIC_HOMEKEY_RST   \
+   (MTK_PMIC_HOMEKEY_RST_EN_MASK << MTK_PMIC_HOMEKEY_RST_EN_SHIFT)
+
+#define MTK_PMIC_PWRKEY_INDEX  0
+#define MTK_PMIC_HOMEKEY_INDEX 1
+#define MTK_PMIC_MAX_KEY_COUNT 2
+
+struct mtk_pmic_keys_regs {
+   u32 deb_reg;
+   u32 deb_mask;
+   u32 intsel_reg;
+   u32 intsel_mask;
+};
+
+#define MTK_PMIC_KEYS_REGS(_deb_reg, _deb_mask,\
+   _intsel_reg, _intsel_mask)  \
+{  \
+   .deb_reg= _deb_reg, \
+   .deb_mask   = _deb_mask,\
+   .intsel_reg = _intsel_reg,  \
+   .intsel_mask= _intsel_mask, \
+}
+
+struct mtk_pmic_regs {
+   const struct mtk_pmic_keys_regs keys_regs[MTK_PMIC_MAX_KEY_COUNT];
+   u32 pmic_rst_reg;
+};
+
+static const struct mtk_pmic_regs mt6397_regs = {
+   .keys_regs[MTK_PMIC_PWRKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6397_CHRSTATUS,
+   0x8, MT6397_INT_RSV, 0x10),
+   .keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6397_OCSTATUS2,
+   0x10, MT6397_INT_RSV, 0x8),
+   .pmic_rst_reg = MT6397_TOP_RST_MISC,
+};
+
+static const struct mtk_pmic_regs mt6323_regs = {
+   .keys_regs[MTK_PMIC_PWRKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x2, MT6323_INT_MISC_CON, 0x10),
+   .keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x4, MT6323_INT_MISC_CON, 0x8),
+   .pmic_rst_reg = MT6323_TOP_RST_MISC,
+};
+
+struct mtk_pmic_keys_info {
+   struct mtk_pmic_keys *keys;
+   const struct mtk_pmic_keys_regs *regs;
+   unsigned int keycode;
+   int irq;
+   bool wak

[PATCH v5 5/6] input: Add MediaTek PMIC keys support

2017-09-27 Thread Chen Zhong
This patch add support to handle MediaTek PMIC MT6397/MT6323 key
interrupts including pwrkey and homekey, also add setting for
long press key shutdown behavior.

Signed-off-by: Chen Zhong 
---
 drivers/input/keyboard/Kconfig |9 +
 drivers/input/keyboard/Makefile|1 +
 drivers/input/keyboard/mtk-pmic-keys.c |  341 
 3 files changed, 351 insertions(+)
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 4c4ab1c..bd4e20a 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -756,4 +756,13 @@ config KEYBOARD_BCM
  To compile this driver as a module, choose M here: the
  module will be called bcm-keypad.
 
+config KEYBOARD_MTK_PMIC
+   tristate "MediaTek PMIC keys support"
+   depends on MFD_MT6397
+   help
+ Say Y here if you want to use the pmic keys (powerkey/homekey).
+
+ To compile this driver as a module, choose M here: the
+ module will be called pmic-keys.
+
 endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index d2338ba..20c0b98 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
 obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
 obj-$(CONFIG_KEYBOARD_MPR121)  += mpr121_touchkey.o
+obj-$(CONFIG_KEYBOARD_MTK_PMIC)+= mtk-pmic-keys.o
 obj-$(CONFIG_KEYBOARD_NEWTON)  += newtonkbd.o
 obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
 obj-$(CONFIG_KEYBOARD_NSPIRE)  += nspire-keypad.o
diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
b/drivers/input/keyboard/mtk-pmic-keys.c
new file mode 100644
index 000..529fd95
--- /dev/null
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -0,0 +1,341 @@
+/*
+ * Copyright (C) 2017 MediaTek, Inc.
+ *
+ * Author: Chen Zhong 
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MTK_PMIC_PWRKEY_RST_EN_MASK0x1
+#define MTK_PMIC_PWRKEY_RST_EN_SHIFT   6
+#define MTK_PMIC_HOMEKEY_RST_EN_MASK   0x1
+#define MTK_PMIC_HOMEKEY_RST_EN_SHIFT  5
+#define MTK_PMIC_RST_DU_MASK   0x3
+#define MTK_PMIC_RST_DU_SHIFT  8
+
+#define MTK_PMIC_PWRKEY_RST\
+   (MTK_PMIC_PWRKEY_RST_EN_MASK << MTK_PMIC_PWRKEY_RST_EN_SHIFT)
+#define MTK_PMIC_HOMEKEY_RST   \
+   (MTK_PMIC_HOMEKEY_RST_EN_MASK << MTK_PMIC_HOMEKEY_RST_EN_SHIFT)
+
+#define MTK_PMIC_PWRKEY_INDEX  0
+#define MTK_PMIC_HOMEKEY_INDEX 1
+#define MTK_PMIC_MAX_KEY_COUNT 2
+
+struct mtk_pmic_keys_regs {
+   u32 deb_reg;
+   u32 deb_mask;
+   u32 intsel_reg;
+   u32 intsel_mask;
+};
+
+#define MTK_PMIC_KEYS_REGS(_deb_reg, _deb_mask,\
+   _intsel_reg, _intsel_mask)  \
+{  \
+   .deb_reg= _deb_reg, \
+   .deb_mask   = _deb_mask,\
+   .intsel_reg = _intsel_reg,  \
+   .intsel_mask= _intsel_mask, \
+}
+
+struct mtk_pmic_regs {
+   const struct mtk_pmic_keys_regs keys_regs[MTK_PMIC_MAX_KEY_COUNT];
+   u32 pmic_rst_reg;
+};
+
+static const struct mtk_pmic_regs mt6397_regs = {
+   .keys_regs[MTK_PMIC_PWRKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6397_CHRSTATUS,
+   0x8, MT6397_INT_RSV, 0x10),
+   .keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6397_OCSTATUS2,
+   0x10, MT6397_INT_RSV, 0x8),
+   .pmic_rst_reg = MT6397_TOP_RST_MISC,
+};
+
+static const struct mtk_pmic_regs mt6323_regs = {
+   .keys_regs[MTK_PMIC_PWRKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x2, MT6323_INT_MISC_CON, 0x10),
+   .keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x4, MT6323_INT_MISC_CON, 0x8),
+   .pmic_rst_reg = MT6323_TOP_RST_MISC,
+};
+
+struct mtk_pmic_keys_info {
+   struct mtk_pmic_keys *keys;
+   const struct mtk_pmic_keys_regs *regs;
+   unsigned int keycode;
+   int irq;
+   bool wakeup:1;
+};
+
+struct mtk_pmic_keys {
+   struct input_dev *inp

[PATCH v5 0/6] Add MediaTek PMIC keys support

2017-09-27 Thread Chen Zhong
Changes since v4:
- rebase to Linux 4.14-rc1
- add a common keyboard binding document
- use child device tree node to define each key

Changes since v3:
- make the naming to be consistent as mtk_pmic or MTK_PMIC
- add suspend/resume functions to enable/disable irq
- change binding properties to define wakeup sources

Changes since v2:
- use standard properties for keycodes and debounce time
- change to use platform_get_irq in leaf drivers
- use better ways to define IRQ resources

Changes since v1:
- create irq mappings in mfd core driver instead of leaf drivers
- remove some unused parts in mtk-pmic-keys driver

MediaTek PMIC are multi-function devices that can handle key interrupts,
typically there are two keys attached to PMIC, which called pwrkey
and homekey. PWRKEY usually used to wake up system from sleep. Homekey
can used as volume down key due to board design. Long press keys can
shutdown PMIC, the mode can be choose to be one key only or two keys
together.
This series add support for key functions for MediaTek PMIC MT6397/MT6323.

Chen Zhong (6):
  mfd: mt6397: create irq mappings in mfd core driver
  dt-bindings: input: Add common keyboard document bindings
  dt-bindings: input: Add document bindings for mtk-pmic-keys
  dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
  input: Add MediaTek PMIC keys support
  mfd: mt6397: Add PMIC keys support to MT6397 driver

 Documentation/devicetree/bindings/input/keys.txt   |   8 +
 .../devicetree/bindings/input/mtk-pmic-keys.txt|  43 +++
 Documentation/devicetree/bindings/mfd/mt6397.txt   |   6 +
 drivers/input/keyboard/Kconfig |   9 +
 drivers/input/keyboard/Makefile|   1 +
 drivers/input/keyboard/mtk-pmic-keys.c | 341 +
 drivers/mfd/mt6397-core.c  |  26 +-
 drivers/rtc/rtc-mt6397.c   |   7 +-
 8 files changed, 434 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/keys.txt
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

-- 
1.9.1



[PATCH v5 4/6] dt-bindings: mfd: Add bindings for the keys as subnode of PMIC

2017-09-27 Thread Chen Zhong
This patch adds documentation for device tree bindings for keys support
as the subnode of MT6397/MT6323 PMIC.

Acked-by: Rob Herring <r...@kernel.org>
Acked-for-MFD-by: Lee Jones <lee.jo...@linaro.org>
Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 Documentation/devicetree/bindings/mfd/mt6397.txt |6 ++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/mt6397.txt 
b/Documentation/devicetree/bindings/mfd/mt6397.txt
index 522a3bb..d1df77f 100644
--- a/Documentation/devicetree/bindings/mfd/mt6397.txt
+++ b/Documentation/devicetree/bindings/mfd/mt6397.txt
@@ -7,6 +7,7 @@ MT6397/MT6323 is a multifunction device with the following sub 
modules:
 - GPIO
 - Clock
 - LED
+- Keys
 
 It is interfaced to host controller using SPI interface by a proprietary 
hardware
 called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.
@@ -40,6 +41,11 @@ Optional subnodes:
- compatible: "mediatek,mt6323-led"
see Documentation/devicetree/bindings/leds/leds-mt6323.txt
 
+- keys
+   Required properties:
+   - compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+   see Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
+
 Example:
pwrap: pwrap@1000f000 {
compatible = "mediatek,mt8135-pwrap";
-- 
1.7.9.5



[PATCH v5 0/6] Add MediaTek PMIC keys support

2017-09-27 Thread Chen Zhong
Changes since v4:
- rebase to Linux 4.14-rc1
- add a common keyboard binding document
- use child device tree node to define each key

Changes since v3:
- make the naming to be consistent as mtk_pmic or MTK_PMIC
- add suspend/resume functions to enable/disable irq
- change binding properties to define wakeup sources

Changes since v2:
- use standard properties for keycodes and debounce time
- change to use platform_get_irq in leaf drivers
- use better ways to define IRQ resources

Changes since v1:
- create irq mappings in mfd core driver instead of leaf drivers
- remove some unused parts in mtk-pmic-keys driver

MediaTek PMIC are multi-function devices that can handle key interrupts,
typically there are two keys attached to PMIC, which called pwrkey
and homekey. PWRKEY usually used to wake up system from sleep. Homekey
can used as volume down key due to board design. Long press keys can
shutdown PMIC, the mode can be choose to be one key only or two keys
together.
This series add support for key functions for MediaTek PMIC MT6397/MT6323.

Chen Zhong (6):
  mfd: mt6397: create irq mappings in mfd core driver
  dt-bindings: input: Add common keyboard document bindings
  dt-bindings: input: Add document bindings for mtk-pmic-keys
  dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
  input: Add MediaTek PMIC keys support
  mfd: mt6397: Add PMIC keys support to MT6397 driver

 Documentation/devicetree/bindings/input/keys.txt   |   8 +
 .../devicetree/bindings/input/mtk-pmic-keys.txt|  43 +++
 Documentation/devicetree/bindings/mfd/mt6397.txt   |   6 +
 drivers/input/keyboard/Kconfig |   9 +
 drivers/input/keyboard/Makefile|   1 +
 drivers/input/keyboard/mtk-pmic-keys.c | 341 +
 drivers/mfd/mt6397-core.c  |  26 +-
 drivers/rtc/rtc-mt6397.c   |   7 +-
 8 files changed, 434 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/keys.txt
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

-- 
1.9.1



[PATCH v5 4/6] dt-bindings: mfd: Add bindings for the keys as subnode of PMIC

2017-09-27 Thread Chen Zhong
This patch adds documentation for device tree bindings for keys support
as the subnode of MT6397/MT6323 PMIC.

Acked-by: Rob Herring 
Acked-for-MFD-by: Lee Jones 
Signed-off-by: Chen Zhong 
---
 Documentation/devicetree/bindings/mfd/mt6397.txt |6 ++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/mt6397.txt 
b/Documentation/devicetree/bindings/mfd/mt6397.txt
index 522a3bb..d1df77f 100644
--- a/Documentation/devicetree/bindings/mfd/mt6397.txt
+++ b/Documentation/devicetree/bindings/mfd/mt6397.txt
@@ -7,6 +7,7 @@ MT6397/MT6323 is a multifunction device with the following sub 
modules:
 - GPIO
 - Clock
 - LED
+- Keys
 
 It is interfaced to host controller using SPI interface by a proprietary 
hardware
 called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.
@@ -40,6 +41,11 @@ Optional subnodes:
- compatible: "mediatek,mt6323-led"
see Documentation/devicetree/bindings/leds/leds-mt6323.txt
 
+- keys
+   Required properties:
+   - compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+   see Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
+
 Example:
pwrap: pwrap@1000f000 {
compatible = "mediatek,mt8135-pwrap";
-- 
1.7.9.5



[PATCH v5 6/6] mfd: mt6397: Add PMIC keys support to MT6397 driver

2017-09-27 Thread Chen Zhong
This patch adds compatible strings and interrupts for pmic keys
which serves as child device of MFD.

Acked-for-MFD-by: Lee Jones <lee.jo...@linaro.org>
Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 drivers/mfd/mt6397-core.c |   22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 6546d7f..77b64bd 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -43,6 +43,16 @@
},
 };
 
+static const struct resource mt6323_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_PWRKEY),
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_FCHRKEY),
+};
+
+static const struct resource mt6397_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6397_IRQ_PWRKEY),
+   DEFINE_RES_IRQ(MT6397_IRQ_HOMEKEY),
+};
+
 static const struct mfd_cell mt6323_devs[] = {
{
.name = "mt6323-regulator",
@@ -50,6 +60,11 @@
}, {
.name = "mt6323-led",
.of_compatible = "mediatek,mt6323-led"
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6323_keys_resources),
+   .resources = mt6323_keys_resources,
+   .of_compatible = "mediatek,mt6323-keys"
},
 };
 
@@ -71,7 +86,12 @@
}, {
.name = "mt6397-pinctrl",
.of_compatible = "mediatek,mt6397-pinctrl",
-   },
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6397_keys_resources),
+   .resources = mt6397_keys_resources,
+   .of_compatible = "mediatek,mt6397-keys"
+   }
 };
 
 static void mt6397_irq_lock(struct irq_data *data)
-- 
1.7.9.5



[PATCH v5 6/6] mfd: mt6397: Add PMIC keys support to MT6397 driver

2017-09-27 Thread Chen Zhong
This patch adds compatible strings and interrupts for pmic keys
which serves as child device of MFD.

Acked-for-MFD-by: Lee Jones 
Signed-off-by: Chen Zhong 
---
 drivers/mfd/mt6397-core.c |   22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 6546d7f..77b64bd 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -43,6 +43,16 @@
},
 };
 
+static const struct resource mt6323_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_PWRKEY),
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_FCHRKEY),
+};
+
+static const struct resource mt6397_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6397_IRQ_PWRKEY),
+   DEFINE_RES_IRQ(MT6397_IRQ_HOMEKEY),
+};
+
 static const struct mfd_cell mt6323_devs[] = {
{
.name = "mt6323-regulator",
@@ -50,6 +60,11 @@
}, {
.name = "mt6323-led",
.of_compatible = "mediatek,mt6323-led"
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6323_keys_resources),
+   .resources = mt6323_keys_resources,
+   .of_compatible = "mediatek,mt6323-keys"
},
 };
 
@@ -71,7 +86,12 @@
}, {
.name = "mt6397-pinctrl",
.of_compatible = "mediatek,mt6397-pinctrl",
-   },
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6397_keys_resources),
+   .resources = mt6397_keys_resources,
+   .of_compatible = "mediatek,mt6397-keys"
+   }
 };
 
 static void mt6397_irq_lock(struct irq_data *data)
-- 
1.7.9.5



[PATCH v5 1/6] mfd: mt6397: create irq mappings in mfd core driver

2017-09-27 Thread Chen Zhong
The core driver should create and manage irq mappings instead of
leaf drivers. This patch change to pass irq domain to
devm_mfd_add_devices() and it will create mapping for irq resources
automatically. And remove irq mapping in rtc driver since this has
been done in core driver.

Acked-for-MFD-by: Lee Jones <lee.jo...@linaro.org>
Acked-by: Alexandre Belloni <alexandre.bell...@free-electrons.com>
Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 drivers/mfd/mt6397-core.c |4 ++--
 drivers/rtc/rtc-mt6397.c  |7 +++
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 04a601f..6546d7f 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6323_devs,
   ARRAY_SIZE(mt6323_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
case MT6397_CID_CODE:
@@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6397_devs,
   ARRAY_SIZE(mt6397_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
default:
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 1a61fa5..385f830 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -322,10 +322,9 @@ static int mtk_rtc_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
rtc->addr_base = res->start;
 
-   res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
-   if (rtc->irq <= 0)
-   return -EINVAL;
+   rtc->irq = platform_get_irq(pdev, 0);
+   if (rtc->irq < 0)
+   return rtc->irq;
 
rtc->regmap = mt6397_chip->regmap;
rtc->dev = >dev;
-- 
1.7.9.5



[PATCH v5 1/6] mfd: mt6397: create irq mappings in mfd core driver

2017-09-27 Thread Chen Zhong
The core driver should create and manage irq mappings instead of
leaf drivers. This patch change to pass irq domain to
devm_mfd_add_devices() and it will create mapping for irq resources
automatically. And remove irq mapping in rtc driver since this has
been done in core driver.

Acked-for-MFD-by: Lee Jones 
Acked-by: Alexandre Belloni 
Signed-off-by: Chen Zhong 
---
 drivers/mfd/mt6397-core.c |4 ++--
 drivers/rtc/rtc-mt6397.c  |7 +++
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 04a601f..6546d7f 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6323_devs,
   ARRAY_SIZE(mt6323_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
case MT6397_CID_CODE:
@@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6397_devs,
   ARRAY_SIZE(mt6397_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
default:
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 1a61fa5..385f830 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -322,10 +322,9 @@ static int mtk_rtc_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
rtc->addr_base = res->start;
 
-   res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
-   if (rtc->irq <= 0)
-   return -EINVAL;
+   rtc->irq = platform_get_irq(pdev, 0);
+   if (rtc->irq < 0)
+   return rtc->irq;
 
rtc->regmap = mt6397_chip->regmap;
rtc->dev = >dev;
-- 
1.7.9.5



Re: [PATCH v4 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-09-25 Thread Chen Zhong
On Sun, 2017-09-24 at 23:11 -0500, Rob Herring wrote:
> On Sat, Sep 23, 2017 at 1:47 AM, Chen Zhong <chen.zh...@mediatek.com> wrote:
> > Sorry for the typo.
> >
> > On Sat, 2017-09-23 at 14:38 +0800, Chen Zhong wrote:
> >> On Wed, 2017-09-20 at 15:53 -0500, Rob Herring wrote:
> >> > On Sun, Sep 17, 2017 at 04:00:49PM +0800, Chen Zhong wrote:
> >> > > This patch adds the device tree binding documentation for the MediaTek
> >> > > pmic keys found on PMIC MT6397/MT6323.
> >> > >
> >> > > Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
> >> > > ---
> >> > >  .../devicetree/bindings/input/mtk-pmic-keys.txt|   41 
> >> > > 
> >> > >  1 file changed, 41 insertions(+)
> >> > >  create mode 100644 
> >> > > Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> >> > >
> >> > > diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
> >> > > b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> >> > > new file mode 100644
> >> > > index 000..fd48ff7
> >> > > --- /dev/null
> >> > > +++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> >> > > @@ -0,0 +1,41 @@
> >> > > +MediaTek MT6397/MT6323 PMIC Keys Device Driver
> >> > > +
> >> > > +There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
> >> > > +and homekey. The key functions are defined as the subnode of the 
> >> > > function
> >> > > +node provided by MT6397/MT6323 PMIC that is being defined as one kind
> >> > > +of Muti-Function Device (MFD)
> >> > > +
> >> > > +For MT6397/MT6323 MFD bindings see:
> >> > > +Documentation/devicetree/bindings/mfd/mt6397.txt
> >> > > +
> >> > > +Required properties:
> >> > > +- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
> >> > > +- linux,keycodes: Specifies the numeric keycode values to
> >> > > + be used for reporting keys presses. The array can
> >> > > + contain up to 2 entries.
> >> > > +
> >> > > +Optional Properties:
> >> > > +- mediatek,wakeup-keys: Specifies each key can be used as a wakeup 
> >> > > source
> >> > > + or not. This can be customized depends on board design.
> >> >
> >> > I think this should be a common property if we're going to put into DT.
> >> > Something like "wakeup-scancodes" to be clear the values are the raw
> >> > scancodes. Alternatively, we could list Linux keycodes instead with
> >> > something like "linux,wakeup-keycodes".
> >> >
> >> > > +- wakeup-source: PMIC keys can be used as wakeup sources.
> >> >
> >> > Just "See ../power/wakeup-source.txt" for the description.
> >> >
> >> > > +- mediatek,long-press-mode: Long press key shutdown setting, 1 for
> >> > > + pwrkey only, 2 for pwrkey/homekey together, others for disabled.
> >> > > +- debounce-interval: Long press key shutdown debouncing interval time
> >> > > + in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults 
> >> > > to 0.
> >> >
> >> > This property units should be in milliseconds. However, this doesn't
> >> > sound like debounce filtering time if 5-14 seconds. That sounds like
> >> > forced power off time (i.e. for a hung device). This also should be
> >> > common. I imagine we already have some drivers with similar properties.
> >>
> >> Hi Rob,
> >>
> >> I searched in kernel documents and found a similar usage in
> >> "ti,palmas-pwrbutton.txt"
> >> "- ti,palmas-long-press-seconds: Duration in seconds which the power
> >>   button should be kept pressed for Palmas to power off automatically."
> >>
> >> Could I just wrote it like this?
> >> mediatek,long-press-seconds = <0>;
> 
> That doesn't really tell what the long press does. How about
> "power-off-time-sec"? Surprisingly we don't have a common keyboard
> binding doc, so please start one and document it there. Then just
> refer to it.
> 

OK, I will add a common document named "keys.txt" and put the long press
property "power-off-time-sec" there as a common property.

> >>
> >> And for the wakeup source part, how about Dmitry's suggestion?
> 
> It's fine for me.
> 
> >> The whole device node would be:
> >>
> >> mt6397keys: mt6397keys {
> >>   compatible = "mediatek,mt6397-keys";
> >>   mediatek,long-press-mode = <1>;
> >>   mediatek,long-press-seconds = <0>;
> >>
> >>   power@0 {
> >>   linux,code = <116>;
> 
> linux,keycodes
> 
> Also, you either need a reg property with "0" or drop the unit address.

There is no need to add reg property here, I'll drop the unit address.

Thank you.
> 
> >>   wakeup-source;
> >>   };
> >>
> >>   home@0 {
> > should be home@1 {
> >>   linux,code = <114>;
> >>   };
> >> };
> >>
> >> Thank you.
> >>
> >> >
> >> > Rob
> >>
> >
> >




Re: [PATCH v4 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-09-25 Thread Chen Zhong
On Sun, 2017-09-24 at 23:11 -0500, Rob Herring wrote:
> On Sat, Sep 23, 2017 at 1:47 AM, Chen Zhong  wrote:
> > Sorry for the typo.
> >
> > On Sat, 2017-09-23 at 14:38 +0800, Chen Zhong wrote:
> >> On Wed, 2017-09-20 at 15:53 -0500, Rob Herring wrote:
> >> > On Sun, Sep 17, 2017 at 04:00:49PM +0800, Chen Zhong wrote:
> >> > > This patch adds the device tree binding documentation for the MediaTek
> >> > > pmic keys found on PMIC MT6397/MT6323.
> >> > >
> >> > > Signed-off-by: Chen Zhong 
> >> > > ---
> >> > >  .../devicetree/bindings/input/mtk-pmic-keys.txt|   41 
> >> > > 
> >> > >  1 file changed, 41 insertions(+)
> >> > >  create mode 100644 
> >> > > Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> >> > >
> >> > > diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
> >> > > b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> >> > > new file mode 100644
> >> > > index 000..fd48ff7
> >> > > --- /dev/null
> >> > > +++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> >> > > @@ -0,0 +1,41 @@
> >> > > +MediaTek MT6397/MT6323 PMIC Keys Device Driver
> >> > > +
> >> > > +There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
> >> > > +and homekey. The key functions are defined as the subnode of the 
> >> > > function
> >> > > +node provided by MT6397/MT6323 PMIC that is being defined as one kind
> >> > > +of Muti-Function Device (MFD)
> >> > > +
> >> > > +For MT6397/MT6323 MFD bindings see:
> >> > > +Documentation/devicetree/bindings/mfd/mt6397.txt
> >> > > +
> >> > > +Required properties:
> >> > > +- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
> >> > > +- linux,keycodes: Specifies the numeric keycode values to
> >> > > + be used for reporting keys presses. The array can
> >> > > + contain up to 2 entries.
> >> > > +
> >> > > +Optional Properties:
> >> > > +- mediatek,wakeup-keys: Specifies each key can be used as a wakeup 
> >> > > source
> >> > > + or not. This can be customized depends on board design.
> >> >
> >> > I think this should be a common property if we're going to put into DT.
> >> > Something like "wakeup-scancodes" to be clear the values are the raw
> >> > scancodes. Alternatively, we could list Linux keycodes instead with
> >> > something like "linux,wakeup-keycodes".
> >> >
> >> > > +- wakeup-source: PMIC keys can be used as wakeup sources.
> >> >
> >> > Just "See ../power/wakeup-source.txt" for the description.
> >> >
> >> > > +- mediatek,long-press-mode: Long press key shutdown setting, 1 for
> >> > > + pwrkey only, 2 for pwrkey/homekey together, others for disabled.
> >> > > +- debounce-interval: Long press key shutdown debouncing interval time
> >> > > + in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults 
> >> > > to 0.
> >> >
> >> > This property units should be in milliseconds. However, this doesn't
> >> > sound like debounce filtering time if 5-14 seconds. That sounds like
> >> > forced power off time (i.e. for a hung device). This also should be
> >> > common. I imagine we already have some drivers with similar properties.
> >>
> >> Hi Rob,
> >>
> >> I searched in kernel documents and found a similar usage in
> >> "ti,palmas-pwrbutton.txt"
> >> "- ti,palmas-long-press-seconds: Duration in seconds which the power
> >>   button should be kept pressed for Palmas to power off automatically."
> >>
> >> Could I just wrote it like this?
> >> mediatek,long-press-seconds = <0>;
> 
> That doesn't really tell what the long press does. How about
> "power-off-time-sec"? Surprisingly we don't have a common keyboard
> binding doc, so please start one and document it there. Then just
> refer to it.
> 

OK, I will add a common document named "keys.txt" and put the long press
property "power-off-time-sec" there as a common property.

> >>
> >> And for the wakeup source part, how about Dmitry's suggestion?
> 
> It's fine for me.
> 
> >> The whole device node would be:
> >>
> >> mt6397keys: mt6397keys {
> >>   compatible = "mediatek,mt6397-keys";
> >>   mediatek,long-press-mode = <1>;
> >>   mediatek,long-press-seconds = <0>;
> >>
> >>   power@0 {
> >>   linux,code = <116>;
> 
> linux,keycodes
> 
> Also, you either need a reg property with "0" or drop the unit address.

There is no need to add reg property here, I'll drop the unit address.

Thank you.
> 
> >>   wakeup-source;
> >>   };
> >>
> >>   home@0 {
> > should be home@1 {
> >>   linux,code = <114>;
> >>   };
> >> };
> >>
> >> Thank you.
> >>
> >> >
> >> > Rob
> >>
> >
> >




Re: [PATCH v4 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-09-23 Thread Chen Zhong
Sorry for the typo.

On Sat, 2017-09-23 at 14:38 +0800, Chen Zhong wrote:
> On Wed, 2017-09-20 at 15:53 -0500, Rob Herring wrote:
> > On Sun, Sep 17, 2017 at 04:00:49PM +0800, Chen Zhong wrote:
> > > This patch adds the device tree binding documentation for the MediaTek
> > > pmic keys found on PMIC MT6397/MT6323.
> > > 
> > > Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
> > > ---
> > >  .../devicetree/bindings/input/mtk-pmic-keys.txt|   41 
> > > 
> > >  1 file changed, 41 insertions(+)
> > >  create mode 100644 
> > > Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > > 
> > > diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
> > > b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > > new file mode 100644
> > > index 000..fd48ff7
> > > --- /dev/null
> > > +++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > > @@ -0,0 +1,41 @@
> > > +MediaTek MT6397/MT6323 PMIC Keys Device Driver
> > > +
> > > +There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
> > > +and homekey. The key functions are defined as the subnode of the function
> > > +node provided by MT6397/MT6323 PMIC that is being defined as one kind
> > > +of Muti-Function Device (MFD)
> > > +
> > > +For MT6397/MT6323 MFD bindings see:
> > > +Documentation/devicetree/bindings/mfd/mt6397.txt
> > > +
> > > +Required properties:
> > > +- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
> > > +- linux,keycodes: Specifies the numeric keycode values to
> > > + be used for reporting keys presses. The array can
> > > + contain up to 2 entries.
> > > +
> > > +Optional Properties:
> > > +- mediatek,wakeup-keys: Specifies each key can be used as a wakeup source
> > > + or not. This can be customized depends on board design.
> > 
> > I think this should be a common property if we're going to put into DT. 
> > Something like "wakeup-scancodes" to be clear the values are the raw 
> > scancodes. Alternatively, we could list Linux keycodes instead with 
> > something like "linux,wakeup-keycodes".
> > 
> > > +- wakeup-source: PMIC keys can be used as wakeup sources.
> > 
> > Just "See ../power/wakeup-source.txt" for the description.
> > 
> > > +- mediatek,long-press-mode: Long press key shutdown setting, 1 for
> > > + pwrkey only, 2 for pwrkey/homekey together, others for disabled.
> > > +- debounce-interval: Long press key shutdown debouncing interval time
> > > + in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 
> > > 0.
> > 
> > This property units should be in milliseconds. However, this doesn't 
> > sound like debounce filtering time if 5-14 seconds. That sounds like 
> > forced power off time (i.e. for a hung device). This also should be 
> > common. I imagine we already have some drivers with similar properties.
> 
> Hi Rob,
> 
> I searched in kernel documents and found a similar usage in
> "ti,palmas-pwrbutton.txt"
> "- ti,palmas-long-press-seconds: Duration in seconds which the power
>   button should be kept pressed for Palmas to power off automatically."
> 
> Could I just wrote it like this?
> mediatek,long-press-seconds = <0>;
> 
> And for the wakeup source part, how about Dmitry's suggestion? 
> The whole device node would be:
> 
> mt6397keys: mt6397keys {
>   compatible = "mediatek,mt6397-keys";
>   mediatek,long-press-mode = <1>;
>   mediatek,long-press-seconds = <0>;
>   
>   power@0 {
>   linux,code = <116>;
>   wakeup-source;
>   };
> 
>   home@0 {
should be home@1 {
>   linux,code = <114>;
>   };
> };
> 
> Thank you.
> 
> > 
> > Rob
> 




Re: [PATCH v4 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-09-23 Thread Chen Zhong
Sorry for the typo.

On Sat, 2017-09-23 at 14:38 +0800, Chen Zhong wrote:
> On Wed, 2017-09-20 at 15:53 -0500, Rob Herring wrote:
> > On Sun, Sep 17, 2017 at 04:00:49PM +0800, Chen Zhong wrote:
> > > This patch adds the device tree binding documentation for the MediaTek
> > > pmic keys found on PMIC MT6397/MT6323.
> > > 
> > > Signed-off-by: Chen Zhong 
> > > ---
> > >  .../devicetree/bindings/input/mtk-pmic-keys.txt|   41 
> > > 
> > >  1 file changed, 41 insertions(+)
> > >  create mode 100644 
> > > Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > > 
> > > diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
> > > b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > > new file mode 100644
> > > index 000..fd48ff7
> > > --- /dev/null
> > > +++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > > @@ -0,0 +1,41 @@
> > > +MediaTek MT6397/MT6323 PMIC Keys Device Driver
> > > +
> > > +There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
> > > +and homekey. The key functions are defined as the subnode of the function
> > > +node provided by MT6397/MT6323 PMIC that is being defined as one kind
> > > +of Muti-Function Device (MFD)
> > > +
> > > +For MT6397/MT6323 MFD bindings see:
> > > +Documentation/devicetree/bindings/mfd/mt6397.txt
> > > +
> > > +Required properties:
> > > +- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
> > > +- linux,keycodes: Specifies the numeric keycode values to
> > > + be used for reporting keys presses. The array can
> > > + contain up to 2 entries.
> > > +
> > > +Optional Properties:
> > > +- mediatek,wakeup-keys: Specifies each key can be used as a wakeup source
> > > + or not. This can be customized depends on board design.
> > 
> > I think this should be a common property if we're going to put into DT. 
> > Something like "wakeup-scancodes" to be clear the values are the raw 
> > scancodes. Alternatively, we could list Linux keycodes instead with 
> > something like "linux,wakeup-keycodes".
> > 
> > > +- wakeup-source: PMIC keys can be used as wakeup sources.
> > 
> > Just "See ../power/wakeup-source.txt" for the description.
> > 
> > > +- mediatek,long-press-mode: Long press key shutdown setting, 1 for
> > > + pwrkey only, 2 for pwrkey/homekey together, others for disabled.
> > > +- debounce-interval: Long press key shutdown debouncing interval time
> > > + in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 
> > > 0.
> > 
> > This property units should be in milliseconds. However, this doesn't 
> > sound like debounce filtering time if 5-14 seconds. That sounds like 
> > forced power off time (i.e. for a hung device). This also should be 
> > common. I imagine we already have some drivers with similar properties.
> 
> Hi Rob,
> 
> I searched in kernel documents and found a similar usage in
> "ti,palmas-pwrbutton.txt"
> "- ti,palmas-long-press-seconds: Duration in seconds which the power
>   button should be kept pressed for Palmas to power off automatically."
> 
> Could I just wrote it like this?
> mediatek,long-press-seconds = <0>;
> 
> And for the wakeup source part, how about Dmitry's suggestion? 
> The whole device node would be:
> 
> mt6397keys: mt6397keys {
>   compatible = "mediatek,mt6397-keys";
>   mediatek,long-press-mode = <1>;
>   mediatek,long-press-seconds = <0>;
>   
>   power@0 {
>   linux,code = <116>;
>   wakeup-source;
>   };
> 
>   home@0 {
should be home@1 {
>   linux,code = <114>;
>   };
> };
> 
> Thank you.
> 
> > 
> > Rob
> 




Re: [PATCH v4 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-09-23 Thread Chen Zhong
On Wed, 2017-09-20 at 15:53 -0500, Rob Herring wrote:
> On Sun, Sep 17, 2017 at 04:00:49PM +0800, Chen Zhong wrote:
> > This patch adds the device tree binding documentation for the MediaTek
> > pmic keys found on PMIC MT6397/MT6323.
> > 
> > Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
> > ---
> >  .../devicetree/bindings/input/mtk-pmic-keys.txt|   41 
> > 
> >  1 file changed, 41 insertions(+)
> >  create mode 100644 
> > Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
> > b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > new file mode 100644
> > index 000..fd48ff7
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > @@ -0,0 +1,41 @@
> > +MediaTek MT6397/MT6323 PMIC Keys Device Driver
> > +
> > +There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
> > +and homekey. The key functions are defined as the subnode of the function
> > +node provided by MT6397/MT6323 PMIC that is being defined as one kind
> > +of Muti-Function Device (MFD)
> > +
> > +For MT6397/MT6323 MFD bindings see:
> > +Documentation/devicetree/bindings/mfd/mt6397.txt
> > +
> > +Required properties:
> > +- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
> > +- linux,keycodes: Specifies the numeric keycode values to
> > +   be used for reporting keys presses. The array can
> > +   contain up to 2 entries.
> > +
> > +Optional Properties:
> > +- mediatek,wakeup-keys: Specifies each key can be used as a wakeup source
> > +   or not. This can be customized depends on board design.
> 
> I think this should be a common property if we're going to put into DT. 
> Something like "wakeup-scancodes" to be clear the values are the raw 
> scancodes. Alternatively, we could list Linux keycodes instead with 
> something like "linux,wakeup-keycodes".
> 
> > +- wakeup-source: PMIC keys can be used as wakeup sources.
> 
> Just "See ../power/wakeup-source.txt" for the description.
> 
> > +- mediatek,long-press-mode: Long press key shutdown setting, 1 for
> > +   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
> > +- debounce-interval: Long press key shutdown debouncing interval time
> > +   in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 
> > 0.
> 
> This property units should be in milliseconds. However, this doesn't 
> sound like debounce filtering time if 5-14 seconds. That sounds like 
> forced power off time (i.e. for a hung device). This also should be 
> common. I imagine we already have some drivers with similar properties.

Hi Rob,

I searched in kernel documents and found a similar usage in
"ti,palmas-pwrbutton.txt"
"- ti,palmas-long-press-seconds: Duration in seconds which the power
  button should be kept pressed for Palmas to power off automatically."

Could I just wrote it like this?
mediatek,long-press-seconds = <0>;

And for the wakeup source part, how about Dmitry's suggestion? 
The whole device node would be:

mt6397keys: mt6397keys {
compatible = "mediatek,mt6397-keys";
mediatek,long-press-mode = <1>;
mediatek,long-press-seconds = <0>;

power@0 {
linux,code = <116>;
wakeup-source;
};

home@0 {
linux,code = <114>;
};
};

Thank you.

> 
> Rob




Re: [PATCH v4 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-09-23 Thread Chen Zhong
On Wed, 2017-09-20 at 15:53 -0500, Rob Herring wrote:
> On Sun, Sep 17, 2017 at 04:00:49PM +0800, Chen Zhong wrote:
> > This patch adds the device tree binding documentation for the MediaTek
> > pmic keys found on PMIC MT6397/MT6323.
> > 
> > Signed-off-by: Chen Zhong 
> > ---
> >  .../devicetree/bindings/input/mtk-pmic-keys.txt|   41 
> > 
> >  1 file changed, 41 insertions(+)
> >  create mode 100644 
> > Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
> > b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > new file mode 100644
> > index 000..fd48ff7
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > @@ -0,0 +1,41 @@
> > +MediaTek MT6397/MT6323 PMIC Keys Device Driver
> > +
> > +There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
> > +and homekey. The key functions are defined as the subnode of the function
> > +node provided by MT6397/MT6323 PMIC that is being defined as one kind
> > +of Muti-Function Device (MFD)
> > +
> > +For MT6397/MT6323 MFD bindings see:
> > +Documentation/devicetree/bindings/mfd/mt6397.txt
> > +
> > +Required properties:
> > +- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
> > +- linux,keycodes: Specifies the numeric keycode values to
> > +   be used for reporting keys presses. The array can
> > +   contain up to 2 entries.
> > +
> > +Optional Properties:
> > +- mediatek,wakeup-keys: Specifies each key can be used as a wakeup source
> > +   or not. This can be customized depends on board design.
> 
> I think this should be a common property if we're going to put into DT. 
> Something like "wakeup-scancodes" to be clear the values are the raw 
> scancodes. Alternatively, we could list Linux keycodes instead with 
> something like "linux,wakeup-keycodes".
> 
> > +- wakeup-source: PMIC keys can be used as wakeup sources.
> 
> Just "See ../power/wakeup-source.txt" for the description.
> 
> > +- mediatek,long-press-mode: Long press key shutdown setting, 1 for
> > +   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
> > +- debounce-interval: Long press key shutdown debouncing interval time
> > +   in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 
> > 0.
> 
> This property units should be in milliseconds. However, this doesn't 
> sound like debounce filtering time if 5-14 seconds. That sounds like 
> forced power off time (i.e. for a hung device). This also should be 
> common. I imagine we already have some drivers with similar properties.

Hi Rob,

I searched in kernel documents and found a similar usage in
"ti,palmas-pwrbutton.txt"
"- ti,palmas-long-press-seconds: Duration in seconds which the power
  button should be kept pressed for Palmas to power off automatically."

Could I just wrote it like this?
mediatek,long-press-seconds = <0>;

And for the wakeup source part, how about Dmitry's suggestion? 
The whole device node would be:

mt6397keys: mt6397keys {
compatible = "mediatek,mt6397-keys";
mediatek,long-press-mode = <1>;
mediatek,long-press-seconds = <0>;

power@0 {
linux,code = <116>;
wakeup-source;
};

home@0 {
linux,code = <114>;
};
};

Thank you.

> 
> Rob




[PATCH v4 4/5] input: Add MediaTek PMIC keys support

2017-09-17 Thread Chen Zhong
This patch add support to handle MediaTek PMIC MT6397/MT6323 key
interrupts including pwrkey and homekey, also add setting for
long press key shutdown behavior.

Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 drivers/input/keyboard/Kconfig |9 +
 drivers/input/keyboard/Makefile|1 +
 drivers/input/keyboard/mtk-pmic-keys.c |  354 
 3 files changed, 364 insertions(+)
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 4c4ab1c..bd4e20a 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -756,4 +756,13 @@ config KEYBOARD_BCM
  To compile this driver as a module, choose M here: the
  module will be called bcm-keypad.
 
+config KEYBOARD_MTK_PMIC
+   tristate "MediaTek PMIC keys support"
+   depends on MFD_MT6397
+   help
+ Say Y here if you want to use the pmic keys (powerkey/homekey).
+
+ To compile this driver as a module, choose M here: the
+ module will be called pmic-keys.
+
 endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index d2338ba..20c0b98 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
 obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
 obj-$(CONFIG_KEYBOARD_MPR121)  += mpr121_touchkey.o
+obj-$(CONFIG_KEYBOARD_MTK_PMIC)+= mtk-pmic-keys.o
 obj-$(CONFIG_KEYBOARD_NEWTON)  += newtonkbd.o
 obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
 obj-$(CONFIG_KEYBOARD_NSPIRE)  += nspire-keypad.o
diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
b/drivers/input/keyboard/mtk-pmic-keys.c
new file mode 100644
index 000..23b6ee4
--- /dev/null
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -0,0 +1,354 @@
+/*
+ * Copyright (C) 2017 MediaTek, Inc.
+ *
+ * Author: Chen Zhong <chen.zh...@mediatek.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MTK_PMIC_PWRKEY_RST_EN_MASK0x1
+#define MTK_PMIC_PWRKEY_RST_EN_SHIFT   6
+#define MTK_PMIC_HOMEKEY_RST_EN_MASK   0x1
+#define MTK_PMIC_HOMEKEY_RST_EN_SHIFT  5
+#define MTK_PMIC_RST_DU_MASK   0x3
+#define MTK_PMIC_RST_DU_SHIFT  8
+
+#define MTK_PMIC_PWRKEY_RST\
+   (MTK_PMIC_PWRKEY_RST_EN_MASK << MTK_PMIC_PWRKEY_RST_EN_SHIFT)
+#define MTK_PMIC_HOMEKEY_RST   \
+   (MTK_PMIC_HOMEKEY_RST_EN_MASK << MTK_PMIC_HOMEKEY_RST_EN_SHIFT)
+
+#define MTK_PMIC_PWRKEY_INDEX  0
+#define MTK_PMIC_HOMEKEY_INDEX 1
+#define MTK_PMIC_MAX_KEY_COUNT 2
+
+struct mtk_pmic_keys_regs {
+   u32 deb_reg;
+   u32 deb_mask;
+   u32 intsel_reg;
+   u32 intsel_mask;
+};
+
+#define MTK_PMIC_KEYS_REGS(_deb_reg, _deb_mask,\
+   _intsel_reg, _intsel_mask)  \
+{  \
+   .deb_reg= _deb_reg, \
+   .deb_mask   = _deb_mask,\
+   .intsel_reg = _intsel_reg,  \
+   .intsel_mask= _intsel_mask, \
+}
+
+struct mtk_pmic_regs {
+   const struct mtk_pmic_keys_regs keys_regs[MTK_PMIC_MAX_KEY_COUNT];
+   u32 pmic_rst_reg;
+};
+
+static const struct mtk_pmic_regs mt6397_regs = {
+   .keys_regs[MTK_PMIC_PWRKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6397_CHRSTATUS,
+   0x8, MT6397_INT_RSV, 0x10),
+   .keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6397_OCSTATUS2,
+   0x10, MT6397_INT_RSV, 0x8),
+   .pmic_rst_reg = MT6397_TOP_RST_MISC,
+};
+
+static const struct mtk_pmic_regs mt6323_regs = {
+   .keys_regs[MTK_PMIC_PWRKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x2, MT6323_INT_MISC_CON, 0x10),
+   .keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x4, MT6323_INT_MISC_CON, 0x8),
+   .pmic_rst_reg = MT6323_TOP_RST_MISC,
+};
+
+struct mtk_pmic_keys_info {
+   struct mtk_pmic_keys *keys;
+   const struct mtk_pmic_keys_regs *regs;
+   unsigned int keycode;
+   int irq;
+   bool wak

[PATCH v4 5/5] mfd: mt6397: Add PMIC keys support to MT6397 driver

2017-09-17 Thread Chen Zhong
This patch adds compatible strings and interrupts for pmic keys
which serves as child device of MFD.

Acked-for-MFD-by: Lee Jones <lee.jo...@linaro.org>
Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 drivers/mfd/mt6397-core.c |   22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 6546d7f..77b64bd 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -43,6 +43,16 @@
},
 };
 
+static const struct resource mt6323_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_PWRKEY),
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_FCHRKEY),
+};
+
+static const struct resource mt6397_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6397_IRQ_PWRKEY),
+   DEFINE_RES_IRQ(MT6397_IRQ_HOMEKEY),
+};
+
 static const struct mfd_cell mt6323_devs[] = {
{
.name = "mt6323-regulator",
@@ -50,6 +60,11 @@
}, {
.name = "mt6323-led",
.of_compatible = "mediatek,mt6323-led"
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6323_keys_resources),
+   .resources = mt6323_keys_resources,
+   .of_compatible = "mediatek,mt6323-keys"
},
 };
 
@@ -71,7 +86,12 @@
}, {
.name = "mt6397-pinctrl",
.of_compatible = "mediatek,mt6397-pinctrl",
-   },
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6397_keys_resources),
+   .resources = mt6397_keys_resources,
+   .of_compatible = "mediatek,mt6397-keys"
+   }
 };
 
 static void mt6397_irq_lock(struct irq_data *data)
-- 
1.7.9.5



[PATCH v4 4/5] input: Add MediaTek PMIC keys support

2017-09-17 Thread Chen Zhong
This patch add support to handle MediaTek PMIC MT6397/MT6323 key
interrupts including pwrkey and homekey, also add setting for
long press key shutdown behavior.

Signed-off-by: Chen Zhong 
---
 drivers/input/keyboard/Kconfig |9 +
 drivers/input/keyboard/Makefile|1 +
 drivers/input/keyboard/mtk-pmic-keys.c |  354 
 3 files changed, 364 insertions(+)
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 4c4ab1c..bd4e20a 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -756,4 +756,13 @@ config KEYBOARD_BCM
  To compile this driver as a module, choose M here: the
  module will be called bcm-keypad.
 
+config KEYBOARD_MTK_PMIC
+   tristate "MediaTek PMIC keys support"
+   depends on MFD_MT6397
+   help
+ Say Y here if you want to use the pmic keys (powerkey/homekey).
+
+ To compile this driver as a module, choose M here: the
+ module will be called pmic-keys.
+
 endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index d2338ba..20c0b98 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
 obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
 obj-$(CONFIG_KEYBOARD_MPR121)  += mpr121_touchkey.o
+obj-$(CONFIG_KEYBOARD_MTK_PMIC)+= mtk-pmic-keys.o
 obj-$(CONFIG_KEYBOARD_NEWTON)  += newtonkbd.o
 obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
 obj-$(CONFIG_KEYBOARD_NSPIRE)  += nspire-keypad.o
diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
b/drivers/input/keyboard/mtk-pmic-keys.c
new file mode 100644
index 000..23b6ee4
--- /dev/null
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -0,0 +1,354 @@
+/*
+ * Copyright (C) 2017 MediaTek, Inc.
+ *
+ * Author: Chen Zhong 
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MTK_PMIC_PWRKEY_RST_EN_MASK0x1
+#define MTK_PMIC_PWRKEY_RST_EN_SHIFT   6
+#define MTK_PMIC_HOMEKEY_RST_EN_MASK   0x1
+#define MTK_PMIC_HOMEKEY_RST_EN_SHIFT  5
+#define MTK_PMIC_RST_DU_MASK   0x3
+#define MTK_PMIC_RST_DU_SHIFT  8
+
+#define MTK_PMIC_PWRKEY_RST\
+   (MTK_PMIC_PWRKEY_RST_EN_MASK << MTK_PMIC_PWRKEY_RST_EN_SHIFT)
+#define MTK_PMIC_HOMEKEY_RST   \
+   (MTK_PMIC_HOMEKEY_RST_EN_MASK << MTK_PMIC_HOMEKEY_RST_EN_SHIFT)
+
+#define MTK_PMIC_PWRKEY_INDEX  0
+#define MTK_PMIC_HOMEKEY_INDEX 1
+#define MTK_PMIC_MAX_KEY_COUNT 2
+
+struct mtk_pmic_keys_regs {
+   u32 deb_reg;
+   u32 deb_mask;
+   u32 intsel_reg;
+   u32 intsel_mask;
+};
+
+#define MTK_PMIC_KEYS_REGS(_deb_reg, _deb_mask,\
+   _intsel_reg, _intsel_mask)  \
+{  \
+   .deb_reg= _deb_reg, \
+   .deb_mask   = _deb_mask,\
+   .intsel_reg = _intsel_reg,  \
+   .intsel_mask= _intsel_mask, \
+}
+
+struct mtk_pmic_regs {
+   const struct mtk_pmic_keys_regs keys_regs[MTK_PMIC_MAX_KEY_COUNT];
+   u32 pmic_rst_reg;
+};
+
+static const struct mtk_pmic_regs mt6397_regs = {
+   .keys_regs[MTK_PMIC_PWRKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6397_CHRSTATUS,
+   0x8, MT6397_INT_RSV, 0x10),
+   .keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6397_OCSTATUS2,
+   0x10, MT6397_INT_RSV, 0x8),
+   .pmic_rst_reg = MT6397_TOP_RST_MISC,
+};
+
+static const struct mtk_pmic_regs mt6323_regs = {
+   .keys_regs[MTK_PMIC_PWRKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x2, MT6323_INT_MISC_CON, 0x10),
+   .keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
+   MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x4, MT6323_INT_MISC_CON, 0x8),
+   .pmic_rst_reg = MT6323_TOP_RST_MISC,
+};
+
+struct mtk_pmic_keys_info {
+   struct mtk_pmic_keys *keys;
+   const struct mtk_pmic_keys_regs *regs;
+   unsigned int keycode;
+   int irq;
+   bool wakeup:1;
+};
+
+struct mtk_pmic_keys {
+   struct input_dev *inp

[PATCH v4 5/5] mfd: mt6397: Add PMIC keys support to MT6397 driver

2017-09-17 Thread Chen Zhong
This patch adds compatible strings and interrupts for pmic keys
which serves as child device of MFD.

Acked-for-MFD-by: Lee Jones 
Signed-off-by: Chen Zhong 
---
 drivers/mfd/mt6397-core.c |   22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 6546d7f..77b64bd 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -43,6 +43,16 @@
},
 };
 
+static const struct resource mt6323_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_PWRKEY),
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_FCHRKEY),
+};
+
+static const struct resource mt6397_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6397_IRQ_PWRKEY),
+   DEFINE_RES_IRQ(MT6397_IRQ_HOMEKEY),
+};
+
 static const struct mfd_cell mt6323_devs[] = {
{
.name = "mt6323-regulator",
@@ -50,6 +60,11 @@
}, {
.name = "mt6323-led",
.of_compatible = "mediatek,mt6323-led"
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6323_keys_resources),
+   .resources = mt6323_keys_resources,
+   .of_compatible = "mediatek,mt6323-keys"
},
 };
 
@@ -71,7 +86,12 @@
}, {
.name = "mt6397-pinctrl",
.of_compatible = "mediatek,mt6397-pinctrl",
-   },
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6397_keys_resources),
+   .resources = mt6397_keys_resources,
+   .of_compatible = "mediatek,mt6397-keys"
+   }
 };
 
 static void mt6397_irq_lock(struct irq_data *data)
-- 
1.7.9.5



[PATCH v4 3/5] dt-bindings: mfd: Add bindings for the keys as subnode of PMIC

2017-09-17 Thread Chen Zhong
This patch adds documentation for device tree bindings for keys support
as the subnode of MT6397/MT6323 PMIC.

Acked-by: Rob Herring <r...@kernel.org>
Acked-for-MFD-by: Lee Jones <lee.jo...@linaro.org>
Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 Documentation/devicetree/bindings/mfd/mt6397.txt |6 ++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/mt6397.txt 
b/Documentation/devicetree/bindings/mfd/mt6397.txt
index 522a3bb..d1df77f 100644
--- a/Documentation/devicetree/bindings/mfd/mt6397.txt
+++ b/Documentation/devicetree/bindings/mfd/mt6397.txt
@@ -7,6 +7,7 @@ MT6397/MT6323 is a multifunction device with the following sub 
modules:
 - GPIO
 - Clock
 - LED
+- Keys
 
 It is interfaced to host controller using SPI interface by a proprietary 
hardware
 called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.
@@ -40,6 +41,11 @@ Optional subnodes:
- compatible: "mediatek,mt6323-led"
see Documentation/devicetree/bindings/leds/leds-mt6323.txt
 
+- keys
+   Required properties:
+   - compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+   see Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
+
 Example:
pwrap: pwrap@1000f000 {
compatible = "mediatek,mt8135-pwrap";
-- 
1.7.9.5



[PATCH v4 3/5] dt-bindings: mfd: Add bindings for the keys as subnode of PMIC

2017-09-17 Thread Chen Zhong
This patch adds documentation for device tree bindings for keys support
as the subnode of MT6397/MT6323 PMIC.

Acked-by: Rob Herring 
Acked-for-MFD-by: Lee Jones 
Signed-off-by: Chen Zhong 
---
 Documentation/devicetree/bindings/mfd/mt6397.txt |6 ++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/mt6397.txt 
b/Documentation/devicetree/bindings/mfd/mt6397.txt
index 522a3bb..d1df77f 100644
--- a/Documentation/devicetree/bindings/mfd/mt6397.txt
+++ b/Documentation/devicetree/bindings/mfd/mt6397.txt
@@ -7,6 +7,7 @@ MT6397/MT6323 is a multifunction device with the following sub 
modules:
 - GPIO
 - Clock
 - LED
+- Keys
 
 It is interfaced to host controller using SPI interface by a proprietary 
hardware
 called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.
@@ -40,6 +41,11 @@ Optional subnodes:
- compatible: "mediatek,mt6323-led"
see Documentation/devicetree/bindings/leds/leds-mt6323.txt
 
+- keys
+   Required properties:
+   - compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+   see Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
+
 Example:
pwrap: pwrap@1000f000 {
compatible = "mediatek,mt8135-pwrap";
-- 
1.7.9.5



[PATCH v4 1/5] mfd: mt6397: create irq mappings in mfd core driver

2017-09-17 Thread Chen Zhong
The core driver should create and manage irq mappings instead of
leaf drivers. This patch change to pass irq domain to
devm_mfd_add_devices() and it will create mapping for irq resources
automatically. And remove irq mapping in rtc driver since this has
been done in core driver.

Acked-for-MFD-by: Lee Jones <lee.jo...@linaro.org>
Acked-by: Alexandre Belloni <alexandre.bell...@free-electrons.com>
Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 drivers/mfd/mt6397-core.c |4 ++--
 drivers/rtc/rtc-mt6397.c  |7 +++
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 04a601f..6546d7f 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6323_devs,
   ARRAY_SIZE(mt6323_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
case MT6397_CID_CODE:
@@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6397_devs,
   ARRAY_SIZE(mt6397_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
default:
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 1a61fa5..385f830 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -322,10 +322,9 @@ static int mtk_rtc_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
rtc->addr_base = res->start;
 
-   res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
-   if (rtc->irq <= 0)
-   return -EINVAL;
+   rtc->irq = platform_get_irq(pdev, 0);
+   if (rtc->irq < 0)
+   return rtc->irq;
 
rtc->regmap = mt6397_chip->regmap;
rtc->dev = >dev;
-- 
1.7.9.5



[PATCH v4 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-09-17 Thread Chen Zhong
This patch adds the device tree binding documentation for the MediaTek
pmic keys found on PMIC MT6397/MT6323.

Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 .../devicetree/bindings/input/mtk-pmic-keys.txt|   41 
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt

diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
new file mode 100644
index 000..fd48ff7
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
@@ -0,0 +1,41 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: Specifies the numeric keycode values to
+   be used for reporting keys presses. The array can
+   contain up to 2 entries.
+
+Optional Properties:
+- mediatek,wakeup-keys: Specifies each key can be used as a wakeup source
+   or not. This can be customized depends on board design.
+- wakeup-source: PMIC keys can be used as wakeup sources.
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- debounce-interval: Long press key shutdown debouncing interval time
+   in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 
0.
+
+Example:
+
+   pmic: mt6397 {
+   compatible = "mediatek,mt6397";
+
+   ...
+
+   mt6397keys: mt6397keys {
+   compatible = "mediatek,mt6397-keys";
+   linux,keycodes = <116>, <114>;
+   mediatek,wakeup-keys = <1>, <0>;
+   wakeup-source;
+   mediatek,long-press-mode = <1>;
+   debounce-interval = <0>;
+   };
+   };
-- 
1.7.9.5



[PATCH v4 1/5] mfd: mt6397: create irq mappings in mfd core driver

2017-09-17 Thread Chen Zhong
The core driver should create and manage irq mappings instead of
leaf drivers. This patch change to pass irq domain to
devm_mfd_add_devices() and it will create mapping for irq resources
automatically. And remove irq mapping in rtc driver since this has
been done in core driver.

Acked-for-MFD-by: Lee Jones 
Acked-by: Alexandre Belloni 
Signed-off-by: Chen Zhong 
---
 drivers/mfd/mt6397-core.c |4 ++--
 drivers/rtc/rtc-mt6397.c  |7 +++
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 04a601f..6546d7f 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6323_devs,
   ARRAY_SIZE(mt6323_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
case MT6397_CID_CODE:
@@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6397_devs,
   ARRAY_SIZE(mt6397_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
default:
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 1a61fa5..385f830 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -322,10 +322,9 @@ static int mtk_rtc_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
rtc->addr_base = res->start;
 
-   res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
-   if (rtc->irq <= 0)
-   return -EINVAL;
+   rtc->irq = platform_get_irq(pdev, 0);
+   if (rtc->irq < 0)
+   return rtc->irq;
 
rtc->regmap = mt6397_chip->regmap;
rtc->dev = >dev;
-- 
1.7.9.5



[PATCH v4 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-09-17 Thread Chen Zhong
This patch adds the device tree binding documentation for the MediaTek
pmic keys found on PMIC MT6397/MT6323.

Signed-off-by: Chen Zhong 
---
 .../devicetree/bindings/input/mtk-pmic-keys.txt|   41 
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt

diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
new file mode 100644
index 000..fd48ff7
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
@@ -0,0 +1,41 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: Specifies the numeric keycode values to
+   be used for reporting keys presses. The array can
+   contain up to 2 entries.
+
+Optional Properties:
+- mediatek,wakeup-keys: Specifies each key can be used as a wakeup source
+   or not. This can be customized depends on board design.
+- wakeup-source: PMIC keys can be used as wakeup sources.
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- debounce-interval: Long press key shutdown debouncing interval time
+   in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 
0.
+
+Example:
+
+   pmic: mt6397 {
+   compatible = "mediatek,mt6397";
+
+   ...
+
+   mt6397keys: mt6397keys {
+   compatible = "mediatek,mt6397-keys";
+   linux,keycodes = <116>, <114>;
+   mediatek,wakeup-keys = <1>, <0>;
+   wakeup-source;
+   mediatek,long-press-mode = <1>;
+   debounce-interval = <0>;
+   };
+   };
-- 
1.7.9.5



[PATCH v4 0/5] Add MediaTek PMIC keys support

2017-09-17 Thread Chen Zhong
Changes since v3:
- make the naming to be consistent as mtk_pmic or MTK_PMIC
- add suspend/resume functions to enable/disable irq
- change binding properties to define wakeup sources

Changes since v2:
- use standard properties for keycodes and debounce time
- change to use platform_get_irq in leaf drivers
- use better ways to define IRQ resources

Changes since v1:
- create irq mappings in mfd core driver instead of leaf drivers
- remove some unused parts in mtk-pmic-keys driver

MediaTek PMIC are multi-function devices that can handle key interrupts,
typically there are two keys attached to PMIC, which called pwrkey
and homekey. PWRKEY usually used to wake up system from sleep. Homekey
can used as volume down key due to board design. Long press keys can
shutdown PMIC, the mode can be choose to be one key only or two keys
together.
This series add support for key functions for MediaTek PMIC MT6397/MT6323.

Chen Zhong (5):
  mfd: mt6397: create irq mappings in mfd core driver
  dt-bindings: input: Add document bindings for mtk-pmic-keys
  dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
  input: Add MediaTek PMIC keys support
  mfd: mt6397: Add PMIC keys support to MT6397 driver

 .../devicetree/bindings/input/mtk-pmic-keys.txt|   41 +++
 Documentation/devicetree/bindings/mfd/mt6397.txt   |6 +
 drivers/input/keyboard/Kconfig |9 +
 drivers/input/keyboard/Makefile|1 +
 drivers/input/keyboard/mtk-pmic-keys.c |  354 
 drivers/mfd/mt6397-core.c  |   26 +-
 drivers/rtc/rtc-mt6397.c   |7 +-
 7 files changed, 437 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

--
1.7.9.5




[PATCH v4 0/5] Add MediaTek PMIC keys support

2017-09-17 Thread Chen Zhong
Changes since v3:
- make the naming to be consistent as mtk_pmic or MTK_PMIC
- add suspend/resume functions to enable/disable irq
- change binding properties to define wakeup sources

Changes since v2:
- use standard properties for keycodes and debounce time
- change to use platform_get_irq in leaf drivers
- use better ways to define IRQ resources

Changes since v1:
- create irq mappings in mfd core driver instead of leaf drivers
- remove some unused parts in mtk-pmic-keys driver

MediaTek PMIC are multi-function devices that can handle key interrupts,
typically there are two keys attached to PMIC, which called pwrkey
and homekey. PWRKEY usually used to wake up system from sleep. Homekey
can used as volume down key due to board design. Long press keys can
shutdown PMIC, the mode can be choose to be one key only or two keys
together.
This series add support for key functions for MediaTek PMIC MT6397/MT6323.

Chen Zhong (5):
  mfd: mt6397: create irq mappings in mfd core driver
  dt-bindings: input: Add document bindings for mtk-pmic-keys
  dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
  input: Add MediaTek PMIC keys support
  mfd: mt6397: Add PMIC keys support to MT6397 driver

 .../devicetree/bindings/input/mtk-pmic-keys.txt|   41 +++
 Documentation/devicetree/bindings/mfd/mt6397.txt   |6 +
 drivers/input/keyboard/Kconfig |9 +
 drivers/input/keyboard/Makefile|1 +
 drivers/input/keyboard/mtk-pmic-keys.c |  354 
 drivers/mfd/mt6397-core.c  |   26 +-
 drivers/rtc/rtc-mt6397.c   |7 +-
 7 files changed, 437 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

--
1.7.9.5




Re: [PATCH v3 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-09-06 Thread Chen Zhong
On Tue, 2017-09-05 at 11:05 -0500, Rob Herring wrote:
> On Fri, Sep 1, 2017 at 9:16 PM, Chen Zhong <chen.zh...@mediatek.com> wrote:
> > On Thu, 2017-08-31 at 14:52 -0500, Rob Herring wrote:
> >> On Fri, Aug 25, 2017 at 02:32:30PM +0800, Chen Zhong wrote:
> >> > This patch adds the device tree binding documentation for the MediaTek
> >> > pmic keys found on PMIC MT6397/MT6323.
> >> >
> >> > Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
> >> > ---
> >> >  .../devicetree/bindings/input/mtk-pmic-keys.txt|   38 
> >> > 
> >> >  1 file changed, 38 insertions(+)
> >> >  create mode 100644 
> >> > Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> >> >
> >> > diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
> >> > b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> >> > new file mode 100644
> >> > index 000..100ec44
> >> > --- /dev/null
> >> > +++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> >> > @@ -0,0 +1,38 @@
> >> > +MediaTek MT6397/MT6323 PMIC Keys Device Driver
> >> > +
> >> > +There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
> >> > +and homekey. The key functions are defined as the subnode of the 
> >> > function
> >> > +node provided by MT6397/MT6323 PMIC that is being defined as one kind
> >> > +of Muti-Function Device (MFD)
> >> > +
> >> > +For MT6397/MT6323 MFD bindings see:
> >> > +Documentation/devicetree/bindings/mfd/mt6397.txt
> >> > +
> >> > +Required properties:
> >> > +- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
> >> > +- linux,keycodes: Specifies the numeric keycode values to
> >> > +   be used for reporting keys presses. The array can
> >> > +   contain up to 2 entries.
> >> > +
> >> > +Optional Properties:
> >> > +- wakeup-source: each key can be used as a wakeup source.
> >>
> >> wakeup-source is defined as a boolean.
> >
> > Hi Rob,
> >
> > Could I modify it as this?
> >
> > mediatek,wakeup-keys = <1>, <0>;
> > wakeup-source;
> 
> What do the values and index signify? The power key is index 0 and the
> value 1 means enable wakeup? Or each value is the raw key (i.e.
> indexes in linux,keycode) that wakeup is enabled for?
> 
> I don't think this should be in DT really. It's really up to the user
> (i.e. userspace) to decide what keys cause wakeup (or maybe that's
> only suspend). If you default to the power key causes wakeup, do you
> really need to support different options?
> 
> If we do put this in DT, then it should be a common binding to specify
> keys that cause wake-up.
> 
> Rob

Hi Rob,

Yes, we want to describe that power key is index 0 and is a wakeup
source, homekey is index 1 and not a wakeup source.

Since power key and homekey are two real HW keys, customer can decide
which key to be the wakeup source or both due to their hw design, so we
put this in DT and can be different for different boards.

Thank you.

Chen




Re: [PATCH v3 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-09-06 Thread Chen Zhong
On Tue, 2017-09-05 at 11:05 -0500, Rob Herring wrote:
> On Fri, Sep 1, 2017 at 9:16 PM, Chen Zhong  wrote:
> > On Thu, 2017-08-31 at 14:52 -0500, Rob Herring wrote:
> >> On Fri, Aug 25, 2017 at 02:32:30PM +0800, Chen Zhong wrote:
> >> > This patch adds the device tree binding documentation for the MediaTek
> >> > pmic keys found on PMIC MT6397/MT6323.
> >> >
> >> > Signed-off-by: Chen Zhong 
> >> > ---
> >> >  .../devicetree/bindings/input/mtk-pmic-keys.txt|   38 
> >> > 
> >> >  1 file changed, 38 insertions(+)
> >> >  create mode 100644 
> >> > Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> >> >
> >> > diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
> >> > b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> >> > new file mode 100644
> >> > index 000..100ec44
> >> > --- /dev/null
> >> > +++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> >> > @@ -0,0 +1,38 @@
> >> > +MediaTek MT6397/MT6323 PMIC Keys Device Driver
> >> > +
> >> > +There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
> >> > +and homekey. The key functions are defined as the subnode of the 
> >> > function
> >> > +node provided by MT6397/MT6323 PMIC that is being defined as one kind
> >> > +of Muti-Function Device (MFD)
> >> > +
> >> > +For MT6397/MT6323 MFD bindings see:
> >> > +Documentation/devicetree/bindings/mfd/mt6397.txt
> >> > +
> >> > +Required properties:
> >> > +- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
> >> > +- linux,keycodes: Specifies the numeric keycode values to
> >> > +   be used for reporting keys presses. The array can
> >> > +   contain up to 2 entries.
> >> > +
> >> > +Optional Properties:
> >> > +- wakeup-source: each key can be used as a wakeup source.
> >>
> >> wakeup-source is defined as a boolean.
> >
> > Hi Rob,
> >
> > Could I modify it as this?
> >
> > mediatek,wakeup-keys = <1>, <0>;
> > wakeup-source;
> 
> What do the values and index signify? The power key is index 0 and the
> value 1 means enable wakeup? Or each value is the raw key (i.e.
> indexes in linux,keycode) that wakeup is enabled for?
> 
> I don't think this should be in DT really. It's really up to the user
> (i.e. userspace) to decide what keys cause wakeup (or maybe that's
> only suspend). If you default to the power key causes wakeup, do you
> really need to support different options?
> 
> If we do put this in DT, then it should be a common binding to specify
> keys that cause wake-up.
> 
> Rob

Hi Rob,

Yes, we want to describe that power key is index 0 and is a wakeup
source, homekey is index 1 and not a wakeup source.

Since power key and homekey are two real HW keys, customer can decide
which key to be the wakeup source or both due to their hw design, so we
put this in DT and can be different for different boards.

Thank you.

Chen




Re: [PATCH v3 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-09-01 Thread Chen Zhong
On Thu, 2017-08-31 at 14:52 -0500, Rob Herring wrote:
> On Fri, Aug 25, 2017 at 02:32:30PM +0800, Chen Zhong wrote:
> > This patch adds the device tree binding documentation for the MediaTek
> > pmic keys found on PMIC MT6397/MT6323.
> > 
> > Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
> > ---
> >  .../devicetree/bindings/input/mtk-pmic-keys.txt|   38 
> > 
> >  1 file changed, 38 insertions(+)
> >  create mode 100644 
> > Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
> > b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > new file mode 100644
> > index 000..100ec44
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > @@ -0,0 +1,38 @@
> > +MediaTek MT6397/MT6323 PMIC Keys Device Driver
> > +
> > +There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
> > +and homekey. The key functions are defined as the subnode of the function
> > +node provided by MT6397/MT6323 PMIC that is being defined as one kind
> > +of Muti-Function Device (MFD)
> > +
> > +For MT6397/MT6323 MFD bindings see:
> > +Documentation/devicetree/bindings/mfd/mt6397.txt
> > +
> > +Required properties:
> > +- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
> > +- linux,keycodes: Specifies the numeric keycode values to
> > +   be used for reporting keys presses. The array can
> > +   contain up to 2 entries.
> > +
> > +Optional Properties:
> > +- wakeup-source: each key can be used as a wakeup source.
> 
> wakeup-source is defined as a boolean.

Hi Rob,

Could I modify it as this?

mediatek,wakeup-keys = <1>, <0>;
wakeup-source;

Thanks.
> 
> > +- mediatek,long-press-mode: Long press key shutdown setting, 1 for
> > +   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
> > +- debounce-interval: Long press key shutdown debouncing interval time
> > +   in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 
> > 0.
> > +
> > +Example:
> > +
> > +   pmic: mt6397 {
> > +   compatible = "mediatek,mt6397";
> > +
> > +   ...
> > +
> > +   mt6397keys: mt6397keys {
> > +   compatible = "mediatek,mt6397-keys";
> > +   linux,keycodes = , ;
> > +   wakeup-source = <1>, <0>;
> > +   mediatek,long-press-mode = <1>;
> > +   debounce-interval = <0>;
> > +   };
> > +   };
> > -- 
> > 1.7.9.5
> > 




Re: [PATCH v3 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-09-01 Thread Chen Zhong
On Thu, 2017-08-31 at 14:52 -0500, Rob Herring wrote:
> On Fri, Aug 25, 2017 at 02:32:30PM +0800, Chen Zhong wrote:
> > This patch adds the device tree binding documentation for the MediaTek
> > pmic keys found on PMIC MT6397/MT6323.
> > 
> > Signed-off-by: Chen Zhong 
> > ---
> >  .../devicetree/bindings/input/mtk-pmic-keys.txt|   38 
> > 
> >  1 file changed, 38 insertions(+)
> >  create mode 100644 
> > Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
> > b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > new file mode 100644
> > index 000..100ec44
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > @@ -0,0 +1,38 @@
> > +MediaTek MT6397/MT6323 PMIC Keys Device Driver
> > +
> > +There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
> > +and homekey. The key functions are defined as the subnode of the function
> > +node provided by MT6397/MT6323 PMIC that is being defined as one kind
> > +of Muti-Function Device (MFD)
> > +
> > +For MT6397/MT6323 MFD bindings see:
> > +Documentation/devicetree/bindings/mfd/mt6397.txt
> > +
> > +Required properties:
> > +- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
> > +- linux,keycodes: Specifies the numeric keycode values to
> > +   be used for reporting keys presses. The array can
> > +   contain up to 2 entries.
> > +
> > +Optional Properties:
> > +- wakeup-source: each key can be used as a wakeup source.
> 
> wakeup-source is defined as a boolean.

Hi Rob,

Could I modify it as this?

mediatek,wakeup-keys = <1>, <0>;
wakeup-source;

Thanks.
> 
> > +- mediatek,long-press-mode: Long press key shutdown setting, 1 for
> > +   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
> > +- debounce-interval: Long press key shutdown debouncing interval time
> > +   in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 
> > 0.
> > +
> > +Example:
> > +
> > +   pmic: mt6397 {
> > +   compatible = "mediatek,mt6397";
> > +
> > +   ...
> > +
> > +   mt6397keys: mt6397keys {
> > +   compatible = "mediatek,mt6397-keys";
> > +   linux,keycodes = , ;
> > +   wakeup-source = <1>, <0>;
> > +   mediatek,long-press-mode = <1>;
> > +   debounce-interval = <0>;
> > +   };
> > +   };
> > -- 
> > 1.7.9.5
> > 




Re: [PATCH v3 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-08-31 Thread Chen Zhong
On Thu, 2017-08-31 at 14:52 -0500, Rob Herring wrote:
> On Fri, Aug 25, 2017 at 02:32:30PM +0800, Chen Zhong wrote:
> > This patch adds the device tree binding documentation for the MediaTek
> > pmic keys found on PMIC MT6397/MT6323.
> > 
> > Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
> > ---
> >  .../devicetree/bindings/input/mtk-pmic-keys.txt|   38 
> > 
> >  1 file changed, 38 insertions(+)
> >  create mode 100644 
> > Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
> > b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > new file mode 100644
> > index 000..100ec44
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > @@ -0,0 +1,38 @@
> > +MediaTek MT6397/MT6323 PMIC Keys Device Driver
> > +
> > +There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
> > +and homekey. The key functions are defined as the subnode of the function
> > +node provided by MT6397/MT6323 PMIC that is being defined as one kind
> > +of Muti-Function Device (MFD)
> > +
> > +For MT6397/MT6323 MFD bindings see:
> > +Documentation/devicetree/bindings/mfd/mt6397.txt
> > +
> > +Required properties:
> > +- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
> > +- linux,keycodes: Specifies the numeric keycode values to
> > +   be used for reporting keys presses. The array can
> > +   contain up to 2 entries.
> > +
> > +Optional Properties:
> > +- wakeup-source: each key can be used as a wakeup source.
> 
> wakeup-source is defined as a boolean.

Hi Rob,

We have two keys, maybe one key can be used as a wakeup source, another
not.Since wakeup-source is defined as a boolean, we cannot distinguish
the behavior of the two keys. May i know the better way to do this?

Thank you.
> 
> > +- mediatek,long-press-mode: Long press key shutdown setting, 1 for
> > +   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
> > +- debounce-interval: Long press key shutdown debouncing interval time
> > +   in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 
> > 0.
> > +
> > +Example:
> > +
> > +   pmic: mt6397 {
> > +   compatible = "mediatek,mt6397";
> > +
> > +   ...
> > +
> > +   mt6397keys: mt6397keys {
> > +   compatible = "mediatek,mt6397-keys";
> > +   linux,keycodes = , ;
> > +   wakeup-source = <1>, <0>;
> > +   mediatek,long-press-mode = <1>;
> > +   debounce-interval = <0>;
> > +   };
> > +   };
> > -- 
> > 1.7.9.5
> > 




Re: [PATCH v3 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-08-31 Thread Chen Zhong
On Thu, 2017-08-31 at 14:52 -0500, Rob Herring wrote:
> On Fri, Aug 25, 2017 at 02:32:30PM +0800, Chen Zhong wrote:
> > This patch adds the device tree binding documentation for the MediaTek
> > pmic keys found on PMIC MT6397/MT6323.
> > 
> > Signed-off-by: Chen Zhong 
> > ---
> >  .../devicetree/bindings/input/mtk-pmic-keys.txt|   38 
> > 
> >  1 file changed, 38 insertions(+)
> >  create mode 100644 
> > Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
> > b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > new file mode 100644
> > index 000..100ec44
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > @@ -0,0 +1,38 @@
> > +MediaTek MT6397/MT6323 PMIC Keys Device Driver
> > +
> > +There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
> > +and homekey. The key functions are defined as the subnode of the function
> > +node provided by MT6397/MT6323 PMIC that is being defined as one kind
> > +of Muti-Function Device (MFD)
> > +
> > +For MT6397/MT6323 MFD bindings see:
> > +Documentation/devicetree/bindings/mfd/mt6397.txt
> > +
> > +Required properties:
> > +- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
> > +- linux,keycodes: Specifies the numeric keycode values to
> > +   be used for reporting keys presses. The array can
> > +   contain up to 2 entries.
> > +
> > +Optional Properties:
> > +- wakeup-source: each key can be used as a wakeup source.
> 
> wakeup-source is defined as a boolean.

Hi Rob,

We have two keys, maybe one key can be used as a wakeup source, another
not.Since wakeup-source is defined as a boolean, we cannot distinguish
the behavior of the two keys. May i know the better way to do this?

Thank you.
> 
> > +- mediatek,long-press-mode: Long press key shutdown setting, 1 for
> > +   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
> > +- debounce-interval: Long press key shutdown debouncing interval time
> > +   in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 
> > 0.
> > +
> > +Example:
> > +
> > +   pmic: mt6397 {
> > +   compatible = "mediatek,mt6397";
> > +
> > +   ...
> > +
> > +   mt6397keys: mt6397keys {
> > +   compatible = "mediatek,mt6397-keys";
> > +   linux,keycodes = , ;
> > +   wakeup-source = <1>, <0>;
> > +   mediatek,long-press-mode = <1>;
> > +   debounce-interval = <0>;
> > +   };
> > +   };
> > -- 
> > 1.7.9.5
> > 




Re: [PATCH v3 4/5] input: Add MediaTek PMIC keys support

2017-08-29 Thread Chen Zhong
Hi Andi,

Sorry for that, i deleted some prefix since the namings will be such
long. If this should be consistent, I'll check and modify them in the
next version.

Thank you.

On Tue, 2017-08-29 at 16:34 +0900, Andi Shyti wrote:
> Hi Chen,
> 
> what I would ask you is to be consistent with the naming, if your
> driver is called mtk-pmic, then all your functions and global
> variables should be named accordingly as mtk_pmic or MTK_PMIC.
> Please check in between the lines for real examples:
> 
> > +#define PWRKEY_RST_EN_MASK 0x1
> > +#define PWRKEY_RST_EN_SHIFT6
> > +#define HOMEKEY_RST_EN_MASK0x1
> > +#define HOMEKEY_RST_EN_SHIFT   5
> > +#define RST_DU_MASK0x3
> > +#define RST_DU_SHIFT   8
> > +
> > +#define PMIC_PWRKEY_INDEX  0
> > +#define PMIC_HOMEKEY_INDEX 1
> > +#define PMIC_MAX_KEY_COUNT 2
> 
> #define MTK_PMIC_*
> 
> > +struct pmic_keys_regs {
> 
> struct mtk_pmic_keys_regs
> 
> > +   u32 deb_reg;
> > +   u32 deb_mask;
> > +   u32 intsel_reg;
> > +   u32 intsel_mask;
> > +};
> > +
> > +#define PMIC_KEYS_REGS(_deb_reg, _deb_mask, _intsel_reg, _intsel_mask) 
> > \
> 
> MTK_PMIC_KEYS_REGS
> 
> > +{  \
> > +   .deb_reg= _deb_reg, \
> > +   .deb_mask   = _deb_mask,\
> > +   .intsel_reg = _intsel_reg,  \
> > +   .intsel_mask= _intsel_mask, \
> > +}
> > +
> > +struct pmic_regs {
> 
> mtk_pmic_regs
> 
> and so on... you got the point.
> 
> Andi




Re: [PATCH v3 4/5] input: Add MediaTek PMIC keys support

2017-08-29 Thread Chen Zhong
Hi Andi,

Sorry for that, i deleted some prefix since the namings will be such
long. If this should be consistent, I'll check and modify them in the
next version.

Thank you.

On Tue, 2017-08-29 at 16:34 +0900, Andi Shyti wrote:
> Hi Chen,
> 
> what I would ask you is to be consistent with the naming, if your
> driver is called mtk-pmic, then all your functions and global
> variables should be named accordingly as mtk_pmic or MTK_PMIC.
> Please check in between the lines for real examples:
> 
> > +#define PWRKEY_RST_EN_MASK 0x1
> > +#define PWRKEY_RST_EN_SHIFT6
> > +#define HOMEKEY_RST_EN_MASK0x1
> > +#define HOMEKEY_RST_EN_SHIFT   5
> > +#define RST_DU_MASK0x3
> > +#define RST_DU_SHIFT   8
> > +
> > +#define PMIC_PWRKEY_INDEX  0
> > +#define PMIC_HOMEKEY_INDEX 1
> > +#define PMIC_MAX_KEY_COUNT 2
> 
> #define MTK_PMIC_*
> 
> > +struct pmic_keys_regs {
> 
> struct mtk_pmic_keys_regs
> 
> > +   u32 deb_reg;
> > +   u32 deb_mask;
> > +   u32 intsel_reg;
> > +   u32 intsel_mask;
> > +};
> > +
> > +#define PMIC_KEYS_REGS(_deb_reg, _deb_mask, _intsel_reg, _intsel_mask) 
> > \
> 
> MTK_PMIC_KEYS_REGS
> 
> > +{  \
> > +   .deb_reg= _deb_reg, \
> > +   .deb_mask   = _deb_mask,\
> > +   .intsel_reg = _intsel_reg,  \
> > +   .intsel_mask= _intsel_mask, \
> > +}
> > +
> > +struct pmic_regs {
> 
> mtk_pmic_regs
> 
> and so on... you got the point.
> 
> Andi




Re: [PATCH v3 4/5] input: Add MediaTek PMIC keys support

2017-08-28 Thread Chen Zhong
On Mon, 2017-08-28 at 09:57 -0700, Dmitry Torokhov wrote:
> Hi Chen,
> 
> On Fri, Aug 25, 2017 at 02:32:32PM +0800, Chen Zhong wrote:
> > +static int mtk_pmic_key_setup(struct mtk_pmic_keys *keys,
> > +   struct pmic_keys_info *info)
> > +{
> > +   int ret;
> > +
> > +   info->keys = keys;
> > +
> > +   ret = regmap_update_bits(keys->regmap, info->regs->intsel_reg,
> > +info->regs->intsel_mask,
> > +info->regs->intsel_mask);
> > +   if (ret < 0)
> > +   return ret;
> > +
> > +   ret = devm_request_threaded_irq(keys->dev, info->irq, NULL,
> > +   mtk_pmic_keys_irq_handler_thread,
> > +   IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
> > +   "mtk-pmic-keys", info);
> > +   if (ret) {
> > +   dev_err(keys->dev, "Failed to request IRQ: %d: %d\n",
> > +   info->irq, ret);
> > +   return ret;
> > +   }
> > +
> > +   if (info->wakeup)
> > +   irq_set_irq_wake(info->irq, 1);
> 
> Normally we do this in suspend() (and undo in resume()), and I believe
> the drover API is enable_irq_wake() and disable_irq_wake().
> 

Hi Dmitry,

I'll add suspend/resume callback functions and do this with
enable_irq_wake() and disable_irq_wake().

Thank you.


> Thanks.
> 




Re: [PATCH v3 4/5] input: Add MediaTek PMIC keys support

2017-08-28 Thread Chen Zhong
On Mon, 2017-08-28 at 09:57 -0700, Dmitry Torokhov wrote:
> Hi Chen,
> 
> On Fri, Aug 25, 2017 at 02:32:32PM +0800, Chen Zhong wrote:
> > +static int mtk_pmic_key_setup(struct mtk_pmic_keys *keys,
> > +   struct pmic_keys_info *info)
> > +{
> > +   int ret;
> > +
> > +   info->keys = keys;
> > +
> > +   ret = regmap_update_bits(keys->regmap, info->regs->intsel_reg,
> > +info->regs->intsel_mask,
> > +info->regs->intsel_mask);
> > +   if (ret < 0)
> > +   return ret;
> > +
> > +   ret = devm_request_threaded_irq(keys->dev, info->irq, NULL,
> > +   mtk_pmic_keys_irq_handler_thread,
> > +   IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
> > +   "mtk-pmic-keys", info);
> > +   if (ret) {
> > +   dev_err(keys->dev, "Failed to request IRQ: %d: %d\n",
> > +   info->irq, ret);
> > +   return ret;
> > +   }
> > +
> > +   if (info->wakeup)
> > +   irq_set_irq_wake(info->irq, 1);
> 
> Normally we do this in suspend() (and undo in resume()), and I believe
> the drover API is enable_irq_wake() and disable_irq_wake().
> 

Hi Dmitry,

I'll add suspend/resume callback functions and do this with
enable_irq_wake() and disable_irq_wake().

Thank you.


> Thanks.
> 




Re: [PATCH v3 0/5] Add MediaTek PMIC keys support

2017-08-25 Thread Chen Zhong
Sorry for missing the change history.

Changes since v2:
- use standard properties for keycodes and debounce time
- change to use platform_get_irq in leaf drivers
- use better ways to define IRQ resources

Changes since v1:
- create irq mappings in mfd core driver instead of leaf drivers
- remove some unused parts in mtk-pmic-keys driver

On Fri, 2017-08-25 at 14:32 +0800, Chen Zhong wrote:
> MediaTek PMIC are multi-function devices that can handle key interrupts,
> typically there are two keys attached to PMIC, which called pwrkey
> and homekey. PWRKEY usually used to wake up system from sleep. Homekey
> can used as volume down key due to board design. Long press keys can
> shutdown PMIC, the mode can be choose to be one key only or two keys
> together.
> This series add support for key functions for MediaTek PMIC MT6397/MT6323.
> 
> Chen Zhong (5):
>   mfd: mt6397: create irq mappings in mfd core driver
>   dt-bindings: input: Add document bindings for mtk-pmic-keys
>   dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
>   input: Add MediaTek PMIC keys support
>   mfd: mt6397: Add PMIC keys support to MT6397 driver
> 
>  .../devicetree/bindings/input/mtk-pmic-keys.txt|  38 +++
>  Documentation/devicetree/bindings/mfd/mt6397.txt   |   6 +
>  drivers/input/keyboard/Kconfig |   9 +
>  drivers/input/keyboard/Makefile|   1 +
>  drivers/input/keyboard/mtk-pmic-keys.c | 308 
> +
>  drivers/mfd/mt6397-core.c  |  26 +-
>  drivers/rtc/rtc-mt6397.c   |   7 +-
>  7 files changed, 388 insertions(+), 7 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
>  create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
> 




Re: [PATCH v3 0/5] Add MediaTek PMIC keys support

2017-08-25 Thread Chen Zhong
Sorry for missing the change history.

Changes since v2:
- use standard properties for keycodes and debounce time
- change to use platform_get_irq in leaf drivers
- use better ways to define IRQ resources

Changes since v1:
- create irq mappings in mfd core driver instead of leaf drivers
- remove some unused parts in mtk-pmic-keys driver

On Fri, 2017-08-25 at 14:32 +0800, Chen Zhong wrote:
> MediaTek PMIC are multi-function devices that can handle key interrupts,
> typically there are two keys attached to PMIC, which called pwrkey
> and homekey. PWRKEY usually used to wake up system from sleep. Homekey
> can used as volume down key due to board design. Long press keys can
> shutdown PMIC, the mode can be choose to be one key only or two keys
> together.
> This series add support for key functions for MediaTek PMIC MT6397/MT6323.
> 
> Chen Zhong (5):
>   mfd: mt6397: create irq mappings in mfd core driver
>   dt-bindings: input: Add document bindings for mtk-pmic-keys
>   dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
>   input: Add MediaTek PMIC keys support
>   mfd: mt6397: Add PMIC keys support to MT6397 driver
> 
>  .../devicetree/bindings/input/mtk-pmic-keys.txt|  38 +++
>  Documentation/devicetree/bindings/mfd/mt6397.txt   |   6 +
>  drivers/input/keyboard/Kconfig |   9 +
>  drivers/input/keyboard/Makefile|   1 +
>  drivers/input/keyboard/mtk-pmic-keys.c | 308 
> +
>  drivers/mfd/mt6397-core.c  |  26 +-
>  drivers/rtc/rtc-mt6397.c   |   7 +-
>  7 files changed, 388 insertions(+), 7 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
>  create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
> 




[PATCH v3 1/5] mfd: mt6397: create irq mappings in mfd core driver

2017-08-25 Thread Chen Zhong
The core driver should create and manage irq mappings instead of
leaf drivers. This patch change to pass irq domain to
devm_mfd_add_devices() and it will create mapping for irq resources
automatically. And remove irq mapping in rtc driver since this has
been done in core driver.

Acked-for-MFD-by: Lee Jones <lee.jo...@linaro.org>
Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 drivers/mfd/mt6397-core.c |4 ++--
 drivers/rtc/rtc-mt6397.c  |7 +++
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 04a601f..6546d7f 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6323_devs,
   ARRAY_SIZE(mt6323_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
case MT6397_CID_CODE:
@@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6397_devs,
   ARRAY_SIZE(mt6397_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
default:
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 1a61fa5..385f830 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -322,10 +322,9 @@ static int mtk_rtc_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
rtc->addr_base = res->start;
 
-   res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
-   if (rtc->irq <= 0)
-   return -EINVAL;
+   rtc->irq = platform_get_irq(pdev, 0);
+   if (rtc->irq < 0)
+   return rtc->irq;
 
rtc->regmap = mt6397_chip->regmap;
rtc->dev = >dev;
-- 
1.7.9.5



[PATCH v3 1/5] mfd: mt6397: create irq mappings in mfd core driver

2017-08-25 Thread Chen Zhong
The core driver should create and manage irq mappings instead of
leaf drivers. This patch change to pass irq domain to
devm_mfd_add_devices() and it will create mapping for irq resources
automatically. And remove irq mapping in rtc driver since this has
been done in core driver.

Acked-for-MFD-by: Lee Jones 
Signed-off-by: Chen Zhong 
---
 drivers/mfd/mt6397-core.c |4 ++--
 drivers/rtc/rtc-mt6397.c  |7 +++
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 04a601f..6546d7f 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6323_devs,
   ARRAY_SIZE(mt6323_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
case MT6397_CID_CODE:
@@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
ret = devm_mfd_add_devices(>dev, -1, mt6397_devs,
   ARRAY_SIZE(mt6397_devs), NULL,
-  0, NULL);
+  0, pmic->irq_domain);
break;
 
default:
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 1a61fa5..385f830 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -322,10 +322,9 @@ static int mtk_rtc_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
rtc->addr_base = res->start;
 
-   res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
-   if (rtc->irq <= 0)
-   return -EINVAL;
+   rtc->irq = platform_get_irq(pdev, 0);
+   if (rtc->irq < 0)
+   return rtc->irq;
 
rtc->regmap = mt6397_chip->regmap;
rtc->dev = >dev;
-- 
1.7.9.5



[PATCH v3 5/5] mfd: mt6397: Add PMIC keys support to MT6397 driver

2017-08-25 Thread Chen Zhong
This patch adds compatible strings and interrupts for pmic keys
which serves as child device of MFD.

Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 drivers/mfd/mt6397-core.c |   22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 6546d7f..77b64bd 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -43,6 +43,16 @@
},
 };
 
+static const struct resource mt6323_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_PWRKEY),
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_FCHRKEY),
+};
+
+static const struct resource mt6397_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6397_IRQ_PWRKEY),
+   DEFINE_RES_IRQ(MT6397_IRQ_HOMEKEY),
+};
+
 static const struct mfd_cell mt6323_devs[] = {
{
.name = "mt6323-regulator",
@@ -50,6 +60,11 @@
}, {
.name = "mt6323-led",
.of_compatible = "mediatek,mt6323-led"
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6323_keys_resources),
+   .resources = mt6323_keys_resources,
+   .of_compatible = "mediatek,mt6323-keys"
},
 };
 
@@ -71,7 +86,12 @@
}, {
.name = "mt6397-pinctrl",
.of_compatible = "mediatek,mt6397-pinctrl",
-   },
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6397_keys_resources),
+   .resources = mt6397_keys_resources,
+   .of_compatible = "mediatek,mt6397-keys"
+   }
 };
 
 static void mt6397_irq_lock(struct irq_data *data)
-- 
1.7.9.5



[PATCH v3 5/5] mfd: mt6397: Add PMIC keys support to MT6397 driver

2017-08-25 Thread Chen Zhong
This patch adds compatible strings and interrupts for pmic keys
which serves as child device of MFD.

Signed-off-by: Chen Zhong 
---
 drivers/mfd/mt6397-core.c |   22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 6546d7f..77b64bd 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -43,6 +43,16 @@
},
 };
 
+static const struct resource mt6323_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_PWRKEY),
+   DEFINE_RES_IRQ(MT6323_IRQ_STATUS_FCHRKEY),
+};
+
+static const struct resource mt6397_keys_resources[] = {
+   DEFINE_RES_IRQ(MT6397_IRQ_PWRKEY),
+   DEFINE_RES_IRQ(MT6397_IRQ_HOMEKEY),
+};
+
 static const struct mfd_cell mt6323_devs[] = {
{
.name = "mt6323-regulator",
@@ -50,6 +60,11 @@
}, {
.name = "mt6323-led",
.of_compatible = "mediatek,mt6323-led"
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6323_keys_resources),
+   .resources = mt6323_keys_resources,
+   .of_compatible = "mediatek,mt6323-keys"
},
 };
 
@@ -71,7 +86,12 @@
}, {
.name = "mt6397-pinctrl",
.of_compatible = "mediatek,mt6397-pinctrl",
-   },
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6397_keys_resources),
+   .resources = mt6397_keys_resources,
+   .of_compatible = "mediatek,mt6397-keys"
+   }
 };
 
 static void mt6397_irq_lock(struct irq_data *data)
-- 
1.7.9.5



[PATCH v3 0/5] Add MediaTek PMIC keys support

2017-08-25 Thread Chen Zhong
MediaTek PMIC are multi-function devices that can handle key interrupts,
typically there are two keys attached to PMIC, which called pwrkey
and homekey. PWRKEY usually used to wake up system from sleep. Homekey
can used as volume down key due to board design. Long press keys can
shutdown PMIC, the mode can be choose to be one key only or two keys
together.
This series add support for key functions for MediaTek PMIC MT6397/MT6323.

Chen Zhong (5):
  mfd: mt6397: create irq mappings in mfd core driver
  dt-bindings: input: Add document bindings for mtk-pmic-keys
  dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
  input: Add MediaTek PMIC keys support
  mfd: mt6397: Add PMIC keys support to MT6397 driver

 .../devicetree/bindings/input/mtk-pmic-keys.txt|  38 +++
 Documentation/devicetree/bindings/mfd/mt6397.txt   |   6 +
 drivers/input/keyboard/Kconfig |   9 +
 drivers/input/keyboard/Makefile|   1 +
 drivers/input/keyboard/mtk-pmic-keys.c | 308 +
 drivers/mfd/mt6397-core.c  |  26 +-
 drivers/rtc/rtc-mt6397.c   |   7 +-
 7 files changed, 388 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

-- 
1.9.1




[PATCH v3 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-08-25 Thread Chen Zhong
This patch adds the device tree binding documentation for the MediaTek
pmic keys found on PMIC MT6397/MT6323.

Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 .../devicetree/bindings/input/mtk-pmic-keys.txt|   38 
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt

diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
new file mode 100644
index 000..100ec44
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
@@ -0,0 +1,38 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: Specifies the numeric keycode values to
+   be used for reporting keys presses. The array can
+   contain up to 2 entries.
+
+Optional Properties:
+- wakeup-source: each key can be used as a wakeup source.
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- debounce-interval: Long press key shutdown debouncing interval time
+   in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 
0.
+
+Example:
+
+   pmic: mt6397 {
+   compatible = "mediatek,mt6397";
+
+   ...
+
+   mt6397keys: mt6397keys {
+   compatible = "mediatek,mt6397-keys";
+   linux,keycodes = , ;
+   wakeup-source = <1>, <0>;
+   mediatek,long-press-mode = <1>;
+   debounce-interval = <0>;
+   };
+   };
-- 
1.7.9.5



[PATCH v3 0/5] Add MediaTek PMIC keys support

2017-08-25 Thread Chen Zhong
MediaTek PMIC are multi-function devices that can handle key interrupts,
typically there are two keys attached to PMIC, which called pwrkey
and homekey. PWRKEY usually used to wake up system from sleep. Homekey
can used as volume down key due to board design. Long press keys can
shutdown PMIC, the mode can be choose to be one key only or two keys
together.
This series add support for key functions for MediaTek PMIC MT6397/MT6323.

Chen Zhong (5):
  mfd: mt6397: create irq mappings in mfd core driver
  dt-bindings: input: Add document bindings for mtk-pmic-keys
  dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
  input: Add MediaTek PMIC keys support
  mfd: mt6397: Add PMIC keys support to MT6397 driver

 .../devicetree/bindings/input/mtk-pmic-keys.txt|  38 +++
 Documentation/devicetree/bindings/mfd/mt6397.txt   |   6 +
 drivers/input/keyboard/Kconfig |   9 +
 drivers/input/keyboard/Makefile|   1 +
 drivers/input/keyboard/mtk-pmic-keys.c | 308 +
 drivers/mfd/mt6397-core.c  |  26 +-
 drivers/rtc/rtc-mt6397.c   |   7 +-
 7 files changed, 388 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

-- 
1.9.1




[PATCH v3 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-08-25 Thread Chen Zhong
This patch adds the device tree binding documentation for the MediaTek
pmic keys found on PMIC MT6397/MT6323.

Signed-off-by: Chen Zhong 
---
 .../devicetree/bindings/input/mtk-pmic-keys.txt|   38 
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt

diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
new file mode 100644
index 000..100ec44
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
@@ -0,0 +1,38 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: Specifies the numeric keycode values to
+   be used for reporting keys presses. The array can
+   contain up to 2 entries.
+
+Optional Properties:
+- wakeup-source: each key can be used as a wakeup source.
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- debounce-interval: Long press key shutdown debouncing interval time
+   in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 
0.
+
+Example:
+
+   pmic: mt6397 {
+   compatible = "mediatek,mt6397";
+
+   ...
+
+   mt6397keys: mt6397keys {
+   compatible = "mediatek,mt6397-keys";
+   linux,keycodes = , ;
+   wakeup-source = <1>, <0>;
+   mediatek,long-press-mode = <1>;
+   debounce-interval = <0>;
+   };
+   };
-- 
1.7.9.5



[PATCH v3 4/5] input: Add MediaTek PMIC keys support

2017-08-25 Thread Chen Zhong
This patch add support to handle MediaTek PMIC MT6397/MT6323 key
interrupts including pwrkey and homekey, also add setting for
long press key shutdown behavior.

Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 drivers/input/keyboard/Kconfig |9 +
 drivers/input/keyboard/Makefile|1 +
 drivers/input/keyboard/mtk-pmic-keys.c |  308 
 3 files changed, 318 insertions(+)
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 4c4ab1c..bd4e20a 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -756,4 +756,13 @@ config KEYBOARD_BCM
  To compile this driver as a module, choose M here: the
  module will be called bcm-keypad.
 
+config KEYBOARD_MTK_PMIC
+   tristate "MediaTek PMIC keys support"
+   depends on MFD_MT6397
+   help
+ Say Y here if you want to use the pmic keys (powerkey/homekey).
+
+ To compile this driver as a module, choose M here: the
+ module will be called pmic-keys.
+
 endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index d2338ba..20c0b98 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
 obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
 obj-$(CONFIG_KEYBOARD_MPR121)  += mpr121_touchkey.o
+obj-$(CONFIG_KEYBOARD_MTK_PMIC)+= mtk-pmic-keys.o
 obj-$(CONFIG_KEYBOARD_NEWTON)  += newtonkbd.o
 obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
 obj-$(CONFIG_KEYBOARD_NSPIRE)  += nspire-keypad.o
diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
b/drivers/input/keyboard/mtk-pmic-keys.c
new file mode 100644
index 000..40518ce
--- /dev/null
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -0,0 +1,308 @@
+/*
+ * Copyright (C) 2017 MediaTek, Inc.
+ *
+ * Author: Chen Zhong <chen.zh...@mediatek.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PWRKEY_RST_EN_MASK 0x1
+#define PWRKEY_RST_EN_SHIFT6
+#define HOMEKEY_RST_EN_MASK0x1
+#define HOMEKEY_RST_EN_SHIFT   5
+#define RST_DU_MASK0x3
+#define RST_DU_SHIFT   8
+
+#define PMIC_PWRKEY_INDEX  0
+#define PMIC_HOMEKEY_INDEX 1
+#define PMIC_MAX_KEY_COUNT 2
+
+struct pmic_keys_regs {
+   u32 deb_reg;
+   u32 deb_mask;
+   u32 intsel_reg;
+   u32 intsel_mask;
+};
+
+#define PMIC_KEYS_REGS(_deb_reg, _deb_mask, _intsel_reg, _intsel_mask) \
+{  \
+   .deb_reg= _deb_reg, \
+   .deb_mask   = _deb_mask,\
+   .intsel_reg = _intsel_reg,  \
+   .intsel_mask= _intsel_mask, \
+}
+
+struct pmic_regs {
+   const struct pmic_keys_regs keys_regs[PMIC_MAX_KEY_COUNT];
+   u32 pmic_rst_reg;
+};
+
+static const struct pmic_regs mt6397_regs = {
+   .keys_regs[PMIC_PWRKEY_INDEX] = PMIC_KEYS_REGS(MT6397_CHRSTATUS,
+   0x8, MT6397_INT_RSV, 0x10),
+   .keys_regs[PMIC_HOMEKEY_INDEX] = PMIC_KEYS_REGS(MT6397_OCSTATUS2,
+   0x10, MT6397_INT_RSV, 0x8),
+   .pmic_rst_reg = MT6397_TOP_RST_MISC,
+};
+
+static const struct pmic_regs mt6323_regs = {
+   .keys_regs[PMIC_PWRKEY_INDEX] = PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x2, MT6323_INT_MISC_CON, 0x10),
+   .keys_regs[PMIC_HOMEKEY_INDEX] = PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x4, MT6323_INT_MISC_CON, 0x8),
+   .pmic_rst_reg = MT6323_TOP_RST_MISC,
+};
+
+struct pmic_keys_info {
+   struct mtk_pmic_keys *keys;
+   const struct pmic_keys_regs *regs;
+   unsigned int keycode;
+   int irq;
+   bool wakeup:1;
+};
+
+struct mtk_pmic_keys {
+   struct input_dev *input_dev;
+   struct device *dev;
+   struct regmap *regmap;
+   struct pmic_keys_info keys[PMIC_MAX_KEY_COUNT];
+};
+
+enum long_press_mode {
+   LP_DISABLE,
+   LP_ONEKEY,
+   LP_TWOKEY,
+};
+
+static void long_press_reset_setup(struct mtk_pmic_keys *keys, u32 
pmic_rst_reg)
+{
+   int ret;
+

[PATCH v3 4/5] input: Add MediaTek PMIC keys support

2017-08-25 Thread Chen Zhong
This patch add support to handle MediaTek PMIC MT6397/MT6323 key
interrupts including pwrkey and homekey, also add setting for
long press key shutdown behavior.

Signed-off-by: Chen Zhong 
---
 drivers/input/keyboard/Kconfig |9 +
 drivers/input/keyboard/Makefile|1 +
 drivers/input/keyboard/mtk-pmic-keys.c |  308 
 3 files changed, 318 insertions(+)
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 4c4ab1c..bd4e20a 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -756,4 +756,13 @@ config KEYBOARD_BCM
  To compile this driver as a module, choose M here: the
  module will be called bcm-keypad.
 
+config KEYBOARD_MTK_PMIC
+   tristate "MediaTek PMIC keys support"
+   depends on MFD_MT6397
+   help
+ Say Y here if you want to use the pmic keys (powerkey/homekey).
+
+ To compile this driver as a module, choose M here: the
+ module will be called pmic-keys.
+
 endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index d2338ba..20c0b98 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
 obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
 obj-$(CONFIG_KEYBOARD_MPR121)  += mpr121_touchkey.o
+obj-$(CONFIG_KEYBOARD_MTK_PMIC)+= mtk-pmic-keys.o
 obj-$(CONFIG_KEYBOARD_NEWTON)  += newtonkbd.o
 obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
 obj-$(CONFIG_KEYBOARD_NSPIRE)  += nspire-keypad.o
diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
b/drivers/input/keyboard/mtk-pmic-keys.c
new file mode 100644
index 000..40518ce
--- /dev/null
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -0,0 +1,308 @@
+/*
+ * Copyright (C) 2017 MediaTek, Inc.
+ *
+ * Author: Chen Zhong 
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PWRKEY_RST_EN_MASK 0x1
+#define PWRKEY_RST_EN_SHIFT6
+#define HOMEKEY_RST_EN_MASK0x1
+#define HOMEKEY_RST_EN_SHIFT   5
+#define RST_DU_MASK0x3
+#define RST_DU_SHIFT   8
+
+#define PMIC_PWRKEY_INDEX  0
+#define PMIC_HOMEKEY_INDEX 1
+#define PMIC_MAX_KEY_COUNT 2
+
+struct pmic_keys_regs {
+   u32 deb_reg;
+   u32 deb_mask;
+   u32 intsel_reg;
+   u32 intsel_mask;
+};
+
+#define PMIC_KEYS_REGS(_deb_reg, _deb_mask, _intsel_reg, _intsel_mask) \
+{  \
+   .deb_reg= _deb_reg, \
+   .deb_mask   = _deb_mask,\
+   .intsel_reg = _intsel_reg,  \
+   .intsel_mask= _intsel_mask, \
+}
+
+struct pmic_regs {
+   const struct pmic_keys_regs keys_regs[PMIC_MAX_KEY_COUNT];
+   u32 pmic_rst_reg;
+};
+
+static const struct pmic_regs mt6397_regs = {
+   .keys_regs[PMIC_PWRKEY_INDEX] = PMIC_KEYS_REGS(MT6397_CHRSTATUS,
+   0x8, MT6397_INT_RSV, 0x10),
+   .keys_regs[PMIC_HOMEKEY_INDEX] = PMIC_KEYS_REGS(MT6397_OCSTATUS2,
+   0x10, MT6397_INT_RSV, 0x8),
+   .pmic_rst_reg = MT6397_TOP_RST_MISC,
+};
+
+static const struct pmic_regs mt6323_regs = {
+   .keys_regs[PMIC_PWRKEY_INDEX] = PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x2, MT6323_INT_MISC_CON, 0x10),
+   .keys_regs[PMIC_HOMEKEY_INDEX] = PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x4, MT6323_INT_MISC_CON, 0x8),
+   .pmic_rst_reg = MT6323_TOP_RST_MISC,
+};
+
+struct pmic_keys_info {
+   struct mtk_pmic_keys *keys;
+   const struct pmic_keys_regs *regs;
+   unsigned int keycode;
+   int irq;
+   bool wakeup:1;
+};
+
+struct mtk_pmic_keys {
+   struct input_dev *input_dev;
+   struct device *dev;
+   struct regmap *regmap;
+   struct pmic_keys_info keys[PMIC_MAX_KEY_COUNT];
+};
+
+enum long_press_mode {
+   LP_DISABLE,
+   LP_ONEKEY,
+   LP_TWOKEY,
+};
+
+static void long_press_reset_setup(struct mtk_pmic_keys *keys, u32 
pmic_rst_reg)
+{
+   int ret;
+   u32 long_press_mode, long_press_debounce;
+
+

[PATCH v3 3/5] dt-bindings: mfd: Add bindings for the keys as subnode of PMIC

2017-08-25 Thread Chen Zhong
This patch adds documentation for device tree bindings for keys support
as the subnode of MT6397/MT6323 PMIC.

Acked-by: Rob Herring <r...@kernel.org>
Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 Documentation/devicetree/bindings/mfd/mt6397.txt |6 ++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/mt6397.txt 
b/Documentation/devicetree/bindings/mfd/mt6397.txt
index 522a3bb..d1df77f 100644
--- a/Documentation/devicetree/bindings/mfd/mt6397.txt
+++ b/Documentation/devicetree/bindings/mfd/mt6397.txt
@@ -7,6 +7,7 @@ MT6397/MT6323 is a multifunction device with the following sub 
modules:
 - GPIO
 - Clock
 - LED
+- Keys
 
 It is interfaced to host controller using SPI interface by a proprietary 
hardware
 called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.
@@ -40,6 +41,11 @@ Optional subnodes:
- compatible: "mediatek,mt6323-led"
see Documentation/devicetree/bindings/leds/leds-mt6323.txt
 
+- keys
+   Required properties:
+   - compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+   see Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
+
 Example:
pwrap: pwrap@1000f000 {
compatible = "mediatek,mt8135-pwrap";
-- 
1.7.9.5



[PATCH v3 3/5] dt-bindings: mfd: Add bindings for the keys as subnode of PMIC

2017-08-25 Thread Chen Zhong
This patch adds documentation for device tree bindings for keys support
as the subnode of MT6397/MT6323 PMIC.

Acked-by: Rob Herring 
Signed-off-by: Chen Zhong 
---
 Documentation/devicetree/bindings/mfd/mt6397.txt |6 ++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/mt6397.txt 
b/Documentation/devicetree/bindings/mfd/mt6397.txt
index 522a3bb..d1df77f 100644
--- a/Documentation/devicetree/bindings/mfd/mt6397.txt
+++ b/Documentation/devicetree/bindings/mfd/mt6397.txt
@@ -7,6 +7,7 @@ MT6397/MT6323 is a multifunction device with the following sub 
modules:
 - GPIO
 - Clock
 - LED
+- Keys
 
 It is interfaced to host controller using SPI interface by a proprietary 
hardware
 called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.
@@ -40,6 +41,11 @@ Optional subnodes:
- compatible: "mediatek,mt6323-led"
see Documentation/devicetree/bindings/leds/leds-mt6323.txt
 
+- keys
+   Required properties:
+   - compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+   see Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
+
 Example:
pwrap: pwrap@1000f000 {
compatible = "mediatek,mt8135-pwrap";
-- 
1.7.9.5



Re: [PATCH v2 5/5] mfd: mt6397: Add PMIC keys support to MT6397 driver

2017-08-11 Thread Chen Zhong
On Tue, 2017-08-08 at 12:15 +0100, Lee Jones wrote:
> On Mon, 07 Aug 2017, Chen Zhong wrote:
> 
> > This patch adds compatible strings and interrupts for pmic keys
> > which serves as child device of MFD.
> > 
> > Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
> > ---
> >  drivers/mfd/mt6397-core.c |   36 +++-
> >  1 file changed, 35 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
> > index 6546d7f..3c6a765 100644
> > --- a/drivers/mfd/mt6397-core.c
> > +++ b/drivers/mfd/mt6397-core.c
> > @@ -43,6 +43,30 @@
> > },
> >  };
> >  
> > +static const struct resource mt6323_keys_resources[] = {
> > +   {
> > +   .start = MT6323_IRQ_STATUS_PWRKEY,
> > +   .end   = MT6323_IRQ_STATUS_PWRKEY,
> > +   .flags = IORESOURCE_IRQ,
> > +   }, {
> > +   .start = MT6323_IRQ_STATUS_FCHRKEY,
> > +   .end   = MT6323_IRQ_STATUS_FCHRKEY,
> > +   .flags = IORESOURCE_IRQ,
> > +   },
> > +};
> > +
> > +static const struct resource mt6397_keys_resources[] = {
> > +   {
> > +   .start = MT6397_IRQ_PWRKEY,
> > +   .end   = MT6397_IRQ_PWRKEY,
> > +   .flags = IORESOURCE_IRQ,
> > +   }, {
> > +   .start = MT6397_IRQ_HOMEKEY,
> > +   .end   = MT6397_IRQ_HOMEKEY,
> > +   .flags = IORESOURCE_IRQ,
> > +   },
> > +};
> 
> We have better ways to define these now.
> 
> Please grep for "DEFINE_RES_"

I'll define these with "DEFINE_RES_IRQ" here, Thank you for your
suggestion.

> 
> >  static const struct mfd_cell mt6323_devs[] = {
> > {
> > .name = "mt6323-regulator",
> > @@ -50,6 +74,11 @@
> > }, {
> > .name = "mt6323-led",
> > .of_compatible = "mediatek,mt6323-led"
> > +   }, {
> > +   .name = "mtk-pmic-keys",
> > +   .num_resources = ARRAY_SIZE(mt6323_keys_resources),
> > +   .resources = mt6323_keys_resources,
> > +   .of_compatible = "mediatek,mt6323-keys"
> > },
> >  };
> >  
> > @@ -71,7 +100,12 @@
> > }, {
> > .name = "mt6397-pinctrl",
> > .of_compatible = "mediatek,mt6397-pinctrl",
> > -   },
> > +   }, {
> > +   .name = "mtk-pmic-keys",
> > +   .num_resources = ARRAY_SIZE(mt6397_keys_resources),
> > +   .resources = mt6397_keys_resources,
> > +   .of_compatible = "mediatek,mt6397-keys"
> > +   }
> >  };
> >  
> >  static void mt6397_irq_lock(struct irq_data *data)
> 




Re: [PATCH v2 5/5] mfd: mt6397: Add PMIC keys support to MT6397 driver

2017-08-11 Thread Chen Zhong
On Tue, 2017-08-08 at 12:15 +0100, Lee Jones wrote:
> On Mon, 07 Aug 2017, Chen Zhong wrote:
> 
> > This patch adds compatible strings and interrupts for pmic keys
> > which serves as child device of MFD.
> > 
> > Signed-off-by: Chen Zhong 
> > ---
> >  drivers/mfd/mt6397-core.c |   36 +++-
> >  1 file changed, 35 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
> > index 6546d7f..3c6a765 100644
> > --- a/drivers/mfd/mt6397-core.c
> > +++ b/drivers/mfd/mt6397-core.c
> > @@ -43,6 +43,30 @@
> > },
> >  };
> >  
> > +static const struct resource mt6323_keys_resources[] = {
> > +   {
> > +   .start = MT6323_IRQ_STATUS_PWRKEY,
> > +   .end   = MT6323_IRQ_STATUS_PWRKEY,
> > +   .flags = IORESOURCE_IRQ,
> > +   }, {
> > +   .start = MT6323_IRQ_STATUS_FCHRKEY,
> > +   .end   = MT6323_IRQ_STATUS_FCHRKEY,
> > +   .flags = IORESOURCE_IRQ,
> > +   },
> > +};
> > +
> > +static const struct resource mt6397_keys_resources[] = {
> > +   {
> > +   .start = MT6397_IRQ_PWRKEY,
> > +   .end   = MT6397_IRQ_PWRKEY,
> > +   .flags = IORESOURCE_IRQ,
> > +   }, {
> > +   .start = MT6397_IRQ_HOMEKEY,
> > +   .end   = MT6397_IRQ_HOMEKEY,
> > +   .flags = IORESOURCE_IRQ,
> > +   },
> > +};
> 
> We have better ways to define these now.
> 
> Please grep for "DEFINE_RES_"

I'll define these with "DEFINE_RES_IRQ" here, Thank you for your
suggestion.

> 
> >  static const struct mfd_cell mt6323_devs[] = {
> > {
> > .name = "mt6323-regulator",
> > @@ -50,6 +74,11 @@
> > }, {
> > .name = "mt6323-led",
> > .of_compatible = "mediatek,mt6323-led"
> > +   }, {
> > +   .name = "mtk-pmic-keys",
> > +   .num_resources = ARRAY_SIZE(mt6323_keys_resources),
> > +   .resources = mt6323_keys_resources,
> > +   .of_compatible = "mediatek,mt6323-keys"
> > },
> >  };
> >  
> > @@ -71,7 +100,12 @@
> > }, {
> > .name = "mt6397-pinctrl",
> > .of_compatible = "mediatek,mt6397-pinctrl",
> > -   },
> > +   }, {
> > +   .name = "mtk-pmic-keys",
> > +   .num_resources = ARRAY_SIZE(mt6397_keys_resources),
> > +   .resources = mt6397_keys_resources,
> > +   .of_compatible = "mediatek,mt6397-keys"
> > +   }
> >  };
> >  
> >  static void mt6397_irq_lock(struct irq_data *data)
> 




Re: [PATCH v2 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-08-11 Thread Chen Zhong
Hi Rob,

On Thu, 2017-08-10 at 15:41 -0500, Rob Herring wrote:
> On Mon, Aug 07, 2017 at 09:57:42AM +0800, Chen Zhong wrote:
> > This patch adds the device tree binding documentation for the MediaTek
> > pmic keys found on PMIC MT6397/MT6323.
> > 
> > Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
> > ---
> >  .../devicetree/bindings/input/mtk-pmic-keys.txt|   36 
> > 
> >  1 file changed, 36 insertions(+)
> >  create mode 100644 
> > Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
> > b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > new file mode 100644
> > index 000..c5b230f
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > @@ -0,0 +1,36 @@
> > +MediaTek MT6397/MT6323 PMIC Keys Device Driver
> > +
> > +There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
> > +and homekey. The key functions are defined as the subnode of the function
> > +node provided by MT6397/MT6323 PMIC that is being defined as one kind
> > +of Muti-Function Device (MFD)
> > +
> > +For MT6397/MT6323 MFD bindings see:
> > +Documentation/devicetree/bindings/mfd/mt6397.txt
> > +
> > +Required properties:
> > +- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
> > +- mediatek,pwrkey-code: Keycode of pwrkey
> > +
> > +Optional Properties:
> > +- mediatek,homekey-code: Keycode of homekey
> > +- mediatek,long-press-mode: Long press key shutdown setting, 1 for
> > +   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
> > +- mediatek,long-press-duration: Long press key shutdown duration setting,
> > +   0/1/2/3 for 8/11/14/5 seconds.
> 
> Surely this could be a common property.

Sorry I'm not very clear about this. Could i move this to required
properties or remove the "mediatek" string here?

> 
> > +
> > +Example:
> > +
> > +   pmic: mt6397 {
> > +   compatible = "mediatek,mt6397";
> > +
> > +   ...
> > +
> > +   mt6397keys: mt6397keys {
> > +   compatible = "mediatek,mt6397-keys";
> > +   mediatek,pwrkey-code = <116>;
> > +   mediatek,homekey-code = <114>;
> 
> We have a standard properties for keycodes.

Could i write them like this way?

linux,keycodes = , 

> 
> > +   mediatek,long-press-mode = <1>;
> > +   mediatek,long-press-duration = <0>;
> > +   };
> > +   };
> > \ No newline at end of file
> > -- 
> > 1.7.9.5
> > 

Thanks.



Re: [PATCH v2 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-08-11 Thread Chen Zhong
Hi Rob,

On Thu, 2017-08-10 at 15:41 -0500, Rob Herring wrote:
> On Mon, Aug 07, 2017 at 09:57:42AM +0800, Chen Zhong wrote:
> > This patch adds the device tree binding documentation for the MediaTek
> > pmic keys found on PMIC MT6397/MT6323.
> > 
> > Signed-off-by: Chen Zhong 
> > ---
> >  .../devicetree/bindings/input/mtk-pmic-keys.txt|   36 
> > 
> >  1 file changed, 36 insertions(+)
> >  create mode 100644 
> > Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
> > b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > new file mode 100644
> > index 000..c5b230f
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
> > @@ -0,0 +1,36 @@
> > +MediaTek MT6397/MT6323 PMIC Keys Device Driver
> > +
> > +There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
> > +and homekey. The key functions are defined as the subnode of the function
> > +node provided by MT6397/MT6323 PMIC that is being defined as one kind
> > +of Muti-Function Device (MFD)
> > +
> > +For MT6397/MT6323 MFD bindings see:
> > +Documentation/devicetree/bindings/mfd/mt6397.txt
> > +
> > +Required properties:
> > +- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
> > +- mediatek,pwrkey-code: Keycode of pwrkey
> > +
> > +Optional Properties:
> > +- mediatek,homekey-code: Keycode of homekey
> > +- mediatek,long-press-mode: Long press key shutdown setting, 1 for
> > +   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
> > +- mediatek,long-press-duration: Long press key shutdown duration setting,
> > +   0/1/2/3 for 8/11/14/5 seconds.
> 
> Surely this could be a common property.

Sorry I'm not very clear about this. Could i move this to required
properties or remove the "mediatek" string here?

> 
> > +
> > +Example:
> > +
> > +   pmic: mt6397 {
> > +   compatible = "mediatek,mt6397";
> > +
> > +   ...
> > +
> > +   mt6397keys: mt6397keys {
> > +   compatible = "mediatek,mt6397-keys";
> > +   mediatek,pwrkey-code = <116>;
> > +   mediatek,homekey-code = <114>;
> 
> We have a standard properties for keycodes.

Could i write them like this way?

linux,keycodes = , 

> 
> > +   mediatek,long-press-mode = <1>;
> > +   mediatek,long-press-duration = <0>;
> > +   };
> > +   };
> > \ No newline at end of file
> > -- 
> > 1.7.9.5
> > 

Thanks.



Re: [PATCH v2 4/5] input: Add MediaTek PMIC keys support

2017-08-08 Thread Chen Zhong
Hi Dmitry,

Thanks for your suggestions. I'll modify them and send the next version
later.

On Mon, 2017-08-07 at 20:03 -0700, Dmitry Torokhov wrote:
> Hi Chen,
> 
> On Mon, Aug 07, 2017 at 09:57:44AM +0800, Chen Zhong wrote:
> > This patch add support to handle MediaTek PMIC MT6397/MT6323 key
> > interrupts including pwrkey and homekey, also add setting for
> > long press key shutdown behavior.
> > 
> > Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
> > ---
> >  drivers/input/keyboard/Kconfig |9 +
> >  drivers/input/keyboard/Makefile|1 +
> >  drivers/input/keyboard/mtk-pmic-keys.c |  331 
> > 
> >  3 files changed, 341 insertions(+)
> >  create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
> > 
> > diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> > index 4c4ab1c..730d9b5 100644
> > --- a/drivers/input/keyboard/Kconfig
> > +++ b/drivers/input/keyboard/Kconfig
> > @@ -756,4 +756,13 @@ config KEYBOARD_BCM
> >   To compile this driver as a module, choose M here: the
> >   module will be called bcm-keypad.
> >  
> > +config KEYBOARD_MTK_PMIC
> > +   tristate "MediaTek PMIC keys support"
> > +   depends on MFD_MT6397
> > +   help
> > + Say Y here if you want to use the pmic keys (pwrkey/homekey).
> > +
> > + To compile this driver as a module, choose M here: the
> > + module will be called pmic-keys.
> > +
> >  endif
> > diff --git a/drivers/input/keyboard/Makefile 
> > b/drivers/input/keyboard/Makefile
> > index d2338ba..20c0b98 100644
> > --- a/drivers/input/keyboard/Makefile
> > +++ b/drivers/input/keyboard/Makefile
> > @@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += 
> > matrix_keypad.o
> >  obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
> >  obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
> >  obj-$(CONFIG_KEYBOARD_MPR121)  += mpr121_touchkey.o
> > +obj-$(CONFIG_KEYBOARD_MTK_PMIC)+= mtk-pmic-keys.o
> >  obj-$(CONFIG_KEYBOARD_NEWTON)  += newtonkbd.o
> >  obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
> >  obj-$(CONFIG_KEYBOARD_NSPIRE)  += nspire-keypad.o
> > diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
> > b/drivers/input/keyboard/mtk-pmic-keys.c
> > new file mode 100644
> > index 000..5d1f133
> > --- /dev/null
> > +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> > @@ -0,0 +1,331 @@
> > +/*
> > + * Copyright (C) 2017 MediaTek, Inc.
> > + *
> > + * Author: Chen Zhong <chen.zh...@mediatek.com>
> > + *
> > + * This software is licensed under the terms of the GNU General Public
> > + * License version 2, as published by the Free Software Foundation, and
> > + * may be copied, distributed, and modified under those terms.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + *
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> 
> Not needed.

Sorry for that. All not needed parts will be removed.
> 
> > +
> > +#define PWRKEY_RST_EN_MASK 0x1
> > +#define PWRKEY_RST_EN_SHIFT6
> > +#define HOMEKEY_RST_EN_MASK0x1
> > +#define HOMEKEY_RST_EN_SHIFT   5
> > +#define RST_DU_MASK0x3
> > +#define RST_DU_SHIFT   8
> > +
> > +struct pmic_keys_regs {
> > +   u32 deb_reg;
> > +   u32 deb_mask;
> > +   u32 intsel_reg;
> > +   u32 intsel_mask;
> > +};
> > +
> > +#define PMIC_KEYS_REGS(_deb_reg, _deb_mask, _intsel_reg, _intsel_mask) 
> > \
> > +{  \
> > +   .deb_reg= _deb_reg, \
> > +   .deb_mask   = _deb_mask,\
> > +   .intsel_reg = _intsel_reg,  \
> > +   .intsel_mask= _intsel_mask, \
> > +}
> > +
> > +struct pmic_regs {
> > +   const struct pmic_keys_regs pwrkey_r

Re: [PATCH v2 4/5] input: Add MediaTek PMIC keys support

2017-08-08 Thread Chen Zhong
Hi Dmitry,

Thanks for your suggestions. I'll modify them and send the next version
later.

On Mon, 2017-08-07 at 20:03 -0700, Dmitry Torokhov wrote:
> Hi Chen,
> 
> On Mon, Aug 07, 2017 at 09:57:44AM +0800, Chen Zhong wrote:
> > This patch add support to handle MediaTek PMIC MT6397/MT6323 key
> > interrupts including pwrkey and homekey, also add setting for
> > long press key shutdown behavior.
> > 
> > Signed-off-by: Chen Zhong 
> > ---
> >  drivers/input/keyboard/Kconfig |9 +
> >  drivers/input/keyboard/Makefile|1 +
> >  drivers/input/keyboard/mtk-pmic-keys.c |  331 
> > 
> >  3 files changed, 341 insertions(+)
> >  create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
> > 
> > diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> > index 4c4ab1c..730d9b5 100644
> > --- a/drivers/input/keyboard/Kconfig
> > +++ b/drivers/input/keyboard/Kconfig
> > @@ -756,4 +756,13 @@ config KEYBOARD_BCM
> >   To compile this driver as a module, choose M here: the
> >   module will be called bcm-keypad.
> >  
> > +config KEYBOARD_MTK_PMIC
> > +   tristate "MediaTek PMIC keys support"
> > +   depends on MFD_MT6397
> > +   help
> > + Say Y here if you want to use the pmic keys (pwrkey/homekey).
> > +
> > + To compile this driver as a module, choose M here: the
> > + module will be called pmic-keys.
> > +
> >  endif
> > diff --git a/drivers/input/keyboard/Makefile 
> > b/drivers/input/keyboard/Makefile
> > index d2338ba..20c0b98 100644
> > --- a/drivers/input/keyboard/Makefile
> > +++ b/drivers/input/keyboard/Makefile
> > @@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += 
> > matrix_keypad.o
> >  obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
> >  obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
> >  obj-$(CONFIG_KEYBOARD_MPR121)  += mpr121_touchkey.o
> > +obj-$(CONFIG_KEYBOARD_MTK_PMIC)+= mtk-pmic-keys.o
> >  obj-$(CONFIG_KEYBOARD_NEWTON)  += newtonkbd.o
> >  obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
> >  obj-$(CONFIG_KEYBOARD_NSPIRE)  += nspire-keypad.o
> > diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
> > b/drivers/input/keyboard/mtk-pmic-keys.c
> > new file mode 100644
> > index 000..5d1f133
> > --- /dev/null
> > +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> > @@ -0,0 +1,331 @@
> > +/*
> > + * Copyright (C) 2017 MediaTek, Inc.
> > + *
> > + * Author: Chen Zhong 
> > + *
> > + * This software is licensed under the terms of the GNU General Public
> > + * License version 2, as published by the Free Software Foundation, and
> > + * may be copied, distributed, and modified under those terms.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + *
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> 
> Not needed.

Sorry for that. All not needed parts will be removed.
> 
> > +
> > +#define PWRKEY_RST_EN_MASK 0x1
> > +#define PWRKEY_RST_EN_SHIFT6
> > +#define HOMEKEY_RST_EN_MASK0x1
> > +#define HOMEKEY_RST_EN_SHIFT   5
> > +#define RST_DU_MASK0x3
> > +#define RST_DU_SHIFT   8
> > +
> > +struct pmic_keys_regs {
> > +   u32 deb_reg;
> > +   u32 deb_mask;
> > +   u32 intsel_reg;
> > +   u32 intsel_mask;
> > +};
> > +
> > +#define PMIC_KEYS_REGS(_deb_reg, _deb_mask, _intsel_reg, _intsel_mask) 
> > \
> > +{  \
> > +   .deb_reg= _deb_reg, \
> > +   .deb_mask   = _deb_mask,\
> > +   .intsel_reg = _intsel_reg,  \
> > +   .intsel_mask= _intsel_mask, \
> > +}
> > +
> > +struct pmic_regs {
> > +   const struct pmic_keys_regs pwrkey_regs;
> > +   const struct pmic_keys_regs homekey_regs;

Re: [PATCH v2 1/5] mfd: mt6397: create irq mappings in mfd core driver

2017-08-08 Thread Chen Zhong
On Mon, 2017-08-07 at 19:53 -0700, Dmitry Torokhov wrote:
> On Mon, Aug 07, 2017 at 11:32:44PM +0200, Alexandre Belloni wrote:
> > On 07/08/2017 at 09:57:41 +0800, Chen Zhong wrote:
> > > The core driver should create and manage irq mappings instead of
> > > leaf drivers. This patch change to pass irq domain to
> > > devm_mfd_add_devices() and it will create mapping for irq resources
> > > automatically. And remove irq mapping in rtc driver since this has
> > > been done in core driver.
> > > 
> > > Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
> > 
> > For the RTC part:
> > Acked-by: Alexandre Belloni <alexandre.bell...@free-electrons.com>
> > 
> > > ---
> > >  drivers/mfd/mt6397-core.c |4 ++--
> > >  drivers/rtc/rtc-mt6397.c  |2 +-
> > >  2 files changed, 3 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
> > > index 04a601f..6546d7f 100644
> > > --- a/drivers/mfd/mt6397-core.c
> > > +++ b/drivers/mfd/mt6397-core.c
> > > @@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
> > >  
> > >   ret = devm_mfd_add_devices(>dev, -1, mt6323_devs,
> > >  ARRAY_SIZE(mt6323_devs), NULL,
> > > -0, NULL);
> > > +0, pmic->irq_domain);
> > >   break;
> > >  
> > >   case MT6397_CID_CODE:
> > > @@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
> > >  
> > >   ret = devm_mfd_add_devices(>dev, -1, mt6397_devs,
> > >  ARRAY_SIZE(mt6397_devs), NULL,
> > > -0, NULL);
> > > +0, pmic->irq_domain);
> > >   break;
> > >  
> > >   default:
> > > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> > > index 1a61fa5..22c52f7 100644
> > > --- a/drivers/rtc/rtc-mt6397.c
> > > +++ b/drivers/rtc/rtc-mt6397.c
> > > @@ -323,7 +323,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
> > >   rtc->addr_base = res->start;
> > >  
> > >   res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> > > - rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
> > > + rtc->irq = res->start;
> 
> Why not
> 
>   rtc->irq = platform_get_irq(pdev, 0);
>   if (rtc->irq < 0)
>   return rtc->irq;
> ?
> 
> This way you propagate error properly.
> 
> Thanks.
> 

Hi Dmitry,

I'll modify it to get irq number via this way.

Thank you.



Re: [PATCH v2 1/5] mfd: mt6397: create irq mappings in mfd core driver

2017-08-08 Thread Chen Zhong
On Mon, 2017-08-07 at 19:53 -0700, Dmitry Torokhov wrote:
> On Mon, Aug 07, 2017 at 11:32:44PM +0200, Alexandre Belloni wrote:
> > On 07/08/2017 at 09:57:41 +0800, Chen Zhong wrote:
> > > The core driver should create and manage irq mappings instead of
> > > leaf drivers. This patch change to pass irq domain to
> > > devm_mfd_add_devices() and it will create mapping for irq resources
> > > automatically. And remove irq mapping in rtc driver since this has
> > > been done in core driver.
> > > 
> > > Signed-off-by: Chen Zhong 
> > 
> > For the RTC part:
> > Acked-by: Alexandre Belloni 
> > 
> > > ---
> > >  drivers/mfd/mt6397-core.c |4 ++--
> > >  drivers/rtc/rtc-mt6397.c  |2 +-
> > >  2 files changed, 3 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
> > > index 04a601f..6546d7f 100644
> > > --- a/drivers/mfd/mt6397-core.c
> > > +++ b/drivers/mfd/mt6397-core.c
> > > @@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
> > >  
> > >   ret = devm_mfd_add_devices(>dev, -1, mt6323_devs,
> > >  ARRAY_SIZE(mt6323_devs), NULL,
> > > -0, NULL);
> > > +0, pmic->irq_domain);
> > >   break;
> > >  
> > >   case MT6397_CID_CODE:
> > > @@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
> > >  
> > >   ret = devm_mfd_add_devices(>dev, -1, mt6397_devs,
> > >  ARRAY_SIZE(mt6397_devs), NULL,
> > > -0, NULL);
> > > +0, pmic->irq_domain);
> > >   break;
> > >  
> > >   default:
> > > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> > > index 1a61fa5..22c52f7 100644
> > > --- a/drivers/rtc/rtc-mt6397.c
> > > +++ b/drivers/rtc/rtc-mt6397.c
> > > @@ -323,7 +323,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
> > >   rtc->addr_base = res->start;
> > >  
> > >   res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> > > - rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
> > > + rtc->irq = res->start;
> 
> Why not
> 
>   rtc->irq = platform_get_irq(pdev, 0);
>   if (rtc->irq < 0)
>   return rtc->irq;
> ?
> 
> This way you propagate error properly.
> 
> Thanks.
> 

Hi Dmitry,

I'll modify it to get irq number via this way.

Thank you.



[PATCH v2 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-08-06 Thread Chen Zhong
This patch adds the device tree binding documentation for the MediaTek
pmic keys found on PMIC MT6397/MT6323.

Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 .../devicetree/bindings/input/mtk-pmic-keys.txt|   36 
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt

diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
new file mode 100644
index 000..c5b230f
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
@@ -0,0 +1,36 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- mediatek,pwrkey-code: Keycode of pwrkey
+
+Optional Properties:
+- mediatek,homekey-code: Keycode of homekey
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- mediatek,long-press-duration: Long press key shutdown duration setting,
+   0/1/2/3 for 8/11/14/5 seconds.
+
+Example:
+
+   pmic: mt6397 {
+   compatible = "mediatek,mt6397";
+
+   ...
+
+   mt6397keys: mt6397keys {
+   compatible = "mediatek,mt6397-keys";
+   mediatek,pwrkey-code = <116>;
+   mediatek,homekey-code = <114>;
+   mediatek,long-press-mode = <1>;
+   mediatek,long-press-duration = <0>;
+   };
+   };
\ No newline at end of file
-- 
1.7.9.5



[PATCH v2 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

2017-08-06 Thread Chen Zhong
This patch adds the device tree binding documentation for the MediaTek
pmic keys found on PMIC MT6397/MT6323.

Signed-off-by: Chen Zhong 
---
 .../devicetree/bindings/input/mtk-pmic-keys.txt|   36 
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt

diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt 
b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
new file mode 100644
index 000..c5b230f
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
@@ -0,0 +1,36 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- mediatek,pwrkey-code: Keycode of pwrkey
+
+Optional Properties:
+- mediatek,homekey-code: Keycode of homekey
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+   pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- mediatek,long-press-duration: Long press key shutdown duration setting,
+   0/1/2/3 for 8/11/14/5 seconds.
+
+Example:
+
+   pmic: mt6397 {
+   compatible = "mediatek,mt6397";
+
+   ...
+
+   mt6397keys: mt6397keys {
+   compatible = "mediatek,mt6397-keys";
+   mediatek,pwrkey-code = <116>;
+   mediatek,homekey-code = <114>;
+   mediatek,long-press-mode = <1>;
+   mediatek,long-press-duration = <0>;
+   };
+   };
\ No newline at end of file
-- 
1.7.9.5



[PATCH v2 4/5] input: Add MediaTek PMIC keys support

2017-08-06 Thread Chen Zhong
This patch add support to handle MediaTek PMIC MT6397/MT6323 key
interrupts including pwrkey and homekey, also add setting for
long press key shutdown behavior.

Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 drivers/input/keyboard/Kconfig |9 +
 drivers/input/keyboard/Makefile|1 +
 drivers/input/keyboard/mtk-pmic-keys.c |  331 
 3 files changed, 341 insertions(+)
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 4c4ab1c..730d9b5 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -756,4 +756,13 @@ config KEYBOARD_BCM
  To compile this driver as a module, choose M here: the
  module will be called bcm-keypad.
 
+config KEYBOARD_MTK_PMIC
+   tristate "MediaTek PMIC keys support"
+   depends on MFD_MT6397
+   help
+ Say Y here if you want to use the pmic keys (pwrkey/homekey).
+
+ To compile this driver as a module, choose M here: the
+ module will be called pmic-keys.
+
 endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index d2338ba..20c0b98 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
 obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
 obj-$(CONFIG_KEYBOARD_MPR121)  += mpr121_touchkey.o
+obj-$(CONFIG_KEYBOARD_MTK_PMIC)+= mtk-pmic-keys.o
 obj-$(CONFIG_KEYBOARD_NEWTON)  += newtonkbd.o
 obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
 obj-$(CONFIG_KEYBOARD_NSPIRE)  += nspire-keypad.o
diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
b/drivers/input/keyboard/mtk-pmic-keys.c
new file mode 100644
index 000..5d1f133
--- /dev/null
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -0,0 +1,331 @@
+/*
+ * Copyright (C) 2017 MediaTek, Inc.
+ *
+ * Author: Chen Zhong <chen.zh...@mediatek.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PWRKEY_RST_EN_MASK 0x1
+#define PWRKEY_RST_EN_SHIFT6
+#define HOMEKEY_RST_EN_MASK0x1
+#define HOMEKEY_RST_EN_SHIFT   5
+#define RST_DU_MASK0x3
+#define RST_DU_SHIFT   8
+
+struct pmic_keys_regs {
+   u32 deb_reg;
+   u32 deb_mask;
+   u32 intsel_reg;
+   u32 intsel_mask;
+};
+
+#define PMIC_KEYS_REGS(_deb_reg, _deb_mask, _intsel_reg, _intsel_mask) \
+{  \
+   .deb_reg= _deb_reg, \
+   .deb_mask   = _deb_mask,\
+   .intsel_reg = _intsel_reg,  \
+   .intsel_mask= _intsel_mask, \
+}
+
+struct pmic_regs {
+   const struct pmic_keys_regs pwrkey_regs;
+   const struct pmic_keys_regs homekey_regs;
+   u32 pmic_rst_reg;
+};
+
+static const struct pmic_regs mt6397_regs = {
+   .pwrkey_regs = PMIC_KEYS_REGS(MT6397_CHRSTATUS,
+   0x8, MT6397_INT_RSV, 0x10),
+   .homekey_regs = PMIC_KEYS_REGS(MT6397_OCSTATUS2,
+   0x10, MT6397_INT_RSV, 0x8),
+   .pmic_rst_reg = MT6397_TOP_RST_MISC,
+};
+
+static const struct pmic_regs mt6323_regs = {
+   .pwrkey_regs = PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x2, MT6323_INT_MISC_CON, 0x10),
+   .homekey_regs = PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x4, MT6323_INT_MISC_CON, 0x8),
+   .pmic_rst_reg = MT6323_TOP_RST_MISC,
+};
+
+struct pmic_keys_info {
+   struct mtk_pmic_keys *keys;
+   const struct pmic_keys_regs *regs;
+   int keycode;
+   int irq;
+};
+
+struct mtk_pmic_keys {
+   struct input_dev *input_dev;
+   struct device *dev;
+   struct regmap *regmap;
+   struct irq_domain *irq_domain;
+   struct pmic_keys_info pwrkey, homekey;
+};
+
+enum long_press_mode {
+   LP_DISABLE,
+   LP_ONEKEY,
+   LP_TWOKEY,
+};
+
+static void long_press_reset_setup(struct mtk_pmic_keys *keys, u32 
pmic_rst_reg)
+{
+   int ret;
+   u32 long_press_mode, long_press_duration;
+
+   ret = of_property_read_u32(keys->dev->of_node,
+   &

[PATCH v2 5/5] mfd: mt6397: Add PMIC keys support to MT6397 driver

2017-08-06 Thread Chen Zhong
This patch adds compatible strings and interrupts for pmic keys
which serves as child device of MFD.

Signed-off-by: Chen Zhong <chen.zh...@mediatek.com>
---
 drivers/mfd/mt6397-core.c |   36 +++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 6546d7f..3c6a765 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -43,6 +43,30 @@
},
 };
 
+static const struct resource mt6323_keys_resources[] = {
+   {
+   .start = MT6323_IRQ_STATUS_PWRKEY,
+   .end   = MT6323_IRQ_STATUS_PWRKEY,
+   .flags = IORESOURCE_IRQ,
+   }, {
+   .start = MT6323_IRQ_STATUS_FCHRKEY,
+   .end   = MT6323_IRQ_STATUS_FCHRKEY,
+   .flags = IORESOURCE_IRQ,
+   },
+};
+
+static const struct resource mt6397_keys_resources[] = {
+   {
+   .start = MT6397_IRQ_PWRKEY,
+   .end   = MT6397_IRQ_PWRKEY,
+   .flags = IORESOURCE_IRQ,
+   }, {
+   .start = MT6397_IRQ_HOMEKEY,
+   .end   = MT6397_IRQ_HOMEKEY,
+   .flags = IORESOURCE_IRQ,
+   },
+};
+
 static const struct mfd_cell mt6323_devs[] = {
{
.name = "mt6323-regulator",
@@ -50,6 +74,11 @@
}, {
.name = "mt6323-led",
.of_compatible = "mediatek,mt6323-led"
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6323_keys_resources),
+   .resources = mt6323_keys_resources,
+   .of_compatible = "mediatek,mt6323-keys"
},
 };
 
@@ -71,7 +100,12 @@
}, {
.name = "mt6397-pinctrl",
.of_compatible = "mediatek,mt6397-pinctrl",
-   },
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6397_keys_resources),
+   .resources = mt6397_keys_resources,
+   .of_compatible = "mediatek,mt6397-keys"
+   }
 };
 
 static void mt6397_irq_lock(struct irq_data *data)
-- 
1.7.9.5



[PATCH v2 4/5] input: Add MediaTek PMIC keys support

2017-08-06 Thread Chen Zhong
This patch add support to handle MediaTek PMIC MT6397/MT6323 key
interrupts including pwrkey and homekey, also add setting for
long press key shutdown behavior.

Signed-off-by: Chen Zhong 
---
 drivers/input/keyboard/Kconfig |9 +
 drivers/input/keyboard/Makefile|1 +
 drivers/input/keyboard/mtk-pmic-keys.c |  331 
 3 files changed, 341 insertions(+)
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 4c4ab1c..730d9b5 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -756,4 +756,13 @@ config KEYBOARD_BCM
  To compile this driver as a module, choose M here: the
  module will be called bcm-keypad.
 
+config KEYBOARD_MTK_PMIC
+   tristate "MediaTek PMIC keys support"
+   depends on MFD_MT6397
+   help
+ Say Y here if you want to use the pmic keys (pwrkey/homekey).
+
+ To compile this driver as a module, choose M here: the
+ module will be called pmic-keys.
+
 endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index d2338ba..20c0b98 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
 obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
 obj-$(CONFIG_KEYBOARD_MPR121)  += mpr121_touchkey.o
+obj-$(CONFIG_KEYBOARD_MTK_PMIC)+= mtk-pmic-keys.o
 obj-$(CONFIG_KEYBOARD_NEWTON)  += newtonkbd.o
 obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
 obj-$(CONFIG_KEYBOARD_NSPIRE)  += nspire-keypad.o
diff --git a/drivers/input/keyboard/mtk-pmic-keys.c 
b/drivers/input/keyboard/mtk-pmic-keys.c
new file mode 100644
index 000..5d1f133
--- /dev/null
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -0,0 +1,331 @@
+/*
+ * Copyright (C) 2017 MediaTek, Inc.
+ *
+ * Author: Chen Zhong 
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PWRKEY_RST_EN_MASK 0x1
+#define PWRKEY_RST_EN_SHIFT6
+#define HOMEKEY_RST_EN_MASK0x1
+#define HOMEKEY_RST_EN_SHIFT   5
+#define RST_DU_MASK0x3
+#define RST_DU_SHIFT   8
+
+struct pmic_keys_regs {
+   u32 deb_reg;
+   u32 deb_mask;
+   u32 intsel_reg;
+   u32 intsel_mask;
+};
+
+#define PMIC_KEYS_REGS(_deb_reg, _deb_mask, _intsel_reg, _intsel_mask) \
+{  \
+   .deb_reg= _deb_reg, \
+   .deb_mask   = _deb_mask,\
+   .intsel_reg = _intsel_reg,  \
+   .intsel_mask= _intsel_mask, \
+}
+
+struct pmic_regs {
+   const struct pmic_keys_regs pwrkey_regs;
+   const struct pmic_keys_regs homekey_regs;
+   u32 pmic_rst_reg;
+};
+
+static const struct pmic_regs mt6397_regs = {
+   .pwrkey_regs = PMIC_KEYS_REGS(MT6397_CHRSTATUS,
+   0x8, MT6397_INT_RSV, 0x10),
+   .homekey_regs = PMIC_KEYS_REGS(MT6397_OCSTATUS2,
+   0x10, MT6397_INT_RSV, 0x8),
+   .pmic_rst_reg = MT6397_TOP_RST_MISC,
+};
+
+static const struct pmic_regs mt6323_regs = {
+   .pwrkey_regs = PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x2, MT6323_INT_MISC_CON, 0x10),
+   .homekey_regs = PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+   0x4, MT6323_INT_MISC_CON, 0x8),
+   .pmic_rst_reg = MT6323_TOP_RST_MISC,
+};
+
+struct pmic_keys_info {
+   struct mtk_pmic_keys *keys;
+   const struct pmic_keys_regs *regs;
+   int keycode;
+   int irq;
+};
+
+struct mtk_pmic_keys {
+   struct input_dev *input_dev;
+   struct device *dev;
+   struct regmap *regmap;
+   struct irq_domain *irq_domain;
+   struct pmic_keys_info pwrkey, homekey;
+};
+
+enum long_press_mode {
+   LP_DISABLE,
+   LP_ONEKEY,
+   LP_TWOKEY,
+};
+
+static void long_press_reset_setup(struct mtk_pmic_keys *keys, u32 
pmic_rst_reg)
+{
+   int ret;
+   u32 long_press_mode, long_press_duration;
+
+   ret = of_property_read_u32(keys->dev->of_node,
+   "mediatek,long-press-duration", _press_

[PATCH v2 5/5] mfd: mt6397: Add PMIC keys support to MT6397 driver

2017-08-06 Thread Chen Zhong
This patch adds compatible strings and interrupts for pmic keys
which serves as child device of MFD.

Signed-off-by: Chen Zhong 
---
 drivers/mfd/mt6397-core.c |   36 +++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 6546d7f..3c6a765 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -43,6 +43,30 @@
},
 };
 
+static const struct resource mt6323_keys_resources[] = {
+   {
+   .start = MT6323_IRQ_STATUS_PWRKEY,
+   .end   = MT6323_IRQ_STATUS_PWRKEY,
+   .flags = IORESOURCE_IRQ,
+   }, {
+   .start = MT6323_IRQ_STATUS_FCHRKEY,
+   .end   = MT6323_IRQ_STATUS_FCHRKEY,
+   .flags = IORESOURCE_IRQ,
+   },
+};
+
+static const struct resource mt6397_keys_resources[] = {
+   {
+   .start = MT6397_IRQ_PWRKEY,
+   .end   = MT6397_IRQ_PWRKEY,
+   .flags = IORESOURCE_IRQ,
+   }, {
+   .start = MT6397_IRQ_HOMEKEY,
+   .end   = MT6397_IRQ_HOMEKEY,
+   .flags = IORESOURCE_IRQ,
+   },
+};
+
 static const struct mfd_cell mt6323_devs[] = {
{
.name = "mt6323-regulator",
@@ -50,6 +74,11 @@
}, {
.name = "mt6323-led",
.of_compatible = "mediatek,mt6323-led"
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6323_keys_resources),
+   .resources = mt6323_keys_resources,
+   .of_compatible = "mediatek,mt6323-keys"
},
 };
 
@@ -71,7 +100,12 @@
}, {
.name = "mt6397-pinctrl",
.of_compatible = "mediatek,mt6397-pinctrl",
-   },
+   }, {
+   .name = "mtk-pmic-keys",
+   .num_resources = ARRAY_SIZE(mt6397_keys_resources),
+   .resources = mt6397_keys_resources,
+   .of_compatible = "mediatek,mt6397-keys"
+   }
 };
 
 static void mt6397_irq_lock(struct irq_data *data)
-- 
1.7.9.5



  1   2   >