ccu_sdm.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2017 Chen-Yu Tsai. All rights reserved.
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _CCU_SDM_H
  14. #define _CCU_SDM_H
  15. #include <linux/clk-provider.h>
  16. #include "ccu_common.h"
  17. struct ccu_sdm_setting {
  18. unsigned long rate;
  19. /*
  20. * XXX We don't know what the step and bottom register fields
  21. * mean. Just copy the whole register value from the vendor
  22. * kernel for now.
  23. */
  24. u32 pattern;
  25. /*
  26. * M and N factors here should be the values used in
  27. * calculation, not the raw values written to registers
  28. */
  29. u32 m;
  30. u32 n;
  31. };
  32. struct ccu_sdm_internal {
  33. struct ccu_sdm_setting *table;
  34. u32 table_size;
  35. /* early SoCs don't have the SDM enable bit in the PLL register */
  36. u32 enable;
  37. /* second enable bit in tuning register */
  38. u32 tuning_enable;
  39. u16 tuning_reg;
  40. };
  41. #define _SUNXI_CCU_SDM(_table, _enable, \
  42. _reg, _reg_enable) \
  43. { \
  44. .table = _table, \
  45. .table_size = ARRAY_SIZE(_table), \
  46. .enable = _enable, \
  47. .tuning_enable = _reg_enable, \
  48. .tuning_reg = _reg, \
  49. }
  50. bool ccu_sdm_helper_is_enabled(struct ccu_common *common,
  51. struct ccu_sdm_internal *sdm);
  52. void ccu_sdm_helper_enable(struct ccu_common *common,
  53. struct ccu_sdm_internal *sdm,
  54. unsigned long rate);
  55. void ccu_sdm_helper_disable(struct ccu_common *common,
  56. struct ccu_sdm_internal *sdm);
  57. bool ccu_sdm_helper_has_rate(struct ccu_common *common,
  58. struct ccu_sdm_internal *sdm,
  59. unsigned long rate);
  60. unsigned long ccu_sdm_helper_read_rate(struct ccu_common *common,
  61. struct ccu_sdm_internal *sdm,
  62. u32 m, u32 n);
  63. int ccu_sdm_helper_get_factors(struct ccu_common *common,
  64. struct ccu_sdm_internal *sdm,
  65. unsigned long rate,
  66. unsigned long *m, unsigned long *n);
  67. #endif