clk.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * This program is free software; you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License version 2 as published
  4. * by the Free Software Foundation.
  5. *
  6. * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
  7. * Copyright (C) 2013 John Crispin <john@phrozen.org>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/export.h>
  12. #include <linux/clkdev.h>
  13. #include <linux/clk.h>
  14. #include <asm/time.h>
  15. #include "common.h"
  16. struct clk {
  17. struct clk_lookup cl;
  18. unsigned long rate;
  19. };
  20. void ralink_clk_add(const char *dev, unsigned long rate)
  21. {
  22. struct clk *clk = kzalloc(sizeof(struct clk), GFP_KERNEL);
  23. if (!clk)
  24. panic("failed to add clock");
  25. clk->cl.dev_id = dev;
  26. clk->cl.clk = clk;
  27. clk->rate = rate;
  28. clkdev_add(&clk->cl);
  29. }
  30. /*
  31. * Linux clock API
  32. */
  33. int clk_enable(struct clk *clk)
  34. {
  35. return 0;
  36. }
  37. EXPORT_SYMBOL_GPL(clk_enable);
  38. void clk_disable(struct clk *clk)
  39. {
  40. }
  41. EXPORT_SYMBOL_GPL(clk_disable);
  42. unsigned long clk_get_rate(struct clk *clk)
  43. {
  44. if (!clk)
  45. return 0;
  46. return clk->rate;
  47. }
  48. EXPORT_SYMBOL_GPL(clk_get_rate);
  49. int clk_set_rate(struct clk *clk, unsigned long rate)
  50. {
  51. return -1;
  52. }
  53. EXPORT_SYMBOL_GPL(clk_set_rate);
  54. long clk_round_rate(struct clk *clk, unsigned long rate)
  55. {
  56. return -1;
  57. }
  58. EXPORT_SYMBOL_GPL(clk_round_rate);
  59. void __init plat_time_init(void)
  60. {
  61. struct clk *clk;
  62. ralink_of_remap();
  63. ralink_clk_init();
  64. clk = clk_get_sys("cpu", NULL);
  65. if (IS_ERR(clk))
  66. panic("unable to get CPU clock, err=%ld", PTR_ERR(clk));
  67. pr_info("CPU Clock: %ldMHz\n", clk_get_rate(clk) / 1000000);
  68. mips_hpt_frequency = clk_get_rate(clk) / 2;
  69. clk_put(clk);
  70. timer_probe();
  71. }