Skip to content

Commit

Permalink
HID: amd_sfh: Add a new interface for exporting ALS data
Browse files Browse the repository at this point in the history
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/ad064333-48a4-4cfa-9428-69e8a7c44667@redhat.com/
Reviewed-by: Mario Limonciello <mario.limonciello@amd.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>
  • Loading branch information
Basavaraj Natikar authored and Jiri Kosina committed Jan 4, 2024
1 parent b5b0774 commit 584f35a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/hid/amd-sfh-hid/amd_sfh_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct amd_mp2_sensor_info {

struct sfh_dev_status {
bool is_hpd_present;
bool is_als_present;
};

struct amd_mp2_dev {
Expand Down
6 changes: 6 additions & 0 deletions drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ static int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata)
case HPD_IDX:
privdata->dev_en.is_hpd_present = false;
break;
case ALS_IDX:
privdata->dev_en.is_als_present = false;
break;
}

if (cl_data->sensor_sts[i] == SENSOR_ENABLED) {
Expand Down Expand Up @@ -188,6 +191,9 @@ static int amd_sfh1_1_hid_client_init(struct amd_mp2_dev *privdata)
case HPD_IDX:
privdata->dev_en.is_hpd_present = true;
break;
case ALS_IDX:
privdata->dev_en.is_als_present = true;
break;
}
}
dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n",
Expand Down
22 changes: 22 additions & 0 deletions drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,34 @@ static int amd_sfh_hpd_info(u8 *user_present)
return 0;
}

static int amd_sfh_als_info(u32 *ambient_light)
{
struct sfh_als_data als_data;
void __iomem *sensoraddr;

if (!ambient_light)
return -EINVAL;

if (!emp2 || !emp2->dev_en.is_als_present)
return -ENODEV;

sensoraddr = emp2->vsbase +
(ALS_IDX * SENSOR_DATA_MEM_SIZE_DEFAULT) +
OFFSET_SENSOR_DATA_DEFAULT;
memcpy_fromio(&als_data, sensoraddr, sizeof(struct sfh_als_data));
*ambient_light = amd_sfh_float_to_int(als_data.lux);

return 0;
}

int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op)
{
if (sfh_info) {
switch (op) {
case MT_HPD:
return amd_sfh_hpd_info(&sfh_info->user_present);
case MT_ALS:
return amd_sfh_als_info(&sfh_info->ambient_light);
}
}
return -EINVAL;
Expand Down
4 changes: 4 additions & 0 deletions include/linux/amd-pmf-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
/**
* enum sfh_message_type - Query the SFH message type
* @MT_HPD: Message ID to know the Human presence info from MP2 FW
* @MT_ALS: Message ID to know the Ambient light info from MP2 FW
*/
enum sfh_message_type {
MT_HPD,
MT_ALS,
};

/**
Expand All @@ -36,9 +38,11 @@ enum sfh_hpd_info {

/**
* struct amd_sfh_info - get HPD sensor info from MP2 FW
* @ambient_light: Populates the ambient light information
* @user_present: Populates the user presence information
*/
struct amd_sfh_info {
u32 ambient_light;
u8 user_present;
};

Expand Down

0 comments on commit 584f35a

Please sign in to comment.