From patchwork Fri Sep 8 09:53:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 13377314 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96FA7EE57EB for ; Fri, 8 Sep 2023 09:55:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242748AbjIHJzp (ORCPT ); Fri, 8 Sep 2023 05:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242689AbjIHJzm (ORCPT ); Fri, 8 Sep 2023 05:55:42 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 924591FC1; Fri, 8 Sep 2023 02:54:55 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-56b2e689828so1405597a12.1; Fri, 08 Sep 2023 02:54:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694166864; x=1694771664; darn=vger.kernel.org; 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=foX0JP3DAWSOOC0u2+6IXCRMxX6qZKC8TnZGDqevErY=; b=JvblvJO2QJUV7r4NQgDUYNSD+47AiN24MARFBeFcvbmtjt6DF2miVIkhhPTB86G2A5 JlwOBQY5m/CTNqKI5B+s5Qyry9nZ+4KoGNEiCchABnSw2AI/4OddEP8ffzUbQ3QCkEHf KaoNsngL7EzAWkbiOrdGCYPF9QfwGAmZkgIXQb/NXrSTv90lIkp2OuOZS51l1EYOe8lL SdLFcyLuQOtYYmqU7B7/qryKTovKKk0mRYcqxlfMLgD/AJhaPgg+yYcnjLxRu/mruRLC fTDFp4l5b7rLN+QDLaFc1GZ3n39kLSiIw04lLZ19CZ9xLXEMwxw+5bQOhObgWH6Ae4U/ rHyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694166864; x=1694771664; 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=foX0JP3DAWSOOC0u2+6IXCRMxX6qZKC8TnZGDqevErY=; b=fjbvRXFQ83+a/6olmj6pHp604Aw4yJSNxTbcBvHODI8k6NuGEaDtVq8l7YsnQwiDPC YQXd9rQQWEFItT8caL1FkE2t6/WxbyVdt2Gg/3MMx9Ffl+M1UL+y3p/fk9pjELBXQY/W rYTXic6McO2MUL2RBoOEgdb/M5Boe4lD2Tb0T/oVQpo6H6FvH7Mlm8UMWYWJ+jd+LP3e AUYIWsPckRkBSELfWBJcHjNBuqPTHfz/TTOShw26ECHUmJDiSQP4GiKYquLKXI5IPsN6 8ZxQJ9yh24muXNFstL2ynMZOtKChiXjRAzT6xc0hsB34OhtLgKhTMrsoL3M7wK4hb4/N q7ww== X-Gm-Message-State: AOJu0Yyb3LdhhpF2rqhr3nMqCPf9jCKGVC6kY2riaboWZ2PUxr3sOh6d Xbz+k2+87O4aJxWxVX5UcVHY6VWiPhA= X-Google-Smtp-Source: AGHT+IG2+kS4vtZmgB9s3/RN3rs15QAraRpLAZKbDv3xIsOai3UHoeLRNmbLMEKzs5ddn1d0CnxwtQ== X-Received: by 2002:a05:6a20:ce83:b0:134:4f86:7990 with SMTP id if3-20020a056a20ce8300b001344f867990mr2141584pzb.3.1694166864095; Fri, 08 Sep 2023 02:54:24 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e3a1-00a4-a20b-46bc-ccec-3e79.emome-ip6.hinet.net. [2001:b400:e3a1:a4:a20b:46bc:ccec:3e79]) by smtp.gmail.com with ESMTPSA id c9-20020a170902d48900b001b892aac5c9sm1172178plg.298.2023.09.08.02.54.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 02:54:23 -0700 (PDT) From: Victor Shih To: ulf.hansson@linaro.org, adrian.hunter@intel.com Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, benchuanggli@gmail.com, HL.Liu@genesyslogic.com.tw, Greg.tu@genesyslogic.com.tw, takahiro.akashi@linaro.org, dlunev@chromium.org, Victor Shih , Ben Chuang , Victor Shih Subject: [PATCH V11 16/23] mmc: sdhci-uhs2: add clock operations Date: Fri, 8 Sep 2023 17:53:23 +0800 Message-Id: <20230908095330.12075-17-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230908095330.12075-1-victorshihgli@gmail.com> References: <20230908095330.12075-1-victorshihgli@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org From: Victor Shih This is a sdhci version of mmc's uhs2_[enable|disable]_clk operations. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- Updates in V8: - Remove unnecessary include file. - read_poll_timeout() to instead of read_poll_timeout_atomic() in sdhci_uhs2_enable_clk(). - Put the comment on the end and put the lines in descending line length in sdhci_uhs2_enable_clk(). - Modify return value in sdhci_uhs2_enable_clk(). Updates in V6: - Remove unnecessary functions. --- drivers/mmc/host/sdhci-uhs2.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 4c2a56629ab3..af1b0c5e48fd 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -329,6 +329,36 @@ static int sdhci_uhs2_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) return 0; } +static int sdhci_uhs2_disable_clk(struct mmc_host *mmc) +{ + struct sdhci_host *host = mmc_priv(mmc); + u16 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); + + clk &= ~SDHCI_CLOCK_CARD_EN; + sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); + + return 0; +} + +static int sdhci_uhs2_enable_clk(struct mmc_host *mmc) +{ + struct sdhci_host *host = mmc_priv(mmc); + u16 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); + int timeout_us = 20000; /* 20ms */ + u32 val; + + clk |= SDHCI_CLOCK_CARD_EN; + sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); + + if (read_poll_timeout(sdhci_readw, val, (val & SDHCI_CLOCK_INT_STABLE), + 10, timeout_us, true, host, SDHCI_CLOCK_CONTROL)) { + pr_err("%s: Internal clock never stabilised.\n", mmc_hostname(host->mmc)); + sdhci_dumpregs(host); + return -EIO; + } + return 0; +} + /*****************************************************************************\ * * * Driver init/exit *