Skip to content

Commit 2545c1c

Browse files
poeschelojeda
authored andcommitted
auxdisplay: Move hwidth and bwidth to struct hd44780_common
hwidth is for the hardware buffer size and bwidth is for the buffer width of one single line. This is specific to the hd44780 displays and so it is moved out from charlcd to struct hd44780_common. Reviewed-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Lars Poeschel <poeschel@lemonage.de> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 718e05e commit 2545c1c

File tree

6 files changed

+67
-55
lines changed

6 files changed

+67
-55
lines changed

drivers/auxdisplay/charlcd.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
#include <generated/utsrelease.h>
2222

2323
#include "charlcd.h"
24-
25-
#define DEFAULT_LCD_BWIDTH 40
26-
#define DEFAULT_LCD_HWIDTH 64
24+
#include "hd44780_common.h"
2725

2826
/* Keep the backlight on this many seconds for each flash */
2927
#define LCD_BL_TEMPO_PERIOD 4
@@ -151,18 +149,19 @@ EXPORT_SYMBOL_GPL(charlcd_poke);
151149
static void charlcd_gotoxy(struct charlcd *lcd)
152150
{
153151
struct charlcd_priv *priv = charlcd_to_priv(lcd);
152+
struct hd44780_common *hdc = lcd->drvdata;
154153
unsigned int addr;
155154

156155
/*
157156
* we force the cursor to stay at the end of the
158157
* line if it wants to go farther
159158
*/
160-
addr = priv->addr.x < lcd->bwidth ? priv->addr.x & (lcd->hwidth - 1)
161-
: lcd->bwidth - 1;
159+
addr = priv->addr.x < hdc->bwidth ? priv->addr.x & (hdc->hwidth - 1)
160+
: hdc->bwidth - 1;
162161
if (priv->addr.y & 1)
163-
addr += lcd->hwidth;
162+
addr += hdc->hwidth;
164163
if (priv->addr.y & 2)
165-
addr += lcd->bwidth;
164+
addr += hdc->bwidth;
166165
lcd->ops->write_cmd(lcd, LCD_CMD_SET_DDRAM_ADDR | addr);
167166
}
168167

