Lines Matching refs:sensorhub
39 cros_sensorhub_send_sample(struct cros_ec_sensorhub *sensorhub, in cros_sensorhub_send_sample() argument
46 if (id >= sensorhub->sensor_num) in cros_sensorhub_send_sample()
49 cb = sensorhub->push_data[id].push_data_cb; in cros_sensorhub_send_sample()
53 indio_dev = sensorhub->push_data[id].indio_dev; in cros_sensorhub_send_sample()
75 int cros_ec_sensorhub_register_push_data(struct cros_ec_sensorhub *sensorhub, in cros_ec_sensorhub_register_push_data() argument
80 if (sensor_num >= sensorhub->sensor_num) in cros_ec_sensorhub_register_push_data()
82 if (sensorhub->push_data[sensor_num].indio_dev) in cros_ec_sensorhub_register_push_data()
85 sensorhub->push_data[sensor_num].indio_dev = indio_dev; in cros_ec_sensorhub_register_push_data()
86 sensorhub->push_data[sensor_num].push_data_cb = cb; in cros_ec_sensorhub_register_push_data()
92 void cros_ec_sensorhub_unregister_push_data(struct cros_ec_sensorhub *sensorhub, in cros_ec_sensorhub_unregister_push_data() argument
95 sensorhub->push_data[sensor_num].indio_dev = NULL; in cros_ec_sensorhub_unregister_push_data()
96 sensorhub->push_data[sensor_num].push_data_cb = NULL; in cros_ec_sensorhub_unregister_push_data()
110 int cros_ec_sensorhub_ring_fifo_enable(struct cros_ec_sensorhub *sensorhub, in cros_ec_sensorhub_ring_fifo_enable() argument
115 mutex_lock(&sensorhub->cmd_lock); in cros_ec_sensorhub_ring_fifo_enable()
116 if (sensorhub->tight_timestamps) in cros_ec_sensorhub_ring_fifo_enable()
117 for (i = 0; i < sensorhub->sensor_num; i++) in cros_ec_sensorhub_ring_fifo_enable()
118 sensorhub->batch_state[i].last_len = 0; in cros_ec_sensorhub_ring_fifo_enable()
120 sensorhub->params->cmd = MOTIONSENSE_CMD_FIFO_INT_ENABLE; in cros_ec_sensorhub_ring_fifo_enable()
121 sensorhub->params->fifo_int_enable.enable = on; in cros_ec_sensorhub_ring_fifo_enable()
123 sensorhub->msg->outsize = sizeof(struct ec_params_motion_sense); in cros_ec_sensorhub_ring_fifo_enable()
124 sensorhub->msg->insize = sizeof(struct ec_response_motion_sense); in cros_ec_sensorhub_ring_fifo_enable()
126 ret = cros_ec_cmd_xfer_status(sensorhub->ec->ec_dev, sensorhub->msg); in cros_ec_sensorhub_ring_fifo_enable()
127 mutex_unlock(&sensorhub->cmd_lock); in cros_ec_sensorhub_ring_fifo_enable()
385 *sensorhub, in cros_ec_sensor_ring_check_for_past_timestamp()
392 if (sensorhub->batch_state[sensor_id].newest_sensor_event > in cros_ec_sensor_ring_check_for_past_timestamp()
396 sensorhub->batch_state[sensor_id].last_ts; in cros_ec_sensor_ring_check_for_past_timestamp()
398 sensorhub->batch_state[sensor_id].newest_sensor_event = in cros_ec_sensor_ring_check_for_past_timestamp()
417 cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub, in cros_ec_sensor_ring_process_event() argument
438 &sensorhub->overflow_a); in cros_ec_sensor_ring_process_event()
440 &sensorhub->overflow_b); in cros_ec_sensor_ring_process_event()
442 if (sensorhub->tight_timestamps) { in cros_ec_sensor_ring_process_event()
444 &sensorhub->filter, b, c); in cros_ec_sensor_ring_process_event()
446 &sensorhub->filter, a); in cros_ec_sensor_ring_process_event()
470 if (sensorhub->tight_timestamps) { in cros_ec_sensor_ring_process_event()
471 sensorhub->batch_state[in->sensor_num].last_len = 0; in cros_ec_sensor_ring_process_event()
472 sensorhub->batch_state[in->sensor_num].penul_len = 0; in cros_ec_sensor_ring_process_event()
485 if (sensorhub->tight_timestamps) in cros_ec_sensor_ring_process_event()
486 sensorhub->batch_state[out->sensor_id].last_len = 0; in cros_ec_sensor_ring_process_event()
511 sensorhub->future_timestamp_total_ns += in cros_ec_sensor_ring_process_event()
513 if (++sensorhub->future_timestamp_count == in cros_ec_sensor_ring_process_event()
515 s64 avg = div_s64(sensorhub->future_timestamp_total_ns, in cros_ec_sensor_ring_process_event()
516 sensorhub->future_timestamp_count); in cros_ec_sensor_ring_process_event()
517 dev_warn_ratelimited(sensorhub->dev, in cros_ec_sensor_ring_process_event()
520 sensorhub->future_timestamp_count = 0; in cros_ec_sensor_ring_process_event()
521 sensorhub->future_timestamp_total_ns = 0; in cros_ec_sensor_ring_process_event()
532 if (sensorhub->tight_timestamps) in cros_ec_sensor_ring_process_event()
533 cros_ec_sensor_ring_check_for_past_timestamp(sensorhub, out); in cros_ec_sensor_ring_process_event()
569 cros_ec_sensor_ring_spread_add(struct cros_ec_sensorhub *sensorhub, in cros_ec_sensor_ring_spread_add() argument
576 for_each_set_bit(id, &sensor_mask, sensorhub->sensor_num) { in cros_ec_sensor_ring_spread_add()
577 for (batch_start = sensorhub->ring; batch_start < last_out; in cros_ec_sensor_ring_spread_add()
605 cros_sensorhub_send_sample(sensorhub, in cros_ec_sensor_ring_spread_add()
612 sensorhub->batch_state[id].last_ts) { in cros_ec_sensor_ring_spread_add()
614 sensorhub->batch_state[id].last_ts; in cros_ec_sensor_ring_spread_add()
615 batch_len = sensorhub->batch_state[id].last_len; in cros_ec_sensor_ring_spread_add()
619 sensorhub->batch_state[id].last_ts = in cros_ec_sensor_ring_spread_add()
620 sensorhub->batch_state[id].penul_ts; in cros_ec_sensor_ring_spread_add()
621 sensorhub->batch_state[id].last_len = in cros_ec_sensor_ring_spread_add()
622 sensorhub->batch_state[id].penul_len; in cros_ec_sensor_ring_spread_add()
631 cros_sensorhub_send_sample(sensorhub, in cros_ec_sensor_ring_spread_add()
658 if (sensorhub->batch_state[id].last_len == 0) { in cros_ec_sensor_ring_spread_add()
659 dev_warn(sensorhub->dev, "Sensor %d: lost %d samples when spreading\n", in cros_ec_sensor_ring_spread_add()
671 sensorhub->batch_state[id].last_ts, in cros_ec_sensor_ring_spread_add()
672 sensorhub->batch_state[id].last_len); in cros_ec_sensor_ring_spread_add()
673 dev_dbg(sensorhub->dev, in cros_ec_sensor_ring_spread_add()
676 sensorhub->batch_state[id].last_ts, in cros_ec_sensor_ring_spread_add()
677 sensorhub->batch_state[id].last_len, in cros_ec_sensor_ring_spread_add()
697 cros_sensorhub_send_sample(sensorhub, s); in cros_ec_sensor_ring_spread_add()
701 sensorhub->batch_state[id].penul_ts = in cros_ec_sensor_ring_spread_add()
702 sensorhub->batch_state[id].last_ts; in cros_ec_sensor_ring_spread_add()
703 sensorhub->batch_state[id].penul_len = in cros_ec_sensor_ring_spread_add()
704 sensorhub->batch_state[id].last_len; in cros_ec_sensor_ring_spread_add()
706 sensorhub->batch_state[id].last_ts = in cros_ec_sensor_ring_spread_add()
708 sensorhub->batch_state[id].last_len = batch_len; in cros_ec_sensor_ring_spread_add()
737 cros_ec_sensor_ring_spread_add_legacy(struct cros_ec_sensorhub *sensorhub, in cros_ec_sensor_ring_spread_add_legacy() argument
746 for_each_set_bit(i, &sensor_mask, sensorhub->sensor_num) { in cros_ec_sensor_ring_spread_add_legacy()
751 for (out = sensorhub->ring; out < last_out; out++) { in cros_ec_sensor_ring_spread_add_legacy()
773 for (out = sensorhub->ring; out < last_out; out++) { in cros_ec_sensor_ring_spread_add_legacy()
782 for (out = sensorhub->ring; out < last_out; out++) in cros_ec_sensor_ring_spread_add_legacy()
783 cros_sensorhub_send_sample(sensorhub, out); in cros_ec_sensor_ring_spread_add_legacy()
793 static void cros_ec_sensorhub_ring_handler(struct cros_ec_sensorhub *sensorhub) in cros_ec_sensorhub_ring_handler() argument
796 sensorhub->fifo_info; in cros_ec_sensorhub_ring_handler()
797 struct cros_ec_dev *ec = sensorhub->ec; in cros_ec_sensorhub_ring_handler()
804 mutex_lock(&sensorhub->cmd_lock); in cros_ec_sensorhub_ring_handler()
810 sizeof(u16) * sensorhub->sensor_num; in cros_ec_sensorhub_ring_handler()
813 sensorhub->params->cmd = MOTIONSENSE_CMD_FIFO_INFO; in cros_ec_sensorhub_ring_handler()
814 sensorhub->msg->outsize = 1; in cros_ec_sensorhub_ring_handler()
815 sensorhub->msg->insize = fifo_info_length; in cros_ec_sensorhub_ring_handler()
817 if (cros_ec_cmd_xfer_status(ec->ec_dev, sensorhub->msg) < 0) in cros_ec_sensorhub_ring_handler()
820 memcpy(fifo_info, &sensorhub->resp->fifo_info, in cros_ec_sensorhub_ring_handler()
829 fifo_timestamp = sensorhub->fifo_timestamp[ in cros_ec_sensorhub_ring_handler()
833 if (fifo_info->count > sensorhub->fifo_size || in cros_ec_sensorhub_ring_handler()
834 fifo_info->size != sensorhub->fifo_size) { in cros_ec_sensorhub_ring_handler()
835 dev_warn(sensorhub->dev, in cros_ec_sensorhub_ring_handler()
838 sensorhub->fifo_size); in cros_ec_sensorhub_ring_handler()
843 current_timestamp = sensorhub->fifo_timestamp[CROS_EC_SENSOR_LAST_TS]; in cros_ec_sensorhub_ring_handler()
844 out = sensorhub->ring; in cros_ec_sensorhub_ring_handler()
846 sensorhub->params->cmd = MOTIONSENSE_CMD_FIFO_READ; in cros_ec_sensorhub_ring_handler()
847 sensorhub->params->fifo_read.max_data_vector = in cros_ec_sensorhub_ring_handler()
849 sensorhub->msg->outsize = in cros_ec_sensorhub_ring_handler()
851 sensorhub->msg->insize = in cros_ec_sensorhub_ring_handler()
852 sizeof(sensorhub->resp->fifo_read) + in cros_ec_sensorhub_ring_handler()
853 sensorhub->params->fifo_read.max_data_vector * in cros_ec_sensorhub_ring_handler()
855 ret = cros_ec_cmd_xfer_status(ec->ec_dev, sensorhub->msg); in cros_ec_sensorhub_ring_handler()
857 dev_warn(sensorhub->dev, "Fifo error: %d\n", ret); in cros_ec_sensorhub_ring_handler()
860 number_data = sensorhub->resp->fifo_read.number_data; in cros_ec_sensorhub_ring_handler()
862 dev_dbg(sensorhub->dev, "Unexpected empty FIFO\n"); in cros_ec_sensorhub_ring_handler()
866 dev_warn(sensorhub->dev, in cros_ec_sensorhub_ring_handler()
872 sensorhub->ring + fifo_info->count) { in cros_ec_sensorhub_ring_handler()
873 dev_warn(sensorhub->dev, in cros_ec_sensorhub_ring_handler()
875 i, out - sensorhub->ring, i + number_data, in cros_ec_sensorhub_ring_handler()
880 for (in = sensorhub->resp->fifo_read.data, j = 0; in cros_ec_sensorhub_ring_handler()
883 sensorhub, fifo_info, in cros_ec_sensorhub_ring_handler()
892 mutex_unlock(&sensorhub->cmd_lock); in cros_ec_sensorhub_ring_handler()
895 if (out == sensorhub->ring) in cros_ec_sensorhub_ring_handler()
905 if (!sensorhub->tight_timestamps && in cros_ec_sensorhub_ring_handler()
911 for (i = 0; i < sensorhub->sensor_num; i++) { in cros_ec_sensorhub_ring_handler()
913 dev_warn_ratelimited(sensorhub->dev, in cros_ec_sensorhub_ring_handler()
917 if (sensorhub->tight_timestamps) in cros_ec_sensorhub_ring_handler()
918 sensorhub->batch_state[i].last_len = 0; in cros_ec_sensorhub_ring_handler()
926 if (sensorhub->tight_timestamps) in cros_ec_sensorhub_ring_handler()
927 cros_ec_sensor_ring_spread_add(sensorhub, sensor_mask, in cros_ec_sensorhub_ring_handler()
930 cros_ec_sensor_ring_spread_add_legacy(sensorhub, sensor_mask, in cros_ec_sensorhub_ring_handler()
935 sensorhub->fifo_timestamp[CROS_EC_SENSOR_LAST_TS] = current_timestamp; in cros_ec_sensorhub_ring_handler()
939 mutex_unlock(&sensorhub->cmd_lock); in cros_ec_sensorhub_ring_handler()
946 struct cros_ec_sensorhub *sensorhub; in cros_ec_sensorhub_event() local
949 sensorhub = container_of(nb, struct cros_ec_sensorhub, notifier); in cros_ec_sensorhub_event()
950 ec_dev = sensorhub->ec->ec_dev; in cros_ec_sensorhub_event()
963 memcpy(sensorhub->fifo_info, &ec_dev->event_data.data.sensor_fifo.info, in cros_ec_sensorhub_event()
964 sizeof(*sensorhub->fifo_info)); in cros_ec_sensorhub_event()
965 sensorhub->fifo_timestamp[CROS_EC_SENSOR_NEW_TS] = in cros_ec_sensorhub_event()
967 cros_ec_sensorhub_ring_handler(sensorhub); in cros_ec_sensorhub_event()
980 int cros_ec_sensorhub_ring_allocate(struct cros_ec_sensorhub *sensorhub) in cros_ec_sensorhub_ring_allocate() argument
984 sizeof(u16) * sensorhub->sensor_num; in cros_ec_sensorhub_ring_allocate()
987 sensorhub->fifo_info = devm_kzalloc(sensorhub->dev, fifo_info_length, in cros_ec_sensorhub_ring_allocate()
989 if (!sensorhub->fifo_info) in cros_ec_sensorhub_ring_allocate()
996 sensorhub->push_data = devm_kcalloc(sensorhub->dev, in cros_ec_sensorhub_ring_allocate()
997 sensorhub->sensor_num, in cros_ec_sensorhub_ring_allocate()
998 sizeof(*sensorhub->push_data), in cros_ec_sensorhub_ring_allocate()
1000 if (!sensorhub->push_data) in cros_ec_sensorhub_ring_allocate()
1003 sensorhub->tight_timestamps = cros_ec_check_features( in cros_ec_sensorhub_ring_allocate()
1004 sensorhub->ec, in cros_ec_sensorhub_ring_allocate()
1007 if (sensorhub->tight_timestamps) { in cros_ec_sensorhub_ring_allocate()
1008 sensorhub->batch_state = devm_kcalloc(sensorhub->dev, in cros_ec_sensorhub_ring_allocate()
1009 sensorhub->sensor_num, in cros_ec_sensorhub_ring_allocate()
1010 sizeof(*sensorhub->batch_state), in cros_ec_sensorhub_ring_allocate()
1012 if (!sensorhub->batch_state) in cros_ec_sensorhub_ring_allocate()
1027 int cros_ec_sensorhub_ring_add(struct cros_ec_sensorhub *sensorhub) in cros_ec_sensorhub_ring_add() argument
1029 struct cros_ec_dev *ec = sensorhub->ec; in cros_ec_sensorhub_ring_add()
1033 sizeof(u16) * sensorhub->sensor_num; in cros_ec_sensorhub_ring_add()
1036 sensorhub->msg->version = 2; in cros_ec_sensorhub_ring_add()
1037 sensorhub->params->cmd = MOTIONSENSE_CMD_FIFO_INFO; in cros_ec_sensorhub_ring_add()
1038 sensorhub->msg->outsize = 1; in cros_ec_sensorhub_ring_add()
1039 sensorhub->msg->insize = fifo_info_length; in cros_ec_sensorhub_ring_add()
1041 ret = cros_ec_cmd_xfer_status(ec->ec_dev, sensorhub->msg); in cros_ec_sensorhub_ring_add()
1049 sensorhub->fifo_size = sensorhub->resp->fifo_info.size; in cros_ec_sensorhub_ring_add()
1050 sensorhub->ring = devm_kcalloc(sensorhub->dev, sensorhub->fifo_size, in cros_ec_sensorhub_ring_add()
1051 sizeof(*sensorhub->ring), GFP_KERNEL); in cros_ec_sensorhub_ring_add()
1052 if (!sensorhub->ring) in cros_ec_sensorhub_ring_add()
1055 sensorhub->fifo_timestamp[CROS_EC_SENSOR_LAST_TS] = in cros_ec_sensorhub_ring_add()
1059 sensorhub->notifier.notifier_call = cros_ec_sensorhub_event; in cros_ec_sensorhub_ring_add()
1061 &sensorhub->notifier); in cros_ec_sensorhub_ring_add()
1066 return cros_ec_sensorhub_ring_fifo_enable(sensorhub, true); in cros_ec_sensorhub_ring_add()
1071 struct cros_ec_sensorhub *sensorhub = arg; in cros_ec_sensorhub_ring_remove() local
1072 struct cros_ec_device *ec_dev = sensorhub->ec->ec_dev; in cros_ec_sensorhub_ring_remove()
1075 cros_ec_sensorhub_ring_fifo_enable(sensorhub, false); in cros_ec_sensorhub_ring_remove()
1077 &sensorhub->notifier); in cros_ec_sensorhub_ring_remove()