1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright 2023 Google LLC
4  * Written by Simon Glass <sjg@chromium.org>
5  */
6 
7 #ifndef __CEDIT_H
8 #define __CEDIT_H
9 
10 #include <stdbool.h>
11 #include <dm/ofnode_decl.h>
12 #include <linux/types.h>
13 
14 struct abuf;
15 struct expo;
16 struct expo_action;
17 struct scene;
18 struct udevice;
19 struct video_priv;
20 struct udevice;
21 
22 enum {
23 	/* size increment for writing FDT */
24 	CEDIT_SIZE_INC	= 1024,
25 };
26 
27 /* Name of the cedit node in the devicetree */
28 #define CEDIT_NODE_NAME		"cedit-values"
29 
30 extern struct expo *cur_exp;
31 
32 /**
33  * cedit_arange() - Arrange objects in a configuration-editor scene
34  *
35  * @exp: Expo to update
36  * @vid_priv: Private info of the video device
37  * @scene_id: scene ID to arrange
38  * Returns: 0 if OK, -ve on error
39  */
40 int cedit_arange(struct expo *exp, struct video_priv *vid_priv, uint scene_id);
41 
42 /**
43  * cedit_run() - Run a configuration editor
44  *
45  * This accepts input until the user quits with Escape
46  *
47  * @exp: Expo to use
48  * Returns: 0 if OK, -ve on error
49  */
50 int cedit_run(struct expo *exp);
51 
52 /**
53  * cedit_prepare() - Prepare to run a cedit
54  *
55  * Set up the video device, select the first scene and highlight the first item.
56  * This ensures that all menus have a selected item.
57  *
58  * @exp: Expo to use
59  * @dev: Video device to use
60  * @scnp: Set to the first scene
61  * Return: scene ID of first scene if OK, -ve on error
62  */
63 int cedit_prepare(struct expo *exp, struct udevice *vid_dev,
64 		  struct scene **scnp);
65 
66 /**
67  * cedit_do_action() - Process an action on a cedit
68  *
69  * @exp: Expo to use
70  * @scn: Current scene
71  * @vid_priv: Private data for the video device
72  * @act: Action to process
73  * Return: 0 on success, -EAGAIN if there was no action taken
74  */
75 int cedit_do_action(struct expo *exp, struct scene *scn,
76 		    struct video_priv *vid_priv, struct expo_action *act);
77 
78 /**
79  * cedit_write_settings() - Write settings in FDT format
80  *
81  * Sets up an FDT with the settings
82  *
83  * @exp: Expo to write settings from
84  * @buf: Returns abuf containing the settings FDT (inited by this function)
85  * Return: 0 if OK, -ve on error
86  */
87 int cedit_write_settings(struct expo *exp, struct abuf *buf);
88 
89 /**
90  * cedit_read_settings() - Read settings in FDT format
91  *
92  * Read an FDT with the settings
93  *
94  * @exp: Expo to read settings into
95  * @tree: Tree to read from
96  * Return: 0 if OK, -ve on error
97  */
98 int cedit_read_settings(struct expo *exp, oftree tree);
99 
100 /**
101  * cedit_write_settings_env() - Write settings to envrionment variables
102  *
103  * @exp: Expo to write settings from
104  * @verbose: true to print each var as it is set
105  * Return: 0 if OK, -ve on error
106  */
107 int cedit_write_settings_env(struct expo *exp, bool verbose);
108 
109 /*
110  * cedit_read_settings_env() - Read settings from the environment
111  *
112  * @exp: Expo to read settings into
113  * @verbose: true to print each var before it is read
114  */
115 int cedit_read_settings_env(struct expo *exp, bool verbose);
116 
117 /**
118  * cedit_write_settings_cmos() - Write settings to CMOS RAM
119  *
120  * Write settings to the defined places in CMOS RAM
121  *
122  * @exp: Expo to write settings from
123  * @dev: UCLASS_RTC device containing space for this information
124  * Returns 0 if OK, -ve on error
125  * @verbose: true to print a summary at the end
126  */
127 int cedit_write_settings_cmos(struct expo *exp, struct udevice *dev,
128 			      bool verbose);
129 
130 /**
131  * cedit_read_settings_cmos() - Read settings from CMOS RAM
132  *
133  * Read settings from the defined places in CMO RAM
134  *
135  * @exp: Expo to read settings into
136  * @dev: RTC device to read settings from
137  * @verbose: true to print a summary at the end
138  */
139 int cedit_read_settings_cmos(struct expo *exp, struct udevice *dev,
140 			     bool verbose);
141 
142 #endif /* __CEDIT_H */
143