Commit 70efbf88 authored by Uwe Kleine-König's avatar Uwe Kleine-König

pwm: samsung: Change prototype of helpers to prepare further changes

This prepares the driver for further changes that will make it harder to
determine the pwm_chip from a given samsung_pwm_chip. To just not have
to do that, rework pwm_samsung_calc_tin() and pwm_samsung_parse_dt take
a pwm_chip. Also use the pwm_chip as driver data instead of the
samsung_pwm_chip.

Link: https://lore.kernel.org/r/33ea7d7fbf3be4a542ae8aafa213470c5831487e.1707900770.git.u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
parent 56696c1c
...@@ -181,9 +181,10 @@ static unsigned long pwm_samsung_get_tin_rate(struct samsung_pwm_chip *our_chip, ...@@ -181,9 +181,10 @@ static unsigned long pwm_samsung_get_tin_rate(struct samsung_pwm_chip *our_chip,
return rate / (reg + 1); return rate / (reg + 1);
} }
static unsigned long pwm_samsung_calc_tin(struct samsung_pwm_chip *our_chip, static unsigned long pwm_samsung_calc_tin(struct pwm_chip *chip,
unsigned int chan, unsigned long freq) unsigned int chan, unsigned long freq)
{ {
struct samsung_pwm_chip *our_chip = to_samsung_pwm_chip(chip);
struct samsung_pwm_variant *variant = &our_chip->variant; struct samsung_pwm_variant *variant = &our_chip->variant;
unsigned long rate; unsigned long rate;
struct clk *clk; struct clk *clk;
...@@ -197,12 +198,12 @@ static unsigned long pwm_samsung_calc_tin(struct samsung_pwm_chip *our_chip, ...@@ -197,12 +198,12 @@ static unsigned long pwm_samsung_calc_tin(struct samsung_pwm_chip *our_chip,
return rate; return rate;
} }
dev_warn(our_chip->chip.dev, dev_warn(chip->dev,
"tclk of PWM %d is inoperational, using tdiv\n", chan); "tclk of PWM %d is inoperational, using tdiv\n", chan);
} }
rate = pwm_samsung_get_tin_rate(our_chip, chan); rate = pwm_samsung_get_tin_rate(our_chip, chan);
dev_dbg(our_chip->chip.dev, "tin parent at %lu\n", rate); dev_dbg(chip->dev, "tin parent at %lu\n", rate);
/* /*
* Compare minimum PWM frequency that can be achieved with possible * Compare minimum PWM frequency that can be achieved with possible
...@@ -329,7 +330,7 @@ static int __pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -329,7 +330,7 @@ static int __pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm,
dev_dbg(chip->dev, "duty_ns=%d, period_ns=%d (%u)\n", dev_dbg(chip->dev, "duty_ns=%d, period_ns=%d (%u)\n",
duty_ns, period_ns, period); duty_ns, period_ns, period);
tin_rate = pwm_samsung_calc_tin(our_chip, pwm->hwpwm, period); tin_rate = pwm_samsung_calc_tin(chip, pwm->hwpwm, period);
dev_dbg(chip->dev, "tin_rate=%lu\n", tin_rate); dev_dbg(chip->dev, "tin_rate=%lu\n", tin_rate);
...@@ -506,9 +507,10 @@ static const struct of_device_id samsung_pwm_matches[] = { ...@@ -506,9 +507,10 @@ static const struct of_device_id samsung_pwm_matches[] = {
}; };
MODULE_DEVICE_TABLE(of, samsung_pwm_matches); MODULE_DEVICE_TABLE(of, samsung_pwm_matches);
static int pwm_samsung_parse_dt(struct samsung_pwm_chip *our_chip) static int pwm_samsung_parse_dt(struct pwm_chip *chip)
{ {
struct device_node *np = our_chip->chip.dev->of_node; struct samsung_pwm_chip *our_chip = to_samsung_pwm_chip(chip);
struct device_node *np = chip->dev->of_node;
const struct of_device_id *match; const struct of_device_id *match;
struct property *prop; struct property *prop;
const __be32 *cur; const __be32 *cur;
...@@ -522,7 +524,7 @@ static int pwm_samsung_parse_dt(struct samsung_pwm_chip *our_chip) ...@@ -522,7 +524,7 @@ static int pwm_samsung_parse_dt(struct samsung_pwm_chip *our_chip)
of_property_for_each_u32(np, "samsung,pwm-outputs", prop, cur, val) { of_property_for_each_u32(np, "samsung,pwm-outputs", prop, cur, val) {
if (val >= SAMSUNG_PWM_NUM) { if (val >= SAMSUNG_PWM_NUM) {
dev_err(our_chip->chip.dev, dev_err(chip->dev,
"%s: invalid channel index in samsung,pwm-outputs property\n", "%s: invalid channel index in samsung,pwm-outputs property\n",
__func__); __func__);
continue; continue;
...@@ -533,7 +535,7 @@ static int pwm_samsung_parse_dt(struct samsung_pwm_chip *our_chip) ...@@ -533,7 +535,7 @@ static int pwm_samsung_parse_dt(struct samsung_pwm_chip *our_chip)
return 0; return 0;
} }
#else #else
static int pwm_samsung_parse_dt(struct samsung_pwm_chip *our_chip) static int pwm_samsung_parse_dt(struct pwm_chip *chip)
{ {
return -ENODEV; return -ENODEV;
} }
...@@ -543,6 +545,7 @@ static int pwm_samsung_probe(struct platform_device *pdev) ...@@ -543,6 +545,7 @@ static int pwm_samsung_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct samsung_pwm_chip *our_chip; struct samsung_pwm_chip *our_chip;
struct pwm_chip *chip;
unsigned int chan; unsigned int chan;
int ret; int ret;
...@@ -550,13 +553,14 @@ static int pwm_samsung_probe(struct platform_device *pdev) ...@@ -550,13 +553,14 @@ static int pwm_samsung_probe(struct platform_device *pdev)
if (our_chip == NULL) if (our_chip == NULL)
return -ENOMEM; return -ENOMEM;
our_chip->chip.dev = &pdev->dev; chip = &our_chip->chip;
our_chip->chip.ops = &pwm_samsung_ops; chip->dev = &pdev->dev;
our_chip->chip.npwm = SAMSUNG_PWM_NUM; chip->ops = &pwm_samsung_ops;
chip->npwm = SAMSUNG_PWM_NUM;
our_chip->inverter_mask = BIT(SAMSUNG_PWM_NUM) - 1; our_chip->inverter_mask = BIT(SAMSUNG_PWM_NUM) - 1;
if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) { if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
ret = pwm_samsung_parse_dt(our_chip); ret = pwm_samsung_parse_dt(chip);
if (ret) if (ret)
return ret; return ret;
} else { } else {
...@@ -593,9 +597,9 @@ static int pwm_samsung_probe(struct platform_device *pdev) ...@@ -593,9 +597,9 @@ static int pwm_samsung_probe(struct platform_device *pdev)
our_chip->tclk0 = devm_clk_get(&pdev->dev, "pwm-tclk0"); our_chip->tclk0 = devm_clk_get(&pdev->dev, "pwm-tclk0");
our_chip->tclk1 = devm_clk_get(&pdev->dev, "pwm-tclk1"); our_chip->tclk1 = devm_clk_get(&pdev->dev, "pwm-tclk1");
platform_set_drvdata(pdev, our_chip); platform_set_drvdata(pdev, chip);
ret = pwmchip_add(&our_chip->chip); ret = pwmchip_add(chip);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "failed to register PWM chip\n"); dev_err(dev, "failed to register PWM chip\n");
clk_disable_unprepare(our_chip->base_clk); clk_disable_unprepare(our_chip->base_clk);
...@@ -612,17 +616,18 @@ static int pwm_samsung_probe(struct platform_device *pdev) ...@@ -612,17 +616,18 @@ static int pwm_samsung_probe(struct platform_device *pdev)
static void pwm_samsung_remove(struct platform_device *pdev) static void pwm_samsung_remove(struct platform_device *pdev)
{ {
struct samsung_pwm_chip *our_chip = platform_get_drvdata(pdev); struct pwm_chip *chip = platform_get_drvdata(pdev);
struct samsung_pwm_chip *our_chip = to_samsung_pwm_chip(chip);
pwmchip_remove(&our_chip->chip); pwmchip_remove(chip);
clk_disable_unprepare(our_chip->base_clk); clk_disable_unprepare(our_chip->base_clk);
} }
static int pwm_samsung_resume(struct device *dev) static int pwm_samsung_resume(struct device *dev)
{ {
struct samsung_pwm_chip *our_chip = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct pwm_chip *chip = &our_chip->chip; struct samsung_pwm_chip *our_chip = to_samsung_pwm_chip(chip);
unsigned int i; unsigned int i;
for (i = 0; i < SAMSUNG_PWM_NUM; i++) { for (i = 0; i < SAMSUNG_PWM_NUM; i++) {
......
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