Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp978072iob; Fri, 13 May 2022 18:21:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOBuowMmP+rvN8yR5jLziJSxe6ELsnP0gIRD1/msuPDuO0uAPZBvIak83Yd0OcG/TBstNr X-Received: by 2002:a5d:6488:0:b0:203:b628:70d2 with SMTP id o8-20020a5d6488000000b00203b62870d2mr6014753wri.83.1652491316036; Fri, 13 May 2022 18:21:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652491316; cv=none; d=google.com; s=arc-20160816; b=H3qyZLCAAbJjv1J1Qy7sb28l/hfbaJcbbnnoMJalCyTPf6q6kVJGCXHbdLTZab0TWN cf99EmLjkHktOwGmaAtMql6Lqh/EPVWOH9KQpRE3yYwurmfkAjG/+i8JOwJisEmNSXYy O4MRUPd1UkL3FAupOM3UBhWpMmjqUZqdSkDvPExNqRvJlWYZozVHMtX+Z+yJ9X6Gg5Fi NK45t/9gG10h3lajDxyiOWlVKdFthc4putarW0EysUAfXOJ0EUUHRbbCS4/HBrQ6ywrE +tPTcdsNQIXphI4o+Q1+NnDqSOyOY7BgF8XoEIiovGWg6qKvVU4npI+aHbW/zsoPn4uc AA8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mdwl/3qncGxvSHEmA5NweSXMbdpIo4aGSyCfwpXQg7U=; b=rOY+Vid4y4az/gRDbu+njRkcseLxGiN1+DzwCsSAD1C2Iu8FMebcxOjpn1ThFdOtNR SVbMvP9y5qc+5zJmfbwvw53xtGSjT85I12sQ3NTs5tK2vURCRWqhavmEf2O6yhwGWaig hTc2HJG89BxOmyjNRP0o13eWrMs9/SxKPh+W+M/IpWqV2OAcmJLB42awQIY+CqlzP+hP zxmcMqmM3PMxmOXSr9+Xocb3AElmAzPEmRm3teUCuvYnBhLQa/cQVOVKm+EWefImjt3R SNLbsjlRbWbkMPt6H1GhnNoMBpJwoXlkqQCXZU41J1RDrL5VI9/uUofZ6geKrrRyT78W MZ4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QqMy8jOZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x11-20020a7bc20b000000b00393ef46f579si3962917wmi.125.2022.05.13.18.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:21:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QqMy8jOZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CE44B3CC5B9; Fri, 13 May 2022 16:51:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378464AbiEMOY6 (ORCPT + 99 others); Fri, 13 May 2022 10:24:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377289AbiEMOYm (ORCPT ); Fri, 13 May 2022 10:24:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C61B75EBD1; Fri, 13 May 2022 07:24:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4C2D66215A; Fri, 13 May 2022 14:24:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55273C34100; Fri, 13 May 2022 14:24:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652451878; bh=WrtSnC9ElmgIEbQerXZBPCxouw+fQ4cO0pntLGU/bfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QqMy8jOZqY+ho8LNRsXTVylrTIcysg62G28vnu5g1Ycx8B14V+uJJqxAQmAkD0jHO MXyw9JPABkW77q/P2v7zNJE2JMmZqZWuMERKcsw7JO+xTN30k2bzZ5j7HQtVqsfX89 78u7dcDUe5VPRRQczO7DqMuDEko0YGmV6LM+Fiqs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ricky Wu , Ulf Hansson , Christian Loehle Subject: [PATCH 4.9 6/7] mmc: rtsx: add 74 Clocks in power on flow Date: Fri, 13 May 2022 16:23:21 +0200 Message-Id: <20220513142226.100940342@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513142225.909697091@linuxfoundation.org> References: <20220513142225.909697091@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ricky WU commit 1f311c94aabdb419c28e3147bcc8ab89269f1a7e upstream. SD spec definition: "Host provides at least 74 Clocks before issuing first command" After 1ms for the voltage stable then start issuing the Clock signals if POWER STATE is MMC_POWER_OFF to MMC_POWER_UP to issue Clock signal to card MMC_POWER_UP to MMC_POWER_ON to stop issuing signal to card Signed-off-by: Ricky Wu Link: https://lore.kernel.org/r/1badf10aba764191a1a752edcbf90389@realtek.com Signed-off-by: Ulf Hansson Signed-off-by: Ricky Wu Signed-off-by: Ulf Hansson Signed-off-by: Christian Loehle Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/host/rtsx_pci_sdmmc.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) --- a/drivers/mmc/host/rtsx_pci_sdmmc.c +++ b/drivers/mmc/host/rtsx_pci_sdmmc.c @@ -49,10 +49,7 @@ struct realtek_pci_sdmmc { bool double_clk; bool eject; bool initial_mode; - int power_state; -#define SDMMC_POWER_ON 1 -#define SDMMC_POWER_OFF 0 - + int prev_power_state; int sg_count; s32 cookie; int cookie_sg_count; @@ -914,14 +911,21 @@ static int sd_set_bus_width(struct realt return err; } -static int sd_power_on(struct realtek_pci_sdmmc *host) +static int sd_power_on(struct realtek_pci_sdmmc *host, unsigned char power_mode) { struct rtsx_pcr *pcr = host->pcr; int err; - if (host->power_state == SDMMC_POWER_ON) + if (host->prev_power_state == MMC_POWER_ON) return 0; + if (host->prev_power_state == MMC_POWER_UP) { + rtsx_pci_write_register(pcr, SD_BUS_STAT, SD_CLK_TOGGLE_EN, 0); + goto finish; + } + + msleep(100); + rtsx_pci_init_cmd(pcr); rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_SELECT, 0x07, SD_MOD_SEL); rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_SHARE_MODE, @@ -940,11 +944,17 @@ static int sd_power_on(struct realtek_pc if (err < 0) return err; + mdelay(1); + err = rtsx_pci_write_register(pcr, CARD_OE, SD_OUTPUT_EN, SD_OUTPUT_EN); if (err < 0) return err; - host->power_state = SDMMC_POWER_ON; + /* send at least 74 clocks */ + rtsx_pci_write_register(pcr, SD_BUS_STAT, SD_CLK_TOGGLE_EN, SD_CLK_TOGGLE_EN); + +finish: + host->prev_power_state = power_mode; return 0; } @@ -953,7 +963,7 @@ static int sd_power_off(struct realtek_p struct rtsx_pcr *pcr = host->pcr; int err; - host->power_state = SDMMC_POWER_OFF; + host->prev_power_state = MMC_POWER_OFF; rtsx_pci_init_cmd(pcr); @@ -979,7 +989,7 @@ static int sd_set_power_mode(struct real if (power_mode == MMC_POWER_OFF) err = sd_power_off(host); else - err = sd_power_on(host); + err = sd_power_on(host, power_mode); return err; } @@ -1417,7 +1427,7 @@ static int rtsx_pci_sdmmc_drv_probe(stru host->mmc = mmc; host->pdev = pdev; host->cookie = -1; - host->power_state = SDMMC_POWER_OFF; + host->prev_power_state = MMC_POWER_OFF; INIT_WORK(&host->work, sd_request); platform_set_drvdata(pdev, host); pcr->slots[RTSX_SD_CARD].p_dev = pdev;