Lines Matching +full:a +full:- +full:display

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Character line display core support
20 #include "line-display.h"
25 * linedisp_scroll() - scroll the display by a character
26 * @t: really a pointer to the private data structure
28 * Scroll the current message along the display by one character, rearming the
34 unsigned int i, ch = linedisp->scroll_pos; in linedisp_scroll()
35 unsigned int num_chars = linedisp->num_chars; in linedisp_scroll()
40 for (; i < num_chars && ch < linedisp->message_len; i++, ch++) in linedisp_scroll()
41 linedisp->buf[i] = linedisp->message[ch]; in linedisp_scroll()
47 /* update the display */ in linedisp_scroll()
48 linedisp->update(linedisp); in linedisp_scroll()
51 linedisp->scroll_pos++; in linedisp_scroll()
52 linedisp->scroll_pos %= linedisp->message_len; in linedisp_scroll()
55 if (linedisp->message_len > num_chars && linedisp->scroll_rate) in linedisp_scroll()
56 mod_timer(&linedisp->timer, jiffies + linedisp->scroll_rate); in linedisp_scroll()
60 * linedisp_display() - set the message to be displayed
62 * @msg: the message to display
63 * @count: length of msg, or -1
65 * Display a new message @msg on the display. @msg can be longer than the
66 * number of characters the display can display, in which case it will begin
67 * scrolling across the display.
69 * Return: 0 on success, -ENOMEM on memory allocation failure
77 del_timer_sync(&linedisp->timer); in linedisp_display()
79 if (count == -1) in linedisp_display()
82 /* if the string ends with a newline, trim it */ in linedisp_display()
83 if (msg[count - 1] == '\n') in linedisp_display()
84 count--; in linedisp_display()
87 /* Clear the display */ in linedisp_display()
88 kfree(linedisp->message); in linedisp_display()
89 linedisp->message = NULL; in linedisp_display()
90 linedisp->message_len = 0; in linedisp_display()
91 memset(linedisp->buf, ' ', linedisp->num_chars); in linedisp_display()
92 linedisp->update(linedisp); in linedisp_display()
98 return -ENOMEM; in linedisp_display()
100 kfree(linedisp->message); in linedisp_display()
102 linedisp->message = new_msg; in linedisp_display()
103 linedisp->message_len = count; in linedisp_display()
104 linedisp->scroll_pos = 0; in linedisp_display()
106 /* update the display */ in linedisp_display()
107 linedisp_scroll(&linedisp->timer); in linedisp_display()
113 * message_show() - read message via sysfs
114 * @dev: the display device
115 * @attr: the display message attribute
118 * Read the current message being displayed or scrolled across the display into
128 return sysfs_emit(buf, "%s\n", linedisp->message); in message_show()
132 * message_store() - write a new message via sysfs
133 * @dev: the display device
134 * @attr: the display message attribute
138 * Write a new message to display or scroll across the display from sysfs.
140 * Return: the size of the message on success, else -ERRNO
159 return sysfs_emit(buf, "%u\n", jiffies_to_msecs(linedisp->scroll_rate)); in scroll_step_ms_show()
170 return -EINVAL; in scroll_step_ms_store()
172 linedisp->scroll_rate = msecs_to_jiffies(ms); in scroll_step_ms_store()
173 if (linedisp->message && linedisp->message_len > linedisp->num_chars) { in scroll_step_ms_store()
174 del_timer_sync(&linedisp->timer); in scroll_step_ms_store()
175 if (linedisp->scroll_rate) in scroll_step_ms_store()
176 linedisp_scroll(&linedisp->timer); in scroll_step_ms_store()
196 * linedisp_register - register a character line display
197 * @linedisp: pointer to character line display structure
200 * @buf: pointer to a buffer that can hold @num_chars characters
201 * @update: Function called to update the display. This must not sleep!
203 * Return: zero on success, else a negative error code.
209 static atomic_t linedisp_id = ATOMIC_INIT(-1); in linedisp_register()
213 linedisp->dev.parent = parent; in linedisp_register()
214 linedisp->dev.type = &linedisp_type; in linedisp_register()
215 linedisp->update = update; in linedisp_register()
216 linedisp->buf = buf; in linedisp_register()
217 linedisp->num_chars = num_chars; in linedisp_register()
218 linedisp->scroll_rate = DEFAULT_SCROLL_RATE; in linedisp_register()
220 device_initialize(&linedisp->dev); in linedisp_register()
221 dev_set_name(&linedisp->dev, "linedisp.%lu", in linedisp_register()
224 /* initialise a timer for scrolling the message */ in linedisp_register()
225 timer_setup(&linedisp->timer, linedisp_scroll, 0); in linedisp_register()
227 err = device_add(&linedisp->dev); in linedisp_register()
231 /* display a default message */ in linedisp_register()
232 err = linedisp_display(linedisp, "Linux " UTS_RELEASE " ", -1); in linedisp_register()
239 device_del(&linedisp->dev); in linedisp_register()
241 del_timer_sync(&linedisp->timer); in linedisp_register()
242 put_device(&linedisp->dev); in linedisp_register()
248 * linedisp_unregister - unregister a character line display
249 * @linedisp: pointer to character line display structure registered previously
254 device_del(&linedisp->dev); in linedisp_unregister()
255 del_timer_sync(&linedisp->timer); in linedisp_unregister()
256 kfree(linedisp->message); in linedisp_unregister()
257 put_device(&linedisp->dev); in linedisp_unregister()