Merge tag 'v5.15.57' into rpi-5.15.y
[platform/kernel/linux-rpi.git] / drivers / usb / host / dwc_otg / test / test_sysfs.pl
1 #!/usr/bin/perl -w
2 #
3 # Run this program on the integrator
4 # - Tests select sysfs attributes.
5 # - Todo ... test more attributes, hnp/srp, buspower/bussuspend, etc.
6 # -----------------------------------------------------------------------------
7 use strict;
8 use dwc_otg_test;
9
10 check_arch() or die;
11
12 #
13 #
14 sub test {
15   my ($attr,$expected) = @_;
16   my $string = get($attr);
17
18   if ($string eq $expected) {
19     printf("$attr = $string, okay\n");
20   }
21   else {
22     warn "ERROR: value of $attr != $expected, $string\n";
23     $errors ++;
24   }
25 }
26
27 #
28 #
29 sub set {
30   my ($reg, $value) = @_;
31   system "echo $value > $sysfsdir/$reg";
32 }
33
34 #
35 #
36 sub get {
37   my $attr = shift;
38   my $string = `cat $sysfsdir/$attr`;
39   chomp $string;
40   if ($string =~ m/\s\=\s/) {
41     my $tmp;
42     ($tmp, $string) = split /\s=\s/, $string;
43   }
44   return $string;
45 }
46
47 #
48 #
49 sub test_main {
50   print("\nTesting Sysfs Attributes\n");
51
52   load_module("") or die;
53
54   # Test initial values of regoffset/regvalue/guid/gsnpsid
55   print("\nTesting Default Values\n");
56
57   test("regoffset", "0xffffffff");
58   test("regvalue", "invalid offset");
59   test("guid", "0x12345678");   # this will fail if it has been changed
60   test("gsnpsid", "0x4f54200a");
61
62   # Test operation of regoffset/regvalue
63   print("\nTesting regoffset\n");
64   set('regoffset', '5a5a5a5a');
65   test("regoffset", "0xffffffff");
66
67   set('regoffset', '0');
68   test("regoffset", "0x00000000");
69
70   set('regoffset', '40000');
71   test("regoffset", "0x00000000");
72
73   set('regoffset', '3ffff');
74   test("regoffset", "0x0003ffff");
75
76   set('regoffset', '1');
77   test("regoffset", "0x00000001");
78
79   print("\nTesting regvalue\n");
80   set('regoffset', '3c');
81   test("regvalue", "0x12345678");
82   set('regvalue', '5a5a5a5a');
83   test("regvalue", "0x5a5a5a5a");
84   set('regvalue','a5a5a5a5');
85   test("regvalue", "0xa5a5a5a5");
86   set('guid','12345678');
87
88   # Test HNP Capable
89   print("\nTesting HNP Capable bit\n");
90   set('hnpcapable', '1');
91   test("hnpcapable", "0x1");
92   set('hnpcapable','0');
93   test("hnpcapable", "0x0");
94
95   set('regoffset','0c');
96
97   my $old = get('gusbcfg');
98   print("setting hnpcapable\n");
99   set('hnpcapable', '1');
100   test("hnpcapable", "0x1");
101   test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<9)));
102   test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<9)));
103
104   $old = get('gusbcfg');
105   print("clearing hnpcapable\n");
106   set('hnpcapable', '0');
107   test("hnpcapable", "0x0");
108   test ('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<9)));
109   test ('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<9)));
110
111   # Test SRP Capable
112   print("\nTesting SRP Capable bit\n");
113   set('srpcapable', '1');
114   test("srpcapable", "0x1");
115   set('srpcapable','0');
116   test("srpcapable", "0x0");
117
118   set('regoffset','0c');
119
120   $old = get('gusbcfg');
121   print("setting srpcapable\n");
122   set('srpcapable', '1');
123   test("srpcapable", "0x1");
124   test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<8)));
125   test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<8)));
126
127   $old = get('gusbcfg');
128   print("clearing srpcapable\n");
129   set('srpcapable', '0');
130   test("srpcapable", "0x0");
131   test('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<8)));
132   test('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<8)));
133
134   # Test GGPIO
135   print("\nTesting GGPIO\n");
136   set('ggpio','5a5a5a5a');
137   test('ggpio','0x5a5a0000');
138   set('ggpio','a5a5a5a5');
139   test('ggpio','0xa5a50000');
140   set('ggpio','11110000');
141   test('ggpio','0x11110000');
142   set('ggpio','00001111');
143   test('ggpio','0x00000000');
144
145   # Test DEVSPEED
146   print("\nTesting DEVSPEED\n");
147   set('regoffset','800');
148   $old = get('regvalue');
149   set('devspeed','0');
150   test('devspeed','0x0');
151   test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
152   set('devspeed','1');
153   test('devspeed','0x1');
154   test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
155   set('devspeed','2');
156   test('devspeed','0x2');
157   test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 2));
158   set('devspeed','3');
159   test('devspeed','0x3');
160   test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 3));
161   set('devspeed','4');
162   test('devspeed','0x0');
163   test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
164   set('devspeed','5');
165   test('devspeed','0x1');
166   test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
167
168
169   #  mode       Returns the current mode:0 for device mode1 for host mode       Read
170   #  hnp        Initiate the Host Negotiation Protocol.  Read returns the status.       Read/Write
171   #  srp        Initiate the Session Request Protocol.  Read returns the status.        Read/Write
172   #  buspower   Get or Set the Power State of the bus (0 - Off or 1 - On)       Read/Write
173   #  bussuspend Suspend the USB bus.    Read/Write
174   #  busconnected       Get the connection status of the bus    Read
175
176   #  gotgctl    Get or set the Core Control Status Register.    Read/Write
177   ##  gusbcfg   Get or set the Core USB Configuration Register  Read/Write
178   #  grxfsiz    Get or set the Receive FIFO Size Register       Read/Write
179   #  gnptxfsiz  Get or set the non-periodic Transmit Size Register      Read/Write
180   #  gpvndctl   Get or set the PHY Vendor Control Register      Read/Write
181   ##  ggpio     Get the value in the lower 16-bits of the General Purpose IO Register or Set the upper 16 bits. Read/Write
182   ##  guid      Get or set the value of the User ID Register    Read/Write
183   ##  gsnpsid   Get the value of the Synopsys ID Regester       Read
184   ##  devspeed  Get or set the device speed setting in the DCFG register        Read/Write
185   #  enumspeed  Gets the device enumeration Speed.      Read
186   #  hptxfsiz   Get the value of the Host Periodic Transmit FIFO        Read
187   #  hprt0      Get or Set the value in the Host Port Control and Status Register       Read/Write
188
189   test_status("TEST NYI") or die;
190 }
191
192 test_main();
193 0;