From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BB2E450903; Tue, 16 Jun 2026 15:59:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781625541; cv=none; b=GeEopPRZ7rEcZpD0kqA0cEzahuV08fA2FKPGDrQEK7GEc+V44jjUtfAv+bnF4u59acuojcRXPURilLGAo5hR/vIvepBtSo5pYAhXTzD1GiNoPfN34rG3isCpyXO6dAKyaoMwTclOKbOkJ53si13UxIBJxvrssNr72mgNR6X3FMQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781625541; c=relaxed/simple; bh=bxq3pRJZO41WKXCYnhffBBE/AFl/wcJ/AVK6NG09f6Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WG52rDeQd5qqCUYNOwnenyi3LdXVl9xyqxrnTiFXUfu8hn/jZjnU7H6Vn2l2xNELIr7xyf7xVYbqMmslq2aw7am0k9G4qFiIayD9fkf8fMc40oVRneBb/coI7GttPQ/kR834jVqouLS8KTAaP7x9peLn2LzDZsjvb0HvO834iDE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=UvDqJ82g; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="UvDqJ82g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75AA91F00A3E; Tue, 16 Jun 2026 15:58:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781625540; bh=Qp03/BLK5O2mVhqD5lx4zdPrDl+ZEIMH11UjhkZBAvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UvDqJ82gULypMZsg5hXyKJ4aJpnSIX4+ibp2ep8ZaQhf3M4LIMNQlJbjJ+/eXKNvF hALLYc8jKbc35+8ORIoVGynRwkc7hl5AeKTO99Uc/ckvqFQKg3JG5X5S9nIT1Qm5P+ mqhLqaU642PwnTAPg3hq62nqYmCIxKVltpwkkgjI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Inochi Amaoto , Gabriel Somlo , Ulf Hansson Subject: [PATCH 6.18 163/325] mmc: litex_mmc: Use DIV_ROUND_UP for more accurate clock calculation Date: Tue, 16 Jun 2026 20:29:19 +0530 Message-ID: <20260616145105.902436958@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145057.827196531@linuxfoundation.org> References: <20260616145057.827196531@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Inochi Amaoto commit b837e38c255dd9f8b53511d52e87f1fda32b3dfe upstream. The previous clock uses roundup_pow_of_two() to calculate the core clock frequency. It does not meet the actual hardware meaning. The actual frequency is calculated by "ref_clk / ((div >> 1) << 1)". Fix the clock divider calculation. Fixes: 92e099104729 ("mmc: Add driver for LiteX's LiteSDCard interface") Signed-off-by: Inochi Amaoto Reviewed-by: Gabriel Somlo Cc: stable@vger.kernel.org Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/host/litex_mmc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/mmc/host/litex_mmc.c +++ b/drivers/mmc/host/litex_mmc.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -436,11 +437,10 @@ static void litex_mmc_setclk(struct lite struct device *dev = mmc_dev(host->mmc); u32 div; - div = freq ? host->ref_clk / freq : 256U; - div = roundup_pow_of_two(div); + div = freq ? DIV_ROUND_UP(host->ref_clk, freq) : 256U; div = clamp(div, 2U, 256U); dev_dbg(dev, "sd_clk_freq=%d: set to %d via div=%d\n", - freq, host->ref_clk / div, div); + freq, host->ref_clk / ((div + 1) & ~1U), div); litex_write16(host->sdphy + LITEX_PHY_CLOCKERDIV, div); host->sd_clk = freq; }