Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

auxdisplay: linedisp: Add support for changing scroll rate

If the message to display is longer than the number of characters that
the display can show, the message will be scrolled. Currently the
scroll rate is fixed, moving every 500 ms.

Add support for changing the scroll rate through a "scroll_step_ms"
device attribute in sysfs.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

authored by

Geert Uytterhoeven and committed by
Miguel Ojeda
d79141c3 364f2c39

+35 -2
+35 -2
drivers/auxdisplay/line-display.c
··· 19 19 20 20 #include "line-display.h" 21 21 22 + #define DEFAULT_SCROLL_RATE (HZ / 2) 23 + 22 24 /** 23 25 * linedisp_scroll() - scroll the display by a character 24 26 * @t: really a pointer to the private data structure ··· 52 50 linedisp->scroll_pos %= linedisp->message_len; 53 51 54 52 /* rearm the timer */ 55 - if (linedisp->message_len > num_chars) 53 + if (linedisp->message_len > num_chars && linedisp->scroll_rate) 56 54 mod_timer(&linedisp->timer, jiffies + linedisp->scroll_rate); 57 55 } 58 56 ··· 151 149 152 150 static DEVICE_ATTR_RW(message); 153 151 152 + static ssize_t scroll_step_ms_show(struct device *dev, 153 + struct device_attribute *attr, char *buf) 154 + { 155 + struct linedisp *linedisp = container_of(dev, struct linedisp, dev); 156 + 157 + return sysfs_emit(buf, "%u\n", jiffies_to_msecs(linedisp->scroll_rate)); 158 + } 159 + 160 + static ssize_t scroll_step_ms_store(struct device *dev, 161 + struct device_attribute *attr, 162 + const char *buf, size_t count) 163 + { 164 + struct linedisp *linedisp = container_of(dev, struct linedisp, dev); 165 + unsigned int ms; 166 + 167 + if (kstrtouint(buf, 10, &ms) != 0) 168 + return -EINVAL; 169 + 170 + linedisp->scroll_rate = msecs_to_jiffies(ms); 171 + if (linedisp->message && linedisp->message_len > linedisp->num_chars) { 172 + del_timer_sync(&linedisp->timer); 173 + if (linedisp->scroll_rate) 174 + linedisp_scroll(&linedisp->timer); 175 + } 176 + 177 + return count; 178 + } 179 + 180 + static DEVICE_ATTR_RW(scroll_step_ms); 181 + 154 182 static struct attribute *linedisp_attrs[] = { 155 183 &dev_attr_message.attr, 184 + &dev_attr_scroll_step_ms.attr, 156 185 NULL, 157 186 }; 158 187 ATTRIBUTE_GROUPS(linedisp); ··· 215 182 linedisp->update = update; 216 183 linedisp->buf = buf; 217 184 linedisp->num_chars = num_chars; 218 - linedisp->scroll_rate = HZ / 2; 185 + linedisp->scroll_rate = DEFAULT_SCROLL_RATE; 219 186 220 187 device_initialize(&linedisp->dev); 221 188 dev_set_name(&linedisp->dev, "linedisp.%lu",