From patchwork Thu Jul 25 20:45:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 814398 Delivered-To: patch@linaro.org Received: by 2002:adf:e641:0:b0:367:895a:4699 with SMTP id b1csp567175wrn; Thu, 25 Jul 2024 13:49:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWxaY73bW3RmYp+P9mZPXURSDTfzRZ5rVEi1QMWoGHYlU0I0mTpI70btUFxMdqpKlsyagFVUUtMSza++jfA5njk X-Google-Smtp-Source: AGHT+IHnlu9aYd4sl9ultMd6Jr0e0YNkR8RXt2qhyHtoF+MMZcpon6Tk/UKyCAjLnwSgKEFJoJ2r X-Received: by 2002:a2e:9382:0:b0:2ee:88d8:e807 with SMTP id 38308e7fff4ca-2f03db7e0d0mr20515971fa.16.1721940550451; Thu, 25 Jul 2024 13:49:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721940550; cv=none; d=google.com; s=arc-20160816; b=o8vgEqnlPP1+c4Kh7m48D2NexOcZiotiEIwrLcQJBvNhgSIqhvevCwTLkl+FdzRq/h z16v9OStY/+nnMeHf86uDsMTrjsdYQDxq19L/b0YbzRP/V5IiABHu+YwcpJMFyXRqnSB yTvnoOBNUQUxEMPgtXJDvwlXA2rBQk5ZL8ZbY+a+7+b54SBxnb6Q5Po3HO9rKTgj9ZLz XhkeFQyETYRJ2DGqkkBMND7EA89RFnmsIhhDIFh47XzDcAbU3pHXFYQkv6LEcdrirKV/ agIm1wh8vjOfTJ2gYsjXCw0JCpas5pDltAP+jdcGCsFETSF6RR2ph8BgdPok5JDpkOzT qh8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SDSW/FQ0raQJfa8ItZTqmxPmyzRYX/IJa/0gNS33P20=; fh=tc1uCTLO6ybx4bfyl8cYnfORLl545EtLy7MIbirwSSc=; b=TjqjosVkcrPmc39Fl4k3olQlhQo8hKle+nM/KvlJ5HC79VMOOAFKk0A5JogVUeGMzw fZHnDUCKh3TWirr9E8jQptsJCxOAoOpKbya6asH6f6v5bzeucOJ4fIZcK3KUVZTq8gDp cfuv4pMBYvDQCxHcAJaepyerVYJrk016d//cvfPRhhpHpBAgSK/DEbbQt7ARDeYokF7r 0QBsIhTL9BwxY9b+/0jEKt1fvqn0m0hv2En0Jg4mp0QnP6i5xKYjSiRvhyZpeAD1ziz2 PzMz5bQYcToRsQAUddYMxpopGaCqMRHB3RmvuGo0Yfsjg22lJ+1U7aLrK3W2OHobYXy1 Q+AA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="lhzV/thR"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 38308e7fff4ca-2f03d187f5bsi6047291fa.584.2024.07.25.13.49.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 13:49:10 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="lhzV/thR"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2DA0988732; Thu, 25 Jul 2024 22:45:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="lhzV/thR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 58E7F882EF; Thu, 25 Jul 2024 22:45:41 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7B379885C5 for ; Thu, 25 Jul 2024 22:45:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=semen.protsenko@linaro.org Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-5d5c2ac3410so72574eaf.2 for ; Thu, 25 Jul 2024 13:45:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721940336; x=1722545136; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SDSW/FQ0raQJfa8ItZTqmxPmyzRYX/IJa/0gNS33P20=; b=lhzV/thRiNik8TzS7YfKKzr+soLxq0+Jj7HJMyUR7MYyJxPnME+BHFXMGrVvgT8AJY ATHpI5bU3IfmmM0c4oGVcSOn2YjBQV9rzVEcqFDnbwDNCTZkdSqM0PH/kMbO+vQQEMQD Q84CX7R3O4pr/gGlq/35g7wjPp1dFWjXe4RXwP9DqTCBp3rNIRLAd7yGapE1v78VuDEE /fJo09n4IXgJl6Hbx4VfyUPlVXeK44Jgf+by+JvRI7+odG+3KMcQhKJ3YaWO6Svis2mg sr5VdiYz3rHlEUFVoC7RQ7ZnEte+xzkIuiWm59YITHZObcNW8r+Xp9bQ27x27qm/fCER Z1xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721940336; x=1722545136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SDSW/FQ0raQJfa8ItZTqmxPmyzRYX/IJa/0gNS33P20=; b=V3Of63rrhLUs1MdIhpC3uH31ysGvbuPPxadt9+pjKEIj5NQaFXG2Li8B1CSZLoJtfd uxfxpcYtHbsLa7V4TLrqzYS1Do3yRWAQSZTArxkrgbGT7hc56PLfDkg1pKEh+MNsLacU CYmB0erdx4/XbzwLWSZOKWy7Ky/AU0ntKUeqWh9T8RUFkf4Ni0Ak2HfWR/UWsgdHIZ7H YYmuR6zBs6HmfEQuLBUEwqnVQzF7p2HDhd7SOHB2KP4YwsmiX7FDPREmQdHAKX1Jj9fj VePifniPlYuU2pUz2YdWtdymM8+dLIfsfngfsaqwrpM6b8R3oLNICgv2XYLLbfiqCJFs 7Khw== X-Forwarded-Encrypted: i=1; AJvYcCWkPF0ezu9pHw5o52zSRk78NcoRmqnXWefYEvK5tslvz2xpsTRDyH9VoLLo4s4wRmQV83PehUR9jIVdI+o/vmVOfRIH/g== X-Gm-Message-State: AOJu0YypAqpPJZoziOnP0+DM6VZqkdQChhtn1QuW8o+8vzupR6QMerpz +/5oPbOqKrKK9UmVZr4rR3d/UOiCX5VO2S8npX07jFqedukbKwD6AD788zZl6N8= X-Received: by 2002:a4a:ee17:0:b0:5d5:b226:2ffa with SMTP id 006d021491bc7-5d5b42f7cf8mr4252972eaf.7.1721940336205; Thu, 25 Jul 2024 13:45:36 -0700 (PDT) Received: from localhost ([136.62.192.75]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5d5b346d58csm266472eaf.6.2024.07.25.13.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 13:45:35 -0700 (PDT) From: Sam Protsenko To: Jaehoon Chung Cc: Minkyu Kang , Minkyu Kang , Tom Rini , Peng Fan , Simon Glass , Quentin Schulz , Philipp Tomsich , Kever Yang , Eugeniy Paltsev , Peter Robinson , Jonas Karlman , Yang Xiwen , Ferass El Hafidi , Sean Anderson , u-boot@lists.denx.de, uboot-snps-arc@synopsys.com Subject: [PATCH v4 20/38] mmc: exynos_dw_mmc: Obtain and use CIU clock via CCF API Date: Thu, 25 Jul 2024 15:45:02 -0500 Message-Id: <20240725204520.18134-21-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240725204520.18134-1-semen.protsenko@linaro.org> References: <20240725204520.18134-1-semen.protsenko@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean New Exynos chips should implement clock drivers using CCF framework. In that case corresponding CCF functions can be used to get/set the clock rates. Moreover, already existing get_mmc_clk() and set_mmc_clk() calls are only implemented for CONFIG_CPU_V7A (i.e. ARM32 chips). In case of ARM64 chips that config option is not defined, so build will crash on linking stage, with errors like these: ld: drivers/mmc/exynos_dw_mmc.o: in function `exynos_dwmci_get_sclk': undefined reference to `get_mmc_clk' ld: drivers/mmc/exynos_dw_mmc.o: in function `exynos_dwmci_set_sclk': undefined reference to `set_mmc_clk' Fix that issue by using CCF clocks API on ARM64 platforms for getting and setting the source clock (sclk = SDCLKIN = CIU) rate. To implement this, first extract the existing ARM32 clock control code into helper functions with more generic signatures to abstract getting/setting the sclk rate. Then add CCF clock support to those functions for ARM64 platforms. Fixes: a082a2dde061 ("EXYNOS5: DWMMC: Added FDT support for DWMMC") Signed-off-by: Sam Protsenko --- Changes in v4: - (none) Changes in v3: - (none) Changes in v2: - Replaced CONFIG_IS_ENABLED() with #ifdef drivers/mmc/exynos_dw_mmc.c | 87 +++++++++++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 8 deletions(-) diff --git a/drivers/mmc/exynos_dw_mmc.c b/drivers/mmc/exynos_dw_mmc.c index ed2752391603..4d28ede0d756 100644 --- a/drivers/mmc/exynos_dw_mmc.c +++ b/drivers/mmc/exynos_dw_mmc.c @@ -4,6 +4,7 @@ * Jaehoon Chung */ +#include #include #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #include #define DWMMC_MAX_CH_NUM 4 @@ -38,6 +40,7 @@ struct dwmci_exynos_priv_data { #ifdef CONFIG_DM_MMC struct dwmci_host host; #endif + struct clk clk; u32 sdr_timing; }; @@ -51,6 +54,61 @@ static struct dwmci_exynos_priv_data *exynos_dwmmc_get_priv( #endif } +/** + * exynos_dwmmc_get_sclk - Get source clock (SDCLKIN) rate + * @host: MMC controller object + * @rate: Will contain clock rate, Hz + * + * Return: 0 on success or negative value on error + */ +static int exynos_dwmmc_get_sclk(struct dwmci_host *host, unsigned long *rate) +{ +#ifdef CONFIG_CPU_V7A + *rate = get_mmc_clk(host->dev_index); +#else + struct dwmci_exynos_priv_data *priv = exynos_dwmmc_get_priv(host); + + *rate = clk_get_rate(&priv->clk); +#endif + + if (IS_ERR_VALUE(*rate)) + return *rate; + + return 0; +} + +/** + * exynos_dwmmc_set_sclk - Set source clock (SDCLKIN) rate + * @host: MMC controller object + * @rate: Desired clock rate, Hz + * + * Return: 0 on success or negative value on error + */ +static int exynos_dwmmc_set_sclk(struct dwmci_host *host, unsigned long rate) +{ + int err; + +#ifdef CONFIG_CPU_V7A + unsigned long sclk; + unsigned int div; + + err = exynos_dwmmc_get_sclk(host, &sclk); + if (err) + return err; + + div = DIV_ROUND_UP(sclk, rate); + set_mmc_clk(host->dev_index, div); +#else + struct dwmci_exynos_priv_data *priv = exynos_dwmmc_get_priv(host); + + err = clk_set_rate(&priv->clk, rate); + if (err < 0) + return err; +#endif + + return 0; +} + /* * Function used as callback function to initialise the * CLKSEL register for every mmc channel. @@ -68,6 +126,7 @@ unsigned int exynos_dwmci_get_clk(struct dwmci_host *host, uint freq) { unsigned long sclk; int8_t clk_div; + int err; /* * Since SDCLKIN is divided inside controller by the DIVRATIO @@ -77,7 +136,13 @@ unsigned int exynos_dwmci_get_clk(struct dwmci_host *host, uint freq) */ clk_div = ((dwmci_readl(host, DWMCI_CLKSEL) >> DWMCI_DIVRATIO_BIT) & DWMCI_DIVRATIO_MASK) + 1; - sclk = get_mmc_clk(host->dev_index); + + err = exynos_dwmmc_get_sclk(host, &sclk); + if (err) { + printf("DWMMC%d: failed to get clock rate (%d)\n", + host->dev_index, err); + return 0; + } /* * Assume to know divider value. @@ -107,19 +172,19 @@ static void exynos_dwmci_board_init(struct dwmci_host *host) static int exynos_dwmci_core_init(struct dwmci_host *host) { - unsigned int div; - unsigned long freq, sclk; + unsigned long freq; + int err; if (host->bus_hz) freq = host->bus_hz; else freq = DWMMC_MAX_FREQ; - /* request mmc clock vlaue of 52MHz. */ - sclk = get_mmc_clk(host->dev_index); - div = DIV_ROUND_UP(sclk, freq); - /* set the clock divisor for mmc */ - set_mmc_clk(host->dev_index, div); + err = exynos_dwmmc_set_sclk(host, freq); + if (err) { + printf("DWMMC%d: failed to set clock rate on probe (%d); " + "continue anyway\n", host->dev_index, err); + } host->name = "EXYNOS DWMMC"; #ifdef CONFIG_EXYNOS5420 @@ -230,6 +295,12 @@ static int exynos_dwmmc_probe(struct udevice *dev) struct dwmci_host *host = &priv->host; int err; +#ifndef CONFIG_CPU_V7A + err = clk_get_by_index(dev, 1, &priv->clk); /* ciu */ + if (err) + return err; +#endif + err = exynos_dwmci_get_config(dev, gd->fdt_blob, dev_of_offset(dev), host, priv); if (err)