clock_test.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. void dump_clock_tree(struct clk* clk);
  2. void print_clk_name(struct clk* clk);
  3. static int clk_disable_before(void* privdata)
  4. {
  5. printk("[%s] :%s\n",__func__,privdata);
  6. return 0;
  7. }
  8. static int clk_disable_after(void* privdata,int failed)
  9. {
  10. printk("[%s] :%s failed:%d\n",__func__,privdata,failed);
  11. return 0;
  12. }
  13. static int clk_enable_before(void* privdata)
  14. {
  15. printk("%s] :%s\n",__func__,privdata);
  16. return 0;
  17. }
  18. static int clk_enable_after(void* privdata,int failed)
  19. {
  20. printk("[%s] :%s failed:%d\n",__func__,privdata,failed);
  21. return 0;
  22. }
  23. static int clk_ratechange_before(unsigned long newrate,void* privdata)
  24. {
  25. printk("[%s] :%s\n",__func__,privdata);
  26. return 0;
  27. }
  28. static int clk_ratechange_after(unsigned long newrate,void* privdata,int failed)
  29. {
  30. printk("[%s] :%s failed:%d\n",__func__,privdata,failed);
  31. return 0;
  32. }
  33. static struct clk_ops uart_clk_ops={
  34. .clk_disable_before = clk_disable_before,
  35. .clk_disable_after = clk_disable_after,
  36. .clk_enable_before = clk_enable_before,
  37. .clk_enable_after = clk_enable_after,
  38. .clk_ratechange_before = clk_ratechange_before,
  39. .clk_ratechange_after = clk_ratechange_after,
  40. .privdata = "clk81 -> uart",
  41. };
  42. static struct clk_ops usb_clk_ops={
  43. .clk_disable_before = clk_disable_before,
  44. .clk_disable_after = clk_disable_after,
  45. .clk_enable_before = clk_enable_before,
  46. .clk_enable_after = clk_enable_after,
  47. .clk_ratechange_before = clk_ratechange_before,
  48. .clk_ratechange_after = clk_ratechange_after,
  49. .privdata = "clk81 -> usb",
  50. };
  51. static struct clk_ops xtaldev_clk_ops={
  52. .clk_disable_before = clk_disable_before,
  53. .clk_disable_after = clk_disable_after,
  54. .clk_enable_before = clk_enable_before,
  55. .clk_enable_after = clk_enable_after,
  56. .clk_ratechange_before = clk_ratechange_before,
  57. .clk_ratechange_after = clk_ratechange_after,
  58. .privdata = "xtal device",
  59. };
  60. static struct clk_ops audio_clk_ops={
  61. .clk_disable_before = clk_disable_before,
  62. .clk_disable_after = clk_disable_after,
  63. .clk_enable_before = clk_enable_before,
  64. .clk_enable_after = clk_enable_after,
  65. .clk_ratechange_before = clk_ratechange_before,
  66. .clk_ratechange_after = clk_ratechange_after,
  67. .privdata = "fixed pll -> audio",
  68. };
  69. static struct clk_ops clk81_clk_ops={
  70. .clk_disable_before = clk_disable_before,
  71. .clk_disable_after = clk_disable_after,
  72. .clk_enable_before = clk_enable_before,
  73. .clk_enable_after = clk_enable_after,
  74. .clk_ratechange_before = clk_ratechange_before,
  75. .clk_ratechange_after = clk_ratechange_after,
  76. .privdata = "fixed pll -> clk81",
  77. };
  78. static struct clk_ops audiodev_clk_ops={
  79. .clk_disable_before = clk_disable_before,
  80. .clk_disable_after = clk_disable_after,
  81. .clk_enable_before = clk_enable_before,
  82. .clk_enable_after = clk_enable_after,
  83. .clk_ratechange_before = clk_ratechange_before,
  84. .clk_ratechange_after = clk_ratechange_after,
  85. .privdata = "audio device",
  86. };
  87. static int set_rate(struct clk *clk, unsigned long rate)
  88. {
  89. printk("[ww: %s] rate:%d\n",__func__,rate);
  90. print_clk_name(clk);
  91. return 0;
  92. }
  93. void test_clock_tree()
  94. {
  95. clkdev_add(&clk_lookup_xtal);
  96. CLK_DEFINE(pll_ddr,xtal,3,NULL,clk_msr_get,NULL,NULL,NULL);
  97. PLL_CLK_DEFINE(sys,23);
  98. PLL_CLK_DEFINE(vid2,12);
  99. PLL_CLK_DEFINE(fixed,-1);
  100. PLL_CLK_DEFINE(hpll,-1);///@todo unknown now
  101. // Add clk81
  102. CLK_DEFINE(clk81,pll_fixed,7,NULL,clk_msr_get,NULL,NULL,NULL);
  103. CLK_DEFINE(clkA9,pll_sys,-1,NULL,NULL,NULL,NULL,NULL);
  104. CLK_DEFINE(audio,pll_fixed,-1,NULL,NULL,NULL,NULL,NULL);
  105. PLL_RELATION_DEF(sys,xtal);
  106. PLL_RELATION_DEF(ddr,xtal);
  107. PLL_RELATION_DEF(vid2,xtal);
  108. PLL_RELATION_DEF(fixed,xtal);
  109. PLL_RELATION_DEF(hpll,xtal);
  110. CLK_PLL_CHILD_DEF(clkA9,sys);
  111. CLK_PLL_CHILD_DEF(clk81,fixed);
  112. CLK_PLL_CHILD_DEF(audio,fixed);
  113. dump_clock_tree(&clk_xtal);
  114. printk("unregister clk clkA9 ...\n");
  115. clk_unregister(&clk_clkA9);
  116. dump_clock_tree(&clk_xtal);
  117. printk("register clk clkA9 to pll_sys...\n");
  118. clk_register(&clk_clkA9,"pll_sys");
  119. dump_clock_tree(&clk_xtal);
  120. printk("unregister clk_audio ...\n");
  121. clk_unregister(&clk_audio);
  122. dump_clock_tree(&clk_xtal);
  123. printk("register clk_audio to pll_fixed ...\n");
  124. clk_register(&clk_audio,"pll_fixed");
  125. dump_clock_tree(&clk_xtal);
  126. printk("unregister clk_clk81 ...\n");
  127. clk_unregister(&clk_clk81);
  128. dump_clock_tree(&clk_xtal);
  129. printk("register clkA9, clk81, clk_audio ...\n");
  130. clk_register(&clk_clkA9,"pll_sys");
  131. clk_register(&clk_audio,"pll_fixed");
  132. clk_register(&clk_clk81,"pll_fixed");
  133. dump_clock_tree(&clk_xtal);
  134. printk("register clk operations ...\n");
  135. clk_ops_register(&clk_pll_fixed,&audio_clk_ops);
  136. clk_ops_register(&clk_pll_fixed,&clk81_clk_ops);
  137. clk_ops_register(&clk_clk81,&uart_clk_ops);
  138. clk_ops_register(&clk_clk81,&usb_clk_ops);
  139. clk_ops_register(&clk_xtal,&xtaldev_clk_ops);
  140. clk_ops_register(&clk_audio,&audiodev_clk_ops);
  141. printk("disable xtal ...\n");
  142. clk_disable(&clk_xtal);
  143. printk("enable xtal ...\n");
  144. clk_enable(&clk_xtal);
  145. printk("disable pll_fixed ...\n");
  146. clk_disable(&clk_pll_fixed);
  147. printk("enable pll_fixed ...\n");
  148. clk_enable(&clk_pll_fixed);
  149. printk("disable clk_clk81 ...\n");
  150. clk_disable(&clk_clk81);
  151. printk("enable clk_clk81 ...\n");
  152. clk_enable(&clk_clk81);
  153. printk("disable clk_audio ...\n");
  154. clk_disable(&clk_audio);
  155. printk("enable clk_audio ...\n");
  156. clk_enable(&clk_audio);
  157. clk_xtal.set_rate = set_rate;
  158. clk_clk81.set_rate = set_rate;
  159. clk_audio.set_rate = set_rate;
  160. printk("change rate xtal ...\n");
  161. clk_set_rate(&clk_xtal,250000000);
  162. printk("change rate pll_fixed ...\n");
  163. clk_set_rate(&clk_pll_fixed,2000000000);
  164. printk("change rate clk81 ...\n");
  165. clk_set_rate(&clk_clk81,2000000000);
  166. printk("change rate clk audio ...\n");
  167. clk_set_rate(&clk_audio,2000000000);
  168. }
  169. extern struct clk_lookup * lookup_clk(struct clk* clk);
  170. void print_clk_name(struct clk* clk)
  171. {
  172. struct clk_lookup * p = lookup_clk(clk);
  173. if(p)
  174. printk(" %s \n",p->dev_id);
  175. else
  176. printk(" unknown \n");
  177. }
  178. void dump_child(int nlevel, struct clk* clk)
  179. {
  180. if(!IS_CLK_ERR(clk)){
  181. int i;
  182. for(i = 0; i < nlevel; i++)
  183. printk(" ");
  184. print_clk_name(clk);
  185. dump_child(nlevel+6,(struct clk*)(clk->child.next));
  186. {
  187. struct clk * p = (struct clk*)(clk->sibling.prev);
  188. while(p){
  189. for(i = 0; i < nlevel; i++)
  190. printk(" ");
  191. print_clk_name(p);
  192. dump_child(nlevel+6,(struct clk*)(p->child.next));
  193. p = (struct clk*)(p->sibling.prev);
  194. }
  195. p = (struct clk*)(clk->sibling.next);
  196. while(p){
  197. for(i = 0; i < nlevel; i++)
  198. printk(" ");
  199. print_clk_name(p);
  200. dump_child(nlevel+6,(struct clk*)(p->child.next));
  201. p = (struct clk*)(p->sibling.next);
  202. }
  203. }
  204. }
  205. }
  206. void dump_clock_tree(struct clk* clk)
  207. {
  208. printk("========= dump clock tree==============\n");
  209. mutex_lock(&clock_ops_lock);
  210. int nlevel = 0;
  211. if(!IS_CLK_ERR(clk)){
  212. print_clk_name(clk);
  213. dump_child(nlevel + 6,(struct clk*)(clk->child.next));
  214. { int i;
  215. struct clk * p = (struct clk*)clk->sibling.prev;
  216. while(p){
  217. for(i = 0; i < nlevel; i++)
  218. printk(" ");
  219. print_clk_name(p);
  220. dump_child(nlevel+6,(struct clk*)(p->child.next));
  221. p = (struct clk*)clk->sibling.prev;
  222. }
  223. p = (struct clk*)clk->sibling.next;
  224. while(p){
  225. for(i = 0; i < nlevel; i++)
  226. printk(" ");
  227. print_clk_name(p);
  228. dump_child(nlevel+6,(struct clk*)(p->child.next));
  229. p = (struct clk*)clk->sibling.next;
  230. }
  231. }
  232. }
  233. mutex_unlock(&clock_ops_lock);
  234. printk("========= dump clock tree end ==============\n");
  235. }