dpmc.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright 2008 Analog Devices Inc.
  3. *
  4. * Licensed under the GPL-2 or later.
  5. */
  6. #include <linux/cdev.h>
  7. #include <linux/device.h>
  8. #include <linux/errno.h>
  9. #include <linux/fs.h>
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/types.h>
  14. #include <linux/cpufreq.h>
  15. #include <asm/delay.h>
  16. #include <asm/dpmc.h>
  17. #define DRIVER_NAME "bfin dpmc"
  18. #define dprintk(msg...) \
  19. cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, DRIVER_NAME, msg)
  20. struct bfin_dpmc_platform_data *pdata;
  21. /**
  22. * bfin_set_vlev - Update VLEV field in VR_CTL Reg.
  23. * Avoid BYPASS sequence
  24. */
  25. static void bfin_set_vlev(unsigned int vlev)
  26. {
  27. unsigned pll_lcnt;
  28. pll_lcnt = bfin_read_PLL_LOCKCNT();
  29. bfin_write_PLL_LOCKCNT(1);
  30. bfin_write_VR_CTL((bfin_read_VR_CTL() & ~VLEV) | vlev);
  31. bfin_write_PLL_LOCKCNT(pll_lcnt);
  32. }
  33. /**
  34. * bfin_get_vlev - Get CPU specific VLEV from platform device data
  35. */
  36. static unsigned int bfin_get_vlev(unsigned int freq)
  37. {
  38. int i;
  39. if (!pdata)
  40. goto err_out;
  41. freq >>= 16;
  42. for (i = 0; i < pdata->tabsize; i++)
  43. if (freq <= (pdata->tuple_tab[i] & 0xFFFF))
  44. return pdata->tuple_tab[i] >> 16;
  45. err_out:
  46. printk(KERN_WARNING "DPMC: No suitable CCLK VDDINT voltage pair found\n");
  47. return VLEV_120;
  48. }
  49. #ifdef CONFIG_CPU_FREQ
  50. static int
  51. vreg_cpufreq_notifier(struct notifier_block *nb, unsigned long val, void *data)
  52. {
  53. struct cpufreq_freqs *freq = data;
  54. if (val == CPUFREQ_PRECHANGE && freq->old < freq->new) {
  55. bfin_set_vlev(bfin_get_vlev(freq->new));
  56. udelay(pdata->vr_settling_time); /* Wait until Volatge settled */
  57. } else if (val == CPUFREQ_POSTCHANGE && freq->old > freq->new)
  58. bfin_set_vlev(bfin_get_vlev(freq->new));
  59. return 0;
  60. }
  61. static struct notifier_block vreg_cpufreq_notifier_block = {
  62. .notifier_call = vreg_cpufreq_notifier
  63. };
  64. #endif /* CONFIG_CPU_FREQ */
  65. /**
  66. * bfin_dpmc_probe -
  67. *
  68. */
  69. static int __devinit bfin_dpmc_probe(struct platform_device *pdev)
  70. {
  71. if (pdev->dev.platform_data)
  72. pdata = pdev->dev.platform_data;
  73. else
  74. return -EINVAL;
  75. return cpufreq_register_notifier(&vreg_cpufreq_notifier_block,
  76. CPUFREQ_TRANSITION_NOTIFIER);
  77. }
  78. /**
  79. * bfin_dpmc_remove -
  80. */
  81. static int __devexit bfin_dpmc_remove(struct platform_device *pdev)
  82. {
  83. pdata = NULL;
  84. return cpufreq_unregister_notifier(&vreg_cpufreq_notifier_block,
  85. CPUFREQ_TRANSITION_NOTIFIER);
  86. }
  87. struct platform_driver bfin_dpmc_device_driver = {
  88. .probe = bfin_dpmc_probe,
  89. .remove = __devexit_p(bfin_dpmc_remove),
  90. .driver = {
  91. .name = DRIVER_NAME,
  92. }
  93. };
  94. /**
  95. * bfin_dpmc_init - Init driver
  96. */
  97. static int __init bfin_dpmc_init(void)
  98. {
  99. return platform_driver_register(&bfin_dpmc_device_driver);
  100. }
  101. module_init(bfin_dpmc_init);
  102. /**
  103. * bfin_dpmc_exit - break down driver
  104. */
  105. static void __exit bfin_dpmc_exit(void)
  106. {
  107. platform_driver_unregister(&bfin_dpmc_device_driver);
  108. }
  109. module_exit(bfin_dpmc_exit);
  110. MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
  111. MODULE_DESCRIPTION("cpu power management driver for Blackfin");
  112. MODULE_LICENSE("GPL");