#ifndef BCM2835_PWMREG_H
#define BCM2835_PWMREG_H
#define PWM_CTL 0x00
#define PWM_CTL_MSEN2 __BIT(15)
#define PWM_CTL_USEF2 __BIT(13)
#define PWM_CTL_POLA2 __BIT(12)
#define PWM_CTL_SBIT2 __BIT(11)
#define PWM_CTL_RPTL2 __BIT(10)
#define PWM_CTL_MODE2 __BIT(9)
#define PWM_CTL_PWEN2 __BIT(8)
#define PWM_CTL_MSEN1 __BIT(7)
#define PWM_CTL_CLRF1 __BIT(6)
#define PWM_CTL_USEF1 __BIT(5)
#define PWM_CTL_POLA1 __BIT(4)
#define PWM_CTL_SBIT1 __BIT(3)
#define PWM_CTL_RPTL1 __BIT(2)
#define PWM_CTL_MODE1 __BIT(1)
#define PWM_CTL_PWEN1 __BIT(0)
#define PWM_CTL_WRITEZERO (__BITS(16,31)|__BIT(14))
#define PWM_STA 0x04
#define PWM_STA_STA4 __BIT(12)
#define PWM_STA_STA3 __BIT(11)
#define PWM_STA_STA2 __BIT(10)
#define PWM_STA_STA1 __BIT(9)
#define PWM_STA_BERR __BIT(8)
#define PWM_STA_GAPO4 __BIT(7)
#define PWM_STA_GAPO3 __BIT(6)
#define PWM_STA_GAPO2 __BIT(5)
#define PWM_STA_GAPO1 __BIT(4)
#define PWM_STA_RERR1 __BIT(3)
#define PWM_STA_WERR1 __BIT(2)
#define PWM_STA_EMPT1 __BIT(1)
#define PWM_STA_FULL1 __BIT(0)
#define PWM_STA_WRITEZERO __BITS(13,31)
#define PWM_DMAC 0x08
#define PWM_DMAC_ENAB __BIT(31)
#define PWM_DMAC_PANIC __BITS(8,15)
#define PWM_DMAC_DREQ __BITS(0,7)
#define PWM_DMAC_WRITEZERO __BITS(16,30)
#define PWM_RNG1 0x10
#define PWM_DAT1 0x14
#define PWM_FIFO 0x18
#define PWM_RNG2 0x20
#define PWM_DAT2 0x24
struct bcm_pwm_channel;
struct bcm_pwm_channel *bcm_pwm_alloc(int num);
void bcm_pwm_free(struct bcm_pwm_channel *);
void bcm_pwm_control(struct bcm_pwm_channel *, uint32_t, uint32_t);
uint32_t bcm_pwm_status(struct bcm_pwm_channel *);
int bcm_pwm_write(struct bcm_pwm_channel *, uint32_t *, uint32_t *, int);
void bcm_pwm_set(struct bcm_pwm_channel *, uint32_t);
int bcm_pwm_flush(struct bcm_pwm_channel *);
void bcm_pwm_dma_enable(struct bcm_pwm_channel *, bool);
uint32_t bcm_pwm_dma_address(struct bcm_pwm_channel *);
#define PWM_CTL_MSEN PWM_CTL_MSEN1
#define PWM_CTL_USEF PWM_CTL_USEF1
#define PWM_CTL_RPTL PWM_CTL_RPTL1
#define PWM_CTL_MODE PWM_CTL_MODE1
#define PWM_CTL_PWEN PWM_CTL_PWEN1
#define PWM_STA_STA PWM_STA_STA1
#define PWM_STA_GAPO PWM_STA_GAPO1
#define PWM_STA_RERR PWM_STA_RERR1
#define PWM_STA_WERR PWM_STA_WERR1
#define PWM_STA_EMPT PWM_STA_EMPT1
#define PWM_STA_FULL PWM_STA_FULL1
#endif