linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* linux-next: manual merge of the pwm tree with the regulator tree
@ 2016-05-03  8:25 Stephen Rothwell
  2016-05-03 11:03 ` Mark Brown
  0 siblings, 1 reply; 10+ messages in thread
From: Stephen Rothwell @ 2016-05-03  8:25 UTC (permalink / raw)
  To: Thierry Reding, Mark Brown, Liam Girdwood
  Cc: linux-next, linux-kernel, Boris Brezillon, Laxman Dewangan

Hi Thierry,

Today's linux-next merge of the pwm tree got a conflict in:

  drivers/regulator/pwm-regulator.c

between commit:

  fd786fb0276a ("regulator: pwm: Try to avoid voltage error in duty cycle calculation")

from the regulator tree and commit:

  f137b90ba6cd ("regulator: pwm: Use pwm_get_args() where appropriate")

from the pwm tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/regulator/pwm-regulator.c
index 8e928f23279b,ffdb895ace0a..000000000000
--- a/drivers/regulator/pwm-regulator.c
+++ b/drivers/regulator/pwm-regulator.c
@@@ -63,14 -63,14 +63,14 @@@ static int pwm_regulator_set_voltage_se
  	int dutycycle;
  	int ret;
  
- 	pwm_reg_period = pwm_get_period(drvdata->pwm);
+ 	pwm_get_args(drvdata->pwm, &pargs);
  
- 	dutycycle = (pwm_reg_period *
+ 	dutycycle = (pargs.period *
  		    drvdata->duty_cycle_table[selector].dutycycle) / 100;
  
- 	ret = pwm_config(drvdata->pwm, dutycycle, pwm_reg_period);
+ 	ret = pwm_config(drvdata->pwm, dutycycle, pargs.period);
  	if (ret) {
 -		dev_err(&rdev->dev, "Failed to configure PWM\n");
 +		dev_err(&rdev->dev, "Failed to configure PWM: %d\n", ret);
  		return ret;
  	}
  
@@@ -126,35 -138,17 +126,36 @@@ static int pwm_regulator_set_voltage(st
  {
  	struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
  	unsigned int ramp_delay = rdev->constraints->ramp_delay;
- 	unsigned int period = pwm_get_period(drvdata->pwm);
+ 	struct pwm_args pargs;
 -	int duty_cycle;
 +	unsigned int req_diff = min_uV - rdev->constraints->min_uV;
 +	unsigned int diff;
 +	unsigned int duty_pulse;
 +	u64 req_period;
 +	u32 rem;
  	int ret;
  
+ 	pwm_get_args(drvdata->pwm, &pargs);
 -	duty_cycle = pwm_voltage_to_duty_cycle_percentage(rdev, min_uV);
 +	diff = rdev->constraints->max_uV - rdev->constraints->min_uV;
 +
 +	/* First try to find out if we get the iduty cycle time which is
 +	 * factor of PWM period time. If (request_diff_to_min * pwm_period)
 +	 * is perfect divided by voltage_range_diff then it is possible to
 +	 * get duty cycle time which is factor of PWM period. This will help
 +	 * to get output voltage nearer to requested value as there is no
 +	 * calculation loss.
 +	 */
- 	req_period = req_diff * period;
++	req_period = req_diff * pargs.period;
 +	div_u64_rem(req_period, diff, &rem);
 +	if (!rem) {
 +		do_div(req_period, diff);
 +		duty_pulse = (unsigned int)req_period;
 +	} else {
- 		duty_pulse = (period / 100) * ((req_diff * 100) / diff);
++		duty_pulse = (pargs.period / 100) * ((req_diff * 100) / diff);
 +	}
  
- 	ret = pwm_config(drvdata->pwm, duty_pulse, period);
 -	ret = pwm_config(drvdata->pwm, (pargs.period / 100) * duty_cycle,
 -			 pargs.period);
++	ret = pwm_config(drvdata->pwm, duty_pulse, pargs.period);
  	if (ret) {
 -		dev_err(&rdev->dev, "Failed to configure PWM\n");
 +		dev_err(&rdev->dev, "Failed to configure PWM: %d\n", ret);
  		return ret;
  	}
  
@@@ -284,11 -279,16 +285,17 @@@ static int pwm_regulator_probe(struct p
  
  	drvdata->pwm = devm_pwm_get(&pdev->dev, NULL);
  	if (IS_ERR(drvdata->pwm)) {
 -		dev_err(&pdev->dev, "Failed to get PWM\n");
 -		return PTR_ERR(drvdata->pwm);
 +		ret = PTR_ERR(drvdata->pwm);
 +		dev_err(&pdev->dev, "Failed to get PWM: %d\n", ret);
 +		return ret;
  	}
  
+ 	/*
+ 	 * FIXME: pwm_apply_args() should be removed when switching to the
+ 	 * atomic PWM API.
+ 	 */
+ 	pwm_apply_args(drvdata->pwm);
+ 
  	regulator = devm_regulator_register(&pdev->dev,
  					    &drvdata->desc, &config);
  	if (IS_ERR(regulator)) {

^ permalink raw reply	[flat|nested] 10+ messages in thread
* linux-next: manual merge of the pwm tree with the regulator tree
@ 2016-07-11  6:56 Stephen Rothwell
  2016-07-11 16:47 ` Doug Anderson
  0 siblings, 1 reply; 10+ messages in thread
From: Stephen Rothwell @ 2016-07-11  6:56 UTC (permalink / raw)
  To: Thierry Reding, Mark Brown, Liam Girdwood
  Cc: linux-next, linux-kernel, Boris Brezillon, Alexandre Courbot,
	Douglas Anderson

Hi Thierry,

Today's linux-next merge of the pwm tree got a conflict in:

  drivers/regulator/pwm-regulator.c

between commit:

  830583004e61 ("regulator: pwm: Drop unneeded pwm_enable() call")
  27bfa8893b15 ("regulator: pwm: Support for enable GPIO")
  c2588393e631 ("regulator: pwm: Fix regulator ramp delay for continuous mode")

from the regulator tree and commit:

  b0303deaa480 ("regulator: pwm: Adjust PWM config at probe time")
  8bd57ca236d0 ("regulator: pwm: Switch to the atomic PWM API")
  25d16595935b ("regulator: pwm: Retrieve correct voltage")
  53f239af4c14 ("regulator: pwm: Support extra continuous mode cases")

from the pwm tree.

I fixed it up (I think, please check - see below) and can carry the fix
as necessary. This is now fixed as far as linux-next is concerned, but
any non trivial conflicts should be mentioned to your upstream maintainer
when your tree is submitted for merging.  You may also want to consider
cooperating with the maintainer of the conflicting tree to minimise any
particularly complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/regulator/pwm-regulator.c
index 666bc3bb52ef,a8e9147dd8db..000000000000
--- a/drivers/regulator/pwm-regulator.c
+++ b/drivers/regulator/pwm-regulator.c
@@@ -20,8 -20,13 +20,14 @@@
  #include <linux/of.h>
  #include <linux/of_device.h>
  #include <linux/pwm.h>
 +#include <linux/gpio/consumer.h>
  
