platform/chrome: cros_ec_sensorhub: Add the number of sensors in sensorhub
authorGwendal Grignou <gwendal@chromium.org>
Fri, 27 Mar 2020 22:34:32 +0000 (15:34 -0700)
committerEnric Balletbo i Serra <enric.balletbo@collabora.com>
Sat, 28 Mar 2020 21:04:32 +0000 (22:04 +0100)
To better manage resources, store the number of sensors reported by
the EC.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
drivers/platform/chrome/cros_ec_sensorhub.c
include/linux/platform_data/cros_ec_sensorhub.h

index 79fefd3bb0fa61082bd1a54deac1678f29501ff8..134ee5e46047255fd69e86e4c055e78c4214f180 100644 (file)
@@ -65,6 +65,7 @@ static int cros_ec_sensorhub_register(struct device *dev,
                return sensor_num;
        }
 
+       sensorhub->sensor_num = sensor_num;
        if (sensor_num == 0) {
                dev_err(dev, "Zero sensors reported.\n");
                return -EINVAL;
@@ -172,7 +173,8 @@ static int cros_ec_sensorhub_probe(struct platform_device *pdev)
                 * If the device has sensors but does not claim to
                 * be a sensor hub, we are in legacy mode.
                 */
-               for (i = 0; i < 2; i++) {
+               data->sensor_num = 2;
+               for (i = 0; i < data->sensor_num; i++) {
                        ret = cros_ec_sensorhub_allocate_sensor(dev,
                                                "cros-ec-accel-legacy", i);
                        if (ret)
index bef7ffc7fce10703b082098f9092b9c9016113b9..7e46a47fd642bc98f80f37c30b07afad3f58ed96 100644 (file)
@@ -22,9 +22,11 @@ struct cros_ec_sensor_platform {
  * struct cros_ec_sensorhub - Sensor Hub device data.
  *
  * @ec: Embedded Controller where the hub is located.
+ * @sensor_num: Number of MEMS sensors present in the EC.
  */
 struct cros_ec_sensorhub {
        struct cros_ec_dev *ec;
+       int sensor_num;
 };
 
 #endif   /* __LINUX_PLATFORM_DATA_CROS_EC_SENSORHUB_H */