3 # Copyright 2010 Ben Dooks <ben-linux@fluff.org>
8 # ./clksrc-change-registers.awk arch/arm/plat-s5pc1xx/include/plat/regs-clock.h < src > dst
10 function extract_value
(s
)
14 return substr(s
, eqat
+2, (comat
-eqat
)-2)
17 function remove_brackets
(b
)
19 return substr(b
, 2, length(b
)-2)
22 function splitdefine
(l
, p
)
27 p
[1] = remove_brackets
(tp
[3])
30 function find_length
(f
)
33 printf "find_length " f
"\n" > "/dev/stderr"
44 printf "unknown legnth " f
"\n" > "/dev/stderr"
48 function find_shift
(s
)
52 printf "cannot find shift " s
"\n" > "/dev/stderr"
56 return substr(s
, id
+2)
62 print "too few arguments" > "/dev/stderr"
66 # read the header file and find the mask values that we will need
67 # to replace and create an associative array of values
69 while (getline line
< ARGV[1] > 0) {
70 if (line ~
/\
#define.*_MASK/ &&
71 !
(line ~
/S5PC100_EPLL_MASK
/) &&
72 !
(line ~
/USB_SIG_MASK
/)) {
73 splitdefine
(line
, fields
)
76 printf "MASK " line
"\n" > "/dev/stderr"
77 dmask
[name
,0] = find_length
(fields
[1])
78 dmask
[name
,1] = find_shift
(fields
[1])
80 printf "=> '" name
"' LENGTH=" dmask
[name
,0] " SHIFT=" dmask
[name
,1] "\n" > "/dev/stderr"
99 if ((getline line
) <=
0) {
100 printf "unexpected end of file" > "/dev/stderr"
104 if (line ~
/\.shift
/) {
105 shift = extract_value
(line
)
106 } else if (line ~
/\.mask
/) {
107 mask = extract_value
(line
)
108 } else if (line ~
/\.reg_divider
/) {
109 reg_div = extract_value
(line
)
110 } else if (line ~
/\.reg_source
/) {
111 reg_src = extract_value
(line
)
112 } else if (line ~
/\.divider_shift
/) {
113 divshift = extract_value
(line
)
114 } else if (line ~
/{/) {
117 } else if (line ~
/}/) {
122 printf "shift '" shift
"' ='" dmask
[shift
,0] "'\n" > "/dev/stderr"
123 printf "mask '" mask
"'\n" > "/dev/stderr"
124 printf "dshft '" divshift
"'\n" > "/dev/stderr"
125 printf "rdiv '" reg_div
"'\n" > "/dev/stderr"
126 printf "rsrc '" reg_src
"'\n" > "/dev/stderr"
130 sub(reg_src
, reg_div
, generated
)
133 printf "/* rsrc " reg_src
" */\n"
134 printf "/* rdiv " reg_div
" */\n"
135 printf "/* shift " shift
" */\n"
136 printf "/* mask " mask
" */\n"
137 printf "/* generated " generated
" */\n"
141 printf "\t.reg_div = { "
142 printf ".reg = " reg_div
", "
143 printf ".shift = " dmask
[generated
,1] ", "
144 printf ".size = " dmask
[generated
,0] ", "
148 printf "\t.reg_src = { "
149 printf ".reg = " reg_src
", "
150 printf ".shift = " dmask
[mask
,1] ", "
151 printf ".size = " dmask
[mask
,0] ", "
163 printf indent
":" line
"\n" > "/dev/stderr"
167 // && !
/clksrc_clk.
*=.
*{/ { print $
0 }