1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3 * Copyright (c) 2013 Google, Inc
4 */
5
6 #ifndef __SANDBOX_SDL_H
7 #define __SANDBOX_SDL_H
8
9 #include <errno.h>
10 #include <video.h>
11
12 #ifdef CONFIG_SANDBOX_SDL
13
14 /**
15 * sandbox_sdl_init_display() - Set up SDL video ready for use
16 *
17 * @width: Window width in pixels
18 * @height Window height in pixels
19 * @log2_bpp: Log to base 2 of the number of bits per pixel. So a 32bpp
20 * display will pass 5, since 2*5 = 32
21 * @double_size: true to double the visible size in each direction for high-DPI
22 * displays
23 * Return: 0 if OK, -ENODEV if no device, -EIO if SDL failed to initialize
24 * and -EPERM if the video failed to come up.
25 */
26 int sandbox_sdl_init_display(int width, int height, int log2_bpp,
27 bool double_size);
28
29 /**
30 * sandbox_sdl_remove_display() - Remove the SDL screen
31 *
32 * Return: 0 if OK, -ENOENT if the SDL had not been inited.
33 */
34 int sandbox_sdl_remove_display(void);
35
36 /**
37 * sandbox_sdl_sync() - Sync current U-Boot LCD frame buffer to SDL
38 *
39 * This must be called periodically to update the screen for SDL so that the
40 * user can see it.
41 *
42 * @lcd_base: Base of frame buffer
43 * Return: 0 if screen was updated, -ENODEV is there is no screen.
44 */
45 int sandbox_sdl_sync(void *lcd_base);
46
47 /**
48 * sandbox_sdl_scan_keys() - scan for pressed keys
49 *
50 * Works out which keys are pressed and returns a list
51 *
52 * @key: Array to receive keycodes
53 * @max_keys: Size of array
54 * Return: number of keycodes found, 0 if none, -ENODEV if no keyboard
55 */
56 int sandbox_sdl_scan_keys(int key[], int max_keys);
57
58 /**
59 * sandbox_sdl_key_pressed() - check if a particular key is pressed
60 *
61 * @keycode: Keycode to check (KEY_... - see include/linux/input.h
62 * Return: 0 if pressed, -ENOENT if not pressed. -ENODEV if keybord not
63 * available,
64 */
65 int sandbox_sdl_key_pressed(int keycode);
66
67 /**
68 * sandbox_sdl_sound_play() - Play a sound
69 *
70 * @data: Data to play (typically 16-bit)
71 * @count: Number of bytes in data
72 */
73 int sandbox_sdl_sound_play(const void *data, uint count);
74
75 /**
76 * sandbox_sdl_sound_stop() - stop playing a sound
77 *
78 * Return: 0 if OK, -ENODEV if no sound is available
79 */
80 int sandbox_sdl_sound_stop(void);
81
82 /**
83 * sandbox_sdl_sound_init() - set up the sound system
84 *
85 * @rate: Sample rate to use
86 * @channels: Number of channels to use (1=mono, 2=stereo)
87 * Return: 0 if OK, -ENODEV if no sound is available
88 */
89 int sandbox_sdl_sound_init(int rate, int channels);
90
91 /**
92 * sandbox_sdl_set_bpp() - Set the depth of the sandbox display
93 *
94 * The device must not be active when this function is called. It activiates it
95 * before returning.
96 *
97 * This updates the depth value and adjusts a few other settings accordingly.
98 * It must be called before the display is probed.
99 *
100 * @dev: Device to adjust
101 * @l2bpp: depth to set
102 * Return: 0 if the device was already active, other error if it fails to probe
103 * after the change
104 */
105 int sandbox_sdl_set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp);
106
107 #else
sandbox_sdl_init_display(int width,int height,int log2_bpp,bool double_size)108 static inline int sandbox_sdl_init_display(int width, int height, int log2_bpp,
109 bool double_size)
110 {
111 return -ENODEV;
112 }
113
sandbox_sdl_remove_display(void)114 static inline int sandbox_sdl_remove_display(void)
115 {
116 return -ENODEV;
117 }
118
sandbox_sdl_sync(void * lcd_base)119 static inline int sandbox_sdl_sync(void *lcd_base)
120 {
121 return -ENODEV;
122 }
123
sandbox_sdl_scan_keys(int key[],int max_keys)124 static inline int sandbox_sdl_scan_keys(int key[], int max_keys)
125 {
126 return -ENODEV;
127 }
128
sandbox_sdl_key_pressed(int keycode)129 static inline int sandbox_sdl_key_pressed(int keycode)
130 {
131 return -ENODEV;
132 }
133
sandbox_sdl_sound_start(uint frequency)134 static inline int sandbox_sdl_sound_start(uint frequency)
135 {
136 return -ENODEV;
137 }
138
sandbox_sdl_sound_play(const void * data,uint count)139 static inline int sandbox_sdl_sound_play(const void *data, uint count)
140 {
141 return -ENODEV;
142 }
143
sandbox_sdl_sound_stop(void)144 static inline int sandbox_sdl_sound_stop(void)
145 {
146 return -ENODEV;
147 }
148
sandbox_sdl_sound_init(int rate,int channels)149 static inline int sandbox_sdl_sound_init(int rate, int channels)
150 {
151 return -ENODEV;
152 }
153
sandbox_sdl_set_bpp(struct udevice * dev,enum video_log2_bpp l2bpp)154 static inline int sandbox_sdl_set_bpp(struct udevice *dev,
155 enum video_log2_bpp l2bpp)
156 {
157 return -ENOSYS;
158 }
159
160 #endif
161
162 #endif
163