linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Douglas Anderson <dianders@chromium.org>,
	Sean Paul <seanpaul@chromium.org>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.4 056/102] drm/rockchip: Round up _before_ giving to the clock framework
Date: Fri, 24 Jan 2020 10:30:57 +0100	[thread overview]
Message-ID: <20200124092814.815114198@linuxfoundation.org> (raw)
In-Reply-To: <20200124092806.004582306@linuxfoundation.org>

From: Douglas Anderson <dianders@chromium.org>

[ Upstream commit 287422a95fe28e05c1952de0472e0dfdffa6caae ]

I'm embarassed to say that even though I've touched
vop_crtc_mode_fixup() twice and I swear I tested it, there's still a
stupid glaring bug in it.  Specifically, on veyron_minnie (with all
the latest display timings) we want to be setting our pixel clock to
66,666,666.67 Hz and we tell userspace that's what we set, but we're
actually choosing 66,000,000 Hz.  This is confirmed by looking at the
clock tree.

The problem is that in drm_display_mode_from_videomode() we convert
from Hz to kHz with:

  dmode->clock = vm->pixelclock / 1000;

...and drm_display_mode_from_videomode() is called from panel-simple
when we have an "override_mode" like we do on veyron_minnie.  See
commit 123643e5c40a ("ARM: dts: rockchip: Specify
rk3288-veyron-minnie's display timings").

...so when the device tree specifies a clock of 66666667 for the panel
then DRM translates that to 66666000.  The clock framework will always
pick a clock that is _lower_ than the one requested, so it will refuse
to pick 66666667 and we'll end up at 66000000.

While we could try to fix drm_display_mode_from_videomode() to round
to the nearest kHz and it would fix our problem, it wouldn't help if
the clock we actually needed was 60,000,001 Hz.  We could
alternatively have DRM always round up, but maybe this would break
someone else who already baked in the assumption that DRM rounds down.
Specifically note that clock drivers are not consistent about whether
they round up or round down when you call clk_set_rate().  We know how
Rockchip's clock driver works, but (for instance) you can see that on
most Qualcomm clocks the default is clk_rcg2_ops which rounds up.

Let's solve this by just adding 999 Hz before calling
clk_round_rate().  This should be safe and work everywhere.  As
discussed in more detail in comments in the commit, Rockchip's PLLs
are configured in a way that there shouldn't be another PLL setting
that is only a few kHz off so we won't get mixed up.

NOTE: if this is picked to stable, it's probably easiest to first pick
commit 527e4ca3b6d1 ("drm/rockchip: Base adjustments of the mode based
on prev adjustments") which shouldn't hurt in stable.

Fixes: b59b8de31497 ("drm/rockchip: return a true clock rate to adjusted_mode")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20191003114726.v2.1.Ib233b3e706cf6317858384264d5b0ed35657456e@changeid
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 37 +++++++++++++++++++--
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index 613404f86668d..84e3decb17b1f 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -1040,10 +1040,41 @@ static bool vop_crtc_mode_fixup(struct drm_crtc *crtc,
 				struct drm_display_mode *adjusted_mode)
 {
 	struct vop *vop = to_vop(crtc);
+	unsigned long rate;
 
-	adjusted_mode->clock =
-		DIV_ROUND_UP(clk_round_rate(vop->dclk,
-					    adjusted_mode->clock * 1000), 1000);
+	/*
+	 * Clock craziness.
+	 *
+	 * Key points:
+	 *
+	 * - DRM works in in kHz.
+	 * - Clock framework works in Hz.
+	 * - Rockchip's clock driver picks the clock rate that is the
+	 *   same _OR LOWER_ than the one requested.
+	 *
+	 * Action plan:
+	 *
+	 * 1. When DRM gives us a mode, we should add 999 Hz to it.  That way
+	 *    if the clock we need is 60000001 Hz (~60 MHz) and DRM tells us to
+	 *    make 60000 kHz then the clock framework will actually give us
+	 *    the right clock.
+	 *
+	 *    NOTE: if the PLL (maybe through a divider) could actually make
+	 *    a clock rate 999 Hz higher instead of the one we want then this
+	 *    could be a problem.  Unfortunately there's not much we can do
+	 *    since it's baked into DRM to use kHz.  It shouldn't matter in
+	 *    practice since Rockchip PLLs are controlled by tables and
+	 *    even if there is a divider in the middle I wouldn't expect PLL
+	 *    rates in the table that are just a few kHz different.
+	 *
+	 * 2. Get the clock framework to round the rate for us to tell us
+	 *    what it will actually make.
+	 *
+	 * 3. Store the rounded up rate so that we don't need to worry about
+	 *    this in the actual clk_set_rate().
+	 */
+	rate = clk_round_rate(vop->dclk, adjusted_mode->clock * 1000 + 999);
+	adjusted_mode->clock = DIV_ROUND_UP(rate, 1000);
 
 	return true;
 }
-- 
2.20.1




  parent reply	other threads:[~2020-01-24  9:40 UTC|newest]

Thread overview: 113+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-24  9:30 [PATCH 5.4 000/102] 5.4.15-stable review Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 001/102] drm/i915: Fix pid leak with banned clients Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 002/102] libbpf: Fix compatibility for kernels without need_wakeup Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 003/102] libbpf: Fix memory leak/double free issue Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 004/102] libbpf: Fix potential overflow issue Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 005/102] libbpf: Fix another potential overflow issue in bpf_prog_linfo Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 006/102] libbpf: Make btf__resolve_size logic always check size error condition Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 007/102] libbpf: Fix call relocation offset calculation bug Greg Kroah-Hartman
2020-01-24 13:43   ` Naresh Kamboju
2020-01-24 15:18     ` Sasha Levin
2020-01-24  9:30 ` [PATCH 5.4 008/102] bpf: Force .BTF section start to zero when dumping from vmlinux Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 009/102] samples: bpf: update map definition to new syntax BTF-defined map Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 010/102] samples/bpf: Fix broken xdp_rxq_info due to map order assumptions Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 011/102] ARM: dts: logicpd-torpedo-37xx-devkit-28: Reference new DRM panel Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 012/102] ARM: OMAP2+: Add missing put_device() call in omapdss_init_of() Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 013/102] xfs: Sanity check flags of Q_XQUOTARM call Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 014/102] i2c: stm32f7: rework slave_id allocation Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 015/102] i2c: i2c-stm32f7: fix 10-bits check in slave free id search loop Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 016/102] mfd: intel-lpss: Add default I2C device properties for Gemini Lake Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 017/102] SUNRPC: Fix svcauth_gss_proxy_init() Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 018/102] SUNRPC: Fix backchannel latency metrics Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 019/102] powerpc/security: Fix debugfs data leak on 32-bit Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 020/102] powerpc/pseries: Enable support for ibm,drc-info property Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 021/102] powerpc/kasan: Fix boot failure with RELOCATABLE && FSL_BOOKE Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 022/102] powerpc/archrandom: fix arch_get_random_seed_int() Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 023/102] tipc: reduce sensitive to retransmit failures Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 024/102] tipc: update mons self addr when node addr generated Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 025/102] tipc: fix potential memory leak in __tipc_sendmsg() Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 026/102] tipc: fix wrong socket reference counter after tipc_sk_timeout() returns Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 027/102] tipc: fix wrong timeout input for tipc_wait_for_cond() Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 028/102] net/mlx5e: Fix free peer_flow when refcount is 0 Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 029/102] phy: lantiq: vrx200-pcie: fix error return code in ltq_vrx200_pcie_phy_power_on() Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 030/102] net: phy: broadcom: Fix RGMII delays configuration for BCM54210E Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 031/102] phy: ti: gmii-sel: fix mac tx internal delay for rgmii-rxid Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 032/102] mt76: mt76u: fix endpoint definition order Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 033/102] mt7601u: fix bbp version check in mt7601u_wait_bbp_ready Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 034/102] ice: fix stack leakage Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 035/102] s390/pkey: fix memory leak within _copy_apqns_from_user() Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 036/102] nfsd: depend on CRYPTO_MD5 for legacy client tracking Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 037/102] crypto: amcc - restore CRYPTO_AES dependency Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 038/102] crypto: sun4i-ss - fix big endian issues Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 039/102] perf map: No need to adjust the long name of modules Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 040/102] leds: tlc591xx: update the maximum brightness Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 041/102] soc/tegra: pmc: Fix crashes for hierarchical interrupts Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 042/102] soc: qcom: llcc: Name regmaps to avoid collisions Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 043/102] soc: renesas: Add missing check for non-zero product register address Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 044/102] soc: aspeed: Fix snoop_file_poll()s return type Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 045/102] watchdog: sprd: Fix the incorrect pointer getting from driver data Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 046/102] ipmi: Fix memory leak in __ipmi_bmc_register Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 047/102] sched/core: Further clarify sched_class::set_next_task() Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 048/102] gpiolib: No need to call gpiochip_remove_pin_ranges() twice Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 049/102] rtw88: fix beaconing mode rsvd_page memory violation issue Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 050/102] rtw88: fix error handling when setup efuse info Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 051/102] drm/panfrost: Add missing check for pfdev->regulator Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 052/102] drm: panel-lvds: Potential Oops in probe error handling Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 053/102] drm/amdgpu: remove excess function parameter description Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 054/102] hwrng: omap3-rom - Fix missing clock by probing with device tree Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 055/102] dpaa2-eth: Fix minor bug in ethtool stats reporting Greg Kroah-Hartman
2020-01-24  9:30 ` Greg Kroah-Hartman [this message]
2020-01-24  9:30 ` [PATCH 5.4 057/102] software node: Get reference to parent swnode in get_parent op Greg Kroah-Hartman
2020-01-24  9:30 ` [PATCH 5.4 058/102] PCI: mobiveil: Fix csr_read()/write() build issue Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 059/102] drm: rcar_lvds: Fix color mismatches on R-Car H2 ES2.0 and later Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 060/102] net: netsec: Correct dma sync for XDP_TX frames Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 061/102] ACPI: platform: Unregister stale platform devices Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 062/102] pwm: sun4i: Fix incorrect calculation of duty_cycle/period Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 063/102] regulator: bd70528: Add MODULE_ALIAS to allow module auto loading Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 064/102] drm/amdgpu/vi: silence an uninitialized variable warning Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 065/102] power: supply: bd70528: Add MODULE_ALIAS to allow module auto loading Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 066/102] firmware: imx: Remove call to devm_of_platform_populate Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 067/102] libbpf: Dont use kernel-side u32 type in xsk.c Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 068/102] rcu: Fix uninitialized variable in nocb_gp_wait() Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 069/102] dpaa_eth: perform DMA unmapping before read Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 070/102] dpaa_eth: avoid timestamp read on error paths Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 071/102] scsi: ufs: delete redundant function ufshcd_def_desc_sizes() Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 072/102] net: openvswitch: dont unlock mutex when changing the user_features fails Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 073/102] hv_netvsc: flag software created hash value Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 074/102] rt2800: remove errornous duplicate condition Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 075/102] net: neigh: use long type to store jiffies delta Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 076/102] net: axienet: Fix error return code in axienet_probe() Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 077/102] selftests: gen_kselftest_tar.sh: Do not clobber kselftest/ Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 078/102] rtc: bd70528: fix module alias to autoload module Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 079/102] packet: fix data-race in fanout_flow_is_huge() Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 080/102] i2c: stm32f7: report dma error during probe Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 081/102] kselftests: cgroup: Avoid the reuse of fd after it is deallocated Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 082/102] firmware: arm_scmi: Fix doorbell ring logic for !CONFIG_64BIT Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 083/102] mmc: sdio: fix wl1251 vendor id Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 084/102] mmc: core: fix wl1251 sdio quirks Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 085/102] tee: optee: Fix dynamic shm pool allocations Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 086/102] tee: optee: fix device enumeration error handling Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 087/102] workqueue: Add RCU annotation for pwq list walk Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 088/102] SUNRPC: Fix another issue with MIC buffer space Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 089/102] sched/cpufreq: Move the cfs_rq_util_change() call to cpufreq_update_util() Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 090/102] mt76: mt76u: rely on usb_interface instead of usb_dev Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 091/102] dma-direct: dont check swiotlb=force in dma_direct_map_resource Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 092/102] afs: Remove set but not used variables before, after Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 093/102] dmaengine: ti: edma: fix missed failure handling Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 094/102] drm/radeon: fix bad DMA from INTERRUPT_CNTL2 Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 095/102] xdp: Fix cleanup on map free for devmap_hash map type Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 096/102] platform/chrome: wilco_ec: fix use after free issue Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 097/102] block: fix memleak of bio integrity data Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 098/102] s390/qeth: fix dangling IO buffers after halt/clear Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 099/102] net-sysfs: Call dev_hold always in netdev_queue_add_kobject Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 100/102] gpio: aspeed: avoid return type warning Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 101/102] phy/rockchip: inno-hdmi: round clock rate down to closest 1000 Hz Greg Kroah-Hartman
2020-01-24  9:31 ` [PATCH 5.4 102/102] optee: Fix multi page dynamic shm pool alloc Greg Kroah-Hartman
2020-01-24 13:47 ` [PATCH 5.4 000/102] 5.4.15-stable review Naresh Kamboju
2020-01-24 14:52 ` Jon Hunter
2020-01-24 21:46 ` shuah
2020-01-25 13:51   ` Greg Kroah-Hartman
2020-01-24 23:56 ` Guenter Roeck
2020-01-25 13:52   ` Greg Kroah-Hartman
2020-01-25 10:22 ` Naresh Kamboju
2020-01-25 13:52   ` 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=20200124092814.815114198@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=dianders@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sashal@kernel.org \
    --cc=seanpaul@chromium.org \
    --cc=stable@vger.kernel.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).