Skip to content

Commit 899383f

Browse files
cpackham-atlnzandy-shev
authored andcommitted
auxdisplay: Add 7-segment LED display driver
Add a driver for a 7-segment LED display. At the moment only one character is supported but it should be possible to expand this to support more characters and/or 14-segment displays in the future. Signed-off-by: Chris Packham <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]>
1 parent a9bcd02 commit 899383f

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

drivers/auxdisplay/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,17 @@ config ARM_CHARLCD
211211
line and the Linux version on the second line, but that's
212212
still useful.
213213

214+
config SEG_LED_GPIO
215+
tristate "Generic 7-segment LED display"
216+
depends on GPIOLIB || COMPILE_TEST
217+
select LINEDISP
218+
help
219+
This driver supports a generic 7-segment LED display made up
220+
of GPIO pins connected to the individual segments.
221+
222+
This driver can also be built as a module. If so, the module
223+
will be called seg-led-gpio.
224+
214225
menuconfig PARPORT_PANEL
215226
tristate "Parallel port LCD/Keypad Panel support"
216227
depends on PARPORT

drivers/auxdisplay/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ obj-$(CONFIG_PARPORT_PANEL) += panel.o
1515
obj-$(CONFIG_LCD2S) += lcd2s.o
1616
obj-$(CONFIG_LINEDISP) += line-display.o
1717
obj-$(CONFIG_MAX6959) += max6959.o
18+
obj-$(CONFIG_SEG_LED_GPIO) += seg-led-gpio.o

drivers/auxdisplay/seg-led-gpio.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Driver for a 7-segment LED display
4+
*
5+
* The decimal point LED present on some devices is currently not
6+
* supported.
7+
*
8+
* Copyright (C) Allied Telesis Labs
9+
*/
10+
11+
#include <linux/bitmap.h>
12+
#include <linux/container_of.h>
13+
#include <linux/errno.h>
14+
#include <linux/gpio/consumer.h>
15+
#include <linux/map_to_7segment.h>
16+
#include <linux/mod_devicetable.h>
17+
#include <linux/module.h>
18+
#include <linux/platform_device.h>
19+
#include <linux/types.h>
20+
#include <linux/workqueue.h>
21+
22+
#include "line-display.h"
23+
24+
struct seg_led_priv {
25+
struct linedisp linedisp;
26+
struct delayed_work work;
27+
struct gpio_descs *segment_gpios;
28+
};
29+
30+
static void seg_led_update(struct work_struct *work)
31+
{
32+
struct seg_led_priv *priv = container_of(work, struct seg_led_priv, work.work);
33+
struct linedisp *linedisp = &priv->linedisp;
34+
struct linedisp_map *map = linedisp->map;
35+
DECLARE_BITMAP(values, 8) = { };
36+
37+
bitmap_set_value8(values, map_to_seg7(&map->map.seg7, linedisp->buf[0]), 0);
38+
39+
gpiod_set_array_value_cansleep(priv->segment_gpios->ndescs, priv->segment_gpios->desc,
40+
priv->segment_gpios->info, values);
41+
}
42+
43+
static int seg_led_linedisp_get_map_type(struct linedisp *linedisp)
44+
{
45+
struct seg_led_priv *priv = container_of(linedisp, struct seg_led_priv, linedisp);
46+
47+
INIT_DELAYED_WORK(&priv->work, seg_led_update);
48+
return LINEDISP_MAP_SEG7;
49+
}
50+
51+
static void seg_led_linedisp_update(struct linedisp *linedisp)
52+
{
53+
struct seg_led_priv *priv = container_of(linedisp, struct seg_led_priv, linedisp);
54+
55+
schedule_delayed_work(&priv->work, 0);
56+
}
57+
58+
static const struct linedisp_ops seg_led_linedisp_ops = {
59+
.get_map_type = seg_led_linedisp_get_map_type,
60+
.update = seg_led_linedisp_update,
61+
};
62+
63+
static int seg_led_probe(struct platform_device *pdev)
64+
{
65+
struct seg_led_priv *priv;
66+
struct device *dev = &pdev->dev;
67+
68+
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
69+
if (!priv)
70+
return -ENOMEM;
71+
72+
platform_set_drvdata(pdev, priv);
73+
74+
priv->segment_gpios = devm_gpiod_get_array(dev, "segment", GPIOD_OUT_LOW);
75+
if (IS_ERR(priv->segment_gpios))
76+
return PTR_ERR(priv->segment_gpios);
77+
78+
if (priv->segment_gpios->ndescs < 7 || priv->segment_gpios->ndescs > 8)
79+
return -EINVAL;
80+
81+
return linedisp_register(&priv->linedisp, dev, 1, &seg_led_linedisp_ops);
82+
}
83+
84+
static int seg_led_remove(struct platform_device *pdev)
85+
{
86+
struct seg_led_priv *priv = platform_get_drvdata(pdev);
87+
88+
cancel_delayed_work_sync(&priv->work);
89+
linedisp_unregister(&priv->linedisp);
90+
91+
return 0;
92+
}
93+
94+
static const struct of_device_id seg_led_of_match[] = {
95+
{ .compatible = "gpio-7-segment"},
96+
{}
97+
};
98+
MODULE_DEVICE_TABLE(of, seg_led_of_match);
99+
100+
static struct platform_driver seg_led_driver = {
101+
.probe = seg_led_probe,
102+
.remove = seg_led_remove,
103+
.driver = {
104+
.name = "seg-led-gpio",
105+
.of_match_table = seg_led_of_match,
106+
},
107+
};
108+
module_platform_driver(seg_led_driver);
109+
110+
MODULE_AUTHOR("Chris Packham <[email protected]>");
111+
MODULE_DESCRIPTION("7 segment LED driver");
112+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)