[PATCH 2/2] soc: mediatek: Add PMIC wrapper for MT8135 and MT8173 SoCs

2015-03-17 Thread Sascha Hauer
From: Flora Fu 

This adds support for the PMIC wrapper found on MediaTek MT8135 and
MT8173 SoCs. The PMIC wrapper is found on MT6xxx SoCs aswell but these
are currently not supported.

On MediaTek MT8135, MT8173 and other SoCs the PMIC is connected via
SPI. The SPI master interface is not directly visible to the CPU, but
only through the PMIC wrapper inside the SoC. The communication between
the SoC and the PMIC can optionally be encrypted. Also a non standard
Dual IO SPI mode can be used to increase speed. The MT8135 also supports
a special feature named "IP Pairing". With IP Pairing the pins of some
SoC internal peripherals can be on the PMIC. The signals of these pins
are routed over the SPI bus using the pwrap bridge. Because of these
optional non SPI conform features the PMIC driver is not implemented as
a SPI bus master driver.

Signed-off-by: Flora Fu, MediaTek
Signed-off-by: Sascha Hauer 
---
 drivers/soc/Kconfig  |   1 +
 drivers/soc/Makefile |   1 +
 drivers/soc/mediatek/Kconfig |  11 +
 drivers/soc/mediatek/Makefile|   1 +
 drivers/soc/mediatek/mtk-pmic-wrap.c | 977 +++
 5 files changed, 991 insertions(+)
 create mode 100644 drivers/soc/mediatek/Kconfig
 create mode 100644 drivers/soc/mediatek/Makefile
 create mode 100644 drivers/soc/mediatek/mtk-pmic-wrap.c

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index 76d6bd4..d8bde82f0 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -1,5 +1,6 @@
 menu "SOC (System On Chip) specific Drivers"
 
+source "drivers/soc/mediatek/Kconfig"
 source "drivers/soc/qcom/Kconfig"
 source "drivers/soc/ti/Kconfig"
 source "drivers/soc/versatile/Kconfig"
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 063113d..70042b2 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -2,6 +2,7 @@
 # Makefile for the Linux Kernel SOC specific device drivers.
 #
 
+obj-$(CONFIG_ARCH_MEDIATEK)+= mediatek/
 obj-$(CONFIG_ARCH_QCOM)+= qcom/
 obj-$(CONFIG_ARCH_TEGRA)   += tegra/
 obj-$(CONFIG_SOC_TI)   += ti/
diff --git a/drivers/soc/mediatek/Kconfig b/drivers/soc/mediatek/Kconfig
new file mode 100644
index 000..bcdb22d
--- /dev/null
+++ b/drivers/soc/mediatek/Kconfig
@@ -0,0 +1,11 @@
+#
+# MediaTek SoC drivers
+#
+config MTK_PMIC_WRAP
+   tristate "MediaTek PMIC Wrapper Support"
+   depends on ARCH_MEDIATEK
+   select REGMAP
+   help
+ Say yes here to add support for MediaTek PMIC Wrapper found
+ on different MediaTek SoCs. The PMIC wrapper is a proprietary
+ hardware to connect the PMIC.
diff --git a/drivers/soc/mediatek/Makefile b/drivers/soc/mediatek/Makefile
new file mode 100644
index 000..ecaf4de
--- /dev/null
+++ b/drivers/soc/mediatek/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o
diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c 
b/drivers/soc/mediatek/mtk-pmic-wrap.c
new file mode 100644
index 000..4a38506
--- /dev/null
+++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
@@ -0,0 +1,977 @@
+/*
+ * Copyright (c) 2014 MediaTek Inc.
+ * Author: Flora Fu, MediaTek
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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 
+
+#define PWRAP_MT8135_BRIDGE_IORD_ARB_EN0x4
+#define PWRAP_MT8135_BRIDGE_WACS3_EN   0x10
+#define PWRAP_MT8135_BRIDGE_INIT_DONE3 0x14
+#define PWRAP_MT8135_BRIDGE_WACS4_EN   0x24
+#define PWRAP_MT8135_BRIDGE_INIT_DONE4 0x28
+#define PWRAP_MT8135_BRIDGE_INT_EN 0x38
+#define PWRAP_MT8135_BRIDGE_TIMER_EN   0x48
+#define PWRAP_MT8135_BRIDGE_WDT_UNIT   0x50
+#define PWRAP_MT8135_BRIDGE_WDT_SRC_EN 0x54
+
+/* macro for wrapper status */
+#define PWRAP_GET_WACS_RDATA(x)(((x) >> 0) & 0x)
+#define PWRAP_GET_WACS_FSM(x)  (((x) >> 16) & 0x0007)
+#define PWRAP_GET_WACS_REQ(x)  (((x) >> 19) & 0x0001)
+#define PWRAP_STATE_SYNC_IDLE0 (1 << 20)
+#define PWRAP_STATE_INIT_DONE0 (1 << 21)
+
+/* macro for WACS FSM */
+#define PWRAP_WACS_FSM_IDLE0x00
+#define PWRAP_WACS_FSM_REQ 0x02
+#define PWRAP_WACS_FSM_WFDLE   0x04
+#define PWRAP_WACS_FSM_WFVLDCLR0x06
+#define PWRAP_WACS_INIT_DONE   0x01
+#define PWRAP_WACS_WACS_SYNC_IDLE  0x01
+#define PWRAP_WACS_SYNC_BUSY   0x00
+
+/* macro for device wrapper default value */
+#define PWRAP_DEW_READ_TEST_VAL

