Skip to contentSkip to conversation

Updates to amd-sfh driver

PATCH Applied Basavaraj Natikar 2 participants 7 messages Aug 2, 2021 – Aug 20, 2021

Subsystems (2)
lore
Share & tools
lore

Basavaraj Natikar

author maintainer
#0 lore raw

cover Updates to amd-sfh driver

Changes include updates to the existing FW reporting mechanism, MP2 FW status checks, adding power management routines and couple of other minor fixes to the existing driver.

Basavaraj Natikar (5):
amd_sfh:Fix period data field to enable sensor amd_sfh:Add command response to check command status amd_sfh:Move hid probe after sensor is enabled amd_sfh:Add support for PM suspend and resume amd_sfh:Add dyndbg prints for debugging

 drivers/hid/amd-sfh-hid/amd_sfh_client.c | 62 +++++++++++++++------
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c   | 69 ++++++++++++++++++++++++
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.h   | 23 ++++++++
 3 files changed, 139 insertions(+), 15 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 1/5 amd_sfh:Fix period data field to enable sensor

Existing amd-sfh driver is programming the MP2 firmware period field in units of jiffies, but the MP2 firmware expects in milliseconds unit.

Changing it to milliseconds.

Fixes 4b2c53d93a4b ("SFH:Transport Driver to add support of AMD Sensor Fusion Hub (SFH)")
---
 drivers/hid/amd-sfh-hid/amd_sfh_client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/amd-sfh-hid/amd_sfh_client.c +1 -1
index efb849411d25..4710b9aa24a5 100644
@@ -184,7 +184,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
 			rc = -ENOMEM;
 			goto cleanup;
 		}
-		info.period = msecs_to_jiffies(AMD_SFH_IDLE_LOOP);
+		info.period = AMD_SFH_IDLE_LOOP;
 		info.sensor_idx = cl_idx;
 		info.dma_address = cl_data->sensor_dma_addr[i];
 
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH 2/5 amd_sfh:Add command response to check command status

In reply to Basavaraj Natikar

Sometimes sensor enable/disable may take time, without checking the actual status bits from MP2 FW can lead the amd-sfh to misbehave.

Hence add a status check of enable/disable command by waiting on the command response before sending the next command to FW.

---
 drivers/hid/amd-sfh-hid/amd_sfh_client.c | 40 ++++++++++++++++++------
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c   | 16 ++++++++++
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.h   | 18 +++++++++++
 3 files changed, 64 insertions(+), 10 deletions(-)
drivers/hid/amd-sfh-hid/amd_sfh_client.c +30 -10
index 4710b9aa24a5..b7b66a1eb971 100644
@@ -123,14 +123,24 @@ static void amd_sfh_work_buffer(struct work_struct *work)
 	int i;
 
 	for (i = 0; i < cli_data->num_hid_devices; i++) {
-		report_size = get_input_report(i, cli_data->sensor_idx[i], cli_data->report_id[i],
-					       in_data);
-		hid_input_report(cli_data->hid_sensor_hubs[i], HID_INPUT_REPORT,
-				 in_data->input_report[i], report_size, 0);
+		if (cli_data->sensor_sts[i] == SENSOR_ENABLED) {
+			report_size = get_input_report
+				(i, cli_data->sensor_idx[i], cli_data->report_id[i], in_data);
+			hid_input_report(cli_data->hid_sensor_hubs[i], HID_INPUT_REPORT,
+					 in_data->input_report[i], report_size, 0);
+		}
 	}
 	schedule_delayed_work(&cli_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
 }
 
