Skip to content

Commit b5d7f43

Browse files
basuamdJiri Kosina
authored andcommitted
HID: amd_sfh: Add support for sensor discovery
Sensor discovery status fails in case of broken sensors or platform not supported. Hence disable driver on failure of sensor discovery. Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 62f8857 commit b5d7f43

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,17 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
227227
dev_dbg(dev, "sid 0x%x status 0x%x\n",
228228
cl_data->sensor_idx[i], cl_data->sensor_sts[i]);
229229
}
230+
if (privdata->mp2_ops->discovery_status &&
231+
privdata->mp2_ops->discovery_status(privdata) == 0) {
232+
amd_sfh_hid_client_deinit(privdata);
233+
for (i = 0; i < cl_data->num_hid_devices; i++) {
234+
devm_kfree(dev, cl_data->feature_report[i]);
235+
devm_kfree(dev, in_data->input_report[i]);
236+
devm_kfree(dev, cl_data->report_descr[i]);
237+
}
238+
dev_warn(dev, "Failed to discover, sensors not enabled\n");
239+
return -EOPNOTSUPP;
240+
}
230241
schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
231242
return 0;
232243

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ static int amd_sfh_irq_init_v2(struct amd_mp2_dev *privdata)
130130
return 0;
131131
}
132132

133+
static int amd_sfh_dis_sts_v2(struct amd_mp2_dev *privdata)
134+
{
135+
return (readl(privdata->mmio + AMD_P2C_MSG(1)) &
136+
SENSOR_DISCOVERY_STATUS_MASK) >> SENSOR_DISCOVERY_STATUS_SHIFT;
137+
}
138+
133139
void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info)
134140
{
135141
union sfh_cmd_param cmd_param;
@@ -245,6 +251,7 @@ static const struct amd_mp2_ops amd_sfh_ops_v2 = {
245251
.response = amd_sfh_wait_response_v2,
246252
.clear_intr = amd_sfh_clear_intr_v2,
247253
.init_intr = amd_sfh_irq_init_v2,
254+
.discovery_status = amd_sfh_dis_sts_v2,
248255
};
249256

250257
static const struct amd_mp2_ops amd_sfh_ops = {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939

4040
#define AMD_SFH_IDLE_LOOP 200
4141

42+
#define SENSOR_DISCOVERY_STATUS_MASK GENMASK(5, 3)
43+
#define SENSOR_DISCOVERY_STATUS_SHIFT 3
44+
4245
/* SFH Command register */
4346
union sfh_cmd_base {
4447
u32 ul;
@@ -143,5 +146,6 @@ struct amd_mp2_ops {
143146
int (*response)(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
144147
void (*clear_intr)(struct amd_mp2_dev *privdata);
145148
int (*init_intr)(struct amd_mp2_dev *privdata);
149+
int (*discovery_status)(struct amd_mp2_dev *privdata);
146150
};
147151
#endif

0 commit comments

Comments
 (0)