[PATCH 2/2] soc: mediatek: Add PMIC wrapper for MT8135 and MT8173 SoCs

2015-03-17 Thread Sascha Hauer
From: Flora Fu flora...@mediatek.com

This adds support for the PMIC wrapper found on MediaTek MT8135 and
MT8173 SoCs. The PMIC wrapper is found on MT6xxx SoCs aswell but these
are currently not supported.

On MediaTek MT8135, MT8173 and other SoCs the PMIC is connected via
SPI. The SPI master interface is not directly visible to the CPU, but
only through the PMIC wrapper inside the SoC. The communication between
the SoC and the PMIC can optionally be encrypted. Also a non standard
Dual IO SPI mode can be used to increase speed. The MT8135 also supports
a special feature named IP Pairing. With IP Pairing the pins of some
SoC internal peripherals can be on the PMIC. The signals of these pins
are routed over the SPI bus using the pwrap bridge. Because of these
optional non SPI conform features the PMIC driver is not implemented as
a SPI bus master driver.

Signed-off-by: Flora Fu, MediaTek
Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
---
 drivers/soc/Kconfig  |   1 +
 drivers/soc/Makefile |   1 +
 drivers/soc/mediatek/Kconfig |  11 +
 drivers/soc/mediatek/Makefile|   1 +
 drivers/soc/mediatek/mtk-pmic-wrap.c | 977 +++
 5 files changed, 991 insertions(+)
 create mode 100644 drivers/soc/mediatek/Kconfig
 create mode 100644 drivers/soc/mediatek/Makefile
 create mode 100644 drivers/soc/mediatek/mtk-pmic-wrap.c

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index 76d6bd4..d8bde82f0 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -1,5 +1,6 @@
 menu SOC (System On Chip) specific Drivers
 
+source drivers/soc/mediatek/Kconfig
 source drivers/soc/qcom/Kconfig
 source drivers/soc/ti/Kconfig
 source drivers/soc/versatile/Kconfig
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 063113d..70042b2 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -2,6 +2,7 @@
 # Makefile for the Linux Kernel SOC specific device drivers.
 #
 
+obj-$(CONFIG_ARCH_MEDIATEK)+= mediatek/
 obj-$(CONFIG_ARCH_QCOM)+= qcom/
 obj-$(CONFIG_ARCH_TEGRA)   += tegra/
 obj-$(CONFIG_SOC_TI)   += ti/
