Skip to content

Commit b5b0774

Browse files
basuamdJiri Kosina
authored andcommitted
HID: amd_sfh: Add a new interface for exporting HPD data
AMDSFH has information about the User presence information via the Human Presence Detection (HPD) sensor which is part of the AMD sensor fusion hub. Add a new interface to export this information, where other drivers like PMF can use this information to enhance user experiences. Link: https://lore.kernel.org/all/ad064333-48a4-4cfa-9428-69e8a7c44667@redhat.com/ Co-developed-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> Signed-off-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.com>
1 parent 4e71d26 commit b5b0774

5 files changed

Lines changed: 103 additions & 0 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ struct amd_mp2_sensor_info {
3737
dma_addr_t dma_address;
3838
};
3939

40+
struct sfh_dev_status {
41+
bool is_hpd_present;
42+
};
43+
4044
struct amd_mp2_dev {
4145
struct pci_dev *pdev;
4246
struct amdtp_cl_data *cl_data;
@@ -47,6 +51,7 @@ struct amd_mp2_dev {
4751
struct amd_input_data in_data;
4852
/* mp2 active control status */
4953
u32 mp2_acs;
54+
struct sfh_dev_status dev_en;
5055
};
5156

5257
struct amd_mp2_ops {

drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ static int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata)
7373
int i, status;
7474

7575
for (i = 0; i < cl_data->num_hid_devices; i++) {
76+
switch (cl_data->sensor_idx[i]) {
77+
case HPD_IDX:
78+
privdata->dev_en.is_hpd_present = false;
79+
break;
80+
}
81+
7682
if (cl_data->sensor_sts[i] == SENSOR_ENABLED) {
7783
privdata->mp2_ops->stop(privdata, cl_data->sensor_idx[i]);
7884
status = amd_sfh_wait_for_response
@@ -178,6 +184,11 @@ static int amd_sfh1_1_hid_client_init(struct amd_mp2_dev *privdata)
178184
rc = amdtp_hid_probe(i, cl_data);
179185
if (rc)
180186
goto cleanup;
187+
switch (cl_data->sensor_idx[i]) {
188+
case HPD_IDX:
189+
privdata->dev_en.is_hpd_present = true;
190+
break;
191+
}
181192
}
182193
dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n",
183194
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
@@ -259,6 +270,7 @@ static void amd_mp2_pci_remove(void *privdata)
259270
{
260271
struct amd_mp2_dev *mp2 = privdata;
261272

273+
sfh_deinit_emp2();
262274
amd_sfh_hid_client_deinit(privdata);
263275
mp2->mp2_ops->stop_all(mp2);
264276
pci_intx(mp2->pdev, false);
@@ -311,12 +323,14 @@ int amd_sfh1_1_init(struct amd_mp2_dev *mp2)
311323

312324
rc = amd_sfh_irq_init(mp2);
313325
if (rc) {
326+
sfh_deinit_emp2();
314327
dev_err(dev, "amd_sfh_irq_init failed\n");
315328
return rc;
316329
}
317330

318331
rc = amd_sfh1_1_hid_client_init(mp2);
319332
if (rc) {
333+
sfh_deinit_emp2();
320334
dev_err(dev, "amd_sfh1_1_hid_client_init failed\n");
321335
return rc;
322336
}

drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
*
88
* Author: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
99
*/
10+
#include <linux/amd-pmf-io.h>
1011
#include <linux/io-64-nonatomic-lo-hi.h>
1112
#include <linux/iopoll.h>
1213

1314
#include "amd_sfh_interface.h"
1415

16+
static struct amd_mp2_dev *emp2;
17+
1518
static int amd_sfh_wait_response(struct amd_mp2_dev *mp2, u8 sid, u32 cmd_id)
1619
{
1720
struct sfh_cmd_response cmd_resp;
@@ -73,7 +76,41 @@ static struct amd_mp2_ops amd_sfh_ops = {
7376
.response = amd_sfh_wait_response,
7477
};
7578

79+
void sfh_deinit_emp2(void)
80+
{
81+
emp2 = NULL;
82+
}
83+
7684
void sfh_interface_init(struct amd_mp2_dev *mp2)
7785
{
7886
mp2->mp2_ops = &amd_sfh_ops;
87+
emp2 = mp2;
88+
}
89+
90+
static int amd_sfh_hpd_info(u8 *user_present)
91+
{
92+
struct hpd_status hpdstatus;
93+
94+
if (!user_present)
95+
return -EINVAL;
96+
97+
if (!emp2 || !emp2->dev_en.is_hpd_present)
98+
return -ENODEV;
99+
100+
hpdstatus.val = readl(emp2->mmio + AMD_C2P_MSG(4));
101+
*user_present = hpdstatus.shpd.presence;
102+
103+
return 0;
104+
}
105+
106+
int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op)
107+
{
108+
if (sfh_info) {
109+
switch (op) {
110+
case MT_HPD:
111+
return amd_sfh_hpd_info(&sfh_info->user_present);
112+
}
113+
}
114+
return -EINVAL;
79115
}
116+
EXPORT_SYMBOL_GPL(amd_get_sfh_info);

drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ struct hpd_status {
165165
};
166166

167167
void sfh_interface_init(struct amd_mp2_dev *mp2);
168+
void sfh_deinit_emp2(void);
168169
void amd_sfh1_1_set_desc_ops(struct amd_mp2_ops *mp2_ops);
169170
int amd_sfh_float_to_int(u32 flt32_val);
170171
#endif

include/linux/amd-pmf-io.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* AMD Platform Management Framework Interface
4+
*
5+
* Copyright (c) 2023, Advanced Micro Devices, Inc.
6+
* All Rights Reserved.
7+
*
8+
* Authors: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
9+
* Basavaraj Natikar <Basavaraj.Natikar@amd.com>
10+
*/
11+
12+
#ifndef AMD_PMF_IO_H
13+
#define AMD_PMF_IO_H
14+
15+
#include <linux/types.h>
16+
17+
/**
18+
* enum sfh_message_type - Query the SFH message type
19+
* @MT_HPD: Message ID to know the Human presence info from MP2 FW
20+
*/
21+
enum sfh_message_type {
22+
MT_HPD,
23+
};
24+
25+
/**
26+
* enum sfh_hpd_info - Query the Human presence information
27+
* @SFH_NOT_DETECTED: Check the HPD connection information from MP2 FW
28+
* @SFH_USER_PRESENT: Check if the user is present from HPD sensor
29+
* @SFH_USER_AWAY: Check if the user is away from HPD sensor
30+
*/
31+
enum sfh_hpd_info {
32+
SFH_NOT_DETECTED,
33+
SFH_USER_PRESENT,
34+
SFH_USER_AWAY,
35+
};
36+
37+
/**
38+
* struct amd_sfh_info - get HPD sensor info from MP2 FW
39+
* @user_present: Populates the user presence information
40+
*/
41+
struct amd_sfh_info {
42+
u8 user_present;
43+
};
44+
45+
int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op);
46+
#endif

0 commit comments

Comments
 (0)