1
2 /* Microcode patches for the CPM as supplied by Motorola.
3 * This is the one for IIC/SPI. There is a newer one that
4 * also relocates SMC2, but this would require additional changes
5 * to uart.c, so I am holding off on that for a moment.
6 */
7 #include <linux/config.h>
8 #include <linux/errno.h>
9 #include <linux/sched.h>
10 #include <linux/kernel.h>
11 #include <linux/param.h>
12 #include <linux/string.h>
13 #include <linux/mm.h>
14 #include <linux/interrupt.h>
15 #include <asm/irq.h>
16 #include <asm/mpc8xx.h>
17 #include <asm/page.h>
18 #include <asm/pgtable.h>
19 #include <asm/8xx_immap.h>
20 #include <asm/commproc.h>
21
22 /* Define this to get SMC patches as well. You need to modify the uart
23 * driver as well......
24 #define USE_SMC_PATCH 1
25 */
26
27 #ifdef CONFIG_USB_MPC8xx
28 #define USE_USB_SOF_PATCH
29 #endif
30
31 #ifdef USE_IIC_PATCH
32 #define PATCH_DEFINED
33 /* IIC/SPI */
34 uint patch_2000[] = {
35 0x7FFFEFD9,
36 0x3FFD0000,
37 0x7FFB49F7,
38 0x7FF90000,
39 0x5FEFADF7,
40 0x5F89ADF7,
41 0x5FEFAFF7,
42 0x5F89AFF7,
43 0x3A9CFBC8,
44 0xE7C0EDF0,
45 0x77C1E1BB,
46 0xF4DC7F1D,
47 0xABAD932F,
48 0x4E08FDCF,
49 0x6E0FAFF8,
50 0x7CCF76CF,
51 0xFD1FF9CF,
52 0xABF88DC6,
53 0xAB5679F7,
54 0xB0937383,
55 0xDFCE79F7,
56 0xB091E6BB,
57 0xE5BBE74F,
58 0xB3FA6F0F,
59 0x6FFB76CE,
60 0xEE0DF9CF,
61 0x2BFBEFEF,
62 0xCFEEF9CF,
63 0x76CEAD24,
64 0x90B2DF9A,
65 0x7FDDD0BF,
66 0x4BF847FD,
67 0x7CCF76CE,
68 0xCFEF7E1F,
69 0x7F1D7DFD,
70 0xF0B6EF71,
71 0x7FC177C1,
72 0xFBC86079,
73 0xE722FBC8,
74 0x5FFFDFFF,
75 0x5FB2FFFB,
76 0xFBC8F3C8,
77 0x94A67F01,
78 0x7F1D5F39,
79 0xAFE85F5E,
80 0xFFDFDF96,
81 0xCB9FAF7D,
82 0x5FC1AFED,
83 0x8C1C5FC1,
84 0xAFDD5FC3,
85 0xDF9A7EFD,
86 0xB0B25FB2,
87 0xFFFEABAD,
88 0x5FB2FFFE,
89 0x5FCE600B,
90 0xE6BB600B,
91 0x5FCEDFC6,
92 0x27FBEFDF,
93 0x5FC8CFDE,
94 0x3A9CE7C0,
95 0xEDF0F3C8,
96 0x7F0154CD,
97 0x7F1D2D3D,
98 0x363A7570,
99 0x7E0AF1CE,
100 0x37EF2E68,
101 0x7FEE10EC,
102 0xADF8EFDE,
103 0xCFEAE52F,
104 0x7D0FE12B,
105 0xF1CE5F65,
106 0x7E0A4DF8,
107 0xCFEA5F72,
108 0x7D0BEFEE,
109 0xCFEA5F74,
110 0xE522EFDE,
111 0x5F74CFDA,
112 0x0B627385,
113 0xDF627E0A,
114 0x30D8145B,
115 0xBFFFF3C8,
116 0x5FFFDFFF,
117 0xA7F85F5E,
118 0xBFFE7F7D,
119 0x10D31450,
120 0x5F36BFFF,
121 0xAF785F5E,
122 0xBFFDA7F8,
123 0x5F36BFFE,
124 0x77FD30C0,
125 0x4E08FDCF,
126 0xE5FF6E0F,
127 0xAFF87E1F,
128 0x7E0FFD1F,
129 0xF1CF5F1B,
130 0xABF80D5E,
131 0x5F5EFFEF,
132 0x79F730A2,
133 0xAFDD5F34,
134 0x47F85F34,
135 0xAFED7FDD,
136 0x50B24978,
137 0x47FD7F1D,
138 0x7DFD70AD,
139 0xEF717EC1,
140 0x6BA47F01,
141 0x2D267EFD,
142 0x30DE5F5E,
143 0xFFFD5F5E,
144 0xFFEF5F5E,
145 0xFFDF0CA0,
146 0xAFED0A9E,
147 0xAFDD0C3A,
148 0x5F3AAFBD,
149 0x7FBDB082,
150 0x5F8247F8
151 };
152
153 uint patch_2f00[] = {
154 0x3E303430,
155 0x34343737,
156 0xABF7BF9B,
157 0x994B4FBD,
158 0xBD599493,
159 0x349FFF37,
160 0xFB9B177D,
161 0xD9936956,
162 0xBBFDD697,
163 0xBDD2FD11,
164 0x31DB9BB3,
165 0x63139637,
166 0x93733693,
167 0x193137F7,
168 0x331737AF,
169 0x7BB9B999,
170 0xBB197957,
171 0x7FDFD3D5,
172 0x73B773F7,
173 0x37933B99,
174 0x1D115316,
175 0x99315315,
176 0x31694BF4,
177 0xFBDBD359,
178 0x31497353,
179 0x76956D69,
180 0x7B9D9693,
181 0x13131979,
182 0x79376935
183 };
184 #endif
185
186 #ifdef USE_SMC_PATCH
187 #define PATCH_DEFINED
188 /* SMC2/IIC/SPI Patch */
189 /* This is the area from 0x2000 to 0x23ff.
190 */
191 uint patch_2000[] = {
192 0x3fff0000,
193 0x3ffd0000,
194 0x3ffb0000,
195 0x3ff90000,
196 0x5f13eff8,
197 0x5eb5eff8,
198 0x5f88adf7,
199 0x5fefadf7,
200 0x3a9cfbc8,
201 0x77cae1bb,
202 0xf4de7fad,
203 0xabae9330,
204 0x4e08fdcf,
205 0x6e0faff8,
206 0x7ccf76cf,
207 0xfdaff9cf,
208 0xabf88dc8,
209 0xab5879f7,
210 0xb0925d8d,
211 0xdfd079f7,
212 0xb090e6bb,
213 0xe5bbe74f,
214 0x9e046f0f,
215 0x6ffb76ce,
216 0xee0cf9cf,
217 0x2bfbefef,
218 0xcfeef9cf,
219 0x76cead23,
220 0x90b3df99,
221 0x7fddd0c1,
222 0x4bf847fd,
223 0x7ccf76ce,
224 0xcfef77ca,
225 0x7eaf7fad,
226 0x7dfdf0b7,
227 0xef7a7fca,
228 0x77cafbc8,
229 0x6079e722,
230 0xfbc85fff,
231 0xdfff5fb3,
232 0xfffbfbc8,
233 0xf3c894a5,
234 0xe7c9edf9,
235 0x7f9a7fad,
236 0x5f36afe8,
237 0x5f5bffdf,
238 0xdf95cb9e,
239 0xaf7d5fc3,
240 0xafed8c1b,
241 0x5fc3afdd,
242 0x5fc5df99,
243 0x7efdb0b3,
244 0x5fb3fffe,
245 0xabae5fb3,
246 0xfffe5fd0,
247 0x600be6bb,
248 0x600b5fd0,
249 0xdfc827fb,
250 0xefdf5fca,
251 0xcfde3a9c,
252 0xe7c9edf9,
253 0xf3c87f9e,
254 0x54ca7fed,
255 0x2d3a3637,
256 0x756f7e9a,
257 0xf1ce37ef,
258 0x2e677fee,
259 0x10ebadf8,
260 0xefdecfea,
261 0xe52f7d9f,
262 0xe12bf1ce,
263 0x5f647e9a,
264 0x4df8cfea,
265 0x5f717d9b,
266 0xefeecfea,
267 0x5f73e522,
268 0xefde5f73,
269 0xcfda0b61,
270 0x5d8fdf61,
271 0xe7c9edf9,
272 0x7e9a30d5,
273 0x1458bfff,
274 0xf3c85fff,
275 0xdfffa7f8,
276 0x5f5bbffe,
277 0x7f7d10d0,
278 0x144d5f33,
279 0xbfffaf78,
280 0x5f5bbffd,
281 0xa7f85f33,
282 0xbffe77fd,
283 0x30bd4e08,
284 0xfdcfe5ff,
285 0x6e0faff8,
286 0x7eef7e9f,
287 0xfdeff1cf,
288 0x5f17abf8,
289 0x0d5b5f5b,
290 0xffef79f7,
291 0x309eafdd,
292 0x5f3147f8,
293 0x5f31afed,
294 0x7fdd50af,
295 0x497847fd,
296 0x7f9e7fed,
297 0x7dfd70a9,
298 0xef7e7ece,
299 0x6ba07f9e,
300 0x2d227efd,
301 0x30db5f5b,
302 0xfffd5f5b,
303 0xffef5f5b,
304 0xffdf0c9c,
305 0xafed0a9a,
306 0xafdd0c37,
307 0x5f37afbd,
308 0x7fbdb081,
309 0x5f8147f8,
310 0x3a11e710,
311 0xedf0ccdd,
312 0xf3186d0a,
313 0x7f0e5f06,
314 0x7fedbb38,
315 0x3afe7468,
316 0x7fedf4fc,
317 0x8ffbb951,
318 0xb85f77fd,
319 0xb0df5ddd,
320 0xdefe7fed,
321 0x90e1e74d,
322 0x6f0dcbf7,
323 0xe7decfed,
324 0xcb74cfed,
325 0xcfeddf6d,
326 0x91714f74,
327 0x5dd2deef,
328 0x9e04e7df,
329 0xefbb6ffb,
330 0xe7ef7f0e,
331 0x9e097fed,
332 0xebdbeffa,
333 0xeb54affb,
334 0x7fea90d7,
335 0x7e0cf0c3,
336 0xbffff318,
337 0x5fffdfff,
338 0xac59efea,
339 0x7fce1ee5,
340 0xe2ff5ee1,
341 0xaffbe2ff,
342 0x5ee3affb,
343 0xf9cc7d0f,
344 0xaef8770f,
345 0x7d0fb0c6,
346 0xeffbbfff,
347 0xcfef5ede,
348 0x7d0fbfff,
349 0x5ede4cf8,
350 0x7fddd0bf,
351 0x49f847fd,
352 0x7efdf0bb,
353 0x7fedfffd,
354 0x7dfdf0b7,
355 0xef7e7e1e,
356 0x5ede7f0e,
357 0x3a11e710,
358 0xedf0ccab,
359 0xfb18ad2e,
360 0x1ea9bbb8,
361 0x74283b7e,
362 0x73c2e4bb,
363 0x2ada4fb8,
364 0xdc21e4bb,
365 0xb2a1ffbf,
366 0x5e2c43f8,
367 0xfc87e1bb,
368 0xe74ffd91,
369 0x6f0f4fe8,
370 0xc7ba32e2,
371 0xf396efeb,
372 0x600b4f78,
373 0xe5bb760b,
374 0x53acaef8,
375 0x4ef88b0e,
376 0xcfef9e09,
377 0xabf8751f,
378 0xefef5bac,
379 0x741f4fe8,
380 0x751e760d,
381 0x7fdbf081,
382 0x741cafce,
383 0xefcc7fce,
384 0x751e70ac,
385 0x741ce7bb,
386 0x3372cfed,
387 0xafdbefeb,
388 0xe5bb760b,
389 0x53f2aef8,
390 0xafe8e7eb,
391 0x4bf8771e,
392 0x7e247fed,
393 0x4fcbe2cc,
394 0x7fbc30a9,
395 0x7b0f7a0f,
396 0x34d577fd,
397 0x308b5db7,
398 0xde553e5f,
399 0xaf78741f,
400 0x741f30f0,
401 0xcfef5e2c,
402 0x741f3eac,
403 0xafb8771e,
404 0x5e677fed,
405 0x0bd3e2cc,
406 0x741ccfec,
407 0xe5ca53cd,
408 0x6fcb4f74,
409 0x5dadde4b,
410 0x2ab63d38,
411 0x4bb3de30,
412 0x751f741c,
413 0x6c42effa,
414 0xefea7fce,
415 0x6ffc30be,
416 0xefec3fca,
417 0x30b3de2e,
418 0xadf85d9e,
419 0xaf7daefd,
420 0x5d9ede2e,
421 0x5d9eafdd,
422 0x761f10ac,
423 0x1da07efd,
424 0x30adfffe,
425 0x4908fb18,
426 0x5fffdfff,
427 0xafbb709b,
428 0x4ef85e67,
429 0xadf814ad,
430 0x7a0f70ad,
431 0xcfef50ad,
432 0x7a0fde30,
433 0x5da0afed,
434 0x3c12780f,
435 0xefef780f,
436 0xefef790f,
437 0xa7f85e0f,
438 0xffef790f,
439 0xefef790f,
440 0x14adde2e,
441 0x5d9eadfd,
442 0x5e2dfffb,
443 0xe79addfd,
444 0xeff96079,
445 0x607ae79a,
446 0xddfceff9,
447 0x60795dff,
448 0x607acfef,
449 0xefefefdf,
450 0xefbfef7f,
451 0xeeffedff,
452 0xebffe7ff,
453 0xafefafdf,
454 0xafbfaf7f,
455 0xaeffadff,
456 0xabffa7ff,
457 0x6fef6fdf,
458 0x6fbf6f7f,
459 0x6eff6dff,
460 0x6bff67ff,
461 0x2fef2fdf,
462 0x2fbf2f7f,
463 0x2eff2dff,
464 0x2bff27ff,
465 0x4e08fd1f,
466 0xe5ff6e0f,
467 0xaff87eef,
468 0x7e0ffdef,
469 0xf11f6079,
470 0xabf8f542,
471 0x7e0af11c,
472 0x37cfae3a,
473 0x7fec90be,
474 0xadf8efdc,
475 0xcfeae52f,
476 0x7d0fe12b,
477 0xf11c6079,
478 0x7e0a4df8,
479 0xcfea5dc4,
480 0x7d0befec,
481 0xcfea5dc6,
482 0xe522efdc,
483 0x5dc6cfda,
484 0x4e08fd1f,
485 0x6e0faff8,
486 0x7c1f761f,
487 0xfdeff91f,
488 0x6079abf8,
489 0x761cee24,
490 0xf91f2bfb,
491 0xefefcfec,
492 0xf91f6079,
493 0x761c27fb,
494 0xefdf5da7,
495 0xcfdc7fdd,
496 0xd09c4bf8,
497 0x47fd7c1f,
498 0x761ccfcf,
499 0x7eef7fed,
500 0x7dfdf093,
501 0xef7e7f1e,
502 0x771efb18,
503 0x6079e722,
504 0xe6bbe5bb,
505 0xae0ae5bb,
506 0x600bae85,
507 0xe2bbe2bb,
508 0xe2bbe2bb,
509 0xaf02e2bb,
510 0xe2bb2ff9,
511 0x6079e2bb
512 };
513
514 /* This is from 0x2f00 to 0x2fff
515 */
516 uint patch_2f00[] = {
517 0x30303030,
518 0x3e3e3434,
519 0xabbf9b99,
520 0x4b4fbdbd,
521 0x59949334,
522 0x9fff37fb,
523 0x9b177dd9,
524 0x936956bb,
525 0xfbdd697b,
526 0xdd2fd113,
527 0x1db9f7bb,
528 0x36313963,
529 0x79373369,
530 0x3193137f,
531 0x7331737a,
532 0xf7bb9b99,
533 0x9bb19795,
534 0x77fdfd3d,
535 0x573b773f,
536 0x737933f7,
537 0xb991d115,
538 0x31699315,
539 0x31531694,
540 0xbf4fbdbd,
541 0x35931497,
542 0x35376956,
543 0xbd697b9d,
544 0x96931313,
545 0x19797937,
546 0x6935af78,
547 0xb9b3baa3,
548 0xb8788683,
549 0x368f78f7,
550 0x87778733,
551 0x3ffffb3b,
552 0x8e8f78b8,
553 0x1d118e13,
554 0xf3ff3f8b,
555 0x6bd8e173,
556 0xd1366856,
557 0x68d1687b,
558 0x3daf78b8,
559 0x3a3a3f87,
560 0x8f81378f,
561 0xf876f887,
562 0x77fd8778,
563 0x737de8d6,
564 0xbbf8bfff,
565 0xd8df87f7,
566 0xfd876f7b,
567 0x8bfff8bd,
568 0x8683387d,
569 0xb873d87b,
570 0x3b8fd7f8,
571 0xf7338883,
572 0xbb8ee1f8,
573 0xef837377,
574 0x3337b836,
575 0x817d11f8,
576 0x7378b878,
577 0xd3368b7d,
578 0xed731b7d,
579 0x833731f3,
580 0xf22f3f23
581 };
582
583 uint patch_2e00[] = {
584 /* This is from 0x2e00 to 0x2e3c
585 */
586 0x27eeeeee,
587 0xeeeeeeee,
588 0xeeeeeeee,
589 0xeeeeeeee,
590 0xee4bf4fb,
591 0xdbd259bb,
592 0x1979577f,
593 0xdfd2d573,
594 0xb773f737,
595 0x4b4fbdbd,
596 0x25b9b177,
597 0xd2d17376,
598 0x956bbfdd,
599 0x697bdd2f,
600 0xff9f79ff,
601 0xff9ff22f
602 };
603 #endif
604
605 #ifdef USE_USB_SOF_PATCH
606 #define PATCH_DEFINED
607 uint patch_2000[] = {
608 0x7fff0000,
609 0x7ffd0000,
610 0x7ffb0000,
611 0x49f7ba5b,
612 0xba383ffb,
613 0xf9b8b46d,
614 0xe5ab4e07,
615 0xaf77bffe,
616 0x3f7bbf79,
617 0xba5bba38,
618 0xe7676076,
619 0x60750000
620 };
621
622 uint patch_2f00[] = {
623 0x3030304c,
624 0xcab9e441,
625 0xa1aaf220
626 };
627 #endif
628
629 /* Load the microcode patch. This is called early in the CPM initialization
630 * with the controller in the reset state. We enable the processor after
631 * we load the patch.
632 */
633 void
cpm_load_patch(volatile immap_t * immr)634 cpm_load_patch(volatile immap_t *immr)
635 {
636 #ifdef PATCH_DEFINED
637 volatile uint *dp;
638 volatile cpm8xx_t *commproc;
639 volatile iic_t *iip;
640 volatile spi_t *spp;
641 int i;
642
643 commproc = (cpm8xx_t *)&immr->im_cpm;
644
645 /* We work closely with commproc.c. We know it only allocates
646 * from data only space.
647 * For this particular patch, we only use the bottom 512 bytes
648 * and the upper 256 byte extension. We will use the space
649 * starting at 1K for the relocated parameters, as the general
650 * CPM allocation won't come from that area.
651 */
652 commproc->cp_rccr = 0;
653
654 /* Copy the patch into DPRAM.
655 */
656 dp = (uint *)(commproc->cp_dpmem);
657 for (i=0; i<(sizeof(patch_2000)/4); i++)
658 *dp++ = patch_2000[i];
659
660 dp = (uint *)&(commproc->cp_dpmem[0x0f00]);
661 for (i=0; i<(sizeof(patch_2f00)/4); i++)
662 *dp++ = patch_2f00[i];
663
664 #ifdef USE_USB_SOF_PATCH
665 #if 0 /* usb patch should not relocate iic */
666 iip = (iic_t *)&commproc->cp_dparam[PROFF_IIC];
667 #define RPBASE 0x0030
668 iip->iic_rpbase = RPBASE;
669
670 /* Put SPI above the IIC, also 32-byte aligned.
671 */
672 i = (RPBASE + sizeof(iic_t) + 31) & ~31;
673 spp = (spi_t *)&commproc->cp_dparam[PROFF_SPI];
674 spp->spi_rpbase = i;
675 #endif
676
677 /* Enable uCode fetches from DPRAM. */
678 commproc->cp_rccr = 0x0009;
679
680 printk("USB uCode patch installed\n");
681 #endif /* USE_USB_SOF_PATCH */
682
683 #if defined(USE_SMC_PATCH) || defined(USE_IIC_PATCH)
684
685 iip = (iic_t *)&commproc->cp_dparam[PROFF_IIC];
686 #define RPBASE 0x0400
687 iip->iic_rpbase = RPBASE;
688
689 /* Put SPI above the IIC, also 32-byte aligned.
690 */
691 i = (RPBASE + sizeof(iic_t) + 31) & ~31;
692 spp = (spi_t *)&commproc->cp_dparam[PROFF_SPI];
693 spp->spi_rpbase = i;
694
695 #ifdef USE_SMC_PATCH
696 dp = (uint *)&(commproc->cp_dpmem[0x0e00]);
697 for (i=0; i<(sizeof(patch_2e00)/4); i++)
698 *dp++ = patch_2e00[i];
699
700 /* Enable the traps to get to it.
701 */
702 commproc->cp_cpmcr1 = 0x8080;
703 commproc->cp_cpmcr2 = 0x808a;
704 commproc->cp_cpmcr3 = 0x8028;
705 commproc->cp_cpmcr4 = 0x802a;
706
707 /* Enable uCode fetches from DPRAM.
708 */
709 commproc->cp_rccr = 3;
710 #endif
711
712 #ifdef USE_IIC_PATCH
713 /* Enable the traps to get to it.
714 */
715 commproc->cp_cpmcr1 = 0x802a;
716 commproc->cp_cpmcr2 = 0x8028;
717 commproc->cp_cpmcr3 = 0x802e;
718 commproc->cp_cpmcr4 = 0x802c;
719
720 /* Enable uCode fetches from DPRAM.
721 */
722 commproc->cp_rccr = 1;
723
724 printk("I2C uCode patch installed\n");
725 #endif
726
727 /* Relocate the IIC and SPI parameter areas. These have to
728 * aligned on 32-byte boundaries.
729 */
730 iip = (iic_t *)&commproc->cp_dparam[PROFF_IIC];
731 iip->iic_rpbase = RPBASE;
732
733 /* Put SPI above the IIC, also 32-byte aligned.
734 */
735 i = (RPBASE + sizeof(iic_t) + 31) & ~31;
736 spp = (spi_t *)&commproc->cp_dparam[PROFF_SPI];
737 spp->spi_rpbase = i;
738
739 #endif /* USE_SMC_PATCH || USE_IIC_PATCH */
740 #endif /* PATCH_DEFINED */
741 }
742
743 void
verify_patch(volatile immap_t * immr)744 verify_patch(volatile immap_t *immr)
745 {
746 #ifdef PATCH_DEFINED
747 volatile uint *dp;
748 volatile cpm8xx_t *commproc;
749 int i;
750
751 commproc = (cpm8xx_t *)&immr->im_cpm;
752
753 printk("cp_rccr %x\n", commproc->cp_rccr);
754 commproc->cp_rccr = 0;
755
756 dp = (uint *)(commproc->cp_dpmem);
757 for (i=0; i<(sizeof(patch_2000)/4); i++)
758 if (*dp++ != patch_2000[i]) {
759 printk("patch_2000 bad at %d\n", i);
760 dp--;
761 printk("found 0x%X, wanted 0x%X\n", *dp, patch_2000[i]);
762 break;
763 }
764
765 dp = (uint *)&(commproc->cp_dpmem[0x0f00]);
766 for (i=0; i<(sizeof(patch_2f00)/4); i++)
767 if (*dp++ != patch_2f00[i]) {
768 printk("patch_2f00 bad at %d\n", i);
769 dp--;
770 printk("found 0x%X, wanted 0x%X\n", *dp, patch_2f00[i]);
771 break;
772 }
773
774 commproc->cp_rccr = 0x0009;
775 #endif /* PATCH_DEFINED */
776 }
777
778