diff --git a/drivers/soc/mediatek/Kconfig b/drivers/soc/mediatek/Kconfig
new file mode 100644
index 000..bcdb22d
--- /dev/null
+++ b/drivers/soc/mediatek/Kconfig
@@ -0,0 +1,11 @@
+#
+# MediaTek SoC drivers
+#
+config MTK_PMIC_WRAP
+   tristate MediaTek PMIC Wrapper Support
+   depends on ARCH_MEDIATEK
+   select REGMAP
+   help
+ Say yes here to add support for MediaTek PMIC Wrapper found
+ on different MediaTek SoCs. The PMIC wrapper is a proprietary
+ hardware to connect the PMIC.
diff --git a/drivers/soc/mediatek/Makefile b/drivers/soc/mediatek/Makefile
new file mode 100644
index 000..ecaf4de
--- /dev/null
+++ b/drivers/soc/mediatek/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o
diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c 
b/drivers/soc/mediatek/mtk-pmic-wrap.c
new file mode 100644
index 000..4a38506
--- /dev/null
+++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
@@ -0,0 +1,977 @@
+/*
+ * Copyright (c) 2014 MediaTek Inc.
+ * Author: Flora Fu, MediaTek
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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 linux/clk.h
+#include linux/interrupt.h
+#include linux/io.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/of_device.h
+#include linux/platform_device.h
+#include linux/regmap.h
+#include linux/reset.h
+
+#define PWRAP_MT8135_BRIDGE_IORD_ARB_EN0x4
+#define PWRAP_MT8135_BRIDGE_WACS3_EN   0x10
+#define PWRAP_MT8135_BRIDGE_INIT_DONE3 0x14
+#define PWRAP_MT8135_BRIDGE_WACS4_EN   0x24
+#define PWRAP_MT8135_BRIDGE_INIT_DONE4 0x28
+#define PWRAP_MT8135_BRIDGE_INT_EN 0x38
+#define PWRAP_MT8135_BRIDGE_TIMER_EN   0x48
+#define PWRAP_MT8135_BRIDGE_WDT_UNIT   0x50
+#define PWRAP_MT8135_BRIDGE_WDT_SRC_EN 0x54
+
+/* macro for wrapper status */
+#define PWRAP_GET_WACS_RDATA(x)(((x)  0)  0x)
+#define PWRAP_GET_WACS_FSM(x)  (((x)  16)  0x0007)
+#define PWRAP_GET_WACS_REQ(x)  (((x)  19)  0x0001)
+#define PWRAP_STATE_SYNC_IDLE0 (1  20)
+#define PWRAP_STATE_INIT_DONE0 (1  21)
+
+/* macro for WACS FSM */
+#define PWRAP_WACS_FSM_IDLE0x00
+#define PWRAP_WACS_FSM_REQ 0x02
+#define PWRAP_WACS_FSM_WFDLE   0x04
+#define PWRAP_WACS_FSM_WFVLDCLR0x06
+#define PWRAP_WACS_INIT_DONE   0x01
+#define PWRAP_WACS_WACS_SYNC_IDLE  

Re: [PATCH 2/2] soc: mediatek: Add PMIC wrapper for MT8135 and MT8173 SoCs

2015-03-12 Thread Sascha Hauer
On Wed, Mar 11, 2015 at 12:12:31PM +0100, Paul Bolle wrote:
> On Tue, 2015-03-10 at 16:22 +0100, Sascha Hauer wrote:
> > --- /dev/null
> > +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
> > @@ -0,0 +1,978 @@
> > +/*
> > + * Copyright (c) 2014 MediaTek Inc.
> > + * Author: Flora Fu, MediaTek
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + *
> > + * 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.
> > + */
> 
> This states the license is GPL v2.
> 
> > +MODULE_LICENSE("GPL");
> 
> So you probably want
> MODULE_LICENSE("GPL v2");

Fixed that, thanks.

Also fixed in the power domain driver you found the same issue.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] soc: mediatek: Add PMIC wrapper for MT8135 and MT8173 SoCs

2015-03-12 Thread Sascha Hauer
On Wed, Mar 11, 2015 at 12:12:31PM +0100, Paul Bolle wrote:
 On Tue, 2015-03-10 at 16:22 +0100, Sascha Hauer wrote:
  --- /dev/null
  +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
  @@ -0,0 +1,978 @@
  +/*
  + * Copyright (c) 2014 MediaTek Inc.
  + * Author: Flora Fu, MediaTek
  + *
  + * This program is free software; you can redistribute it and/or modify
  + * it under the terms of the GNU General Public License version 2 as
  + * published by the Free Software Foundation.
  + *
  + * 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.
  + */
 
 This states the license is GPL v2.
 
  +MODULE_LICENSE(GPL);
 
 So you probably want
 MODULE_LICENSE(GPL v2);

Fixed that, thanks.

