Skip to content

Commit 584f35a

Browse files
basuamdJiri Kosina
authored andcommitted
HID: amd_sfh: Add a new interface for exporting ALS data
AMDSFH has information about the Ambient light via the Ambient Light Sensor (ALS) 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/[email protected]/ Reviewed-by: Mario Limonciello <[email protected]> Co-developed-by: Shyam Sundar S K <[email protected]> Signed-off-by: Shyam Sundar S K <[email protected]> Signed-off-by: Basavaraj Natikar <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent b5b0774 commit 584f35a

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct amd_mp2_sensor_info {
3939

4040
struct sfh_dev_status {
4141
bool is_hpd_present;
42+
bool is_als_present;
4243
};
4344

4445
struct amd_mp2_dev {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ static int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata)
7777
case HPD_IDX:
7878
privdata->dev_en.is_hpd_present = false;
7979
break;
80+
case ALS_IDX:
81+
privdata->dev_en.is_als_present = false;
82+
break;
8083
}
8184

8285
if (cl_data->sensor_sts[i] == SENSOR_ENABLED) {
@@ -188,6 +191,9 @@ static int amd_sfh1_1_hid_client_init(struct amd_mp2_dev *privdata)
188191
case HPD_IDX:
189192
privdata->dev_en.is_hpd_present = true;
190193
break;
194+
case ALS_IDX:
195+
privdata->dev_en.is_als_present = true;
196+
break;
191197
}
192198
}
193199
dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n",

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,34 @@ static int amd_sfh_hpd_info(u8 *user_present)
103103
return 0;
104104
}
105105

106+
static int amd_sfh_als_info(u32 *ambient_light)
107+
{
108+
struct sfh_als_data als_data;
109+
void __iomem *sensoraddr;
110+
111+
if (!ambient_light)
112+
return -EINVAL;
113+
114+
if (!emp2 || !emp2->dev_en.is_als_present)
115+
return -ENODEV;
116+
117+
sensoraddr = emp2->vsbase +
118+
(ALS_IDX * SENSOR_DATA_MEM_SIZE_DEFAULT) +
119+
OFFSET_SENSOR_DATA_DEFAULT;
120+
memcpy_fromio(&als_data, sensoraddr, sizeof(struct sfh_als_data));
121+
*ambient_light = amd_sfh_float_to_int(als_data.lux);
122+
123+
return 0;
124+
}
125+
106126
int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op)
107127
{
108128
if (sfh_info) {
109129
switch (op) {
110130
case MT_HPD:
111131
return amd_sfh_hpd_info(&sfh_info->user_present);
132+
case MT_ALS:
133+
return amd_sfh_als_info(&sfh_info->ambient_light);
112134
}
113135
}
114136
return -EINVAL;

include/linux/amd-pmf-io.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
/**
1818
* enum sfh_message_type - Query the SFH message type
1919
* @MT_HPD: Message ID to know the Human presence info from MP2 FW
20+
* @MT_ALS: Message ID to know the Ambient light info from MP2 FW
2021
*/
2122
enum sfh_message_type {
2223
MT_HPD,
24+
MT_ALS,
2325
};
2426

2527
/**
@@ -36,9 +38,11 @@ enum sfh_hpd_info {
3638

3739
/**
3840
* struct amd_sfh_info - get HPD sensor info from MP2 FW
41+
* @ambient_light: Populates the ambient light information
3942
* @user_present: Populates the user presence information
4043
*/
4144
struct amd_sfh_info {
45+
u32 ambient_light;
4246
u8 user_present;
4347
};
4448

0 commit comments

Comments
 (0)