diff mbox series

[U-Boot,v1,1/4] mmc: omap_hsmmc: do not embed struct mmc in struct omap_hsmmc_plat

Message ID 1519295148-6817-2-git-send-email-jjhiblot@ti.com
State Superseded
Delegated to: Jaehoon Chung
Headers show
Series mmc: omap_hsmmc: Reduce the footprint of the driver and fix am335x clock | expand

Commit Message

Jean-Jacques Hiblot Feb. 22, 2018, 10:25 a.m. UTC
The area for struct mmc can be allocated dynamically. It greatly reduces
the size of struct omap_hsmmc_plat. This is useful in cases where the board
level code declares one or two struct omap_hsmmc_plat because it doesn't
use the Driver Model.

This saves around 740 bytes for the am335x_evm SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
---

 arch/arm/include/asm/omap_mmc.h | 2 +-
 drivers/mmc/omap_hsmmc.c        | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Tom Rini Feb. 22, 2018, 3:47 p.m. UTC | #1
On Thu, Feb 22, 2018 at 11:25:45AM +0100, Jean-Jacques Hiblot wrote:

> The area for struct mmc can be allocated dynamically. It greatly reduces
> the size of struct omap_hsmmc_plat. This is useful in cases where the board
> level code declares one or two struct omap_hsmmc_plat because it doesn't
> use the Driver Model.
> 
> This saves around 740 bytes for the am335x_evm SPL.
> 
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>
Simon Glass Feb. 23, 2018, 8:59 p.m. UTC | #2
Hi Jean-Jacques,

On 22 February 2018 at 03:25, Jean-Jacques Hiblot <jjhiblot@ti.com> wrote:
> The area for struct mmc can be allocated dynamically. It greatly reduces
> the size of struct omap_hsmmc_plat. This is useful in cases where the board
> level code declares one or two struct omap_hsmmc_plat because it doesn't
> use the Driver Model.
>
> This saves around 740 bytes for the am335x_evm SPL.
>
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
> ---
>
>  arch/arm/include/asm/omap_mmc.h | 2 +-
>  drivers/mmc/omap_hsmmc.c        | 6 +++---
>  2 files changed, 4 insertions(+), 4 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

I would like to understand why this saves memory though. Presumably
the pointer has to point to a real struct anyway, which uses memory.
So how does this help?

- Simon
Jean-Jacques Hiblot Feb. 26, 2018, 10:24 a.m. UTC | #3
On 23/02/2018 21:59, Simon Glass wrote:
> Hi Jean-Jacques,
>
> On 22 February 2018 at 03:25, Jean-Jacques Hiblot <jjhiblot@ti.com> wrote:
>> The area for struct mmc can be allocated dynamically. It greatly reduces
>> the size of struct omap_hsmmc_plat. This is useful in cases where the board
>> level code declares one or two struct omap_hsmmc_plat because it doesn't
>> use the Driver Model.
>>
>> This saves around 740 bytes for the am335x_evm SPL.
>>
>> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
>> ---
>>
>>   arch/arm/include/asm/omap_mmc.h | 2 +-
>>   drivers/mmc/omap_hsmmc.c        | 6 +++---
>>   2 files changed, 4 insertions(+), 4 deletions(-)
>>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> I would like to understand why this saves memory though. Presumably
> the pointer has to point to a real struct anyway, which uses memory.
> So how does this help?
struct omap_hsmmc_plat are initialized variables so they are part of the 
binary. With this patch the memory is dynamically allocated so that it's 
not taking space in the binary.

JJ
>
> - Simon
>
diff mbox series

Patch

diff --git a/arch/arm/include/asm/omap_mmc.h b/arch/arm/include/asm/omap_mmc.h
index 3d70148..42ce8dc 100644
--- a/arch/arm/include/asm/omap_mmc.h
+++ b/arch/arm/include/asm/omap_mmc.h
@@ -67,7 +67,7 @@  struct hsmmc {
 struct omap_hsmmc_plat {
 	struct mmc_config cfg;
 	struct hsmmc *base_addr;
-	struct mmc mmc;
+	struct mmc *mmc;
 	bool cd_inverted;
 	u32 controller_flags;
 	const char *hw_rev;
diff --git a/drivers/mmc/omap_hsmmc.c b/drivers/mmc/omap_hsmmc.c
index 02970f2..e0b679a 100644
--- a/drivers/mmc/omap_hsmmc.c
+++ b/drivers/mmc/omap_hsmmc.c
@@ -1858,8 +1858,8 @@  static int omap_hsmmc_ofdata_to_platdata(struct udevice *dev)
 static int omap_hsmmc_bind(struct udevice *dev)
 {
 	struct omap_hsmmc_plat *plat = dev_get_platdata(dev);
-
-	return mmc_bind(dev, &plat->mmc, &plat->cfg);
+	plat->mmc = calloc(1, sizeof(struct mmc));
+	return mmc_bind(dev, plat->mmc, &plat->cfg);
 }
 #endif
 static int omap_hsmmc_probe(struct udevice *dev)
@@ -1882,7 +1882,7 @@  static int omap_hsmmc_probe(struct udevice *dev)
 #endif
 
 #ifdef CONFIG_BLK
-	mmc = &plat->mmc;
+	mmc = plat->mmc;
 #else
 	mmc = mmc_create(cfg, priv);
 	if (mmc == NULL)