Commit 3aacd3e1 authored by Ajit Pal Singh's avatar Ajit Pal Singh Committed by Thierry Reding

pwm: sti: Remove PWM period table

Removes the PWM period table. Instead the prescaler is computed
from the period value passed in the config() function.
Signed-off-by: default avatarAjit Pal Singh <ajitpal.singh@st.com>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent 6ad6b838
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
* (at your option) any later version. * (at your option) any later version.
*/ */
#include <linux/bsearch.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/math64.h> #include <linux/math64.h>
#include <linux/mfd/syscon.h> #include <linux/mfd/syscon.h>
...@@ -56,7 +55,6 @@ struct sti_pwm_chip { ...@@ -56,7 +55,6 @@ struct sti_pwm_chip {
struct regmap_field *prescale_high; struct regmap_field *prescale_high;
struct regmap_field *pwm_en; struct regmap_field *pwm_en;
struct regmap_field *pwm_int_en; struct regmap_field *pwm_int_en;
unsigned long *pwm_periods;
struct pwm_chip chip; struct pwm_chip chip;
struct pwm_device *cur; struct pwm_device *cur;
unsigned int en_count; unsigned int en_count;
...@@ -77,29 +75,31 @@ static inline struct sti_pwm_chip *to_sti_pwmchip(struct pwm_chip *chip) ...@@ -77,29 +75,31 @@ static inline struct sti_pwm_chip *to_sti_pwmchip(struct pwm_chip *chip)
} }
/* /*
* Calculate the period values supported by the PWM for the * Calculate the prescaler value corresponding to the period.
* current clock rate.
*/ */
static void sti_pwm_calc_periods(struct sti_pwm_chip *pc) static int sti_pwm_get_prescale(struct sti_pwm_chip *pc, unsigned long period,
unsigned int *prescale)
{ {
struct sti_pwm_compat_data *cdata = pc->cdata; struct sti_pwm_compat_data *cdata = pc->cdata;
struct device *dev = pc->dev;
unsigned long val; unsigned long val;
int i; unsigned int ps;
/* /*
* period_ns = (10^9 * (prescaler + 1) * (MAX_PWM_COUNT + 1)) / CLK_RATE * prescale = ((period_ns * clk_rate) / (10^9 * (max_pwm_count + 1)) - 1
*/ */
val = NSEC_PER_SEC / pc->clk_rate; val = NSEC_PER_SEC / pc->clk_rate;
val *= cdata->max_pwm_cnt + 1; val *= cdata->max_pwm_cnt + 1;
dev_dbg(dev, "possible periods for clkrate[HZ]:%lu\n", pc->clk_rate); if (period % val) {
return -EINVAL;
for (i = 0; i <= cdata->max_prescale; i++) { } else {
pc->pwm_periods[i] = val * (i + 1); ps = period / val - 1;
dev_dbg(dev, "prescale:%d, period[ns]:%lu\n", if (ps > cdata->max_prescale)
i, pc->pwm_periods[i]); return -EINVAL;
} }
*prescale = ps;
return 0;
} }
/* Calculate the number of PWM devices configured with a period. */ /* Calculate the number of PWM devices configured with a period. */
...@@ -120,17 +120,6 @@ static unsigned int sti_pwm_count_configured(struct pwm_chip *chip) ...@@ -120,17 +120,6 @@ static unsigned int sti_pwm_count_configured(struct pwm_chip *chip)
return ncfg; return ncfg;
} }
static int sti_pwm_cmp_periods(const void *key, const void *elt)
{
unsigned long i = *(unsigned long *)key;
unsigned long j = *(unsigned long *)elt;
if (i < j)
return -1;
else
return i == j ? 0 : 1;
}
/* /*
* For STiH4xx PWM IP, the PWM period is fixed to 256 local clock cycles. * For STiH4xx PWM IP, the PWM period is fixed to 256 local clock cycles.
* The only way to change the period (apart from changing the PWM input clock) * The only way to change the period (apart from changing the PWM input clock)
...@@ -148,7 +137,6 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -148,7 +137,6 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
struct pwm_device *cur = pc->cur; struct pwm_device *cur = pc->cur;
struct device *dev = pc->dev; struct device *dev = pc->dev;
unsigned int prescale = 0, pwmvalx; unsigned int prescale = 0, pwmvalx;
unsigned long *found;
int ret; int ret;
unsigned int ncfg; unsigned int ncfg;
bool period_same = false; bool period_same = false;
...@@ -178,21 +166,9 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -178,21 +166,9 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
return ret; return ret;
if (!period_same) { if (!period_same) {
/* ret = sti_pwm_get_prescale(pc, period_ns, &prescale);
* Search for matching period value. if (ret)
* The corresponding index is our prescale value.
*/
found = bsearch(&period_ns, &pc->pwm_periods[0],
cdata->max_prescale + 1,
sizeof(unsigned long),
sti_pwm_cmp_periods);
if (!found) {
dev_err(dev,
"failed to find matching period\n");
ret = -EINVAL;
goto clk_dis; goto clk_dis;
}
prescale = found - &pc->pwm_periods[0];
ret = ret =
regmap_field_write(pc->prescale_low, regmap_field_write(pc->prescale_low,
...@@ -373,12 +349,6 @@ static int sti_pwm_probe(struct platform_device *pdev) ...@@ -373,12 +349,6 @@ static int sti_pwm_probe(struct platform_device *pdev)
if (ret) if (ret)
return ret; return ret;
pc->pwm_periods = devm_kzalloc(dev,
sizeof(unsigned long) * (pc->cdata->max_prescale + 1),
GFP_KERNEL);
if (!pc->pwm_periods)
return -ENOMEM;
pc->clk = of_clk_get_by_name(dev->of_node, "pwm"); pc->clk = of_clk_get_by_name(dev->of_node, "pwm");
if (IS_ERR(pc->clk)) { if (IS_ERR(pc->clk)) {
dev_err(dev, "failed to get PWM clock\n"); dev_err(dev, "failed to get PWM clock\n");
...@@ -397,8 +367,6 @@ static int sti_pwm_probe(struct platform_device *pdev) ...@@ -397,8 +367,6 @@ static int sti_pwm_probe(struct platform_device *pdev)
return ret; return ret;
} }
sti_pwm_calc_periods(pc);
pc->chip.dev = dev; pc->chip.dev = dev;
pc->chip.ops = &sti_pwm_ops; pc->chip.ops = &sti_pwm_ops;
pc->chip.base = -1; pc->chip.base = -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment