[U-Boot] [PATCH v2] mmc: Split device init to decouple OCR-polling delay
Jaehoon Chung
jh80.chung at samsung.com
Fri Nov 30 09:25:42 CET 2012
Hi,
This concept is very good.
But I have one question. I think need to call mmc_init() one more, right?
how did you save the boot time(200ms)?
On 11/29/2012 10:21 AM, Simon Glass wrote:
> From: Che-Liang Chiou <clchiou at chromium.org>
>
> Most of time that MMC driver spends on initializing a device is polling
> OCR (operation conditions register). To decouple this polling loop,
> device init is split into two parts: The first part fires the OCR query
> command, and the second part polls the result. So the caller is now no
> longer bound to the OCR-polling delay; he may fire the query, go
> somewhere and then come back later for the result.
>
> To use this, call mmc_set_preinit() on any device which needs this.
>
> This can save significant amounts of time on boot (e.g. 200ms) by
> hiding the MMC init time behind other init.
snip..
> +int mmc_init(struct mmc *mmc)
> +{
> + int err = IN_PROGRESS;
> + unsigned start = get_timer(0);
> +
> + if (mmc->has_init)
> + return 0;
> + if (!mmc->init_in_progress)
> + err = mmc_start_init(mmc);
It need not to return? if err is IN_PROGRESS, next condition is immediately run.
Then i think we didn't save the time before adjust this patch.
> +
> + if (!err || err == IN_PROGRESS)
> + err = mmc_complete_init(mmc);
> + debug("%s: %d, time %lu\n", __func__, err, get_timer(start));
> return err;
> }
>
> @@ -1315,6 +1368,25 @@ int get_mmc_num(void)
> return cur_dev_num;
> }
>
> +void mmc_set_preinit(struct mmc *mmc, int preinit)
> +{
> + mmc->preinit = preinit;
> +}
> +
> +static void do_preinit(void)
> +{
> + struct mmc *m;
> + struct list_head *entry;
> +
> + list_for_each(entry, &mmc_devices) {
> + m = list_entry(entry, struct mmc, link);
> +
> + if (m->preinit)
> + mmc_start_init(m);
> + }
> +}
> +
> +
> int mmc_initialize(bd_t *bis)
> {
> INIT_LIST_HEAD (&mmc_devices);
> @@ -1325,5 +1397,6 @@ int mmc_initialize(bd_t *bis)
>
> print_mmc_devices(',');
>
> + do_preinit();
> return 0;
> }
> diff --git a/include/mmc.h b/include/mmc.h
> index a13e2bd..445d714 100644
> --- a/include/mmc.h
> +++ b/include/mmc.h
> @@ -62,6 +62,7 @@
> #define UNUSABLE_ERR -17 /* Unusable Card */
> #define COMM_ERR -18 /* Communications Error */
> #define TIMEOUT -19
> +#define IN_PROGRESS -20 /* operation is in progress */
>
> #define MMC_CMD_GO_IDLE_STATE 0
> #define MMC_CMD_SEND_OP_COND 1
> @@ -260,6 +261,10 @@ struct mmc {
> int (*init)(struct mmc *mmc);
> int (*getcd)(struct mmc *mmc);
> uint b_max;
> + char op_cond_pending; /* 1 if we are waiting on an op_cond command */
> + char init_in_progress; /* 1 if we have done mmc_start_init() */
> + char preinit; /* start init as early as possible */
> + uint op_cond_response; /* the response byte from the last op_cond */
> };
>
> int mmc_register(struct mmc *mmc);
> @@ -276,6 +281,31 @@ int mmc_switch_part(int dev_num, unsigned int part_num);
> int mmc_getcd(struct mmc *mmc);
> void spl_mmc_load(void) __noreturn;
>
> +/**
> + * Start device initialization and return immediately; it does not block on
> + * polling OCR (operation condition register) status. Then you should call
> + * mmc_init, which would block on polling OCR status and complete the device
> + * initializatin.
> + *
> + * @param mmc Pointer to a MMC device struct
> + * @return 0 on success, IN_PROGRESS on waiting for OCR status, <0 on error.
> + */
> +int mmc_start_init(struct mmc *mmc);
> +
> +/**
> + * Set preinit flag of mmc device.
> + *
> + * This will cause the device to be pre-inited during mmc_initialize(),
> + * which may save boot time if the device is not accessed until later.
> + * Some eMMC devices take 200-300ms to init, but unfortunately they
> + * must be sent a series of commands to even get them to start preparing
> + * for operation.
> + *
> + * @param mmc Pointer to a MMC device struct
> + * @param preinit preinit flag value
> + */
> +void mmc_set_preinit(struct mmc *mmc, int preinit);
> +
> #ifdef CONFIG_GENERIC_MMC
> #define mmc_host_is_spi(mmc) ((mmc)->host_caps & MMC_MODE_SPI)
> struct mmc *mmc_spi_init(uint bus, uint cs, uint speed, uint mode);
>
More information about the U-Boot
mailing list