clock.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 <linux/string.h>
  17. #include <asm/semaphore.h>
  18. #include <asm/hardware/clock.h>
  19. #include <asm/hardware/icst307.h>
  20. #include "clock.h"
  21. static LIST_HEAD(clocks);
  22. static DECLARE_MUTEX(clocks_sem);
  23. struct clk *clk_get(struct device *dev, const char *id)
  24. {
  25. struct clk *p, *clk = ERR_PTR(-ENOENT);
  26. down(&clocks_sem);
  27. list_for_each_entry(p, &clocks, node) {
  28. if (strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
  29. clk = p;
  30. break;
  31. }
  32. }
  33. up(&clocks_sem);
  34. return clk;
  35. }
  36. EXPORT_SYMBOL(clk_get);
  37. void clk_put(struct clk *clk)
  38. {
  39. module_put(clk->owner);
  40. }
  41. EXPORT_SYMBOL(clk_put);
  42. int clk_enable(struct clk *clk)
  43. {
  44. return 0;
  45. }
  46. EXPORT_SYMBOL(clk_enable);
  47. void clk_disable(struct clk *clk)
  48. {
  49. }
  50. EXPORT_SYMBOL(clk_disable);
  51. int clk_use(struct clk *clk)
  52. {
  53. return 0;
  54. }
  55. EXPORT_SYMBOL(clk_use);
  56. void clk_unuse(struct clk *clk)
  57. {
  58. }
  59. EXPORT_SYMBOL(clk_unuse);
  60. unsigned long clk_get_rate(struct clk *clk)
  61. {
  62. return clk->rate;
  63. }
  64. EXPORT_SYMBOL(clk_get_rate);
  65. long clk_round_rate(struct clk *clk, unsigned long rate)
  66. {
  67. return rate;
  68. }
  69. EXPORT_SYMBOL(clk_round_rate);
  70. int clk_set_rate(struct clk *clk, unsigned long rate)
  71. {
  72. int ret = -EIO;
  73. if (clk->setvco) {
  74. struct icst307_vco vco;
  75. vco = icst307_khz_to_vco(clk->params, rate / 1000);
  76. clk->rate = icst307_khz(clk->params, vco) * 1000;
  77. printk("Clock %s: setting VCO reg params: S=%d R=%d V=%d\n",
  78. clk->name, vco.s, vco.r, vco.v);
  79. clk->setvco(clk, vco);
  80. ret = 0;
  81. }
  82. return ret;
  83. }
  84. EXPORT_SYMBOL(clk_set_rate);
  85. /*
  86. * These are fixed clocks.
  87. */
  88. static struct clk kmi_clk = {
  89. .name = "KMIREFCLK",
  90. .rate = 24000000,
  91. };
  92. static struct clk uart_clk = {
  93. .name = "UARTCLK",
  94. .rate = 24000000,
  95. };
  96. static struct clk mmci_clk = {
  97. .name = "MCLK",
  98. .rate = 33000000,
  99. };
  100. int clk_register(struct clk *clk)
  101. {
  102. down(&clocks_sem);
  103. list_add(&clk->node, &clocks);
  104. up(&clocks_sem);
  105. return 0;
  106. }
  107. EXPORT_SYMBOL(clk_register);
  108. void clk_unregister(struct clk *clk)
  109. {
  110. down(&clocks_sem);
  111. list_del(&clk->node);
  112. up(&clocks_sem);
  113. }
  114. EXPORT_SYMBOL(clk_unregister);
  115. static int __init clk_init(void)
  116. {
  117. clk_register(&kmi_clk);
  118. clk_register(&uart_clk);
  119. clk_register(&mmci_clk);
  120. return 0;
  121. }
  122. arch_initcall(clk_init);