summaryrefslogtreecommitdiff
path: root/drivers/input/misc/lis3dh_interrupt.c
blob: ba8018344e738148245cc847ca241f265f3bb1c6 (plain)
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
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
 *
 * File Name          : lis3dh_acc.c
 * Authors            : MSH - Motion Mems BU - Application Team
 *		      : Carmine Iascone (carmine.iascone@st.com)
 *		      : Matteo Dameno (matteo.dameno@st.com)
 * Version            : V.1.0.5
 * Date               : 16/08/2010
 * Description        : LIS3DH accelerometer sensor API
 *
 *******************************************************************************
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * THE PRESENT SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, FOR THE SOLE
 * PURPOSE TO SUPPORT YOUR APPLICATION DEVELOPMENT.
 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
 *
 * THIS SOFTWARE IS SPECIFICALLY DESIGNED FOR EXCLUSIVE USE WITH ST PARTS.
 *
 ******************************************************************************
 Revision 1.0.0 05/11/09
 First Release
 Revision 1.0.3 22/01/2010
  Linux K&R Compliant Release;
 Revision 1.0.5 16/08/2010
 modified _get_acceleration_data function
 modified _update_odr function
 manages 2 interrupts

 ******************************************************************************/

#include	<linux/module.h>
#include	<linux/err.h>
#include	<linux/errno.h>
#include	<linux/delay.h>
#include	<linux/fs.h>
#include	<linux/i2c.h>

#include	<linux/input.h>
#include	<linux/input-polldev.h>
#include	<linux/miscdevice.h>
#include	<linux/uaccess.h>
#include        <linux/slab.h>

#include	<linux/workqueue.h>
#include	<linux/irq.h>
#include	<linux/gpio.h>
#include	<linux/interrupt.h>
#ifdef CONFIG_HAS_EARLYSUSPEND
#include  <linux/earlysuspend.h>
#endif

#include <linux/i2c/lis3dh.h>
#include <linux/of_device.h>
#include <linux/of_address.h>
#include <linux/of_gpio.h>

#include <linux/sched.h>
#include <linux/kthread.h>
#include <linux/completion.h>
#include <linux/err.h>

#include <soc/sprd/i2c-sprd.h>

#define	INTERRUPT_MANAGEMENT 1

#define	G_MAX		16000	/** Maximum polled-device-reported g value */

/*
#define	SHIFT_ADJ_2G		4
#define	SHIFT_ADJ_4G		3
#define	SHIFT_ADJ_8G		2
#define	SHIFT_ADJ_16G		1
*/
#define GSENSOR_INTERRUPT_MODE

#define SENSITIVITY_2G		1	/**	mg/LSB	*/
#define SENSITIVITY_4G		2	/**	mg/LSB	*/
#define SENSITIVITY_8G		4	/**	mg/LSB	*/
#define SENSITIVITY_16G		12	/**	mg/LSB	*/

#define	HIGH_RESOLUTION		0x08

#define	AXISDATA_REG		0x28
#define WHOAMI_LIS3DH_ACC	0x33	/*      Expctd content for WAI  */

/*	CONTROL REGISTERS	*/
#define WHO_AM_I		0x0F	/*      WhoAmI register         */
#define	TEMP_CFG_REG		0x1F	/*      temper sens control reg */
/* ctrl 1: ODR3 ODR2 ODR ODR0 LPen Zenable Yenable Zenable */
#define	CTRL_REG1		0x20	/*      control reg 1           */
#define	CTRL_REG2		0x21	/*      control reg 2           */
#define	CTRL_REG3		0x22	/*      control reg 3           */
#define	CTRL_REG4		0x23	/*      control reg 4           */
#define	CTRL_REG5		0x24	/*      control reg 5           */
#define	CTRL_REG6		0x25	/*      control reg 6           */

#define	FIFO_CTRL_REG		0x2E	/*      FiFo control reg        */

#define	INT_CFG1		0x30	/*      interrupt 1 config      */
#define	INT_SRC1		0x31	/*      interrupt 1 source      */
#define	INT_THS1		0x32	/*      interrupt 1 threshold   */
#define	INT_DUR1		0x33	/*      interrupt 1 duration    */

#define	INT_CFG2		0x34	/*      interrupt 2 config      */
#define	INT_SRC2		0x35	/*      interrupt 2 source      */
#define	INT_THS2		0x36	/*      interrupt 2 threshold   */
#define	INT_DUR2		0x37	/*      interrupt 2 duration    */

#define	TT_CFG			0x38	/*      tap config              */
#define	TT_SRC			0x39	/*      tap source              */
#define	TT_THS			0x3A	/*      tap threshold           */
#define	TT_LIM			0x3B	/*      tap time limit          */
#define	TT_TLAT			0x3C	/*      tap time latency        */
#define	TT_TW			0x3D	/*      tap time window         */
/*	end CONTROL REGISTRES	*/

#define ENABLE_HIGH_RESOLUTION	1

#define LIS3DH_ACC_PM_OFF		0x00
#define LIS3DH_ACC_ENABLE_ALL_AXES	0x07

#define PMODE_MASK			0x08
#define ODR_MASK			0XF0

#define ODR1		0x10	/* 1Hz output data rate */
#define ODR10		0x20	/* 10Hz output data rate */
#define ODR25		0x30	/* 25Hz output data rate */
#define ODR50		0x40	/* 50Hz output data rate */
#define ODR100		0x50	/* 100Hz output data rate */
#define ODR200		0x60	/* 200Hz output data rate */
#define ODR400		0x70	/* 400Hz output data rate */
#define ODR1250		0x90	/* 1250Hz output data rate  : test actually 650hz*/ 

#define	IA			0x40
#define	ZH			0x20
#define	ZL			0x10
#define	YH			0x08
#define	YL			0x04
#define	XH			0x02
#define	XL			0x01
/* */
/* CTRL REG BITS*/
#define	CTRL_REG3_I1_AOI1	0x40
#define	CTRL_REG6_I2_TAPEN	0x80
/*
CTRL_REG3 (22h)  的I1_DRDY1 位  enable
CTRL_REG5 (24h)   LIR_INT1   1 为 触发中断 后 中断保持,0  为 脉冲 
CTRL_REG6 (25h)    0  为中断 高有效, 1  为中断低有效
********must read data then will interrupter,******
*/
#define	CTRL_REG3_I1_DRDY1	0x10  //DRDY1 interrupt on INT1
#define	CTRL_REG5_LIR_INT1        0x08  //latch interrupt
//#define	CTRL_REG6_HLACTIVE	0x02  //low
#define	CTRL_REG6_HLACTIVE	0x00  //high


/* */

/* TAP_SOURCE_REG BIT */
#define	DTAP			0x20
#define	STAP			0x10
#define	SIGNTAP			0x08
#define	ZTAP			0x04
#define	YTAP			0x02
#define	XTAZ			0x01

#define	FUZZ			32
#define	FLAT			32
#define	I2C_RETRY_DELAY		5
#define	I2C_RETRIES		5
#define	I2C_AUTO_INCREMENT	0x80

/* RESUME STATE INDICES */
#define	RES_CTRL_REG1		0
#define	RES_CTRL_REG2		1
#define	RES_CTRL_REG3		2
#define	RES_CTRL_REG4		3
#define	RES_CTRL_REG5		4
#define	RES_CTRL_REG6		5

#define	RES_INT_CFG1		6
#define	RES_INT_THS1		7
#define	RES_INT_DUR1		8
#define	RES_INT_CFG2		9
#define	RES_INT_THS2		10
#define	RES_INT_DUR2		11

#define	RES_TT_CFG		12
#define	RES_TT_THS		13
#define	RES_TT_LIM		14
#define	RES_TT_TLAT		15
#define	RES_TT_TW		16

#define	RES_TEMP_CFG_REG	17
#define	RES_REFERENCE_REG	18
#define	RES_FIFO_CTRL_REG	19

#define	RESUME_ENTRIES		20
#define DEVICE_INFO             "ST, LIS3DH"
#define DEVICE_INFO_LEN         32
/* end RESUME STATE INDICES */

//#define GSENSOR_GINT1_GPI 238
#define GSENSOR_GINT2_GPI 1

#define LOG_TAG				        "[LIS3DH] "
#define LOG_FUN( )			        printk(KERN_INFO LOG_TAG"%s\n", __FUNCTION__)
#define LOG_INFO(fmt, args...)		printk(KERN_INFO LOG_TAG fmt, ##args)
#define LOG_ERR(fmt, args...)		printk(KERN_ERR  LOG_TAG"%s %d : "fmt, __FUNCTION__, __LINE__, ##args)

//#define LIS3DH_DBG
#define GSENSOR_INTERRUPT_MODE
#define USE_WAIT_QUEUE 1
#if USE_WAIT_QUEUE
static struct task_struct *thread = NULL;
static DECLARE_WAIT_QUEUE_HEAD(waiter);
static int gsensor_flag = 0;
#endif

struct {
	unsigned int cutoff_ms;
	unsigned int mask;
} lis3dh_acc_odr_table[] = {
	{
	1, ODR1250}, {
	2, ODR400}, {
	5, ODR200}, {
	10, ODR100}, {
	20, ODR50}, {
	40, ODR25}, {
	100, ODR10}, {
	1000, ODR1},};

struct lis3dh_acc_data {
	struct i2c_client *client;
	struct lis3dh_acc_platform_data *pdata;

	struct mutex lock;
	struct delayed_work input_work;

	struct input_dev *input_dev;

	int hw_initialized;
	/* hw_working=-1 means not tested yet */
	int hw_working;
	atomic_t enabled;
	int on_before_suspend;

	u8 sensitivity;

	u8 resume_state[RESUME_ENTRIES];

//	int irq1_gpio_number;
	int irq1;
	struct work_struct irq1_work;
	struct workqueue_struct *irq1_work_queue;
	int irq2;
	struct work_struct irq2_work;
	struct workqueue_struct *irq2_work_queue;
#ifdef CONFIG_HAS_EARLYSUSPEND
	struct early_suspend early_suspend;
#endif
#ifdef LIS3DH_DBG
struct {
		u8 diag_reg_addr_wr;
		u8 diag_reg_val_wr;
	} debug;
	u64 data_num;
#endif
};

/*
 * Because misc devices can not carry a pointer from driver register to
 * open, we keep this global.  This limits the driver to a single instance.
 */
struct lis3dh_acc_data *lis3dh_acc_misc_data;
struct i2c_client *lis3dh_i2c_client;

#ifndef GSENSOR_INTERRUPT_MODE 
static struct workqueue_struct *_gSensorWork_workqueue = NULL;
#endif

static int lis3dh_acc_get_acceleration_data(struct lis3dh_acc_data *acc,int *xyz);
static void lis3dh_acc_report_values(struct lis3dh_acc_data *acc, int *xyz);

