Skip to contentSkip to conversation

Add i2c support for MediaTek mt8512

PATCH Superseded mingming lee 2 participants 8 messages Sep 9, 2020 – Sep 30, 2020

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Add i2c support for MediaTek mt8512

From: Mingming Lee <[email protected]>

This patch series adds basic i2c support for MediaTek MT8512 EMMC boards.

Mingming Lee (3):
i2c: mediatek: add basic driver support
ARM: dts: Mediatek: add i2c node support for mt8512
configs: mt8512: Enable I2C related configs

 arch/arm/dts/mt8512-bm1-emmc.dts  |  12 +
 arch/arm/dts/mt8512.dtsi          |  38 ++-
 configs/mt8512_bm1_emmc_defconfig |   3 +
 drivers/i2c/Kconfig               |   9 +
 drivers/i2c/Makefile              |   1 +
 drivers/i2c/mt_i2c.c              | 619 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 681 insertions(+), 1 deletion(-)
 create mode 100644 drivers/i2c/mt_i2c.c
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/3 i2c: mediatek: add basic driver support

From: Mingming Lee <[email protected]>

Add MediaTek I2C basic driver

---
 drivers/i2c/Kconfig  |   9 +
 drivers/i2c/Makefile |   1 +
 drivers/i2c/mt_i2c.c | 619 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 629 insertions(+)
 create mode 100644 drivers/i2c/mt_i2c.c
drivers/i2c/Kconfig +9 -0
index dec6dc9..103688e 100644
@@ -159,6 +159,15 @@ config SYS_I2C_MESON
 	  internal buffer holding up to 8 bytes for transfers and supports
 	  both 7-bit and 10-bit addresses.
 
+config SYS_I2C_MTK
+	bool "MediaTek I2C driver"
+	default n
+	help
+	  This selects the MediaTek Integrated Inter Circuit bus driver.
+	  The I2C bus adapter is the base for some other I2C client, eg: touch, sensors.
+	  If you want to use MediaTek I2C interface, say Y here.
+	  If unsure, say N.
+
 config SYS_I2C_MXC
 	bool "NXP MXC I2C driver"
 	help
drivers/i2c/Makefile +1 -0
index e851ec4..7227742 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_SYS_I2C_LPC32XX) += lpc32xx_i2c.o
 obj-$(CONFIG_SYS_I2C_MESON) += meson_i2c.o
 obj-$(CONFIG_SYS_I2C_MVTWSI) += mvtwsi.o
 obj-$(CONFIG_SYS_I2C_MXC) += mxc_i2c.o
+obj-$(CONFIG_SYS_I2C_MTK) += mt_i2c.o
 obj-$(CONFIG_SYS_I2C_NEXELL) += nx_i2c.o
 obj-$(CONFIG_SYS_I2C_OCTEON) += octeon_i2c.o
 obj-$(CONFIG_SYS_I2C_OMAP24XX) += omap24xx_i2c.o
drivers/i2c/mt_i2c.c new file +619 -0

619 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

PATCH 1/3 i2c: mediatek: add basic driver support

Hello mingming,

Am 09.09.2020 um 08:07 schrieb mingming lee:

Quoted 11 lines

From: Mingming Lee <[email protected]>

Add MediaTek I2C basic driver

---
  drivers/i2c/Kconfig  |   9 +
  drivers/i2c/Makefile |   1 +
  drivers/i2c/mt_i2c.c | 619 +++++++++++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 629 insertions(+)

create mode 100644 drivers/i2c/mt_i2c.c

Nitpicks only:

As you introduce here new DTS bindings, can you please document them in u-boot:/doc/device-tree-bindings/

Thanks!

[snip]

Quoted 16 lines
drivers/i2c/mt_i2c.c new file +10 -0
new file mode 100644
index 0000000..5badde9
@@ -0,0 +1,619 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MediaTek I2C Interface driver
+ *
+ * Copyright (C) 2020 MediaTek Inc.
+ * Author: Mingming Lee <[email protected]>
+ */
+
+#include <asm/cache.h>
+#include <asm/io.h>

drivers/i2c/mt_i2c.c line 20

Quoted 10 lines
drivers/i2c/mt_i2c.c new file +10 -0
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+#include <i2c.h>
+#include <linux/delay.h>
+
+#define I2C_OK			0
+#define EINVAL_I2C		22  /* invalid argument */
+#define ETIMEDOUT_I2C		110 /* connection timed out */
+#define EACK_I2C		6   /* remote I/O error */

You could use defines from include/linux/errno.h ?

[snip]

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#3 lore raw

PATCH 1/3 i2c: mediatek: add basic driver support

Quoted 15 lines · Heiko Schocher

Hello mingming,

Am 09.09.2020 um 08:07 schrieb mingming lee:

Quoted 11 lines

From: Mingming Lee <[email protected]>

Add MediaTek I2C basic driver

---
  drivers/i2c/Kconfig  |   9 +
  drivers/i2c/Makefile |   1 +
  drivers/i2c/mt_i2c.c | 619 +++++++++++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 629 insertions(+)

create mode 100644 drivers/i2c/mt_i2c.c

Quoted 5 lines

Nitpicks only:

As you introduce here new DTS bindings, can you please document them in u-boot:/doc/device-tree-bindings/

----->thank you for for advice, I would add the new DTS bingding in next version.

Quoted 24 lines

Thanks!

[snip]

