calculationOfAverageTemperature.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* linux/arch/arm/plat-s3c24xx/clock.c
  2. *
  3. * Copyright 2004-2005 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * S3C24XX Core clock control support
  7. *
  8. * Based on, and code from linux/arch/arm/mach-versatile/clock.c
  9. **
  10. ** Copyright (C) 2004 ARM Limited.
  11. ** Written by Deep Blue Solutions Limited.
  12. *
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. */
  28. #include <linux/init.h>
  29. #include <linux/module.h>
  30. #include <linux/kernel.h>
  31. #include <linux/list.h>
  32. #include <linux/errno.h>
  33. #include <linux/err.h>
  34. #include <linux/platform_device.h>
  35. #include <linux/device.h>
  36. #include <linux/interrupt.h>
  37. #include <linux/ioport.h>
  38. #include <linux/clk.h>
  39. #include <linux/spinlock.h>
  40. #include <linux/io.h>
  41. #if defined(CONFIG_DEBUG_FS)
  42. #include <linux/debugfs.h>
  43. #endif
  44. #include <mach/hardware.h>
  45. #include <asm/irq.h>
  46. #include <plat/cpu-freq.h>
  47. #include <plat/clock.h>
  48. #include <plat/cpu.h>
  49. #include <linux/serial_core.h>
  50. #include <plat/regs-serial.h> /* for s3c24xx_uart_devs */
  51. /* clock information */
  52. static LIST_HEAD(clocks);
  53. /* We originally used an mutex here, but some contexts (see resume)
  54. * are calling functions such as clk_set_parent() with IRQs disabled
  55. * causing an BUG to be triggered.
  56. */
  57. DEFINE_SPINLOCK(clocks_lock);
  58. /* Global watchdog clock used by arch_wtd_reset() callback */
  59. struct clk *s3c2410_wdtclk;
  60. static int __init s3c_wdt_reset_init(void)
  61. {
  62. s3c2410_wdtclk = clk_get(NULL, "watchdog");
  63. if (IS_ERR(s3c2410_wdtclk))
  64. printk(KERN_WARNING "%s: warning: cannot get watchdog clock\n", __func__);
  65. return 0;
  66. }
  67. arch_initcall(s3c_wdt_reset_init);
  68. /* enable and disable calls for use with the clk struct */
  69. static int clk_null_enable(struct clk *clk, int enable)
  70. {
  71. return 0;
  72. }
  73. int clk_enable(struct clk *clk)
  74. {
  75. unsigned long flags;
  76. if (IS_ERR(clk) || clk == NULL)
  77. return -EINVAL;
  78. clk_enable(clk->parent);
  79. spin_lock_irqsave(&clocks_lock, flags);
  80. if ((clk->usage++) == 0)
  81. (clk->enable)(clk, 1);
  82. spin_unlock_irqrestore(&clocks_lock, flags);
  83. return 0;
  84. }
  85. void clk_disable(struct clk *clk)
  86. {
  87. unsigned long flags;
  88. if (IS_ERR(clk) || clk == NULL)
  89. return;
  90. spin_lock_irqsave(&clocks_lock, flags);
  91. if ((--clk->usage) == 0)
  92. (clk->enable)(clk, 0);
  93. spin_unlock_irqrestore(&clocks_lock, flags);
  94. clk_disable(clk->parent);
  95. }
  96. unsigned long clk_get_rate(struct clk *clk)
  97. {
  98. if (IS_ERR_OR_NULL(clk))
  99. return 0;
  100. if (clk->rate != 0)
  101. return clk->rate;
  102. if (clk->ops != NULL && clk->ops->get_rate != NULL)
  103. return (clk->ops->get_rate)(clk);
  104. if (clk->parent != NULL)
  105. return clk_get_rate(clk->parent);
  106. return clk->rate;
  107. }
  108. long clk_round_rate(struct clk *clk, unsigned long rate)
  109. {
  110. if (!IS_ERR_OR_NULL(clk) && clk->ops && clk->ops->round_rate)
  111. return (clk->ops->round_rate)(clk, rate);
  112. return rate;
  113. }
  114. int clk_set_rate(struct clk *clk, unsigned long rate)
  115. {
  116. unsigned long flags;
  117. int ret;
  118. if (IS_ERR_OR_NULL(clk))
  119. return -EINVAL;
  120. /* We do not default just do a clk->rate = rate as
  121. * the clock may have been made this way by choice.
  122. */