linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] Handle amd_sfh work buffer and interrupts
@ 2022-02-08 12:21 Basavaraj Natikar
  2022-02-08 12:21 ` [PATCH 1/5] HID: amd_sfh: Handle amd_sfh work buffer in PM ops Basavaraj Natikar
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Basavaraj Natikar @ 2022-02-08 12:21 UTC (permalink / raw)
  To: jikos, benjamin.tissoires, linux-input, Nehal-Bakulchandra.shah
  Cc: Basavaraj Natikar

Changes include to handle amd_sfh work buffer in PM operations, disable
interrupts for sensors commands, process and clear interrupts on 
newer AMD platforms like Renoir, Cezanne.

Basavaraj Natikar (5):
  HID: amd_sfh: Handle amd_sfh work buffer in PM ops
  HID: amd_sfh: Correct the structure field name
  HID: amd_sfh: Disable the interrupt for all command
  HID: amd_sfh: Add functionality to clear interrupts
  HID: amd_sfh: Add interrupt handler to process interrupts

 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 72 +++++++++++++++++++++++++-
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.h |  4 +-
 2 files changed, 74 insertions(+), 2 deletions(-)

-- 
2.25.1


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

* [PATCH 1/5] HID: amd_sfh: Handle amd_sfh work buffer in PM ops
  2022-02-08 12:21 [PATCH 0/5] Handle amd_sfh work buffer and interrupts Basavaraj Natikar
@ 2022-02-08 12:21 ` Basavaraj Natikar
  2022-02-08 12:21 ` [PATCH 2/5] HID: amd_sfh: Correct the structure field name Basavaraj Natikar
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Basavaraj Natikar @ 2022-02-08 12:21 UTC (permalink / raw)
  To: jikos, benjamin.tissoires, linux-input, Nehal-Bakulchandra.shah
  Cc: Basavaraj Natikar

Since in the current amd_sfh design the sensor data is periodically
obtained in the form of poll data, during the suspend/resume cycle,
scheduling a delayed work adds no value.

So, cancel the work and restart back during the suspend/resume cycle
respectively.

Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
---
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
index d3f32ffe299a..dacac30a6b27 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
@@ -290,6 +290,8 @@ static int __maybe_unused amd_mp2_pci_resume(struct device *dev)
 		}
 	}
 
+	schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
+
 	return 0;
 }
 
@@ -312,6 +314,8 @@ static int __maybe_unused amd_mp2_pci_suspend(struct device *dev)
 		}
 	}
 
+	cancel_delayed_work_sync(&cl_data->work_buffer);
+
 	return 0;
 }
 
-- 
2.25.1


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

* [PATCH 2/5] HID: amd_sfh: Correct the structure field name
  2022-02-08 12:21 [PATCH 0/5] Handle amd_sfh work buffer and interrupts Basavaraj Natikar
  2022-02-08 12:21 ` [PATCH 1/5] HID: amd_sfh: Handle amd_sfh work buffer in PM ops Basavaraj Natikar
@ 2022-02-08 12:21 ` Basavaraj Natikar
  2022-02-08 12:21 ` [PATCH 3/5] HID: amd_sfh: Disable the interrupt for all command Basavaraj Natikar
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Basavaraj Natikar @ 2022-02-08 12:21 UTC (permalink / raw)
  To: jikos, benjamin.tissoires, linux-input, Nehal-Bakulchandra.shah
  Cc: Basavaraj Natikar

Misinterpreted intr_enable field name. Hence correct the structure
field name accordingly to reflect the functionality.

