diff mbox series

[7/7] arm64: dts: qcom: msm8916-samsung-fortuna: Add NFC

Message ID 20230622000437.48367-1-linmengbo0689@protonmail.com
State New
Headers show
Series arm64: dts: qcom: msm8916-samsung-fortuna: Add initial device trees | expand

Commit Message

Lin, Meng-Bo June 22, 2023, 12:05 a.m. UTC
From: Joe Mason <buddyjojo06@outlook.com>

The Samsung Galaxy Ace 4, Core Prime and some Grand Prime have a
Samsung S3FWRN5 NFC chip that works quite well with the s3fwrn5 driver
in the Linux NFC subsystem.

The clock setup for the NFC chip is a bit special (although this
seems to be a common approach used for Qualcomm devices with NFC):

The NFC chip has an output GPIO that is asserted whenever the clock
is needed to function properly. On the A3/A5 this is wired up to
PM8916 GPIO2, which is then configured with a special function
(NFC_CLK_REQ or BB_CLK2_REQ).

Enabling the rpmcc RPM_SMD_BB_CLK2_PIN clock will then instruct
PM8916 to automatically enable the clock whenever the NFC chip
requests it. The advantage is that the clock is only enabled when
needed and we don't need to manage it ourselves from the NFC driver.

Grand Prime SM-G530Y (fortunaltezt) has a NXP PN547, which is supported
by the nxp-nci-i2c driver in mainline.

It seems to detect NFC tags using "nfctool" just fine, although more
testing is difficult given there seem to be very few useful applications
making use of the Linux NFC subsystem.

Signed-off-by: Joe Mason <buddyjojo06@outlook.com>
[Put i2c-nfc and NFC pinctrl into fortuna.dtsi to share it with other variants]
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
[Add pn547_nfc]
Signed-off-by: Lin, Meng-Bo <linmengbo0689@protonmail.com>
---
 .../dts/qcom/msm8216-samsung-fortuna3g.dts    |  5 ++
 .../qcom/msm8916-samsung-fortuna-common.dtsi  | 81 +++++++++++++++++++
 .../dts/qcom/msm8916-samsung-fortunaltezt.dts |  4 +
 .../dts/qcom/msm8916-samsung-gprimeltecan.dts | 25 ++++++
 .../qcom/msm8916-samsung-grandprimelte.dts    |  4 +
 .../qcom/msm8916-samsung-rossa-common.dtsi    |  4 +
 6 files changed, 123 insertions(+)

Comments

Krzysztof Kozlowski June 22, 2023, 3:20 p.m. UTC | #1
On 22/06/2023 02:05, Lin, Meng-Bo wrote:
> From: Joe Mason <buddyjojo06@outlook.com>
> 
> The Samsung Galaxy Ace 4, Core Prime and some Grand Prime have a
> Samsung S3FWRN5 NFC chip that works quite well with the s3fwrn5 driver
> in the Linux NFC subsystem.
> 
> The clock setup for the NFC chip is a bit special (although this
> seems to be a common approach used for Qualcomm devices with NFC):
> 
> The NFC chip has an output GPIO that is asserted whenever the clock
> is needed to function properly. On the A3/A5 this is wired up to
> PM8916 GPIO2, which is then configured with a special function
> (NFC_CLK_REQ or BB_CLK2_REQ).
> 
> Enabling the rpmcc RPM_SMD_BB_CLK2_PIN clock will then instruct
> PM8916 to automatically enable the clock whenever the NFC chip
> requests it. The advantage is that the clock is only enabled when
> needed and we don't need to manage it ourselves from the NFC driver.
> 
> Grand Prime SM-G530Y (fortunaltezt) has a NXP PN547, which is supported
> by the nxp-nci-i2c driver in mainline.
> 
> It seems to detect NFC tags using "nfctool" just fine, although more
> testing is difficult given there seem to be very few useful applications
> making use of the Linux NFC subsystem.
> 
> Signed-off-by: Joe Mason <buddyjojo06@outlook.com>
> [Put i2c-nfc and NFC pinctrl into fortuna.dtsi to share it with other variants]
> Signed-off-by: Stephan Gerhold <stephan@gerhold.net>

This and other SoB chains look like missing Co-developed-by.

> [Add pn547_nfc]
> Signed-off-by: Lin, Meng-Bo <linmengbo0689@protonmail.com>
> ---


