hd44780.c (e42f6f9be4f83c537aa81b4c6239ea94ff5b29ce) hd44780.c (b9762bebc6332b40c33e03dea03e30fa12d9e3ed)
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * HD44780 Character LCD driver for Linux
4 *
5 * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu>
6 * Copyright (C) 2016-2017 Glider bvba
7 */
8

--- 48 unchanged lines hidden (view full) ---

57 udelay(40);
58
59 gpiod_set_value_cansleep(hd->pins[PIN_CTRL_E], 0);
60}
61
62/* write to an LCD panel register in 8 bit GPIO mode */
63static void hd44780_write_gpio8(struct hd44780 *hd, u8 val, unsigned int rs)
64{
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * HD44780 Character LCD driver for Linux
4 *
5 * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu>
6 * Copyright (C) 2016-2017 Glider bvba
7 */
8

--- 48 unchanged lines hidden (view full) ---

57 udelay(40);
58
59 gpiod_set_value_cansleep(hd->pins[PIN_CTRL_E], 0);
60}
61
62/* write to an LCD panel register in 8 bit GPIO mode */
63static void hd44780_write_gpio8(struct hd44780 *hd, u8 val, unsigned int rs)
64{
65 int values[10]; /* for DATA[0-7], RS, RW */
66 unsigned int i, n;
65 DECLARE_BITMAP(values, 10); /* for DATA[0-7], RS, RW */
66 unsigned int n;
67
67
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 }
68 values[0] = val;
69 __assign_bit(8, values, rs);
70 n = hd->pins[PIN_CTRL_RW] ? 10 : 9;
76
77 /* Present the data to the port */
78 gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA0], values);
79
80 hd44780_strobe_gpio(hd);
81}
82
83/* write to an LCD panel register in 4 bit GPIO mode */
84static void hd44780_write_gpio4(struct hd44780 *hd, u8 val, unsigned int rs)
85{
71
72 /* Present the data to the port */
73 gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA0], values);
74
75 hd44780_strobe_gpio(hd);
76}
77
78/* write to an LCD panel register in 4 bit GPIO mode */
79static void hd44780_write_gpio4(struct hd44780 *hd, u8 val, unsigned int rs)
80{
86 int values[10]; /* for DATA[0-7], RS, RW, but DATA[0-3] is unused */
87 unsigned int i, n;
81 DECLARE_BITMAP(values, 6); /* for DATA[4-7], RS, RW */
82 unsigned int n;
88
89 /* High nibble + RS, RW */
83
84 /* 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 }
85 values[0] = val >> 4;
86 __assign_bit(4, values, rs);
87 n = hd->pins[PIN_CTRL_RW] ? 6 : 5;
98
99 /* Present the data to the port */
88
89 /* Present the data to the port */
100 gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4],
101 &values[PIN_DATA4]);
90 gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], values);
102
103 hd44780_strobe_gpio(hd);
104
105 /* Low nibble */
91
92 hd44780_strobe_gpio(hd);
93
94 /* Low nibble */
106 for (i = 0; i < 4; i++)
107 values[PIN_DATA4 + i] = !!(val & BIT(i));
95 values[0] &= ~0x0fUL;
96 values[0] |= val & 0x0f;
108
109 /* Present the data to the port */
97
98 /* Present the data to the port */
110 gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4],
111 &values[PIN_DATA4]);
99 gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], values);
112
113 hd44780_strobe_gpio(hd);
114}
115
116/* Send a command to the LCD panel in 8 bit GPIO mode */
117static void hd44780_write_cmd_gpio8(struct charlcd *lcd, int cmd)
118{
119 struct hd44780 *hd = lcd->drvdata;

--- 30 unchanged lines hidden (view full) ---

150
151 /* The shortest command takes at least 120 us */
152 udelay(120);
153}
154
155/* Send 4-bits of a command to the LCD panel in raw 4 bit GPIO mode */
156static void hd44780_write_cmd_raw_gpio4(struct charlcd *lcd, int cmd)
157{
100
101 hd44780_strobe_gpio(hd);
102}
103
104/* Send a command to the LCD panel in 8 bit GPIO mode */
105static void hd44780_write_cmd_gpio8(struct charlcd *lcd, int cmd)
106{
107 struct hd44780 *hd = lcd->drvdata;

--- 30 unchanged lines hidden (view full) ---

138
139 /* The shortest command takes at least 120 us */
140 udelay(120);
141}
142
143/* Send 4-bits of a command to the LCD panel in raw 4 bit GPIO mode */
144static void hd44780_write_cmd_raw_gpio4(struct charlcd *lcd, int cmd)
145{
158 int values[10]; /* for DATA[0-7], RS, RW, but DATA[0-3] is unused */
146 DECLARE_BITMAP(values, 6); /* for DATA[4-7], RS, RW */
159 struct hd44780 *hd = lcd->drvdata;
147 struct hd44780 *hd = lcd->drvdata;
160 unsigned int i, n;
148 unsigned int n;
161
162 /* Command nibble + RS, RW */
149
150 /* 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 }
151 values[0] = cmd & 0x0f;
152 n = hd->pins[PIN_CTRL_RW] ? 6 : 5;
171
172 /* Present the data to the port */
153
154 /* Present the data to the port */
173 gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4],
174 &values[PIN_DATA4]);
155 gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], values);
175
176 hd44780_strobe_gpio(hd);
177}
178
179/* Send data to the LCD panel in 4 bit GPIO mode */
180static void hd44780_write_data_gpio4(struct charlcd *lcd, int data)
181{
182 struct hd44780 *hd = lcd->drvdata;

--- 141 unchanged lines hidden ---
156
157 hd44780_strobe_gpio(hd);
158}
159
160/* Send data to the LCD panel in 4 bit GPIO mode */
161static void hd44780_write_data_gpio4(struct charlcd *lcd, int data)
162{
163 struct hd44780 *hd = lcd->drvdata;

--- 141 unchanged lines hidden ---