clock.c 2.5 KB

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