forked from omapconf/omapconf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomapconf.c
1207 lines (1104 loc) · 33 KB
/
omapconf.c
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
/*
*
* @Component OMAPCONF
* @Filename omapconf.c
* @Description omapconf main entry file
* @Author Patrick Titiano ([email protected])
* @Date 2010
* @Copyright Texas Instruments Incorporated
*
*
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <ctype.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <lib.h>
#include <lib44xx.h>
#include <main44xx.h>
#include <main54xx.h>
#include <dpll54xx.h>
#include <lib_android.h>
#include <i2c-tools.h>
#include <help.h>
#include <autoadjust_table.h>
#include <cpuinfo.h>
#include <signal.h>
#include <mem.h>
#include <lib54xx.h>
#include <trace.h>
#include <mem.h>
#include <opp.h>
#include <voltdomain.h>
#include <temperature.h>
#include <module.h>
#include <powerdomain.h>
#include <clockdomain.h>
/* #define DEBUG */
#ifdef DEBUG
/* #define OMAPCONF_READREG_DEBUG */
/* #define OMAPCONF_WRITEREG_DEBUG */
/* #define OMAPCONF_CLEARBIT_DEBUG */
/* #define OMAPCONF_SETBIT_DEBUG */
/* #define OMAPCONF_FIND_REG_ADDR_DEBUG */
/* #define OMAPCONF_ADDRESS_IN_VALID_RANGE_DEBUG */
#define dprintf(format, ...) printf(format, ## __VA_ARGS__)
#else
#define dprintf(format, ...)
#endif
static unsigned short cpu_found;
/* ------------------------------------------------------------------------*//**
* @FUNCTION main_readreg
* @BRIEF read OMAP register
* @RETURNS 0 in case of success
* -1 in case of incorrect register name/address
* -2 in case of incorrect format
* @param[in] reg_addr: register address
* can be hex value (with mandatory '0x' prefix) or name
* @param[in] val_format: value output format
* can be "hex", "bin" or "dec"
* @DESCRIPTION read OMAP register
*//*------------------------------------------------------------------------ */
static int main_readreg(const char *reg_addr, const char *val_format)
{
int ret = 0;
unsigned int value, addr;
char value_bin[33] = ""; /* 32 digits + '\0' */
char name[OMAPCONF_REG_NAME_MAX_LENGTH + 1] = "";
unsigned char by_name = 0;
#ifdef OMAPCONF_READREG_DEBUG
printf("%s(): reg_addr=%s\n", __func__, reg_addr);
#endif
/* Retrieve and check register address */
if ((reg_addr[0] == '0') && (reg_addr[1] == 'X')) {
/* As an integer, must start with "0x" */
ret = sscanf(reg_addr, "0X%x", &addr);
if (ret != 1) {
#ifdef OMAPCONF_READREG_DEBUG
printf("%s(): could not retrieve integer value\n",
__func__);
#endif
fprintf(stderr, "register address not recognized!\n");
return -1;
}
} else {
/* As a string, must start with alpha character */
if (isalpha(reg_addr[0])) {
ret = sscanf(reg_addr, "%50s", (char *) name);
if (ret != 1) {
#ifdef OMAPCONF_READREG_DEBUG
printf("%s(): could not retrieve name\n",
__func__);
#endif
fprintf(stderr,
"register name not recognized!\n");
return -1;
} else
by_name = 1;
} else {
fprintf(stderr,
"register name/address not recognized!\n");
return -1;
}
}
#ifdef OMAPCONF_READREG_DEBUG
if (by_name)
printf("%s(): found reg_addr = %s\n", __func__, name);
else
printf("%s(): found reg_addr = 0x%08X\n", __func__, addr);
#endif
/*
* If reg. name was entered, check name is valid and retrieve reg. addr.
*/
if (by_name == 1) {
ret = find_reg_addr((char *) name, &addr);
if (ret != 0) {
fprintf(stderr, "not a valid register name!\n");
return -1;
}
#ifdef OMAPCONF_READREG_DEBUG
else
printf("%s(): reg. addr. found. (0x%08X)\n",
__func__, addr);
#endif
}
/* Check data format is valid */
if ((strcmp(val_format, "hex") != 0) &&
(strcmp(val_format, "bin") != 0) &&
(strcmp(val_format, "dec") != 0)) {
fprintf(stderr, "not a valid format! (%s)\n", val_format);
return -2;
}
/* Reaching this point means arguments OK */
#ifdef OMAPCONF_READREG_DEBUG
printf("%s(): addr=%x\n", __func__, addr);
printf("%s(): name=%s\n", __func__, name);
printf("%s(): format=%s\n", __func__, val_format);
printf("%s(): ret=%d\n", __func__, ret);
#endif
/* Read OMAP register */
ret = mem_read(addr, &value);
if (ret != 0) {
fprintf(stderr, "internal error (failed to read)!\n");
return OMAPCONF_ERR_REG_ACCESS;
}
/* Display value in selected format */
if (strcmp(val_format, "hex") == 0) {
printf("%08X\n", value);
} else if (strcmp(val_format, "bin") == 0) {
/* compiler does not understand %b, so do it manually */
/* printf("%b\n", value); */
printf("%s\n", bin2str_32(value_bin, value));
} else {
/* val_format == "dec" */
printf("%d\n", value);
}
return 0;
}
/* ------------------------------------------------------------------------*//**
* @FUNCTION main_writereg
* @BRIEF write into OMAP register
* @RETURNS 0 in case of success
* -1 in case of incorrect register name/address
* -2 in case of incorrect format
* @param[in] reg_addr: register address
* can be hex value (with mandatory'0x' prefix) or name
* @param[in] reg_val: value to be written into reg_addr
* @DESCRIPTION write into OMAP register
*//*------------------------------------------------------------------------ */
static int main_writereg(const char *reg_addr, const char *reg_val)
{
int ret = 0;
unsigned int value, addr;
char name[OMAPCONF_REG_NAME_MAX_LENGTH + 1] = "";
unsigned char by_name = 0;
#ifdef OMAPCONF_WRITEREG_DEBUG
printf("%s(): reg_addr=%s\n", __func__, reg_addr);
printf("%s(): reg_val=%s\n", __func__, reg_val);
#endif
/* Retrieve and check register address */
if ((reg_addr[0] == '0') && (reg_addr[1] == 'X')) {
/* As an integer, must start with "0x" */
ret = sscanf(reg_addr, "0X%x", &addr);
if (ret != 1) {
#ifdef OMAPCONF_WRITEREG_DEBUG
printf("%s(): could not retrieve integer value\n",
__func__);
#endif
fprintf(stderr,
"register address not recognized!\n");
return -1;
}
} else {
/* As a string, must start with alpha character */
if (isalpha(reg_addr[0])) {
ret = sscanf(reg_addr, "%50s", (char *) name);
if (ret != 1) {
#ifdef OMAPCONF_WRITEREG_DEBUG
printf("(): could not retrieve name\n",
__func__);
#endif
fprintf(stderr,
"register name not recognized!\n");
return -1;
} else
by_name = 1;
} else {
fprintf(stderr,
"register name/address not recognized!\n");
return -1;
}
}
#ifdef OMAPCONF_WRITEREG_DEBUG
if (by_name)
printf("%s(): found reg_addr = %s\n", __func__, name);
else
printf("%s(): found reg_addr = 0x%08X\n", __func__, addr);
#endif
/*
* If reg. name was entered, check name is valid and retrieve reg. addr.
*/
if (by_name == 1) {
ret = find_reg_addr((char *) name, &addr);
if (ret != 0) {
fprintf(stderr, "not a valid register name!\n");
return -1;
}
#ifdef OMAPCONF_WRITEREG_DEBUG
else
printf("%s(): reg. addr. found. (0x%08X)\n",
__func__, addr);
#endif
}
/* Retrieve and check value to be written into register */
if ((reg_val[0] == '0') && (reg_val[1] == 'X')) {
/* As an integer, must start with "0x" */
ret = sscanf(reg_val, "0X%x", &value);
if (ret != 1) {
#ifdef OMAPCONF_WRITEREG_DEBUG
printf("%s(): could not retrieve integer value\n",
__func__);
#endif
fprintf(stderr,
"register address not recognized!\n");
return -2;
}
} else {
fprintf(stderr,
"value to be written not recognized!\n");
return -2;
}
#ifdef OMAPCONF_WRITEREG_DEBUG
printf("%s(): found value = 0x%08X\n", __func__, value);
#endif
/* Reaching this point means arguments OK */
#ifdef OMAPCONF_WRITEREG_DEBUG
printf("%s(): addr=0x%x\n", __func__, addr);
printf("%s(): name=%s\n", __func__, name);
printf("%s(): value=0x%x\n", __func__, value);
printf("%s(): ret=%d\n", __func__, ret);
#endif
/* Write OMAP register */
ret = mem_write(addr, value);
if (ret != 0) {
fprintf(stderr, "internal error (failed to write)!\n");
return OMAPCONF_ERR_REG_ACCESS;
}
return ret;
}
/* ------------------------------------------------------------------------*//**
* @FUNCTION main_clearbit
* @BRIEF clear given bit into OMAP register
* @RETURNS 0 in case of success
* OMAPCONF_ERR_ARG
* OMAPCONF_ERR_REG_ACCESS
* @param[in] argc: shell input argument number
* @param[in] argv: shell input argument(s)
* @DESCRIPTION clear given bit into OMAP register
*//*------------------------------------------------------------------------ */
static int main_clearbit(int argc, char *argv[])
{
int ret = 0;
unsigned int pos, value, value2, addr;
char name[OMAPCONF_REG_NAME_MAX_LENGTH + 1] = "";
unsigned char by_name = 0;
if (strcmp(argv[0], "clear") != 0)
goto main_clearbit_arg_err;
if (strcmp(argv[1], "bit") != 0)
goto main_clearbit_arg_err;
if (argc != 4)
goto main_clearbit_arg_err;
argv[2] = uppercase(argv[2]);
#ifdef OMAPCONF_CLEARBIT_DEBUG
printf("%s(): argv[0]=%s\n", __func__, argv[0]);
printf("%s(): argv[1]=%s\n", __func__, argv[1]);
printf("%s(): argv[2]=%s\n", __func__, argv[2]);
printf("%s(): argv[3]=%s\n", __func__, argv[3]);
#endif
/* Retrieve and check register address */
if ((argv[2][0] == '0') && (argv[2][1] == 'X')) {
/* As an integer, must start with "0x" */
ret = sscanf(argv[2], "0X%x", &addr);
if (ret != 1) {
#ifdef OMAPCONF_CLEARBIT_DEBUG
printf("%s(): could not retrieve integer value\n",
__func__);
#endif
goto main_clearbit_arg_err;
}
} else {
/* As a string, must start with alpha character */
if (isalpha(argv[2][0])) {
ret = sscanf(argv[2], "%72s", (char *) name);
if (ret != 1) {
#ifdef OMAPCONF_CLEARBIT_DEBUG
printf("%s(): could not retrieve name\n",
__func__);
#endif
goto main_clearbit_arg_err;
} else
by_name = 1;
} else {
goto main_clearbit_arg_err;
}
}
#ifdef OMAPCONF_CLEARBIT_DEBUG
if (by_name)
printf("%s(): found reg_addr = %s\n", __func__, name);
else
printf("%s(): found reg_addr = 0x%08X\n", __func__, addr);
#endif
/*
* If reg. name was entered, check name is valid and retrieve reg. addr.
*/
if (by_name == 1) {
ret = find_reg_addr((char *) name, &addr);
if (ret != 0) {
printf("Not a valid register name! (%s)\n", name);
return OMAPCONF_ERR_ARG;
}
#ifdef OMAPCONF_CLEARBIT_DEBUG
else
printf("%s(): reg. addr. found. (0x%08X)\n",
__func__, addr);
#endif
}
/* Retrieve and check bit position */
ret = sscanf(argv[3], "%u", &pos);
if (ret != 1) {
#ifdef OMAPCONF_CLEARBIT_DEBUG
printf("%s(): could not retrieve bit position\n",
__func__);
#endif
goto main_clearbit_arg_err;
}
if (pos >= 32) {
printf("Incorrect bit position! (%s)\n", argv[3]);
return OMAPCONF_ERR_ARG;
}
#ifdef OMAPCONF_CLEARBIT_DEBUG
printf("%s(): found position = %u\n", __func__, pos);
#endif
/* Reaching this point means arguments OK */
#ifdef OMAPCONF_CLEARBIT_DEBUG
printf("%s(): addr=0x%x\n", __func__, addr);
printf("%s(): name=%s\n", __func__, name);
printf("%s(): pos=%d\n", __func__, pos);
printf("%s(): ret=%d\n", __func__, ret);
#endif
/* Clear bit in OMAP register */
ret = mem_read(addr, &value);
if (ret != 0) {
fprintf(stderr, "internal error (failed to write)!\n");
return OMAPCONF_ERR_REG_ACCESS;
}
#ifdef OMAPCONF_CLEARBIT_DEBUG
printf("%s(): value=0x%x\n", __func__, value);
printf("%s(): 1<<pos=0x%x\n", __func__, 1 << pos);
printf("%s(): ~(1<<pos)=0x%x\n", __func__, ~(1 << pos));
printf("%s(): value & ~(1<<pos)=0x%x\n", __func__, value & ~(1 << pos));
#endif
ret = mem_write(addr, value & ~(1 << pos));
if (ret != 0) {
fprintf(stderr, "internal error (failed to write)!\n");
return OMAPCONF_ERR_REG_ACCESS;
}
ret = mem_read(addr, &value2);
if (ret != 0) {
fprintf(stderr, "internal error (failed to read back)!\n");
return OMAPCONF_ERR_REG_ACCESS;
}
printf("@0x%08X: 0x%08X ==> 0x%08X\n\n", addr, value, value2);
return ret;
main_clearbit_arg_err:
help(HELP_RW);
return 0;
}
/* ------------------------------------------------------------------------*//**
* @FUNCTION main_setbit
* @BRIEF set given bit into OMAP register
* @RETURNS 0 in case of success
* OMAPCONF_ERR_ARG
* OMAPCONF_ERR_REG_ACCESS
* @param[in] argc: shell input argument number
* @param[in] argv: shell input argument(s)
* @DESCRIPTION set given bit into OMAP register
*//*------------------------------------------------------------------------ */
static int main_setbit(int argc, char *argv[])
{
int ret = 0;
unsigned int pos, value, value2, addr;
char name[OMAPCONF_REG_NAME_MAX_LENGTH + 1] = "";
unsigned char by_name = 0;
if (strcmp(argv[0], "set") != 0)
goto main_setbit_arg_err;
if (strcmp(argv[1], "bit") != 0)
goto main_setbit_arg_err;
if (argc != 4)
goto main_setbit_arg_err;
argv[2] = uppercase(argv[2]);
#ifdef OMAPCONF_SETBIT_DEBUG
printf("%s(): argv[0]=%s\n", __func__, argv[0]);
printf("%s(): argv[1]=%s\n", __func__, argv[1]);
printf("%s(): argv[2]=%s\n", __func__, argv[2]);
printf("%s(): argv[3]=%s\n", __func__, argv[3]);
#endif
/* Retrieve and check register address */
if ((argv[2][0] == '0') && (argv[2][1] == 'X')) {
/* As an integer, must start with "0x" */
ret = sscanf(argv[2], "0X%x", &addr);
if (ret != 1) {
#ifdef OMAPCONF_SETBIT_DEBUG
printf("%s(): could not retrieve integer value\n",
__func__);
#endif
goto main_setbit_arg_err;
}
} else {
/* As a string, must start with alpha character */
if (isalpha(argv[2][0])) {
ret = sscanf(argv[2], "%72s", (char *) name);
if (ret != 1) {
#ifdef OMAPCONF_SETBIT_DEBUG
printf("%s(): could not retrieve name\n",
__func__);
#endif
goto main_setbit_arg_err;
} else
by_name = 1;
} else
goto main_setbit_arg_err;
}
#ifdef OMAPCONF_SETBIT_DEBUG
if (by_name)
printf("%s(): found reg_addr = %s\n", __func__, name);
else
printf("%s(): found reg_addr = 0x%08X\n", __func__, addr);
#endif
/*
* If reg. name was entered, check name is valid and retrieve reg. addr.
*/
if (by_name == 1) {
ret = find_reg_addr((char *) name, &addr);
if (ret != 0) {
printf("Not a valid register name! (%s)\n", name);
return OMAPCONF_ERR_ARG;
}
#ifdef OMAPCONF_SETBIT_DEBUG
else
printf("%s(): reg. addr. found. (0x%08X)\n",
__func__, addr);
#endif
}
/* Retrieve and check bit position */
ret = sscanf(argv[3], "%u", &pos);
if (ret != 1) {
#ifdef OMAPCONF_SETBIT_DEBUG
printf("%s(): could not retrieve bit position\n",
__func__);
#endif
goto main_setbit_arg_err;
}
if (pos > 31) {
printf("Incorrect bit position! (%s)\n", argv[3]);
return OMAPCONF_ERR_ARG;
}
#ifdef OMAPCONF_SETBIT_DEBUG
printf("%s(): found position = %u\n", __func__, pos);
#endif
/* Reaching this point means arguments OK */
#ifdef OMAPCONF_SETBIT_DEBUG
printf("%s(): addr=0x%x\n", __func__, addr);
printf("%s(): name=%s\n", __func__, name);
printf("%s(): pos=%d\n", __func__, pos);
printf("%s(): ret=%d\n", __func__, ret);
#endif
/* Set bit in OMAP register */
ret = mem_read(addr, &value);
if (ret != 0) {
fprintf(stderr, "internal error (failed to read)!\n");
return OMAPCONF_ERR_REG_ACCESS;
}
#ifdef OMAPCONF_SETBIT_DEBUG
printf("%s(): value = 0x%x\n", __func__, value);
printf("%s(): 1 << pos = 0x%x\n", __func__, 1 << pos);
printf("%s(): value | (1 << pos) = 0x%x\n",
__func__, value | (1 << pos));
#endif
ret = mem_write(addr, value | (1 << pos));
if (ret != 0) {
fprintf(stderr, "internal error (failed to write)!\n");
return OMAPCONF_ERR_REG_ACCESS;
}
ret = mem_read(addr, &value2);
if (ret != 0) {
fprintf(stderr, "internal error (failed to read back)!\n");
return OMAPCONF_ERR_REG_ACCESS;
}
printf("@0x%08X: 0x%08X ==> 0x%08X\n\n", addr, value, value2);
return ret;
main_setbit_arg_err:
help(HELP_RW);
return 0;
}
/* ------------------------------------------------------------------------*//**
* @FUNCTION main_i2c_read
* @BRIEF read given data from given address of given device of
* given I2C bus
* @RETURNS 0 in case of success
* OMAPCONF_ERR_ARG
* OMAPCONF_ERR_NOT_AVAILABLE
* OMAPCONF_ERR_REG_ACCESS
* @param[in] argc: shell input argument number
* argc must be 5
* @param[in] argv: shell input argument(s)
* argv[2] = i2cbus: I2C bus number
* argv[3] = address: I2C device address
* argv[4] = daddress: I2C device register address
* @DESCRIPTION read given data from given address of given device of
* given I2C bus
*//*------------------------------------------------------------------------ */
static int main_i2c_read(int argc, char *argv[])
{
unsigned int i2cbus, chip_address, data_address;
unsigned int data;
int ret;
CHECK_NULL_ARG(argv, OMAPCONF_ERR_ARG);
/* Retrieve arguments */
if (argc != 5)
goto main_i2c_read_err;
ret = sscanf(argv[2], "%u", &i2cbus);
if (ret != 1)
goto main_i2c_read_err;
ret = sscanf(argv[3], "0x%x", &chip_address);
if (ret != 1)
goto main_i2c_read_err;
ret = sscanf(argv[4], "0x%x", &data_address);
if (ret != 1)
goto main_i2c_read_err;
ret = i2cget(i2cbus, chip_address, data_address, &data);
if (ret == 0)
printf("0x%02x\n", data);
return ret;
main_i2c_read_err:
printf(
"Usage: omapconf i2c read 'i2cbus' 0x'chip-address' 0x'data-address'\n");
printf(" 'i2cbus' is decimal value.\n");
printf(" 'chip-address' & 'data-address' are hexadecimal values.\n");
printf(" Warning: prefix '0x' is mandatory.\n");
return OMAPCONF_ERR_ARG;
}
/* ------------------------------------------------------------------------*//**
* @FUNCTION main_i2c_write
* @BRIEF write given data at given address of given device of
* given I2C bus
* @RETURNS 0 in case of success
* OMAPCONF_ERR_ARG
* OMAPCONF_ERR_NOT_AVAILABLE
* OMAPCONF_ERR_REG_ACCESS
* @param[in] argc: shell input argument number
* argc must be 6
* @param[in] argv: shell input argument(s)
* argv[2] = i2cbus: I2C bus number
* argv[3] = address: I2C device address
* argv[4] = daddress: I2C device register address
* argv[5] = data: data to be written
* @DESCRIPTION write given data at given address of given device of
* given I2C bus
*//*------------------------------------------------------------------------ */
static int main_i2c_write(int argc, char *argv[])
{
unsigned int i2cbus, chip_address, data_address;
unsigned int data;
int ret;
if (argv == NULL) {
printf("%s(): argv == NULL!!!\n", __func__);
return OMAPCONF_ERR_ARG;
}
/* Retrieve arguments */
if (argc != 6)
goto main_i2c_write_err;
ret = sscanf(argv[2], "%u", &i2cbus);
if (ret != 1)
goto main_i2c_write_err;
ret = sscanf(argv[3], "0x%x", &chip_address);
if (ret != 1)
goto main_i2c_write_err;
ret = sscanf(argv[4], "0x%x", &data_address);
if (ret != 1)
goto main_i2c_write_err;
ret = sscanf(argv[5], "0x%x", &data);
if (ret != 1)
goto main_i2c_write_err;
ret = i2cset(i2cbus, chip_address, data_address, data);
return ret;
main_i2c_write_err:
printf(
"Usage: omapconf i2c write 'i2cbus' 0x'chip-address' 0x'data-address' 0x'data'\n");
printf(" 'i2cbus' is decimal value.\n");
printf(
" 'chip-address', 'data-address' & 'data' are hexadecimal values.\n");
printf(" Warning: prefix '0x' is mandatory.\n");
return OMAPCONF_ERR_ARG;
}
/* ------------------------------------------------------------------------*//**
* @FUNCTION main_sigbus_handler
* @BRIEF catch bus error and print failing memory physical
* address
* @DESCRIPTION catch bus error and print failing memory physical
* address
*//*------------------------------------------------------------------------ */
static void main_sigbus_handler(int sig, siginfo_t *siginfo, void *context)
{
/* just to remove "unused parameter" warnings ... */
sig = sig;
siginfo = siginfo;
context = context;
dprintf("%s(): sig=%d siginfo=0x%08X, context=0x%08X\n", __func__, sig,
(unsigned int) siginfo, (unsigned int) context);
fprintf(stderr, "\n\n!!! OUPS... MEMORY ERROR @ 0x%08X !!!\n",
mem_last_addr_get());
fprintf(stderr, "Are you sure that:\n");
fprintf(stderr, " MEMORY ADDRESS IS VALID?\n");
fprintf(stderr, " TARGETED MODULE IS CLOCKED?\n\n");
exit(-1);
}
/* ------------------------------------------------------------------------*//**
* @FUNCTION main_arguments_lowercase
* @BRIEF make sure all user arguments are in lower case.
* @RETURNS none
* @param[in, out] argc: shell input argument number
* @param[in, out] argv: shell input argument(s)
* @DESCRIPTION make sure all user arguments are in lower case, so that
* case can be ignored further on.
*//*------------------------------------------------------------------------ */
static void main_arguments_lowercase(int argc, char *argv[])
{
int i;
for (i = 0; i < argc; i++) {
dprintf("%s(): Before: argv[%d] = '%s'\n",
__func__, argc, argv[i]);
lowercase(argv[i]);
dprintf("%s(): After: argv[%d] = '%s'\n",
__func__, argc, argv[i]);
}
}
/* ------------------------------------------------------------------------*//**
* @FUNCTION main_options_scan
* @BRIEF search for omapconf option(s) in argv and set it.
* Remove found option(s) from argv (by increasing argv
* pointer).
* @RETURNS >= 0 number of options found
* OMAPCONF_ERR_ARG
* @param[in, out] argc: shell input argument number
* @param[in, out] argv: shell input argument(s)
* @DESCRIPTION search for omapconf option(s) in argv and set it.
* Remove found option(s) from argv (by increasing argv
* pointer).
*//*------------------------------------------------------------------------ */
static int main_options_scan(int *argc, char **argv[])
{
int ret = 0, cpt = 0;
int i;
if (argc == NULL) {
fprintf(stderr, "%s(): argc == NULL!!!\n", __func__);
goto main_options_scan_err;
}
if (argv == NULL) {
fprintf(stderr, "%s(): argv == NULL!!!\n", __func__);
goto main_options_scan_err;
}
for (i = 0; i < *argc; i++) {
if (strcmp((*argv)[i], "--import") == 0) {
dprintf("%s(): found option \"--import\" at i=%u\n",
__func__, i);
if (i + 1 == *argc) {
/* missing import file name, abort */
omapconf_revision_show(stdout);
printf("Error: missing import file name!\n\n");
help(HELP_ALL);
goto main_options_scan_err;
}
if (!cpu_is_omap54xx()) {
printf(
"Sorry, only available for OMAP5...\n\n");
goto main_options_scan_err;
}
/* Import register content from file */
ret = lib54xx_import((*argv)[i + 1]);
if (ret != 0) {
omapconf_revision_show(stdout);
printf(
"Oups, error during import from \"%s\" :-(\n\n",
(*argv)[i + 1]);
goto main_options_scan_err;
} else {
printf(
"### Registers successfully imported from \"%s\" file. ###\n\n",
(*argv)[i + 1]);
}
cpt += 2;
ret++;
} else if (strcmp((*argv)[i], "--force") == 0) {
dprintf("%s(): found option \"--force\" at i=%u\n",
__func__, i);
if (i + 1 == *argc) {
/* missing forced cpu name, abort */
omapconf_revision_show(stdout);
printf("Error, missing forced CPU name!\n\n");
help(HELP_FORCEDETECT);
goto main_options_scan_err;
}
/* Force detection of selected CPU */
ret = cpu_force((*argv)[i + 1]);
if (ret != 0) {
omapconf_revision_show(stdout);
printf(
"\"%s\" CPU is not supported, see list of supported CPU below.\n\n",
(*argv)[i + 1]);
help(HELP_FORCEDETECT);
goto main_options_scan_err;
}
cpu_found = 1;
cpt += 2;
ret++;
} else if (strcmp((*argv)[i], "--norw") == 0) {
dprintf("%s(): found option \"--norw\" at i=%u\n",
__func__, i);
/* Enable fake memory access debug mode */
mem_fake_access_set(1);
printf(
"\n### FAKE MEMORY ACCESS DEBUG MODE ENABLED ###\n\n");
cpt++;
ret++;
} else if (strcmp((*argv)[i], "--trace_read") == 0) {
/* Trace all memory read access */
mem_read_trace_enable(1);
cpt++;
ret++;
} else if (strcmp((*argv)[i], "--trace_write") == 0) {
/* Trace all memory write access */
mem_write_trace_enable(1);
cpt++;
ret++;
}
}
/* "Remove" arguments from argv */
(*argc) -= cpt;
(*argv) += cpt;
goto main_options_scan_end;
main_options_scan_err:
ret = OMAPCONF_ERR_ARG;
main_options_scan_end:
dprintf("%s(): ret=%d\n", __func__, ret);
return ret;
}
/* ------------------------------------------------------------------------*//**
* @FUNCTION main
* @BRIEF main entry point
* @RETURNS 0 on success
* OMAPCONF_ERR_CPU
* OMAPCONF_ERR_ARG
* OMAPCONF_ERR_REG_ACCESS
* @param[in, out] argc: shell input argument number
* @param[in, out] argv: shell input argument(s)
* @DESCRIPTION main entry point
*//*------------------------------------------------------------------------ */
int main(int argc, char *argv[])
{
int ret;
struct sigaction act;
unsigned int start, end, time, delay;
double sampling_rate;
char *prefix;
char *cfgfile;
int c;
cpu_found = 0;
ret = 0;
/* Register signal handler in order to catch incorrect memory access. */
act.sa_sigaction = &main_sigbus_handler;
act.sa_flags = SA_SIGINFO;
sigaction(SIGBUS, &act, NULL);
/* Some of the omapconf functions do not support DEVICE OFF Mode,
* so by default acquire a wakelock if OS is Android.
*/
if (os_is_android())
wakelock_acquire();
/* To be case-insensitive, lowercase all arguments */
main_arguments_lowercase(argc, argv);
/* Scan user arguments for options */
argc--;
argv++;
ret = main_options_scan(&argc, &argv);
if (ret < 0)
goto main_exit;
if (!cpu_is_forced()) {
/* Detect CPU if not user-enforced */
ret = cpu_detect();
switch (ret) {
case 0:
cpu_found = 1;
break;
case OMAPCONF_ERR_REG_ACCESS:
omapconf_revision_show(stdout);
printf("'/dev/mem' could not be opened.\n");
printf(
"Privileged access required to run omapconf.\n\n");
ret = OMAPCONF_ERR_REG_ACCESS;
goto main_exit;
case OMAPCONF_ERR_CPU:
printf(
"Warning: chip not recognized, running in safe mode (only platform-generic functions allowed).\n\n");
break;
case OMAPCONF_ERR_UNEXPECTED:
default:
omapconf_revision_show(stdout);
printf("Unexpected error, sorry ... (%d)\n\n", ret);
ret = OMAPCONF_ERR_UNEXPECTED;
goto main_exit;
}
}
if (argc == 0) {
help(HELP_USAGE);
ret = OMAPCONF_ERR_ARG;
goto main_exit;
}
/* Platform-generic functions, no need to detect cpu */
if (strcmp(argv[0], "--help") == 0) {
omapconf_revision_show(stdout);
help(HELP_ALL);
ret = 0;
goto main_exit;
} else if (strcmp(argv[0], "--version") == 0) {
omapconf_revision_show(stdout);
ret = 0;
goto main_exit;
} else if (strcmp(argv[0], "--cpuinfo") == 0) {
omapconf_revision_show(stdout);
chips_info_show(stdout, 1);
ret = 0;
goto main_exit;
} else if (strcmp(argv[0], "--buildinfo") == 0) {
omapconf_revision_show(stdout);
release_info_show(stdout);
ret = 0;
goto main_exit;
} else if (strcmp(argv[0], "read") == 0) {
if ((argc >= 2) &&
(strcmp(argv[1], "audioic") == 0)) {
goto main_platform_specific;
} else if ((argc >= 2) &&
(strcmp(argv[1], "i2c") == 0)) {
if (argc < 5) {
ret = err_arg_missing_msg_show(HELP_I2C_RW);
goto main_exit;
} else if (argc == 5) {
ret = main_i2c_read(argc, argv);