#include <linux/ioport.h>
#include <linux/kernel.h>
#include <linux/math64.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#define PWMCR_PWM_ENABLE 0x1
#define PWMCR_PRESCALE_SHIFT 2
#define PWMCR_MIN_PRESCALE 0x00
#define PWMCR_MAX_PRESCALE 0x3FFF
#define PWMDCR_MIN_DUTY 0x0001
#define PWMDCR_MAX_DUTY 0xFFFF
#define PWMPCR_MIN_PERIOD 0x0001
#define PWMPCR_MAX_PERIOD 0xFFFF
#define PWMMCR_PWM_ENABLE 0x1
static inline struct spear_pwm_chip *to_spear_pwm_chip(struct pwm_chip *chip)
return container_of(chip, struct spear_pwm_chip, chip);
static inline u32 spear_pwm_readl(struct spear_pwm_chip *chip, unsigned int num,
return readl_relaxed(chip->mmio_base + (num << 4) + offset);
static inline void spear_pwm_writel(struct spear_pwm_chip *chip,
unsigned int num, unsigned long offset,
writel_relaxed(val, chip->mmio_base + (num << 4) + offset);
static int spear_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
int duty_ns, int period_ns)
struct spear_pwm_chip *pc = to_spear_pwm_chip(chip);
unsigned long prescale = PWMCR_MIN_PRESCALE, pv, dc;