pwm-dwc.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * DesignWare PWM Controller driver
  4. *
  5. * Copyright (C) 2018-2020 Intel Corporation
  6. *
  7. * Author: Felipe Balbi (Intel)
  8. * Author: Jarkko Nikula <jarkko.nikula@linux.intel.com>
  9. * Author: Raymond Tan <raymond.tan@intel.com>
  10. */
  11. MODULE_IMPORT_NS(dwc_pwm);
  12. #define DWC_TIM_LD_CNT(n) ((n) * 0x14)
  13. #define DWC_TIM_LD_CNT2(n) (((n) * 4) + 0xb0)
  14. #define DWC_TIM_CUR_VAL(n) (((n) * 0x14) + 0x04)
  15. #define DWC_TIM_CTRL(n) (((n) * 0x14) + 0x08)
  16. #define DWC_TIM_EOI(n) (((n) * 0x14) + 0x0c)
  17. #define DWC_TIM_INT_STS(n) (((n) * 0x14) + 0x10)
  18. #define DWC_TIMERS_INT_STS 0xa0
  19. #define DWC_TIMERS_EOI 0xa4
  20. #define DWC_TIMERS_RAW_INT_STS 0xa8
  21. #define DWC_TIMERS_COMP_VERSION 0xac
  22. #define DWC_TIMERS_TOTAL 8
  23. /* Timer Control Register */
  24. #define DWC_TIM_CTRL_EN BIT(0)
  25. #define DWC_TIM_CTRL_MODE BIT(1)
  26. #define DWC_TIM_CTRL_MODE_FREE (0 << 1)
  27. #define DWC_TIM_CTRL_MODE_USER (1 << 1)
  28. #define DWC_TIM_CTRL_INT_MASK BIT(2)
  29. #define DWC_TIM_CTRL_PWM BIT(3)
  30. struct dwc_pwm_info {
  31. unsigned int nr;
  32. unsigned int size;
  33. };
  34. struct dwc_pwm_drvdata {
  35. const struct dwc_pwm_info *info;
  36. void __iomem *io_base;
  37. struct pwm_chip *chips[];
  38. };
  39. struct dwc_pwm_ctx {
  40. u32 cnt;
  41. u32 cnt2;
  42. u32 ctrl;
  43. };
  44. struct dwc_pwm {
  45. void __iomem *base;
  46. unsigned int clk_ns;
  47. struct dwc_pwm_ctx ctx[DWC_TIMERS_TOTAL];
  48. };
  49. static inline struct dwc_pwm *to_dwc_pwm(struct pwm_chip *chip)
  50. {
  51. return pwmchip_get_drvdata(chip);
  52. }
  53. static inline u32 dwc_pwm_readl(struct dwc_pwm *dwc, u32 offset)
  54. {
  55. return readl(dwc->base + offset);
  56. }
  57. static inline void dwc_pwm_writel(struct dwc_pwm *dwc, u32 value, u32 offset)
  58. {
  59. writel(value, dwc->base + offset);
  60. }
  61. extern struct pwm_chip *dwc_pwm_alloc(struct device *dev);