devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Moon <linux.amoon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Lukasz Majewski
	<l.majewski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>,
	Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>,
	Eduardo Valentin
	<edubezval-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Sjoerd Simons
	<sjoerd.simons-ZGY8ohtN/8pPYcu2f3hruQ@public.gmane.org>,
	Markus Reichl <m.reichl-SRyzfwRm/0rPTwkrwQOX7A@public.gmane.org>,
	Russell King <linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>,
	Kukjin Kim <kgene-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Anand Moon <linux.amoon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: [PATCH v3 6/6] hwmon: pwm-fan: Update the duty cycle inorder to control the pwm-fan
Date: Mon, 13 Apr 2015 00:24:12 +0930	[thread overview]
Message-ID: <1428850452-4178-7-git-send-email-linux.amoon@gmail.com> (raw)
In-Reply-To: <1428850452-4178-1-git-send-email-linux.amoon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

In order to disable the PWM we need to update using following sequence.

	pwm_config(pwm, 0, period);
 	pwm_disable(pwm);

pwm_config() with a zero duty cycle to make it clear the timer and update the PWM registers.
pwm_disable will clear the TCON_AUTORELOAD(tcon_chan) and update the PWM register.

Next change in state will get trigger unless a new PWM cycle happened.

	pwm_config(pwm, duty, period);
 	pwm_enable(pwm);

Through pwm_config we update the duty cycle and period and update the PWM register.
pwm_enable will update the state to TCON_MANUALUPDATE(tcon_chan)
and TCON_START(tcon_chan) | TCON_AUTORELOAD(tcon_chan) and update the PWM register.

Reported-by: Markus Reichl <m.reichl-SRyzfwRm/0rPTwkrwQOX7A@public.gmane.org>
Tested-by: Markus Reichl <m.reichl-SRyzfwRm/0rPTwkrwQOX7A@public.gmane.org>
Reviewed-by: Lukasz Majewski <l.majewski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Reviewed-by: Sjoerd Simons <sjoerd.simons-ZGY8ohtN/8pPYcu2f3hruQ@public.gmane.org>
Signed-off-by: Anand Moon <linux.amoon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/hwmon/pwm-fan.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index 7c83dc4..f25c841 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -44,26 +44,24 @@ static int  __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)
 	int ret = 0;
 
 	mutex_lock(&ctx->lock);
+
 	if (ctx->pwm_value == pwm)
 		goto exit_set_pwm_err;
 
-	if (pwm == 0) {
-		pwm_disable(ctx->pwm);
-		goto exit_set_pwm;
-	}
-
 	duty = DIV_ROUND_UP(pwm * (ctx->pwm->period - 1), MAX_PWM);
 	ret = pwm_config(ctx->pwm, duty, ctx->pwm->period);
 	if (ret)
 		goto exit_set_pwm_err;
 
+	if (pwm == 0)
+		pwm_disable(ctx->pwm);
+
 	if (ctx->pwm_value == 0) {
 		ret = pwm_enable(ctx->pwm);
 		if (ret)
 			goto exit_set_pwm_err;
 	}
 
-exit_set_pwm:
 	ctx->pwm_value = pwm;
 exit_set_pwm_err:
 	mutex_unlock(&ctx->lock);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2015-04-12 14:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-12 14:54 v3 Exynos5422 odroidxu3 pwm-fan control using thermal sensors Anand Moon
2015-04-12 14:54 ` [PATCH v3 1/6] ARM: dts :exynos5422-odroidxu3 Add pwm-fan node to the Odroid-XU3 board Anand Moon
2015-04-12 14:54 ` [PATCH v3 2/6] ARM: dts: OdroidXU3: Enable TMU at Exynos5422 base Anand Moon
2015-04-12 14:54 ` [PATCH v3 3/6] ARM: dts: define default thermal-zones for exynos5 Anand Moon
2015-04-12 14:54 ` [PATCH v3 4/6] ARM: dts exynos5420 update the cooling cells for core cpu0 Anand Moon
     [not found] ` <1428850452-4178-1-git-send-email-linux.amoon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-04-12 14:54   ` [PATCH v3 5/6] ARM: dts: Enable thermal_zone for exynos5422 Anand Moon
2015-04-12 14:54   ` Anand Moon [this message]
2015-04-12 15:07     ` [PATCH v3 6/6] hwmon: pwm-fan: Update the duty cycle inorder to control the pwm-fan Guenter Roeck
     [not found]       ` <552A8A1C.9000409-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2015-04-12 15:29         ` Anand Moon
2015-04-12 15:41           ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1428850452-4178-7-git-send-email-linux.amoon@gmail.com \
    --to=linux.amoon-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=edubezval-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=kgene-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=l.majewski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
    --cc=linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
    --cc=linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=m.reichl-SRyzfwRm/0rPTwkrwQOX7A@public.gmane.org \
    --cc=sjoerd.simons-ZGY8ohtN/8pPYcu2f3hruQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).