@@ -178,29 +177,31 @@ static void charlcd_home(struct charlcd *lcd)
178177
static void charlcd_print(struct charlcd *lcd, char c)
179178
{
180179
struct charlcd_priv *priv = charlcd_to_priv(lcd);
180+
struct hd44780_common *hdc = lcd->drvdata;
181181

182-
if (priv->addr.x < lcd->bwidth) {
182+
if (priv->addr.x < hdc->bwidth) {
183183
if (lcd->char_conv)
184184
c = lcd->char_conv[(unsigned char)c];
185185
lcd->ops->write_data(lcd, c);
186186
priv->addr.x++;
187187

188188
/* prevents the cursor from wrapping onto the next line */
189-
if (priv->addr.x == lcd->bwidth)
189+
if (priv->addr.x == hdc->bwidth)
190190
charlcd_gotoxy(lcd);
191191
}
192192
}
193193

194194
static void charlcd_clear_fast(struct charlcd *lcd)
195195
{
196+
struct hd44780_common *hdc = lcd->drvdata;
196197
int pos;
197198

198199
charlcd_home(lcd);
199200

200201
if (lcd->ops->clear_fast)
201202
lcd->ops->clear_fast(lcd);
202203
else
203-
for (pos = 0; pos < min(2, lcd->height) * lcd->hwidth; pos++)
204+
for (pos = 0; pos < min(2, lcd->height) * hdc->hwidth; pos++)
204205
lcd->ops->write_data(lcd, ' ');
205206

206207
charlcd_home(lcd);
@@ -348,6 +349,7 @@ static bool parse_xy(const char *s, unsigned long *x, unsigned long *y)
348349
static inline int handle_lcd_special_code(struct charlcd *lcd)
349350
{
350351
struct charlcd_priv *priv = charlcd_to_priv(lcd);
352+
struct hd44780_common *hdc = lcd->drvdata;
351353

352354
/* LCD special codes */
353355

@@ -413,7 +415,7 @@ static inline int handle_lcd_special_code(struct charlcd *lcd)
413415
case 'l': /* Shift Cursor Left */
414416
if (priv->addr.x > 0) {
415417
/* back one char if not at end of line */
416-
if (priv->addr.x < lcd->bwidth)
418+
if (priv->addr.x < hdc->bwidth)
417419
lcd->ops->write_cmd(lcd, LCD_CMD_SHIFT);
418420
priv->addr.x--;
419421
}
@@ -422,7 +424,7 @@ static inline int handle_lcd_special_code(struct charlcd *lcd)
422424
case 'r': /* shift cursor right */
423425
if (priv->addr.x < lcd->width) {
424426
/* allow the cursor to pass the end of the line */
425-
if (priv->addr.x < (lcd->bwidth - 1))
427+
if (priv->addr.x < (hdc->bwidth - 1))
426428
lcd->ops->write_cmd(lcd,
427429
LCD_CMD_SHIFT | LCD_CMD_SHIFT_RIGHT);
428430
priv->addr.x++;
@@ -442,7 +444,7 @@ static inline int handle_lcd_special_code(struct charlcd *lcd)
442444
case 'k': { /* kill end of line */
443445
int x;
444446

445-
for (x = priv->addr.x; x < lcd->bwidth; x++)
447+
for (x = priv->addr.x; x < hdc->bwidth; x++)
446448
lcd->ops->write_data(lcd, ' ');
447449

448450
/* restore cursor position */
@@ -554,6 +556,7 @@ static inline int handle_lcd_special_code(struct charlcd *lcd)
554556
static void charlcd_write_char(struct charlcd *lcd, char c)
555557
{
556558
struct charlcd_priv *priv = charlcd_to_priv(lcd);
559+
struct hd44780_common *hdc = lcd->drvdata;
557560

558561
/* first, we'll test if we're in escape mode */
559562
if ((c != '\n') && priv->esc_seq.len >= 0) {
@@ -577,7 +580,7 @@ static void charlcd_write_char(struct charlcd *lcd, char c)
577580
* check if we're not at the
578581
* end of the line
579582
*/
580-
if (priv->addr.x < lcd->bwidth)
583+
if (priv->addr.x < hdc->bwidth)
581584
/* back one char */
582585
lcd->ops->write_cmd(lcd, LCD_CMD_SHIFT);
583586
priv->addr.x--;
@@ -596,7 +599,7 @@ static void charlcd_write_char(struct charlcd *lcd, char c)
596599
* flush the remainder of the current line and
597600
* go to the beginning of the next line
598601
*/
599-
for (; priv->addr.x < lcd->bwidth; priv->addr.x++)
602+
for (; priv->addr.x < hdc->bwidth; priv->addr.x++)
600603
lcd->ops->write_data(lcd, ' ');
601604
priv->addr.x = 0;
602605
priv->addr.y = (priv->addr.y + 1) % lcd->height;
@@ -779,22 +782,19 @@ static int charlcd_init(struct charlcd *lcd)
779782
return 0;
780783
}
781784

782-
struct charlcd *charlcd_alloc(unsigned int drvdata_size)
785+
struct charlcd *charlcd_alloc(void)
783786
{
784787
struct charlcd_priv *priv;
785788
struct charlcd *lcd;
786789

787-
priv = kzalloc(sizeof(*priv) + drvdata_size, GFP_KERNEL);
790+
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
788791
if (!priv)
789792
return NULL;
790793

791794
priv->esc_seq.len = -1;
792795

793796
lcd = &priv->lcd;
794797
lcd->ifwidth = 8;
795-
lcd->bwidth = DEFAULT_LCD_BWIDTH;
796-
lcd->hwidth = DEFAULT_LCD_HWIDTH;
797-
lcd->drvdata = priv->drvdata;
798798

799799
return lcd;
800800
}

drivers/auxdisplay/charlcd.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ struct charlcd {
2121
int ifwidth; /* 4-bit or 8-bit (default) */
2222
int height;
2323
int width;
24-
int bwidth; /* Default set by charlcd_alloc() */
25-
int hwidth; /* Default set by charlcd_alloc() */
2624

27-
void *drvdata; /* Set by charlcd_alloc() */
25+
void *drvdata;
2826
};
2927

3028
struct charlcd_ops {
@@ -38,7 +36,7 @@ struct charlcd_ops {
3836
void (*backlight)(struct charlcd *lcd, enum charlcd_onoff on);
3937
};
4038

41-
struct charlcd *charlcd_alloc(unsigned int drvdata_size);
39+
struct charlcd *charlcd_alloc(void);
4240
void charlcd_free(struct charlcd *lcd);
4341

4442
int charlcd_register(struct charlcd *lcd);

drivers/auxdisplay/hd44780.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ struct hd44780 {
4040

4141
static void hd44780_backlight(struct charlcd *lcd, enum charlcd_onoff on)
4242
{
43-
struct hd44780 *hd = lcd->drvdata;
43+
struct hd44780_common *hdc = lcd->drvdata;
44+
struct hd44780 *hd = hdc->hd44780;
4445

4546
if (hd->pins[PIN_CTRL_BL])
4647
gpiod_set_value_cansleep(hd->pins[PIN_CTRL_BL], on);
@@ -104,7 +105,8 @@ static void hd44780_write_gpio4(struct hd44780 *hd, u8 val, unsigned int rs)
104105
/* Send a command to the LCD panel in 8 bit GPIO mode */
105106
static void hd44780_write_cmd_gpio8(struct charlcd *lcd, int cmd)
106107
{
107-
struct hd44780 *hd = lcd->drvdata;
108+
struct hd44780_common *hdc = lcd->drvdata;
109+
struct hd44780 *hd = hdc->hd44780;
108110

109111
hd44780_write_gpio8(hd, cmd, 0);
110112

@@ -115,7 +117,8 @@ static void hd44780_write_cmd_gpio8(struct charlcd *lcd, int cmd)
115117
/* Send data to the LCD panel in 8 bit GPIO mode */
116118
static void hd44780_write_data_gpio8(struct charlcd *lcd, int data)
117119
{
118-
struct hd44780 *hd = lcd->drvdata;
120+
struct hd44780_common *hdc = lcd->drvdata;
121+
struct hd44780 *hd = hdc->hd44780;
119122

120123
hd44780_write_gpio8(hd, data, 1);
121124

@@ -132,7 +135,8 @@ static const struct charlcd_ops hd44780_ops_gpio8 = {
132135
/* Send a command to the LCD panel in 4 bit GPIO mode */
133136
static void hd44780_write_cmd_gpio4(struct charlcd *lcd, int cmd)
134137
{
135-
struct hd44780 *hd = lcd->drvdata;
138+
struct hd44780_common *hdc = lcd->drvdata;
139+
struct hd44780 *hd = hdc->hd44780;
136140

137141
hd44780_write_gpio4(hd, cmd, 0);
138142

@@ -144,7 +148,8 @@ static void hd44780_write_cmd_gpio4(struct charlcd *lcd, int cmd)
144148
static void hd44780_write_cmd_raw_gpio4(struct charlcd *lcd, int cmd)
145149
{
146150
DECLARE_BITMAP(values, 6); /* for DATA[4-7], RS, RW */
147-
struct hd44780 *hd = lcd->drvdata;
151+
struct hd44780_common *hdc = lcd->drvdata;
152+
struct hd44780 *hd = hdc->hd44780;
148153
unsigned int n;
149154

150155
/* Command nibble + RS, RW */
@@ -160,7 +165,8 @@ static void hd44780_write_cmd_raw_gpio4(struct charlcd *lcd, int cmd)
160165
/* Send data to the LCD panel in 4 bit GPIO mode */
161166
static void hd44780_write_data_gpio4(struct charlcd *lcd, int data)
162167
{
163-
struct hd44780 *hd = lcd->drvdata;
168+
struct hd44780_common *hdc = lcd->drvdata;
169+
struct hd44780 *hd = hdc->hd44780;
164170

165171
hd44780_write_gpio4(hd, data, 1);
166172

@@ -204,7 +210,7 @@ static int hd44780_probe(struct platform_device *pdev)
204210
if (!hdc)
205211
return -ENOMEM;
206212

207-
lcd = charlcd_alloc(sizeof(struct hd44780));
213+
lcd = charlcd_alloc();
208214
if (!lcd)
209215
goto fail1;
210216

@@ -264,10 +270,10 @@ static int hd44780_probe(struct platform_device *pdev)
264270
* usually equal to the display width
265271
*/
266272
if (lcd->height > 2)
267-
lcd->bwidth = lcd->width;
273+
hdc->bwidth = lcd->width;
268274

269275
/* Optional properties */
270-
device_property_read_u32(dev, "internal-buffer-width", &lcd->bwidth);
276+
device_property_read_u32(dev, "internal-buffer-width", &hdc->bwidth);
271277

272278
lcd->ifwidth = ifwidth;
273279
lcd->ops = ifwidth == 8 ? &hd44780_ops_gpio8 : &hd44780_ops_gpio4;

drivers/auxdisplay/hd44780_common.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ struct hd44780_common *hd44780_common_alloc(void)
1212
if (!hd)
1313
return NULL;
1414

15+
hd->bwidth = DEFAULT_LCD_BWIDTH;
16+
hd->hwidth = DEFAULT_LCD_HWIDTH;
1517
return hd;
1618
}
1719
EXPORT_SYMBOL_GPL(hd44780_common_alloc);

drivers/auxdisplay/hd44780_common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
/* SPDX-License-Identifier: GPL-2.0-or-later */
22

3+
#define DEFAULT_LCD_BWIDTH 40
4+
#define DEFAULT_LCD_HWIDTH 64
5+
36
struct hd44780_common {
7+
int bwidth; /* Default set by hd44780_alloc() */
8+
int hwidth; /* Default set by hd44780_alloc() */
49
void *hd44780;
510
};
611

0 commit comments

Comments
 (0)