clock.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (C) 2006 - 2008 Lemote Inc. & Institute of Computing Technology
  3. * Author: Yanhua, [email protected]
  4. *
  5. * This file is subject to the terms and conditions of the GNU General Public
  6. * License. See the file "COPYING" in the main directory of this archive
  7. * for more details.
  8. */
  9. #include <linux/cpufreq.h>
  10. #include <linux/errno.h>
  11. #include <linux/export.h>
  12. #include <asm/mach-loongson2ef/loongson.h>
  13. enum {
  14. DC_ZERO, DC_25PT = 2, DC_37PT, DC_50PT, DC_62PT, DC_75PT,
  15. DC_87PT, DC_DISABLE, DC_RESV
  16. };
  17. struct cpufreq_frequency_table loongson2_clockmod_table[] = {
  18. {0, DC_RESV, CPUFREQ_ENTRY_INVALID},
  19. {0, DC_ZERO, CPUFREQ_ENTRY_INVALID},
  20. {0, DC_25PT, 0},
  21. {0, DC_37PT, 0},
  22. {0, DC_50PT, 0},
  23. {0, DC_62PT, 0},
  24. {0, DC_75PT, 0},
  25. {0, DC_87PT, 0},
  26. {0, DC_DISABLE, 0},
  27. {0, DC_RESV, CPUFREQ_TABLE_END},
  28. };
  29. EXPORT_SYMBOL_GPL(loongson2_clockmod_table);
  30. int loongson2_cpu_set_rate(unsigned long rate_khz)
  31. {
  32. struct cpufreq_frequency_table *pos;
  33. int regval;
  34. cpufreq_for_each_valid_entry(pos, loongson2_clockmod_table)
  35. if (rate_khz == pos->frequency)
  36. break;
  37. if (rate_khz != pos->frequency)
  38. return -ENOTSUPP;
  39. regval = readl(LOONGSON_CHIPCFG);
  40. regval = (regval & ~0x7) | (pos->driver_data - 1);
  41. writel(regval, LOONGSON_CHIPCFG);
  42. return 0;
  43. }
  44. EXPORT_SYMBOL_GPL(loongson2_cpu_set_rate);