From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, David Rivshin <drivshin@allworx.com>,
Neil Armstrong <narmstrong@baylibre.com>,
Adam Ford <aford173@gmail.com>,
Thierry Reding <thierry.reding@gmail.com>
Subject: [PATCH 4.5 28/88] pwm: omap-dmtimer: Fix inaccurate period and duty cycle calculations
Date: Mon, 9 May 2016 09:21:17 +0200 [thread overview]
Message-ID: <20160509071953.518093413@linuxfoundation.org> (raw)
In-Reply-To: <20160509071952.129092535@linuxfoundation.org>
4.5-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Rivshin <drivshin@allworx.com>
commit f8caa792261c0edded20eba2b8fcc899a1b91819 upstream.
Fix the calculation of load_value and match_value. Currently they
are slightly too low, which produces a noticeably wrong PWM rate with
sufficiently short periods (i.e. when 1/period approaches clk_rate/2).
Example:
clk_rate=32768Hz, period=122070ns, duty_cycle=61035ns (8192Hz/50% PWM)
Correct values: load = 0xfffffffc, match = 0xfffffffd
Current values: load = 0xfffffffa, match = 0xfffffffc
effective PWM: period=183105ns, duty_cycle=91553ns (5461Hz/50% PWM)
Fixes: 6604c6556db9 ("pwm: Add PWM driver for OMAP using dual-mode timers")
Signed-off-by: David Rivshin <drivshin@allworx.com>
Acked-by: Neil Armstrong <narmstrong@baylibre.com>
Tested-by: Adam Ford <aford173@gmail.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/pwm/pwm-omap-dmtimer.c | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
--- a/drivers/pwm/pwm-omap-dmtimer.c
+++ b/drivers/pwm/pwm-omap-dmtimer.c
@@ -31,6 +31,7 @@
#include <linux/time.h>
#define DM_TIMER_LOAD_MIN 0xfffffffe
+#define DM_TIMER_MAX 0xffffffff
struct pwm_omap_dmtimer_chip {
struct pwm_chip chip;
@@ -46,13 +47,13 @@ to_pwm_omap_dmtimer_chip(struct pwm_chip
return container_of(chip, struct pwm_omap_dmtimer_chip, chip);
}
-static int pwm_omap_dmtimer_calc_value(unsigned long clk_rate, int ns)
+static u32 pwm_omap_dmtimer_get_clock_cycles(unsigned long clk_rate, int ns)
{
u64 c = (u64)clk_rate * ns;
do_div(c, NSEC_PER_SEC);
- return DM_TIMER_LOAD_MIN - c;
+ return c;
}
static void pwm_omap_dmtimer_start(struct pwm_omap_dmtimer_chip *omap)
@@ -99,7 +100,8 @@ static int pwm_omap_dmtimer_config(struc
int duty_ns, int period_ns)
{
struct pwm_omap_dmtimer_chip *omap = to_pwm_omap_dmtimer_chip(chip);
- int load_value, match_value;
+ u32 period_cycles, duty_cycles;
+ u32 load_value, match_value;
struct clk *fclk;
unsigned long clk_rate;
bool timer_active;
@@ -133,11 +135,22 @@ static int pwm_omap_dmtimer_config(struc
/*
* Calculate the appropriate load and match values based on the
* specified period and duty cycle. The load value determines the
- * cycle time and the match value determines the duty cycle.
+ * period time and the match value determines the duty time.
+ *
+ * The period lasts for (DM_TIMER_MAX-load_value+1) clock cycles.
+ * Similarly, the active time lasts (match_value-load_value+1) cycles.
+ * The non-active time is the remainder: (DM_TIMER_MAX-match_value)
+ * clock cycles.
+ *
+ * References:
+ * OMAP4430/60/70 TRM sections 22.2.4.10 and 22.2.4.11
+ * AM335x Sitara TRM sections 20.1.3.5 and 20.1.3.6
*/
- load_value = pwm_omap_dmtimer_calc_value(clk_rate, period_ns);
- match_value = pwm_omap_dmtimer_calc_value(clk_rate,
- period_ns - duty_ns);
+ period_cycles = pwm_omap_dmtimer_get_clock_cycles(clk_rate, period_ns);
+ duty_cycles = pwm_omap_dmtimer_get_clock_cycles(clk_rate, duty_ns);
+
+ load_value = (DM_TIMER_MAX - period_cycles) + 1;
+ match_value = load_value + duty_cycles - 1;
/*
* We MUST stop the associated dual-mode timer before attempting to
next prev parent reply other threads:[~2016-05-09 7:38 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-09 7:20 [PATCH 4.5 00/88] 4.5.4-stable review Greg Kroah-Hartman
2016-05-09 7:20 ` [PATCH 4.5 01/88] clocksource/drivers/tango-xtal: Fix boot hang due to incorrect test Greg Kroah-Hartman
2016-05-09 7:20 ` [PATCH 4.5 02/88] RDMA/iw_cxgb4: Fix bar2 virt addr calculation for T4 chips Greg Kroah-Hartman
2016-05-09 7:20 ` [PATCH 4.5 03/88] net/mlx5_core: Fix caching ATOMIC endian mode capability Greg Kroah-Hartman
2016-05-09 7:20 ` [PATCH 4.5 04/88] ipvs: handle ip_vs_fill_iph_skb_off failure Greg Kroah-Hartman
2016-05-09 7:20 ` [PATCH 4.5 05/88] ipvs: correct initial offset of Call-ID header search in SIP persistence engine Greg Kroah-Hartman
2016-05-09 7:20 ` [PATCH 4.5 06/88] ipvs: drop first packet to redirect conntrack Greg Kroah-Hartman
2016-05-09 7:20 ` [PATCH 4.5 07/88] rtlwifi: Fix size of wireless mode variable Greg Kroah-Hartman
2016-05-09 7:20 ` [PATCH 4.5 08/88] mfd: intel-lpss: Remove clock tree on error path Greg Kroah-Hartman
2016-05-09 7:20 ` [PATCH 4.5 09/88] nbd: ratelimit error msgs after socket close Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 11/88] null_blk: add lightnvm null_blk device to the nullb_list Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 12/88] ata: ahci_xgene: dereferencing uninitialized pointer in probe Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 13/88] wlcore: fix error handling in wlcore_event_fw_logger Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 14/88] ath10k: fix pktlog in QCA99X0 Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 15/88] mwifiex: fix corner case association failure Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 17/88] clk-divider: make sure read-only dividers do not write to their register Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 18/88] soc: rockchip: power-domain: fix err handle while probing Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 19/88] clk: rockchip: fix wrong mmc phase shift for rk3228 Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 20/88] clk: rockchip: free memory in error cases when registering clock branches Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 22/88] clk: qcom: msm8960: fix ce3_core clk enable register Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 23/88] clk: versatile: sp810: support reentrance Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 24/88] clk: qcom: msm8960: Fix ce3_src register offset Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 25/88] clk: sunxi: Fix sun8i-a23-apb0-clk divider flags Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 26/88] clk: xgene: Add missing parenthesis when clearing divider value Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 27/88] clk: bcm2835: fix check of error code returned by devm_ioremap_resource() Greg Kroah-Hartman
2016-05-09 7:21 ` Greg Kroah-Hartman [this message]
2016-05-09 7:21 ` [PATCH 4.5 29/88] pwm: omap-dmtimer: Add sanity checking for load and match values Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 30/88] pwm: omap-dmtimer: Round load and match values rather than truncate Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 31/88] lpfc: fix misleading indentation Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 33/88] ath9k: ar5008_hw_cmn_spur_mitigate: add missing mask_m & mask_p initialisation Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 34/88] mac80211: fix statistics leak if dev_alloc_name() fails Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 35/88] tracing: Dont display trigger file for events that cant be enabled Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 36/88] MD: make bio mergeable Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 37/88] Minimal fix-up of bad hashing behavior of hash_64() Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 38/88] mm: memcontrol: let v2 cgroups follow changes in system swappiness Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 39/88] mm, cma: prevent nr_isolated_* counters from going negative Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 40/88] mm/zswap: provide unique zpool name Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 41/88] propogate_mnt: Handle the first propogated copy being a slave Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 42/88] modpost: fix module autoloading for OF devices with generic compatible property Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 43/88] ARM: EXYNOS: Properly skip unitialized parent clock in power domain on Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 44/88] ARM: SoCFPGA: Fix secondary CPU startup in thumb2 kernel Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 45/88] xen: Fix page <-> pfn conversion on 32 bit systems Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 46/88] xen/balloon: Fix crash when ballooning on x86 32 bit PAE Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 47/88] xen/evtchn: fix ring resize when binding new events Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 48/88] HID: wacom: Add support for DTK-1651 Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 49/88] HID: Fix boot delay for Creative SB Omni Surround 5.1 with quirk Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 50/88] Input: zforce_ts - fix dual touch recognition Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 51/88] proc: prevent accessing /proc/<PID>/environ until its ready Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 52/88] mm: update min_free_kbytes from khugepaged after core initialization Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 53/88] batman-adv: fix DAT candidate selection (must use vid) Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 54/88] batman-adv: Check skb size before using encapsulated ETH+VLAN header Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 56/88] batman-adv: Reduce refcnt of removed router when updating route Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 57/88] libnvdimm, pfn: fix memmap reservation sizing Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 58/88] writeback: Fix performance regression in wb_over_bg_thresh() Greg Kroah-Hartman
[not found] ` <20160509071952.129092535-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
2016-05-09 7:21 ` [PATCH 4.5 59/88] MAINTAINERS: Remove asterisk from EFI directory names Greg Kroah-Hartman
2016-05-09 7:21 ` Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 60/88] x86/tsc: Read all ratio bits from MSR_PLATFORM_INFO Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 61/88] ARM: cpuidle: Pass on arm_cpuidle_suspend()s return value Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 62/88] parisc: fix a bug when syscall number of tracee is __NR_Linux_syscalls Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 63/88] cpufreq: st: enable selective initialization based on the platform Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 64/88] ARC: Add missing io barriers to io{read,write}{16,32}be() Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 65/88] x86/sysfb_efi: Fix valid BAR address range check Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 66/88] ARM: dts: apq8064: add ahci ports-implemented mask Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 67/88] ACPICA: Dispatcher: Update thread ID for recursive method calls Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 68/88] powerpc: Fix bad inline asm constraint in create_zero_mask() Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 69/88] libahci: save port map for forced port map Greg Kroah-Hartman
2016-05-09 7:21 ` [PATCH 4.5 70/88] ata: ahci-platform: Add ports-implemented DT bindings Greg Kroah-Hartman
2016-05-09 7:22 ` [PATCH 4.5 71/88] USB: serial: cp210x: add ID for Link ECU Greg Kroah-Hartman
2016-05-09 7:22 ` [PATCH 4.5 72/88] USB: serial: cp210x: add Straizona Focusers device ids Greg Kroah-Hartman
2016-05-09 7:22 ` [PATCH 4.5 73/88] Revert "USB / PM: Allow USB devices to remain runtime-suspended when sleeping" Greg Kroah-Hartman
2016-05-09 7:22 ` [PATCH 4.5 74/88] nvmem: mxs-ocotp: fix buffer overflow in read Greg Kroah-Hartman
2016-05-09 7:22 ` [PATCH 4.5 75/88] Drivers: hv: vmbus: Fix signaling logic in hv_need_to_signal_on_read() Greg Kroah-Hartman
2016-05-09 7:22 ` [PATCH 4.5 76/88] gpu: ipu-v3: Fix imx-ipuv3-crtc module autoloading Greg Kroah-Hartman
2016-05-09 7:22 ` [PATCH 4.5 77/88] drm/amdgpu: make sure vertical front porch is at least 1 Greg Kroah-Hartman
2016-05-09 7:22 ` [PATCH 4.5 79/88] iio: ak8975: Fix NULL pointer exception on early interrupt Greg Kroah-Hartman
2016-05-09 7:22 ` [PATCH 4.5 81/88] drm/radeon: make sure vertical front porch is at least 1 Greg Kroah-Hartman
2016-05-09 7:22 ` [PATCH 4.5 88/88] ACPI / processor: Request native thermal interrupt handling via _OSC Greg Kroah-Hartman
[not found] ` <5730411d.47afc20a.a55a6.ffffa291@mx.google.com>
2016-05-09 8:06 ` [PATCH 4.5 00/88] 4.5.4-stable review Greg Kroah-Hartman
2016-05-11 8:45 ` Kevin Hilman
2016-05-09 13:08 ` Guenter Roeck
2016-05-10 7:03 ` Greg Kroah-Hartman
2016-05-09 19:41 ` Shuah Khan
2016-05-10 7:03 ` Greg Kroah-Hartman
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=20160509071953.518093413@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=aford173@gmail.com \
--cc=drivshin@allworx.com \
--cc=linux-kernel@vger.kernel.org \
--cc=narmstrong@baylibre.com \
--cc=stable@vger.kernel.org \
--cc=thierry.reding@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.