Also fixed in the power domain driver you found the same issue.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] soc: mediatek: Add PMIC wrapper for MT8135 and MT8173 SoCs

2015-03-11 Thread Paul Bolle
On Tue, 2015-03-10 at 16:22 +0100, Sascha Hauer wrote:
> --- /dev/null
> +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
> @@ -0,0 +1,978 @@
> +/*
> + * Copyright (c) 2014 MediaTek Inc.
> + * Author: Flora Fu, MediaTek
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * 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.
> + */

This states the license is GPL v2.

> +MODULE_LICENSE("GPL");

So you probably want
MODULE_LICENSE("GPL v2");

here.


Paul Bolle

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


Re: [PATCH 2/2] soc: mediatek: Add PMIC wrapper for MT8135 and MT8173 SoCs

2015-03-11 Thread Paul Bolle
On Tue, 2015-03-10 at 16:22 +0100, Sascha Hauer wrote:
 --- /dev/null
 +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
 @@ -0,0 +1,978 @@
 +/*
 + * Copyright (c) 2014 MediaTek Inc.
 + * Author: Flora Fu, MediaTek
 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License version 2 as
 + * published by the Free Software Foundation.
 + *
 + * 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.
 + */

This states the license is GPL v2.

 +MODULE_LICENSE(GPL);

So you probably want
MODULE_LICENSE(GPL v2);

here.


Paul Bolle

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


Re: [PATCH 2/2] soc: mediatek: Add PMIC wrapper for MT8135 and MT8173 SoCs

2015-03-10 Thread Sascha Hauer
On Tue, Mar 10, 2015 at 03:46:11PM +, Russell King - ARM Linux wrote:
> On Tue, Mar 10, 2015 at 04:22:34PM +0100, Sascha Hauer wrote:
> > +   for (i = 0; i < 4; i++) {
> > +   pwrap_writel(wrp, i, PWRAP_SIDLY);
> > +   pwrap_read(wrp, PWRAP_DEW_READ_TEST, );
> > +   printk("%s: 0x%04x\n", __func__, rdata);
> 
> Is this really ready for submission, or is this just a hidden oversight?
> 
> What I tend to do with such debugging is _not_ to indent it at all, which
> means when the file is reviewed before sending it out (or indeed, when
> diffing it to review the updates before committing those changes or an
> amendment to the previous commit) that it sticks out like a sore thumb.

I often do this aswell, apparently not all the time :-/

This message is also not seen often during booting since the driver has
this in it:

/*
 * The PMIC could already be initialized by the bootloader.
 * Skip initialization here in this case.
 */
if (!pwrap_readl(wrp, PWRAP_INIT_DONE2)) {
ret = pwrap_init(wrp);
if (ret) {
dev_dbg(wrp->dev, "init failed with %d\n", ret);
goto err_out2;
}
}

I first have to comment out the already initialized check to see this
message. I just rechecked, yes, the initialisation still works as
expected.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] soc: mediatek: Add PMIC wrapper for MT8135 and MT8173 SoCs

2015-03-10 Thread Russell King - ARM Linux
On Tue, Mar 10, 2015 at 04:22:34PM +0100, Sascha Hauer wrote:
> + for (i = 0; i < 4; i++) {
> + pwrap_writel(wrp, i, PWRAP_SIDLY);
> + pwrap_read(wrp, PWRAP_DEW_READ_TEST, );
> + printk("%s: 0x%04x\n", __func__, rdata);

Is this really ready for submission, or is this just a hidden oversight?

What I tend to do with such debugging is _not_ to indent it at all, which
means when the file is reviewed before sending it out (or indeed, when
diffing it to review the updates before committing those changes or an
amendment to the previous commit) that it sticks out like a sore thumb.

-- 
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] soc: mediatek: Add PMIC wrapper for MT8135 and MT8173 SoCs

2015-03-10 Thread Sascha Hauer
From: Flora Fu 

This adds support for the PMIC wrapper found on MediaTek MT8135 and
MT8173 SoCs. The PMIC wrapper is found on MT6xxx SoCs aswell but these
are currently not supported.

