ibm440gp_common.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * PPC440GP system library
  3. *
  4. * Matt Porter <mporter@mvista.com>
  5. * Copyright 2002-2003 MontaVista Software Inc.
  6. *
  7. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  8. * Copyright (c) 2003 Zultys Technologies
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. */
  16. #include <linux/types.h>
  17. #include <asm/reg.h>
  18. #include <asm/ibm44x.h>
  19. #include <asm/mmu.h>
  20. /*
  21. * Calculate 440GP clocks
  22. */
  23. void __init ibm440gp_get_clocks(struct ibm44x_clocks* p,
  24. unsigned int sys_clk,
  25. unsigned int ser_clk)
  26. {
  27. u32 cpc0_sys0 = mfdcr(DCRN_CPC0_SYS0);
  28. u32 cpc0_cr0 = mfdcr(DCRN_CPC0_CR0);
  29. u32 opdv = ((cpc0_sys0 >> 10) & 0x3) + 1;
  30. u32 epdv = ((cpc0_sys0 >> 8) & 0x3) + 1;
  31. if (cpc0_sys0 & 0x2){
  32. /* Bypass system PLL */
  33. p->cpu = p->plb = sys_clk;
  34. }
  35. else {
  36. u32 fbdv, fwdva, fwdvb, m, vco;
  37. fbdv = (cpc0_sys0 >> 18) & 0x0f;
  38. if (!fbdv)
  39. fbdv = 16;
  40. fwdva = 8 - ((cpc0_sys0 >> 15) & 0x7);
  41. fwdvb = 8 - ((cpc0_sys0 >> 12) & 0x7);
  42. /* Feedback path */
  43. if (cpc0_sys0 & 0x00000080){
  44. /* PerClk */
  45. m = fwdvb * opdv * epdv;
  46. }
  47. else {
  48. /* CPU clock */
  49. m = fbdv * fwdva;
  50. }
  51. vco = sys_clk * m;
  52. p->cpu = vco / fwdva;
  53. p->plb = vco / fwdvb;
  54. }
  55. p->opb = p->plb / opdv;
  56. p->ebc = p->opb / epdv;
  57. if (cpc0_cr0 & 0x00400000){
  58. /* External UART clock */
  59. p->uart0 = p->uart1 = ser_clk;
  60. }
  61. else {
  62. /* Internal UART clock */
  63. u32 uart_div = ((cpc0_cr0 >> 16) & 0x1f) + 1;
  64. p->uart0 = p->uart1 = p->plb / uart_div;
  65. }
  66. }