+u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts)
+{
+	if (mp2->mp2_ops->response)
+		sensor_sts = mp2->mp2_ops->response(mp2, sid, sensor_sts);
+
+	return sensor_sts;
+}
+
 int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
 {
 	struct amd_input_data *in_data = &privdata->in_data;
@@ -139,8 +149,8 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
 	struct device *dev;
 	u32 feature_report_size;
 	u32 input_report_size;
+	int rc, i, status;
 	u8 cl_idx;
-	int rc, i;
 
 	dev = &privdata->pdev->dev;
 
@@ -155,7 +165,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
 		in_data->sensor_virt_addr[i] = dma_alloc_coherent(dev, sizeof(int) * 8,
 								  &cl_data->sensor_dma_addr[i],
 								  GFP_KERNEL);
-		cl_data->sensor_sts[i] = 0;
+		cl_data->sensor_sts[i] = SENSOR_DISABLED;
 		cl_data->sensor_requested_cnt[i] = 0;
 		cl_data->cur_hid_dev = i;
 		cl_idx = cl_data->sensor_idx[i];
@@ -201,7 +211,10 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
 		if (rc)
 			return rc;
 		privdata->mp2_ops->start(privdata, info);
-		cl_data->sensor_sts[i] = 1;
+		status = amd_sfh_wait_for_response
+				(privdata, cl_data->sensor_idx[i], SENSOR_ENABLED);
+		if (status == SENSOR_ENABLED)
+			cl_data->sensor_sts[i] = SENSOR_ENABLED;
 	}
 	schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
 	return 0;
