Skip to content

Commit 94b8e51

Browse files
author
Enric Balletbo i Serra
committed
Merge remote-tracking branch 'origin/chrome-platform-5.7-fixes' into for-kernelci
Merging 5.7 fixes branch as of April 29, containing one fix to branch destined for chrome-platform-5.8. b31d1d2 platform/chrome: cros_ec_sensorhub: Allocate sensorhub resource before claiming sensors Signed-off-by: Enric Balletbo i Serra <[email protected]>
2 parents 89d9c24 + b31d1d2 commit 94b8e51

File tree

3 files changed

+93
-61
lines changed

3 files changed

+93
-61
lines changed

drivers/platform/chrome/cros_ec_sensorhub.c

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,15 @@ static int cros_ec_sensorhub_register(struct device *dev,
5252
int sensor_type[MOTIONSENSE_TYPE_MAX] = { 0 };
5353
struct cros_ec_command *msg = sensorhub->msg;
5454
struct cros_ec_dev *ec = sensorhub->ec;
55-
int ret, i, sensor_num;
55+
int ret, i;
5656
char *name;
5757

58-
sensor_num = cros_ec_get_sensor_count(ec);
59-
if (sensor_num < 0) {
60-
dev_err(dev,
61-
"Unable to retrieve sensor information (err:%d)\n",
62-
sensor_num);
63-
return sensor_num;
64-
}
65-
66-
sensorhub->sensor_num = sensor_num;
67-
if (sensor_num == 0) {
68-
dev_err(dev, "Zero sensors reported.\n");
69-
return -EINVAL;
70-
}
7158

7259
msg->version = 1;
7360
msg->insize = sizeof(struct ec_response_motion_sense);
7461
msg->outsize = sizeof(struct ec_params_motion_sense);
7562

76-
for (i = 0; i < sensor_num; i++) {
63+
for (i = 0; i < sensorhub->sensor_num; i++) {
7764
sensorhub->params->cmd = MOTIONSENSE_CMD_INFO;
7865
sensorhub->params->info.sensor_num = i;
7966

@@ -140,8 +127,7 @@ static int cros_ec_sensorhub_probe(struct platform_device *pdev)
140127
struct cros_ec_dev *ec = dev_get_drvdata(dev->parent);
141128
struct cros_ec_sensorhub *data;
142129
struct cros_ec_command *msg;
143-
int ret;
144-
int i;
130+
int ret, i, sensor_num;
145131

146132
msg = devm_kzalloc(dev, sizeof(struct cros_ec_command) +
147133
max((u16)sizeof(struct ec_params_motion_sense),
@@ -166,10 +152,52 @@ static int cros_ec_sensorhub_probe(struct platform_device *pdev)
166152
dev_set_drvdata(dev, data);
167153

168154
/* Check whether this EC is a sensor hub. */
169-
if (cros_ec_check_features(data->ec, EC_FEATURE_MOTION_SENSE)) {
155+
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE)) {
156+
sensor_num = cros_ec_get_sensor_count(ec);
157+
if (sensor_num < 0) {
158+
dev_err(dev,
159+
"Unable to retrieve sensor information (err:%d)\n",
160+
sensor_num);
161+
return sensor_num;
162+
}
163+
if (sensor_num == 0) {
164+
dev_err(dev, "Zero sensors reported.\n");
165+
return -EINVAL;
166+
}
167+
data->sensor_num = sensor_num;
168+
169+
/*
170+
* Prepare the ring handler before enumering the
171+
* sensors.
172+
*/
173+
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
174+
ret = cros_ec_sensorhub_ring_allocate(data);
175+
if (ret)
176+
return ret;
177+
}
178+
179+
/* Enumerate the sensors.*/
170180
ret = cros_ec_sensorhub_register(dev, data);
171181
if (ret)
172182
return ret;
183+
184+
/*
185+
* When the EC does not have a FIFO, the sensors will query
186+
* their data themselves via sysfs or a software trigger.
187+
*/
188+
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
189+
ret = cros_ec_sensorhub_ring_add(data);
190+
if (ret)
191+
return ret;
192+
/*
193+
* The msg and its data is not under the control of the
194+
* ring handler.
195+
*/
196+
return devm_add_action_or_reset(dev,
197+
cros_ec_sensorhub_ring_remove,
198+
data);
199+
}
200+
173201
} else {
174202
/*
175203
* If the device has sensors but does not claim to
@@ -184,22 +212,6 @@ static int cros_ec_sensorhub_probe(struct platform_device *pdev)
184212
}
185213
}
186214

187-
/*
188-
* If the EC does not have a FIFO, the sensors will query their data
189-
* themselves via sysfs or a software trigger.
190-
*/
191-
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
192-
ret = cros_ec_sensorhub_ring_add(data);
193-
if (ret)
194-
return ret;
195-
/*
196-
* The msg and its data is not under the control of the ring
197-
* handler.
198-
*/
199-
return devm_add_action_or_reset(dev,
200-
cros_ec_sensorhub_ring_remove,
201-
data);
202-
}
203215

204216
return 0;
205217
}

drivers/platform/chrome/cros_ec_sensorhub_ring.c

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -957,17 +957,15 @@ static int cros_ec_sensorhub_event(struct notifier_block *nb,
957957
}
958958

959959
/**
960-
* cros_ec_sensorhub_ring_add() - Add the FIFO functionality if the EC
961-
* supports it.
960+
* cros_ec_sensorhub_ring_allocate() - Prepare the FIFO functionality if the EC
961+
* supports it.
962962
*
963963
* @sensorhub : Sensor Hub object.
964964
*
965965
* Return: 0 on success.
966966
*/
967-
int cros_ec_sensorhub_ring_add(struct cros_ec_sensorhub *sensorhub)
967+
int cros_ec_sensorhub_ring_allocate(struct cros_ec_sensorhub *sensorhub)
968968
{
969-
struct cros_ec_dev *ec = sensorhub->ec;
970-
int ret;
971969
int fifo_info_length =
972970
sizeof(struct ec_response_motion_sense_fifo_info) +
973971
sizeof(u16) * sensorhub->sensor_num;
@@ -978,6 +976,49 @@ int cros_ec_sensorhub_ring_add(struct cros_ec_sensorhub *sensorhub)
978976
if (!sensorhub->fifo_info)
979977
return -ENOMEM;
980978

979+
/*
980+
* Allocate the callback area based on the number of sensors.
981+
* Add one for the sensor ring.
982+
*/
983+
sensorhub->push_data = devm_kcalloc(sensorhub->dev,
984+
sensorhub->sensor_num,
985+
sizeof(*sensorhub->push_data),
986+
GFP_KERNEL);
987+
if (!sensorhub->push_data)
988+
return -ENOMEM;
989+
990+
sensorhub->tight_timestamps = cros_ec_check_features(
991+
sensorhub->ec,
992+
EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS);
993+
994+
if (sensorhub->tight_timestamps) {
995+
sensorhub->batch_state = devm_kcalloc(sensorhub->dev,
996+
sensorhub->sensor_num,
997+
sizeof(*sensorhub->batch_state),
998+
GFP_KERNEL);
999+
if (!sensorhub->batch_state)
1000+
return -ENOMEM;
1001+
}
1002+
1003+
return 0;
1004+
}
1005+
1006+
/**
1007+
* cros_ec_sensorhub_ring_add() - Add the FIFO functionality if the EC
1008+
* supports it.
1009+
*
1010+
* @sensorhub : Sensor Hub object.
1011+
*
1012+
* Return: 0 on success.
1013+
*/
1014+
int cros_ec_sensorhub_ring_add(struct cros_ec_sensorhub *sensorhub)
1015+
{
1016+
struct cros_ec_dev *ec = sensorhub->ec;
1017+
int ret;
1018+
int fifo_info_length =
1019+
sizeof(struct ec_response_motion_sense_fifo_info) +
1020+
sizeof(u16) * sensorhub->sensor_num;
1021+
9811022
/* Retrieve FIFO information */
9821023
sensorhub->msg->version = 2;
9831024
sensorhub->params->cmd = MOTIONSENSE_CMD_FIFO_INFO;
@@ -998,31 +1039,9 @@ int cros_ec_sensorhub_ring_add(struct cros_ec_sensorhub *sensorhub)
9981039
if (!sensorhub->ring)
9991040
return -ENOMEM;
10001041

1001-
/*
1002-
* Allocate the callback area based on the number of sensors.
1003-
*/
1004-
sensorhub->push_data = devm_kcalloc(
1005-
sensorhub->dev, sensorhub->sensor_num,
1006-
sizeof(*sensorhub->push_data),
1007-
GFP_KERNEL);
1008-
if (!sensorhub->push_data)
1009-
return -ENOMEM;
1010-
10111042
sensorhub->fifo_timestamp[CROS_EC_SENSOR_LAST_TS] =
10121043
cros_ec_get_time_ns();
10131044

1014-
sensorhub->tight_timestamps = cros_ec_check_features(
1015-
ec, EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS);
1016-
1017-
if (sensorhub->tight_timestamps) {
1018-
sensorhub->batch_state = devm_kcalloc(sensorhub->dev,
1019-
sensorhub->sensor_num,
1020-
sizeof(*sensorhub->batch_state),
1021-
GFP_KERNEL);
1022-
if (!sensorhub->batch_state)
1023-
return -ENOMEM;
1024-
}
1025-
10261045
/* Register the notifier that will act as a top half interrupt. */
10271046
sensorhub->notifier.notifier_call = cros_ec_sensorhub_event;
10281047
ret = blocking_notifier_chain_register(&ec->ec_dev->event_notifier,

include/linux/platform_data/cros_ec_sensorhub.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ int cros_ec_sensorhub_register_push_data(struct cros_ec_sensorhub *sensorhub,
185185
void cros_ec_sensorhub_unregister_push_data(struct cros_ec_sensorhub *sensorhub,
186186
u8 sensor_num);
187187

188+
int cros_ec_sensorhub_ring_allocate(struct cros_ec_sensorhub *sensorhub);
188189
int cros_ec_sensorhub_ring_add(struct cros_ec_sensorhub *sensorhub);
189190
void cros_ec_sensorhub_ring_remove(void *arg);
190191
int cros_ec_sensorhub_ring_fifo_enable(struct cros_ec_sensorhub *sensorhub,

0 commit comments

Comments
 (0)