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