Skip to content

Commit 24a31ea

Browse files
basuamdJiri Kosina
authored andcommitted
HID: amd_sfh: Add initial support for HPD sensor
Add Human Presence Detection (HPD) sensors support on AMD next generation HPD supported platforms. Signed-off-by: Basavaraj Natikar <[email protected]> Reviewed-by: Nehal Shah <[email protected]> Reviewed-by: Shyam Sundar S K <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 0aad9c9 commit 24a31ea

File tree

6 files changed

+174
-2
lines changed

6 files changed

+174
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef AMDSFH_HID_H
1010
#define AMDSFH_HID_H
1111

12-
#define MAX_HID_DEVICES 4
12+
#define MAX_HID_DEVICES 5
1313
#define BUS_AMD_AMDTP 0x20
1414
#define AMD_SFH_HID_VENDOR 0x1022
1515
#define AMD_SFH_HID_PRODUCT 0x0001

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define ACEL_EN BIT(0)
2525
#define GYRO_EN BIT(1)
2626
#define MAGNO_EN BIT(2)
27+
#define HPD_EN BIT(16)
2728
#define ALS_EN BIT(19)
2829

2930
static int sensor_mask_override = -1;
@@ -165,6 +166,9 @@ int amd_mp2_get_sensor_num(struct amd_mp2_dev *privdata, u8 *sensor_id)
165166
if (ALS_EN & activestatus)
166167
sensor_id[num_of_sensors++] = als_idx;
167168

169+
if (HPD_EN & activestatus)
170+
sensor_id[num_of_sensors++] = HPD_IDX;
171+
168172
return num_of_sensors;
169173
}
170174

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
#define V2_STATUS 0x2
3232

33+
#define HPD_IDX 16
34+
3335
/* SFH Command register */
3436
union sfh_cmd_base {
3537
u32 ul;
@@ -92,6 +94,18 @@ enum mem_use_type {
9294
USE_C2P_REG,
9395
};
9496

97+
struct hpd_status {
98+
union {
99+
struct {
100+
u32 human_presence_report : 4;
101+
u32 human_presence_actual : 4;
102+
u32 probablity : 8;
103+
u32 object_distance : 16;
104+
} shpd;
105+
u32 val;
106+
};
107+
};
108+
95109
void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info);
96110
void amd_stop_sensor(struct amd_mp2_dev *privdata, u16 sensor_idx);
97111
void amd_stop_all_sensors(struct amd_mp2_dev *privdata);

drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_desc.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ int get_report_descriptor(int sensor_idx, u8 *rep_desc)
5050
memcpy(rep_desc, als_report_descriptor,
5151
sizeof(als_report_descriptor));
5252
break;
53+
case HPD_IDX: /* HPD sensor */
54+
memset(rep_desc, 0, sizeof(hpd_report_descriptor));
55+
memcpy(rep_desc, hpd_report_descriptor,
56+
sizeof(hpd_report_descriptor));
57+
break;
5358
default:
5459
break;
5560
}
@@ -99,6 +104,17 @@ u32 get_descr_sz(int sensor_idx, int descriptor_name)
99104
return sizeof(struct als_feature_report);
100105
}
101106
break;
107+
case HPD_IDX:
108+
switch (descriptor_name) {
109+
case descr_size:
110+
return sizeof(hpd_report_descriptor);
111+
case input_size:
112+
return sizeof(struct hpd_input_report);
113+
case feature_size:
114+
return sizeof(struct hpd_feature_report);
115+
}
116+
break;
117+
102118
default:
103119
break;
104120
}
@@ -120,6 +136,7 @@ u8 get_feature_report(int sensor_idx, int report_id, u8 *feature_report)
120136
struct accel3_feature_report acc_feature;
121137
struct gyro_feature_report gyro_feature;
122138
struct magno_feature_report magno_feature;
139+
struct hpd_feature_report hpd_feature;
123140
struct als_feature_report als_feature;
124141
u8 report_size = 0;
125142

