Skip to content

Commit 70fb97c

Browse files
committed
auxdisplay: linedisp: Provide struct linedisp_ops for future extension
Currently the line display library doesn't scale in case we want to provide more operations. Prepare the library to take a newly created struct linedisp_ops that scales. Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org> Tested-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
1 parent fe5bd82 commit 70fb97c

4 files changed

Lines changed: 35 additions & 15 deletions

File tree

drivers/auxdisplay/ht16k33.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ static void ht16k33_linedisp_update(struct linedisp *linedisp)
448448
schedule_delayed_work(&priv->work, 0);
449449
}
450450

451+
static const struct linedisp_ops ht16k33_linedisp_ops = {
452+
.update = ht16k33_linedisp_update,
453+
};
454+
451455
static void ht16k33_seg7_update(struct work_struct *work)
452456
{
453457
struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv,
@@ -697,7 +701,7 @@ static int ht16k33_seg_probe(struct device *dev, struct ht16k33_priv *priv,
697701
return err;
698702

699703
err = linedisp_register(&seg->linedisp, dev, 4, seg->curr,
700-
ht16k33_linedisp_update);
704+
&ht16k33_linedisp_ops);
701705
if (err)
702706
goto err_remove_map_file;
703707

drivers/auxdisplay/img-ascii-lcd.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ struct img_ascii_lcd_ctx;
2222
* struct img_ascii_lcd_config - Configuration information about an LCD model
2323
* @num_chars: the number of characters the LCD can display
2424
* @external_regmap: true if registers are in a system controller, else false
25-
* @update: function called to update the LCD
25+
* @ops: character line display operations
2626
*/
2727
struct img_ascii_lcd_config {
2828
unsigned int num_chars;
2929
bool external_regmap;
30-
void (*update)(struct linedisp *linedisp);
30+
const struct linedisp_ops ops;
3131
};
3232

3333
/**
@@ -75,7 +75,9 @@ static void boston_update(struct linedisp *linedisp)
7575

7676
static struct img_ascii_lcd_config boston_config = {
7777
.num_chars = 8,
78-
.update = boston_update,
78+
.ops = {
79+
.update = boston_update,
80+
},
7981
};
8082

8183
/*
@@ -103,7 +105,9 @@ static void malta_update(struct linedisp *linedisp)
103105
static struct img_ascii_lcd_config malta_config = {
104106
.num_chars = 8,
105107
.external_regmap = true,
106-
.update = malta_update,
108+
.ops = {
109+
.update = malta_update,
110+
},
107111
};
108112

109113
/*
@@ -203,7 +207,9 @@ static void sead3_update(struct linedisp *linedisp)
203207
static struct img_ascii_lcd_config sead3_config = {
204208
.num_chars = 16,
205209
.external_regmap = true,
206-
.update = sead3_update,
210+
.ops = {
211+
.update = sead3_update,
212+
},
207213
};
208214

209215
static const struct of_device_id img_ascii_lcd_matches[] = {
@@ -248,7 +254,7 @@ static int img_ascii_lcd_probe(struct platform_device *pdev)
248254
}
249255

250256
err = linedisp_register(&ctx->linedisp, dev, cfg->num_chars, ctx->curr,
251-
cfg->update);
257+
&cfg->ops);
252258
if (err)
253259
return err;
254260

drivers/auxdisplay/line-display.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void linedisp_scroll(struct timer_list *t)
5050
}
5151

5252
/* update the display */
53-
linedisp->update(linedisp);
53+
linedisp->ops->update(linedisp);
5454

5555
/* move on to the next character */
5656
linedisp->scroll_pos++;
@@ -94,7 +94,7 @@ static int linedisp_display(struct linedisp *linedisp, const char *msg,
9494
linedisp->message = NULL;
9595
linedisp->message_len = 0;
9696
memset(linedisp->buf, ' ', linedisp->num_chars);
97-
linedisp->update(linedisp);
97+
linedisp->ops->update(linedisp);
9898
return 0;
9999
}
100100

@@ -216,20 +216,20 @@ static const struct device_type linedisp_type = {
216216
* @parent: parent device
217217
* @num_chars: the number of characters that can be displayed
218218
* @buf: pointer to a buffer that can hold @num_chars characters
219-
* @update: Function called to update the display. This must not sleep!
219+
* @ops: character line display operations
220220
*
221221
* Return: zero on success, else a negative error code.
222222
*/
223223
int linedisp_register(struct linedisp *linedisp, struct device *parent,
224224
unsigned int num_chars, char *buf,
225-
void (*update)(struct linedisp *linedisp))
225+
const struct linedisp_ops *ops)
226226
{
227227
int err;
228228

229229
memset(linedisp, 0, sizeof(*linedisp));
230230
linedisp->dev.parent = parent;
231231
linedisp->dev.type = &linedisp_type;
232-
linedisp->update = update;
232+
linedisp->ops = ops;
233233
linedisp->buf = buf;
234234
linedisp->num_chars = num_chars;
235235
linedisp->scroll_rate = DEFAULT_SCROLL_RATE;

drivers/auxdisplay/line-display.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@
1414
#include <linux/device.h>
1515
#include <linux/timer_types.h>
1616

17+
struct linedisp;
18+
19+
/**
20+
* struct linedisp_ops - character line display operations
21+
* @update: Function called to update the display. This must not sleep!
22+
*/
23+
struct linedisp_ops {
24+
void (*update)(struct linedisp *linedisp);
25+
};
26+
1727
/**
1828
* struct linedisp - character line display private data structure
1929
* @dev: the line display device
2030
* @timer: timer used to implement scrolling
21-
* @update: function called to update the display
31+
* @ops: character line display operations
2232
* @buf: pointer to the buffer for the string currently displayed
2333
* @message: the full message to display or scroll on the display
2434
* @num_chars: the number of characters that can be displayed
@@ -30,7 +40,7 @@
3040
struct linedisp {
3141
struct device dev;
3242
struct timer_list timer;
33-
void (*update)(struct linedisp *linedisp);
43+
const struct linedisp_ops *ops;
3444
char *buf;
3545
char *message;
3646
unsigned int num_chars;
@@ -42,7 +52,7 @@ struct linedisp {
4252

4353
int linedisp_register(struct linedisp *linedisp, struct device *parent,
4454
unsigned int num_chars, char *buf,
45-
void (*update)(struct linedisp *linedisp));
55+
const struct linedisp_ops *ops);
4656
void linedisp_unregister(struct linedisp *linedisp);
4757

4858
#endif /* LINEDISP_H */

0 commit comments

Comments
 (0)