summaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-bcmring/include/mach/csp/chipcHw_inline.h
blob: 03238c299001a9893dffc80561cca43664a4d404 (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
/*****************************************************************************
* Copyright 2003 - 2008 Broadcom Corporation.  All rights reserved.
*
* Unless you and Broadcom execute a separate written software license
* agreement governing use of this software, this software is licensed to you
* under the terms of the GNU General Public License version 2, available at
* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
*
* Notwithstanding the above, under no circumstances may you combine this
* software in any way with any other Broadcom software provided under a
* license other than the GPL, without Broadcom's express prior written
* consent.
*****************************************************************************/

#ifndef CHIPC_INLINE_H
#define CHIPC_INLINE_H

/* ---- Include Files ----------------------------------------------------- */

#include <csp/errno.h>
#include <csp/reg.h>
#include <mach/csp/chipcHw_reg.h>
#include <mach/csp/chipcHw_def.h>

/* ---- Private Constants and Types --------------------------------------- */
typedef enum {
	chipcHw_OPTYPE_BYPASS,	/* Bypass operation */
	chipcHw_OPTYPE_OUTPUT	/* Output operation */
} chipcHw_OPTYPE_e;

/* ---- Public Constants and Types ---------------------------------------- */
/* ---- Public Variable Externs ------------------------------------------- */
/* ---- Public Function Prototypes ---------------------------------------- */
/* ---- Private Function Prototypes --------------------------------------- */
static inline void chipcHw_setClock(chipcHw_CLOCK_e clock,
				    chipcHw_OPTYPE_e type, int mode);

/****************************************************************************/
/**
*  @brief   Get Numeric Chip ID
*
*  This function returns Chip ID that includes the revison number
*
*  @return  Complete numeric Chip ID
*
*/
/****************************************************************************/
static inline uint32_t chipcHw_getChipId(void)
{
	return pChipcHw->ChipId;
}

/****************************************************************************/
/**
*  @brief   Enable Spread Spectrum
*
*  @note chipcHw_Init() must be called earlier
*/
/****************************************************************************/
static inline void chipcHw_enableSpreadSpectrum(void)
{
	if ((pChipcHw->
	     PLLPreDivider & chipcHw_REG_PLL_PREDIVIDER_NDIV_MODE_MASK) !=
	    chipcHw_REG_PLL_PREDIVIDER_NDIV_MODE_INTEGER) {
		ddrcReg_PHY_ADDR_CTL_REGP->ssCfg =
		    (0xFFFF << ddrcReg_PHY_ADDR_SS_CFG_NDIV_AMPLITUDE_SHIFT) |
		    (ddrcReg_PHY_ADDR_SS_CFG_MIN_CYCLE_PER_TICK <<
		     ddrcReg_PHY_ADDR_SS_CFG_CYCLE_PER_TICK_SHIFT);
		ddrcReg_PHY_ADDR_CTL_REGP->ssCtl |=
		    ddrcReg_PHY_ADDR_SS_CTRL_ENABLE;
	}
}

/****************************************************************************/
/**
*  @brief   Disable Spread Spectrum
*
*/
/****************************************************************************/
static inline void chipcHw_disableSpreadSpectrum(void)
{
	ddrcReg_PHY_ADDR_CTL_REGP->ssCtl &= ~ddrcReg_PHY_ADDR_SS_CTRL_ENABLE;
}

/****************************************************************************/
/**
*  @brief   Get Chip Product ID
*
*  This function returns Chip Product ID
*
*  @return  Chip Product ID
*/
/****************************************************************************/
static inline uint32_t chipcHw_getChipProductId(void)
{
	return (pChipcHw->
		 ChipId & chipcHw_REG_CHIPID_BASE_MASK) >>
		chipcHw_REG_CHIPID_BASE_SHIFT;
}

/****************************************************************************/
/**
*  @brief   Get revision number
*
*  This function returns revision number of the chip
*
*  @return  Revision number
*/
/****************************************************************************/
static inline chipcHw_REV_NUMBER_e chipcHw_getChipRevisionNumber(void)
{
	return pChipcHw->ChipId & chipcHw_REG_CHIPID_REV_MASK;
}

/****************************************************************************/
/**
*  @brief   Enables bus interface clock
*
*  Enables  bus interface clock of various device
*
*  @return  void
*
*  @note    use chipcHw_REG_BUS_CLOCK_XXXX for mask
*/
/****************************************************************************/
static inline void chipcHw_busInterfaceClockEnable(uint32_t mask)
{
	reg32_modify_or(&pChipcHw->BusIntfClock, mask);
}

/****************************************************************************/
/**
*  @brief   Disables bus interface clock
*
*  Disables  bus interface clock of various device
*
*  @return  void
*
*  @note    use chipcHw_REG_BUS_CLOCK_XXXX
*/
/****************************************************************************/
static inline void chipcHw_busInterfaceClockDisable(uint32_t mask)
{
	reg32_modify_and(&pChipcHw->BusIntfClock, ~mask);
}

/****************************************************************************/
/**
*  @brief   Get status (enabled/disabled) of bus interface clock
*
*  This function returns the status of devices' bus interface clock
*
*  @return  Bus interface clock
*
*/
/****************************************************************************/
static inline uint32_t chipcHw_getBusInterfaceClockStatus(void)
{
	return pChipcHw->BusIntfClock;
}

/****************************************************************************/
/**
*  @brief   Enables various audio channels
*
*  Enables audio channel
*
*  @return  void
*
*  @note    use chipcHw_REG_AUDIO_CHANNEL_XXXXXX
*/
/****************************************************************************/
static inline void chipcHw_audioChannelEnable(uint32_t mask)
{
	reg32_modify_or(&pChipcHw->AudioEnable, mask);
}

/****************************************************************************/
/**
*  @brief   Disables various audio channels
*
*  Disables audio channel
*
*  @return  void
*
*  @note    use chipcHw_REG_AUDIO_CHANNEL_XXXXXX
*/
/****************************************************************************/
static inline void chipcHw_audioChannelDisable(uint32_t mask)
{
	reg32_modify_and(&pChipcHw->AudioEnable, ~mask);
}

/****************************************************************************/
/**
*  @brief    Soft resets devices
*
*  Soft resets various devices
*
*  @return   void
*
*  @note     use chipcHw_REG_SOFT_RESET_XXXXXX defines
*/
/****************************************************************************/
static inline void chipcHw_softReset(uint64_t mask)
{
	chipcHw_softResetEnable(mask);
	chipcHw_softResetDisable(mask);
}

static inline void chipcHw_softResetDisable(uint64_t mask)
{
	uint32_t ctrl1 = (uint32_t) mask;
	uint32_t ctrl2 = (uint32_t) (mask >> 32);

	/* Deassert module soft reset */
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->SoftReset1 ^= ctrl1;
	pChipcHw->SoftReset2 ^= (ctrl2 & (~chipcHw_REG_SOFT_RESET_UNHOLD_MASK));
	REG_LOCAL_IRQ_RESTORE;
}

static inline void chipcHw_softResetEnable(uint64_t mask)
{
	uint32_t ctrl1 = (uint32_t) mask;
	uint32_t ctrl2 = (uint32_t) (mask >> 32);
	uint32_t unhold = 0;

	REG_LOCAL_IRQ_SAVE;
	pChipcHw->SoftReset1 |= ctrl1;
	/* Mask out unhold request bits */
	pChipcHw->SoftReset2 |= (ctrl2 & (~chipcHw_REG_SOFT_RESET_UNHOLD_MASK));

	/* Process unhold requests */
	if (ctrl2 & chipcHw_REG_SOFT_RESET_VPM_GLOBAL_UNHOLD) {
		unhold = chipcHw_REG_SOFT_RESET_VPM_GLOBAL_HOLD;
	}

	if (ctrl2 & chipcHw_REG_SOFT_RESET_VPM_UNHOLD) {
		unhold |= chipcHw_REG_SOFT_RESET_VPM_HOLD;
	}

	if (ctrl2 & chipcHw_REG_SOFT_RESET_ARM_UNHOLD) {
		unhold |= chipcHw_REG_SOFT_RESET_ARM_HOLD;
	}

	if (unhold) {
		/* Make sure unhold request is effective */
		pChipcHw->SoftReset1 &= ~unhold;
	}
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief    Configures misc CHIP functionality
*
*  Configures CHIP functionality
*
*  @return   void
*
*  @note     use chipcHw_REG_MISC_CTRL_XXXXXX
*/
/****************************************************************************/
static inline void chipcHw_miscControl(uint32_t mask)
{
	reg32_write(&pChipcHw->MiscCtrl, mask);
}

static inline void chipcHw_miscControlDisable(uint32_t mask)
{
	reg32_modify_and(&pChipcHw->MiscCtrl, ~mask);
}

static inline void chipcHw_miscControlEnable(uint32_t mask)
{
	reg32_modify_or(&pChipcHw->MiscCtrl, mask);
}

/****************************************************************************/
/**
*  @brief    Set OTP options
*
*  Set OTP options
*
*  @return   void
*
*  @note     use chipcHw_REG_OTP_XXXXXX
*/
/****************************************************************************/
static inline void chipcHw_setOTPOption(uint64_t mask)
{
	uint32_t ctrl1 = (uint32_t) mask;
	uint32_t ctrl2 = (uint32_t) (mask >> 32);

	reg32_modify_or(&pChipcHw->SoftOTP1, ctrl1);
	reg32_modify_or(&pChipcHw->SoftOTP2, ctrl2);
}

/****************************************************************************/
/**
*  @brief    Get sticky bits
*
*  @return   Sticky bit options of type chipcHw_REG_STICKY_XXXXXX
*
*/
/****************************************************************************/
static inline uint32_t chipcHw_getStickyBits(void)
{
	return pChipcHw->Sticky;
}

/****************************************************************************/
/**
*  @brief    Set sticky bits
*
*  @return   void
*
*  @note     use chipcHw_REG_STICKY_XXXXXX
*/
/****************************************************************************/
static inline void chipcHw_setStickyBits(uint32_t mask)
{
	uint32_t bits = 0;

	REG_LOCAL_IRQ_SAVE;
	if (mask & chipcHw_REG_STICKY_POR_BROM) {
		bits |= chipcHw_REG_STICKY_POR_BROM;
	} else {
		uint32_t sticky;
		sticky = pChipcHw->Sticky;

		if ((mask & chipcHw_REG_STICKY_BOOT_DONE)
		    && (sticky & chipcHw_REG_STICKY_BOOT_DONE) == 0) {
			bits |= chipcHw_REG_STICKY_BOOT_DONE;
		}
		if ((mask & chipcHw_REG_STICKY_GENERAL_1)
		    && (sticky & chipcHw_REG_STICKY_GENERAL_1) == 0) {
			bits |= chipcHw_REG_STICKY_GENERAL_1;
		}
		if ((mask & chipcHw_REG_STICKY_GENERAL_2)
		    && (sticky & chipcHw_REG_STICKY_GENERAL_2) == 0) {
			bits |= chipcHw_REG_STICKY_GENERAL_2;
		}
		if ((mask & chipcHw_REG_STICKY_GENERAL_3)
		    && (sticky & chipcHw_REG_STICKY_GENERAL_3) == 0) {
			bits |= chipcHw_REG_STICKY_GENERAL_3;
		}
		if ((mask & chipcHw_REG_STICKY_GENERAL_4)
		    && (sticky & chipcHw_REG_STICKY_GENERAL_4) == 0) {
			bits |= chipcHw_REG_STICKY_GENERAL_4;
		}
		if ((mask & chipcHw_REG_STICKY_GENERAL_5)
		    && (sticky & chipcHw_REG_STICKY_GENERAL_5) == 0) {
			bits |= chipcHw_REG_STICKY_GENERAL_5;
		}
	}
	pChipcHw->Sticky = bits;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief    Clear sticky bits
*
*  @return   void
*
*  @note     use chipcHw_REG_STICKY_XXXXXX
*/
/****************************************************************************/
static inline void chipcHw_clearStickyBits(uint32_t mask)
{
	uint32_t bits = 0;

	REG_LOCAL_IRQ_SAVE;
	if (mask &
	    (chipcHw_REG_STICKY_BOOT_DONE | chipcHw_REG_STICKY_GENERAL_1 |
	     chipcHw_REG_STICKY_GENERAL_2 | chipcHw_REG_STICKY_GENERAL_3 |
	     chipcHw_REG_STICKY_GENERAL_4 | chipcHw_REG_STICKY_GENERAL_5)) {
		uint32_t sticky = pChipcHw->Sticky;

		if ((mask & chipcHw_REG_STICKY_BOOT_DONE)
		    && (sticky & chipcHw_REG_STICKY_BOOT_DONE)) {
			bits = chipcHw_REG_STICKY_BOOT_DONE;
			mask &= ~chipcHw_REG_STICKY_BOOT_DONE;
		}
		if ((mask & chipcHw_REG_STICKY_GENERAL_1)
		    && (sticky & chipcHw_REG_STICKY_GENERAL_1)) {
			bits |= chipcHw_REG_STICKY_GENERAL_1;
			mask &= ~chipcHw_REG_STICKY_GENERAL_1;
		}
		if ((mask & chipcHw_REG_STICKY_GENERAL_2)
		    && (sticky & chipcHw_REG_STICKY_GENERAL_2)) {
			bits |= chipcHw_REG_STICKY_GENERAL_2;
			mask &= ~chipcHw_REG_STICKY_GENERAL_2;
		}
		if ((mask & chipcHw_REG_STICKY_GENERAL_3)
		    && (sticky & chipcHw_REG_STICKY_GENERAL_3)) {
			bits |= chipcHw_REG_STICKY_GENERAL_3;
			mask &= ~chipcHw_REG_STICKY_GENERAL_3;
		}
		if ((mask & chipcHw_REG_STICKY_GENERAL_4)
		    && (sticky & chipcHw_REG_STICKY_GENERAL_4)) {
			bits |= chipcHw_REG_STICKY_GENERAL_4;
			mask &= ~chipcHw_REG_STICKY_GENERAL_4;
		}
		if ((mask & chipcHw_REG_STICKY_GENERAL_5)
		    && (sticky & chipcHw_REG_STICKY_GENERAL_5)) {
			bits |= chipcHw_REG_STICKY_GENERAL_5;
			mask &= ~chipcHw_REG_STICKY_GENERAL_5;
		}
	}
	pChipcHw->Sticky = bits | mask;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief    Get software strap value
*
*  Retrieves software strap value
*
*  @return   Software strap value
*
*/
/****************************************************************************/
static inline uint32_t chipcHw_getSoftStraps(void)
{
	return pChipcHw->SoftStraps;
}

/****************************************************************************/
/**
*  @brief    Set software override strap options
*
*  set software override strap options
*
*  @return   nothing
*
*/
/****************************************************************************/
static inline void chipcHw_setSoftStraps(uint32_t strapOptions)
{
	reg32_write(&pChipcHw->SoftStraps, strapOptions);
}

/****************************************************************************/
/**
*  @brief   Get Pin Strap Options
*
*  This function returns the raw boot strap options
*
*  @return  strap options
*
*/
/****************************************************************************/
static inline uint32_t chipcHw_getPinStraps(void)
{
	return pChipcHw->PinStraps;
}

/****************************************************************************/
/**
*  @brief   Get Valid Strap Options
*
*  This function returns the valid raw boot strap options
*
*  @return  strap options
*
*/
/****************************************************************************/
static inline uint32_t chipcHw_getValidStraps(void)
{
	uint32_t softStraps;

	/*
	 ** Always return the SoftStraps - bootROM calls chipcHw_initValidStraps
	 ** which copies HW straps to soft straps if there is no override
	 */
	softStraps = chipcHw_getSoftStraps();

	return softStraps;
}

/****************************************************************************/
/**
*  @brief    Initialize valid pin strap options
*
*  Retrieves valid pin strap options by copying HW strap options to soft register
*  (if chipcHw_STRAPS_SOFT_OVERRIDE not set)
*
*  @return   nothing
*
*/
/****************************************************************************/
static inline void chipcHw_initValidStraps(void)
{
	uint32_t softStraps;

	REG_LOCAL_IRQ_SAVE;
	softStraps = chipcHw_getSoftStraps();

	if ((softStraps & chipcHw_STRAPS_SOFT_OVERRIDE) == 0) {
		/* Copy HW straps to software straps */
		chipcHw_setSoftStraps(chipcHw_getPinStraps());
	}
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Get boot device
*
*  This function returns the device type used in booting the system
*
*  @return  Boot device of type chipcHw_BOOT_DEVICE
*
*/
/****************************************************************************/
static inline chipcHw_BOOT_DEVICE_e chipcHw_getBootDevice(void)
{
	return chipcHw_getValidStraps() & chipcHw_STRAPS_BOOT_DEVICE_MASK;
}

/****************************************************************************/
/**
*  @brief   Get boot mode
*
*  This function returns the way the system was booted
*
*  @return  Boot mode of type chipcHw_BOOT_MODE
*
*/
/****************************************************************************/
static inline chipcHw_BOOT_MODE_e chipcHw_getBootMode(void)
{
	return chipcHw_getValidStraps() & chipcHw_STRAPS_BOOT_MODE_MASK;
}

/****************************************************************************/
/**
*  @brief   Get NAND flash page size
*
*  This function returns the NAND device page size
*
*  @return  Boot NAND device page size
*
*/
/****************************************************************************/
static inline chipcHw_NAND_PAGESIZE_e chipcHw_getNandPageSize(void)
{
	return chipcHw_getValidStraps() & chipcHw_STRAPS_NAND_PAGESIZE_MASK;
}

/****************************************************************************/
/**
*  @brief   Get NAND flash address cycle configuration
*
*  This function returns the NAND flash address cycle configuration
*
*  @return  0 = Do not extra address cycle, 1 = Add extra cycle
*
*/
/****************************************************************************/
static inline int chipcHw_getNandExtraCycle(void)
{
	if (chipcHw_getValidStraps() & chipcHw_STRAPS_NAND_EXTRA_CYCLE) {
		return 1;
	} else {
		return 0;
	}
}

/****************************************************************************/
/**
*  @brief   Activates PIF interface
*
*  This function activates PIF interface by taking control of LCD pins
*
*  @note
*       When activated, LCD pins will be defined as follows for PIF operation
*
*       CLD[17:0]  = pif_data[17:0]
*       CLD[23:18] = pif_address[5:0]
*       CLPOWER    = pif_wr_str
*       CLCP       = pif_rd_str
*       CLAC       = pif_hat1
*       CLFP       = pif_hrdy1
*       CLLP       = pif_hat2
*       GPIO[42]   = pif_hrdy2
*
*       In PIF mode, "pif_hrdy2" overrides other shared function for GPIO[42] pin
*
*/
/****************************************************************************/
static inline void chipcHw_activatePifInterface(void)
{
	reg32_write(&pChipcHw->LcdPifMode, chipcHw_REG_PIF_PIN_ENABLE);
}

/****************************************************************************/
/**
*  @brief   Activates LCD interface
*
*  This function activates LCD interface
*
*  @note
*       When activated, LCD pins will be defined as follows
*
*       CLD[17:0]  = LCD data
*       CLD[23:18] = LCD data
*       CLPOWER    = LCD power
*       CLCP       =
*       CLAC       = LCD ack
*       CLFP       =
*       CLLP       =
*/
/****************************************************************************/
static inline void chipcHw_activateLcdInterface(void)
{
	reg32_write(&pChipcHw->LcdPifMode, chipcHw_REG_LCD_PIN_ENABLE);
}

/****************************************************************************/
/**
*  @brief   Deactivates PIF/LCD interface
*
*  This function deactivates PIF/LCD interface
*
*  @note
*       When deactivated LCD pins will be in rti-stated
*
*/
/****************************************************************************/
static inline void chipcHw_deactivatePifLcdInterface(void)
{
	reg32_write(&pChipcHw->LcdPifMode, 0);
}

/****************************************************************************/
/**
*  @brief   Select GE2
*
*  This function select GE2 as the graphic engine
*
*/
/****************************************************************************/
static inline void chipcHw_selectGE2(void)
{
	reg32_modify_and(&pChipcHw->MiscCtrl, ~chipcHw_REG_MISC_CTRL_GE_SEL);
}

/****************************************************************************/
/**
*  @brief   Select GE3
*
*  This function select GE3 as the graphic engine
*
*/
/****************************************************************************/
static inline void chipcHw_selectGE3(void)
{
	reg32_modify_or(&pChipcHw->MiscCtrl, chipcHw_REG_MISC_CTRL_GE_SEL);
}

/****************************************************************************/
/**
*  @brief   Get to know the configuration of GPIO pin
*
*/
/****************************************************************************/
static inline chipcHw_GPIO_FUNCTION_e chipcHw_getGpioPinFunction(int pin)
{
	return (*((uint32_t *) chipcHw_REG_GPIO_MUX(pin)) &
		(chipcHw_REG_GPIO_MUX_MASK <<
		 chipcHw_REG_GPIO_MUX_POSITION(pin))) >>
	    chipcHw_REG_GPIO_MUX_POSITION(pin);
}

/****************************************************************************/
/**
*  @brief   Configure GPIO pin function
*
*/
/****************************************************************************/
static inline void chipcHw_setGpioPinFunction(int pin,
					      chipcHw_GPIO_FUNCTION_e func)
{
	REG_LOCAL_IRQ_SAVE;
	*((uint32_t *) chipcHw_REG_GPIO_MUX(pin)) &=
	    ~(chipcHw_REG_GPIO_MUX_MASK << chipcHw_REG_GPIO_MUX_POSITION(pin));
	*((uint32_t *) chipcHw_REG_GPIO_MUX(pin)) |=
	    func << chipcHw_REG_GPIO_MUX_POSITION(pin);
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Set Pin slew rate
*
*  This function sets the slew of individual pin
*
*/
/****************************************************************************/
static inline void chipcHw_setPinSlewRate(uint32_t pin,
					  chipcHw_PIN_SLEW_RATE_e slewRate)
{
	REG_LOCAL_IRQ_SAVE;
	*((uint32_t *) chipcHw_REG_SLEW_RATE(pin)) &=
	    ~(chipcHw_REG_SLEW_RATE_MASK <<
	      chipcHw_REG_SLEW_RATE_POSITION(pin));
	*((uint32_t *) chipcHw_REG_SLEW_RATE(pin)) |=
	    (uint32_t) slewRate << chipcHw_REG_SLEW_RATE_POSITION(pin);
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Set Pin output drive current
*
*  This function sets output drive current of individual pin
*
*  Note: Avoid the use of the word 'current' since linux headers define this
*        to be the current task.
*/
/****************************************************************************/
static inline void chipcHw_setPinOutputCurrent(uint32_t pin,
					       chipcHw_PIN_CURRENT_STRENGTH_e
					       curr)
{
	REG_LOCAL_IRQ_SAVE;
	*((uint32_t *) chipcHw_REG_CURRENT(pin)) &=
	    ~(chipcHw_REG_CURRENT_MASK << chipcHw_REG_CURRENT_POSITION(pin));
	*((uint32_t *) chipcHw_REG_CURRENT(pin)) |=
	    (uint32_t) curr << chipcHw_REG_CURRENT_POSITION(pin);
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Set Pin pullup register
*
*  This function sets pullup register of individual pin
*
*/
/****************************************************************************/
static inline void chipcHw_setPinPullup(uint32_t pin, chipcHw_PIN_PULL_e pullup)
{
	REG_LOCAL_IRQ_SAVE;
	*((uint32_t *) chipcHw_REG_PULLUP(pin)) &=
	    ~(chipcHw_REG_PULLUP_MASK << chipcHw_REG_PULLUP_POSITION(pin));
	*((uint32_t *) chipcHw_REG_PULLUP(pin)) |=
	    (uint32_t) pullup << chipcHw_REG_PULLUP_POSITION(pin);
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Set Pin input type
*
*  This function sets input type of individual pin
*
*/
/****************************************************************************/
static inline void chipcHw_setPinInputType(uint32_t pin,
					   chipcHw_PIN_INPUTTYPE_e inputType)
{
	REG_LOCAL_IRQ_SAVE;
	*((uint32_t *) chipcHw_REG_INPUTTYPE(pin)) &=
	    ~(chipcHw_REG_INPUTTYPE_MASK <<
	      chipcHw_REG_INPUTTYPE_POSITION(pin));
	*((uint32_t *) chipcHw_REG_INPUTTYPE(pin)) |=
	    (uint32_t) inputType << chipcHw_REG_INPUTTYPE_POSITION(pin);
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Power up the USB PHY
*
*  This function powers up the USB PHY
*
*/
/****************************************************************************/
static inline void chipcHw_powerUpUsbPhy(void)
{
	reg32_modify_and(&pChipcHw->MiscCtrl,
			 chipcHw_REG_MISC_CTRL_USB_POWERON);
}

/****************************************************************************/
/**
*  @brief   Power down the USB PHY
*
*  This function powers down the USB PHY
*
*/
/****************************************************************************/
static inline void chipcHw_powerDownUsbPhy(void)
{
	reg32_modify_or(&pChipcHw->MiscCtrl,
			chipcHw_REG_MISC_CTRL_USB_POWEROFF);
}

/****************************************************************************/
/**
*  @brief   Set the 2nd USB as host
*
*  This function sets the 2nd USB as host
*
*/
/****************************************************************************/
static inline void chipcHw_setUsbHost(void)
{
	reg32_modify_or(&pChipcHw->MiscCtrl,
			chipcHw_REG_MISC_CTRL_USB_MODE_HOST);
}

/****************************************************************************/
/**
*  @brief   Set the 2nd USB as device
*
*  This function sets the 2nd USB as device
*
*/
/****************************************************************************/
static inline void chipcHw_setUsbDevice(void)
{
	reg32_modify_and(&pChipcHw->MiscCtrl,
			 chipcHw_REG_MISC_CTRL_USB_MODE_DEVICE);
}

/****************************************************************************/
/**
*  @brief   Lower layer function to enable/disable a clock of a certain device
*
*  This function enables/disables a core clock
*
*/
/****************************************************************************/
static inline void chipcHw_setClock(chipcHw_CLOCK_e clock,
				    chipcHw_OPTYPE_e type, int mode)
{
	volatile uint32_t *pPLLReg = (uint32_t *) 0x0;
	volatile uint32_t *pClockCtrl = (uint32_t *) 0x0;

	switch (clock) {
	case chipcHw_CLOCK_DDR:
		pPLLReg = &pChipcHw->DDRClock;
		break;
	case chipcHw_CLOCK_ARM:
		pPLLReg = &pChipcHw->ARMClock;
		break;
	case chipcHw_CLOCK_ESW:
		pPLLReg = &pChipcHw->ESWClock;
		break;
	case chipcHw_CLOCK_VPM:
		pPLLReg = &pChipcHw->VPMClock;
		break;
	case chipcHw_CLOCK_ESW125:
		pPLLReg = &pChipcHw->ESW125Clock;
		break;
	case chipcHw_CLOCK_UART:
		pPLLReg = &pChipcHw->UARTClock;
		break;
	case chipcHw_CLOCK_SDIO0:
		pPLLReg = &pChipcHw->SDIO0Clock;
		break;
	case chipcHw_CLOCK_SDIO1:
		pPLLReg = &pChipcHw->SDIO1Clock;
		break;
	case chipcHw_CLOCK_SPI:
		pPLLReg = &pChipcHw->SPIClock;
		break;
	case chipcHw_CLOCK_ETM:
		pPLLReg = &pChipcHw->ETMClock;
		break;
	case chipcHw_CLOCK_USB:
		pPLLReg = &pChipcHw->USBClock;
		if (type == chipcHw_OPTYPE_OUTPUT) {
			if (mode) {
				reg32_modify_and(pPLLReg,
						 ~chipcHw_REG_PLL_CLOCK_POWER_DOWN);
			} else {
				reg32_modify_or(pPLLReg,
						chipcHw_REG_PLL_CLOCK_POWER_DOWN);
			}
		}
		break;
	case chipcHw_CLOCK_LCD:
		pPLLReg = &pChipcHw->LCDClock;
		if (type == chipcHw_OPTYPE_OUTPUT) {
			if (mode) {
				reg32_modify_and(pPLLReg,
						 ~chipcHw_REG_PLL_CLOCK_POWER_DOWN);
			} else {
				reg32_modify_or(pPLLReg,
						chipcHw_REG_PLL_CLOCK_POWER_DOWN);
			}
		}
		break;
	case chipcHw_CLOCK_APM:
		pPLLReg = &pChipcHw->APMClock;
		if (type == chipcHw_OPTYPE_OUTPUT) {
			if (mode) {
				reg32_modify_and(pPLLReg,
						 ~chipcHw_REG_PLL_CLOCK_POWER_DOWN);
			} else {
				reg32_modify_or(pPLLReg,
						chipcHw_REG_PLL_CLOCK_POWER_DOWN);
			}
		}
		break;
	case chipcHw_CLOCK_BUS:
		pClockCtrl = &pChipcHw->ACLKClock;
		break;
	case chipcHw_CLOCK_OTP:
		pClockCtrl = &pChipcHw->OTPClock;
		break;
	case chipcHw_CLOCK_I2C:
		pClockCtrl = &pChipcHw->I2CClock;
		break;
	case chipcHw_CLOCK_I2S0:
		pClockCtrl = &pChipcHw->I2S0Clock;
		break;
	case chipcHw_CLOCK_RTBUS:
		pClockCtrl = &pChipcHw->RTBUSClock;
		break;
	case chipcHw_CLOCK_APM100:
		pClockCtrl = &pChipcHw->APM100Clock;
		break;
	case chipcHw_CLOCK_TSC:
		pClockCtrl = &pChipcHw->TSCClock;
		break;
	case chipcHw_CLOCK_LED:
		pClockCtrl = &pChipcHw->LEDClock;
		break;
	case chipcHw_CLOCK_I2S1:
		pClockCtrl = &pChipcHw->I2S1Clock;
		break;
	}

	if (pPLLReg) {
		switch (type) {
		case chipcHw_OPTYPE_OUTPUT:
			/* PLL clock output enable/disable */
			if (mode) {
				if (clock == chipcHw_CLOCK_DDR) {
					/* DDR clock enable is inverted */
					reg32_modify_and(pPLLReg,
							 ~chipcHw_REG_PLL_CLOCK_OUTPUT_ENABLE);
				} else {
					reg32_modify_or(pPLLReg,
							chipcHw_REG_PLL_CLOCK_OUTPUT_ENABLE);
				}
			} else {
				if (clock == chipcHw_CLOCK_DDR) {
					/* DDR clock disable is inverted */
					reg32_modify_or(pPLLReg,
							chipcHw_REG_PLL_CLOCK_OUTPUT_ENABLE);
				} else {
					reg32_modify_and(pPLLReg,
							 ~chipcHw_REG_PLL_CLOCK_OUTPUT_ENABLE);
				}
			}
			break;
		case chipcHw_OPTYPE_BYPASS:
			/* PLL clock bypass enable/disable */
			if (mode) {
				reg32_modify_or(pPLLReg,
						chipcHw_REG_PLL_CLOCK_BYPASS_SELECT);
			} else {
				reg32_modify_and(pPLLReg,
						 ~chipcHw_REG_PLL_CLOCK_BYPASS_SELECT);
			}
			break;
		}
	} else if (pClockCtrl) {
		switch (type) {
		case chipcHw_OPTYPE_OUTPUT:
			if (mode) {
				reg32_modify_or(pClockCtrl,
						chipcHw_REG_DIV_CLOCK_OUTPUT_ENABLE);
			} else {
				reg32_modify_and(pClockCtrl,
						 ~chipcHw_REG_DIV_CLOCK_OUTPUT_ENABLE);
			}
			break;
		case chipcHw_OPTYPE_BYPASS:
			if (mode) {
				reg32_modify_or(pClockCtrl,
						chipcHw_REG_DIV_CLOCK_BYPASS_SELECT);
			} else {
				reg32_modify_and(pClockCtrl,
						 ~chipcHw_REG_DIV_CLOCK_BYPASS_SELECT);
			}
			break;
		}
	}
}

/****************************************************************************/
/**
*  @brief   Disables a core clock of a certain device
*
*  This function disables a core clock
*
*  @note    no change in power consumption
*/
/****************************************************************************/
static inline void chipcHw_setClockDisable(chipcHw_CLOCK_e clock)
{

	/* Disable output of the clock */
	chipcHw_setClock(clock, chipcHw_OPTYPE_OUTPUT, 0);
}

/****************************************************************************/
/**
*  @brief   Enable a core clock of a certain device
*
*  This function enables a core clock
*
*  @note    no change in power consumption
*/
/****************************************************************************/
static inline void chipcHw_setClockEnable(chipcHw_CLOCK_e clock)
{

	/* Enable output of the clock */
	chipcHw_setClock(clock, chipcHw_OPTYPE_OUTPUT, 1);
}

/****************************************************************************/
/**
*  @brief   Enables bypass clock of a certain device
*
*  This function enables bypass clock
*
*  @note    Doesnot affect the bus interface clock
*/
/****************************************************************************/
static inline void chipcHw_bypassClockEnable(chipcHw_CLOCK_e clock)
{
	/* Enable bypass clock */
	chipcHw_setClock(clock, chipcHw_OPTYPE_BYPASS, 1);
}

/****************************************************************************/
/**
*  @brief   Disabled bypass clock of a certain device
*
*  This function disables bypass clock
*
*  @note    Doesnot affect the bus interface clock
*/
/****************************************************************************/
static inline void chipcHw_bypassClockDisable(chipcHw_CLOCK_e clock)
{
	/* Disable bypass clock */
	chipcHw_setClock(clock, chipcHw_OPTYPE_BYPASS, 0);

}

/****************************************************************************/
/**  @brief Checks if software strap is enabled
 *
 *   @return 1 : When enable
 *           0 : When disable
 */
/****************************************************************************/
static inline int chipcHw_isSoftwareStrapsEnable(void)
{
	return pChipcHw->SoftStraps & 0x00000001;
}

/****************************************************************************/
/**  @brief Enable software strap
 */
/****************************************************************************/
static inline void chipcHw_softwareStrapsEnable(void)
{
	reg32_modify_or(&pChipcHw->SoftStraps, 0x00000001);
}

/****************************************************************************/
/**  @brief Disable software strap
 */
/****************************************************************************/
static inline void chipcHw_softwareStrapsDisable(void)
{
	reg32_modify_and(&pChipcHw->SoftStraps, (~0x00000001));
}

/****************************************************************************/
/**  @brief PLL test enable
 */
/****************************************************************************/
static inline void chipcHw_pllTestEnable(void)
{
	reg32_modify_or(&pChipcHw->PLLConfig,
			chipcHw_REG_PLL_CONFIG_TEST_ENABLE);
}

/****************************************************************************/
/**  @brief PLL2 test enable
 */
/****************************************************************************/
static inline void chipcHw_pll2TestEnable(void)
{
	reg32_modify_or(&pChipcHw->PLLConfig2,
			chipcHw_REG_PLL_CONFIG_TEST_ENABLE);
}

/****************************************************************************/
/**  @brief PLL test disable
 */
/****************************************************************************/
static inline void chipcHw_pllTestDisable(void)
{
	reg32_modify_and(&pChipcHw->PLLConfig,
			 ~chipcHw_REG_PLL_CONFIG_TEST_ENABLE);
}

/****************************************************************************/
/**  @brief PLL2 test disable
 */
/****************************************************************************/
static inline void chipcHw_pll2TestDisable(void)
{
	reg32_modify_and(&pChipcHw->PLLConfig2,
			 ~chipcHw_REG_PLL_CONFIG_TEST_ENABLE);
}

/****************************************************************************/
/**  @brief Get PLL test status
 */
/****************************************************************************/
static inline int chipcHw_isPllTestEnable(void)
{
	return pChipcHw->PLLConfig & chipcHw_REG_PLL_CONFIG_TEST_ENABLE;
}

/****************************************************************************/
/**  @brief Get PLL2 test status
 */
/****************************************************************************/
static inline int chipcHw_isPll2TestEnable(void)
{
	return pChipcHw->PLLConfig2 & chipcHw_REG_PLL_CONFIG_TEST_ENABLE;
}

/****************************************************************************/
/**  @brief PLL test select
 */
/****************************************************************************/
static inline void chipcHw_pllTestSelect(uint32_t val)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->PLLConfig &= ~chipcHw_REG_PLL_CONFIG_TEST_SELECT_MASK;
	pChipcHw->PLLConfig |=
	    (val) << chipcHw_REG_PLL_CONFIG_TEST_SELECT_SHIFT;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**  @brief PLL2 test select
 */
/****************************************************************************/
static inline void chipcHw_pll2TestSelect(uint32_t val)
{

	REG_LOCAL_IRQ_SAVE;
	pChipcHw->PLLConfig2 &= ~chipcHw_REG_PLL_CONFIG_TEST_SELECT_MASK;
	pChipcHw->PLLConfig2 |=
	    (val) << chipcHw_REG_PLL_CONFIG_TEST_SELECT_SHIFT;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**  @brief Get PLL test selected option
 */
/****************************************************************************/
static inline uint8_t chipcHw_getPllTestSelected(void)
{
	return (uint8_t) ((pChipcHw->
			   PLLConfig & chipcHw_REG_PLL_CONFIG_TEST_SELECT_MASK)
			  >> chipcHw_REG_PLL_CONFIG_TEST_SELECT_SHIFT);
}

/****************************************************************************/
/**  @brief Get PLL2 test selected option
 */
/****************************************************************************/
static inline uint8_t chipcHw_getPll2TestSelected(void)
{
	return (uint8_t) ((pChipcHw->
			   PLLConfig2 & chipcHw_REG_PLL_CONFIG_TEST_SELECT_MASK)
			  >> chipcHw_REG_PLL_CONFIG_TEST_SELECT_SHIFT);
}

/****************************************************************************/
/**
*  @brief  Disable the PLL1
*
*/
/****************************************************************************/
static inline void chipcHw_pll1Disable(void)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->PLLConfig |= chipcHw_REG_PLL_CONFIG_POWER_DOWN;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief  Disable the PLL2
*
*/
/****************************************************************************/
static inline void chipcHw_pll2Disable(void)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->PLLConfig2 |= chipcHw_REG_PLL_CONFIG_POWER_DOWN;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Enables DDR SW phase alignment interrupt
*/
/****************************************************************************/
static inline void chipcHw_ddrPhaseAlignInterruptEnable(void)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->Spare1 |= chipcHw_REG_SPARE1_DDR_PHASE_INTR_ENABLE;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Disables DDR SW phase alignment interrupt
*/
/****************************************************************************/
static inline void chipcHw_ddrPhaseAlignInterruptDisable(void)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->Spare1 &= ~chipcHw_REG_SPARE1_DDR_PHASE_INTR_ENABLE;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Set VPM SW phase alignment interrupt mode
*
*  This function sets VPM phase alignment interrupt
*/
/****************************************************************************/
static inline void
chipcHw_vpmPhaseAlignInterruptMode(chipcHw_VPM_HW_PHASE_INTR_e mode)
{
	REG_LOCAL_IRQ_SAVE;
	if (mode == chipcHw_VPM_HW_PHASE_INTR_DISABLE) {
		pChipcHw->Spare1 &= ~chipcHw_REG_SPARE1_VPM_PHASE_INTR_ENABLE;
	} else {
		pChipcHw->Spare1 |= chipcHw_REG_SPARE1_VPM_PHASE_INTR_ENABLE;
	}
	pChipcHw->VPMPhaseCtrl2 =
	    (pChipcHw->
	     VPMPhaseCtrl2 & ~(chipcHw_REG_VPM_INTR_SELECT_MASK <<
			       chipcHw_REG_VPM_INTR_SELECT_SHIFT)) | mode;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Enable DDR phase alignment in software
*
*/
/****************************************************************************/
static inline void chipcHw_ddrSwPhaseAlignEnable(void)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->DDRPhaseCtrl1 |= chipcHw_REG_DDR_SW_PHASE_CTRL_ENABLE;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Disable DDR phase alignment in software
*
*/
/****************************************************************************/
static inline void chipcHw_ddrSwPhaseAlignDisable(void)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->DDRPhaseCtrl1 &= ~chipcHw_REG_DDR_SW_PHASE_CTRL_ENABLE;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Enable DDR phase alignment in hardware
*
*/
/****************************************************************************/
static inline void chipcHw_ddrHwPhaseAlignEnable(void)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->DDRPhaseCtrl1 |= chipcHw_REG_DDR_HW_PHASE_CTRL_ENABLE;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Disable DDR phase alignment in hardware
*
*/
/****************************************************************************/
static inline void chipcHw_ddrHwPhaseAlignDisable(void)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->DDRPhaseCtrl1 &= ~chipcHw_REG_DDR_HW_PHASE_CTRL_ENABLE;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Enable VPM phase alignment in software
*
*/
/****************************************************************************/
static inline void chipcHw_vpmSwPhaseAlignEnable(void)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->VPMPhaseCtrl1 |= chipcHw_REG_VPM_SW_PHASE_CTRL_ENABLE;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Disable VPM phase alignment in software
*
*/
/****************************************************************************/
static inline void chipcHw_vpmSwPhaseAlignDisable(void)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->VPMPhaseCtrl1 &= ~chipcHw_REG_VPM_SW_PHASE_CTRL_ENABLE;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Enable VPM phase alignment in hardware
*
*/
/****************************************************************************/
static inline void chipcHw_vpmHwPhaseAlignEnable(void)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->VPMPhaseCtrl1 |= chipcHw_REG_VPM_HW_PHASE_CTRL_ENABLE;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Disable VPM phase alignment in hardware
*
*/
/****************************************************************************/
static inline void chipcHw_vpmHwPhaseAlignDisable(void)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->VPMPhaseCtrl1 &= ~chipcHw_REG_VPM_HW_PHASE_CTRL_ENABLE;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Set DDR phase alignment margin in hardware
*
*/
/****************************************************************************/
static inline void
chipcHw_setDdrHwPhaseAlignMargin(chipcHw_DDR_HW_PHASE_MARGIN_e margin)
{
	uint32_t ge = 0;
	uint32_t le = 0;

	switch (margin) {
	case chipcHw_DDR_HW_PHASE_MARGIN_STRICT:
		ge = 0x0F;
		le = 0x0F;
		break;
	case chipcHw_DDR_HW_PHASE_MARGIN_MEDIUM:
		ge = 0x03;
		le = 0x3F;
		break;
	case chipcHw_DDR_HW_PHASE_MARGIN_WIDE:
		ge = 0x01;
		le = 0x7F;
		break;
	}

	{
		REG_LOCAL_IRQ_SAVE;

		pChipcHw->DDRPhaseCtrl1 &=
		    ~((chipcHw_REG_DDR_PHASE_VALUE_GE_MASK <<
		       chipcHw_REG_DDR_PHASE_VALUE_GE_SHIFT)
		      || (chipcHw_REG_DDR_PHASE_VALUE_LE_MASK <<
			  chipcHw_REG_DDR_PHASE_VALUE_LE_SHIFT));

		pChipcHw->DDRPhaseCtrl1 |=
		    ((ge << chipcHw_REG_DDR_PHASE_VALUE_GE_SHIFT)
		     || (le << chipcHw_REG_DDR_PHASE_VALUE_LE_SHIFT));

		REG_LOCAL_IRQ_RESTORE;
	}
}

/****************************************************************************/
/**
*  @brief   Set VPM phase alignment margin in hardware
*
*/
/****************************************************************************/
static inline void
chipcHw_setVpmHwPhaseAlignMargin(chipcHw_VPM_HW_PHASE_MARGIN_e margin)
{
	uint32_t ge = 0;
	uint32_t le = 0;

	switch (margin) {
	case chipcHw_VPM_HW_PHASE_MARGIN_STRICT:
		ge = 0x0F;
		le = 0x0F;
		break;
	case chipcHw_VPM_HW_PHASE_MARGIN_MEDIUM:
		ge = 0x03;
		le = 0x3F;
		break;
	case chipcHw_VPM_HW_PHASE_MARGIN_WIDE:
		ge = 0x01;
		le = 0x7F;
		break;
	}

	{
		REG_LOCAL_IRQ_SAVE;

		pChipcHw->VPMPhaseCtrl1 &=
		    ~((chipcHw_REG_VPM_PHASE_VALUE_GE_MASK <<
		       chipcHw_REG_VPM_PHASE_VALUE_GE_SHIFT)
		      || (chipcHw_REG_VPM_PHASE_VALUE_LE_MASK <<
			  chipcHw_REG_VPM_PHASE_VALUE_LE_SHIFT));

		pChipcHw->VPMPhaseCtrl1 |=
		    ((ge << chipcHw_REG_VPM_PHASE_VALUE_GE_SHIFT)
		     || (le << chipcHw_REG_VPM_PHASE_VALUE_LE_SHIFT));

		REG_LOCAL_IRQ_RESTORE;
	}
}

/****************************************************************************/
/**
*  @brief   Checks DDR phase aligned status done by HW
*
*  @return  1: When aligned
*           0: When not aligned
*/
/****************************************************************************/
static inline uint32_t chipcHw_isDdrHwPhaseAligned(void)
{
	return (pChipcHw->
		PhaseAlignStatus & chipcHw_REG_DDR_PHASE_ALIGNED) ? 1 : 0;
}

/****************************************************************************/
/**
*  @brief   Checks VPM phase aligned status done by HW
*
*  @return  1: When aligned
*           0: When not aligned
*/
/****************************************************************************/
static inline uint32_t chipcHw_isVpmHwPhaseAligned(void)
{
	return (pChipcHw->
		PhaseAlignStatus & chipcHw_REG_VPM_PHASE_ALIGNED) ? 1 : 0;
}

/****************************************************************************/
/**
*  @brief   Get DDR phase aligned status done by HW
*
*/
/****************************************************************************/
static inline uint32_t chipcHw_getDdrHwPhaseAlignStatus(void)
{
	return (pChipcHw->
		PhaseAlignStatus & chipcHw_REG_DDR_PHASE_STATUS_MASK) >>
	    chipcHw_REG_DDR_PHASE_STATUS_SHIFT;
}

/****************************************************************************/
/**
*  @brief   Get VPM phase aligned status done by HW
*
*/
/****************************************************************************/
static inline uint32_t chipcHw_getVpmHwPhaseAlignStatus(void)
{
	return (pChipcHw->
		PhaseAlignStatus & chipcHw_REG_VPM_PHASE_STATUS_MASK) >>
	    chipcHw_REG_VPM_PHASE_STATUS_SHIFT;
}

/****************************************************************************/
/**
*  @brief   Get DDR phase control value
*
*/
/****************************************************************************/
static inline uint32_t chipcHw_getDdrPhaseControl(void)
{
	return (pChipcHw->
		PhaseAlignStatus & chipcHw_REG_DDR_PHASE_CTRL_MASK) >>
	    chipcHw_REG_DDR_PHASE_CTRL_SHIFT;
}

/****************************************************************************/
/**
*  @brief   Get VPM phase control value
*
*/
/****************************************************************************/
static inline uint32_t chipcHw_getVpmPhaseControl(void)
{
	return (pChipcHw->
		PhaseAlignStatus & chipcHw_REG_VPM_PHASE_CTRL_MASK) >>
	    chipcHw_REG_VPM_PHASE_CTRL_SHIFT;
}

/****************************************************************************/
/**
*  @brief   DDR phase alignment timeout count
*
*  @note    If HW fails to perform the phase alignment, it will trigger
*           a DDR phase alignment timeout interrupt.
*/
/****************************************************************************/
static inline void chipcHw_ddrHwPhaseAlignTimeout(uint32_t busCycle)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->DDRPhaseCtrl2 &=
	    ~(chipcHw_REG_DDR_PHASE_TIMEOUT_COUNT_MASK <<
	      chipcHw_REG_DDR_PHASE_TIMEOUT_COUNT_SHIFT);
	pChipcHw->DDRPhaseCtrl2 |=
	    (busCycle & chipcHw_REG_DDR_PHASE_TIMEOUT_COUNT_MASK) <<
	    chipcHw_REG_DDR_PHASE_TIMEOUT_COUNT_SHIFT;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   VPM phase alignment timeout count
*
*  @note    If HW fails to perform the phase alignment, it will trigger
*           a VPM phase alignment timeout interrupt.
*/
/****************************************************************************/
static inline void chipcHw_vpmHwPhaseAlignTimeout(uint32_t busCycle)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->VPMPhaseCtrl2 &=
	    ~(chipcHw_REG_VPM_PHASE_TIMEOUT_COUNT_MASK <<
	      chipcHw_REG_VPM_PHASE_TIMEOUT_COUNT_SHIFT);
	pChipcHw->VPMPhaseCtrl2 |=
	    (busCycle & chipcHw_REG_VPM_PHASE_TIMEOUT_COUNT_MASK) <<
	    chipcHw_REG_VPM_PHASE_TIMEOUT_COUNT_SHIFT;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Clear DDR phase alignment timeout interrupt
*
*/
/****************************************************************************/
static inline void chipcHw_ddrHwPhaseAlignTimeoutInterruptClear(void)
{
	REG_LOCAL_IRQ_SAVE;
	/* Clear timeout interrupt service bit */
	pChipcHw->DDRPhaseCtrl2 |= chipcHw_REG_DDR_INTR_SERVICED;
	pChipcHw->DDRPhaseCtrl2 &= ~chipcHw_REG_DDR_INTR_SERVICED;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   Clear VPM phase alignment timeout interrupt
*
*/
/****************************************************************************/
static inline void chipcHw_vpmHwPhaseAlignTimeoutInterruptClear(void)
{
	REG_LOCAL_IRQ_SAVE;
	/* Clear timeout interrupt service bit */
	pChipcHw->VPMPhaseCtrl2 |= chipcHw_REG_VPM_INTR_SERVICED;
	pChipcHw->VPMPhaseCtrl2 &= ~chipcHw_REG_VPM_INTR_SERVICED;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   DDR phase alignment timeout interrupt enable
*
*/
/****************************************************************************/
static inline void chipcHw_ddrHwPhaseAlignTimeoutInterruptEnable(void)
{
	REG_LOCAL_IRQ_SAVE;
	chipcHw_ddrHwPhaseAlignTimeoutInterruptClear();	/* Recommended */
	/* Enable timeout interrupt */
	pChipcHw->DDRPhaseCtrl2 |= chipcHw_REG_DDR_TIMEOUT_INTR_ENABLE;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   VPM phase alignment timeout interrupt enable
*
*/
/****************************************************************************/
static inline void chipcHw_vpmHwPhaseAlignTimeoutInterruptEnable(void)
{
	REG_LOCAL_IRQ_SAVE;
	chipcHw_vpmHwPhaseAlignTimeoutInterruptClear();	/* Recommended */
	/* Enable timeout interrupt */
	pChipcHw->VPMPhaseCtrl2 |= chipcHw_REG_VPM_TIMEOUT_INTR_ENABLE;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   DDR phase alignment timeout interrupt disable
*
*/
/****************************************************************************/
static inline void chipcHw_ddrHwPhaseAlignTimeoutInterruptDisable(void)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->DDRPhaseCtrl2 &= ~chipcHw_REG_DDR_TIMEOUT_INTR_ENABLE;
	REG_LOCAL_IRQ_RESTORE;
}

/****************************************************************************/
/**
*  @brief   VPM phase alignment timeout interrupt disable
*
*/
/****************************************************************************/
static inline void chipcHw_vpmHwPhaseAlignTimeoutInterruptDisable(void)
{
	REG_LOCAL_IRQ_SAVE;
	pChipcHw->VPMPhaseCtrl2 &= ~chipcHw_REG_VPM_TIMEOUT_INTR_ENABLE;
	REG_LOCAL_IRQ_RESTORE;
}

#endif /* CHIPC_INLINE_H */