hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/auxdisplay/hd44780.c
....@@ -14,8 +14,7 @@
1414 #include <linux/property.h>
1515 #include <linux/slab.h>
1616
17
-#include <misc/charlcd.h>
18
-
17
+#include "charlcd.h"
1918
2019 enum hd44780_pin {
2120 /* Order does matter due to writing to GPIO array subsets! */
....@@ -62,20 +61,15 @@
6261 /* write to an LCD panel register in 8 bit GPIO mode */
6362 static void hd44780_write_gpio8(struct hd44780 *hd, u8 val, unsigned int rs)
6463 {
65
- int values[10]; /* for DATA[0-7], RS, RW */
66
- unsigned int i, n;
64
+ DECLARE_BITMAP(values, 10); /* for DATA[0-7], RS, RW */
65
+ unsigned int n;
6766
68
- for (i = 0; i < 8; i++)
69
- values[PIN_DATA0 + i] = !!(val & BIT(i));
70
- values[PIN_CTRL_RS] = rs;
71
- n = 9;
72
- if (hd->pins[PIN_CTRL_RW]) {
73
- values[PIN_CTRL_RW] = 0;
74
- n++;
75
- }
67
+ values[0] = val;
68
+ __assign_bit(8, values, rs);
69
+ n = hd->pins[PIN_CTRL_RW] ? 10 : 9;
7670
7771 /* Present the data to the port */
78
- gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA0], values);
72
+ gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA0], NULL, values);
7973
8074 hd44780_strobe_gpio(hd);
8175 }
....@@ -83,32 +77,25 @@
8377 /* write to an LCD panel register in 4 bit GPIO mode */
8478 static void hd44780_write_gpio4(struct hd44780 *hd, u8 val, unsigned int rs)
8579 {
86
- int values[10]; /* for DATA[0-7], RS, RW, but DATA[0-3] is unused */
87
- unsigned int i, n;
80
+ DECLARE_BITMAP(values, 6); /* for DATA[4-7], RS, RW */
81
+ unsigned int n;
8882
8983 /* High nibble + RS, RW */
90
- for (i = 4; i < 8; i++)
91
- values[PIN_DATA0 + i] = !!(val & BIT(i));
92
- values[PIN_CTRL_RS] = rs;
93
- n = 5;
94
- if (hd->pins[PIN_CTRL_RW]) {
95
- values[PIN_CTRL_RW] = 0;
96
- n++;
97
- }
84
+ values[0] = val >> 4;
85
+ __assign_bit(4, values, rs);
86
+ n = hd->pins[PIN_CTRL_RW] ? 6 : 5;
9887
9988 /* Present the data to the port */
100
- gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4],
101
- &values[PIN_DATA4]);
89
+ gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values);
10290
10391 hd44780_strobe_gpio(hd);
10492
10593 /* Low nibble */
106
- for (i = 0; i < 4; i++)
107
- values[PIN_DATA4 + i] = !!(val & BIT(i));
94
+ values[0] &= ~0x0fUL;
95
+ values[0] |= val & 0x0f;
10896
10997 /* Present the data to the port */
110
- gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4],
111
- &values[PIN_DATA4]);
98
+ gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values);
11299
113100 hd44780_strobe_gpio(hd);
114101 }
....@@ -155,23 +142,16 @@
155142 /* Send 4-bits of a command to the LCD panel in raw 4 bit GPIO mode */
156143 static void hd44780_write_cmd_raw_gpio4(struct charlcd *lcd, int cmd)
157144 {
158
- int values[10]; /* for DATA[0-7], RS, RW, but DATA[0-3] is unused */
145
+ DECLARE_BITMAP(values, 6); /* for DATA[4-7], RS, RW */
159146 struct hd44780 *hd = lcd->drvdata;
160
- unsigned int i, n;
147
+ unsigned int n;
161148
162149 /* Command nibble + RS, RW */
163
- for (i = 0; i < 4; i++)
164
- values[PIN_DATA4 + i] = !!(cmd & BIT(i));
165
- values[PIN_CTRL_RS] = 0;
166
- n = 5;
167
- if (hd->pins[PIN_CTRL_RW]) {
168
- values[PIN_CTRL_RW] = 0;
169
- n++;
170
- }
150
+ values[0] = cmd & 0x0f;
151
+ n = hd->pins[PIN_CTRL_RW] ? 6 : 5;
171152
172153 /* Present the data to the port */
173
- gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4],
174
- &values[PIN_DATA4]);
154
+ gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values);
175155
176156 hd44780_strobe_gpio(hd);
177157 }
....@@ -290,7 +270,7 @@
290270 return 0;
291271
292272 fail:
293
- kfree(lcd);
273
+ charlcd_free(lcd);
294274 return ret;
295275 }
296276
....@@ -300,7 +280,7 @@
300280
301281 charlcd_unregister(lcd);
302282
303
- kfree(lcd);
283
+ charlcd_free(lcd);
304284 return 0;
305285 }
306286