via_clock.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
  4. * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
  5. * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
  6. */
  7. /*
  8. * clock and PLL management functions
  9. */
  10. #ifndef __VIA_CLOCK_H__
  11. #define __VIA_CLOCK_H__
  12. #include <linux/types.h>
  13. enum via_clksrc {
  14. VIA_CLKSRC_X1 = 0,
  15. VIA_CLKSRC_TVX1,
  16. VIA_CLKSRC_TVPLL,
  17. VIA_CLKSRC_DVP1TVCLKR,
  18. VIA_CLKSRC_CAP0,
  19. VIA_CLKSRC_CAP1,
  20. };
  21. struct via_pll_config {
  22. u16 multiplier;
  23. u8 divisor;
  24. u8 rshift;
  25. };
  26. struct via_clock {
  27. void (*set_primary_clock_state)(u8 state);
  28. void (*set_primary_clock_source)(enum via_clksrc src, bool use_pll);
  29. void (*set_primary_pll_state)(u8 state);
  30. void (*set_primary_pll)(struct via_pll_config config);
  31. void (*set_secondary_clock_state)(u8 state);
  32. void (*set_secondary_clock_source)(enum via_clksrc src, bool use_pll);
  33. void (*set_secondary_pll_state)(u8 state);
  34. void (*set_secondary_pll)(struct via_pll_config config);
  35. void (*set_engine_pll_state)(u8 state);
  36. void (*set_engine_pll)(struct via_pll_config config);
  37. };
  38. static inline u32 get_pll_internal_frequency(u32 ref_freq,
  39. struct via_pll_config pll)
  40. {
  41. return ref_freq / pll.divisor * pll.multiplier;
  42. }
  43. static inline u32 get_pll_output_frequency(u32 ref_freq,
  44. struct via_pll_config pll)
  45. {
  46. return get_pll_internal_frequency(ref_freq, pll) >> pll.rshift;
  47. }
  48. void via_clock_init(struct via_clock *clock, int gfx_chip);
  49. #endif /* __VIA_CLOCK_H__ */