Lines Matching +full:acquisition +full:- +full:time
1 // SPDX-License-Identifier: GPL-2.0-or-later
55 .name = "ssp-accelerometer",
58 .name = "ssp-gyroscope",
64 gpiod_set_value(data->mcu_reset_gpiod, 0); in ssp_toggle_mcu_reset_gpio()
66 gpiod_set_value(data->mcu_reset_gpiod, 1); in ssp_toggle_mcu_reset_gpio()
75 if (data->available_sensors & BIT(i)) { in ssp_sync_available_sensors()
76 ret = ssp_enable_sensor(data, i, data->delay_buf[i]); in ssp_sync_available_sensors()
78 dev_err(&data->spi->dev, in ssp_sync_available_sensors()
86 data->mcu_dump_mode); in ssp_sync_available_sensors()
88 dev_err(&data->spi->dev, in ssp_sync_available_sensors()
94 dev_info(&data->spi->dev, "current shutdown = %d, old = %d\n", enable, in ssp_enable_mcu()
95 data->shut_down); in ssp_enable_mcu()
97 if (enable && data->shut_down) { in ssp_enable_mcu()
98 data->shut_down = false; in ssp_enable_mcu()
99 enable_irq(data->spi->irq); in ssp_enable_mcu()
100 enable_irq_wake(data->spi->irq); in ssp_enable_mcu()
101 } else if (!enable && !data->shut_down) { in ssp_enable_mcu()
102 data->shut_down = true; in ssp_enable_mcu()
103 disable_irq(data->spi->irq); in ssp_enable_mcu()
104 disable_irq_wake(data->spi->irq); in ssp_enable_mcu()
106 dev_warn(&data->spi->dev, "current shutdown = %d, old = %d\n", in ssp_enable_mcu()
107 enable, data->shut_down); in ssp_enable_mcu()
120 data->cur_firm_rev = ssp_get_firmware_rev(data); in ssp_check_fwbl()
121 if (data->cur_firm_rev == SSP_INVALID_REVISION || in ssp_check_fwbl()
122 data->cur_firm_rev == SSP_INVALID_REVISION2) { in ssp_check_fwbl()
123 dev_warn(&data->spi->dev, in ssp_check_fwbl()
124 "Invalid revision, trying %d time\n", retries); in ssp_check_fwbl()
130 if (data->cur_firm_rev == SSP_INVALID_REVISION || in ssp_check_fwbl()
131 data->cur_firm_rev == SSP_INVALID_REVISION2) { in ssp_check_fwbl()
132 dev_err(&data->spi->dev, "SSP_INVALID_REVISION\n"); in ssp_check_fwbl()
136 dev_info(&data->spi->dev, in ssp_check_fwbl()
138 data->cur_firm_rev, in ssp_check_fwbl()
139 data->sensorhub_info->fw_rev); in ssp_check_fwbl()
141 if (data->cur_firm_rev != data->sensorhub_info->fw_rev) in ssp_check_fwbl()
159 dev_err(&data->spi->dev, "%s - Sensor state: 0x%x, RC: %u, CC: %u\n", in ssp_wdt_work_func()
160 __func__, data->available_sensors, data->reset_cnt, in ssp_wdt_work_func()
161 data->com_fail_cnt); in ssp_wdt_work_func()
164 data->com_fail_cnt = 0; in ssp_wdt_work_func()
165 data->timeout_cnt = 0; in ssp_wdt_work_func()
172 switch (data->fw_dl_state) { in ssp_wdt_timer_func()
179 if (data->timeout_cnt > SSP_LIMIT_TIMEOUT_CNT || in ssp_wdt_timer_func()
180 data->com_fail_cnt > SSP_LIMIT_RESET_CNT) in ssp_wdt_timer_func()
181 queue_work(system_power_efficient_wq, &data->work_wdt); in ssp_wdt_timer_func()
183 mod_timer(&data->wdt_timer, jiffies + msecs_to_jiffies(SSP_WDT_TIME)); in ssp_wdt_timer_func()
188 mod_timer(&data->wdt_timer, jiffies + msecs_to_jiffies(SSP_WDT_TIME)); in ssp_enable_wdt_timer()
193 del_timer_sync(&data->wdt_timer); in ssp_disable_wdt_timer()
194 cancel_work_sync(&data->work_wdt); in ssp_disable_wdt_timer()
198 * ssp_get_sensor_delay() - gets sensor data acquisition period
202 * Returns acquisition period in ms
206 return data->delay_buf[type]; in ssp_get_sensor_delay()
211 * ssp_enable_sensor() - enables data acquisition for sensor
225 to_send.b = cpu_to_le32(data->batch_latency_buf[type]); in ssp_enable_sensor()
226 to_send.c = data->batch_opt_buf[type]; in ssp_enable_sensor()
228 switch (data->check_status[type]) { in ssp_enable_sensor()
237 dev_err(&data->spi->dev, "Enabling sensor failed\n"); in ssp_enable_sensor()
238 data->check_status[type] = SSP_NO_SENSOR_STATE; in ssp_enable_sensor()
242 data->sensor_enable |= BIT(type); in ssp_enable_sensor()
243 data->check_status[type] = SSP_RUNNING_SENSOR_STATE; in ssp_enable_sensor()
250 dev_err(&data->spi->dev, in ssp_enable_sensor()
256 data->check_status[type] = SSP_ADD_SENSOR_STATE; in ssp_enable_sensor()
260 data->delay_buf[type] = delay; in ssp_enable_sensor()
262 if (atomic_inc_return(&data->enable_refcount) == 1) in ssp_enable_sensor()
273 * ssp_change_delay() - changes data acquisition for sensor
287 to_send.b = cpu_to_le32(data->batch_latency_buf[type]); in ssp_change_delay()
288 to_send.c = data->batch_opt_buf[type]; in ssp_change_delay()
293 dev_err(&data->spi->dev, "Changing sensor delay failed\n"); in ssp_change_delay()
297 data->delay_buf[type] = delay; in ssp_change_delay()
304 * ssp_disable_sensor() - disables sensor
316 if (data->sensor_enable & BIT(type)) { in ssp_disable_sensor()
317 command = cpu_to_le32(data->delay_buf[type]); in ssp_disable_sensor()
324 dev_err(&data->spi->dev, "Remove sensor fail\n"); in ssp_disable_sensor()
328 data->sensor_enable &= ~BIT(type); in ssp_disable_sensor()
331 data->check_status[type] = SSP_ADD_SENSOR_STATE; in ssp_disable_sensor()
333 if (atomic_dec_and_test(&data->enable_refcount)) in ssp_disable_sensor()
361 dev_err(&data->spi->dev, "%s - MCU %s ret = %d\n", __func__, in ssp_initialize_mcu()
364 return ret < 0 ? ret : -ENODEV; in ssp_initialize_mcu()
367 dev_info(&data->spi->dev, "MCU device ID = %d\n", ret); in ssp_initialize_mcu()
375 dev_err(&data->spi->dev, in ssp_initialize_mcu()
376 "%s - ssp_set_magnetic_matrix failed\n", __func__); in ssp_initialize_mcu()
380 data->available_sensors = ssp_get_sensor_scanning_info(data); in ssp_initialize_mcu()
381 if (data->available_sensors == 0) { in ssp_initialize_mcu()
382 dev_err(&data->spi->dev, in ssp_initialize_mcu()
383 "%s - ssp_get_sensor_scanning_info failed\n", __func__); in ssp_initialize_mcu()
384 return -EIO; in ssp_initialize_mcu()
387 data->cur_firm_rev = ssp_get_firmware_rev(data); in ssp_initialize_mcu()
388 dev_info(&data->spi->dev, "MCU Firm Rev : New = %8u\n", in ssp_initialize_mcu()
389 data->cur_firm_rev); in ssp_initialize_mcu()
403 dev_info(&data->spi->dev, "refreshing\n"); in ssp_refresh_task()
405 data->reset_cnt++; in ssp_refresh_task()
409 if (data->last_ap_state != 0) in ssp_refresh_task()
410 ssp_command(data, data->last_ap_state, 0); in ssp_refresh_task()
412 if (data->last_resume_state != 0) in ssp_refresh_task()
413 ssp_command(data, data->last_resume_state, 0); in ssp_refresh_task()
415 data->timeout_cnt = 0; in ssp_refresh_task()
416 data->com_fail_cnt = 0; in ssp_refresh_task()
422 cancel_delayed_work_sync(&data->work_refresh); in ssp_queue_ssp_refresh_task()
425 &data->work_refresh, in ssp_queue_ssp_refresh_task()
431 .compatible = "samsung,sensorhub-rinato",
434 .compatible = "samsung,sensorhub-thermostat",
449 data->mcu_ap_gpiod = devm_gpiod_get(dev, "mcu-ap", GPIOD_IN); in ssp_parse_dt()
450 if (IS_ERR(data->mcu_ap_gpiod)) in ssp_parse_dt()
453 data->ap_mcu_gpiod = devm_gpiod_get(dev, "ap-mcu", GPIOD_OUT_HIGH); in ssp_parse_dt()
454 if (IS_ERR(data->ap_mcu_gpiod)) in ssp_parse_dt()
457 data->mcu_reset_gpiod = devm_gpiod_get(dev, "mcu-reset", in ssp_parse_dt()
459 if (IS_ERR(data->mcu_reset_gpiod)) in ssp_parse_dt()
462 data->sensorhub_info = device_get_match_data(dev); in ssp_parse_dt()
470 * ssp_register_consumer() - registers iio consumer in ssp framework
477 struct ssp_data *data = dev_get_drvdata(indio_dev->dev.parent->parent); in ssp_register_consumer()
479 data->sensor_devs[type] = indio_dev; in ssp_register_consumer()
488 data = ssp_parse_dt(&spi->dev); in ssp_probe()
490 dev_err(&spi->dev, "Failed to find platform data\n"); in ssp_probe()
491 return -ENODEV; in ssp_probe()
494 ret = mfd_add_devices(&spi->dev, PLATFORM_DEVID_NONE, in ssp_probe()
498 dev_err(&spi->dev, "mfd add devices fail\n"); in ssp_probe()
502 spi->mode = SPI_MODE_1; in ssp_probe()
505 dev_err(&spi->dev, "Failed to setup spi\n"); in ssp_probe()
509 data->fw_dl_state = SSP_FW_DL_STATE_NONE; in ssp_probe()
510 data->spi = spi; in ssp_probe()
513 mutex_init(&data->comm_lock); in ssp_probe()
516 data->delay_buf[i] = SSP_DEFAULT_POLLING_DELAY; in ssp_probe()
517 data->batch_latency_buf[i] = 0; in ssp_probe()
518 data->batch_opt_buf[i] = 0; in ssp_probe()
519 data->check_status[i] = SSP_INITIALIZATION_STATE; in ssp_probe()
522 data->delay_buf[SSP_BIO_HRM_LIB] = 100; in ssp_probe()
524 data->time_syncing = true; in ssp_probe()
526 mutex_init(&data->pending_lock); in ssp_probe()
527 INIT_LIST_HEAD(&data->pending_list); in ssp_probe()
529 atomic_set(&data->enable_refcount, 0); in ssp_probe()
531 INIT_WORK(&data->work_wdt, ssp_wdt_work_func); in ssp_probe()
532 INIT_DELAYED_WORK(&data->work_refresh, ssp_refresh_task); in ssp_probe()
534 timer_setup(&data->wdt_timer, ssp_wdt_timer_func, 0); in ssp_probe()
536 ret = request_threaded_irq(data->spi->irq, NULL, in ssp_probe()
541 dev_err(&spi->dev, "Irq request fail\n"); in ssp_probe()
546 data->shut_down = false; in ssp_probe()
549 enable_irq_wake(data->spi->irq); in ssp_probe()
551 data->fw_dl_state = ssp_check_fwbl(data); in ssp_probe()
552 if (data->fw_dl_state == SSP_FW_DL_STATE_NONE) { in ssp_probe()
555 dev_err(&spi->dev, "Initialize_mcu failed\n"); in ssp_probe()
559 dev_err(&spi->dev, "Firmware version not supported\n"); in ssp_probe()
560 ret = -EPERM; in ssp_probe()
567 free_irq(data->spi->irq, data); in ssp_probe()
569 mutex_destroy(&data->pending_lock); in ssp_probe()
570 mutex_destroy(&data->comm_lock); in ssp_probe()
572 dev_err(&spi->dev, "Probe failed!\n"); in ssp_probe()
582 dev_err(&data->spi->dev, in ssp_remove()
590 free_irq(data->spi->irq, data); in ssp_remove()
592 del_timer_sync(&data->wdt_timer); in ssp_remove()
593 cancel_work_sync(&data->work_wdt); in ssp_remove()
595 mutex_destroy(&data->comm_lock); in ssp_remove()
596 mutex_destroy(&data->pending_lock); in ssp_remove()
598 mfd_remove_devices(&spi->dev); in ssp_remove()
606 data->last_resume_state = SSP_MSG2SSP_AP_STATUS_SUSPEND; in ssp_suspend()
608 if (atomic_read(&data->enable_refcount) > 0) in ssp_suspend()
613 dev_err(&data->spi->dev, in ssp_suspend()
620 data->time_syncing = false; in ssp_suspend()
621 disable_irq(data->spi->irq); in ssp_suspend()
631 enable_irq(data->spi->irq); in ssp_resume()
633 if (atomic_read(&data->enable_refcount) > 0) in ssp_resume()
638 dev_err(&data->spi->dev, in ssp_resume()
645 data->last_resume_state = SSP_MSG2SSP_AP_STATUS_RESUME; in ssp_resume()