drivers/auxdisplay/hd44780.c
Source file repositories/reference/linux-study-clean/drivers/auxdisplay/hd44780.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/auxdisplay/hd44780.c- Extension
.c- Size
- 8528 bytes
- Lines
- 346
- Domain
- Driver Families
- Bucket
- drivers/auxdisplay
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/gpio/consumer.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/property.hlinux/slab.hcharlcd.hhd44780_common.h
Detected Declarations
struct hd44780enum hd44780_pinfunction hd44780_backlightfunction hd44780_strobe_gpiofunction hd44780_write_gpio8function hd44780_write_gpio4function hd44780_write_cmd_gpio8function hd44780_write_data_gpio8function hd44780_write_cmd_gpio4function hd44780_write_cmd_raw_gpio4function hd44780_write_data_gpio4function hd44780_probefunction hd44780_remove
Annotated Snippet
struct hd44780 {
struct gpio_desc *pins[PIN_NUM];
};
static void hd44780_backlight(struct charlcd *lcd, enum charlcd_onoff on)
{
struct hd44780_common *hdc = lcd->drvdata;
struct hd44780 *hd = hdc->hd44780;
if (hd->pins[PIN_CTRL_BL])
gpiod_set_value_cansleep(hd->pins[PIN_CTRL_BL], on);
}
static void hd44780_strobe_gpio(struct hd44780 *hd)
{
/* Maintain the data during 20 us before the strobe */
udelay(20);
gpiod_set_value_cansleep(hd->pins[PIN_CTRL_E], 1);
/* Maintain the strobe during 40 us */
udelay(40);
gpiod_set_value_cansleep(hd->pins[PIN_CTRL_E], 0);
}
/* write to an LCD panel register in 8 bit GPIO mode */
static void hd44780_write_gpio8(struct hd44780 *hd, u8 val, unsigned int rs)
{
DECLARE_BITMAP(values, 10); /* for DATA[0-7], RS, RW */
unsigned int n;
values[0] = val;
__assign_bit(8, values, rs);
n = hd->pins[PIN_CTRL_RW] ? 10 : 9;
/* Present the data to the port */
gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA0], NULL, values);
hd44780_strobe_gpio(hd);
}
/* write to an LCD panel register in 4 bit GPIO mode */
static void hd44780_write_gpio4(struct hd44780 *hd, u8 val, unsigned int rs)
{
DECLARE_BITMAP(values, 6); /* for DATA[4-7], RS, RW */
unsigned int n;
/* High nibble + RS, RW */
values[0] = val >> 4;
__assign_bit(4, values, rs);
n = hd->pins[PIN_CTRL_RW] ? 6 : 5;
/* Present the data to the port */
gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values);
hd44780_strobe_gpio(hd);
/* Low nibble */
values[0] &= ~0x0fUL;
values[0] |= val & 0x0f;
/* Present the data to the port */
gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values);
hd44780_strobe_gpio(hd);
}
/* Send a command to the LCD panel in 8 bit GPIO mode */
static void hd44780_write_cmd_gpio8(struct hd44780_common *hdc, int cmd)
{
struct hd44780 *hd = hdc->hd44780;
hd44780_write_gpio8(hd, cmd, 0);
/* The shortest command takes at least 120 us */
udelay(120);
}
/* Send data to the LCD panel in 8 bit GPIO mode */
static void hd44780_write_data_gpio8(struct hd44780_common *hdc, int data)
{
struct hd44780 *hd = hdc->hd44780;
hd44780_write_gpio8(hd, data, 1);
/* The shortest data takes at least 45 us */
udelay(45);
}
Annotation
- Immediate include surface: `linux/delay.h`, `linux/gpio/consumer.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/property.h`, `linux/slab.h`, `charlcd.h`.
- Detected declarations: `struct hd44780`, `enum hd44780_pin`, `function hd44780_backlight`, `function hd44780_strobe_gpio`, `function hd44780_write_gpio8`, `function hd44780_write_gpio4`, `function hd44780_write_cmd_gpio8`, `function hd44780_write_data_gpio8`, `function hd44780_write_cmd_gpio4`, `function hd44780_write_cmd_raw_gpio4`.
- Atlas domain: Driver Families / drivers/auxdisplay.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.