+ struct pwm_continuous_reg_data {
+ 	unsigned int min_uV_dutycycle;
+ 	unsigned int max_uV_dutycycle;
+ 	unsigned int dutycycle_unit;
+ };
+ 
  struct pwm_regulator_data {
  	/*  Shared */
  	struct pwm_device *pwm;
@@@ -36,12 -44,6 +45,9 @@@
  	struct regulator_ops ops;
  
  	int state;
 +
- 	/* Continuous voltage */
- 	int volt_uV;
- 
 +	/* Enable GPIO */
 +	struct gpio_desc *enb_gpio;
  };
  
  struct pwm_voltages {
@@@ -134,53 -174,59 +187,58 @@@ static int pwm_regulator_get_voltage(st
  }
  
  static int pwm_regulator_set_voltage(struct regulator_dev *rdev,
- 					int min_uV, int max_uV,
- 					unsigned *selector)
+ 				     int req_min_uV, int req_max_uV,
+ 				     unsigned int *selector)
  {
  	struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
+ 	unsigned int min_uV_duty = drvdata->continuous.min_uV_dutycycle;
+ 	unsigned int max_uV_duty = drvdata->continuous.max_uV_dutycycle;
+ 	unsigned int duty_unit = drvdata->continuous.dutycycle_unit;
  	unsigned int ramp_delay = rdev->constraints->ramp_delay;
- 	struct pwm_args pargs;
- 	unsigned int req_diff = min_uV - rdev->constraints->min_uV;
- 	unsigned int diff;
- 	unsigned int duty_pulse;
- 	u64 req_period;
- 	u32 rem;
+ 	int min_uV = rdev->constraints->min_uV;
+ 	int max_uV = rdev->constraints->max_uV;
+ 	int diff_uV = max_uV - min_uV;
+ 	struct pwm_state pstate;
+ 	unsigned int diff_duty;
+ 	unsigned int dutycycle;
 +	int old_uV = pwm_regulator_get_voltage(rdev);
  	int ret;
  
- 	pwm_get_args(drvdata->pwm, &pargs);
- 	diff = rdev->constraints->max_uV - rdev->constraints->min_uV;
+ 	pwm_init_state(drvdata->pwm, &pstate);
  
- 	/* First try to find out if we get the iduty cycle time which is
- 	 * factor of PWM period time. If (request_diff_to_min * pwm_period)
- 	 * is perfect divided by voltage_range_diff then it is possible to
- 	 * get duty cycle time which is factor of PWM period. This will help
- 	 * to get output voltage nearer to requested value as there is no
- 	 * calculation loss.
+ 	/*
+ 	 * The dutycycle for min_uV might be greater than the one for max_uV.
+ 	 * This is happening when the user needs an inversed polarity, but the
+ 	 * PWM device does not support inversing it in hardware.
  	 */
- 	req_period = req_diff * pargs.period;
- 	div_u64_rem(req_period, diff, &rem);
- 	if (!rem) {
- 		do_div(req_period, diff);
- 		duty_pulse = (unsigned int)req_period;
- 	} else {
- 		duty_pulse = (pargs.period / 100) * ((req_diff * 100) / diff);
- 	}
+ 	if (max_uV_duty < min_uV_duty)
+ 		diff_duty = min_uV_duty - max_uV_duty;
+ 	else
+ 		diff_duty = max_uV_duty - min_uV_duty;
+ 
+ 	dutycycle = DIV_ROUND_CLOSEST_ULL((u64)(req_min_uV - min_uV) *
+ 					  diff_duty,
+ 					  diff_uV);
+ 
+ 	if (max_uV_duty < min_uV_duty)
+ 		dutycycle = min_uV_duty - dutycycle;
+ 	else
+ 		dutycycle = min_uV_duty + dutycycle;
+ 
+ 	pwm_set_relative_duty_cycle(&pstate, dutycycle, duty_unit);
  
- 	ret = pwm_config(drvdata->pwm, duty_pulse, pargs.period);
+ 	ret = pwm_apply_state(drvdata->pwm, &pstate);
  	if (ret) {
  		dev_err(&rdev->dev, "Failed to configure PWM: %d\n", ret);
  		return ret;
  	}
  
- 	drvdata->volt_uV = min_uV;
- 
 -	ret = pwm_enable(drvdata->pwm);
 -	if (ret) {
 -		dev_err(&rdev->dev, "Failed to enable PWM: %d\n", ret);
 -		return ret;
 -	}
 +	if ((ramp_delay == 0) || !pwm_regulator_is_enabled(rdev))
 +		return 0;
  
 -	/* Delay required by PWM regulator to settle to the new voltage */
 -	usleep_range(ramp_delay, ramp_delay + 1000);
 +	/* Ramp delay is in uV/uS. Adjust to uS and delay */
 +	ramp_delay = DIV_ROUND_UP(abs(min_uV - old_uV), ramp_delay);
 +	usleep_range(ramp_delay, ramp_delay + DIV_ROUND_UP(ramp_delay, 10));
  
  	return 0;
  }
@@@ -304,23 -367,9 +380,21 @@@ static int pwm_regulator_probe(struct p
  		return ret;
  	}
  
 +	if (init_data->constraints.boot_on || init_data->constraints.always_on)
 +		gpio_flags = GPIOD_OUT_HIGH;
 +	else
 +		gpio_flags = GPIOD_OUT_LOW;
 +	drvdata->enb_gpio = devm_gpiod_get_optional(&pdev->dev, "enable",
 +						    gpio_flags);
 +	if (IS_ERR(drvdata->enb_gpio)) {
 +		ret = PTR_ERR(drvdata->enb_gpio);
 +		dev_err(&pdev->dev, "Failed to get enable GPIO: %d\n", ret);
 +		return ret;
 +	}
 +
- 	/*
- 	 * FIXME: pwm_apply_args() should be removed when switching to the
- 	 * atomic PWM API.
- 	 */
- 	pwm_apply_args(drvdata->pwm);
+ 	ret = pwm_adjust_config(drvdata->pwm);
+ 	if (ret)
+ 		return ret;
  
  	regulator = devm_regulator_register(&pdev->dev,
  					    &drvdata->desc, &config);

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-07-25 14:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-03  8:25 linux-next: manual merge of the pwm tree with the regulator tree Stephen Rothwell
2016-05-03 11:03 ` Mark Brown
2016-05-03 12:18   ` Thierry Reding
2016-07-11  6:56 Stephen Rothwell
2016-07-11 16:47 ` Doug Anderson
2016-07-11 21:30   ` Thierry Reding
2016-07-11 21:39     ` Thierry Reding
2016-07-25  8:29       ` Thierry Reding
2016-07-25 13:29         ` Doug Anderson
2016-07-25 14:26           ` Thierry Reding

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).