averageVoltageCalculation.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * linux/arch/arm/mach-sa1100/generic.c
  3. *
  4. * Author: Nicolas Pitre
  5. *
  6. * Code common to all SA11x0 machines.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/gpio.h>
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/delay.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/pm.h>
  19. #include <linux/cpufreq.h>
  20. #include <linux/ioport.h>
  21. #include <linux/platform_device.h>
  22. #include <video/sa1100fb.h>
  23. #include <asm/div64.h>
  24. #include <asm/mach/map.h>
  25. #include <asm/mach/flash.h>
  26. #include <asm/irq.h>
  27. #include <asm/system_misc.h>
  28. #include <mach/hardware.h>
  29. #include <mach/irqs.h>
  30. #include "generic.h"
  31. unsigned int reset_status;
  32. EXPORT_SYMBOL(reset_status);
  33. #define NR_FREQS 16
  34. /*
  35. * This table is setup for a 3.6864MHz Crystal.
  36. */
  37. static const unsigned short cclk_frequency_100khz[NR_FREQS] = {
  38. 590, /* 59.0 MHz */
  39. 737, /* 73.7 MHz */
  40. 885, /* 88.5 MHz */
  41. 1032, /* 103.2 MHz */
  42. 1180, /* 118.0 MHz */
  43. 1327, /* 132.7 MHz */
  44. 1475, /* 147.5 MHz */
  45. 1622, /* 162.2 MHz */
  46. 1769, /* 176.9 MHz */
  47. 1917, /* 191.7 MHz */
  48. 2064, /* 206.4 MHz */
  49. 2212, /* 221.2 MHz */
  50. 2359, /* 235.9 MHz */
  51. 2507, /* 250.7 MHz */
  52. 2654, /* 265.4 MHz */
  53. 2802 /* 280.2 MHz */
  54. };
  55. /* rounds up(!) */
  56. unsigned int sa11x0_freq_to_ppcr(unsigned int khz)
  57. {
  58. int i;
  59. khz /= 100;
  60. for (i = 0; i < NR_FREQS; i++)
  61. if (cclk_frequency_100khz[i] >= khz)
  62. break;
  63. return i;
  64. }
  65. unsigned int sa11x0_ppcr_to_freq(unsigned int idx)
  66. {
  67. unsigned int freq = 0;
  68. if (idx < NR_FREQS)
  69. freq = cclk_frequency_100khz[idx] * 100;
  70. return freq;
  71. }
  72. /* make sure that only the "userspace" governor is run -- anything else wouldn't make sense on
  73. * this platform, anyway.
  74. */
  75. int sa11x0_verify_speed(struct cpufreq_policy *policy)
  76. {
  77. unsigned int tmp;
  78. if (policy->cpu)
  79. return -EINVAL;
  80. cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
  81. /* make sure that at least one frequency is within the policy */
  82. tmp = cclk_frequency_100khz[sa11x0_freq_to_ppcr(policy->min)] * 100;
  83. if (tmp > policy->max)
  84. policy->max = tmp;
  85. cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
  86. return 0;
  87. }
  88. unsigned int sa11x0_getspeed(unsigned int cpu)
  89. {
  90. if (cpu)
  91. return 0;
  92. return cclk_frequency_100khz[PPCR & 0xf] * 100;