From patchwork Thu Feb 15 20:52:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 773007 Delivered-To: patch@linaro.org Received: by 2002:adf:9dc2:0:b0:33b:4db1:f5b3 with SMTP id q2csp1035064wre; Thu, 15 Feb 2024 12:54:09 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWOgeSCQL0sqkfrE3kzwEUGJLBxSedHk6uhqxi1syjg8mXN9TUlP+lDuoF9W7jS3JfucCYToL4lYFJly8mwnPXy X-Google-Smtp-Source: AGHT+IH3Joyve8pJZs1r9Ua3/LVQRK8IhjWO3tN04gevMTolmKLmxXTl1oTU6PfKHF7hLwdy5lLW X-Received: by 2002:a17:906:817:b0:a3c:1db3:46c2 with SMTP id e23-20020a170906081700b00a3c1db346c2mr1857769ejd.65.1708030449571; Thu, 15 Feb 2024 12:54:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708030449; cv=none; d=google.com; s=arc-20160816; b=dl0oA70DxYT5YYFty/vs6Q1VwMrfrWVufexkWuRWV/7mREjuESVYItkwTXRxWomG5B 1H6I4iIrPbRGjg98SWUsBDZ21Ol9llG0gvj9QJ9cL0g3ckMWmw+O9qoga6dwTLRpjveF EQ/LkPZ9cIwxEXbw3h2tqeKpdQX2E2cLr5JiwfZ6zehREzkZ27JH6TN9lw7wRe8ebLQH RWMueLQP/d6RB67RAI41/j3SDSoHLbOGM4N1xM0ZpAUnos42f2gMx4Prxat42T0Gt5gB dbV7muEZfwgliz1pzuVY6XnrGbvtUPEybUmf+StJFc2xWwS0kGRTM5rZAxw6MMAA6XKs Gc9A== 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:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=SsqdANfMWbuVxdecVrYWNUH1yqMAfaRWXbnEFhSzf0Q=; fh=y+jssU8WxEOX6xpoUntStDoe7Govi+Ud0+CLpc7yv/A=; b=D64+JlgK+0Vs15E8t1NzYZirzLJKvUy6aS/6fVEEPkw2/oZpdeBLJM6dlYG94CFnVZ ldRH+w+OYQtXtupgCpJk0TlEhWlR3U4b2FtsTo6hCfr9V7wwJ3FmK+hVhIQbdLr0/0fl gAA/heICN5yk+m1ueRWFBGFtwd2wLTO0ZW71jkYPxkHk7hLTrunY8MK7L/94+xuHbOqg Vc+bOIFjMC+WJ2JDjxp/yZ2ooMvi7+WvhL2gZBJIXaUsF9U0+xqLMSZeBf+VMt/f5qxU Xfwe3b4FRDl6lYcZPu5LUMOV/0rSqJZM0MeCXxrfD8kvRRfGgu8wh3JMbg5pQZYOPrzf hz+g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="r/DRE+C8"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id fi29-20020a170906da1d00b00a3d70fc1f7esi970253ejb.85.2024.02.15.12.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 12:54:09 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="r/DRE+C8"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0272787F2A; Thu, 15 Feb 2024 21:53:02 +0100 (CET) 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="r/DRE+C8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D49C087F25; Thu, 15 Feb 2024 21:53:01 +0100 (CET) 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, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) (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 2722087E56 for ; Thu, 15 Feb 2024 21:52:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=caleb.connolly@linaro.org Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-41232741dc4so57905e9.3 for ; Thu, 15 Feb 2024 12:52:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708030348; x=1708635148; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=SsqdANfMWbuVxdecVrYWNUH1yqMAfaRWXbnEFhSzf0Q=; b=r/DRE+C87WKXEfrBovfzbUU/y1les4ghcNfsK3Vn8JuwFJKtupeCAUm0b8+Fe5wTeG oEPH+oUAFQKw7hRSgPmCRrg1VvH5Dl4vviOJmieo39CtKQ0KBBMSz5asRXxqz+kHjowl un1AM+6G0HT042rvb44/mLv60hO1O6XeK6xGiPjB3LJCHC1ChrLcffJ9hRJVtNTFnQTI VtCXOAlWe8/ii5sLygfM2KQNSO6fyBCy0LPOvPTyKBYHzawG7TOYRJLbONGpgjJLi5Fs es1NY0yxmxBqYI7RIiIvK1u5w9vG6fqWLNW+ltZQK1bezG5UvQzI3IaoD6F5SNgSWMI4 tAPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708030348; x=1708635148; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SsqdANfMWbuVxdecVrYWNUH1yqMAfaRWXbnEFhSzf0Q=; b=bOcXpNIWeICDLccSZN/U+GBHA3MEhkziDJ7iz0tCO8wLtqbCkKg6P4oIbn9FXLwf+b MFKZZxY9OBDbRCoPDX3zNODIrafpTjZ8DP3lUoHHuwvjXIb0rGFhYK5PxdeHeUAoZHZk 4tzVct0r2FXb1GE5aqXCKyCaMDmEYjes2YeMTEcbQKTsbpbnBepuu5Ynl7stQUlqFARf S4iXW9nC/nQCP0UmIHz99FDQmpvRq//cz5duRZ+AZcEVTqmctjVLTeh2gXxouuoTQhHY tFcV4m2c+HVz1fWo/iPCfJzurKha0u77+ZMxu6s4J6YsxIttkPeccVpniJW4I9cWGSaz RCTQ== X-Forwarded-Encrypted: i=1; AJvYcCXJtEz2hnv9FOrujcTV+y+SlGjObTGF/HUoRAkHW1r0QBWqc78hwZIAdJiYHQmW674licPMC0ObiZ2VFBVw50I0jOnrYQ== X-Gm-Message-State: AOJu0YzNi0q8wFaQmCESt3n53arKpK+xSFbFunecE62QgML46C1leAr2 b8LgRbYyZQzpP9HSRV0Q6BhGZkGHR8Tq1X5z8AEw+wl/9vAPhZzzQgaZXoky9R1s0XdIJRjix6P P X-Received: by 2002:adf:f488:0:b0:33d:7f4:8ce4 with SMTP id l8-20020adff488000000b0033d07f48ce4mr1496336wro.59.1708030348243; Thu, 15 Feb 2024 12:52:28 -0800 (PST) Received: from lion.localdomain (host-92-17-96-232.as13285.net. [92.17.96.232]) by smtp.gmail.com with ESMTPSA id e4-20020adfe384000000b0033cfa00e497sm194025wrm.64.2024.02.15.12.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 12:52:27 -0800 (PST) From: Caleb Connolly Date: Thu, 15 Feb 2024 20:52:21 +0000 Subject: [PATCH v4 03/39] mmc: msm_sdhci: use modern clock handling MIME-Version: 1.0 Message-Id: <20240215-b4-qcom-common-target-v4-3-ed06355c634a@linaro.org> References: <20240215-b4-qcom-common-target-v4-0-ed06355c634a@linaro.org> In-Reply-To: <20240215-b4-qcom-common-target-v4-0-ed06355c634a@linaro.org> To: Neil Armstrong , Sumit Garg , Ramon Fried , Dzmitry Sankouski , Caleb Connolly , Peng Fan , Jaehoon Chung , Rayagonda Kokatanur , Lukasz Majewski , Sean Anderson , Jorge Ramirez-Ortiz , Stephan Gerhold Cc: Marek Vasut , u-boot@lists.denx.de X-Mailer: b4 0.13-dev-4bd13 X-Developer-Signature: v=1; a=openpgp-sha256; l=3190; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=e9xdgw2JqebGrluwSTHSO2hp+eVKBlJB6+PnmFCeF5E=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhtRzlS2Sj4z3v8nMZDHcf3yjU9j32olP5kqd5FjKxuZjf bGrMOlVRykLgyAHg6yYIov4iWWWTWsv22tsX3ABZg4rE8gQBi5OAZjIJXuG/4lLGBLcbyi4T22Z pDbhawzPsdiiwgbr6bGWxcKi37ZsdWZk6Hte2CqncS9jXfsMJYeoM7tP/disEFmmxxOw5tJJPeU tVwA= X-Developer-Key: i=caleb.connolly@linaro.org; a=openpgp; fpr=83B24DA7FE145076BC38BB250CD904EB673A7C47 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 Use the clk_* helper functions and the correct property name for clocks. Reviewed-by: Neil Armstrong Signed-off-by: Caleb Connolly Reviewed-by: Sumit Garg --- drivers/mmc/msm_sdhci.c | 69 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/drivers/mmc/msm_sdhci.c b/drivers/mmc/msm_sdhci.c index fe1e754bfde0..b63538fce20c 100644 --- a/drivers/mmc/msm_sdhci.c +++ b/drivers/mmc/msm_sdhci.c @@ -44,6 +44,7 @@ struct msm_sdhc_plat { struct msm_sdhc { struct sdhci_host host; void *base; + struct clk_bulk clks; }; struct msm_sdhc_variant_info { @@ -54,35 +55,57 @@ DECLARE_GLOBAL_DATA_PTR; static int msm_sdc_clk_init(struct udevice *dev) { - int node = dev_of_offset(dev); - uint clk_rate = fdtdec_get_uint(gd->fdt_blob, node, "clock-frequency", - 400000); - uint clkd[2]; /* clk_id and clk_no */ - int clk_offset; - struct udevice *clk_dev; - struct clk clk; - int ret; + struct msm_sdhc *prv = dev_get_priv(dev); + ofnode node = dev_ofnode(dev); + uint clk_rate; + int ret, i = 0, n_clks; + const char *clk_name; - ret = fdtdec_get_int_array(gd->fdt_blob, node, "clock", clkd, 2); + ret = ofnode_read_u32(node, "clock-frequency", &clk_rate); if (ret) - return ret; + clk_rate = 400000; - clk_offset = fdt_node_offset_by_phandle(gd->fdt_blob, clkd[0]); - if (clk_offset < 0) - return clk_offset; - - ret = uclass_get_device_by_of_offset(UCLASS_CLK, clk_offset, &clk_dev); - if (ret) + ret = clk_get_bulk(dev, &prv->clks); + if (ret) { + log_warning("Couldn't get mmc clocks: %d\n", ret); return ret; + } - clk.id = clkd[1]; - ret = clk_request(clk_dev, &clk); - if (ret < 0) + ret = clk_enable_bulk(&prv->clks); + if (ret) { + log_warning("Couldn't enable mmc clocks: %d\n", ret); return ret; + } - ret = clk_set_rate(&clk, clk_rate); - if (ret < 0) - return ret; + /* If clock-names is unspecified, then the first clock is the core clock */ + if (!ofnode_get_property(node, "clock-names", &n_clks)) { + if (!clk_set_rate(&prv->clks.clks[0], clk_rate)) { + log_warning("Couldn't set core clock rate: %d\n", ret); + return -EINVAL; + } + } + + /* Find the index of the "core" clock */ + while (i < n_clks) { + ofnode_read_string_index(node, "clock-names", i, &clk_name); + if (!strcmp(clk_name, "core")) + break; + i++; + } + + if (i >= prv->clks.count) { + log_warning("Couldn't find core clock (index %d but only have %d clocks)\n", i, + prv->clks.count); + return -EINVAL; + } + + /* The clock is already enabled by the clk_bulk above */ + ret = clk_set_rate(&prv->clks.clks[i], clk_rate); + /* If we get a rate of 0 then something has probably gone wrong. */ + if (ret == 0) { + log_warning("Couldn't set core clock rate to %u! Driver returned rate of 0\n", clk_rate); + return -EINVAL; + } return 0; } @@ -187,6 +210,8 @@ static int msm_sdc_remove(struct udevice *dev) if (!var_info->mci_removed) writel(0, priv->base + SDCC_MCI_HC_MODE); + clk_release_bulk(&priv->clks); + return 0; }