Fixes: f264481ad614 ("HID: amd_sfh: Extend driver capabilities for multi-generation support")
Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
---
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
index ae30e059f847..8a9c544c27ae 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
@@ -49,7 +49,7 @@ union sfh_cmd_base {
 	} s;
 	struct {
 		u32 cmd_id : 4;
-		u32 intr_enable : 1;
+		u32 intr_disable : 1;
 		u32 rsvd1 : 3;
 		u32 length : 7;
 		u32 mem_type : 1;
-- 
2.25.1


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

* [PATCH 3/5] HID: amd_sfh: Disable the interrupt for all command
  2022-02-08 12:21 [PATCH 0/5] Handle amd_sfh work buffer and interrupts Basavaraj Natikar
  2022-02-08 12:21 ` [PATCH 1/5] HID: amd_sfh: Handle amd_sfh work buffer in PM ops Basavaraj Natikar
  2022-02-08 12:21 ` [PATCH 2/5] HID: amd_sfh: Correct the structure field name Basavaraj Natikar
@ 2022-02-08 12:21 ` Basavaraj Natikar
  2022-02-08 12:21 ` [PATCH 4/5] HID: amd_sfh: Add functionality to clear interrupts Basavaraj Natikar
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Basavaraj Natikar @ 2022-02-08 12:21 UTC (permalink / raw)
  To: jikos, benjamin.tissoires, linux-input, Nehal-Bakulchandra.shah
  Cc: Basavaraj Natikar

Sensor data is processed in polling mode. Hence disable the interrupt
for all sensor command.

Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
---
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
index dacac30a6b27..16670e910014 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
@@ -53,6 +53,7 @@ static void amd_start_sensor_v2(struct amd_mp2_dev *privdata, struct amd_mp2_sen
 
 	cmd_base.ul = 0;
 	cmd_base.cmd_v2.cmd_id = ENABLE_SENSOR;
+	cmd_base.cmd_v2.intr_disable = 1;
 	cmd_base.cmd_v2.period = info.period;
 	cmd_base.cmd_v2.sensor_id = info.sensor_idx;
 	cmd_base.cmd_v2.length = 16;
@@ -70,6 +71,7 @@ static void amd_stop_sensor_v2(struct amd_mp2_dev *privdata, u16 sensor_idx)
 
 	cmd_base.ul = 0;
 	cmd_base.cmd_v2.cmd_id = DISABLE_SENSOR;
+	cmd_base.cmd_v2.intr_disable = 1;
 	cmd_base.cmd_v2.period = 0;
 	cmd_base.cmd_v2.sensor_id = sensor_idx;
 	cmd_base.cmd_v2.length  = 16;
@@ -83,6 +85,7 @@ static void amd_stop_all_sensor_v2(struct amd_mp2_dev *privdata)
 	union sfh_cmd_base cmd_base;
 
 	cmd_base.cmd_v2.cmd_id = STOP_ALL_SENSORS;
+	cmd_base.cmd_v2.intr_disable = 1;
 	cmd_base.cmd_v2.period = 0;
 	cmd_base.cmd_v2.sensor_id = 0;
 
-- 
2.25.1


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

* [PATCH 4/5] HID: amd_sfh: Add functionality to clear interrupts
  2022-02-08 12:21 [PATCH 0/5] Handle amd_sfh work buffer and interrupts Basavaraj Natikar
                   ` (2 preceding siblings ...)
  2022-02-08 12:21 ` [PATCH 3/5] HID: amd_sfh: Disable the interrupt for all command Basavaraj Natikar
@ 2022-02-08 12:21 ` Basavaraj Natikar
  2022-02-08 12:21 ` [PATCH 5/5] HID: amd_sfh: Add interrupt handler to process interrupts Basavaraj Natikar
  2022-02-14 15:29 ` [PATCH 0/5] Handle amd_sfh work buffer and interrupts Jiri Kosina
  5 siblings, 0 replies; 7+ messages in thread
From: Basavaraj Natikar @ 2022-02-08 12:21 UTC (permalink / raw)
  To: jikos, benjamin.tissoires, linux-input, Nehal-Bakulchandra.shah
  Cc: Basavaraj Natikar

Newer AMD platforms with SFH may generate interrupts on some events
which are unwarranted. Until this is cleared the actual MP2 data
processing maybe stalled in some cases.

Add a mechanism to clear the pending interrupts (if any) during the
driver initialization and sensor command operations.

Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
---
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 25 ++++++++++++++++++++++++-
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.h |  1 +
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
index 16670e910014..7236b223fb68 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
@@ -92,6 +92,20 @@ static void amd_stop_all_sensor_v2(struct amd_mp2_dev *privdata)
 	writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG0);
 }
 
+static void amd_sfh_clear_intr_v2(struct amd_mp2_dev *privdata)
+{
+	if (readl(privdata->mmio + AMD_P2C_MSG(4))) {
+		writel(0, privdata->mmio + AMD_P2C_MSG(4));
+		writel(0xf, privdata->mmio + AMD_P2C_MSG(5));
+	}
+}
+
+static void amd_sfh_clear_intr(struct amd_mp2_dev *privdata)
+{
+	if (privdata->mp2_ops->clear_intr)
+		privdata->mp2_ops->clear_intr(privdata);
+}
+
 void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info)
 {
 	union sfh_cmd_param cmd_param;
@@ -196,6 +210,7 @@ static void amd_mp2_pci_remove(void *privdata)
 	struct amd_mp2_dev *mp2 = privdata;
 	amd_sfh_hid_client_deinit(privdata);
 	mp2->mp2_ops->stop_all(mp2);
+	amd_sfh_clear_intr(mp2);
 }
 
 static const struct amd_mp2_ops amd_sfh_ops_v2 = {
@@ -203,6 +218,7 @@ static const struct amd_mp2_ops amd_sfh_ops_v2 = {
 	.stop = amd_stop_sensor_v2,
 	.stop_all = amd_stop_all_sensor_v2,
 	.response = amd_sfh_wait_response_v2,
+	.clear_intr = amd_sfh_clear_intr_v2,
 };
 
 static const struct amd_mp2_ops amd_sfh_ops = {
@@ -265,8 +281,13 @@ static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i
 	mp2_select_ops(privdata);
 
 	rc = amd_sfh_hid_client_init(privdata);
-	if (rc)
+	if (rc) {
+		amd_sfh_clear_intr(privdata);
+		dev_err(&pdev->dev, "amd_sfh_hid_client_init failed\n");
 		return rc;
+	}
+
+	amd_sfh_clear_intr(privdata);
 
 	return devm_add_action_or_reset(&pdev->dev, amd_mp2_pci_remove, privdata);
 }
@@ -294,6 +315,7 @@ static int __maybe_unused amd_mp2_pci_resume(struct device *dev)
 	}
 
 	schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
+	amd_sfh_clear_intr(mp2);
 
 	return 0;
 }
@@ -318,6 +340,7 @@ static int __maybe_unused amd_mp2_pci_suspend(struct device *dev)
 	}
 
 	cancel_delayed_work_sync(&cl_data->work_buffer);
+	amd_sfh_clear_intr(mp2);
 
 	return 0;
 }
diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
index 8a9c544c27ae..61de09ba5124 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
@@ -141,5 +141,6 @@ struct amd_mp2_ops {
 	 void (*stop)(struct amd_mp2_dev *privdata, u16 sensor_idx);
 	 void (*stop_all)(struct amd_mp2_dev *privdata);
 	 int (*response)(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
+	 void (*clear_intr)(struct amd_mp2_dev *privdata);
 };
 #endif
-- 
2.25.1


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

* [PATCH 5/5] HID: amd_sfh: Add interrupt handler to process interrupts
  2022-02-08 12:21 [PATCH 0/5] Handle amd_sfh work buffer and interrupts Basavaraj Natikar
                   ` (3 preceding siblings ...)
  2022-02-08 12:21 ` [PATCH 4/5] HID: amd_sfh: Add functionality to clear interrupts Basavaraj Natikar
@ 2022-02-08 12:21 ` Basavaraj Natikar
  2022-02-14 15:29 ` [PATCH 0/5] Handle amd_sfh work buffer and interrupts Jiri Kosina
  5 siblings, 0 replies; 7+ messages in thread
From: Basavaraj Natikar @ 2022-02-08 12:21 UTC (permalink / raw)
  To: jikos, benjamin.tissoires, linux-input, Nehal-Bakulchandra.shah
  Cc: Basavaraj Natikar

On newer AMD platforms with SFH, it is observed that random interrupts
get generated on the SFH hardware and until this is cleared the firmware
sensor processing is stalled, resulting in no data been received to
driver side.

Add routines to handle these interrupts, so that firmware operations are
not stalled.

Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
---
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 40 ++++++++++++++++++++++++++
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.h |  1 +
 2 files changed, 41 insertions(+)

diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
index 7236b223fb68..19fa734a9a79 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
@@ -106,6 +106,30 @@ static void amd_sfh_clear_intr(struct amd_mp2_dev *privdata)
 		privdata->mp2_ops->clear_intr(privdata);
 }
 
+static irqreturn_t amd_sfh_irq_handler(int irq, void *data)
+{
+	amd_sfh_clear_intr(data);
+
+	return IRQ_HANDLED;
+}
+
+static int amd_sfh_irq_init_v2(struct amd_mp2_dev *privdata)
+{
+	int rc;
+
+	pci_intx(privdata->pdev, true);
+
+	rc = devm_request_irq(&privdata->pdev->dev, privdata->pdev->irq,
+			      amd_sfh_irq_handler, 0, DRIVER_NAME, privdata);
+	if (rc) {
+		dev_err(&privdata->pdev->dev, "failed to request irq %d err=%d\n",
+			privdata->pdev->irq, rc);
+		return rc;
+	}
+
+	return 0;
+}
+
 void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info)
 {
 	union sfh_cmd_param cmd_param;
@@ -210,6 +234,7 @@ static void amd_mp2_pci_remove(void *privdata)
 	struct amd_mp2_dev *mp2 = privdata;
 	amd_sfh_hid_client_deinit(privdata);
 	mp2->mp2_ops->stop_all(mp2);
+	pci_intx(mp2->pdev, false);
 	amd_sfh_clear_intr(mp2);
 }
 
@@ -219,6 +244,7 @@ static const struct amd_mp2_ops amd_sfh_ops_v2 = {
 	.stop_all = amd_stop_all_sensor_v2,
 	.response = amd_sfh_wait_response_v2,
 	.clear_intr = amd_sfh_clear_intr_v2,
+	.init_intr = amd_sfh_irq_init_v2,
 };
 
 static const struct amd_mp2_ops amd_sfh_ops = {
@@ -244,6 +270,14 @@ static void mp2_select_ops(struct amd_mp2_dev *privdata)
 	}
 }
 
+static int amd_sfh_irq_init(struct amd_mp2_dev *privdata)
+{
+	if (privdata->mp2_ops->init_intr)
+		return privdata->mp2_ops->init_intr(privdata);
+
+	return 0;
+}
+
 static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	struct amd_mp2_dev *privdata;
@@ -280,6 +314,12 @@ static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i
 
 	mp2_select_ops(privdata);
 
+	rc = amd_sfh_irq_init(privdata);
+	if (rc) {
+		dev_err(&pdev->dev, "amd_sfh_irq_init failed\n");
+		return rc;
+	}
+
 	rc = amd_sfh_hid_client_init(privdata);
 	if (rc) {
 		amd_sfh_clear_intr(privdata);
diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
index 61de09ba5124..97b99861fae2 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
@@ -142,5 +142,6 @@ struct amd_mp2_ops {
 	 void (*stop_all)(struct amd_mp2_dev *privdata);
 	 int (*response)(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
 	 void (*clear_intr)(struct amd_mp2_dev *privdata);
+	 int (*init_intr)(struct amd_mp2_dev *privdata);
 };
 #endif
-- 
2.25.1


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

* Re: [PATCH 0/5] Handle amd_sfh work buffer and interrupts
  2022-02-08 12:21 [PATCH 0/5] Handle amd_sfh work buffer and interrupts Basavaraj Natikar
                   ` (4 preceding siblings ...)
  2022-02-08 12:21 ` [PATCH 5/5] HID: amd_sfh: Add interrupt handler to process interrupts Basavaraj Natikar
@ 2022-02-14 15:29 ` Jiri Kosina
  5 siblings, 0 replies; 7+ messages in thread
From: Jiri Kosina @ 2022-02-14 15:29 UTC (permalink / raw)
  To: Basavaraj Natikar
  Cc: benjamin.tissoires, linux-input, Nehal-Bakulchandra.shah

On Tue, 8 Feb 2022, Basavaraj Natikar wrote:

> Changes include to handle amd_sfh work buffer in PM operations, disable
> interrupts for sensors commands, process and clear interrupts on 
> newer AMD platforms like Renoir, Cezanne.
> 
> Basavaraj Natikar (5):
>   HID: amd_sfh: Handle amd_sfh work buffer in PM ops
>   HID: amd_sfh: Correct the structure field name
>   HID: amd_sfh: Disable the interrupt for all command
>   HID: amd_sfh: Add functionality to clear interrupts
>   HID: amd_sfh: Add interrupt handler to process interrupts
> 
>  drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 72 +++++++++++++++++++++++++-
>  drivers/hid/amd-sfh-hid/amd_sfh_pcie.h |  4 +-
>  2 files changed, 74 insertions(+), 2 deletions(-)

I have queued this for 5.17 still.

Thanks,

-- 
Jiri Kosina
SUSE Labs


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

end of thread, other threads:[~2022-02-14 15:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-08 12:21 [PATCH 0/5] Handle amd_sfh work buffer and interrupts Basavaraj Natikar
2022-02-08 12:21 ` [PATCH 1/5] HID: amd_sfh: Handle amd_sfh work buffer in PM ops Basavaraj Natikar
2022-02-08 12:21 ` [PATCH 2/5] HID: amd_sfh: Correct the structure field name Basavaraj Natikar
2022-02-08 12:21 ` [PATCH 3/5] HID: amd_sfh: Disable the interrupt for all command Basavaraj Natikar
2022-02-08 12:21 ` [PATCH 4/5] HID: amd_sfh: Add functionality to clear interrupts Basavaraj Natikar
2022-02-08 12:21 ` [PATCH 5/5] HID: amd_sfh: Add interrupt handler to process interrupts Basavaraj Natikar
2022-02-14 15:29 ` [PATCH 0/5] Handle amd_sfh work buffer and interrupts Jiri Kosina

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