Skip to content

Commit 9acadc7

Browse files
basuamdJiri Kosina
authored andcommitted
HID: amd_sfh: Add PM operations in amd_mp2_ops
Add PM operations as part of amd_mp2_ops structure to support all AMD SOCs and use wherever applicable. Signed-off-by: Basavaraj Natikar <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 786aa1b commit 9acadc7

File tree

3 files changed

+58
-39
lines changed

3 files changed

+58
-39
lines changed

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,57 @@ const char *get_sensor_name(int idx)
155155
}
156156
}
157157

158+
static void amd_sfh_resume(struct amd_mp2_dev *mp2)
159+
{
160+
struct amdtp_cl_data *cl_data = mp2->cl_data;
161+
struct amd_mp2_sensor_info info;
162+
int i, status;
163+
164+
for (i = 0; i < cl_data->num_hid_devices; i++) {
165+
if (cl_data->sensor_sts[i] == SENSOR_DISABLED) {
166+
info.period = AMD_SFH_IDLE_LOOP;
167+
info.sensor_idx = cl_data->sensor_idx[i];
168+
info.dma_address = cl_data->sensor_dma_addr[i];
169+
mp2->mp2_ops->start(mp2, info);
170+
status = amd_sfh_wait_for_response
171+
(mp2, cl_data->sensor_idx[i], SENSOR_ENABLED);
172+
if (status == SENSOR_ENABLED)
173+
cl_data->sensor_sts[i] = SENSOR_ENABLED;
174+
dev_dbg(&mp2->pdev->dev, "resume sid 0x%x (%s) status 0x%x\n",
175+
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
176+
cl_data->sensor_sts[i]);
177+
}
178+
}
179+
180+
schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
181+
if (mp2->mp2_ops->clear_intr)
182+
mp2->mp2_ops->clear_intr(mp2);
183+
}
184+
185+
static void amd_sfh_suspend(struct amd_mp2_dev *mp2)
186+
{
187+
struct amdtp_cl_data *cl_data = mp2->cl_data;
188+
int i, status;
189+
190+
for (i = 0; i < cl_data->num_hid_devices; i++) {
191+
if (cl_data->sensor_idx[i] != HPD_IDX &&
192+
cl_data->sensor_sts[i] == SENSOR_ENABLED) {
193+
mp2->mp2_ops->stop(mp2, cl_data->sensor_idx[i]);
194+
status = amd_sfh_wait_for_response
195+
(mp2, cl_data->sensor_idx[i], SENSOR_DISABLED);
196+
if (status != SENSOR_ENABLED)
197+
cl_data->sensor_sts[i] = SENSOR_DISABLED;
198+
dev_dbg(&mp2->pdev->dev, "suspend sid 0x%x (%s) status 0x%x\n",
199+
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
200+
cl_data->sensor_sts[i]);
201+
}
202+
}
203+
204+
cancel_delayed_work_sync(&cl_data->work_buffer);
205+
if (mp2->mp2_ops->clear_intr)
206+
mp2->mp2_ops->clear_intr(mp2);
207+
}
208+
158209
int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
159210
{
160211
struct amd_input_data *in_data = &privdata->in_data;
@@ -172,6 +223,9 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
172223
dev = &privdata->pdev->dev;
173224
amd_sfh_set_desc_ops(mp2_ops);
174225

226+
mp2_ops->suspend = amd_sfh_suspend;
227+
mp2_ops->resume = amd_sfh_resume;
228+
175229
cl_data->num_hid_devices = amd_mp2_get_sensor_num(privdata, &cl_data->sensor_idx[0]);
176230

177231
INIT_DELAYED_WORK(&cl_data->work, amd_sfh_work);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct amd_mp2_ops {
5454
void (*clear_intr)(struct amd_mp2_dev *privdata);
5555
int (*init_intr)(struct amd_mp2_dev *privdata);
5656
int (*discovery_status)(struct amd_mp2_dev *privdata);
57+
void (*suspend)(struct amd_mp2_dev *mp2);
58+
void (*resume)(struct amd_mp2_dev *mp2);
5759
int (*get_rep_desc)(int sensor_idx, u8 rep_desc[]);
5860
u32 (*get_desc_sz)(int sensor_idx, int descriptor_name);
5961
u8 (*get_feat_rep)(int sensor_idx, int report_id, u8 *feature_report);

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

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -339,54 +339,17 @@ static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i
339339
static int __maybe_unused amd_mp2_pci_resume(struct device *dev)
340340
{
341341
struct amd_mp2_dev *mp2 = dev_get_drvdata(dev);
342-
struct amdtp_cl_data *cl_data = mp2->cl_data;
343-
struct amd_mp2_sensor_info info;
344-
int i, status;
345-
346-
for (i = 0; i < cl_data->num_hid_devices; i++) {
347-
if (cl_data->sensor_sts[i] == SENSOR_DISABLED) {
348-
info.period = AMD_SFH_IDLE_LOOP;
349-
info.sensor_idx = cl_data->sensor_idx[i];
350-
info.dma_address = cl_data->sensor_dma_addr[i];
351-
mp2->mp2_ops->start(mp2, info);
352-
status = amd_sfh_wait_for_response
353-
(mp2, cl_data->sensor_idx[i], SENSOR_ENABLED);
354-
if (status == SENSOR_ENABLED)
355-
cl_data->sensor_sts[i] = SENSOR_ENABLED;
356-
dev_dbg(dev, "suspend sid 0x%x (%s) status 0x%x\n",
357-
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
358-
cl_data->sensor_sts[i]);
359-
}
360-
}
361342

362-
schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
363-
amd_sfh_clear_intr(mp2);
343+
mp2->mp2_ops->resume(mp2);
364344

365345
return 0;
366346
}
367347

368348
static int __maybe_unused amd_mp2_pci_suspend(struct device *dev)
369349
{
370350
struct amd_mp2_dev *mp2 = dev_get_drvdata(dev);
371-
struct amdtp_cl_data *cl_data = mp2->cl_data;
372-
int i, status;
373-
374-
for (i = 0; i < cl_data->num_hid_devices; i++) {
375-
if (cl_data->sensor_idx[i] != HPD_IDX &&
376-
cl_data->sensor_sts[i] == SENSOR_ENABLED) {
377-
mp2->mp2_ops->stop(mp2, cl_data->sensor_idx[i]);
378-
status = amd_sfh_wait_for_response
379-
(mp2, cl_data->sensor_idx[i], SENSOR_DISABLED);
380-
if (status != SENSOR_ENABLED)
381-
cl_data->sensor_sts[i] = SENSOR_DISABLED;
382-
dev_dbg(dev, "suspend sid 0x%x (%s) status 0x%x\n",
383-
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
384-
cl_data->sensor_sts[i]);
385-
}
386-
}
387351

388-
cancel_delayed_work_sync(&cl_data->work_buffer);
389-
amd_sfh_clear_intr(mp2);
352+
mp2->mp2_ops->suspend(mp2);
390353

391354
return 0;
392355
}

0 commit comments

Comments
 (0)