atmel_pwm.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef __LINUX_ATMEL_PWM_H
  2. #define __LINUX_ATMEL_PWM_H
  3. /**
  4. * struct pwm_channel - driver handle to a PWM channel
  5. * @regs: base of this channel's registers
  6. * @index: number of this channel (0..31)
  7. * @mck: base clock rate, which can be prescaled and maybe subdivided
  8. *
  9. * Drivers initialize a pwm_channel structure using pwm_channel_alloc().
  10. * Then they configure its clock rate (derived from MCK), alignment,
  11. * polarity, and duty cycle by writing directly to the channel registers,
  12. * before enabling the channel by calling pwm_channel_enable().
  13. *
  14. * After emitting a PWM signal for the desired length of time, drivers
  15. * may then pwm_channel_disable() or pwm_channel_free(). Both of these
  16. * disable the channel, but when it's freed the IRQ is deconfigured and
  17. * the channel must later be re-allocated and reconfigured.
  18. *
  19. * Note that if the period or duty cycle need to be changed while the
  20. * PWM channel is operating, drivers must use the PWM_CUPD double buffer
  21. * mechanism, either polling until they change or getting implicitly
  22. * notified through a once-per-period interrupt handler.
  23. */
  24. struct pwm_channel {
  25. void __iomem *regs;
  26. unsigned index;
  27. unsigned long mck;
  28. };
  29. extern int pwm_channel_alloc(int index, struct pwm_channel *ch);
  30. extern int pwm_channel_free(struct pwm_channel *ch);
  31. extern int pwm_clk_alloc(unsigned prescale, unsigned div);
  32. extern void pwm_clk_free(unsigned clk);
  33. extern int __pwm_channel_onoff(struct pwm_channel *ch, int enabled);
  34. #define pwm_channel_enable(ch) __pwm_channel_onoff((ch), 1)
  35. #define pwm_channel_disable(ch) __pwm_channel_onoff((ch), 0)
  36. /* periodic interrupts, mostly for CUPD changes to period or cycle */
  37. extern int pwm_channel_handler(struct pwm_channel *ch,
  38. void (*handler)(struct pwm_channel *ch));
  39. /* per-channel registers (banked at pwm_channel->regs) */
  40. #define PWM_CMR 0x00 /* mode register */
  41. #define PWM_CPR_CPD (1 << 10) /* set: CUPD modifies period */
  42. #define PWM_CPR_CPOL (1 << 9) /* set: idle high */
  43. #define PWM_CPR_CALG (1 << 8) /* set: center align */
  44. #define PWM_CPR_CPRE (0xf << 0) /* mask: rate is mck/(2^pre) */
  45. #define PWM_CPR_CLKA (0xb << 0) /* rate CLKA */
  46. #define PWM_CPR_CLKB (0xc << 0) /* rate CLKB */
  47. #define PWM_CDTY 0x04 /* duty cycle (max of CPRD) */
  48. #define PWM_CPRD 0x08 /* period (count up from zero) */
  49. #define PWM_CCNT 0x0c /* counter (20 bits?) */
  50. #define PWM_CUPD 0x10 /* update CPRD (or CDTY) next period */
  51. static inline void
  52. pwm_channel_writel(struct pwm_channel *pwmc, unsigned offset, u32 val)
  53. {
  54. __raw_writel(val, pwmc->regs + offset);
  55. }
  56. static inline u32 pwm_channel_readl(struct pwm_channel *pwmc, unsigned offset)
  57. {
  58. return __raw_readl(pwmc->regs + offset);
  59. }
  60. #endif /* __LINUX_ATMEL_PWM_H */