@@ -224,10 +237,17 @@ int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata)
 {
 	struct amdtp_cl_data *cl_data = privdata->cl_data;
 	struct amd_input_data *in_data = cl_data->in_data;
-	int i;
+	int i, status;
 
-	for (i = 0; i < cl_data->num_hid_devices; i++)
-		privdata->mp2_ops->stop(privdata, i);
+	for (i = 0; i < cl_data->num_hid_devices; i++) {
+		if (cl_data->sensor_sts[i] == SENSOR_ENABLED) {
+			privdata->mp2_ops->stop(privdata, cl_data->sensor_idx[i]);
+			status = amd_sfh_wait_for_response
+					(privdata, cl_data->sensor_idx[i], SENSOR_DISABLED);
+			if (status != SENSOR_ENABLED)
+				cl_data->sensor_sts[i] = SENSOR_DISABLED;
+		}
+	}
 
 	cancel_delayed_work_sync(&cl_data->work);
 	cancel_delayed_work_sync(&cl_data->work_buffer);
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +16 -0
index 8d68796aa905..fd2e3011086d 100644
@@ -13,6 +13,7 @@
 #include <linux/dmi.h>
 #include <linux/interrupt.h>
 #include <linux/io-64-nonatomic-lo-hi.h>
+#include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/slab.h>
 
@@ -31,6 +32,20 @@ static int sensor_mask_override = -1;
 module_param_named(sensor_mask, sensor_mask_override, int, 0444);
 MODULE_PARM_DESC(sensor_mask, "override the detected sensors mask");
 
+static int amd_sfh_wait_response_v2(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts)
+{
+	union cmd_response cmd_resp;
+
+	/* Get response with status within a max of 800 ms timeout */
+	if (!readl_poll_timeout(mp2->mmio + AMD_P2C_MSG(0), cmd_resp.resp,
+				(cmd_resp.response_v2.response == sensor_sts &&
+				cmd_resp.response_v2.status == 0 && (sid == 0xff ||
+				cmd_resp.response_v2.sensor_id == sid)), 500, 800000))
+		return cmd_resp.response_v2.response;
+
+	return SENSOR_DISABLED;
+}
+
 static void amd_start_sensor_v2(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info)
 {
 	union sfh_cmd_base cmd_base;
@@ -183,6 +198,7 @@ static const struct amd_mp2_ops amd_sfh_ops_v2 = {
 	.start = amd_start_sensor_v2,
 	.stop = amd_stop_sensor_v2,
 	.stop_all = amd_stop_all_sensor_v2,
+	.response = amd_sfh_wait_response_v2,
 };
 
 static const struct amd_mp2_ops amd_sfh_ops = {
drivers/hid/amd-sfh-hid/amd_sfh_pcie.h +18 -0
index 2d5c57e3782d..21ef55da712a 100644
@@ -24,12 +24,16 @@
 #define AMD_C2P_MSG2	0x10508
 
 #define AMD_C2P_MSG(regno) (0x10500 + ((regno) * 4))
+#define AMD_P2C_MSG(regno) (0x10680 + ((regno) * 4))
 
 /* MP2 P2C Message Registers */
 #define AMD_P2C_MSG3	0x1068C /* Supported Sensors info */
 
 #define V2_STATUS	0x2
 
+#define SENSOR_ENABLED     4
+#define SENSOR_DISABLED    5
+
 #define HPD_IDX		16
 
 /* SFH Command register */
@@ -51,6 +55,19 @@ union sfh_cmd_base {
 	} cmd_v2;
 };
 
+union cmd_response {
+	u32 resp;
+	struct {
+		u32 status	: 2;
+		u32 out_in_c2p	: 1;
+		u32 rsvd1	: 1;
+		u32 response	: 4;
+		u32 sub_cmd	: 8;
+		u32 sensor_id	: 6;
+		u32 rsvd2	: 10;
+	} response_v2;
+};
+
 union sfh_cmd_param {
 	u32 ul;
 	struct {
@@ -117,5 +134,6 @@ struct amd_mp2_ops {
 	 void (*start)(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info);
 	 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);
 };
 #endif
Signature · 1 line
2.25.1
author maintainer
#3 lore raw

PATCH 3/5 amd_sfh:Move hid probe after sensor is enabled

In reply to Basavaraj Natikar

Earlier platforms don’t have sensor status checking mechanism. Sensors are always enabled without checking sensor status. Hence invoke hid probe only after the sensor is enabled by checking sensor status.

---
 drivers/hid/amd-sfh-hid/amd_sfh_client.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/hid/amd-sfh-hid/amd_sfh_client.c +11 -4
index b7b66a1eb971..4982ccf9dc25 100644
@@ -205,16 +205,23 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
 			goto cleanup;
 		}
 		rc = get_report_descriptor(cl_idx, cl_data->report_descr[i]);
-		if (rc)
-			return rc;
-		rc = amdtp_hid_probe(cl_data->cur_hid_dev, cl_data);
 		if (rc)
 			return rc;
 		privdata->mp2_ops->start(privdata, info);
 		status = amd_sfh_wait_for_response
 				(privdata, cl_data->sensor_idx[i], SENSOR_ENABLED);
-		if (status == SENSOR_ENABLED)
+		if (status == SENSOR_ENABLED) {
 			cl_data->sensor_sts[i] = SENSOR_ENABLED;
+			rc = amdtp_hid_probe(cl_data->cur_hid_dev, cl_data);
+			if (rc) {
+				privdata->mp2_ops->stop(privdata, cl_data->sensor_idx[i]);
+				status = amd_sfh_wait_for_response
+					(privdata, cl_data->sensor_idx[i], SENSOR_DISABLED);
+				if (status != SENSOR_ENABLED)
+					cl_data->sensor_sts[i] = SENSOR_DISABLED;
+				goto cleanup;
+			}
+		}
 	}
 	schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
 	return 0;
Signature · 1 line
2.25.1
author maintainer
#4 lore raw

PATCH 4/5 amd_sfh:Add support for PM suspend and resume

In reply to Basavaraj Natikar

Add support for power management routines.

---
 drivers/hid/amd-sfh-hid/amd_sfh_client.c |  1 -
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c   | 49 ++++++++++++++++++++++++
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.h   |  5 +++
 3 files changed, 54 insertions(+), 1 deletion(-)
drivers/hid/amd-sfh-hid/amd_sfh_client.c +0 -1
index 4982ccf9dc25..050df796aa2e 100644
@@ -17,7 +17,6 @@
 #include "amd_sfh_pcie.h"
 #include "amd_sfh_hid.h"
 
-#define AMD_SFH_IDLE_LOOP	200
 
 struct request_list {
 	struct hid_device *hid;
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +49 -0

61 lines not on this page · raw message

drivers/hid/amd-sfh-hid/amd_sfh_pcie.h +5 -0
index 21ef55da712a..1ff6f83cb6fd 100644
@@ -36,6 +36,8 @@
 
 #define HPD_IDX		16
 
+#define AMD_SFH_IDLE_LOOP	200
+
 /* SFH Command register */
 union sfh_cmd_base {
 	u32 ul;
@@ -129,6 +131,9 @@ void amd_stop_all_sensors(struct amd_mp2_dev *privdata);
 int amd_mp2_get_sensor_num(struct amd_mp2_dev *privdata, u8 *sensor_id);
 int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata);
 int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata);
+u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
+void amd_mp2_suspend(struct amd_mp2_dev *mp2);
+void amd_mp2_resume(struct amd_mp2_dev *mp2);
 
 struct amd_mp2_ops {
 	 void (*start)(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info);
Signature · 1 line
2.25.1
author maintainer
#5 lore raw

PATCH 5/5 amd_sfh:Add dyndbg prints for debugging

In reply to Basavaraj Natikar

Add dynamic debug for debugging sensors states during initialization, stop, suspend and resume.

---
 drivers/hid/amd-sfh-hid/amd_sfh_client.c | 6 ++++++
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c   | 4 ++++
 2 files changed, 10 insertions(+)
drivers/hid/amd-sfh-hid/amd_sfh_client.c +6 -0
index 050df796aa2e..840fd075c56f 100644
@@ -218,9 +218,13 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
 					(privdata, cl_data->sensor_idx[i], SENSOR_DISABLED);
 				if (status != SENSOR_ENABLED)
 					cl_data->sensor_sts[i] = SENSOR_DISABLED;
+				dev_dbg(dev, "sid 0x%x status 0x%x\n",
+					cl_data->sensor_idx[i], cl_data->sensor_sts[i]);
 				goto cleanup;
 			}
 		}
