]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/xscale/triton270/v2_0/include/triton270_1w_dev.inl
RedBoot TX53 Release 2012-02-15
[karo-tx-redboot.git] / packages / hal / arm / xscale / triton270 / v2_0 / include / triton270_1w_dev.inl
1
2 #define SNO_WRITE_SCRATCHPAD            0x0f
3 #define SNO_READ_SCRATCHPAD             0xaa
4 #define SNO_COPY_SCRATCHPAD             0x55
5 #define SNO_READ_MEMORY                 0xf0
6 #define SNO_WRITE_APPLICATION_REG       0x99
7 #define SNO_READ_STATUS_REG             0x66
8 #define SNO_READ_APPLICATION_REG        0xc3
9 #define SNO_COPY_LOCK                   0x5a
10 #define SNO_READ_ROM                    0x33
11 #define SNO_MATCH_ROM                   0x55
12 #define SNO_SKIP_ROM                    0xcc
13 #define SNO_SEARCH_ROM                  0xf0
14
15 int reset_1w(void)
16 {
17         int fu_result;
18
19         asm volatile (
20                       "ldr r4, =0x00000020;"    // mask for GPIO 5
21
22                       "ldr r5, =0x40e0000c;"    // pin dir register
23                       "ldr r6, [r5];"
24                       "orr r6, r6, r4;"
25                       "str r6, [r5];"           // set GPIO to output
26
27                       "ldr r5, =0x40e00024;"    // output clear register
28                       "str r4, [r5];"           // reset pin
29
30                       "ldr r5, =0x40a00010;"    // timer 500 usec
31                       "ldr r6, [r5];"
32                       "ldr r7, =1800;"
33                       "adc r6, r6, r7;"
34
35                       "112:;"
36                       "ldr r7, [r5];"
37                       "cmp r7, r6;"
38                       "bls 112b;"
39
40                       "ldr r5, =0x40e00018;"    // output set register
41                       "str r4, [r5];"           // reset pin
42
43                       "ldr r5, =0x40e0000c;"    // pin dir register
44                       "ldr r6, [r5];"
45                       "bic r6, r6, r4;"
46                       "str r6, [r5];"           // set GPIO to input
47
48                       "ldr r5, =0x40a00010;"    // timer 80 usec
49                       "ldr r6, [r5];"
50                       "ldr r7, =288;"
51                       "adc r6, r6, r7;"
52
53                       "113:;"
54                       "ldr r7, [r5];"
55                       "cmp r7, r6;"
56                       "bls 113b;"
57
58                       "ldr r5, =0x40e00000;"    // pin level register
59                       "ldr r6, [r5];"
60                       "and r6, r6, r4;"
61                       "mov %0, r6, lsr#5;"      // shift right by 5
62
63                       "ldr r5, =0x40a00010;"    // timer 500 usec
64                       "ldr r6, [r5];"
65                       "ldr r7, =1800;"
66                       "adc r6, r6, r7;"
67
68                       "114:;"
69                       "ldr r7, [r5];"
70                       "cmp r7, r6;"
71                       "bls 114b;"
72
73                       : "=r"(fu_result)
74                       :
75                       : "r4","r5","r6","r7");
76
77         return fu_result;
78 }
79
80 int sno_read(void)
81 {
82         int fu_result;
83
84         asm volatile (
85                       "ldr r4, =0x00000020;"    // mask for GPIO 5
86
87                       "ldr r5, =0x40e0000c;"    // pin dir register
88                       "ldr r6, [r5];"
89                       "orr r6, r6, r4;"
90                       "str r6, [r5];"           // set GPIO to output
91
92                       "ldr r5, =0x40e00024;"    // output clear register
93                       "str r4, [r5];"           // reset pin
94
95                       "ldr r5, =0x40a00010;"    // timer 5 usec
96                       "ldr r6, [r5];"
97                       "adc r6, r6, #18;"
98
99                       "112:;"
100                       "ldr r7, [r5];"
101                       "cmp r7, r6;"
102                       "bls 112b;"
103
104                       "ldr r5, =0x40e00018;"    // output set register
105                       "str r4, [r5];"           // reset pin
106
107                       "ldr r5, =0x40e0000c;"    // pin dir register
108                       "ldr r6, [r5];"
109                       "bic r6, r6, r4;"
110                       "str r6, [r5];"           // set GPIO to input
111
112                       "ldr r5, =0x40a00010;"    // timer 5 usec
113                       "ldr r6, [r5];"
114                       "adc r6, r6, #18;"
115
116                       "113:;"
117                       "ldr r7, [r5];"
118                       "cmp r7, r6;"
119                       "bls 113b;"
120
121                       "ldr r5, =0x40e00000;"    // pin level register
122                       "ldr r6, [r5];"
123                       "and r6, r6, r4;"
124                       "mov %0, r6, lsr#5;"      // shift right by 5
125
126                       : "=r"(fu_result)
127                       :
128                       : "r4","r5","r6","r7");
129
130         return fu_result;
131 }
132
133 void sno_write_1(void)
134 {
135         asm volatile (
136                       "ldr r4, =0x00000020;"    // mask for GPIO 5
137
138                       "ldr r5, =0x40e0000c;"    // pin dir register
139                       "ldr r6, [r5];"
140                       "orr r6, r6, r4;"
141                       "str r6, [r5];"           // set GPIO to output
142
143                       "ldr r5, =0x40e00024;"    // output clear register
144                       "str r4, [r5];"           // reset pin
145
146                       "ldr r5, =0x40a00010;"    // timer 5 usec
147                       "ldr r6, [r5];"
148                       "adc r6, r6, #18;"
149
150                       "112:;"
151                       "ldr r7, [r5];"
152                       "cmp r7, r6;"
153                       "bls 112b;"
154
155                       "ldr r5, =0x40e00018;"    // output set register
156                       "str r4, [r5];"           // reset pin
157
158                       "ldr r5, =0x40e0000c;"    // pin dir register
159                       "ldr r6, [r5];"
160                       "bic r6, r6, r4;"
161                       "str r6, [r5];"           // set GPIO to input
162
163                       "ldr r5, =0x40a00010;"    // timer 60 usec
164                       "ldr r6, [r5];"
165                       "adc r6, r6, #214;"
166
167                       "113:;"
168                       "ldr r7, [r5];"
169                       "cmp r7, r6;"
170                       "bls 113b;"
171
172                       :
173                       :
174                       : "r4","r5","r6","r7");
175 }
176
177 void sno_write_0(void)
178 {
179         asm volatile (
180                       "ldr r4, =0x00000020;"    // mask for GPIO 5
181
182                       "ldr r5, =0x40e0000c;"    // pin dir register
183                       "ldr r6, [r5];"
184                       "orr r6, r6, r4;"
185                       "str r6, [r5];"           // set GPIO to output
186
187                       "ldr r5, =0x40e00024;"    // output clear register
188                       "str r4, [r5];"           // reset pin
189
190                       "ldr r5, =0x40a00010;"    // timer 67 usec
191                       "ldr r6, [r5];"
192                       "adc r6, r6, #240;"
193
194                       "112:;"
195                       "ldr r7, [r5];"
196                       "cmp r7, r6;"
197                       "bls 112b;"
198
199                       "ldr r5, =0x40e00018;"    // output set register
200                       "str r4, [r5];"           // reset pin
201
202                       "ldr r5, =0x40e0000c;"    // pin dir register
203                       "ldr r6, [r5];"
204                       "bic r6, r6, r4;"
205                       "str r6, [r5];"           // set GPIO to input
206
207                       :
208                       :
209                       : "r4","r5","r6","r7");
210 }
211
212 void sno_write_byte (unsigned char sbyte)
213 {
214         unsigned char mask;
215         int i;
216
217         mask = 0x01;
218         for (i = 0; i < 8; i++) {
219                 if (sbyte & mask) {
220                         sno_write_1();
221                 } else {
222                         sno_write_0();
223                 }
224                 mask <<= 1;
225                 HAL_DELAY_US(1);
226         }
227 }
228
229 unsigned char sno_read_byte (void)
230 {
231         unsigned char mask = 0x01;
232         unsigned char abyte = 0x00;
233         unsigned char return_value;
234         int i;
235
236         for (i = 0; i < 8; i++) {
237                 return_value = sno_read();
238                 if (return_value) {
239                         abyte |= mask;
240                 }
241                 HAL_DELAY_US(80);
242                 mask <<= 1;
243         }
244         return abyte;
245 }
246
247 unsigned char sno_crc8(unsigned char * data, unsigned long count)
248 {
249         unsigned char look_up_table[256] = {
250                 0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65,
251                 157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220,
252                 35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98,
253                 190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255,
254                 70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7,
255                 219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154,
256                 101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36,
257                 248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185,
258                 140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205,
259                 17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80,
260                 175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238,
261                 50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115,
262                 202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139,
263                 87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22,
264                 233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168,
265                 116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53};
266         int i;
267         unsigned char crc = 0;
268
269         for (i = 0; i < count; i++) {
270                 crc = look_up_table[crc ^ data[i]];
271         }
272         return crc;
273 }
274
275 int sno_reset(void)
276 {
277         int result;
278
279         result = reset_1w();
280         if (!result) {
281                 //diag_printf("presence pulse detected\n");
282                 return 0;
283         } else {
284                 diag_printf("NO presence pulse detected\n");
285                 return 1;
286         }
287 }
288
289 cyg_bool get_esa_1w(cyg_uint8 *buffer)
290 {
291         int i;
292         unsigned char mac_data[8] = {0x00,0x00,0x0c,0xc6,0x00,0x00,0x00,0x00};
293         unsigned char crc, status;
294
295         asm volatile (
296                       "ldr r4, =0x00000020;"    // mask for GPIO 5
297                       "ldr r7, =0x00000040;"    // mask for GPIO 6
298
299                       "ldr r5, =0x40e0000c;"    // pin dir register
300                       "ldr r6, [r5];"
301                       "orr r6, r6, r4;"
302                       "orr r6, r6, r7;"
303
304                       "str r6, [r5];"           // set GPIO to output
305
306                       "ldr r5, =0x40e00024;"    // output clear register
307                       "str r4, [r5];"           // reset pin
308
309                       "ldr r5, =0x40e00018;"    // output set register
310                       "str r7, [r5];"           // set pin
311
312                       "ldr r5, =0x40e0000c;"    // pin dir register
313                       "ldr r6, [r5];"
314                       "bic r6, r6, r4;"
315                       "str r6, [r5];"           // set GPIO to input
316
317                       "ldr r4, =0x00003c00;"
318                       "ldr r5, =0x40e00054;"    // alternate function register
319                       "ldr r6, [r5];"
320                       "bic r6, r6, r4;"
321                       "str r6, [r5];"           // set GPIO to IO function
322                       :
323                       :
324                       : "r4","r5","r6","r7"
325                       );
326
327         HAL_DELAY_US(2000);                     // 2 msec recovery time
328
329         // check status of application register
330
331         if (sno_reset()) {
332                 diag_printf("no eeprom device for MAC address found \n");
333                 return 0;
334         }
335
336         sno_write_byte(SNO_SKIP_ROM);
337         sno_write_byte(SNO_READ_STATUS_REG);
338         sno_write_byte(0x00);                                           // validation key
339         status = sno_read_byte();
340         //diag_printf("Status des Application Registers ist: %02X\n", status);
341
342         if (sno_reset()) {
343                 diag_printf("no eeprom device for MAC address found \n");
344                 return 0;
345         }
346
347         if (status & 0x03) {
348                 diag_printf("No information in Application Register !!!!\n");
349                 diag_printf("using defauft MAC 0x00 : 0x0C : 0xC6 : 0x00 : 0x00 : 0x00\n");
350                 for (i = 0; i < 6; i++) {
351                         buffer[i] = mac_data[i+1];
352                 }
353                 return 1;
354         }
355
356         sno_write_byte(SNO_SKIP_ROM);
357         sno_write_byte(SNO_READ_APPLICATION_REG);
358         sno_write_byte(0x00);                                           // register address
359         for (i = 0; i < 8;i++) {
360                 mac_data[i] = sno_read_byte();
361         }
362
363         if (sno_reset()) {
364                 diag_printf("no eeprom device for MAC address found \n");
365                 return 0;
366         }
367
368 //      diag_printf("\nMAC address read from ROM: ");
369 //      for (i=0; i<8; i++) {
370 //              diag_printf("0x%02X ", mac_data[i]);
371 //      }
372         diag_printf("\n");
373
374         crc = sno_crc8(mac_data,7);
375
376         //diag_printf("calculated CRC is: %02X\n", crc );
377
378         if (crc != mac_data[7]) {
379                 diag_printf("ROM data CRC Checksum Error !!!\n\n");
380                 return 0;
381         }
382
383         for (i = 0; i < 6; i++)
384                 buffer[i] = mac_data[i + 1];
385
386         return 1;
387 }