HID: amd_sfh: Add a new interface for exporting ALS data
authorBasavaraj Natikar <Basavaraj.Natikar@amd.com>
Wed, 20 Dec 2023 07:00:42 +0000 (12:30 +0530)
committerJiri Kosina <jkosina@suse.com>
Thu, 4 Jan 2024 14:19:17 +0000 (15:19 +0100)
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>
drivers/hid/amd-sfh-hid/amd_sfh_common.h
drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c
drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c
include/linux/amd-pmf-io.h

index cd57037bf217415ad4912161527271a75177cef7..a1950bc6e6cefee4ca1dcdc5cc2ceaf4216c9065 100644 (file)
@@ -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 {
index 0351b0fd394a98593d9410a297315fb882fc53e1..9dbe6f4cb29426a109c8c6c2565ae89e808cd3aa 100644 (file)
@@ -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) {
@@ -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",
index 197b828fc6a0bab81928ae3edd0c477c33cdb608..ae36312bc23650e0b77171e46d1b972e463c1899 100644 (file)
@@ -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;
index 5b6d29d369221a64b66f65a23773199bb3e38bd1..b4f8182052169c0b74e5c12d69470e2af9605b99 100644 (file)
 /**
  * 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,
 };
 
 /**
@@ -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;
 };