From: Daniel Schwierzeck Date: Wed, 18 Sep 2019 22:50:43 +0200 Subject: [U-Boot] [PATCH v2 22/28] mmc: mtk-sd: add a dts property cd-active-high for builtin-cd mode In-Reply-To: <1568772962-18697-23-git-send-email-weijie.gao@mediatek.com> References: <1568772962-18697-1-git-send-email-weijie.gao@mediatek.com> <1568772962-18697-23-git-send-email-weijie.gao@mediatek.com> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Am 18.09.19 um 04:15 schrieb Weijie Gao: > This patch adds a dts property cd-active-high for builtin-cd mode to make > it configurable instead of using hardcoded active-low. > > Signed-off-by: Weijie Gao > --- > drivers/mmc/mtk-sd.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/mmc/mtk-sd.c b/drivers/mmc/mtk-sd.c > index 7069fe8948..814a1b5fe9 100644 > --- a/drivers/mmc/mtk-sd.c > +++ b/drivers/mmc/mtk-sd.c > @@ -270,6 +270,7 @@ struct msdc_host { > > /* whether to use gpio detection or built-in hw detection */ > bool builtin_cd; > + bool cd_active_high; > > /* card detection / write protection GPIOs */ > #if CONFIG_IS_ENABLED(DM_GPIO) > @@ -852,7 +853,12 @@ static int msdc_ops_get_cd(struct udevice *dev) > > if (host->builtin_cd) { > val = readl(&host->base->msdc_ps); > - return !(val & MSDC_PS_CDSTS); > + val &= MSDC_PS_CDSTS; > + > + if (!host->cd_active_high) > + val = !val; > + > + return val; you could shorten this to return !(val & MSDC_PS_CDSTS) ^ host->cd_active_high; > } > > #if CONFIG_IS_ENABLED(DM_GPIO) > @@ -1355,6 +1361,7 @@ static int msdc_ofdata_to_platdata(struct udevice *dev) > host->latch_ck = dev_read_u32_default(dev, "latch-ck", 0); > host->r_smpl = dev_read_u32_default(dev, "r_smpl", 0); > host->builtin_cd = dev_read_u32_default(dev, "builtin-cd", 0); > + host->cd_active_high = dev_read_bool(dev, "cd-active-high"); > > return 0; > } > -- - Daniel