1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
|
/*
* Copyright (C) 2012, Samsung Electronics Co. Ltd. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "ssp.h"
#ifdef CONFIG_OF
#include <linux/of_gpio.h>
#endif
#include <linux/sec_debug.h>
#include <linux/sec_batt.h>
#define DEBUG
#ifdef CONFIG_HAS_EARLYSUSPEND
static void ssp_early_suspend(struct early_suspend *handler);
static void ssp_late_resume(struct early_suspend *handler);
#endif
#define NORMAL_SENSOR_STATE_K 0x3FEFF
#if defined(CONFIG_MUIC_NOTIFIER)
#include <linux/muic/muic.h>
#include <linux/muic/muic_notifier.h>
#endif
unsigned int bootmode;
EXPORT_SYMBOL(bootmode);
static int __init bootmode_setup(char *str)
{
get_option(&str, &bootmode);
pr_info("[SSP] bootmode_setup = %d\n",bootmode);
return 1;
}
__setup("bootmode=", bootmode_setup);
void ssp_enable(struct ssp_data *data, bool enable)
{
if (enable == !data->bSspShutdown)
return;
pr_info("[SSP] %s, new enable = %d, old enable = %d\n",
__func__, enable, !data->bSspShutdown);
if (enable && data->bSspShutdown)
data->bSspShutdown = false;
else if (!enable && !data->bSspShutdown)
data->bSspShutdown = true;
}
u64 get_current_timestamp(void)
{
u64 timestamp;
struct timespec ts;
ts = ktime_to_timespec(ktime_get_boottime());
timestamp = ts.tv_sec * 1000000000ULL + ts.tv_nsec;
return timestamp;
}
u64 get_kernel_timestamp(void)
{
u64 timestamp;
struct timespec ts;
ktime_get_ts(&ts); /* get high res monotonic timestamp */
timestamp = ts.tv_sec * 1000000000ULL + ts.tv_nsec;
return timestamp;
}
/*************************************************************************/
/* initialize sensor hub */
/*************************************************************************/
static void initialize_variable(struct ssp_data *data)
{
int iSensorIndex;
int sensor_data_size[SENSOR_MAX] = SENSOR_DATA_SIZE;
int sensor_report_mode[SENSOR_MAX] = SENSOR_REPORT_MODE;
memcpy(&data->sensor_data_size, sensor_data_size, sizeof(data->sensor_data_size));
memcpy(&data->sensor_report_mode, sensor_report_mode, sizeof(data->sensor_report_mode));
data->cameraGyroSyncMode = false;
data->ts_stacked_cnt = 0;
data->ts_stacked_offset = 0;
data->ts_irq_last = 0ULL;
for (iSensorIndex = 0; iSensorIndex < SENSOR_MAX; iSensorIndex++) {
data->adDelayBuf[iSensorIndex] = DEFUALT_POLLING_DELAY;
data->batchLatencyBuf[iSensorIndex] = 0;
data->batchOptBuf[iSensorIndex] = 0;
data->aiCheckStatus[iSensorIndex] = INITIALIZATION_STATE;
data->lastTimestamp[iSensorIndex] = 0;
data->reportedData[iSensorIndex] = false;
}
atomic64_set(&data->aSensorEnable, 0);
data->iLibraryLength = 0;
data->uSensorState = NORMAL_SENSOR_STATE_K;
data->uFactoryProxAvg[0] = 0;
data->uMagCntlRegData = 1;
data->uResetCnt = 0;
data->uTimeOutCnt = 0;
data->uComFailCnt = 0;
data->uIrqCnt = 0;
data->bSspShutdown = true;
data->bProximityRawEnabled = false;
data->bGeomagneticRawEnabled = false;
data->bBarcodeEnabled = false;
data->bAccelAlert = false;
data->bTimeSyncing = true;
data->bHandlingIrq = false;
data->accelcal.x = 0;
data->accelcal.y = 0;
data->accelcal.z = 0;
data->gyrocal.x = 0;
data->gyrocal.y = 0;
data->gyrocal.z = 0;
data->magoffset.x = 0;
data->magoffset.y = 0;
data->magoffset.z = 0;
data->iPressureCal = 0;
data->uProxCanc = 0;
data->uProxHiThresh = data->uProxHiThresh_default;
data->uProxLoThresh = data->uProxLoThresh_default;
data->uGyroDps = GYROSCOPE_DPS2000;
data->uIr_Current = DEFUALT_IR_CURRENT;
data->mcu_device = NULL;
data->acc_device = NULL;
data->gyro_device = NULL;
data->mag_device = NULL;
data->prs_device = NULL;
data->prox_device = NULL;
data->light_device = NULL;
data->ges_device = NULL;
data->voice_device = NULL;
data->bMcuDumpMode = ssp_check_sec_dump_mode();
INIT_LIST_HEAD(&data->pending_list);
data->bbd_on_packet_wq =
create_singlethread_workqueue("ssp_bbd_on_packet_wq");
INIT_WORK(&data->work_bbd_on_packet, bbd_on_packet_work_func);
data->bbd_mcu_ready_wq =
create_singlethread_workqueue("ssp_bbd_mcu_ready_wq");
INIT_WORK(&data->work_bbd_mcu_ready, bbd_mcu_ready_work_func);
#ifdef SSP_BBD_USE_SEND_WORK
data->bbd_send_packet_wq =
create_singlethread_workqueue("ssp_bbd_send_packet_wq");
INIT_WORK(&data->work_bbd_send_packet, bbd_send_packet_work_func);
#endif /* SSP_BBD_USE_SEND_WORK */
data->step_count_total = 0;
data->sealevelpressure = 0;
data->gyro_lib_state = GYRO_CALIBRATION_STATE_NOT_YET;
// HIFI batching wakeup issue
data->resumeTimestamp = 0;
data->bIsResumed = false;
data->lastOffset = 0;
initialize_function_pointer(data);
data->errorCount = 0;
data->pktErrCnt = 0;
data->mcuAbnormal = false;
}
int initialize_mcu(struct ssp_data *data)
{
int iRet = 0;
clean_pending_list(data);
iRet = get_chipid(data);
pr_info("[SSP] MCU device ID = %d, reading ID = %d\n", DEVICE_ID, iRet);
if (iRet != DEVICE_ID) {
if (iRet < 0) {
pr_err("[SSP]: %s - MCU is not working : 0x%x\n",
__func__, iRet);
} else {
pr_err("[SSP]: %s - MCU identification failed\n",
__func__);
iRet = -ENODEV;
}
goto out;
}
iRet = set_sensor_position(data);
if (iRet < 0) {
pr_err("[SSP]: %s - set_sensor_position failed\n", __func__);
goto out;
}
#if defined (CONFIG_SENSORS_SSP_VLTE)
iRet = set_sensor_sub_position(data);
if (iRet < 0) {
pr_err("[SSP]: %s - set_sensor_sub_position failed\n", __func__);
goto out;
}
#endif
#ifdef CONFIG_SENSORS_MULTIPLE_GLASS_TYPE
iRet = set_glass_type(data);
if (iRet < 0) {
pr_err("[SSP]: %s - set_glass_type failed\n", __func__);
goto out;
}
#endif
/* Hall IC threshold */
if (data->hall_threshold[0]) {
iRet = set_hall_threshold(data);
if (iRet < 0) {
pr_err("[SSP]: %s - set_hall_threshold failed\n", __func__);
goto out;
}
}
data->uSensorState = get_sensor_scanning_info(data);
if (data->uSensorState == 0) {
pr_err("[SSP]: %s - get_sensor_scanning_info failed\n",
__func__);
iRet = ERROR;
goto out;
}
iRet = initialize_magnetic_sensor(data);
if (iRet < 0)
pr_err("[SSP]: %s - initialize magnetic sensor failed\n",
__func__);
data->uCurFirmRev = get_firmware_rev(data);
pr_info("[SSP] MCU Firm Rev : New = %8u\n",
data->uCurFirmRev);
// hoi: il dan mak a
#ifndef CONFIG_SENSORS_SSP_BBD
iRet = ssp_send_cmd(data, MSG2SSP_AP_MCU_DUMP_CHECK, 0);
#endif
out:
return iRet;
}
static bbd_callbacks ssp_bbd_callbacks = {
.on_packet = NULL,
.on_packet_alarm = callback_bbd_on_packet_alarm,
.on_control = callback_bbd_on_control,
.on_mcu_ready = callback_bbd_on_mcu_ready,
};
static int ssp_parse_dt(struct device *dev,struct ssp_data *data)
{
struct device_node *np = dev->of_node;
int errorno = 0;
#if defined(CONFIG_SENSORS_SSP_YAS532) || defined(CONFIG_SENSORS_SSP_YAS537)
u32 len, temp;
int i;
#endif
if (!np) {
pr_err("[SSP] NO dt node!!\n");
return errorno;
}
if (of_property_read_u32(np, "ssp-acc-position", &data->accel_position))
data->accel_position = 0;
if (of_property_read_u32(np, "ssp-mag-position", &data->mag_position))
data->mag_position = 0;
pr_info("[SSP] acc-posi[%d] mag-posi[%d]\n",
data->accel_position, data->mag_position);
#if defined (CONFIG_SENSORS_SSP_VLTE)
if (of_property_read_u32(np, "ssp-acc-sub-position", &data->accel_sub_position))
data->accel_position = 0;
pr_info("[SSP] acc-sub-posi[%d] \n", data->accel_sub_position);
#endif
/* acc type */
if (of_property_read_u32(np, "ssp-acc-type", &data->acc_type))
data->acc_type = 0;
pr_info("[SSP] acc-type = %d\n", data->acc_type);
if (of_property_read_u32(np, "ssp-ap-rev", &data->ap_rev))
data->ap_rev = 0;
if (of_property_read_u32(np, "ssp,prox-hi_thresh",
&data->uProxHiThresh_default))
data->uProxHiThresh_default = DEFUALT_HIGH_THRESHOLD;
if (of_property_read_u32(np, "ssp,prox-low_thresh",
&data->uProxLoThresh_default))
data->uProxLoThresh_default = DEFUALT_LOW_THRESHOLD;
pr_info("[SSP] hi-thresh[%u] low-thresh[%u]\n",
data->uProxHiThresh_default, data->uProxLoThresh_default);
if (of_property_read_u32(np, "ssp,prox-cal_hi_thresh",
&data->uProxHiThresh_cal))
data->uProxHiThresh_cal = DEFUALT_CAL_HIGH_THRESHOLD;
if (of_property_read_u32(np, "ssp,prox-cal_LOW_thresh",
&data->uProxLoThresh_cal))
data->uProxLoThresh_cal = DEFUALT_CAL_LOW_THRESHOLD;
pr_info("[SSP] cal-hi[%u] cal-low[%u]\n",
data->uProxHiThresh_cal, data->uProxLoThresh_cal);
#ifdef CONFIG_SENSORS_MULTIPLE_GLASS_TYPE
if (of_property_read_u32(np, "ssp-glass-type", &data->glass_type))
data->glass_type = 0;
#endif
#if defined(CONFIG_SENSORS_SSP_YAS532) || defined(CONFIG_SENSORS_SSP_YAS537)
if (!of_get_property(np, "ssp-mag-array", &len)) {
pr_info("[SSP] No static matrix at DT for YAS532!(%p)\n", data->static_matrix);
goto dt_exit;
}
if (len/4 != 9) {
pr_err("[SSP] Length/4:%d should be 9 for YAS532!\n", len/4);
goto dt_exit;
}
data->static_matrix = kzalloc(9*sizeof(s16), GFP_KERNEL);
pr_info("[SSP] static matrix Length:%d, Len/4=%d\n", len, len/4);
for (i = 0; i < 9; i++) {
if (of_property_read_u32_index(np, "ssp-mag-array", i, &temp)) {
pr_err("[SSP] %s cannot get u32 of array[%d]!\n", __func__, i);
goto dt_exit;
}
*(data->static_matrix+i) = (int)temp;
}
#endif
/* Hall IC threshold */
if (of_property_read_u16_array(np, "ssp-hall-threshold",
data->hall_threshold, ARRAY_SIZE(data->hall_threshold))) {
pr_err("[SSP]: %s - no hall-threshold, set as 0\n", __func__);
} else {
pr_info("[SSP]: %s - hall thr: %d %d %d %d %d\n", __func__,
data->hall_threshold[0], data->hall_threshold[1],
data->hall_threshold[2], data->hall_threshold[3],
data->hall_threshold[4]);
}
return errorno;
#if defined(CONFIG_SENSORS_SSP_YAS532) || defined(CONFIG_SENSORS_SSP_YAS537)
dt_exit:
if(data->static_matrix != NULL)
kfree(data->static_matrix);
return errorno;
#endif
}
#if defined(CONFIG_MUIC_NOTIFIER)
static int exynos_cpuidle_muic_notifier(struct notifier_block *nb,
unsigned long action, void *data)
{
struct ssp_data *ssp_data;
muic_attached_dev_t attached_dev = *(muic_attached_dev_t *)data;
ssp_data = container_of(nb, struct ssp_data, cpuidle_muic_nb);
switch (attached_dev) {
case ATTACHED_DEV_JIG_UART_OFF_MUIC:
case ATTACHED_DEV_JIG_UART_OFF_VB_MUIC:
case ATTACHED_DEV_JIG_UART_OFF_VB_OTG_MUIC:
case ATTACHED_DEV_JIG_UART_OFF_VB_FG_MUIC:
case ATTACHED_DEV_JIG_UART_ON_MUIC:
if (action == MUIC_NOTIFY_CMD_DETACH)
ssp_data->jig_is_attached = false;
else if (action == MUIC_NOTIFY_CMD_ATTACH)
ssp_data->jig_is_attached = true;
else
pr_err("[SSP] %s: ACTION Error!\n", __func__);
break;
default:
break;
}
pr_info("[SSP] %s: dev=%d, action=%lu\n", __func__, attached_dev, action);
return NOTIFY_DONE;
}
#endif
static int ssp_probe(struct spi_device *spi)
{
struct ssp_data *data;
struct ssp_platform_data *pdata;
int iRet = 0;
pr_info("[SSP] %s, is called\n", __func__);
data = kzalloc(sizeof(*data), GFP_KERNEL);
if (data == NULL) {
pr_err("[SSP] %s, failed to allocate memory for data\n", __func__);
iRet = -ENOMEM;
goto exit;
}
if (spi->dev.of_node) {
iRet = ssp_parse_dt(&spi->dev, data);
if (iRet) {
pr_err("[SSP]: %s - Failed to parse DT\n", __func__);
goto err_setup;
}
//data->ssp_changes = SSP_MCU_L5; /* K330, MPU L5*/
} else {
pdata = spi->dev.platform_data;
if (pdata == NULL) {
pr_err("[SSP] %s, platform_data is null\n", __func__);
iRet = -ENOMEM;
goto err_setup;
}
/* AP system_rev */
if (pdata->check_ap_rev)
data->ap_rev = pdata->check_ap_rev();
else
data->ap_rev = 0;
/* Get sensor positions */
if (pdata->get_positions) {
pdata->get_positions(&data->accel_position,
&data->mag_position);
} else {
data->accel_position = 0;
data->mag_position = 0;
}
if (pdata->mag_matrix) {
data->mag_matrix_size = pdata->mag_matrix_size;
data->mag_matrix = pdata->mag_matrix;
}
}
spi->mode = SPI_MODE_3;
if (spi_setup(spi)) {
pr_err("[SSP] %s, failed to setup spi\n", __func__);
iRet = -ENODEV;
goto err_setup;
}
data->bProbeIsDone = false;
data->spi = spi;
spi_set_drvdata(spi, data);
#ifdef CONFIG_SENSORS_SSP_SHTC1
mutex_init(&data->cp_temp_adc_lock);
mutex_init(&data->bulk_temp_read_lock);
#endif
mutex_init(&data->comm_mutex);
mutex_init(&data->pending_mutex);
mutex_init(&data->enable_mutex);
mutex_init(&data->ssp_enable_mutex);
if (spi->dev.of_node == NULL) {
pr_err("[SSP] %s, function callback is null\n", __func__);
iRet = -EIO;
goto err_reset_null;
}
pr_info("\n#####################################################\n");
initialize_variable(data);
wake_lock_init(&data->ssp_wake_lock,
WAKE_LOCK_SUSPEND, "ssp_wake_lock");
iRet = initialize_input_dev(data);
if (iRet < 0) {
pr_err("[SSP]: %s - could not create input device\n", __func__);
goto err_input_register_device;
}
iRet = initialize_debug_timer(data);
if (iRet < 0) {
pr_err("[SSP]: %s - could not create workqueue\n", __func__);
goto err_create_workqueue;
}
iRet = initialize_sysfs(data);
if (iRet < 0) {
pr_err("[SSP]: %s - could not create sysfs\n", __func__);
goto err_sysfs_create;
}
iRet = initialize_event_symlink(data);
if (iRet < 0) {
pr_err("[SSP]: %s - could not create symlink\n", __func__);
goto err_symlink_create;
}
msleep(70);
#ifdef CONFIG_SENSORS_SSP_SENSORHUB
/* init sensorhub device */
iRet = ssp_sensorhub_initialize(data);
if (iRet < 0) {
pr_err("%s: ssp_sensorhub_initialize err(%d)\n", __func__, iRet);
ssp_sensorhub_remove(data);
}
#endif
/* HIFI Sensor + Batch Support */
mutex_init(&data->batch_events_lock);
data->batch_wq = create_singlethread_workqueue("ssp_batch_wq");
if (!data->batch_wq)
{
iRet = -1;
pr_err("[SSP]: %s - could not create batch workqueue\n", __func__);
goto err_create_batch_workqueue;
}
bbd_register(data, &ssp_bbd_callbacks);
#ifdef CONFIG_HAS_EARLYSUSPEND
data->early_suspend.suspend = ssp_early_suspend;
data->early_suspend.resume = ssp_late_resume;
register_early_suspend(&data->early_suspend);
#endif
#if defined(CONFIG_MUIC_NOTIFIER)
muic_notifier_register(&data->cpuidle_muic_nb,
exynos_cpuidle_muic_notifier, MUIC_NOTIFY_DEV_CPUIDLE);
#endif
pr_info("[SSP]: %s - probe success!\n", __func__);
enable_debug_timer(data);
data->bProbeIsDone = true;
iRet = 0;
goto exit;
err_create_batch_workqueue:
destroy_workqueue(data->batch_wq);
mutex_destroy(&data->batch_events_lock);
err_symlink_create:
remove_sysfs(data);
err_sysfs_create:
destroy_workqueue(data->debug_wq);
err_create_workqueue:
remove_input_dev(data);
err_input_register_device:
wake_lock_destroy(&data->ssp_wake_lock);
err_reset_null:
mutex_destroy(&data->comm_mutex);
mutex_destroy(&data->pending_mutex);
mutex_destroy(&data->enable_mutex);
mutex_destroy(&data->ssp_enable_mutex);
#ifdef CONFIG_SENSORS_SSP_SHTC1
mutex_destroy(&data->bulk_temp_read_lock);
mutex_destroy(&data->cp_temp_adc_lock);
#endif
err_setup:
kfree(data);
pr_err("[SSP] %s, probe failed!\n", __func__);
exit:
pr_info("#####################################################\n\n");
return iRet;
}
static void ssp_shutdown(struct spi_device *spi)
{
struct ssp_data *data = spi_get_drvdata(spi);
pr_err("[SSP] lpm %d recovery\n", lpcharge);
func_dbg();
if (data->bProbeIsDone == false)
goto exit;
disable_debug_timer(data);
//hoi
// if (SUCCESS != ssp_send_cmd(data, MSG2SSP_AP_STATUS_SHUTDOWN, 0))
// pr_err("[SSP]: %s MSG2SSP_AP_STATUS_SHUTDOWN failed\n",
// __func__);
mutex_lock(&data->ssp_enable_mutex);
ssp_enable(data, false);
clean_pending_list(data);
mutex_unlock(&data->ssp_enable_mutex);
#ifdef CONFIG_HAS_EARLYSUSPEND
unregister_early_suspend(&data->early_suspend);
#endif
bbd_register(NULL, NULL);
//hoi
cancel_work_sync(&data->work_bbd_on_packet); // should be cancelled before removing iio dev
destroy_workqueue(data->bbd_on_packet_wq);
cancel_work_sync(&data->work_bbd_mcu_ready);
destroy_workqueue(data->bbd_mcu_ready_wq);
//hoi
destroy_workqueue(data->batch_wq); /* HIFI */
mutex_destroy(&data->batch_events_lock);
remove_event_symlink(data);
remove_sysfs(data);
remove_input_dev(data);
#ifdef CONFIG_SENSORS_SSP_SENSORHUB
ssp_sensorhub_remove(data);
#endif
del_timer_sync(&data->debug_timer);
cancel_work_sync(&data->work_debug);
destroy_workqueue(data->debug_wq);
wake_lock_destroy(&data->ssp_wake_lock);
#ifdef CONFIG_SENSORS_SSP_SHTC1
mutex_destroy(&data->bulk_temp_read_lock);
mutex_destroy(&data->cp_temp_adc_lock);
#endif
mutex_destroy(&data->comm_mutex);
mutex_destroy(&data->pending_mutex);
mutex_destroy(&data->enable_mutex);
mutex_destroy(&data->ssp_enable_mutex);
pr_info("[SSP] %s done\n", __func__);
exit:
kfree(data);
}
#ifdef CONFIG_HAS_EARLYSUSPEND
static void ssp_early_suspend(struct early_suspend *handler)
{
struct ssp_data *data;
data = container_of(handler, struct ssp_data, early_suspend);
func_dbg();
disable_debug_timer(data);
#ifdef CONFIG_SENSORS_SSP_SENSORHUB
/* give notice to user that AP goes to sleep */
ssp_sensorhub_report_notice(data, MSG2SSP_AP_STATUS_SLEEP);
ssp_sleep_mode(data);
data->uLastAPState = MSG2SSP_AP_STATUS_SLEEP;
#else
if (atomic64_read(&data->aSensorEnable) > 0)
ssp_sleep_mode(data);
#endif
}
static void ssp_late_resume(struct early_suspend *handler)
{
struct ssp_data *data;
data = container_of(handler, struct ssp_data, early_suspend);
func_dbg();
enable_debug_timer(data);
#ifdef CONFIG_SENSORS_SSP_SENSORHUB
/* give notice to user that AP goes to sleep */
ssp_sensorhub_report_notice(data, MSG2SSP_AP_STATUS_WAKEUP);
ssp_resume_mode(data);
data->uLastAPState = MSG2SSP_AP_STATUS_WAKEUP;
#else
if (atomic64_read(&data->aSensorEnable) > 0)
ssp_resume_mode(data);
#endif
}
#else /* no early suspend */
static int ssp_suspend(struct device *dev)
{
struct spi_device *spi = to_spi_device(dev);
struct ssp_data *data = spi_get_drvdata(spi);
func_dbg();
if (SUCCESS != ssp_send_cmd(data, MSG2SSP_AP_STATUS_SUSPEND, 0))
pr_err("[SSP]: %s MSG2SSP_AP_STATUS_SUSPEND failed\n",
__func__);
data->uLastResumeState = MSG2SSP_AP_STATUS_SUSPEND;
disable_debug_timer(data);
data->bTimeSyncing = false;
pr_info("[SSP]: isHandlingIrq:%d\n", data->bHandlingIrq);
return 0;
}
static int ssp_resume(struct device *dev)
{
struct spi_device *spi = to_spi_device(dev);
struct ssp_data *data = spi_get_drvdata(spi);
func_dbg();
enable_debug_timer(data);
data->resumeTimestamp = get_kernel_timestamp();
data->bIsResumed = true;
if (SUCCESS != ssp_send_cmd(data, MSG2SSP_AP_STATUS_RESUME, 0))
pr_err("[SSP]: %s MSG2SSP_AP_STATUS_RESUME failed\n",
__func__);
data->uLastResumeState = MSG2SSP_AP_STATUS_RESUME;
return 0;
}
static const struct dev_pm_ops ssp_pm_ops = {
.suspend = ssp_suspend,
.resume = ssp_resume
};
#endif /* CONFIG_HAS_EARLYSUSPEND */
static const struct spi_device_id ssp_id[] = {
{"ssp-spi", 0},
{}
};
MODULE_DEVICE_TABLE(spi, ssp_id);
static struct spi_driver ssp_driver = {
.probe = ssp_probe,
.shutdown = ssp_shutdown,
.id_table = ssp_id,
.driver = {
#ifndef CONFIG_HAS_EARLYSUSPEND
.pm = &ssp_pm_ops,
#endif
.owner = THIS_MODULE,
.name = "ssp-spi",
},
};
struct spi_driver *pssp_driver = &ssp_driver;
module_spi_driver(ssp_driver);
MODULE_DESCRIPTION("ssp spi driver");
MODULE_AUTHOR("Samsung Electronics");
MODULE_LICENSE("GPL");
|