From c5022b5d92e246481568bd856118ee440f24efa3 Mon Sep 17 00:00:00 2001 From: Lars Ivar Miljeteig Date: Wed, 20 Nov 2019 22:39:43 +0100 Subject: [PATCH] epd init: Add mmc tools Move duplicate code to mmc_tools. Make sure the epd_pmic_init cleans up the global mmc definition at exit, otherwise calling saveenv results in a nasty hangup. --- board/reMarkable/zero-sugar/Makefile | 1 + .../reMarkable/zero-sugar/epd_display_init.c | 28 +-------------- board/reMarkable/zero-sugar/epd_pmic_init.c | 34 ++++--------------- board/reMarkable/zero-sugar/mmc_tools.c | 34 +++++++++++++++++++ board/reMarkable/zero-sugar/mmc_tools.h | 9 +++++ 5 files changed, 52 insertions(+), 54 deletions(-) create mode 100644 board/reMarkable/zero-sugar/mmc_tools.c create mode 100644 board/reMarkable/zero-sugar/mmc_tools.h diff --git a/board/reMarkable/zero-sugar/Makefile b/board/reMarkable/zero-sugar/Makefile index 80dc952ae7..94d0cad137 100644 --- a/board/reMarkable/zero-sugar/Makefile +++ b/board/reMarkable/zero-sugar/Makefile @@ -9,6 +9,7 @@ obj-y := zero-sugar.o \ epd_display_init.o \ digitizer_init.o \ charger_init.o \ + mmc_tools.o \ serial_download_trap.o \ jump_rom_usb_download.o \ ../../freescale/common/mmc.o diff --git a/board/reMarkable/zero-sugar/epd_display_init.c b/board/reMarkable/zero-sugar/epd_display_init.c index 1f3abd799e..3746624d42 100644 --- a/board/reMarkable/zero-sugar/epd_display_init.c +++ b/board/reMarkable/zero-sugar/epd_display_init.c @@ -1,5 +1,6 @@ #include "epd_display_init.h" #include "epd_pmic_init.h" +#include "mmc_tools.h" #include #include @@ -10,7 +11,6 @@ #include #include #include -#include static int epd_splash(void); static int splash_init(void); @@ -93,32 +93,6 @@ struct splash_functions { int (*blit_gc)(uint32_t*, const uint8_t*, int, int, int, int, int); }splash; -static bool mmc_set_dev_part(int dev, int part) -{ - struct mmc *mmc; - int ret; - - mmc = find_mmc_device(dev); - if (!mmc) { - printf("%s: no mmc device at slot %x\n", __func__, dev); - return false; - } - mmc->has_init = 0; - - if (mmc_init(mmc)) { - printf("%s: Unable to initialize mmc\n", __func__); - return false; - } - - ret = blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part); - if (ret) { - printf("%s: Unable to switch partition, returned %d\n", __func__, ret); - return false; - } - - return true; -} - static int splash_init(void) { const char *filename = "zplash"; diff --git a/board/reMarkable/zero-sugar/epd_pmic_init.c b/board/reMarkable/zero-sugar/epd_pmic_init.c index b9979d1a17..1aa46900df 100644 --- a/board/reMarkable/zero-sugar/epd_pmic_init.c +++ b/board/reMarkable/zero-sugar/epd_pmic_init.c @@ -1,4 +1,5 @@ #include "epd_pmic_init.h" +#include "mmc_tools.h" #include #include @@ -7,6 +8,7 @@ #include #include +#include #include #define SY7636A_I2C_BUS 3 @@ -165,30 +167,6 @@ int epd_read_temp(int *temp) return sy7636a_thermistor_get(dev, temp); } -static struct mmc *mmc_set_part_dev(int dev, int part) -{ - int ret; - struct mmc *mmc = find_mmc_device(dev); - if (!mmc) { - printf("%s: no mmc device at slot %x\n", __func__, dev); - return NULL; - } - mmc->has_init = 0; - - if (mmc_init(mmc)) { - printf("%s: Unable to initialize mmc\n", __func__); - return NULL; - } - - ret = blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part); - if (ret) { - printf("%s: Unable to switch partition, returned %d\n", __func__, ret); - return NULL; - } - - return mmc; -} - #define EPDIDVCOM_INDEX 3 #define EPDIDVCOM_LEN 25 #define VCOM_LEN 5 @@ -205,14 +183,15 @@ static int read_vcom_from_mmc(int dev, int part, ulong *vcom) const u32 blk_cnt = 1; - mmc = mmc_set_part_dev(dev, part); + mmc = mmc_set_dev_part(dev, part); if (!mmc) return -1; buffer = (char*)malloc(512); if (!buffer) { printf("%s: Unable to allocate memory\n", __func__); - return -1; + ret = -1; + goto reset_mmc; } n = blk_dread(mmc_get_blk_desc(mmc), 0, blk_cnt, buffer); @@ -269,6 +248,8 @@ static int read_vcom_from_mmc(int dev, int part, ulong *vcom) free_buf: free(buffer); +reset_mmc: + mmc_reset(); return ret; } @@ -318,7 +299,6 @@ int zs_do_epd_power_on(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] ret = read_vcom_from_mmc(0, 2, &vcom); if (ret == 0) { env_set_ulong("vcom", vcom); - mmc_set_part_dev(0, 0); env_save(); } else { printf("Unable to read vcom from mmc, using default\n"); diff --git a/board/reMarkable/zero-sugar/mmc_tools.c b/board/reMarkable/zero-sugar/mmc_tools.c new file mode 100644 index 0000000000..4f7eb6e73a --- /dev/null +++ b/board/reMarkable/zero-sugar/mmc_tools.c @@ -0,0 +1,34 @@ +#include "mmc_tools.h" + +#include +#include + +struct mmc *mmc_set_dev_part(int dev, int part) +{ + int ret; + struct mmc *mmc = find_mmc_device(dev); + if (!mmc) { + printf("%s: no mmc device at slot %x\n", __func__, dev); + return NULL; + } + mmc->has_init = 0; + + if (mmc_init(mmc)) { + printf("%s: Unable to initialize mmc\n", __func__); + return NULL; + } + + ret = blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part); + if (ret) { + printf("%s: Unable to switch partition, returned %d\n", __func__, ret); + return NULL; + } + + return mmc; +} + +int mmc_reset(void) +{ + struct mmc *mmc = mmc_set_dev_part(mmc_get_env_dev(), 0); + return mmc ? 0 : -1; +} diff --git a/board/reMarkable/zero-sugar/mmc_tools.h b/board/reMarkable/zero-sugar/mmc_tools.h new file mode 100644 index 0000000000..471272a603 --- /dev/null +++ b/board/reMarkable/zero-sugar/mmc_tools.h @@ -0,0 +1,9 @@ +#ifndef MMC_TOOLS_H +#define MMC_TOOLS_H + +struct mmc; + +struct mmc *mmc_set_dev_part(int dev, int part); +int mmc_reset(void); + +#endif