~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/arch/arm/samsung/clksrc-change-registers.awk

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/usr/bin/awk -f
  2 #
  3 # Copyright 2010 Ben Dooks <ben-linux@fluff.org>
  4 #
  5 # Released under GPLv2
  6 
  7 # example usage
  8 # ./clksrc-change-registers.awk arch/arm/plat-s5pc1xx/include/plat/regs-clock.h < src > dst
  9 
 10 function extract_value(s)
 11 {
 12     eqat = index(s, "=")
 13     comat = index(s, ",")
 14     return substr(s, eqat+2, (comat-eqat)-2)
 15 }
 16 
 17 function remove_brackets(b)
 18 {
 19     return substr(b, 2, length(b)-2)
 20 }
 21 
 22 function splitdefine(l, p)
 23 {
 24     r = split(l, tp)
 25 
 26     p[0] = tp[2]
 27     p[1] = remove_brackets(tp[3])
 28 }
 29 
 30 function find_length(f)
 31 {
 32     if (0)
 33         printf "find_length " f "\n" > "/dev/stderr"
 34 
 35     if (f ~ /0x1/)
 36         return 1
 37     else if (f ~ /0x3/)
 38         return 2
 39     else if (f ~ /0x7/)
 40         return 3
 41     else if (f ~ /0xf/)
 42         return 4
 43 
 44     printf "unknown length " f "\n" > "/dev/stderr"
 45     exit
 46 }
 47 
 48 function find_shift(s)
 49 {
 50     id = index(s, "<")
 51     if (id <= 0) {
 52         printf "cannot find shift " s "\n" > "/dev/stderr"
 53         exit
 54     }
 55 
 56     return substr(s, id+2)
 57 }
 58 
 59 
 60 BEGIN {
 61     if (ARGC < 2) {
 62         print "too few arguments" > "/dev/stderr"
 63         exit
 64     }
 65 
 66 # read the header file and find the mask values that we will need
 67 # to replace and create an associative array of values
 68 
 69     while (getline line < ARGV[1] > 0) {
 70         if (line ~ /\#define.*_MASK/ &&
 71             !(line ~ /USB_SIG_MASK/)) {
 72             splitdefine(line, fields)
 73             name = fields[0]
 74             if (0)
 75                 printf "MASK " line "\n" > "/dev/stderr"
 76             dmask[name,0] = find_length(fields[1])
 77             dmask[name,1] = find_shift(fields[1])
 78             if (0)
 79                 printf "=> '" name "' LENGTH=" dmask[name,0] " SHIFT=" dmask[name,1] "\n" > "/dev/stderr"
 80         } else {
 81         }
 82     }
 83 
 84     delete ARGV[1]
 85 }
 86 
 87 /clksrc_clk.*=.*{/ {
 88     shift=""
 89     mask=""
 90     divshift=""
 91     reg_div=""
 92     reg_src=""
 93     indent=1
 94 
 95     print $0
 96 
 97     for(; indent >= 1;) {
 98         if ((getline line) <= 0) {
 99             printf "unexpected end of file" > "/dev/stderr"
100             exit 1;
101         }
102 
103         if (line ~ /\.shift/) {
104             shift = extract_value(line)
105         } else if (line ~ /\.mask/) {
106             mask = extract_value(line)
107         } else if (line ~ /\.reg_divider/) {
108             reg_div = extract_value(line)
109         } else if (line ~ /\.reg_source/) {
110             reg_src = extract_value(line)
111         } else if (line ~ /\.divider_shift/) {
112             divshift = extract_value(line)
113         } else if (line ~ /{/) {
114                 indent++
115                 print line
116             } else if (line ~ /}/) {
117             indent--
118 
119             if (indent == 0) {
120                 if (0) {
121                     printf "shift '" shift   "' ='" dmask[shift,0] "'\n" > "/dev/stderr"
122                     printf "mask  '" mask    "'\n" > "/dev/stderr"
123                     printf "dshft '" divshift "'\n" > "/dev/stderr"
124                     printf "rdiv  '" reg_div "'\n" > "/dev/stderr"
125                     printf "rsrc  '" reg_src "'\n" > "/dev/stderr"
126                 }
127 
128                 generated = mask
129                 sub(reg_src, reg_div, generated)
130 
131                 if (0) {
132                     printf "/* rsrc " reg_src " */\n"
133                     printf "/* rdiv " reg_div " */\n"
134                     printf "/* shift " shift " */\n"
135                     printf "/* mask " mask " */\n"
136                     printf "/* generated " generated " */\n"
137                 }
138 
139                 if (reg_div != "") {
140                     printf "\t.reg_div = { "
141                     printf ".reg = " reg_div ", "
142                     printf ".shift = " dmask[generated,1] ", "
143                     printf ".size = " dmask[generated,0] ", "
144                     printf "},\n"
145                 }
146 
147                 printf "\t.reg_src = { "
148                 printf ".reg = " reg_src ", "
149                 printf ".shift = " dmask[mask,1] ", "
150                 printf ".size = " dmask[mask,0] ", "
151 
152                 printf "},\n"
153 
154             }
155 
156             print line
157         } else {
158             print line
159         }
160 
161         if (0)
162             printf indent ":" line "\n" > "/dev/stderr"
163     }
164 }
165 
166 // && ! /clksrc_clk.*=.*{/ { print $0 }

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php