Skip to content

Commit 0873d1a

Browse files
basuamdJiri Kosina
authored andcommitted
HID: amd_sfh: Add support for PM suspend and resume
Add support for power management routines. 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 ac15e91 commit 0873d1a

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "amd_sfh_pcie.h"
1818
#include "amd_sfh_hid.h"
1919

20-
#define AMD_SFH_IDLE_LOOP 200
2120

2221
struct request_list {
2322
struct hid_device *hid;

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,54 @@ static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i
264264
return amd_sfh_hid_client_init(privdata);
265265
}
266266

267+
static int __maybe_unused amd_mp2_pci_resume(struct device *dev)
268+
{
269+
struct pci_dev *pdev = to_pci_dev(dev);
270+
struct amd_mp2_dev *mp2 = pci_get_drvdata(pdev);
271+
struct amdtp_cl_data *cl_data = mp2->cl_data;
272+
struct amd_mp2_sensor_info info;
273+
int i, status;
274+
275+
for (i = 0; i < cl_data->num_hid_devices; i++) {
276+
if (cl_data->sensor_sts[i] == SENSOR_DISABLED) {
277+
info.period = AMD_SFH_IDLE_LOOP;
278+
info.sensor_idx = cl_data->sensor_idx[i];
279+
info.dma_address = cl_data->sensor_dma_addr[i];
280+
mp2->mp2_ops->start(mp2, info);
281+
status = amd_sfh_wait_for_response
282+
(mp2, cl_data->sensor_idx[i], SENSOR_ENABLED);
283+
if (status == SENSOR_ENABLED)
284+
cl_data->sensor_sts[i] = SENSOR_ENABLED;
285+
}
286+
}
287+
288+
return 0;
289+
}
290+
291+
static int __maybe_unused amd_mp2_pci_suspend(struct device *dev)
292+
{
293+
struct pci_dev *pdev = to_pci_dev(dev);
294+
struct amd_mp2_dev *mp2 = pci_get_drvdata(pdev);
295+
struct amdtp_cl_data *cl_data = mp2->cl_data;
296+
int i, status;
297+
298+
for (i = 0; i < cl_data->num_hid_devices; i++) {
299+
if (cl_data->sensor_idx[i] != HPD_IDX &&
300+
cl_data->sensor_sts[i] == SENSOR_ENABLED) {
301+
mp2->mp2_ops->stop(mp2, cl_data->sensor_idx[i]);
302+
status = amd_sfh_wait_for_response
303+
(mp2, cl_data->sensor_idx[i], SENSOR_DISABLED);
304+
if (status != SENSOR_ENABLED)
305+
cl_data->sensor_sts[i] = SENSOR_DISABLED;
306+
}
307+
}
308+
309+
return 0;
310+
}
311+
312+
static SIMPLE_DEV_PM_OPS(amd_mp2_pm_ops, amd_mp2_pci_suspend,
313+
amd_mp2_pci_resume);
314+
267315
static const struct pci_device_id amd_mp2_pci_tbl[] = {
268316
{ PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_MP2) },
269317
{ }
@@ -274,6 +322,7 @@ static struct pci_driver amd_mp2_pci_driver = {
274322
.name = DRIVER_NAME,
275323
.id_table = amd_mp2_pci_tbl,
276324
.probe = amd_mp2_pci_probe,
325+
.driver.pm = &amd_mp2_pm_ops,
277326
};
278327
module_pci_driver(amd_mp2_pci_driver);
279328

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#define HPD_IDX 16
3838

39+
#define AMD_SFH_IDLE_LOOP 200
40+
3941
/* SFH Command register */
4042
union sfh_cmd_base {
4143
u32 ul;
@@ -129,6 +131,9 @@ void amd_stop_all_sensors(struct amd_mp2_dev *privdata);
129131
int amd_mp2_get_sensor_num(struct amd_mp2_dev *privdata, u8 *sensor_id);
130132
int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata);
131133
int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata);
134+
u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
135+
void amd_mp2_suspend(struct amd_mp2_dev *mp2);
136+
void amd_mp2_resume(struct amd_mp2_dev *mp2);
132137

133138
struct amd_mp2_ops {
134139
void (*start)(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info);

0 commit comments

Comments
 (0)