From: Michal Simek Date: Mon, 3 Jun 2019 09:32:19 +0200 Subject: [U-Boot] [PATCH] mmc: implement SDHCI card detect In-Reply-To: References: <1558619699-1104-1-git-send-email-ibai.erkiaga-elorza@xilinx.com> <15d9c03a-51c7-64aa-8f19-5914a08d372f@xilinx.com> Message-ID: <392a3f82-7d4a-1745-e79a-3ebac57be1f1@xilinx.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 31. 05. 19 15:27, Ibai Erkiaga Elorza wrote: > Hi Michal, > >> -----Original Message----- >> From: Michal Simek >> Sent: 27 May 2019 06:53 >> To: Ibai Erkiaga Elorza ; u-boot at lists.denx.de >> Subject: Re: [U-Boot] [PATCH] mmc: implement SDHCI card detect >> >> On 23. 05. 19 15:54, Ibai Erkiaga wrote: >>> Card detect function implemented for SDHCI framework. >>> >>> Signed-off-by: Ibai Erkiaga >>> --- >>> >>> drivers/mmc/sdhci.c | 17 +++++++++++++++++ >>> 1 file changed, 17 insertions(+) >>> >>> diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c index >>> e2bb90a..cb4db8d 100644 >>> --- a/drivers/mmc/sdhci.c >>> +++ b/drivers/mmc/sdhci.c >>> @@ -390,6 +390,21 @@ static int sdhci_send_command(struct mmc *mmc, >> struct mmc_cmd *cmd, >>> return -ECOMM; >>> } >>> >>> +#if IS_ENABLED(CONFIG_DM_MMC) >>> +static int sdhci_get_cd(struct udevice *dev) { >>> + struct mmc *mmc = mmc_get_mmc_dev(dev); #else static int >>> +sdhci_get_cd(struct mmc *mmc) { #endif >>> + u32 state; >>> + struct sdhci_host *host = mmc->priv; >>> + >>> + state = sdhci_readl(host, SDHCI_PRESENT_STATE); >>> + return (state & SDHCI_CARD_PRESENT); >> >> This should be much more robust. It should at least handle cases where you >> have broken-cd, cd-gpios, cd-inverted cases. >> This code will likely work with boards which have CD connected properly but >> it is enabled for all which will cause a lot of issues. >> > You are right, this implementation is quite basic and the idea was just to get rid-off the polling message for the golden use case (properly connected CD). > >> If you want to add this functionality one by one then new Kconfig should be >> used but I am not big fan of that. >> > The broken-cd Kconfig is already in the MMC framework so I would say that you can use this implementation if your CD is properly connected and just stay as current implementation using CONFIG_MMC_BROKEN_CD. I expect that there are several pieces around but it needs to be done properly or this will break a lot of boards. M