Lines Matching refs:data
62 static void ssp_toggle_mcu_reset_gpio(struct ssp_data *data) in ssp_toggle_mcu_reset_gpio() argument
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()
70 static void ssp_sync_available_sensors(struct ssp_data *data) in ssp_sync_available_sensors() argument
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()
85 ret = ssp_command(data, SSP_MSG2SSP_AP_MCU_SET_DUMPMODE, 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()
92 static void ssp_enable_mcu(struct ssp_data *data, bool enable) in ssp_enable_mcu() argument
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()
115 static int ssp_check_fwbl(struct ssp_data *data) in ssp_check_fwbl() argument
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()
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()
147 static void ssp_reset_mcu(struct ssp_data *data) in ssp_reset_mcu() argument
149 ssp_enable_mcu(data, false); in ssp_reset_mcu()
150 ssp_clean_pending_list(data); in ssp_reset_mcu()
151 ssp_toggle_mcu_reset_gpio(data); in ssp_reset_mcu()
152 ssp_enable_mcu(data, true); in ssp_reset_mcu()
157 struct ssp_data *data = container_of(work, struct ssp_data, work_wdt); in ssp_wdt_work_func() local
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()
163 ssp_reset_mcu(data); 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()
170 struct ssp_data *data = from_timer(data, t, wdt_timer); in ssp_wdt_timer_func() local
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()
186 static void ssp_enable_wdt_timer(struct ssp_data *data) in ssp_enable_wdt_timer() argument
188 mod_timer(&data->wdt_timer, jiffies + msecs_to_jiffies(SSP_WDT_TIME)); in ssp_enable_wdt_timer()
191 static void ssp_disable_wdt_timer(struct ssp_data *data) in ssp_disable_wdt_timer() argument
193 del_timer_sync(&data->wdt_timer); in ssp_disable_wdt_timer()
194 cancel_work_sync(&data->work_wdt); in ssp_disable_wdt_timer()
204 u32 ssp_get_sensor_delay(struct ssp_data *data, enum ssp_sensor_type type) in ssp_get_sensor_delay() argument
206 return data->delay_buf[type]; in ssp_get_sensor_delay()
218 int ssp_enable_sensor(struct ssp_data *data, enum ssp_sensor_type type, in ssp_enable_sensor() argument
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()
232 ret = ssp_send_instruction(data, 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()
246 ret = ssp_send_instruction(data, 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()
263 ssp_enable_wdt_timer(data); in ssp_enable_sensor()
280 int ssp_change_delay(struct ssp_data *data, enum ssp_sensor_type type, in ssp_change_delay() argument
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()
290 ret = ssp_send_instruction(data, SSP_MSG2SSP_INST_CHANGE_DELAY, 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()
311 int ssp_disable_sensor(struct ssp_data *data, enum ssp_sensor_type type) in ssp_disable_sensor() argument
316 if (data->sensor_enable & BIT(type)) { in ssp_disable_sensor()
317 command = cpu_to_le32(data->delay_buf[type]); in ssp_disable_sensor()
319 ret = ssp_send_instruction(data, 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()
334 ssp_disable_wdt_timer(data); in ssp_disable_sensor()
342 struct ssp_data *data = dev_id; in ssp_irq_thread_fn() local
348 ssp_irq_msg(data); in ssp_irq_thread_fn()
353 static int ssp_initialize_mcu(struct ssp_data *data) in ssp_initialize_mcu() argument
357 ssp_clean_pending_list(data); in ssp_initialize_mcu()
359 ret = ssp_get_chipid(data); in ssp_initialize_mcu()
361 dev_err(&data->spi->dev, "%s - MCU %s ret = %d\n", __func__, in ssp_initialize_mcu()
367 dev_info(&data->spi->dev, "MCU device ID = %d\n", ret); in ssp_initialize_mcu()
373 ret = ssp_set_magnetic_matrix(data); in ssp_initialize_mcu()
375 dev_err(&data->spi->dev, 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()
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()
391 return ssp_command(data, SSP_MSG2SSP_AP_MCU_DUMP_CHECK, 0); in ssp_initialize_mcu()
400 struct ssp_data *data = container_of((struct delayed_work *)work, in ssp_refresh_task() local
403 dev_info(&data->spi->dev, "refreshing\n"); in ssp_refresh_task()
405 data->reset_cnt++; in ssp_refresh_task()
407 if (ssp_initialize_mcu(data) >= 0) { in ssp_refresh_task()
408 ssp_sync_available_sensors(data); 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()
420 int ssp_queue_ssp_refresh_task(struct ssp_data *data, unsigned int delay) in ssp_queue_ssp_refresh_task() argument
422 cancel_delayed_work_sync(&data->work_refresh); in ssp_queue_ssp_refresh_task()
425 &data->work_refresh, in ssp_queue_ssp_refresh_task()
432 .data = &ssp_rinato_info,
435 .data = &ssp_thermostat_info,
443 struct ssp_data *data; in ssp_parse_dt() local
445 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); in ssp_parse_dt()
446 if (!data) in ssp_parse_dt()
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()
464 dev_set_drvdata(dev, data); in ssp_parse_dt()
466 return data; in ssp_parse_dt()
477 struct ssp_data *data = dev_get_drvdata(indio_dev->dev.parent->parent); in ssp_register_consumer() local
479 data->sensor_devs[type] = indio_dev; in ssp_register_consumer()
486 struct ssp_data *data; in ssp_probe() local
488 data = ssp_parse_dt(&spi->dev); in ssp_probe()
489 if (!data) { in ssp_probe()
509 data->fw_dl_state = SSP_FW_DL_STATE_NONE; in ssp_probe()
510 data->spi = spi; in ssp_probe()
511 spi_set_drvdata(spi, data); 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()
539 "SSP_Int", data); 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()
553 ret = ssp_initialize_mcu(data); 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()
579 struct ssp_data *data = spi_get_drvdata(spi); in ssp_remove() local
581 if (ssp_command(data, SSP_MSG2SSP_AP_STATUS_SHUTDOWN, 0) < 0) in ssp_remove()
582 dev_err(&data->spi->dev, in ssp_remove()
585 ssp_enable_mcu(data, false); in ssp_remove()
586 ssp_disable_wdt_timer(data); in ssp_remove()
588 ssp_clean_pending_list(data); 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()
604 struct ssp_data *data = spi_get_drvdata(to_spi_device(dev)); in ssp_suspend() local
606 data->last_resume_state = SSP_MSG2SSP_AP_STATUS_SUSPEND; in ssp_suspend()
608 if (atomic_read(&data->enable_refcount) > 0) in ssp_suspend()
609 ssp_disable_wdt_timer(data); in ssp_suspend()
611 ret = ssp_command(data, SSP_MSG2SSP_AP_STATUS_SUSPEND, 0); in ssp_suspend()
613 dev_err(&data->spi->dev, in ssp_suspend()
616 ssp_enable_wdt_timer(data); in ssp_suspend()
620 data->time_syncing = false; in ssp_suspend()
621 disable_irq(data->spi->irq); in ssp_suspend()
629 struct ssp_data *data = spi_get_drvdata(to_spi_device(dev)); in ssp_resume() local
631 enable_irq(data->spi->irq); in ssp_resume()
633 if (atomic_read(&data->enable_refcount) > 0) in ssp_resume()
634 ssp_enable_wdt_timer(data); in ssp_resume()
636 ret = ssp_command(data, SSP_MSG2SSP_AP_STATUS_RESUME, 0); in ssp_resume()
638 dev_err(&data->spi->dev, in ssp_resume()
640 ssp_disable_wdt_timer(data); in ssp_resume()
645 data->last_resume_state = SSP_MSG2SSP_AP_STATUS_RESUME; in ssp_resume()