clk.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <blogic@openwrt.org>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/clkdev.h>
  12. #include <linux/clk.h>
  13. #include <asm/time.h>
  14. #include "common.h"
  15. struct clk {
  16. struct clk_lookup cl;
  17. unsigned long rate;
  18. };
  19. void ralink_clk_add(const char *dev, unsigned long rate)
  20. {
  21. struct clk *clk = kzalloc(sizeof(struct clk), GFP_KERNEL);
  22. if (!clk)
  23. panic("failed to add clock");
  24. clk->cl.dev_id = dev;
  25. clk->cl.clk = clk;
  26. clk->rate = rate;
  27. clkdev_add(&clk->cl);
  28. }
  29. /*
  30. * Linux clock API
  31. */
  32. int clk_enable(struct clk *clk)
  33. {
  34. return 0;
  35. }
  36. EXPORT_SYMBOL_GPL(clk_enable);
  37. void clk_disable(struct clk *clk)
  38. {
  39. }
  40. EXPORT_SYMBOL_GPL(clk_disable);
  41. unsigned long clk_get_rate(struct clk *clk)
  42. {
  43. return clk->rate;
  44. }
  45. EXPORT_SYMBOL_GPL(clk_get_rate);
  46. int clk_set_rate(struct clk *clk, unsigned long rate)
  47. {
  48. return -1;
  49. }
  50. EXPORT_SYMBOL_GPL(clk_set_rate);
  51. void __init plat_time_init(void)
  52. {
  53. struct clk *clk;
  54. ralink_of_remap();
  55. ralink_clk_init();
  56. clk = clk_get_sys("cpu", NULL);
  57. if (IS_ERR(clk))
  58. panic("unable to get CPU clock, err=%ld", PTR_ERR(clk));
  59. pr_info("CPU Clock: %ldMHz\n", clk_get_rate(clk) / 1000000);
  60. mips_hpt_frequency = clk_get_rate(clk) / 2;
  61. clk_put(clk);
  62. clocksource_probe();
  63. }