diff options
author | Andrey Smirnov <andrew.smirnov@gmail.com> | 2019-12-02 07:19:47 -0800 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2019-12-04 08:37:12 +0100 |
commit | 70b0c6d3f06fdf84648d3462246ffb04cefb2063 (patch) | |
tree | 886e19322d717a2ba2509fc10114b395acfa0eb8 /drivers/mci/imx-esdhc-pbl.c | |
parent | 3755c616cc12aa98352762e5809616e71df056d9 (diff) | |
download | barebox-70b0c6d3f06fdf84648d3462246ffb04cefb2063.tar.gz barebox-70b0c6d3f06fdf84648d3462246ffb04cefb2063.tar.xz |
mci: imx-esdhc-pbl: Share initialization code
Move common ESDHC initialization code into subroutines and convert the
rest of the code to use it.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mci/imx-esdhc-pbl.c')
-rw-r--r-- | drivers/mci/imx-esdhc-pbl.c | 64 |
1 files changed, 33 insertions, 31 deletions
diff --git a/drivers/mci/imx-esdhc-pbl.c b/drivers/mci/imx-esdhc-pbl.c index 2afb55af9d..d5d83d18ea 100644 --- a/drivers/mci/imx-esdhc-pbl.c +++ b/drivers/mci/imx-esdhc-pbl.c @@ -365,6 +365,31 @@ esdhc_start_image(struct esdhc *esdhc, ptrdiff_t address, ptrdiff_t entry, bb(); } +static void imx_esdhc_init(struct esdhc *esdhc) +{ + esdhc->is_be = 0; + esdhc->is_mx6 = 1; + esdhc->wrap_wml = false; +} + +static int imx8_esdhc_init(struct esdhc *esdhc, int instance) +{ + switch (instance) { + case 0: + esdhc->regs = IOMEM(MX8MQ_USDHC1_BASE_ADDR); + break; + case 1: + esdhc->regs = IOMEM(MX8MQ_USDHC2_BASE_ADDR); + break; + default: + return -EINVAL; + } + + imx_esdhc_init(esdhc); + + return 0; +} + /** * imx6_esdhc_start_image - Load and start an image from USDHC controller * @instance: The USDHC controller instance (0..4) @@ -398,9 +423,7 @@ int imx6_esdhc_start_image(int instance) return -EINVAL; } - esdhc.is_be = 0; - esdhc.is_mx6 = 1; - esdhc.wrap_wml = false; + imx_esdhc_init(&esdhc); return esdhc_start_image(&esdhc, 0x10000000, 0x10000000, 0); } @@ -420,21 +443,11 @@ int imx6_esdhc_start_image(int instance) int imx8_esdhc_start_image(int instance) { struct esdhc esdhc; + int ret; - switch (instance) { - case 0: - esdhc.regs = IOMEM(MX8MQ_USDHC1_BASE_ADDR); - break; - case 1: - esdhc.regs = IOMEM(MX8MQ_USDHC2_BASE_ADDR); - break; - default: - return -EINVAL; - } - - esdhc.is_be = 0; - esdhc.is_mx6 = 1; - esdhc.wrap_wml = false; + ret = imx8_esdhc_init(&esdhc, instance); + if (ret) + return ret; return esdhc_start_image(&esdhc, MX8MQ_DDR_CSD1_BASE_ADDR, MX8MQ_ATF_BL33_BASE_ADDR, SZ_32K); @@ -448,20 +461,9 @@ int imx8_esdhc_load_piggy(int instance) int ret, len; int offset = SZ_32K; - switch (instance) { - case 0: - esdhc.regs = IOMEM(MX8MQ_USDHC1_BASE_ADDR); - break; - case 1: - esdhc.regs = IOMEM(MX8MQ_USDHC2_BASE_ADDR); - break; - default: - return -EINVAL; - } - - esdhc.is_be = 0; - esdhc.is_mx6 = 1; - esdhc.wrap_wml = false; + ret = imx8_esdhc_init(&esdhc, instance); + if (ret) + return ret; /* * We expect to be running at MX8MQ_ATF_BL33_BASE_ADDR where the atf |