From patchwork Tue Jan 23 06:28:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 190737 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp152213dyi; Mon, 22 Jan 2024 22:32:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmcgv9yuXP0yA5cxX2IXy78d6hF/MLhgqrMnA+OaJvjGn7hzYak4mSGQHxtHt9ugI1k8mU X-Received: by 2002:a17:906:a50:b0:a29:f195:c53f with SMTP id x16-20020a1709060a5000b00a29f195c53fmr3357735ejf.64.1705991541052; Mon, 22 Jan 2024 22:32:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705991541; cv=pass; d=google.com; s=arc-20160816; b=SzGK6oyY8NgTrQmybYlMn4NBvnENjEgpIHrt0YIF4PMLomjR/n2xCrCkzpA3fqjFLR cnp57vvhZd0T/Xv4/lDXm+lG1HEc9Q9PWO5kay1CFKFXWWvnoLXGlZy/FbBpySObHOCv 2+Hwo+j2Fucd258932Dk9TqKq/VRa1Bi0rvLlmG0WpvQhWUxa8lvej4uvOoww3xLZkMg io/wVMzbe+WeMRa9xXjapD2cJfOChNkX2QAkMihyt6GYJyLNcfHfKkYHVXY8ga6A6z7G D7Mpej+xbPdY1P7at1oo7gisdcnbX9HUHxND8vFe4LwpkXslmey54Kh/js10A/rSB/c3 Js3g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=26CNdTVVJq8o8BZk7L6XwH8jugTBS1HprBk1fTIUDoo=; fh=y5fk6vguAkbcel7KoRWpitGO8B8BpGYTQpzSdaI/dY4=; b=0YH4HrdjlXmY3DQyMlwTrZQNVRXdpuwOxmJX/keE+Mj/OfGilmZvijb8MbEYGS2tHg c0YWBrUXy5jdW8aU5W1i5EmoD8XW/kYe9z2PEiJxklqkGRr8gu0mxLU/qgmyMYtc7RYP TbEKRlNVb6L8tVZgxz1wqT3x3Y87szRkUBkeAaJlRxTzuH8L1LO0tgIZCI3wuCGkQPsZ /EbDKqZpVin5I8QqC06xmiILaLVzzvFARf3hPTYB0bYSN+p/9pfD0sRGgbyiq8YWWPKE 07FKGWgyqqwGDgN1tPXSP3wc93tPyVd7S7ZakUKfOjjdlmlg0NVvkSTUS9tya4MdmJU7 T+pw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FujWr9yN; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-34782-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34782-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n16-20020a170906689000b00a30a8927889si641404ejr.227.2024.01.22.22.32.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 22:32:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34782-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FujWr9yN; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-34782-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34782-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 808CB1F2296E for ; Tue, 23 Jan 2024 06:32:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC877524C9; Tue, 23 Jan 2024 06:29:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FujWr9yN" Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D555050267; Tue, 23 Jan 2024 06:29:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705991360; cv=none; b=Y1Dx2UTibGZ091Vkm33KEhs9cmECfAk/2Gf8kj4awAoQo5fk1ETzoyzvYdhA42vi5Zt48PhT12oDhKkj5xfuarZsAGED9ccLpdtRXUmXa6qslS3XgPAsbMBrz9C0g1EgWSwbsWKQTus2DiA/S+m9xonb+F9vVazyxoUOOQJgg60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705991360; c=relaxed/simple; bh=O9XSXUN5T0BD61EErTNuzKNUavdcT7DU8Ryr3nR7FUQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FSj8O6MB888NAF9T7r1ymrilHN90TBf+hTccDJlgJ9dWg6Q400kEG+oRKE/o0mfPynGCjaFI0lYROrTeKUUEuj0zuEDxEWGw+kYNUgmI2KfMq8Sw8hVfR5FMf/fJYGkw4wLIH+uoElqpY8tcHVvdE5ljOT2zMemIvZVr8ErboNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FujWr9yN; arc=none smtp.client-ip=209.85.210.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-6dc8b280155so1519743a34.0; Mon, 22 Jan 2024 22:29:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705991358; x=1706596158; 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=26CNdTVVJq8o8BZk7L6XwH8jugTBS1HprBk1fTIUDoo=; b=FujWr9yNffiTGG3wFF0k0512YAEEHv4vLseYqEJVBLU3JPHdqbbQ9aVib+slund990 0/Y+VNNBetPaP71xV+2W1PFkhnkGhXScqozQQvY5i/7kg4uQMtWWb+X+UwxNIVps8x3q PStWut5yh/PKXc1VsmYUpoJYcvxk90ZWkftu0l3pVnmctmQuwAREQZ97Jm3FqfdbzfnL 2uw15jncG1DpL9cNfvsSFL046RT64lK99YvpnO8G2V/wNH1UhtHOYFr5j67xmNjApoI7 P4QnPPTal0mkwR0ezhkUJiF6ejn1x9C2bL4xufISuYHJM3uiszKRlZTvHv5peehUaVGG /WZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705991358; x=1706596158; 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=26CNdTVVJq8o8BZk7L6XwH8jugTBS1HprBk1fTIUDoo=; b=I5+In0RaNOFqY0ZnSsTWRLpOnL1QOSZ2IkyOMRkf91jZGeiPGIEk6gVIlwCjlk+pFs KJppygdu6qevaX3qdBaFSSJRGzb3R9DtLLwttqWQobuLqwbTcqp+M6TG1lmzPH/ARCG0 4vy2wP5XpIQ/AzliclMXKWBvgt/Pve1kRlLeI2nG9mQPksn/Rjzd+GPMXEZEjV70sIkV iyHg/Qml2A02PtX/ud67PYPUeQnrzLr3KPP4LiTcxGVzsQc8Sq0jDVTSWdpJuhe1soXC VmanCV/F5aVaN6OIzsPlWm2LakZj4pPqCAA5JxVxZSQboX2Hnv0A8x6fI5h+pkN2c6jH ic3g== X-Gm-Message-State: AOJu0YzqdhTEcq8ug3l04qvQSZRUPcvBv6RDPz5BiBrHc6rZA1E7eBJb HeG+GERcWgChPXoQFarn45zlTl621/Ls+4aa2okhjr4aJwykQ3D0 X-Received: by 2002:a05:6808:bc8:b0:3bd:bb13:4d1e with SMTP id o8-20020a0568080bc800b003bdbb134d1emr2341075oik.101.1705991357921; Mon, 22 Jan 2024 22:29:17 -0800 (PST) Received: from localhost.localdomain (2001-b400-e2ac-a4c6-7d2b-d8b3-ed27-1f50.emome-ip6.hinet.net. [2001:b400:e2ac:a4c6:7d2b:d8b3:ed27:1f50]) by smtp.gmail.com with ESMTPSA id l10-20020a056a00140a00b006d9b2694b0csm10595188pfu.200.2024.01.22.22.29.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 22:29:17 -0800 (PST) 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 V14 12/21] mmc: sdhci-uhs2: add set_power() to support vdd2 Date: Tue, 23 Jan 2024 14:28:18 +0800 Message-Id: <20240123062827.8525-13-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240123062827.8525-1-victorshihgli@gmail.com> References: <20240123062827.8525-1-victorshihgli@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788861785993279725 X-GMAIL-MSGID: 1788861785993279725 From: Victor Shih This is a UHS-II version of sdhci's set_power operation. Use sdhci_uhs2_set_power() to set VDD2 for support UHS2 interface. VDD2, as well as VDD, is handled here. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih --- Updates in V13: - Drop use vmmc2. - Modify comment message. Updates in V10: - Move some definitions of PatchV9[05/23] to PatchV10[11/23]. Updates in V9: - Modify annotations in sdhci_get_vdd_value(). Updates in V8: - Adjust the position of matching brackets. - Add the initial value of the pwr in sdhci_uhs2_set_power(). Updates in V7: - Add clear the power reg before setting a new value in sdhci_uhs2_set_power(). - Add MMC_VDD_34_35 case and MMC_VDD_35_36 case in sdhci_get_vdd_value(). - Drop pwr variable in sdhci_get_vdd_value(). Updates in V6: - Add mmc_opt_regulator_set_ocr(). - Remove unnecessary functions. --- drivers/mmc/host/sdhci-uhs2.c | 48 +++++++++++++++++++++++++++ drivers/mmc/host/sdhci.c | 61 +++++++++++++++++++---------------- drivers/mmc/host/sdhci.h | 1 + 3 files changed, 82 insertions(+), 28 deletions(-) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 3d16f1ef9344..4fe106e2ba8c 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -59,6 +59,13 @@ EXPORT_SYMBOL_GPL(sdhci_uhs2_dump_regs); * * \*****************************************************************************/ +static inline int mmc_opt_regulator_set_ocr(struct mmc_host *mmc, + struct regulator *supply, + unsigned short vdd_bit) +{ + return IS_ERR_OR_NULL(supply) ? 0 : mmc_regulator_set_ocr(mmc, supply, vdd_bit); +} + /** * sdhci_uhs2_reset - invoke SW reset * @host: SDHCI host @@ -86,6 +93,47 @@ void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask) } EXPORT_SYMBOL_GPL(sdhci_uhs2_reset); +static void sdhci_uhs2_set_power(struct sdhci_host *host, unsigned char mode, unsigned short vdd) +{ + struct mmc_host *mmc = host->mmc; + u8 pwr = 0; + + if (mode != MMC_POWER_OFF) { + pwr = sdhci_get_vdd_value(vdd); + if (!pwr) + WARN(1, "%s: Invalid vdd %#x\n", + mmc_hostname(host->mmc), vdd); + pwr |= SDHCI_VDD2_POWER_180; + } + + if (host->pwr == pwr) + return; + host->pwr = pwr; + + if (pwr == 0) { + sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); + + mmc_opt_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); + mmc_regulator_set_vqmmc2(mmc, &mmc->ios); + } else { + mmc_opt_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd); + /* support 1.8v only for now */ + mmc_regulator_set_vqmmc2(mmc, &mmc->ios); + + /* Clear the power reg before setting a new value */ + sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); + + /* vdd first */ + pwr |= SDHCI_POWER_ON; + sdhci_writeb(host, pwr & 0xf, SDHCI_POWER_CONTROL); + mdelay(5); + + pwr |= SDHCI_VDD2_POWER_ON; + sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); + mdelay(5); + } +} + /*****************************************************************************\ * * * Driver init/exit * diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 27ea5b875c29..4d50cac7717d 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -23,7 +23,7 @@ #include #include #include - +#include #include #include @@ -2061,41 +2061,46 @@ static void sdhci_set_power_reg(struct sdhci_host *host, unsigned char mode, sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); } +unsigned short sdhci_get_vdd_value(unsigned short vdd) +{ + switch (1 << vdd) { + case MMC_VDD_165_195: + /* + * Without a regulator, SDHCI does not support 2.0v + * so we only get here if the driver deliberately + * added the 2.0v range to ocr_avail. Map it to 1.8v + * for the purpose of turning on the power. + */ + case MMC_VDD_20_21: + return SDHCI_POWER_180; + case MMC_VDD_29_30: + case MMC_VDD_30_31: + return SDHCI_POWER_300; + case MMC_VDD_32_33: + case MMC_VDD_33_34: + /* + * 3.4V ~ 3.6V are valid only for those platforms where it's + * known that the voltage range is supported by hardware. + */ + case MMC_VDD_34_35: + case MMC_VDD_35_36: + return SDHCI_POWER_330; + default: + return 0; + } +} +EXPORT_SYMBOL_GPL(sdhci_get_vdd_value); + void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode, unsigned short vdd) { u8 pwr = 0; if (mode != MMC_POWER_OFF) { - switch (1 << vdd) { - case MMC_VDD_165_195: - /* - * Without a regulator, SDHCI does not support 2.0v - * so we only get here if the driver deliberately - * added the 2.0v range to ocr_avail. Map it to 1.8v - * for the purpose of turning on the power. - */ - case MMC_VDD_20_21: - pwr = SDHCI_POWER_180; - break; - case MMC_VDD_29_30: - case MMC_VDD_30_31: - pwr = SDHCI_POWER_300; - break; - case MMC_VDD_32_33: - case MMC_VDD_33_34: - /* - * 3.4 ~ 3.6V are valid only for those platforms where it's - * known that the voltage range is supported by hardware. - */ - case MMC_VDD_34_35: - case MMC_VDD_35_36: - pwr = SDHCI_POWER_330; - break; - default: + pwr = sdhci_get_vdd_value(vdd); + if (!pwr) { WARN(1, "%s: Invalid vdd %#x\n", mmc_hostname(host->mmc), vdd); - break; } } diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index 782c399fae15..cdb418d97c4d 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -837,6 +837,7 @@ void sdhci_set_power(struct sdhci_host *host, unsigned char mode, void sdhci_set_power_and_bus_voltage(struct sdhci_host *host, unsigned char mode, unsigned short vdd); +unsigned short sdhci_get_vdd_value(unsigned short vdd); void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode, unsigned short vdd); int sdhci_get_cd_nogpio(struct mmc_host *mmc);