static int lis3dh_acc_i2c_read(struct lis3dh_acc_data *acc, u8 * buf, int len)
{
	int err;
	int tries = 0;

	struct i2c_msg msgs[] = {
		{
		 .addr = acc->client->addr,
		 .flags = acc->client->flags & I2C_M_TEN,
		 .len = 1,
		 .buf = buf,},
		{
		 .addr = acc->client->addr,
		 .flags = (acc->client->flags & I2C_M_TEN) | I2C_M_RD,
		 .len = len,
		 .buf = buf,},
	};

	do {
		err = i2c_transfer(acc->client->adapter, msgs, 2);
		if (err != 2){
			LOG_ERR("************* exception read transfer error,tries=%d********\n",tries);
			msleep_interruptible(I2C_RETRY_DELAY);
		}
	} while ((err != 2) && (++tries < I2C_RETRIES));

	if (err != 2) {
		LOG_ERR(" exception read transfer error\n");
		err = -EIO;
	} else {
		err = 0;
	}

	return err;
}

static int lis3dh_acc_i2c_write(struct lis3dh_acc_data *acc, u8 * buf, int len)
{
	int err;
	int tries = 0;

	struct i2c_msg msgs[] = { {.addr = acc->client->addr,
				   .flags = acc->client->flags & I2C_M_TEN,
				   .len = len + 1,.buf = buf,},
	};
	do {
		err = i2c_transfer(acc->client->adapter, msgs, 1);
		if (err != 1)
			msleep_interruptible(I2C_RETRY_DELAY);
	} while ((err != 1) && (++tries < I2C_RETRIES));

	if (err != 1) {
		dev_err(&acc->client->dev, "write transfer error\n");
		err = -EIO;
	} else {
		err = 0;
	}

	return err;
}


static int lis3dh_acc_register_read(struct lis3dh_acc_data *acc, u8 * buf,
				    u8 reg_address)
{
	int err = -1;
	buf[0] = (reg_address);
	err = lis3dh_acc_i2c_read(acc, buf, 1);
	return err;
}

static void lis3dh_read_interrupt_reg(struct lis3dh_acc_data *acc)
{      
	  u8 value = 0;
	   int err;

	err = lis3dh_acc_register_read(acc, &value, CTRL_REG3);
	LOG_INFO("REG content: =======================>\n");
	if (err >= 0)
		LOG_INFO("REG content: [CTRL_REG3:0x%x]= 0x%02x\n", CTRL_REG3, value);

	err = lis3dh_acc_register_read(acc, &value, CTRL_REG5);
	if (err >= 0)
		LOG_INFO("REG content: [CTRL_REG5:0x%x]= 0x%02x\n", CTRL_REG5, value);
	err = lis3dh_acc_register_read(acc, &value, CTRL_REG6);
	if (err >= 0)
		LOG_INFO("REG content: [CTRL_REG6:0x%x]= 0x%02x\n", CTRL_REG6, value);

	LOG_INFO("REG content:< =======================\n");

}



/*  if  CTM want to turn off vdd & vddio , we recommend to call this function to retrive register setting   */

static int lis3dh_acc_hw_init(struct lis3dh_acc_data *acc)
{
	int err = -1;
	u8 buf[7];

	pr_debug("%s: hw init start\n", LIS3DH_ACC_DEV_NAME);
	LOG_INFO("sprd-gsensor: -- %s entry  :acc-> pdata ->gpio_int1=%d-- !\n",__func__,gpio_get_value(acc-> pdata ->gpio_int1));

	buf[0] = WHO_AM_I;
	err = lis3dh_acc_i2c_read(acc, buf, 1);
	if (err < 0)
		goto error_firstread;
	else
		acc->hw_working = 1;
	if (buf[0] != WHOAMI_LIS3DH_ACC) {
		err = -1;	/* choose the right coded error */
		goto error_unknown_device;
	}

	buf[0] = CTRL_REG1;
	buf[1] = acc->resume_state[RES_CTRL_REG1];
	err = lis3dh_acc_i2c_write(acc, buf, 1);
	if (err < 0)
		goto error1;

	buf[0] = TEMP_CFG_REG;
	buf[1] = acc->resume_state[RES_TEMP_CFG_REG];
	err = lis3dh_acc_i2c_write(acc, buf, 1);
	if (err < 0)
		goto error1;

	buf[0] = FIFO_CTRL_REG;
	buf[1] = acc->resume_state[RES_FIFO_CTRL_REG];
	err = lis3dh_acc_i2c_write(acc, buf, 1);
	if (err < 0)
		goto error1;

	buf[0] = (I2C_AUTO_INCREMENT | TT_THS);
	buf[1] = acc->resume_state[RES_TT_THS];
	buf[2] = acc->resume_state[RES_TT_LIM];
	buf[3] = acc->resume_state[RES_TT_TLAT];
	buf[4] = acc->resume_state[RES_TT_TW];
	err = lis3dh_acc_i2c_write(acc, buf, 4);
	if (err < 0)
		goto error1;
	buf[0] = TT_CFG;
	buf[1] = acc->resume_state[RES_TT_CFG];
	err = lis3dh_acc_i2c_write(acc, buf, 1);
	if (err < 0)
		goto error1;

	buf[0] = (I2C_AUTO_INCREMENT | INT_THS1);
	buf[1] = acc->resume_state[RES_INT_THS1];
	buf[2] = acc->resume_state[RES_INT_DUR1];
	err = lis3dh_acc_i2c_write(acc, buf, 2);
	if (err < 0)
		goto error1;
	buf[0] = INT_CFG1;
	buf[1] = acc->resume_state[RES_INT_CFG1];
	err = lis3dh_acc_i2c_write(acc, buf, 1);
	if (err < 0)
		goto error1;

	buf[0] = (I2C_AUTO_INCREMENT | INT_THS2);
	buf[1] = acc->resume_state[RES_INT_THS2];
	buf[2] = acc->resume_state[RES_INT_DUR2];
	err = lis3dh_acc_i2c_write(acc, buf, 2);
	if (err < 0)
		goto error1;
	buf[0] = INT_CFG2;
	buf[1] = acc->resume_state[RES_INT_CFG2];
	err = lis3dh_acc_i2c_write(acc, buf, 1);
	if (err < 0)
		goto error1;

	buf[0] = (I2C_AUTO_INCREMENT | CTRL_REG2);
	buf[1] = acc->resume_state[RES_CTRL_REG2];
	buf[2] = acc->resume_state[RES_CTRL_REG3];
	buf[3] = acc->resume_state[RES_CTRL_REG4];
	buf[4] = acc->resume_state[RES_CTRL_REG5];
	buf[5] = acc->resume_state[RES_CTRL_REG6];
	err = lis3dh_acc_i2c_write(acc, buf, 5);
	if (err < 0)
		goto error1;

	acc->hw_initialized = 1;

	LOG_INFO("sprd-gsensor: -- %s exit :acc-> pdata ->gpio_int1=%d-- !\n",__func__,gpio_get_value(acc-> pdata ->gpio_int1));

	pr_debug("%s: hw init done\n", LIS3DH_ACC_DEV_NAME);
	return 0;

error_firstread:
	acc->hw_working = 0;
	dev_warn(&acc->client->dev, "Error reading WHO_AM_I: is device "
		 "available/working?\n");
	goto error1;
error_unknown_device:
	dev_err(&acc->client->dev,
		"device unknown. Expected: 0x%x,"
		" Replies: 0x%x\n", WHOAMI_LIS3DH_ACC, buf[0]);
error1:
	acc->hw_initialized = 0;
	dev_err(&acc->client->dev, "hw init error 0x%x,0x%x: %d\n", buf[0],
		buf[1], err);
	return err;
}

static void lis3dh_acc_device_power_off(struct lis3dh_acc_data *acc)
{
	int err;
	u8 buf[2] = { CTRL_REG1, LIS3DH_ACC_PM_OFF };
	int xyz[3] = { 0 };

	err = lis3dh_acc_i2c_write(acc, buf, 1);
	if (err < 0)
		dev_err(&acc->client->dev, "soft power off failed: %d\n", err);
#ifdef GSENSOR_INTERRUPT_MODE
/*
read data:clear interrupter
*/
	err = lis3dh_acc_get_acceleration_data(acc, xyz);
#endif
	LOG_INFO("sprd-gsensor: -- %s  acc-> pdata ->gpio_int1=%d  acc->hw_initialized=%d-- !\n",__func__,gpio_get_value(acc-> pdata ->gpio_int1),acc->hw_initialized);	

}

static int lis3dh_acc_device_power_on(struct lis3dh_acc_data *acc)
{
	int err = -1;
	u8 buf[2];


	if (acc->pdata->power_on) {
		err = acc->pdata->power_on();
		if (err < 0) {
			dev_err(&acc->client->dev,
				"power_on failed: %d\n", err);
			return err;
		}
	}

	LOG_INFO("sprd-gsensor: -- %s  acc->irq1_gpio_number=%d acc->hw_initialized=%d-- !\n",__func__,gpio_get_value(acc-> pdata ->gpio_int1),acc->hw_initialized);	
	buf[0] = CTRL_REG1;
	buf[1] = acc->resume_state[RES_CTRL_REG1];
	err = lis3dh_acc_i2c_write(acc, buf, 1);
	if (err < 0)
		return err;
	LOG_INFO("sprd-gsensor: -- %s  acc->resume_state[RES_CTRL_REG1]=0x%02x-- !\n",__func__, acc->resume_state[RES_CTRL_REG1]);


	if (!acc->hw_initialized) {
		err = lis3dh_acc_hw_init(acc);
		lis3dh_read_interrupt_reg(acc);
		if (acc->hw_working == 1 && err < 0) {
			lis3dh_acc_device_power_off(acc);
			return err;
		}
	}
	return 0;
}

static irqreturn_t lis3dh_acc_isr1(int irq, void *dev)
{
#ifndef USE_WAIT_QUEUE
	struct lis3dh_acc_data *acc = dev;
#endif

#ifdef LIS3DH_DBG
	static int count_intr = 0;
	static s64 interrupt_last = 0;
	static s64 interrupt_cur = 0;
	static int poll_interval=0;
	ktime_t time_mono;

	time_mono = ktime_get();
	if (poll_interval !=lis3dh_acc_misc_data->pdata->poll_interval) {
		count_intr=1;
		poll_interval = lis3dh_acc_misc_data->pdata->poll_interval;
	      interrupt_last = ktime_to_ns(time_mono);
	}
	interrupt_cur = ktime_to_ns(time_mono);
	int interrupt_interval = interrupt_cur - interrupt_last;
	interrupt_last = interrupt_cur;

	if(interrupt_interval > (lis3dh_acc_misc_data->pdata->poll_interval*1000000) +(lis3dh_acc_misc_data->pdata->poll_interval*1000000) /4)
		LOG_INFO("***sprd-gsensor ISR  exception:count_intr=%d,interrupt_interval=%d,poll_interva=%d********\n",count_intr++,interrupt_interval,lis3dh_acc_misc_data->pdata->poll_interval);
       LOG_INFO("sprd-gsensor: -- %s entry : interrupt_interval=%d,poll_interval=%d,acc->irq1_gpio_number=%d-- >>>>>>>>>>>>>>>>>!\n",__func__,interrupt_interval,poll_interval,gpio_get_value(lis3dh_acc_misc_data->pdata->gpio_int1));	
#endif

	disable_irq_nosync(irq);
#if USE_WAIT_QUEUE
	gsensor_flag = 1;
	wake_up_interruptible(&waiter);
#else
	queue_work(acc->irq1_work_queue, &acc->irq1_work);
#endif
	pr_debug("%s: isr1 queued\n", LIS3DH_ACC_DEV_NAME);
	return IRQ_HANDLED;
}

static irqreturn_t lis3dh_acc_isr2(int irq, void *dev)
{
	struct lis3dh_acc_data *acc = dev;

//	disable_irq_nosync(irq);
	queue_work(acc->irq2_work_queue, &acc->irq2_work);

	pr_debug("%s: isr2 queued\n", LIS3DH_ACC_DEV_NAME);

	return IRQ_HANDLED;
}
//static int lis3dh_acc_get_acceleration_data(struct lis3dh_acc_data *acc,int *xyz);
static void lis3dh_acc_irq1_work_func(struct work_struct *work)
{
	int xyz[3] = { 0 };
	int err;
	u8 value;
	struct lis3dh_acc_data *acc =
	    container_of(work, struct lis3dh_acc_data, irq1_work);

	/* TODO  add interrupt service procedure.
	   ie:lis3dh_acc_get_int1_source(acc); */
	;
	/*  */
	LOG_INFO("%s: isr1 queued=========>>>>>>>>>>>>>>>>>\n", __func__);
       LOG_INFO("sprd-gsensor: -- %s entry :acc->irq1_gpio_number=%d-- !\n",__func__,gpio_get_value(acc->pdata->gpio_int1));
	   
	err = lis3dh_acc_register_read(acc, &value, INT_SRC1);

        if (err < 0) {
	        LOG_INFO("%s, error read register INT_SRC1\n", __func__);
        }
	LOG_INFO("%s: IRQ1 triggered  INT_SRC1=0x%02x\n",__func__,value);

	err = lis3dh_acc_get_acceleration_data(acc, xyz);
	if (err < 0)
		dev_err(&acc->client->dev, "get_acceleration_data failed\n");
	else
		lis3dh_acc_report_values(acc, xyz);


       LOG_INFO("sprd-gsensor: -- %s exit :acc->irq1_gpio_number=%d-- !\n",__func__,gpio_get_value(acc->pdata->gpio_int1));
	enable_irq(acc->irq1);
}


#if USE_WAIT_QUEUE

static void lis3dh_acc_update_data_func(void)
{
	int xyz[3] = { 0 };
	int err;
	struct lis3dh_acc_data *acc =lis3dh_acc_misc_data;

//       LOG_INFO("sprd-gsensor: -- %s entry :acc->irq1_gpio_number=%d-- !\n",__func__,gpio_get_value(acc->pdata->gpio_int1));
	err = lis3dh_acc_get_acceleration_data(acc, xyz);
 	if (err < 0)
		LOG_ERR("get_acceleration_data failed*******************************\n");
	else
		lis3dh_acc_report_values(acc, xyz);
#ifdef LIS3DH_DBG
       LOG_INFO("sprd-gsensor: -- %s exit :acc->irq1_gpio_number=%d-->>>>>>>>>>>>>>>>> !\n\n",__func__,gpio_get_value(acc->pdata->gpio_int1));
       LOG_INFO("\n");
   #endif
	enable_irq(acc->irq1);
}

static int gsensor_event_handler(void *unused)
{
#ifdef LIS3DH_DBG
	static int count_intr = 0;
	static s64 interrupt_last = 0;
	static s64 interrupt_read = 0;
	static s64 interrupt_cur = 0;
	static int poll_interval=0;
	ktime_t time_mono;
#endif
	struct sched_param param = { .sched_priority = 5};

	sched_setscheduler(current, SCHED_RR, &param);
        LOG_INFO("sprd-gsensor: -- %s entry :acc->irq1_gpio_number=%d-- !\n",__func__,gpio_get_value(lis3dh_acc_misc_data->pdata->gpio_int1));	

	do {
#ifdef LIS3DH_DBG
	       LOG_INFO("sprd-gsensor: -- %s 1 : gsensor_flag=%d,acc->irq1_gpio_number=%d-- !\n",__func__,gsensor_flag,gpio_get_value(lis3dh_acc_misc_data->pdata->gpio_int1));	
#endif

		set_current_state(TASK_INTERRUPTIBLE);
		wait_event_interruptible(waiter, (0 != gsensor_flag));
//
#ifdef LIS3DH_DBG
		time_mono = ktime_get();
		if (poll_interval !=lis3dh_acc_misc_data->pdata->poll_interval) {
			count_intr=1;
			poll_interval = lis3dh_acc_misc_data->pdata->poll_interval;
		      interrupt_last = ktime_to_ns(time_mono);
		}
		interrupt_cur = ktime_to_ns(time_mono);
		int interrupt_interval = interrupt_cur - interrupt_last;
		interrupt_last = interrupt_cur;

		if(interrupt_interval > (lis3dh_acc_misc_data->pdata->poll_interval*1000000) +(lis3dh_acc_misc_data->pdata->poll_interval*1000000) /4)
			LOG_INFO("***sprd-gsensor SHED  exception:count_intr=%d,interrupt_interval=%d,poll_interva=%d********\n",count_intr++,interrupt_interval,lis3dh_acc_misc_data->pdata->poll_interval);

	       LOG_INFO("sprd-gsensor: -- %s 2: interrupt_interval=%d,poll_interval=%d,gsensor_flag=%d,acc->irq1_gpio_number=%d-- !\n",__func__,interrupt_interval,poll_interval,gsensor_flag,gpio_get_value(lis3dh_acc_misc_data->pdata->gpio_int1));	
#endif
		gsensor_flag = 0;
		set_current_state(TASK_RUNNING);
		lis3dh_acc_update_data_func();
#ifdef LIS3DH_DBG
             time_mono = ktime_get();
             interrupt_read=ktime_to_ns(time_mono)-interrupt_cur;
		if(interrupt_interval > (lis3dh_acc_misc_data->pdata->poll_interval*1000000) +(lis3dh_acc_misc_data->pdata->poll_interval*1000000) /4)
			LOG_INFO("***sprd-gsensor SHED  exception:count_intr=%d,interrupt_interval=%d,poll_interva=%d, interrupt_read=%lld********\n",count_intr++,interrupt_interval,lis3dh_acc_misc_data->pdata->poll_interval,interrupt_read);

             LOG_INFO("sprd-gsensor: -- %s 3: interrupt_read=%lld,poll_interval=%d,gsensor_flag=%d,acc->irq1_gpio_number=%d-- !\n",__func__,interrupt_read,poll_interval,gsensor_flag,gpio_get_value(lis3dh_acc_misc_data->pdata->gpio_int1));		    
#endif
	} while (!kthread_should_stop());

	return 0;
}
#endif


static void lis3dh_acc_irq2_work_func(struct work_struct *work)
{

	/*struct lis3dh_acc_data *acc =
	    container_of(work, struct lis3dh_acc_data, irq2_work);
	*/
	/* TODO  add interrupt service procedure.
	   ie:lis3dh_acc_get_tap_source(acc); */
	;
	/*  */

	LOG_INFO("%s: IRQ2 triggered\n", LIS3DH_ACC_DEV_NAME);
}

int lis3dh_acc_update_g_range(struct lis3dh_acc_data *acc, u8 new_g_range)
{
	int err;

	u8 sensitivity;
	u8 buf[2];
	u8 updated_val;
	u8 init_val;
	u8 new_val;
	u8 mask = LIS3DH_ACC_FS_MASK | HIGH_RESOLUTION;

	pr_debug("%s\n", __func__);

	switch (new_g_range) {
	case LIS3DH_ACC_G_2G:

		sensitivity = SENSITIVITY_2G;
		break;
	case LIS3DH_ACC_G_4G:

		sensitivity = SENSITIVITY_4G;
		break;
	case LIS3DH_ACC_G_8G:

		sensitivity = SENSITIVITY_8G;
		break;
	case LIS3DH_ACC_G_16G:

		sensitivity = SENSITIVITY_16G;
		break;
	default:
		dev_err(&acc->client->dev, "invalid g range requested: %u\n",
			new_g_range);
		return -EINVAL;
	}

	if (atomic_read(&acc->enabled)) {
		/* Set configuration register 4, which contains g range setting
		 *  NOTE: this is a straight overwrite because this driver does
		 *  not use any of the other configuration bits in this
		 *  register.  Should this become untrue, we will have to read
		 *  out the value and only change the relevant bits --XX----
		 *  (marked by X) */
		buf[0] = CTRL_REG4;
		err = lis3dh_acc_i2c_read(acc, buf, 1);
		if (err < 0)
			goto error;
		init_val = buf[0];
		acc->resume_state[RES_CTRL_REG4] = init_val;
		new_val = new_g_range | HIGH_RESOLUTION;
		updated_val = ((mask & new_val) | ((~mask) & init_val));
		buf[1] = updated_val;
		buf[0] = CTRL_REG4;
		err = lis3dh_acc_i2c_write(acc, buf, 1);
		if (err < 0)
			goto error;
		acc->resume_state[RES_CTRL_REG4] = updated_val;
		acc->sensitivity = sensitivity;

		pr_debug("%s sensitivity %d g-range %d\n", __func__, sensitivity,new_g_range);
	}

	return 0;
error:
	dev_err(&acc->client->dev, "update g range failed 0x%x,0x%x: %d\n",
		buf[0], buf[1], err);

	return err;
}

int lis3dh_acc_update_odr(struct lis3dh_acc_data *acc, int poll_interval_ms)
{
	int err = -1;
	int i;
	u8 config[2];

	/* Convert the poll interval into an output data rate configuration
	 *  that is as low as possible.  The ordering of these checks must be
	 *  maintained due to the cascading cut off values - poll intervals are
	 *  checked from shortest to longest.  At each check, if the next lower
	 *  ODR cannot support the current poll interval, we stop searching */
	for (i = ARRAY_SIZE(lis3dh_acc_odr_table) - 1; i >= 0; i--) {
		if (lis3dh_acc_odr_table[i].cutoff_ms <= poll_interval_ms)
			break;
	}
	config[1] = lis3dh_acc_odr_table[i].mask;

	LOG_INFO("%s :ODR  poll_interval_ms=%d, config[1]=0x%02x,cutoff_ms %d",__func__,poll_interval_ms,config[1],lis3dh_acc_odr_table[i].cutoff_ms );

	config[1] |= LIS3DH_ACC_ENABLE_ALL_AXES;

	/* If device is currently enabled, we need to write new
	 *  configuration out to it */
	if (atomic_read(&acc->enabled)) {
		config[0] = CTRL_REG1;
		err = lis3dh_acc_i2c_write(acc, config, 1);
		if (err < 0)
			goto error;
		acc->resume_state[RES_CTRL_REG1] = config[1];
	}

	return 0;

error:
	dev_err(&acc->client->dev, "update odr failed 0x%x,0x%x: %d\n",
		config[0], config[1], err);

	return err;
}

/* */

static int lis3dh_acc_register_write(struct lis3dh_acc_data *acc, u8 * buf,
				     u8 reg_address, u8 new_value)
{
	int err = -1;

	if (atomic_read(&acc->enabled)) {
		/* Sets configuration register at reg_address
		 *  NOTE: this is a straight overwrite  */
		buf[0] = reg_address;
		buf[1] = new_value;
		err = lis3dh_acc_i2c_write(acc, buf, 1);
		if (err < 0)
			return err;
	}
	return err;
}

static int lis3dh_acc_register_update(struct lis3dh_acc_data *acc, u8 * buf,
				      u8 reg_address, u8 mask,
				      u8 new_bit_values)
{
	int err = -1;
	u8 init_val;
	u8 updated_val;
	err = lis3dh_acc_register_read(acc, buf, reg_address);
	if (!(err < 0)) {
		init_val = buf[1];
		updated_val = ((mask & new_bit_values) | ((~mask) & init_val));
		err = lis3dh_acc_register_write(acc, buf, reg_address,
						updated_val);
	}
	return err;
}

/* */

static int lis3dh_acc_get_acceleration_data(struct lis3dh_acc_data *acc,
					    int *xyz)
{
	int err = -1;
	/* Data bytes from hardware xL, xH, yL, yH, zL, zH */
	u8 acc_data[6];
	/* x,y,z hardware data */
	s16 hw_d[3] = { 0 };

	acc_data[0] = (I2C_AUTO_INCREMENT | AXISDATA_REG);
	err = lis3dh_acc_i2c_read(acc, acc_data, 6);

	if (err < 0) {
		LOG_ERR("%s  exception ssssI2C read error %d\n", LIS3DH_ACC_I2C_NAME,
		       err);
		return err;
	}

	hw_d[0] = (((s16) ((acc_data[1] << 8) | acc_data[0])) >> 4);
	hw_d[1] = (((s16) ((acc_data[3] << 8) | acc_data[2])) >> 4);
	hw_d[2] = (((s16) ((acc_data[5] << 8) | acc_data[4])) >> 4);

	hw_d[0] = hw_d[0] * acc->sensitivity;
	hw_d[1] = hw_d[1] * acc->sensitivity;
	hw_d[2] = hw_d[2] * acc->sensitivity;

	xyz[0] = ((acc->pdata->negate_x) ? (-hw_d[acc->pdata->axis_map_x])
		  : (hw_d[acc->pdata->axis_map_x]));
	xyz[1] = ((acc->pdata->negate_y) ? (-hw_d[acc->pdata->axis_map_y])
		  : (hw_d[acc->pdata->axis_map_y]));
	xyz[2] = ((acc->pdata->negate_z) ? (-hw_d[acc->pdata->axis_map_z])
		  : (hw_d[acc->pdata->axis_map_z]));
#ifdef LIS3DH_DBG
	LOG_INFO("%s read x=%d, y=%d, z=%d\n",
	       LIS3DH_ACC_DEV_NAME, xyz[0], xyz[1], xyz[2]);
#endif

	return err;
}

static void lis3dh_acc_report_values(struct lis3dh_acc_data *acc, int *xyz)
{
	input_report_abs(acc->input_dev, ABS_X, xyz[0]);
	input_report_abs(acc->input_dev, ABS_Y, xyz[1]);
	input_report_abs(acc->input_dev, ABS_Z, xyz[2]);
	input_sync(acc->input_dev);
	#ifdef LIS3DH_DBG
		acc->data_num++;
	#endif
}

static int lis3dh_acc_enable(struct lis3dh_acc_data *acc)
{
	int err;

	pr_debug("%s: pr_debug PRINT  \n", __func__);

	LOG_INFO("sprd-gsensor: -- %s entry :acc->irq1_gpio_number=%d-- !\n",__func__,gpio_get_value(acc->pdata->gpio_int1));	

	if (!atomic_cmpxchg(&acc->enabled, 0, 1)) {
		err = lis3dh_acc_device_power_on(acc);
		LOG_INFO("sprd-gsensor: -- %s err=%d-- !\n",__func__,err);
		if (err < 0) {
			atomic_set(&acc->enabled, 0);
			return err;
		}

		LOG_INFO("sprd-gsensor: -- %s  acc->hw_initialized=%d  acc->irq1=%d-- !\n",__func__,acc->hw_initialized,acc->irq1);
		if (acc->hw_initialized) {
			if (acc->irq1 != 0){
				LOG_INFO("sprd-gsensor: -- %s  after init : acc->irq1_gpio_number=%d-- !\n",__func__,gpio_get_value(acc->pdata->gpio_int1));	
				enable_irq(acc->irq1);
			}
			if (acc->irq2 != 0)
				enable_irq(acc->irq2);
			LOG_INFO("%s: power on: irq enabled\n",
			       LIS3DH_ACC_DEV_NAME);
		}

		#ifdef LIS3DH_DBG
			acc->data_num = 0;
		#endif

       /* 
		schedule_delayed_work(&acc->input_work,
				      msecs_to_jiffies(acc->pdata->
						       poll_interval));
	*/
#ifndef GSENSOR_INTERRUPT_MODE
        queue_delayed_work(_gSensorWork_workqueue, &acc->input_work, msecs_to_jiffies(acc->pdata->poll_interval));
#endif
        }
	 LOG_INFO("sprd-gsensor: -- %s exit :acc->irq1_gpio_number=%d-- !\n",__func__,gpio_get_value(acc->pdata->gpio_int1));
        LOG_INFO("sprd-gsensor: -- %s -- success!\n",__func__);
	return 0;
}

static int lis3dh_acc_disable(struct lis3dh_acc_data *acc)
{
	LOG_INFO("sprd-gsensor: -- %s --acc->hw_initialized=%d\n",__func__,acc->hw_initialized);
	if (atomic_cmpxchg(&acc->enabled, 1, 0)) {
		cancel_delayed_work_sync(&acc->input_work);

		if (acc->pdata->power_off) {
			if (acc->irq1 != 0)
				disable_irq_nosync(acc->irq1);
			if (acc->irq2 != 0)
				disable_irq_nosync(acc->irq2);
			acc->pdata->power_off();
			acc->hw_initialized = 0;
		}
		if (acc->hw_initialized) {
			if (acc->irq1 != 0)
				disable_irq_nosync(acc->irq1);
			if (acc->irq2 != 0)
				disable_irq_nosync(acc->irq2);
	//only init once during probe, the sensor is ALWAYS power supply
	//		acc->hw_initialized = 0;
		}
		lis3dh_acc_device_power_off(acc);
	}
#ifdef LIS3DH_DBG
	LOG_INFO("******sprd-gsensor: -- %s --acc->data_num =%lld ,acc->pdata->poll_interval =%d****\n",__func__,acc->data_num,acc->pdata->poll_interval);
	acc->data_num = 0;
#endif
	return 0;
}

static int lis3dh_acc_misc_open(struct inode *inode, struct file *file)
{
	int err;
	err = nonseekable_open(inode, file);
	if (err < 0)
		return err;

	file->private_data = lis3dh_acc_misc_data;

	return 0;
}

static long lis3dh_acc_misc_ioctl(struct file *file, unsigned int cmd,
				unsigned long arg)
{
	void __user *argp = (void __user *)arg;
	u8 buf[4];
	u8 mask;
	u8 reg_address;
	u8 bit_values;
	int err;
	int interval;
	int xyz[3] = { 0 };
	struct lis3dh_acc_data *acc = file->private_data;


       LOG_INFO("%s :ioctl cmd %d\n",__func__, _IOC_NR(cmd));
	switch (cmd) {
	case LIS3DH_ACC_IOCTL_GET_DELAY:
		interval = acc->pdata->poll_interval;
		if (copy_to_user(argp, &interval, sizeof(interval)))
			return -EFAULT;
		break;

	case LIS3DH_ACC_IOCTL_SET_DELAY:
		if (copy_from_user(&interval, argp, sizeof(interval)))
			return -EFAULT;
		if (interval < 0 || interval > 1000)
			return -EINVAL;
		interval = interval/2;
		acc->pdata->poll_interval = max(interval,acc->pdata->min_interval); // max the frequecy of g sensor
             LOG_INFO(" %s,acc->pdata->poll_interval =%d,interval=%d,acc->pdata->min_interval=%d\n", __func__,acc->pdata->poll_interval,interval,acc->pdata->min_interval );
		err = lis3dh_acc_update_odr(acc, acc->pdata->poll_interval);
		/* TODO: if update fails poll is still set */
		if (err < 0)
			return err;
		break;

	case LIS3DH_ACC_IOCTL_SET_ENABLE:
		if (copy_from_user(&interval, argp, sizeof(interval)))
			return -EFAULT;
		if (interval > 1)
			return -EINVAL;
		if (interval)
			err = lis3dh_acc_enable(acc);
		else
			err = lis3dh_acc_disable(acc);
		return err;
		break;

	case LIS3DH_ACC_IOCTL_GET_ENABLE:
		interval = atomic_read(&acc->enabled);
		if (copy_to_user(argp, &interval, sizeof(interval)))
			return -EINVAL;
		break;

	case LIS3DH_ACC_IOCTL_SET_G_RANGE:
		if (copy_from_user(buf, argp, 1))
			return -EFAULT;
		bit_values = buf[0];
		err = lis3dh_acc_update_g_range(acc, bit_values);
		if (err < 0)
			return err;
		break;

#ifdef INTERRUPT_MANAGEMENT
	case LIS3DH_ACC_IOCTL_SET_CTRL_REG3:
		if (copy_from_user(buf, argp, 2))
			return -EFAULT;
		reg_address = CTRL_REG3;
		mask = buf[1];
		bit_values = buf[0];
		err = lis3dh_acc_register_update(acc, (u8 *) arg, reg_address,
						 mask, bit_values);
		if (err < 0)
			return err;
		acc->resume_state[RES_CTRL_REG3] = ((mask & bit_values) |
						    (~mask & acc->
						     resume_state
						     [RES_CTRL_REG3]));
		break;

	case LIS3DH_ACC_IOCTL_SET_CTRL_REG6:
		if (copy_from_user(buf, argp, 2))
			return -EFAULT;
		reg_address = CTRL_REG6;
		mask = buf[1];
		bit_values = buf[0];
		err = lis3dh_acc_register_update(acc, (u8 *) arg, reg_address,
						 mask, bit_values);
		if (err < 0)
			return err;
		acc->resume_state[RES_CTRL_REG6] = ((mask & bit_values) |
						    (~mask & acc->
						     resume_state
						     [RES_CTRL_REG6]));
		break;

	case LIS3DH_ACC_IOCTL_SET_DURATION1:
		if (copy_from_user(buf, argp, 1))
			return -EFAULT;
		reg_address = INT_DUR1;
		mask = 0x7F;
		bit_values = buf[0];
		err = lis3dh_acc_register_update(acc, (u8 *) arg, reg_address,
						 mask, bit_values);
		if (err < 0)
			return err;
		acc->resume_state[RES_INT_DUR1] = ((mask & bit_values) |
						   (~mask & acc->
						    resume_state
						    [RES_INT_DUR1]));
		break;

	case LIS3DH_ACC_IOCTL_SET_THRESHOLD1:
		if (copy_from_user(buf, argp, 1))
			return -EFAULT;
		reg_address = INT_THS1;
		mask = 0x7F;
		bit_values = buf[0];
		err = lis3dh_acc_register_update(acc, (u8 *) arg, reg_address,
						 mask, bit_values);
		if (err < 0)
			return err;
		acc->resume_state[RES_INT_THS1] = ((mask & bit_values) |
						   (~mask & acc->
						    resume_state
						    [RES_INT_THS1]));
		break;

	case LIS3DH_ACC_IOCTL_SET_CONFIG1:
		if (copy_from_user(buf, argp, 2))
			return -EFAULT;
		reg_address = INT_CFG1;
		mask = buf[1];
		bit_values = buf[0];
		err = lis3dh_acc_register_update(acc, (u8 *) arg, reg_address,
						 mask, bit_values);
		if (err < 0)
			return err;
		acc->resume_state[RES_INT_CFG1] = ((mask & bit_values) |
						   (~mask & acc->
						    resume_state
						    [RES_INT_CFG1]));
		break;

	case LIS3DH_ACC_IOCTL_GET_SOURCE1:
		err = lis3dh_acc_register_read(acc, buf, INT_SRC1);
		if (err < 0)
			return err;

		pr_debug("INT1_SRC content: %d , 0x%x\n", buf[0], buf[0]);

		if (copy_to_user(argp, buf, 1))
			return -EINVAL;
		break;

	case LIS3DH_ACC_IOCTL_SET_DURATION2:
		if (copy_from_user(buf, argp, 1))
			return -EFAULT;
		reg_address = INT_DUR2;
		mask = 0x7F;
		bit_values = buf[0];
		err = lis3dh_acc_register_update(acc, (u8 *) arg, reg_address,
						 mask, bit_values);
		if (err < 0)
			return err;
		acc->resume_state[RES_INT_DUR2] = ((mask & bit_values) |
						   (~mask & acc->
						    resume_state
						    [RES_INT_DUR2]));
		break;

	case LIS3DH_ACC_IOCTL_SET_THRESHOLD2:
		if (copy_from_user(buf, argp, 1))
			return -EFAULT;
		reg_address = INT_THS2;
		mask = 0x7F;
		bit_values = buf[0];
		err = lis3dh_acc_register_update(acc, (u8 *) arg, reg_address,
						 mask, bit_values);
		if (err < 0)
			return err;
		acc->resume_state[RES_INT_THS2] = ((mask & bit_values) |
						   (~mask & acc->
						    resume_state
						    [RES_INT_THS2]));
		break;

	case LIS3DH_ACC_IOCTL_SET_CONFIG2:
		if (copy_from_user(buf, argp, 2))
			return -EFAULT;
		reg_address = INT_CFG2;
		mask = buf[1];
		bit_values = buf[0];
		err = lis3dh_acc_register_update(acc, (u8 *) arg, reg_address,
						 mask, bit_values);
		if (err < 0)
			return err;
		acc->resume_state[RES_INT_CFG2] = ((mask & bit_values) |
						   (~mask & acc->
						    resume_state
						    [RES_INT_CFG2]));
		break;

	case LIS3DH_ACC_IOCTL_GET_SOURCE2:
		err = lis3dh_acc_register_read(acc, buf, INT_SRC2);
		if (err < 0)
			return err;

		pr_debug("INT2_SRC content: %d , 0x%x\n", buf[0], buf[0]);

		if (copy_to_user(argp, buf, 1))
			return -EINVAL;
		break;

	case LIS3DH_ACC_IOCTL_GET_TAP_SOURCE:
		err = lis3dh_acc_register_read(acc, buf, TT_SRC);
		if (err < 0)
			return err;
		pr_debug("TT_SRC content: %d , 0x%x\n", buf[0], buf[0]);

		if (copy_to_user(argp, buf, 1)) {
			pr_err("%s: %s error in copy_to_user \n",
			       LIS3DH_ACC_DEV_NAME, __func__);
			return -EINVAL;
		}
		break;
	case LIS3DH_ACC_IOCTL_GET_COOR_XYZ:
		err = lis3dh_acc_get_acceleration_data(acc, xyz);
		if (err < 0)
			return err;

		if (copy_to_user(argp, xyz, sizeof(xyz))) {
			pr_err(" %s %d error in copy_to_user \n",
			       __func__, __LINE__);
			return -EINVAL;
		}
		break;
	case LIS3DH_ACC_IOCTL_SET_TAP_CFG:
		if (copy_from_user(buf, argp, 2))
			return -EFAULT;
		reg_address = TT_CFG;
		mask = buf[1];
		bit_values = buf[0];
		err = lis3dh_acc_register_update(acc, (u8 *) arg, reg_address,
						 mask, bit_values);
		if (err < 0)
			return err;
		acc->resume_state[RES_TT_CFG] = ((mask & bit_values) |
						 (~mask & acc->
						  resume_state[RES_TT_CFG]));
		break;

	case LIS3DH_ACC_IOCTL_SET_TAP_TLIM:
		if (copy_from_user(buf, argp, 2))
			return -EFAULT;
		reg_address = TT_LIM;
		mask = buf[1];
		bit_values = buf[0];
		err = lis3dh_acc_register_update(acc, (u8 *) arg, reg_address,
						 mask, bit_values);
		if (err < 0)
			return err;
		acc->resume_state[RES_TT_LIM] = ((mask & bit_values) |
						 (~mask & acc->
						  resume_state[RES_TT_LIM]));
		break;

	case LIS3DH_ACC_IOCTL_SET_TAP_THS:
		if (copy_from_user(buf, argp, 2))
			return -EFAULT;
		reg_address = TT_THS;
		mask = buf[1];
		bit_values = buf[0];
		err = lis3dh_acc_register_update(acc, (u8 *) arg, reg_address,
						 mask, bit_values);
		if (err < 0)
			return err;
		acc->resume_state[RES_TT_THS] = ((mask & bit_values) |
						 (~mask & acc->
						  resume_state[RES_TT_THS]));
		break;

	case LIS3DH_ACC_IOCTL_SET_TAP_TLAT:
		if (copy_from_user(buf, argp, 2))
			return -EFAULT;
		reg_address = TT_TLAT;
		mask = buf[1];
		bit_values = buf[0];
		err = lis3dh_acc_register_update(acc, (u8 *) arg, reg_address,
						 mask, bit_values);
		if (err < 0)
			return err;
		acc->resume_state[RES_TT_TLAT] = ((mask & bit_values) |
						  (~mask & acc->
						   resume_state[RES_TT_TLAT]));
		break;

	case LIS3DH_ACC_IOCTL_SET_TAP_TW:
		if (copy_from_user(buf, argp, 2))
			return -EFAULT;
		reg_address = TT_TW;
		mask = buf[1];
		bit_values = buf[0];
		err = lis3dh_acc_register_update(acc, (u8 *) arg, reg_address,
						 mask, bit_values);
		if (err < 0)
			return err;
		acc->resume_state[RES_TT_TW] = ((mask & bit_values) |
						(~mask & acc->
						 resume_state[RES_TT_TW]));
		break;

#endif /* INTERRUPT_MANAGEMENT */
	case LIS3DH_ACC_IOCTL_GET_CHIP_ID:
	    {
	        u8 devid = 0;
	        u8 devinfo[DEVICE_INFO_LEN] = {0};
	        err = lis3dh_acc_register_read(acc, &devid, WHO_AM_I);
	        if (err < 0) {
	            LOG_INFO("%s, error read register WHO_AM_I\n", __func__);
	            return -EAGAIN;
	        }
	        sprintf(devinfo, "%s, %#x", DEVICE_INFO, devid);

	        if (copy_to_user(argp, devinfo, sizeof(devinfo))) {
	            printk("%s error in copy_to_user(IOCTL_GET_CHIP_ID)\n", __func__);
	            return -EINVAL;
	        }
	    }
	   break;
	default:
		return -EINVAL;
	}

	return 0;
}

static const struct file_operations lis3dh_acc_misc_fops = {
	.owner = THIS_MODULE,
	.open = lis3dh_acc_misc_open,
	.unlocked_ioctl = lis3dh_acc_misc_ioctl,
};

static struct miscdevice lis3dh_acc_misc_device = {
	.minor = MISC_DYNAMIC_MINOR,
	.name = LIS3DH_ACC_DEV_NAME,
	.fops = &lis3dh_acc_misc_fops,
};


#ifndef GSENSOR_INTERRUPT_MODE 

static void lis3dh_acc_input_work_func(struct work_struct *work)
{
	struct lis3dh_acc_data *acc;

	int xyz[3] = { 0 };
	int err;
	static int count_intr = 0;
	static s64 interrupt_last = 0;
	static s64 interrupt_cur = 0;
	ktime_t time_mono;
	time_mono = ktime_get();
	interrupt_cur = ktime_to_ns(time_mono);
	int interrupt_interval = interrupt_cur - interrupt_last;
	interrupt_last = interrupt_cur;

//	LOG_INFO("ENTRY----->%s\n",__func__);
	acc = container_of((struct delayed_work *)work,
			   struct lis3dh_acc_data, input_work);

	mutex_lock(&acc->lock);
	err = lis3dh_acc_get_acceleration_data(acc, xyz);
	if (err < 0)
		dev_err(&acc->client->dev, "get_acceleration_data failed\n");
	else
		lis3dh_acc_report_values(acc, xyz);
//	LOG_INFO(KERN_ERR "lihai: sprd-gsensor count_intr=%8d  interrupt_interval=%8d,  poll_interval=%d, err=%d \n", count_intr++, interrupt_interval, acc->pdata->poll_interval, err);
#if 0
        schedule_delayed_work(&acc->input_work,
			      msecs_to_jiffies(acc->pdata->poll_interval));
#else
        queue_delayed_work(_gSensorWork_workqueue, &acc->input_work, msecs_to_jiffies(acc->pdata->poll_interval));
#endif        
        mutex_unlock(&acc->lock);

//	LOG_INFO("EXIT----->%s\n\n",__func__);
}
#endif
	
#ifdef LIS3DH_OPEN_ENABLE
int lis3dh_acc_input_open(struct input_dev *input)
{
	struct lis3dh_acc_data *acc = input_get_drvdata(input);

	return lis3dh_acc_enable(acc);
}

void lis3dh_acc_input_close(struct input_dev *dev)
{
	struct lis3dh_acc_data *acc = input_get_drvdata(dev);

	lis3dh_acc_disable(acc);
}
#endif

static int lis3dh_acc_validate_pdata(struct lis3dh_acc_data *acc)
{
	acc->pdata->poll_interval = max(acc->pdata->poll_interval,
					acc->pdata->min_interval);

	if (acc->pdata->axis_map_x > 2 || acc->pdata->axis_map_y > 2
	    || acc->pdata->axis_map_z > 2) {
		dev_err(&acc->client->dev, "invalid axis_map value "
			"x:%u y:%u z%u\n", acc->pdata->axis_map_x,
			acc->pdata->axis_map_y, acc->pdata->axis_map_z);
		return -EINVAL;
	}

	/* Only allow 0 and 1 for negation boolean flag */
	if (acc->pdata->negate_x > 1 || acc->pdata->negate_y > 1
	    || acc->pdata->negate_z > 1) {
		dev_err(&acc->client->dev, "invalid negate value "
			"x:%u y:%u z:%u\n", acc->pdata->negate_x,
			acc->pdata->negate_y, acc->pdata->negate_z);
		return -EINVAL;
	}

	/* Enforce minimum polling interval */
	if (acc->pdata->poll_interval < acc->pdata->min_interval) {
		dev_err(&acc->client->dev, "minimum poll interval violated\n");
		return -EINVAL;
	}

	return 0;
}

static int lis3dh_acc_input_init(struct lis3dh_acc_data *acc)
{
	int err;

#ifndef GSENSOR_INTERRUPT_MODE 
	/* Polling rx data when the interrupt is not used.*/
	if (1 /*acc->irq1 == 0 && acc->irq1 == 0 */ ) {
		INIT_DELAYED_WORK(&acc->input_work, lis3dh_acc_input_work_func);
	    _gSensorWork_workqueue = create_singlethread_workqueue("acc_singlethread");
            if (!_gSensorWork_workqueue) {
                    err = -ESRCH;
                    printk(KERN_ERR "acc: create_singlethread_workqueue\n");
                   return err;
            }
        }
#endif

	acc->input_dev = input_allocate_device();
	if (!acc->input_dev) {
		err = -ENOMEM;
		dev_err(&acc->client->dev, "input device allocate failed\n");
		goto err0;
	}
#ifdef LIS3DH_ACC_OPEN_ENABLE
	acc->input_dev->open = lis3dh_acc_input_open;
	acc->input_dev->close = lis3dh_acc_input_close;
#endif

	input_set_drvdata(acc->input_dev, acc);

	set_bit(EV_ABS, acc->input_dev->evbit);
	/*      next is used for interruptA sources data if the case */
	set_bit(ABS_MISC, acc->input_dev->absbit);
	/*      next is used for interruptB sources data if the case */
	set_bit(ABS_WHEEL, acc->input_dev->absbit);

	input_set_abs_params(acc->input_dev, ABS_X, -G_MAX, G_MAX, 0, 0);
	input_set_abs_params(acc->input_dev, ABS_Y, -G_MAX, G_MAX, 0, 0);
	input_set_abs_params(acc->input_dev, ABS_Z, -G_MAX, G_MAX, 0, 0);
	/*      next is used for interruptA sources data if the case */
	input_set_abs_params(acc->input_dev, ABS_MISC, INT_MIN, INT_MAX, 0, 0);
	/*      next is used for interruptB sources data if the case */
	input_set_abs_params(acc->input_dev, ABS_WHEEL, INT_MIN, INT_MAX, 0, 0);

	acc->input_dev->name = "accelerometer";

	err = input_register_device(acc->input_dev);
	if (err) {
		dev_err(&acc->client->dev,
			"unable to register input polled device %s\n",
			acc->input_dev->name);
		goto err1;
	}

	return 0;

err1:
	input_free_device(acc->input_dev);
err0:
	return err;
}

static void lis3dh_acc_input_cleanup(struct lis3dh_acc_data *acc)
{
	input_unregister_device(acc->input_dev);
	input_free_device(acc->input_dev);
}

#ifdef CONFIG_HAS_EARLYSUSPEND
static void lis3dh_early_suspend(struct early_suspend *es);
static void lis3dh_early_resume(struct early_suspend *es);
#endif

#ifdef CONFIG_OF
static struct lis3dh_acc_platform_data *lis3dh_acc_parse_dt(struct device *dev)
{
	struct lis3dh_acc_platform_data *pdata;
	struct device_node *np = dev->of_node;
	int ret;
	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
	if (!pdata) {
		dev_err(dev, "Could not allocate struct lis3dh_acc_platform_data");
		return NULL;
	}

	pdata->gpio_int1 = of_get_gpio(np, 0);
	LOG_INFO(" %s:get gpio_int1  %d\n",__func__,pdata->gpio_int1);
	if(pdata->gpio_int1 < 0){
		dev_err(dev, "fail to get irq_gpio_number\n");
		LOG_INFO(" get irq1_gpio_number fail\n");
		goto fail;
	}
	ret = of_property_read_u32(np, "poll_interval", &pdata->poll_interval);
	LOG_INFO("%s: get pdata->poll_interval %d\n",__func__,pdata->poll_interval);	
	if(ret){
		dev_err(dev, "fail to get poll_interval\n");
		goto fail;
	}
	ret = of_property_read_u32(np, "min_interval", &pdata->min_interval);
	if(ret){
		dev_err(dev, "fail to get min_interval\n");
		goto fail;
	}
	ret = of_property_read_u32(np, "g_range", &pdata->g_range);
	if(ret){
		dev_err(dev, "fail to get g_range\n");
		goto fail;
	}
	ret = of_property_read_u32(np, "axis_map_x", &pdata->axis_map_x);
	if(ret){
		dev_err(dev, "fail to get axis_map_x\n");
		goto fail;
	}
	ret = of_property_read_u32(np, "axis_map_y", &pdata->axis_map_y);
	if(ret){
		dev_err(dev, "fail to get axis_map_y\n");
		goto fail;
	}
	ret = of_property_read_u32(np, "axis_map_z", &pdata->axis_map_z);
	if(ret){
		dev_err(dev, "fail to get axis_map_z\n");
		goto fail;
	}
	ret = of_property_read_u32(np, "negate_x", &pdata->negate_x);
	if(ret){
		dev_err(dev, "fail to get negate_x\n");
		goto fail;
	}
	ret = of_property_read_u32(np, "negate_y", &pdata->negate_y);
	if(ret){
		dev_err(dev, "fail to get negate_y\n");
		goto fail;
	}
	ret = of_property_read_u32(np, "negate_z", &pdata->negate_z);
	if(ret){
		dev_err(dev, "fail to get negate_z\n");
		goto fail;
	}
	return pdata;
fail:
	kfree(pdata);
	return NULL;
}
#endif




#ifdef LIS3DH_DBG
static int str2int(char *p, char *end)
{
        int result = 0;
        int len = end - p + 1;
        int c;

        for(; len > 0; len--, p++) {
                if(p > end)
                        return -1;
                c = *p - '0';
                if((unsigned int)c >= 10)
                        return -1;
                result = result * 10 + c;
        }
        return result;
}

/*parse a int from the string*/
static int get_int(char *p, u8 max_len)
{
        char *start = p;
        char *end =NULL;

        if(max_len > 60) {
                LOG_ERR("CMD ERROR!the max length of the cmd should less than 60\n");
                return -1;
        }
        for(; max_len > 0; max_len--, p++) {
                if(*p >= '0' && *p <= '9') {
                        start = p;
                        break;
                }
        }
        if(0 == max_len)
                return -1;

        end = start;

        for(; max_len > 0; max_len--, p++) {
                if(*p >= '0' && *p <= '9') {
                        end = p;
                        continue;
                }
                break;
        }

        return str2int(start, end);
}

static ssize_t lis3dh_val_show(struct kobject *kobj, struct kobj_attribute *attr, char *buff)
{
	 LOG_FUN( );
	
        return sprintf(buff, "acc->pdata->poll_interva=%d\n",lis3dh_acc_misc_data->pdata->poll_interval);
}
// adjust poll interval dynamiclly,eg echo 5>val_show ,means poll interval is 5ms
static ssize_t lis3dh_val_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buff, size_t n)
{
	LOG_FUN( );
	char *buff_temp = NULL;
	int interval;
       int err;
	   
	buff_temp = kmalloc(n, GFP_KERNEL);
	if(NULL == buff_temp){
	    LOG_ERR("kmalloc err\n");
	    return n;
	}

	memcpy(buff_temp, buff, n);
	interval = get_int(buff_temp, n);

	if (interval < 0 || interval > 1000)
	return -EINVAL;

	lis3dh_acc_misc_data->pdata->poll_interval = max(interval,lis3dh_acc_misc_data->pdata->min_interval); // max the frequecy of g sensor
       LOG_INFO("yuebao %s,acc->pdata->poll_interval =%d,interval=%d,acc->pdata->min_interval=%d\n", __func__,lis3dh_acc_misc_data->pdata->poll_interval,interval,lis3dh_acc_misc_data->pdata->min_interval );
	err = lis3dh_acc_update_odr(lis3dh_acc_misc_data, lis3dh_acc_misc_data->pdata->poll_interval );
	/* TODO: if update fails poll is still set */
	//		if (err < 0)
	//			return err;
	if(buff_temp != NULL)
	    kfree(buff_temp);

	return 0;
}

/*
1  should first write ,eg echo 0x20=0x97>reg
2  then read ,eg cat reg:Addr: 0x20 Val: 0x97
*/
static ssize_t sensor_reg_show(struct kobject *kobj, struct kobj_attribute *attr, char *buff)
{
        int err;
	  u8 value = 0;
	
	 LOG_FUN( );

	err = lis3dh_acc_register_read(lis3dh_acc_misc_data, &value, lis3dh_acc_misc_data->debug.diag_reg_addr_wr);
	return sprintf(buff, "Addr: 0x%x Val: 0x%x\n",
			lis3dh_acc_misc_data->debug.diag_reg_addr_wr, value);	
}

static ssize_t sensor_reg_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buff, size_t n)
{
	char buf[32];
	char *sptr, *token;
	unsigned int len = 0;
	u8 reg_addr, reg_val;
	 int err = -1;

	LOG_INFO("%s, user echo is:%s\n",__func__,buff);
	len = min(n, sizeof(buf) - 1);
	if (!memcpy(buf, buff, len)){
		LOG_INFO("%s, %s\n",__func__,buf);
		return -EFAULT;
	}

	buf[len] = '\0';
	sptr = buf;

	token = strsep(&sptr, "=");
	LOG_INFO("%s, token=%s\n",__func__,token);

	if (!token)
		return -EINVAL;

	 LOG_INFO("%s,now  token=%s,sptr=%s\n",__func__,token,sptr);

	if (kstrtou8(token, 0, &reg_addr)){
		 LOG_INFO("%s,now  reg_addr=0x%x\n",__func__,reg_addr);
		return -EINVAL;
	}
//	if (!ath6kl_dbg_is_diag_reg_valid(reg_addr))
//		return -EINVAL;

	if (kstrtou8(sptr, 0, &reg_val)){
		 LOG_INFO("%s,now reg_val=0x%x\n",__func__,reg_val);
		return -EINVAL;
	}
	 LOG_INFO("%s,now  reg_addr=0x%x,reg_val=0x%x\n",__func__,reg_addr,reg_val);

	lis3dh_acc_misc_data->debug.diag_reg_addr_wr = reg_addr;
	lis3dh_acc_misc_data->debug.diag_reg_val_wr = reg_val;

	buf[0] = reg_addr;
	buf[1] = reg_val;
		
	err = lis3dh_acc_i2c_write(lis3dh_acc_misc_data, buf, 1);
	if (err < 0){
		LOG_ERR("%s: %d\n",__func__,err);
		return -EIO;
	}
	//resume_state[index]   index  is not   reg addr,  so ONLY CAN config CTRL_REG1~CTRL_REG6 
	lis3dh_acc_misc_data->resume_state[reg_addr-0x20] = reg_val;
	 LOG_INFO("%s,now n=%d\n",__func__,n);
	return n;
}
static struct kobject *lis3dh_kobj;
static struct kobj_attribute lis3dh_val_attr =
        __ATTR(show_val, 0644, lis3dh_val_show, lis3dh_val_store);
static struct kobj_attribute sensor_reg_attr =
        __ATTR(reg, 0644, sensor_reg_show, sensor_reg_store);


static struct attribute *sensor_sysfs_attrs[] = {
	&lis3dh_val_attr.attr,
	&sensor_reg_attr.attr,
		
	NULL
};

static struct attribute_group sensor_attribute_group = {
	.attrs = sensor_sysfs_attrs,
};


static int lis3dh_sysfs_init(struct lis3dh_acc_data *acc)
{
        int ret = -1;

        lis3dh_kobj = kobject_create_and_add("lis3dh", &(acc->input_dev->dev.kobj));
        if (lis3dh_kobj == NULL) {
                ret = -ENOMEM;
                LOG_ERR("register sysfs failed. ret = %d\n", ret);
                return ret;
        }
	 ret = sysfs_create_group(lis3dh_kobj, &sensor_attribute_group);
        if (ret) {
                LOG_ERR("create sysfs failed. ret = %d\n", ret);
                return ret;
        }
        return ret;
}

#endif

static int lis3dh_acc_probe(struct i2c_client *client,
			    const struct i2c_device_id *id)
{

	struct lis3dh_acc_data *acc;
	struct lis3dh_acc_platform_data *pdata = client->dev.platform_data;

	int err = -1;
	int tempvalue;
	LOG_INFO("sprd-gsensor: -- %s -- start !\n",__func__);
	pr_debug("%s: probe start.\n", LIS3DH_ACC_DEV_NAME);


#ifdef CONFIG_OF
	struct device_node *np = client->dev.of_node;
	if (np && !pdata){
		pdata = lis3dh_acc_parse_dt(&client->dev);
		if(pdata){
			client->dev.platform_data = pdata;
		}
		if(!pdata){
			err = -ENOMEM;
			goto exit_alloc_platform_data_failed;
		}
	}
#endif
	/*
	if (client->dev.platform_data == NULL) {
		dev_err(&client->dev, "platform data is NULL. exiting.\n");
		err = -ENODEV;
		goto exit_check_functionality_failed;
	}
	*/
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		dev_err(&client->dev, "client not i2c capable\n");
		err = -ENODEV;
		goto exit_check_functionality_failed;
	}

	if (!i2c_check_functionality(client->adapter,
				     I2C_FUNC_SMBUS_BYTE |
				     I2C_FUNC_SMBUS_BYTE_DATA |
				     I2C_FUNC_SMBUS_WORD_DATA)) {
		dev_err(&client->dev, "client not smb-i2c capable:2\n");
		err = -EIO;
		goto exit_check_functionality_failed;
	}

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) {
		dev_err(&client->dev, "client not smb-i2c capable:3\n");
		err = -EIO;
		goto exit_check_functionality_failed;
	}
	/*
	 * OK. From now, we presume we have a valid client. We now create the
	 * client structure, even though we cannot fill it completely yet.
	 */

	acc = kzalloc(sizeof(struct lis3dh_acc_data), GFP_KERNEL);
	if (acc == NULL) {
		err = -ENOMEM;
		dev_err(&client->dev,
			"failed to allocate memory for module data: "
			"%d\n", err);
		goto exit_alloc_data_failed;
	}

	mutex_init(&acc->lock);
	mutex_lock(&acc->lock);

	acc->client = client;
	lis3dh_i2c_client = client;
	i2c_set_clientdata(client, acc);

	LOG_INFO("gpio pin request  (%d)\n", pdata->gpio_int1);
       err=gpio_request(pdata->gpio_int1, "GSENSOR_INT1");
    
	if (err) {
	        LOG_ERR("gpio pin request fail (%d)\n", err);
	        goto err_free_irq1;
	}  else  {
			gpio_direction_input(pdata->gpio_int1);
			LOG_INFO("sprd-gsensor: -- %s  acc->irq1_gpio_number  status is [%d]-- !\n",__func__,gpio_get_value(pdata->gpio_int1));
			/*get irq*/
			acc->irq1  = gpio_to_irq(pdata->gpio_int1);
			LOG_INFO("IRQ1 number is %d\n", acc->irq1 );
	}
	if (acc->irq1 != 0) {
		pr_debug("%s request irq1\n", __func__);
		err =
		    request_irq(acc->irq1, lis3dh_acc_isr1, IRQF_TRIGGER_HIGH| IRQF_NO_SUSPEND ,
				"lis3dh_acc_irq1", acc);
		if (err < 0) {
			dev_err(&client->dev, "request irq1 failed: %d\n", err);
			goto err_mutexunlockfreedata;
		}
		disable_irq_nosync(acc->irq1);

		INIT_WORK(&acc->irq1_work, lis3dh_acc_irq1_work_func);
		acc->irq1_work_queue =
		    create_singlethread_workqueue("lis3dh_acc_wq1");
		if (!acc->irq1_work_queue) {
			err = -ENOMEM;
			dev_err(&client->dev, "cannot create work queue1: %d\n",
				err);
			goto err_free_irq1;
		}
	}


//	gpio_request(GSENSOR_GINT2_GPI, "GSENSOR_INT2");
	acc->irq2 = 0; /* gpio_to_irq(GSENSOR_GINT2_GPI); */
	if (acc->irq2 != 0) {
		err =
		    request_irq(acc->irq2, lis3dh_acc_isr2, IRQF_TRIGGER_RISING,
				"lis3dh_acc_irq2", acc);
		if (err < 0) {
			dev_err(&client->dev, "request irq2 failed: %d\n", err);
			goto err_destoyworkqueue1;
		}
		disable_irq_nosync(acc->irq2);

/*		 Create workqueue for IRQ.*/

		INIT_WORK(&acc->irq2_work, lis3dh_acc_irq2_work_func);
		acc->irq2_work_queue =
		    create_singlethread_workqueue("lis3dh_acc_wq2");
		if (!acc->irq2_work_queue) {
			err = -ENOMEM;
			dev_err(&client->dev, "cannot create work queue2: %d\n",
				err);
			goto err_free_irq2;
		}
	}

	acc->pdata = kmalloc(sizeof(*acc->pdata), GFP_KERNEL);
	if (acc->pdata == NULL) {
		err = -ENOMEM;
		dev_err(&client->dev,
			"failed to allocate memory for pdata: %d\n", err);
		goto err_destoyworkqueue2;
	}

	memcpy(acc->pdata, client->dev.platform_data, sizeof(*acc->pdata));

	err = lis3dh_acc_validate_pdata(acc);
	if (err < 0) {
		dev_err(&client->dev, "failed to validate platform data\n");
		goto exit_kfree_pdata;
	}

#ifdef GSENSOR_INTERRUPT_MODE
memset(acc->resume_state, 0, ARRAY_SIZE(acc->resume_state));

	acc->resume_state[RES_CTRL_REG1] = LIS3DH_ACC_ENABLE_ALL_AXES;
	acc->resume_state[RES_CTRL_REG2] = 0x00;
	acc->resume_state[RES_CTRL_REG3] = CTRL_REG3_I1_DRDY1;//0x00;
	acc->resume_state[RES_CTRL_REG4] = 0x00;
	acc->resume_state[RES_CTRL_REG5] = CTRL_REG5_LIR_INT1;//0x00;
	acc->resume_state[RES_CTRL_REG6] = CTRL_REG6_HLACTIVE;//0x00;

	acc->resume_state[RES_TEMP_CFG_REG] = 0x00;
	acc->resume_state[RES_FIFO_CTRL_REG] = 0x00;
	acc->resume_state[RES_INT_CFG1] = 0x00;
	acc->resume_state[RES_INT_THS1] = 0x00;
	acc->resume_state[RES_INT_DUR1] = 0x00;
	acc->resume_state[RES_INT_CFG2] = 0x00;
	acc->resume_state[RES_INT_THS2] = 0x00;
	acc->resume_state[RES_INT_DUR2] = 0x00;

	acc->resume_state[RES_TT_CFG] = 0x00;
	acc->resume_state[RES_TT_THS] = 0x00;
	acc->resume_state[RES_TT_LIM] = 0x00;
	acc->resume_state[RES_TT_TLAT] = 0x00;
	acc->resume_state[RES_TT_TW] = 0x00;

#endif
	sprd_i2c_ctl_chg_clk(client->adapter->nr, 400000);




	err = lis3dh_acc_device_power_on(acc);
	if (err < 0) {
		dev_err(&client->dev, "power on failed: %d\n", err);
		goto err2;
	}

#if 1
	if (i2c_smbus_read_byte(client) < 0) {
		pr_err("i2c_smbus_read_byte error!!\n");
		goto err_destoyworkqueue2;
	} else {
		pr_debug("%s Device detected!\n", LIS3DH_ACC_DEV_NAME);
	}
#endif
	/* read chip id */

	tempvalue = i2c_smbus_read_word_data(client, WHO_AM_I);

	if ((tempvalue & 0x00FF) == WHOAMI_LIS3DH_ACC) {
		pr_debug("%s I2C driver registered!\n",
		       LIS3DH_ACC_DEV_NAME);
	} else {
		acc->client = NULL;
		pr_debug("I2C driver not registered!"
		       " Device unknown 0x%x\n", tempvalue);
		goto err_destoyworkqueue2;
	}
	
	i2c_set_clientdata(client, acc);

	if (acc->pdata->init) {
		err = acc->pdata->init();
		if (err < 0) {
			dev_err(&client->dev, "init failed: %d\n", err);
			goto err2;
		}
	}
#ifndef GSENSOR_INTERRUPT_MODE
	memset(acc->resume_state, 0, ARRAY_SIZE(acc->resume_state));

	acc->resume_state[RES_CTRL_REG1] = LIS3DH_ACC_ENABLE_ALL_AXES;
	acc->resume_state[RES_CTRL_REG2] = 0x00;
	acc->resume_state[RES_CTRL_REG3] = CTRL_REG3_I1_DRDY1;//0x00;
	acc->resume_state[RES_CTRL_REG4] = 0x00;
	acc->resume_state[RES_CTRL_REG5] = 0x00;//CTRL_REG5_LIR_INT1;//0x04;
	acc->resume_state[RES_CTRL_REG6] = CTRL_REG6_HLACTIVE;//0x00;

	acc->resume_state[RES_TEMP_CFG_REG] = 0x00;
	acc->resume_state[RES_FIFO_CTRL_REG] = 0x00;
	acc->resume_state[RES_INT_CFG1] = 0x00;
	acc->resume_state[RES_INT_THS1] = 0x00;
	acc->resume_state[RES_INT_DUR1] = 0x00;
	acc->resume_state[RES_INT_CFG2] = 0x00;
	acc->resume_state[RES_INT_THS2] = 0x00;
	acc->resume_state[RES_INT_DUR2] = 0x00;

	acc->resume_state[RES_TT_CFG] = 0x00;
	acc->resume_state[RES_TT_THS] = 0x00;
	acc->resume_state[RES_TT_LIM] = 0x00;
	acc->resume_state[RES_TT_TLAT] = 0x00;
	acc->resume_state[RES_TT_TW] = 0x00;

#endif
	atomic_set(&acc->enabled, 1);

	err = lis3dh_acc_update_g_range(acc, acc->pdata->g_range);
	if (err < 0) {
		dev_err(&client->dev, "update_g_range failed\n");
		goto err_power_off;
	}

	err = lis3dh_acc_update_odr(acc, acc->pdata->poll_interval);
	if (err < 0) {
		dev_err(&client->dev, "update_odr failed\n");
		goto err_power_off;
	}

	err = lis3dh_acc_input_init(acc);
	if (err < 0) {
		dev_err(&client->dev, "input init failed\n");
		goto err_power_off;
	}
	lis3dh_acc_misc_data = acc;

	err = misc_register(&lis3dh_acc_misc_device);
	if (err < 0) {
		dev_err(&client->dev,
			"misc LIS3DH_ACC_DEV_NAME register failed\n");
		goto err_input_cleanup;
	}

	lis3dh_acc_device_power_off(acc);

	/* As default, do not report information */
	atomic_set(&acc->enabled, 0);
/*
#ifdef CONFIG_HAS_EARLYSUSPEND
	acc->early_suspend.suspend = lis3dh_early_suspend;
	acc->early_suspend.resume = lis3dh_early_resume;
	acc->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN;
	register_early_suspend(&acc->early_suspend);
#endif
*/
#ifdef LIS3DH_DBG
        err = lis3dh_sysfs_init(acc);
        if(err) {
                LOG_ERR("lis3dh_sysfs_init failed!\n");
                goto exit_lis3dh_sysfs_init_failed;
        }
#endif
#if USE_WAIT_QUEUE
	thread = kthread_run(gsensor_event_handler, 0, "gsensor-wait");
	if (IS_ERR(thread))
	{
		err = PTR_ERR(thread);
		LOG_ERR("failed to create kernel thread: %d\n", err);
	}
#endif
	mutex_unlock(&acc->lock);
	dev_info(&client->dev, "###%s###\n", __func__);
       LOG_INFO("sprd-gsensor: -- %s exit :acc->irq1_gpio_number status is [%d]-- !\n",__func__,gpio_get_value(acc->pdata->gpio_int1));
	LOG_INFO("sprd-gsensor: -- %s -- success !\n",__func__);
	return 0;

#ifdef LIS3DH_DBG
exit_lis3dh_sysfs_init_failed:
#endif
	
err_input_cleanup:
	lis3dh_acc_input_cleanup(acc);
err_power_off:
	lis3dh_acc_device_power_off(acc);
err2:
	if (acc->pdata->exit)
		acc->pdata->exit();
exit_kfree_pdata:
	kfree(acc->pdata);
err_destoyworkqueue2:
	if (acc->irq2_work_queue)
		destroy_workqueue(acc->irq2_work_queue);
err_free_irq2:
	if (acc->irq2) {
		free_irq(acc->irq2, acc);
		gpio_free(GSENSOR_GINT2_GPI);
	}
err_destoyworkqueue1:
	if (acc->irq1_work_queue)
		destroy_workqueue(acc->irq1_work_queue);
err_free_irq1:
	if (acc->irq1) {
		free_irq(acc->irq1, acc);
		gpio_free(acc->pdata->gpio_int1);
	}
err_mutexunlockfreedata:
	i2c_set_clientdata(client, NULL);
	mutex_unlock(&acc->lock);
	kfree(acc);
	lis3dh_acc_misc_data = NULL;
exit_alloc_data_failed:
exit_check_functionality_failed:
	pr_err("%s: Driver Init failed\n", LIS3DH_ACC_DEV_NAME);
exit_alloc_platform_data_failed:
	return err;
}

static int  lis3dh_acc_remove(struct i2c_client *client)
{

	/* TODO: revisit ordering here once _probe order is finalized */
	struct lis3dh_acc_data *acc = i2c_get_clientdata(client);
	if (acc != NULL) {
		if (acc->irq1) {
			free_irq(acc->irq1, acc);
			gpio_free(acc->pdata->gpio_int1);
		}
		if (acc->irq2) {
			free_irq(acc->irq2, acc);
			gpio_free(GSENSOR_GINT2_GPI);
		}

		if (acc->irq1_work_queue)
			destroy_workqueue(acc->irq1_work_queue);
		if (acc->irq2_work_queue)
			destroy_workqueue(acc->irq2_work_queue);
		misc_deregister(&lis3dh_acc_misc_device);
		lis3dh_acc_input_cleanup(acc);
		lis3dh_acc_device_power_off(acc);
		if (acc->pdata->exit)
			acc->pdata->exit();
		kfree(acc->pdata);
		kfree(acc);
	}

	return 0;
}

static int lis3dh_acc_resume(struct i2c_client *client)
{
	struct lis3dh_acc_data *acc = i2c_get_clientdata(client);

	LOG_INFO("sprd-gsensor: -- %s -- !\n",__func__);
	dev_dbg(&client->dev, "###%s###\n", __func__);
	if (acc != NULL && acc->on_before_suspend)
		return lis3dh_acc_enable(acc);

	return 0;
}

static int lis3dh_acc_suspend(struct i2c_client *client, pm_message_t mesg)
{
	struct lis3dh_acc_data *acc = i2c_get_clientdata(client);

	LOG_INFO("sprd-gsensor: -- %s -- !\n",__func__);
	dev_dbg(&client->dev, "###%s###\n", __func__);
	if (acc != NULL) {
		acc->on_before_suspend = atomic_read(&acc->enabled);
		return lis3dh_acc_disable(acc);
	}
	return 0;
}

#ifdef CONFIG_HAS_EARLYSUSPEND

static void lis3dh_early_suspend(struct early_suspend *es)
{
	lis3dh_acc_suspend(lis3dh_i2c_client, (pm_message_t) {
			   .event = 0});
}

static void lis3dh_early_resume(struct early_suspend *es)
{
	lis3dh_acc_resume(lis3dh_i2c_client);
}

#endif /* CONFIG_HAS_EARLYSUSPEND */

static const struct i2c_device_id lis3dh_acc_id[]
= { {LIS3DH_ACC_DEV_NAME, 0}, {}, };

MODULE_DEVICE_TABLE(i2c, lis3dh_acc_id);

static const struct of_device_id lis3dh_acc_of_match[] = {
       { .compatible = "ST,lis3dh_acc", },
       { }
};
MODULE_DEVICE_TABLE(of, lis3dh_acc_of_match);
static struct i2c_driver lis3dh_acc_driver = {
	.driver = {
		   .name = LIS3DH_ACC_I2C_NAME,
		   .of_match_table = lis3dh_acc_of_match,
		   },
	.probe = lis3dh_acc_probe,
	.remove = lis3dh_acc_remove,
	.resume = lis3dh_acc_resume,
	.suspend = lis3dh_acc_suspend,
	.id_table = lis3dh_acc_id,
};


static int __init lis3dh_acc_init(void)
{
	pr_debug("%s accelerometer driver: init\n", LIS3DH_ACC_I2C_NAME);

	return i2c_add_driver(&lis3dh_acc_driver);
}

static void __exit lis3dh_acc_exit(void)
{
	pr_debug("%s accelerometer driver exit\n", LIS3DH_ACC_DEV_NAME);

	i2c_del_driver(&lis3dh_acc_driver);
	return;
}

module_init(lis3dh_acc_init);
module_exit(lis3dh_acc_exit);

MODULE_DESCRIPTION("lis3dh accelerometer misc driver");
MODULE_AUTHOR("STMicroelectronics");
MODULE_LICENSE("GPL");