From patchwork Sat Apr 14 22:37:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 898206 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="O/4z6ziv"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40NqKm21wQz9s0b for ; Sun, 15 Apr 2018 08:38:04 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id CBF68C21DEC; Sat, 14 Apr 2018 22:37:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 805D6C21E77; Sat, 14 Apr 2018 22:37:19 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 512CBC21BE5; Sat, 14 Apr 2018 22:37:14 +0000 (UTC) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by lists.denx.de (Postfix) with ESMTPS id ED53CC21E4F for ; Sat, 14 Apr 2018 22:37:13 +0000 (UTC) Received: by mail-wr0-f193.google.com with SMTP id q6so4343192wrd.6 for ; Sat, 14 Apr 2018 15:37:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=UWYR5b/VD9bIGu3IUlY/JCqdAEgsEIGR8mGEjVlNG4c=; b=O/4z6zivjn0pUDlpBQHgnSZkeR0shouB0r33lR4srCipT0ko0JQq94fnH0S0AK7qau 9n+KQHS92FpWgqZzg1a0x5z/2VWMBXw+VSkufTNcESU4KSQjj2dVUFfgA6lRl+IqC162 wZd0gVRjIkMSSelSX2mlrlMe0/mY8rBo4VO0nZfDpE6UkLJ+u74ezgO/+3NOjwbETd3h jp2AJtOwjwHvy+r/NqC6IwdKJcGSPshGnOxH0Qv5M8OKFjWJx1j3Px9id83A+X+ksiFg fchTGjGUQgk/Vat8dVq6+vM7gJaKxUNaGG2f5lGwKts9z7L9XWe7BXuNr1TDNZVWF9vJ edmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=UWYR5b/VD9bIGu3IUlY/JCqdAEgsEIGR8mGEjVlNG4c=; b=SHOAJiL7BCvatOi6gwnONTmz4GXCBcEtmu7Un4xEs0T054pqHEXY+tkn/IQ0TE8Gm9 XPzwcTkBvdbQ6FK/h+UujejvRfTwy+/Dh0IalPNs/B142yZQjticLpSOllV+Fo/057kz 0kGOIYZfFQbzhjfWChfdwccTSIjP4XovnQJW1i5ycoW7WiLgDeN8116FcGdVw7aE7L6d jEHba1mB1JYnlV37RblLomrXFuCIA4Ryp9aoqdbXUd81adNpn/zBVrDyrhi8bLhVMEZU x5c+fjLrHrOezSO83S+bKq2MwVZVvbbCrJtt2apPOln0Oe6fULPIYO68qbqkPuf0cKO4 C0pw== X-Gm-Message-State: ALQs6tC+i9Lp59XAjhSm9QBNiN8qIaJ+xYqyIeem1O7TEDKMYnGiH1OD a8qAdFNditgzopnkKDiYoiPJ6ltn X-Google-Smtp-Source: AIpwx494NMFyM7UKVfQm4/qBYlK9ZNpkkXJbtTLM81Q/OvDNPKNh74UW+csYG36/2RFmn/+yr6o1DQ== X-Received: by 10.28.14.70 with SMTP id 67mr7345023wmo.17.1523745433369; Sat, 14 Apr 2018 15:37:13 -0700 (PDT) Received: from kurokawa.lan (ip-86-49-107-50.net.upcbroadband.cz. [86.49.107.50]) by smtp.gmail.com with ESMTPSA id u196sm4283135wmf.30.2018.04.14.15.37.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 Apr 2018 15:37:12 -0700 (PDT) From: Marek Vasut X-Google-Original-From: Marek Vasut To: u-boot@lists.denx.de Date: Sun, 15 Apr 2018 00:37:11 +0200 Message-Id: <20180414223711.17531-1-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.16.2 Cc: Tom Rini Subject: [U-Boot] [PATCH] mmc: Improve tinification X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Marek Vasut Drop all the extra content from the MMC core, so that tiny MMC support is really tiny, no fancy anything. That means the tiny MMC support does only 1-bit transfers at default speed settings. Moreover, this patch drops duplicate instance of struct mmc mmc_static, which wasted about 360 bytes. Furthermore, since MMC tiny supports only one controller at all times, get rid of mallocating the ext csd backup and replace it with static array. All in all, this patch saves ~4 kiB of bloat from the MMC core, which on platforms with severe limitations can be beneficial. Signed-off-by: Marek Vasut Cc: Jaehoon Chung Cc: Tom Rini --- drivers/mmc/mmc.c | 66 +++++++++++++++++++++++++++++------------------- drivers/mmc/mmc_legacy.c | 23 ++++++++++++++++- 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index f72b80c704..961bd49db0 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -24,29 +24,8 @@ static int mmc_set_signal_voltage(struct mmc *mmc, uint signal_voltage); static int mmc_power_cycle(struct mmc *mmc); +#if !CONFIG_IS_ENABLED(MMC_TINY) static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps); - -#if CONFIG_IS_ENABLED(MMC_TINY) -static struct mmc mmc_static; -struct mmc *find_mmc_device(int dev_num) -{ - return &mmc_static; -} - -void mmc_do_preinit(void) -{ - struct mmc *m = &mmc_static; -#ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT - mmc_set_preinit(m, 1); -#endif - if (m->preinit) - mmc_start_init(m); -} - -struct blk_desc *mmc_get_blk_desc(struct mmc *mmc) -{ - return &mmc->block_dev; -} #endif #if !CONFIG_IS_ENABLED(DM_MMC) @@ -772,7 +751,7 @@ int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value) return ret; } - +#if !CONFIG_IS_ENABLED(MMC_TINY) static int mmc_set_card_speed(struct mmc *mmc, enum bus_mode mode) { int err; @@ -856,6 +835,7 @@ static int mmc_get_capabilities(struct mmc *mmc) return 0; } +#endif static int mmc_set_capacity(struct mmc *mmc, int part_num) { @@ -1155,6 +1135,7 @@ int mmc_getcd(struct mmc *mmc) } #endif +#if !CONFIG_IS_ENABLED(MMC_TINY) static int sd_switch(struct mmc *mmc, int mode, int group, u8 value, u8 *resp) { struct mmc_cmd cmd; @@ -1175,7 +1156,6 @@ static int sd_switch(struct mmc *mmc, int mode, int group, u8 value, u8 *resp) return mmc_send_cmd(mmc, &cmd, &data); } - static int sd_get_capabilities(struct mmc *mmc) { int err; @@ -1362,6 +1342,7 @@ static int sd_select_bus_width(struct mmc *mmc, int w) return 0; } +#endif #if CONFIG_IS_ENABLED(MMC_WRITE) static int sd_read_ssr(struct mmc *mmc) @@ -1583,6 +1564,7 @@ static inline int mmc_set_signal_voltage(struct mmc *mmc, uint signal_voltage) } #endif +#if !CONFIG_IS_ENABLED(MMC_TINY) static const struct mode_width_tuning sd_modes_by_pref[] = { #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) #ifdef MMC_SUPPORTS_TUNING @@ -1933,9 +1915,15 @@ error: return -ENOTSUPP; } +#endif + +#if CONFIG_IS_ENABLED(MMC_TINY) +DEFINE_CACHE_ALIGN_BUFFER(u8, ext_csd_bkup, MMC_MAX_BLOCK_LEN); +#endif static int mmc_startup_v4(struct mmc *mmc) { + int err, i; u64 capacity; bool has_parts = false; @@ -1952,6 +1940,23 @@ static int mmc_startup_v4(struct mmc *mmc) MMC_VERSION_5_1 }; +#if CONFIG_IS_ENABLED(MMC_TINY) + u8 *ext_csd = ext_csd_bkup; + + if (IS_SD(mmc) || (mmc->version < MMC_VERSION_4)) + return 0; + + if (!mmc->ext_csd) + memset(ext_csd_bkup, 0, sizeof(ext_csd_bkup)); + + err = mmc_send_ext_csd(mmc, ext_csd); + if (err) + goto error; + + /* store the ext csd for future reference */ + if (!mmc->ext_csd) + mmc->ext_csd = ext_csd; +#else ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN); if (IS_SD(mmc) || (mmc->version < MMC_VERSION_4)) @@ -1968,7 +1973,7 @@ static int mmc_startup_v4(struct mmc *mmc) if (!mmc->ext_csd) return -ENOMEM; memcpy(mmc->ext_csd, ext_csd, MMC_MAX_BLOCK_LEN); - +#endif if (ext_csd[EXT_CSD_REV] >= ARRAY_SIZE(mmc_versions)) return -EINVAL; @@ -2107,7 +2112,9 @@ static int mmc_startup_v4(struct mmc *mmc) return 0; error: if (mmc->ext_csd) { +#if !CONFIG_IS_ENABLED(MMC_TINY) free(mmc->ext_csd); +#endif mmc->ext_csd = NULL; } return err; @@ -2296,6 +2303,13 @@ static int mmc_startup(struct mmc *mmc) if (err) return err; + + +#if CONFIG_IS_ENABLED(MMC_TINY) + mmc_set_clock(mmc, mmc->legacy_speed, false); + mmc_select_mode(mmc, IS_SD(mmc) ? SD_LEGACY : MMC_LEGACY); + mmc_set_bus_width(mmc, 1); +#else if (IS_SD(mmc)) { err = sd_get_capabilities(mmc); if (err) @@ -2307,7 +2321,7 @@ static int mmc_startup(struct mmc *mmc) return err; mmc_select_mode_and_width(mmc, mmc->card_caps); } - +#endif if (err) return err; diff --git a/drivers/mmc/mmc_legacy.c b/drivers/mmc/mmc_legacy.c index 100b931e5b..8d62440f15 100644 --- a/drivers/mmc/mmc_legacy.c +++ b/drivers/mmc/mmc_legacy.c @@ -13,7 +13,28 @@ static struct list_head mmc_devices; static int cur_dev_num = -1; -#if !CONFIG_IS_ENABLED(MMC_TINY) +#if CONFIG_IS_ENABLED(MMC_TINY) +static struct mmc mmc_static; +struct mmc *find_mmc_device(int dev_num) +{ + return &mmc_static; +} + +void mmc_do_preinit(void) +{ + struct mmc *m = &mmc_static; +#ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT + mmc_set_preinit(m, 1); +#endif + if (m->preinit) + mmc_start_init(m); +} + +struct blk_desc *mmc_get_blk_desc(struct mmc *mmc) +{ + return &mmc->block_dev; +} +#else struct mmc *find_mmc_device(int dev_num) { struct mmc *m;