@@ -162,6 +179,12 @@ u8 get_feature_report(int sensor_idx, int report_id, u8 *feature_report)
162179
memcpy(feature_report, &als_feature, sizeof(als_feature));
163180
report_size = sizeof(als_feature);
164181
break;
182+
case HPD_IDX: /* human presence detection sensor */
183+
get_common_features(&hpd_feature.common_property, report_id);
184+
memcpy(feature_report, &hpd_feature, sizeof(hpd_feature));
185+
report_size = sizeof(hpd_feature);
186+
break;
187+
165188
default:
166189
break;
167190
}
@@ -181,10 +204,12 @@ u8 get_input_report(u8 current_index, int sensor_idx, int report_id, struct amd_
181204
u32 *sensor_virt_addr = in_data->sensor_virt_addr[current_index];
182205
u8 *input_report = in_data->input_report[current_index];
183206
u8 supported_input = privdata->mp2_acs & GENMASK(3, 0);
207+
struct magno_input_report magno_input;
184208
struct accel3_input_report acc_input;
185209
struct gyro_input_report gyro_input;
186-
struct magno_input_report magno_input;
210+
struct hpd_input_report hpd_input;
187211
struct als_input_report als_input;
212+
struct hpd_status hpdstatus;
188213
u8 report_size = 0;
189214

190215
if (!sensor_virt_addr || !input_report)
@@ -227,6 +252,13 @@ u8 get_input_report(u8 current_index, int sensor_idx, int report_id, struct amd_
227252
report_size = sizeof(als_input);
228253
memcpy(input_report, &als_input, sizeof(als_input));
229254
break;
255+
case HPD_IDX: /* hpd */
256+
get_common_inputs(&hpd_input.common_property, report_id);
257+
hpdstatus.val = readl(privdata->mmio + AMD_C2P_MSG(4));
258+
hpd_input.human_presence = hpdstatus.shpd.human_presence_actual;
259+
report_size = sizeof(hpd_input);
260+
memcpy(input_report, &hpd_input, sizeof(hpd_input));
261+
break;
230262
default:
231263
break;
232264
}

drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_desc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ struct als_input_report {
100100
int illuminance_value;
101101
} __packed;
102102

103+
struct hpd_feature_report {
104+
struct common_feature_property common_property;
105+
} __packed;
106+
107+
struct hpd_input_report {
108+
struct common_input_property common_property;
109+
/* values specific to human presence sensor */
110+
u8 human_presence;
111+
} __packed;
112+
103113
int get_report_descriptor(int sensor_idx, u8 rep_desc[]);
104114
u32 get_descr_sz(int sensor_idx, int descriptor_name);
105115
u8 get_feature_report(int sensor_idx, int report_id, u8 *feature_report);

drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_desc.h

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,4 +642,116 @@ const u8 als_report_descriptor[] = {
642642
0X81, 0x02, /* HID Input (Data_Arr_Abs) */
643643
0xC0 /* HID end collection */
644644
};
645+
646+
/* BIOMETRIC PRESENCE*/
647+
static const u8 hpd_report_descriptor[] = {
648+
0x05, 0x20, /* Usage page */
649+
0x09, 0x11, /* BIOMETRIC PRESENCE */
650+
0xA1, 0x00, /* HID Collection (Physical) */
651+
652+
//feature reports(xmit/receive)
653+
0x85, 5, /* HID Report ID */
654+
0x05, 0x20, /* HID usage page sensor */
655+
0x0A, 0x09, 0x03, /* Sensor property and sensor connection type */
656+
0x15, 0, /* HID logical MIN_8(0) */
657+
0x25, 2, /* HID logical MAX_8(2) */
658+
0x75, 8, /* HID report size(8) */
659+
0x95, 1, /* HID report count(1) */
660+
0xA1, 0x02, /* HID collection (logical) */
661+
0x0A, 0x30, 0x08, /* Sensor property connection type intergated sel*/
662+
0x0A, 0x31, 0x08, /* Sensor property connection type attached sel */
663+
0x0A, 0x32, 0x08, /* Sensor property connection type external sel */
664+
0xB1, 0x00, /* HID feature (Data_Arr_Abs) */
665+
0xC0, /* HID end collection */
666+
0x0A, 0x16, 0x03, /* HID usage sensor property reporting state */
667+
0x15, 0, /* HID logical Min_8(0) */
668+
0x25, 5, /* HID logical Max_8(5) */
669+
0x75, 8, /* HID report size(8) */
670+
0x95, 1, /* HID report count(1) */
671+
0xA1, 0x02, /* HID collection(logical) */
672+
0x0A, 0x40, 0x08, /* Sensor property report state no events sel */
673+
0x0A, 0x41, 0x08, /* Sensor property report state all events sel */
674+
0x0A, 0x42, 0x08, /* Sensor property report state threshold events sel */
675+
0x0A, 0x43, 0x08, /* Sensor property report state no events wake sel */
676+
0x0A, 0x44, 0x08, /* Sensor property report state all events wake sel */
677+
0x0A, 0x45, 0x08, /* Sensor property report state threshold events wake sel */
678+
0xB1, 0x00, /* HID feature (Data_Arr_Abs) */
679+
0xC0, /* HID end collection */
680+
0x0A, 0x19, 0x03, /* HID usage sensor property power state */
681+
0x15, 0, /* HID logical Min_8(0) */
682+
0x25, 5, /* HID logical Max_8(5) */
683+
0x75, 8, /* HID report size(8) */
684+
0x95, 1, /* HID report count(1) */
685+
0xA1, 0x02, /* HID collection(logical) */
686+
0x0A, 0x50, 0x08, /* Sensor property power state undefined sel */
687+
0x0A, 0x51, 0x08, /* Sensor property power state D0 full power sel */
688+
0x0A, 0x52, 0x08, /* Sensor property power state D1 low power sel */
689+
0x0A, 0x53, 0x08, /* Sensor property power state D2 standby with wake sel */
690+
0x0A, 0x54, 0x08, /* Sensor property power state D3 sleep with wake sel */
691+
0x0A, 0x55, 0x08, /* Sensor property power state D4 power off sel */
692+
0xB1, 0x00, /* HID feature (Data_Arr_Abs) */
693+
0xC0, /* HID end collection */
694+
0x0A, 0x01, 0x02, /* HID usage sensor state */
695+
0x15, 0, /* HID logical Min_8(0) */
696+
0x25, 6, /* HID logical Max_8(6) */
697+
0x75, 8, /* HID report size(8) */
698+
0x95, 1, /* HID report count(1) */
699+
0xA1, 0x02, /* HID collection(logical) */
700+
0x0A, 0x00, 0x08, /* HID usage sensor state unknown sel */
701+
0x0A, 0x01, 0x08, /* HID usage sensor state ready sel */
702+
0x0A, 0x02, 0x08, /* HID usage sensor state not available sel */
703+
0x0A, 0x03, 0x08, /* HID usage sensor state no data sel */
704+
0x0A, 0x04, 0x08, /* HID usage sensor state initializing sel */
705+
0x0A, 0x05, 0x08, /* HID usage sensor state access denied sel */
706+
0x0A, 0x06, 0x08, /* HID usage sensor state error sel */
707+
0xB1, 0x00, /* HID feature (Data_Arr_Abs) */
708+
0xC0, /* HID end collection */
709+
0x0A, 0x0E, 0x03, /* HID usage sensor property report interval */
710+
0x15, 0, /* HID logical Min_8(0) */
711+
0x27, 0xFF, 0xFF, 0xFF, 0xFF, /* HID logical Max_32 */
712+
713+
0x75, 32, /* HID report size(32) */
714+
0x95, 1, /* HID report count(1) */
715+
0x55, 0, /* HID unit exponent(0) */
716+
0xB1, 0x02, /* HID feature (Data_Var_Abs) */
717+
718+
//input report (transmit)
719+
0x05, 0x20, /* HID usage page sensors */
720+
0x0A, 0x01, 0x02, /* HID usage sensor state */
721+
0x15, 0, /* HID logical Min_8(0) */
722+
0x25, 6, /* HID logical Max_8(6) */
723+
0x75, 8, /* HID report size(8) */
724+
0x95, 1, /* HID report count (1) */
725+
0xA1, 0x02, /* HID end collection (logical) */
726+
0x0A, 0x00, 0x08, /* HID usage sensor state unknown sel */
727+
0x0A, 0x01, 0x08, /* HID usage sensor state ready sel */
728+
0x0A, 0x02, 0x08, /* HID usage sensor state not available sel */
729+
0x0A, 0x03, 0x08, /* HID usage sensor state no data sel */
730+
0x0A, 0x04, 0x08, /* HID usage sensor state initializing sel */
731+
0x0A, 0x05, 0x08, /* HID usage sensor state access denied sel */
732+
0x0A, 0x06, 0x08, /* HID usage sensor state error sel */
733+
0X81, 0x00, /* HID Input (Data_Arr_Abs) */
734+
0xC0, /* HID end collection */
735+
0x0A, 0x02, 0x02, /* HID usage sensor event */
736+
0x15, 0, /* HID logical Min_8(0) */
737+
0x25, 5, /* HID logical Max_8(5) */
738+
0x75, 8, /* HID report size(8) */
739+
0x95, 1, /* HID report count (1) */
740+
0xA1, 0x02, /* HID end collection (logical) */
741+
0x0A, 0x10, 0x08, /* HID usage sensor event unknown sel */
742+
0x0A, 0x11, 0x08, /* HID usage sensor event state changed sel */
743+
0x0A, 0x12, 0x08, /* HID usage sensor event property changed sel */
744+
0x0A, 0x13, 0x08, /* HID usage sensor event data updated sel */
745+
0x0A, 0x14, 0x08, /* HID usage sensor event poll response sel */
746+
0x0A, 0x15, 0x08, /* HID usage sensor event change sensitivity sel */
747+
0X81, 0x00, /* HID Input (Data_Arr_Abs) */
748+
0xC0, /* HID end collection */
749+
0x0A, 0xB1, 0x04, /* HID usage sensor data BIOMETRIC HUMAN PRESENCE */
750+
0x15, 0, /* HID logical Min_8(0) */
751+
0x25, 1, /* HID logical Max_8(1) */
752+
0x75, 8, /* HID report size(8) */
753+
0x95, 1, /* HID report count (1) */
754+
0X81, 0x02, /* HID Input (Data_Var_Abs) */
755+
0xC0 /* HID end collection */
756+
};
645757
#endif

0 commit comments

Comments
 (0)