On MediaTek MT8135, MT8173 and other SoCs the PMIC is connected via
SPI. The SPI master interface is not directly visible to the CPU, but
only through the PMIC wrapper inside the SoC. The communication between
the SoC and the PMIC can optionally be encrypted. Also a non standard
Dual IO SPI mode can be used to increase speed. The MT8135 also supports
a special feature named "IP Pairing". With IP Pairing the pins of some
SoC internal peripherals can be on the PMIC. The signals of these pins
are routed over the SPI bus using the pwrap bridge. Because of these
optional non SPI conform features the PMIC driver is not implemented as
a SPI bus master driver.

Signed-off-by: Flora Fu, MediaTek
Signed-off-by: Sascha Hauer 
---
 drivers/soc/Kconfig  |   1 +
 drivers/soc/Makefile |   1 +
 drivers/soc/mediatek/Kconfig |  11 +
 drivers/soc/mediatek/Makefile|   1 +
 drivers/soc/mediatek/mtk-pmic-wrap.c | 978 +++
 5 files changed, 992 insertions(+)
 create mode 100644 drivers/soc/mediatek/Kconfig
 create mode 100644 drivers/soc/mediatek/Makefile
 create mode 100644 drivers/soc/mediatek/mtk-pmic-wrap.c

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index 76d6bd4..d8bde82f0 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -1,5 +1,6 @@
 menu "SOC (System On Chip) specific Drivers"
 
+source "drivers/soc/mediatek/Kconfig"
 source "drivers/soc/qcom/Kconfig"
 source "drivers/soc/ti/Kconfig"
 source "drivers/soc/versatile/Kconfig"
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 063113d..70042b2 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -2,6 +2,7 @@
 # Makefile for the Linux Kernel SOC specific device drivers.
 #
 
+obj-$(CONFIG_ARCH_MEDIATEK)+= mediatek/
 obj-$(CONFIG_ARCH_QCOM)+= qcom/
 obj-$(CONFIG_ARCH_TEGRA)   += tegra/
 obj-$(CONFIG_SOC_TI)   += ti/
diff --git a/drivers/soc/mediatek/Kconfig b/drivers/soc/mediatek/Kconfig
new file mode 100644
index 000..bcdb22d
--- /dev/null
+++ b/drivers/soc/mediatek/Kconfig
@@ -0,0 +1,11 @@
+#
+# MediaTek SoC drivers
+#
+config MTK_PMIC_WRAP
+   tristate "MediaTek PMIC Wrapper Support"
+   depends on ARCH_MEDIATEK
+   select REGMAP
+   help
+ Say yes here to add support for MediaTek PMIC Wrapper found
+ on different MediaTek SoCs. The PMIC wrapper is a proprietary
+ hardware to connect the PMIC.
diff --git a/drivers/soc/mediatek/Makefile b/drivers/soc/mediatek/Makefile
new file mode 100644
index 000..ecaf4de
--- /dev/null
+++ b/drivers/soc/mediatek/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o
diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c 
b/drivers/soc/mediatek/mtk-pmic-wrap.c
new file mode 100644
index 000..0cd8fc10
--- /dev/null
+++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
@@ -0,0 +1,978 @@
+/*
+ * Copyright (c) 2014 MediaTek Inc.
+ * Author: Flora Fu, MediaTek
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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 
+
+#define PWRAP_MT8135_BRIDGE_IORD_ARB_EN0x4
+#define PWRAP_MT8135_BRIDGE_WACS3_EN   0x10
+#define PWRAP_MT8135_BRIDGE_INIT_DONE3 0x14
+#define PWRAP_MT8135_BRIDGE_WACS4_EN   0x24
+#define PWRAP_MT8135_BRIDGE_INIT_DONE4 0x28
+#define PWRAP_MT8135_BRIDGE_INT_EN 0x38
+#define PWRAP_MT8135_BRIDGE_TIMER_EN   0x48
+#define PWRAP_MT8135_BRIDGE_WDT_UNIT   0x50
+#define PWRAP_MT8135_BRIDGE_WDT_SRC_EN 0x54
+
+/* macro for wrapper status */
+#define PWRAP_GET_WACS_RDATA(x)(((x) >> 0) & 0x)
+#define PWRAP_GET_WACS_FSM(x)  (((x) >> 16) & 0x0007)
+#define PWRAP_GET_WACS_REQ(x)  (((x) >> 19) & 0x0001)
+#define PWRAP_STATE_SYNC_IDLE0 (1 << 20)
+#define PWRAP_STATE_INIT_DONE0 (1 << 21)
+
+/* macro for WACS FSM */
+#define PWRAP_WACS_FSM_IDLE0x00
+#define PWRAP_WACS_FSM_REQ 0x02
+#define PWRAP_WACS_FSM_WFDLE   0x04
+#define PWRAP_WACS_FSM_WFVLDCLR0x06
+#define PWRAP_WACS_INIT_DONE   0x01
+#define PWRAP_WACS_WACS_SYNC_IDLE  0x01
+#define PWRAP_WACS_SYNC_BUSY   0x00
+
+/* macro for device wrapper default value */
+#define PWRAP_DEW_READ_TEST_VAL

