xref: /linux/drivers/auxdisplay/line-display.h (revision 94e244d9ccab578f83a218ec58376d025014fcce)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Character line display core support
4  *
5  * Copyright (C) 2016 Imagination Technologies
6  * Author: Paul Burton <paul.burton@mips.com>
7  *
8  * Copyright (C) 2021 Glider bv
9  * Copyright (C) 2025 Jean-François Lessard
10  */
11 
12 #ifndef _LINEDISP_H
13 #define _LINEDISP_H
14 
15 #include <linux/device.h>
16 #include <linux/timer_types.h>
17 
18 #include <linux/map_to_7segment.h>
19 #include <linux/map_to_14segment.h>
20 
21 struct linedisp;
22 
23 /**
24  * enum linedisp_map_type - type of the character mapping
25  * @LINEDISP_MAP_SEG7: Map characters to 7 segment display
26  * @LINEDISP_MAP_SEG14: Map characters to 14 segment display
27  */
28 enum linedisp_map_type {
29 	LINEDISP_MAP_SEG7,
30 	LINEDISP_MAP_SEG14,
31 };
32 
33 /**
34  * struct linedisp_map - character mapping
35  * @type: type of the character mapping
36  * @map: conversion character mapping
37  * @size: size of the @map
38  */
39 struct linedisp_map {
40 	enum linedisp_map_type type;
41 	union {
42 		struct seg7_conversion_map seg7;
43 		struct seg14_conversion_map seg14;
44 	} map;
45 	unsigned int size;
46 };
47 
48 /**
49  * struct linedisp_ops - character line display operations
50  * @get_map_type: Function called to get the character mapping, if required
51  * @update: Function called to update the display. This must not sleep!
52  */
53 struct linedisp_ops {
54 	int (*get_map_type)(struct linedisp *linedisp);
55 	void (*update)(struct linedisp *linedisp);
56 };
57 
58 /**
59  * struct linedisp - character line display private data structure
60  * @dev: the line display device
61  * @timer: timer used to implement scrolling
62  * @ops: character line display operations
63  * @buf: pointer to the buffer for the string currently displayed
64  * @message: the full message to display or scroll on the display
65  * @num_chars: the number of characters that can be displayed
66  * @message_len: the length of the @message string
67  * @scroll_pos: index of the first character of @message currently displayed
68  * @scroll_rate: scroll interval in jiffies
69  * @id: instance id of this display
70  */
71 struct linedisp {
72 	struct device dev;
73 	struct timer_list timer;
74 	const struct linedisp_ops *ops;
75 	struct linedisp_map *map;
76 	char *buf;
77 	char *message;
78 	unsigned int num_chars;
79 	unsigned int message_len;
80 	unsigned int scroll_pos;
81 	unsigned int scroll_rate;
82 	unsigned int id;
83 };
84 
85 int linedisp_attach(struct linedisp *linedisp, struct device *dev,
86 		    unsigned int num_chars, const struct linedisp_ops *ops);
87 void linedisp_detach(struct device *dev);
88 int linedisp_register(struct linedisp *linedisp, struct device *parent,
89 		      unsigned int num_chars, const struct linedisp_ops *ops);
90 void linedisp_unregister(struct linedisp *linedisp);
91 
92 #endif /* LINEDISP_H */
93