Skip to content

Commit 173709f

Browse files
basuamdJiri Kosina
authored andcommitted
HID: amd_sfh: Add command response to check command status
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. Reviewed-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 3978f54 commit 173709f

3 files changed

Lines changed: 64 additions & 10 deletions

File tree

drivers/hid/amd-sfh-hid/amd_sfh_client.c

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,24 @@ static void amd_sfh_work_buffer(struct work_struct *work)
123123
int i;
124124

125125
for (i = 0; i < cli_data->num_hid_devices; i++) {
126-
report_size = get_input_report(i, cli_data->sensor_idx[i], cli_data->report_id[i],
127-
in_data);
128-
hid_input_report(cli_data->hid_sensor_hubs[i], HID_INPUT_REPORT,
129-
in_data->input_report[i], report_size, 0);
126+
if (cli_data->sensor_sts[i] == SENSOR_ENABLED) {
127+
report_size = get_input_report
128+
(i, cli_data->sensor_idx[i], cli_data->report_id[i], in_data);
129+
hid_input_report(cli_data->hid_sensor_hubs[i], HID_INPUT_REPORT,
130+
in_data->input_report[i], report_size, 0);
131+
}
130132
}
131133
schedule_delayed_work(&cli_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
132134
}
133135

136+
u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts)
137+
{
138+
if (mp2->mp2_ops->response)
139+
sensor_sts = mp2->mp2_ops->response(mp2, sid, sensor_sts);
140+
141+
return sensor_sts;
142+
}
143+
134144
int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
135145
{
136146
struct amd_input_data *in_data = &privdata->in_data;
@@ -139,8 +149,8 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
139149
struct device *dev;
140150
u32 feature_report_size;
141151
u32 input_report_size;
152+
int rc, i, status;
142153
u8 cl_idx;
143-
int rc, i;
144154

145155
dev = &privdata->pdev->dev;
146156

@@ -155,7 +165,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
155165
in_data->sensor_virt_addr[i] = dma_alloc_coherent(dev, sizeof(int) * 8,
156166
&cl_data->sensor_dma_addr[i],
157167
GFP_KERNEL);
158-
cl_data->sensor_sts[i] = 0;
168+
cl_data->sensor_sts[i] = SENSOR_DISABLED;
159169
cl_data->sensor_requested_cnt[i] = 0;
160170
cl_data->cur_hid_dev = i;
161171
cl_idx = cl_data->sensor_idx[i];
@@ -201,7 +211,10 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
201211
if (rc)
202212
return rc;
203213
privdata->mp2_ops->start(privdata, info);
204-
cl_data->sensor_sts[i] = 1;
214+
status = amd_sfh_wait_for_response
215+
(privdata, cl_data->sensor_idx[i], SENSOR_ENABLED);
216+
if (status == SENSOR_ENABLED)
217+
cl_data->sensor_sts[i] = SENSOR_ENABLED;
205218
}
206219
schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
207220
return 0;
@@ -224,10 +237,17 @@ int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata)
224237
{
225238
struct amdtp_cl_data *cl_data = privdata->cl_data;
226239
struct amd_input_data *in_data = cl_data->in_data;
227-
int i;
240+
int i, status;
228241

229-
for (i = 0; i < cl_data->num_hid_devices; i++)
230-
privdata->mp2_ops->stop(privdata, i);
242+
for (i = 0; i < cl_data->num_hid_devices; i++) {
243+
if (cl_data->sensor_sts[i] == SENSOR_ENABLED) {
244+
privdata->mp2_ops->stop(privdata, cl_data->sensor_idx[i]);
245+
status = amd_sfh_wait_for_response
246+
(privdata, cl_data->sensor_idx[i], SENSOR_DISABLED);
247+
if (status != SENSOR_ENABLED)
248+
cl_data->sensor_sts[i] = SENSOR_DISABLED;
249+
}
250+
}
231251

232252
cancel_delayed_work_sync(&cl_data->work);
233253
cancel_delayed_work_sync(&cl_data->work_buffer);

drivers/hid/amd-sfh-hid/amd_sfh_pcie.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/dmi.h>
1414
#include <linux/interrupt.h>
1515
#include <linux/io-64-nonatomic-lo-hi.h>
16+
#include <linux/iopoll.h>
1617
#include <linux/module.h>
1718
#include <linux/slab.h>
1819

@@ -31,6 +32,20 @@ static int sensor_mask_override = -1;
3132
module_param_named(sensor_mask, sensor_mask_override, int, 0444);
3233
MODULE_PARM_DESC(sensor_mask, "override the detected sensors mask");
3334

35+
static int amd_sfh_wait_response_v2(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts)
36+
{
37+
union cmd_response cmd_resp;
38+
39+
/* Get response with status within a max of 800 ms timeout */
40+
if (!readl_poll_timeout(mp2->mmio + AMD_P2C_MSG(0), cmd_resp.resp,
41+
(cmd_resp.response_v2.response == sensor_sts &&
42+
cmd_resp.response_v2.status == 0 && (sid == 0xff ||
43+
cmd_resp.response_v2.sensor_id == sid)), 500, 800000))
44+
return cmd_resp.response_v2.response;
45+
46+
return SENSOR_DISABLED;
47+
}
48+
3449
static void amd_start_sensor_v2(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info)
3550
{
3651
union sfh_cmd_base cmd_base;
@@ -183,6 +198,7 @@ static const struct amd_mp2_ops amd_sfh_ops_v2 = {
183198
.start = amd_start_sensor_v2,
184199
.stop = amd_stop_sensor_v2,
185200
.stop_all = amd_stop_all_sensor_v2,
201+
.response = amd_sfh_wait_response_v2,
186202
};
187203

188204
static const struct amd_mp2_ops amd_sfh_ops = {

drivers/hid/amd-sfh-hid/amd_sfh_pcie.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@
2424
#define AMD_C2P_MSG2 0x10508
2525

2626
#define AMD_C2P_MSG(regno) (0x10500 + ((regno) * 4))
27+
#define AMD_P2C_MSG(regno) (0x10680 + ((regno) * 4))
2728

2829
/* MP2 P2C Message Registers */
2930
#define AMD_P2C_MSG3 0x1068C /* Supported Sensors info */
3031

3132
#define V2_STATUS 0x2
3233

34+
#define SENSOR_ENABLED 4
35+
#define SENSOR_DISABLED 5
36+
3337
#define HPD_IDX 16
3438

3539
/* SFH Command register */
@@ -51,6 +55,19 @@ union sfh_cmd_base {
5155
} cmd_v2;
5256
};
5357

58+
union cmd_response {
59+
u32 resp;
60+
struct {
61+
u32 status : 2;
62+
u32 out_in_c2p : 1;
63+
u32 rsvd1 : 1;
64+
u32 response : 4;
65+
u32 sub_cmd : 8;
66+
u32 sensor_id : 6;
67+
u32 rsvd2 : 10;
68+
} response_v2;
69+
};
70+
5471
union sfh_cmd_param {
5572
u32 ul;
5673
struct {
@@ -117,5 +134,6 @@ struct amd_mp2_ops {
117134
void (*start)(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info);
118135
void (*stop)(struct amd_mp2_dev *privdata, u16 sensor_idx);
119136
void (*stop_all)(struct amd_mp2_dev *privdata);
137+
int (*response)(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
120138
};
121139
#endif

0 commit comments

Comments
 (0)