[PATCH 2/2] soc: mediatek: Add PMIC wrapper for MT8135 and MT8173 SoCs

2015-03-10 Thread Sascha Hauer
From: Flora Fu flora...@mediatek.com

This adds support for the PMIC wrapper found on MediaTek MT8135 and
MT8173 SoCs. The PMIC wrapper is found on MT6xxx SoCs aswell but these
are currently not supported.

On MediaTek MT8135, MT8173 and other SoCs the PMIC is connected via
SPI. The SPI master interface is not directly visible to the CPU, but
only through the PMIC wrapper inside the SoC. The communication between
the SoC and the PMIC can optionally be encrypted. Also a non standard
Dual IO SPI mode can be used to increase speed. The MT8135 also supports
a special feature named IP Pairing. With IP Pairing the pins of some
SoC internal peripherals can be on the PMIC. The signals of these pins
are routed over the SPI bus using the pwrap bridge. Because of these
optional non SPI conform features the PMIC driver is not implemented as
a SPI bus master driver.

Signed-off-by: Flora Fu, MediaTek
Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
---
 drivers/soc/Kconfig  |   1 +
 drivers/soc/Makefile |   1 +
 drivers/soc/mediatek/Kconfig |  11 +
 drivers/soc/mediatek/Makefile|   1 +
 drivers/soc/mediatek/mtk-pmic-wrap.c | 978 +++
 5 files changed, 992 insertions(+)
 create mode 100644 drivers/soc/mediatek/Kconfig
 create mode 100644 drivers/soc/mediatek/Makefile
 create mode 100644 drivers/soc/mediatek/mtk-pmic-wrap.c

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index 76d6bd4..d8bde82f0 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -1,5 +1,6 @@
 menu SOC (System On Chip) specific Drivers
 
+source drivers/soc/mediatek/Kconfig
 source drivers/soc/qcom/Kconfig
 source drivers/soc/ti/Kconfig
 source drivers/soc/versatile/Kconfig
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 063113d..70042b2 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -2,6 +2,7 @@
 # Makefile for the Linux Kernel SOC specific device drivers.
 #
 
+obj-$(CONFIG_ARCH_MEDIATEK)+= mediatek/
 obj-$(CONFIG_ARCH_QCOM)+= qcom/
 obj-$(CONFIG_ARCH_TEGRA)   += tegra/
 obj-$(CONFIG_SOC_TI)   += ti/