Quoted 20 lines
drivers/i2c/mt_i2c.c new file +14 -0
new file mode 100644
index 0000000..5badde9
@@ -0,0 +1,619 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MediaTek I2C Interface driver
+ *
+ * Copyright (C) 2020 MediaTek Inc.
+ * Author: Mingming Lee <[email protected]>
+ */
+
+#include <asm/cache.h>
+#include <asm/io.h>
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+#include <i2c.h>
Quoted 9 lines

drivers/i2c/mt_i2c.c line 20

Quoted 6 lines
drivers/i2c/mt_i2c.c new file +6 -0
+#include <linux/delay.h>
+
+#define I2C_OK			0
+#define EINVAL_I2C		22  /* invalid argument */
+#define ETIMEDOUT_I2C		110 /* connection timed out */
+#define EACK_I2C		6   /* remote I/O error */

You could use defines from include/linux/errno.h ?

------->I think it is better to use the define from include/linux/errno.h, and I would modify it in next version today.

Quoted 9 lines

[snip]

Thanks!

bye,
Heiko

#4 lore raw

PATCH 2/3 ARM: dts: Mediatek: add i2c node support for mt8512

In reply to mingming lee

From: Mingming Lee <[email protected]>

add i2c dts node support for mt8512

---
 arch/arm/dts/mt8512-bm1-emmc.dts | 12 ++++++++++++
 arch/arm/dts/mt8512.dtsi         | 38 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletion(-)
arch/arm/dts/mt8512-bm1-emmc.dts +12 -0
index 296ed93..7c02539 100644
@@ -45,6 +45,18 @@
 	};
 };
 
+&i2c0 {
+	status = "okay";
+};
+
+&i2c1 {
+	status = "okay";
+};
+
+&i2c2 {
+	status = "okay";
+};
+
 &mmc0 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&mmc0_pins_default>;
arch/arm/dts/mt8512.dtsi +37 -1
index 01a02a7..39e9499 100644
@@ -90,6 +90,42 @@
 		reg = <0x10200a80 0x50>;
 	};
 
+	i2c0: i2c at 11007000 {
+		compatible = "mediatek,mt8512-i2c";
+		reg = <0x11007000 0x1000>,
+			  <0x11000080 0x80>;
+		clocks = <&infracfg CLK_INFRA_I2C0_AXI>,
+					<&infracfg CLK_INFRA_AP_DMA>;
+		clock-names = "main", "dma";
+		#address-cells = <1>;
+		#size-cells = <0>;
+		status = "disabled";
+	};
+
+	i2c1: i2c at 10019000 {
+		compatible = "mediatek,mt8512-i2c";
+		reg = <0x10019000 0x1000>,
+			  <0x11000100 0x80>;
+		clocks = <&infracfg CLK_INFRA_I2C1_AXI>,
+				<&infracfg CLK_INFRA_AP_DMA>;
+		clock-names = "main", "dma";
+		#address-cells = <1>;
+		#size-cells = <0>;
+		status = "disabled";
+	};
+
+	i2c2: i2c at 1001e000 {
+		compatible = "mediatek,mt8512-i2c";
+		reg = <0x1001e000 0x1000>,
+			  <0x11000180 0x80>;
+		clocks = <&infracfg CLK_INFRA_I2C1_AXI>,
+					<&infracfg CLK_INFRA_AP_DMA>;
+		clock-names = "main", "dma";
+		#address-cells = <1>;
+		#size-cells = <0>;
+		status = "disabled";
+	};
+
 	uart0: serial at 11002000 {
 		compatible = "mediatek,hsuart";
 		reg = <0x11002000 0x1000>;
@@ -112,4 +148,4 @@
 		status = "disabled";
 	};
 
-};
\ No newline at end of file
+};
Signature · 1 line
1.9.1
#5 lore raw

PATCH 2/3 ARM: dts: Mediatek: add i2c node support for mt8512

Hello mingming,

Am 09.09.2020 um 08:07 schrieb mingming lee:

Quoted 9 lines

From: Mingming Lee <[email protected]>

add i2c dts node support for mt8512

---
  arch/arm/dts/mt8512-bm1-emmc.dts | 12 ++++++++++++
  arch/arm/dts/mt8512.dtsi         | 38 +++++++++++++++++++++++++++++++++++++-
  2 files changed, 49 insertions(+), 1 deletion(-)

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#6 lore raw

PATCH 3/3 configs: mt8512: Enable I2C related configs

In reply to mingming lee

From: Mingming Lee <[email protected]>

Enable MTK I2C
Enable I2C basic command

---
 configs/mt8512_bm1_emmc_defconfig | 3 +++
 1 file changed, 3 insertions(+)
configs/mt8512_bm1_emmc_defconfig +3 -0
index 10a2083..6b3d9a4 100644
@@ -33,3 +33,6 @@ CONFIG_MTK_TIMER=y
 CONFIG_WDT=y
 CONFIG_WDT_MTK=y
 CONFIG_LZO=y
+CONFIG_CMD_I2C=y
+CONFIG_DM_I2C=y
+CONFIG_SYS_I2C_MTK=y
Signature · 1 line
1.9.1
#7 lore raw

PATCH 3/3 configs: mt8512: Enable I2C related configs

Hello mingming,

Am 09.09.2020 um 08:07 schrieb mingming lee:

Quoted 9 lines

From: Mingming Lee <[email protected]>

Enable MTK I2C
Enable I2C basic command

---
  configs/mt8512_bm1_emmc_defconfig | 3 +++
  1 file changed, 3 insertions(+)

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de