> +		/* Available NFC chip varies depending on model variant */
> +		pn547_nfc: nfc@2b {
> +			compatible = "nxp,pn547", "nxp,nxp-nci-i2c";
> +			reg = <0x2b>;
> +
> +			interrupt-parent = <&tlmm>;
> +			interrupts = <21 IRQ_TYPE_EDGE_RISING>;
> +
> +			enable-gpios = <&tlmm 20 GPIO_ACTIVE_HIGH>;
> +			firmware-gpios = <&tlmm 49 GPIO_ACTIVE_HIGH>;
> +
> +			pinctrl-0 = <&nfc_default>;
> +			pinctrl-names = "default";
> +
> +			status = "disabled";
> +		};
> +
> +		s3fwrn5_nfc: nfc@27 {
> +			compatible = "samsung,s3fwrn5-i2c";
> +			reg = <0x27>;
> +
> +			interrupt-parent = <&tlmm>;
> +			interrupts = <21 IRQ_TYPE_EDGE_RISING>;
> +
> +			en-gpios = <&tlmm 20 GPIO_ACTIVE_HIGH>;
> +			wake-gpios = <&tlmm 49 GPIO_ACTIVE_HIGH>;
> +
> +			clocks = <&rpmcc RPM_SMD_BB_CLK2_PIN>;
> +
> +			pinctrl-0 = <&nfc_default>, <&nfc_clk_req>;
> +			pinctrl-names = "default";
> +
> +			status = "disabled";

Common part does not have two NFCs. It seems common part has zero
NFCs... or should be put into different file.

Best regards,
Krzysztof
diff mbox series

Patch

diff --git a/arch/arm64/boot/dts/qcom/msm8216-samsung-fortuna3g.dts b/arch/arm64/boot/dts/qcom/msm8216-samsung-fortuna3g.dts
index e7f6df229f9a..694a9962ee22 100644
--- a/arch/arm64/boot/dts/qcom/msm8216-samsung-fortuna3g.dts
+++ b/arch/arm64/boot/dts/qcom/msm8216-samsung-fortuna3g.dts
@@ -10,6 +10,11 @@  / {
 	chassis-type = "handset";
 };
 
+&i2c_nfc {
+	/* 3G variant doesn't have NFC */
+	status = "disabled";
+};
+
 &st_accel {
 	status = "okay";
 };
diff --git a/arch/arm64/boot/dts/qcom/msm8916-samsung-fortuna-common.dtsi b/arch/arm64/boot/dts/qcom/msm8916-samsung-fortuna-common.dtsi
index 0436b8ccc3e8..e58cce5d1879 100644
--- a/arch/arm64/boot/dts/qcom/msm8916-samsung-fortuna-common.dtsi
+++ b/arch/arm64/boot/dts/qcom/msm8916-samsung-fortuna-common.dtsi
@@ -4,6 +4,7 @@ 
 #include <dt-bindings/gpio/gpio.h>
 #include <dt-bindings/input/input.h>
 #include <dt-bindings/interrupt-controller/irq.h>
+#include <dt-bindings/pinctrl/qcom,pmic-gpio.h>
 
 / {
 	aliases {
@@ -52,6 +53,53 @@  haptic {
 		max-microvolt = <3300000>;
 	};
 
+	i2c_nfc: i2c-nfc {
+		compatible = "i2c-gpio";
+		sda-gpios = <&tlmm 0 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
+		scl-gpios = <&tlmm 1 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
+
+		pinctrl-0 = <&nfc_i2c_default>;
+		pinctrl-names = "default";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		/* Available NFC chip varies depending on model variant */
+		pn547_nfc: nfc@2b {
+			compatible = "nxp,pn547", "nxp,nxp-nci-i2c";
+			reg = <0x2b>;
+
+			interrupt-parent = <&tlmm>;
+			interrupts = <21 IRQ_TYPE_EDGE_RISING>;
+
+			enable-gpios = <&tlmm 20 GPIO_ACTIVE_HIGH>;
+			firmware-gpios = <&tlmm 49 GPIO_ACTIVE_HIGH>;
+
+			pinctrl-0 = <&nfc_default>;
+			pinctrl-names = "default";
+
+			status = "disabled";
+		};
+
+		s3fwrn5_nfc: nfc@27 {
+			compatible = "samsung,s3fwrn5-i2c";
+			reg = <0x27>;
+
+			interrupt-parent = <&tlmm>;
+			interrupts = <21 IRQ_TYPE_EDGE_RISING>;
+
+			en-gpios = <&tlmm 20 GPIO_ACTIVE_HIGH>;
+			wake-gpios = <&tlmm 49 GPIO_ACTIVE_HIGH>;
+
+			clocks = <&rpmcc RPM_SMD_BB_CLK2_PIN>;
+
+			pinctrl-0 = <&nfc_default>, <&nfc_clk_req>;
+			pinctrl-names = "default";
+
+			status = "disabled";
+		};
+	};
+
 	reg_motor_vdd: regulator-motor-vdd {
 		compatible = "regulator-fixed";
 		regulator-name = "motor_vdd";
@@ -286,6 +334,29 @@  muic_int_default: muic-int-default-state {
 		bias-disable;
 	};
 
+	nfc_default: nfc-default-state {
+		nfc-pins {
+			pins = "gpio20", "gpio49";
+			function = "gpio";
+			drive-strength = <2>;
+			bias-disable;
+		};
+
+		irq-pins {
+			pins = "gpio21";
+			function = "gpio";
+			drive-strength = <2>;
+			bias-pull-down;
+		};
+	};
+
+	nfc_i2c_default: nfc-i2c-default-state {
+		pins = "gpio0", "gpio1";
+		function = "gpio";
+		drive-strength = <2>;
+		bias-disable;
+	};
+
 	sdc2_cd_default: sdc2-cd-default-state {
 		pins = "gpio38";
 		function = "gpio";
@@ -307,3 +378,13 @@  tsp_int_default: tsp-int-default-state {
 		bias-disable;
 	};
 };
+
+&pm8916_gpios {
+	nfc_clk_req: nfc-clk-req-state {
+		pins = "gpio2";
+		function = "func1";
+		power-source = <PM8916_GPIO_L2>;
+		bias-disable;
+		input-enable;
+	};
+};
diff --git a/arch/arm64/boot/dts/qcom/msm8916-samsung-fortunaltezt.dts b/arch/arm64/boot/dts/qcom/msm8916-samsung-fortunaltezt.dts
index 0716ef577df1..eb033f555184 100644
--- a/arch/arm64/boot/dts/qcom/msm8916-samsung-fortunaltezt.dts
+++ b/arch/arm64/boot/dts/qcom/msm8916-samsung-fortunaltezt.dts
@@ -22,6 +22,10 @@  / {
 	chassis-type = "handset";
 };
 
+&pn547_nfc {
+	status = "okay";
+};
+
 &st_accel {
 	compatible = "st,lis2hh12";
 	mount-matrix = "1",  "0", "0",
diff --git a/arch/arm64/boot/dts/qcom/msm8916-samsung-gprimeltecan.dts b/arch/arm64/boot/dts/qcom/msm8916-samsung-gprimeltecan.dts
index b0d8ac3d6ce9..1a24e00e2024 100644
--- a/arch/arm64/boot/dts/qcom/msm8916-samsung-gprimeltecan.dts
+++ b/arch/arm64/boot/dts/qcom/msm8916-samsung-gprimeltecan.dts
@@ -21,6 +21,26 @@  tz-apps@85500000 {
 	};
 };
 
+&blsp_i2c6 {
+	status = "okay";
+
+	nfc@27 {
+		compatible = "samsung,s3fwrn5-i2c";
+		reg = <0x27>;
+
+		interrupt-parent = <&tlmm>;
+		interrupts = <21 IRQ_TYPE_EDGE_RISING>;
+
+		en-gpios = <&tlmm 20 GPIO_ACTIVE_HIGH>;
+		wake-gpios = <&tlmm 49 GPIO_ACTIVE_HIGH>;
+
+		clocks = <&rpmcc RPM_SMD_BB_CLK2_PIN>;
+
+		pinctrl-0 = <&nfc_default>, <&nfc_clk_req>;
+		pinctrl-names = "default";
+	};
+};
+
 &bosch_accel {
 	status = "okay";
 };
@@ -28,3 +48,8 @@  &bosch_accel {
 &bosch_magn {
 	status = "okay";
 };
+
+&i2c_nfc {
+	/* Used for MFD instead. NFC is on i2c6 */
+	status = "disabled";
+};
diff --git a/arch/arm64/boot/dts/qcom/msm8916-samsung-grandprimelte.dts b/arch/arm64/boot/dts/qcom/msm8916-samsung-grandprimelte.dts
index f7fc538fda04..090b8fb6b444 100644
--- a/arch/arm64/boot/dts/qcom/msm8916-samsung-grandprimelte.dts
+++ b/arch/arm64/boot/dts/qcom/msm8916-samsung-grandprimelte.dts
@@ -17,3 +17,7 @@  &bosch_accel {
 &bosch_magn {
 	status = "okay";
 };
+
+&s3fwrn5_nfc {
+	status = "okay";
+};
diff --git a/arch/arm64/boot/dts/qcom/msm8916-samsung-rossa-common.dtsi b/arch/arm64/boot/dts/qcom/msm8916-samsung-rossa-common.dtsi
index 39f99b5030e5..dbc4ee8719a6 100644
--- a/arch/arm64/boot/dts/qcom/msm8916-samsung-rossa-common.dtsi
+++ b/arch/arm64/boot/dts/qcom/msm8916-samsung-rossa-common.dtsi
@@ -23,6 +23,10 @@  &blsp_i2c5 {
 	/delete-node/ touchscreen@20;
 };
 
+&s3fwrn5_nfc {
+	status = "okay";
+};
+
 &st_accel {
 	compatible = "st,lis2hh12";
 	mount-matrix = "1",  "0", "0",