+		dev_dbg(dev, "sid 0x%x status 0x%x\n",
+			cl_data->sensor_idx[i], cl_data->sensor_sts[i]);
 	}
 	schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
 	return 0;
@@ -252,6 +256,8 @@ int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata)
 					(privdata, cl_data->sensor_idx[i], SENSOR_DISABLED);
 			if (status != SENSOR_ENABLED)
 				cl_data->sensor_sts[i] = SENSOR_DISABLED;
+			dev_dbg(&privdata->pdev->dev, "stopping sid 0x%x status 0x%x\n",
+				cl_data->sensor_idx[i], cl_data->sensor_sts[i]);
 		}
 	}
 
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +4 -0
index bdef47118c3d..79b138fd4261 100644
@@ -282,6 +282,8 @@ static int __maybe_unused amd_mp2_pci_resume(struct device *dev)
 					(mp2, cl_data->sensor_idx[i], SENSOR_ENABLED);
 			if (status == SENSOR_ENABLED)
 				cl_data->sensor_sts[i] = SENSOR_ENABLED;
+			dev_dbg(dev, "resume sid 0x%x status 0x%x\n",
+				cl_data->sensor_idx[i], cl_data->sensor_sts[i]);
 		}
 	}
 
@@ -303,6 +305,8 @@ static int __maybe_unused amd_mp2_pci_suspend(struct device *dev)
 					(mp2, cl_data->sensor_idx[i], SENSOR_DISABLED);
 			if (status != SENSOR_ENABLED)
 				cl_data->sensor_sts[i] = SENSOR_DISABLED;
+			dev_dbg(dev, "suspend sid 0x%x status 0x%x\n",
+				cl_data->sensor_idx[i], cl_data->sensor_sts[i]);
 		}
 	}
 
Signature · 1 line
2.25.1
maintainer Applied
#6 lore raw
In reply to Basavaraj Natikar
Quoted 11 lines · Basavaraj Natikar

Changes include updates to the existing FW reporting mechanism, MP2 FW status checks, adding power management routines and couple of other minor fixes to the existing driver.

Basavaraj Natikar (5):
amd_sfh:Fix period data field to enable sensor amd_sfh:Add command response to check command status amd_sfh:Move hid probe after sensor is enabled amd_sfh:Add support for PM suspend and resume amd_sfh:Add dyndbg prints for debugging

Quoted 4 lines
 drivers/hid/amd-sfh-hid/amd_sfh_client.c | 62 +++++++++++++++------
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c   | 69 ++++++++++++++++++++++++
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.h   | 23 ++++++++
 3 files changed, 139 insertions(+), 15 deletions(-)

I have queued the series for 5.15. Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs