aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-kernel/linux/files/0020-Quark-IIO-quark.patch
blob: 809c203170b2128e078e44234d4da26946dea1d7 (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
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
From xxxx Mon Sep 17 00:00:00 2001
From: Dan O'Donovan <dan.odonovan@emutex.com>
Date: Fri, 14 Feb 2014 14:10:33 +0000
Subject: [PATCH 20/21] Quark IIO

---
 drivers/iio/adc/ad7298.c                       |   20 +-
 drivers/staging/iio/adc/Kconfig                |   13 +
 drivers/staging/iio/adc/Makefile               |    1 +
 drivers/staging/iio/adc/max78m6610_lmu.c       | 2235 ++++++++++++++++++++++++
 drivers/staging/iio/trigger/Kconfig            |   11 +
 drivers/staging/iio/trigger/Makefile           |    1 +
 drivers/staging/iio/trigger/iio-trig-hrtimer.c |  288 +++
 include/linux/platform_data/ad7298.h           |    5 +
 include/linux/platform_data/max78m6610_lmu.h   |   34 +
 9 files changed, 2603 insertions(+), 5 deletions(-)
 create mode 100644 drivers/staging/iio/adc/max78m6610_lmu.c
 create mode 100644 drivers/staging/iio/trigger/iio-trig-hrtimer.c
 create mode 100644 include/linux/platform_data/max78m6610_lmu.h

diff --git a/drivers/iio/adc/ad7298.c b/drivers/iio/adc/ad7298.c
index b34d754..60491e4 100644
--- a/drivers/iio/adc/ad7298.c
+++ b/drivers/iio/adc/ad7298.c
@@ -33,7 +33,6 @@
 #define AD7298_TAVG	(1 << 1) /* temperature sensor averaging enable */
 #define AD7298_PDD	(1 << 0) /* partial power down enable */
 
-#define AD7298_MAX_CHAN		8
 #define AD7298_BITS		12
 #define AD7298_STORAGE_BITS	16
 #define AD7298_INTREF_mV	2500
@@ -46,6 +45,7 @@ struct ad7298_state {
 	struct spi_device		*spi;
 	struct regulator		*reg;
 	unsigned			ext_ref;
+	u16				ext_vin_max[AD7298_MAX_CHAN];
 	struct spi_transfer		ring_xfer[10];
 	struct spi_transfer		scan_single_xfer[3];
 	struct spi_message		ring_msg;
@@ -64,7 +64,7 @@ struct ad7298_state {
 		.indexed = 1,						\
 		.channel = index,					\
 		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |		\
-		IIO_CHAN_INFO_SCALE_SHARED_BIT,				\
+			IIO_CHAN_INFO_SCALE_SEPARATE_BIT,		\
 		.address = index,					\
 		.scan_index = index,					\
 		.scan_type = {						\
@@ -269,7 +269,10 @@ static int ad7298_read_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_SCALE:
 		switch (chan->type) {
 		case IIO_VOLTAGE:
-			*val = ad7298_get_ref_voltage(st);
+			if (st->ext_vin_max[chan->channel])
+				*val = st->ext_vin_max[chan->channel];
+			else
+				*val = ad7298_get_ref_voltage(st);
 			*val2 = chan->scan_type.realbits;
 			return IIO_VAL_FRACTIONAL_LOG2;
 		case IIO_TEMP:
@@ -304,8 +307,15 @@ static int ad7298_probe(struct spi_device *spi)
 
 	st = iio_priv(indio_dev);
 
-	if (pdata && pdata->ext_ref)
-		st->ext_ref = AD7298_EXTREF;
+	if (pdata) {
+		int i;
+
+		if (pdata->ext_ref)
+			st->ext_ref = AD7298_EXTREF;
+
+		for (i = 0; i < AD7298_MAX_CHAN; i++)
+			st->ext_vin_max[i] = pdata->ext_vin_max[i];
+	}
 
 	if (st->ext_ref) {
 		st->reg = regulator_get(&spi->dev, "vref");
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index fb8c239..1309fac 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -137,4 +137,17 @@ config SPEAR_ADC
 	  Say yes here to build support for the integrated ADC inside the
 	  ST SPEAr SoC. Provides direct access via sysfs.
 
+config MAX78M6610_LMU
+	tristate "Maxim 78M6610+LMU driver"
+	depends on SPI
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	help
+	  Say yes here to build support for Maxim Energy Measurement Processor
+	  for Load Monitoring Units.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called max78m6610_lmu.
+
+
 endmenu
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index d285596..2c4e7e1 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile
@@ -21,3 +21,4 @@ obj-$(CONFIG_AD7280) += ad7280a.o
 obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
 obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
 obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
+obj-$(CONFIG_MAX78M6610_LMU) += max78m6610_lmu.o
diff --git a/drivers/staging/iio/adc/max78m6610_lmu.c b/drivers/staging/iio/adc/max78m6610_lmu.c
new file mode 100644
index 0000000..c427517
--- /dev/null
+++ b/drivers/staging/iio/adc/max78m6610_lmu.c
@@ -0,0 +1,2235 @@
+/*
+ * max78m6610+lmu SPI protocol driver
+ *
+ * Copyright(c) 2013 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Contact Information:
+ * Intel Corporation
+ *
+ * This SPI protocol driver is developed for the Maxim 78M6610+LMU (eADC).
+ * The driver is developed as a part of the Quark BSP where integrated into
+ * Quark Evaluation Boards Cross Hill Industrial-E.
+ *
+ * The Maxim 78M6610+LMU is an energy measurement processor (EMP) for
+ * load monitoring on single or spilt-phase AC loads. It supports varies
+ * interface configuration protocols through I/O pins.
+ *
+ * With 3 wire serial input/output interfaces provided by Quark SoC,
+ * the 78M6610+LMU can be connected directly as SPI slave device.
+ */
+
+#include <linux/cdev.h>
+#include <linux/delay.h>
+#include <linux/fs.h>
+#include <linux/gpio.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/types.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/events.h>
+#include <linux/platform_data/max78m6610_lmu.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/spidev.h>
+#include <linux/version.h>
+
+/* Calibration registers */
+#define COMMAND         0x00 /* Command Register */
+#define SAMPLES         0x03 /* High-rate samples per low-rate */
+#define CALCYCS         0x04 /* Number of Calibration Cycles to Average */
+#define PHASECOMP1      0x05 /* Phase compensation for S1 input */
+#define PHASECOMP3      0x06 /* Phase compensation for S3 input */
+#define S1_GAIN         0x07 /* Input S1 Gain Calibration */
+#define S0_GAIN         0x08 /* Input S0 Gain Calibration */
+#define S3_GAIN         0x09 /* Input S3 Gain Calibration */
+#define S2_GAIN         0x0A /* Input S2 Gain Calibration */
+#define S1_OFFSET       0x0D /* Input S1 Offset Calibration */
+#define S0_OFFSET       0x0B /* Input S0 Offset Calibration */
+#define S3_OFFSET       0x0E /* Input S3 Offset Calibration */
+#define S2_OFFSET       0x0C /* Input S2 Offset Calibration */
+#define VTARGET         0x12 /* Voltage Calibration Target */
+#define ITARGET         0x39 /* Current Calibration Target */
+
+#define CALCMD_S0_GAIN  0xCA2030 /* Calibrate Voltage Gain for Input S0 */
+#define CALCMD_S1_GAIN  0xCA0830 /* Calibrate Current Gain for Input S1 */
+#define CALCMD_S2_GAIN  0xCA4030 /* Calibrate Voltage Gain for Input S2 */
+#define CALCMD_S3_GAIN  0xCA1030 /* Calibrate Current Gain for Input S3 */
+#define CALCMD_S0_OFFS  0xCA2210 /* Calibrate Voltage Offset for Input S0 */
+#define CALCMD_S1_OFFS  0xCA0A10 /* Calibrate Current Offset for Input S1 */
+#define CALCMD_S2_OFFS  0xCA4210 /* Calibrate Voltage Offset for Input S2 */
+#define CALCMD_S3_OFFS  0xCA1210 /* Calibrate Current Offset for Input S3 */
+#define FLASHSAVE_CMD   0xACC210 /* Save calibration coefficients to flash */
+
+/* Interrupt status registers */
+#define MASK0           0x02 /* Status bit mask for MP0 pin */
+#define STATUS          0x0F /* Status of device and alarms */
+#define STATUS_RESET    0x11 /* Used to Reset Status bits */
+#define STATUS_MASK_DRDY     (1 << 23)
+#define STATUS_MASK_MMUPD    (1 << 22)
+#define STATUS_MASK_VA_SAG   (1 << 21)
+#define STATUS_MASK_VB_SAG   (1 << 20)
+#define STATUS_MASK_SIGN_VA  (1 << 19)
+#define STATUS_MASK_SIGN_VB  (1 << 18)
+#define STATUS_MASK_OV_TEMP  (1 << 17)
+#define STATUS_MASK_UN_TEMP  (1 << 16)
+#define STATUS_MASK_OV_FREQ  (1 << 15)
+#define STATUS_MASK_UN_FREQ  (1 << 14)
+#define STATUS_MASK_OV_VRMSA (1 << 13)
+#define STATUS_MASK_UN_VRMSA (1 << 12)
+#define STATUS_MASK_OV_VRMSB (1 << 11)
+#define STATUS_MASK_UN_VRMSB (1 << 10)
+#define STATUS_MASK_VA_SURGE (1 << 9)
+#define STATUS_MASK_VB_SURGE (1 << 8)
+#define STATUS_MASK_OV_WATT1 (1 << 7)
+#define STATUS_MASK_OV_WATT2 (1 << 6)
+#define STATUS_MASK_OV_AMP1  (1 << 5)
+#define STATUS_MASK_OV_AMP2  (1 << 4)
+#define STATUS_MASK_XSTATE   (1 << 3)
+#define STATUS_MASK_RELAY1   (1 << 2)
+#define STATUS_MASK_RELAY2   (1 << 1)
+#define STATUS_MASK_RESET    (1)
+#define STATUS_MASK_STICKY   (0x73FFF0)
+#define STATUS_MASK_IGNORE   (0x00000F)
+
+#define VSURG_VAL	0x13 /* Voltage surge alarm threshold */
+#define VSAG_VAL	0x14 /* Voltage sag alarm threshold */
+#define VRMS_MIN	0x15 /* Voltage lower alarm limit */
+#define VRMS_MAX	0x16 /* Voltage upper alarm limit */
+#define IRMS_MAX	0x27 /* Over Current alarm limit */
+#define WATT_MAX	0x32 /* Power alarm limit */
+
+#define INSTAN_VA       0x1D /* instaneous Voltage for VA source */
+#define INSTAN_IA       0x25 /* instaneous Current for IA source */
+#define INSTAN_PA       0x2E /* instaneous Active Power for source A*/
+#define INSTAN_PQA      0x30 /* instaneous Reactive Power for source A*/
+#define VA_RMS          0x17 /* RMS voltage for VA source */
+#define IA_RMS          0x1F /* RMS current for VA source */
+#define WATT_A          0x28 /* Active Power for source A */
+#define VAR_A           0x2C /* Reactive power for source A */
+#define VA_A            0x2A /* Volt-Amperes for source A */
+#define PFA             0x33 /* Source A Power Factor */
+
+#define INSTAN_VB       0x1E /* instaneous Voltage for VB source */
+#define INSTAN_IB       0x26 /* instaneous Current for IB source */
+#define INSTAN_PB       0x2F /* instaneous Active Power for source B*/
+#define INSTAN_PQB      0x31 /* instaneous Voltage for VB source */
+#define VB_RMS          0x18 /* RMS voltage for VB source */
+#define IB_RMS          0x20 /* RMS current for VB source */
+#define WATT_B          0x29 /* Active Power for source B */
+#define VAR_B           0x2D /* Reactive power for source B */
+#define VA_B            0x2B /* Volt-amperes for source B */
+#define PFB             0x34 /* Source B Power Factor */
+
+/* Addr bit 6-7: ADDR6, ADDR7 */
+#define SPI_CB_ADDR_MASK_7_6(x)	(((x) & 0xC0) >> 6)
+/* Addr bit 0 - 5 */
+#define SPI_TB_ADDR_MASK_5_0(x)	((x) & 0x3F)
+
+#define SPI_CB_NBR_ACC	0x00	/* number register of accesss, limit to 1 */
+#define SPI_CB_CMD	0x01	/* SPI command flag */
+#define SPI_OP_READ	0x00	/* bit 1: Read/Write RD:0 W:1 */
+#define SPI_OP_WRITE	0x02	/* bit 1: Read/Write RD:0 W:1 */
+/* Positive / negative conversion */
+#define SIGN_CONVERT	0xFFFFFFFFFFFFFFFF
+#define DATA_BIT_MASK	0x00FFFFFF
+#define SIGN_BIT_NUM	23
+#define SPI_MSG_LEN	5
+#define RX_OFFSET	1
+#define SPI_BBUFFER_LEN 4096
+/* All registers on the device are 24-bit */
+#define REG_WIDTH	24
+#define SAMPLE_INTERVAL_USEC 250 /* High-rate sample interval (microseconds) */
+#define RESET_DELAY_MSEC 100
+#define INTR_GPIO        2
+
+/* SPI message Control byte */
+#define SPI_CB(x)	((SPI_CB_NBR_ACC << 4)\
+			| (SPI_CB_ADDR_MASK_7_6(x) << 2)\
+			| SPI_CB_CMD)
+/* SPI message Transaction byte */
+#define SPI_TB_READ(x)	((SPI_TB_ADDR_MASK_5_0(x) << 2)\
+			| SPI_OP_READ)
+#define SPI_TB_WRITE(x)	((SPI_TB_ADDR_MASK_5_0(x) << 2)\
+			| SPI_OP_WRITE)
+
+/**
+ * max78m6610_lmu_channels structure maps eADC measurement features to
+ * IIO channels on the IIO sysfs user interface
+ */
+static const struct iio_chan_spec max78m6610_lmu_channels[] = {
+	/* IIO Channels for source A */
+	{
+		.type = IIO_VOLTAGE,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "inst",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = INSTAN_VA,
+		.scan_index = 0,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_CURRENT,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "rms",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = IA_RMS,
+		.scan_index = 1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_POWER,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "inst_act",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = INSTAN_PA,
+		.scan_index = 2,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_POWER,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "inst_react",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = INSTAN_PQA,
+		.scan_index = 3,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_POWER,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "avg_act",
+		/* IIO_CHAN_INFO_AVERAGE_RAW is not used here,
+		 * this average value is provide by HW register,
+		 */
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = WATT_A,
+		.scan_index = 4,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_POWER,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "avg_react",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = VAR_A,
+		.scan_index = 5,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_POWER,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "apparent",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = VA_A,
+		.scan_index = 6,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_POWER,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "factor",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = PFA,
+		.scan_index = 7,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32, /* data type S.22 */
+			.storagebits = 32,
+			.shift = 22,
+		},
+	},
+	{
+		.type = IIO_VOLTAGE,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "rms",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = VA_RMS,
+		.scan_index = 8,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+
+	/* IIO channels for source B */
+	{
+		.type = IIO_VOLTAGE,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "inst",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = INSTAN_VB,
+		.scan_index = 9,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_CURRENT,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "rms",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = IB_RMS,
+		.scan_index = 10,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_POWER,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "inst_act",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = INSTAN_PB,
+		.scan_index = 11,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_POWER,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "inst_react",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = INSTAN_PQB,
+		.scan_index = 12,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_POWER,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "avg_act",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = WATT_B,
+		.scan_index = 13,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_POWER,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "avg_react",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = VAR_B,
+		.scan_index = 14,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_POWER,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "apparent",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = VA_B,
+		.scan_index = 15,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_POWER,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "factor",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = PFB,
+		.scan_index = 16,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 22, /* data type S.22 */
+		},
+	},
+	{
+		.type = IIO_VOLTAGE,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "rms",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = VB_RMS,
+		.scan_index = 17,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_CURRENT,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "inst",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = INSTAN_IA,
+		.scan_index = 18,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_CURRENT,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "inst",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+				IIO_CHAN_INFO_SCALE_SHARED_BIT,
+		.address = INSTAN_IB,
+		.scan_index = 19,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+	},
+	{
+		.type = IIO_CURRENT,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "phasecomp",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = PHASECOMP1,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 21,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_CURRENT,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "phasecomp",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = PHASECOMP3,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 21,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_VOLTAGE,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "calib_target_rms",
+		.info_mask = IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_RAW),
+		.address = VTARGET,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_CURRENT,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "calib_target_rms",
+		.info_mask = IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_RAW),
+		.address = ITARGET,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_VOLTAGE,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "calib_gain",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = S0_GAIN,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 21,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_VOLTAGE,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "calib_gain",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = S2_GAIN,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 21,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_CURRENT,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "calib_gain",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = S1_GAIN,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 21,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_CURRENT,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "calib_gain",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = S3_GAIN,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 21,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_VOLTAGE,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "calib_offset",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = S0_OFFSET,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_VOLTAGE,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "calib_offset",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = S2_OFFSET,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_CURRENT,
+		.indexed = 1,
+		.channel = 0,
+		.extend_name = "calib_offset",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = S1_OFFSET,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_CURRENT,
+		.indexed = 1,
+		.channel = 1,
+		.extend_name = "calib_offset",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = S3_OFFSET,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_VOLTAGE,
+		.indexed = 0,
+		.channel = 0,
+		.extend_name = "surge_threshold",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = VSURG_VAL,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_VOLTAGE,
+		.indexed = 0,
+		.channel = 0,
+		.extend_name = "sag_threshold",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = VSAG_VAL,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_VOLTAGE,
+		.indexed = 0,
+		.channel = 0,
+		.extend_name = "rms_min_threshold",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = VRMS_MIN,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_VOLTAGE,
+		.indexed = 0,
+		.channel = 0,
+		.extend_name = "rms_max_threshold",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = VRMS_MAX,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_CURRENT,
+		.indexed = 0,
+		.channel = 0,
+		.extend_name = "rms_max_threshold",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = IRMS_MAX,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+		.output = 1,
+	},
+	{
+		.type = IIO_POWER,
+		.indexed = 0,
+		.channel = 0,
+		.extend_name = "active_max_threshold",
+		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		.address = WATT_MAX,
+		.scan_index = -1,
+		.scan_type = {
+			.sign = 's',
+			.realbits = 32,
+			.storagebits = 32,
+			.shift = 23,
+		},
+		.output = 1,
+	},
+
+	IIO_CHAN_SOFT_TIMESTAMP(20),
+};
+
+/* max number of iio channels */
+#define MAX_CHAN_NUM		ARRAY_SIZE(max78m6610_lmu_channels)
+
+/* eADC state structure */
+struct max78m6610_lmu_state {
+	struct spi_device	*spi;
+	struct iio_dev_attr	*iio_attr;
+	struct iio_trigger      *trig;
+	struct spi_transfer	ring_xfer[MAX_CHAN_NUM];
+	struct spi_transfer	scan_single_xfer;
+	struct spi_message	ring_msg;
+	struct spi_message	scan_single_msg;
+
+	u8	tx_buf[SPI_MSG_LEN * MAX_CHAN_NUM];
+	u8	rx_buf[SPI_MSG_LEN * MAX_CHAN_NUM + sizeof(s64)];
+
+	int reset_gpio;
+
+	/* Char dev to provide ioctl interface for f/w upgrade
+	 * or low-level register access */
+	struct cdev cdev;
+	dev_t cdev_no;
+	struct class *cl;
+	u8	*bbuffer;
+};
+
+/**
+ * ret_fraction_log2
+ *
+ * @param val: pointer to val
+ * @param val2: pointer to val2
+ * @return: no returns
+ *
+ * this function to re-implement of IIO_VAL_FRACTIONAL_LOG2 marco in IIO
+ * because of the do_div() function is not correctly handle the negative
+ * input value.
+ */
+static void ret_fraction_log2(int *val, int *val2)
+{
+	s64 tmp;
+
+	tmp = *val;
+
+	if (*val < 0) {
+		/* the do_div function will return trash if the value
+		 * of input is negative. We need to treat tmp as
+		 * a positive number for calculation.
+		 * 1. XOR tmp with 0xFFFFFFFFFFFFFFFF.
+		 * 2. add on the differential
+		 */
+		tmp = (tmp ^ SIGN_CONVERT) + 1;
+		tmp = tmp * 1000000000LL >> (*val2);
+		*val2 = do_div(tmp, 1000000000LL);
+		*val = tmp;
+		/* the IIO_VAL_INT_PLUS_NANO marco is used in the later stage
+		 * to return the proper format of output.
+		 * The IIO use the value of val2 to determinate the sign
+		 * of the output.
+		 * Convert val2 from positive to negative to fool IIO to
+		 * display the
+		 * correct output format.
+		 */
+		*val2 = *val2 ^ SIGN_CONVERT;
+	} else {
+
+		tmp = tmp * 1000000000LL >> (*val2);
+		*val2 = do_div(tmp, 1000000000LL);
+		*val = tmp;
+	}
+}
+
+/**
+ * intplusnano_to_regval
+ *
+ * @param val_int:  Integer part of floating point value
+ * @param val_nano: Fractional part of floating point value
+ * @param frac_bits: The number of fractional bits to produce for this register
+ * @param regval: The resulting 24-bit signed fixed-point register value
+ * @return: 0 on success, non-zero on error
+ *
+ * As the kernel doesn't allow floating point numbers, IIO
+ * will split them into separate integer and fractional parts.  This function
+ * then converts them into fixed-point signed register values for the MAX78M6610
+ */
+static int intplusnano_to_regval(int val_int, int val_nano,
+				 int fract_bits, u32 *regval)
+{
+	int i, max_int, negative = 0;
+
+	/* Maximum integer value must be 24 bits minus sign and fraction_bits */
+	max_int = 1 << (REG_WIDTH - fract_bits - 1);
+
+	if ((val_int >= max_int) ||
+	    (val_int < -max_int) ||
+	    ((val_int == -max_int) && (val_nano != 0))) {
+		pr_err("Input value exceeds maximum allowed range\n");
+		return -EINVAL;
+	}
+
+	*regval = abs(val_int) << fract_bits;
+
+	/* Set the sign-bit, if input is negative */
+	if ((val_int < 0) || (val_nano < 0))
+		negative = 1;
+
+	val_nano = abs(val_nano);
+
+	/* Divide the fractional part down by negative powers of 2*/
+	for (i = fract_bits-1; i >= 0 && val_nano; i--) {
+		val_nano = val_nano << 1;
+		if (val_nano >= 1000000000LL) {
+			*regval |= (1 << i);
+			val_nano -= 1000000000LL;
+		}
+	}
+
+	/* Get 2s complement of number if negative */
+	if (negative)
+		*regval = (~(*regval) + 1) & ((1 << REG_WIDTH) - 1);
+
+	return 0;
+}
+
+/**
+ * __max78m6610_lmu_spi_reg_read
+ *
+ * @param st: Driver state data
+ * @param regaddr: The register word address to read
+ * @param regval: The 24-bit register value obtained by the read operation
+ * @return: 0 on success, non-zero on error
+ *
+ * Issues a SPI transaction to read a single register on the device.
+ * Performs endian byte swap before returning the register data.
+ */
+static inline
+int __max78m6610_lmu_spi_reg_read(struct max78m6610_lmu_state *st,
+				  u8 regaddr,
+				  u32 *regval)
+{
+	int ret;
+
+	st->tx_buf[0] = SPI_CB(regaddr);
+	st->tx_buf[1] = SPI_TB_READ(regaddr);
+	ret = spi_sync(st->spi, &st->scan_single_msg);
+	if (ret) {
+		pr_err("spi_sync return error: %d\n", ret);
+		return -EIO;
+	}
+
+	*regval = (st->rx_buf[2] << 16) | (st->rx_buf[3] << 8) | st->rx_buf[4];
+
+	return 0;
+}
+
+/**
+ * __max78m6610_lmu_spi_reg_write
+ *
+ * @param st: Driver state data
+ * @param regaddr: The register word address to write
+ * @param regval: The 24-bit value to write to the register
+ * @return: 0 on success, non-zero on error
+ *
+ * Issues a SPI transaction to write a single register on the device.
+ * Performs endian byte swap before writing the register data.
+ */
+static inline
+int __max78m6610_lmu_spi_reg_write(struct max78m6610_lmu_state *st,
+				   u8 regaddr,
+				   u32 regval)
+{
+	int ret;
+
+	st->tx_buf[0] = SPI_CB(regaddr);
+	st->tx_buf[1] = SPI_TB_WRITE(regaddr);
+	st->tx_buf[2] = regval >> 16;
+	st->tx_buf[3] = regval >> 8;
+	st->tx_buf[4] = regval & 0xFF;
+
+	ret = spi_sync(st->spi, &st->scan_single_msg);
+	if (ret) {
+		pr_err("spi_sync return non-zero value\n");
+		ret = -EIO;
+	}
+
+	return 0;
+}
+
+/**
+ * max78m6610_lmu_update_scan_mode
+ *
+ * @param indio_dev: iio_dev pointer.
+ * @param active_scan_mask: pointer to scan mask.
+ * @return 0 on success or standard errnos on failure
+ *
+ * setup the spi transfer buffer for the actived scan mask
+ **/
+static int max78m6610_lmu_update_scan_mode(struct iio_dev *indio_dev,
+	const unsigned long *active_scan_mask)
+{
+	struct max78m6610_lmu_state *st = iio_priv(indio_dev);
+	int i, tx = 0, k = 0;
+	unsigned addr;
+
+	spi_message_init(&st->ring_msg);
+
+	/* scan through all the channels */
+	for (i = 0; i < MAX_CHAN_NUM; i++) {
+		/* we build the the spi message here that support
+		 * multiple register access request on the selected channel */
+		if (test_bit(i, active_scan_mask)) {
+			addr = max78m6610_lmu_channels[i].address;
+			/* first two bytes are the contol bytes */
+			st->tx_buf[tx] = SPI_CB(addr);
+			st->tx_buf[tx+1] = SPI_TB_READ(addr);
+
+			st->ring_xfer[k].cs_change = 0;
+			st->ring_xfer[k].tx_buf = &st->tx_buf[tx];
+			/* rx buffer */
+			/* All the HW registers in the HW are designed as 24 bit
+			 * size, so we skip the first byte in the rx_buf when
+			 * constructing the ring_xfer.
+			 */
+			st->ring_xfer[k].rx_buf = &st->rx_buf[tx];
+			st->ring_xfer[k].len = SPI_MSG_LEN;
+			st->ring_xfer[k].cs_change = 1;
+
+			spi_message_add_tail(&st->ring_xfer[k],
+					&st->ring_msg);
+			/* update in bytes number */
+			tx += SPI_MSG_LEN;
+			k++;
+		}
+	}
+
+	return 0;
+}
+
+/**
+ * max78m6610_lmu_trigger_handle
+ *
+ * @param irq: irq indicator
+ * @parma p: iio pull funciton pointer
+ * @return IRQ_HANDLED
+ *
+ * bh handler of trigger launched polling to ring buffer
+ *
+ **/
+static irqreturn_t max78m6610_lmu_trigger_handler(int irq, void *p)
+{
+	struct iio_poll_func *pf = p;
+	struct iio_dev *indio_dev = pf->indio_dev;
+	struct max78m6610_lmu_state *st = iio_priv(indio_dev);
+
+	u32 scan_buf[((sizeof(u32)*MAX_CHAN_NUM)+sizeof(s64))/sizeof(u32)];
+	s64 time_ns = 0;
+	int b_sent;
+	int i = 0, rx_bit = 0;
+	int scan_count;
+
+	b_sent = spi_sync(st->spi, &st->ring_msg);
+	if (b_sent) {
+		pr_err("spi_sync failed.\n");
+		goto done;
+	}
+
+	scan_count = bitmap_weight(indio_dev->active_scan_mask,
+				   indio_dev->masklength);
+
+	if (indio_dev->scan_timestamp) {
+		time_ns = iio_get_time_ns();
+		memcpy((u8 *)scan_buf + indio_dev->scan_bytes - sizeof(s64),
+			&time_ns, sizeof(time_ns));
+	}
+
+	for (i = 0; i < scan_count; i++) {
+		u32 *rx_buf_32 = NULL;
+		rx_bit = i*SPI_MSG_LEN + RX_OFFSET;
+		rx_buf_32 = (u32 *)&(st->rx_buf[rx_bit]);
+		*rx_buf_32 = be32_to_cpu(*rx_buf_32) & DATA_BIT_MASK;
+		scan_buf[i] = sign_extend32(*rx_buf_32,
+				SIGN_BIT_NUM);
+	}
+
+	iio_push_to_buffers(indio_dev, (u8 *)scan_buf);
+done:
+	iio_trigger_notify_done(indio_dev->trig);
+
+	return IRQ_HANDLED;
+}
+
+/**
+ * max78m6610_lmu_read_raw
+ *
+ * @param indio_dev: iio_dev pointer
+ * @param chan: pointer to iio channel spec struct
+ * @param val: return value pointer
+ * @param val2: return value 2 ponter
+ * @parma m: read mask
+ * @return: IIO value type
+ *
+ * This function will be invoked when request a value form the device.
+ * Read mask specifies which value, return value will specify the type of
+ * value returned from device, val and val2 will contains the elements
+ * making up the return value.
+ */
+static int max78m6610_lmu_read_raw(struct iio_dev *indio_dev,
+			   struct iio_chan_spec const *chan,
+			   int *val,
+			   int *val2,
+			   long m)
+{
+	int ret;
+	u32 regval;
+	struct max78m6610_lmu_state *st = iio_priv(indio_dev);
+
+	switch (m) {
+
+	case IIO_CHAN_INFO_RAW:
+		mutex_lock(&indio_dev->mlock);
+		if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
+			mutex_unlock(&indio_dev->mlock);
+			return -EBUSY;
+		}
+
+		ret = __max78m6610_lmu_spi_reg_read(st, chan->address, &regval);
+		mutex_unlock(&indio_dev->mlock);
+		if (ret)
+			return ret;
+
+		*val = sign_extend32(regval, SIGN_BIT_NUM);
+		*val2 = chan->scan_type.shift;
+
+		ret_fraction_log2(val, val2);
+		return IIO_VAL_INT_PLUS_NANO;
+
+		/* the full scale units : -1.0 to 1-LSB (0x7FFFFF)
+		 * As an example, if 230V-peak at the input to the voltage
+		 * divider gives 250mV-peak at the chip input, one would get a
+		 * full scale register reading of 1 - LSB (0x7FFFFF) for
+		 * instaneous voltage.
+		 * Similarly, if 30Apk at the sensor input provides 250mV-peak
+		 * to the chip input, a full scale register value of 1 - LSB
+		 * (0x7FFFFF) for instanteous current would correspond to
+		 * 30 amps.
+		 * Full scale watts correspond to the result of full scale
+		 * current and voltage so, in this example, full scale watts
+		 * is 230 x 30 or 6900 watts.
+		 */
+
+	case IIO_CHAN_INFO_SCALE:
+		switch (chan->type) {
+		case IIO_CURRENT:
+			*val = 250; /* unit mV */
+			return IIO_VAL_INT;
+
+		case IIO_VOLTAGE:
+			*val = 250; /* unit: mV */
+			return IIO_VAL_INT;
+
+		case IIO_POWER:
+			*val = 250*250; /* uV */
+			return IIO_VAL_INT;
+
+		default:
+			return -EINVAL;
+		}
+
+	}
+	return -EINVAL;
+}
+
+/**
+ * max78m6610_lmu_write_raw
+ *
+ * @param indio_dev: iio_dev pointer
+ * @param chan: pointer to iio channel spec struct
+ * @param val: input value pointer
+ * @param val2: input value 2 ponter
+ * @parma m: write mask indicating IIO info type
+ * @return: status indicating success (zero) or fail (non-zero)
+ *
+ * This function will be invoked on a request to write a value to the device.
+ * Write mask specifies an IIO value type, val and val2 contain the integer and
+ * fractional elements of the floating point input value (INT+NANO).
+ */
+static int max78m6610_lmu_write_raw(struct iio_dev *indio_dev,
+				    struct iio_chan_spec const *chan,
+				    int val,
+				    int val2,
+				    long m)
+{
+	int ret;
+	u32 regval;
+	struct max78m6610_lmu_state *st = iio_priv(indio_dev);
+
+	mutex_lock(&indio_dev->mlock);
+	if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
+		ret = -EBUSY;
+		goto exit_unlock;
+	}
+
+	switch (m) {
+
+	case IIO_CHAN_INFO_RAW:
+		ret = intplusnano_to_regval(val, val2,
+					    chan->scan_type.shift, &regval);
+		if (ret)
+			goto exit_unlock;
+
+		ret = __max78m6610_lmu_spi_reg_write(st, chan->address, regval);
+		break;
+
+	default:
+		pr_err("Invalid channel selected for writing\n");
+		ret = -EINVAL;
+		goto exit_unlock;
+	}
+
+exit_unlock:
+	mutex_unlock(&indio_dev->mlock);
+
+	return ret;
+}
+
+/**
+ * max78m6610_lmu_write_raw_get_fmt
+ *
+ * @param indio_dev: iio_dev pointer
+ * @param chan: pointer to iio channel spec struct
+ * @param mask: specifies which value to be written
+ * @return: the format specifier for the channel value to be written
+ *
+ * IIO will query the expected format of the input value, and will then
+ * interpret and format it correctly before passing it to
+ * max78m6610_lmu_write_raw().  In all cases, we expect floating point
+ * numbers as input, which IIO will convert into integer and fractional parts
+ */
+static int max78m6610_lmu_write_raw_get_fmt(struct iio_dev *indio_dev,
+					    struct iio_chan_spec const *chan,
+					    long mask)
+{
+	return IIO_VAL_INT_PLUS_NANO;
+}
+
+
+/**
+ * max78m6610_lmu_reg_access
+ *
+ * @param indio_dev: iio_dev pointer
+ * @param reg: register address
+ * @param writeval: register value to write (ignored if readval is set)
+ * @parma readval: pointer to return register read result (set NULL for write)
+ * @return: status indicating success (zero) or fail (non-zero)
+ *
+ * This function allows direct read/write access MAX78M6610+LMU registers
+ * for debug only
+ */
+static int max78m6610_lmu_reg_access(struct iio_dev *indio_dev,
+				     unsigned reg, unsigned writeval,
+				     unsigned *readval)
+{
+	struct max78m6610_lmu_state *st = iio_priv(indio_dev);
+	int ret = 0;
+
+	mutex_lock(&indio_dev->mlock);
+	if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
+		ret = -EBUSY;
+		goto exit_unlock;
+	}
+
+	if (readval)
+		ret = __max78m6610_lmu_spi_reg_read(st, reg, readval);
+	else
+		ret = __max78m6610_lmu_spi_reg_write(st, reg, writeval);
+
+exit_unlock:
+	mutex_unlock(&indio_dev->mlock);
+
+	return ret;
+}
+
+/**
+ * max78m6610_lmu_reset
+ *
+ * @param indio_dev: iio_dev pointer
+ *
+ * Executes a reset of the MAX78M6610+LMU by briefly asserting the
+ * hardware reset signal for the device.  Volatile register values
+ * will revert to power-on default values.
+ */
+static int max78m6610_lmu_reset(struct iio_dev *indio_dev)
+{
+	struct max78m6610_lmu_state *st = iio_priv(indio_dev);
+	int ret = 0;
+	int gpio = st->reset_gpio;
+
+	struct gpio device_reset_gpio = {
+		gpio,
+		GPIOF_OUT_INIT_HIGH,
+		"max78m6610_lmu_reset"
+	};
+
+	if (gpio < 0) {
+		pr_err("Reset GPIO has not been configured\n");
+		return -ENXIO;
+	}
+
+	mutex_lock(&indio_dev->mlock);
+	if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
+		ret = -EBUSY;
+		goto exit_unlock;
+	}
+
+	ret = gpio_request_array(&device_reset_gpio, 1);
+	if (ret) {
+		pr_err("%s: Failed to allocate Device Reset GPIO pin\n",
+				__func__);
+		goto exit_unlock;
+	}
+	gpio_set_value(gpio, 0);
+	msleep(RESET_DELAY_MSEC);
+	gpio_set_value(gpio, 1);
+	msleep(RESET_DELAY_MSEC);
+
+	gpio_free_array(&device_reset_gpio, 1);
+
+exit_unlock:
+	mutex_unlock(&indio_dev->mlock);
+
+	return ret;
+}
+
+/**
+ * max78m6610_lmu_write_reset
+ *
+ * @param dev: device descriptor associated with sysfs attribute node
+ * @param attr: device sysfs attribute descriptor
+ * @param buf: data written by user to the attribute node
+ * @param len: length in bytes of data written by user
+ *
+ * This handles a write to this sysfs node from user-space, and invokes a
+ * reset of the MAX78M6610+LMU if an appropriate value is written.
+ * Valid input character values are 1, y and Y
+ */
+static ssize_t max78m6610_lmu_write_reset(struct device *dev,
+		struct device_attribute *attr,
+		const char *buf, size_t len)
+{
+	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	int ret = 0;
+
+	if (len < 1)
+		return -1;
+	switch (buf[0]) {
+	case '1':
+	case 'y':
+	case 'Y':
+		ret = max78m6610_lmu_reset(indio_dev);
+		return ret ? ret : len;
+	}
+	return -1;
+}
+
+/**
+ * max78m6610_lmu_calib_cmd
+ *
+ * @param indio_dev: iio_dev pointer
+ * @param calib_command: 24-bit calibration command value
+ *
+ * Executes a specified calibration command on the MAX78M6610+LMU
+ * The calib_command input value is written directly to the COMMAND
+ * register on the device, to invoke a selected automatic calibration
+ * routine.  The driver waits until the calibration completes, and then
+ * checks the status (depending on the specific command)
+ */
+static int max78m6610_lmu_calib_cmd(struct iio_dev *indio_dev,
+				    u32 calib_command)
+{
+	struct max78m6610_lmu_state *st = iio_priv(indio_dev);
+	u32 samples, calcycs;
+	unsigned delay_ms;
+	int max_retries = 5;
+	int ret = 0;
+
+	mutex_lock(&indio_dev->mlock);
+	if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
+		ret = -EBUSY;
+		goto exit_unlock;
+	}
+
+	/* Calculate the delay required for calibration to complete */
+	ret = __max78m6610_lmu_spi_reg_read(st, SAMPLES, &samples);
+	if (ret)
+		goto exit_unlock;
+	ret = __max78m6610_lmu_spi_reg_read(st, CALCYCS, &calcycs);
+	if (ret)
+		goto exit_unlock;
+	delay_ms = (samples * calcycs * SAMPLE_INTERVAL_USEC)/1000;
+
+	ret = __max78m6610_lmu_spi_reg_write(st, COMMAND, calib_command);
+	if (ret)
+		goto exit_unlock;
+
+	do {
+		/* Wait for the calibration to complete */
+		mdelay(delay_ms);
+
+		ret = __max78m6610_lmu_spi_reg_read(st, COMMAND,
+						    &calib_command);
+		if (ret)
+			goto exit_unlock;
+	} while ((calib_command & 0xFF0000) && (max_retries--));
+
+	if (max_retries <= 0) {
+		pr_err("Timed out waiting for calibration to complete\n");
+		ret = -EIO;
+		goto exit_unlock;
+	}
+
+	/* Gain calibration commands (bit 9 unset) can be checked for failure */
+	if ((!(calib_command & 0x000200)) && (calib_command & 0x007800)) {
+		pr_err("Calibration failed: COMMAND=0x%06X\n", calib_command);
+		ret = -EFAULT;
+	}
+
+exit_unlock:
+	mutex_unlock(&indio_dev->mlock);
+
+	return ret;
+}
+
+/**
+ * max78m6610_lmu_write_calib
+ *
+ * @param dev: device descriptor associated with sysfs attribute node
+ * @param attr: device sysfs attribute descriptor
+ * @param buf: data written by user to the attribute node
+ * @param len: length in bytes of data written by user
+ *
+ * This handles a write to this sysfs node from user-space, and invokes a
+ * calibration command on the MAX78M6610+LMU if an appropriate value is written.
+ * Valid input character values are 1, y and Y.
+ * The handler is re-used for multiple calibration commands, so the command
+ * value is passed transparently via the attribute address field
+ */
+static ssize_t max78m6610_lmu_write_calib(struct device *dev,
+		struct device_attribute *attr,
+		const char *buf, size_t len)
+{
+	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
+	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	int ret = 0;
+
+	if (len < 1)
+		return -1;
+	switch (buf[0]) {
+	case '1':
+	case 'y':
+	case 'Y':
+		ret = max78m6610_lmu_calib_cmd(indio_dev, this_attr->address);
+		return ret ? ret : len;
+	}
+	return -1;
+}
+
+/**
+ * max78m6610_lmu_flash_save_cmd
+ *
+ * @param indio_dev: iio_dev pointer
+ *
+ * Executes a flash-save command on the MAX78M6610+LMU.
+ * This saves all current volatile register values to flash on the device,
+ * making them persistent across device resets or power cycles.
+ */
+static int max78m6610_lmu_flash_save_cmd(struct iio_dev *indio_dev)
+{
+	struct max78m6610_lmu_state *st = iio_priv(indio_dev);
+	int ret = 0;
+
+	mutex_lock(&indio_dev->mlock);
+	if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
+		ret = -EBUSY;
+		goto exit_unlock;
+	}
+
+	ret = __max78m6610_lmu_spi_reg_write(st, COMMAND, FLASHSAVE_CMD);
+
+exit_unlock:
+	mutex_unlock(&indio_dev->mlock);
+
+	return ret;
+}
+
+/**
+ * max78m6610_lmu_write_flash
+ *
+ * @param dev: device descriptor associated with sysfs attribute node
+ * @param attr: device sysfs attribute descriptor
+ * @param buf: data written by user to the attribute node
+ * @param len: length in bytes of data written by user
+ *
+ * This handles a write to this sysfs node from user-space, and invokes a
+ * flash-save command on the MAX78M6610+LMU if an appropriate value is written.
+ * Valid input character values are 1, y and Y.
+ */
+static ssize_t max78m6610_lmu_write_flash(struct device *dev,
+		struct device_attribute *attr,
+		const char *buf, size_t len)
+{
+	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	int ret = 0;
+
+	if (len < 1)
+		return -1;
+	switch (buf[0]) {
+	case '1':
+	case 'y':
+	case 'Y':
+		ret = max78m6610_lmu_flash_save_cmd(indio_dev);
+		return ret ? ret : len;
+	}
+	return -1;
+}
+
+/**
+ * max78m6610_lmu_flash_save_cmd
+ *
+ * @param indio_dev: iio_dev pointer
+ *
+ * Executes a read of the STATUS register on the MAX78M6610+LMU.
+ * Event status bits are checked, and event notifications are raised for
+ * user-space applications if any events are asserted. Event status bits are
+ * sticky and are cleared by setting the corresponding bit in the STATUS_RESET
+ * register to allow further occurances of the same event to be detected
+ */
+static int max78m6610_lmu_status_scan(struct iio_dev *indio_dev)
+{
+	struct max78m6610_lmu_state *st = iio_priv(indio_dev);
+	unsigned status;
+	int ret;
+	u64 timestamp_ns = iio_get_time_ns();
+
+	mutex_lock(&indio_dev->mlock);
+	if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
+		ret = -EBUSY;
+		goto exit_unlock;
+	}
+
+	ret = __max78m6610_lmu_spi_reg_read(st, STATUS, &status);
+	if (ret) {
+		pr_err("Failed to read STATUS register\n");
+		goto exit_unlock;
+	}
+
+	status &= ~STATUS_MASK_IGNORE;
+
+	/* Nothing more to do if no interesting status bits are set */
+	if (!status)
+		goto exit_unlock;
+
+	/* Not all of the event types used below are ideal, but there is a
+	 * limited set available and we want to use different event types for
+	 * the different events (e.g sag vs. min-threshold) to allow user
+	 * applications to distinguish them
+	 */
+	if (status & STATUS_MASK_VA_SAG) {
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 0,
+						    IIO_EV_TYPE_MAG,
+						    IIO_EV_DIR_FALLING),
+			       timestamp_ns);
+	}
+	if (status & STATUS_MASK_VB_SAG) {
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 1,
+						    IIO_EV_TYPE_MAG,
+						    IIO_EV_DIR_FALLING),
+			       timestamp_ns);
+	}
+	if (status & STATUS_MASK_OV_VRMSA) {
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 0,
+						    IIO_EV_TYPE_THRESH,
+						    IIO_EV_DIR_RISING),
+			       timestamp_ns);
+	}
+	if (status & STATUS_MASK_UN_VRMSA) {
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 0,
+						    IIO_EV_TYPE_THRESH,
+						    IIO_EV_DIR_FALLING),
+			       timestamp_ns);
+	}
+	if (status & STATUS_MASK_OV_VRMSB) {
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 1,
+						    IIO_EV_TYPE_THRESH,
+						    IIO_EV_DIR_RISING),
+			       timestamp_ns);
+	}
+	if (status & STATUS_MASK_UN_VRMSB) {
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 1,
+						    IIO_EV_TYPE_THRESH,
+						    IIO_EV_DIR_FALLING),
+			       timestamp_ns);
+	}
+	if (status & STATUS_MASK_VA_SURGE) {
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 0,
+						    IIO_EV_TYPE_MAG,
+						    IIO_EV_DIR_RISING),
+			       timestamp_ns);
+	}
+	if (status & STATUS_MASK_VB_SURGE) {
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 1,
+						    IIO_EV_TYPE_MAG,
+						    IIO_EV_DIR_RISING),
+			       timestamp_ns);
+	}
+	if (status & STATUS_MASK_OV_WATT1) {
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_POWER, 0,
+						    IIO_EV_TYPE_THRESH,
+						    IIO_EV_DIR_RISING),
+			       timestamp_ns);
+	}
+	if (status & STATUS_MASK_OV_WATT2) {
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_POWER, 1,
+						    IIO_EV_TYPE_THRESH,
+						    IIO_EV_DIR_RISING),
+			       timestamp_ns);
+	}
+	if (status & STATUS_MASK_OV_AMP1) {
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_CURRENT, 0,
+						    IIO_EV_TYPE_THRESH,
+						    IIO_EV_DIR_RISING),
+			       timestamp_ns);
+	}
+	if (status & STATUS_MASK_OV_AMP2) {
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_CURRENT, 1,
+						    IIO_EV_TYPE_THRESH,
+						    IIO_EV_DIR_RISING),
+			       timestamp_ns);
+	}
+
+	ret = __max78m6610_lmu_spi_reg_write(st, STATUS_RESET,
+					     status & STATUS_MASK_STICKY);
+	if (ret) {
+		pr_err("Failed to write STATUS_RESET register\n");
+		goto exit_unlock;
+	}
+
+exit_unlock:
+	mutex_unlock(&indio_dev->mlock);
+
+	return ret;
+}
+
+/**
+ * max78m6610_lmu_write_status_scan
+ *
+ * @param dev: device descriptor associated with sysfs attribute node
+ * @param attr: device sysfs attribute descriptor
+ * @param buf: data written by user to the attribute node
+ * @param len: length in bytes of data written by user
+ *
+ * This handles a write to this sysfs node from user-space, and invokes a
+ * read of the status register on the MAX78M6610+LMU if an appropriate value
+ * is written.  Valid input character values are 1, y and Y
+ */
+static ssize_t max78m6610_lmu_write_status_scan(struct device *dev,
+		struct device_attribute *attr,
+		const char *buf, size_t len)
+{
+	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	int ret = 0;
+
+	if (len < 1)
+		return -1;
+	switch (buf[0]) {
+	case '1':
+	case 'y':
+	case 'Y':
+		ret = max78m6610_lmu_status_scan(indio_dev);
+		return ret ? ret : len;
+	}
+	return -1;
+}
+
+/**
+ * max78m6610_lmu_write_int
+ *
+ * @param dev: device descriptor associated with sysfs attribute node
+ * @param attr: device sysfs attribute descriptor
+ * @param buf: data written by user to the attribute node
+ * @param len: length in bytes of data written by user
+ *
+ * This is a generic handler to write integer values to any integer registers
+ * which are exposed as device sysfs attributes on the user interface.
+ * The attribute address field specifies which register to write.
+ */
+
+static IIO_DEVICE_ATTR(do_reset, S_IWUSR, NULL,
+		       max78m6610_lmu_write_reset, 0);
+static IIO_DEVICE_ATTR(do_voltage0_gain_calib, S_IWUSR, NULL,
+		       max78m6610_lmu_write_calib, CALCMD_S0_GAIN);
+static IIO_DEVICE_ATTR(do_current0_gain_calib, S_IWUSR, NULL,
+		       max78m6610_lmu_write_calib, CALCMD_S1_GAIN);
+static IIO_DEVICE_ATTR(do_voltage1_gain_calib, S_IWUSR, NULL,
+		       max78m6610_lmu_write_calib, CALCMD_S2_GAIN);
+static IIO_DEVICE_ATTR(do_current1_gain_calib, S_IWUSR, NULL,
+		       max78m6610_lmu_write_calib, CALCMD_S3_GAIN);
+static IIO_DEVICE_ATTR(do_voltage0_offset_calib, S_IWUSR, NULL,
+		       max78m6610_lmu_write_calib, CALCMD_S0_OFFS);
+static IIO_DEVICE_ATTR(do_current0_offset_calib, S_IWUSR, NULL,
+		       max78m6610_lmu_write_calib, CALCMD_S1_OFFS);
+static IIO_DEVICE_ATTR(do_voltage1_offset_calib, S_IWUSR, NULL,
+		       max78m6610_lmu_write_calib, CALCMD_S2_OFFS);
+static IIO_DEVICE_ATTR(do_current1_offset_calib, S_IWUSR, NULL,
+		       max78m6610_lmu_write_calib, CALCMD_S3_OFFS);
+static IIO_DEVICE_ATTR(do_save_to_flash, S_IWUSR, NULL,
+		       max78m6610_lmu_write_flash, 0);
+
+static struct attribute *max78m6610_lmu_attributes[] = {
+	&iio_dev_attr_do_reset.dev_attr.attr,
+	&iio_dev_attr_do_voltage0_gain_calib.dev_attr.attr,
+	&iio_dev_attr_do_current0_gain_calib.dev_attr.attr,
+	&iio_dev_attr_do_voltage1_gain_calib.dev_attr.attr,
+	&iio_dev_attr_do_current1_gain_calib.dev_attr.attr,
+	&iio_dev_attr_do_voltage0_offset_calib.dev_attr.attr,
+	&iio_dev_attr_do_current0_offset_calib.dev_attr.attr,
+	&iio_dev_attr_do_voltage1_offset_calib.dev_attr.attr,
+	&iio_dev_attr_do_current1_offset_calib.dev_attr.attr,
+	&iio_dev_attr_do_save_to_flash.dev_attr.attr,
+	NULL,
+};
+
+static const struct attribute_group max78m6610_lmu_attribute_group = {
+	.attrs = max78m6610_lmu_attributes,
+};
+
+/* Provides an option to poll for events (useful if interrupts unavailable) */
+static IIO_DEVICE_ATTR(do_status_scan, S_IWUSR, NULL,
+		       max78m6610_lmu_write_status_scan, 0);
+
+/* Need to have at least 1 event attribute to enable IIO events.
+ * Purposely not setting .event_mask for the channels because that would
+ * enable the IIO events sysfs entries which are not suitable for this driver
+ */
+static struct attribute *max78m6610_lmu_event_attributes[] = {
+	&iio_dev_attr_do_status_scan.dev_attr.attr,
+	NULL,
+};
+
+static struct attribute_group max78m6610_lmu_event_attribute_group = {
+	.attrs = max78m6610_lmu_event_attributes,
+};
+
+
+/* Driver specific iio info structure */
+static const struct iio_info max78m6610_lmu_info = {
+	.read_raw = max78m6610_lmu_read_raw,
+	.write_raw = max78m6610_lmu_write_raw,
+	.write_raw_get_fmt = max78m6610_lmu_write_raw_get_fmt,
+	.debugfs_reg_access = max78m6610_lmu_reg_access,
+	.update_scan_mode = max78m6610_lmu_update_scan_mode,
+	.event_attrs = &max78m6610_lmu_event_attribute_group,
+	.attrs = &max78m6610_lmu_attribute_group,
+	.driver_module = THIS_MODULE,
+};
+
+/**
+ * max78m6610_lmu_open
+ *
+ * @param inode: inode descriptor associated with char device
+ * @param filp: file object pointer
+ * @return 0 on success, non-zero errno otherwise
+ *
+ * This handles an open syscall on the character device node
+ */
+static int
+max78m6610_lmu_open(struct inode *inode, struct file *filp)
+{
+	struct max78m6610_lmu_state *st;
+	int ret = 0;
+
+	st = container_of(inode->i_cdev,
+			    struct max78m6610_lmu_state,
+			    cdev);
+	filp->private_data = st;
+
+	if (!st->bbuffer) {
+		st->bbuffer = kmalloc(SPI_BBUFFER_LEN, GFP_KERNEL);
+		if (!st->bbuffer) {
+			dev_dbg(&st->spi->dev, "open/ENOMEM\n");
+			ret = -ENOMEM;
+		}
+	}
+
+	return ret;
+}
+
+/**
+ * max78m6610_lmu_release
+ *
+ * @param inode: inode descriptor associated with char device
+ * @param filp: file object pointer
+ * @return 0 on success, non-zero errno otherwise
+ *
+ * This handles a close syscall on the character device node
+ */
+static int
+max78m6610_lmu_release(struct inode *inode, struct file *filp)
+{
+	struct max78m6610_lmu_state *st =
+		(struct max78m6610_lmu_state *)filp->private_data;
+
+	kfree(st->bbuffer);
+	st->bbuffer = NULL;
+
+	return 0;
+}
+
+/**
+ * spidev_message
+ *
+ * @param st: driver state information
+ * @param u_xfers: spi transfer descriptor array
+ * @param n_xfers: number of spi transfer descriptors
+ * @return 0 on success, non-zero errno otherwise
+ *
+ * Translates a set of user-space SPI transfer requests to kernel-space
+ * equivalent, using bounce-buffers for the data, and invokes spi_sync()
+ * to execute the bi-directional SPI transfers
+ *
+ * The implementation below was borrowed directly from the spidev kernel driver
+ * with minor modifications to fit it in here
+ */
+static int spidev_message(struct max78m6610_lmu_state *st,
+			  struct spi_ioc_transfer *u_xfers,
+			  unsigned n_xfers)
+{
+	struct spi_message	msg;
+	struct spi_transfer	*k_xfers;
+	struct spi_transfer	*k_tmp;
+	struct spi_ioc_transfer *u_tmp;
+	unsigned		n, total;
+	u8			*buf;
+	int			status = -EFAULT;
+
+	spi_message_init(&msg);
+	k_xfers = kcalloc(n_xfers, sizeof(*k_tmp), GFP_KERNEL);
+	if (k_xfers == NULL)
+		return -ENOMEM;
+
+	/* Construct spi_message, copying any tx data to bounce buffer.
+	 * We walk the array of user-provided transfers, using each one
+	 * to initialize a kernel version of the same transfer.
+	 */
+	buf = st->bbuffer;
+	total = 0;
+	for (n = n_xfers, k_tmp = k_xfers, u_tmp = u_xfers;
+			n;
+			n--, k_tmp++, u_tmp++) {
+		k_tmp->len = u_tmp->len;
+
+		total += k_tmp->len;
+		if (total > SPI_BBUFFER_LEN) {
+			status = -EMSGSIZE;
+			goto done;
+		}
+
+		if (u_tmp->rx_buf) {
+			k_tmp->rx_buf = buf;
+			if (!access_ok(VERIFY_WRITE, (u8 __user *)
+						(uintptr_t) u_tmp->rx_buf,
+						u_tmp->len))
+				goto done;
+		}
+		if (u_tmp->tx_buf) {
+			k_tmp->tx_buf = buf;
+			if (copy_from_user(buf, (const u8 __user *)
+						(uintptr_t) u_tmp->tx_buf,
+					u_tmp->len))
+				goto done;
+		}
+		buf += k_tmp->len;
+
+		k_tmp->cs_change = !!u_tmp->cs_change;
+		k_tmp->bits_per_word = u_tmp->bits_per_word;
+		k_tmp->delay_usecs = u_tmp->delay_usecs;
+		k_tmp->speed_hz = u_tmp->speed_hz;
+#ifdef VERBOSE
+		dev_dbg(&st->spi->dev,
+			"  xfer len %zd %s%s%s%dbits %u usec %uHz\n",
+			u_tmp->len,
+			u_tmp->rx_buf ? "rx " : "",
+			u_tmp->tx_buf ? "tx " : "",
+			u_tmp->cs_change ? "cs " : "",
+			u_tmp->bits_per_word ? : st->spi->bits_per_word,
+			u_tmp->delay_usecs,
+			u_tmp->speed_hz ? : st->spi->max_speed_hz);
+#endif
+		spi_message_add_tail(k_tmp, &msg);
+	}
+
+	status = spi_sync(st->spi, &msg);
+	if (status < 0)
+		goto done;
+
+	/* copy any rx data out of bounce buffer */
+	buf = st->bbuffer;
+	for (n = n_xfers, u_tmp = u_xfers; n; n--, u_tmp++) {
+		if (u_tmp->rx_buf) {
+			if (__copy_to_user((u8 __user *)
+					(uintptr_t) u_tmp->rx_buf, buf,
+					u_tmp->len)) {
+				status = -EFAULT;
+				goto done;
+			}
+		}
+		buf += u_tmp->len;
+	}
+	status = total;
+
+done:
+	kfree(k_xfers);
+	return status;
+}
+
+/**
+ * max78m6610_lmu_ioctl
+ *
+ * @param filp: file object pointer
+ * @param cmd: ioctl command
+ * @param arg: optional data argument
+ * @return 0 on success, non-zero errno otherwise
+ *
+ * This handles an ioctl syscall on the character device node.  This handler
+ * supports only the SPI_IOC_MESSAGE ioctl command defined in spidev.h
+ * The implementation below was borrowed from the spidev driver, with some minor
+ * modifications to remove support for other ioctl commands not needed here
+ */
+static long
+max78m6610_lmu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+	struct max78m6610_lmu_state *st = filp->private_data;
+	struct iio_dev *indio_dev = spi_get_drvdata(st->spi);
+	u32			tmp;
+	unsigned		n_ioc;
+	struct spi_ioc_transfer	*ioc;
+	int ret = 0;
+
+	/* Check type and command number */
+	if (_IOC_TYPE(cmd) != SPI_IOC_MAGIC)
+		return -ENOTTY;
+
+	/* Check access direction once here; don't repeat below.
+	 * IOC_DIR is from the user perspective, while access_ok is
+	 * from the kernel perspective; so they look reversed.
+	 */
+	if (_IOC_DIR(cmd) & _IOC_READ)
+		ret = !access_ok(VERIFY_WRITE,
+				(void __user *)arg, _IOC_SIZE(cmd));
+	if (ret == 0 && _IOC_DIR(cmd) & _IOC_WRITE)
+		ret = !access_ok(VERIFY_READ,
+				(void __user *)arg, _IOC_SIZE(cmd));
+	if (ret)
+		return -EFAULT;
+
+	ret = mutex_lock_interruptible(&indio_dev->mlock);
+	if (ret)
+		return ret;
+
+	/* segmented and/or full-duplex I/O request */
+	if (_IOC_NR(cmd) != _IOC_NR(SPI_IOC_MESSAGE(0))
+	    || _IOC_DIR(cmd) != _IOC_WRITE) {
+		ret = -ENOTTY;
+		goto exit;
+	}
+
+	tmp = _IOC_SIZE(cmd);
+	if ((tmp % sizeof(struct spi_ioc_transfer)) != 0) {
+		ret = -EINVAL;
+		goto exit;
+	}
+	n_ioc = tmp / sizeof(struct spi_ioc_transfer);
+	if (n_ioc == 0)
+		goto exit;
+
+	/* copy into scratch area */
+	ioc = kmalloc(tmp, GFP_KERNEL);
+	if (!ioc) {
+		ret = -ENOMEM;
+		goto exit;
+	}
+	if (__copy_from_user(ioc, (void __user *)arg, tmp)) {
+		kfree(ioc);
+		ret = -EFAULT;
+		goto exit;
+	}
+
+	/* translate to spi_message, execute */
+	ret = spidev_message(st, ioc, n_ioc);
+	kfree(ioc);
+
+exit:
+	mutex_unlock(&indio_dev->mlock);
+
+	return ret;
+}
+
+static const struct file_operations max78m6610_lmu_fops = {
+	.owner = THIS_MODULE,
+	.open = max78m6610_lmu_open,
+	.release = max78m6610_lmu_release,
+	.unlocked_ioctl = max78m6610_lmu_ioctl,
+};
+
+/**
+ * max78m6610_lmu_chrdev_init
+ *
+ * @param st: driver state information
+ * @return 0 on success, non-zero errno otherwise
+ *
+ * Creates a character device to implement a subset of the spidev user-interface
+ * API, namely full-duplex SPI transfers via the ioctl() interface.
+ * The intention is to provide user-space applications with direct access to the
+ * underlying SPI device if required.  The user-space application is, in this
+ * mode of operation, responsible for directly constructing the SPI messages
+ * required by the MAX78M6610 and those messages are passed transparently
+ * through this driver.  This is needed, for example, to facilitate binary-only
+ * firmware update applications, but may also be used by user-space applications
+ * to access any device registers which have not been exposed by this driver.
+ *
+ * The device node created will appear in the filesystem as /dev/max78m6610_lmu
+ */
+static int
+max78m6610_lmu_chrdev_init(struct max78m6610_lmu_state *st)
+{
+	int ret;
+	struct device *dev;
+
+	ret = alloc_chrdev_region(&st->cdev_no, 0, 1,
+				  "max78m6610_lmu");
+	if (ret) {
+		pr_err("Failed to alloc chrdev: %d", ret);
+		return ret;
+	}
+
+	cdev_init(&st->cdev, &max78m6610_lmu_fops);
+
+	ret = cdev_add(&st->cdev, st->cdev_no, 1);
+	if (ret) {
+		pr_err("Failed to add cdev: %d", ret);
+		unregister_chrdev_region(st->cdev_no, 1);
+		return ret;
+	}
+
+	st->cl = class_create(THIS_MODULE, "char");
+	if (IS_ERR(st->cl)) {
+		pr_err("Failed to create device class: %ld",
+		       PTR_ERR(st->cl));
+		cdev_del(&st->cdev);
+		unregister_chrdev_region(st->cdev_no, 1);
+		return PTR_ERR(st->cl);
+	}
+
+	dev = device_create(st->cl, NULL, st->cdev_no, NULL,
+			    "max78m6610_lmu");
+	if (IS_ERR(dev)) {
+		pr_err("Failed to create device: %ld",
+		       PTR_ERR(st->cl));
+		class_destroy(st->cl);
+		cdev_del(&st->cdev);
+		unregister_chrdev_region(st->cdev_no, 1);
+		return PTR_ERR(dev);
+	}
+
+	return 0;
+}
+
+/**
+ * max78m6610_lmu_chrdev_remove
+ *
+ * @param st: driver state information
+ * @return 0 on success, non-zero errno otherwise
+ *
+ * Remove the character device created by max78m6610_lmu_chrdev_init()
+ */
+static int
+max78m6610_lmu_chrdev_remove(struct max78m6610_lmu_state *st)
+{
+	device_destroy(st->cl, st->cdev_no);
+	class_destroy(st->cl);
+	cdev_del(&st->cdev);
+	unregister_chrdev_region(st->cdev_no, 1);
+
+	return 0;
+}
+
+/**
+ * max78m6610_lmu_probe
+ *
+ * @param spi: spi device pointer
+ * @return: return 0 or standard errorids if failure
+ *
+ * device driver probe funciton for iio_dev struct initialisation.
+ */
+static int max78m6610_lmu_probe(struct spi_device *spi)
+{
+	struct max78m6610_lmu_state *st;
+	struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
+	struct max78m6610_lmu_platform_data *pdata = spi->dev.platform_data;
+	int ret;
+
+	if (indio_dev == NULL)
+		return -ENOMEM;
+	st = iio_priv(indio_dev);
+
+	spi_set_drvdata(spi, indio_dev);
+	st->spi = spi;
+
+	if (pdata)
+		st->reset_gpio = pdata->reset_gpio;
+	else
+		st->reset_gpio = -1;
+
+	indio_dev->name = spi_get_device_id(spi)->name;
+	indio_dev->dev.parent = &spi->dev;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->channels = max78m6610_lmu_channels;
+	indio_dev->num_channels = ARRAY_SIZE(max78m6610_lmu_channels);
+	indio_dev->info = &max78m6610_lmu_info;
+
+	/* Setup default message */
+	st->scan_single_xfer.tx_buf = &st->tx_buf[0];
+	st->scan_single_xfer.rx_buf = &st->rx_buf[0];
+	st->scan_single_xfer.len = SPI_MSG_LEN;
+
+	spi_message_init(&st->scan_single_msg);
+	spi_message_add_tail(&st->scan_single_xfer, &st->scan_single_msg);
+
+	ret = iio_triggered_buffer_setup(indio_dev, NULL,
+			&max78m6610_lmu_trigger_handler, NULL);
+	if (ret) {
+		pr_err("triger buffer setup failed !\n");
+		goto error_free;
+	}
+
+	pr_debug("%s: alloc dev id: %d\n", __func__, indio_dev->id);
+	ret = iio_device_register(indio_dev);
+	if (ret)
+		goto error_cleanup_ring;
+
+	ret = max78m6610_lmu_chrdev_init(st);
+	if (ret)
+		goto error_cleanup_ring;
+
+	return 0;
+
+error_cleanup_ring:
+	iio_triggered_buffer_cleanup(indio_dev);
+error_free:
+	iio_device_free(indio_dev);
+
+	return ret;
+}
+
+/**
+ * max78m6610_lmu_remove
+ *
+ * @param spi: spi device pointer
+ * @return: return 0
+ *
+ * iio device unregister & cleanup
+ */
+static int max78m6610_lmu_remove(struct spi_device *spi)
+{
+	struct iio_dev *indio_dev = spi_get_drvdata(spi);
+	struct max78m6610_lmu_state *st = iio_priv(indio_dev);
+
+	max78m6610_lmu_chrdev_remove(st);
+	iio_device_unregister(indio_dev);
+	iio_triggered_buffer_cleanup(indio_dev);
+	iio_device_free(indio_dev);
+
+	return 0;
+}
+
+static const struct spi_device_id max78m6610_lmu_id[] = {
+	{"max78m6610_lmu", 0},
+	{}
+};
+MODULE_DEVICE_TABLE(spi, max78m6610_lmu_id);
+
+static struct spi_driver max78m6610_lmu_driver = {
+	.driver = {
+		.name	= "max78m6610_lmu",
+		.owner	= THIS_MODULE,
+	},
+	.probe		= max78m6610_lmu_probe,
+	.remove		= max78m6610_lmu_remove,
+	.id_table	= max78m6610_lmu_id,
+};
+
+/**
+ * max78m6610_lmu_init
+ *
+ * device driver module init
+ */
+static __init int max78m6610_lmu_init(void)
+{
+	int ret;
+
+	ret = spi_register_driver(&max78m6610_lmu_driver);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+module_init(max78m6610_lmu_init);
+
+/**
+ * max78m6610_lmu_exit
+ *
+ * device driver module exit
+ */
+static __exit void max78m6610_lmu_exit(void)
+{
+	spi_unregister_driver(&max78m6610_lmu_driver);
+}
+module_exit(max78m6610_lmu_exit);
+
+
+MODULE_AUTHOR("Kai Ji <kai.ji@emutex.com>");
+MODULE_DESCRIPTION("Maxim 78M6610+LMU eADC");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/trigger/Kconfig b/drivers/staging/iio/trigger/Kconfig
index 7d32075..e9e837d 100644
--- a/drivers/staging/iio/trigger/Kconfig
+++ b/drivers/staging/iio/trigger/Kconfig
@@ -29,6 +29,17 @@ config IIO_SYSFS_TRIGGER
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called iio-trig-sysfs.
+ 
+config IIO_HRTIMER_TRIGGER
+	tristate "HRTIMER trigger"
+	#depends on HRTIMER
+	select IRQ_WORK
+	help
+	  Provides support for using HRTIMER entries as IIO triggers.
+	  If unsure, say N (but it's safe to say "Y").
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called iio-trig-hrtimer.
 
 config IIO_BFIN_TMR_TRIGGER
 	tristate "Blackfin TIMER trigger"
diff --git a/drivers/staging/iio/trigger/Makefile b/drivers/staging/iio/trigger/Makefile
index b088b57..ad2f595 100644
--- a/drivers/staging/iio/trigger/Makefile
+++ b/drivers/staging/iio/trigger/Makefile
@@ -5,4 +5,5 @@
 obj-$(CONFIG_IIO_PERIODIC_RTC_TRIGGER) += iio-trig-periodic-rtc.o
 obj-$(CONFIG_IIO_GPIO_TRIGGER) += iio-trig-gpio.o
 obj-$(CONFIG_IIO_SYSFS_TRIGGER) += iio-trig-sysfs.o
+obj-$(CONFIG_IIO_HRTIMER_TRIGGER) += iio-trig-hrtimer.o
 obj-$(CONFIG_IIO_BFIN_TMR_TRIGGER) += iio-trig-bfin-timer.o
diff --git a/drivers/staging/iio/trigger/iio-trig-hrtimer.c b/drivers/staging/iio/trigger/iio-trig-hrtimer.c
new file mode 100644
index 0000000..5dc30e5
--- /dev/null
+++ b/drivers/staging/iio/trigger/iio-trig-hrtimer.c
@@ -0,0 +1,288 @@
+/*
+ * Industrial I/O - hrtimer trigger support
+ *
+ * Copyright 2013 STMicroelectronics Inc.
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * 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.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/hrtimer.h>
+#include <linux/ktime.h>
+#include <linux/slab.h>
+#include <linux/list.h>
+
+#include <linux/iio/iio.h>
+#include <linux/iio/trigger.h>
+
+struct iio_hrtimer_trigger_data {
+	struct iio_trigger *trig;
+	struct hrtimer timer;
+	struct list_head l;
+	ktime_t period;
+	u16  freq;
+	int id;
+};
+
+static LIST_HEAD(iio_hrtimer_trigger_list);
+static DEFINE_MUTEX(iio_hrtimer_trigger_list_mut);
+
+static int iio_hrtimer_trigger_probe(int id);
+static int iio_hrtimer_trigger_remove(int id);
+
+static ssize_t iio_sysfs_hrtimer_trig_add(struct device *dev,
+		struct device_attribute *attr, const char *buf, size_t len)
+{
+	int ret;
+	unsigned long input;
+
+	ret = kstrtoul(buf, 10, &input);
+	if (ret)
+		return ret;
+
+	ret = iio_hrtimer_trigger_probe(input);
+	if (ret)
+		return ret;
+
+	return len;
+}
+static DEVICE_ATTR(add_trigger, S_IWUSR, NULL, &iio_sysfs_hrtimer_trig_add);
+
+static ssize_t iio_sysfs_hrtimer_trig_remove(struct device *dev,
+		struct device_attribute *attr, const char *buf, size_t len)
+{
+	int ret;
+	unsigned long input;
+
+	ret = kstrtoul(buf, 10, &input);
+	if (ret)
+		return ret;
+
+	ret = iio_hrtimer_trigger_remove(input);
+	if (ret)
+		return ret;
+
+	return len;
+}
+static DEVICE_ATTR(remove_trigger, S_IWUSR,
+					NULL, &iio_sysfs_hrtimer_trig_remove);
+
+static struct attribute *iio_hrtimer_trig_attrs[] = {
+	&dev_attr_add_trigger.attr,
+	&dev_attr_remove_trigger.attr,
+	NULL,
+};
+
+static const struct attribute_group iio_hrtimer_trig_group = {
+	.attrs = iio_hrtimer_trig_attrs,
+};
+
+static const struct attribute_group *iio_hrtimer_trig_groups[] = {
+	&iio_hrtimer_trig_group,
+	NULL,
+};
+
+/* Nothing to actually do upon release */
+static void iio_hrtimer_trig_release(struct device *dev)
+{
+}
+
+static struct device iio_hrtimer_trig_dev = {
+	.bus = &iio_bus_type,
+	.groups = iio_hrtimer_trig_groups,
+	.release = &iio_hrtimer_trig_release,
+};
+
+static int iio_hrtimer_trig_set_state(struct iio_trigger *trig, bool state)
+{
+	struct iio_hrtimer_trigger_data *trig_data =
+						dev_get_drvdata(&trig->dev);
+
+	if (trig_data->freq == 0)
+		return -EINVAL;
+
+	if (state)
+		hrtimer_start(&trig_data->timer,
+					trig_data->period, HRTIMER_MODE_REL);
+	else
+		hrtimer_cancel(&trig_data->timer);
+
+	return 0;
+}
+
+static ssize_t iio_hrtimer_trigger_set_freq_value(struct device *dev,
+		struct device_attribute *attr, const char *buf, size_t len)
+{
+	int ret;
+	u16 frequency;
+	struct iio_trigger *trig = to_iio_trigger(dev);
+	struct iio_hrtimer_trigger_data *trig_data =
+						dev_get_drvdata(&trig->dev);
+
+	ret = kstrtou16(buf, 10, &frequency);
+	if (ret < 0)
+		return ret;
+
+	if (frequency > NSEC_PER_SEC)
+		return -EINVAL;
+
+	trig_data->freq = frequency;
+
+	if (frequency)
+		trig_data->period =
+				ktime_set(0, NSEC_PER_SEC / trig_data->freq);
+
+	return len;
+}
+
+static ssize_t iio_hrtimer_trigger_get_freq_value(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	struct iio_trigger *trig = to_iio_trigger(dev);
+	struct iio_hrtimer_trigger_data *trig_data =
+						dev_get_drvdata(&trig->dev);
+
+	return sprintf(buf, "%hu\n", trig_data->freq);
+}
+
+static DEVICE_ATTR(frequency, S_IWUSR | S_IRUGO,
+					iio_hrtimer_trigger_get_freq_value,
+					iio_hrtimer_trigger_set_freq_value);
+
+static struct attribute *iio_hrtimer_trigger_attrs[] = {
+	&dev_attr_frequency.attr,
+	NULL,
+};
+
+static const struct attribute_group iio_hrtimer_trigger_attr_group = {
+	.attrs = iio_hrtimer_trigger_attrs,
+};
+
+static const struct attribute_group *iio_hrtimer_trigger_attr_groups[] = {
+	&iio_hrtimer_trigger_attr_group,
+	NULL,
+};
+
+static const struct iio_trigger_ops iio_hrtimer_trigger_ops = {
+	.owner = THIS_MODULE,
+	.set_trigger_state = &iio_hrtimer_trig_set_state,
+};
+
+enum hrtimer_restart iio_hrtimer_trigger_func(struct hrtimer *timer)
+{
+	struct iio_hrtimer_trigger_data *trig_data;
+
+	trig_data = container_of(timer, struct iio_hrtimer_trigger_data, timer);
+
+	hrtimer_forward_now(timer, trig_data->period);
+	iio_trigger_poll(trig_data->trig, 0);
+
+	return HRTIMER_RESTART;
+}
+
+static int iio_hrtimer_trigger_probe(int id)
+{
+	int err;
+	bool foundit = false;
+	struct iio_hrtimer_trigger_data *trig_data;
+
+	mutex_lock(&iio_hrtimer_trigger_list_mut);
+	list_for_each_entry(trig_data, &iio_hrtimer_trigger_list, l) {
+		if (id == trig_data->id) {
+			foundit = true;
+			break;
+		}
+	}
+	if (foundit) {
+		err = -EINVAL;
+		goto iio_hrtimer_mutex_unlock;
+	}
+
+	trig_data = kmalloc(sizeof(*trig_data), GFP_KERNEL);
+	if (trig_data == NULL) {
+		err = -ENOMEM;
+		goto iio_hrtimer_mutex_unlock;
+	}
+
+	trig_data->id = id;
+	trig_data->trig = iio_trigger_alloc("hrtimer_trig%d", id);
+	if (!trig_data->trig) {
+		err = -ENOMEM;
+		goto iio_hrtimer_free_trig_data;
+	}
+
+	trig_data->trig->dev.groups = iio_hrtimer_trigger_attr_groups;
+	trig_data->trig->ops = &iio_hrtimer_trigger_ops;
+	trig_data->trig->dev.parent = &iio_hrtimer_trig_dev;
+	dev_set_drvdata(&trig_data->trig->dev, trig_data);
+
+	trig_data->freq = 0;
+	hrtimer_init(&trig_data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+	trig_data->timer.function = &iio_hrtimer_trigger_func;
+
+	err = iio_trigger_register(trig_data->trig);
+	if (err)
+		goto iio_hrtimer_free_trig_data;
+
+	list_add(&trig_data->l, &iio_hrtimer_trigger_list);
+	__module_get(THIS_MODULE);
+	mutex_unlock(&iio_hrtimer_trigger_list_mut);
+
+	return 0;
+
+iio_hrtimer_free_trig_data:
+	kfree(trig_data);
+iio_hrtimer_mutex_unlock:
+	mutex_unlock(&iio_hrtimer_trigger_list_mut);
+	return err;
+}
+
+static int iio_hrtimer_trigger_remove(int id)
+{
+	bool foundit = false;
+	struct iio_hrtimer_trigger_data *trig_data;
+
+	mutex_lock(&iio_hrtimer_trigger_list_mut);
+	list_for_each_entry(trig_data, &iio_hrtimer_trigger_list, l) {
+		if (id == trig_data->id) {
+			foundit = true;
+			break;
+		}
+	}
+	if (!foundit) {
+		mutex_unlock(&iio_hrtimer_trigger_list_mut);
+		return -EINVAL;
+	}
+
+	iio_trigger_unregister(trig_data->trig);
+	iio_trigger_free(trig_data->trig);
+
+	list_del(&trig_data->l);
+	kfree(trig_data);
+	module_put(THIS_MODULE);
+	mutex_unlock(&iio_hrtimer_trigger_list_mut);
+
+	return 0;
+}
+
+static int __init iio_hrtimer_trig_init(void)
+{
+	device_initialize(&iio_hrtimer_trig_dev);
+	dev_set_name(&iio_hrtimer_trig_dev, "iio_hrtimer_trigger");
+	return device_add(&iio_hrtimer_trig_dev);
+}
+module_init(iio_hrtimer_trig_init);
+
+static void __exit iio_hrtimer_trig_exit(void)
+{
+	device_unregister(&iio_hrtimer_trig_dev);
+}
+module_exit(iio_hrtimer_trig_exit);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("Hrtimer trigger for the iio subsystem");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/platform_data/ad7298.h b/include/linux/platform_data/ad7298.h
index fbf8adf..721ed6f 100644
--- a/include/linux/platform_data/ad7298.h
+++ b/include/linux/platform_data/ad7298.h
@@ -9,12 +9,17 @@
 #ifndef __LINUX_PLATFORM_DATA_AD7298_H__
 #define __LINUX_PLATFORM_DATA_AD7298_H__
 
+#define AD7298_MAX_CHAN		8
+
 /**
  * struct ad7298_platform_data - Platform data for the ad7298 ADC driver
  * @ext_ref: Whether to use an external reference voltage.
+ * @ext_vin_max: External input voltage range for each voltage input channel
+ *               (set to non-zero if platform uses external voltage dividers)
  **/
 struct ad7298_platform_data {
 	bool ext_ref;
+	u16  ext_vin_max[AD7298_MAX_CHAN];
 };
 
 #endif /* IIO_ADC_AD7298_H_ */
diff --git a/include/linux/platform_data/max78m6610_lmu.h b/include/linux/platform_data/max78m6610_lmu.h
new file mode 100644
index 0000000..d05d513
--- /dev/null
+++ b/include/linux/platform_data/max78m6610_lmu.h
@@ -0,0 +1,34 @@
+/*
+ * Platform data for max78m6610+lmu SPI protocol driver
+ * Copyright(c) 2013 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Contact Information:
+ * Intel Corporation
+ */
+
+#ifndef __LINUX_PLATFORM_DATA_MAX78M6610_LMU_H__
+#define __LINUX_PLATFORM_DATA_MAX78M6610_LMU_H__
+
+/**
+ * struct max78m6610_lmu_platform_data - Platform data for the max78m6610_lmu
+ *                                       ADC driver
+ * @reset_gpio: GPIO pin number reserved for MAX78M6610+LMU device reset
+ **/
+struct max78m6610_lmu_platform_data {
+	int reset_gpio;
+};
+
+#endif /* IIO_ADC_MAX78M6610_LMU_H_ */
-- 
1.7.4.1