dm: treewide: Rename dev_get_platdata() to dev_get_plat()
[platform/kernel/u-boot.git] / drivers / video / sandbox_sdl.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2013 Google, Inc
4  */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <fdtdec.h>
9 #include <log.h>
10 #include <video.h>
11 #include <asm/sdl.h>
12 #include <asm/state.h>
13 #include <asm/u-boot-sandbox.h>
14 #include <dm/test.h>
15
16 DECLARE_GLOBAL_DATA_PTR;
17
18 enum {
19         /* Default LCD size we support */
20         LCD_MAX_WIDTH           = 1366,
21         LCD_MAX_HEIGHT          = 768,
22 };
23
24 static int sandbox_sdl_probe(struct udevice *dev)
25 {
26         struct video_uc_platdata *uc_plat = dev_get_uclass_plat(dev);
27         struct sandbox_sdl_plat *plat = dev_get_plat(dev);
28         struct video_priv *uc_priv = dev_get_uclass_priv(dev);
29         struct sandbox_state *state = state_get_current();
30         int ret;
31
32         ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix,
33                                        state->double_lcd);
34         if (ret) {
35                 puts("LCD init failed\n");
36                 return ret;
37         }
38         uc_priv->xsize = plat->xres;
39         uc_priv->ysize = plat->yres;
40         uc_priv->bpix = plat->bpix;
41         uc_priv->rot = plat->rot;
42         uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name;
43         uc_priv->font_size = plat->font_size;
44         if (IS_ENABLED(CONFIG_VIDEO_COPY))
45                 uc_plat->copy_base = uc_plat->base - uc_plat->size / 2;
46
47         return 0;
48 }
49
50 static int sandbox_sdl_bind(struct udevice *dev)
51 {
52         struct video_uc_platdata *uc_plat = dev_get_uclass_plat(dev);
53         struct sandbox_sdl_plat *plat = dev_get_plat(dev);
54         int ret = 0;
55
56         plat->xres = dev_read_u32_default(dev, "xres", LCD_MAX_WIDTH);
57         plat->yres = dev_read_u32_default(dev, "yres", LCD_MAX_HEIGHT);
58         plat->bpix = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16);
59         plat->rot = dev_read_u32_default(dev, "rotate", 0);
60         uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8;
61
62         /* Allow space for two buffers, the lower one being the copy buffer */
63         log_debug("Frame buffer size %x\n", uc_plat->size);
64         if (IS_ENABLED(CONFIG_VIDEO_COPY))
65                 uc_plat->size *= 2;
66
67         return ret;
68 }
69
70 static const struct udevice_id sandbox_sdl_ids[] = {
71         { .compatible = "sandbox,lcd-sdl" },
72         { }
73 };
74
75 U_BOOT_DRIVER(sandbox_lcd_sdl) = {
76         .name   = "sandbox_lcd_sdl",
77         .id     = UCLASS_VIDEO,
78         .of_match = sandbox_sdl_ids,
79         .bind   = sandbox_sdl_bind,
80         .probe  = sandbox_sdl_probe,
81         .plat_auto      = sizeof(struct sandbox_sdl_plat),
82 };