diff --git a/drivers/soc/mediatek/Kconfig b/drivers/soc/mediatek/Kconfig
new file mode 100644
index 000..bcdb22d
--- /dev/null
+++ b/drivers/soc/mediatek/Kconfig
@@ -0,0 +1,11 @@
+#
+# MediaTek SoC drivers
+#
+config MTK_PMIC_WRAP
+   tristate MediaTek PMIC Wrapper Support
+   depends on ARCH_MEDIATEK
+   select REGMAP
+   help
+ Say yes here to add support for MediaTek PMIC Wrapper found
+ on different MediaTek SoCs. The PMIC wrapper is a proprietary
+ hardware to connect the PMIC.
diff --git a/drivers/soc/mediatek/Makefile b/drivers/soc/mediatek/Makefile
new file mode 100644
index 000..ecaf4de
--- /dev/null
+++ b/drivers/soc/mediatek/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o
diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c 
b/drivers/soc/mediatek/mtk-pmic-wrap.c
new file mode 100644
index 000..0cd8fc10
--- /dev/null
+++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
@@ -0,0 +1,978 @@
+/*
+ * Copyright (c) 2014 MediaTek Inc.
+ * Author: Flora Fu, MediaTek
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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 linux/clk.h
+#include linux/interrupt.h
+#include linux/io.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/of_device.h
+#include linux/platform_device.h
+#include linux/regmap.h
+#include linux/reset.h
+
+#define PWRAP_MT8135_BRIDGE_IORD_ARB_EN0x4
+#define PWRAP_MT8135_BRIDGE_WACS3_EN   0x10
+#define PWRAP_MT8135_BRIDGE_INIT_DONE3 0x14
+#define PWRAP_MT8135_BRIDGE_WACS4_EN   0x24
+#define PWRAP_MT8135_BRIDGE_INIT_DONE4 0x28
+#define PWRAP_MT8135_BRIDGE_INT_EN 0x38
+#define PWRAP_MT8135_BRIDGE_TIMER_EN   0x48
+#define PWRAP_MT8135_BRIDGE_WDT_UNIT   0x50
+#define PWRAP_MT8135_BRIDGE_WDT_SRC_EN 0x54
+
+/* macro for wrapper status */
+#define PWRAP_GET_WACS_RDATA(x)(((x)  0)  0x)
+#define PWRAP_GET_WACS_FSM(x)  (((x)  16)  0x0007)
+#define PWRAP_GET_WACS_REQ(x)  (((x)  19)  0x0001)
+#define PWRAP_STATE_SYNC_IDLE0 (1  20)
+#define PWRAP_STATE_INIT_DONE0 (1  21)
+
+/* macro for WACS FSM */
+#define PWRAP_WACS_FSM_IDLE0x00
+#define PWRAP_WACS_FSM_REQ 0x02
+#define PWRAP_WACS_FSM_WFDLE   0x04
+#define PWRAP_WACS_FSM_WFVLDCLR0x06
+#define PWRAP_WACS_INIT_DONE   0x01
+#define PWRAP_WACS_WACS_SYNC_IDLE  

Re: [PATCH 2/2] soc: mediatek: Add PMIC wrapper for MT8135 and MT8173 SoCs

2015-03-10 Thread Russell King - ARM Linux
On Tue, Mar 10, 2015 at 04:22:34PM +0100, Sascha Hauer wrote:
 + for (i = 0; i  4; i++) {
 + pwrap_writel(wrp, i, PWRAP_SIDLY);
 + pwrap_read(wrp, PWRAP_DEW_READ_TEST, rdata);
 + printk(%s: 0x%04x\n, __func__, rdata);

Is this really ready for submission, or is this just a hidden oversight?

What I tend to do with such debugging is _not_ to indent it at all, which
means when the file is reviewed before sending it out (or indeed, when
diffing it to review the updates before committing those changes or an
amendment to the previous commit) that it sticks out like a sore thumb.

-- 
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] soc: mediatek: Add PMIC wrapper for MT8135 and MT8173 SoCs

2015-03-10 Thread Sascha Hauer
On Tue, Mar 10, 2015 at 03:46:11PM +, Russell King - ARM Linux wrote:
 On Tue, Mar 10, 2015 at 04:22:34PM +0100, Sascha Hauer wrote:
  +   for (i = 0; i  4; i++) {
  +   pwrap_writel(wrp, i, PWRAP_SIDLY);
  +   pwrap_read(wrp, PWRAP_DEW_READ_TEST, rdata);
  +   printk(%s: 0x%04x\n, __func__, rdata);
 
 Is this really ready for submission, or is this just a hidden oversight?
 
 What I tend to do with such debugging is _not_ to indent it at all, which
 means when the file is reviewed before sending it out (or indeed, when
 diffing it to review the updates before committing those changes or an
 amendment to the previous commit) that it sticks out like a sore thumb.

I often do this aswell, apparently not all the time :-/

This message is also not seen often during booting since the driver has
this in it:

/*
 * The PMIC could already be initialized by the bootloader.
 * Skip initialization here in this case.
 */
if (!pwrap_readl(wrp, PWRAP_INIT_DONE2)) {
ret = pwrap_init(wrp);
if (ret) {
dev_dbg(wrp-dev, init failed with %d\n, ret);
goto err_out2;
}
}

I first have to comment out the already initialized check to see this
message. I just rechecked, yes, the initialisation still works as
expected.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/