clock.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * linux/arch/arm/mach-versatile/clock.c
  3. *
  4. * Copyright (C) 2004 ARM Limited.
  5. * Written by Deep Blue Solutions Limited.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/list.h>
  14. #include <linux/errno.h>
  15. #include <linux/err.h>
  16. #include <asm/semaphore.h>
  17. #include <asm/hardware/clock.h>
  18. #include <asm/hardware/icst307.h>
  19. #include "clock.h"
  20. static LIST_HEAD(clocks);
  21. static DECLARE_MUTEX(clocks_sem);
  22. struct clk *clk_get(struct device *dev, const char *id)
  23. {
  24. struct clk *p, *clk = ERR_PTR(-ENOENT);
  25. down(&clocks_sem);
  26. list_for_each_entry(p, &clocks, node) {
  27. if (strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
  28. clk = p;
  29. break;
  30. }
  31. }
  32. up(&clocks_sem);
  33. return clk;
  34. }
  35. EXPORT_SYMBOL(clk_get);
  36. void clk_put(struct clk *clk)
  37. {
  38. module_put(clk->owner);
  39. }
  40. EXPORT_SYMBOL(clk_put);
  41. int clk_enable(struct clk *clk)
  42. {
  43. return 0;
  44. }
  45. EXPORT_SYMBOL(clk_enable);
  46. void clk_disable(struct clk *clk)
  47. {
  48. }
  49. EXPORT_SYMBOL(clk_disable);
  50. int clk_use(struct clk *clk)
  51. {
  52. return 0;
  53. }
  54. EXPORT_SYMBOL(clk_use);
  55. void clk_unuse(struct clk *clk)
  56. {
  57. }
  58. EXPORT_SYMBOL(clk_unuse);
  59. unsigned long clk_get_rate(struct clk *clk)
  60. {
  61. return clk->rate;
  62. }
  63. EXPORT_SYMBOL(clk_get_rate);
  64. long clk_round_rate(struct clk *clk, unsigned long rate)
  65. {
  66. return rate;
  67. }
  68. EXPORT_SYMBOL(clk_round_rate);
  69. int clk_set_rate(struct clk *clk, unsigned long rate)
  70. {
  71. int ret = -EIO;
  72. if (clk->setvco) {
  73. struct icst307_vco vco;
  74. vco = icst307_khz_to_vco(clk->params, rate / 1000);
  75. clk->rate = icst307_khz(clk->params, vco) * 1000;
  76. printk("Clock %s: setting VCO reg params: S=%d R=%d V=%d\n",
  77. clk->name, vco.s, vco.r, vco.v);
  78. clk->setvco(clk, vco);
  79. ret = 0;
  80. }
  81. return ret;
  82. }
  83. EXPORT_SYMBOL(clk_set_rate);
  84. /*
  85. * These are fixed clocks.
  86. */
  87. static struct clk kmi_clk = {
  88. .name = "KMIREFCLK",
  89. .rate = 24000000,
  90. };
  91. static struct clk uart_clk = {
  92. .name = "UARTCLK",
  93. .rate = 24000000,
  94. };
  95. static struct clk mmci_clk = {
  96. .name = "MCLK",
  97. .rate = 33000000,
  98. };
  99. int clk_register(struct clk *clk)
  100. {
  101. down(&clocks_sem);
  102. list_add(&clk->node, &clocks);
  103. up(&clocks_sem);
  104. return 0;
  105. }
  106. EXPORT_SYMBOL(clk_register);
  107. void clk_unregister(struct clk *clk)
  108. {
  109. down(&clocks_sem);
  110. list_del(&clk->node);
  111. up(&clocks_sem);
  112. }
  113. EXPORT_SYMBOL(clk_unregister);
  114. static int __init clk_init(void)
  115. {
  116. clk_register(&kmi_clk);
  117. clk_register(&uart_clk);
  118. clk_register(&mmci_clk);
  119. return 0;
  120. }
  121. arch_initcall(clk_init);