At present this function locates it own video device. Pass it in to
provide more flexibility.

Signed-off-by: Simon Glass <s...@chromium.org>

---

Changes in v2:
- Add new patch to pass in the video device for cedit_prepare()

 boot/cedit.c      | 18 ++++++++++--------
 include/cedit.h   |  4 ++--
 test/boot/cedit.c | 20 ++++++++++++++++----
 3 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/boot/cedit.c b/boot/cedit.c
index bcbbe69fe33..3fde6928f90 100644
--- a/boot/cedit.c
+++ b/boot/cedit.c
@@ -100,19 +100,16 @@ int cedit_arange(struct expo *exp, struct video_priv 
*vpriv, uint scene_id)
        return 0;
 }
 
-int cedit_prepare(struct expo *exp, struct video_priv **vid_privp,
+int cedit_prepare(struct expo *exp, struct udevice *vid_dev,
                  struct scene **scnp)
 {
+       struct udevice *dev = vid_dev;
        struct video_priv *vid_priv;
-       struct udevice *dev;
        struct scene *scn;
        uint scene_id;
        int ret;
 
        /* For now we only support a video console */
-       ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
-       if (ret)
-               return log_msg_ret("vid", ret);
        ret = expo_set_display(exp, dev);
        if (ret)
                return log_msg_ret("dis", ret);
@@ -143,7 +140,6 @@ int cedit_prepare(struct expo *exp, struct video_priv 
**vid_privp,
        if (ret)
                return log_msg_ret("dim", ret);
 
-       *vid_privp = vid_priv;
        *scnp = scn;
 
        return scene_id;
@@ -193,11 +189,17 @@ int cedit_do_action(struct expo *exp, struct scene *scn,
 int cedit_run(struct expo *exp)
 {
        struct video_priv *vid_priv;
-       uint scene_id;
+       struct udevice *dev;
        struct scene *scn;
+       uint scene_id;
        int ret;
 
-       ret = cedit_prepare(exp, &vid_priv, &scn);
+       ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
+       if (ret)
+               return log_msg_ret("vid", ret);
+       vid_priv = dev_get_uclass_priv(dev);
+
+       ret = cedit_prepare(exp, dev, &scn);
        if (ret < 0)
                return log_msg_ret("prep", ret);
        scene_id = ret;
diff --git a/include/cedit.h b/include/cedit.h
index a9305ceebcb..319a61aecb8 100644
--- a/include/cedit.h
+++ b/include/cedit.h
@@ -56,11 +56,11 @@ int cedit_run(struct expo *exp);
  * This ensures that all menus have a selected item.
  *
  * @exp: Expo to use
- * @vid_privp: Set to private data for the video device
+ * @dev: Video device to use
  * @scnp: Set to the first scene
  * Return: scene ID of first scene if OK, -ve on error
  */
-int cedit_prepare(struct expo *exp, struct video_priv **vid_privp,
+int cedit_prepare(struct expo *exp, struct udevice *vid_dev,
                  struct scene **scnp);
 
 /**
diff --git a/test/boot/cedit.c b/test/boot/cedit.c
index 5b3e9b586a6..746f60067fd 100644
--- a/test/boot/cedit.c
+++ b/test/boot/cedit.c
@@ -63,6 +63,7 @@ static int cedit_fdt(struct unit_test_state *uts)
        struct video_priv *vid_priv;
        extern struct expo *cur_exp;
        struct scene_obj_menu *menu;
+       struct udevice *dev;
        ulong addr = 0x1000;
        struct ofprop prop;
        struct scene *scn;
@@ -72,9 +73,12 @@ static int cedit_fdt(struct unit_test_state *uts)
        void *fdt;
        int i;
 
+       ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
+       vid_priv = dev_get_uclass_priv(dev);
+
        ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
 
-       ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn));
+       ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, dev, &scn));
 
        /* get a menu to fiddle with */
        menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU);
@@ -134,12 +138,16 @@ static int cedit_env(struct unit_test_state *uts)
        struct video_priv *vid_priv;
        extern struct expo *cur_exp;
        struct scene_obj_menu *menu;
+       struct udevice *dev;
        struct scene *scn;
        char *str;
 
        ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
 
-       ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn));
+       ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
+       vid_priv = dev_get_uclass_priv(dev);
+
+       ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, dev, &scn));
 
        /* get a menu to fiddle with */
        menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU);
@@ -189,11 +197,14 @@ static int cedit_cmos(struct unit_test_state *uts)
        struct scene_obj_menu *menu, *menu2;
        struct video_priv *vid_priv;
        extern struct expo *cur_exp;
+       struct udevice *dev;
        struct scene *scn;
 
        ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
 
-       ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn));
+       ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
+       vid_priv = dev_get_uclass_priv(dev);
+       ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, dev, &scn));
 
        /* get the menus to fiddle with */
        menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU);
@@ -238,7 +249,8 @@ static int cedit_render(struct unit_test_state *uts)
 
        exp = cur_exp;
        ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
-       ut_asserteq(ID_SCENE1, cedit_prepare(exp, &vid_priv, &scn));
+       vid_priv = dev_get_uclass_priv(dev);
+       ut_asserteq(ID_SCENE1, cedit_prepare(exp, dev, &scn));
 
        menu = scene_obj_find(scn, ID_POWER_LOSS, SCENEOBJT_MENU);
        ut_assertnonnull(menu);
-- 
2.43.0

Reply via email to