hd44780.c (718e05ed92ecac0d9d3954bcc8064527c3ce7565) | hd44780.c (2545c1c948a6a765f1a0e820c7598138b36f67ef) |
---|---|
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 --- 26 unchanged lines hidden (view full) --- 35}; 36 37struct hd44780 { 38 struct gpio_desc *pins[PIN_NUM]; 39}; 40 41static void hd44780_backlight(struct charlcd *lcd, enum charlcd_onoff on) 42{ | 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 --- 26 unchanged lines hidden (view full) --- 35}; 36 37struct hd44780 { 38 struct gpio_desc *pins[PIN_NUM]; 39}; 40 41static void hd44780_backlight(struct charlcd *lcd, enum charlcd_onoff on) 42{ |
43 struct hd44780 *hd = lcd->drvdata; | 43 struct hd44780_common *hdc = lcd->drvdata; 44 struct hd44780 *hd = hdc->hd44780; |
44 45 if (hd->pins[PIN_CTRL_BL]) 46 gpiod_set_value_cansleep(hd->pins[PIN_CTRL_BL], on); 47} 48 49static void hd44780_strobe_gpio(struct hd44780 *hd) 50{ 51 /* Maintain the data during 20 us before the strobe */ --- 47 unchanged lines hidden (view full) --- 99 gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values); 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{ | 45 46 if (hd->pins[PIN_CTRL_BL]) 47 gpiod_set_value_cansleep(hd->pins[PIN_CTRL_BL], on); 48} 49 50static void hd44780_strobe_gpio(struct hd44780 *hd) 51{ 52 /* Maintain the data during 20 us before the strobe */ --- 47 unchanged lines hidden (view full) --- 100 gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values); 101 102 hd44780_strobe_gpio(hd); 103} 104 105/* Send a command to the LCD panel in 8 bit GPIO mode */ 106static void hd44780_write_cmd_gpio8(struct charlcd *lcd, int cmd) 107{ |
107 struct hd44780 *hd = lcd->drvdata; | 108 struct hd44780_common *hdc = lcd->drvdata; 109 struct hd44780 *hd = hdc->hd44780; |
108 109 hd44780_write_gpio8(hd, cmd, 0); 110 111 /* The shortest command takes at least 120 us */ 112 udelay(120); 113} 114 115/* Send data to the LCD panel in 8 bit GPIO mode */ 116static void hd44780_write_data_gpio8(struct charlcd *lcd, int data) 117{ | 110 111 hd44780_write_gpio8(hd, cmd, 0); 112 113 /* The shortest command takes at least 120 us */ 114 udelay(120); 115} 116 117/* Send data to the LCD panel in 8 bit GPIO mode */ 118static void hd44780_write_data_gpio8(struct charlcd *lcd, int data) 119{ |
118 struct hd44780 *hd = lcd->drvdata; | 120 struct hd44780_common *hdc = lcd->drvdata; 121 struct hd44780 *hd = hdc->hd44780; |
119 120 hd44780_write_gpio8(hd, data, 1); 121 122 /* The shortest data takes at least 45 us */ 123 udelay(45); 124} 125 126static const struct charlcd_ops hd44780_ops_gpio8 = { 127 .write_cmd = hd44780_write_cmd_gpio8, 128 .write_data = hd44780_write_data_gpio8, 129 .backlight = hd44780_backlight, 130}; 131 132/* Send a command to the LCD panel in 4 bit GPIO mode */ 133static void hd44780_write_cmd_gpio4(struct charlcd *lcd, int cmd) 134{ | 122 123 hd44780_write_gpio8(hd, data, 1); 124 125 /* The shortest data takes at least 45 us */ 126 udelay(45); 127} 128 129static const struct charlcd_ops hd44780_ops_gpio8 = { 130 .write_cmd = hd44780_write_cmd_gpio8, 131 .write_data = hd44780_write_data_gpio8, 132 .backlight = hd44780_backlight, 133}; 134 135/* Send a command to the LCD panel in 4 bit GPIO mode */ 136static void hd44780_write_cmd_gpio4(struct charlcd *lcd, int cmd) 137{ |
135 struct hd44780 *hd = lcd->drvdata; | 138 struct hd44780_common *hdc = lcd->drvdata; 139 struct hd44780 *hd = hdc->hd44780; |
136 137 hd44780_write_gpio4(hd, cmd, 0); 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{ 146 DECLARE_BITMAP(values, 6); /* for DATA[4-7], RS, RW */ | 140 141 hd44780_write_gpio4(hd, cmd, 0); 142 143 /* The shortest command takes at least 120 us */ 144 udelay(120); 145} 146 147/* Send 4-bits of a command to the LCD panel in raw 4 bit GPIO mode */ 148static void hd44780_write_cmd_raw_gpio4(struct charlcd *lcd, int cmd) 149{ 150 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; |
148 unsigned int n; 149 150 /* Command nibble + RS, RW */ 151 values[0] = cmd & 0x0f; 152 n = hd->pins[PIN_CTRL_RW] ? 6 : 5; 153 154 /* Present the data to the port */ 155 gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values); 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{ | 153 unsigned int n; 154 155 /* Command nibble + RS, RW */ 156 values[0] = cmd & 0x0f; 157 n = hd->pins[PIN_CTRL_RW] ? 6 : 5; 158 159 /* Present the data to the port */ 160 gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values); 161 162 hd44780_strobe_gpio(hd); 163} 164 165/* Send data to the LCD panel in 4 bit GPIO mode */ 166static void hd44780_write_data_gpio4(struct charlcd *lcd, int data) 167{ |
163 struct hd44780 *hd = lcd->drvdata; | 168 struct hd44780_common *hdc = lcd->drvdata; 169 struct hd44780 *hd = hdc->hd44780; |
164 165 hd44780_write_gpio4(hd, data, 1); 166 167 /* The shortest data takes at least 45 us */ 168 udelay(45); 169} 170 171static const struct charlcd_ops hd44780_ops_gpio4 = { --- 27 unchanged lines hidden (view full) --- 199 default: 200 return -EINVAL; 201 } 202 203 hdc = hd44780_common_alloc(); 204 if (!hdc) 205 return -ENOMEM; 206 | 170 171 hd44780_write_gpio4(hd, data, 1); 172 173 /* The shortest data takes at least 45 us */ 174 udelay(45); 175} 176 177static const struct charlcd_ops hd44780_ops_gpio4 = { --- 27 unchanged lines hidden (view full) --- 205 default: 206 return -EINVAL; 207 } 208 209 hdc = hd44780_common_alloc(); 210 if (!hdc) 211 return -ENOMEM; 212 |
207 lcd = charlcd_alloc(sizeof(struct hd44780)); | 213 lcd = charlcd_alloc(); |
208 if (!lcd) 209 goto fail1; 210 211 hd = kzalloc(sizeof(struct hd44780), GFP_KERNEL); 212 if (!hd) 213 goto fail2; 214 215 hdc->hd44780 = hd; --- 43 unchanged lines hidden (view full) --- 259 if (ret) 260 goto fail3; 261 262 /* 263 * On displays with more than two rows, the internal buffer width is 264 * usually equal to the display width 265 */ 266 if (lcd->height > 2) | 214 if (!lcd) 215 goto fail1; 216 217 hd = kzalloc(sizeof(struct hd44780), GFP_KERNEL); 218 if (!hd) 219 goto fail2; 220 221 hdc->hd44780 = hd; --- 43 unchanged lines hidden (view full) --- 265 if (ret) 266 goto fail3; 267 268 /* 269 * On displays with more than two rows, the internal buffer width is 270 * usually equal to the display width 271 */ 272 if (lcd->height > 2) |
267 lcd->bwidth = lcd->width; | 273 hdc->bwidth = lcd->width; |
268 269 /* Optional properties */ | 274 275 /* Optional properties */ |
270 device_property_read_u32(dev, "internal-buffer-width", &lcd->bwidth); | 276 device_property_read_u32(dev, "internal-buffer-width", &hdc->bwidth); |
271 272 lcd->ifwidth = ifwidth; 273 lcd->ops = ifwidth == 8 ? &hd44780_ops_gpio8 : &hd44780_ops_gpio4; 274 275 ret = charlcd_register(lcd); 276 if (ret) 277 goto fail3; 278 --- 42 unchanged lines hidden --- | 277 278 lcd->ifwidth = ifwidth; 279 lcd->ops = ifwidth == 8 ? &hd44780_ops_gpio8 : &hd44780_ops_gpio4; 280 281 ret = charlcd_register(lcd); 282 if (ret) 283 goto fail3; 284 --- 42 unchanged lines hidden --- |