[U-Boot] mx31: Approach for WEIM CS accessors
Helmut Raiger
helmut.raiger at hale.at
Wed Sep 28 14:48:19 CEST 2011
I tried to fix the magic numbers used by ALL mx31 boards (except one CS in qong.c)
by using some macros. I stayed away from bitfields as it would have resulted
in a very verbose change (something like the setup of CS 3 in qong.c).
To verify the code I used this helper:
-------------- cut -----------
#include <stdio.h>
typedef unsigned int uint;
/* 13 fields of the upper CS control register */
#define CSCR_U(sp, wp, bcd, bcs, psz, pme, sync, dol, \
cnc, wsc, ew, wws, edc) \
((sp) << 31 | (wp) << 30 | (bcd) << 28 | (psz) << 22 | (pme) << 21 |\
(sync) << 20 | (dol) << 16 | (cnc) << 14 | (wsc) << 8 | (ew) << 7 |\
(wws) << 4 | (edc) << 0)
/* 12 fields of the lower CS control register */
#define CSCR_L(oea, oen, ebwa, ebwn, \
csa, ebc, dsz, csn, psr, cre, wrap, csen) \
((oea) << 28 | (oen) << 24 | (ebwa) << 20 | (ebwn) << 16 |\
(csa) << 12 | (ebc) << 11 | (dsz) << 8 | (csn) << 4 |\
(psr) << 3 | (cre) << 2 | (wrap) << 1 | (csen) << 0)
/* 14 fields of the additional CS control register */
#define CSCR_A(ebra, ebrn, rwa, rwn, mum, lah, lbn, lba, dww, dct, \
wwu, age, cnc2, fce) \
((ebra) << 28 | (ebrn) << 24 | (rwa) << 20 | (rwn) << 16 |\
(mum) << 15 | (lah) << 13 | (lbn) << 10 | (lba) << 8 |\
(dww) << 6 | (dct) << 4 | (wwu) << 3 |\
(age) << 2 | (cnc2) << 1 | (fce) << 0)
void decode(unsigned int u, unsigned int l, unsigned int a)
{
/* 13 fields of the upper CS control register */
uint sp = (u >> 31) & 1;
uint wp = (u >> 30) & 1;
uint bcd = (u >> 28) & 1;
uint bcs = (u >> 24) & 15;
uint psz = (u >> 22) & 3;
uint pme = (u >> 21) & 1;
uint sync = (u >> 20) & 1;
uint dol = (u >> 16) & 15;
uint cnc = (u >> 14) & 3;
uint wsc = (u >> 8) & 31;
uint ew = (u >> 7) & 1;
uint wws = (u >> 4) & 7;
uint edc = (u >> 0) & 15;
/* 12 fields of the lower CS control register */
uint oea = (l >> 28) & 15;
uint oen = (l >> 24) & 15;
uint ebwa = (l >> 20) & 15;
uint ebwn = (l >> 16) & 15;
uint csa = (l >> 12) & 15;
uint ebc = (l >> 11) & 1;
uint dsz = (l >> 8) & 7;
uint csn = (l >> 4) & 15;
uint psr = (l >> 3) & 1;
uint cre = (l >> 2) & 1;
uint wrap = (l >> 1) & 1;
uint csen = (l >> 0) & 1;
/* 14 fields of the additional CS control register */
uint ebra = (a >> 28) & 15;
uint ebrn = (a >> 24) & 15;
uint rwa = (a >> 20) & 15;
uint rwn = (a >> 16) & 15;
uint mum = (a >> 15) & 1;
uint lah = (a >> 13) & 3;
uint lbn = (a >> 10) & 7;
uint lba = (a >> 8) & 3;
uint dww = (a >> 6) & 3;
uint dct = (a >> 4) & 3;
uint wwu = (a >> 3) & 1;
uint age = (a >> 2) & 1;
uint cnc2 = (a >> 1) & 1;
uint fce = (a >> 0) & 1;
printf("---- decode(0x%08x, 0x%08x, 0x%08x):\n", u, l, a);
printf("/* sp wp bcd bcs psz pme sync dol cnc wsc ew wws edc */\n");
printf("CSCR_U(%2u,%2u,%3u,%3u,%3u,%3u,%4u,%3u,%3u,%3u,%2u,%3u,%3u)\n",
sp, wp, bcd, bcs, psz, pme, sync, dol, cnc, wsc, ew, wws, edc);
if(CSCR_U(sp, wp, bcd, bcs, psz, pme, sync, dol, cnc, wsc, ew, wws, edc) != u)
printf("U is wrong\n");
printf("/* oea oen ebwa ebwn csa ebc dsz csn psr cre wrap csen */\n");
printf("CSCR_L(%3u,%3u,%4u,%4u,%3u,%3u,%3u,%3u,%3u,%3u,%4u,%4u)\n",
oea, oen, ebwa, ebwn, csa, ebc, dsz, csn, psr, cre, wrap, csen);
if(CSCR_L(oea, oen, ebwa, ebwn, csa, ebc, dsz, csn, psr, cre, wrap, csen) != l)
printf("L is wrong\n");
printf("/* ebra ebrn rwa rwn mum lah lbn lba dww dct wwu age cnc2 fce */\n");
printf("CSCR_A(%2u,%4u,%3u,%3u,%3u,%3u,%3u,%3u,%3u,%3u,%3u,%3u,%4u,%3u)\n",
ebra, ebrn, rwa, rwn, mum, lah, lbn, lba, dww, dct, wwu, age, cnc2, fce);
if(CSCR_A(ebra, ebrn, rwa, rwn, mum, lah, lbn, lba, dww, dct, wwu, age, cnc2, fce) != a)
printf("A is wrong\n");
}
int main(void)
{
printf("qong: CS1 "); decode(0x00000A01, 0x20040501, 0x04020C00);
printf("qong: CS3 "); decode(0x00004f00, 0x20013b31, 0x00020800);
printf("tt01: CS4 "); decode(0x0000dcf6, 0x444A4541, 0x44443302);
printf("pdk: CS5 "); decode(0x0000d843, 0x22252521, 0x22220a00);
printf("ads: CS0 "); decode(0x00000f00, 0x10000D03, 0x00720900);
printf("phycore: CS0 "); decode(0x0000cf03, 0x10000d03, 0x00720900);
printf("phycore: CS1 "); decode(0x0000df06, 0x444a4541, 0x44443302);
printf("phycore: CS4 "); decode(0x0000d843, 0x22252521, 0x22220a00);
printf("litekit: CS0 "); decode(0x0000cf03, 0xa0330d01, 0x00220800);
printf("litekit: CS4 "); decode(0x0000dcf6, 0x444a4541, 0x44443302);
}
-------------------- cut --------------------
--
Scanned by MailScanner.
More information about the U-Boot
mailing list